mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
Move default paint volume computation into a function
This should reduce the amount of copy and paste for actor sub-classes that use the default paint volume from the allocation.
This commit is contained in:
parent
fd41024d29
commit
16f7ee13f2
@ -367,28 +367,12 @@ clutter_cairo_texture_get_preferred_height (ClutterActor *actor,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_cairo_texture_get_paint_volume (ClutterActor *self,
|
||||
clutter_cairo_texture_get_paint_volume (ClutterActor *self,
|
||||
ClutterPaintVolume *volume)
|
||||
{
|
||||
ClutterGeometry allocation;
|
||||
|
||||
/* XXX: we are being conservative here and not making assumptions
|
||||
* that sub-classes won't paint outside their allocation. */
|
||||
if (G_OBJECT_TYPE (self) != CLUTTER_TYPE_CAIRO_TEXTURE)
|
||||
return FALSE;
|
||||
|
||||
/* XXX: clutter_actor_get_allocation can potentially be very
|
||||
* expensive to call if called while the actor doesn't have a valid
|
||||
* allocation since it will trigger a synchronous relayout of the
|
||||
* scenegraph. We explicitly check we have a valid allocation
|
||||
* to avoid hitting that codepath. */
|
||||
if (!clutter_actor_has_allocation (self))
|
||||
return FALSE;
|
||||
|
||||
clutter_actor_get_allocation_geometry (self, &allocation);
|
||||
clutter_paint_volume_set_width (volume, allocation.width);
|
||||
clutter_paint_volume_set_height (volume, allocation.height);
|
||||
return TRUE;
|
||||
return _clutter_actor_set_default_paint_volume (self,
|
||||
CLUTTER_TYPE_CAIRO_TEXTURE,
|
||||
volume);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -812,4 +812,50 @@ _clutter_paint_volume_axis_align (ClutterPaintVolume *pv)
|
||||
pv->is_2d = FALSE;
|
||||
}
|
||||
|
||||
/*<private>
|
||||
* _clutter_actor_set_default_paint_volume:
|
||||
* @self: a #ClutterActor
|
||||
* @check_gtype: if not %G_TYPE_INVALID, match the type of @self against
|
||||
* this type
|
||||
* @volume: the #ClutterPaintVolume to set
|
||||
*
|
||||
* Sets the default paint volume for @self.
|
||||
*
|
||||
* This function should be called by #ClutterActor sub-classes that follow
|
||||
* the default assumption that their paint volume is defined by their
|
||||
* allocation.
|
||||
*
|
||||
* If @check_gtype is not %G_TYPE_INVALID, this function will check the
|
||||
* type of @self and only compute the paint volume if the type matches;
|
||||
* this can be used to avoid computing the paint volume for sub-classes
|
||||
* of an actor class
|
||||
*
|
||||
* Return value: %TRUE if the paint volume was set, and %FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
_clutter_actor_set_default_paint_volume (ClutterActor *self,
|
||||
GType check_gtype,
|
||||
ClutterPaintVolume *volume)
|
||||
{
|
||||
ClutterGeometry geometry = { 0, };
|
||||
|
||||
if (check_gtype != G_TYPE_INVALID)
|
||||
{
|
||||
if (G_OBJECT_TYPE (self) != check_gtype)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* calling clutter_actor_get_allocation_* can potentially be very
|
||||
* expensive, as it can result in a synchronous full stage relayout
|
||||
* and redraw
|
||||
*/
|
||||
if (!clutter_actor_has_allocation (self))
|
||||
return FALSE;
|
||||
|
||||
clutter_actor_get_allocation_geometry (self, &geometry);
|
||||
|
||||
clutter_paint_volume_set_width (volume, geometry.width);
|
||||
clutter_paint_volume_set_height (volume, geometry.height);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -530,6 +530,10 @@ void _clutter_util_fully_transform_vertices (const CoglMatrix *mo
|
||||
ClutterVertex *vertices_out,
|
||||
int n_vertices);
|
||||
|
||||
gboolean _clutter_actor_set_default_paint_volume (ClutterActor *self,
|
||||
GType check_gtype,
|
||||
ClutterPaintVolume *volume);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _HAVE_CLUTTER_PRIVATE_H */
|
||||
|
@ -153,28 +153,12 @@ clutter_rectangle_paint (ClutterActor *self)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_rectangle_get_paint_volume (ClutterActor *self,
|
||||
clutter_rectangle_get_paint_volume (ClutterActor *self,
|
||||
ClutterPaintVolume *volume)
|
||||
{
|
||||
ClutterGeometry allocation;
|
||||
|
||||
/* XXX: we are being conservative here and not making assumptions
|
||||
* that sub-classes won't paint outside their allocation. */
|
||||
if (G_OBJECT_TYPE (self) != CLUTTER_TYPE_RECTANGLE)
|
||||
return FALSE;
|
||||
|
||||
/* XXX: clutter_actor_get_allocation can potentially be very
|
||||
* expensive to call if called while the actor doesn't have a valid
|
||||
* allocation since it will trigger a synchronous relayout of the
|
||||
* scenegraph. We explicitly check we have a valid allocation
|
||||
* to avoid hitting that codepath. */
|
||||
if (!clutter_actor_has_allocation (self))
|
||||
return FALSE;
|
||||
|
||||
clutter_actor_get_allocation_geometry (self, &allocation);
|
||||
clutter_paint_volume_set_width (volume, allocation.width);
|
||||
clutter_paint_volume_set_height (volume, allocation.height);
|
||||
return TRUE;
|
||||
return _clutter_actor_set_default_paint_volume (self,
|
||||
CLUTTER_TYPE_RECTANGLE,
|
||||
volume);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -686,28 +686,12 @@ clutter_texture_paint (ClutterActor *self)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_texture_get_paint_volume (ClutterActor *self,
|
||||
clutter_texture_get_paint_volume (ClutterActor *self,
|
||||
ClutterPaintVolume *volume)
|
||||
{
|
||||
ClutterGeometry allocation;
|
||||
|
||||
/* XXX: we are being conservative here and not making assumptions
|
||||
* that sub-classes won't paint outside their allocation. */
|
||||
if (G_OBJECT_TYPE (self) != CLUTTER_TYPE_TEXTURE)
|
||||
return FALSE;
|
||||
|
||||
/* XXX: clutter_actor_get_allocation can potentially be very
|
||||
* expensive to call if called while the actor doesn't have a valid
|
||||
* allocation since it will trigger a synchronous relayout of the
|
||||
* scenegraph. We explicitly check we have a valid allocation
|
||||
* to avoid hitting that codepath. */
|
||||
if (!clutter_actor_has_allocation (self))
|
||||
return FALSE;
|
||||
|
||||
clutter_actor_get_allocation_geometry (self, &allocation);
|
||||
clutter_paint_volume_set_width (volume, allocation.width);
|
||||
clutter_paint_volume_set_height (volume, allocation.height);
|
||||
return TRUE;
|
||||
return _clutter_actor_set_default_paint_volume (self,
|
||||
CLUTTER_TYPE_TEXTURE,
|
||||
volume);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user