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.
This commit is contained in:
Emmanuele Bassi 2013-12-03 12:12:52 +00:00
parent 1b45841414
commit 705640367a
5 changed files with 69 additions and 48 deletions

View File

@ -3352,10 +3352,11 @@ in_clone_paint (void)
* means there's no point in trying to cull descendants of the current * means there's no point in trying to cull descendants of the current
* node. */ * node. */
static gboolean static gboolean
cull_actor (ClutterActor *self, ClutterCullResult *result_out) cull_actor (ClutterActor *self,
ClutterCullResult *result_out)
{ {
ClutterActorPrivate *priv = self->priv; ClutterActorPrivate *priv = self->priv;
ClutterActor *stage; ClutterStage *stage;
const ClutterPlane *stage_clip; const ClutterPlane *stage_clip;
if (!priv->last_paint_volume_valid) 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)) if (G_UNLIKELY (clutter_paint_debug_flags & CLUTTER_DEBUG_DISABLE_CULLING))
return FALSE; return FALSE;
stage = _clutter_actor_get_stage_internal (self); stage = (ClutterStage *) _clutter_actor_get_stage_internal (self);
stage_clip = _clutter_stage_get_clip (CLUTTER_STAGE (stage)); stage_clip = _clutter_stage_get_clip (stage);
if (G_UNLIKELY (!stage_clip)) if (G_UNLIKELY (!stage_clip))
{ {
CLUTTER_NOTE (CLIPPING, "Bail from cull_actor without culling (%s): " CLUTTER_NOTE (CLIPPING, "Bail from cull_actor without culling (%s): "
@ -3379,8 +3380,7 @@ cull_actor (ClutterActor *self, ClutterCullResult *result_out)
return FALSE; return FALSE;
} }
if (cogl_get_draw_framebuffer () != if (cogl_get_draw_framebuffer () != _clutter_stage_get_active_framebuffer (stage))
_clutter_stage_get_active_framebuffer (CLUTTER_STAGE (stage)))
{ {
CLUTTER_NOTE (CLIPPING, "Bail from cull_actor without culling (%s): " CLUTTER_NOTE (CLIPPING, "Bail from cull_actor without culling (%s): "
"Current framebuffer doesn't correspond to stage", "Current framebuffer doesn't correspond to stage",
@ -3390,6 +3390,7 @@ cull_actor (ClutterActor *self, ClutterCullResult *result_out)
*result_out = *result_out =
_clutter_paint_volume_cull (&priv->last_paint_volume, stage_clip); _clutter_paint_volume_cull (&priv->last_paint_volume, stage_clip);
return TRUE; return TRUE;
} }
@ -3664,6 +3665,7 @@ clutter_actor_paint (ClutterActor *self)
ClutterPickMode pick_mode; ClutterPickMode pick_mode;
gboolean clip_set = FALSE; gboolean clip_set = FALSE;
gboolean shader_applied = FALSE; gboolean shader_applied = FALSE;
ClutterStage *stage;
CLUTTER_STATIC_COUNTER (actor_paint_counter, CLUTTER_STATIC_COUNTER (actor_paint_counter,
"Actor real-paint counter", "Actor real-paint counter",
@ -3703,6 +3705,8 @@ clutter_actor_paint (ClutterActor *self)
if (!CLUTTER_ACTOR_IS_MAPPED (self)) if (!CLUTTER_ACTOR_IS_MAPPED (self))
return; return;
stage = (ClutterStage *) _clutter_actor_get_stage_internal (self);
/* mark that we are in the paint process */ /* mark that we are in the paint process */
CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_IN_PAINT); CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_IN_PAINT);
@ -3761,7 +3765,9 @@ clutter_actor_paint (ClutterActor *self)
if (priv->has_clip) if (priv->has_clip)
{ {
cogl_clip_push_rectangle (priv->clip.origin.x, 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.y,
priv->clip.origin.x + priv->clip.size.width, priv->clip.origin.x + priv->clip.size.width,
priv->clip.origin.y + priv->clip.size.height); priv->clip.origin.y + priv->clip.size.height);
@ -3769,12 +3775,13 @@ clutter_actor_paint (ClutterActor *self)
} }
else if (priv->clip_to_allocation) else if (priv->clip_to_allocation)
{ {
CoglFramebuffer *fb = _clutter_stage_get_active_framebuffer (stage);
gfloat width, height; gfloat width, height;
width = priv->allocation.x2 - priv->allocation.x1; width = priv->allocation.x2 - priv->allocation.x1;
height = priv->allocation.y2 - priv->allocation.y1; 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; clip_set = TRUE;
} }
@ -3871,7 +3878,11 @@ done:
priv->is_dirty = FALSE; priv->is_dirty = FALSE;
if (clip_set) if (clip_set)
cogl_clip_pop(); {
CoglFramebuffer *fb = _clutter_stage_get_active_framebuffer (stage);
cogl_framebuffer_pop_clip (fb);
}
cogl_pop_matrix (); cogl_pop_matrix ();

View File

@ -758,11 +758,14 @@ clutter_text_node_draw (ClutterPaintNode *node)
{ {
ClutterTextNode *tnode = CLUTTER_TEXT_NODE (node); ClutterTextNode *tnode = CLUTTER_TEXT_NODE (node);
PangoRectangle extents; PangoRectangle extents;
CoglFramebuffer *fb;
guint i; guint i;
if (node->operations == NULL) if (node->operations == NULL)
return; return;
fb = cogl_get_draw_framebuffer ();
pango_layout_get_pixel_extents (tnode->layout, NULL, &extents); pango_layout_get_pixel_extents (tnode->layout, NULL, &extents);
for (i = 0; i < node->operations->len; i++) for (i = 0; i < node->operations->len; i++)
@ -786,7 +789,8 @@ clutter_text_node_draw (ClutterPaintNode *node)
if (extents.width > op_width || if (extents.width > op_width ||
extents.height > op_height) extents.height > op_height)
{ {
cogl_clip_push_rectangle (op->op.texrect[0], cogl_framebuffer_push_rectangle_clip (fb,
op->op.texrect[0],
op->op.texrect[1], op->op.texrect[1],
op->op.texrect[2], op->op.texrect[2],
op->op.texrect[3]); op->op.texrect[3]);
@ -800,7 +804,7 @@ clutter_text_node_draw (ClutterPaintNode *node)
0); 0);
if (clipped) if (clipped)
cogl_clip_pop (); cogl_framebuffer_pop_clip (fb);
break; break;
case PAINT_OP_PATH: case PAINT_OP_PATH:

View File

@ -1490,6 +1490,8 @@ _clutter_stage_do_pick (ClutterStage *stage,
clutter_stage_ensure_current (stage); clutter_stage_ensure_current (stage);
window_scale = _clutter_stage_window_get_scale_factor (priv->impl); window_scale = _clutter_stage_window_get_scale_factor (priv->impl);
fb = cogl_get_draw_framebuffer ();
_clutter_backend_ensure_context (context->backend, stage); _clutter_backend_ensure_context (context->backend, stage);
/* needed for when a context switch happens */ /* 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); _clutter_stage_window_get_dirty_pixel (priv->impl, &dirty_x, &dirty_y);
if (G_LIKELY (!(clutter_pick_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS))) 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, 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, 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); CLUTTER_TIMER_STOP (_clutter_uprof_context, pick_clear);
/* Disable dithering (if any) when doing the painting in pick mode */ /* 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); dither_enabled_save = cogl_framebuffer_get_dither_enabled (fb);
cogl_framebuffer_set_dither_enabled (fb, FALSE); 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); cogl_framebuffer_set_dither_enabled (fb, dither_enabled_save);
if (G_LIKELY (!(clutter_pick_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS))) 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); _clutter_stage_dirty_viewport (stage);

View File

@ -1632,6 +1632,11 @@ selection_paint (ClutterText *self)
PangoLayout *layout = clutter_text_get_layout (self); PangoLayout *layout = clutter_text_get_layout (self);
CoglPath *selection_path = cogl_path_new (); CoglPath *selection_path = cogl_path_new ();
CoglColor cogl_color = { 0, }; CoglColor cogl_color = { 0, };
CoglFramebuffer *fb;
fb = _clutter_actor_get_active_framebuffer (actor);
if (G_UNLIKELY (fb == NULL))
return;
/* Paint selection background */ /* Paint selection background */
if (priv->selection_color_set) if (priv->selection_color_set)
@ -1653,8 +1658,7 @@ selection_paint (ClutterText *self)
cogl_path_fill (selection_path); cogl_path_fill (selection_path);
/* Paint selected text */ /* Paint selected text */
cogl_framebuffer_push_path_clip (cogl_get_draw_framebuffer (), cogl_framebuffer_push_path_clip (fb, selection_path);
selection_path);
cogl_object_unref (selection_path); cogl_object_unref (selection_path);
if (priv->selected_text_color_set) 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_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); ClutterText *text = CLUTTER_TEXT (self);
ClutterTextPrivate *priv = text->priv; ClutterTextPrivate *priv = text->priv;
CoglFramebuffer *fb;
PangoLayout *layout; PangoLayout *layout;
ClutterActorBox alloc = { 0, }; ClutterActorBox alloc = { 0, };
CoglColor color = { 0, }; CoglColor color = { 0, };
@ -2214,6 +2219,10 @@ clutter_text_paint (ClutterActor *self)
gboolean clip_set = FALSE; gboolean clip_set = FALSE;
gboolean bg_color_set = FALSE; gboolean bg_color_set = FALSE;
guint n_chars; 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 /* Note that if anything in this paint method changes it needs to be
reflected in the get_paint_volume implementation which is tightly 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)); n_chars = clutter_text_buffer_get_length (get_buffer (text));
clutter_actor_get_allocation_box (self, &alloc); 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); g_object_get (self, "background-color-set", &bg_color_set, NULL);
if (bg_color_set) if (bg_color_set)
@ -2236,7 +2247,7 @@ clutter_text_paint (ClutterActor *self)
bg_color.green, bg_color.green,
bg_color.blue, bg_color.blue,
bg_color.alpha); 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 /* 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) if (priv->wrap && priv->ellipsize)
{ {
layout = clutter_text_create_layout (text, layout = clutter_text_create_layout (text, alloc_width, alloc_height);
alloc.x2 - alloc.x1,
alloc.y2 - alloc.y1);
} }
else else
{ {
@ -2275,9 +2284,7 @@ clutter_text_paint (ClutterActor *self)
* in the assigned width, then we clip the actor if the * in the assigned width, then we clip the actor if the
* logical rectangle overflows the allocation. * logical rectangle overflows the allocation.
*/ */
layout = clutter_text_create_layout (text, layout = clutter_text_create_layout (text, alloc_width, -1);
alloc.x2 - alloc.x1,
-1);
} }
} }
@ -2292,13 +2299,10 @@ clutter_text_paint (ClutterActor *self)
pango_layout_get_extents (layout, NULL, &logical_rect); pango_layout_get_extents (layout, NULL, &logical_rect);
cogl_clip_push_rectangle (0, 0, cogl_framebuffer_push_rectangle_clip (fb, 0, 0, alloc_width, alloc_height);
(alloc.x2 - alloc.x1),
(alloc.y2 - alloc.y1));
clip_set = TRUE; clip_set = TRUE;
actor_width = (alloc.x2 - alloc.x1) actor_width = alloc_width - 2 * TEXT_PADDING;
- 2 * TEXT_PADDING;
text_width = logical_rect.width / PANGO_SCALE; text_width = logical_rect.width / PANGO_SCALE;
rtl = clutter_actor_get_text_direction (self) == CLUTTER_TEXT_DIRECTION_RTL; 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); pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
/* don't clip if the layout managed to fit inside our allocation */ /* don't clip if the layout managed to fit inside our allocation */
if (logical_rect.width > (alloc.x2 - alloc.x1) || if (logical_rect.width > alloc_width ||
logical_rect.height > (alloc.y2 - alloc.y1)) logical_rect.height > alloc_height)
{ {
cogl_clip_push_rectangle (0, 0, cogl_framebuffer_push_rectangle_clip (fb, 0, 0, alloc_width, alloc_height);
alloc.x2 - alloc.x1,
alloc.y2 - alloc.y1);
clip_set = TRUE; clip_set = TRUE;
} }
@ -2379,7 +2381,7 @@ clutter_text_paint (ClutterActor *self)
selection_paint (text); selection_paint (text);
if (clip_set) if (clip_set)
cogl_clip_pop (); cogl_framebuffer_pop_clip (fb);
} }
static void static void

View File

@ -518,6 +518,8 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window)
if (use_clipped_redraw) if (use_clipped_redraw)
{ {
CoglFramebuffer *fb = COGL_FRAMEBUFFER (stage_cogl->onscreen);
CLUTTER_NOTE (CLIPPING, CLUTTER_NOTE (CLIPPING,
"Stage clip pushed: x=%d, y=%d, width=%d, height=%d\n", "Stage clip pushed: x=%d, y=%d, width=%d, height=%d\n",
clip_region->x, clip_region->x,
@ -527,12 +529,13 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window)
stage_cogl->using_clipped_redraw = TRUE; stage_cogl->using_clipped_redraw = TRUE;
cogl_clip_push_window_rectangle (clip_region->x * window_scale, cogl_framebuffer_push_rectangle_clip (fb,
clip_region->x * window_scale,
clip_region->y * window_scale, clip_region->y * window_scale,
clip_region->width * window_scale, clip_region->width * window_scale,
clip_region->height * window_scale); clip_region->height * window_scale);
_clutter_stage_do_paint (CLUTTER_STAGE (wrapper), clip_region); _clutter_stage_do_paint (CLUTTER_STAGE (wrapper), clip_region);
cogl_clip_pop (); cogl_framebuffer_pop_clip (fb);
stage_cogl->using_clipped_redraw = FALSE; stage_cogl->using_clipped_redraw = FALSE;
} }