1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright © 2014 Keith Packard
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission to use, copy, modify, distribute, and sell this software and its
5*4882a593Smuzhiyun * documentation for any purpose is hereby granted without fee, provided that
6*4882a593Smuzhiyun * the above copyright notice appear in all copies and that both that copyright
7*4882a593Smuzhiyun * notice and this permission notice appear in supporting documentation, and
8*4882a593Smuzhiyun * that the name of the copyright holders not be used in advertising or
9*4882a593Smuzhiyun * publicity pertaining to distribution of the software without specific,
10*4882a593Smuzhiyun * written prior permission. The copyright holders make no representations
11*4882a593Smuzhiyun * about the suitability of this software for any purpose. It is provided "as
12*4882a593Smuzhiyun * is" without express or implied warranty.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15*4882a593Smuzhiyun * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16*4882a593Smuzhiyun * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17*4882a593Smuzhiyun * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18*4882a593Smuzhiyun * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19*4882a593Smuzhiyun * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20*4882a593Smuzhiyun * OF THIS SOFTWARE.
21*4882a593Smuzhiyun */
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #include "glamor_priv.h"
24*4882a593Smuzhiyun #include "glamor_transfer.h"
25*4882a593Smuzhiyun #include "glamor_prepare.h"
26*4882a593Smuzhiyun #include "glamor_transform.h"
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun struct copy_args {
29*4882a593Smuzhiyun PixmapPtr src_pixmap;
30*4882a593Smuzhiyun glamor_pixmap_fbo *src;
31*4882a593Smuzhiyun uint32_t bitplane;
32*4882a593Smuzhiyun int dx, dy;
33*4882a593Smuzhiyun };
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun static Bool
use_copyarea(PixmapPtr dst,GCPtr gc,glamor_program * prog,void * arg)36*4882a593Smuzhiyun use_copyarea(PixmapPtr dst, GCPtr gc, glamor_program *prog, void *arg)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun struct copy_args *args = arg;
39*4882a593Smuzhiyun glamor_pixmap_fbo *src = args->src;
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun glamor_bind_texture(glamor_get_screen_private(dst->drawable.pScreen),
42*4882a593Smuzhiyun GL_TEXTURE0, src, TRUE);
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun glUniform2f(prog->fill_offset_uniform, args->dx, args->dy);
45*4882a593Smuzhiyun glUniform2f(prog->fill_size_inv_uniform, 1.0f/src->width, 1.0f/src->height);
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun return TRUE;
48*4882a593Smuzhiyun }
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun static const glamor_facet glamor_facet_copyarea = {
51*4882a593Smuzhiyun "copy_area",
52*4882a593Smuzhiyun .vs_vars = "attribute vec2 primitive;\n",
53*4882a593Smuzhiyun .vs_exec = (GLAMOR_POS(gl_Position, primitive.xy)
54*4882a593Smuzhiyun " fill_pos = (fill_offset + primitive.xy) * fill_size_inv;\n"),
55*4882a593Smuzhiyun .fs_exec = " gl_FragColor = texture2D(sampler, fill_pos);\n",
56*4882a593Smuzhiyun .locations = glamor_program_location_fillsamp | glamor_program_location_fillpos,
57*4882a593Smuzhiyun .use = use_copyarea,
58*4882a593Smuzhiyun };
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun /*
61*4882a593Smuzhiyun * Configure the copy plane program for the current operation
62*4882a593Smuzhiyun */
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun static Bool
use_copyplane(PixmapPtr dst,GCPtr gc,glamor_program * prog,void * arg)65*4882a593Smuzhiyun use_copyplane(PixmapPtr dst, GCPtr gc, glamor_program *prog, void *arg)
66*4882a593Smuzhiyun {
67*4882a593Smuzhiyun struct copy_args *args = arg;
68*4882a593Smuzhiyun glamor_pixmap_fbo *src = args->src;
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun glamor_bind_texture(glamor_get_screen_private(dst->drawable.pScreen),
71*4882a593Smuzhiyun GL_TEXTURE0, src, TRUE);
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun glUniform2f(prog->fill_offset_uniform, args->dx, args->dy);
74*4882a593Smuzhiyun glUniform2f(prog->fill_size_inv_uniform, 1.0f/src->width, 1.0f/src->height);
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun glamor_set_color(dst, gc->fgPixel, prog->fg_uniform);
77*4882a593Smuzhiyun glamor_set_color(dst, gc->bgPixel, prog->bg_uniform);
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun /* XXX handle 2 10 10 10 and 1555 formats; presumably the pixmap private knows this? */
80*4882a593Smuzhiyun switch (args->src_pixmap->drawable.depth) {
81*4882a593Smuzhiyun case 30:
82*4882a593Smuzhiyun glUniform4ui(prog->bitplane_uniform,
83*4882a593Smuzhiyun (args->bitplane >> 20) & 0x3ff,
84*4882a593Smuzhiyun (args->bitplane >> 10) & 0x3ff,
85*4882a593Smuzhiyun (args->bitplane ) & 0x3ff,
86*4882a593Smuzhiyun 0);
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun glUniform4f(prog->bitmul_uniform, 0x3ff, 0x3ff, 0x3ff, 0);
89*4882a593Smuzhiyun break;
90*4882a593Smuzhiyun case 24:
91*4882a593Smuzhiyun glUniform4ui(prog->bitplane_uniform,
92*4882a593Smuzhiyun (args->bitplane >> 16) & 0xff,
93*4882a593Smuzhiyun (args->bitplane >> 8) & 0xff,
94*4882a593Smuzhiyun (args->bitplane ) & 0xff,
95*4882a593Smuzhiyun 0);
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun glUniform4f(prog->bitmul_uniform, 0xff, 0xff, 0xff, 0);
98*4882a593Smuzhiyun break;
99*4882a593Smuzhiyun case 32:
100*4882a593Smuzhiyun glUniform4ui(prog->bitplane_uniform,
101*4882a593Smuzhiyun (args->bitplane >> 16) & 0xff,
102*4882a593Smuzhiyun (args->bitplane >> 8) & 0xff,
103*4882a593Smuzhiyun (args->bitplane ) & 0xff,
104*4882a593Smuzhiyun (args->bitplane >> 24) & 0xff);
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun glUniform4f(prog->bitmul_uniform, 0xff, 0xff, 0xff, 0xff);
107*4882a593Smuzhiyun break;
108*4882a593Smuzhiyun case 16:
109*4882a593Smuzhiyun glUniform4ui(prog->bitplane_uniform,
110*4882a593Smuzhiyun (args->bitplane >> 11) & 0x1f,
111*4882a593Smuzhiyun (args->bitplane >> 5) & 0x3f,
112*4882a593Smuzhiyun (args->bitplane ) & 0x1f,
113*4882a593Smuzhiyun 0);
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun glUniform4f(prog->bitmul_uniform, 0x1f, 0x3f, 0x1f, 0);
116*4882a593Smuzhiyun break;
117*4882a593Smuzhiyun case 15:
118*4882a593Smuzhiyun glUniform4ui(prog->bitplane_uniform,
119*4882a593Smuzhiyun (args->bitplane >> 10) & 0x1f,
120*4882a593Smuzhiyun (args->bitplane >> 5) & 0x1f,
121*4882a593Smuzhiyun (args->bitplane ) & 0x1f,
122*4882a593Smuzhiyun 0);
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun glUniform4f(prog->bitmul_uniform, 0x1f, 0x1f, 0x1f, 0);
125*4882a593Smuzhiyun break;
126*4882a593Smuzhiyun case 8:
127*4882a593Smuzhiyun glUniform4ui(prog->bitplane_uniform,
128*4882a593Smuzhiyun 0, 0, 0, args->bitplane);
129*4882a593Smuzhiyun glUniform4f(prog->bitmul_uniform, 0, 0, 0, 0xff);
130*4882a593Smuzhiyun break;
131*4882a593Smuzhiyun case 1:
132*4882a593Smuzhiyun glUniform4ui(prog->bitplane_uniform,
133*4882a593Smuzhiyun 0, 0, 0, args->bitplane);
134*4882a593Smuzhiyun glUniform4f(prog->bitmul_uniform, 0, 0, 0, 0xff);
135*4882a593Smuzhiyun break;
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun return TRUE;
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun static const glamor_facet glamor_facet_copyplane = {
142*4882a593Smuzhiyun "copy_plane",
143*4882a593Smuzhiyun .version = 130,
144*4882a593Smuzhiyun .vs_vars = "attribute vec2 primitive;\n",
145*4882a593Smuzhiyun .vs_exec = (GLAMOR_POS(gl_Position, (primitive.xy))
146*4882a593Smuzhiyun " fill_pos = (fill_offset + primitive.xy) * fill_size_inv;\n"),
147*4882a593Smuzhiyun .fs_exec = (" uvec4 bits = uvec4(round(texture2D(sampler, fill_pos) * bitmul));\n"
148*4882a593Smuzhiyun " if ((bits & bitplane) != uvec4(0,0,0,0))\n"
149*4882a593Smuzhiyun " gl_FragColor = fg;\n"
150*4882a593Smuzhiyun " else\n"
151*4882a593Smuzhiyun " gl_FragColor = bg;\n"),
152*4882a593Smuzhiyun .locations = glamor_program_location_fillsamp|glamor_program_location_fillpos|glamor_program_location_fg|glamor_program_location_bg|glamor_program_location_bitplane,
153*4882a593Smuzhiyun .use = use_copyplane,
154*4882a593Smuzhiyun };
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun /*
157*4882a593Smuzhiyun * When all else fails, pull the bits out of the GPU and do the
158*4882a593Smuzhiyun * operation with fb
159*4882a593Smuzhiyun */
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun static void
glamor_copy_bail(DrawablePtr src,DrawablePtr dst,GCPtr gc,BoxPtr box,int nbox,int dx,int dy,Bool reverse,Bool upsidedown,Pixel bitplane,void * closure)162*4882a593Smuzhiyun glamor_copy_bail(DrawablePtr src,
163*4882a593Smuzhiyun DrawablePtr dst,
164*4882a593Smuzhiyun GCPtr gc,
165*4882a593Smuzhiyun BoxPtr box,
166*4882a593Smuzhiyun int nbox,
167*4882a593Smuzhiyun int dx,
168*4882a593Smuzhiyun int dy,
169*4882a593Smuzhiyun Bool reverse,
170*4882a593Smuzhiyun Bool upsidedown,
171*4882a593Smuzhiyun Pixel bitplane,
172*4882a593Smuzhiyun void *closure)
173*4882a593Smuzhiyun {
174*4882a593Smuzhiyun if (glamor_prepare_access(dst, GLAMOR_ACCESS_RW) && glamor_prepare_access(src, GLAMOR_ACCESS_RO)) {
175*4882a593Smuzhiyun if (bitplane) {
176*4882a593Smuzhiyun if (src->bitsPerPixel > 1)
177*4882a593Smuzhiyun fbCopyNto1(src, dst, gc, box, nbox, dx, dy,
178*4882a593Smuzhiyun reverse, upsidedown, bitplane, closure);
179*4882a593Smuzhiyun else
180*4882a593Smuzhiyun fbCopy1toN(src, dst, gc, box, nbox, dx, dy,
181*4882a593Smuzhiyun reverse, upsidedown, bitplane, closure);
182*4882a593Smuzhiyun } else {
183*4882a593Smuzhiyun fbCopyNtoN(src, dst, gc, box, nbox, dx, dy,
184*4882a593Smuzhiyun reverse, upsidedown, bitplane, closure);
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun glamor_finish_access(dst);
188*4882a593Smuzhiyun glamor_finish_access(src);
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun /**
192*4882a593Smuzhiyun * Implements CopyPlane and CopyArea from the CPU to the GPU by using
193*4882a593Smuzhiyun * the source as a texture and painting that into the destination.
194*4882a593Smuzhiyun *
195*4882a593Smuzhiyun * This requires that source and dest are different textures, or that
196*4882a593Smuzhiyun * (if the copy area doesn't overlap), GL_NV_texture_barrier is used
197*4882a593Smuzhiyun * to ensure that the caches are flushed at the right times.
198*4882a593Smuzhiyun */
199*4882a593Smuzhiyun static Bool
glamor_copy_cpu_fbo(DrawablePtr src,DrawablePtr dst,GCPtr gc,BoxPtr box,int nbox,int dx,int dy,Bool reverse,Bool upsidedown,Pixel bitplane,void * closure)200*4882a593Smuzhiyun glamor_copy_cpu_fbo(DrawablePtr src,
201*4882a593Smuzhiyun DrawablePtr dst,
202*4882a593Smuzhiyun GCPtr gc,
203*4882a593Smuzhiyun BoxPtr box,
204*4882a593Smuzhiyun int nbox,
205*4882a593Smuzhiyun int dx,
206*4882a593Smuzhiyun int dy,
207*4882a593Smuzhiyun Bool reverse,
208*4882a593Smuzhiyun Bool upsidedown,
209*4882a593Smuzhiyun Pixel bitplane,
210*4882a593Smuzhiyun void *closure)
211*4882a593Smuzhiyun {
212*4882a593Smuzhiyun ScreenPtr screen = dst->pScreen;
213*4882a593Smuzhiyun glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
214*4882a593Smuzhiyun PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
215*4882a593Smuzhiyun int dst_xoff, dst_yoff;
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun if (gc && gc->alu != GXcopy)
218*4882a593Smuzhiyun goto bail;
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun if (gc && !glamor_pm_is_solid(gc->depth, gc->planemask))
221*4882a593Smuzhiyun goto bail;
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun glamor_make_current(glamor_priv);
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun if (!glamor_prepare_access(src, GLAMOR_ACCESS_RO))
226*4882a593Smuzhiyun goto bail;
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun glamor_get_drawable_deltas(dst, dst_pixmap, &dst_xoff, &dst_yoff);
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun if (bitplane) {
231*4882a593Smuzhiyun FbBits *tmp_bits;
232*4882a593Smuzhiyun FbStride tmp_stride;
233*4882a593Smuzhiyun int tmp_bpp;
234*4882a593Smuzhiyun int tmp_xoff, tmp_yoff;
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun PixmapPtr tmp_pix = fbCreatePixmap(screen, dst_pixmap->drawable.width,
237*4882a593Smuzhiyun dst_pixmap->drawable.height,
238*4882a593Smuzhiyun dst->depth, 0);
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun if (!tmp_pix) {
241*4882a593Smuzhiyun glamor_finish_access(src);
242*4882a593Smuzhiyun goto bail;
243*4882a593Smuzhiyun }
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun tmp_pix->drawable.x = dst_xoff;
246*4882a593Smuzhiyun tmp_pix->drawable.y = dst_yoff;
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun fbGetDrawable(&tmp_pix->drawable, tmp_bits, tmp_stride, tmp_bpp, tmp_xoff,
249*4882a593Smuzhiyun tmp_yoff);
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun if (src->bitsPerPixel > 1)
252*4882a593Smuzhiyun fbCopyNto1(src, &tmp_pix->drawable, gc, box, nbox, dx, dy,
253*4882a593Smuzhiyun reverse, upsidedown, bitplane, closure);
254*4882a593Smuzhiyun else
255*4882a593Smuzhiyun fbCopy1toN(src, &tmp_pix->drawable, gc, box, nbox, dx, dy,
256*4882a593Smuzhiyun reverse, upsidedown, bitplane, closure);
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun glamor_upload_boxes(dst_pixmap, box, nbox, tmp_xoff, tmp_yoff,
259*4882a593Smuzhiyun dst_xoff, dst_yoff, (uint8_t *) tmp_bits,
260*4882a593Smuzhiyun tmp_stride * sizeof(FbBits));
261*4882a593Smuzhiyun fbDestroyPixmap(tmp_pix);
262*4882a593Smuzhiyun } else {
263*4882a593Smuzhiyun FbBits *src_bits;
264*4882a593Smuzhiyun FbStride src_stride;
265*4882a593Smuzhiyun int src_bpp;
266*4882a593Smuzhiyun int src_xoff, src_yoff;
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun fbGetDrawable(src, src_bits, src_stride, src_bpp, src_xoff, src_yoff);
269*4882a593Smuzhiyun glamor_upload_boxes(dst_pixmap, box, nbox, src_xoff + dx, src_yoff + dy,
270*4882a593Smuzhiyun dst_xoff, dst_yoff,
271*4882a593Smuzhiyun (uint8_t *) src_bits, src_stride * sizeof (FbBits));
272*4882a593Smuzhiyun }
273*4882a593Smuzhiyun glamor_finish_access(src);
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun return TRUE;
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun bail:
278*4882a593Smuzhiyun return FALSE;
279*4882a593Smuzhiyun }
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun /**
282*4882a593Smuzhiyun * Implements CopyArea from the GPU to the CPU using glReadPixels from the
283*4882a593Smuzhiyun * source FBO.
284*4882a593Smuzhiyun */
285*4882a593Smuzhiyun static Bool
glamor_copy_fbo_cpu(DrawablePtr src,DrawablePtr dst,GCPtr gc,BoxPtr box,int nbox,int dx,int dy,Bool reverse,Bool upsidedown,Pixel bitplane,void * closure)286*4882a593Smuzhiyun glamor_copy_fbo_cpu(DrawablePtr src,
287*4882a593Smuzhiyun DrawablePtr dst,
288*4882a593Smuzhiyun GCPtr gc,
289*4882a593Smuzhiyun BoxPtr box,
290*4882a593Smuzhiyun int nbox,
291*4882a593Smuzhiyun int dx,
292*4882a593Smuzhiyun int dy,
293*4882a593Smuzhiyun Bool reverse,
294*4882a593Smuzhiyun Bool upsidedown,
295*4882a593Smuzhiyun Pixel bitplane,
296*4882a593Smuzhiyun void *closure)
297*4882a593Smuzhiyun {
298*4882a593Smuzhiyun ScreenPtr screen = dst->pScreen;
299*4882a593Smuzhiyun glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
300*4882a593Smuzhiyun PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
301*4882a593Smuzhiyun FbBits *dst_bits;
302*4882a593Smuzhiyun FbStride dst_stride;
303*4882a593Smuzhiyun int dst_bpp;
304*4882a593Smuzhiyun int src_xoff, src_yoff;
305*4882a593Smuzhiyun int dst_xoff, dst_yoff;
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun if (gc && gc->alu != GXcopy)
308*4882a593Smuzhiyun goto bail;
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun if (gc && !glamor_pm_is_solid(gc->depth, gc->planemask))
311*4882a593Smuzhiyun goto bail;
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun glamor_make_current(glamor_priv);
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun if (!glamor_prepare_access(dst, GLAMOR_ACCESS_RW))
316*4882a593Smuzhiyun goto bail;
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun glamor_get_drawable_deltas(src, src_pixmap, &src_xoff, &src_yoff);
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun fbGetDrawable(dst, dst_bits, dst_stride, dst_bpp, dst_xoff, dst_yoff);
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun glamor_download_boxes(src_pixmap, box, nbox, src_xoff + dx, src_yoff + dy,
323*4882a593Smuzhiyun dst_xoff, dst_yoff,
324*4882a593Smuzhiyun (uint8_t *) dst_bits, dst_stride * sizeof (FbBits));
325*4882a593Smuzhiyun glamor_finish_access(dst);
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun return TRUE;
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun bail:
330*4882a593Smuzhiyun return FALSE;
331*4882a593Smuzhiyun }
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun /* Include the enums here for the moment, to keep from needing to bump epoxy. */
334*4882a593Smuzhiyun #ifndef GL_TILE_RASTER_ORDER_FIXED_MESA
335*4882a593Smuzhiyun #define GL_TILE_RASTER_ORDER_FIXED_MESA 0x8BB8
336*4882a593Smuzhiyun #define GL_TILE_RASTER_ORDER_INCREASING_X_MESA 0x8BB9
337*4882a593Smuzhiyun #define GL_TILE_RASTER_ORDER_INCREASING_Y_MESA 0x8BBA
338*4882a593Smuzhiyun #endif
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun /*
341*4882a593Smuzhiyun * Copy from GPU to GPU by using the source
342*4882a593Smuzhiyun * as a texture and painting that into the destination
343*4882a593Smuzhiyun */
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun static Bool
glamor_copy_fbo_fbo_draw(DrawablePtr src,DrawablePtr dst,GCPtr gc,BoxPtr box,int nbox,int dx,int dy,Bool reverse,Bool upsidedown,Pixel bitplane,void * closure)346*4882a593Smuzhiyun glamor_copy_fbo_fbo_draw(DrawablePtr src,
347*4882a593Smuzhiyun DrawablePtr dst,
348*4882a593Smuzhiyun GCPtr gc,
349*4882a593Smuzhiyun BoxPtr box,
350*4882a593Smuzhiyun int nbox,
351*4882a593Smuzhiyun int dx,
352*4882a593Smuzhiyun int dy,
353*4882a593Smuzhiyun Bool reverse,
354*4882a593Smuzhiyun Bool upsidedown,
355*4882a593Smuzhiyun Pixel bitplane,
356*4882a593Smuzhiyun void *closure)
357*4882a593Smuzhiyun {
358*4882a593Smuzhiyun ScreenPtr screen = dst->pScreen;
359*4882a593Smuzhiyun glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
360*4882a593Smuzhiyun PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
361*4882a593Smuzhiyun PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
362*4882a593Smuzhiyun glamor_pixmap_private *src_priv = glamor_get_pixmap_private(src_pixmap);
363*4882a593Smuzhiyun glamor_pixmap_private *dst_priv = glamor_get_pixmap_private(dst_pixmap);
364*4882a593Smuzhiyun int src_box_index, dst_box_index;
365*4882a593Smuzhiyun int dst_off_x, dst_off_y;
366*4882a593Smuzhiyun int src_off_x, src_off_y;
367*4882a593Smuzhiyun GLshort *v;
368*4882a593Smuzhiyun char *vbo_offset;
369*4882a593Smuzhiyun struct copy_args args;
370*4882a593Smuzhiyun glamor_program *prog;
371*4882a593Smuzhiyun const glamor_facet *copy_facet;
372*4882a593Smuzhiyun int n;
373*4882a593Smuzhiyun Bool ret = FALSE;
374*4882a593Smuzhiyun BoxRec bounds = glamor_no_rendering_bounds();
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun glamor_make_current(glamor_priv);
377*4882a593Smuzhiyun
378*4882a593Smuzhiyun if (gc && !glamor_set_planemask(gc->depth, gc->planemask))
379*4882a593Smuzhiyun goto bail_ctx;
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun if (!glamor_set_alu(screen, gc ? gc->alu : GXcopy))
382*4882a593Smuzhiyun goto bail_ctx;
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun if (bitplane && !glamor_priv->can_copyplane)
385*4882a593Smuzhiyun goto bail_ctx;
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun if (bitplane) {
388*4882a593Smuzhiyun prog = &glamor_priv->copy_plane_prog;
389*4882a593Smuzhiyun copy_facet = &glamor_facet_copyplane;
390*4882a593Smuzhiyun } else {
391*4882a593Smuzhiyun prog = &glamor_priv->copy_area_prog;
392*4882a593Smuzhiyun copy_facet = &glamor_facet_copyarea;
393*4882a593Smuzhiyun }
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun if (prog->failed)
396*4882a593Smuzhiyun goto bail_ctx;
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun if (!prog->prog) {
399*4882a593Smuzhiyun if (!glamor_build_program(screen, prog,
400*4882a593Smuzhiyun copy_facet, NULL, NULL, NULL))
401*4882a593Smuzhiyun goto bail_ctx;
402*4882a593Smuzhiyun }
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun args.src_pixmap = src_pixmap;
405*4882a593Smuzhiyun args.bitplane = bitplane;
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun /* Set up the vertex buffers for the points */
408*4882a593Smuzhiyun
409*4882a593Smuzhiyun v = glamor_get_vbo_space(dst->pScreen, nbox * 8 * sizeof (int16_t), &vbo_offset);
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun if (src_pixmap == dst_pixmap && glamor_priv->has_mesa_tile_raster_order) {
412*4882a593Smuzhiyun glEnable(GL_TILE_RASTER_ORDER_FIXED_MESA);
413*4882a593Smuzhiyun if (dx >= 0)
414*4882a593Smuzhiyun glEnable(GL_TILE_RASTER_ORDER_INCREASING_X_MESA);
415*4882a593Smuzhiyun else
416*4882a593Smuzhiyun glDisable(GL_TILE_RASTER_ORDER_INCREASING_X_MESA);
417*4882a593Smuzhiyun if (dy >= 0)
418*4882a593Smuzhiyun glEnable(GL_TILE_RASTER_ORDER_INCREASING_Y_MESA);
419*4882a593Smuzhiyun else
420*4882a593Smuzhiyun glDisable(GL_TILE_RASTER_ORDER_INCREASING_Y_MESA);
421*4882a593Smuzhiyun }
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
424*4882a593Smuzhiyun glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT, GL_FALSE,
425*4882a593Smuzhiyun 2 * sizeof (GLshort), vbo_offset);
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun if (nbox < 100) {
428*4882a593Smuzhiyun bounds = glamor_start_rendering_bounds();
429*4882a593Smuzhiyun for (int i = 0; i < nbox; i++)
430*4882a593Smuzhiyun glamor_bounds_union_box(&bounds, &box[i]);
431*4882a593Smuzhiyun }
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun for (n = 0; n < nbox; n++) {
434*4882a593Smuzhiyun v[0] = box->x1; v[1] = box->y1;
435*4882a593Smuzhiyun v[2] = box->x1; v[3] = box->y2;
436*4882a593Smuzhiyun v[4] = box->x2; v[5] = box->y2;
437*4882a593Smuzhiyun v[6] = box->x2; v[7] = box->y1;
438*4882a593Smuzhiyun
439*4882a593Smuzhiyun v += 8;
440*4882a593Smuzhiyun box++;
441*4882a593Smuzhiyun }
442*4882a593Smuzhiyun
443*4882a593Smuzhiyun glamor_put_vbo_space(screen);
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun glamor_get_drawable_deltas(src, src_pixmap, &src_off_x, &src_off_y);
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun glEnable(GL_SCISSOR_TEST);
448*4882a593Smuzhiyun
449*4882a593Smuzhiyun glamor_pixmap_loop(src_priv, src_box_index) {
450*4882a593Smuzhiyun BoxPtr src_box = glamor_pixmap_box_at(src_priv, src_box_index);
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun args.dx = dx + src_off_x - src_box->x1;
453*4882a593Smuzhiyun args.dy = dy + src_off_y - src_box->y1;
454*4882a593Smuzhiyun args.src = glamor_pixmap_fbo_at(src_priv, src_box_index);
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun if (!glamor_use_program(dst_pixmap, gc, prog, &args))
457*4882a593Smuzhiyun goto bail_ctx;
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun glamor_pixmap_loop(dst_priv, dst_box_index) {
460*4882a593Smuzhiyun BoxRec scissor = {
461*4882a593Smuzhiyun .x1 = max(-args.dx, bounds.x1),
462*4882a593Smuzhiyun .y1 = max(-args.dy, bounds.y1),
463*4882a593Smuzhiyun .x2 = min(-args.dx + src_box->x2 - src_box->x1, bounds.x2),
464*4882a593Smuzhiyun .y2 = min(-args.dy + src_box->y2 - src_box->y1, bounds.y2),
465*4882a593Smuzhiyun };
466*4882a593Smuzhiyun if (scissor.x1 >= scissor.x2 || scissor.y1 >= scissor.y2)
467*4882a593Smuzhiyun continue;
468*4882a593Smuzhiyun
469*4882a593Smuzhiyun if (!glamor_set_destination_drawable(dst, dst_box_index, FALSE, FALSE,
470*4882a593Smuzhiyun prog->matrix_uniform,
471*4882a593Smuzhiyun &dst_off_x, &dst_off_y))
472*4882a593Smuzhiyun goto bail_ctx;
473*4882a593Smuzhiyun
474*4882a593Smuzhiyun glScissor(scissor.x1 + dst_off_x,
475*4882a593Smuzhiyun scissor.y1 + dst_off_y,
476*4882a593Smuzhiyun scissor.x2 - scissor.x1,
477*4882a593Smuzhiyun scissor.y2 - scissor.y1);
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun glamor_glDrawArrays_GL_QUADS(glamor_priv, nbox);
480*4882a593Smuzhiyun }
481*4882a593Smuzhiyun }
482*4882a593Smuzhiyun
483*4882a593Smuzhiyun glamor_pixmap_invalid(dst_pixmap);
484*4882a593Smuzhiyun
485*4882a593Smuzhiyun ret = TRUE;
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun bail_ctx:
488*4882a593Smuzhiyun if (src_pixmap == dst_pixmap && glamor_priv->has_mesa_tile_raster_order) {
489*4882a593Smuzhiyun glDisable(GL_TILE_RASTER_ORDER_FIXED_MESA);
490*4882a593Smuzhiyun }
491*4882a593Smuzhiyun glDisable(GL_SCISSOR_TEST);
492*4882a593Smuzhiyun glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun return ret;
495*4882a593Smuzhiyun }
496*4882a593Smuzhiyun
497*4882a593Smuzhiyun /**
498*4882a593Smuzhiyun * Copies from the GPU to the GPU using a temporary pixmap in between,
499*4882a593Smuzhiyun * to correctly handle overlapping copies.
500*4882a593Smuzhiyun */
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun static Bool
glamor_copy_fbo_fbo_temp(DrawablePtr src,DrawablePtr dst,GCPtr gc,BoxPtr box,int nbox,int dx,int dy,Bool reverse,Bool upsidedown,Pixel bitplane,void * closure)503*4882a593Smuzhiyun glamor_copy_fbo_fbo_temp(DrawablePtr src,
504*4882a593Smuzhiyun DrawablePtr dst,
505*4882a593Smuzhiyun GCPtr gc,
506*4882a593Smuzhiyun BoxPtr box,
507*4882a593Smuzhiyun int nbox,
508*4882a593Smuzhiyun int dx,
509*4882a593Smuzhiyun int dy,
510*4882a593Smuzhiyun Bool reverse,
511*4882a593Smuzhiyun Bool upsidedown,
512*4882a593Smuzhiyun Pixel bitplane,
513*4882a593Smuzhiyun void *closure)
514*4882a593Smuzhiyun {
515*4882a593Smuzhiyun ScreenPtr screen = dst->pScreen;
516*4882a593Smuzhiyun glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
517*4882a593Smuzhiyun PixmapPtr tmp_pixmap;
518*4882a593Smuzhiyun BoxRec bounds;
519*4882a593Smuzhiyun int n;
520*4882a593Smuzhiyun BoxPtr tmp_box;
521*4882a593Smuzhiyun
522*4882a593Smuzhiyun if (nbox == 0)
523*4882a593Smuzhiyun return TRUE;
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun /* Sanity check state to avoid getting halfway through and bailing
526*4882a593Smuzhiyun * at the last second. Might be nice to have checks that didn't
527*4882a593Smuzhiyun * involve setting state.
528*4882a593Smuzhiyun */
529*4882a593Smuzhiyun glamor_make_current(glamor_priv);
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun if (gc && !glamor_set_planemask(gc->depth, gc->planemask))
532*4882a593Smuzhiyun goto bail_ctx;
533*4882a593Smuzhiyun
534*4882a593Smuzhiyun if (!glamor_set_alu(screen, gc ? gc->alu : GXcopy))
535*4882a593Smuzhiyun goto bail_ctx;
536*4882a593Smuzhiyun
537*4882a593Smuzhiyun /* Find the size of the area to copy
538*4882a593Smuzhiyun */
539*4882a593Smuzhiyun bounds = box[0];
540*4882a593Smuzhiyun for (n = 1; n < nbox; n++) {
541*4882a593Smuzhiyun bounds.x1 = min(bounds.x1, box[n].x1);
542*4882a593Smuzhiyun bounds.x2 = max(bounds.x2, box[n].x2);
543*4882a593Smuzhiyun bounds.y1 = min(bounds.y1, box[n].y1);
544*4882a593Smuzhiyun bounds.y2 = max(bounds.y2, box[n].y2);
545*4882a593Smuzhiyun }
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun /* Allocate a suitable temporary pixmap
548*4882a593Smuzhiyun */
549*4882a593Smuzhiyun tmp_pixmap = glamor_create_pixmap(screen,
550*4882a593Smuzhiyun bounds.x2 - bounds.x1,
551*4882a593Smuzhiyun bounds.y2 - bounds.y1,
552*4882a593Smuzhiyun src->depth, 0);
553*4882a593Smuzhiyun if (!tmp_pixmap)
554*4882a593Smuzhiyun goto bail;
555*4882a593Smuzhiyun
556*4882a593Smuzhiyun tmp_box = calloc(nbox, sizeof (BoxRec));
557*4882a593Smuzhiyun if (!tmp_box)
558*4882a593Smuzhiyun goto bail_pixmap;
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun /* Convert destination boxes into tmp pixmap boxes
561*4882a593Smuzhiyun */
562*4882a593Smuzhiyun for (n = 0; n < nbox; n++) {
563*4882a593Smuzhiyun tmp_box[n].x1 = box[n].x1 - bounds.x1;
564*4882a593Smuzhiyun tmp_box[n].x2 = box[n].x2 - bounds.x1;
565*4882a593Smuzhiyun tmp_box[n].y1 = box[n].y1 - bounds.y1;
566*4882a593Smuzhiyun tmp_box[n].y2 = box[n].y2 - bounds.y1;
567*4882a593Smuzhiyun }
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun if (!glamor_copy_fbo_fbo_draw(src,
570*4882a593Smuzhiyun &tmp_pixmap->drawable,
571*4882a593Smuzhiyun NULL,
572*4882a593Smuzhiyun tmp_box,
573*4882a593Smuzhiyun nbox,
574*4882a593Smuzhiyun dx + bounds.x1,
575*4882a593Smuzhiyun dy + bounds.y1,
576*4882a593Smuzhiyun FALSE, FALSE,
577*4882a593Smuzhiyun 0, NULL))
578*4882a593Smuzhiyun goto bail_box;
579*4882a593Smuzhiyun
580*4882a593Smuzhiyun if (!glamor_copy_fbo_fbo_draw(&tmp_pixmap->drawable,
581*4882a593Smuzhiyun dst,
582*4882a593Smuzhiyun gc,
583*4882a593Smuzhiyun box,
584*4882a593Smuzhiyun nbox,
585*4882a593Smuzhiyun -bounds.x1,
586*4882a593Smuzhiyun -bounds.y1,
587*4882a593Smuzhiyun FALSE, FALSE,
588*4882a593Smuzhiyun bitplane, closure))
589*4882a593Smuzhiyun goto bail_box;
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun free(tmp_box);
592*4882a593Smuzhiyun
593*4882a593Smuzhiyun glamor_destroy_pixmap(tmp_pixmap);
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun return TRUE;
596*4882a593Smuzhiyun bail_box:
597*4882a593Smuzhiyun free(tmp_box);
598*4882a593Smuzhiyun bail_pixmap:
599*4882a593Smuzhiyun glamor_destroy_pixmap(tmp_pixmap);
600*4882a593Smuzhiyun bail:
601*4882a593Smuzhiyun return FALSE;
602*4882a593Smuzhiyun
603*4882a593Smuzhiyun bail_ctx:
604*4882a593Smuzhiyun return FALSE;
605*4882a593Smuzhiyun }
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun /**
608*4882a593Smuzhiyun * Returns TRUE if the copy has to be implemented with
609*4882a593Smuzhiyun * glamor_copy_fbo_fbo_temp() instead of glamor_copy_fbo_fbo().
610*4882a593Smuzhiyun *
611*4882a593Smuzhiyun * If the src and dst are in the same pixmap, then glamor_copy_fbo_fbo()'s
612*4882a593Smuzhiyun * sampling would give undefined results (since the same texture would be
613*4882a593Smuzhiyun * bound as an FBO destination and as a texture source). However, if we
614*4882a593Smuzhiyun * have GL_NV_texture_barrier, we can take advantage of the exception it
615*4882a593Smuzhiyun * added:
616*4882a593Smuzhiyun *
617*4882a593Smuzhiyun * "- If a texel has been written, then in order to safely read the result
618*4882a593Smuzhiyun * a texel fetch must be in a subsequent Draw separated by the command
619*4882a593Smuzhiyun *
620*4882a593Smuzhiyun * void TextureBarrierNV(void);
621*4882a593Smuzhiyun *
622*4882a593Smuzhiyun * TextureBarrierNV() will guarantee that writes have completed and caches
623*4882a593Smuzhiyun * have been invalidated before subsequent Draws are executed."
624*4882a593Smuzhiyun */
625*4882a593Smuzhiyun static Bool
glamor_copy_needs_temp(DrawablePtr src,DrawablePtr dst,BoxPtr box,int nbox,int dx,int dy)626*4882a593Smuzhiyun glamor_copy_needs_temp(DrawablePtr src,
627*4882a593Smuzhiyun DrawablePtr dst,
628*4882a593Smuzhiyun BoxPtr box,
629*4882a593Smuzhiyun int nbox,
630*4882a593Smuzhiyun int dx,
631*4882a593Smuzhiyun int dy)
632*4882a593Smuzhiyun {
633*4882a593Smuzhiyun PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
634*4882a593Smuzhiyun PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
635*4882a593Smuzhiyun ScreenPtr screen = dst->pScreen;
636*4882a593Smuzhiyun glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
637*4882a593Smuzhiyun int n;
638*4882a593Smuzhiyun int dst_off_x, dst_off_y;
639*4882a593Smuzhiyun int src_off_x, src_off_y;
640*4882a593Smuzhiyun BoxRec bounds;
641*4882a593Smuzhiyun
642*4882a593Smuzhiyun if (src_pixmap != dst_pixmap)
643*4882a593Smuzhiyun return FALSE;
644*4882a593Smuzhiyun
645*4882a593Smuzhiyun if (nbox == 0)
646*4882a593Smuzhiyun return FALSE;
647*4882a593Smuzhiyun
648*4882a593Smuzhiyun if (!glamor_priv->has_nv_texture_barrier)
649*4882a593Smuzhiyun return TRUE;
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun if (!glamor_priv->has_mesa_tile_raster_order) {
652*4882a593Smuzhiyun glamor_get_drawable_deltas(src, src_pixmap, &src_off_x, &src_off_y);
653*4882a593Smuzhiyun glamor_get_drawable_deltas(dst, dst_pixmap, &dst_off_x, &dst_off_y);
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun bounds = box[0];
656*4882a593Smuzhiyun for (n = 1; n < nbox; n++) {
657*4882a593Smuzhiyun bounds.x1 = min(bounds.x1, box[n].x1);
658*4882a593Smuzhiyun bounds.y1 = min(bounds.y1, box[n].y1);
659*4882a593Smuzhiyun
660*4882a593Smuzhiyun bounds.x2 = max(bounds.x2, box[n].x2);
661*4882a593Smuzhiyun bounds.y2 = max(bounds.y2, box[n].y2);
662*4882a593Smuzhiyun }
663*4882a593Smuzhiyun
664*4882a593Smuzhiyun /* Check to see if the pixmap-relative boxes overlap in both X and Y,
665*4882a593Smuzhiyun * in which case we can't rely on NV_texture_barrier and must
666*4882a593Smuzhiyun * make a temporary copy
667*4882a593Smuzhiyun *
668*4882a593Smuzhiyun * dst.x1 < src.x2 &&
669*4882a593Smuzhiyun * src.x1 < dst.x2 &&
670*4882a593Smuzhiyun *
671*4882a593Smuzhiyun * dst.y1 < src.y2 &&
672*4882a593Smuzhiyun * src.y1 < dst.y2
673*4882a593Smuzhiyun */
674*4882a593Smuzhiyun if (bounds.x1 + dst_off_x < bounds.x2 + dx + src_off_x &&
675*4882a593Smuzhiyun bounds.x1 + dx + src_off_x < bounds.x2 + dst_off_x &&
676*4882a593Smuzhiyun
677*4882a593Smuzhiyun bounds.y1 + dst_off_y < bounds.y2 + dy + src_off_y &&
678*4882a593Smuzhiyun bounds.y1 + dy + src_off_y < bounds.y2 + dst_off_y) {
679*4882a593Smuzhiyun return TRUE;
680*4882a593Smuzhiyun }
681*4882a593Smuzhiyun }
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun glTextureBarrierNV();
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun return FALSE;
686*4882a593Smuzhiyun }
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun static Bool
glamor_copy_gl(DrawablePtr src,DrawablePtr dst,GCPtr gc,BoxPtr box,int nbox,int dx,int dy,Bool reverse,Bool upsidedown,Pixel bitplane,void * closure)689*4882a593Smuzhiyun glamor_copy_gl(DrawablePtr src,
690*4882a593Smuzhiyun DrawablePtr dst,
691*4882a593Smuzhiyun GCPtr gc,
692*4882a593Smuzhiyun BoxPtr box,
693*4882a593Smuzhiyun int nbox,
694*4882a593Smuzhiyun int dx,
695*4882a593Smuzhiyun int dy,
696*4882a593Smuzhiyun Bool reverse,
697*4882a593Smuzhiyun Bool upsidedown,
698*4882a593Smuzhiyun Pixel bitplane,
699*4882a593Smuzhiyun void *closure)
700*4882a593Smuzhiyun {
701*4882a593Smuzhiyun PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
702*4882a593Smuzhiyun PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
703*4882a593Smuzhiyun glamor_pixmap_private *src_priv = glamor_get_pixmap_private(src_pixmap);
704*4882a593Smuzhiyun glamor_pixmap_private *dst_priv = glamor_get_pixmap_private(dst_pixmap);
705*4882a593Smuzhiyun
706*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM_MAP
707*4882a593Smuzhiyun /* HACK for freerdp */
708*4882a593Smuzhiyun if (nbox == 1 && (box->x2 - box->x1) == 64 && (box->y2 - box->y1) == 64)
709*4882a593Smuzhiyun return FALSE;
710*4882a593Smuzhiyun #endif
711*4882a593Smuzhiyun
712*4882a593Smuzhiyun if (GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_priv)) {
713*4882a593Smuzhiyun if (GLAMOR_PIXMAP_PRIV_HAS_FBO(src_priv)) {
714*4882a593Smuzhiyun if (glamor_copy_needs_temp(src, dst, box, nbox, dx, dy))
715*4882a593Smuzhiyun return glamor_copy_fbo_fbo_temp(src, dst, gc, box, nbox, dx, dy,
716*4882a593Smuzhiyun reverse, upsidedown, bitplane, closure);
717*4882a593Smuzhiyun else
718*4882a593Smuzhiyun return glamor_copy_fbo_fbo_draw(src, dst, gc, box, nbox, dx, dy,
719*4882a593Smuzhiyun reverse, upsidedown, bitplane, closure);
720*4882a593Smuzhiyun }
721*4882a593Smuzhiyun
722*4882a593Smuzhiyun return glamor_copy_cpu_fbo(src, dst, gc, box, nbox, dx, dy,
723*4882a593Smuzhiyun reverse, upsidedown, bitplane, closure);
724*4882a593Smuzhiyun } else if (GLAMOR_PIXMAP_PRIV_HAS_FBO(src_priv) &&
725*4882a593Smuzhiyun dst_priv->type != GLAMOR_DRM_ONLY &&
726*4882a593Smuzhiyun bitplane == 0) {
727*4882a593Smuzhiyun return glamor_copy_fbo_cpu(src, dst, gc, box, nbox, dx, dy,
728*4882a593Smuzhiyun reverse, upsidedown, bitplane, closure);
729*4882a593Smuzhiyun }
730*4882a593Smuzhiyun return FALSE;
731*4882a593Smuzhiyun }
732*4882a593Smuzhiyun
733*4882a593Smuzhiyun void
glamor_copy(DrawablePtr src,DrawablePtr dst,GCPtr gc,BoxPtr box,int nbox,int dx,int dy,Bool reverse,Bool upsidedown,Pixel bitplane,void * closure)734*4882a593Smuzhiyun glamor_copy(DrawablePtr src,
735*4882a593Smuzhiyun DrawablePtr dst,
736*4882a593Smuzhiyun GCPtr gc,
737*4882a593Smuzhiyun BoxPtr box,
738*4882a593Smuzhiyun int nbox,
739*4882a593Smuzhiyun int dx,
740*4882a593Smuzhiyun int dy,
741*4882a593Smuzhiyun Bool reverse,
742*4882a593Smuzhiyun Bool upsidedown,
743*4882a593Smuzhiyun Pixel bitplane,
744*4882a593Smuzhiyun void *closure)
745*4882a593Smuzhiyun {
746*4882a593Smuzhiyun if (nbox == 0)
747*4882a593Smuzhiyun return;
748*4882a593Smuzhiyun
749*4882a593Smuzhiyun if (GLAMOR_PREFER_GL() &&
750*4882a593Smuzhiyun glamor_copy_gl(src, dst, gc, box, nbox, dx, dy, reverse,
751*4882a593Smuzhiyun upsidedown, bitplane, closure))
752*4882a593Smuzhiyun return;
753*4882a593Smuzhiyun glamor_copy_bail(src, dst, gc, box, nbox, dx, dy, reverse, upsidedown, bitplane, closure);
754*4882a593Smuzhiyun }
755*4882a593Smuzhiyun
756*4882a593Smuzhiyun RegionPtr
glamor_copy_area(DrawablePtr src,DrawablePtr dst,GCPtr gc,int srcx,int srcy,int width,int height,int dstx,int dsty)757*4882a593Smuzhiyun glamor_copy_area(DrawablePtr src, DrawablePtr dst, GCPtr gc,
758*4882a593Smuzhiyun int srcx, int srcy, int width, int height, int dstx, int dsty)
759*4882a593Smuzhiyun {
760*4882a593Smuzhiyun return miDoCopy(src, dst, gc,
761*4882a593Smuzhiyun srcx, srcy, width, height,
762*4882a593Smuzhiyun dstx, dsty, glamor_copy, 0, NULL);
763*4882a593Smuzhiyun }
764*4882a593Smuzhiyun
765*4882a593Smuzhiyun RegionPtr
glamor_copy_plane(DrawablePtr src,DrawablePtr dst,GCPtr gc,int srcx,int srcy,int width,int height,int dstx,int dsty,unsigned long bitplane)766*4882a593Smuzhiyun glamor_copy_plane(DrawablePtr src, DrawablePtr dst, GCPtr gc,
767*4882a593Smuzhiyun int srcx, int srcy, int width, int height, int dstx, int dsty,
768*4882a593Smuzhiyun unsigned long bitplane)
769*4882a593Smuzhiyun {
770*4882a593Smuzhiyun if ((bitplane & FbFullMask(src->depth)) == 0)
771*4882a593Smuzhiyun return miHandleExposures(src, dst, gc,
772*4882a593Smuzhiyun srcx, srcy, width, height, dstx, dsty);
773*4882a593Smuzhiyun return miDoCopy(src, dst, gc,
774*4882a593Smuzhiyun srcx, srcy, width, height,
775*4882a593Smuzhiyun dstx, dsty, glamor_copy, bitplane, NULL);
776*4882a593Smuzhiyun }
777*4882a593Smuzhiyun
778*4882a593Smuzhiyun void
glamor_copy_window(WindowPtr window,DDXPointRec old_origin,RegionPtr src_region)779*4882a593Smuzhiyun glamor_copy_window(WindowPtr window, DDXPointRec old_origin, RegionPtr src_region)
780*4882a593Smuzhiyun {
781*4882a593Smuzhiyun PixmapPtr pixmap = glamor_get_drawable_pixmap(&window->drawable);
782*4882a593Smuzhiyun DrawablePtr drawable = &pixmap->drawable;
783*4882a593Smuzhiyun RegionRec dst_region;
784*4882a593Smuzhiyun int dx, dy;
785*4882a593Smuzhiyun
786*4882a593Smuzhiyun dx = old_origin.x - window->drawable.x;
787*4882a593Smuzhiyun dy = old_origin.y - window->drawable.y;
788*4882a593Smuzhiyun RegionTranslate(src_region, -dx, -dy);
789*4882a593Smuzhiyun
790*4882a593Smuzhiyun RegionNull(&dst_region);
791*4882a593Smuzhiyun
792*4882a593Smuzhiyun RegionIntersect(&dst_region, &window->borderClip, src_region);
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun #ifdef COMPOSITE
795*4882a593Smuzhiyun if (pixmap->screen_x || pixmap->screen_y)
796*4882a593Smuzhiyun RegionTranslate(&dst_region, -pixmap->screen_x, -pixmap->screen_y);
797*4882a593Smuzhiyun #endif
798*4882a593Smuzhiyun
799*4882a593Smuzhiyun miCopyRegion(drawable, drawable,
800*4882a593Smuzhiyun 0, &dst_region, dx, dy, glamor_copy, 0, 0);
801*4882a593Smuzhiyun
802*4882a593Smuzhiyun RegionUninit(&dst_region);
803*4882a593Smuzhiyun }
804