[Glamor] [PATCH 3/3] Add macro of vertex setting for triangle stripe
junyan.he at linux.intel.com
junyan.he at linux.intel.com
Sun Jun 3 14:08:45 PDT 2012
From: Junyan He <junyan.he at linux.intel.com>
Add macro of vertex setting for triangle stripe draw,
and make the code clear.
Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
src/glamor_gradient.c | 47 +++++++++++++-------------------------
src/glamor_trapezoid.c | 31 ++++++-------------------
src/glamor_utils.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 82 insertions(+), 54 deletions(-)
diff --git a/src/glamor_gradient.c b/src/glamor_gradient.c
index ab2c2ed..e02c12c 100644
--- a/src/glamor_gradient.c
+++ b/src/glamor_gradient.c
@@ -806,25 +806,25 @@ _glamor_gradient_set_pixmap_destination(ScreenPtr screen,
*xscale, *yscale, x_source, y_source,
dst_picture->pDrawable->width, dst_picture->pDrawable->height);
- glamor_set_normalize_vcoords(*xscale, *yscale,
- 0, 0,
- (INT16)(dst_picture->pDrawable->width),
- (INT16)(dst_picture->pDrawable->height),
- glamor_priv->yInverted, vertices);
+ glamor_set_normalize_vcoords_tri_strip(*xscale, *yscale,
+ 0, 0,
+ (INT16)(dst_picture->pDrawable->width),
+ (INT16)(dst_picture->pDrawable->height),
+ glamor_priv->yInverted, vertices);
if (tex_normalize) {
- glamor_set_normalize_tcoords(*xscale, *yscale,
- x_source, y_source,
- (INT16)(dst_picture->pDrawable->width + x_source),
- (INT16)(dst_picture->pDrawable->height + y_source),
- glamor_priv->yInverted, tex_vertices);
+ glamor_set_normalize_tcoords_tri_stripe(*xscale, *yscale,
+ 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((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);
+ glamor_set_tcoords_tri_strip((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);
}
DEBUGF("vertices --> leftup : %f X %f, rightup: %f X %f,"
@@ -836,21 +836,6 @@ _glamor_gradient_set_pixmap_destination(ScreenPtr screen,
tex_vertices[0], tex_vertices[1], tex_vertices[2], tex_vertices[3],
tex_vertices[4], tex_vertices[5], tex_vertices[6], tex_vertices[7]);
- /* Swap the vtx for triangle render. */
- tmp = vertices[4];
- vertices[4] = vertices[6];
- vertices[6] = tmp;
- tmp = vertices[5];
- vertices[5] = vertices[7];
- vertices[7] = tmp;
-
- tmp = tex_vertices[4];
- tex_vertices[4] = tex_vertices[6];
- tex_vertices[6] = tmp;
- tmp = tex_vertices[5];
- tex_vertices[5] = tex_vertices[7];
- tex_vertices[7] = tmp;
-
dispatch = glamor_get_dispatch(glamor_priv);
dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
diff --git a/src/glamor_trapezoid.c b/src/glamor_trapezoid.c
index d9682ba..e65f7e3 100644
--- a/src/glamor_trapezoid.c
+++ b/src/glamor_trapezoid.c
@@ -490,39 +490,24 @@ _glamor_generate_trapezoid_with_shader(ScreenPtr screen, PicturePtr picture,
xFixedToInt(ptrap->right.p2.y), ptrap->right.p2.y);
miTrapezoidBounds(1, ptrap, &one_trap_bound);
- glamor_set_tcoords((pixmap_priv->container->drawable.width),
- (pixmap_priv->container->drawable.height),
- (one_trap_bound.x1),
- (one_trap_bound.y1),
- (one_trap_bound.x2),
- (one_trap_bound.y2),
- glamor_priv->yInverted, tex_vertices);
+ glamor_set_tcoords_tri_strip((pixmap_priv->container->drawable.width),
+ (pixmap_priv->container->drawable.height),
+ (one_trap_bound.x1),
+ (one_trap_bound.y1),
+ (one_trap_bound.x2),
+ (one_trap_bound.y2),
+ glamor_priv->yInverted, tex_vertices);
/* Need to rebase. */
one_trap_bound.x1 -= bounds->x1;
one_trap_bound.x2 -= bounds->x1;
one_trap_bound.y1 -= bounds->y1;
one_trap_bound.y2 -= bounds->y1;
- glamor_set_normalize_vcoords(xscale, yscale,
+ glamor_set_normalize_vcoords_tri_strip(xscale, yscale,
one_trap_bound.x1, one_trap_bound.y1,
one_trap_bound.x2, one_trap_bound.y2,
glamor_priv->yInverted, vertices);
- /* Swap the vtx for triangle render. */
- tmp = vertices[4];
- vertices[4] = vertices[6];
- vertices[6] = tmp;
- tmp = vertices[5];
- vertices[5] = vertices[7];
- vertices[7] = tmp;
-
- tmp = tex_vertices[4];
- tex_vertices[4] = tex_vertices[6];
- tex_vertices[6] = tmp;
- tmp = tex_vertices[5];
- tex_vertices[5] = tex_vertices[7];
- tex_vertices[7] = tmp;
-
DEBUGF("vertices --> leftup : %f X %f, rightup: %f X %f,"
"rightbottom: %f X %f, leftbottom : %f X %f\n",
vertices[0], vertices[1], vertices[2], vertices[3],
diff --git a/src/glamor_utils.h b/src/glamor_utils.h
index 4af6739..73c3280 100644
--- a/src/glamor_utils.h
+++ b/src/glamor_utils.h
@@ -143,6 +143,26 @@
(vertices)[7] = (vertices)[5]; \
} while(0)
+#define glamor_set_normalize_tcoords_tri_stripe(xscale, yscale, \
+ x1, y1, x2, y2, \
+ yInverted, vertices) \
+ do { \
+ (vertices)[0] = t_from_x_coord_x(xscale, x1); \
+ (vertices)[2] = t_from_x_coord_x(xscale, x2); \
+ (vertices)[6] = (vertices)[2]; \
+ (vertices)[4] = (vertices)[0]; \
+ if (yInverted) { \
+ (vertices)[1] = t_from_x_coord_y_inverted(yscale, y1); \
+ (vertices)[7] = t_from_x_coord_y_inverted(yscale, y2); \
+ } \
+ else { \
+ (vertices)[1] = t_from_x_coord_y(yscale, y1); \
+ (vertices)[7] = t_from_x_coord_y(yscale, y2); \
+ } \
+ (vertices)[3] = (vertices)[1]; \
+ (vertices)[5] = (vertices)[7]; \
+ } while(0)
+
#define glamor_set_tcoords(width, height, x1, y1, x2, y2, \
yInverted, vertices) \
do { \
@@ -162,6 +182,24 @@
(vertices)[7] = (vertices)[5]; \
} while(0)
+#define glamor_set_tcoords_tri_strip(width, height, x1, y1, x2, y2, \
+ yInverted, vertices) \
+ do { \
+ (vertices)[0] = (x1); \
+ (vertices)[2] = (x2); \
+ (vertices)[6] = (vertices)[2]; \
+ (vertices)[4] = (vertices)[0]; \
+ if (yInverted) { \
+ (vertices)[1] = (y1); \
+ (vertices)[7] = (y2); \
+ } \
+ else { \
+ (vertices)[1] = height - (y2); \
+ (vertices)[7] = height - (y1); \
+ } \
+ (vertices)[3] = (vertices)[1]; \
+ (vertices)[5] = (vertices)[7]; \
+ } while(0)
#define glamor_set_normalize_vcoords(xscale, yscale, x1, y1, x2, y2, \
yInverted, vertices) \
@@ -182,6 +220,26 @@
(vertices)[7] = (vertices)[5]; \
} while(0)
+#define glamor_set_normalize_vcoords_tri_strip(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)[6] = (vertices)[2]; \
+ (vertices)[4] = (vertices)[0]; \
+ if (yInverted) { \
+ (vertices)[1] = v_from_x_coord_y_inverted(yscale, y1); \
+ (vertices)[7] = v_from_x_coord_y_inverted(yscale, y2); \
+ } \
+ else { \
+ (vertices)[1] = v_from_x_coord_y(yscale, y1); \
+ (vertices)[7] = v_from_x_coord_y(yscale, y2); \
+ } \
+ (vertices)[3] = (vertices)[1]; \
+ (vertices)[5] = (vertices)[7]; \
+ } while(0)
+
#define glamor_set_normalize_pt(xscale, yscale, x, y, \
yInverted, pt) \
do { \
--
1.7.7.6
More information about the Glamor
mailing list