2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "GraphicsLayerTextureMapper.h"
23 #include "TextureMapperNode.h"
27 GraphicsLayerTextureMapper::GraphicsLayerTextureMapper(GraphicsLayerClient* client)
28 : GraphicsLayer(client)
29 , m_node(adoptPtr(new TextureMapperNode()))
31 , m_animationStartedTimer(this, &GraphicsLayerTextureMapper::animationStartedTimerFired)
35 void GraphicsLayerTextureMapper::notifyChange(TextureMapperNode::ChangeMask changeMask)
37 m_changeMask |= changeMask;
40 client()->notifySyncRequired(this);
43 void GraphicsLayerTextureMapper::didSynchronize()
47 m_pendingContent.needsDisplay = false;
48 m_pendingContent.needsDisplayRect = IntRect();
51 void GraphicsLayerTextureMapper::setName(const String& name)
53 GraphicsLayer::setName(name);
56 GraphicsLayerTextureMapper::~GraphicsLayerTextureMapper()
60 /* \reimp (GraphicsLayer.h): The current size might change, thus we need to update the whole display.
62 void GraphicsLayerTextureMapper::setNeedsDisplay()
64 m_pendingContent.needsDisplay = true;
65 notifyChange(TextureMapperNode::DisplayChange);
68 /* \reimp (GraphicsLayer.h)
70 void GraphicsLayerTextureMapper::setNeedsDisplayInRect(const FloatRect& rect)
72 if (m_pendingContent.needsDisplay)
74 m_pendingContent.needsDisplayRect.unite(rect);
75 notifyChange(TextureMapperNode::DisplayChange);
78 /* \reimp (GraphicsLayer.h)
80 void GraphicsLayerTextureMapper::setParent(GraphicsLayer* layer)
82 notifyChange(TextureMapperNode::ParentChange);
83 GraphicsLayer::setParent(layer);
86 /* \reimp (GraphicsLayer.h)
88 bool GraphicsLayerTextureMapper::setChildren(const Vector<GraphicsLayer*>& children)
90 notifyChange(TextureMapperNode::ChildrenChange);
91 return GraphicsLayer::setChildren(children);
94 /* \reimp (GraphicsLayer.h)
96 void GraphicsLayerTextureMapper::addChild(GraphicsLayer* layer)
98 notifyChange(TextureMapperNode::ChildrenChange);
99 GraphicsLayer::addChild(layer);
102 /* \reimp (GraphicsLayer.h)
104 void GraphicsLayerTextureMapper::addChildAtIndex(GraphicsLayer* layer, int index)
106 GraphicsLayer::addChildAtIndex(layer, index);
107 notifyChange(TextureMapperNode::ChildrenChange);
110 /* \reimp (GraphicsLayer.h)
112 void GraphicsLayerTextureMapper::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling)
114 GraphicsLayer::addChildAbove(layer, sibling);
115 notifyChange(TextureMapperNode::ChildrenChange);
118 /* \reimp (GraphicsLayer.h)
120 void GraphicsLayerTextureMapper::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling)
123 GraphicsLayer::addChildBelow(layer, sibling);
124 notifyChange(TextureMapperNode::ChildrenChange);
127 /* \reimp (GraphicsLayer.h)
129 bool GraphicsLayerTextureMapper::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
131 if (GraphicsLayer::replaceChild(oldChild, newChild)) {
132 notifyChange(TextureMapperNode::ChildrenChange);
138 /* \reimp (GraphicsLayer.h)
140 void GraphicsLayerTextureMapper::removeFromParent()
144 notifyChange(TextureMapperNode::ParentChange);
145 GraphicsLayer::removeFromParent();
148 /* \reimp (GraphicsLayer.h)
150 void GraphicsLayerTextureMapper::setMaskLayer(GraphicsLayer* value)
152 if (value == maskLayer())
154 GraphicsLayer::setMaskLayer(value);
155 notifyChange(TextureMapperNode::MaskLayerChange);
159 /* \reimp (GraphicsLayer.h)
161 void GraphicsLayerTextureMapper::setReplicatedByLayer(GraphicsLayer* value)
163 if (value == replicaLayer())
165 GraphicsLayer::setReplicatedByLayer(value);
166 notifyChange(TextureMapperNode::ReplicaLayerChange);
169 /* \reimp (GraphicsLayer.h)
171 void GraphicsLayerTextureMapper::setPosition(const FloatPoint& value)
173 if (value == position())
175 GraphicsLayer::setPosition(value);
176 notifyChange(TextureMapperNode::PositionChange);
179 /* \reimp (GraphicsLayer.h)
181 void GraphicsLayerTextureMapper::setAnchorPoint(const FloatPoint3D& value)
183 if (value == anchorPoint())
185 GraphicsLayer::setAnchorPoint(value);
186 notifyChange(TextureMapperNode::AnchorPointChange);
189 /* \reimp (GraphicsLayer.h)
191 void GraphicsLayerTextureMapper::setSize(const FloatSize& value)
196 GraphicsLayer::setSize(value);
197 notifyChange(TextureMapperNode::SizeChange);
200 /* \reimp (GraphicsLayer.h)
202 void GraphicsLayerTextureMapper::setTransform(const TransformationMatrix& value)
204 if (value == transform())
207 GraphicsLayer::setTransform(value);
208 notifyChange(TextureMapperNode::TransformChange);
211 /* \reimp (GraphicsLayer.h)
213 void GraphicsLayerTextureMapper::setChildrenTransform(const TransformationMatrix& value)
215 if (value == childrenTransform())
217 GraphicsLayer::setChildrenTransform(value);
218 notifyChange(TextureMapperNode::ChildrenTransformChange);
221 /* \reimp (GraphicsLayer.h)
223 void GraphicsLayerTextureMapper::setPreserves3D(bool value)
225 if (value == preserves3D())
227 GraphicsLayer::setPreserves3D(value);
228 notifyChange(TextureMapperNode::Preserves3DChange);
231 /* \reimp (GraphicsLayer.h)
233 void GraphicsLayerTextureMapper::setMasksToBounds(bool value)
235 if (value == masksToBounds())
237 GraphicsLayer::setMasksToBounds(value);
238 notifyChange(TextureMapperNode::MasksToBoundsChange);
241 /* \reimp (GraphicsLayer.h)
243 void GraphicsLayerTextureMapper::setDrawsContent(bool value)
245 if (value == drawsContent())
247 notifyChange(TextureMapperNode::DrawsContentChange);
248 GraphicsLayer::setDrawsContent(value);
251 /* \reimp (GraphicsLayer.h)
253 void GraphicsLayerTextureMapper::setBackgroundColor(const Color& value)
255 if (value == m_pendingContent.backgroundColor)
257 m_pendingContent.backgroundColor = value;
258 GraphicsLayer::setBackgroundColor(value);
259 notifyChange(TextureMapperNode::BackgroundColorChange);
262 /* \reimp (GraphicsLayer.h)
264 void GraphicsLayerTextureMapper::clearBackgroundColor()
266 if (!m_pendingContent.backgroundColor.isValid())
268 m_pendingContent.backgroundColor = Color();
269 GraphicsLayer::clearBackgroundColor();
270 notifyChange(TextureMapperNode::BackgroundColorChange);
273 /* \reimp (GraphicsLayer.h)
275 void GraphicsLayerTextureMapper::setContentsOpaque(bool value)
277 if (value == contentsOpaque())
279 notifyChange(TextureMapperNode::ContentsOpaqueChange);
280 GraphicsLayer::setContentsOpaque(value);
283 /* \reimp (GraphicsLayer.h)
285 void GraphicsLayerTextureMapper::setBackfaceVisibility(bool value)
287 if (value == backfaceVisibility())
289 GraphicsLayer::setBackfaceVisibility(value);
290 notifyChange(TextureMapperNode::BackfaceVisibilityChange);
293 /* \reimp (GraphicsLayer.h)
295 void GraphicsLayerTextureMapper::setOpacity(float value)
297 if (value == opacity())
299 GraphicsLayer::setOpacity(value);
300 notifyChange(TextureMapperNode::OpacityChange);
303 /* \reimp (GraphicsLayer.h)
305 void GraphicsLayerTextureMapper::setContentsRect(const IntRect& value)
307 if (value == contentsRect())
309 GraphicsLayer::setContentsRect(value);
310 notifyChange(TextureMapperNode::ContentsRectChange);
313 /* \reimp (GraphicsLayer.h)
315 void GraphicsLayerTextureMapper::setContentsToImage(Image* image)
317 notifyChange(TextureMapperNode::ContentChange);
318 m_pendingContent.contentType = image ? TextureMapperNode::DirectImageContentType : TextureMapperNode::HTMLContentType;
319 m_pendingContent.image = image;
320 GraphicsLayer::setContentsToImage(image);
323 void GraphicsLayerTextureMapper::setContentsToMedia(TextureMapperPlatformLayer* media)
325 GraphicsLayer::setContentsToMedia(media);
326 notifyChange(TextureMapperNode::ContentChange);
327 m_pendingContent.contentType = media ? TextureMapperNode::MediaContentType : TextureMapperNode::HTMLContentType;
328 m_pendingContent.media = media;
331 /* \reimp (GraphicsLayer.h)
333 void GraphicsLayerTextureMapper::syncCompositingStateForThisLayerOnly()
335 m_node->syncCompositingState(this);
338 /* \reimp (GraphicsLayer.h)
340 void GraphicsLayerTextureMapper::syncCompositingState(const FloatRect&)
342 m_node->syncCompositingState(this, TextureMapperNode::TraverseDescendants);
345 /* \reimp (GraphicsLayer.h)
347 PlatformLayer* GraphicsLayerTextureMapper::platformLayer() const
349 return const_cast<TextureMapperPlatformLayer*>(node()->media());
352 bool GraphicsLayerTextureMapper::addAnimation(const KeyframeValueList& valueList, const IntSize& boxSize, const Animation* anim, const String& keyframesName, double timeOffset)
354 ASSERT(!keyframesName.isEmpty());
356 if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2 || (valueList.property() != AnimatedPropertyWebkitTransform && valueList.property() != AnimatedPropertyOpacity))
359 for (size_t i = 0; i < m_animations.size(); ++i) {
360 // The same animation name can be used for two animations with different properties.
361 if (m_animations[i]->name != keyframesName || m_animations[i]->keyframes.property() != valueList.property())
364 // We already have a copy of this animation, that means that we're resuming it rather than adding it.
365 RefPtr<TextureMapperAnimation>& animation = m_animations[i];
366 animation->animation = Animation::create(anim);
367 animation->paused = false;
368 animation->startTime = WTF::currentTime() - timeOffset;
369 notifyChange(TextureMapperNode::AnimationChange);
370 m_animationStartedTimer.startOneShot(0);
374 RefPtr<TextureMapperAnimation> animation = TextureMapperAnimation::create(valueList);
375 animation->boxSize = boxSize;
376 animation->name = keyframesName;
377 animation->animation = Animation::create(anim);
378 animation->paused = false;
379 animation->startTime = WTF::currentTime() - timeOffset;
381 if (valueList.property() == AnimatedPropertyWebkitTransform) {
382 bool hasBigRotation; // Not used, but required as a pointer parameter for the function.
383 fetchTransformOperationList(valueList, animation->functionList, animation->listsMatch, hasBigRotation);
386 m_animations.append(animation);
387 notifyChange(TextureMapperNode::AnimationChange);
388 m_animationStartedTimer.startOneShot(0);
393 void GraphicsLayerTextureMapper::pauseAnimation(const String& animationName, double timeOffset)
395 for (size_t i = 0; i < m_animations.size(); ++i) {
396 if (m_animations[i]->name != animationName)
398 m_animations[i]->paused = true;
399 notifyChange(TextureMapperNode::AnimationChange);
403 void GraphicsLayerTextureMapper::removeAnimation(const String& animationName)
405 for (int i = m_animations.size() - 1; i >= 0; --i) {
406 // The same animation name can be used for two animations with different properties. We should remove both.
407 if (m_animations[i]->name != animationName)
409 m_animations.remove(i);
410 notifyChange(TextureMapperNode::AnimationChange);
414 void GraphicsLayerTextureMapper::animationStartedTimerFired(Timer<GraphicsLayerTextureMapper>*)
416 client()->notifyAnimationStarted(this, /* DOM time */ WTF::currentTime());
419 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
421 if (s_graphicsLayerFactory)
422 return (*s_graphicsLayerFactory)(client);
423 return adoptPtr(new GraphicsLayerTextureMapper(client));