xref: /plan9/sys/src/libmemlayer/lhide.c (revision ec59a3ddbfceee0efe34584c2c9981a5e5ff1ec4)
1 #include <u.h>
2 #include <libc.h>
3 #include <draw.h>
4 #include <memdraw.h>
5 #include <memlayer.h>
6 #include <pool.h>
7 
8 /*
9  * Hide puts that portion of screenr now on the screen into the window's save area.
10  * Expose puts that portion of screenr now in the save area onto the screen.
11  *
12  * Hide and Expose both require that the layer structures in the screen
13  * match the geometry they are being asked to update, that is, they update the
14  * save area (hide) or screen (expose) based on what those structures tell them.
15  * This means they must be called at the correct time during window shuffles.
16  */
17 
18 static
19 void
20 lhideop(Memimage *src, Rectangle screenr, Rectangle clipr, void *etc, int insave)
21 {
22 	Rectangle r;
23 	Memlayer *l;
24 
25 	USED(clipr.min.x);
26 	USED(insave);
27 	l = etc;
28 	if(src != l->save){	/* do nothing if src is already in save area */
29 		r = rectsubpt(screenr, l->delta);
30 		memdraw(l->save, r, src, screenr.min, nil, screenr.min, S);
31 	}
32 }
33 
34 void
35 memlhide(Memimage *i, Rectangle screenr)
36 {
37 	if(i->layer->save == nil)
38 		return;
39 	if(rectclip(&screenr, i->layer->screen->image->r) == 0)
40 		return;
41 	_memlayerop(lhideop, i, screenr, screenr, i->layer);
42 }
43 
44 static
45 void
46 lexposeop(Memimage *dst, Rectangle screenr, Rectangle clipr, void *etc, int insave)
47 {
48 	Memlayer *l;
49 	Rectangle r;
50 
51 	USED(clipr.min.x);
52 	if(insave)	/* if dst is save area, don't bother */
53 		return;
54 	l = etc;
55 	r = rectsubpt(screenr, l->delta);
56 	if(l->save)
57 		memdraw(dst, screenr, l->save, r.min, nil, r.min, S);
58 	else
59 		l->refreshfn(dst, r, l->refreshptr);
60 }
61 
62 void
63 memlexpose(Memimage *i, Rectangle screenr)
64 {
65 	if(rectclip(&screenr, i->layer->screen->image->r) == 0)
66 		return;
67 	_memlayerop(lexposeop, i, screenr, screenr, i->layer);
68 }
69