material: Adds a simple material age getter

When we add support for weak materials it's expected that Clutter will
want to attach them as private data to other materials and it needs a
mechanism to determine when a weak material should be re-created because
its parent has changed somehow.

This adds the concept of a material age (internal only currently) which
increments whenever a material is modified. Clutter can then save the
age of the material which its weak materials are derived from and later
determine when the weak material may be invalid.
This commit is contained in:
Robert Bragg 2010-05-27 15:19:15 +01:00
parent c9702be94e
commit 9689ec5aad
2 changed files with 29 additions and 0 deletions

View File

@ -472,6 +472,13 @@ struct _CoglMaterial
* bitfield can associate private data with a material. */
void *backend_priv;
/* Whenever a material is modified we increment the age. There's no
* guarantee that it won't wrap but it can nevertheless be a
* convenient mechanism to determine when a material has been
* changed to you can invalidate some some associated cache that
* depends on the old state. */
unsigned long age;
/* This is the primary color of the material.
*
* This is a sparse property, ref COGL_MATERIAL_STATE_COLOR */
@ -761,5 +768,8 @@ void
_cogl_material_set_static_breadcrumb (CoglHandle handle,
const char *breadcrumb);
unsigned long
_cogl_material_get_age (CoglHandle handle);
#endif /* __COGL_MATERIAL_PRIVATE_H */

View File

@ -368,6 +368,8 @@ _cogl_material_init_default_material (void)
material->static_breadcrumb = "default material";
material->has_static_breadcrumb = TRUE;
material->age = 0;
/* Use the same defaults as the GL spec... */
cogl_color_init_from_4ub (&material->color, 0xff, 0xff, 0xff, 0xff);
@ -469,6 +471,8 @@ cogl_material_copy (CoglHandle handle)
material->has_static_breadcrumb = FALSE;
material->age = 0;
return _cogl_material_handle_new (material);
}
@ -1184,6 +1188,8 @@ _cogl_material_pre_change_notify (CoglMaterial *material,
* are now free to modify the material. */
g_assert (!material->has_children);
material->age++;
/* If the material isn't already an authority for the state group
* being modified then we need to initialize the corresponding
* state. */
@ -1561,6 +1567,9 @@ _cogl_material_layer_pre_change_notify (CoglMaterial *required_owner,
init_layer_state:
if (required_owner)
required_owner->age++;
/* If the material isn't already an authority for the state group
* being modified then we need to initialize the corresponding
* state. */
@ -4109,6 +4118,16 @@ cogl_material_get_depth_range (CoglHandle handle,
*far = authority->big_state->depth_state.depth_range_far;
}
unsigned long
_cogl_material_get_age (CoglHandle handle)
{
CoglMaterial *material = COGL_MATERIAL (handle);
g_return_val_if_fail (cogl_is_material (handle), 0);
return material->age;
}
static CoglMaterialLayer *
_cogl_material_layer_copy (CoglMaterialLayer *src)
{