1 /* 2 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. 24 */ 25 26 #ifndef RenderLayerBacking_h 27 #define RenderLayerBacking_h 28 29 #if USE(ACCELERATED_COMPOSITING) 30 31 #include "FloatPoint.h" 32 #include "FloatPoint3D.h" 33 #include "GraphicsLayer.h" 34 #include "GraphicsLayerClient.h" 35 #include "RenderLayer.h" 36 #include "TransformationMatrix.h" 37 38 namespace WebCore { 39 40 class KeyframeList; 41 class RenderLayerCompositor; 42 43 // RenderLayerBacking controls the compositing behavior for a single RenderLayer. 44 // It holds the various GraphicsLayers, and makes decisions about intra-layer rendering 45 // optimizations. 46 // 47 // There is one RenderLayerBacking for each RenderLayer that is composited. 48 49 class RenderLayerBacking : public GraphicsLayerClient { 50 public: 51 RenderLayerBacking(RenderLayer*); 52 ~RenderLayerBacking(); 53 owningLayer()54 RenderLayer* owningLayer() const { return m_owningLayer; } 55 56 enum UpdateDepth { CompositingChildren, AllDescendants }; 57 void updateAfterLayout(UpdateDepth, bool isUpdateRoot); 58 59 // Returns true if layer configuration changed. 60 bool updateGraphicsLayerConfiguration(); 61 // Update graphics layer position and bounds. 62 void updateGraphicsLayerGeometry(); // make private 63 // Update contents and clipping structure. 64 void updateInternalHierarchy(); // make private 65 graphicsLayer()66 GraphicsLayer* graphicsLayer() const { return m_graphicsLayer.get(); } 67 68 // Layer to clip children hasClippingLayer()69 bool hasClippingLayer() const { return m_clippingLayer != 0; } clippingLayer()70 GraphicsLayer* clippingLayer() const { return m_clippingLayer.get(); } 71 72 // Layer to get clipped by ancestor hasAncestorClippingLayer()73 bool hasAncestorClippingLayer() const { return m_ancestorClippingLayer != 0; } ancestorClippingLayer()74 GraphicsLayer* ancestorClippingLayer() const { return m_ancestorClippingLayer.get(); } 75 hasContentsLayer()76 bool hasContentsLayer() const { return m_foregroundLayer != 0; } foregroundLayer()77 GraphicsLayer* foregroundLayer() const { return m_foregroundLayer.get(); } 78 hasMaskLayer()79 bool hasMaskLayer() const { return m_maskLayer != 0; } 80 parentForSublayers()81 GraphicsLayer* parentForSublayers() const { return m_clippingLayer ? m_clippingLayer.get() : m_graphicsLayer.get(); } childForSuperlayers()82 GraphicsLayer* childForSuperlayers() const { return m_ancestorClippingLayer ? m_ancestorClippingLayer.get() : m_graphicsLayer.get(); } 83 84 // RenderLayers with backing normally short-circuit paintLayer() because 85 // their content is rendered via callbacks from GraphicsLayer. However, the document 86 // layer is special, because it has a GraphicsLayer to act as a container for the GraphicsLayers 87 // for descendants, but its contents usually render into the window (in which case this returns true). 88 // This returns false for other layers, and when the document layer actually needs to paint into its backing store 89 // for some reason. 90 bool paintingGoesToWindow() const; 91 92 void setContentsNeedDisplay(); 93 // r is in the coordinate space of the layer's render object 94 void setContentsNeedDisplayInRect(const IntRect& r); 95 96 // Notification from the renderer that its content changed; used by RenderImage. 97 void rendererContentChanged(); 98 99 // Interface to start, finish, suspend and resume animations and transitions 100 bool startAnimation(double timeOffset, const Animation* anim, const KeyframeList& keyframes); 101 bool startTransition(double timeOffset, int property, const RenderStyle* fromStyle, const RenderStyle* toStyle); 102 void animationFinished(const String& name); 103 void animationPaused(double timeOffset, const String& name); 104 void transitionFinished(int property); 105 106 void suspendAnimations(double time = 0); 107 void resumeAnimations(); 108 109 IntRect compositedBounds() const; 110 void setCompositedBounds(const IntRect&); 111 void updateCompositedBounds(); 112 113 FloatPoint graphicsLayerToContentsCoordinates(const GraphicsLayer*, const FloatPoint&); 114 FloatPoint contentsToGraphicsLayerCoordinates(const GraphicsLayer*, const FloatPoint&); 115 116 // GraphicsLayerClient interface 117 virtual void notifyAnimationStarted(const GraphicsLayer*, double startTime); 118 virtual void notifySyncRequired(const GraphicsLayer*); 119 120 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& clip); 121 122 virtual bool showDebugBorders() const; 123 virtual bool showRepaintCounter() const; 124 125 IntRect contentsBox() const; 126 127 private: 128 void createGraphicsLayer(); 129 void destroyGraphicsLayer(); 130 renderer()131 RenderBoxModelObject* renderer() const { return m_owningLayer->renderer(); } compositor()132 RenderLayerCompositor* compositor() const { return m_owningLayer->compositor(); } 133 134 bool updateClippingLayers(bool needsAncestorClip, bool needsDescendantClip); 135 bool updateForegroundLayer(bool needsForegroundLayer); 136 bool updateMaskLayer(bool needsMaskLayer); 137 138 GraphicsLayerPaintingPhase paintingPhaseForPrimaryLayer() const; 139 140 IntSize contentOffsetInCompostingLayer() const; 141 // Result is transform origin in pixels. 142 FloatPoint3D computeTransformOrigin(const IntRect& borderBox) const; 143 // Result is perspective origin in pixels. 144 FloatPoint computePerspectiveOrigin(const IntRect& borderBox) const; 145 146 void updateLayerOpacity(const RenderStyle*); 147 void updateLayerTransform(const RenderStyle*); 148 149 // Return the opacity value that this layer should use for compositing. 150 float compositingOpacity(float rendererOpacity) const; 151 152 // Returns true if this compositing layer has no visible content. 153 bool isSimpleContainerCompositingLayer() const; 154 // Returns true if this layer has content that needs to be rendered by painting into the backing store. 155 bool containsPaintedContent() const; 156 // Returns true if the RenderLayer just contains an image that we can composite directly. 157 bool isDirectlyCompositedImage() const; 158 void updateImageContents(); 159 160 bool rendererHasBackground() const; 161 const Color& rendererBackgroundColor() const; 162 163 bool hasNonCompositingContent() const; 164 165 void paintIntoLayer(RenderLayer* rootLayer, GraphicsContext*, const IntRect& paintDirtyRect, 166 PaintBehavior paintBehavior, GraphicsLayerPaintingPhase, RenderObject* paintingRoot); 167 168 static int graphicsLayerToCSSProperty(AnimatedPropertyID); 169 static AnimatedPropertyID cssToGraphicsLayerProperty(int); 170 171 private: 172 RenderLayer* m_owningLayer; 173 174 OwnPtr<GraphicsLayer> m_ancestorClippingLayer; // only used if we are clipped by an ancestor which is not a stacking context 175 OwnPtr<GraphicsLayer> m_graphicsLayer; 176 OwnPtr<GraphicsLayer> m_foregroundLayer; // only used in cases where we need to draw the foreground separately 177 OwnPtr<GraphicsLayer> m_clippingLayer; // only used if we have clipping on a stacking context, with compositing children 178 OwnPtr<GraphicsLayer> m_maskLayer; // only used if we have a mask 179 180 IntRect m_compositedBounds; 181 182 bool m_artificiallyInflatedBounds; // bounds had to be made non-zero to make transform-origin work 183 }; 184 185 } // namespace WebCore 186 187 #endif // USE(ACCELERATED_COMPOSITING) 188 189 #endif // RenderLayerBacking_h 190