Commit 07f0d90e authored by Eric Anholt's avatar Eric Anholt

glamor: Simplify the pixmap box looping.

We had a double loop across h and w, and passed the current x and y
out to callers who then used w to multiply/add to an index.  Instead,
just single loop across w * h.
Signed-off-by: Eric Anholt's avatarEric Anholt <eric@anholt.net>
Reviewed-by: default avatarDave Airlie <airlied@redhat.com>
Reviewed-by: Kenneth Graunke's avatarKenneth Graunke <kenneth@whitecape.org>
parent 0dbce65b
......@@ -237,10 +237,10 @@ glamor_glyphs_flush(CARD8 op, PicturePtr src, PicturePtr dst,
glamor_screen_private *glamor_priv = glamor_get_screen_private(drawable->pScreen);
PixmapPtr atlas_pixmap = atlas->atlas;
glamor_pixmap_private *atlas_priv = glamor_get_pixmap_private(atlas_pixmap);
glamor_pixmap_fbo *atlas_fbo = glamor_pixmap_fbo_at(atlas_priv, 0, 0);
glamor_pixmap_fbo *atlas_fbo = glamor_pixmap_fbo_at(atlas_priv, 0);
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
int box_x, box_y;
int box_index;
int off_x, off_y;
glamor_put_vbo_space(drawable->pScreen);
......@@ -255,11 +255,13 @@ glamor_glyphs_flush(CARD8 op, PicturePtr src, PicturePtr dst,
glUniform1i(prog->atlas_uniform, 1);
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
glamor_pixmap_loop(pixmap_priv, box_index) {
BoxPtr box = RegionRects(dst->pCompositeClip);
int nbox = RegionNumRects(dst->pCompositeClip);
glamor_set_destination_drawable(drawable, box_x, box_y, TRUE, FALSE, prog->matrix_uniform, &off_x, &off_y);
glamor_set_destination_drawable(drawable, box_index, TRUE, FALSE,
prog->matrix_uniform,
&off_x, &off_y);
/* Run over the clip list, drawing the glyphs
* in each box
......
......@@ -307,7 +307,7 @@ glamor_copy_fbo_fbo_draw(DrawablePtr src,
PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
glamor_pixmap_private *src_priv = glamor_get_pixmap_private(src_pixmap);
glamor_pixmap_private *dst_priv = glamor_get_pixmap_private(dst_pixmap);
int src_box_x, src_box_y, dst_box_x, dst_box_y;
int src_box_index, dst_box_index;
int dst_off_x, dst_off_y;
int src_off_x, src_off_y;
GLshort *v;
......@@ -368,19 +368,20 @@ glamor_copy_fbo_fbo_draw(DrawablePtr src,
glEnable(GL_SCISSOR_TEST);
glamor_pixmap_loop(src_priv, src_box_x, src_box_y) {
BoxPtr src_box = glamor_pixmap_box_at(src_priv, src_box_x, src_box_y);
glamor_pixmap_loop(src_priv, src_box_index) {
BoxPtr src_box = glamor_pixmap_box_at(src_priv, src_box_index);
args.dx = dx + src_off_x - src_box->x1;
args.dy = dy + src_off_y - src_box->y1;
args.src = glamor_pixmap_fbo_at(src_priv, src_box_x, src_box_y);
args.src = glamor_pixmap_fbo_at(src_priv, src_box_index);
if (!glamor_use_program(dst_pixmap, gc, prog, &args))
goto bail_ctx;
glamor_pixmap_loop(dst_priv, dst_box_x, dst_box_y) {
glamor_set_destination_drawable(dst, dst_box_x, dst_box_y, FALSE, FALSE,
prog->matrix_uniform, &dst_off_x, &dst_off_y);
glamor_pixmap_loop(dst_priv, dst_box_index) {
glamor_set_destination_drawable(dst, dst_box_index, FALSE, FALSE,
prog->matrix_uniform,
&dst_off_x, &dst_off_y);
glScissor(dst_off_x - args.dx,
dst_off_y - args.dy,
......
......@@ -205,16 +205,16 @@ glamor_dash_loop(DrawablePtr drawable, GCPtr gc, glamor_program *prog,
{
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
int box_x, box_y;
int box_index;
int off_x, off_y;
glEnable(GL_SCISSOR_TEST);
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
glamor_pixmap_loop(pixmap_priv, box_index) {
int nbox = RegionNumRects(gc->pCompositeClip);
BoxPtr box = RegionRects(gc->pCompositeClip);
glamor_set_destination_drawable(drawable, box_x, box_y, TRUE, TRUE,
glamor_set_destination_drawable(drawable, box_index, TRUE, TRUE,
prog->matrix_uniform, &off_x, &off_y);
while (nbox--) {
......
......@@ -48,7 +48,7 @@ glamor_poly_glyph_blt_gl(DrawablePtr drawable, GCPtr gc,
glamor_pixmap_private *pixmap_priv;
glamor_program *prog;
RegionPtr clip = gc->pCompositeClip;
int box_x, box_y;
int box_index;
pixmap_priv = glamor_get_pixmap_private(pixmap);
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
......@@ -67,7 +67,7 @@ glamor_poly_glyph_blt_gl(DrawablePtr drawable, GCPtr gc,
start_x += drawable->x;
y += drawable->y;
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
glamor_pixmap_loop(pixmap_priv, box_index) {
int x;
int n;
int num_points, max_points;
......@@ -75,7 +75,7 @@ glamor_poly_glyph_blt_gl(DrawablePtr drawable, GCPtr gc,
int off_x, off_y;
char *vbo_offset;
glamor_set_destination_drawable(drawable, box_x, box_y, FALSE, TRUE,
glamor_set_destination_drawable(drawable, box_index, FALSE, TRUE,
prog->matrix_uniform, &off_x, &off_y);
max_points = 500;
......@@ -169,7 +169,7 @@ glamor_push_pixels_gl(GCPtr gc, PixmapPtr bitmap,
int bitmap_stride = bitmap->devKind;
glamor_program *prog;
RegionPtr clip = gc->pCompositeClip;
int box_x, box_y;
int box_index;
int yy, xx;
int num_points;
INT16 *points = NULL;
......@@ -220,8 +220,8 @@ glamor_push_pixels_gl(GCPtr gc, PixmapPtr bitmap,
glamor_put_vbo_space(screen);
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
glamor_set_destination_drawable(drawable, box_x, box_y, FALSE, TRUE,
glamor_pixmap_loop(pixmap_priv, box_index) {
glamor_set_destination_drawable(drawable, box_index, FALSE, TRUE,
prog->matrix_uniform, NULL, NULL);
glDrawArrays(GL_POINTS, 0, num_points);
......
......@@ -44,7 +44,7 @@ glamor_poly_lines_solid_gl(DrawablePtr drawable, GCPtr gc,
int off_x, off_y;
DDXPointPtr v;
char *vbo_offset;
int box_x, box_y;
int box_index;
int add_last;
pixmap_priv = glamor_get_pixmap_private(pixmap);
......@@ -99,11 +99,11 @@ glamor_poly_lines_solid_gl(DrawablePtr drawable, GCPtr gc,
glEnable(GL_SCISSOR_TEST);
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
glamor_pixmap_loop(pixmap_priv, box_index) {
int nbox = RegionNumRects(gc->pCompositeClip);
BoxPtr box = RegionRects(gc->pCompositeClip);
glamor_set_destination_drawable(drawable, box_x, box_y, TRUE, TRUE,
glamor_set_destination_drawable(drawable, box_index, TRUE, TRUE,
prog->matrix_uniform, &off_x, &off_y);
while (nbox--) {
......
......@@ -46,7 +46,7 @@ glamor_poly_point_gl(DrawablePtr drawable, GCPtr gc, int mode, int npt, DDXPoint
int off_x, off_y;
GLshort *vbo_ppt;
char *vbo_offset;
int box_x, box_y;
int box_index;
pixmap_priv = glamor_get_pixmap_private(pixmap);
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
......@@ -86,11 +86,12 @@ glamor_poly_point_gl(DrawablePtr drawable, GCPtr gc, int mode, int npt, DDXPoint
glEnable(GL_SCISSOR_TEST);
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
glamor_pixmap_loop(pixmap_priv, box_index) {
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);
glamor_set_destination_drawable(drawable, box_index, TRUE, TRUE,
prog->matrix_uniform, &off_x, &off_y);
while (nbox--) {
glScissor(box->x1 + off_x,
......
......@@ -485,19 +485,17 @@ glamor_set_pixmap_fbo_current(glamor_pixmap_private *priv, int idx)
}
static inline glamor_pixmap_fbo *
glamor_pixmap_fbo_at(glamor_pixmap_private *priv, int x, int y)
glamor_pixmap_fbo_at(glamor_pixmap_private *priv, int box)
{
assert(x < priv->block_wcnt);
assert(y < priv->block_hcnt);
return priv->fbo_array[y * priv->block_wcnt + x];
assert(box < priv->block_wcnt * priv->block_hcnt);
return priv->fbo_array[box];
}
static inline BoxPtr
glamor_pixmap_box_at(glamor_pixmap_private *priv, int x, int y)
glamor_pixmap_box_at(glamor_pixmap_private *priv, int box)
{
assert(x < priv->block_wcnt);
assert(y < priv->block_hcnt);
return &priv->box_array[y * priv->block_wcnt + x];
assert(box < priv->block_wcnt * priv->block_hcnt);
return &priv->box_array[box];
}
static inline int
......@@ -512,9 +510,9 @@ glamor_pixmap_hcnt(glamor_pixmap_private *priv)
return priv->block_hcnt;
}
#define glamor_pixmap_loop(priv, x, y) \
for (y = 0; y < glamor_pixmap_hcnt(priv); y++) \
for (x = 0; x < glamor_pixmap_wcnt(priv); x++)
#define glamor_pixmap_loop(priv, box_index) \
for (box_index = 0; box_index < glamor_pixmap_hcnt(priv) * \
glamor_pixmap_wcnt(priv); box_index++) \
/**
* Pixmap upload status, used by glamor_render.c's support for
......
......@@ -51,7 +51,7 @@ glamor_poly_fill_rect_gl(DrawablePtr drawable,
int off_x, off_y;
GLshort *v;
char *vbo_offset;
int box_x, box_y;
int box_index;
pixmap_priv = glamor_get_pixmap_private(pixmap);
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
......@@ -111,11 +111,12 @@ glamor_poly_fill_rect_gl(DrawablePtr drawable,
glEnable(GL_SCISSOR_TEST);
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
glamor_pixmap_loop(pixmap_priv, box_index) {
int nbox = RegionNumRects(gc->pCompositeClip);
BoxPtr box = RegionRects(gc->pCompositeClip);
glamor_set_destination_drawable(drawable, box_x, box_y, TRUE, FALSE, prog->matrix_uniform, &off_x, &off_y);
glamor_set_destination_drawable(drawable, box_index, TRUE, FALSE,
prog->matrix_uniform, &off_x, &off_y);
while (nbox--) {
glScissor(box->x1 + off_x,
......
......@@ -44,7 +44,7 @@ glamor_poly_segment_solid_gl(DrawablePtr drawable, GCPtr gc,
int off_x, off_y;
xSegment *v;
char *vbo_offset;
int box_x, box_y;
int box_index;
int add_last;
pixmap_priv = glamor_get_pixmap_private(pixmap);
......@@ -91,11 +91,11 @@ glamor_poly_segment_solid_gl(DrawablePtr drawable, GCPtr gc,
glEnable(GL_SCISSOR_TEST);
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
glamor_pixmap_loop(pixmap_priv, box_index) {
int nbox = RegionNumRects(gc->pCompositeClip);
BoxPtr box = RegionRects(gc->pCompositeClip);
glamor_set_destination_drawable(drawable, box_x, box_y, TRUE, TRUE,
glamor_set_destination_drawable(drawable, box_index, TRUE, TRUE,
prog->matrix_uniform, &off_x, &off_y);
while (nbox--) {
......
......@@ -55,7 +55,7 @@ glamor_fill_spans_gl(DrawablePtr drawable,
GLshort *v;
char *vbo_offset;
int c;
int box_x, box_y;
int box_index;
pixmap_priv = glamor_get_pixmap_private(pixmap);
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
......@@ -119,11 +119,12 @@ glamor_fill_spans_gl(DrawablePtr drawable,
glEnable(GL_SCISSOR_TEST);
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
glamor_pixmap_loop(pixmap_priv, box_index) {
int nbox = RegionNumRects(gc->pCompositeClip);
BoxPtr box = RegionRects(gc->pCompositeClip);
glamor_set_destination_drawable(drawable, box_x, box_y, FALSE, FALSE, prog->matrix_uniform, &off_x, &off_y);
glamor_set_destination_drawable(drawable, box_index, FALSE, FALSE,
prog->matrix_uniform, &off_x, &off_y);
while (nbox--) {
glScissor(box->x1 + off_x,
......@@ -180,7 +181,7 @@ glamor_get_spans_gl(DrawablePtr drawable, int wmax,
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
glamor_pixmap_private *pixmap_priv;
int box_x, box_y;
int box_index;
int n;
char *d;
GLenum type;
......@@ -197,9 +198,9 @@ glamor_get_spans_gl(DrawablePtr drawable, int wmax,
glamor_make_current(glamor_priv);
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
BoxPtr box = glamor_pixmap_box_at(pixmap_priv, box_x, box_y);
glamor_pixmap_fbo *fbo = glamor_pixmap_fbo_at(pixmap_priv, box_x, box_y);
glamor_pixmap_loop(pixmap_priv, box_index) {
BoxPtr box = glamor_pixmap_box_at(pixmap_priv, box_index);
glamor_pixmap_fbo *fbo = glamor_pixmap_fbo_at(pixmap_priv, box_index);
glBindFramebuffer(GL_FRAMEBUFFER, fbo->fb);
glPixelStorei(GL_PACK_ALIGNMENT, 4);
......@@ -265,7 +266,7 @@ glamor_set_spans_gl(DrawablePtr drawable, GCPtr gc, char *src,
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
glamor_pixmap_private *pixmap_priv;
int box_x, box_y;
int box_index;
int n;
char *s;
GLenum type;
......@@ -289,9 +290,9 @@ glamor_set_spans_gl(DrawablePtr drawable, GCPtr gc, char *src,
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
BoxPtr box = glamor_pixmap_box_at(pixmap_priv, box_x, box_y);
glamor_pixmap_fbo *fbo = glamor_pixmap_fbo_at(pixmap_priv, box_x, box_y);
glamor_pixmap_loop(pixmap_priv, box_index) {
BoxPtr box = glamor_pixmap_box_at(pixmap_priv, box_index);
glamor_pixmap_fbo *fbo = glamor_pixmap_fbo_at(pixmap_priv, box_index);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, fbo->tex);
......
......@@ -107,7 +107,7 @@ glamor_text(DrawablePtr drawable, GCPtr gc,
int firstCol = font->info.firstCol;
int glyph_spacing_x = glamor_font->glyph_width_bytes * 8;
int glyph_spacing_y = glamor_font->glyph_height;
int box_x, box_y;
int box_index;
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
......@@ -188,11 +188,13 @@ glamor_text(DrawablePtr drawable, GCPtr gc,
glEnable(GL_SCISSOR_TEST);
glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
glamor_pixmap_loop(pixmap_priv, box_index) {
BoxPtr box = RegionRects(gc->pCompositeClip);
int nbox = RegionNumRects(gc->pCompositeClip);
glamor_set_destination_drawable(drawable, box_x, box_y, TRUE, FALSE, prog->matrix_uniform, &off_x, &off_y);
glamor_set_destination_drawable(drawable, box_index, TRUE, FALSE,
prog->matrix_uniform,
&off_x, &off_y);
/* Run over the clip list, drawing the glyphs
* in each box
......
......@@ -63,7 +63,7 @@ glamor_upload_boxes(PixmapPtr pixmap, BoxPtr in_boxes, int in_nbox,
ScreenPtr screen = pixmap->drawable.pScreen;
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
int box_x, box_y;
int box_index;
int bytes_per_pixel = pixmap->drawable.bitsPerPixel >> 3;
GLenum type;
GLenum format;
......@@ -77,9 +77,9 @@ glamor_upload_boxes(PixmapPtr pixmap, BoxPtr in_boxes, int in_nbox,
if (glamor_priv->has_unpack_subimage)
glPixelStorei(GL_UNPACK_ROW_LENGTH, byte_stride / bytes_per_pixel);
glamor_pixmap_loop(priv, box_x, box_y) {
BoxPtr box = glamor_pixmap_box_at(priv, box_x, box_y);
glamor_pixmap_fbo *fbo = glamor_pixmap_fbo_at(priv, box_x, box_y);
glamor_pixmap_loop(priv, box_index) {
BoxPtr box = glamor_pixmap_box_at(priv, box_index);
glamor_pixmap_fbo *fbo = glamor_pixmap_fbo_at(priv, box_index);
BoxPtr boxes = in_boxes;
int nbox = in_nbox;
......@@ -167,7 +167,7 @@ glamor_download_boxes(PixmapPtr pixmap, BoxPtr in_boxes, int in_nbox,
ScreenPtr screen = pixmap->drawable.pScreen;
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
int box_x, box_y;
int box_index;
int bytes_per_pixel = pixmap->drawable.bitsPerPixel >> 3;
GLenum type;
GLenum format;
......@@ -180,9 +180,9 @@ glamor_download_boxes(PixmapPtr pixmap, BoxPtr in_boxes, int in_nbox,
if (glamor_priv->has_pack_subimage)
glPixelStorei(GL_PACK_ROW_LENGTH, byte_stride / bytes_per_pixel);
glamor_pixmap_loop(priv, box_x, box_y) {
BoxPtr box = glamor_pixmap_box_at(priv, box_x, box_y);
glamor_pixmap_fbo *fbo = glamor_pixmap_fbo_at(priv, box_x, box_y);
glamor_pixmap_loop(priv, box_index) {
BoxPtr box = glamor_pixmap_box_at(priv, box_index);
glamor_pixmap_fbo *fbo = glamor_pixmap_fbo_at(priv, box_index);
BoxPtr boxes = in_boxes;
int nbox = in_nbox;
......
......@@ -35,8 +35,7 @@
void
glamor_set_destination_drawable(DrawablePtr drawable,
int box_x,
int box_y,
int box_index,
Bool do_drawable_translate,
Bool center_offset,
GLint matrix_uniform_location,
......@@ -48,7 +47,7 @@ glamor_set_destination_drawable(DrawablePtr drawable,
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
int off_x, off_y;
BoxPtr box = glamor_pixmap_box_at(pixmap_priv, box_x, box_y);
BoxPtr box = glamor_pixmap_box_at(pixmap_priv, box_index);
int w = box->x2 - box->x1;
int h = box->y2 - box->y1;
float scale_x = 2.0f / (float) w;
......@@ -95,7 +94,7 @@ glamor_set_destination_drawable(DrawablePtr drawable,
scale_x, (off_x + center_adjust) * scale_x - 1.0f,
scale_y, (off_y + center_adjust) * scale_y - 1.0f);
glamor_set_destination_pixmap_fbo(glamor_priv, glamor_pixmap_fbo_at(pixmap_priv, box_x, box_y),
glamor_set_destination_pixmap_fbo(glamor_priv, glamor_pixmap_fbo_at(pixmap_priv, box_index),
0, 0, w, h);
}
......
......@@ -25,8 +25,7 @@
void
glamor_set_destination_drawable(DrawablePtr drawable,
int box_x,
int box_y,
int box_index,
Bool do_drawable_translate,
Bool center_offset,
GLint matrix_uniform_location,
......
......@@ -258,7 +258,7 @@ glamor_xv_render(glamor_port_private *port_priv)
GLint uloc;
GLfloat *v;
char *vbo_offset;
int dst_box_x, dst_box_y;
int dst_box_index;
if (!glamor_priv->xv_prog.prog)
glamor_init_xv_shader(screen);
......@@ -368,11 +368,11 @@ glamor_xv_render(glamor_port_private *port_priv)
glamor_put_vbo_space(screen);
/* Now draw our big triangle, clipped to each of the clip boxes. */
glamor_pixmap_loop(pixmap_priv, dst_box_x, dst_box_y) {
glamor_pixmap_loop(pixmap_priv, dst_box_index) {
int dst_off_x, dst_off_y;
glamor_set_destination_drawable(port_priv->pDraw,
dst_box_x, dst_box_y,
dst_box_index,
FALSE, FALSE,
glamor_priv->xv_prog.matrix_uniform,
&dst_off_x, &dst_off_y);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment