2014-09-27 11:52:59 -06:00
|
|
|
/*
|
|
|
|
* 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@gmail.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "glamor_priv.h"
|
|
|
|
#include <dixfontstr.h>
|
|
|
|
#include "glamor_transform.h"
|
|
|
|
|
|
|
|
static const glamor_facet glamor_facet_poly_glyph_blt = {
|
|
|
|
.name = "poly_glyph_blt",
|
|
|
|
.vs_vars = "attribute vec2 primitive;\n",
|
|
|
|
.vs_exec = (" vec2 pos = vec2(0,0);\n"
|
|
|
|
GLAMOR_POS(gl_Position, primitive)),
|
|
|
|
};
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
glamor_poly_glyph_blt_gl(DrawablePtr drawable, GCPtr gc,
|
|
|
|
int start_x, int y, unsigned int nglyph,
|
|
|
|
CharInfoPtr *ppci, void *pglyph_base)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
RegionPtr clip = gc->pCompositeClip;
|
2016-05-29 06:02:34 -06:00
|
|
|
int box_index;
|
2017-12-08 08:01:59 -07:00
|
|
|
Bool ret = FALSE;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
|
|
|
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
|
|
|
|
goto bail;
|
|
|
|
|
|
|
|
glamor_make_current(glamor_priv);
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
prog = glamor_use_program_fill(pixmap, gc,
|
|
|
|
&glamor_priv->poly_glyph_blt_progs,
|
2014-09-27 11:52:59 -06:00
|
|
|
&glamor_facet_poly_glyph_blt);
|
|
|
|
if (!prog)
|
2016-05-29 06:02:34 -06:00
|
|
|
goto bail;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
|
|
|
|
|
|
|
|
start_x += drawable->x;
|
|
|
|
y += drawable->y;
|
|
|
|
|
2016-05-29 06:02:34 -06:00
|
|
|
glamor_pixmap_loop(pixmap_priv, box_index) {
|
2014-09-27 11:52:59 -06:00
|
|
|
int x;
|
|
|
|
int n;
|
|
|
|
int num_points, max_points;
|
|
|
|
INT16 *points = NULL;
|
|
|
|
int off_x, off_y;
|
|
|
|
char *vbo_offset;
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
if (!glamor_set_destination_drawable(drawable, box_index, FALSE, TRUE,
|
|
|
|
prog->matrix_uniform, &off_x, &off_y))
|
|
|
|
goto bail;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
max_points = 500;
|
|
|
|
num_points = 0;
|
|
|
|
x = start_x;
|
|
|
|
for (n = 0; n < nglyph; n++) {
|
|
|
|
CharInfoPtr charinfo = ppci[n];
|
|
|
|
int w = GLYPHWIDTHPIXELS(charinfo);
|
|
|
|
int h = GLYPHHEIGHTPIXELS(charinfo);
|
|
|
|
uint8_t *glyphbits = FONTGLYPHBITS(NULL, charinfo);
|
|
|
|
|
|
|
|
if (w && h) {
|
|
|
|
int glyph_x = x + charinfo->metrics.leftSideBearing;
|
|
|
|
int glyph_y = y - charinfo->metrics.ascent;
|
|
|
|
int glyph_stride = GLYPHWIDTHBYTESPADDED(charinfo);
|
|
|
|
int xx, yy;
|
|
|
|
|
|
|
|
for (yy = 0; yy < h; yy++) {
|
|
|
|
uint8_t *glyph = glyphbits;
|
|
|
|
for (xx = 0; xx < w; glyph += ((xx&7) == 7), xx++) {
|
|
|
|
int pt_x_i = glyph_x + xx;
|
|
|
|
int pt_y_i = glyph_y + yy;
|
|
|
|
|
|
|
|
if (!(*glyph & (1 << (xx & 7))))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!RegionContainsPoint(clip, pt_x_i, pt_y_i, NULL))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!num_points) {
|
|
|
|
points = glamor_get_vbo_space(screen,
|
2015-09-16 13:10:19 -06:00
|
|
|
max_points *
|
|
|
|
(2 * sizeof (INT16)),
|
2014-09-27 11:52:59 -06:00
|
|
|
&vbo_offset);
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
glVertexAttribPointer(GLAMOR_VERTEX_POS,
|
|
|
|
2, GL_SHORT,
|
2014-09-27 11:52:59 -06:00
|
|
|
GL_FALSE, 0, vbo_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
*points++ = pt_x_i;
|
|
|
|
*points++ = pt_y_i;
|
|
|
|
num_points++;
|
|
|
|
|
|
|
|
if (num_points == max_points) {
|
|
|
|
glamor_put_vbo_space(screen);
|
|
|
|
glDrawArrays(GL_POINTS, 0, num_points);
|
|
|
|
num_points = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
glyphbits += glyph_stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x += charinfo->metrics.characterWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_points) {
|
|
|
|
glamor_put_vbo_space(screen);
|
|
|
|
glDrawArrays(GL_POINTS, 0, num_points);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
ret = TRUE;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
bail:
|
2017-12-08 08:01:59 -07:00
|
|
|
glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
|
|
|
|
|
|
|
|
return ret;
|
2014-09-27 11:52:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
glamor_poly_glyph_blt(DrawablePtr drawable, GCPtr gc,
|
|
|
|
int start_x, int y, unsigned int nglyph,
|
|
|
|
CharInfoPtr *ppci, void *pglyph_base)
|
|
|
|
{
|
2015-09-16 13:10:19 -06:00
|
|
|
if (glamor_poly_glyph_blt_gl(drawable, gc, start_x, y, nglyph, ppci,
|
|
|
|
pglyph_base))
|
2014-09-27 11:52:59 -06:00
|
|
|
return;
|
|
|
|
miPolyGlyphBlt(drawable, gc, start_x, y, nglyph,
|
|
|
|
ppci, pglyph_base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
2015-09-16 13:10:19 -06:00
|
|
|
glamor_push_pixels_gl(GCPtr gc, PixmapPtr bitmap,
|
|
|
|
DrawablePtr drawable, int w, int h, int x, int y)
|
2014-09-27 11:52:59 -06:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
uint8_t *bitmap_data = bitmap->devPrivate.ptr;
|
|
|
|
int bitmap_stride = bitmap->devKind;
|
2015-09-16 13:10:19 -06:00
|
|
|
glamor_program *prog;
|
|
|
|
RegionPtr clip = gc->pCompositeClip;
|
2016-05-29 06:02:34 -06:00
|
|
|
int box_index;
|
2014-09-27 11:52:59 -06:00
|
|
|
int yy, xx;
|
2015-09-16 13:10:19 -06:00
|
|
|
int num_points;
|
|
|
|
INT16 *points = NULL;
|
2014-09-27 11:52:59 -06:00
|
|
|
char *vbo_offset;
|
2017-12-08 08:01:59 -07:00
|
|
|
Bool ret = FALSE;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
if (w * h > MAXINT / (2 * sizeof(float)))
|
2015-09-16 13:10:19 -06:00
|
|
|
goto bail;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
pixmap_priv = glamor_get_pixmap_private(pixmap);
|
|
|
|
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
|
2015-09-16 13:10:19 -06:00
|
|
|
goto bail;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
glamor_make_current(glamor_priv);
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
prog = glamor_use_program_fill(pixmap, gc,
|
|
|
|
&glamor_priv->poly_glyph_blt_progs,
|
|
|
|
&glamor_facet_poly_glyph_blt);
|
|
|
|
if (!prog)
|
2016-05-29 06:02:34 -06:00
|
|
|
goto bail;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
|
2014-09-27 11:52:59 -06:00
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
points = glamor_get_vbo_space(screen, w * h * sizeof(INT16) * 2,
|
2014-09-27 11:52:59 -06:00
|
|
|
&vbo_offset);
|
2015-09-16 13:10:19 -06:00
|
|
|
num_points = 0;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
/* Note that because fb sets miTranslate in the GC, our incoming X
|
|
|
|
* and Y are in screen coordinate space (same for spans, but not
|
|
|
|
* other operations).
|
|
|
|
*/
|
2015-09-16 13:10:19 -06:00
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
for (yy = 0; yy < h; yy++) {
|
|
|
|
uint8_t *bitmap_row = bitmap_data + yy * bitmap_stride;
|
|
|
|
for (xx = 0; xx < w; xx++) {
|
|
|
|
if (bitmap_row[xx / 8] & (1 << xx % 8) &&
|
|
|
|
RegionContainsPoint(clip,
|
|
|
|
x + xx,
|
|
|
|
y + yy,
|
|
|
|
NULL)) {
|
2015-09-16 13:10:19 -06:00
|
|
|
*points++ = x + xx;
|
|
|
|
*points++ = y + yy;
|
2014-09-27 11:52:59 -06:00
|
|
|
num_points++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-16 13:10:19 -06:00
|
|
|
glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT,
|
|
|
|
GL_FALSE, 0, vbo_offset);
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
glamor_put_vbo_space(screen);
|
|
|
|
|
2016-05-29 06:02:34 -06:00
|
|
|
glamor_pixmap_loop(pixmap_priv, box_index) {
|
2017-12-08 08:01:59 -07:00
|
|
|
if (!glamor_set_destination_drawable(drawable, box_index, FALSE, TRUE,
|
|
|
|
prog->matrix_uniform, NULL, NULL))
|
|
|
|
goto bail;
|
2014-09-27 11:52:59 -06:00
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
glDrawArrays(GL_POINTS, 0, num_points);
|
2014-09-27 11:52:59 -06:00
|
|
|
}
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
ret = TRUE;
|
2015-09-16 13:10:19 -06:00
|
|
|
|
|
|
|
bail:
|
2017-12-08 08:01:59 -07:00
|
|
|
glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
|
|
|
|
|
|
|
|
return ret;
|
2014-09-27 11:52:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
glamor_push_pixels(GCPtr pGC, PixmapPtr pBitmap,
|
|
|
|
DrawablePtr pDrawable, int w, int h, int x, int y)
|
|
|
|
{
|
2015-09-16 13:10:19 -06:00
|
|
|
if (glamor_push_pixels_gl(pGC, pBitmap, pDrawable, w, h, x, y))
|
|
|
|
return;
|
|
|
|
|
|
|
|
miPushPixels(pGC, pBitmap, pDrawable, w, h, x, y);
|
2014-09-27 11:52:59 -06:00
|
|
|
}
|