2 * Copyright (C) 2009 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "GraphicsLayerAndroid.h"
20 #if USE(ACCELERATED_COMPOSITING)
22 #include "AndroidAnimation.h"
23 #include "Animation.h"
24 #include "FloatRect.h"
25 #include "GraphicsContext.h"
28 #include "MediaLayer.h"
29 #include "PlatformBridge.h"
30 #include "PlatformGraphicsContext.h"
31 #include "RenderLayerBacking.h"
32 #include "RenderView.h"
33 #include "RotateTransformOperation.h"
34 #include "ScaleTransformOperation.h"
35 #include "ScrollableLayerAndroid.h"
38 #include "TransformationMatrix.h"
39 #include "TranslateTransformOperation.h"
41 #include <cutils/log.h>
42 #include <wtf/CurrentTime.h>
43 #include <wtf/text/CString.h>
46 #define LOG(...) android_printLog(ANDROID_LOG_DEBUG, "GraphicsLayer", __VA_ARGS__)
47 #define MLOG(...) android_printLog(ANDROID_LOG_DEBUG, "GraphicsLayer", __VA_ARGS__)
48 #define TLOG(...) android_printLog(ANDROID_LOG_DEBUG, "GraphicsLayer", __VA_ARGS__)
61 static double gPausedDelay;
65 static int gDebugGraphicsLayerAndroidInstances = 0;
66 inline int GraphicsLayerAndroid::instancesCount()
68 return gDebugGraphicsLayerAndroidInstances;
71 static String propertyIdToString(AnimatedPropertyID property)
74 case AnimatedPropertyWebkitTransform:
76 case AnimatedPropertyOpacity:
78 case AnimatedPropertyBackgroundColor:
79 return "backgroundColor";
80 case AnimatedPropertyInvalid:
87 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
89 return new GraphicsLayerAndroid(client);
92 SkLength convertLength(Length len)
95 length.type = SkLength::Undefined;
97 if (len.type() == WebCore::Percent) {
98 length.type = SkLength::Percent;
99 length.value = len.percent();
101 if (len.type() == WebCore::Fixed) {
102 length.type = SkLength::Fixed;
103 length.value = len.value();
108 static RenderLayer* renderLayerFromClient(GraphicsLayerClient* client)
111 return static_cast<RenderLayerBacking*>(client)->owningLayer();
115 GraphicsLayerAndroid::GraphicsLayerAndroid(GraphicsLayerClient* client) :
116 GraphicsLayer(client),
117 m_needsSyncChildren(false),
118 m_needsSyncMask(false),
119 m_needsRepaint(false),
120 m_needsNotifyClient(false),
121 m_haveContents(false),
125 m_foregroundLayer(0),
126 m_foregroundClipLayer(0)
128 RenderLayer* renderLayer = renderLayerFromClient(m_client);
129 m_contentLayer = new LayerAndroid(renderLayer);
130 gDebugGraphicsLayerAndroidInstances++;
133 GraphicsLayerAndroid::~GraphicsLayerAndroid()
135 m_contentLayer->unref();
136 SkSafeUnref(m_foregroundLayer);
137 SkSafeUnref(m_foregroundClipLayer);
138 gDebugGraphicsLayerAndroidInstances--;
141 void GraphicsLayerAndroid::setName(const String& name)
143 GraphicsLayer::setName(name);
146 NativeLayer GraphicsLayerAndroid::nativeLayer() const
148 LOG("(%x) nativeLayer", this);
152 bool GraphicsLayerAndroid::setChildren(const Vector<GraphicsLayer*>& children)
154 bool childrenChanged = GraphicsLayer::setChildren(children);
155 if (childrenChanged) {
156 m_needsSyncChildren = true;
160 return childrenChanged;
163 void GraphicsLayerAndroid::addChild(GraphicsLayer* childLayer)
166 const String& name = childLayer->name();
167 LOG("(%x) addChild: %x (%s)", this, childLayer, name.latin1().data());
169 GraphicsLayer::addChild(childLayer);
170 m_needsSyncChildren = true;
174 void GraphicsLayerAndroid::addChildAtIndex(GraphicsLayer* childLayer, int index)
176 LOG("(%x) addChild %x AtIndex %d", this, childLayer, index);
177 GraphicsLayer::addChildAtIndex(childLayer, index);
178 m_needsSyncChildren = true;
182 void GraphicsLayerAndroid::addChildBelow(GraphicsLayer* childLayer, GraphicsLayer* sibling)
184 LOG("(%x) addChild %x Below %x", this, childLayer, sibling);
185 GraphicsLayer::addChildBelow(childLayer, sibling);
186 m_needsSyncChildren = true;
190 void GraphicsLayerAndroid::addChildAbove(GraphicsLayer* childLayer, GraphicsLayer* sibling)
192 LOG("(%x) addChild %x Above %x", this, childLayer, sibling);
193 GraphicsLayer::addChildAbove(childLayer, sibling);
194 m_needsSyncChildren = true;
198 bool GraphicsLayerAndroid::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
200 LOG("(%x) replaceChild %x by %x", this, oldChild, newChild);
201 bool ret = GraphicsLayer::replaceChild(oldChild, newChild);
203 m_needsSyncChildren = true;
209 void GraphicsLayerAndroid::removeFromParent()
211 LOG("(%x) removeFromParent()", this);
212 GraphicsLayerAndroid* parent = static_cast<GraphicsLayerAndroid*>(m_parent);
213 GraphicsLayer::removeFromParent();
214 // Update the parent's children.
216 parent->m_needsSyncChildren = true;
221 void GraphicsLayerAndroid::updateFixedPosition()
226 RenderLayer* renderLayer = renderLayerFromClient(m_client);
227 RenderView* view = static_cast<RenderView*>(renderLayer->renderer());
229 // We will need the Iframe flag in the LayerAndroid tree for fixed position
230 if (view && view->isRenderIFrame())
231 m_contentLayer->setIsIframe(true);
232 // If we are a fixed position layer, just set it
233 if (view->isPositioned() && view->style()->position() == FixedPosition) {
234 // We need to get the passed CSS properties for the element
235 SkLength left, top, right, bottom;
236 left = convertLength(view->style()->left());
237 top = convertLength(view->style()->top());
238 right = convertLength(view->style()->right());
239 bottom = convertLength(view->style()->bottom());
241 // We also need to get the margin...
242 SkLength marginLeft, marginTop, marginRight, marginBottom;
243 marginLeft = convertLength(view->style()->marginLeft());
244 marginTop = convertLength(view->style()->marginTop());
245 marginRight = convertLength(view->style()->marginRight());
246 marginBottom = convertLength(view->style()->marginBottom());
248 // In order to compute the fixed element's position, we need the width
249 // and height of the element when bottom or right is defined.
250 // And here we should use the non-overflowed value, that means, the
251 // overflowed content (e.g. outset shadow) will not be counted into the
253 int w = view->width();
254 int h = view->height();
256 int paintingOffsetX = - offsetFromRenderer().width();
257 int paintingOffsetY = - offsetFromRenderer().height();
260 viewRect.set(paintingOffsetX, paintingOffsetY, paintingOffsetX + w, paintingOffsetY + h);
261 IntPoint renderLayerPos(renderLayer->x(), renderLayer->y());
262 m_contentLayer->setFixedPosition(left, top, right, bottom,
263 marginLeft, marginTop,
264 marginRight, marginBottom,
270 void GraphicsLayerAndroid::setPosition(const FloatPoint& point)
272 if (point == m_position)
275 GraphicsLayer::setPosition(point);
278 LOG("(%x) setPosition(%.2f,%.2f) pos(%.2f, %.2f) anchor(%.2f,%.2f) size(%.2f, %.2f)",
279 this, point.x(), point.y(), m_position.x(), m_position.y(),
280 m_anchorPoint.x(), m_anchorPoint.y(), m_size.width(), m_size.height());
282 m_contentLayer->setPosition(point.x(), point.y());
286 void GraphicsLayerAndroid::setPreserves3D(bool preserves3D)
288 if (preserves3D == m_preserves3D)
291 GraphicsLayer::setPreserves3D(preserves3D);
292 m_contentLayer->setPreserves3D(preserves3D);
296 void GraphicsLayerAndroid::setAnchorPoint(const FloatPoint3D& point)
298 if (point == m_anchorPoint)
300 GraphicsLayer::setAnchorPoint(point);
301 m_contentLayer->setAnchorPoint(point.x(), point.y());
302 m_contentLayer->setAnchorPointZ(point.z());
306 void GraphicsLayerAndroid::setSize(const FloatSize& size)
310 MLOG("(%x) setSize (%.2f,%.2f)", this, size.width(), size.height());
311 GraphicsLayer::setSize(size);
313 // If it is a media layer the size may have changed as a result of the media
314 // element (e.g. plugin) gaining focus. Therefore, we must sync the size of
315 // the focus' outline so that our UI thread can draw accordingly.
316 if (m_contentLayer->isMedia() && m_client) {
317 RenderLayer* layer = renderLayerFromClient(m_client);
318 RenderBox* box = layer->renderBox();
319 int outline = box->view()->maximalOutlineSize();
320 static_cast<MediaLayer*>(m_contentLayer)->setOutlineSize(outline);
321 LOG("Media Outline: %d %p %p %p", outline, m_client, layer, box);
322 LOG("Media Size: %g,%g", size.width(), size.height());
325 m_contentLayer->setSize(size.width(), size.height());
329 void GraphicsLayerAndroid::setBackfaceVisibility(bool b)
331 GraphicsLayer::setBackfaceVisibility(b);
332 m_contentLayer->setBackfaceVisibility(b);
336 void GraphicsLayerAndroid::setTransform(const TransformationMatrix& t)
338 if (t == m_transform)
341 GraphicsLayer::setTransform(t);
342 m_contentLayer->setTransform(t);
346 void GraphicsLayerAndroid::setChildrenTransform(const TransformationMatrix& t)
348 if (t == m_childrenTransform)
350 LOG("(%x) setChildrenTransform", this);
352 GraphicsLayer::setChildrenTransform(t);
353 m_contentLayer->setChildrenTransform(t);
354 for (unsigned int i = 0; i < m_children.size(); i++) {
355 GraphicsLayer* layer = m_children[i];
356 layer->setTransform(t);
357 if (layer->children().size())
358 layer->setChildrenTransform(t);
363 void GraphicsLayerAndroid::setMaskLayer(GraphicsLayer* layer)
365 if (layer == m_maskLayer)
368 GraphicsLayer::setMaskLayer(layer);
369 m_needsSyncMask = true;
373 void GraphicsLayerAndroid::setMasksToBounds(bool masksToBounds)
375 if (masksToBounds == m_masksToBounds)
377 GraphicsLayer::setMasksToBounds(masksToBounds);
378 m_needsSyncMask = true;
382 void GraphicsLayerAndroid::setDrawsContent(bool drawsContent)
384 if (drawsContent == m_drawsContent)
386 GraphicsLayer::setDrawsContent(drawsContent);
387 if (m_drawsContent) {
388 m_haveContents = true;
394 void GraphicsLayerAndroid::setBackgroundColor(const Color& color)
396 if (color == m_backgroundColor)
398 LOG("(%x) setBackgroundColor", this);
399 GraphicsLayer::setBackgroundColor(color);
400 SkColor c = SkColorSetARGB(color.alpha(), color.red(), color.green(), color.blue());
401 m_contentLayer->setBackgroundColor(c);
402 m_haveContents = true;
406 void GraphicsLayerAndroid::clearBackgroundColor()
408 LOG("(%x) clearBackgroundColor", this);
409 GraphicsLayer::clearBackgroundColor();
413 void GraphicsLayerAndroid::setContentsOpaque(bool opaque)
415 if (opaque == m_contentsOpaque)
417 LOG("(%x) setContentsOpaque (%d)", this, opaque);
418 GraphicsLayer::setContentsOpaque(opaque);
419 m_haveContents = true;
423 void GraphicsLayerAndroid::setOpacity(float opacity)
425 LOG("(%x) setOpacity: %.2f", this, opacity);
426 float clampedOpacity = max(0.0f, min(opacity, 1.0f));
428 if (clampedOpacity == m_opacity)
431 MLOG("(%x) setFinalOpacity: %.2f=>%.2f (%.2f)", this,
432 opacity, clampedOpacity, m_opacity);
433 GraphicsLayer::setOpacity(clampedOpacity);
434 m_contentLayer->setOpacity(clampedOpacity);
438 void GraphicsLayerAndroid::setNeedsDisplay()
440 LOG("(%x) setNeedsDisplay()", this);
441 FloatRect rect(0, 0, m_size.width(), m_size.height());
442 setNeedsDisplayInRect(rect);
445 // Helper to set and clear the painting phase as well as auto restore the
447 class PaintingPhase {
449 PaintingPhase(GraphicsLayer* layer)
451 , m_originalPhase(layer->paintingPhase()) {}
455 m_layer->setPaintingPhase(m_originalPhase);
458 void set(GraphicsLayerPaintingPhase phase)
460 m_layer->setPaintingPhase(phase);
463 void clear(GraphicsLayerPaintingPhase phase)
465 m_layer->setPaintingPhase(
466 (GraphicsLayerPaintingPhase) (m_originalPhase & ~phase));
469 GraphicsLayer* m_layer;
470 GraphicsLayerPaintingPhase m_originalPhase;
473 void GraphicsLayerAndroid::updateScrollingLayers()
475 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
476 RenderLayer* layer = renderLayerFromClient(m_client);
477 if (!layer || !m_haveContents)
479 bool hasOverflowScroll = m_foregroundLayer || m_contentLayer->contentIsScrollable();
480 bool layerNeedsOverflow = layer->hasOverflowScroll();
481 bool iframeNeedsOverflow = layer->isRootLayer() &&
482 layer->renderer()->frame()->ownerRenderer() &&
483 layer->renderer()->frame()->view()->hasOverflowScroll();
485 if (hasOverflowScroll && (layerNeedsOverflow || iframeNeedsOverflow)) {
486 // Already has overflow layers.
489 if (!hasOverflowScroll && !layerNeedsOverflow && !iframeNeedsOverflow) {
490 // Does not need overflow layers.
493 if (layerNeedsOverflow || iframeNeedsOverflow) {
494 ASSERT(!hasOverflowScroll);
495 if (layerNeedsOverflow) {
496 ASSERT(!m_foregroundLayer && !m_foregroundClipLayer);
497 m_foregroundLayer = new ScrollableLayerAndroid(layer);
498 m_foregroundClipLayer = new LayerAndroid(layer);
499 m_foregroundClipLayer->setMasksToBounds(true);
500 m_foregroundClipLayer->addChild(m_foregroundLayer);
501 m_contentLayer->addChild(m_foregroundClipLayer);
503 ASSERT(iframeNeedsOverflow && !m_contentLayer->contentIsScrollable());
504 // No need to copy the children as they will be removed and synced.
505 m_contentLayer->removeChildren();
506 // Replace the content layer with a scrollable layer.
507 LayerAndroid* layer = new ScrollableLayerAndroid(*m_contentLayer);
508 m_contentLayer->unref();
509 m_contentLayer = layer;
511 // The content layer has changed so the parent needs to sync
513 static_cast<GraphicsLayerAndroid*>(m_parent)->m_needsSyncChildren = true;
516 // Need to rebuild our children based on the new structure.
517 m_needsSyncChildren = true;
519 ASSERT(hasOverflowScroll && !layerNeedsOverflow && !iframeNeedsOverflow);
520 ASSERT(m_contentLayer);
521 // Remove the foreground layers.
522 if (m_foregroundLayer) {
523 m_foregroundLayer->unref();
524 m_foregroundLayer = 0;
525 m_foregroundClipLayer->unref();
526 m_foregroundClipLayer = 0;
528 // No need to copy over children.
529 m_contentLayer->removeChildren();
530 LayerAndroid* layer = new LayerAndroid(*m_contentLayer);
531 m_contentLayer->unref();
532 m_contentLayer = layer;
534 // The content layer has changed so the parent needs to sync
536 static_cast<GraphicsLayerAndroid*>(m_parent)->m_needsSyncChildren = true;
538 // Children are all re-parented.
539 m_needsSyncChildren = true;
544 bool GraphicsLayerAndroid::repaint()
546 LOG("(%x) repaint(), gPaused(%d) m_needsRepaint(%d) m_haveContents(%d) ",
547 this, gPaused, m_needsRepaint, m_haveContents);
549 if (!gPaused && m_haveContents && m_needsRepaint && !m_haveImage) {
550 // with SkPicture, we request the entire layer's content.
551 IntRect layerBounds(0, 0, m_size.width(), m_size.height());
553 RenderLayer* layer = renderLayerFromClient(m_client);
554 if (m_foregroundLayer) {
555 PaintingPhase phase(this);
556 // Paint the background into a separate context.
557 phase.set(GraphicsLayerPaintBackground);
558 if (!paintContext(m_contentLayer->recordContext(), layerBounds))
561 // Construct the foreground layer and draw.
562 RenderBox* box = layer->renderBox();
563 int outline = box->view()->maximalOutlineSize();
564 IntRect contentsRect(0, 0,
565 box->borderLeft() + box->borderRight() + layer->scrollWidth(),
566 box->borderTop() + box->borderBottom() + layer->scrollHeight());
567 contentsRect.inflate(outline);
568 // Update the foreground layer size.
569 m_foregroundLayer->setSize(contentsRect.width(), contentsRect.height());
570 // Paint everything else into the main recording canvas.
571 phase.clear(GraphicsLayerPaintBackground);
574 IntSize scroll = layer->scrolledContentOffset();
575 layer->scrollToOffset(0, 0);
576 // At this point, it doesn't matter if painting failed.
577 (void) paintContext(m_foregroundLayer->recordContext(), contentsRect);
578 layer->scrollToOffset(scroll.width(), scroll.height());
580 // Construct the clip layer for masking the contents.
581 IntRect clip = layer->renderer()->absoluteBoundingBoxRect();
582 // absoluteBoundingBoxRect does not include the outline so we need
583 // to offset the position.
584 int x = box->borderLeft() + outline;
585 int y = box->borderTop() + outline;
586 int width = clip.width() - box->borderLeft() - box->borderRight();
587 int height = clip.height() - box->borderTop() - box->borderBottom();
588 m_foregroundClipLayer->setPosition(x, y);
589 m_foregroundClipLayer->setSize(width, height);
591 // Need to offset the foreground layer by the clip layer in order
592 // for the contents to be in the correct position.
593 m_foregroundLayer->setPosition(-x, -y);
594 // Set the scrollable bounds of the layer.
595 m_foregroundLayer->setScrollLimits(-x, -y, m_size.width(), m_size.height());
596 m_foregroundLayer->needsRepaint();
598 // If there is no contents clip, we can draw everything into one
600 if (!paintContext(m_contentLayer->recordContext(), layerBounds))
602 // Check for a scrollable iframe and report the scrolling
603 // limits based on the view size.
604 if (m_contentLayer->contentIsScrollable()) {
605 FrameView* view = layer->renderer()->frame()->view();
606 static_cast<ScrollableLayerAndroid*>(m_contentLayer)->setScrollLimits(
607 m_position.x(), m_position.y(), view->layoutWidth(), view->layoutHeight());
611 LOG("(%x) repaint() on (%.2f,%.2f) contentlayer(%.2f,%.2f,%.2f,%.2f)paintGraphicsLayer called!",
612 this, m_size.width(), m_size.height(),
613 m_contentLayer->getPosition().fX,
614 m_contentLayer->getPosition().fY,
615 m_contentLayer->getSize().width(),
616 m_contentLayer->getSize().height());
618 m_contentLayer->needsRepaint();
619 m_needsRepaint = false;
620 m_invalidatedRects.clear();
624 if (m_needsRepaint && m_haveImage && m_newImage) {
625 // We need to tell the GL thread that we will need to repaint the
626 // texture. Only do so if we effectively have a new image!
627 m_contentLayer->needsRepaint();
629 m_needsRepaint = false;
635 bool GraphicsLayerAndroid::paintContext(SkPicture* context,
638 SkAutoPictureRecord arp(context, rect.width(), rect.height());
639 SkCanvas* canvas = arp.getRecordingCanvas();
644 PlatformGraphicsContext platformContext(canvas, 0);
645 GraphicsContext graphicsContext(&platformContext);
647 paintGraphicsLayerContents(graphicsContext, rect);
651 void GraphicsLayerAndroid::setNeedsDisplayInRect(const FloatRect& rect)
653 for (unsigned int i = 0; i < m_children.size(); i++) {
654 GraphicsLayer* layer = m_children[i];
656 FloatRect childrenRect = m_transform.mapRect(rect);
657 layer->setNeedsDisplayInRect(childrenRect);
661 if (!m_haveImage && !drawsContent()) {
662 LOG("(%x) setNeedsDisplay(%.2f,%.2f,%.2f,%.2f) doesn't have content, bypass...",
663 this, rect.x(), rect.y(), rect.width(), rect.height());
667 bool addInval = true;
668 const size_t maxDirtyRects = 8;
669 for (size_t i = 0; i < m_invalidatedRects.size(); ++i) {
670 if (m_invalidatedRects[i].contains(rect)) {
677 LOG("(%x) layer %d setNeedsDisplayInRect(%d) - (%.2f, %.2f, %.2f, %.2f)", this,
678 m_contentLayer->uniqueId(), m_needsRepaint, rect.x(), rect.y(), rect.width(), rect.height());
682 if (m_invalidatedRects.size() < maxDirtyRects)
683 m_invalidatedRects.append(rect);
685 m_invalidatedRects[0].unite(rect);
688 m_needsRepaint = true;
692 void GraphicsLayerAndroid::pauseDisplay(bool state)
696 gPausedDelay = WTF::currentTime() + 1;
699 bool GraphicsLayerAndroid::addAnimation(const KeyframeValueList& valueList,
700 const IntSize& boxSize,
701 const Animation* anim,
702 const String& keyframesName,
705 if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2)
708 bool createdAnimations = false;
709 if (valueList.property() == AnimatedPropertyWebkitTransform) {
710 createdAnimations = createTransformAnimationsFromKeyframes(valueList,
716 createdAnimations = createAnimationFromKeyframes(valueList,
721 if (createdAnimations)
723 return createdAnimations;
726 bool GraphicsLayerAndroid::createAnimationFromKeyframes(const KeyframeValueList& valueList,
727 const Animation* animation, const String& keyframesName, double beginTime)
729 bool isKeyframe = valueList.size() > 2;
730 TLOG("createAnimationFromKeyframes(%d), name(%s) beginTime(%.2f)",
731 isKeyframe, keyframesName.latin1().data(), beginTime);
733 switch (valueList.property()) {
734 case AnimatedPropertyInvalid: break;
735 case AnimatedPropertyWebkitTransform: break;
736 case AnimatedPropertyBackgroundColor: break;
737 case AnimatedPropertyOpacity: {
738 MLOG("ANIMATEDPROPERTYOPACITY");
740 KeyframeValueList* operationsList = new KeyframeValueList(AnimatedPropertyOpacity);
741 for (unsigned int i = 0; i < valueList.size(); i++) {
742 FloatAnimationValue* originalValue = (FloatAnimationValue*)valueList.at(i);
743 PassRefPtr<TimingFunction> timingFunction(const_cast<TimingFunction*>(originalValue->timingFunction()));
744 FloatAnimationValue* value = new FloatAnimationValue(originalValue->keyTime(),
745 originalValue->value(),
747 operationsList->insert(value);
750 RefPtr<AndroidOpacityAnimation> anim = AndroidOpacityAnimation::create(animation,
753 if (keyframesName.isEmpty())
754 anim->setName(propertyIdToString(valueList.property()));
756 anim->setName(keyframesName);
758 m_contentLayer->addAnimation(anim.release());
766 void GraphicsLayerAndroid::needsNotifyClient()
768 m_needsNotifyClient = true;
772 bool GraphicsLayerAndroid::createTransformAnimationsFromKeyframes(const KeyframeValueList& valueList,
773 const Animation* animation,
774 const String& keyframesName,
776 const IntSize& boxSize)
778 ASSERT(valueList.property() == AnimatedPropertyWebkitTransform);
779 TLOG("createTransformAnimationFromKeyframes, name(%s) beginTime(%.2f)",
780 keyframesName.latin1().data(), beginTime);
782 KeyframeValueList* operationsList = new KeyframeValueList(AnimatedPropertyWebkitTransform);
783 for (unsigned int i = 0; i < valueList.size(); i++) {
784 TransformAnimationValue* originalValue = (TransformAnimationValue*)valueList.at(i);
785 PassRefPtr<TimingFunction> timingFunction(const_cast<TimingFunction*>(originalValue->timingFunction()));
786 TransformAnimationValue* value = new TransformAnimationValue(originalValue->keyTime(),
787 originalValue->value(),
789 operationsList->insert(value);
792 RefPtr<AndroidTransformAnimation> anim = AndroidTransformAnimation::create(animation,
796 if (keyframesName.isEmpty())
797 anim->setName(propertyIdToString(valueList.property()));
799 anim->setName(keyframesName);
802 m_contentLayer->addAnimation(anim.release());
808 void GraphicsLayerAndroid::removeAnimationsForProperty(AnimatedPropertyID anID)
810 TLOG("NRO removeAnimationsForProperty(%d)", anID);
811 m_contentLayer->removeAnimationsForProperty(anID);
815 void GraphicsLayerAndroid::removeAnimationsForKeyframes(const String& keyframesName)
817 TLOG("NRO removeAnimationsForKeyframes(%s)", keyframesName.latin1().data());
818 m_contentLayer->removeAnimationsForKeyframes(keyframesName);
822 void GraphicsLayerAndroid::pauseAnimation(const String& keyframesName)
824 TLOG("NRO pauseAnimation(%s)", keyframesName.latin1().data());
827 void GraphicsLayerAndroid::suspendAnimations(double time)
829 TLOG("NRO suspendAnimations(%.2f)", time);
832 void GraphicsLayerAndroid::resumeAnimations()
834 TLOG("NRO resumeAnimations()");
837 void GraphicsLayerAndroid::setContentsToImage(Image* image)
839 TLOG("(%x) setContentsToImage", this, image);
841 m_haveContents = true;
843 // Only pass the new image if it's a different one
844 if (image->nativeImageForCurrentFrame() != m_imageRef) {
846 m_contentLayer->setContentsImage(image->nativeImageForCurrentFrame());
847 // remember the passed image.
848 m_imageRef = image->nativeImageForCurrentFrame();
855 void GraphicsLayerAndroid::setContentsToMedia(PlatformLayer* mediaLayer)
857 // Only fullscreen video on Android, so media doesn't get it's own layer.
858 // We might still have other layers though.
859 if (m_contentLayer != mediaLayer && mediaLayer) {
861 // TODO add a copy method to LayerAndroid to sync everything
862 // copy data from the original content layer to the new one
863 mediaLayer->setPosition(m_contentLayer->getPosition().fX,
864 m_contentLayer->getPosition().fY);
865 mediaLayer->setSize(m_contentLayer->getWidth(), m_contentLayer->getHeight());
866 mediaLayer->setDrawTransform(m_contentLayer->drawTransform());
869 m_contentLayer->unref();
870 m_contentLayer = mediaLayer;
872 // If the parent exists then notify it to re-sync it's children
874 GraphicsLayerAndroid* parent = static_cast<GraphicsLayerAndroid*>(m_parent);
875 parent->m_needsSyncChildren = true;
877 m_needsSyncChildren = true;
884 PlatformLayer* GraphicsLayerAndroid::platformLayer() const
886 LOG("platformLayer");
887 return m_contentLayer;
891 void GraphicsLayerAndroid::setDebugBackgroundColor(const Color& color)
895 void GraphicsLayerAndroid::setDebugBorder(const Color& color, float borderWidth)
900 void GraphicsLayerAndroid::setZPosition(float position)
902 if (position == m_zPosition)
904 LOG("(%x) setZPosition: %.2f", this, position);
905 GraphicsLayer::setZPosition(position);
909 void GraphicsLayerAndroid::askForSync()
915 m_client->notifySyncRequired(this);
918 void GraphicsLayerAndroid::syncChildren()
920 if (m_needsSyncChildren) {
921 m_contentLayer->removeChildren();
922 LayerAndroid* layer = m_contentLayer;
923 if (m_foregroundClipLayer) {
924 m_contentLayer->addChild(m_foregroundClipLayer);
925 // Use the scrollable content layer as the parent of the children so
926 // that they move with the content.
927 layer = m_foregroundLayer;
928 layer->removeChildren();
930 for (unsigned int i = 0; i < m_children.size(); i++)
931 layer->addChild(m_children[i]->platformLayer());
932 m_needsSyncChildren = false;
936 void GraphicsLayerAndroid::syncMask()
938 if (m_needsSyncMask) {
940 LayerAndroid* mask = m_maskLayer->platformLayer();
941 m_contentLayer->setMaskLayer(mask);
943 m_contentLayer->setMaskLayer(0);
945 m_contentLayer->setMasksToBounds(m_masksToBounds);
946 m_needsSyncMask = false;
950 void GraphicsLayerAndroid::syncCompositingState()
952 for (unsigned int i = 0; i < m_children.size(); i++)
953 m_children[i]->syncCompositingState();
955 updateScrollingLayers();
956 updateFixedPosition();
960 if (!gPaused || WTF::currentTime() >= gPausedDelay)
964 void GraphicsLayerAndroid::notifyClientAnimationStarted()
966 for (unsigned int i = 0; i < m_children.size(); i++)
967 static_cast<GraphicsLayerAndroid*>(m_children[i])->notifyClientAnimationStarted();
969 if (m_needsNotifyClient) {
971 client()->notifyAnimationStarted(this, WTF::currentTime());
972 m_needsNotifyClient = false;
976 } // namespace WebCore
978 #endif // USE(ACCELERATED_COMPOSITING)