lsetrefresh.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. memlsetrefresh(Memimage *i, Refreshfn fn, void *ptr)
  16. {
  17. Memlayer *l;
  18. l = i->layer;
  19. if(l->refreshfn!=nil && fn!=nil){ /* just change functions */
  20. l->refreshfn = fn;
  21. l->refreshptr = ptr;
  22. return 1;
  23. }
  24. if(l->refreshfn == nil){ /* is using backup image; just free it */
  25. freememimage(l->save);
  26. l->save = nil;
  27. l->refreshfn = fn;
  28. l->refreshptr = ptr;
  29. return 1;
  30. }
  31. l->save = allocmemimage(i->r, i->chan);
  32. if(l->save == nil)
  33. return 0;
  34. /* easiest way is just to update the entire save area */
  35. l->refreshfn(i, i->r, l->refreshptr);
  36. l->refreshfn = nil;
  37. l->refreshptr = nil;
  38. return 1;
  39. }