mirror of
https://github.com/brl/mutter.git
synced 2024-12-25 04:22:05 +00:00
[CoglPangoDisplayList] Don't store the base color in the display list
It should be possible render a single PangoLayout with different colors without recalculating the layout. This was not working because the color used at the first edit was being stored in the display list. This broke changing the opacity on a ClutterText. Now each node in the display list has a 'color override' flag which marks whether it should use the base color or not. The base color is now passed in from _cogl_pango_display_list_render_texture. The alpha value is always taken from the base color.
This commit is contained in:
parent
6fe22ac850
commit
ea15e4c7f0
@ -43,6 +43,7 @@ typedef struct _CoglPangoDisplayListVertex CoglPangoDisplayListVertex;
|
|||||||
|
|
||||||
struct _CoglPangoDisplayList
|
struct _CoglPangoDisplayList
|
||||||
{
|
{
|
||||||
|
gboolean color_override;
|
||||||
CoglColor color;
|
CoglColor color;
|
||||||
GSList *nodes;
|
GSList *nodes;
|
||||||
GSList *last_node;
|
GSList *last_node;
|
||||||
@ -52,6 +53,7 @@ struct _CoglPangoDisplayListNode
|
|||||||
{
|
{
|
||||||
CoglPangoDisplayListNodeType type;
|
CoglPangoDisplayListNodeType type;
|
||||||
|
|
||||||
|
gboolean color_override;
|
||||||
CoglColor color;
|
CoglColor color;
|
||||||
|
|
||||||
union
|
union
|
||||||
@ -106,12 +108,19 @@ _cogl_pango_display_list_append_node (CoglPangoDisplayList *dl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_pango_display_list_set_color (CoglPangoDisplayList *dl,
|
_cogl_pango_display_list_set_color_override (CoglPangoDisplayList *dl,
|
||||||
const CoglColor *color)
|
const CoglColor *color)
|
||||||
{
|
{
|
||||||
|
dl->color_override = TRUE;
|
||||||
dl->color = *color;
|
dl->color = *color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_cogl_pango_display_list_remove_color_override (CoglPangoDisplayList *dl)
|
||||||
|
{
|
||||||
|
dl->color_override = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
|
_cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
|
||||||
CoglHandle texture,
|
CoglHandle texture,
|
||||||
@ -128,7 +137,10 @@ _cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
|
|||||||
if (dl->last_node
|
if (dl->last_node
|
||||||
&& (node = dl->last_node->data)->type == COGL_PANGO_DISPLAY_LIST_TEXTURE
|
&& (node = dl->last_node->data)->type == COGL_PANGO_DISPLAY_LIST_TEXTURE
|
||||||
&& node->d.texture.texture == texture
|
&& node->d.texture.texture == texture
|
||||||
&& !memcmp (&dl->color, &node->color, sizeof (CoglColor)))
|
&& (dl->color_override
|
||||||
|
? (node->color_override && !memcmp (&dl->color, &node->color,
|
||||||
|
sizeof (CoglColor)))
|
||||||
|
: !node->color_override))
|
||||||
{
|
{
|
||||||
/* Get rid of the vertex buffer so that it will be recreated */
|
/* Get rid of the vertex buffer so that it will be recreated */
|
||||||
if (node->d.texture.vertex_buffer != COGL_INVALID_HANDLE)
|
if (node->d.texture.vertex_buffer != COGL_INVALID_HANDLE)
|
||||||
@ -143,6 +155,7 @@ _cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
|
|||||||
node = g_slice_new (CoglPangoDisplayListNode);
|
node = g_slice_new (CoglPangoDisplayListNode);
|
||||||
|
|
||||||
node->type = COGL_PANGO_DISPLAY_LIST_TEXTURE;
|
node->type = COGL_PANGO_DISPLAY_LIST_TEXTURE;
|
||||||
|
node->color_override = dl->color_override;
|
||||||
node->color = dl->color;
|
node->color = dl->color;
|
||||||
node->d.texture.texture = cogl_texture_ref (texture);
|
node->d.texture.texture = cogl_texture_ref (texture);
|
||||||
node->d.texture.verts
|
node->d.texture.verts
|
||||||
@ -187,6 +200,7 @@ _cogl_pango_display_list_add_rectangle (CoglPangoDisplayList *dl,
|
|||||||
CoglPangoDisplayListNode *node = g_slice_new (CoglPangoDisplayListNode);
|
CoglPangoDisplayListNode *node = g_slice_new (CoglPangoDisplayListNode);
|
||||||
|
|
||||||
node->type = COGL_PANGO_DISPLAY_LIST_RECTANGLE;
|
node->type = COGL_PANGO_DISPLAY_LIST_RECTANGLE;
|
||||||
|
node->color_override = dl->color_override;
|
||||||
node->color = dl->color;
|
node->color = dl->color;
|
||||||
node->d.rectangle.x_1 = x_1;
|
node->d.rectangle.x_1 = x_1;
|
||||||
node->d.rectangle.y_1 = y_1;
|
node->d.rectangle.y_1 = y_1;
|
||||||
@ -208,6 +222,7 @@ _cogl_pango_display_list_add_trapezoid (CoglPangoDisplayList *dl,
|
|||||||
CoglPangoDisplayListNode *node = g_slice_new (CoglPangoDisplayListNode);
|
CoglPangoDisplayListNode *node = g_slice_new (CoglPangoDisplayListNode);
|
||||||
|
|
||||||
node->type = COGL_PANGO_DISPLAY_LIST_TRAPEZOID;
|
node->type = COGL_PANGO_DISPLAY_LIST_TRAPEZOID;
|
||||||
|
node->color_override = dl->color_override;
|
||||||
node->color = dl->color;
|
node->color = dl->color;
|
||||||
node->d.trapezoid.y_1 = y_1;
|
node->d.trapezoid.y_1 = y_1;
|
||||||
node->d.trapezoid.x_11 = x_11;
|
node->d.trapezoid.x_11 = x_11;
|
||||||
@ -221,10 +236,11 @@ _cogl_pango_display_list_add_trapezoid (CoglPangoDisplayList *dl,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
_cogl_pango_display_list_render_texture (CoglHandle material,
|
_cogl_pango_display_list_render_texture (CoglHandle material,
|
||||||
|
const CoglColor *color,
|
||||||
CoglPangoDisplayListNode *node)
|
CoglPangoDisplayListNode *node)
|
||||||
{
|
{
|
||||||
cogl_material_set_layer (material, 0, node->d.texture.texture);
|
cogl_material_set_layer (material, 0, node->d.texture.texture);
|
||||||
cogl_material_set_color (material, &node->color);
|
cogl_material_set_color (material, color);
|
||||||
cogl_set_source (material);
|
cogl_set_source (material);
|
||||||
|
|
||||||
if (node->d.texture.vertex_buffer == COGL_INVALID_HANDLE)
|
if (node->d.texture.vertex_buffer == COGL_INVALID_HANDLE)
|
||||||
@ -274,6 +290,7 @@ _cogl_pango_display_list_render_texture (CoglHandle material,
|
|||||||
|
|
||||||
void
|
void
|
||||||
_cogl_pango_display_list_render (CoglPangoDisplayList *dl,
|
_cogl_pango_display_list_render (CoglPangoDisplayList *dl,
|
||||||
|
const CoglColor *color,
|
||||||
CoglHandle glyph_material,
|
CoglHandle glyph_material,
|
||||||
CoglHandle solid_material)
|
CoglHandle solid_material)
|
||||||
{
|
{
|
||||||
@ -282,15 +299,28 @@ _cogl_pango_display_list_render (CoglPangoDisplayList *dl,
|
|||||||
for (l = dl->nodes; l; l = l->next)
|
for (l = dl->nodes; l; l = l->next)
|
||||||
{
|
{
|
||||||
CoglPangoDisplayListNode *node = l->data;
|
CoglPangoDisplayListNode *node = l->data;
|
||||||
|
CoglColor draw_color;
|
||||||
|
|
||||||
|
if (node->color_override)
|
||||||
|
/* Use the override color but preserve the alpha from the
|
||||||
|
draw color */
|
||||||
|
cogl_color_set_from_4ub (&draw_color,
|
||||||
|
cogl_color_get_red_byte (&node->color),
|
||||||
|
cogl_color_get_green_byte (&node->color),
|
||||||
|
cogl_color_get_blue_byte (&node->color),
|
||||||
|
cogl_color_get_alpha_byte (color));
|
||||||
|
else
|
||||||
|
draw_color = *color;
|
||||||
|
|
||||||
switch (node->type)
|
switch (node->type)
|
||||||
{
|
{
|
||||||
case COGL_PANGO_DISPLAY_LIST_TEXTURE:
|
case COGL_PANGO_DISPLAY_LIST_TEXTURE:
|
||||||
_cogl_pango_display_list_render_texture (glyph_material, node);
|
_cogl_pango_display_list_render_texture (glyph_material,
|
||||||
|
&draw_color, node);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COGL_PANGO_DISPLAY_LIST_RECTANGLE:
|
case COGL_PANGO_DISPLAY_LIST_RECTANGLE:
|
||||||
cogl_material_set_color (solid_material, &node->color);
|
cogl_material_set_color (solid_material, &draw_color);
|
||||||
cogl_set_source (solid_material);
|
cogl_set_source (solid_material);
|
||||||
cogl_rectangle (node->d.rectangle.x_1,
|
cogl_rectangle (node->d.rectangle.x_1,
|
||||||
node->d.rectangle.y_1,
|
node->d.rectangle.y_1,
|
||||||
@ -311,7 +341,7 @@ _cogl_pango_display_list_render (CoglPangoDisplayList *dl,
|
|||||||
points[6] = node->d.trapezoid.x_21;
|
points[6] = node->d.trapezoid.x_21;
|
||||||
points[7] = node->d.trapezoid.y_1;
|
points[7] = node->d.trapezoid.y_1;
|
||||||
|
|
||||||
cogl_material_set_color (solid_material, &node->color);
|
cogl_material_set_color (solid_material, &draw_color);
|
||||||
cogl_set_source (solid_material);
|
cogl_set_source (solid_material);
|
||||||
cogl_path_polygon (points, 4);
|
cogl_path_polygon (points, 4);
|
||||||
cogl_path_fill ();
|
cogl_path_fill ();
|
||||||
|
@ -33,8 +33,9 @@ typedef struct _CoglPangoDisplayList CoglPangoDisplayList;
|
|||||||
|
|
||||||
CoglPangoDisplayList *_cogl_pango_display_list_new (void);
|
CoglPangoDisplayList *_cogl_pango_display_list_new (void);
|
||||||
|
|
||||||
void _cogl_pango_display_list_set_color (CoglPangoDisplayList *dl,
|
void _cogl_pango_display_list_set_color_override (CoglPangoDisplayList *dl,
|
||||||
const CoglColor *color);
|
const CoglColor *color);
|
||||||
|
void _cogl_pango_display_list_remove_color_override (CoglPangoDisplayList *dl);
|
||||||
|
|
||||||
void _cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
|
void _cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
|
||||||
CoglHandle texture,
|
CoglHandle texture,
|
||||||
@ -56,6 +57,7 @@ void _cogl_pango_display_list_add_trapezoid (CoglPangoDisplayList *dl,
|
|||||||
float x_22);
|
float x_22);
|
||||||
|
|
||||||
void _cogl_pango_display_list_render (CoglPangoDisplayList *dl,
|
void _cogl_pango_display_list_render (CoglPangoDisplayList *dl,
|
||||||
|
const CoglColor *color,
|
||||||
CoglHandle glyph_material,
|
CoglHandle glyph_material,
|
||||||
CoglHandle solid_material);
|
CoglHandle solid_material);
|
||||||
|
|
||||||
|
@ -42,8 +42,6 @@ struct _CoglPangoRenderer
|
|||||||
{
|
{
|
||||||
PangoRenderer parent_instance;
|
PangoRenderer parent_instance;
|
||||||
|
|
||||||
/* The color to draw the glyphs with */
|
|
||||||
CoglColor color;
|
|
||||||
/* The material used to texture from the glyph cache with */
|
/* The material used to texture from the glyph cache with */
|
||||||
CoglHandle glyph_material;
|
CoglHandle glyph_material;
|
||||||
/* The material used for solid fills. (boxes, rectangles + trapezoids) */
|
/* The material used for solid fills. (boxes, rectangles + trapezoids) */
|
||||||
@ -261,7 +259,6 @@ cogl_pango_render_layout_subpixel (PangoLayout *layout,
|
|||||||
{
|
{
|
||||||
qdata->display_list = _cogl_pango_display_list_new ();
|
qdata->display_list = _cogl_pango_display_list_new ();
|
||||||
|
|
||||||
priv->color = *color;
|
|
||||||
priv->display_list = qdata->display_list;
|
priv->display_list = qdata->display_list;
|
||||||
pango_renderer_draw_layout (PANGO_RENDERER (priv), layout, 0, 0);
|
pango_renderer_draw_layout (PANGO_RENDERER (priv), layout, 0, 0);
|
||||||
priv->display_list = NULL;
|
priv->display_list = NULL;
|
||||||
@ -270,6 +267,7 @@ cogl_pango_render_layout_subpixel (PangoLayout *layout,
|
|||||||
cogl_push_matrix ();
|
cogl_push_matrix ();
|
||||||
cogl_translate (x / (gfloat) PANGO_SCALE, y / (gfloat) PANGO_SCALE, 0);
|
cogl_translate (x / (gfloat) PANGO_SCALE, y / (gfloat) PANGO_SCALE, 0);
|
||||||
_cogl_pango_display_list_render (qdata->display_list,
|
_cogl_pango_display_list_render (qdata->display_list,
|
||||||
|
color,
|
||||||
priv->glyph_material,
|
priv->glyph_material,
|
||||||
priv->solid_material);
|
priv->solid_material);
|
||||||
cogl_pop_matrix ();
|
cogl_pop_matrix ();
|
||||||
@ -340,13 +338,11 @@ cogl_pango_render_layout_line (PangoLayoutLine *line,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
priv->display_list = _cogl_pango_display_list_new ();
|
priv->display_list = _cogl_pango_display_list_new ();
|
||||||
priv->color = *color;
|
|
||||||
|
|
||||||
pango_renderer_draw_layout_line (PANGO_RENDERER (priv), line, x, y);
|
pango_renderer_draw_layout_line (PANGO_RENDERER (priv), line, x, y);
|
||||||
|
|
||||||
cogl_material_set_color (priv->glyph_material, color);
|
|
||||||
cogl_material_set_color (priv->solid_material, color);
|
|
||||||
_cogl_pango_display_list_render (priv->display_list,
|
_cogl_pango_display_list_render (priv->display_list,
|
||||||
|
color,
|
||||||
priv->glyph_material,
|
priv->glyph_material,
|
||||||
priv->solid_material);
|
priv->solid_material);
|
||||||
|
|
||||||
@ -492,19 +488,21 @@ cogl_pango_renderer_set_color_for_part (PangoRenderer *renderer,
|
|||||||
{
|
{
|
||||||
PangoColor *pango_color = pango_renderer_get_color (renderer, part);
|
PangoColor *pango_color = pango_renderer_get_color (renderer, part);
|
||||||
CoglPangoRenderer *priv = COGL_PANGO_RENDERER (renderer);
|
CoglPangoRenderer *priv = COGL_PANGO_RENDERER (renderer);
|
||||||
CoglColor color;
|
|
||||||
|
|
||||||
if (pango_color)
|
if (pango_color)
|
||||||
{
|
{
|
||||||
color.red = pango_color->red >> 8;
|
CoglColor color;
|
||||||
color.green = pango_color->green >> 8;
|
|
||||||
color.blue = pango_color->blue >> 8;
|
cogl_color_set_from_4ub (&color,
|
||||||
color.alpha = priv->color.alpha;
|
pango_color->red >> 8,
|
||||||
|
pango_color->green >> 8,
|
||||||
|
pango_color->blue >> 8,
|
||||||
|
0xff);
|
||||||
|
|
||||||
|
_cogl_pango_display_list_set_color_override (priv->display_list, &color);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
color = priv->color;
|
_cogl_pango_display_list_remove_color_override (priv->display_list);
|
||||||
|
|
||||||
_cogl_pango_display_list_set_color (priv->display_list, &color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user