code: drawterm

ref: 4f14409f5630abbb4a96d54e7823da3c7ac08c81
dir: /libmemlayer/lsetrefresh.c/

View raw version
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>
#include <memlayer.h>

int
memlsetrefresh(Memimage *i, Refreshfn fn, void *ptr)
{
	Memlayer *l;

	l = i->layer;
	if(l->refreshfn!=0 && fn!=0){	/* just change functions */
		l->refreshfn = fn;
		l->refreshptr = ptr;
		return 1;
	}

	if(l->refreshfn == 0){	/* is using backup image; just free it */
		freememimage(l->save);
		l->save = nil;
		l->refreshfn = fn;
		l->refreshptr = ptr;
		return 1;
	}

	l->save = allocmemimage(i->r, i->chan);
	if(l->save == nil)
		return 0;
	/* easiest way is just to update the entire save area */
	l->refreshfn(i, i->r, l->refreshptr);
	l->refreshfn = 0;
	l->refreshptr = nil;
	return 1;
}