xref: /OK3568_Linux_fs/external/xserver/glamor/glamor_spans.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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_transform.h"
25*4882a593Smuzhiyun #include "glamor_transfer.h"
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun glamor_program  fill_spans_progs[4];
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun static const glamor_facet glamor_facet_fillspans_130 = {
30*4882a593Smuzhiyun     .name = "fill_spans",
31*4882a593Smuzhiyun     .version = 130,
32*4882a593Smuzhiyun     .vs_vars =  "attribute vec3 primitive;\n",
33*4882a593Smuzhiyun     .vs_exec = ("       vec2 pos = vec2(primitive.z,1) * vec2(gl_VertexID&1, (gl_VertexID&2)>>1);\n"
34*4882a593Smuzhiyun                 GLAMOR_POS(gl_Position, (primitive.xy + pos))),
35*4882a593Smuzhiyun };
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun static const glamor_facet glamor_facet_fillspans_120 = {
38*4882a593Smuzhiyun     .name = "fill_spans",
39*4882a593Smuzhiyun     .vs_vars =  "attribute vec2 primitive;\n",
40*4882a593Smuzhiyun     .vs_exec = ("       vec2 pos = vec2(0,0);\n"
41*4882a593Smuzhiyun                 GLAMOR_POS(gl_Position, primitive.xy)),
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun static Bool
glamor_fill_spans_gl(DrawablePtr drawable,GCPtr gc,int n,DDXPointPtr points,int * widths,int sorted)45*4882a593Smuzhiyun glamor_fill_spans_gl(DrawablePtr drawable,
46*4882a593Smuzhiyun                      GCPtr gc,
47*4882a593Smuzhiyun                      int n, DDXPointPtr points, int *widths, int sorted)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun     ScreenPtr screen = drawable->pScreen;
50*4882a593Smuzhiyun     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
51*4882a593Smuzhiyun     PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
52*4882a593Smuzhiyun     glamor_pixmap_private *pixmap_priv;
53*4882a593Smuzhiyun     glamor_program *prog;
54*4882a593Smuzhiyun     int off_x, off_y;
55*4882a593Smuzhiyun     GLshort *v;
56*4882a593Smuzhiyun     char *vbo_offset;
57*4882a593Smuzhiyun     int c;
58*4882a593Smuzhiyun     int box_index;
59*4882a593Smuzhiyun     Bool ret = FALSE;
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun     pixmap_priv = glamor_get_pixmap_private(pixmap);
62*4882a593Smuzhiyun     if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
63*4882a593Smuzhiyun         goto bail;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun     glamor_make_current(glamor_priv);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun     if (glamor_priv->glsl_version >= 130) {
68*4882a593Smuzhiyun         prog = glamor_use_program_fill(pixmap, gc, &glamor_priv->fill_spans_program,
69*4882a593Smuzhiyun                                        &glamor_facet_fillspans_130);
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun         if (!prog)
72*4882a593Smuzhiyun             goto bail;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun         /* Set up the vertex buffers for the points */
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun         v = glamor_get_vbo_space(drawable->pScreen, n * (4 * sizeof (GLshort)), &vbo_offset);
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun         glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
79*4882a593Smuzhiyun         glVertexAttribDivisor(GLAMOR_VERTEX_POS, 1);
80*4882a593Smuzhiyun         glVertexAttribPointer(GLAMOR_VERTEX_POS, 3, GL_SHORT, GL_FALSE,
81*4882a593Smuzhiyun                               4 * sizeof (GLshort), vbo_offset);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun         for (c = 0; c < n; c++) {
84*4882a593Smuzhiyun             v[0] = points->x;
85*4882a593Smuzhiyun             v[1] = points->y;
86*4882a593Smuzhiyun             v[2] = *widths++;
87*4882a593Smuzhiyun             points++;
88*4882a593Smuzhiyun             v += 4;
89*4882a593Smuzhiyun         }
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun         glamor_put_vbo_space(screen);
92*4882a593Smuzhiyun     } else {
93*4882a593Smuzhiyun         prog = glamor_use_program_fill(pixmap, gc, &glamor_priv->fill_spans_program,
94*4882a593Smuzhiyun                                        &glamor_facet_fillspans_120);
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun         if (!prog)
97*4882a593Smuzhiyun             goto bail;
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun         /* Set up the vertex buffers for the points */
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun         v = glamor_get_vbo_space(drawable->pScreen, n * 8 * sizeof (short), &vbo_offset);
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun         glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
104*4882a593Smuzhiyun         glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT, GL_FALSE,
105*4882a593Smuzhiyun                               2 * sizeof (short), vbo_offset);
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun         for (c = 0; c < n; c++) {
108*4882a593Smuzhiyun             v[0] = points->x;           v[1] = points->y;
109*4882a593Smuzhiyun             v[2] = points->x;           v[3] = points->y + 1;
110*4882a593Smuzhiyun             v[4] = points->x + *widths; v[5] = points->y + 1;
111*4882a593Smuzhiyun             v[6] = points->x + *widths; v[7] = points->y;
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun             widths++;
114*4882a593Smuzhiyun             points++;
115*4882a593Smuzhiyun             v += 8;
116*4882a593Smuzhiyun         }
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun         glamor_put_vbo_space(screen);
119*4882a593Smuzhiyun     }
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun     glEnable(GL_SCISSOR_TEST);
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun     glamor_pixmap_loop(pixmap_priv, box_index) {
124*4882a593Smuzhiyun         int nbox = RegionNumRects(gc->pCompositeClip);
125*4882a593Smuzhiyun         BoxPtr box = RegionRects(gc->pCompositeClip);
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun         if (!glamor_set_destination_drawable(drawable, box_index, FALSE, FALSE,
128*4882a593Smuzhiyun                                              prog->matrix_uniform, &off_x, &off_y))
129*4882a593Smuzhiyun             goto bail;
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun         while (nbox--) {
132*4882a593Smuzhiyun             glScissor(box->x1 + off_x,
133*4882a593Smuzhiyun                       box->y1 + off_y,
134*4882a593Smuzhiyun                       box->x2 - box->x1,
135*4882a593Smuzhiyun                       box->y2 - box->y1);
136*4882a593Smuzhiyun             box++;
137*4882a593Smuzhiyun             if (glamor_priv->glsl_version >= 130)
138*4882a593Smuzhiyun                 glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, n);
139*4882a593Smuzhiyun             else {
140*4882a593Smuzhiyun                 glamor_glDrawArrays_GL_QUADS(glamor_priv, n);
141*4882a593Smuzhiyun             }
142*4882a593Smuzhiyun         }
143*4882a593Smuzhiyun     }
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun     glamor_pixmap_invalid(pixmap);
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun     ret = TRUE;
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun bail:
150*4882a593Smuzhiyun     glDisable(GL_SCISSOR_TEST);
151*4882a593Smuzhiyun     if (glamor_priv->glsl_version >= 130)
152*4882a593Smuzhiyun         glVertexAttribDivisor(GLAMOR_VERTEX_POS, 0);
153*4882a593Smuzhiyun     glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun     return ret;
156*4882a593Smuzhiyun }
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun static void
glamor_fill_spans_bail(DrawablePtr drawable,GCPtr gc,int n,DDXPointPtr points,int * widths,int sorted)159*4882a593Smuzhiyun glamor_fill_spans_bail(DrawablePtr drawable,
160*4882a593Smuzhiyun                        GCPtr gc,
161*4882a593Smuzhiyun                        int n, DDXPointPtr points, int *widths, int sorted)
162*4882a593Smuzhiyun {
163*4882a593Smuzhiyun     if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW) &&
164*4882a593Smuzhiyun         glamor_prepare_access_gc(gc)) {
165*4882a593Smuzhiyun         fbFillSpans(drawable, gc, n, points, widths, sorted);
166*4882a593Smuzhiyun     }
167*4882a593Smuzhiyun     glamor_finish_access_gc(gc);
168*4882a593Smuzhiyun     glamor_finish_access(drawable);
169*4882a593Smuzhiyun }
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun void
glamor_fill_spans(DrawablePtr drawable,GCPtr gc,int n,DDXPointPtr points,int * widths,int sorted)172*4882a593Smuzhiyun glamor_fill_spans(DrawablePtr drawable,
173*4882a593Smuzhiyun                   GCPtr gc,
174*4882a593Smuzhiyun                   int n, DDXPointPtr points, int *widths, int sorted)
175*4882a593Smuzhiyun {
176*4882a593Smuzhiyun     if (GLAMOR_PREFER_GL() &&
177*4882a593Smuzhiyun         glamor_fill_spans_gl(drawable, gc, n, points, widths, sorted))
178*4882a593Smuzhiyun         return;
179*4882a593Smuzhiyun     glamor_fill_spans_bail(drawable, gc, n, points, widths, sorted);
180*4882a593Smuzhiyun }
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun static Bool
glamor_get_spans_gl(DrawablePtr drawable,int wmax,DDXPointPtr points,int * widths,int count,char * dst)183*4882a593Smuzhiyun glamor_get_spans_gl(DrawablePtr drawable, int wmax,
184*4882a593Smuzhiyun                     DDXPointPtr points, int *widths, int count, char *dst)
185*4882a593Smuzhiyun {
186*4882a593Smuzhiyun     ScreenPtr screen = drawable->pScreen;
187*4882a593Smuzhiyun     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
188*4882a593Smuzhiyun     PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
189*4882a593Smuzhiyun     glamor_pixmap_private *pixmap_priv;
190*4882a593Smuzhiyun     int box_index;
191*4882a593Smuzhiyun     int n;
192*4882a593Smuzhiyun     char *d;
193*4882a593Smuzhiyun     int off_x, off_y;
194*4882a593Smuzhiyun     const struct glamor_format *f = glamor_format_for_pixmap(pixmap);
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun     pixmap_priv = glamor_get_pixmap_private(pixmap);
197*4882a593Smuzhiyun     if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
198*4882a593Smuzhiyun         goto bail;
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun     glamor_get_drawable_deltas(drawable, pixmap, &off_x, &off_y);
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun     glamor_make_current(glamor_priv);
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun     glamor_pixmap_loop(pixmap_priv, box_index) {
205*4882a593Smuzhiyun         BoxPtr                  box = glamor_pixmap_box_at(pixmap_priv, box_index);
206*4882a593Smuzhiyun         glamor_pixmap_fbo       *fbo = glamor_pixmap_fbo_at(pixmap_priv, box_index);
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun         glBindFramebuffer(GL_FRAMEBUFFER, fbo->fb);
209*4882a593Smuzhiyun         glPixelStorei(GL_PACK_ALIGNMENT, 4);
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun         d = dst;
212*4882a593Smuzhiyun         for (n = 0; n < count; n++) {
213*4882a593Smuzhiyun             int x1 = points[n].x + off_x;
214*4882a593Smuzhiyun             int y = points[n].y + off_y;
215*4882a593Smuzhiyun             int w = widths[n];
216*4882a593Smuzhiyun             int x2 = x1 + w;
217*4882a593Smuzhiyun             char *l;
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun             l = d;
220*4882a593Smuzhiyun             d += PixmapBytePad(w, drawable->depth);
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun             /* clip */
223*4882a593Smuzhiyun             if (x1 < box->x1) {
224*4882a593Smuzhiyun                 l += (box->x1 - x1) * (drawable->bitsPerPixel >> 3);
225*4882a593Smuzhiyun                 x1 = box->x1;
226*4882a593Smuzhiyun             }
227*4882a593Smuzhiyun             if (x2 > box->x2)
228*4882a593Smuzhiyun                 x2 = box->x2;
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun             if (x1 >= x2)
231*4882a593Smuzhiyun                 continue;
232*4882a593Smuzhiyun             if (y < box->y1)
233*4882a593Smuzhiyun                 continue;
234*4882a593Smuzhiyun             if (y >= box->y2)
235*4882a593Smuzhiyun                 continue;
236*4882a593Smuzhiyun 
237*4882a593Smuzhiyun             glReadPixels(x1 - box->x1, y - box->y1, x2 - x1, 1,
238*4882a593Smuzhiyun                          f->format, f->type, l);
239*4882a593Smuzhiyun         }
240*4882a593Smuzhiyun     }
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun     return TRUE;
243*4882a593Smuzhiyun bail:
244*4882a593Smuzhiyun     return FALSE;
245*4882a593Smuzhiyun }
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun static void
glamor_get_spans_bail(DrawablePtr drawable,int wmax,DDXPointPtr points,int * widths,int count,char * dst)248*4882a593Smuzhiyun glamor_get_spans_bail(DrawablePtr drawable, int wmax,
249*4882a593Smuzhiyun                  DDXPointPtr points, int *widths, int count, char *dst)
250*4882a593Smuzhiyun {
251*4882a593Smuzhiyun     if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RO))
252*4882a593Smuzhiyun         fbGetSpans(drawable, wmax, points, widths, count, dst);
253*4882a593Smuzhiyun     glamor_finish_access(drawable);
254*4882a593Smuzhiyun }
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun void
glamor_get_spans(DrawablePtr drawable,int wmax,DDXPointPtr points,int * widths,int count,char * dst)257*4882a593Smuzhiyun glamor_get_spans(DrawablePtr drawable, int wmax,
258*4882a593Smuzhiyun                  DDXPointPtr points, int *widths, int count, char *dst)
259*4882a593Smuzhiyun {
260*4882a593Smuzhiyun     if (GLAMOR_PREFER_GL() &&
261*4882a593Smuzhiyun         glamor_get_spans_gl(drawable, wmax, points, widths, count, dst))
262*4882a593Smuzhiyun         return;
263*4882a593Smuzhiyun     glamor_get_spans_bail(drawable, wmax, points, widths, count, dst);
264*4882a593Smuzhiyun }
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun static Bool
glamor_set_spans_gl(DrawablePtr drawable,GCPtr gc,char * src,DDXPointPtr points,int * widths,int numPoints,int sorted)267*4882a593Smuzhiyun glamor_set_spans_gl(DrawablePtr drawable, GCPtr gc, char *src,
268*4882a593Smuzhiyun                     DDXPointPtr points, int *widths, int numPoints, int sorted)
269*4882a593Smuzhiyun {
270*4882a593Smuzhiyun     ScreenPtr screen = drawable->pScreen;
271*4882a593Smuzhiyun     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
272*4882a593Smuzhiyun     PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
273*4882a593Smuzhiyun     glamor_pixmap_private *pixmap_priv;
274*4882a593Smuzhiyun     const struct glamor_format *f = glamor_format_for_pixmap(pixmap);
275*4882a593Smuzhiyun     int box_index;
276*4882a593Smuzhiyun     int n;
277*4882a593Smuzhiyun     char *s;
278*4882a593Smuzhiyun     int off_x, off_y;
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun     pixmap_priv = glamor_get_pixmap_private(pixmap);
281*4882a593Smuzhiyun     if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
282*4882a593Smuzhiyun         goto bail;
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun     if (gc->alu != GXcopy)
285*4882a593Smuzhiyun         goto bail;
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun     if (!glamor_pm_is_solid(gc->depth, gc->planemask))
288*4882a593Smuzhiyun         goto bail;
289*4882a593Smuzhiyun 
290*4882a593Smuzhiyun     glamor_get_drawable_deltas(drawable, pixmap, &off_x, &off_y);
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun     glamor_make_current(glamor_priv);
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun     glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun     glamor_pixmap_loop(pixmap_priv, box_index) {
297*4882a593Smuzhiyun         BoxPtr              box = glamor_pixmap_box_at(pixmap_priv, box_index);
298*4882a593Smuzhiyun         glamor_pixmap_fbo  *fbo = glamor_pixmap_fbo_at(pixmap_priv, box_index);
299*4882a593Smuzhiyun 
300*4882a593Smuzhiyun         glamor_bind_texture(glamor_priv, GL_TEXTURE0, fbo, TRUE);
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun         s = src;
303*4882a593Smuzhiyun         for (n = 0; n < numPoints; n++) {
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun             BoxPtr      clip_box = RegionRects(gc->pCompositeClip);
306*4882a593Smuzhiyun             int         nclip_box = RegionNumRects(gc->pCompositeClip);
307*4882a593Smuzhiyun             int         w = widths[n];
308*4882a593Smuzhiyun             int         y = points[n].y;
309*4882a593Smuzhiyun             int         x = points[n].x;
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun             while (nclip_box--) {
312*4882a593Smuzhiyun                 int x1 = x;
313*4882a593Smuzhiyun                 int x2 = x + w;
314*4882a593Smuzhiyun                 int y1 = y;
315*4882a593Smuzhiyun                 char *l = s;
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun                 /* clip to composite clip */
318*4882a593Smuzhiyun                 if (x1 < clip_box->x1) {
319*4882a593Smuzhiyun                     l += (clip_box->x1 - x1) * (drawable->bitsPerPixel >> 3);
320*4882a593Smuzhiyun                     x1 = clip_box->x1;
321*4882a593Smuzhiyun                 }
322*4882a593Smuzhiyun                 if (x2 > clip_box->x2)
323*4882a593Smuzhiyun                     x2 = clip_box->x2;
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun                 if (y < clip_box->y1)
326*4882a593Smuzhiyun                     continue;
327*4882a593Smuzhiyun                 if (y >= clip_box->y2)
328*4882a593Smuzhiyun                     continue;
329*4882a593Smuzhiyun 
330*4882a593Smuzhiyun                 /* adjust to pixmap coordinates */
331*4882a593Smuzhiyun                 x1 += off_x;
332*4882a593Smuzhiyun                 x2 += off_x;
333*4882a593Smuzhiyun                 y1 += off_y;
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun                 if (x1 < box->x1) {
336*4882a593Smuzhiyun                     l += (box->x1 - x1) * (drawable->bitsPerPixel >> 3);
337*4882a593Smuzhiyun                     x1 = box->x1;
338*4882a593Smuzhiyun                 }
339*4882a593Smuzhiyun                 if (x2 > box->x2)
340*4882a593Smuzhiyun                     x2 = box->x2;
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun                 if (x1 >= x2)
343*4882a593Smuzhiyun                     continue;
344*4882a593Smuzhiyun                 if (y1 < box->y1)
345*4882a593Smuzhiyun                     continue;
346*4882a593Smuzhiyun                 if (y1 >= box->y2)
347*4882a593Smuzhiyun                     continue;
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun                 glTexSubImage2D(GL_TEXTURE_2D, 0,
350*4882a593Smuzhiyun                                 x1 - box->x1, y1 - box->y1, x2 - x1, 1,
351*4882a593Smuzhiyun                                 f->format, f->type,
352*4882a593Smuzhiyun                                 l);
353*4882a593Smuzhiyun             }
354*4882a593Smuzhiyun             s += PixmapBytePad(w, drawable->depth);
355*4882a593Smuzhiyun         }
356*4882a593Smuzhiyun     }
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun     glamor_pixmap_invalid(pixmap);
359*4882a593Smuzhiyun 
360*4882a593Smuzhiyun     return TRUE;
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun bail:
363*4882a593Smuzhiyun     return FALSE;
364*4882a593Smuzhiyun }
365*4882a593Smuzhiyun 
366*4882a593Smuzhiyun static void
glamor_set_spans_bail(DrawablePtr drawable,GCPtr gc,char * src,DDXPointPtr points,int * widths,int numPoints,int sorted)367*4882a593Smuzhiyun glamor_set_spans_bail(DrawablePtr drawable, GCPtr gc, char *src,
368*4882a593Smuzhiyun                       DDXPointPtr points, int *widths, int numPoints, int sorted)
369*4882a593Smuzhiyun {
370*4882a593Smuzhiyun     if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW) && glamor_prepare_access_gc(gc))
371*4882a593Smuzhiyun         fbSetSpans(drawable, gc, src, points, widths, numPoints, sorted);
372*4882a593Smuzhiyun     glamor_finish_access_gc(gc);
373*4882a593Smuzhiyun     glamor_finish_access(drawable);
374*4882a593Smuzhiyun }
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun void
glamor_set_spans(DrawablePtr drawable,GCPtr gc,char * src,DDXPointPtr points,int * widths,int numPoints,int sorted)377*4882a593Smuzhiyun glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
378*4882a593Smuzhiyun                  DDXPointPtr points, int *widths, int numPoints, int sorted)
379*4882a593Smuzhiyun {
380*4882a593Smuzhiyun     if (GLAMOR_PREFER_GL() &&
381*4882a593Smuzhiyun         glamor_set_spans_gl(drawable, gc, src, points, widths, numPoints, sorted))
382*4882a593Smuzhiyun         return;
383*4882a593Smuzhiyun     glamor_set_spans_bail(drawable, gc, src, points, widths, numPoints, sorted);
384*4882a593Smuzhiyun }
385