glamor_points.c 3.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*
 * Copyright © 2009 Intel Corporation
 * Copyright © 1998 Keith Packard
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Authors:
 *    Zhigang Gong <zhigang.gong@linux.intel.com>
 *
 */

#include "glamor_priv.h"
#include "glamor_transform.h"

static const glamor_facet glamor_facet_point = {
    .name = "poly_point",
    .vs_vars = "attribute vec2 primitive;\n",
    .vs_exec = GLAMOR_POS(gl_Position, primitive),
};

38 39
static Bool
glamor_poly_point_gl(DrawablePtr drawable, GCPtr gc, int mode, int npt, DDXPointPtr ppt)
40 41 42 43 44 45 46 47 48
{
    ScreenPtr screen = drawable->pScreen;
    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
    PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
    glamor_program *prog = &glamor_priv->point_prog;
    glamor_pixmap_private *pixmap_priv;
    int off_x, off_y;
    GLshort *vbo_ppt;
    char *vbo_offset;
49
    int box_index;
50
    Bool ret = FALSE;
51 52 53 54 55

    pixmap_priv = glamor_get_pixmap_private(pixmap);
    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
        goto bail;

56
    glamor_make_current(glamor_priv);
57 58

    if (prog->failed)
59
        goto bail;
60 61 62 63

    if (!prog->prog) {
        if (!glamor_build_program(screen, prog,
                                  &glamor_facet_point,
64 65
                                  &glamor_fill_solid,
                                  NULL, NULL))
66
            goto bail;
67 68 69
    }

    if (!glamor_use_program(pixmap, gc, prog, NULL))
70
        goto bail;
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

    vbo_ppt = glamor_get_vbo_space(screen, npt * (2 * sizeof (INT16)), &vbo_offset);
    glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
    glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT, GL_FALSE, 0, vbo_offset);
    if (mode == CoordModePrevious) {
        int n = npt;
        INT16 x = 0, y = 0;
        while (n--) {
            vbo_ppt[0] = (x += ppt->x);
            vbo_ppt[1] = (y += ppt->y);
            vbo_ppt += 2;
            ppt++;
        }
    } else
        memcpy(vbo_ppt, ppt, npt * (2 * sizeof (INT16)));
    glamor_put_vbo_space(screen);

    glEnable(GL_SCISSOR_TEST);

90
    glamor_pixmap_loop(pixmap_priv, box_index) {
91 92 93
        int nbox = RegionNumRects(gc->pCompositeClip);
        BoxPtr box = RegionRects(gc->pCompositeClip);

94 95 96
        if (!glamor_set_destination_drawable(drawable, box_index, TRUE, TRUE,
                                             prog->matrix_uniform, &off_x, &off_y))
            goto bail;
97 98 99 100 101 102 103 104 105 106 107

        while (nbox--) {
            glScissor(box->x1 + off_x,
                      box->y1 + off_y,
                      box->x2 - box->x1,
                      box->y2 - box->y1);
            box++;
            glDrawArrays(GL_POINTS, 0, npt);
        }
    }

108 109 110
    ret = TRUE;

bail:
111 112 113
    glDisable(GL_SCISSOR_TEST);
    glDisableVertexAttribArray(GLAMOR_VERTEX_POS);

114
    return ret;
115 116 117 118 119 120
}

void
glamor_poly_point(DrawablePtr drawable, GCPtr gc, int mode, int npt,
                  DDXPointPtr ppt)
{
121
    if (glamor_poly_point_gl(drawable, gc, mode, npt, ppt))
122 123 124
        return;
    miPolyPoint(drawable, gc, mode, npt, ppt);
}