From 705640367a5c2ae21405806bfadbf56214b23f0f Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 3 Dec 2013 12:12:52 +0000 Subject: [PATCH] Use the non-deprecated Cogl clipping API Cogl 1.18 deprecated the global clipping API in favour of the per-framebuffer one, but since we're using the 2.0 API internally we don't have access to the deprecated symbols any more. This is pretty much a mechanical port for all the places where we're still using the old 1.x API. --- clutter/clutter-actor.c | 39 +++++++++++++++++---------- clutter/clutter-paint-nodes.c | 14 ++++++---- clutter/clutter-stage.c | 7 ++--- clutter/clutter-text.c | 44 ++++++++++++++++--------------- clutter/cogl/clutter-stage-cogl.c | 13 +++++---- 5 files changed, 69 insertions(+), 48 deletions(-) diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index 39b982b72..df26b3926 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -3352,10 +3352,11 @@ in_clone_paint (void) * means there's no point in trying to cull descendants of the current * node. */ static gboolean -cull_actor (ClutterActor *self, ClutterCullResult *result_out) +cull_actor (ClutterActor *self, + ClutterCullResult *result_out) { ClutterActorPrivate *priv = self->priv; - ClutterActor *stage; + ClutterStage *stage; const ClutterPlane *stage_clip; if (!priv->last_paint_volume_valid) @@ -3369,8 +3370,8 @@ cull_actor (ClutterActor *self, ClutterCullResult *result_out) if (G_UNLIKELY (clutter_paint_debug_flags & CLUTTER_DEBUG_DISABLE_CULLING)) return FALSE; - stage = _clutter_actor_get_stage_internal (self); - stage_clip = _clutter_stage_get_clip (CLUTTER_STAGE (stage)); + stage = (ClutterStage *) _clutter_actor_get_stage_internal (self); + stage_clip = _clutter_stage_get_clip (stage); if (G_UNLIKELY (!stage_clip)) { CLUTTER_NOTE (CLIPPING, "Bail from cull_actor without culling (%s): " @@ -3379,8 +3380,7 @@ cull_actor (ClutterActor *self, ClutterCullResult *result_out) return FALSE; } - if (cogl_get_draw_framebuffer () != - _clutter_stage_get_active_framebuffer (CLUTTER_STAGE (stage))) + if (cogl_get_draw_framebuffer () != _clutter_stage_get_active_framebuffer (stage)) { CLUTTER_NOTE (CLIPPING, "Bail from cull_actor without culling (%s): " "Current framebuffer doesn't correspond to stage", @@ -3390,6 +3390,7 @@ cull_actor (ClutterActor *self, ClutterCullResult *result_out) *result_out = _clutter_paint_volume_cull (&priv->last_paint_volume, stage_clip); + return TRUE; } @@ -3664,6 +3665,7 @@ clutter_actor_paint (ClutterActor *self) ClutterPickMode pick_mode; gboolean clip_set = FALSE; gboolean shader_applied = FALSE; + ClutterStage *stage; CLUTTER_STATIC_COUNTER (actor_paint_counter, "Actor real-paint counter", @@ -3703,10 +3705,12 @@ clutter_actor_paint (ClutterActor *self) if (!CLUTTER_ACTOR_IS_MAPPED (self)) return; + stage = (ClutterStage *) _clutter_actor_get_stage_internal (self); + /* mark that we are in the paint process */ CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_IN_PAINT); - cogl_push_matrix(); + cogl_push_matrix (); if (priv->enable_model_view_transform) { @@ -3761,20 +3765,23 @@ clutter_actor_paint (ClutterActor *self) if (priv->has_clip) { - cogl_clip_push_rectangle (priv->clip.origin.x, - priv->clip.origin.y, - priv->clip.origin.x + priv->clip.size.width, - priv->clip.origin.y + priv->clip.size.height); + CoglFramebuffer *fb = _clutter_stage_get_active_framebuffer (stage); + cogl_framebuffer_push_rectangle_clip (fb, + priv->clip.origin.x, + priv->clip.origin.y, + priv->clip.origin.x + priv->clip.size.width, + priv->clip.origin.y + priv->clip.size.height); clip_set = TRUE; } else if (priv->clip_to_allocation) { + CoglFramebuffer *fb = _clutter_stage_get_active_framebuffer (stage); gfloat width, height; width = priv->allocation.x2 - priv->allocation.x1; height = priv->allocation.y2 - priv->allocation.y1; - cogl_clip_push_rectangle (0, 0, width, height); + cogl_framebuffer_push_rectangle_clip (fb, 0, 0, width, height); clip_set = TRUE; } @@ -3871,9 +3878,13 @@ done: priv->is_dirty = FALSE; if (clip_set) - cogl_clip_pop(); + { + CoglFramebuffer *fb = _clutter_stage_get_active_framebuffer (stage); - cogl_pop_matrix(); + cogl_framebuffer_pop_clip (fb); + } + + cogl_pop_matrix (); /* paint sequence complete */ CLUTTER_UNSET_PRIVATE_FLAGS (self, CLUTTER_IN_PAINT); diff --git a/clutter/clutter-paint-nodes.c b/clutter/clutter-paint-nodes.c index d1b574d23..0a4d6cc44 100644 --- a/clutter/clutter-paint-nodes.c +++ b/clutter/clutter-paint-nodes.c @@ -758,11 +758,14 @@ clutter_text_node_draw (ClutterPaintNode *node) { ClutterTextNode *tnode = CLUTTER_TEXT_NODE (node); PangoRectangle extents; + CoglFramebuffer *fb; guint i; if (node->operations == NULL) return; + fb = cogl_get_draw_framebuffer (); + pango_layout_get_pixel_extents (tnode->layout, NULL, &extents); for (i = 0; i < node->operations->len; i++) @@ -786,10 +789,11 @@ clutter_text_node_draw (ClutterPaintNode *node) if (extents.width > op_width || extents.height > op_height) { - cogl_clip_push_rectangle (op->op.texrect[0], - op->op.texrect[1], - op->op.texrect[2], - op->op.texrect[3]); + cogl_framebuffer_push_rectangle_clip (fb, + op->op.texrect[0], + op->op.texrect[1], + op->op.texrect[2], + op->op.texrect[3]); clipped = TRUE; } @@ -800,7 +804,7 @@ clutter_text_node_draw (ClutterPaintNode *node) 0); if (clipped) - cogl_clip_pop (); + cogl_framebuffer_pop_clip (fb); break; case PAINT_OP_PATH: diff --git a/clutter/clutter-stage.c b/clutter/clutter-stage.c index 9d634bc6f..0f2e7d9a7 100644 --- a/clutter/clutter-stage.c +++ b/clutter/clutter-stage.c @@ -1490,6 +1490,8 @@ _clutter_stage_do_pick (ClutterStage *stage, clutter_stage_ensure_current (stage); window_scale = _clutter_stage_window_get_scale_factor (priv->impl); + fb = cogl_get_draw_framebuffer (); + _clutter_backend_ensure_context (context->backend, stage); /* needed for when a context switch happens */ @@ -1498,7 +1500,7 @@ _clutter_stage_do_pick (ClutterStage *stage, _clutter_stage_window_get_dirty_pixel (priv->impl, &dirty_x, &dirty_y); if (G_LIKELY (!(clutter_pick_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS))) - cogl_clip_push_window_rectangle (dirty_x * window_scale, dirty_y * window_scale, 1, 1); + cogl_framebuffer_push_scissor_clip (fb, dirty_x * window_scale, dirty_y * window_scale, 1, 1); cogl_set_viewport (priv->viewport[0] * window_scale - x * window_scale + dirty_x * window_scale, priv->viewport[1] * window_scale - y * window_scale + dirty_y * window_scale, @@ -1518,7 +1520,6 @@ _clutter_stage_do_pick (ClutterStage *stage, CLUTTER_TIMER_STOP (_clutter_uprof_context, pick_clear); /* Disable dithering (if any) when doing the painting in pick mode */ - fb = cogl_get_draw_framebuffer (); dither_enabled_save = cogl_framebuffer_get_dither_enabled (fb); cogl_framebuffer_set_dither_enabled (fb, FALSE); @@ -1563,7 +1564,7 @@ _clutter_stage_do_pick (ClutterStage *stage, cogl_framebuffer_set_dither_enabled (fb, dither_enabled_save); if (G_LIKELY (!(clutter_pick_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS))) - cogl_clip_pop (); + cogl_framebuffer_pop_clip (fb); _clutter_stage_dirty_viewport (stage); diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index 03090f69e..40e4fa679 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -1632,6 +1632,11 @@ selection_paint (ClutterText *self) PangoLayout *layout = clutter_text_get_layout (self); CoglPath *selection_path = cogl_path_new (); CoglColor cogl_color = { 0, }; + CoglFramebuffer *fb; + + fb = _clutter_actor_get_active_framebuffer (actor); + if (G_UNLIKELY (fb == NULL)) + return; /* Paint selection background */ if (priv->selection_color_set) @@ -1653,8 +1658,7 @@ selection_paint (ClutterText *self) cogl_path_fill (selection_path); /* Paint selected text */ - cogl_framebuffer_push_path_clip (cogl_get_draw_framebuffer (), - selection_path); + cogl_framebuffer_push_path_clip (fb, selection_path); cogl_object_unref (selection_path); if (priv->selected_text_color_set) @@ -1670,7 +1674,7 @@ selection_paint (ClutterText *self) cogl_pango_render_layout (layout, priv->text_x, 0, &cogl_color, 0); - cogl_clip_pop (); + cogl_framebuffer_pop_clip (fb); } } } @@ -2205,6 +2209,7 @@ clutter_text_paint (ClutterActor *self) { ClutterText *text = CLUTTER_TEXT (self); ClutterTextPrivate *priv = text->priv; + CoglFramebuffer *fb; PangoLayout *layout; ClutterActorBox alloc = { 0, }; CoglColor color = { 0, }; @@ -2214,6 +2219,10 @@ clutter_text_paint (ClutterActor *self) gboolean clip_set = FALSE; gboolean bg_color_set = FALSE; guint n_chars; + float alloc_width; + float alloc_height; + + fb = _clutter_actor_get_active_framebuffer (self); /* Note that if anything in this paint method changes it needs to be reflected in the get_paint_volume implementation which is tightly @@ -2221,6 +2230,8 @@ clutter_text_paint (ClutterActor *self) n_chars = clutter_text_buffer_get_length (get_buffer (text)); clutter_actor_get_allocation_box (self, &alloc); + alloc_width = alloc.x2 - alloc.x1; + alloc_height = alloc.y2 - alloc.y1; g_object_get (self, "background-color-set", &bg_color_set, NULL); if (bg_color_set) @@ -2236,7 +2247,7 @@ clutter_text_paint (ClutterActor *self) bg_color.green, bg_color.blue, bg_color.alpha); - cogl_rectangle (0, 0, alloc.x2 - alloc.x1, alloc.y2 - alloc.y1); + cogl_rectangle (0, 0, alloc_width, alloc_height); } /* don't bother painting an empty text actor, unless it's @@ -2256,9 +2267,7 @@ clutter_text_paint (ClutterActor *self) */ if (priv->wrap && priv->ellipsize) { - layout = clutter_text_create_layout (text, - alloc.x2 - alloc.x1, - alloc.y2 - alloc.y1); + layout = clutter_text_create_layout (text, alloc_width, alloc_height); } else { @@ -2275,9 +2284,7 @@ clutter_text_paint (ClutterActor *self) * in the assigned width, then we clip the actor if the * logical rectangle overflows the allocation. */ - layout = clutter_text_create_layout (text, - alloc.x2 - alloc.x1, - -1); + layout = clutter_text_create_layout (text, alloc_width, -1); } } @@ -2292,13 +2299,10 @@ clutter_text_paint (ClutterActor *self) pango_layout_get_extents (layout, NULL, &logical_rect); - cogl_clip_push_rectangle (0, 0, - (alloc.x2 - alloc.x1), - (alloc.y2 - alloc.y1)); + cogl_framebuffer_push_rectangle_clip (fb, 0, 0, alloc_width, alloc_height); clip_set = TRUE; - actor_width = (alloc.x2 - alloc.x1) - - 2 * TEXT_PADDING; + actor_width = alloc_width - 2 * TEXT_PADDING; text_width = logical_rect.width / PANGO_SCALE; rtl = clutter_actor_get_text_direction (self) == CLUTTER_TEXT_DIRECTION_RTL; @@ -2339,12 +2343,10 @@ clutter_text_paint (ClutterActor *self) pango_layout_get_pixel_extents (layout, NULL, &logical_rect); /* don't clip if the layout managed to fit inside our allocation */ - if (logical_rect.width > (alloc.x2 - alloc.x1) || - logical_rect.height > (alloc.y2 - alloc.y1)) + if (logical_rect.width > alloc_width || + logical_rect.height > alloc_height) { - cogl_clip_push_rectangle (0, 0, - alloc.x2 - alloc.x1, - alloc.y2 - alloc.y1); + cogl_framebuffer_push_rectangle_clip (fb, 0, 0, alloc_width, alloc_height); clip_set = TRUE; } @@ -2379,7 +2381,7 @@ clutter_text_paint (ClutterActor *self) selection_paint (text); if (clip_set) - cogl_clip_pop (); + cogl_framebuffer_pop_clip (fb); } static void diff --git a/clutter/cogl/clutter-stage-cogl.c b/clutter/cogl/clutter-stage-cogl.c index 3aa02bdad..fd91491cc 100644 --- a/clutter/cogl/clutter-stage-cogl.c +++ b/clutter/cogl/clutter-stage-cogl.c @@ -518,6 +518,8 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window) if (use_clipped_redraw) { + CoglFramebuffer *fb = COGL_FRAMEBUFFER (stage_cogl->onscreen); + CLUTTER_NOTE (CLIPPING, "Stage clip pushed: x=%d, y=%d, width=%d, height=%d\n", clip_region->x, @@ -527,12 +529,13 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window) stage_cogl->using_clipped_redraw = TRUE; - cogl_clip_push_window_rectangle (clip_region->x * window_scale, - clip_region->y * window_scale, - clip_region->width * window_scale, - clip_region->height * window_scale); + cogl_framebuffer_push_rectangle_clip (fb, + clip_region->x * window_scale, + clip_region->y * window_scale, + clip_region->width * window_scale, + clip_region->height * window_scale); _clutter_stage_do_paint (CLUTTER_STAGE (wrapper), clip_region); - cogl_clip_pop (); + cogl_framebuffer_pop_clip (fb); stage_cogl->using_clipped_redraw = FALSE; }