pango: push/pop source instead of trashing users source
The pango-display-list code was calling cogl_set_source in numerous places and it didn't appear to be saving the users source to restore later. This could result in the user inadvertantly drawing a primitive with one of these internally managed materials instead of one that they chose. To rectify this the code now uses cogl_{push,pop}_source to save and restore the users source.
This commit is contained in:
parent
4e69c73085
commit
7ee99aaa83
@ -234,40 +234,27 @@ _cogl_pango_display_list_add_trapezoid (CoglPangoDisplayList *dl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_cogl_pango_display_list_render_texture (CoglHandle material,
|
emit_rectangles_through_journal (CoglPangoDisplayListNode *node)
|
||||||
const CoglColor *color,
|
|
||||||
CoglPangoDisplayListNode *node)
|
|
||||||
{
|
{
|
||||||
CoglColor premult_color = *color;
|
int i;
|
||||||
cogl_material_set_layer (material, 0, node->d.texture.texture);
|
|
||||||
cogl_material_set_color (material, &premult_color);
|
|
||||||
cogl_set_source (material);
|
|
||||||
|
|
||||||
/* For small runs of text like icon labels, we can get better performance
|
for (i = 0; i < node->d.texture.verts->len; i += 4)
|
||||||
* going through the Cogl journal since text may then be batched together
|
|
||||||
* with other geometry. */
|
|
||||||
/* FIXME: 100 is a number I plucked out of thin air; it would be good
|
|
||||||
* to determine this empirically! */
|
|
||||||
if (node->d.texture.verts->len < 100)
|
|
||||||
{
|
{
|
||||||
int i;
|
CoglPangoDisplayListVertex *v0 =
|
||||||
|
&g_array_index (node->d.texture.verts,
|
||||||
for (i = 0; i < node->d.texture.verts->len; i += 4)
|
CoglPangoDisplayListVertex, i);
|
||||||
{
|
CoglPangoDisplayListVertex *v1 =
|
||||||
CoglPangoDisplayListVertex *v0 =
|
&g_array_index (node->d.texture.verts,
|
||||||
&g_array_index (node->d.texture.verts,
|
CoglPangoDisplayListVertex, i + 2);
|
||||||
CoglPangoDisplayListVertex, i);
|
cogl_rectangle_with_texture_coords (v0->x, v0->y, v1->x, v1->y,
|
||||||
CoglPangoDisplayListVertex *v1 =
|
v0->t_x, v0->t_y,
|
||||||
&g_array_index (node->d.texture.verts,
|
v1->t_x, v1->t_y);
|
||||||
CoglPangoDisplayListVertex, i + 2);
|
|
||||||
cogl_rectangle_with_texture_coords (v0->x, v0->y, v1->x, v1->y,
|
|
||||||
v0->t_x, v0->t_y,
|
|
||||||
v1->t_x, v1->t_y);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
emit_vertex_buffer_geometry (CoglPangoDisplayListNode *node)
|
||||||
|
{
|
||||||
/* It's expensive to go through the Cogl journal for large runs
|
/* It's expensive to go through the Cogl journal for large runs
|
||||||
* of text in part because the journal transforms the quads in software
|
* of text in part because the journal transforms the quads in software
|
||||||
* to avoid changing the modelview matrix. So for larger runs of text
|
* to avoid changing the modelview matrix. So for larger runs of text
|
||||||
@ -321,6 +308,31 @@ _cogl_pango_display_list_render_texture (CoglHandle material,
|
|||||||
#endif /* CLUTTER_COGL_HAS_GL */
|
#endif /* CLUTTER_COGL_HAS_GL */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_cogl_pango_display_list_render_texture (CoglHandle material,
|
||||||
|
const CoglColor *color,
|
||||||
|
CoglPangoDisplayListNode *node)
|
||||||
|
{
|
||||||
|
CoglColor premult_color = *color;
|
||||||
|
|
||||||
|
cogl_material_set_layer (material, 0, node->d.texture.texture);
|
||||||
|
cogl_material_set_color (material, &premult_color);
|
||||||
|
|
||||||
|
cogl_push_source (material);
|
||||||
|
|
||||||
|
/* For small runs of text like icon labels, we can get better performance
|
||||||
|
* going through the Cogl journal since text may then be batched together
|
||||||
|
* with other geometry. */
|
||||||
|
/* FIXME: 100 is a number I plucked out of thin air; it would be good
|
||||||
|
* to determine this empirically! */
|
||||||
|
if (node->d.texture.verts->len < 100)
|
||||||
|
emit_rectangles_through_journal (node);
|
||||||
|
else
|
||||||
|
emit_vertex_buffer_geometry (node);
|
||||||
|
|
||||||
|
cogl_pop_source ();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_pango_display_list_render (CoglPangoDisplayList *dl,
|
_cogl_pango_display_list_render (CoglPangoDisplayList *dl,
|
||||||
const CoglColor *color,
|
const CoglColor *color,
|
||||||
@ -355,11 +367,12 @@ _cogl_pango_display_list_render (CoglPangoDisplayList *dl,
|
|||||||
|
|
||||||
case COGL_PANGO_DISPLAY_LIST_RECTANGLE:
|
case COGL_PANGO_DISPLAY_LIST_RECTANGLE:
|
||||||
cogl_material_set_color (solid_material, &draw_color);
|
cogl_material_set_color (solid_material, &draw_color);
|
||||||
cogl_set_source (solid_material);
|
cogl_push_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,
|
||||||
node->d.rectangle.x_2,
|
node->d.rectangle.x_2,
|
||||||
node->d.rectangle.y_2);
|
node->d.rectangle.y_2);
|
||||||
|
cogl_pop_source ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COGL_PANGO_DISPLAY_LIST_TRAPEZOID:
|
case COGL_PANGO_DISPLAY_LIST_TRAPEZOID:
|
||||||
@ -376,9 +389,10 @@ _cogl_pango_display_list_render (CoglPangoDisplayList *dl,
|
|||||||
points[7] = node->d.trapezoid.y_1;
|
points[7] = node->d.trapezoid.y_1;
|
||||||
|
|
||||||
cogl_material_set_color (solid_material, &draw_color);
|
cogl_material_set_color (solid_material, &draw_color);
|
||||||
cogl_set_source (solid_material);
|
cogl_push_source (solid_material);
|
||||||
cogl_path_polygon (points, 4);
|
cogl_path_polygon (points, 4);
|
||||||
cogl_path_fill ();
|
cogl_path_fill ();
|
||||||
|
cogl_pop_source ();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user