135c4bbdfSmrg/*
235c4bbdfSmrg * Copyright © 2009 Intel Corporation
335c4bbdfSmrg * Copyright © 1998 Keith Packard
435c4bbdfSmrg *
535c4bbdfSmrg * Permission is hereby granted, free of charge, to any person obtaining a
635c4bbdfSmrg * copy of this software and associated documentation files (the "Software"),
735c4bbdfSmrg * to deal in the Software without restriction, including without limitation
835c4bbdfSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
935c4bbdfSmrg * and/or sell copies of the Software, and to permit persons to whom the
1035c4bbdfSmrg * Software is furnished to do so, subject to the following conditions:
1135c4bbdfSmrg *
1235c4bbdfSmrg * The above copyright notice and this permission notice (including the next
1335c4bbdfSmrg * paragraph) shall be included in all copies or substantial portions of the
1435c4bbdfSmrg * Software.
1535c4bbdfSmrg *
1635c4bbdfSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1735c4bbdfSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1835c4bbdfSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1935c4bbdfSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2035c4bbdfSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2135c4bbdfSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2235c4bbdfSmrg * IN THE SOFTWARE.
2335c4bbdfSmrg *
2435c4bbdfSmrg * Authors:
2535c4bbdfSmrg *    Zhigang Gong <zhigang.gong@linux.intel.com>
2635c4bbdfSmrg *
2735c4bbdfSmrg */
2835c4bbdfSmrg
2935c4bbdfSmrg#include "glamor_priv.h"
3035c4bbdfSmrg#include "glamor_transform.h"
3135c4bbdfSmrg
3235c4bbdfSmrgstatic const glamor_facet glamor_facet_point = {
3335c4bbdfSmrg    .name = "poly_point",
3435c4bbdfSmrg    .vs_vars = "attribute vec2 primitive;\n",
3535c4bbdfSmrg    .vs_exec = GLAMOR_POS(gl_Position, primitive),
3635c4bbdfSmrg};
3735c4bbdfSmrg
3835c4bbdfSmrgstatic Bool
3935c4bbdfSmrgglamor_poly_point_gl(DrawablePtr drawable, GCPtr gc, int mode, int npt, DDXPointPtr ppt)
4035c4bbdfSmrg{
4135c4bbdfSmrg    ScreenPtr screen = drawable->pScreen;
4235c4bbdfSmrg    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
4335c4bbdfSmrg    PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
4435c4bbdfSmrg    glamor_program *prog = &glamor_priv->point_prog;
4535c4bbdfSmrg    glamor_pixmap_private *pixmap_priv;
4635c4bbdfSmrg    int off_x, off_y;
4735c4bbdfSmrg    GLshort *vbo_ppt;
4835c4bbdfSmrg    char *vbo_offset;
4935c4bbdfSmrg    int box_index;
501b5d61b8Smrg    Bool ret = FALSE;
5135c4bbdfSmrg
5235c4bbdfSmrg    pixmap_priv = glamor_get_pixmap_private(pixmap);
5335c4bbdfSmrg    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
5435c4bbdfSmrg        goto bail;
5535c4bbdfSmrg
5635c4bbdfSmrg    glamor_make_current(glamor_priv);
5735c4bbdfSmrg
5835c4bbdfSmrg    if (prog->failed)
5935c4bbdfSmrg        goto bail;
6035c4bbdfSmrg
6135c4bbdfSmrg    if (!prog->prog) {
6235c4bbdfSmrg        if (!glamor_build_program(screen, prog,
6335c4bbdfSmrg                                  &glamor_facet_point,
6435c4bbdfSmrg                                  &glamor_fill_solid,
6535c4bbdfSmrg                                  NULL, NULL))
6635c4bbdfSmrg            goto bail;
6735c4bbdfSmrg    }
6835c4bbdfSmrg
6935c4bbdfSmrg    if (!glamor_use_program(pixmap, gc, prog, NULL))
7035c4bbdfSmrg        goto bail;
7135c4bbdfSmrg
7235c4bbdfSmrg    vbo_ppt = glamor_get_vbo_space(screen, npt * (2 * sizeof (INT16)), &vbo_offset);
7335c4bbdfSmrg    glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
7435c4bbdfSmrg    glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT, GL_FALSE, 0, vbo_offset);
7535c4bbdfSmrg    if (mode == CoordModePrevious) {
7635c4bbdfSmrg        int n = npt;
7735c4bbdfSmrg        INT16 x = 0, y = 0;
7835c4bbdfSmrg        while (n--) {
7935c4bbdfSmrg            vbo_ppt[0] = (x += ppt->x);
8035c4bbdfSmrg            vbo_ppt[1] = (y += ppt->y);
8135c4bbdfSmrg            vbo_ppt += 2;
8235c4bbdfSmrg            ppt++;
8335c4bbdfSmrg        }
8435c4bbdfSmrg    } else
8535c4bbdfSmrg        memcpy(vbo_ppt, ppt, npt * (2 * sizeof (INT16)));
8635c4bbdfSmrg    glamor_put_vbo_space(screen);
8735c4bbdfSmrg
8835c4bbdfSmrg    glEnable(GL_SCISSOR_TEST);
8935c4bbdfSmrg
9035c4bbdfSmrg    glamor_pixmap_loop(pixmap_priv, box_index) {
9135c4bbdfSmrg        int nbox = RegionNumRects(gc->pCompositeClip);
9235c4bbdfSmrg        BoxPtr box = RegionRects(gc->pCompositeClip);
9335c4bbdfSmrg
941b5d61b8Smrg        if (!glamor_set_destination_drawable(drawable, box_index, TRUE, TRUE,
951b5d61b8Smrg                                             prog->matrix_uniform, &off_x, &off_y))
961b5d61b8Smrg            goto bail;
9735c4bbdfSmrg
9835c4bbdfSmrg        while (nbox--) {
9935c4bbdfSmrg            glScissor(box->x1 + off_x,
10035c4bbdfSmrg                      box->y1 + off_y,
10135c4bbdfSmrg                      box->x2 - box->x1,
10235c4bbdfSmrg                      box->y2 - box->y1);
10335c4bbdfSmrg            box++;
10435c4bbdfSmrg            glDrawArrays(GL_POINTS, 0, npt);
10535c4bbdfSmrg        }
10635c4bbdfSmrg    }
10735c4bbdfSmrg
1081b5d61b8Smrg    ret = TRUE;
1091b5d61b8Smrg
1101b5d61b8Smrgbail:
11135c4bbdfSmrg    glDisable(GL_SCISSOR_TEST);
11235c4bbdfSmrg    glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
11335c4bbdfSmrg
1141b5d61b8Smrg    return ret;
11535c4bbdfSmrg}
11635c4bbdfSmrg
11735c4bbdfSmrgvoid
11835c4bbdfSmrgglamor_poly_point(DrawablePtr drawable, GCPtr gc, int mode, int npt,
11935c4bbdfSmrg                  DDXPointPtr ppt)
12035c4bbdfSmrg{
12135c4bbdfSmrg    if (glamor_poly_point_gl(drawable, gc, mode, npt, ppt))
12235c4bbdfSmrg        return;
12335c4bbdfSmrg    miPolyPoint(drawable, gc, mode, npt, ppt);
12435c4bbdfSmrg}
125