gsk: Add a shortcut for a common transform case

Add a private getter for the translation part of a
transform node, to avoid pulling it out of the transform
over and over.
This commit is contained in:
Matthias Clasen 2021-07-24 10:48:20 -04:00
parent 7fb1389648
commit b695ef9168
3 changed files with 39 additions and 7 deletions

View File

@ -2804,6 +2804,7 @@ struct _GskTransformNode
GskRenderNode *child; GskRenderNode *child;
GskTransform *transform; GskTransform *transform;
float dx, dy;
}; };
static void static void
@ -2955,6 +2956,11 @@ gsk_transform_node_new (GskRenderNode *child,
self->child = gsk_render_node_ref (child); self->child = gsk_render_node_ref (child);
self->transform = gsk_transform_ref (transform); self->transform = gsk_transform_ref (transform);
if (gsk_transform_get_category (transform) >= GSK_TRANSFORM_CATEGORY_2D_TRANSLATE)
gsk_transform_to_translate (transform, &self->dx, &self->dy);
else
self->dx = self->dy = 0;
gsk_transform_transform_bounds (self->transform, gsk_transform_transform_bounds (self->transform,
&child->bounds, &child->bounds,
&node->bounds); &node->bounds);
@ -2994,6 +3000,17 @@ gsk_transform_node_get_transform (const GskRenderNode *node)
return self->transform; return self->transform;
} }
void
gsk_transform_node_get_translate (const GskRenderNode *node,
float *dx,
float *dy)
{
const GskTransformNode *self = (const GskTransformNode *) node;
*dx = self->dx;
*dy = self->dy;
}
/*** GSK_OPACITY_NODE ***/ /*** GSK_OPACITY_NODE ***/
/** /**

View File

@ -106,6 +106,10 @@ void gsk_text_node_serialize_glyphs (GskRenderNode
GskRenderNode ** gsk_container_node_get_children (const GskRenderNode *node, GskRenderNode ** gsk_container_node_get_children (const GskRenderNode *node,
guint *n_children); guint *n_children);
void gsk_transform_node_get_translate (const GskRenderNode *node,
float *dx,
float *dy);
G_END_DECLS G_END_DECLS

View File

@ -89,6 +89,8 @@ typedef struct _GskNglRenderModelview
GskTransform *transform; GskTransform *transform;
float scale_x; float scale_x;
float scale_y; float scale_y;
float dx;
float dy;
float offset_x_before; float offset_x_before;
float offset_y_before; float offset_y_before;
graphene_matrix_t matrix; graphene_matrix_t matrix;
@ -424,22 +426,28 @@ gsk_ngl_render_job_set_alpha (GskNglRenderJob *job,
static void static void
extract_matrix_metadata (GskNglRenderModelview *modelview) extract_matrix_metadata (GskNglRenderModelview *modelview)
{ {
float dummy;
gsk_transform_to_matrix (modelview->transform, &modelview->matrix); gsk_transform_to_matrix (modelview->transform, &modelview->matrix);
switch (gsk_transform_get_category (modelview->transform)) switch (gsk_transform_get_category (modelview->transform))
{ {
case GSK_TRANSFORM_CATEGORY_IDENTITY: case GSK_TRANSFORM_CATEGORY_IDENTITY:
modelview->scale_x = 1;
modelview->scale_y = 1;
modelview->dx = 0;
modelview->dy = 0;
break;
case GSK_TRANSFORM_CATEGORY_2D_TRANSLATE: case GSK_TRANSFORM_CATEGORY_2D_TRANSLATE:
modelview->scale_x = 1; modelview->scale_x = 1;
modelview->scale_y = 1; modelview->scale_y = 1;
gsk_transform_to_translate (modelview->transform,
&modelview->dx, &modelview->dy);
break; break;
case GSK_TRANSFORM_CATEGORY_2D_AFFINE: case GSK_TRANSFORM_CATEGORY_2D_AFFINE:
gsk_transform_to_affine (modelview->transform, gsk_transform_to_affine (modelview->transform,
&modelview->scale_x, &modelview->scale_y, &modelview->scale_x, &modelview->scale_y,
&dummy, &dummy); &modelview->dx, &modelview->dy);
break; break;
case GSK_TRANSFORM_CATEGORY_UNKNOWN: case GSK_TRANSFORM_CATEGORY_UNKNOWN:
@ -464,6 +472,8 @@ extract_matrix_metadata (GskNglRenderModelview *modelview)
modelview->scale_x = graphene_vec3_length (&col1); modelview->scale_x = graphene_vec3_length (&col1);
modelview->scale_y = graphene_vec3_length (&col2); modelview->scale_y = graphene_vec3_length (&col2);
modelview->dx = 0;
modelview->dy = 0;
} }
break; break;
@ -743,9 +753,10 @@ gsk_ngl_render_job_transform_bounds (GskNglRenderJob *job,
*/ */
if G_LIKELY (category >= GSK_TRANSFORM_CATEGORY_2D_AFFINE) if G_LIKELY (category >= GSK_TRANSFORM_CATEGORY_2D_AFFINE)
{ {
float dx, dy, scale_x, scale_y; float scale_x = job->current_modelview->scale_x;
float scale_y = job->current_modelview->scale_y;
gsk_transform_to_affine (transform, &scale_x, &scale_y, &dx, &dy); float dx = job->current_modelview->dx;
float dy = job->current_modelview->dy;
/* Init directly into out rect */ /* Init directly into out rect */
out_rect->origin.x = ((rect->origin.x + job->offset_x) * scale_x) + dx; out_rect->origin.x = ((rect->origin.x + job->offset_x) * scale_x) + dx;
@ -1956,7 +1967,7 @@ gsk_ngl_render_job_visit_transform_node (GskNglRenderJob *job,
{ {
float dx, dy; float dx, dy;
gsk_transform_to_translate (transform, &dx, &dy); gsk_transform_node_get_translate (node, &dx, &dy);
gsk_ngl_render_job_offset (job, dx, dy); gsk_ngl_render_job_offset (job, dx, dy);
gsk_ngl_render_job_visit_node (job, child); gsk_ngl_render_job_visit_node (job, child);
gsk_ngl_render_job_offset (job, -dx, -dy); gsk_ngl_render_job_offset (job, -dx, -dy);