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"
27 #include "ImagesManager.h"
30 #include "MediaLayer.h"
31 #include "PlatformBridge.h"
32 #include "PlatformGraphicsContext.h"
33 #include "RenderLayerBacking.h"
34 #include "RenderView.h"
35 #include "RotateTransformOperation.h"
36 #include "ScaleTransformOperation.h"
37 #include "ScrollableLayerAndroid.h"
40 #include "TransformationMatrix.h"
41 #include "TranslateTransformOperation.h"
43 #include <cutils/log.h>
44 #include <wtf/CurrentTime.h>
45 #include <wtf/text/CString.h>
48 #define LOG(...) android_printLog(ANDROID_LOG_DEBUG, "GraphicsLayer", __VA_ARGS__)
49 #define MLOG(...) android_printLog(ANDROID_LOG_DEBUG, "GraphicsLayer", __VA_ARGS__)
50 #define TLOG(...) android_printLog(ANDROID_LOG_DEBUG, "GraphicsLayer", __VA_ARGS__)
63 static double gPausedDelay;
67 static int gDebugGraphicsLayerAndroidInstances = 0;
68 inline int GraphicsLayerAndroid::instancesCount()
70 return gDebugGraphicsLayerAndroidInstances;
73 static String propertyIdToString(AnimatedPropertyID property)
76 case AnimatedPropertyWebkitTransform:
78 case AnimatedPropertyOpacity:
80 case AnimatedPropertyBackgroundColor:
81 return "backgroundColor";
82 case AnimatedPropertyInvalid:
89 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
91 return new GraphicsLayerAndroid(client);
94 SkLength convertLength(Length len)
97 length.type = SkLength::Undefined;
99 if (len.type() == WebCore::Percent) {
100 length.type = SkLength::Percent;
101 length.value = len.percent();
103 if (len.type() == WebCore::Fixed) {
104 length.type = SkLength::Fixed;
105 length.value = len.value();
110 static RenderLayer* renderLayerFromClient(GraphicsLayerClient* client)
112 return client ? client->owningLayer() : 0;
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),
124 m_foregroundLayer(0),
125 m_foregroundClipLayer(0)
127 RenderLayer* renderLayer = renderLayerFromClient(m_client);
128 m_contentLayer = new LayerAndroid(renderLayer);
129 m_dirtyRegion.setEmpty();
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()
223 RenderLayer* renderLayer = renderLayerFromClient(m_client);
226 RenderView* view = static_cast<RenderView*>(renderLayer->renderer());
231 // We will need the Iframe flag in the LayerAndroid tree for fixed position
232 if (view->isRenderIFrame())
233 m_contentLayer->setIsIframe(true);
234 // If we are a fixed position layer, just set it
235 if (view->isPositioned() && view->style()->position() == FixedPosition) {
236 // We need to get the passed CSS properties for the element
237 SkLength left, top, right, bottom;
238 left = convertLength(view->style()->left());
239 top = convertLength(view->style()->top());
240 right = convertLength(view->style()->right());
241 bottom = convertLength(view->style()->bottom());
243 // We also need to get the margin...
244 SkLength marginLeft, marginTop, marginRight, marginBottom;
245 marginLeft = convertLength(view->style()->marginLeft());
246 marginTop = convertLength(view->style()->marginTop());
247 marginRight = convertLength(view->style()->marginRight());
248 marginBottom = convertLength(view->style()->marginBottom());
250 // In order to compute the fixed element's position, we need the width
251 // and height of the element when bottom or right is defined.
252 // And here we should use the non-overflowed value, that means, the
253 // overflowed content (e.g. outset shadow) will not be counted into the
255 int w = view->width();
256 int h = view->height();
258 int paintingOffsetX = - offsetFromRenderer().width();
259 int paintingOffsetY = - offsetFromRenderer().height();
262 viewRect.set(paintingOffsetX, paintingOffsetY, paintingOffsetX + w, paintingOffsetY + h);
263 IntPoint renderLayerPos(renderLayer->x(), renderLayer->y());
264 m_contentLayer->setFixedPosition(left, top, right, bottom,
265 marginLeft, marginTop,
266 marginRight, marginBottom,
272 void GraphicsLayerAndroid::setPosition(const FloatPoint& point)
274 if (point == m_position)
277 GraphicsLayer::setPosition(point);
280 LOG("(%x) setPosition(%.2f,%.2f) pos(%.2f, %.2f) anchor(%.2f,%.2f) size(%.2f, %.2f)",
281 this, point.x(), point.y(), m_position.x(), m_position.y(),
282 m_anchorPoint.x(), m_anchorPoint.y(), m_size.width(), m_size.height());
284 m_contentLayer->setPosition(point.x(), point.y());
288 void GraphicsLayerAndroid::setPreserves3D(bool preserves3D)
290 if (preserves3D == m_preserves3D)
293 GraphicsLayer::setPreserves3D(preserves3D);
294 m_contentLayer->setPreserves3D(preserves3D);
298 void GraphicsLayerAndroid::setAnchorPoint(const FloatPoint3D& point)
300 if (point == m_anchorPoint)
302 GraphicsLayer::setAnchorPoint(point);
303 m_contentLayer->setAnchorPoint(point.x(), point.y());
304 m_contentLayer->setAnchorPointZ(point.z());
308 void GraphicsLayerAndroid::setSize(const FloatSize& size)
312 MLOG("(%x) setSize (%.2f,%.2f)", this, size.width(), size.height());
313 GraphicsLayer::setSize(size);
315 // If it is a media layer the size may have changed as a result of the media
316 // element (e.g. plugin) gaining focus. Therefore, we must sync the size of
317 // the focus' outline so that our UI thread can draw accordingly.
318 RenderLayer* layer = renderLayerFromClient(m_client);
319 if (layer && m_contentLayer->isMedia()) {
320 RenderBox* box = layer->renderBox();
321 int outline = box->view()->maximalOutlineSize();
322 static_cast<MediaLayer*>(m_contentLayer)->setOutlineSize(outline);
323 LOG("Media Outline: %d %p %p %p", outline, m_client, layer, box);
324 LOG("Media Size: %g,%g", size.width(), size.height());
327 m_contentLayer->setSize(size.width(), size.height());
332 void GraphicsLayerAndroid::setBackfaceVisibility(bool b)
334 GraphicsLayer::setBackfaceVisibility(b);
335 m_contentLayer->setBackfaceVisibility(b);
339 void GraphicsLayerAndroid::setTransform(const TransformationMatrix& t)
341 if (t == m_transform)
344 GraphicsLayer::setTransform(t);
345 m_contentLayer->setTransform(t);
349 void GraphicsLayerAndroid::setChildrenTransform(const TransformationMatrix& t)
351 if (t == m_childrenTransform)
353 LOG("(%x) setChildrenTransform", this);
355 GraphicsLayer::setChildrenTransform(t);
356 m_contentLayer->setChildrenTransform(t);
357 for (unsigned int i = 0; i < m_children.size(); i++) {
358 GraphicsLayer* layer = m_children[i];
359 layer->setTransform(t);
360 if (layer->children().size())
361 layer->setChildrenTransform(t);
366 void GraphicsLayerAndroid::setMaskLayer(GraphicsLayer* layer)
368 if (layer == m_maskLayer)
371 GraphicsLayer::setMaskLayer(layer);
372 m_needsSyncMask = true;
376 void GraphicsLayerAndroid::setMasksToBounds(bool masksToBounds)
378 if (masksToBounds == m_masksToBounds)
380 GraphicsLayer::setMasksToBounds(masksToBounds);
381 m_needsSyncMask = true;
385 void GraphicsLayerAndroid::setDrawsContent(bool drawsContent)
387 if (drawsContent == m_drawsContent)
389 GraphicsLayer::setDrawsContent(drawsContent);
390 m_contentLayer->setVisible(drawsContent);
391 if (m_drawsContent) {
392 m_haveContents = true;
398 void GraphicsLayerAndroid::setBackgroundColor(const Color& color)
400 if (color == m_backgroundColor)
402 LOG("(%x) setBackgroundColor", this);
403 GraphicsLayer::setBackgroundColor(color);
404 SkColor c = SkColorSetARGB(color.alpha(), color.red(), color.green(), color.blue());
405 m_contentLayer->setBackgroundColor(c);
406 m_haveContents = true;
410 void GraphicsLayerAndroid::clearBackgroundColor()
412 LOG("(%x) clearBackgroundColor", this);
413 GraphicsLayer::clearBackgroundColor();
417 void GraphicsLayerAndroid::setContentsOpaque(bool opaque)
419 if (opaque == m_contentsOpaque)
421 LOG("(%x) setContentsOpaque (%d)", this, opaque);
422 GraphicsLayer::setContentsOpaque(opaque);
423 m_haveContents = true;
427 void GraphicsLayerAndroid::setOpacity(float opacity)
429 LOG("(%x) setOpacity: %.2f", this, opacity);
430 float clampedOpacity = max(0.0f, min(opacity, 1.0f));
432 if (clampedOpacity == m_opacity)
435 MLOG("(%x) setFinalOpacity: %.2f=>%.2f (%.2f)", this,
436 opacity, clampedOpacity, m_opacity);
437 GraphicsLayer::setOpacity(clampedOpacity);
438 m_contentLayer->setOpacity(clampedOpacity);
442 void GraphicsLayerAndroid::setNeedsDisplay()
444 LOG("(%x) setNeedsDisplay()", this);
445 FloatRect rect(0, 0, m_size.width(), m_size.height());
446 setNeedsDisplayInRect(rect);
449 // Helper to set and clear the painting phase as well as auto restore the
451 class PaintingPhase {
453 PaintingPhase(GraphicsLayer* layer)
455 , m_originalPhase(layer->paintingPhase()) {}
459 m_layer->setPaintingPhase(m_originalPhase);
462 void set(GraphicsLayerPaintingPhase phase)
464 m_layer->setPaintingPhase(phase);
467 void clear(GraphicsLayerPaintingPhase phase)
469 m_layer->setPaintingPhase(
470 (GraphicsLayerPaintingPhase) (m_originalPhase & ~phase));
473 GraphicsLayer* m_layer;
474 GraphicsLayerPaintingPhase m_originalPhase;
477 void GraphicsLayerAndroid::updateScrollingLayers()
479 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
480 RenderLayer* layer = renderLayerFromClient(m_client);
481 if (!layer || !m_haveContents)
483 bool hasOverflowScroll = m_foregroundLayer || m_contentLayer->contentIsScrollable();
484 bool layerNeedsOverflow = layer->hasOverflowScroll();
485 bool iframeNeedsOverflow = layer->isRootLayer() &&
486 layer->renderer()->frame()->ownerRenderer() &&
487 layer->renderer()->frame()->view()->hasOverflowScroll();
489 if (hasOverflowScroll && (layerNeedsOverflow || iframeNeedsOverflow)) {
490 // Already has overflow layers.
493 if (!hasOverflowScroll && !layerNeedsOverflow && !iframeNeedsOverflow) {
494 // Does not need overflow layers.
497 if (layerNeedsOverflow || iframeNeedsOverflow) {
498 ASSERT(!hasOverflowScroll);
499 if (layerNeedsOverflow) {
500 ASSERT(!m_foregroundLayer && !m_foregroundClipLayer);
501 m_foregroundLayer = new ScrollableLayerAndroid(layer);
502 m_foregroundClipLayer = new LayerAndroid(layer);
503 m_foregroundClipLayer->setMasksToBounds(true);
504 m_foregroundClipLayer->addChild(m_foregroundLayer);
505 m_contentLayer->addChild(m_foregroundClipLayer);
506 m_contentLayer->setHasOverflowChildren(true);
508 ASSERT(iframeNeedsOverflow && !m_contentLayer->contentIsScrollable());
509 // No need to copy the children as they will be removed and synced.
510 m_contentLayer->removeChildren();
511 // Replace the content layer with a scrollable layer.
512 LayerAndroid* layer = new ScrollableLayerAndroid(*m_contentLayer);
513 m_contentLayer->unref();
514 m_contentLayer = layer;
516 // The content layer has changed so the parent needs to sync
518 static_cast<GraphicsLayerAndroid*>(m_parent)->m_needsSyncChildren = true;
521 // Need to rebuild our children based on the new structure.
522 m_needsSyncChildren = true;
524 ASSERT(hasOverflowScroll && !layerNeedsOverflow && !iframeNeedsOverflow);
525 ASSERT(m_contentLayer);
526 // Remove the foreground layers.
527 if (m_foregroundLayer) {
528 m_foregroundLayer->unref();
529 m_foregroundLayer = 0;
530 m_foregroundClipLayer->unref();
531 m_foregroundClipLayer = 0;
533 // No need to copy over children.
534 m_contentLayer->removeChildren();
535 LayerAndroid* layer = new LayerAndroid(*m_contentLayer);
536 m_contentLayer->unref();
537 m_contentLayer = layer;
539 // The content layer has changed so the parent needs to sync
541 static_cast<GraphicsLayerAndroid*>(m_parent)->m_needsSyncChildren = true;
543 // Children are all re-parented.
544 m_needsSyncChildren = true;
549 bool GraphicsLayerAndroid::repaint()
551 LOG("(%x) repaint(), gPaused(%d) m_needsRepaint(%d) m_haveContents(%d) ",
552 this, gPaused, m_needsRepaint, m_haveContents);
554 if (!gPaused && m_haveContents && m_needsRepaint && !m_haveImage) {
555 // with SkPicture, we request the entire layer's content.
556 IntRect layerBounds(0, 0, m_size.width(), m_size.height());
558 RenderLayer* layer = renderLayerFromClient(m_client);
561 if (m_foregroundLayer) {
562 PaintingPhase phase(this);
563 // Paint the background into a separate context.
564 phase.set(GraphicsLayerPaintBackground);
565 if (!paintContext(m_contentLayer->recordContext(), layerBounds))
567 m_contentLayer->checkTextPresence();
569 // Construct the foreground layer and draw.
570 RenderBox* box = layer->renderBox();
571 int outline = box->view()->maximalOutlineSize();
572 IntRect contentsRect(0, 0,
573 box->borderLeft() + box->borderRight() + layer->scrollWidth(),
574 box->borderTop() + box->borderBottom() + layer->scrollHeight());
575 contentsRect.inflate(outline);
576 // Update the foreground layer size.
577 m_foregroundLayer->setSize(contentsRect.width(), contentsRect.height());
578 // Paint everything else into the main recording canvas.
579 phase.clear(GraphicsLayerPaintBackground);
582 IntSize scroll = layer->scrolledContentOffset();
583 layer->scrollToOffset(0, 0);
584 // At this point, it doesn't matter if painting failed.
585 (void) paintContext(m_foregroundLayer->recordContext(), contentsRect);
586 m_foregroundLayer->checkTextPresence();
587 layer->scrollToOffset(scroll.width(), scroll.height());
589 // Construct the clip layer for masking the contents.
590 IntRect clip = layer->renderer()->absoluteBoundingBoxRect();
591 // absoluteBoundingBoxRect does not include the outline so we need
592 // to offset the position.
593 int x = box->borderLeft() + outline;
594 int y = box->borderTop() + outline;
595 int width = clip.width() - box->borderLeft() - box->borderRight();
596 int height = clip.height() - box->borderTop() - box->borderBottom();
597 m_foregroundClipLayer->setPosition(x, y);
598 m_foregroundClipLayer->setSize(width, height);
600 // Need to offset the foreground layer by the clip layer in order
601 // for the contents to be in the correct position.
602 m_foregroundLayer->setPosition(-x, -y);
603 // Set the scrollable bounds of the layer.
604 m_foregroundLayer->setScrollLimits(-x, -y, m_size.width(), m_size.height());
605 m_foregroundLayer->markAsDirty(m_dirtyRegion);
606 m_foregroundLayer->needsRepaint();
608 // If there is no contents clip, we can draw everything into one
610 if (!paintContext(m_contentLayer->recordContext(), layerBounds))
612 m_contentLayer->checkTextPresence();
613 // Check for a scrollable iframe and report the scrolling
614 // limits based on the view size.
615 if (m_contentLayer->contentIsScrollable()) {
616 FrameView* view = layer->renderer()->frame()->view();
617 static_cast<ScrollableLayerAndroid*>(m_contentLayer)->setScrollLimits(
618 m_position.x(), m_position.y(), view->layoutWidth(), view->layoutHeight());
622 LOG("(%x) repaint() on (%.2f,%.2f) contentlayer(%.2f,%.2f,%.2f,%.2f)paintGraphicsLayer called!",
623 this, m_size.width(), m_size.height(),
624 m_contentLayer->getPosition().fX,
625 m_contentLayer->getPosition().fY,
626 m_contentLayer->getSize().width(),
627 m_contentLayer->getSize().height());
629 m_contentLayer->markAsDirty(m_dirtyRegion);
630 m_dirtyRegion.setEmpty();
631 m_contentLayer->needsRepaint();
632 m_needsRepaint = false;
636 if (m_needsRepaint && m_haveImage && m_newImage) {
637 // We need to tell the GL thread that we will need to repaint the
638 // texture. Only do so if we effectively have a new image!
639 m_contentLayer->markAsDirty(m_dirtyRegion);
640 m_dirtyRegion.setEmpty();
641 m_contentLayer->needsRepaint();
643 m_needsRepaint = false;
649 bool GraphicsLayerAndroid::paintContext(SkPicture* context,
652 SkAutoPictureRecord arp(context, rect.width(), rect.height());
653 SkCanvas* canvas = arp.getRecordingCanvas();
658 PlatformGraphicsContext platformContext(canvas);
659 GraphicsContext graphicsContext(&platformContext);
661 paintGraphicsLayerContents(graphicsContext, rect);
665 void GraphicsLayerAndroid::setNeedsDisplayInRect(const FloatRect& rect)
667 // rect is in the render object coordinates
669 if (!m_haveImage && !drawsContent()) {
670 LOG("(%x) setNeedsDisplay(%.2f,%.2f,%.2f,%.2f) doesn't have content, bypass...",
671 this, rect.x(), rect.y(), rect.width(), rect.height());
676 region.setRect(rect.x(), rect.y(),
677 rect.x() + rect.width(),
678 rect.y() + rect.height());
679 m_dirtyRegion.op(region, SkRegion::kUnion_Op);
681 m_needsRepaint = true;
685 void GraphicsLayerAndroid::pauseDisplay(bool state)
689 gPausedDelay = WTF::currentTime() + 1;
692 bool GraphicsLayerAndroid::addAnimation(const KeyframeValueList& valueList,
693 const IntSize& boxSize,
694 const Animation* anim,
695 const String& keyframesName,
698 if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2)
701 bool createdAnimations = false;
702 if (valueList.property() == AnimatedPropertyWebkitTransform) {
703 createdAnimations = createTransformAnimationsFromKeyframes(valueList,
709 createdAnimations = createAnimationFromKeyframes(valueList,
714 if (createdAnimations)
716 return createdAnimations;
719 bool GraphicsLayerAndroid::createAnimationFromKeyframes(const KeyframeValueList& valueList,
720 const Animation* animation, const String& keyframesName, double beginTime)
722 bool isKeyframe = valueList.size() > 2;
723 TLOG("createAnimationFromKeyframes(%d), name(%s) beginTime(%.2f)",
724 isKeyframe, keyframesName.latin1().data(), beginTime);
726 switch (valueList.property()) {
727 case AnimatedPropertyInvalid: break;
728 case AnimatedPropertyWebkitTransform: break;
729 case AnimatedPropertyBackgroundColor: break;
730 case AnimatedPropertyOpacity: {
731 MLOG("ANIMATEDPROPERTYOPACITY");
733 KeyframeValueList* operationsList = new KeyframeValueList(AnimatedPropertyOpacity);
734 for (unsigned int i = 0; i < valueList.size(); i++) {
735 FloatAnimationValue* originalValue = (FloatAnimationValue*)valueList.at(i);
736 PassRefPtr<TimingFunction> timingFunction(const_cast<TimingFunction*>(originalValue->timingFunction()));
737 FloatAnimationValue* value = new FloatAnimationValue(originalValue->keyTime(),
738 originalValue->value(),
740 operationsList->insert(value);
743 RefPtr<AndroidOpacityAnimation> anim = AndroidOpacityAnimation::create(animation,
746 if (keyframesName.isEmpty())
747 anim->setName(propertyIdToString(valueList.property()));
749 anim->setName(keyframesName);
751 m_contentLayer->addAnimation(anim.release());
759 void GraphicsLayerAndroid::needsNotifyClient()
761 m_needsNotifyClient = true;
765 bool GraphicsLayerAndroid::createTransformAnimationsFromKeyframes(const KeyframeValueList& valueList,
766 const Animation* animation,
767 const String& keyframesName,
769 const IntSize& boxSize)
771 ASSERT(valueList.property() == AnimatedPropertyWebkitTransform);
772 TLOG("createTransformAnimationFromKeyframes, name(%s) beginTime(%.2f)",
773 keyframesName.latin1().data(), beginTime);
775 KeyframeValueList* operationsList = new KeyframeValueList(AnimatedPropertyWebkitTransform);
776 for (unsigned int i = 0; i < valueList.size(); i++) {
777 TransformAnimationValue* originalValue = (TransformAnimationValue*)valueList.at(i);
778 PassRefPtr<TimingFunction> timingFunction(const_cast<TimingFunction*>(originalValue->timingFunction()));
779 TransformAnimationValue* value = new TransformAnimationValue(originalValue->keyTime(),
780 originalValue->value(),
782 operationsList->insert(value);
785 RefPtr<AndroidTransformAnimation> anim = AndroidTransformAnimation::create(animation,
789 if (keyframesName.isEmpty())
790 anim->setName(propertyIdToString(valueList.property()));
792 anim->setName(keyframesName);
795 m_contentLayer->addAnimation(anim.release());
801 void GraphicsLayerAndroid::removeAnimationsForProperty(AnimatedPropertyID anID)
803 TLOG("NRO removeAnimationsForProperty(%d)", anID);
804 m_contentLayer->removeAnimationsForProperty(anID);
808 void GraphicsLayerAndroid::removeAnimationsForKeyframes(const String& keyframesName)
810 TLOG("NRO removeAnimationsForKeyframes(%s)", keyframesName.latin1().data());
811 m_contentLayer->removeAnimationsForKeyframes(keyframesName);
815 void GraphicsLayerAndroid::pauseAnimation(const String& keyframesName)
817 TLOG("NRO pauseAnimation(%s)", keyframesName.latin1().data());
820 void GraphicsLayerAndroid::suspendAnimations(double time)
822 TLOG("NRO suspendAnimations(%.2f)", time);
825 void GraphicsLayerAndroid::resumeAnimations()
827 TLOG("NRO resumeAnimations()");
830 void GraphicsLayerAndroid::setContentsToImage(Image* image)
832 TLOG("(%x) setContentsToImage", this, image);
834 m_haveContents = true;
837 m_contentLayer->setContentsImage(image->nativeImageForCurrentFrame());
839 if (m_haveImage && !image)
840 m_contentLayer->setContentsImage(0);
846 void GraphicsLayerAndroid::setContentsToMedia(PlatformLayer* mediaLayer)
848 // Only fullscreen video on Android, so media doesn't get it's own layer.
849 // We might still have other layers though.
850 if (m_contentLayer != mediaLayer && mediaLayer) {
852 // TODO add a copy method to LayerAndroid to sync everything
853 // copy data from the original content layer to the new one
854 mediaLayer->setPosition(m_contentLayer->getPosition().fX,
855 m_contentLayer->getPosition().fY);
856 mediaLayer->setSize(m_contentLayer->getWidth(), m_contentLayer->getHeight());
857 mediaLayer->setDrawTransform(*m_contentLayer->drawTransform());
860 m_contentLayer->unref();
861 m_contentLayer = mediaLayer;
863 // If the parent exists then notify it to re-sync it's children
865 GraphicsLayerAndroid* parent = static_cast<GraphicsLayerAndroid*>(m_parent);
866 parent->m_needsSyncChildren = true;
868 m_needsSyncChildren = true;
875 PlatformLayer* GraphicsLayerAndroid::platformLayer() const
877 LOG("platformLayer");
878 return m_contentLayer;
882 void GraphicsLayerAndroid::setDebugBackgroundColor(const Color& color)
886 void GraphicsLayerAndroid::setDebugBorder(const Color& color, float borderWidth)
891 void GraphicsLayerAndroid::setZPosition(float position)
893 if (position == m_zPosition)
895 LOG("(%x) setZPosition: %.2f", this, position);
896 GraphicsLayer::setZPosition(position);
900 void GraphicsLayerAndroid::askForSync()
906 m_client->notifySyncRequired(this);
909 void GraphicsLayerAndroid::syncChildren()
911 if (m_needsSyncChildren) {
912 m_contentLayer->removeChildren();
913 LayerAndroid* layer = m_contentLayer;
914 if (m_foregroundClipLayer) {
915 m_contentLayer->addChild(m_foregroundClipLayer);
916 // Use the scrollable content layer as the parent of the children so
917 // that they move with the content.
918 layer = m_foregroundLayer;
919 layer->removeChildren();
921 for (unsigned int i = 0; i < m_children.size(); i++)
922 layer->addChild(m_children[i]->platformLayer());
923 m_needsSyncChildren = false;
927 void GraphicsLayerAndroid::syncMask()
929 if (m_needsSyncMask) {
931 LayerAndroid* mask = m_maskLayer->platformLayer();
932 m_contentLayer->setMaskLayer(mask);
934 m_contentLayer->setMaskLayer(0);
936 m_contentLayer->setMasksToBounds(m_masksToBounds);
937 m_needsSyncMask = false;
941 void GraphicsLayerAndroid::syncCompositingState()
943 for (unsigned int i = 0; i < m_children.size(); i++)
944 m_children[i]->syncCompositingState();
946 updateScrollingLayers();
947 updateFixedPosition();
951 if (!gPaused || WTF::currentTime() >= gPausedDelay)
955 void GraphicsLayerAndroid::notifyClientAnimationStarted()
957 for (unsigned int i = 0; i < m_children.size(); i++)
958 static_cast<GraphicsLayerAndroid*>(m_children[i])->notifyClientAnimationStarted();
960 if (m_needsNotifyClient) {
962 client()->notifyAnimationStarted(this, WTF::currentTime());
963 m_needsNotifyClient = false;
967 } // namespace WebCore
969 #endif // USE(ACCELERATED_COMPOSITING)