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.
26 #ifndef RenderLayerBacking_h
27 #define RenderLayerBacking_h
29 #if USE(ACCELERATED_COMPOSITING)
31 #include "FloatPoint.h"
32 #include "FloatPoint3D.h"
33 #include "GraphicsLayer.h"
34 #include "GraphicsLayerClient.h"
35 #include "RenderLayer.h"
36 #include "TransformationMatrix.h"
41 class RenderLayerCompositor
;
43 // RenderLayerBacking controls the compositing behavior for a single RenderLayer.
44 // It holds the various GraphicsLayers, and makes decisions about intra-layer rendering
47 // There is one RenderLayerBacking for each RenderLayer that is composited.
49 class RenderLayerBacking
: public GraphicsLayerClient
{
51 RenderLayerBacking(RenderLayer
*);
52 ~RenderLayerBacking();
54 RenderLayer
* owningLayer() const { return m_owningLayer
; }
56 void updateAfterLayout();
58 // Returns true if layer configuration changed.
59 bool updateGraphicsLayerConfiguration();
60 void updateGraphicsLayerGeometry();
61 void updateInternalHierarchy();
63 GraphicsLayer
* graphicsLayer() const { return m_graphicsLayer
; }
65 // Layer to clip children
66 bool hasClippingLayer() const { return m_clippingLayer
!= 0; }
67 GraphicsLayer
* clippingLayer() const { return m_clippingLayer
; }
69 // Layer to get clipped by ancestor
70 bool hasAncestorClippingLayer() const { return m_ancestorClippingLayer
!= 0; }
71 GraphicsLayer
* ancestorClippingLayer() const { return m_ancestorClippingLayer
; }
73 bool hasContentsLayer() const { return m_contentsLayer
!= 0; }
74 GraphicsLayer
* contentsLayer() const { return m_contentsLayer
; }
76 GraphicsLayer
* parentForSublayers() const { return m_clippingLayer
? m_clippingLayer
: m_graphicsLayer
; }
77 GraphicsLayer
* childForSuperlayers() const { return m_ancestorClippingLayer
? m_ancestorClippingLayer
: m_graphicsLayer
; }
79 // RenderLayers with backing normally short-circuit paintLayer() because
80 // their content is rendered via callbacks from GraphicsLayer. However, the document
81 // layer is special, because it has a GraphicsLayer to act as a container for the GraphicsLayers
82 // for descendants, but its contents usually render into the window (in which case this returns true).
83 // This returns false for other layers, and when the document layer actually needs to paint into its backing store
85 bool paintingGoesToWindow() const;
87 void setContentsNeedDisplay();
88 // r is in the coordinate space of the layer's render object
89 void setContentsNeedDisplayInRect(const IntRect
& r
);
91 // Notification from the renderer that its content changed; used by RenderImage.
92 void rendererContentChanged();
94 // Interface to start, finish, suspend and resume animations and transitions
95 bool startAnimation(double beginTime
, const Animation
* anim
, const KeyframeList
& keyframes
);
96 bool startTransition(double beginTime
, int property
, const RenderStyle
* fromStyle
, const RenderStyle
* toStyle
);
97 void animationFinished(const String
& name
, int index
, bool reset
);
98 void transitionFinished(int property
);
100 void suspendAnimations();
101 void resumeAnimations();
103 FloatPoint
graphicsLayerToContentsCoordinates(const GraphicsLayer
*, const FloatPoint
&);
104 FloatPoint
contentsToGraphicsLayerCoordinates(const GraphicsLayer
*, const FloatPoint
&);
106 // GraphicsLayerClient interface
107 virtual void notifyAnimationStarted(const GraphicsLayer
*, double startTime
);
109 virtual void paintContents(const GraphicsLayer
*, GraphicsContext
&, GraphicsLayerPaintingPhase
, const IntRect
& clip
);
111 virtual IntRect
contentsBox(const GraphicsLayer
*);
113 void setDocumentScale(float scale
);
116 void createGraphicsLayer();
117 void destroyGraphicsLayer();
119 RenderBox
* renderer() const { return m_owningLayer
->renderer(); }
120 RenderLayerCompositor
* compositor() const { return m_owningLayer
->compositor(); }
122 bool updateClippingLayers(bool needsAncestorClip
, bool needsDescendantClip
);
123 bool updateContentsLayer(bool needsContentsLayer
);
125 IntSize
contentOffsetInCompostingLayer();
126 // Result is transform origin in pixels.
127 FloatPoint3D
computeTransformOrigin(const IntRect
& borderBox
) const;
128 // Result is perspective origin in pixels.
129 FloatPoint
computePerspectiveOrigin(const IntRect
& borderBox
) const;
131 void updateLayerOpacity();
132 void updateLayerTransform();
134 // Return the opacity value that this layer should use for compositing.
135 float compositingOpacity(float rendererOpacity
) const;
137 // Returns true if this RenderLayer only has content that can be rendered directly
138 // by the compositing layer, without drawing (e.g. solid background color).
139 bool isSimpleContainerCompositingLayer() const;
140 // Returns true if we can optimize the RenderLayer to draw the replaced content
141 // directly into a compositing buffer
142 bool canUseDirectCompositing() const;
143 void updateImageContents();
145 bool rendererHasBackground() const;
146 const Color
& rendererBackgroundColor() const;
148 bool hasNonCompositingContent() const;
150 void paintIntoLayer(RenderLayer
* rootLayer
, GraphicsContext
*, const IntRect
& paintDirtyRect
,
151 bool haveTransparency
, PaintRestriction paintRestriction
, GraphicsLayerPaintingPhase
, RenderObject
* paintingRoot
);
153 static int graphicsLayerToCSSProperty(AnimatedPropertyID
);
154 static AnimatedPropertyID
cssToGraphicsLayerProperty(int);
157 RenderLayer
* m_owningLayer
;
159 GraphicsLayer
* m_ancestorClippingLayer
; // only used if we are clipped by an ancestor which is not a stacking context
160 GraphicsLayer
* m_graphicsLayer
;
161 GraphicsLayer
* m_contentsLayer
; // only used in cases where we need to draw the foreground separately
162 GraphicsLayer
* m_clippingLayer
; // only used if we have clipping on a stacking context, with compositing children
164 IntSize m_compositingContentOffset
;
166 bool m_hasDirectlyCompositedContent
: 1;
167 bool m_compositingContentOffsetDirty
: 1;
170 } // namespace WebCore
172 #endif // USE(ACCELERATED_COMPOSITING)
174 #endif // RenderLayerBacking_h