Blob


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"
8 static int xdraw(Memdrawparam*);
10 /*
11 * The X acceleration doesn't fit into the standard hwaccel
12 * model because we have the extra steps of pulling the image
13 * data off the server and putting it back when we're done.
14 */
15 void
16 memimagedraw(Memimage *dst, Rectangle r, Memimage *src, Point sp,
17 Memimage *mask, Point mp, int op)
18 {
19 Memdrawparam *par;
21 if((par = _memimagedrawsetup(dst, r, src, sp, mask, mp, op)) == nil)
22 return;
24 /* only fetch dst data if we need it */
25 if((par->state&(Simplemask|Fullmask)) != (Simplemask|Fullmask))
26 _xgetxdata(par->dst, par->r);
28 /* always fetch source and mask */
29 _xgetxdata(par->src, par->sr);
30 _xgetxdata(par->mask, par->mr);
32 /* now can run memimagedraw on the in-memory bits */
33 _memimagedraw(par);
35 if(xdraw(par))
36 return;
38 /* put bits back on x server */
39 _xputxdata(par->dst, par->r);
40 }
42 static int
43 xdraw(Memdrawparam *par)
44 {
45 u32int sdval;
46 uint m, state;
47 Memimage *src, *dst, *mask;
48 Point dp, mp, sp;
49 Rectangle r;
50 Xmem *xdst, *xmask, *xsrc;
51 XGC gc;
53 if(par->dst->X == nil)
54 return 0;
56 dst = par->dst;
57 mask = par->mask;
58 r = par->r;
59 src = par->src;
60 state = par->state;
62 /*
63 * If we have an opaque mask and source is one opaque pixel,
64 * we can convert to the destination format and just XFillRectangle.
65 */
66 m = Simplesrc|Simplemask|Fullmask;
67 if((state&m) == m){
68 _xfillcolor(dst, r, par->sdval);
69 // xdirtyxdata(dst, r);
70 return 1;
71 }
73 /*
74 * If no source alpha and an opaque mask, we can just copy
75 * the source onto the destination. If the channels are the
76 * same and the source is not replicated, XCopyArea works.
77 */
78 m = Simplemask|Fullmask;
79 if((state&(m|Replsrc))==m && src->chan==dst->chan && src->X){
80 xdst = dst->X;
81 xsrc = src->X;
82 dp = subpt(r.min, dst->r.min);
83 sp = subpt(par->sr.min, src->r.min);
84 gc = dst->chan==GREY1 ? _x.gccopy0 : _x.gccopy;
86 XCopyArea(_x.display, xsrc->pixmap, xdst->pixmap, gc,
87 sp.x, sp.y, Dx(r), Dy(r), dp.x, dp.y);
88 // xdirtyxdata(dst, r);
89 return 1;
90 }
92 /*
93 * If no source alpha, a 1-bit mask, and a simple source,
94 * we can copy through the mask onto the destination.
95 */
96 if(dst->X && mask->X && !(mask->flags&Frepl)
97 && mask->chan==GREY1 && (state&Simplesrc)){
98 xdst = dst->X;
99 xmask = mask->X;
100 sdval = par->sdval;
102 dp = subpt(r.min, dst->r.min);
103 mp = subpt(r.min, subpt(par->mr.min, mask->r.min));
105 if(dst->chan == GREY1){
106 gc = _x.gcsimplesrc0;
107 if(_x.gcsimplesrc0color != sdval){
108 XSetForeground(_x.display, gc, sdval);
109 _x.gcsimplesrc0color = sdval;
111 if(_x.gcsimplesrc0pixmap != xmask->pixmap){
112 XSetStipple(_x.display, gc, xmask->pixmap);
113 _x.gcsimplesrc0pixmap = xmask->pixmap;
115 }else{
116 /* this doesn't work on rob's mac? */
117 return 0;
118 /* gc = _x.gcsimplesrc;
119 if(dst->chan == CMAP8 && _x.usetable)
120 sdval = _x.tox11[sdval];
122 if(_x.gcsimplesrccolor != sdval){
123 XSetForeground(_x.display, gc, sdval);
124 _x.gcsimplesrccolor = sdval;
126 if(_x.gcsimplesrcpixmap != xmask->pixmap){
127 XSetStipple(_x.display, gc, xmask->pixmap);
128 _x.gcsimplesrcpixmap = xmask->pixmap;
130 */
132 XSetTSOrigin(_x.display, gc, mp.x, mp.y);
133 XFillRectangle(_x.display, xdst->pixmap, gc, dp.x, dp.y,
134 Dx(r), Dy(r));
135 // xdirtyxdata(dst, r);
136 return 1;
139 /*
140 * Can't accelerate.
141 */
142 return 0;