1 /*
2  * Copyright © 2009 Intel Corporation
3  * Copyright © 1998 Keith Packard
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  *
24  * Authors:
25  *    Zhigang Gong <zhigang.gong@linux.intel.com>
26  *
27  */
28 
29 #include "glamor_priv.h"
30 #include "glamor_transform.h"
31 
32 static const glamor_facet glamor_facet_point = {
33     .name = "poly_point",
34     .vs_vars = "attribute vec2 primitive;\n",
35     .vs_exec = GLAMOR_POS(gl_Position, primitive),
36 };
37 
38 static Bool
glamor_poly_point_gl(DrawablePtr drawable,GCPtr gc,int mode,int npt,DDXPointPtr ppt)39 glamor_poly_point_gl(DrawablePtr drawable, GCPtr gc, int mode, int npt, DDXPointPtr ppt)
40 {
41     ScreenPtr screen = drawable->pScreen;
42     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
43     PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
44     glamor_program *prog = &glamor_priv->point_prog;
45     glamor_pixmap_private *pixmap_priv;
46     int off_x, off_y;
47     GLshort *vbo_ppt;
48     char *vbo_offset;
49     int box_index;
50     Bool ret = FALSE;
51 
52     pixmap_priv = glamor_get_pixmap_private(pixmap);
53     if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
54         goto bail;
55 
56     glamor_make_current(glamor_priv);
57 
58     if (prog->failed)
59         goto bail;
60 
61     if (!prog->prog) {
62         if (!glamor_build_program(screen, prog,
63                                   &glamor_facet_point,
64                                   &glamor_fill_solid,
65                                   NULL, NULL))
66             goto bail;
67     }
68 
69     if (!glamor_use_program(pixmap, gc, prog, NULL))
70         goto bail;
71 
72     vbo_ppt = glamor_get_vbo_space(screen, npt * (2 * sizeof (INT16)), &vbo_offset);
73     glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
74     glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT, GL_FALSE, 0, vbo_offset);
75     if (mode == CoordModePrevious) {
76         int n = npt;
77         INT16 x = 0, y = 0;
78         while (n--) {
79             vbo_ppt[0] = (x += ppt->x);
80             vbo_ppt[1] = (y += ppt->y);
81             vbo_ppt += 2;
82             ppt++;
83         }
84     } else
85         memcpy(vbo_ppt, ppt, npt * (2 * sizeof (INT16)));
86     glamor_put_vbo_space(screen);
87 
88     glEnable(GL_SCISSOR_TEST);
89 
90     glamor_pixmap_loop(pixmap_priv, box_index) {
91         int nbox = RegionNumRects(gc->pCompositeClip);
92         BoxPtr box = RegionRects(gc->pCompositeClip);
93 
94         if (!glamor_set_destination_drawable(drawable, box_index, TRUE, TRUE,
95                                              prog->matrix_uniform, &off_x, &off_y))
96             goto bail;
97 
98         while (nbox--) {
99             glScissor(box->x1 + off_x,
100                       box->y1 + off_y,
101                       box->x2 - box->x1,
102                       box->y2 - box->y1);
103             box++;
104             glDrawArrays(GL_POINTS, 0, npt);
105         }
106     }
107 
108     ret = TRUE;
109 
110 bail:
111     glDisable(GL_SCISSOR_TEST);
112     glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
113 
114     return ret;
115 }
116 
117 void
glamor_poly_point(DrawablePtr drawable,GCPtr gc,int mode,int npt,DDXPointPtr ppt)118 glamor_poly_point(DrawablePtr drawable, GCPtr gc, int mode, int npt,
119                   DDXPointPtr ppt)
120 {
121     if (glamor_poly_point_gl(drawable, gc, mode, npt, ppt))
122         return;
123     miPolyPoint(drawable, gc, mode, npt, ppt);
124 }
125