RenderLayerBacking.cpp [plain text]
#include "config.h"
#if USE(ACCELERATED_COMPOSITING)
#include "RenderLayerBacking.h"
#include "AnimationController.h"
#include "CanvasRenderingContext.h"
#include "CSSPropertyNames.h"
#include "Chrome.h"
#include "FontCache.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "GraphicsLayer.h"
#include "HTMLCanvasElement.h"
#include "HTMLIFrameElement.h"
#include "HTMLMediaElement.h"
#include "HTMLNames.h"
#include "InspectorInstrumentation.h"
#include "KeyframeList.h"
#include "PluginViewBase.h"
#include "RenderApplet.h"
#include "RenderIFrame.h"
#include "RenderImage.h"
#include "RenderLayerCompositor.h"
#include "RenderEmbeddedObject.h"
#include "RenderVideo.h"
#include "RenderView.h"
#include "ScrollingCoordinator.h"
#include "StyleResolver.h"
#include "TiledBacking.h"
#if ENABLE(CSS_FILTERS)
#include "FilterEffectRenderer.h"
#endif
#if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
#include "GraphicsContext3D.h"
#endif
using namespace std;
namespace WebCore {
using namespace HTMLNames;
static bool hasBoxDecorations(const RenderStyle*);
static bool hasBoxDecorationsOrBackground(const RenderObject*);
static bool hasBoxDecorationsOrBackgroundImage(const RenderStyle*);
static IntRect clipBox(RenderBox* renderer);
static inline bool isAcceleratedCanvas(RenderObject* renderer)
{
#if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
if (renderer->isCanvas()) {
HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(renderer->node());
if (CanvasRenderingContext* context = canvas->renderingContext())
return context->isAccelerated();
}
#else
UNUSED_PARAM(renderer);
#endif
return false;
}
bool RenderLayerBacking::m_creatingPrimaryGraphicsLayer = false;
RenderLayerBacking::RenderLayerBacking(RenderLayer* layer)
: m_owningLayer(layer)
, m_artificiallyInflatedBounds(false)
, m_isMainFrameRenderViewLayer(false)
, m_usingTiledCacheLayer(false)
#if ENABLE(CSS_FILTERS)
, m_canCompositeFilters(false)
#endif
{
if (renderer()->isRenderView()) {
Frame* frame = toRenderView(renderer())->frameView()->frame();
Page* page = frame ? frame->page() : 0;
if (page && frame && page->mainFrame() == frame) {
m_isMainFrameRenderViewLayer = true;
#if PLATFORM(MAC)
if (page->scrollingCoordinator())
m_usingTiledCacheLayer = true;
#endif
}
}
createPrimaryGraphicsLayer();
if (m_usingTiledCacheLayer) {
if (Page* page = renderer()->frame()->page()) {
if (TiledBacking* tiledBacking = m_graphicsLayer->tiledBacking()) {
Frame* frame = renderer()->frame();
tiledBacking->setIsInWindow(page->isOnscreen());
if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator()) {
bool shouldLimitTileCoverage = !frame->view()->canHaveScrollbars() || scrollingCoordinator->shouldUpdateScrollLayerPositionOnMainThread();
tiledBacking->setTileCoverage(shouldLimitTileCoverage ? TiledBacking::CoverageForVisibleArea : TiledBacking::CoverageForScrolling);
}
}
}
}
}
RenderLayerBacking::~RenderLayerBacking()
{
updateClippingLayers(false, false);
updateOverflowControlsLayers(false, false, false);
updateForegroundLayer(false);
updateMaskLayer(false);
destroyGraphicsLayers();
}
PassOwnPtr<GraphicsLayer> RenderLayerBacking::createGraphicsLayer(const String& name)
{
OwnPtr<GraphicsLayer> graphicsLayer = GraphicsLayer::create(this);
#ifndef NDEBUG
graphicsLayer->setName(name);
#else
UNUSED_PARAM(name);
#endif
graphicsLayer->setMaintainsPixelAlignment(compositor()->keepLayersPixelAligned());
#if PLATFORM(MAC) && USE(CA)
graphicsLayer->setAcceleratesDrawing(compositor()->acceleratedDrawingEnabled());
#endif
return graphicsLayer.release();
}
bool RenderLayerBacking::shouldUseTileCache(const GraphicsLayer*) const
{
return m_usingTiledCacheLayer && m_creatingPrimaryGraphicsLayer;
}
void RenderLayerBacking::createPrimaryGraphicsLayer()
{
String layerName;
#ifndef NDEBUG
layerName = nameForLayer();
#endif
m_creatingPrimaryGraphicsLayer = true;
m_graphicsLayer = createGraphicsLayer(layerName);
m_creatingPrimaryGraphicsLayer = false;
if (m_usingTiledCacheLayer)
m_containmentLayer = createGraphicsLayer("TileCache Flattening Layer");
if (m_isMainFrameRenderViewLayer) {
m_graphicsLayer->setContentsOpaque(true);
m_graphicsLayer->setAppliesPageScale();
}
#if PLATFORM(MAC) && USE(CA)
if (!compositor()->acceleratedDrawingEnabled() && renderer()->isCanvas()) {
HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(renderer()->node());
if (canvas->shouldAccelerate(canvas->size()))
m_graphicsLayer->setAcceleratesDrawing(true);
}
#endif
updateLayerOpacity(renderer()->style());
updateLayerTransform(renderer()->style());
#if ENABLE(CSS_FILTERS)
updateLayerFilters(renderer()->style());
#endif
}
void RenderLayerBacking::destroyGraphicsLayers()
{
if (m_graphicsLayer)
m_graphicsLayer->removeFromParent();
m_graphicsLayer = nullptr;
m_foregroundLayer = nullptr;
m_containmentLayer = nullptr;
m_maskLayer = nullptr;
}
void RenderLayerBacking::updateLayerOpacity(const RenderStyle* style)
{
m_graphicsLayer->setOpacity(compositingOpacity(style->opacity()));
}
void RenderLayerBacking::updateLayerTransform(const RenderStyle* style)
{
TransformationMatrix t;
if (m_owningLayer->hasTransform()) {
style->applyTransform(t, toRenderBox(renderer())->borderBoxRect().size(), RenderStyle::ExcludeTransformOrigin);
makeMatrixRenderable(t, compositor()->canRender3DTransforms());
}
m_graphicsLayer->setTransform(t);
}
#if ENABLE(CSS_FILTERS)
void RenderLayerBacking::updateLayerFilters(const RenderStyle* style)
{
m_canCompositeFilters = m_graphicsLayer->setFilters(style->filter());
}
#endif
static bool hasNonZeroTransformOrigin(const RenderObject* renderer)
{
RenderStyle* style = renderer->style();
return (style->transformOriginX().type() == Fixed && style->transformOriginX().value())
|| (style->transformOriginY().type() == Fixed && style->transformOriginY().value());
}
static bool layerOrAncestorIsTransformed(RenderLayer* layer)
{
for (RenderLayer* curr = layer; curr; curr = curr->parent()) {
if (curr->hasTransform())
return true;
}
return false;
}
bool RenderLayerBacking::shouldClipCompositedBounds() const
{
if (m_usingTiledCacheLayer)
return true;
if (!compositor()->compositingConsultsOverlap())
return false;
if (layerOrAncestorIsTransformed(m_owningLayer))
return false;
return true;
}
void RenderLayerBacking::updateCompositedBounds()
{
IntRect layerBounds = compositor()->calculateCompositedBounds(m_owningLayer, m_owningLayer);
if (shouldClipCompositedBounds()) {
RenderView* view = m_owningLayer->renderer()->view();
RenderLayer* rootLayer = view->layer();
LayoutRect clippingBounds = view->unscaledDocumentRect();
if (m_owningLayer != rootLayer)
clippingBounds.intersect(m_owningLayer->backgroundClipRect(rootLayer, 0, AbsoluteClipRects).rect());
LayoutPoint delta;
m_owningLayer->convertToLayerCoords(rootLayer, delta);
clippingBounds.move(-delta.x(), -delta.y());
layerBounds.intersect(pixelSnappedIntRect(clippingBounds));
}
if (layerBounds.isEmpty() && hasNonZeroTransformOrigin(renderer())) {
layerBounds.setWidth(1);
layerBounds.setHeight(1);
m_artificiallyInflatedBounds = true;
} else
m_artificiallyInflatedBounds = false;
setCompositedBounds(layerBounds);
}
void RenderLayerBacking::updateAfterWidgetResize()
{
if (renderer()->isRenderPart()) {
if (RenderLayerCompositor* innerCompositor = RenderLayerCompositor::frameContentsCompositor(toRenderPart(renderer()))) {
innerCompositor->frameViewDidChangeSize();
innerCompositor->frameViewDidChangeLocation(contentsBox().location());
}
}
}
void RenderLayerBacking::updateAfterLayout(UpdateDepth updateDepth, bool isUpdateRoot)
{
RenderLayerCompositor* layerCompositor = compositor();
if (!layerCompositor->compositingLayersNeedRebuild()) {
updateCompositedBounds();
layerCompositor->updateCompositingDescendantGeometry(m_owningLayer, m_owningLayer, updateDepth);
if (isUpdateRoot) {
updateGraphicsLayerGeometry();
layerCompositor->updateRootLayerPosition();
}
}
}
bool RenderLayerBacking::updateGraphicsLayerConfiguration()
{
RenderLayerCompositor* compositor = this->compositor();
RenderObject* renderer = this->renderer();
bool layerConfigChanged = false;
if (updateForegroundLayer(compositor->needsContentsCompositingLayer(m_owningLayer)))
layerConfigChanged = true;
if (updateClippingLayers(compositor->clippedByAncestor(m_owningLayer), compositor->clipsCompositingDescendants(m_owningLayer)))
layerConfigChanged = true;
if (updateOverflowControlsLayers(requiresHorizontalScrollbarLayer(), requiresVerticalScrollbarLayer(), requiresScrollCornerLayer()))
layerConfigChanged = true;
if (layerConfigChanged)
updateInternalHierarchy();
if (GraphicsLayer* flatteningLayer = tileCacheFlatteningLayer()) {
flatteningLayer->removeFromParent();
m_graphicsLayer->addChild(flatteningLayer);
}
if (updateMaskLayer(renderer->hasMask()))
m_graphicsLayer->setMaskLayer(m_maskLayer.get());
if (m_owningLayer->hasReflection()) {
if (m_owningLayer->reflectionLayer()->backing()) {
GraphicsLayer* reflectionLayer = m_owningLayer->reflectionLayer()->backing()->graphicsLayer();
m_graphicsLayer->setReplicatedByLayer(reflectionLayer);
}
} else
m_graphicsLayer->setReplicatedByLayer(0);
if (isDirectlyCompositedImage())
updateImageContents();
if (renderer->isEmbeddedObject() && toRenderEmbeddedObject(renderer)->allowsAcceleratedCompositing()) {
PluginViewBase* pluginViewBase = static_cast<PluginViewBase*>(toRenderWidget(renderer)->widget());
m_graphicsLayer->setContentsToMedia(pluginViewBase->platformLayer());
}
#if ENABLE(VIDEO)
else if (renderer->isVideo()) {
HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(renderer->node());
m_graphicsLayer->setContentsToMedia(mediaElement->platformLayer());
}
#endif
#if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
else if (isAcceleratedCanvas(renderer)) {
HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(renderer->node());
if (CanvasRenderingContext* context = canvas->renderingContext())
m_graphicsLayer->setContentsToCanvas(context->platformLayer());
layerConfigChanged = true;
}
#endif
#if ENABLE(FULLSCREEN_API)
else if (renderer->isRenderFullScreen()) {
updateBackgroundColor();
}
#endif
if (renderer->isRenderPart())
layerConfigChanged = RenderLayerCompositor::parentFrameContentLayers(toRenderPart(renderer));
return layerConfigChanged;
}
static IntRect clipBox(RenderBox* renderer)
{
LayoutRect result = PaintInfo::infiniteRect();
if (renderer->hasOverflowClip())
result = renderer->overflowClipRect(LayoutPoint(), 0);
if (renderer->hasClip())
result.intersect(renderer->clipRect(LayoutPoint(), 0));
return pixelSnappedIntRect(result);
}
void RenderLayerBacking::updateGraphicsLayerGeometry()
{
if (m_owningLayer->isStackingContext() && m_owningLayer->m_zOrderListsDirty)
return;
if (!renderer()->animation()->isRunningAcceleratedAnimationOnRenderer(renderer(), CSSPropertyWebkitTransform))
updateLayerTransform(renderer()->style());
if (!renderer()->animation()->isRunningAcceleratedAnimationOnRenderer(renderer(), CSSPropertyOpacity))
updateLayerOpacity(renderer()->style());
#if ENABLE(CSS_FILTERS)
updateLayerFilters(renderer()->style());
#endif
m_owningLayer->updateVisibilityStatus();
m_graphicsLayer->setContentsVisible(m_owningLayer->hasVisibleContent() || hasVisibleNonCompositingDescendantLayers());
RenderStyle* style = renderer()->style();
m_graphicsLayer->setPreserves3D(style->transformStyle3D() == TransformStyle3DPreserve3D && !renderer()->hasReflection());
m_graphicsLayer->setBackfaceVisibility(style->backfaceVisibility() == BackfaceVisibilityVisible);
RenderLayer* compAncestor = m_owningLayer->ancestorCompositingLayer();
IntRect ancestorCompositingBounds;
if (compAncestor) {
ASSERT(compAncestor->backing());
ancestorCompositingBounds = pixelSnappedIntRect(compAncestor->backing()->compositedBounds());
}
IntRect localCompositingBounds = pixelSnappedIntRect(compositedBounds());
IntRect relativeCompositingBounds(localCompositingBounds);
IntPoint delta;
m_owningLayer->convertToPixelSnappedLayerCoords(compAncestor, delta);
relativeCompositingBounds.moveBy(delta);
IntPoint graphicsLayerParentLocation;
if (compAncestor && compAncestor->backing()->hasClippingLayer()) {
IntRect clippingBox = clipBox(toRenderBox(compAncestor->renderer()));
graphicsLayerParentLocation = clippingBox.location();
} else if (compAncestor)
graphicsLayerParentLocation = ancestorCompositingBounds.location();
else
graphicsLayerParentLocation = renderer()->view()->documentRect().location();
if (compAncestor && m_ancestorClippingLayer) {
IntRect parentClipRect = pixelSnappedIntRect(m_owningLayer->backgroundClipRect(compAncestor, 0, TemporaryClipRects).rect()); ASSERT(parentClipRect != PaintInfo::infiniteRect());
m_ancestorClippingLayer->setPosition(FloatPoint() + (parentClipRect.location() - graphicsLayerParentLocation));
m_ancestorClippingLayer->setSize(parentClipRect.size());
m_ancestorClippingLayer->setOffsetFromRenderer(parentClipRect.location() - delta);
graphicsLayerParentLocation = parentClipRect.location();
}
m_graphicsLayer->setPosition(FloatPoint() + (relativeCompositingBounds.location() - graphicsLayerParentLocation));
m_graphicsLayer->setOffsetFromRenderer(localCompositingBounds.location() - IntPoint());
FloatSize oldSize = m_graphicsLayer->size();
FloatSize newSize = relativeCompositingBounds.size();
if (oldSize != newSize) {
m_graphicsLayer->setSize(newSize);
m_graphicsLayer->setNeedsDisplay();
}
IntRect clippingBox;
if (GraphicsLayer* clipLayer = clippingLayer()) {
clippingBox = clipBox(toRenderBox(renderer()));
clipLayer->setPosition(FloatPoint() + (clippingBox.location() - localCompositingBounds.location()));
clipLayer->setSize(clippingBox.size());
clipLayer->setOffsetFromRenderer(clippingBox.location() - IntPoint());
}
if (m_maskLayer) {
if (m_maskLayer->size() != m_graphicsLayer->size()) {
m_maskLayer->setSize(m_graphicsLayer->size());
m_maskLayer->setNeedsDisplay();
}
m_maskLayer->setPosition(FloatPoint());
m_maskLayer->setOffsetFromRenderer(m_graphicsLayer->offsetFromRenderer());
}
if (m_owningLayer->hasTransform()) {
const IntRect borderBox = toRenderBox(renderer())->pixelSnappedBorderBoxRect();
IntRect layerBounds = IntRect(delta, borderBox.size());
FloatPoint3D transformOrigin = computeTransformOrigin(borderBox);
FloatPoint3D anchor(relativeCompositingBounds.width() != 0.0f ? ((layerBounds.x() - relativeCompositingBounds.x()) + transformOrigin.x()) / relativeCompositingBounds.width() : 0.5f,
relativeCompositingBounds.height() != 0.0f ? ((layerBounds.y() - relativeCompositingBounds.y()) + transformOrigin.y()) / relativeCompositingBounds.height() : 0.5f,
transformOrigin.z());
m_graphicsLayer->setAnchorPoint(anchor);
RenderStyle* style = renderer()->style();
GraphicsLayer* clipLayer = clippingLayer();
if (style->hasPerspective()) {
TransformationMatrix t = owningLayer()->perspectiveTransform();
if (clipLayer) {
clipLayer->setChildrenTransform(t);
m_graphicsLayer->setChildrenTransform(TransformationMatrix());
}
else
m_graphicsLayer->setChildrenTransform(t);
} else {
if (clipLayer)
clipLayer->setChildrenTransform(TransformationMatrix());
else
m_graphicsLayer->setChildrenTransform(TransformationMatrix());
}
} else {
m_graphicsLayer->setAnchorPoint(FloatPoint3D(0.5f, 0.5f, 0));
}
if (m_foregroundLayer) {
FloatPoint foregroundPosition;
FloatSize foregroundSize = newSize;
IntSize foregroundOffset = m_graphicsLayer->offsetFromRenderer();
if (hasClippingLayer()) {
foregroundSize = FloatSize(clippingBox.size());
foregroundOffset = clippingBox.location() - IntPoint();
}
m_foregroundLayer->setPosition(foregroundPosition);
m_foregroundLayer->setSize(foregroundSize);
m_foregroundLayer->setOffsetFromRenderer(foregroundOffset);
}
if (m_owningLayer->reflectionLayer() && m_owningLayer->reflectionLayer()->isComposited()) {
RenderLayerBacking* reflectionBacking = m_owningLayer->reflectionLayer()->backing();
reflectionBacking->updateGraphicsLayerGeometry();
FloatRect layerBounds = compositedBounds();
FloatRect reflectionLayerBounds = reflectionBacking->compositedBounds();
reflectionBacking->graphicsLayer()->setReplicatedLayerPosition(FloatPoint() + (layerBounds.location() - reflectionLayerBounds.location()));
}
m_graphicsLayer->setContentsRect(contentsBox());
updateDrawsContent();
updateAfterWidgetResize();
}
void RenderLayerBacking::updateInternalHierarchy()
{
if (m_ancestorClippingLayer) {
m_ancestorClippingLayer->removeAllChildren();
m_graphicsLayer->removeFromParent();
m_ancestorClippingLayer->addChild(m_graphicsLayer.get());
}
if (m_containmentLayer) {
m_containmentLayer->removeFromParent();
m_graphicsLayer->addChild(m_containmentLayer.get());
if (m_layerForHorizontalScrollbar) {
m_layerForHorizontalScrollbar->removeFromParent();
m_graphicsLayer->addChild(m_layerForHorizontalScrollbar.get());
}
if (m_layerForVerticalScrollbar) {
m_layerForVerticalScrollbar->removeFromParent();
m_graphicsLayer->addChild(m_layerForVerticalScrollbar.get());
}
if (m_layerForScrollCorner) {
m_layerForScrollCorner->removeFromParent();
m_graphicsLayer->addChild(m_layerForScrollCorner.get());
}
}
}
void RenderLayerBacking::updateDrawsContent()
{
bool hasPaintedContent = containsPaintedContent();
m_graphicsLayer->setDrawsContent(hasPaintedContent);
if (m_foregroundLayer)
m_foregroundLayer->setDrawsContent(hasPaintedContent);
}
bool RenderLayerBacking::updateClippingLayers(bool needsAncestorClip, bool needsDescendantClip)
{
bool layersChanged = false;
if (needsAncestorClip) {
if (!m_ancestorClippingLayer) {
m_ancestorClippingLayer = createGraphicsLayer("Ancestor clipping Layer");
m_ancestorClippingLayer->setMasksToBounds(true);
layersChanged = true;
}
} else if (m_ancestorClippingLayer) {
m_ancestorClippingLayer->removeFromParent();
m_ancestorClippingLayer = nullptr;
layersChanged = true;
}
if (needsDescendantClip) {
if (!m_containmentLayer && !m_usingTiledCacheLayer) {
m_containmentLayer = createGraphicsLayer("Child clipping Layer");
m_containmentLayer->setMasksToBounds(true);
layersChanged = true;
}
} else if (hasClippingLayer()) {
m_containmentLayer->removeFromParent();
m_containmentLayer = nullptr;
layersChanged = true;
}
return layersChanged;
}
bool RenderLayerBacking::requiresHorizontalScrollbarLayer() const
{
#if !PLATFORM(CHROMIUM)
if (!m_owningLayer->hasOverlayScrollbars())
return false;
#endif
return m_owningLayer->horizontalScrollbar();
}
bool RenderLayerBacking::requiresVerticalScrollbarLayer() const
{
#if !PLATFORM(CHROMIUM)
if (!m_owningLayer->hasOverlayScrollbars())
return false;
#endif
return m_owningLayer->verticalScrollbar();
}
bool RenderLayerBacking::requiresScrollCornerLayer() const
{
#if !PLATFORM(CHROMIUM)
if (!m_owningLayer->hasOverlayScrollbars())
return false;
#endif
return !m_owningLayer->scrollCornerAndResizerRect().isEmpty();
}
bool RenderLayerBacking::updateOverflowControlsLayers(bool needsHorizontalScrollbarLayer, bool needsVerticalScrollbarLayer, bool needsScrollCornerLayer)
{
bool layersChanged = false;
if (needsHorizontalScrollbarLayer) {
if (!m_layerForHorizontalScrollbar) {
m_layerForHorizontalScrollbar = createGraphicsLayer("horizontal scrollbar");
layersChanged = true;
}
} else if (m_layerForHorizontalScrollbar) {
m_layerForHorizontalScrollbar.clear();
layersChanged = true;
}
if (needsVerticalScrollbarLayer) {
if (!m_layerForVerticalScrollbar) {
m_layerForVerticalScrollbar = createGraphicsLayer("vertical scrollbar");
layersChanged = true;
}
} else if (m_layerForVerticalScrollbar) {
m_layerForVerticalScrollbar.clear();
layersChanged = true;
}
if (needsScrollCornerLayer) {
if (!m_layerForScrollCorner) {
m_layerForScrollCorner = createGraphicsLayer("scroll corner");
layersChanged = true;
}
} else if (m_layerForScrollCorner) {
m_layerForScrollCorner.clear();
layersChanged = true;
}
return layersChanged;
}
void RenderLayerBacking::positionOverflowControlsLayers(const IntSize& offsetFromRoot)
{
IntSize offsetFromRenderer = m_graphicsLayer->offsetFromRenderer();
if (GraphicsLayer* layer = layerForHorizontalScrollbar()) {
Scrollbar* hBar = m_owningLayer->horizontalScrollbar();
if (hBar) {
layer->setPosition(hBar->frameRect().location() - offsetFromRoot - offsetFromRenderer);
layer->setSize(hBar->frameRect().size());
}
layer->setDrawsContent(hBar);
}
if (GraphicsLayer* layer = layerForVerticalScrollbar()) {
Scrollbar* vBar = m_owningLayer->verticalScrollbar();
if (vBar) {
layer->setPosition(vBar->frameRect().location() - offsetFromRoot - offsetFromRenderer);
layer->setSize(vBar->frameRect().size());
}
layer->setDrawsContent(vBar);
}
if (GraphicsLayer* layer = layerForScrollCorner()) {
const LayoutRect& scrollCornerAndResizer = m_owningLayer->scrollCornerAndResizerRect();
layer->setPosition(scrollCornerAndResizer.location() - offsetFromRenderer);
layer->setSize(scrollCornerAndResizer.size());
layer->setDrawsContent(!scrollCornerAndResizer.isEmpty());
}
}
bool RenderLayerBacking::updateForegroundLayer(bool needsForegroundLayer)
{
bool layerChanged = false;
if (needsForegroundLayer) {
if (!m_foregroundLayer) {
String layerName;
#ifndef NDEBUG
layerName = nameForLayer() + " (foreground)";
#endif
m_foregroundLayer = createGraphicsLayer(layerName);
m_foregroundLayer->setDrawsContent(true);
m_foregroundLayer->setPaintingPhase(GraphicsLayerPaintForeground);
layerChanged = true;
}
} else if (m_foregroundLayer) {
m_foregroundLayer->removeFromParent();
m_foregroundLayer = nullptr;
layerChanged = true;
}
if (layerChanged)
m_graphicsLayer->setPaintingPhase(paintingPhaseForPrimaryLayer());
return layerChanged;
}
bool RenderLayerBacking::updateMaskLayer(bool needsMaskLayer)
{
bool layerChanged = false;
if (needsMaskLayer) {
if (!m_maskLayer) {
m_maskLayer = createGraphicsLayer("Mask");
m_maskLayer->setDrawsContent(true);
m_maskLayer->setPaintingPhase(GraphicsLayerPaintMask);
layerChanged = true;
}
} else if (m_maskLayer) {
m_maskLayer = nullptr;
layerChanged = true;
}
if (layerChanged)
m_graphicsLayer->setPaintingPhase(paintingPhaseForPrimaryLayer());
return layerChanged;
}
GraphicsLayerPaintingPhase RenderLayerBacking::paintingPhaseForPrimaryLayer() const
{
unsigned phase = GraphicsLayerPaintBackground;
if (!m_foregroundLayer)
phase |= GraphicsLayerPaintForeground;
if (!m_maskLayer)
phase |= GraphicsLayerPaintMask;
return static_cast<GraphicsLayerPaintingPhase>(phase);
}
float RenderLayerBacking::compositingOpacity(float rendererOpacity) const
{
float finalOpacity = rendererOpacity;
for (RenderLayer* curr = m_owningLayer->parent(); curr; curr = curr->parent()) {
if (!curr->isStackingContext())
continue;
if (curr->isComposited())
break;
finalOpacity *= curr->renderer()->opacity();
}
return finalOpacity;
}
static bool hasBoxDecorations(const RenderStyle* style)
{
return style->hasBorder() || style->hasBorderRadius() || style->hasOutline() || style->hasAppearance() || style->boxShadow() || style->hasFilter();
}
static bool hasBoxDecorationsOrBackground(const RenderObject* renderer)
{
return hasBoxDecorations(renderer->style()) || renderer->hasBackground();
}
static bool hasBoxDecorationsOrBackgroundImage(const RenderStyle* style)
{
return hasBoxDecorations(style) || style->hasBackgroundImage();
}
Color RenderLayerBacking::rendererBackgroundColor() const
{
RenderObject* backgroundRenderer = renderer();
if (backgroundRenderer->isRoot())
backgroundRenderer = backgroundRenderer->rendererForRootBackground();
return backgroundRenderer->style()->visitedDependentColor(CSSPropertyBackgroundColor);
}
void RenderLayerBacking::updateBackgroundColor()
{
m_graphicsLayer->setContentsToBackgroundColor(rendererBackgroundColor());
}
bool RenderLayerBacking::paintsBoxDecorations() const
{
if (!m_owningLayer->hasVisibleContent())
return false;
if (hasBoxDecorationsOrBackground(renderer()))
return true;
if (m_owningLayer->hasOverflowControls())
return true;
return false;
}
bool RenderLayerBacking::paintsChildren() const
{
if (m_owningLayer->hasVisibleContent() && containsNonEmptyRenderers())
return true;
if (hasVisibleNonCompositingDescendantLayers())
return true;
return false;
}
bool RenderLayerBacking::isSimpleContainerCompositingLayer() const
{
RenderObject* renderObject = renderer();
if (renderObject->isReplaced() || renderObject->hasMask()) return false;
if (paintsBoxDecorations() || paintsChildren())
return false;
if (renderObject->node() && renderObject->node()->isDocumentNode()) {
RenderObject* rootObject = renderObject->document()->documentElement() ? renderObject->document()->documentElement()->renderer() : 0;
if (!rootObject)
return false;
RenderStyle* style = rootObject->style();
if (hasBoxDecorationsOrBackgroundImage(style))
return false;
HTMLElement* body = renderObject->document()->body();
RenderObject* bodyObject = (body && body->hasLocalName(bodyTag)) ? body->renderer() : 0;
if (!bodyObject)
return false;
style = bodyObject->style();
if (hasBoxDecorationsOrBackgroundImage(style))
return false;
}
return true;
}
bool RenderLayerBacking::containsNonEmptyRenderers() const
{
for (RenderObject* child = renderer()->firstChild(); child; child = child->nextSibling()) {
if (!child->hasLayer()) {
if (child->isRenderInline() || !child->isBox())
return true;
if (toRenderBox(child)->width() > 0 || toRenderBox(child)->height() > 0)
return true;
}
}
return false;
}
bool RenderLayerBacking::hasVisibleNonCompositingDescendantLayers() const
{
m_owningLayer->updateLayerListsIfNeeded();
#if !ASSERT_DISABLED
LayerListMutationDetector mutationChecker(m_owningLayer);
#endif
if (Vector<RenderLayer*>* normalFlowList = m_owningLayer->normalFlowList()) {
size_t listSize = normalFlowList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = normalFlowList->at(i);
if (!curLayer->isComposited() && curLayer->hasVisibleContent())
return true;
}
}
if (m_owningLayer->isStackingContext()) {
if (!m_owningLayer->hasVisibleDescendant())
return false;
if (Vector<RenderLayer*>* negZOrderList = m_owningLayer->negZOrderList()) {
size_t listSize = negZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = negZOrderList->at(i);
if (!curLayer->isComposited() && curLayer->hasVisibleContent())
return true;
}
}
if (Vector<RenderLayer*>* posZOrderList = m_owningLayer->posZOrderList()) {
size_t listSize = posZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = posZOrderList->at(i);
if (!curLayer->isComposited() && curLayer->hasVisibleContent())
return true;
}
}
}
return false;
}
bool RenderLayerBacking::containsPaintedContent() const
{
if (isSimpleContainerCompositingLayer() || paintsIntoWindow() || m_artificiallyInflatedBounds || m_owningLayer->isReflection())
return false;
if (isDirectlyCompositedImage())
return false;
#if ENABLE(VIDEO)
if (renderer()->isVideo() && toRenderVideo(renderer())->shouldDisplayVideo())
return hasBoxDecorationsOrBackground(renderer());
#endif
#if PLATFORM(MAC) && USE(CA) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
#elif ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
if (isAcceleratedCanvas(renderer()))
return hasBoxDecorationsOrBackground(renderer());
#endif
return true;
}
bool RenderLayerBacking::isDirectlyCompositedImage() const
{
RenderObject* renderObject = renderer();
if (!renderObject->isImage() || hasBoxDecorationsOrBackground(renderObject) || renderObject->hasClip())
return false;
RenderImage* imageRenderer = toRenderImage(renderObject);
if (CachedImage* cachedImage = imageRenderer->cachedImage()) {
if (cachedImage->hasImage())
return cachedImage->imageForRenderer(imageRenderer)->isBitmapImage();
}
return false;
}
void RenderLayerBacking::contentChanged(ContentChangeType changeType)
{
if ((changeType == ImageChanged) && isDirectlyCompositedImage()) {
updateImageContents();
return;
}
if ((changeType == MaskImageChanged) && m_maskLayer) {
bool isUpdateRoot = true;
updateAfterLayout(CompositingChildren, isUpdateRoot);
}
#if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
if ((changeType == CanvasChanged) && isAcceleratedCanvas(renderer())) {
m_graphicsLayer->setContentsNeedsDisplay();
return;
}
#endif
}
void RenderLayerBacking::updateImageContents()
{
ASSERT(renderer()->isImage());
RenderImage* imageRenderer = toRenderImage(renderer());
CachedImage* cachedImage = imageRenderer->cachedImage();
if (!cachedImage)
return;
Image* image = cachedImage->imageForRenderer(imageRenderer);
if (!image)
return;
if (!cachedImage->isLoaded())
return;
m_graphicsLayer->setContentsToImage(image);
updateDrawsContent();
image->startAnimation();
}
FloatPoint3D RenderLayerBacking::computeTransformOrigin(const IntRect& borderBox) const
{
RenderStyle* style = renderer()->style();
FloatPoint3D origin;
origin.setX(floatValueForLength(style->transformOriginX(), borderBox.width()));
origin.setY(floatValueForLength(style->transformOriginY(), borderBox.height()));
origin.setZ(style->transformOriginZ());
return origin;
}
FloatPoint RenderLayerBacking::computePerspectiveOrigin(const IntRect& borderBox) const
{
RenderStyle* style = renderer()->style();
float boxWidth = borderBox.width();
float boxHeight = borderBox.height();
FloatPoint origin;
origin.setX(floatValueForLength(style->perspectiveOriginX(), boxWidth));
origin.setY(floatValueForLength(style->perspectiveOriginY(), boxHeight));
return origin;
}
IntSize RenderLayerBacking::contentOffsetInCompostingLayer() const
{
return IntSize(-m_compositedBounds.x(), -m_compositedBounds.y());
}
IntRect RenderLayerBacking::contentsBox() const
{
if (!renderer()->isBox())
return IntRect();
IntRect contentsRect;
#if ENABLE(VIDEO)
if (renderer()->isVideo()) {
RenderVideo* videoRenderer = toRenderVideo(renderer());
contentsRect = videoRenderer->videoBox();
} else
#endif
contentsRect = pixelSnappedIntRect(toRenderBox(renderer())->contentBoxRect());
IntSize contentOffset = contentOffsetInCompostingLayer();
contentsRect.move(contentOffset);
return contentsRect;
}
bool RenderLayerBacking::paintsIntoWindow() const
{
if (m_usingTiledCacheLayer)
return false;
if (m_owningLayer->isRootLayer()) {
#if PLATFORM(BLACKBERRY)
if (compositor()->inForcedCompositingMode())
return false;
#endif
return compositor()->rootLayerAttachment() != RenderLayerCompositor::RootLayerAttachedViaEnclosingFrame;
}
return false;
}
void RenderLayerBacking::setContentsNeedDisplay()
{
if (m_graphicsLayer && m_graphicsLayer->drawsContent())
m_graphicsLayer->setNeedsDisplay();
if (m_foregroundLayer && m_foregroundLayer->drawsContent())
m_foregroundLayer->setNeedsDisplay();
if (m_maskLayer && m_maskLayer->drawsContent())
m_maskLayer->setNeedsDisplay();
}
void RenderLayerBacking::setContentsNeedDisplayInRect(const IntRect& r)
{
if (m_graphicsLayer && m_graphicsLayer->drawsContent()) {
IntRect layerDirtyRect = r;
layerDirtyRect.move(-m_graphicsLayer->offsetFromRenderer());
m_graphicsLayer->setNeedsDisplayInRect(layerDirtyRect);
}
if (m_foregroundLayer && m_foregroundLayer->drawsContent()) {
IntRect layerDirtyRect = r;
layerDirtyRect.move(-m_foregroundLayer->offsetFromRenderer());
m_foregroundLayer->setNeedsDisplayInRect(layerDirtyRect);
}
if (m_maskLayer && m_maskLayer->drawsContent()) {
IntRect layerDirtyRect = r;
layerDirtyRect.move(-m_maskLayer->offsetFromRenderer());
m_maskLayer->setNeedsDisplayInRect(layerDirtyRect);
}
}
void RenderLayerBacking::paintIntoLayer(RenderLayer* rootLayer, GraphicsContext* context,
const IntRect& paintDirtyRect, PaintBehavior paintBehavior, GraphicsLayerPaintingPhase paintingPhase)
{
if (paintsIntoWindow()) {
ASSERT_NOT_REACHED();
return;
}
FontCachePurgePreventer fontCachePurgePreventer;
RenderLayer::PaintLayerFlags paintFlags = 0;
if (paintingPhase & GraphicsLayerPaintBackground)
paintFlags |= RenderLayer::PaintLayerPaintingCompositingBackgroundPhase;
if (paintingPhase & GraphicsLayerPaintForeground)
paintFlags |= RenderLayer::PaintLayerPaintingCompositingForegroundPhase;
if (paintingPhase & GraphicsLayerPaintMask)
paintFlags |= RenderLayer::PaintLayerPaintingCompositingMaskPhase;
RenderLayer::LayerPaintingInfo paintingInfo(rootLayer, paintDirtyRect, paintBehavior);
m_owningLayer->paintLayerContents(context, paintingInfo, paintFlags);
if (m_owningLayer->containsDirtyOverlayScrollbars())
m_owningLayer->paintLayerContents(context, paintingInfo, paintFlags | RenderLayer::PaintLayerPaintingOverlayScrollbars);
ASSERT(!m_owningLayer->m_usedTransparency);
}
static void paintScrollbar(Scrollbar* scrollbar, GraphicsContext& context, const IntRect& clip)
{
if (!scrollbar)
return;
context.save();
const IntRect& scrollbarRect = scrollbar->frameRect();
context.translate(-scrollbarRect.x(), -scrollbarRect.y());
IntRect transformedClip = clip;
transformedClip.moveBy(scrollbarRect.location());
scrollbar->paint(&context, transformedClip);
context.restore();
}
void RenderLayerBacking::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& context, GraphicsLayerPaintingPhase paintingPhase, const IntRect& clip)
{
#ifndef NDEBUG
if (Page* page = renderer()->frame()->page())
page->setIsPainting(true);
#endif
if (graphicsLayer == m_graphicsLayer.get() || graphicsLayer == m_foregroundLayer.get() || graphicsLayer == m_maskLayer.get()) {
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willPaint(m_owningLayer->renderer()->frame(), &context, clip);
IntRect dirtyRect = compositedBounds();
dirtyRect.intersect(clip);
paintIntoLayer(m_owningLayer, &context, dirtyRect, PaintBehaviorNormal, paintingPhase);
if (m_usingTiledCacheLayer)
m_owningLayer->renderer()->frame()->view()->setLastPaintTime(currentTime());
InspectorInstrumentation::didPaint(cookie);
} else if (graphicsLayer == layerForHorizontalScrollbar()) {
paintScrollbar(m_owningLayer->horizontalScrollbar(), context, clip);
} else if (graphicsLayer == layerForVerticalScrollbar()) {
paintScrollbar(m_owningLayer->verticalScrollbar(), context, clip);
} else if (graphicsLayer == layerForScrollCorner()) {
const IntRect& scrollCornerAndResizer = m_owningLayer->scrollCornerAndResizerRect();
context.save();
context.translate(-scrollCornerAndResizer.x(), -scrollCornerAndResizer.y());
IntRect transformedClip = clip;
transformedClip.moveBy(scrollCornerAndResizer.location());
m_owningLayer->paintScrollCorner(&context, IntPoint(), transformedClip);
m_owningLayer->paintResizer(&context, IntPoint(), transformedClip);
context.restore();
}
#ifndef NDEBUG
if (Page* page = renderer()->frame()->page())
page->setIsPainting(false);
#endif
}
float RenderLayerBacking::pageScaleFactor() const
{
return compositor()->pageScaleFactor();
}
float RenderLayerBacking::deviceScaleFactor() const
{
return compositor()->deviceScaleFactor();
}
void RenderLayerBacking::didCommitChangesForLayer(const GraphicsLayer*) const
{
compositor()->didFlushChangesForLayer(m_owningLayer);
}
bool RenderLayerBacking::showDebugBorders(const GraphicsLayer*) const
{
return compositor() ? compositor()->compositorShowDebugBorders() : false;
}
bool RenderLayerBacking::showRepaintCounter(const GraphicsLayer*) const
{
return compositor() ? compositor()->compositorShowRepaintCounter() : false;
}
#ifndef NDEBUG
void RenderLayerBacking::verifyNotPainting()
{
ASSERT(!renderer()->frame()->page() || !renderer()->frame()->page()->isPainting());
}
#endif
bool RenderLayerBacking::startAnimation(double timeOffset, const Animation* anim, const KeyframeList& keyframes)
{
bool hasOpacity = keyframes.containsProperty(CSSPropertyOpacity);
bool hasTransform = renderer()->isBox() && keyframes.containsProperty(CSSPropertyWebkitTransform);
#if ENABLE(CSS_FILTERS)
bool hasFilter = keyframes.containsProperty(CSSPropertyWebkitFilter);
#else
bool hasFilter = false;
#endif
if (!hasOpacity && !hasTransform && !hasFilter)
return false;
KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
KeyframeValueList opacityVector(AnimatedPropertyOpacity);
#if ENABLE(CSS_FILTERS)
KeyframeValueList filterVector(AnimatedPropertyWebkitFilter);
#endif
size_t numKeyframes = keyframes.size();
for (size_t i = 0; i < numKeyframes; ++i) {
const KeyframeValue& currentKeyframe = keyframes[i];
const RenderStyle* keyframeStyle = currentKeyframe.style();
float key = currentKeyframe.key();
if (!keyframeStyle)
continue;
RefPtr<TimingFunction> tf = keyframeStyle->hasAnimations() ? (*keyframeStyle->animations()).animation(0)->timingFunction() : 0;
bool isFirstOrLastKeyframe = key == 0 || key == 1;
if ((hasTransform && isFirstOrLastKeyframe) || currentKeyframe.containsProperty(CSSPropertyWebkitTransform))
transformVector.insert(new TransformAnimationValue(key, &(keyframeStyle->transform()), tf));
if ((hasOpacity && isFirstOrLastKeyframe) || currentKeyframe.containsProperty(CSSPropertyOpacity))
opacityVector.insert(new FloatAnimationValue(key, keyframeStyle->opacity(), tf));
#if ENABLE(CSS_FILTERS)
if ((hasFilter && isFirstOrLastKeyframe) || currentKeyframe.containsProperty(CSSPropertyWebkitFilter))
filterVector.insert(new FilterAnimationValue(key, &(keyframeStyle->filter()), tf));
#endif
}
bool didAnimateTransform = false;
bool didAnimateOpacity = false;
#if ENABLE(CSS_FILTERS)
bool didAnimateFilter = false;
#endif
if (hasTransform && m_graphicsLayer->addAnimation(transformVector, toRenderBox(renderer())->pixelSnappedBorderBoxRect().size(), anim, keyframes.animationName(), timeOffset))
didAnimateTransform = true;
if (hasOpacity && m_graphicsLayer->addAnimation(opacityVector, IntSize(), anim, keyframes.animationName(), timeOffset))
didAnimateOpacity = true;
#if ENABLE(CSS_FILTERS)
if (hasFilter && m_graphicsLayer->addAnimation(filterVector, IntSize(), anim, keyframes.animationName(), timeOffset))
didAnimateFilter = true;
#endif
#if ENABLE(CSS_FILTERS)
return didAnimateTransform || didAnimateOpacity || didAnimateFilter;
#else
return didAnimateTransform || didAnimateOpacity;
#endif
}
void RenderLayerBacking::animationPaused(double timeOffset, const String& animationName)
{
m_graphicsLayer->pauseAnimation(animationName, timeOffset);
}
void RenderLayerBacking::animationFinished(const String& animationName)
{
m_graphicsLayer->removeAnimation(animationName);
}
bool RenderLayerBacking::startTransition(double timeOffset, CSSPropertyID property, const RenderStyle* fromStyle, const RenderStyle* toStyle)
{
bool didAnimateOpacity = false;
bool didAnimateTransform = false;
#if ENABLE(CSS_FILTERS)
bool didAnimateFilter = false;
#endif
ASSERT(property != CSSPropertyInvalid);
if (property == CSSPropertyOpacity) {
const Animation* opacityAnim = toStyle->transitionForProperty(CSSPropertyOpacity);
if (opacityAnim && !opacityAnim->isEmptyOrZeroDuration()) {
KeyframeValueList opacityVector(AnimatedPropertyOpacity);
opacityVector.insert(new FloatAnimationValue(0, compositingOpacity(fromStyle->opacity())));
opacityVector.insert(new FloatAnimationValue(1, compositingOpacity(toStyle->opacity())));
if (m_graphicsLayer->addAnimation(opacityVector, IntSize(), opacityAnim, GraphicsLayer::animationNameForTransition(AnimatedPropertyOpacity), timeOffset)) {
updateLayerOpacity(toStyle);
didAnimateOpacity = true;
}
}
}
if (property == CSSPropertyWebkitTransform && m_owningLayer->hasTransform()) {
const Animation* transformAnim = toStyle->transitionForProperty(CSSPropertyWebkitTransform);
if (transformAnim && !transformAnim->isEmptyOrZeroDuration()) {
KeyframeValueList transformVector(AnimatedPropertyWebkitTransform);
transformVector.insert(new TransformAnimationValue(0, &fromStyle->transform()));
transformVector.insert(new TransformAnimationValue(1, &toStyle->transform()));
if (m_graphicsLayer->addAnimation(transformVector, toRenderBox(renderer())->pixelSnappedBorderBoxRect().size(), transformAnim, GraphicsLayer::animationNameForTransition(AnimatedPropertyWebkitTransform), timeOffset)) {
updateLayerTransform(toStyle);
didAnimateTransform = true;
}
}
}
#if ENABLE(CSS_FILTERS)
if (property == CSSPropertyWebkitFilter && m_owningLayer->hasFilter()) {
const Animation* filterAnim = toStyle->transitionForProperty(CSSPropertyWebkitFilter);
if (filterAnim && !filterAnim->isEmptyOrZeroDuration()) {
KeyframeValueList filterVector(AnimatedPropertyWebkitFilter);
filterVector.insert(new FilterAnimationValue(0, &fromStyle->filter()));
filterVector.insert(new FilterAnimationValue(1, &toStyle->filter()));
if (m_graphicsLayer->addAnimation(filterVector, IntSize(), filterAnim, GraphicsLayer::animationNameForTransition(AnimatedPropertyWebkitFilter), timeOffset)) {
updateLayerFilters(toStyle);
didAnimateFilter = true;
}
}
}
#endif
#if ENABLE(CSS_FILTERS)
return didAnimateOpacity || didAnimateTransform || didAnimateFilter;
#else
return didAnimateOpacity || didAnimateTransform;
#endif
}
void RenderLayerBacking::transitionPaused(double timeOffset, CSSPropertyID property)
{
AnimatedPropertyID animatedProperty = cssToGraphicsLayerProperty(property);
if (animatedProperty != AnimatedPropertyInvalid)
m_graphicsLayer->pauseAnimation(GraphicsLayer::animationNameForTransition(animatedProperty), timeOffset);
}
void RenderLayerBacking::transitionFinished(CSSPropertyID property)
{
AnimatedPropertyID animatedProperty = cssToGraphicsLayerProperty(property);
if (animatedProperty != AnimatedPropertyInvalid)
m_graphicsLayer->removeAnimation(GraphicsLayer::animationNameForTransition(animatedProperty));
}
void RenderLayerBacking::notifyAnimationStarted(const GraphicsLayer*, double time)
{
renderer()->animation()->notifyAnimationStarted(renderer(), time);
}
void RenderLayerBacking::notifySyncRequired(const GraphicsLayer*)
{
if (!renderer()->documentBeingDestroyed())
compositor()->scheduleLayerFlush();
}
void RenderLayerBacking::suspendAnimations(double time)
{
m_graphicsLayer->suspendAnimations(time);
}
void RenderLayerBacking::resumeAnimations()
{
m_graphicsLayer->resumeAnimations();
}
IntRect RenderLayerBacking::compositedBounds() const
{
return m_compositedBounds;
}
void RenderLayerBacking::setCompositedBounds(const IntRect& bounds)
{
m_compositedBounds = bounds;
}
CSSPropertyID RenderLayerBacking::graphicsLayerToCSSProperty(AnimatedPropertyID property)
{
CSSPropertyID cssProperty = CSSPropertyInvalid;
switch (property) {
case AnimatedPropertyWebkitTransform:
cssProperty = CSSPropertyWebkitTransform;
break;
case AnimatedPropertyOpacity:
cssProperty = CSSPropertyOpacity;
break;
case AnimatedPropertyBackgroundColor:
cssProperty = CSSPropertyBackgroundColor;
break;
case AnimatedPropertyWebkitFilter:
#if ENABLE(CSS_FILTERS)
cssProperty = CSSPropertyWebkitFilter;
#else
ASSERT_NOT_REACHED();
#endif
break;
case AnimatedPropertyInvalid:
ASSERT_NOT_REACHED();
}
return cssProperty;
}
AnimatedPropertyID RenderLayerBacking::cssToGraphicsLayerProperty(CSSPropertyID cssProperty)
{
switch (cssProperty) {
case CSSPropertyWebkitTransform:
return AnimatedPropertyWebkitTransform;
case CSSPropertyOpacity:
return AnimatedPropertyOpacity;
case CSSPropertyBackgroundColor:
return AnimatedPropertyBackgroundColor;
#if ENABLE(CSS_FILTERS)
case CSSPropertyWebkitFilter:
return AnimatedPropertyWebkitFilter;
#endif
default:
break;
}
return AnimatedPropertyInvalid;
}
String RenderLayerBacking::nameForLayer() const
{
String name = renderer()->renderName();
if (Node* node = renderer()->node()) {
if (node->isElementNode())
name += " " + static_cast<Element*>(node)->tagName();
if (node->hasID())
name += " \'" + static_cast<Element*>(node)->getIdAttribute() + "\'";
}
if (m_owningLayer->isReflection())
name += " (reflection)";
return name;
}
CompositingLayerType RenderLayerBacking::compositingLayerType() const
{
if (m_graphicsLayer->hasContentsLayer())
return MediaCompositingLayer;
if (m_graphicsLayer->drawsContent())
return m_graphicsLayer->usingTiledLayer() ? TiledCompositingLayer : NormalCompositingLayer;
return ContainerCompositingLayer;
}
double RenderLayerBacking::backingStoreArea() const
{
double backingArea;
backingArea = m_graphicsLayer->backingStoreArea();
if (m_foregroundLayer)
backingArea += m_foregroundLayer->backingStoreArea();
if (m_maskLayer)
backingArea += m_maskLayer->backingStoreArea();
if (m_layerForHorizontalScrollbar)
backingArea += m_layerForHorizontalScrollbar->backingStoreArea();
if (m_layerForVerticalScrollbar)
backingArea += m_layerForVerticalScrollbar->backingStoreArea();
if (m_layerForScrollCorner)
backingArea += m_layerForScrollCorner->backingStoreArea();
return backingArea;
}
}
#endif // USE(ACCELERATED_COMPOSITING)