No longer leak FDs on VT switch.
[xserver.git] / glamor / glamor_points.c
blob91b5e4789a1f71a6f1a48342cfe37522fa5de733
1 /*
2 * Copyright © 2009 Intel Corporation
3 * Copyright © 1998 Keith Packard
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:
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.
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.
24 * Authors:
25 * Zhigang Gong <zhigang.gong@linux.intel.com>
29 #include "glamor_priv.h"
30 #include "glamor_transform.h"
32 static const glamor_facet glamor_facet_point = {
33 .name = "poly_point",
34 .vs_vars = "in vec2 primitive;\n",
35 .vs_exec = (GLAMOR_DEFAULT_POINT_SIZE
36 GLAMOR_POS(gl_Position, primitive)),
39 static Bool
40 glamor_poly_point_gl(DrawablePtr drawable, GCPtr gc, int mode, int npt, DDXPointPtr ppt)
42 ScreenPtr screen = drawable->pScreen;
43 glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
44 PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
45 glamor_program *prog = &glamor_priv->point_prog;
46 glamor_pixmap_private *pixmap_priv;
47 int off_x, off_y;
48 GLshort *vbo_ppt;
49 char *vbo_offset;
50 int box_index;
51 Bool ret = FALSE;
53 pixmap_priv = glamor_get_pixmap_private(pixmap);
54 if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
55 goto bail;
57 glamor_make_current(glamor_priv);
59 if (prog->failed)
60 goto bail;
62 if (!prog->prog) {
63 if (!glamor_build_program(screen, prog,
64 &glamor_facet_point,
65 &glamor_fill_solid,
66 NULL, NULL))
67 goto bail;
70 if (!glamor_use_program(drawable, gc, prog, NULL))
71 goto bail;
73 vbo_ppt = glamor_get_vbo_space(screen, npt * (2 * sizeof (INT16)), &vbo_offset);
74 glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
75 glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT, GL_FALSE, 0, vbo_offset);
76 if (mode == CoordModePrevious) {
77 int n = npt;
78 INT16 x = 0, y = 0;
79 while (n--) {
80 vbo_ppt[0] = (x += ppt->x);
81 vbo_ppt[1] = (y += ppt->y);
82 vbo_ppt += 2;
83 ppt++;
85 } else
86 memcpy(vbo_ppt, ppt, npt * (2 * sizeof (INT16)));
87 glamor_put_vbo_space(screen);
89 glEnable(GL_SCISSOR_TEST);
91 glamor_pixmap_loop(pixmap_priv, box_index) {
92 int nbox = RegionNumRects(gc->pCompositeClip);
93 BoxPtr box = RegionRects(gc->pCompositeClip);
95 if (!glamor_set_destination_drawable(drawable, box_index, TRUE, TRUE,
96 prog->matrix_uniform, &off_x, &off_y))
97 goto bail;
99 while (nbox--) {
100 glScissor(box->x1 + off_x,
101 box->y1 + off_y,
102 box->x2 - box->x1,
103 box->y2 - box->y1);
104 box++;
105 glDrawArrays(GL_POINTS, 0, npt);
109 ret = TRUE;
111 bail:
112 glDisable(GL_SCISSOR_TEST);
113 glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
115 return ret;
118 void
119 glamor_poly_point(DrawablePtr drawable, GCPtr gc, int mode, int npt,
120 DDXPointPtr ppt)
122 if (glamor_poly_point_gl(drawable, gc, mode, npt, ppt))
123 return;
124 miPolyPoint(drawable, gc, mode, npt, ppt);