2 * Copyright (C) 2009 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #if USE(ACCELERATED_COMPOSITING)
30 #include "RenderLayerBacking.h"
32 #include "AnimationController.h"
33 #include "CanvasRenderingContext.h"
34 #include "CanvasRenderingContext2D.h"
35 #include "CSSPropertyNames.h"
36 #include "CSSStyleSelector.h"
37 #include "FrameView.h"
38 #include "GraphicsContext.h"
39 #include "GraphicsContext3D.h"
40 #include "GraphicsLayer.h"
41 #include "HTMLCanvasElement.h"
42 #include "HTMLElement.h"
43 #include "HTMLIFrameElement.h"
44 #include "HTMLMediaElement.h"
45 #include "HTMLNames.h"
46 #include "InspectorInstrumentation.h"
47 #include "KeyframeList.h"
48 #include "PluginViewBase.h"
49 #include "RenderApplet.h"
50 #include "RenderBox.h"
51 #include "RenderIFrame.h"
52 #include "RenderImage.h"
53 #include "RenderLayerCompositor.h"
54 #include "RenderEmbeddedObject.h"
55 #include "RenderVideo.h"
56 #include "RenderView.h"
58 #include "WebGLRenderingContext.h"
64 using namespace HTMLNames;
66 static bool hasBorderOutlineOrShadow(const RenderStyle*);
67 static bool hasBoxDecorationsOrBackground(const RenderObject*);
68 static bool hasBoxDecorationsOrBackgroundImage(const RenderStyle*);
69 static IntRect clipBox(RenderBox* renderer);
71 static inline bool isAcceleratedCanvas(RenderObject* renderer)
73 #if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
74 if (renderer->isCanvas()) {
75 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(renderer->node());
76 if (CanvasRenderingContext* context = canvas->renderingContext())
77 return context->isAccelerated();
80 UNUSED_PARAM(renderer);
85 RenderLayerBacking::RenderLayerBacking(RenderLayer* layer)
86 : m_owningLayer(layer)
87 , m_artificiallyInflatedBounds(false)
89 createGraphicsLayer();
92 RenderLayerBacking::~RenderLayerBacking()
94 updateClippingLayers(false, false);
95 updateForegroundLayer(false);
96 updateMaskLayer(false);
97 destroyGraphicsLayer();
100 void RenderLayerBacking::createGraphicsLayer()
102 m_graphicsLayer = GraphicsLayer::create(this);
105 m_graphicsLayer->setName(nameForLayer());
108 #if USE(ACCELERATED_COMPOSITING)
109 ASSERT(renderer() && renderer()->document() && renderer()->document()->frame());
110 if (Frame* frame = renderer()->document()->frame())
111 m_graphicsLayer->setContentsScale(frame->pageScaleFactor());
114 updateLayerOpacity(renderer()->style());
115 updateLayerTransform(renderer()->style());
118 void RenderLayerBacking::destroyGraphicsLayer()
121 m_graphicsLayer->removeFromParent();
124 m_foregroundLayer = 0;
129 void RenderLayerBacking::updateLayerOpacity(const RenderStyle* style)
131 m_graphicsLayer->setOpacity(compositingOpacity(style->opacity()));
134 void RenderLayerBacking::updateLayerTransform(const RenderStyle* style)
136 // FIXME: This could use m_owningLayer->transform(), but that currently has transform-origin
137 // baked into it, and we don't want that.
138 TransformationMatrix t;
139 if (m_owningLayer->hasTransform()) {
140 style->applyTransform(t, toRenderBox(renderer())->borderBoxRect().size(), RenderStyle::ExcludeTransformOrigin);
141 makeMatrixRenderable(t, compositor()->canRender3DTransforms());
144 m_graphicsLayer->setTransform(t);
147 static bool hasNonZeroTransformOrigin(const RenderObject* renderer)
149 RenderStyle* style = renderer->style();
150 return (style->transformOriginX().type() == Fixed && style->transformOriginX().value())
151 || (style->transformOriginY().type() == Fixed && style->transformOriginY().value());
154 static bool layerOrAncestorIsTransformed(RenderLayer* layer)
156 for (RenderLayer* curr = layer; curr; curr = curr->parent()) {
157 if (curr->hasTransform())
164 #if ENABLE(FULLSCREEN_API)
165 static bool layerOrAncestorIsFullScreen(RenderLayer* layer)
167 // Don't traverse through the render layer tree if we do not yet have a full screen renderer.
168 if (!layer->renderer()->document()->fullScreenRenderer())
171 for (RenderLayer* curr = layer; curr; curr = curr->parent()) {
172 if (curr->renderer()->isRenderFullScreen())
180 void RenderLayerBacking::updateCompositedBounds()
182 IntRect layerBounds = compositor()->calculateCompositedBounds(m_owningLayer, m_owningLayer);
184 // Clip to the size of the document or enclosing overflow-scroll layer.
185 // If this or an ancestor is transformed, we can't currently compute the correct rect to intersect with.
186 // We'd need RenderObject::convertContainerToLocalQuad(), which doesn't yet exist. If this
187 // is a fullscreen renderer, don't clip to the viewport, as the renderer will be asked to
188 // display outside of the viewport bounds.
189 if (compositor()->compositingConsultsOverlap() && !layerOrAncestorIsTransformed(m_owningLayer)
190 #if ENABLE(FULLSCREEN_API)
191 && !layerOrAncestorIsFullScreen(m_owningLayer)
194 RenderView* view = m_owningLayer->renderer()->view();
195 RenderLayer* rootLayer = view->layer();
197 // Start by clipping to the view's bounds.
198 IntRect clippingBounds = view->layoutOverflowRect();
200 if (m_owningLayer != rootLayer)
201 clippingBounds.intersect(m_owningLayer->backgroundClipRect(rootLayer, true));
205 m_owningLayer->convertToLayerCoords(rootLayer, deltaX, deltaY);
206 clippingBounds.move(-deltaX, -deltaY);
208 layerBounds.intersect(clippingBounds);
211 // If the element has a transform-origin that has fixed lengths, and the renderer has zero size,
212 // then we need to ensure that the compositing layer has non-zero size so that we can apply
213 // the transform-origin via the GraphicsLayer anchorPoint (which is expressed as a fractional value).
214 if (layerBounds.isEmpty() && hasNonZeroTransformOrigin(renderer())) {
215 layerBounds.setWidth(1);
216 layerBounds.setHeight(1);
217 m_artificiallyInflatedBounds = true;
219 m_artificiallyInflatedBounds = false;
221 setCompositedBounds(layerBounds);
224 void RenderLayerBacking::updateAfterWidgetResize()
226 if (renderer()->isRenderIFrame()) {
227 if (RenderLayerCompositor* innerCompositor = RenderLayerCompositor::iframeContentsCompositor(toRenderIFrame(renderer())))
228 innerCompositor->frameViewDidChangeSize(contentsBox().location());
232 void RenderLayerBacking::updateAfterLayout(UpdateDepth updateDepth, bool isUpdateRoot)
234 RenderLayerCompositor* layerCompositor = compositor();
235 if (!layerCompositor->compositingLayersNeedRebuild()) {
236 // Calling updateGraphicsLayerGeometry() here gives incorrect results, because the
237 // position of this layer's GraphicsLayer depends on the position of our compositing
238 // ancestor's GraphicsLayer. That cannot be determined until all the descendant
239 // RenderLayers of that ancestor have been processed via updateLayerPositions().
241 // The solution is to update compositing children of this layer here,
242 // via updateCompositingChildrenGeometry().
243 updateCompositedBounds();
244 layerCompositor->updateCompositingDescendantGeometry(m_owningLayer, m_owningLayer, updateDepth);
247 updateGraphicsLayerGeometry();
248 layerCompositor->updateRootLayerPosition();
253 bool RenderLayerBacking::updateGraphicsLayerConfiguration()
255 RenderLayerCompositor* compositor = this->compositor();
256 RenderObject* renderer = this->renderer();
258 bool layerConfigChanged = false;
259 if (updateForegroundLayer(compositor->needsContentsCompositingLayer(m_owningLayer)))
260 layerConfigChanged = true;
262 if (updateClippingLayers(compositor->clippedByAncestor(m_owningLayer), compositor->clipsCompositingDescendants(m_owningLayer)))
263 layerConfigChanged = true;
265 if (updateMaskLayer(renderer->hasMask()))
266 m_graphicsLayer->setMaskLayer(m_maskLayer.get());
268 if (m_owningLayer->hasReflection()) {
269 if (m_owningLayer->reflectionLayer()->backing()) {
270 GraphicsLayer* reflectionLayer = m_owningLayer->reflectionLayer()->backing()->graphicsLayer();
271 m_graphicsLayer->setReplicatedByLayer(reflectionLayer);
274 m_graphicsLayer->setReplicatedByLayer(0);
276 if (isDirectlyCompositedImage())
277 updateImageContents();
279 if ((renderer->isEmbeddedObject() && toRenderEmbeddedObject(renderer)->allowsAcceleratedCompositing())
280 || (renderer->isApplet() && toRenderApplet(renderer)->allowsAcceleratedCompositing())) {
281 PluginViewBase* pluginViewBase = static_cast<PluginViewBase*>(toRenderWidget(renderer)->widget());
282 m_graphicsLayer->setContentsToMedia(pluginViewBase->platformLayer());
285 else if (renderer->isVideo()) {
286 HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(renderer->node());
287 m_graphicsLayer->setContentsToMedia(mediaElement->platformLayer());
290 #if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
291 else if (isAcceleratedCanvas(renderer)) {
292 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(renderer->node());
293 if (CanvasRenderingContext* context = canvas->renderingContext())
294 m_graphicsLayer->setContentsToCanvas(context->platformLayer());
295 layerConfigChanged = true;
299 if (renderer->isRenderIFrame())
300 layerConfigChanged = RenderLayerCompositor::parentIFrameContentLayers(toRenderIFrame(renderer));
302 return layerConfigChanged;
305 static IntRect clipBox(RenderBox* renderer)
307 IntRect result = PaintInfo::infiniteRect();
308 if (renderer->hasOverflowClip())
309 result = renderer->overflowClipRect(0, 0);
311 if (renderer->hasClip())
312 result.intersect(renderer->clipRect(0, 0));
317 void RenderLayerBacking::updateGraphicsLayerGeometry()
319 // If we haven't built z-order lists yet, wait until later.
320 if (m_owningLayer->isStackingContext() && m_owningLayer->m_zOrderListsDirty)
323 // Set transform property, if it is not animating. We have to do this here because the transform
324 // is affected by the layer dimensions.
325 if (!renderer()->animation()->isRunningAcceleratedAnimationOnRenderer(renderer(), CSSPropertyWebkitTransform))
326 updateLayerTransform(renderer()->style());
328 // Set opacity, if it is not animating.
329 if (!renderer()->animation()->isRunningAcceleratedAnimationOnRenderer(renderer(), CSSPropertyOpacity))
330 updateLayerOpacity(renderer()->style());
332 RenderStyle* style = renderer()->style();
333 m_graphicsLayer->setPreserves3D(style->transformStyle3D() == TransformStyle3DPreserve3D && !renderer()->hasReflection());
334 m_graphicsLayer->setBackfaceVisibility(style->backfaceVisibility() == BackfaceVisibilityVisible);
336 RenderLayer* compAncestor = m_owningLayer->ancestorCompositingLayer();
338 // We compute everything relative to the enclosing compositing layer.
339 IntRect ancestorCompositingBounds;
341 ASSERT(compAncestor->backing());
342 ancestorCompositingBounds = compAncestor->backing()->compositedBounds();
345 IntRect localCompositingBounds = compositedBounds();
347 IntRect relativeCompositingBounds(localCompositingBounds);
348 int deltaX = 0, deltaY = 0;
349 m_owningLayer->convertToLayerCoords(compAncestor, deltaX, deltaY);
350 relativeCompositingBounds.move(deltaX, deltaY);
352 IntPoint graphicsLayerParentLocation;
353 if (compAncestor && compAncestor->backing()->hasClippingLayer()) {
354 // If the compositing ancestor has a layer to clip children, we parent in that, and therefore
355 // position relative to it.
356 IntRect clippingBox = clipBox(toRenderBox(compAncestor->renderer()));
357 graphicsLayerParentLocation = clippingBox.location();
359 graphicsLayerParentLocation = ancestorCompositingBounds.location();
361 if (compAncestor && m_ancestorClippingLayer) {
362 // Call calculateRects to get the backgroundRect which is what is used to clip the contents of this
363 // layer. Note that we call it with temporaryClipRects = true because normally when computing clip rects
364 // for a compositing layer, rootLayer is the layer itself.
365 IntRect parentClipRect = m_owningLayer->backgroundClipRect(compAncestor, true);
366 m_ancestorClippingLayer->setPosition(FloatPoint() + (parentClipRect.location() - graphicsLayerParentLocation));
367 m_ancestorClippingLayer->setSize(parentClipRect.size());
369 // backgroundRect is relative to compAncestor, so subtract deltaX/deltaY to get back to local coords.
370 IntSize rendererOffset(parentClipRect.location().x() - deltaX, parentClipRect.location().y() - deltaY);
371 m_ancestorClippingLayer->setOffsetFromRenderer(rendererOffset);
373 // The primary layer is then parented in, and positioned relative to this clipping layer.
374 graphicsLayerParentLocation = parentClipRect.location();
377 m_graphicsLayer->setPosition(FloatPoint() + (relativeCompositingBounds.location() - graphicsLayerParentLocation));
379 IntSize oldOffsetFromRenderer = m_graphicsLayer->offsetFromRenderer();
380 m_graphicsLayer->setOffsetFromRenderer(localCompositingBounds.location() - IntPoint());
381 // If the compositing layer offset changes, we need to repaint.
382 if (oldOffsetFromRenderer != m_graphicsLayer->offsetFromRenderer())
383 m_graphicsLayer->setNeedsDisplay();
385 FloatSize oldSize = m_graphicsLayer->size();
386 FloatSize newSize = relativeCompositingBounds.size();
387 if (oldSize != newSize) {
388 m_graphicsLayer->setSize(newSize);
389 // A bounds change will almost always require redisplay. Usually that redisplay
390 // will happen because of a repaint elsewhere, but not always:
391 // e.g. see RenderView::setMaximalOutlineSize()
392 m_graphicsLayer->setNeedsDisplay();
395 // If we have a layer that clips children, position it.
397 if (m_clippingLayer) {
398 clippingBox = clipBox(toRenderBox(renderer()));
399 m_clippingLayer->setPosition(FloatPoint() + (clippingBox.location() - localCompositingBounds.location()));
400 m_clippingLayer->setSize(clippingBox.size());
401 m_clippingLayer->setOffsetFromRenderer(clippingBox.location() - IntPoint());
405 if (m_maskLayer->size() != m_graphicsLayer->size()) {
406 m_maskLayer->setSize(m_graphicsLayer->size());
407 m_maskLayer->setNeedsDisplay();
409 m_maskLayer->setPosition(FloatPoint());
412 if (m_owningLayer->hasTransform()) {
413 const IntRect borderBox = toRenderBox(renderer())->borderBoxRect();
415 // Get layout bounds in the coords of compAncestor to match relativeCompositingBounds.
416 IntRect layerBounds = IntRect(deltaX, deltaY, borderBox.width(), borderBox.height());
418 // Update properties that depend on layer dimensions
419 FloatPoint3D transformOrigin = computeTransformOrigin(borderBox);
420 // Compute the anchor point, which is in the center of the renderer box unless transform-origin is set.
421 FloatPoint3D anchor(relativeCompositingBounds.width() != 0.0f ? ((layerBounds.x() - relativeCompositingBounds.x()) + transformOrigin.x()) / relativeCompositingBounds.width() : 0.5f,
422 relativeCompositingBounds.height() != 0.0f ? ((layerBounds.y() - relativeCompositingBounds.y()) + transformOrigin.y()) / relativeCompositingBounds.height() : 0.5f,
423 transformOrigin.z());
424 m_graphicsLayer->setAnchorPoint(anchor);
426 RenderStyle* style = renderer()->style();
427 if (style->hasPerspective()) {
428 TransformationMatrix t = owningLayer()->perspectiveTransform();
430 if (m_clippingLayer) {
431 m_clippingLayer->setChildrenTransform(t);
432 m_graphicsLayer->setChildrenTransform(TransformationMatrix());
435 m_graphicsLayer->setChildrenTransform(t);
438 m_clippingLayer->setChildrenTransform(TransformationMatrix());
440 m_graphicsLayer->setChildrenTransform(TransformationMatrix());
443 m_graphicsLayer->setAnchorPoint(FloatPoint3D(0.5f, 0.5f, 0));
446 if (m_foregroundLayer) {
447 FloatPoint foregroundPosition;
448 FloatSize foregroundSize = newSize;
449 IntSize foregroundOffset = m_graphicsLayer->offsetFromRenderer();
450 // If we have a clipping layer (which clips descendants), then the foreground layer is a child of it,
451 // so that it gets correctly sorted with children. In that case, position relative to the clipping layer.
452 if (m_clippingLayer) {
453 foregroundPosition = FloatPoint() + (localCompositingBounds.location() - clippingBox.location());
454 foregroundSize = FloatSize(clippingBox.size());
455 foregroundOffset = clippingBox.location() - IntPoint();
458 m_foregroundLayer->setPosition(foregroundPosition);
459 m_foregroundLayer->setSize(foregroundSize);
460 m_foregroundLayer->setOffsetFromRenderer(foregroundOffset);
463 if (m_owningLayer->reflectionLayer() && m_owningLayer->reflectionLayer()->isComposited()) {
464 RenderLayerBacking* reflectionBacking = m_owningLayer->reflectionLayer()->backing();
465 reflectionBacking->updateGraphicsLayerGeometry();
467 // The reflection layer has the bounds of m_owningLayer->reflectionLayer(),
468 // but the reflected layer is the bounds of this layer, so we need to position it appropriately.
469 FloatRect layerBounds = compositedBounds();
470 FloatRect reflectionLayerBounds = reflectionBacking->compositedBounds();
471 reflectionBacking->graphicsLayer()->setReplicatedLayerPosition(FloatPoint() + (layerBounds.location() - reflectionLayerBounds.location()));
474 m_graphicsLayer->setContentsRect(contentsBox());
475 updateDrawsContent();
476 updateAfterWidgetResize();
479 void RenderLayerBacking::updateInternalHierarchy()
481 // m_foregroundLayer has to be inserted in the correct order with child layers,
482 // so it's not inserted here.
483 if (m_ancestorClippingLayer) {
484 m_ancestorClippingLayer->removeAllChildren();
485 m_graphicsLayer->removeFromParent();
486 m_ancestorClippingLayer->addChild(m_graphicsLayer.get());
489 if (m_clippingLayer) {
490 m_clippingLayer->removeFromParent();
491 m_graphicsLayer->addChild(m_clippingLayer.get());
495 void RenderLayerBacking::updateDrawsContent()
497 m_graphicsLayer->setDrawsContent(containsPaintedContent());
500 // Return true if the layers changed.
501 bool RenderLayerBacking::updateClippingLayers(bool needsAncestorClip, bool needsDescendantClip)
503 bool layersChanged = false;
505 if (needsAncestorClip) {
506 if (!m_ancestorClippingLayer) {
507 m_ancestorClippingLayer = GraphicsLayer::create(this);
509 m_ancestorClippingLayer->setName("Ancestor clipping Layer");
511 m_ancestorClippingLayer->setMasksToBounds(true);
512 layersChanged = true;
514 } else if (m_ancestorClippingLayer) {
515 m_ancestorClippingLayer->removeFromParent();
516 m_ancestorClippingLayer = 0;
517 layersChanged = true;
520 if (needsDescendantClip) {
521 if (!m_clippingLayer) {
522 m_clippingLayer = GraphicsLayer::create(this);
524 m_clippingLayer->setName("Child clipping Layer");
526 m_clippingLayer->setMasksToBounds(true);
527 layersChanged = true;
529 } else if (m_clippingLayer) {
530 m_clippingLayer->removeFromParent();
532 layersChanged = true;
536 updateInternalHierarchy();
538 return layersChanged;
541 bool RenderLayerBacking::updateForegroundLayer(bool needsForegroundLayer)
543 bool layerChanged = false;
544 if (needsForegroundLayer) {
545 if (!m_foregroundLayer) {
546 m_foregroundLayer = GraphicsLayer::create(this);
548 m_foregroundLayer->setName(nameForLayer() + " (foreground)");
550 m_foregroundLayer->setDrawsContent(true);
551 m_foregroundLayer->setPaintingPhase(GraphicsLayerPaintForeground);
552 if (Frame* frame = renderer()->document()->frame())
553 m_foregroundLayer->setContentsScale(frame->pageScaleFactor());
556 } else if (m_foregroundLayer) {
557 m_foregroundLayer->removeFromParent();
558 m_foregroundLayer = 0;
563 m_graphicsLayer->setPaintingPhase(paintingPhaseForPrimaryLayer());
568 bool RenderLayerBacking::updateMaskLayer(bool needsMaskLayer)
570 bool layerChanged = false;
571 if (needsMaskLayer) {
573 m_maskLayer = GraphicsLayer::create(this);
575 m_maskLayer->setName("Mask");
577 m_maskLayer->setDrawsContent(true);
578 m_maskLayer->setPaintingPhase(GraphicsLayerPaintMask);
579 if (Frame* frame = renderer()->document()->frame())
580 m_maskLayer->setContentsScale(frame->pageScaleFactor());
583 } else if (m_maskLayer) {
589 m_graphicsLayer->setPaintingPhase(paintingPhaseForPrimaryLayer());
594 GraphicsLayerPaintingPhase RenderLayerBacking::paintingPhaseForPrimaryLayer() const
596 unsigned phase = GraphicsLayerPaintBackground;
597 if (!m_foregroundLayer)
598 phase |= GraphicsLayerPaintForeground;
600 phase |= GraphicsLayerPaintMask;
602 return static_cast<GraphicsLayerPaintingPhase>(phase);
605 float RenderLayerBacking::compositingOpacity(float rendererOpacity) const
607 float finalOpacity = rendererOpacity;
609 for (RenderLayer* curr = m_owningLayer->parent(); curr; curr = curr->parent()) {
610 // We only care about parents that are stacking contexts.
611 // Recall that opacity creates stacking context.
612 if (!curr->isStackingContext())
615 // If we found a compositing layer, we want to compute opacity
616 // relative to it. So we can break here.
617 if (curr->isComposited())
620 finalOpacity *= curr->renderer()->opacity();
626 static bool hasBorderOutlineOrShadow(const RenderStyle* style)
628 return style->hasBorder() || style->hasBorderRadius() || style->hasOutline() || style->hasAppearance() || style->boxShadow();
631 static bool hasBoxDecorationsOrBackground(const RenderObject* renderer)
633 return hasBorderOutlineOrShadow(renderer->style()) || renderer->hasBackground();
636 static bool hasBoxDecorationsOrBackgroundImage(const RenderStyle* style)
638 return hasBorderOutlineOrShadow(style) || style->hasBackgroundImage();
641 bool RenderLayerBacking::rendererHasBackground() const
643 // FIXME: share more code here
644 if (renderer()->node() && renderer()->node()->isDocumentNode()) {
645 RenderObject* htmlObject = renderer()->firstChild();
649 if (htmlObject->hasBackground())
652 RenderObject* bodyObject = htmlObject->firstChild();
656 return bodyObject->hasBackground();
659 return renderer()->hasBackground();
662 const Color RenderLayerBacking::rendererBackgroundColor() const
664 // FIXME: share more code here
665 if (renderer()->node() && renderer()->node()->isDocumentNode()) {
666 RenderObject* htmlObject = renderer()->firstChild();
667 if (htmlObject->hasBackground())
668 return htmlObject->style()->visitedDependentColor(CSSPropertyBackgroundColor);
670 RenderObject* bodyObject = htmlObject->firstChild();
671 return bodyObject->style()->visitedDependentColor(CSSPropertyBackgroundColor);
674 return renderer()->style()->visitedDependentColor(CSSPropertyBackgroundColor);
677 // A "simple container layer" is a RenderLayer which has no visible content to render.
678 // It may have no children, or all its children may be themselves composited.
679 // This is a useful optimization, because it allows us to avoid allocating backing store.
680 bool RenderLayerBacking::isSimpleContainerCompositingLayer() const
682 RenderObject* renderObject = renderer();
683 if (renderObject->isReplaced() || // replaced objects are not containers
684 renderObject->hasMask()) // masks require special treatment
687 RenderStyle* style = renderObject->style();
689 // Reject anything that has a border, a border-radius or outline,
690 // or any background (color or image).
691 // FIXME: we could optimize layers for simple backgrounds.
692 if (hasBoxDecorationsOrBackground(renderObject))
695 if (m_owningLayer->hasOverflowControls())
698 // If we have got this far and the renderer has no children, then we're ok.
699 if (!renderObject->firstChild())
702 if (renderObject->node() && renderObject->node()->isDocumentNode()) {
703 // Look to see if the root object has a non-simple backgound
704 RenderObject* rootObject = renderObject->document()->documentElement()->renderer();
708 style = rootObject->style();
710 // Reject anything that has a border, a border-radius or outline,
711 // or is not a simple background (no background, or solid color).
712 if (hasBoxDecorationsOrBackgroundImage(style))
715 // Now look at the body's renderer.
716 HTMLElement* body = renderObject->document()->body();
717 RenderObject* bodyObject = (body && body->hasLocalName(bodyTag)) ? body->renderer() : 0;
721 style = bodyObject->style();
723 if (hasBoxDecorationsOrBackgroundImage(style))
726 // Check to see if all the body's children are compositing layers.
727 if (hasNonCompositingDescendants())
733 // Check to see if all the renderer's children are compositing layers.
734 if (hasNonCompositingDescendants())
740 // Conservative test for having no rendered children.
741 bool RenderLayerBacking::hasNonCompositingDescendants() const
743 // Some HTML can cause whitespace text nodes to have renderers, like:
747 // so test for 0x0 RenderTexts here
748 for (RenderObject* child = renderer()->firstChild(); child; child = child->nextSibling()) {
749 if (!child->hasLayer()) {
750 if (child->isRenderInline() || !child->isBox())
753 if (toRenderBox(child)->width() > 0 || toRenderBox(child)->height() > 0)
758 if (m_owningLayer->isStackingContext()) {
759 // Use the m_hasCompositingDescendant bit to optimize?
760 if (Vector<RenderLayer*>* negZOrderList = m_owningLayer->negZOrderList()) {
761 size_t listSize = negZOrderList->size();
762 for (size_t i = 0; i < listSize; ++i) {
763 RenderLayer* curLayer = negZOrderList->at(i);
764 if (!curLayer->isComposited())
769 if (Vector<RenderLayer*>* posZOrderList = m_owningLayer->posZOrderList()) {
770 size_t listSize = posZOrderList->size();
771 for (size_t i = 0; i < listSize; ++i) {
772 RenderLayer* curLayer = posZOrderList->at(i);
773 if (!curLayer->isComposited())
779 if (Vector<RenderLayer*>* normalFlowList = m_owningLayer->normalFlowList()) {
780 size_t listSize = normalFlowList->size();
781 for (size_t i = 0; i < listSize; ++i) {
782 RenderLayer* curLayer = normalFlowList->at(i);
783 if (!curLayer->isComposited())
791 bool RenderLayerBacking::containsPaintedContent() const
793 if (isSimpleContainerCompositingLayer() || paintingGoesToWindow() || m_artificiallyInflatedBounds || m_owningLayer->isReflection())
796 if (isDirectlyCompositedImage())
799 // FIXME: we could optimize cases where the image, video or canvas is known to fill the border box entirely,
800 // and set background color on the layer in that case, instead of allocating backing store and painting.
802 if (renderer()->isVideo() && toRenderVideo(renderer())->shouldDisplayVideo())
803 return hasBoxDecorationsOrBackground(renderer());
805 #if PLATFORM(MAC) && PLATFORM(CA) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
806 #elif ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
807 if (isAcceleratedCanvas(renderer()))
808 return hasBoxDecorationsOrBackground(renderer());
814 // An image can be directly compositing if it's the sole content of the layer, and has no box decorations
815 // that require painting. Direct compositing saves backing store.
816 bool RenderLayerBacking::isDirectlyCompositedImage() const
818 RenderObject* renderObject = renderer();
820 if (!renderObject->isImage() || hasBoxDecorationsOrBackground(renderObject) || renderObject->hasClip())
823 RenderImage* imageRenderer = toRenderImage(renderObject);
824 if (CachedImage* cachedImage = imageRenderer->cachedImage()) {
825 if (cachedImage->hasImage())
826 return cachedImage->image()->isBitmapImage();
832 void RenderLayerBacking::contentChanged(RenderLayer::ContentChangeType changeType)
834 if ((changeType == RenderLayer::ImageChanged) && isDirectlyCompositedImage()) {
835 updateImageContents();
839 if ((changeType == RenderLayer::MaskImageChanged) && m_maskLayer) {
840 // The composited layer bounds relies on box->maskClipRect(), which changes
841 // when the mask image becomes available.
842 bool isUpdateRoot = true;
843 updateAfterLayout(CompositingChildren, isUpdateRoot);
846 #if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
847 if ((changeType == RenderLayer::CanvasChanged) && isAcceleratedCanvas(renderer())) {
848 m_graphicsLayer->setContentsNeedsDisplay();
854 void RenderLayerBacking::updateImageContents()
856 ASSERT(renderer()->isImage());
857 RenderImage* imageRenderer = toRenderImage(renderer());
859 CachedImage* cachedImage = imageRenderer->cachedImage();
863 Image* image = cachedImage->image();
867 // We have to wait until the image is fully loaded before setting it on the layer.
868 if (!cachedImage->isLoaded())
871 // This is a no-op if the layer doesn't have an inner layer for the image.
872 m_graphicsLayer->setContentsToImage(image);
874 // Image animation is "lazy", in that it automatically stops unless someone is drawing
875 // the image. So we have to kick the animation each time; this has the downside that the
876 // image will keep animating, even if its layer is not visible.
877 image->startAnimation();
880 FloatPoint3D RenderLayerBacking::computeTransformOrigin(const IntRect& borderBox) const
882 RenderStyle* style = renderer()->style();
885 origin.setX(style->transformOriginX().calcFloatValue(borderBox.width()));
886 origin.setY(style->transformOriginY().calcFloatValue(borderBox.height()));
887 origin.setZ(style->transformOriginZ());
892 FloatPoint RenderLayerBacking::computePerspectiveOrigin(const IntRect& borderBox) const
894 RenderStyle* style = renderer()->style();
896 float boxWidth = borderBox.width();
897 float boxHeight = borderBox.height();
900 origin.setX(style->perspectiveOriginX().calcFloatValue(boxWidth));
901 origin.setY(style->perspectiveOriginY().calcFloatValue(boxHeight));
906 // Return the offset from the top-left of this compositing layer at which the renderer's contents are painted.
907 IntSize RenderLayerBacking::contentOffsetInCompostingLayer() const
909 return IntSize(-m_compositedBounds.x(), -m_compositedBounds.y());
912 IntRect RenderLayerBacking::contentsBox() const
914 if (!renderer()->isBox())
917 IntRect contentsRect;
919 if (renderer()->isVideo()) {
920 RenderVideo* videoRenderer = toRenderVideo(renderer());
921 contentsRect = videoRenderer->videoBox();
924 contentsRect = toRenderBox(renderer())->contentBoxRect();
926 IntSize contentOffset = contentOffsetInCompostingLayer();
927 contentsRect.move(contentOffset);
931 // Map the given point from coordinates in the GraphicsLayer to RenderLayer coordinates.
932 FloatPoint RenderLayerBacking::graphicsLayerToContentsCoordinates(const GraphicsLayer* graphicsLayer, const FloatPoint& point)
934 return point + FloatSize(graphicsLayer->offsetFromRenderer());
937 // Map the given point from coordinates in the RenderLayer to GraphicsLayer coordinates.
938 FloatPoint RenderLayerBacking::contentsToGraphicsLayerCoordinates(const GraphicsLayer* graphicsLayer, const FloatPoint& point)
940 return point - FloatSize(graphicsLayer->offsetFromRenderer());
943 bool RenderLayerBacking::paintingGoesToWindow() const
945 if (m_owningLayer->isRootLayer())
946 return compositor()->rootLayerAttachment() != RenderLayerCompositor::RootLayerAttachedViaEnclosingIframe;
951 void RenderLayerBacking::setContentsNeedDisplay()
953 if (m_graphicsLayer && m_graphicsLayer->drawsContent())
954 m_graphicsLayer->setNeedsDisplay();
956 if (m_foregroundLayer && m_foregroundLayer->drawsContent())
957 m_foregroundLayer->setNeedsDisplay();
959 if (m_maskLayer && m_maskLayer->drawsContent())
960 m_maskLayer->setNeedsDisplay();
963 // r is in the coordinate space of the layer's render object
964 void RenderLayerBacking::setContentsNeedDisplayInRect(const IntRect& r)
966 if (m_graphicsLayer && m_graphicsLayer->drawsContent()) {
967 FloatPoint dirtyOrigin = contentsToGraphicsLayerCoordinates(m_graphicsLayer.get(), FloatPoint(r.x(), r.y()));
968 FloatRect dirtyRect(dirtyOrigin, r.size());
969 FloatRect bounds(FloatPoint(), m_graphicsLayer->size());
970 if (bounds.intersects(dirtyRect))
971 m_graphicsLayer->setNeedsDisplayInRect(dirtyRect);
974 if (m_foregroundLayer && m_foregroundLayer->drawsContent()) {
975 // FIXME: do incremental repaint
976 m_foregroundLayer->setNeedsDisplay();
979 if (m_maskLayer && m_maskLayer->drawsContent()) {
980 // FIXME: do incremental repaint
981 m_maskLayer->setNeedsDisplay();
985 static void setClip(GraphicsContext* p, const IntRect& paintDirtyRect, const IntRect& clipRect)
987 if (paintDirtyRect == clipRect)
993 static void restoreClip(GraphicsContext* p, const IntRect& paintDirtyRect, const IntRect& clipRect)
995 if (paintDirtyRect == clipRect)
1000 // Share this with RenderLayer::paintLayer, which would have to be educated about GraphicsLayerPaintingPhase?
1001 void RenderLayerBacking::paintIntoLayer(RenderLayer* rootLayer, GraphicsContext* context,
1002 const IntRect& paintDirtyRect, // in the coords of rootLayer
1003 PaintBehavior paintBehavior, GraphicsLayerPaintingPhase paintingPhase,
1004 RenderObject* paintingRoot)
1006 if (paintingGoesToWindow()) {
1007 ASSERT_NOT_REACHED();
1011 m_owningLayer->updateLayerListsIfNeeded();
1013 // Calculate the clip rects we should use.
1014 IntRect layerBounds, damageRect, clipRectToApply, outlineRect;
1015 m_owningLayer->calculateRects(rootLayer, paintDirtyRect, layerBounds, damageRect, clipRectToApply, outlineRect);
1017 int x = layerBounds.x(); // layerBounds is computed relative to rootLayer
1018 int y = layerBounds.y();
1019 int tx = x - m_owningLayer->renderBoxX();
1020 int ty = y - m_owningLayer->renderBoxY();
1022 // If this layer's renderer is a child of the paintingRoot, we render unconditionally, which
1023 // is done by passing a nil paintingRoot down to our renderer (as if no paintingRoot was ever set).
1024 // Else, our renderer tree may or may not contain the painting root, so we pass that root along
1025 // so it will be tested against as we decend through the renderers.
1026 RenderObject *paintingRootForRenderer = 0;
1027 if (paintingRoot && !renderer()->isDescendantOf(paintingRoot))
1028 paintingRootForRenderer = paintingRoot;
1030 bool shouldPaint = (m_owningLayer->hasVisibleContent() || m_owningLayer->hasVisibleDescendant()) && m_owningLayer->isSelfPaintingLayer();
1032 if (shouldPaint && (paintingPhase & GraphicsLayerPaintBackground)) {
1033 // Paint our background first, before painting any child layers.
1034 // Establish the clip used to paint our background.
1035 setClip(context, paintDirtyRect, damageRect);
1037 PaintInfo info(context, damageRect, PaintPhaseBlockBackground, false, paintingRootForRenderer, 0);
1038 renderer()->paint(info, tx, ty);
1040 // Our scrollbar widgets paint exactly when we tell them to, so that they work properly with
1041 // z-index. We paint after we painted the background/border, so that the scrollbars will
1042 // sit above the background/border.
1043 m_owningLayer->paintOverflowControls(context, x, y, damageRect);
1045 // Restore the clip.
1046 restoreClip(context, paintDirtyRect, damageRect);
1047 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
1048 // Paint the outline as part of the background phase in order for the
1049 // outline to not be a part of the scrollable content.
1050 if (!outlineRect.isEmpty()) {
1051 // Paint our own outline
1052 PaintInfo paintInfo(context, outlineRect, PaintPhaseSelfOutline, false, paintingRootForRenderer, 0);
1053 setClip(context, paintDirtyRect, outlineRect);
1054 renderer()->paint(paintInfo, tx, ty);
1055 restoreClip(context, paintDirtyRect, outlineRect);
1059 // Now walk the sorted list of children with negative z-indices. Only RenderLayers without compositing layers will paint.
1060 m_owningLayer->paintList(m_owningLayer->negZOrderList(), rootLayer, context, paintDirtyRect, paintBehavior, paintingRoot, 0, 0);
1063 bool forceBlackText = paintBehavior & PaintBehaviorForceBlackText;
1064 bool selectionOnly = paintBehavior & PaintBehaviorSelectionOnly;
1066 if (shouldPaint && (paintingPhase & GraphicsLayerPaintForeground)) {
1067 // Set up the clip used when painting our children.
1068 setClip(context, paintDirtyRect, clipRectToApply);
1069 PaintInfo paintInfo(context, clipRectToApply,
1070 selectionOnly ? PaintPhaseSelection : PaintPhaseChildBlockBackgrounds,
1071 forceBlackText, paintingRootForRenderer, 0);
1072 renderer()->paint(paintInfo, tx, ty);
1074 if (!selectionOnly) {
1075 paintInfo.phase = PaintPhaseFloat;
1076 renderer()->paint(paintInfo, tx, ty);
1078 paintInfo.phase = PaintPhaseForeground;
1079 renderer()->paint(paintInfo, tx, ty);
1081 paintInfo.phase = PaintPhaseChildOutlines;
1082 renderer()->paint(paintInfo, tx, ty);
1085 // Now restore our clip.
1086 restoreClip(context, paintDirtyRect, clipRectToApply);
1088 #if !ENABLE(ANDROID_OVERFLOW_SCROLL)
1089 // Do not paint the outline as part of the foreground since it will
1090 // appear inside the scrollable content.
1091 if (!outlineRect.isEmpty()) {
1092 // Paint our own outline
1093 PaintInfo paintInfo(context, outlineRect, PaintPhaseSelfOutline, false, paintingRootForRenderer, 0);
1094 setClip(context, paintDirtyRect, outlineRect);
1095 renderer()->paint(paintInfo, tx, ty);
1096 restoreClip(context, paintDirtyRect, outlineRect);
1100 // Paint any child layers that have overflow.
1101 m_owningLayer->paintList(m_owningLayer->normalFlowList(), rootLayer, context, paintDirtyRect, paintBehavior, paintingRoot, 0, 0);
1103 // Now walk the sorted list of children with positive z-indices.
1104 m_owningLayer->paintList(m_owningLayer->posZOrderList(), rootLayer, context, paintDirtyRect, paintBehavior, paintingRoot, 0, 0);
1107 if (shouldPaint && (paintingPhase & GraphicsLayerPaintMask)) {
1108 if (renderer()->hasMask() && !selectionOnly && !damageRect.isEmpty()) {
1109 setClip(context, paintDirtyRect, damageRect);
1112 PaintInfo paintInfo(context, damageRect, PaintPhaseMask, false, paintingRootForRenderer, 0);
1113 renderer()->paint(paintInfo, tx, ty);
1115 // Restore the clip.
1116 restoreClip(context, paintDirtyRect, damageRect);
1120 ASSERT(!m_owningLayer->m_usedTransparency);
1123 // Up-call from compositing layer drawing callback.
1124 void RenderLayerBacking::paintContents(const GraphicsLayer*, GraphicsContext& context, GraphicsLayerPaintingPhase paintingPhase, const IntRect& clip)
1126 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willPaint(m_owningLayer->renderer()->frame(), clip);
1128 // We have to use the same root as for hit testing, because both methods
1129 // can compute and cache clipRects.
1130 IntRect enclosingBBox = compositedBounds();
1131 #if ENABLE(ANDROID_OVERFLOW_SCROLL)
1132 // If we encounter a scrollable layer, layers inside the scrollable layer
1133 // will need their entire content recorded.
1134 if (m_owningLayer->hasOverflowParent())
1135 enclosingBBox.setSize(clip.size());
1138 IntRect clipRect(clip);
1140 // Set up the coordinate space to be in the layer's rendering coordinates.
1141 context.translate(-enclosingBBox.x(), -enclosingBBox.y());
1144 clipRect.move(enclosingBBox.x(), enclosingBBox.y());
1146 // The dirtyRect is in the coords of the painting root.
1147 IntRect dirtyRect = enclosingBBox;
1148 dirtyRect.intersect(clipRect);
1150 paintIntoLayer(m_owningLayer, &context, dirtyRect, PaintBehaviorNormal, paintingPhase, renderer());
1152 InspectorInstrumentation::didPaint(cookie);
1155 bool RenderLayerBacking::showDebugBorders() const
1157 return compositor() ? compositor()->compositorShowDebugBorders() : false;
1160 bool RenderLayerBacking::showRepaintCounter() const
1162 return compositor() ? compositor()->compositorShowRepaintCounter() : false;
1165 bool RenderLayerBacking::startAnimation(double timeOffset, const Animation* anim, const KeyframeList& keyframes)
1167 bool hasOpacity = keyframes.containsProperty(CSSPropertyOpacity);
1168 bool hasTransform = renderer()->isBox() && keyframes.containsProperty(CSSPropertyWebkitTransform);
1170 if (!hasOpacity && !hasTransform)
1173 KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
1174 KeyframeValueList opacityVector(AnimatedPropertyOpacity);
1176 size_t numKeyframes = keyframes.size();
1177 for (size_t i = 0; i < numKeyframes; ++i) {
1178 const KeyframeValue& currentKeyframe = keyframes[i];
1179 const RenderStyle* keyframeStyle = currentKeyframe.style();
1180 float key = currentKeyframe.key();
1185 // Get timing function.
1186 RefPtr<TimingFunction> tf = keyframeStyle->hasAnimations() ? (*keyframeStyle->animations()).animation(0)->timingFunction() : 0;
1188 bool isFirstOrLastKeyframe = key == 0 || key == 1;
1189 if ((hasTransform && isFirstOrLastKeyframe) || currentKeyframe.containsProperty(CSSPropertyWebkitTransform))
1190 transformVector.insert(new TransformAnimationValue(key, &(keyframeStyle->transform()), tf));
1192 if ((hasOpacity && isFirstOrLastKeyframe) || currentKeyframe.containsProperty(CSSPropertyOpacity))
1193 opacityVector.insert(new FloatAnimationValue(key, keyframeStyle->opacity(), tf));
1196 bool didAnimateTransform = false;
1197 bool didAnimateOpacity = false;
1199 if (hasTransform && m_graphicsLayer->addAnimation(transformVector, toRenderBox(renderer())->borderBoxRect().size(), anim, keyframes.animationName(), timeOffset)) {
1200 didAnimateTransform = true;
1201 compositor()->didStartAcceleratedAnimation(CSSPropertyWebkitTransform);
1204 if (hasOpacity && m_graphicsLayer->addAnimation(opacityVector, IntSize(), anim, keyframes.animationName(), timeOffset)) {
1205 didAnimateOpacity = true;
1206 compositor()->didStartAcceleratedAnimation(CSSPropertyOpacity);
1209 return didAnimateTransform || didAnimateOpacity;
1212 void RenderLayerBacking::animationPaused(double timeOffset, const String& animationName)
1214 m_graphicsLayer->pauseAnimation(animationName, timeOffset);
1217 void RenderLayerBacking::animationFinished(const String& animationName)
1219 m_graphicsLayer->removeAnimation(animationName);
1222 bool RenderLayerBacking::startTransition(double timeOffset, int property, const RenderStyle* fromStyle, const RenderStyle* toStyle)
1224 bool didAnimateOpacity = false;
1225 bool didAnimateTransform = false;
1226 ASSERT(property != cAnimateAll);
1228 if (property == (int)CSSPropertyOpacity) {
1229 const Animation* opacityAnim = toStyle->transitionForProperty(CSSPropertyOpacity);
1230 if (opacityAnim && !opacityAnim->isEmptyOrZeroDuration()) {
1231 KeyframeValueList opacityVector(AnimatedPropertyOpacity);
1232 opacityVector.insert(new FloatAnimationValue(0, compositingOpacity(fromStyle->opacity())));
1233 opacityVector.insert(new FloatAnimationValue(1, compositingOpacity(toStyle->opacity())));
1234 // The boxSize param is only used for transform animations (which can only run on RenderBoxes), so we pass an empty size here.
1235 if (m_graphicsLayer->addAnimation(opacityVector, IntSize(), opacityAnim, GraphicsLayer::animationNameForTransition(AnimatedPropertyOpacity), timeOffset)) {
1236 // To ensure that the correct opacity is visible when the animation ends, also set the final opacity.
1237 updateLayerOpacity(toStyle);
1238 didAnimateOpacity = true;
1243 if (property == (int)CSSPropertyWebkitTransform && m_owningLayer->hasTransform()) {
1244 const Animation* transformAnim = toStyle->transitionForProperty(CSSPropertyWebkitTransform);
1245 if (transformAnim && !transformAnim->isEmptyOrZeroDuration()) {
1246 KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
1247 transformVector.insert(new TransformAnimationValue(0, &fromStyle->transform()));
1248 transformVector.insert(new TransformAnimationValue(1, &toStyle->transform()));
1249 if (m_graphicsLayer->addAnimation(transformVector, toRenderBox(renderer())->borderBoxRect().size(), transformAnim, GraphicsLayer::animationNameForTransition(AnimatedPropertyWebkitTransform), timeOffset)) {
1250 // To ensure that the correct transform is visible when the animation ends, also set the final opacity.
1251 updateLayerTransform(toStyle);
1252 didAnimateTransform = true;
1257 if (didAnimateOpacity)
1258 compositor()->didStartAcceleratedAnimation(CSSPropertyOpacity);
1260 if (didAnimateTransform)
1261 compositor()->didStartAcceleratedAnimation(CSSPropertyWebkitTransform);
1263 return didAnimateOpacity || didAnimateTransform;
1266 void RenderLayerBacking::transitionPaused(double timeOffset, int property)
1268 AnimatedPropertyID animatedProperty = cssToGraphicsLayerProperty(property);
1269 if (animatedProperty != AnimatedPropertyInvalid)
1270 m_graphicsLayer->pauseAnimation(GraphicsLayer::animationNameForTransition(animatedProperty), timeOffset);
1273 void RenderLayerBacking::transitionFinished(int property)
1275 AnimatedPropertyID animatedProperty = cssToGraphicsLayerProperty(property);
1276 if (animatedProperty != AnimatedPropertyInvalid)
1277 m_graphicsLayer->removeAnimation(GraphicsLayer::animationNameForTransition(animatedProperty));
1280 void RenderLayerBacking::notifyAnimationStarted(const GraphicsLayer*, double time)
1282 renderer()->animation()->notifyAnimationStarted(renderer(), time);
1285 void RenderLayerBacking::notifySyncRequired(const GraphicsLayer*)
1287 if (!renderer()->documentBeingDestroyed())
1288 compositor()->scheduleLayerFlush();
1291 // This is used for the 'freeze' API, for testing only.
1292 void RenderLayerBacking::suspendAnimations(double time)
1294 m_graphicsLayer->suspendAnimations(time);
1297 void RenderLayerBacking::resumeAnimations()
1299 m_graphicsLayer->resumeAnimations();
1302 IntRect RenderLayerBacking::compositedBounds() const
1304 return m_compositedBounds;
1307 void RenderLayerBacking::setCompositedBounds(const IntRect& bounds)
1309 m_compositedBounds = bounds;
1312 int RenderLayerBacking::graphicsLayerToCSSProperty(AnimatedPropertyID property)
1314 int cssProperty = CSSPropertyInvalid;
1316 case AnimatedPropertyWebkitTransform:
1317 cssProperty = CSSPropertyWebkitTransform;
1319 case AnimatedPropertyOpacity:
1320 cssProperty = CSSPropertyOpacity;
1322 case AnimatedPropertyBackgroundColor:
1323 cssProperty = CSSPropertyBackgroundColor;
1325 case AnimatedPropertyInvalid:
1326 ASSERT_NOT_REACHED();
1331 AnimatedPropertyID RenderLayerBacking::cssToGraphicsLayerProperty(int cssProperty)
1333 switch (cssProperty) {
1334 case CSSPropertyWebkitTransform:
1335 return AnimatedPropertyWebkitTransform;
1336 case CSSPropertyOpacity:
1337 return AnimatedPropertyOpacity;
1338 case CSSPropertyBackgroundColor:
1339 return AnimatedPropertyBackgroundColor;
1340 // It's fine if we see other css properties here; they are just not accelerated.
1342 return AnimatedPropertyInvalid;
1346 String RenderLayerBacking::nameForLayer() const
1348 String name = renderer()->renderName();
1349 if (Node* node = renderer()->node()) {
1350 if (node->isElementNode())
1351 name += " " + static_cast<Element*>(node)->tagName();
1353 name += " \'" + static_cast<Element*>(node)->getIdAttribute() + "\'";
1356 if (m_owningLayer->isReflection())
1357 name += " (reflection)";
1363 CompositingLayerType RenderLayerBacking::compositingLayerType() const
1365 if (m_graphicsLayer->hasContentsLayer())
1366 return MediaCompositingLayer;
1368 if (m_graphicsLayer->drawsContent())
1369 return m_graphicsLayer->usingTiledLayer() ? TiledCompositingLayer : NormalCompositingLayer;
1371 return ContainerCompositingLayer;
1374 void RenderLayerBacking::updateContentsScale(float scale)
1376 if (m_graphicsLayer)
1377 m_graphicsLayer->setContentsScale(scale);
1379 if (m_foregroundLayer)
1380 m_foregroundLayer->setContentsScale(scale);
1383 m_maskLayer->setContentsScale(scale);
1386 } // namespace WebCore
1388 #endif // USE(ACCELERATED_COMPOSITING)