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"
29 #include "MediaLayer.h"
30 #include "PlatformBridge.h"
31 #include "PlatformGraphicsContext.h"
32 #include "RenderLayerBacking.h"
33 #include "RenderView.h"
34 #include "RotateTransformOperation.h"
35 #include "ScaleTransformOperation.h"
36 #include "ScrollableLayerAndroid.h"
39 #include "TransformationMatrix.h"
40 #include "TranslateTransformOperation.h"
42 #include <cutils/log.h>
43 #include <wtf/CurrentTime.h>
44 #include <wtf/text/CString.h>
47 #define LOG(...) android_printLog(ANDROID_LOG_DEBUG, "GraphicsLayer", __VA_ARGS__)
48 #define MLOG(...) android_printLog(ANDROID_LOG_DEBUG, "GraphicsLayer", __VA_ARGS__)
49 #define TLOG(...) android_printLog(ANDROID_LOG_DEBUG, "GraphicsLayer", __VA_ARGS__)
62 static double gPausedDelay;
66 static int gDebugGraphicsLayerAndroidInstances = 0;
67 inline int GraphicsLayerAndroid::instancesCount()
69 return gDebugGraphicsLayerAndroidInstances;
72 static String propertyIdToString(AnimatedPropertyID property)
75 case AnimatedPropertyWebkitTransform:
77 case AnimatedPropertyOpacity:
79 case AnimatedPropertyBackgroundColor:
80 return "backgroundColor";
81 case AnimatedPropertyInvalid:
88 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
90 return new GraphicsLayerAndroid(client);
93 SkLength convertLength(Length len)
96 length.type = SkLength::Undefined;
98 if (len.type() == WebCore::Percent) {
99 length.type = SkLength::Percent;
100 length.value = len.percent();
102 if (len.type() == WebCore::Fixed) {
103 length.type = SkLength::Fixed;
104 length.value = len.value();
109 static RenderLayer* renderLayerFromClient(GraphicsLayerClient* client)
111 return client ? client->owningLayer() : 0;
114 GraphicsLayerAndroid::GraphicsLayerAndroid(GraphicsLayerClient* client) :
115 GraphicsLayer(client),
116 m_needsSyncChildren(false),
117 m_needsSyncMask(false),
118 m_needsRepaint(false),
119 m_needsNotifyClient(false),
120 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());
331 void GraphicsLayerAndroid::setBackfaceVisibility(bool b)
333 GraphicsLayer::setBackfaceVisibility(b);
334 m_contentLayer->setBackfaceVisibility(b);
338 void GraphicsLayerAndroid::setTransform(const TransformationMatrix& t)
340 if (t == m_transform)
343 GraphicsLayer::setTransform(t);
344 m_contentLayer->setTransform(t);
348 void GraphicsLayerAndroid::setChildrenTransform(const TransformationMatrix& t)
350 if (t == m_childrenTransform)
352 LOG("(%x) setChildrenTransform", this);
354 GraphicsLayer::setChildrenTransform(t);
355 m_contentLayer->setChildrenTransform(t);
356 for (unsigned int i = 0; i < m_children.size(); i++) {
357 GraphicsLayer* layer = m_children[i];
358 layer->setTransform(t);
359 if (layer->children().size())
360 layer->setChildrenTransform(t);
365 void GraphicsLayerAndroid::setMaskLayer(GraphicsLayer* layer)
367 if (layer == m_maskLayer)
370 GraphicsLayer::setMaskLayer(layer);
371 m_needsSyncMask = true;
375 void GraphicsLayerAndroid::setMasksToBounds(bool masksToBounds)
377 if (masksToBounds == m_masksToBounds)
379 GraphicsLayer::setMasksToBounds(masksToBounds);
380 m_needsSyncMask = true;
384 void GraphicsLayerAndroid::setDrawsContent(bool drawsContent)
386 if (drawsContent == m_drawsContent)
388 GraphicsLayer::setDrawsContent(drawsContent);
389 if (m_drawsContent) {
390 m_haveContents = true;
396 void GraphicsLayerAndroid::setBackgroundColor(const Color& color)
398 if (color == m_backgroundColor)
400 LOG("(%x) setBackgroundColor", this);
401 GraphicsLayer::setBackgroundColor(color);
402 SkColor c = SkColorSetARGB(color.alpha(), color.red(), color.green(), color.blue());
403 m_contentLayer->setBackgroundColor(c);
404 m_haveContents = true;
408 void GraphicsLayerAndroid::clearBackgroundColor()
410 LOG("(%x) clearBackgroundColor", this);
411 GraphicsLayer::clearBackgroundColor();
415 void GraphicsLayerAndroid::setContentsOpaque(bool opaque)
417 if (opaque == m_contentsOpaque)
419 LOG("(%x) setContentsOpaque (%d)", this, opaque);
420 GraphicsLayer::setContentsOpaque(opaque);
421 m_haveContents = true;
425 void GraphicsLayerAndroid::setOpacity(float opacity)
427 LOG("(%x) setOpacity: %.2f", this, opacity);
428 float clampedOpacity = max(0.0f, min(opacity, 1.0f));
430 if (clampedOpacity == m_opacity)
433 MLOG("(%x) setFinalOpacity: %.2f=>%.2f (%.2f)", this,
434 opacity, clampedOpacity, m_opacity);
435 GraphicsLayer::setOpacity(clampedOpacity);
436 m_contentLayer->setOpacity(clampedOpacity);
440 void GraphicsLayerAndroid::setNeedsDisplay()
442 LOG("(%x) setNeedsDisplay()", this);
443 FloatRect rect(0, 0, m_size.width(), m_size.height());
444 setNeedsDisplayInRect(rect);
447 // Helper to set and clear the painting phase as well as auto restore the
449 class PaintingPhase {
451 PaintingPhase(GraphicsLayer* layer)
453 , m_originalPhase(layer->paintingPhase()) {}
457 m_layer->setPaintingPhase(m_originalPhase);
460 void set(GraphicsLayerPaintingPhase phase)
462 m_layer->setPaintingPhase(phase);
465 void clear(GraphicsLayerPaintingPhase phase)
467 m_layer->setPaintingPhase(
468 (GraphicsLayerPaintingPhase) (m_originalPhase & ~phase));
471 GraphicsLayer* m_layer;
472 GraphicsLayerPaintingPhase m_originalPhase;
475 void GraphicsLayerAndroid::updateScrollingLayers()
477 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
478 RenderLayer* layer = renderLayerFromClient(m_client);
479 if (!layer || !m_haveContents)
481 bool hasOverflowScroll = m_foregroundLayer || m_contentLayer->contentIsScrollable();
482 bool layerNeedsOverflow = layer->hasOverflowScroll();
483 bool iframeNeedsOverflow = layer->isRootLayer() &&
484 layer->renderer()->frame()->ownerRenderer() &&
485 layer->renderer()->frame()->view()->hasOverflowScroll();
487 if (hasOverflowScroll && (layerNeedsOverflow || iframeNeedsOverflow)) {
488 // Already has overflow layers.
491 if (!hasOverflowScroll && !layerNeedsOverflow && !iframeNeedsOverflow) {
492 // Does not need overflow layers.
495 if (layerNeedsOverflow || iframeNeedsOverflow) {
496 ASSERT(!hasOverflowScroll);
497 if (layerNeedsOverflow) {
498 ASSERT(!m_foregroundLayer && !m_foregroundClipLayer);
499 m_foregroundLayer = new ScrollableLayerAndroid(layer);
500 m_foregroundClipLayer = new LayerAndroid(layer);
501 m_foregroundClipLayer->setMasksToBounds(true);
502 m_foregroundClipLayer->addChild(m_foregroundLayer);
503 m_contentLayer->addChild(m_foregroundClipLayer);
504 m_contentLayer->setHasOverflowChildren(true);
506 ASSERT(iframeNeedsOverflow && !m_contentLayer->contentIsScrollable());
507 // No need to copy the children as they will be removed and synced.
508 m_contentLayer->removeChildren();
509 // Replace the content layer with a scrollable layer.
510 LayerAndroid* layer = new ScrollableLayerAndroid(*m_contentLayer);
511 m_contentLayer->unref();
512 m_contentLayer = layer;
514 // The content layer has changed so the parent needs to sync
516 static_cast<GraphicsLayerAndroid*>(m_parent)->m_needsSyncChildren = true;
519 // Need to rebuild our children based on the new structure.
520 m_needsSyncChildren = true;
522 ASSERT(hasOverflowScroll && !layerNeedsOverflow && !iframeNeedsOverflow);
523 ASSERT(m_contentLayer);
524 // Remove the foreground layers.
525 if (m_foregroundLayer) {
526 m_foregroundLayer->unref();
527 m_foregroundLayer = 0;
528 m_foregroundClipLayer->unref();
529 m_foregroundClipLayer = 0;
531 // No need to copy over children.
532 m_contentLayer->removeChildren();
533 LayerAndroid* layer = new LayerAndroid(*m_contentLayer);
534 m_contentLayer->unref();
535 m_contentLayer = layer;
537 // The content layer has changed so the parent needs to sync
539 static_cast<GraphicsLayerAndroid*>(m_parent)->m_needsSyncChildren = true;
541 // Children are all re-parented.
542 m_needsSyncChildren = true;
547 bool GraphicsLayerAndroid::repaint()
549 LOG("(%x) repaint(), gPaused(%d) m_needsRepaint(%d) m_haveContents(%d) ",
550 this, gPaused, m_needsRepaint, m_haveContents);
552 if (!gPaused && m_haveContents && m_needsRepaint && !m_haveImage) {
553 // with SkPicture, we request the entire layer's content.
554 IntRect layerBounds(0, 0, m_size.width(), m_size.height());
556 RenderLayer* layer = renderLayerFromClient(m_client);
559 if (m_foregroundLayer) {
560 PaintingPhase phase(this);
561 // Paint the background into a separate context.
562 phase.set(GraphicsLayerPaintBackground);
563 if (!paintContext(m_contentLayer->recordContext(), layerBounds))
566 // Construct the foreground layer and draw.
567 RenderBox* box = layer->renderBox();
568 int outline = box->view()->maximalOutlineSize();
569 IntRect contentsRect(0, 0,
570 box->borderLeft() + box->borderRight() + layer->scrollWidth(),
571 box->borderTop() + box->borderBottom() + layer->scrollHeight());
572 contentsRect.inflate(outline);
573 // Update the foreground layer size.
574 m_foregroundLayer->setSize(contentsRect.width(), contentsRect.height());
575 // Paint everything else into the main recording canvas.
576 phase.clear(GraphicsLayerPaintBackground);
579 IntSize scroll = layer->scrolledContentOffset();
580 layer->scrollToOffset(0, 0);
581 // At this point, it doesn't matter if painting failed.
582 (void) paintContext(m_foregroundLayer->recordContext(), contentsRect);
583 layer->scrollToOffset(scroll.width(), scroll.height());
585 // Construct the clip layer for masking the contents.
586 IntRect clip = layer->renderer()->absoluteBoundingBoxRect();
587 // absoluteBoundingBoxRect does not include the outline so we need
588 // to offset the position.
589 int x = box->borderLeft() + outline;
590 int y = box->borderTop() + outline;
591 int width = clip.width() - box->borderLeft() - box->borderRight();
592 int height = clip.height() - box->borderTop() - box->borderBottom();
593 m_foregroundClipLayer->setPosition(x, y);
594 m_foregroundClipLayer->setSize(width, height);
596 // Need to offset the foreground layer by the clip layer in order
597 // for the contents to be in the correct position.
598 m_foregroundLayer->setPosition(-x, -y);
599 // Set the scrollable bounds of the layer.
600 m_foregroundLayer->setScrollLimits(-x, -y, m_size.width(), m_size.height());
601 m_foregroundLayer->needsRepaint();
603 // If there is no contents clip, we can draw everything into one
605 if (!paintContext(m_contentLayer->recordContext(), layerBounds))
607 // Check for a scrollable iframe and report the scrolling
608 // limits based on the view size.
609 if (m_contentLayer->contentIsScrollable()) {
610 FrameView* view = layer->renderer()->frame()->view();
611 static_cast<ScrollableLayerAndroid*>(m_contentLayer)->setScrollLimits(
612 m_position.x(), m_position.y(), view->layoutWidth(), view->layoutHeight());
616 LOG("(%x) repaint() on (%.2f,%.2f) contentlayer(%.2f,%.2f,%.2f,%.2f)paintGraphicsLayer called!",
617 this, m_size.width(), m_size.height(),
618 m_contentLayer->getPosition().fX,
619 m_contentLayer->getPosition().fY,
620 m_contentLayer->getSize().width(),
621 m_contentLayer->getSize().height());
623 m_contentLayer->markAsDirty(m_dirtyRegion);
624 m_dirtyRegion.setEmpty();
625 m_contentLayer->needsRepaint();
626 m_needsRepaint = false;
630 if (m_needsRepaint && m_haveImage && m_newImage) {
631 // We need to tell the GL thread that we will need to repaint the
632 // texture. Only do so if we effectively have a new image!
633 m_contentLayer->needsRepaint();
635 m_needsRepaint = false;
641 bool GraphicsLayerAndroid::paintContext(SkPicture* context,
644 SkAutoPictureRecord arp(context, rect.width(), rect.height());
645 SkCanvas* canvas = arp.getRecordingCanvas();
650 PlatformGraphicsContext platformContext(canvas, 0);
651 GraphicsContext graphicsContext(&platformContext);
653 paintGraphicsLayerContents(graphicsContext, rect);
657 void GraphicsLayerAndroid::setNeedsDisplayInRect(const FloatRect& rect)
659 for (unsigned int i = 0; i < m_children.size(); i++) {
660 GraphicsLayer* layer = m_children[i];
662 FloatRect childrenRect = m_transform.mapRect(rect);
663 layer->setNeedsDisplayInRect(childrenRect);
667 if (!m_haveImage && !drawsContent()) {
668 LOG("(%x) setNeedsDisplay(%.2f,%.2f,%.2f,%.2f) doesn't have content, bypass...",
669 this, rect.x(), rect.y(), rect.width(), rect.height());
674 region.setRect(rect.x(), rect.y(),
675 rect.x() + rect.width(),
676 rect.y() + rect.height());
677 m_dirtyRegion.op(region, SkRegion::kUnion_Op);
679 m_needsRepaint = true;
683 void GraphicsLayerAndroid::pauseDisplay(bool state)
687 gPausedDelay = WTF::currentTime() + 1;
690 bool GraphicsLayerAndroid::addAnimation(const KeyframeValueList& valueList,
691 const IntSize& boxSize,
692 const Animation* anim,
693 const String& keyframesName,
696 // For now, let webkit deals with the animations -- the current UI-side
697 // animation code has some annoying bugs, and we improved communication
698 // between webkit and UI enough that performance-wise it's not so much
699 // a problem to let webkit do everything.
700 // TODO: re-enable UI-side animations
703 if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2)
706 bool createdAnimations = false;
707 if (valueList.property() == AnimatedPropertyWebkitTransform) {
708 createdAnimations = createTransformAnimationsFromKeyframes(valueList,
714 createdAnimations = createAnimationFromKeyframes(valueList,
719 if (createdAnimations)
721 return createdAnimations;
724 bool GraphicsLayerAndroid::createAnimationFromKeyframes(const KeyframeValueList& valueList,
725 const Animation* animation, const String& keyframesName, double beginTime)
727 bool isKeyframe = valueList.size() > 2;
728 TLOG("createAnimationFromKeyframes(%d), name(%s) beginTime(%.2f)",
729 isKeyframe, keyframesName.latin1().data(), beginTime);
731 switch (valueList.property()) {
732 case AnimatedPropertyInvalid: break;
733 case AnimatedPropertyWebkitTransform: break;
734 case AnimatedPropertyBackgroundColor: break;
735 case AnimatedPropertyOpacity: {
736 MLOG("ANIMATEDPROPERTYOPACITY");
738 KeyframeValueList* operationsList = new KeyframeValueList(AnimatedPropertyOpacity);
739 for (unsigned int i = 0; i < valueList.size(); i++) {
740 FloatAnimationValue* originalValue = (FloatAnimationValue*)valueList.at(i);
741 PassRefPtr<TimingFunction> timingFunction(const_cast<TimingFunction*>(originalValue->timingFunction()));
742 FloatAnimationValue* value = new FloatAnimationValue(originalValue->keyTime(),
743 originalValue->value(),
745 operationsList->insert(value);
748 RefPtr<AndroidOpacityAnimation> anim = AndroidOpacityAnimation::create(animation,
751 if (keyframesName.isEmpty())
752 anim->setName(propertyIdToString(valueList.property()));
754 anim->setName(keyframesName);
756 m_contentLayer->addAnimation(anim.release());
764 void GraphicsLayerAndroid::needsNotifyClient()
766 m_needsNotifyClient = true;
770 bool GraphicsLayerAndroid::createTransformAnimationsFromKeyframes(const KeyframeValueList& valueList,
771 const Animation* animation,
772 const String& keyframesName,
774 const IntSize& boxSize)
776 ASSERT(valueList.property() == AnimatedPropertyWebkitTransform);
777 TLOG("createTransformAnimationFromKeyframes, name(%s) beginTime(%.2f)",
778 keyframesName.latin1().data(), beginTime);
780 KeyframeValueList* operationsList = new KeyframeValueList(AnimatedPropertyWebkitTransform);
781 for (unsigned int i = 0; i < valueList.size(); i++) {
782 TransformAnimationValue* originalValue = (TransformAnimationValue*)valueList.at(i);
783 PassRefPtr<TimingFunction> timingFunction(const_cast<TimingFunction*>(originalValue->timingFunction()));
784 TransformAnimationValue* value = new TransformAnimationValue(originalValue->keyTime(),
785 originalValue->value(),
787 operationsList->insert(value);
790 RefPtr<AndroidTransformAnimation> anim = AndroidTransformAnimation::create(animation,
794 if (keyframesName.isEmpty())
795 anim->setName(propertyIdToString(valueList.property()));
797 anim->setName(keyframesName);
800 m_contentLayer->addAnimation(anim.release());
806 void GraphicsLayerAndroid::removeAnimationsForProperty(AnimatedPropertyID anID)
808 TLOG("NRO removeAnimationsForProperty(%d)", anID);
809 m_contentLayer->removeAnimationsForProperty(anID);
813 void GraphicsLayerAndroid::removeAnimationsForKeyframes(const String& keyframesName)
815 TLOG("NRO removeAnimationsForKeyframes(%s)", keyframesName.latin1().data());
816 m_contentLayer->removeAnimationsForKeyframes(keyframesName);
820 void GraphicsLayerAndroid::pauseAnimation(const String& keyframesName)
822 TLOG("NRO pauseAnimation(%s)", keyframesName.latin1().data());
825 void GraphicsLayerAndroid::suspendAnimations(double time)
827 TLOG("NRO suspendAnimations(%.2f)", time);
830 void GraphicsLayerAndroid::resumeAnimations()
832 TLOG("NRO resumeAnimations()");
835 void GraphicsLayerAndroid::setContentsToImage(Image* image)
837 TLOG("(%x) setContentsToImage", this, image);
839 m_haveContents = true;
841 // Only pass the new image if it's a different one
842 if (image->nativeImageForCurrentFrame() != m_imageRef) {
844 m_contentLayer->setContentsImage(image->nativeImageForCurrentFrame());
845 // remember the passed image.
846 m_imageRef = image->nativeImageForCurrentFrame();
853 void GraphicsLayerAndroid::setContentsToMedia(PlatformLayer* mediaLayer)
855 // Only fullscreen video on Android, so media doesn't get it's own layer.
856 // We might still have other layers though.
857 if (m_contentLayer != mediaLayer && mediaLayer) {
859 // TODO add a copy method to LayerAndroid to sync everything
860 // copy data from the original content layer to the new one
861 mediaLayer->setPosition(m_contentLayer->getPosition().fX,
862 m_contentLayer->getPosition().fY);
863 mediaLayer->setSize(m_contentLayer->getWidth(), m_contentLayer->getHeight());
864 mediaLayer->setDrawTransform(*m_contentLayer->drawTransform());
867 m_contentLayer->unref();
868 m_contentLayer = mediaLayer;
870 // If the parent exists then notify it to re-sync it's children
872 GraphicsLayerAndroid* parent = static_cast<GraphicsLayerAndroid*>(m_parent);
873 parent->m_needsSyncChildren = true;
875 m_needsSyncChildren = true;
882 PlatformLayer* GraphicsLayerAndroid::platformLayer() const
884 LOG("platformLayer");
885 return m_contentLayer;
889 void GraphicsLayerAndroid::setDebugBackgroundColor(const Color& color)
893 void GraphicsLayerAndroid::setDebugBorder(const Color& color, float borderWidth)
898 void GraphicsLayerAndroid::setZPosition(float position)
900 if (position == m_zPosition)
902 LOG("(%x) setZPosition: %.2f", this, position);
903 GraphicsLayer::setZPosition(position);
907 void GraphicsLayerAndroid::askForSync()
913 m_client->notifySyncRequired(this);
916 void GraphicsLayerAndroid::syncChildren()
918 if (m_needsSyncChildren) {
919 m_contentLayer->removeChildren();
920 LayerAndroid* layer = m_contentLayer;
921 if (m_foregroundClipLayer) {
922 m_contentLayer->addChild(m_foregroundClipLayer);
923 // Use the scrollable content layer as the parent of the children so
924 // that they move with the content.
925 layer = m_foregroundLayer;
926 layer->removeChildren();
928 for (unsigned int i = 0; i < m_children.size(); i++)
929 layer->addChild(m_children[i]->platformLayer());
930 m_needsSyncChildren = false;
934 void GraphicsLayerAndroid::syncMask()
936 if (m_needsSyncMask) {
938 LayerAndroid* mask = m_maskLayer->platformLayer();
939 m_contentLayer->setMaskLayer(mask);
941 m_contentLayer->setMaskLayer(0);
943 m_contentLayer->setMasksToBounds(m_masksToBounds);
944 m_needsSyncMask = false;
948 void GraphicsLayerAndroid::syncCompositingState()
950 for (unsigned int i = 0; i < m_children.size(); i++)
951 m_children[i]->syncCompositingState();
953 updateScrollingLayers();
954 updateFixedPosition();
958 if (!gPaused || WTF::currentTime() >= gPausedDelay)
962 void GraphicsLayerAndroid::notifyClientAnimationStarted()
964 for (unsigned int i = 0; i < m_children.size(); i++)
965 static_cast<GraphicsLayerAndroid*>(m_children[i])->notifyClientAnimationStarted();
967 if (m_needsNotifyClient) {
969 client()->notifyAnimationStarted(this, WTF::currentTime());
970 m_needsNotifyClient = false;
974 } // namespace WebCore
976 #endif // USE(ACCELERATED_COMPOSITING)