gl renderer: Refactor add_offscreen_ops

Use a graphene_rect_t for the node bounds instead of 4 floats.
This makes it simpler to pass the size in without the offset applied.
This commit is contained in:
Timm Bäder 2018-12-02 09:05:50 +01:00
parent 933acb3682
commit 2831dbb110

View File

@ -247,10 +247,7 @@ node_supports_transform (GskRenderNode *node)
static void gsk_gl_renderer_setup_render_mode (GskGLRenderer *self); static void gsk_gl_renderer_setup_render_mode (GskGLRenderer *self);
static void add_offscreen_ops (GskGLRenderer *self, static void add_offscreen_ops (GskGLRenderer *self,
RenderOpBuilder *builder, RenderOpBuilder *builder,
float min_x, const graphene_rect_t *bounds,
float max_x,
float min_y,
float max_y,
GskRenderNode *child_node, GskRenderNode *child_node,
int *texture_id, int *texture_id,
gboolean *is_offscreen, gboolean *is_offscreen,
@ -790,7 +787,7 @@ render_transform_node (GskGLRenderer *self,
* for the texture. * for the texture.
*/ */
add_offscreen_ops (self, builder, add_offscreen_ops (self, builder,
min_x, max_x, min_y, max_y, &node->bounds,
child, child,
&texture_id, &is_offscreen, &texture_id, &is_offscreen,
FALSE, TRUE); FALSE, TRUE);
@ -934,7 +931,7 @@ render_rounded_clip_node (GskGLRenderer *self,
} }
prev_clip = ops_set_clip (builder, &child_clip); prev_clip = ops_set_clip (builder, &child_clip);
add_offscreen_ops (self, builder, min_x, max_x, min_y, max_y, add_offscreen_ops (self, builder, &node->bounds,
child, child,
&texture_id, &is_offscreen, TRUE, FALSE); &texture_id, &is_offscreen, TRUE, FALSE);
@ -970,10 +967,7 @@ render_color_matrix_node (GskGLRenderer *self,
/* Pass min_x/max_x/min_y/max_y without builder->dx/dy! */ /* Pass min_x/max_x/min_y/max_y without builder->dx/dy! */
add_offscreen_ops (self, builder, add_offscreen_ops (self, builder,
node->bounds.origin.x, &node->bounds,
node->bounds.origin.x + node->bounds.size.width,
node->bounds.origin.y,
node->bounds.origin.y + node->bounds.size.height,
gsk_color_matrix_node_get_child (node), gsk_color_matrix_node_get_child (node),
&texture_id, &is_offscreen, FALSE, TRUE); &texture_id, &is_offscreen, FALSE, TRUE);
@ -1017,7 +1011,8 @@ render_blur_node (GskGLRenderer *self,
int texture_id; int texture_id;
gboolean is_offscreen; gboolean is_offscreen;
RenderOp op; RenderOp op;
add_offscreen_ops (self, builder, min_x, max_x, min_y, max_y, add_offscreen_ops (self, builder,
&node->bounds,
gsk_blur_node_get_child (node), gsk_blur_node_get_child (node),
&texture_id, &is_offscreen, FALSE, TRUE); &texture_id, &is_offscreen, FALSE, TRUE);
@ -1535,7 +1530,7 @@ render_shadow_node (GskGLRenderer *self,
/* Draw the child offscreen, without the offset. */ /* Draw the child offscreen, without the offset. */
add_offscreen_ops (self, builder, add_offscreen_ops (self, builder,
min_x, max_x, min_y, max_y, &shadow_child->bounds,
shadow_child, &texture_id, &is_offscreen, FALSE, TRUE); shadow_child, &texture_id, &is_offscreen, FALSE, TRUE);
ops_offset (builder, dx, dy); ops_offset (builder, dx, dy);
@ -1583,8 +1578,8 @@ render_cross_fade_node (GskGLRenderer *self,
GskRenderNode *node, GskRenderNode *node,
RenderOpBuilder *builder) RenderOpBuilder *builder)
{ {
const float min_x = node->bounds.origin.x; const float min_x = builder->dx + node->bounds.origin.x;
const float min_y = node->bounds.origin.y; const float min_y = builder->dy + node->bounds.origin.y;
const float max_x = min_x + node->bounds.size.width; const float max_x = min_x + node->bounds.size.width;
const float max_y = min_y + node->bounds.size.height; const float max_y = min_y + node->bounds.size.height;
GskRenderNode *start_node = gsk_cross_fade_node_get_start_child (node); GskRenderNode *start_node = gsk_cross_fade_node_get_start_child (node);
@ -1607,10 +1602,14 @@ render_cross_fade_node (GskGLRenderer *self,
/* TODO: We create 2 textures here as big as the cross-fade node, but both the /* TODO: We create 2 textures here as big as the cross-fade node, but both the
* start and the end node might be a lot smaller than that. */ * start and the end node might be a lot smaller than that. */
add_offscreen_ops (self, builder, min_x, max_x, min_y, max_y, start_node, add_offscreen_ops (self, builder,
&node->bounds,
start_node,
&start_texture_id, &is_offscreen1, TRUE, TRUE); &start_texture_id, &is_offscreen1, TRUE, TRUE);
add_offscreen_ops (self, builder, min_x, max_x, min_y, max_y, end_node, add_offscreen_ops (self, builder,
&node->bounds,
end_node,
&end_texture_id, &is_offscreen2, TRUE, TRUE); &end_texture_id, &is_offscreen2, TRUE, TRUE);
ops_set_program (builder, &self->cross_fade_program); ops_set_program (builder, &self->cross_fade_program);
@ -2316,10 +2315,7 @@ gsk_gl_renderer_add_render_ops (GskGLRenderer *self,
static void static void
add_offscreen_ops (GskGLRenderer *self, add_offscreen_ops (GskGLRenderer *self,
RenderOpBuilder *builder, RenderOpBuilder *builder,
float min_x, const graphene_rect_t *bounds,
float max_x,
float min_y,
float max_y,
GskRenderNode *child_node, GskRenderNode *child_node,
int *texture_id_out, int *texture_id_out,
gboolean *is_offscreen, gboolean *is_offscreen,
@ -2327,8 +2323,8 @@ add_offscreen_ops (GskGLRenderer *self,
gboolean reset_clip) gboolean reset_clip)
{ {
const float scale = ops_get_scale (builder); const float scale = ops_get_scale (builder);
const float width = (max_x - min_x) * scale; const float width = bounds->size.width * scale;
const float height = (max_y - min_y) * scale; const float height = bounds->size.height * scale;
const float dx = builder->dx; const float dx = builder->dx;
const float dy = builder->dy; const float dy = builder->dy;
int render_target; int render_target;
@ -2377,8 +2373,10 @@ add_offscreen_ops (GskGLRenderer *self,
render_target = gsk_gl_driver_create_render_target (self->gl_driver, texture_id, TRUE, TRUE); render_target = gsk_gl_driver_create_render_target (self->gl_driver, texture_id, TRUE, TRUE);
graphene_matrix_init_ortho (&item_proj, graphene_matrix_init_ortho (&item_proj,
min_x * scale, max_x * scale, bounds->origin.x * scale,
min_y * scale, max_y * scale, (bounds->origin.x + bounds->size.width) * scale,
bounds->origin.y * scale,
(bounds->origin.y + bounds->size.height) * scale,
ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE); ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE);
graphene_matrix_scale (&item_proj, 1, -1, 1); graphene_matrix_scale (&item_proj, 1, -1, 1);
graphene_matrix_init_identity (&identity); graphene_matrix_init_identity (&identity);
@ -2390,14 +2388,16 @@ add_offscreen_ops (GskGLRenderer *self,
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_push_modelview (builder, &identity); ops_push_modelview (builder, &identity);
prev_viewport = ops_set_viewport (builder, &GRAPHENE_RECT_INIT (min_x * scale, prev_viewport = ops_set_viewport (builder,
min_y * scale, &GRAPHENE_RECT_INIT (bounds->origin.x * scale,
bounds->origin.y * scale,
width, height)); width, height));
if (reset_clip) if (reset_clip)
prev_clip = ops_set_clip (builder, prev_clip = ops_set_clip (builder,
&GSK_ROUNDED_RECT_INIT (min_x * scale, &GSK_ROUNDED_RECT_INIT (bounds->origin.x * scale,
min_y * scale, bounds->origin.y * scale,
width, height)); width, height));
builder->dx = 0; builder->dx = 0;
builder->dy = 0; builder->dy = 0;