clutter/actor: Draw paint volumes using paint nodes
Clutter has a draw debug mode that allows for painting paint volumes. Right now, this debug mode uses the old immediate paint mode. Switch the painting of paint volumes to use paint nodes, and sneak a few minor style cleanups. https://gitlab.gnome.org/GNOME/mutter/merge_requests/890
This commit is contained in:
parent
03b59f9e19
commit
044238b503
@ -3405,20 +3405,20 @@ _clutter_actor_apply_relative_transformation_matrix (ClutterActor *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_clutter_actor_draw_paint_volume_full (ClutterActor *self,
|
_clutter_actor_draw_paint_volume_full (ClutterActor *self,
|
||||||
ClutterPaintVolume *pv,
|
ClutterPaintVolume *pv,
|
||||||
const char *label,
|
const char *label,
|
||||||
const CoglColor *color)
|
const ClutterColor *color,
|
||||||
|
ClutterPaintNode *node)
|
||||||
{
|
{
|
||||||
|
g_autoptr (ClutterPaintNode) pipeline_node = NULL;
|
||||||
static CoglPipeline *outline = NULL;
|
static CoglPipeline *outline = NULL;
|
||||||
CoglPrimitive *prim;
|
CoglPrimitive *prim;
|
||||||
graphene_point3d_t line_ends[12 * 2];
|
graphene_point3d_t line_ends[12 * 2];
|
||||||
int n_vertices;
|
int n_vertices;
|
||||||
CoglContext *ctx =
|
CoglContext *ctx =
|
||||||
clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
||||||
/* XXX: at some point we'll query this from the stage but we can't
|
CoglColor cogl_color;
|
||||||
* do that until the osx backend uses Cogl natively. */
|
|
||||||
CoglFramebuffer *fb = cogl_get_draw_framebuffer ();
|
|
||||||
|
|
||||||
if (outline == NULL)
|
if (outline == NULL)
|
||||||
outline = cogl_pipeline_new (ctx);
|
outline = cogl_pipeline_new (ctx);
|
||||||
@ -3452,29 +3452,50 @@ _clutter_actor_draw_paint_volume_full (ClutterActor *self,
|
|||||||
n_vertices,
|
n_vertices,
|
||||||
(CoglVertexP3 *)line_ends);
|
(CoglVertexP3 *)line_ends);
|
||||||
|
|
||||||
cogl_pipeline_set_color (outline, color);
|
cogl_color_set_from_4ub (&cogl_color,
|
||||||
cogl_framebuffer_draw_primitive (fb, outline, prim);
|
color->red,
|
||||||
|
color->green,
|
||||||
|
color->blue,
|
||||||
|
color->alpha);
|
||||||
|
cogl_pipeline_set_color (outline, &cogl_color);
|
||||||
|
|
||||||
|
pipeline_node = clutter_pipeline_node_new (outline);
|
||||||
|
clutter_paint_node_set_name (pipeline_node,
|
||||||
|
"ClutterActor (paint volume outline)");
|
||||||
|
clutter_paint_node_add_primitive (pipeline_node, prim);
|
||||||
|
clutter_paint_node_add_child (node, pipeline_node);
|
||||||
cogl_object_unref (prim);
|
cogl_object_unref (prim);
|
||||||
|
|
||||||
if (label)
|
if (label)
|
||||||
{
|
{
|
||||||
|
g_autoptr (ClutterPaintNode) text_node = NULL;
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
|
|
||||||
layout = pango_layout_new (clutter_actor_get_pango_context (self));
|
layout = pango_layout_new (clutter_actor_get_pango_context (self));
|
||||||
pango_layout_set_text (layout, label, -1);
|
pango_layout_set_text (layout, label, -1);
|
||||||
cogl_pango_render_layout (layout,
|
|
||||||
pv->vertices[0].x,
|
text_node = clutter_text_node_new (layout, color);
|
||||||
pv->vertices[0].y,
|
clutter_paint_node_set_name (text_node,
|
||||||
color,
|
"ClutterActor (paint volume label)");
|
||||||
0);
|
clutter_paint_node_add_rectangle (text_node,
|
||||||
|
&(ClutterActorBox) {
|
||||||
|
.x1 = pv->vertices[0].x,
|
||||||
|
.y1 = pv->vertices[0].y,
|
||||||
|
.x2 = pv->vertices[2].x,
|
||||||
|
.y2 = pv->vertices[2].y,
|
||||||
|
});
|
||||||
|
clutter_paint_node_add_child (node, text_node);
|
||||||
|
|
||||||
g_object_unref (layout);
|
g_object_unref (layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_clutter_actor_draw_paint_volume (ClutterActor *self)
|
_clutter_actor_draw_paint_volume (ClutterActor *self,
|
||||||
|
ClutterPaintNode *node)
|
||||||
{
|
{
|
||||||
ClutterPaintVolume *pv;
|
ClutterPaintVolume *pv;
|
||||||
CoglColor color;
|
ClutterColor color;
|
||||||
|
|
||||||
pv = _clutter_actor_get_paint_volume_mutable (self);
|
pv = _clutter_actor_get_paint_volume_mutable (self);
|
||||||
if (!pv)
|
if (!pv)
|
||||||
@ -3489,61 +3510,79 @@ _clutter_actor_draw_paint_volume (ClutterActor *self)
|
|||||||
clutter_paint_volume_set_width (&fake_pv, width);
|
clutter_paint_volume_set_width (&fake_pv, width);
|
||||||
clutter_paint_volume_set_height (&fake_pv, height);
|
clutter_paint_volume_set_height (&fake_pv, height);
|
||||||
|
|
||||||
cogl_color_init_from_4f (&color, 0, 0, 1, 1);
|
clutter_color_init (&color, 0, 0, 255, 255);
|
||||||
_clutter_actor_draw_paint_volume_full (self, &fake_pv,
|
_clutter_actor_draw_paint_volume_full (self, &fake_pv,
|
||||||
_clutter_actor_get_debug_name (self),
|
_clutter_actor_get_debug_name (self),
|
||||||
&color);
|
&color,
|
||||||
|
node);
|
||||||
|
|
||||||
clutter_paint_volume_free (&fake_pv);
|
clutter_paint_volume_free (&fake_pv);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cogl_color_init_from_4f (&color, 0, 1, 0, 1);
|
clutter_color_init (&color, 0, 255, 0, 255);
|
||||||
_clutter_actor_draw_paint_volume_full (self, pv,
|
_clutter_actor_draw_paint_volume_full (self, pv,
|
||||||
_clutter_actor_get_debug_name (self),
|
_clutter_actor_get_debug_name (self),
|
||||||
&color);
|
&color,
|
||||||
|
node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_clutter_actor_paint_cull_result (ClutterActor *self,
|
_clutter_actor_paint_cull_result (ClutterActor *self,
|
||||||
gboolean success,
|
gboolean success,
|
||||||
ClutterCullResult result)
|
ClutterCullResult result,
|
||||||
|
ClutterPaintNode *node)
|
||||||
{
|
{
|
||||||
|
ClutterActorPrivate *priv = self->priv;
|
||||||
ClutterPaintVolume *pv;
|
ClutterPaintVolume *pv;
|
||||||
CoglColor color;
|
ClutterColor color;
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
if (result == CLUTTER_CULL_RESULT_IN)
|
if (result == CLUTTER_CULL_RESULT_IN)
|
||||||
cogl_color_init_from_4f (&color, 0, 1, 0, 1);
|
clutter_color_init (&color, 0, 255, 0, 255);
|
||||||
else if (result == CLUTTER_CULL_RESULT_OUT)
|
else if (result == CLUTTER_CULL_RESULT_OUT)
|
||||||
cogl_color_init_from_4f (&color, 0, 0, 1, 1);
|
clutter_color_init (&color, 0, 0, 255, 255);
|
||||||
else
|
else
|
||||||
cogl_color_init_from_4f (&color, 0, 1, 1, 1);
|
clutter_color_init (&color, 0, 255, 255, 255);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cogl_color_init_from_4f (&color, 1, 1, 1, 1);
|
clutter_color_init (&color, 255, 255, 255, 255);
|
||||||
|
|
||||||
if (success && (pv = _clutter_actor_get_paint_volume_mutable (self)))
|
if (success && (pv = _clutter_actor_get_paint_volume_mutable (self)))
|
||||||
_clutter_actor_draw_paint_volume_full (self, pv,
|
_clutter_actor_draw_paint_volume_full (self, pv,
|
||||||
_clutter_actor_get_debug_name (self),
|
_clutter_actor_get_debug_name (self),
|
||||||
&color);
|
&color,
|
||||||
|
node);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
g_autoptr (ClutterPaintNode) text_node = NULL;
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
|
float width;
|
||||||
|
float height;
|
||||||
char *label =
|
char *label =
|
||||||
g_strdup_printf ("CULL FAILURE: %s", _clutter_actor_get_debug_name (self));
|
g_strdup_printf ("CULL FAILURE: %s", _clutter_actor_get_debug_name (self));
|
||||||
cogl_color_init_from_4f (&color, 1, 1, 1, 1);
|
clutter_color_init (&color, 255, 255, 255, 255);
|
||||||
cogl_set_source_color (&color);
|
|
||||||
|
width = clutter_actor_box_get_width (&priv->allocation);
|
||||||
|
height = clutter_actor_box_get_height (&priv->allocation);
|
||||||
|
|
||||||
layout = pango_layout_new (clutter_actor_get_pango_context (self));
|
layout = pango_layout_new (clutter_actor_get_pango_context (self));
|
||||||
pango_layout_set_text (layout, label, -1);
|
pango_layout_set_text (layout, label, -1);
|
||||||
cogl_pango_render_layout (layout,
|
|
||||||
0,
|
text_node = clutter_text_node_new (layout, &color);
|
||||||
0,
|
clutter_paint_node_set_name (text_node,
|
||||||
&color,
|
"ClutterActor (paint volume text)");
|
||||||
0);
|
clutter_paint_node_add_rectangle (text_node,
|
||||||
|
&(ClutterActorBox) {
|
||||||
|
.x1 = 0.f,
|
||||||
|
.y1 = 0.f,
|
||||||
|
.x2 = width,
|
||||||
|
.y2 = height,
|
||||||
|
});
|
||||||
|
clutter_paint_node_add_child (node, text_node);
|
||||||
|
|
||||||
g_free (label);
|
g_free (label);
|
||||||
g_object_unref (layout);
|
g_object_unref (layout);
|
||||||
}
|
}
|
||||||
@ -4039,7 +4078,7 @@ clutter_actor_paint (ClutterActor *self)
|
|||||||
success = cull_actor (self, &result);
|
success = cull_actor (self, &result);
|
||||||
|
|
||||||
if (G_UNLIKELY (clutter_paint_debug_flags & CLUTTER_DEBUG_REDRAWS))
|
if (G_UNLIKELY (clutter_paint_debug_flags & CLUTTER_DEBUG_REDRAWS))
|
||||||
_clutter_actor_paint_cull_result (self, success, result);
|
_clutter_actor_paint_cull_result (self, success, result, actor_node);
|
||||||
else if (result == CLUTTER_CULL_RESULT_OUT && success)
|
else if (result == CLUTTER_CULL_RESULT_OUT && success)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -4050,10 +4089,10 @@ clutter_actor_paint (ClutterActor *self)
|
|||||||
priv->next_effect_to_paint =
|
priv->next_effect_to_paint =
|
||||||
_clutter_meta_group_peek_metas (priv->effects);
|
_clutter_meta_group_peek_metas (priv->effects);
|
||||||
|
|
||||||
clutter_paint_node_paint (root_node);
|
|
||||||
|
|
||||||
if (G_UNLIKELY (clutter_paint_debug_flags & CLUTTER_DEBUG_PAINT_VOLUMES))
|
if (G_UNLIKELY (clutter_paint_debug_flags & CLUTTER_DEBUG_PAINT_VOLUMES))
|
||||||
_clutter_actor_draw_paint_volume (self);
|
_clutter_actor_draw_paint_volume (self, actor_node);
|
||||||
|
|
||||||
|
clutter_paint_node_paint (root_node);
|
||||||
|
|
||||||
/* If we make it here then the actor has run through a complete
|
/* If we make it here then the actor has run through a complete
|
||||||
paint run including all the effects so it's no longer dirty */
|
paint run including all the effects so it's no longer dirty */
|
||||||
|
Loading…
Reference in New Issue
Block a user