gl renderer: Use GskTransform in render ops builder

for the modelview matrix. We need this later.
This commit is contained in:
Timm Bäder 2019-06-02 09:55:11 +02:00
parent f1996783ec
commit f999572e8f
3 changed files with 65 additions and 75 deletions

View File

@ -880,7 +880,7 @@ render_transform_node (GskGLRenderer *self,
graphene_matrix_t mat; graphene_matrix_t mat;
gsk_transform_to_matrix (node_transform, &mat); gsk_transform_to_matrix (node_transform, &mat);
ops_push_modelview (builder, &mat, category); ops_push_modelview (builder, node_transform);
gsk_gl_renderer_add_render_ops (self, child, builder); gsk_gl_renderer_add_render_ops (self, child, builder);
ops_pop_modelview (builder); ops_pop_modelview (builder);
} }
@ -897,7 +897,7 @@ render_transform_node (GskGLRenderer *self,
if (node_supports_transform (child)) if (node_supports_transform (child))
{ {
gsk_transform_to_matrix (node_transform, &mat); gsk_transform_to_matrix (node_transform, &mat);
ops_push_modelview (builder, &mat, category); ops_push_modelview (builder, node_transform);
gsk_gl_renderer_add_render_ops (self, child, builder); gsk_gl_renderer_add_render_ops (self, child, builder);
ops_pop_modelview (builder); ops_pop_modelview (builder);
} }
@ -922,7 +922,7 @@ render_transform_node (GskGLRenderer *self,
RESET_CLIP | RESET_OPACITY); RESET_CLIP | RESET_OPACITY);
gsk_transform_to_matrix (node_transform, &mat); gsk_transform_to_matrix (node_transform, &mat);
ops_push_modelview (builder, &mat, category); ops_push_modelview (builder, node_transform);
ops_set_texture (builder, texture_id); ops_set_texture (builder, texture_id);
ops_set_program (builder, &self->blit_program); ops_set_program (builder, &self->blit_program);
@ -1494,7 +1494,7 @@ render_outset_shadow_node (GskGLRenderer *self,
op.op = OP_CLEAR; op.op = OP_CLEAR;
ops_add (builder, &op); ops_add (builder, &op);
prev_projection = ops_set_projection (builder, &item_proj); prev_projection = ops_set_projection (builder, &item_proj);
ops_set_modelview (builder, &identity, GSK_TRANSFORM_CATEGORY_IDENTITY); ops_set_modelview (builder, NULL); /* Modelview */
prev_viewport = ops_set_viewport (builder, &GRAPHENE_RECT_INIT (0, 0, texture_width, texture_height)); prev_viewport = ops_set_viewport (builder, &GRAPHENE_RECT_INIT (0, 0, texture_width, texture_height));
/* Draw outline */ /* Draw outline */
@ -2790,9 +2790,7 @@ add_offscreen_ops (GskGLRenderer *self,
op.op = OP_CLEAR; op.op = OP_CLEAR;
ops_add (builder, &op); ops_add (builder, &op);
prev_projection = ops_set_projection (builder, &item_proj); prev_projection = ops_set_projection (builder, &item_proj);
ops_set_modelview (builder, &modelview, ops_set_modelview (builder, gsk_transform_scale (NULL, scale, scale));
G_APPROX_VALUE (scale, 1.0, 0.01f) ? GSK_TRANSFORM_CATEGORY_IDENTITY :
GSK_TRANSFORM_CATEGORY_2D_AFFINE);
prev_viewport = ops_set_viewport (builder, prev_viewport = ops_set_viewport (builder,
&GRAPHENE_RECT_INIT (bounds->origin.x * scale, &GRAPHENE_RECT_INIT (bounds->origin.x * scale,
bounds->origin.y * scale, bounds->origin.y * scale,
@ -3076,8 +3074,7 @@ gsk_gl_renderer_do_render (GskRenderer *renderer,
ops_set_projection (&self->op_builder, &projection); ops_set_projection (&self->op_builder, &projection);
ops_set_viewport (&self->op_builder, viewport); ops_set_viewport (&self->op_builder, viewport);
ops_set_modelview (&self->op_builder, &modelview, ops_set_modelview (&self->op_builder, gsk_transform_scale (NULL, scale_factor, scale_factor));
scale_factor == 1 ? GSK_TRANSFORM_CATEGORY_IDENTITY : GSK_TRANSFORM_CATEGORY_2D_AFFINE);
/* Initial clip is self->render_region! */ /* Initial clip is self->render_region! */
if (self->render_region != NULL) if (self->render_region != NULL)

View File

@ -1,4 +1,5 @@
#include "gskglrenderopsprivate.h" #include "gskglrenderopsprivate.h"
#include "gsktransform.h"
static inline gboolean static inline gboolean
rect_equal (const graphene_rect_t *a, rect_equal (const graphene_rect_t *a,
@ -96,10 +97,10 @@ ops_get_scale (const RenderOpBuilder *builder)
} }
static void static void
extract_matrix_metadata (const graphene_matrix_t *m, extract_matrix_metadata (GskTransform *transform,
OpsMatrixMetadata *md) OpsMatrixMetadata *md)
{ {
switch (md->category) switch (gsk_transform_get_category (transform))
{ {
case GSK_TRANSFORM_CATEGORY_IDENTITY: case GSK_TRANSFORM_CATEGORY_IDENTITY:
md->scale_x = 1; md->scale_x = 1;
@ -107,8 +108,7 @@ extract_matrix_metadata (const graphene_matrix_t *m,
break; break;
case GSK_TRANSFORM_CATEGORY_2D_TRANSLATE: case GSK_TRANSFORM_CATEGORY_2D_TRANSLATE:
md->translate_x = graphene_matrix_get_value (m, 3, 0); gsk_transform_to_translate (transform, &md->translate_x, &md->translate_y);
md->translate_y = graphene_matrix_get_value (m, 3, 1);
md->scale_x = 1; md->scale_x = 1;
md->scale_y = 1; md->scale_y = 1;
break; break;
@ -121,19 +121,24 @@ extract_matrix_metadata (const graphene_matrix_t *m,
{ {
graphene_vec3_t col1; graphene_vec3_t col1;
graphene_vec3_t col2; graphene_vec3_t col2;
graphene_matrix_t m;
md->translate_x = graphene_matrix_get_value (m, 3, 0); gsk_transform_to_matrix (transform, &m);
md->translate_y = graphene_matrix_get_value (m, 3, 1);
/* TODO: Is this event possible (or correct) now that we use a GskTransform here? */
md->translate_x = graphene_matrix_get_value (&m, 3, 0);
md->translate_y = graphene_matrix_get_value (&m, 3, 1);
graphene_vec3_init (&col1, graphene_vec3_init (&col1,
graphene_matrix_get_value (m, 0, 0), graphene_matrix_get_value (&m, 0, 0),
graphene_matrix_get_value (m, 1, 0), graphene_matrix_get_value (&m, 1, 0),
graphene_matrix_get_value (m, 2, 0)); graphene_matrix_get_value (&m, 2, 0));
graphene_vec3_init (&col2, graphene_vec3_init (&col2,
graphene_matrix_get_value (m, 0, 1), graphene_matrix_get_value (&m, 0, 1),
graphene_matrix_get_value (m, 1, 1), graphene_matrix_get_value (&m, 1, 1),
graphene_matrix_get_value (m, 2, 1)); graphene_matrix_get_value (&m, 2, 1));
md->scale_x = graphene_vec3_length (&col1); md->scale_x = graphene_vec3_length (&col1);
md->scale_y = graphene_vec3_length (&col2); md->scale_y = graphene_vec3_length (&col2);
@ -156,7 +161,7 @@ ops_transform_bounds_modelview (const RenderOpBuilder *builder,
head = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1); head = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1);
switch (head->metadata.category) switch (gsk_transform_get_category (head->transform))
{ {
case GSK_TRANSFORM_CATEGORY_IDENTITY: case GSK_TRANSFORM_CATEGORY_IDENTITY:
*dst = *src; *dst = *src;
@ -175,10 +180,7 @@ ops_transform_bounds_modelview (const RenderOpBuilder *builder,
case GSK_TRANSFORM_CATEGORY_2D: case GSK_TRANSFORM_CATEGORY_2D:
case GSK_TRANSFORM_CATEGORY_2D_AFFINE: case GSK_TRANSFORM_CATEGORY_2D_AFFINE:
default: default:
graphene_matrix_transform_bounds (builder->current_modelview, gsk_transform_transform_bounds (builder->current_modelview, src, dst);
src,
dst);
} }
dst->origin.x += builder->dx * head->metadata.scale_x; dst->origin.x += builder->dx * head->metadata.scale_x;
@ -198,7 +200,6 @@ ops_init (RenderOpBuilder *builder)
{ {
builder->program_state[i].opacity = 1.0f; builder->program_state[i].opacity = 1.0f;
} }
} }
void void
@ -234,12 +235,12 @@ ops_set_program (RenderOpBuilder *builder,
} }
if (memcmp (&empty_matrix, &program_state->modelview, sizeof (graphene_matrix_t)) == 0 || if (memcmp (&empty_matrix, &program_state->modelview, sizeof (graphene_matrix_t)) == 0 ||
memcmp (builder->current_modelview, &program_state->modelview, sizeof (graphene_matrix_t)) != 0) !gsk_transform_equal (builder->current_modelview, program_state->modelview))
{ {
op.op = OP_CHANGE_MODELVIEW; op.op = OP_CHANGE_MODELVIEW;
op.modelview = *builder->current_modelview; gsk_transform_to_matrix (builder->current_modelview, &op.modelview);
g_array_append_val (builder->render_ops, op); g_array_append_val (builder->render_ops, op);
program_state->modelview = *builder->current_modelview; program_state->modelview = gsk_transform_ref (builder->current_modelview);
} }
if (rect_equal (&empty_rect, &program_state->viewport) || if (rect_equal (&empty_rect, &program_state->viewport) ||
@ -347,14 +348,16 @@ ops_has_clip (RenderOpBuilder *self)
} }
static void static void
ops_set_modelview_internal (RenderOpBuilder *builder, ops_set_modelview_internal (RenderOpBuilder *builder,
const graphene_matrix_t *modelview) GskTransform *transform)
{ {
RenderOp op; RenderOp op;
graphene_matrix_t matrix;
gsk_transform_to_matrix (transform, &matrix);
if (builder->current_program && if (builder->current_program &&
memcmp (&builder->current_program_state->modelview, modelview, gsk_transform_equal (builder->current_program_state->modelview, transform))
sizeof (graphene_matrix_t)) == 0)
return; return;
if (builder->render_ops->len > 0) if (builder->render_ops->len > 0)
@ -362,32 +365,31 @@ ops_set_modelview_internal (RenderOpBuilder *builder,
RenderOp *last_op = &g_array_index (builder->render_ops, RenderOp, builder->render_ops->len - 1); RenderOp *last_op = &g_array_index (builder->render_ops, RenderOp, builder->render_ops->len - 1);
if (last_op->op == OP_CHANGE_MODELVIEW) if (last_op->op == OP_CHANGE_MODELVIEW)
{ {
last_op->modelview = *modelview; last_op->modelview = matrix;
} }
else else
{ {
op.op = OP_CHANGE_MODELVIEW; op.op = OP_CHANGE_MODELVIEW;
op.modelview = *modelview; op.modelview = matrix;
g_array_append_val (builder->render_ops, op); g_array_append_val (builder->render_ops, op);
} }
} }
else else
{ {
op.op = OP_CHANGE_MODELVIEW; op.op = OP_CHANGE_MODELVIEW;
op.modelview = *modelview; op.modelview = matrix;
g_array_append_val (builder->render_ops, op); g_array_append_val (builder->render_ops, op);
} }
if (builder->current_program != NULL) if (builder->current_program != NULL)
builder->current_program_state->modelview = *modelview; builder->current_program_state->modelview = gsk_transform_ref (transform);
} }
/* This sets the modelview to the given one without looking at the /* This sets the modelview to the given one without looking at the
* one that's currently set */ * one that's currently set */
void void
ops_set_modelview (RenderOpBuilder *builder, ops_set_modelview (RenderOpBuilder *builder,
const graphene_matrix_t *mv, GskTransform *transform)
GskTransformCategory mv_category)
{ {
MatrixStackEntry *entry; MatrixStackEntry *entry;
@ -399,25 +401,23 @@ ops_set_modelview (RenderOpBuilder *builder,
g_array_set_size (builder->mv_stack, builder->mv_stack->len + 1); g_array_set_size (builder->mv_stack, builder->mv_stack->len + 1);
entry = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1); entry = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1);
entry->matrix = *mv; entry->transform = transform;
entry->metadata.category = mv_category;
entry->metadata.dx_before = builder->dx; entry->metadata.dx_before = builder->dx;
entry->metadata.dy_before = builder->dy; entry->metadata.dy_before = builder->dy;
extract_matrix_metadata (mv, &entry->metadata); extract_matrix_metadata (transform, &entry->metadata);
builder->dx = 0; builder->dx = 0;
builder->dy = 0; builder->dy = 0;
builder->current_modelview = &entry->matrix; builder->current_modelview = entry->transform;
ops_set_modelview_internal (builder, &entry->matrix); ops_set_modelview_internal (builder, entry->transform);
} }
/* This sets the given modelview to the one we get when multiplying /* This sets the given modelview to the one we get when multiplying
* the given modelview with the current one. */ * the given modelview with the current one. */
void void
ops_push_modelview (RenderOpBuilder *builder, ops_push_modelview (RenderOpBuilder *builder,
const graphene_matrix_t *mv, GskTransform *transform)
GskTransformCategory mv_category)
{ {
float scale = ops_get_scale (builder); float scale = ops_get_scale (builder);
MatrixStackEntry *entry; MatrixStackEntry *entry;
@ -433,37 +433,34 @@ ops_push_modelview (RenderOpBuilder *builder,
if (G_LIKELY (builder->mv_stack->len >= 2)) if (G_LIKELY (builder->mv_stack->len >= 2))
{ {
const MatrixStackEntry *cur; const MatrixStackEntry *cur;
GskTransform *t;
cur = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 2); cur = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 2);
/* Multiply given matrix with current modelview */ /* Multiply given matrix with current modelview */
graphene_matrix_multiply (mv, &cur->matrix, &entry->matrix); t = gsk_transform_transform (cur->transform, transform);
graphene_matrix_translate (&entry->matrix, t = gsk_transform_translate (t, &(graphene_point_t) { builder->dx * scale, builder->dy * scale });
&(graphene_point3d_t) { builder->dx * scale, builder->dy * scale, 0}); entry->transform = t;
entry->metadata.category = MIN (mv_category, cur->metadata.category);
} }
else else
{ {
entry->matrix = *mv; entry->transform = gsk_transform_ref (transform);
entry->metadata.category = mv_category;
} }
entry->metadata.dx_before = builder->dx; entry->metadata.dx_before = builder->dx;
entry->metadata.dy_before = builder->dy; entry->metadata.dy_before = builder->dy;
extract_matrix_metadata (mv, &entry->metadata); extract_matrix_metadata (transform, &entry->metadata);
builder->dx = 0; builder->dx = 0;
builder->dy = 0; builder->dy = 0;
builder->current_modelview = &entry->matrix; builder->current_modelview = entry->transform;
ops_set_modelview_internal (builder, &entry->matrix); ops_set_modelview_internal (builder, entry->transform);
} }
void void
ops_pop_modelview (RenderOpBuilder *builder) ops_pop_modelview (RenderOpBuilder *builder)
{ {
const graphene_matrix_t *m;
const MatrixStackEntry *head; const MatrixStackEntry *head;
g_assert (builder->mv_stack); g_assert (builder->mv_stack);
@ -472,15 +469,15 @@ ops_pop_modelview (RenderOpBuilder *builder)
head = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1); head = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1);
builder->dx = head->metadata.dx_before; builder->dx = head->metadata.dx_before;
builder->dy = head->metadata.dy_before; builder->dy = head->metadata.dy_before;
gsk_transform_unref (head->transform);
builder->mv_stack->len --; builder->mv_stack->len --;
head = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1); head = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1);
m = &head->matrix;
if (builder->mv_stack->len >= 1) if (builder->mv_stack->len >= 1)
{ {
builder->current_modelview = m; builder->current_modelview = head->transform;
ops_set_modelview_internal (builder, m); ops_set_modelview_internal (builder, head->transform);
} }
else else
{ {

View File

@ -24,13 +24,11 @@ typedef struct
float dx_before; float dx_before;
float dy_before; float dy_before;
GskTransformCategory category;
} OpsMatrixMetadata; } OpsMatrixMetadata;
typedef struct typedef struct
{ {
graphene_matrix_t matrix; GskTransform *transform;
OpsMatrixMetadata metadata; OpsMatrixMetadata metadata;
} MatrixStackEntry; } MatrixStackEntry;
@ -236,8 +234,8 @@ typedef struct
typedef struct typedef struct
{ {
GskTransform *modelview;
GskRoundedRect clip; GskRoundedRect clip;
graphene_matrix_t modelview;
graphene_matrix_t projection; graphene_matrix_t projection;
int source_texture; int source_texture;
graphene_rect_t viewport; graphene_rect_t viewport;
@ -278,11 +276,11 @@ typedef struct
/* Stack of modelview matrices */ /* Stack of modelview matrices */
GArray *mv_stack; GArray *mv_stack;
/* Pointer into mv_stack */ GskTransform *current_modelview;
const graphene_matrix_t *current_modelview;
/* Same thing */ /* Same thing */
GArray *clip_stack; GArray *clip_stack;
/* Pointer into clip_stack */
const GskRoundedRect *current_clip; const GskRoundedRect *current_clip;
} RenderOpBuilder; } RenderOpBuilder;
@ -298,11 +296,9 @@ void ops_pop_debug_group (RenderOpBuilder *builder);
void ops_finish (RenderOpBuilder *builder); void ops_finish (RenderOpBuilder *builder);
void ops_push_modelview (RenderOpBuilder *builder, void ops_push_modelview (RenderOpBuilder *builder,
const graphene_matrix_t *mv, GskTransform *transform);
GskTransformCategory mv_category);
void ops_set_modelview (RenderOpBuilder *builder, void ops_set_modelview (RenderOpBuilder *builder,
const graphene_matrix_t *mv, GskTransform *transform);
GskTransformCategory mv_category);
void ops_pop_modelview (RenderOpBuilder *builder); void ops_pop_modelview (RenderOpBuilder *builder);
float ops_get_scale (const RenderOpBuilder *builder); float ops_get_scale (const RenderOpBuilder *builder);