# define PEPPER_API
#endif
+#define PEPPER_MAX(a, b) ((a) > (b) ? (a) : (b))
+#define PEPPER_MIN(a, b) ((a) < (b) ? (a) : (b))
+
#define pepper_container_of(ptr, type, member) ({ \
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
}
typedef struct pepper_list pepper_list_t;
-typedef struct pepper_matrix pepper_matrix_t;
#define PEPPER_LIST_FOR_EACH(head, pos) \
for (pos = (head)->next; \
PEPPER_API int
pepper_log(const char* domain, int level, const char *format, ...);
-struct pepper_matrix
+typedef struct pepper_mat4 pepper_mat4_t;
+typedef struct pepper_vec4 pepper_vec4_t;
+typedef struct pepper_vec3 pepper_vec3_t;
+typedef struct pepper_vec2 pepper_vec2_t;
+
+struct pepper_mat4
{
double m[16];
uint32_t flags;
};
+struct pepper_vec2
+{
+ double x, y;
+};
+
+struct pepper_vec3
+{
+ double x, y, z;
+};
+
+struct pepper_vec4
+{
+ double x, y, z, w;
+};
+
enum {
PEPPER_MATRIX_TRANSLATE = (1 << 0),
PEPPER_MATRIX_SCALE = (1 << 1),
PEPPER_MATRIX_COMPLEX = (1 << 3),
};
+static inline pepper_bool_t
+pepper_mat4_is_translation(const pepper_mat4_t *matrix)
+{
+ return matrix->flags == PEPPER_MATRIX_TRANSLATE || matrix->flags == 0;
+}
+
static inline double
pepper_reciprocal_sqrt(double x)
{
}
static inline void
-pepper_matrix_multiply(pepper_matrix_t *dst, const pepper_matrix_t *ma, const pepper_matrix_t *mb)
+pepper_mat4_multiply(pepper_mat4_t *dst, const pepper_mat4_t *ma, const pepper_mat4_t *mb)
{
- pepper_matrix_t tmp;
+ pepper_mat4_t tmp;
double *d = tmp.m;
const double *a = ma->m;
const double *b = mb->m;
if (!ma->flags)
{
- memcpy(dst, mb, sizeof(pepper_matrix_t));
+ memcpy(dst, mb, sizeof(pepper_mat4_t));
return;
}
if (!mb->flags)
{
- memcpy(dst, ma, sizeof(pepper_matrix_t));
+ memcpy(dst, ma, sizeof(pepper_mat4_t));
return;
}
d[15] = a[ 3] * b[12] + a[ 7] * b[13] + a[11] * b[14] + a[15] * b[15];
tmp.flags = ma->flags | mb->flags;
- memcpy(dst, &tmp, sizeof(pepper_matrix_t));
+ memcpy(dst, &tmp, sizeof(pepper_mat4_t));
}
static inline void
-pepper_matrix_init_identity(pepper_matrix_t *matrix)
+pepper_mat4_init_identity(pepper_mat4_t *matrix)
{
matrix->m[ 0] = 1.0f;
matrix->m[ 1] = 0.0f;
}
static inline void
-pepper_matrix_init_translate(pepper_matrix_t *matrix, double x, double y, double z)
+pepper_mat4_init_translate(pepper_mat4_t *matrix, double x, double y, double z)
{
- pepper_matrix_init_identity(matrix);
+ pepper_mat4_init_identity(matrix);
matrix->m[ 3] = x;
matrix->m[ 7] = y;
}
static inline void
-pepper_matrix_translate(pepper_matrix_t *matrix, double x, double y, double z)
+pepper_mat4_translate(pepper_mat4_t *matrix, double x, double y, double z)
{
matrix->m[ 3] = matrix->m[0] * x + matrix->m[1] * y + matrix->m[ 2] * z;
matrix->m[ 7] = matrix->m[4] * x + matrix->m[5] * y + matrix->m[ 6] * z;
}
static inline void
-pepper_matrix_init_scale(pepper_matrix_t *matrix, double x, double y, double z)
+pepper_mat4_init_scale(pepper_mat4_t *matrix, double x, double y, double z)
{
- pepper_matrix_init_identity(matrix);
+ pepper_mat4_init_identity(matrix);
matrix->m[ 0] = x;
matrix->m[ 5] = y;
}
static inline void
-pepper_matrix_scale(pepper_matrix_t *matrix, double x, double y, double z)
+pepper_mat4_scale(pepper_mat4_t *matrix, double x, double y, double z)
{
matrix->m[ 0] *= x;
matrix->m[ 1] *= y;
}
static inline void
-pepper_matrix_init_rotate(pepper_matrix_t *matrix, double x, double y, double z, double angle)
+pepper_mat4_init_rotate(pepper_mat4_t *matrix, double x, double y, double z, double angle)
{
double c;
double s;
if (angle == 0.0f || (z == 0.0f && y == 0.0f && z == 0.0f))
{
- pepper_matrix_init_identity(matrix);
+ pepper_mat4_init_identity(matrix);
return;
}
if (x == 0.0f && y == 0.0f)
{
- pepper_matrix_init_identity(matrix);
+ pepper_mat4_init_identity(matrix);
matrix->m[ 0] = c;
matrix->m[ 1] = -s;
}
else if (y == 0.0f && z == 0.0f)
{
- pepper_matrix_init_identity(matrix);
+ pepper_mat4_init_identity(matrix);
matrix->m[ 5] = c;
matrix->m[ 6] = -s;
}
else if (x == 0.0f && z == 0.0f)
{
- pepper_matrix_init_identity(matrix);
+ pepper_mat4_init_identity(matrix);
matrix->m[ 2] = c;
matrix->m[ 0] = -s;
}
static inline void
-pepper_matrix_rotate(pepper_matrix_t *matrix, double x, double y, double z, double angle)
+pepper_mat4_rotate(pepper_mat4_t *matrix, double x, double y, double z, double angle)
{
- pepper_matrix_t rotate;
+ pepper_mat4_t rotate;
+
+ pepper_mat4_init_rotate(&rotate, x, y, z, angle);
+ pepper_mat4_multiply(matrix, matrix, &rotate);
+}
+
+static inline void
+pepper_mat4_copy(pepper_mat4_t *dst, const pepper_mat4_t *src)
+{
+ memcpy(dst, src, sizeof(pepper_mat4_t));
+}
+
+static inline void
+pepper_mat4_transform_vec2(const pepper_mat4_t *matrix, pepper_vec2_t *v)
+{
+ double x, y;
+ const double *m = &matrix->m[0];
+
+ x = m[0] * v->x + m[1] * v->y + m[3];
+ y = m[4] * v->x + m[5] * v->y + m[7];
+
+ v->x = x;
+ v->y = y;
+}
+
+static inline void
+pepper_mat4_transform_vec3(const pepper_mat4_t *matrix, pepper_vec3_t *v)
+{
+ double x, y, z;
+ const double *m = &matrix->m[0];
+
+ x = m[0] * v->x + m[1] * v->y + m[ 2] * v->z + m[ 3];
+ y = m[4] * v->x + m[5] * v->y + m[ 6] * v->z + m[ 7];
+ y = m[8] * v->x + m[9] * v->y + m[10] * v->z + m[11];
- pepper_matrix_init_rotate(&rotate, x, y, z, angle);
- pepper_matrix_multiply(matrix, matrix, &rotate);
+ v->x = x;
+ v->y = y;
+ v->z = z;
}
static inline void
-pepper_matrix_copy(pepper_matrix_t *dst, const pepper_matrix_t *src)
+pepper_mat4_transform_vec4(const pepper_mat4_t *matrix, pepper_vec4_t *v)
{
- memcpy(dst, src, sizeof(pepper_matrix_t));
+ double x, y, z, w;
+ const double *m = &matrix->m[0];
+
+ x = m[ 0] * v->x + m[ 1] * v->y + m[ 2] * v->z + m[ 3] * v->w;
+ y = m[ 4] * v->x + m[ 5] * v->y + m[ 6] * v->z + m[ 7] * v->w;
+ y = m[ 8] * v->x + m[ 9] * v->y + m[10] * v->z + m[11] * v->w;
+ y = m[12] * v->x + m[13] * v->y + m[14] * v->z + m[15] * v->w;
+
+ v->x = x;
+ v->y = y;
+ v->z = z;
+ v->w = w;
}
/* Virtual terminal */
view->w = 0;
view->h = 0;
- pepper_matrix_init_identity(&view->transform);
- pepper_matrix_init_identity(&view->matrix_to_parent);
- pepper_matrix_init_identity(&view->matrix_to_global);
+ pepper_mat4_init_identity(&view->transform);
+ pepper_mat4_init_identity(&view->matrix_to_parent);
+ pepper_mat4_init_identity(&view->matrix_to_global);
view->parent_link.item = (void *)view;
view->z_link.item = (void *)view;
}
PEPPER_API void
-pepper_view_set_transform(pepper_object_t *v, const pepper_matrix_t *matrix)
+pepper_view_set_transform(pepper_object_t *v, const pepper_mat4_t *matrix)
{
pepper_view_t *view = (pepper_view_t *)v;
CHECK_MAGIC_AND_NON_NULL(v, PEPPER_VIEW);
- pepper_matrix_copy(&view->transform, matrix);
+ pepper_mat4_copy(&view->transform, matrix);
view_geometry_dirty(view);
}
-PEPPER_API const pepper_matrix_t *
+PEPPER_API const pepper_mat4_t *
pepper_view_get_transform(pepper_object_t *v)
{
pepper_view_t *view = (pepper_view_t *)v;
}
static void
-damage_region_transform(pixman_region32_t *region, const pepper_matrix_t *matrix)
+damage_region_transform(pixman_region32_t *region, const pepper_mat4_t *matrix)
{
/* TODO: */
}
if (view->parent)
{
- pepper_matrix_multiply(&view->matrix_to_global,
+ pepper_mat4_multiply(&view->matrix_to_global,
&view->parent->matrix_to_global, &view->matrix_to_parent);
}
else
{
- pepper_matrix_copy(&view->matrix_to_global, &view->matrix_to_parent);
+ pepper_mat4_copy(&view->matrix_to_global, &view->matrix_to_parent);
}
view_update_bounding_region(view);