[Glamor] [PATCH 6/7] Fix the problem of x_source and y_source causing radial error
Zhigang Gong
zhigang.gong at linux.intel.com
Mon May 14 22:02:07 PDT 2012
On Tue, May 08, 2012 at 08:45:11AM +0800, junyan.he at linux.intel.com wrote:
> From: Junyan He <junyan.he at linux.intel.com>
>
> The x_source and y_source cause some problem in
> gradient. The old way to handle it by recaulate P1 P2
> to minus the x_source and y_source, but this causes
> problem in radial shader. Now we modify the manner to
> set the texture coordinates: (x_source, y_source) -->
> (x_source + width, y_source + height) to handle all the
> cases.
Why an int translation on the stops can cause problems here? If you
still use x_source and y_source rather than (0,0), then you may
need a considerable larger gradient texture sometimes. Any detail
explaintation?
>
>
> Signed-off-by: Junyan He <junyan.he at linux.intel.com>
> ---
> src/glamor_gradient.c | 39 +++++++++-----------
> src/glamor_utils.h | 95 +++++++++++++++++++++++++++---------------------
> 2 files changed, 71 insertions(+), 63 deletions(-)
>
> diff --git a/src/glamor_gradient.c b/src/glamor_gradient.c
> index 12eff03..ebedb45 100644
> --- a/src/glamor_gradient.c
> +++ b/src/glamor_gradient.c
> @@ -819,14 +819,16 @@ _glamor_gradient_set_pixmap_destination(ScreenPtr screen,
>
> if (tex_normalize) {
> glamor_set_normalize_tcoords(*xscale, *yscale,
> - 0, 0,
> - (INT16)(dst_picture->pDrawable->width),
> - (INT16)(dst_picture->pDrawable->height),
> + x_source, y_source,
> + (INT16)(dst_picture->pDrawable->width + x_source),
> + (INT16)(dst_picture->pDrawable->height + y_source),
> glamor_priv->yInverted, tex_vertices);
> } else {
> - glamor_set_tcoords(0, 0,
> - (INT16)(dst_picture->pDrawable->width),
> + glamor_set_tcoords((INT16)(dst_picture->pDrawable->width),
> (INT16)(dst_picture->pDrawable->height),
> + x_source, y_source,
> + (INT16)(dst_picture->pDrawable->width) + x_source,
> + (INT16)(dst_picture->pDrawable->height) + y_source,
> glamor_priv->yInverted, tex_vertices);
> }
>
> @@ -1204,14 +1206,11 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen,
> r1 = (float)pixman_fixed_to_double(src_picture->pSourcePict->radial.c1.radius);
> r2 = (float)pixman_fixed_to_double(src_picture->pSourcePict->radial.c2.radius);
>
> -
> - cxy[0] = c1x;
> - cxy[1] = c1y;
> + glamor_set_circle_centre(width, height, c1x, c1y, glamor_priv->yInverted, cxy);
> dispatch->glUniform2fv(c1_uniform_location, 1, cxy);
> dispatch->glUniform1f(r1_uniform_location, r1);
>
> - cxy[0] = c2x;
> - cxy[1] = c2y;
> + glamor_set_circle_centre(width, height, c2x, c2y, glamor_priv->yInverted, cxy);
> dispatch->glUniform2fv(c2_uniform_location, 1, cxy);
> dispatch->glUniform1f(r2_uniform_location, r2);
>
> @@ -1285,7 +1284,7 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen,
> int count = 0;
> float slope;
> GLfloat xscale, yscale;
> - GLfloat pt1[4], pt2[4];
> + GLfloat pt1[2], pt2[2];
> float vertices[8];
> float transform_mat[3][3];
> static const float identity_mat[3][3] = {{1.0, 0.0, 0.0},
> @@ -1442,22 +1441,20 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen,
>
> /* Normalize the PTs. */
> glamor_set_normalize_pt(xscale, yscale,
> - pixman_fixed_to_int(src_picture->pSourcePict->linear.p1.x),
> - x_source,
> - pixman_fixed_to_int(src_picture->pSourcePict->linear.p1.y),
> - y_source,
> + pixman_fixed_to_double(src_picture->pSourcePict->linear.p1.x),
> + pixman_fixed_to_double(src_picture->pSourcePict->linear.p1.y),
> glamor_priv->yInverted,
> pt1);
> - DEBUGF("pt1:(%f %f)\n", pt1[0], pt1[1]);
> + DEBUGF("pt1:(%f, %f) ---> (%f %f)\n", pixman_fixed_to_double(src_picture->pSourcePict->linear.p1.x),
> + pixman_fixed_to_double(src_picture->pSourcePict->linear.p1.y), pt1[0], pt1[1]);
>
> glamor_set_normalize_pt(xscale, yscale,
> - pixman_fixed_to_int(src_picture->pSourcePict->linear.p2.x),
> - x_source,
> - pixman_fixed_to_int(src_picture->pSourcePict->linear.p2.y),
> - y_source,
> + pixman_fixed_to_double(src_picture->pSourcePict->linear.p2.x),
> + pixman_fixed_to_double(src_picture->pSourcePict->linear.p2.y),
> glamor_priv->yInverted,
> pt2);
> - DEBUGF("pt2:(%f %f)\n", pt2[0], pt2[1]);
> + DEBUGF("pt2:(%f, %f) ---> (%f %f)\n", pixman_fixed_to_double(src_picture->pSourcePict->linear.p2.x),
> + pixman_fixed_to_double(src_picture->pSourcePict->linear.p2.y), pt2[0], pt2[1]);
>
> /* Set all the stops and colors to shader. */
> if (stops_count > LINEAR_SMALL_STOPS) {
> diff --git a/src/glamor_utils.h b/src/glamor_utils.h
> index 9d32e6e..64ed07f 100644
> --- a/src/glamor_utils.h
> +++ b/src/glamor_utils.h
> @@ -137,54 +137,65 @@
> (vertices)[7] = (vertices)[5]; \
> } while(0)
>
> -#define glamor_set_tcoords(x1, y1, x2, y2, yInverted, vertices) \
> - do { \
> - (vertices)[0] = (x1); \
> - (vertices)[2] = (x2); \
> - (vertices)[4] = (vertices)[2]; \
> - (vertices)[6] = (vertices)[0]; \
> - if (yInverted) { \
> - (vertices)[1] = (y1); \
> - (vertices)[5] = (y2); \
> - } \
> - else { \
> - (vertices)[1] = (y2); \
> - (vertices)[5] = (y1); \
> - } \
> - (vertices)[3] = (vertices)[1]; \
> - (vertices)[7] = (vertices)[5]; \
> +#define glamor_set_tcoords(width, height, x1, y1, x2, y2, \
> + yInverted, vertices) \
> + do { \
> + (vertices)[0] = (x1); \
> + (vertices)[2] = (x2); \
> + (vertices)[4] = (vertices)[2]; \
> + (vertices)[6] = (vertices)[0]; \
> + if (yInverted) { \
> + (vertices)[1] = (y1); \
> + (vertices)[5] = (y2); \
> + } \
> + else { \
> + (vertices)[1] = height - (y2); \
> + (vertices)[5] = height - (y1); \
> + } \
> + (vertices)[3] = (vertices)[1]; \
> + (vertices)[7] = (vertices)[5]; \
> } while(0)
>
>
> #define glamor_set_normalize_vcoords(xscale, yscale, x1, y1, x2, y2, \
> yInverted, vertices) \
> - do { \
> - (vertices)[0] = v_from_x_coord_x(xscale, x1); \
> - (vertices)[2] = v_from_x_coord_x(xscale, x2); \
> - (vertices)[4] = (vertices)[2]; \
> - (vertices)[6] = (vertices)[0]; \
> - if (yInverted) { \
> - (vertices)[1] = v_from_x_coord_y_inverted(yscale, y1); \
> - (vertices)[5] = v_from_x_coord_y_inverted(yscale, y2); \
> - } \
> - else { \
> - (vertices)[1] = v_from_x_coord_y(yscale, y1); \
> - (vertices)[5] = v_from_x_coord_y(yscale, y2); \
> - } \
> - (vertices)[3] = (vertices)[1]; \
> - (vertices)[7] = (vertices)[5]; \
> - } while(0)
> + do { \
> + (vertices)[0] = v_from_x_coord_x(xscale, x1); \
> + (vertices)[2] = v_from_x_coord_x(xscale, x2); \
> + (vertices)[4] = (vertices)[2]; \
> + (vertices)[6] = (vertices)[0]; \
> + if (yInverted) { \
> + (vertices)[1] = v_from_x_coord_y_inverted(yscale, y1); \
> + (vertices)[5] = v_from_x_coord_y_inverted(yscale, y2); \
> + } \
> + else { \
> + (vertices)[1] = v_from_x_coord_y(yscale, y1); \
> + (vertices)[5] = v_from_x_coord_y(yscale, y2); \
> + } \
> + (vertices)[3] = (vertices)[1]; \
> + (vertices)[7] = (vertices)[5]; \
> + } while(0)
> +
> +#define glamor_set_normalize_pt(xscale, yscale, x, y, \
> + yInverted, pt) \
> + do { \
> + (pt)[0] = t_from_x_coord_x(xscale, x); \
> + if (yInverted) { \
> + (pt)[1] = t_from_x_coord_y_inverted(yscale, y); \
> + } else { \
> + (pt)[1] = t_from_x_coord_y(yscale, y); \
> + } \
> + } while(0)
>
> -#define glamor_set_normalize_pt(xscale, yscale, x, x_start, y, y_start, \
> - yInverted, pt) \
> - do { \
> - (pt)[0] = t_from_x_coord_x(xscale, x - x_start); \
> - if (yInverted) { \
> - (pt)[1] = t_from_x_coord_y_inverted(yscale, y - y_start); \
> - } else { \
> - (pt)[1] = t_from_x_coord_y(yscale, y - y_start); \
> - } \
> - (pt)[2] = (pt)[3] = 0.0; \
> +#define glamor_set_circle_centre(width, height, x, y, \
> + yInverted, c) \
> + do { \
> + (c)[0] = (float)x; \
> + if (yInverted) { \
> + (c)[1] = (float)y; \
> + } else { \
> + (c)[1] = (float)height - (float)y; \
> + } \
> } while(0)
>
> inline static void
> --
> 1.7.7.6
>
More information about the Glamor
mailing list