| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | |
| 3 * Copyright (C) 2011, 2012 Collabora Ltd. | |
| 4 * Copyright (C) 2012 Intel Corporation. All rights reserved. | |
| 5 * | |
| 6 * Redistribution and use in source and binary forms, with or without | |
| 7 * modification, are permitted provided that the following conditions | |
| 8 * are met: | |
| 9 * 1. Redistributions of source code must retain the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer. | |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | |
| 12 * notice, this list of conditions and the following disclaimer in the | |
| 13 * documentation and/or other materials provided with the distribution. | |
| 14 * | |
| 15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
| 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 */ | |
| 27 | |
| 28 #ifndef GraphicsLayerClutter_h | |
| 29 #define GraphicsLayerClutter_h | |
| 30 | |
| 31 #if USE(ACCELERATED_COMPOSITING) | |
| 32 | |
| 33 #include "GraphicsLayer.h" | |
| 34 #include "GraphicsLayerClient.h" | |
| 35 #include "Image.h" | |
| 36 #include "ImageSource.h" | |
| 37 #include "PlatformClutterAnimation.h" | |
| 38 #include "PlatformClutterLayerClient.h" | |
| 39 #include <wtf/HashMap.h> | |
| 40 #include <wtf/HashSet.h> | |
| 41 #include <wtf/text/StringHash.h> | |
| 42 | |
| 43 #include <clutter/clutter.h> | |
| 44 #include <wtf/gobject/GRefPtr.h> | |
| 45 | |
| 46 typedef struct _GraphicsLayerActor GraphicsLayerActor; | |
| 47 | |
| 48 namespace WebCore { | |
| 49 | |
| 50 class TransformState; | |
| 51 | |
| 52 typedef Vector<GRefPtr<GraphicsLayerActor> > GraphicsLayerActorList; | |
| 53 | |
| 54 class GraphicsLayerClutter : public GraphicsLayer, public PlatformClutterLayerCl
ient { | |
| 55 public: | |
| 56 enum LayerType { LayerTypeLayer, LayerTypeWebLayer, LayerTypeVideoLayer, Lay
erTypeTransformLayer, LayerTypeRootLayer, LayerTypeCustom }; | |
| 57 | |
| 58 GraphicsLayerClutter(GraphicsLayerClient*); | |
| 59 virtual ~GraphicsLayerClutter(); | |
| 60 | |
| 61 virtual ClutterActor* platformLayer() const; | |
| 62 virtual void addChild(GraphicsLayer*); | |
| 63 virtual void addChildAtIndex(GraphicsLayer*, int index); | |
| 64 virtual void addChildAbove(GraphicsLayer*, GraphicsLayer* sibling); | |
| 65 virtual void addChildBelow(GraphicsLayer*, GraphicsLayer* sibling); | |
| 66 virtual void removeFromParent(); | |
| 67 virtual bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild); | |
| 68 virtual bool setChildren(const Vector<GraphicsLayer*>&); | |
| 69 virtual void setParent(GraphicsLayer*); | |
| 70 | |
| 71 virtual void setDrawsContent(bool); | |
| 72 virtual void setAnchorPoint(const FloatPoint3D&); | |
| 73 virtual void setOpacity(float); | |
| 74 virtual void setPosition(const FloatPoint&); | |
| 75 virtual void setSize(const FloatSize&); | |
| 76 | |
| 77 virtual void setTransform(const TransformationMatrix&); | |
| 78 virtual void setName(const String&); | |
| 79 virtual void setNeedsDisplay(); | |
| 80 virtual void setNeedsDisplayInRect(const FloatRect&); | |
| 81 | |
| 82 virtual void setPreserves3D(bool); | |
| 83 | |
| 84 virtual bool addAnimation(const KeyframeValueList&, const IntSize& boxSize,
const Animation*, const String& animationName, double timeOffset); | |
| 85 virtual void removeAnimation(const String& animationName); | |
| 86 | |
| 87 virtual void flushCompositingState(const FloatRect&); | |
| 88 virtual void flushCompositingStateForThisLayerOnly(); | |
| 89 | |
| 90 struct CommitState { | |
| 91 bool ancestorHasTransformAnimation; | |
| 92 CommitState() | |
| 93 : ancestorHasTransformAnimation(false) | |
| 94 { } | |
| 95 }; | |
| 96 void recursiveCommitChanges(const CommitState&, const TransformState&, float
pageScaleFactor = 1, const FloatPoint& positionRelativeToBase = FloatPoint(), b
ool affectedByPageScale = false); | |
| 97 | |
| 98 private: | |
| 99 FloatPoint computePositionRelativeToBase(float& pageScale) const; | |
| 100 | |
| 101 bool animationIsRunning(const String& animationName) const | |
| 102 { | |
| 103 return m_runningAnimations.find(animationName) != m_runningAnimations.en
d(); | |
| 104 } | |
| 105 | |
| 106 void commitLayerChangesBeforeSublayers(float pageScaleFactor, const FloatPoi
nt& positionRelativeToBase); | |
| 107 void commitLayerChangesAfterSublayers(); | |
| 108 | |
| 109 void updateOpacityOnLayer(); | |
| 110 | |
| 111 virtual void platformClutterLayerAnimationStarted(double beginTime); | |
| 112 virtual void platformClutterLayerPaintContents(GraphicsContext&, const IntRe
ct& clip); | |
| 113 | |
| 114 GraphicsLayerActor* primaryLayer() const { return m_structuralLayer.get() ?
m_structuralLayer.get() : m_layer.get(); } | |
| 115 GraphicsLayerActor* layerForSuperlayer() const; | |
| 116 GraphicsLayerActor* animatedLayer(AnimatedPropertyID) const; | |
| 117 | |
| 118 PassRefPtr<PlatformClutterAnimation> createBasicAnimation(const Animation*,
const String& keyPath, bool additive); | |
| 119 PassRefPtr<PlatformClutterAnimation> createKeyframeAnimation(const Animation
*, const String&, bool additive); | |
| 120 void setupAnimation(PlatformClutterAnimation*, const Animation*, bool additi
ve); | |
| 121 | |
| 122 const TimingFunction* timingFunctionForAnimationValue(const AnimationValue*,
const Animation*); | |
| 123 | |
| 124 bool setAnimationEndpoints(const KeyframeValueList&, const Animation*, Platf
ormClutterAnimation*); | |
| 125 bool setAnimationKeyframes(const KeyframeValueList&, const Animation*, Platf
ormClutterAnimation*); | |
| 126 | |
| 127 void setAnimationOnLayer(PlatformClutterAnimation*, AnimatedPropertyID, cons
t String& animationName, int index, double timeOffset); | |
| 128 bool removeClutterAnimationFromLayer(AnimatedPropertyID, const String& anima
tionName, int index); | |
| 129 void pauseClutterAnimationOnLayer(AnimatedPropertyID, const String& animatio
nName, int index, double timeOffset); | |
| 130 | |
| 131 bool createAnimationFromKeyframes(const KeyframeValueList&, const Animation*
, const String& animationName, double timeOffset); | |
| 132 bool createTransformAnimationsFromKeyframes(const KeyframeValueList&, const
Animation*, const String& animationName, double timeOffset, const IntSize& boxSi
ze); | |
| 133 | |
| 134 bool setTransformAnimationEndpoints(const KeyframeValueList&, const Animatio
n*, PlatformClutterAnimation*, int functionIndex, TransformOperation::OperationT
ype, bool isMatrixAnimation, const IntSize& boxSize); | |
| 135 bool setTransformAnimationKeyframes(const KeyframeValueList&, const Animatio
n*, PlatformClutterAnimation*, int functionIndex, TransformOperation::OperationT
ype, bool isMatrixAnimation, const IntSize& boxSize); | |
| 136 | |
| 137 enum MoveOrCopy { Move, Copy }; | |
| 138 void moveOrCopyAnimations(MoveOrCopy, GraphicsLayerActor* fromLayer, Graphic
sLayerActor* toLayer); | |
| 139 | |
| 140 bool appendToUncommittedAnimations(const KeyframeValueList&, const Transform
Operations*, const Animation*, const String& animationName, const IntSize& boxSi
ze, int animationIndex, double timeOffset, bool isMatrixAnimation); | |
| 141 | |
| 142 enum LayerChange { | |
| 143 NoChange = 0, | |
| 144 NameChanged = 1 << 1, | |
| 145 ChildrenChanged = 1 << 2, // also used for content layer, and preserves-
3d, and size if tiling changes? | |
| 146 GeometryChanged = 1 << 3, | |
| 147 TransformChanged = 1 << 4, | |
| 148 ChildrenTransformChanged = 1 << 5, | |
| 149 Preserves3DChanged = 1 << 6, | |
| 150 MasksToBoundsChanged = 1 << 7, | |
| 151 DrawsContentChanged = 1 << 8, // need this? | |
| 152 BackgroundColorChanged = 1 << 9, | |
| 153 ContentsOpaqueChanged = 1 << 10, | |
| 154 BackfaceVisibilityChanged = 1 << 11, | |
| 155 OpacityChanged = 1 << 12, | |
| 156 AnimationChanged = 1 << 13, | |
| 157 DirtyRectsChanged = 1 << 14, | |
| 158 ContentsImageChanged = 1 << 15, | |
| 159 ContentsMediaLayerChanged = 1 << 16, | |
| 160 ContentsCanvasLayerChanged = 1 << 17, | |
| 161 ContentsColorLayerChanged = 1 << 18, | |
| 162 ContentsRectChanged = 1 << 19, | |
| 163 MaskLayerChanged = 1 << 20, | |
| 164 ReplicatedLayerChanged = 1 << 21, | |
| 165 ContentsNeedsDisplay = 1 << 22, | |
| 166 AcceleratesDrawingChanged = 1 << 23, | |
| 167 ContentsScaleChanged = 1 << 24, | |
| 168 ContentsVisibilityChanged = 1 << 25, | |
| 169 VisibleRectChanged = 1 << 26, | |
| 170 FiltersChanged = 1 << 27, | |
| 171 DebugIndicatorsChanged = 1 << 28 | |
| 172 }; | |
| 173 | |
| 174 typedef unsigned LayerChangeFlags; | |
| 175 void noteLayerPropertyChanged(LayerChangeFlags); | |
| 176 void noteSublayersChanged(); | |
| 177 | |
| 178 void updateBackfaceVisibility(); | |
| 179 void updateStructuralLayer(); | |
| 180 void updateLayerNames(); | |
| 181 void updateSublayerList(); | |
| 182 void updateGeometry(float pixelAlignmentScale, const FloatPoint& positionRel
ativeToBase); | |
| 183 void updateTransform(); | |
| 184 void updateLayerDrawsContent(float pixelAlignmentScale, const FloatPoint& po
sitionRelativeToBase); | |
| 185 | |
| 186 void updateAnimations(); | |
| 187 | |
| 188 enum StructuralLayerPurpose { | |
| 189 NoStructuralLayer = 0, | |
| 190 StructuralLayerForPreserves3D, | |
| 191 StructuralLayerForReplicaFlattening | |
| 192 }; | |
| 193 void ensureStructuralLayer(StructuralLayerPurpose); | |
| 194 StructuralLayerPurpose structuralLayerPurpose() const; | |
| 195 | |
| 196 void repaintLayerDirtyRects(); | |
| 197 | |
| 198 GRefPtr<GraphicsLayerActor> m_layer; | |
| 199 GRefPtr<GraphicsLayerActor> m_structuralLayer; // A layer used for structura
l reasons, like preserves-3d or replica-flattening. Is the parent of m_layer. | |
| 200 | |
| 201 Vector<FloatRect> m_dirtyRects; | |
| 202 LayerChangeFlags m_uncommittedChanges; | |
| 203 | |
| 204 // This represents the animation of a single property. There may be multiple
transform animations for | |
| 205 // a single transition or keyframe animation, so index is used to distinguis
h these. | |
| 206 struct LayerPropertyAnimation { | |
| 207 LayerPropertyAnimation(PassRefPtr<PlatformClutterAnimation> caAnimation,
const String& animationName, AnimatedPropertyID property, int index, double tim
eOffset) | |
| 208 : m_animation(caAnimation) | |
| 209 , m_name(animationName) | |
| 210 , m_property(property) | |
| 211 , m_index(index) | |
| 212 , m_timeOffset(timeOffset) | |
| 213 { } | |
| 214 | |
| 215 RefPtr<PlatformClutterAnimation> m_animation; | |
| 216 String m_name; | |
| 217 AnimatedPropertyID m_property; | |
| 218 int m_index; | |
| 219 double m_timeOffset; | |
| 220 }; | |
| 221 | |
| 222 // Uncommitted transitions and animations. | |
| 223 Vector<LayerPropertyAnimation> m_uncomittedAnimations; | |
| 224 | |
| 225 enum Action { Remove, Pause }; | |
| 226 struct AnimationProcessingAction { | |
| 227 AnimationProcessingAction(Action action = Remove, double timeOffset = 0) | |
| 228 : action(action) | |
| 229 , timeOffset(timeOffset) | |
| 230 { | |
| 231 } | |
| 232 Action action; | |
| 233 double timeOffset; // only used for pause | |
| 234 }; | |
| 235 typedef HashMap<String, AnimationProcessingAction> AnimationsToProcessMap; | |
| 236 AnimationsToProcessMap m_animationsToProcess; | |
| 237 | |
| 238 // Map of animation names to their associated lists of property animations,
so we can remove/pause them. | |
| 239 typedef HashMap<String, Vector<LayerPropertyAnimation> > AnimationsMap; | |
| 240 AnimationsMap m_runningAnimations; | |
| 241 }; | |
| 242 | |
| 243 } // namespace WebCore | |
| 244 | |
| 245 #endif // USE(ACCELERATED_COMPOSITING) | |
| 246 | |
| 247 #endif // GraphicsLayerClutter_h | |
| OLD | NEW |