From 81692804645394b43832c8ec586e8e67f3e4f606 Mon Sep 17 00:00:00 2001 From: Zhigang Gong Date: Tue, 15 May 2012 15:25:41 +0800 Subject: [PATCH] glamor_set_destination_pixmap_priv_nc: set drawable's width x height. Previous implementation set the whole fbo's width and height as the viewpoint. This may increase the numerical error as we may only has a partial region as the valid pixmap. So add a new marco pixmap_priv_get_dest_scale to get proper scale factor for the destination pixmap. For the source/mask pixmap, we still need to consider the whole fbo's size. Signed-off-by: Zhigang Gong --- glamor/glamor_copyarea.c | 4 +--- glamor/glamor_fill.c | 2 +- glamor/glamor_pixmap.c | 19 ++++++++++--------- glamor/glamor_priv.h | 2 +- glamor/glamor_render.c | 4 ++-- glamor/glamor_tile.c | 2 +- glamor/glamor_utils.h | 6 ++++++ 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/glamor/glamor_copyarea.c b/glamor/glamor_copyarea.c index 3bb077cee..356e0f9b6 100644 --- a/glamor/glamor_copyarea.c +++ b/glamor/glamor_copyarea.c @@ -183,7 +183,7 @@ glamor_copy_n_to_n_textured(DrawablePtr src, alu = gc->alu; } - pixmap_priv_get_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale); + pixmap_priv_get_dest_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale); pixmap_priv_get_scale(src_pixmap_priv, &src_xscale, &src_yscale); glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, @@ -206,8 +206,6 @@ glamor_copy_n_to_n_textured(DrawablePtr src, &src_y_off); dx += src_x_off; dy += src_y_off; - pixmap_priv_get_scale(src_pixmap_priv, &src_xscale, - &src_yscale); dispatch->glActiveTexture(GL_TEXTURE0); dispatch->glBindTexture(GL_TEXTURE_2D, diff --git a/glamor/glamor_fill.c b/glamor/glamor_fill.c index 072408e80..57dd69851 100644 --- a/glamor/glamor_fill.c +++ b/glamor/glamor_fill.c @@ -237,7 +237,7 @@ glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height, GL_FALSE, 2 * sizeof(float), vertices); dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); - pixmap_priv_get_scale(pixmap_priv, &xscale, &yscale); + pixmap_priv_get_dest_scale(pixmap_priv, &xscale, &yscale); glamor_set_normalize_vcoords(xscale, yscale, x1, y1, x2, y2, glamor_priv->yInverted, vertices); diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c index 3f268d989..f0c158676 100644 --- a/glamor/glamor_pixmap.c +++ b/glamor/glamor_pixmap.c @@ -64,7 +64,7 @@ glamor_pixmap_fini(ScreenPtr screen) } void -glamor_set_destination_pixmap_fbo(glamor_pixmap_fbo * fbo) +glamor_set_destination_pixmap_fbo(glamor_pixmap_fbo * fbo, int x0, int y0, int width, int height) { glamor_gl_dispatch *dispatch = glamor_get_dispatch(fbo->glamor_priv); dispatch->glBindFramebuffer(GL_FRAMEBUFFER, fbo->fb); @@ -74,9 +74,8 @@ glamor_set_destination_pixmap_fbo(glamor_pixmap_fbo * fbo) dispatch->glMatrixMode(GL_MODELVIEW); dispatch->glLoadIdentity(); #endif - dispatch->glViewport(0, 0, - fbo->width, - fbo->height); + dispatch->glViewport(x0, y0, + width, height); glamor_put_dispatch(fbo->glamor_priv); } @@ -84,7 +83,9 @@ glamor_set_destination_pixmap_fbo(glamor_pixmap_fbo * fbo) void glamor_set_destination_pixmap_priv_nc(glamor_pixmap_private * pixmap_priv) { - glamor_set_destination_pixmap_fbo(pixmap_priv->fbo); + glamor_set_destination_pixmap_fbo(pixmap_priv->fbo, 0, 0, + pixmap_priv->container->drawable.width, + pixmap_priv->container->drawable.height); } int @@ -507,7 +508,7 @@ ready_to_upload: else ptexcoords = texcoords_inv; - pixmap_priv_get_scale(pixmap_priv, &dst_xscale, &dst_yscale); + pixmap_priv_get_dest_scale(pixmap_priv, &dst_xscale, &dst_yscale); glamor_set_normalize_vcoords(dst_xscale, dst_yscale, x, y, @@ -733,8 +734,8 @@ glamor_es2_pixmap_read_prepare(PixmapPtr source, int x, int y, int w, int h, GLe return NULL; dispatch = glamor_get_dispatch(glamor_priv); - temp_xscale = 1.0 / temp_fbo->width; - temp_yscale = 1.0 / temp_fbo->height; + temp_xscale = 1.0 / w; + temp_yscale = 1.0 / h; glamor_set_normalize_vcoords(temp_xscale, temp_yscale, @@ -770,7 +771,7 @@ glamor_es2_pixmap_read_prepare(PixmapPtr source, int x, int y, int w, int h, GLe GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glamor_set_destination_pixmap_fbo(temp_fbo); + glamor_set_destination_pixmap_fbo(temp_fbo, 0, 0, w, h); dispatch->glUseProgram(glamor_priv->finish_access_prog[no_alpha]); dispatch->glUniform1i(glamor_priv-> finish_access_revert[no_alpha], diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h index d26f59f6e..8f1d42876 100644 --- a/glamor/glamor_priv.h +++ b/glamor/glamor_priv.h @@ -456,7 +456,7 @@ void glamor_get_color_4f_from_pixel(PixmapPtr pixmap, int glamor_set_destination_pixmap(PixmapPtr pixmap); int glamor_set_destination_pixmap_priv(glamor_pixmap_private * pixmap_priv); -void glamor_set_destination_pixmap_fbo(glamor_pixmap_fbo *); +void glamor_set_destination_pixmap_fbo(glamor_pixmap_fbo *, int, int, int, int); /* nc means no check. caller must ensure this pixmap has valid fbo. * usually use the GLAMOR_PIXMAP_PRIV_HAS_FBO firstly. diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c index a17b6fd21..94f7dc5a5 100644 --- a/glamor/glamor_render.c +++ b/glamor/glamor_render.c @@ -1210,7 +1210,7 @@ glamor_composite_with_shader(CARD8 op, glamor_get_drawable_deltas(dest->pDrawable, dest_pixmap, &dest_x_off, &dest_y_off); - pixmap_priv_get_scale(dest_pixmap_priv, &dst_xscale, &dst_yscale); + pixmap_priv_get_dest_scale(dest_pixmap_priv, &dst_xscale, &dst_yscale); if (glamor_priv->has_source_coords) { glamor_get_drawable_deltas(source->pDrawable, @@ -2109,7 +2109,7 @@ _glamor_gradient_set_pixmap_destination(ScreenPtr screen, glamor_set_destination_pixmap_priv_nc(pixmap_priv); - pixmap_priv_get_scale(pixmap_priv, xscale, yscale); + pixmap_priv_get_dest_scale(pixmap_priv, xscale, yscale); glamor_priv->has_source_coords = 1; glamor_priv->has_mask_coords = 0; diff --git a/glamor/glamor_tile.c b/glamor/glamor_tile.c index df66d05ec..6790550a3 100644 --- a/glamor/glamor_tile.c +++ b/glamor/glamor_tile.c @@ -154,7 +154,7 @@ glamor_tile(PixmapPtr pixmap, PixmapPtr tile, } glamor_set_destination_pixmap_priv_nc(dst_pixmap_priv); - pixmap_priv_get_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale); + pixmap_priv_get_dest_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale); dispatch = glamor_get_dispatch(glamor_priv); if (!glamor_set_alu(dispatch, alu)) { diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h index 5cd37de4e..8dad2dfd6 100644 --- a/glamor/glamor_utils.h +++ b/glamor/glamor_utils.h @@ -39,6 +39,12 @@ #define t_from_x_coord_y(_yscale_, _y_) (1.0 - (_y_) * (_yscale_)) #define t_from_x_coord_y_inverted(_yscale_, _y_) ((_y_) * (_yscale_)) +#define pixmap_priv_get_dest_scale(_pixmap_priv_, _pxscale_, _pyscale_) \ + do { \ + *(_pxscale_) = 1.0 / (_pixmap_priv_)->container->drawable.width; \ + *(_pyscale_) = 1.0 / (_pixmap_priv_)->container->drawable.height; \ + } while(0) + #define pixmap_priv_get_scale(_pixmap_priv_, _pxscale_, _pyscale_) \ do { \ *(_pxscale_) = 1.0 / (_pixmap_priv_)->fbo->width; \