unload.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <draw.h>
  12. #include <memdraw.h>
  13. #include <memlayer.h>
  14. int
  15. memunload(Memimage *src, Rectangle r, uint8_t *data, int n)
  16. {
  17. Memimage *tmp;
  18. Memlayer *dl;
  19. Rectangle lr;
  20. int dx;
  21. Top:
  22. dl = src->layer;
  23. if(dl == nil)
  24. return unloadmemimage(src, r, data, n);
  25. /*
  26. * Convert to screen coordinates.
  27. */
  28. lr = r;
  29. r.min.x += dl->delta.x;
  30. r.min.y += dl->delta.y;
  31. r.max.x += dl->delta.x;
  32. r.max.y += dl->delta.y;
  33. dx = dl->delta.x&(7/src->depth);
  34. if(dl->clear && dx==0){
  35. src = dl->screen->image;
  36. goto Top;
  37. }
  38. /*
  39. * src is an obscured layer or data is unaligned
  40. */
  41. if(dl->save && dx==0){
  42. if(dl->refreshfn != nil)
  43. return -1; /* can't unload window if it's not Refbackup */
  44. if(n > 0)
  45. memlhide(src, r);
  46. n = unloadmemimage(dl->save, lr, data, n);
  47. return n;
  48. }
  49. tmp = allocmemimage(lr, src->chan);
  50. if(tmp == nil)
  51. return -1;
  52. memdraw(tmp, lr, src, lr.min, nil, lr.min, S);
  53. n = unloadmemimage(tmp, lr, data, n);
  54. freememimage(tmp);
  55. return n;
  56. }