1
0
Fork 0
mutter-performance-source/clutter/clutter-flatten-effect.c

57 lines
1.6 KiB
C
Raw Normal View History

clutter-actor: Add an 'offscreen-redirect' property This adds a property which can be used to redirect the actor through an FBO before painting so that it becomes flattened in an image. The image can be used as a cache to avoid having to repaint the actor if something unrelated in the scene changes. It can also be used to implement correct opacity even if the actor has overlapping primitives. The property is an enum that takes three values: CLUTTER_OFFSCREEN_REDIRECT_NEVER: The default behaviour which is to never flatten the actor. CLUTTER_OFFSCREEN_REDIRECT_ALWAYS: The actor is always redirected through an FBO. CLUTTER_OFFSCREEN_REDIRECT_ONLY_FOR_OPACITY: The actor is only redirected through an FBO if the paint opacity is not 255. This value would be used if the actor wants correct opacity. It will avoid the overhead of using an FBO whenever the actor is fully opaque. The property is implemented by installing a ClutterFlattenEffect. ClutterFlattenEffect is a new internal class which subclasses ClutterOffscreen to redirect the painting to an FBO. When ClutterOffscreen paints, the effect sets an opacity override on the actor so that the image will always contain the actor at full opacity. The opacity is then applied to the resulting image before painting it to the stage. This means the actor does not need to be redrawn while the opacity is being animated. The effect has a high internal priority so that it will always occur before any other effects and it gets hidden from the application.
2011-02-28 15:05:51 +00:00
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2011 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Neil Roberts <neil@linux.intel.com>
*/
/* This is an internal-only effect used to implement the
clutter-actor: Add a 'has_overlaps' virtual This adds a virtual to ClutterActor so that an actor subclass can report whether it has overlapping primitives. ClutterActor uses this to determine whether it needs to use ClutterFlattenEffect to implement the opacity property. The default implementation of the virtual returns TRUE which means that most actors will end up being redirected offscreen when the opacity != 255. ClutterTexture and ClutterRectangle override this to return FALSE because they should never need to be redirected. ClutterClone overrides it to divert to the source. The values for the ClutterOffscreenRedirect enum have changed to: AUTOMATIC_FOR_OPACITY The actor will only be redirected if has_overlaps returns TRUE and the opacity is < 255 ALWAYS_FOR_OPACITY The actor will always be redirected if the opacity < 255 regardless of the return value of has_overlaps ALWAYS The actor will always be redirected offscreen. This means that the property can't be used to prevent the actor from being redirected but only to increase the likelihood that it will be redirected. ClutterActor now adds and removes the flatten effect depending on whether flattening is needed directly in clutter_actor_paint(). There are new internal versions of add/remove_effect that don't queue a redraw. This means that ClutterFlattenEffect is now just a no-op subclass of ClutterOffscreen. It is only needed because ClutterOffscreen is abstract. Removing the effect also makes it so that the cached image will be freed as soon as an actor is repainted without being flattened.
2011-03-14 16:30:53 +00:00
'offscreen-redirect' property of ClutterActor. It doesn't actually
need to do anything on top of the ClutterOffscreenEffect class so
it only exists because that class is abstract */
clutter-actor: Add an 'offscreen-redirect' property This adds a property which can be used to redirect the actor through an FBO before painting so that it becomes flattened in an image. The image can be used as a cache to avoid having to repaint the actor if something unrelated in the scene changes. It can also be used to implement correct opacity even if the actor has overlapping primitives. The property is an enum that takes three values: CLUTTER_OFFSCREEN_REDIRECT_NEVER: The default behaviour which is to never flatten the actor. CLUTTER_OFFSCREEN_REDIRECT_ALWAYS: The actor is always redirected through an FBO. CLUTTER_OFFSCREEN_REDIRECT_ONLY_FOR_OPACITY: The actor is only redirected through an FBO if the paint opacity is not 255. This value would be used if the actor wants correct opacity. It will avoid the overhead of using an FBO whenever the actor is fully opaque. The property is implemented by installing a ClutterFlattenEffect. ClutterFlattenEffect is a new internal class which subclasses ClutterOffscreen to redirect the painting to an FBO. When ClutterOffscreen paints, the effect sets an opacity override on the actor so that the image will always contain the actor at full opacity. The opacity is then applied to the resulting image before painting it to the stage. This means the actor does not need to be redrawn while the opacity is being animated. The effect has a high internal priority so that it will always occur before any other effects and it gets hidden from the application.
2011-02-28 15:05:51 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "clutter-flatten-effect.h"
#include "clutter-private.h"
#include "clutter-actor-private.h"
G_DEFINE_TYPE (ClutterFlattenEffect,
_clutter_flatten_effect,
CLUTTER_TYPE_OFFSCREEN_EFFECT);
static void
_clutter_flatten_effect_class_init (ClutterFlattenEffectClass *klass)
{
}
static void
_clutter_flatten_effect_init (ClutterFlattenEffect *self)
{
}
ClutterEffect *
_clutter_flatten_effect_new (void)
{
return g_object_new (CLUTTER_TYPE_FLATTEN_EFFECT, NULL);
}