xserver-multidpi/glamor/glamor_utils.h
Zhigang Gong ca1908e11d glamor: Concentrate and reduce some coords processing code.
Concentrate the verties and texture coords processing code to a new
file glamor_utils.h. Change most of the code to macro. Will have some
performance benefit on slow machine. And reduce most of the duplicate
code when calculate the normalized coords.

Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
2011-09-26 16:46:35 +08:00

125 lines
4.4 KiB
C

#ifndef GLAMOR_PRIV_H
#error This file can only be included by glamor_priv.h
#endif
#ifndef __GLAMOR_UTILS_H__
#define __GLAMOR_UTILS_H__
#define v_from_x_coord_x(_xscale_, _x_) ( 2 * (_x_) * (_xscale_) - 1.0)
#define v_from_x_coord_y(_yscale_, _y_) (-2 * (_y_) * (_yscale_) + 1.0)
#define v_from_x_coord_y_inverted(_yscale_, _y_) (2 * (_y_) * (_yscale_) - 1.0)
#define t_from_x_coord_x(_xscale_, _x_) ((_x_) * (_xscale_))
#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_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 xFixedToFloat(_val_) ((float)xFixedToInt(_val_) \
+ ((float)xFixedFrac(_val_) / 65536.0))
#define glamor_picture_get_matrixf(_picture_, _matrix_) \
do { \
int _i_; \
if ((_picture_)->transform) \
{ \
for(_i_ = 0; _i_ < 3; _i_++) \
{ \
(_matrix_)[_i_ * 3 + 0] = \
xFixedToFloat((_picture_)->transform->matrix[_i_][0]); \
(_matrix_)[_i_ * 3 + 1] = \
xFixedToFloat((_picture_)->transform->matrix[_i_][1]); \
(_matrix_)[_i_ * 3 + 2] = \
xFixedToFloat((_picture_)->transform->matrix[_i_][2]); \
} \
} \
} while(0)
#define glamor_set_transformed_point(matrix, xscale, yscale, texcoord, \
x, y, yInverted) \
do { \
float result[4]; \
int i; \
float tx, ty; \
\
for (i = 0; i < 3; i++) { \
result[i] = (matrix)[i * 3] * (x) + (matrix)[i * 3 + 1] * (y) \
+ (matrix)[i * 3 + 2]; \
} \
tx = result[0] / result[2]; \
ty = result[1] / result[2]; \
\
(texcoord)[0] = t_from_x_coord_x(xscale, tx); \
if (yInverted) \
(texcoord)[1] = t_from_x_coord_y_inverted(yscale, ty); \
else \
(texcoord)[1] = t_from_x_coord_y(yscale, ty); \
} while(0)
#define glamor_set_transformed_normalize_tcoords( matrix, \
xscale, \
yscale, \
tx1, ty1, tx2, ty2, \
yInverted, texcoords) \
do { \
glamor_set_transformed_point(matrix, xscale, yscale, \
texcoords, tx1, ty1, \
yInverted); \
glamor_set_transformed_point(matrix, xscale, yscale, \
texcoords + 2, tx2, ty1, \
yInverted); \
glamor_set_transformed_point(matrix, xscale, yscale, \
texcoords + 4, tx2, ty2, \
yInverted); \
glamor_set_transformed_point(matrix, xscale, yscale, \
texcoords + 6, tx1, ty2, \
yInverted); \
} while (0)
#define glamor_set_normalize_tcoords(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)[4] = (vertices)[2]; \
(vertices)[6] = (vertices)[0]; \
if (yInverted) { \
(vertices)[1] = t_from_x_coord_y_inverted(yscale, y1); \
(vertices)[5] = t_from_x_coord_y_inverted(yscale, y2); \
} \
else { \
(vertices)[1] = t_from_x_coord_y(yscale, y1); \
(vertices)[5] = t_from_x_coord_y(yscale, y2); \
} \
(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)
#endif