plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

x11-get.c (1887B)


      1 #include <u.h>
      2 #include "x11-inc.h"
      3 #include <libc.h>
      4 #include <draw.h>
      5 #include <memdraw.h>
      6 #include "x11-memdraw.h"
      7 
      8 static void
      9 addrect(Rectangle *rp, Rectangle r)
     10 {
     11 	if(rp->min.x >= rp->max.x)
     12 		*rp = r;
     13 	else
     14 		combinerect(rp, r);
     15 }
     16 
     17 XImage*
     18 _xgetxdata(Memimage *m, Rectangle r)
     19 {
     20 	int x, y;
     21 	uchar *p;
     22 	Point tp, xdelta, delta;
     23 	Xmem *xm;
     24 
     25 	xm = m->X;
     26 	if(xm == nil)
     27 		return nil;
     28 
     29 	if(xm->dirty == 0)
     30 		return xm->xi;
     31 
     32 	abort();	/* should never call this now */
     33 
     34 	r = xm->dirtyr;
     35 	if(Dx(r)==0 || Dy(r)==0)
     36 		return xm->xi;
     37 
     38 	delta = subpt(r.min, m->r.min);
     39 
     40 	tp = xm->r.min;	/* need temp for Digital UNIX */
     41 	xdelta = subpt(r.min, tp);
     42 
     43 	XGetSubImage(_x.display, xm->pixmap, delta.x, delta.y, Dx(r), Dy(r),
     44 		AllPlanes, ZPixmap, xm->xi, xdelta.x, delta.y);
     45 
     46 	if(_x.usetable && m->chan==CMAP8){
     47 		for(y=r.min.y; y<r.max.y; y++)
     48 		for(x=r.min.x, p=byteaddr(m, Pt(x,y)); x<r.max.x; x++, p++)
     49 			*p = _x.toplan9[*p];
     50 	}
     51 	xm->dirty = 0;
     52 	xm->dirtyr = Rect(0,0,0,0);
     53 	return xm->xi;
     54 }
     55 
     56 void
     57 _xputxdata(Memimage *m, Rectangle r)
     58 {
     59 	int x, y;
     60 	uchar *p;
     61 	Point tp, xdelta, delta;
     62 	Xmem *xm;
     63 	XGC gc;
     64 	XImage *xi;
     65 
     66 	xm = m->X;
     67 	if(xm == nil)
     68 		return;
     69 
     70 	xi = xm->xi;
     71 	gc = m->chan==GREY1 ? _x.gccopy0 : _x.gccopy;
     72 
     73 	delta = subpt(r.min, m->r.min);
     74 
     75 	tp = xm->r.min;	/* need temporary on Digital UNIX */
     76 	xdelta = subpt(r.min, tp);
     77 
     78 	if(_x.usetable && m->chan==CMAP8){
     79 		for(y=r.min.y; y<r.max.y; y++)
     80 		for(x=r.min.x, p=byteaddr(m, Pt(x,y)); x<r.max.x; x++, p++)
     81 			*p = _x.tox11[*p];
     82 	}
     83 
     84 	XPutImage(_x.display, xm->pixmap, gc, xi, xdelta.x, xdelta.y, delta.x, delta.y,
     85 		Dx(r), Dy(r));
     86 
     87 	if(_x.usetable && m->chan==CMAP8){
     88 		for(y=r.min.y; y<r.max.y; y++)
     89 		for(x=r.min.x, p=byteaddr(m, Pt(x,y)); x<r.max.x; x++, p++)
     90 			*p = _x.toplan9[*p];
     91 	}
     92 }
     93 
     94 void
     95 _xdirtyxdata(Memimage *m, Rectangle r)
     96 {
     97 	Xmem *xm;
     98 
     99 	xm = m->X;
    100 	if(xm == nil)
    101 		return;
    102 
    103 	xm->dirty = 1;
    104 	addrect(&xm->dirtyr, r);
    105 }