• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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);
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; }
67 
68     // Layer to clip children
hasClippingLayer()69     bool hasClippingLayer() const { return m_clippingLayer != 0; }
clippingLayer()70     GraphicsLayer* clippingLayer() const { return m_clippingLayer; }
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; }
75 
hasContentsLayer()76     bool hasContentsLayer() const { return m_foregroundLayer != 0; }
foregroundLayer()77     GraphicsLayer* foregroundLayer() const { return m_foregroundLayer; }
78 
parentForSublayers()79     GraphicsLayer* parentForSublayers() const { return m_clippingLayer ? m_clippingLayer : m_graphicsLayer; }
childForSuperlayers()80     GraphicsLayer* childForSuperlayers() const { return m_ancestorClippingLayer ? m_ancestorClippingLayer : m_graphicsLayer; }
81 
82     // RenderLayers with backing normally short-circuit paintLayer() because
83     // their content is rendered via callbacks from GraphicsLayer. However, the document
84     // layer is special, because it has a GraphicsLayer to act as a container for the GraphicsLayers
85     // for descendants, but its contents usually render into the window (in which case this returns true).
86     // This returns false for other layers, and when the document layer actually needs to paint into its backing store
87     // for some reason.
88     bool paintingGoesToWindow() const;
89 
90     void setContentsNeedDisplay();
91     // r is in the coordinate space of the layer's render object
92     void setContentsNeedDisplayInRect(const IntRect& r);
93 
94     // Notification from the renderer that its content changed; used by RenderImage.
95     void rendererContentChanged();
96 
97     // Interface to start, finish, suspend and resume animations and transitions
98     bool startAnimation(double beginTime, const Animation* anim, const KeyframeList& keyframes);
99     bool startTransition(double beginTime, int property, const RenderStyle* fromStyle, const RenderStyle* toStyle);
100     void animationFinished(const String& name);
101     void animationPaused(const String& name);
102     void transitionFinished(int property);
103 
104     void suspendAnimations(double time = 0);
105     void resumeAnimations();
106 
107     IntRect compositedBounds() const;
108     void setCompositedBounds(const IntRect&);
109 
110     FloatPoint graphicsLayerToContentsCoordinates(const GraphicsLayer*, const FloatPoint&);
111     FloatPoint contentsToGraphicsLayerCoordinates(const GraphicsLayer*, const FloatPoint&);
112 
113     // GraphicsLayerClient interface
114     virtual void notifyAnimationStarted(const GraphicsLayer*, double startTime);
115     virtual void notifySyncRequired(const GraphicsLayer*);
116 
117     virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& clip);
118 
119     IntRect contentsBox() const;
120 
121 private:
122     void createGraphicsLayer();
123     void destroyGraphicsLayer();
124 
renderer()125     RenderBoxModelObject* renderer() const { return m_owningLayer->renderer(); }
compositor()126     RenderLayerCompositor* compositor() const { return m_owningLayer->compositor(); }
127 
128     bool updateClippingLayers(bool needsAncestorClip, bool needsDescendantClip);
129     bool updateForegroundLayer(bool needsForegroundLayer);
130 
131     IntSize contentOffsetInCompostingLayer() const;
132     // Result is transform origin in pixels.
133     FloatPoint3D computeTransformOrigin(const IntRect& borderBox) const;
134     // Result is perspective origin in pixels.
135     FloatPoint computePerspectiveOrigin(const IntRect& borderBox) const;
136 
137     void updateLayerOpacity();
138     void updateLayerTransform();
139 
140     // Return the opacity value that this layer should use for compositing.
141     float compositingOpacity(float rendererOpacity) const;
142 
143     // Returns true if this RenderLayer only has content that can be rendered directly
144     // by the compositing layer, without drawing (e.g. solid background color).
145     bool isSimpleContainerCompositingLayer() const;
146     // Returns true if we can optimize the RenderLayer to draw the replaced content
147     // directly into a compositing buffer
148     bool canUseDirectCompositing() const;
149     void updateImageContents();
150 
151     bool rendererHasBackground() const;
152     const Color& rendererBackgroundColor() const;
153 
154     bool hasNonCompositingContent() const;
155 
156     void paintIntoLayer(RenderLayer* rootLayer, GraphicsContext*, const IntRect& paintDirtyRect,
157                     PaintRestriction paintRestriction, GraphicsLayerPaintingPhase, RenderObject* paintingRoot);
158 
159     static int graphicsLayerToCSSProperty(AnimatedPropertyID);
160     static AnimatedPropertyID cssToGraphicsLayerProperty(int);
161 
162 private:
163     RenderLayer* m_owningLayer;
164 
165     GraphicsLayer* m_ancestorClippingLayer; // only used if we are clipped by an ancestor which is not a stacking context
166     GraphicsLayer* m_graphicsLayer;
167     GraphicsLayer* m_foregroundLayer;       // only used in cases where we need to draw the foreground separately
168     GraphicsLayer* m_clippingLayer;         // only used if we have clipping on a stacking context, with compositing children
169 
170     IntRect m_compositedBounds;
171 
172     bool m_hasDirectlyCompositedContent;
173 };
174 
175 } // namespace WebCore
176 
177 #endif // USE(ACCELERATED_COMPOSITING)
178 
179 #endif // RenderLayerBacking_h
180