18f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian/* 28f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * Copyright (C) 2009 Apple Inc. All rights reserved. 38f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * 48f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * Redistribution and use in source and binary forms, with or without 58f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * modification, are permitted provided that the following conditions 68f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * are met: 78f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * 1. Redistributions of source code must retain the above copyright 88f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * notice, this list of conditions and the following disclaimer. 98f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * 2. Redistributions in binary form must reproduce the above copyright 108f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * notice, this list of conditions and the following disclaimer in the 118f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * documentation and/or other materials provided with the distribution. 128f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * 138f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 148f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 158f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 168f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 178f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 188f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 198f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 208f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 218f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 228f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 238f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 248f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian */ 258f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 268f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#ifndef RenderLayerBacking_h 278f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#define RenderLayerBacking_h 288f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 298f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#if USE(ACCELERATED_COMPOSITING) 308f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 318f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#include "FloatPoint.h" 328f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#include "FloatPoint3D.h" 338f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#include "GraphicsLayer.h" 348f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#include "GraphicsLayerClient.h" 358f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#include "RenderLayer.h" 368f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#include "TransformationMatrix.h" 378f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 388f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qiannamespace WebCore { 398f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 408f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qianclass KeyframeList; 418f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qianclass RenderLayerCompositor; 428f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 438f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian// RenderLayerBacking controls the compositing behavior for a single RenderLayer. 448f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian// It holds the various GraphicsLayers, and makes decisions about intra-layer rendering 458f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian// optimizations. 468f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian// 478f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian// There is one RenderLayerBacking for each RenderLayer that is composited. 488f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 498f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qianclass RenderLayerBacking : public GraphicsLayerClient { 508f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qianpublic: 518f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian RenderLayerBacking(RenderLayer*); 528f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian ~RenderLayerBacking(); 538f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 548f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian RenderLayer* owningLayer() const { return m_owningLayer; } 558f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 560bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch enum UpdateDepth { CompositingChildren, AllDescendants }; 57cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block void updateAfterLayout(UpdateDepth, bool isUpdateRoot); 588f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 598f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // Returns true if layer configuration changed. 605f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian bool updateGraphicsLayerConfiguration(); 610bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch // Update graphics layer position and bounds. 620bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch void updateGraphicsLayerGeometry(); // make private 630bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch // Update contents and clipping structure. 640bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch void updateInternalHierarchy(); // make private 658f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 66231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block GraphicsLayer* graphicsLayer() const { return m_graphicsLayer.get(); } 678f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 688f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // Layer to clip children 698f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian bool hasClippingLayer() const { return m_clippingLayer != 0; } 70231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block GraphicsLayer* clippingLayer() const { return m_clippingLayer.get(); } 718f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 728f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // Layer to get clipped by ancestor 738f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian bool hasAncestorClippingLayer() const { return m_ancestorClippingLayer != 0; } 74231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block GraphicsLayer* ancestorClippingLayer() const { return m_ancestorClippingLayer.get(); } 758f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 760bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch bool hasContentsLayer() const { return m_foregroundLayer != 0; } 77231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block GraphicsLayer* foregroundLayer() const { return m_foregroundLayer.get(); } 788f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 79231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block bool hasMaskLayer() const { return m_maskLayer != 0; } 80231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 81231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block GraphicsLayer* parentForSublayers() const { return m_clippingLayer ? m_clippingLayer.get() : m_graphicsLayer.get(); } 82231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block GraphicsLayer* childForSuperlayers() const { return m_ancestorClippingLayer ? m_ancestorClippingLayer.get() : m_graphicsLayer.get(); } 838f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 848f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // RenderLayers with backing normally short-circuit paintLayer() because 858f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // their content is rendered via callbacks from GraphicsLayer. However, the document 868f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // layer is special, because it has a GraphicsLayer to act as a container for the GraphicsLayers 878f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // for descendants, but its contents usually render into the window (in which case this returns true). 888f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // This returns false for other layers, and when the document layer actually needs to paint into its backing store 898f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // for some reason. 908f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian bool paintingGoesToWindow() const; 918f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 928f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian void setContentsNeedDisplay(); 938f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // r is in the coordinate space of the layer's render object 948f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian void setContentsNeedDisplayInRect(const IntRect& r); 958f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 968f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // Notification from the renderer that its content changed; used by RenderImage. 978f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian void rendererContentChanged(); 988f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 998f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // Interface to start, finish, suspend and resume animations and transitions 100d0825bca7fe65beaee391d30da42e937db621564Steve Block bool startAnimation(double timeOffset, const Animation* anim, const KeyframeList& keyframes); 101d0825bca7fe65beaee391d30da42e937db621564Steve Block bool startTransition(double timeOffset, int property, const RenderStyle* fromStyle, const RenderStyle* toStyle); 1020bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch void animationFinished(const String& name); 103d0825bca7fe65beaee391d30da42e937db621564Steve Block void animationPaused(double timeOffset, const String& name); 1048f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian void transitionFinished(int property); 1058f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1060bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch void suspendAnimations(double time = 0); 1078f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian void resumeAnimations(); 1088f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1090bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch IntRect compositedBounds() const; 1100bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch void setCompositedBounds(const IntRect&); 111231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block void updateCompositedBounds(); 1120bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch 1138f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian FloatPoint graphicsLayerToContentsCoordinates(const GraphicsLayer*, const FloatPoint&); 1148f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian FloatPoint contentsToGraphicsLayerCoordinates(const GraphicsLayer*, const FloatPoint&); 1158f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1168f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // GraphicsLayerClient interface 1178f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian virtual void notifyAnimationStarted(const GraphicsLayer*, double startTime); 1180bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch virtual void notifySyncRequired(const GraphicsLayer*); 1198f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1208f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& clip); 1218f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 122643ca7872b450ea4efacab6188849e5aac2ba161Steve Block virtual bool showDebugBorders() const; 123643ca7872b450ea4efacab6188849e5aac2ba161Steve Block virtual bool showRepaintCounter() const; 124643ca7872b450ea4efacab6188849e5aac2ba161Steve Block 1250bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch IntRect contentsBox() const; 1268f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1278f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qianprivate: 1288f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian void createGraphicsLayer(); 1298f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian void destroyGraphicsLayer(); 1308f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1318f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian RenderBoxModelObject* renderer() const { return m_owningLayer->renderer(); } 1328f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian RenderLayerCompositor* compositor() const { return m_owningLayer->compositor(); } 1338f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1348f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian bool updateClippingLayers(bool needsAncestorClip, bool needsDescendantClip); 1350bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch bool updateForegroundLayer(bool needsForegroundLayer); 136231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block bool updateMaskLayer(bool needsMaskLayer); 1378f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 138231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block GraphicsLayerPaintingPhase paintingPhaseForPrimaryLayer() const; 139231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 1400bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch IntSize contentOffsetInCompostingLayer() const; 1418f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // Result is transform origin in pixels. 1428f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian FloatPoint3D computeTransformOrigin(const IntRect& borderBox) const; 1438f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // Result is perspective origin in pixels. 1448f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian FloatPoint computePerspectiveOrigin(const IntRect& borderBox) const; 1458f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 146cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block void updateLayerOpacity(const RenderStyle*); 147cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block void updateLayerTransform(const RenderStyle*); 1488f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1498f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian // Return the opacity value that this layer should use for compositing. 1508f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian float compositingOpacity(float rendererOpacity) const; 1518f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 152d0825bca7fe65beaee391d30da42e937db621564Steve Block // Returns true if this compositing layer has no visible content. 1535f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian bool isSimpleContainerCompositingLayer() const; 154d0825bca7fe65beaee391d30da42e937db621564Steve Block // Returns true if this layer has content that needs to be rendered by painting into the backing store. 155d0825bca7fe65beaee391d30da42e937db621564Steve Block bool containsPaintedContent() const; 156d0825bca7fe65beaee391d30da42e937db621564Steve Block // Returns true if the RenderLayer just contains an image that we can composite directly. 157d0825bca7fe65beaee391d30da42e937db621564Steve Block bool isDirectlyCompositedImage() const; 1588f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian void updateImageContents(); 1598f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1608f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian bool rendererHasBackground() const; 1618f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian const Color& rendererBackgroundColor() const; 1628f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1638f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian bool hasNonCompositingContent() const; 1648f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1658f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian void paintIntoLayer(RenderLayer* rootLayer, GraphicsContext*, const IntRect& paintDirtyRect, 166643ca7872b450ea4efacab6188849e5aac2ba161Steve Block PaintBehavior paintBehavior, GraphicsLayerPaintingPhase, RenderObject* paintingRoot); 1678f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1688f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian static int graphicsLayerToCSSProperty(AnimatedPropertyID); 1698f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian static AnimatedPropertyID cssToGraphicsLayerProperty(int); 1708f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1718f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qianprivate: 1728f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian RenderLayer* m_owningLayer; 1738f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 174231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block OwnPtr<GraphicsLayer> m_ancestorClippingLayer; // only used if we are clipped by an ancestor which is not a stacking context 175231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block OwnPtr<GraphicsLayer> m_graphicsLayer; 176231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block OwnPtr<GraphicsLayer> m_foregroundLayer; // only used in cases where we need to draw the foreground separately 177231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block OwnPtr<GraphicsLayer> m_clippingLayer; // only used if we have clipping on a stacking context, with compositing children 178231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block OwnPtr<GraphicsLayer> m_maskLayer; // only used if we have a mask 1798f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1800bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch IntRect m_compositedBounds; 1818f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 182231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block bool m_artificiallyInflatedBounds; // bounds had to be made non-zero to make transform-origin work 1838f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian}; 1848f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1858f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian} // namespace WebCore 1868f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1878f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#endif // USE(ACCELERATED_COMPOSITING) 1888f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian 1898f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#endif // RenderLayerBacking_h 190