From dc9fa9080a1cb994b4e54a341d2245f442dac576 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 23 Mar 2014 20:59:02 -0700 Subject: glamor: Use glamor_program and GL_LINES for 0-width lines GL lines are nearly X compliant; you just need to fill in the last pixel when the client hasn't requested CapNotLast. v2: switch to glamor_make_current v3: use miPolylines instead of custom glamor fallback path. Wrap code to 80 columns. Signed-off-by: Keith Packard Reviewed-by: Eric Anholt --- glamor/Makefile.am | 4 +- glamor/glamor_lines.c | 171 +++++++++++++++++++++++++++++++++++++++++++++ glamor/glamor_polylines.c | 136 ------------------------------------ glamor/glamor_priv.h | 25 ++++--- glamor/glamor_segment.c | 44 ------------ glamor/glamor_segs.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 361 insertions(+), 192 deletions(-) create mode 100644 glamor/glamor_lines.c delete mode 100644 glamor/glamor_polylines.c delete mode 100644 glamor/glamor_segment.c create mode 100644 glamor/glamor_segs.c (limited to 'glamor') diff --git a/glamor/Makefile.am b/glamor/Makefile.am index c0d82d67d..8fd6ec194 100644 --- a/glamor/Makefile.am +++ b/glamor/Makefile.am @@ -15,9 +15,9 @@ libglamor_la_SOURCES = \ glamor_font.h \ glamor_glx.c \ glamor_glyphs.c \ - glamor_polylines.c \ - glamor_segment.c \ glamor_image.c \ + glamor_lines.c \ + glamor_segs.c \ glamor_render.c \ glamor_gradient.c \ glamor_prepare.c \ diff --git a/glamor/glamor_lines.c b/glamor/glamor_lines.c new file mode 100644 index 000000000..ca3cccf8c --- /dev/null +++ b/glamor/glamor_lines.c @@ -0,0 +1,171 @@ +/* + * Copyright © 2014 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "glamor_priv.h" +#include "glamor_program.h" +#include "glamor_transform.h" +#include "glamor_prepare.h" + +static const glamor_facet glamor_facet_poly_lines = { + .name = "poly_lines", + .vs_vars = "attribute vec2 primitive;\n", + .vs_exec = (" vec2 pos = vec2(0.0,0.0);\n" + GLAMOR_POS(gl_Position, primitive.xy)), +}; + +static Bool +glamor_poly_lines_gl(DrawablePtr drawable, GCPtr gc, + int mode, int n, DDXPointPtr points) +{ + ScreenPtr screen = drawable->pScreen; + glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); + PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable); + glamor_pixmap_private *pixmap_priv; + glamor_program *prog; + int off_x, off_y; + DDXPointPtr v; + char *vbo_offset; + int box_x, box_y; + int add_last; + + pixmap_priv = glamor_get_pixmap_private(pixmap); + if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)) + goto bail; + + if (gc->lineWidth != 0) + goto bail; + + if (gc->lineStyle != LineSolid) + goto bail; + + add_last = 0; + if (gc->capStyle != CapNotLast) + add_last = 1; + + if (n < 2) + return TRUE; + + glamor_make_current(glamor_priv); + + prog = glamor_use_program_fill(pixmap, gc, + &glamor_priv->poly_line_program, + &glamor_facet_poly_lines); + + if (!prog) + goto bail_ctx; + + /* Set up the vertex buffers for the points */ + + v = glamor_get_vbo_space(drawable->pScreen, + (n + add_last) * sizeof (DDXPointRec), + &vbo_offset); + + glEnableVertexAttribArray(GLAMOR_VERTEX_POS); + glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT, GL_FALSE, + sizeof (DDXPointRec), vbo_offset); + + if (mode == CoordModePrevious) { + int i; + DDXPointRec here = { 0, 0 }; + + for (i = 0; i < n; i++) { + here.x += points[i].x; + here.y += points[i].y; + v[i] = here; + } + } else { + memcpy(v, points, n * sizeof (DDXPointRec)); + } + + if (add_last) { + v[n].x = v[n-1].x + 1; + v[n].y = v[n-1].y; + } + + glamor_put_vbo_space(screen); + + glEnable(GL_SCISSOR_TEST); + + glamor_pixmap_loop(pixmap_priv, box_x, box_y) { + int nbox = RegionNumRects(gc->pCompositeClip); + BoxPtr box = RegionRects(gc->pCompositeClip); + + glamor_set_destination_drawable(drawable, box_x, box_y, TRUE, TRUE, + prog->matrix_uniform, &off_x, &off_y); + + while (nbox--) { + glScissor(box->x1 + off_x, + box->y1 + off_y, + box->x2 - box->x1, + box->y2 - box->y1); + box++; + glDrawArrays(GL_LINE_STRIP, 0, n + add_last); + } + } + + glDisable(GL_SCISSOR_TEST); + glDisable(GL_COLOR_LOGIC_OP); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + + return TRUE; +bail_ctx: + glDisable(GL_COLOR_LOGIC_OP); +bail: + return FALSE; +} + +static void +glamor_poly_lines_bail(DrawablePtr drawable, GCPtr gc, + int mode, int n, DDXPointPtr points) +{ + glamor_fallback("to %p (%c)\n", drawable, + glamor_get_drawable_location(drawable)); + + miPolylines(drawable, gc, mode, n, points); +} + +void +glamor_poly_lines(DrawablePtr drawable, GCPtr gc, + int mode, int n, DDXPointPtr points) +{ + if (glamor_poly_lines_gl(drawable, gc, mode, n, points)) + return; + glamor_poly_lines_bail(drawable, gc, mode, n, points); +} + +Bool +glamor_poly_lines_nf(DrawablePtr drawable, GCPtr gc, + int mode, int n, DDXPointPtr points) +{ + if (glamor_poly_lines_gl(drawable, gc, mode, n, points)) + return TRUE; + + if (glamor_ddx_fallback_check_pixmap(drawable) && + glamor_ddx_fallback_check_gc(gc)) + { + return FALSE; + } + + glamor_poly_lines_bail(drawable, gc, mode, n, points); + return TRUE; +} + diff --git a/glamor/glamor_polylines.c b/glamor/glamor_polylines.c deleted file mode 100644 index 1adf45ddc..000000000 --- a/glamor/glamor_polylines.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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: - * Eric Anholt - * - */ - -#include "glamor_priv.h" - -/** @file glamor_polylines.c - * - * GC PolyFillRect implementation, taken straight from fb_fill.c - */ - -/** - * glamor_poly_lines() checks if it can accelerate the lines as a group of - * horizontal or vertical lines (rectangles), and uses existing rectangle fill - * acceleration if so. - */ -static Bool -_glamor_poly_lines(DrawablePtr drawable, GCPtr gc, int mode, int n, - DDXPointPtr points, Bool fallback) -{ - xRectangle *rects; - int x1, x2, y1, y2; - int i; - - /* Don't try to do wide lines or non-solid fill style. */ - if (gc->lineWidth != 0) { - /* This ends up in miSetSpans, which is accelerated as well as we - * can hope X wide lines will be. - */ - goto fail; - } - - if (gc->lineStyle != LineSolid) { - glamor_fallback("non-solid fill line style %d\n", gc->lineStyle); - goto fail; - } - rects = malloc(sizeof(xRectangle) * (n - 1)); - x1 = points[0].x; - y1 = points[0].y; - /* If we have any non-horizontal/vertical, fall back. */ - for (i = 0; i < n - 1; i++) { - if (mode == CoordModePrevious) { - x2 = x1 + points[i + 1].x; - y2 = y1 + points[i + 1].y; - } - else { - x2 = points[i + 1].x; - y2 = points[i + 1].y; - } - if (x1 != x2 && y1 != y2) { - free(rects); - glamor_fallback("stub diagonal poly_line\n"); - goto fail; - } - if (x1 < x2) { - rects[i].x = x1; - rects[i].width = x2 - x1 + 1; - } - else { - rects[i].x = x2; - rects[i].width = x1 - x2 + 1; - } - if (y1 < y2) { - rects[i].y = y1; - rects[i].height = y2 - y1 + 1; - } - else { - rects[i].y = y2; - rects[i].height = y1 - y2 + 1; - } - - x1 = x2; - y1 = y2; - } - gc->ops->PolyFillRect(drawable, gc, n - 1, rects); - free(rects); - return TRUE; - - fail: - if (!fallback && glamor_ddx_fallback_check_pixmap(drawable) - && glamor_ddx_fallback_check_gc(gc)) - return FALSE; - - switch (gc->lineStyle) { - case LineSolid: - if (gc->lineWidth == 0) - miZeroLine(drawable, gc, mode, n, points); - else - miWideLine(drawable, gc, mode, n, points); - break; - case LineOnOffDash: - case LineDoubleDash: - miWideDash(drawable, gc, mode, n, points); - break; - } - - return TRUE; -} - -void -glamor_poly_lines(DrawablePtr drawable, GCPtr gc, int mode, int n, - DDXPointPtr points) -{ - _glamor_poly_lines(drawable, gc, mode, n, points, TRUE); -} - -Bool -glamor_poly_lines_nf(DrawablePtr drawable, GCPtr gc, int mode, int n, - DDXPointPtr points) -{ - return _glamor_poly_lines(drawable, gc, mode, n, points, FALSE); -} diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h index 1ae4e94f4..07e1b890f 100644 --- a/glamor/glamor_priv.h +++ b/glamor/glamor_priv.h @@ -241,6 +241,12 @@ typedef struct glamor_screen_private { glamor_program copy_area_prog; glamor_program copy_plane_prog; + /* glamor line shader */ + glamor_program_fill poly_line_program; + + /* glamor segment shaders */ + glamor_program_fill poly_segment_program; + /* vertext/elment_index buffer object for render */ GLuint vbo, ebo; /** Next offset within the VBO that glamor_get_vbo_space() will use. */ @@ -683,10 +689,6 @@ void glamor_glyphs(CARD8 op, INT16 xSrc, INT16 ySrc, int nlist, GlyphListPtr list, GlyphPtr *glyphs); -/* glamor_polylines.c */ -void glamor_poly_lines(DrawablePtr drawable, GCPtr gc, int mode, int n, - DDXPointPtr points); - /* glamor_render.c */ Bool glamor_composite_clipped_region(CARD8 op, PicturePtr source, @@ -967,6 +969,15 @@ glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y, void glamor_get_image(DrawablePtr pDrawable, int x, int y, int w, int h, unsigned int format, unsigned long planeMask, char *d); +/* glamor_lines.c */ +void +glamor_poly_lines(DrawablePtr drawable, GCPtr gc, + int mode, int n, DDXPointPtr points); + +/* glamor_segs.c */ +void +glamor_poly_segment(DrawablePtr drawable, GCPtr gc, + int nseg, xSegment *segs); /* glamor_copy.c */ void @@ -1006,12 +1017,6 @@ void glamor_push_pixels(GCPtr pGC, PixmapPtr pBitmap, void glamor_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt, DDXPointPtr ppt); -void glamor_poly_segment(DrawablePtr pDrawable, GCPtr pGC, int nseg, - xSegment *pSeg); - -void glamor_poly_line(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt, - DDXPointPtr ppt); - void glamor_composite_rectangles(CARD8 op, PicturePtr dst, xRenderColor *color, diff --git a/glamor/glamor_segment.c b/glamor/glamor_segment.c deleted file mode 100644 index 53f7da0cb..000000000 --- a/glamor/glamor_segment.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2014 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#include "glamor_priv.h" - -Bool -glamor_poly_segment_nf(DrawablePtr drawable, GCPtr gc, int nseg, - xSegment *seg) -{ - if (glamor_ddx_fallback_check_pixmap(drawable) && - glamor_ddx_fallback_check_gc(gc)) { - return FALSE; - } - - miPolySegment(drawable, gc, nseg, seg); - - return TRUE; -} - -void -glamor_poly_segment(DrawablePtr drawable, GCPtr gc, int nseg, - xSegment *seg) -{ - miPolySegment(drawable, gc, nseg, seg); -} diff --git a/glamor/glamor_segs.c b/glamor/glamor_segs.c new file mode 100644 index 000000000..0168d053f --- /dev/null +++ b/glamor/glamor_segs.c @@ -0,0 +1,173 @@ +/* + * Copyright © 2014 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include "glamor_priv.h" +#include "glamor_program.h" +#include "glamor_transform.h" +#include "glamor_prepare.h" + +static const glamor_facet glamor_facet_poly_segment = { + .name = "poly_segment", + .vs_vars = "attribute vec2 primitive;\n", + .vs_exec = (" vec2 pos = vec2(0.0,0.0);\n" + GLAMOR_POS(gl_Position, primitive.xy)), +}; + +static Bool +glamor_poly_segment_gl(DrawablePtr drawable, GCPtr gc, + int nseg, xSegment *segs) +{ + ScreenPtr screen = drawable->pScreen; + glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); + PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable); + glamor_pixmap_private *pixmap_priv; + glamor_program *prog; + int off_x, off_y; + xSegment *v; + char *vbo_offset; + int box_x, box_y; + int add_last; + + pixmap_priv = glamor_get_pixmap_private(pixmap); + if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)) + goto bail; + + if (gc->lineWidth != 0) + goto bail; + + if (gc->lineStyle != LineSolid) + goto bail; + + add_last = 0; + if (gc->capStyle != CapNotLast) + add_last = 1; + + glamor_make_current(glamor_priv); + + prog = glamor_use_program_fill(pixmap, gc, + &glamor_priv->poly_segment_program, + &glamor_facet_poly_segment); + + if (!prog) + goto bail_ctx; + + /* Set up the vertex buffers for the points */ + + v = glamor_get_vbo_space(drawable->pScreen, + (nseg << add_last) * sizeof (xSegment), + &vbo_offset); + + glEnableVertexAttribArray(GLAMOR_VERTEX_POS); + glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT, GL_FALSE, + sizeof(DDXPointRec), vbo_offset); + + if (add_last) { + int i, j; + for (i = 0, j=0; i < nseg; i++) { + v[j++] = segs[i]; + v[j].x1 = segs[i].x2; + v[j].y1 = segs[i].y2; + v[j].x2 = segs[i].x2+1; + v[j].y2 = segs[i].y2; + j++; + } + } else + memcpy(v, segs, nseg * sizeof (xSegment)); + + glamor_put_vbo_space(screen); + + glEnable(GL_SCISSOR_TEST); + + glamor_pixmap_loop(pixmap_priv, box_x, box_y) { + int nbox = RegionNumRects(gc->pCompositeClip); + BoxPtr box = RegionRects(gc->pCompositeClip); + + glamor_set_destination_drawable(drawable, box_x, box_y, TRUE, TRUE, + prog->matrix_uniform, &off_x, &off_y); + + while (nbox--) { + glScissor(box->x1 + off_x, + box->y1 + off_y, + box->x2 - box->x1, + box->y2 - box->y1); + box++; + glDrawArrays(GL_LINES, 0, nseg << (1 + add_last)); + } + } + + glDisable(GL_SCISSOR_TEST); + glDisable(GL_COLOR_LOGIC_OP); + glDisableVertexAttribArray(GLAMOR_VERTEX_POS); + + return TRUE; +bail_ctx: + glDisable(GL_COLOR_LOGIC_OP); +bail: + return FALSE; +} + +static void +glamor_poly_segment_bail(DrawablePtr drawable, GCPtr gc, + int nseg, xSegment *segs) +{ + glamor_fallback("to %p (%c)\n", drawable, + glamor_get_drawable_location(drawable)); + + if (gc->lineWidth == 0) { + if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW) && + glamor_prepare_access_gc(gc)) { + fbPolySegment(drawable, gc, nseg, segs); + } + glamor_finish_access_gc(gc); + glamor_finish_access(drawable); + } else + miPolySegment(drawable, gc, nseg, segs); +} + + +void +glamor_poly_segment(DrawablePtr drawable, GCPtr gc, + int nseg, xSegment *segs) +{ + if (glamor_poly_segment_gl(drawable, gc, nseg, segs)) + return; + + glamor_poly_segment_bail(drawable, gc, nseg, segs); +} + +Bool +glamor_poly_segment_nf(DrawablePtr drawable, GCPtr gc, + int nseg, xSegment *segs) +{ + if (glamor_poly_segment_gl(drawable, gc, nseg, segs)) + return TRUE; + + if (glamor_ddx_fallback_check_pixmap(drawable) && + glamor_ddx_fallback_check_gc(gc)) + { + return FALSE; + } + + glamor_poly_segment_bail(drawable, gc, nseg, segs); + return TRUE; +} + -- cgit v1.2.3