Implement android_webview url intercepting.
[chromium-blink-merge.git] / cc / layer.h
blobf16fbe79cfc6f2a72a5bf35f4a5d1d2a521188a9
1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef LayerChromium_h
6 #define LayerChromium_h
8 #include "base/memory/ref_counted.h"
9 #include "CCLayerAnimationController.h"
10 #include "CCOcclusionTracker.h"
11 #include "FloatPoint.h"
12 #include "Region.h"
13 #include "RenderSurfaceChromium.h"
14 #include "third_party/skia/include/core/SkColor.h"
15 #include <public/WebFilterOperations.h>
16 #include <public/WebTransformationMatrix.h>
17 #include <string>
18 #include <vector>
20 namespace WebKit {
21 class WebAnimationDelegate;
22 class WebLayerScrollClient;
25 namespace cc {
27 class CCActiveAnimation;
28 struct CCAnimationEvent;
29 class CCLayerAnimationDelegate;
30 class CCLayerImpl;
31 class CCLayerTreeHost;
32 class CCPriorityCalculator;
33 class CCTextureUpdateQueue;
34 class ScrollbarLayerChromium;
35 struct CCAnimationEvent;
36 struct CCRenderingStats;
38 // Base class for composited layers. Special layer types are derived from
39 // this class.
40 class LayerChromium : public base::RefCounted<LayerChromium>, public CCLayerAnimationControllerClient {
41 public:
42 typedef std::vector<scoped_refptr<LayerChromium> > LayerList;
44 static scoped_refptr<LayerChromium> create();
46 // CCLayerAnimationControllerClient implementation
47 virtual int id() const OVERRIDE;
48 virtual void setOpacityFromAnimation(float) OVERRIDE;
49 virtual float opacity() const OVERRIDE;
50 virtual void setTransformFromAnimation(const WebKit::WebTransformationMatrix&) OVERRIDE;
51 // A layer's transform operates layer space. That is, entirely in logical,
52 // non-page-scaled pixels (that is, they have page zoom baked in, but not page scale).
53 // The root layer is a special case -- it operates in physical pixels.
54 virtual const WebKit::WebTransformationMatrix& transform() const OVERRIDE;
56 LayerChromium* rootLayer();
57 LayerChromium* parent() const;
58 void addChild(scoped_refptr<LayerChromium>);
59 void insertChild(scoped_refptr<LayerChromium>, size_t index);
60 void replaceChild(LayerChromium* reference, scoped_refptr<LayerChromium> newLayer);
61 void removeFromParent();
62 void removeAllChildren();
63 void setChildren(const LayerList&);
65 const LayerList& children() const { return m_children; }
67 void setAnchorPoint(const FloatPoint&);
68 FloatPoint anchorPoint() const { return m_anchorPoint; }
70 void setAnchorPointZ(float);
71 float anchorPointZ() const { return m_anchorPointZ; }
73 void setBackgroundColor(SkColor);
74 SkColor backgroundColor() const { return m_backgroundColor; }
76 // A layer's bounds are in logical, non-page-scaled pixels (however, the
77 // root layer's bounds are in physical pixels).
78 void setBounds(const IntSize&);
79 const IntSize& bounds() const { return m_bounds; }
80 virtual IntSize contentBounds() const;
82 void setMasksToBounds(bool);
83 bool masksToBounds() const { return m_masksToBounds; }
85 void setMaskLayer(LayerChromium*);
86 LayerChromium* maskLayer() const { return m_maskLayer.get(); }
88 virtual void setNeedsDisplayRect(const FloatRect& dirtyRect);
89 void setNeedsDisplay() { setNeedsDisplayRect(FloatRect(FloatPoint(), bounds())); }
90 virtual bool needsDisplay() const;
92 void setOpacity(float);
93 bool opacityIsAnimating() const;
95 void setFilters(const WebKit::WebFilterOperations&);
96 const WebKit::WebFilterOperations& filters() const { return m_filters; }
98 // Background filters are filters applied to what is behind this layer, when they are viewed through non-opaque
99 // regions in this layer. They are used through the WebLayer interface, and are not exposed to HTML.
100 void setBackgroundFilters(const WebKit::WebFilterOperations&);
101 const WebKit::WebFilterOperations& backgroundFilters() const { return m_backgroundFilters; }
103 virtual void setContentsOpaque(bool);
104 bool contentsOpaque() const { return m_contentsOpaque; }
106 void setPosition(const FloatPoint&);
107 FloatPoint position() const { return m_position; }
109 void setIsContainerForFixedPositionLayers(bool);
110 bool isContainerForFixedPositionLayers() const { return m_isContainerForFixedPositionLayers; }
112 void setFixedToContainerLayer(bool);
113 bool fixedToContainerLayer() const { return m_fixedToContainerLayer; }
115 void setSublayerTransform(const WebKit::WebTransformationMatrix&);
116 const WebKit::WebTransformationMatrix& sublayerTransform() const { return m_sublayerTransform; }
118 void setTransform(const WebKit::WebTransformationMatrix&);
119 bool transformIsAnimating() const;
121 const IntRect& visibleContentRect() const { return m_visibleContentRect; }
122 void setVisibleContentRect(const IntRect& visibleContentRect) { m_visibleContentRect = visibleContentRect; }
124 void setScrollPosition(const IntPoint&);
125 const IntPoint& scrollPosition() const { return m_scrollPosition; }
127 void setMaxScrollPosition(const IntSize&);
128 const IntSize& maxScrollPosition() const { return m_maxScrollPosition; }
130 void setScrollable(bool);
131 bool scrollable() const { return m_scrollable; }
133 void setShouldScrollOnMainThread(bool);
134 bool shouldScrollOnMainThread() const { return m_shouldScrollOnMainThread; }
136 void setHaveWheelEventHandlers(bool);
137 bool haveWheelEventHandlers() const { return m_haveWheelEventHandlers; }
139 void setNonFastScrollableRegion(const Region&);
140 void setNonFastScrollableRegionChanged() { m_nonFastScrollableRegionChanged = true; }
141 const Region& nonFastScrollableRegion() const { return m_nonFastScrollableRegion; }
143 void setLayerScrollClient(WebKit::WebLayerScrollClient* layerScrollClient) { m_layerScrollClient = layerScrollClient; }
145 void setDrawCheckerboardForMissingTiles(bool);
146 bool drawCheckerboardForMissingTiles() const { return m_drawCheckerboardForMissingTiles; }
148 bool forceRenderSurface() const { return m_forceRenderSurface; }
149 void setForceRenderSurface(bool);
151 IntSize scrollDelta() const { return IntSize(); }
153 void setImplTransform(const WebKit::WebTransformationMatrix&);
154 const WebKit::WebTransformationMatrix& implTransform() const { return m_implTransform; }
156 void setDoubleSided(bool);
157 bool doubleSided() const { return m_doubleSided; }
159 void setPreserves3D(bool preserve3D) { m_preserves3D = preserve3D; }
160 bool preserves3D() const { return m_preserves3D; }
162 void setUseParentBackfaceVisibility(bool useParentBackfaceVisibility) { m_useParentBackfaceVisibility = useParentBackfaceVisibility; }
163 bool useParentBackfaceVisibility() const { return m_useParentBackfaceVisibility; }
165 virtual void setUseLCDText(bool);
166 bool useLCDText() const { return m_useLCDText; }
168 virtual void setLayerTreeHost(CCLayerTreeHost*);
170 bool hasContributingDelegatedRenderPasses() const { return false; }
172 void setIsDrawable(bool);
174 void setReplicaLayer(LayerChromium*);
175 LayerChromium* replicaLayer() const { return m_replicaLayer.get(); }
177 bool hasMask() const { return m_maskLayer; }
178 bool hasReplica() const { return m_replicaLayer; }
179 bool replicaHasMask() const { return m_replicaLayer && (m_maskLayer || m_replicaLayer->m_maskLayer); }
181 // These methods typically need to be overwritten by derived classes.
182 virtual bool drawsContent() const;
183 virtual void update(CCTextureUpdateQueue&, const CCOcclusionTracker*, CCRenderingStats&) { }
184 virtual bool needMoreUpdates();
185 virtual void setIsMask(bool) { }
186 virtual void bindContentsTexture() { }
187 virtual bool needsContentsScale() const;
189 void setDebugBorderColor(SkColor);
190 void setDebugBorderWidth(float);
191 void setDebugName(const std::string&);
193 virtual void pushPropertiesTo(CCLayerImpl*);
195 void clearRenderSurface() { m_renderSurface.reset(); }
196 RenderSurfaceChromium* renderSurface() const { return m_renderSurface.get(); }
197 void createRenderSurface();
199 float drawOpacity() const { return m_drawOpacity; }
200 void setDrawOpacity(float opacity) { m_drawOpacity = opacity; }
202 bool drawOpacityIsAnimating() const { return m_drawOpacityIsAnimating; }
203 void setDrawOpacityIsAnimating(bool drawOpacityIsAnimating) { m_drawOpacityIsAnimating = drawOpacityIsAnimating; }
205 LayerChromium* renderTarget() const { ASSERT(!m_renderTarget || m_renderTarget->renderSurface()); return m_renderTarget; }
206 void setRenderTarget(LayerChromium* target) { m_renderTarget = target; }
208 bool drawTransformIsAnimating() const { return m_drawTransformIsAnimating; }
209 void setDrawTransformIsAnimating(bool animating) { m_drawTransformIsAnimating = animating; }
210 bool screenSpaceTransformIsAnimating() const { return m_screenSpaceTransformIsAnimating; }
211 void setScreenSpaceTransformIsAnimating(bool animating) { m_screenSpaceTransformIsAnimating = animating; }
213 // This moves from layer space, with origin in the center to target space with origin in the top left.
214 // That is, it converts from logical, non-page-scaled, to target pixels (and if the target is the
215 // root render surface, then this converts to physical pixels).
216 const WebKit::WebTransformationMatrix& drawTransform() const { return m_drawTransform; }
217 void setDrawTransform(const WebKit::WebTransformationMatrix& matrix) { m_drawTransform = matrix; }
218 // This moves from content space, with origin the top left to screen space with origin in the top left.
219 // It converts logical, non-page-scaled pixels to physical pixels.
220 const WebKit::WebTransformationMatrix& screenSpaceTransform() const { return m_screenSpaceTransform; }
221 void setScreenSpaceTransform(const WebKit::WebTransformationMatrix& matrix) { m_screenSpaceTransform = matrix; }
222 const IntRect& drawableContentRect() const { return m_drawableContentRect; }
223 void setDrawableContentRect(const IntRect& rect) { m_drawableContentRect = rect; }
224 // The contentsScale converts from logical, non-page-scaled pixels to target pixels.
225 // The contentsScale is 1 for the root layer as it is already in physical pixels.
226 float contentsScale() const { return m_contentsScale; }
227 void setContentsScale(float);
229 // When true, the layer's contents are not scaled by the current page scale factor.
230 // setBoundsContainPageScale recursively sets the value on all child layers.
231 void setBoundsContainPageScale(bool);
232 bool boundsContainPageScale() const { return m_boundsContainPageScale; }
234 // Returns true if any of the layer's descendants has content to draw.
235 bool descendantDrawsContent();
237 CCLayerTreeHost* layerTreeHost() const { return m_layerTreeHost; }
239 // Set the priority of all desired textures in this layer.
240 virtual void setTexturePriorities(const CCPriorityCalculator&) { }
242 bool addAnimation(scoped_ptr<CCActiveAnimation>);
243 void pauseAnimation(int animationId, double timeOffset);
244 void removeAnimation(int animationId);
246 void suspendAnimations(double monotonicTime);
247 void resumeAnimations(double monotonicTime);
249 CCLayerAnimationController* layerAnimationController() { return m_layerAnimationController.get(); }
250 void setLayerAnimationController(scoped_ptr<CCLayerAnimationController>);
251 scoped_ptr<CCLayerAnimationController> releaseLayerAnimationController();
253 void setLayerAnimationDelegate(WebKit::WebAnimationDelegate* layerAnimationDelegate) { m_layerAnimationDelegate = layerAnimationDelegate; }
255 bool hasActiveAnimation() const;
257 virtual void notifyAnimationStarted(const CCAnimationEvent&, double wallClockTime);
258 virtual void notifyAnimationFinished(double wallClockTime);
260 virtual Region visibleContentOpaqueRegion() const;
262 virtual ScrollbarLayerChromium* toScrollbarLayerChromium();
264 protected:
265 friend class CCLayerImpl;
266 friend class TreeSynchronizer;
267 virtual ~LayerChromium();
269 LayerChromium();
271 void setNeedsCommit();
273 IntRect layerRectToContentRect(const WebKit::WebRect& layerRect);
275 // This flag is set when layer need repainting/updating.
276 bool m_needsDisplay;
278 // Tracks whether this layer may have changed stacking order with its siblings.
279 bool m_stackingOrderChanged;
281 // The update rect is the region of the compositor resource that was actually updated by the compositor.
282 // For layers that may do updating outside the compositor's control (i.e. plugin layers), this information
283 // is not available and the update rect will remain empty.
284 // Note this rect is in layer space (not content space).
285 FloatRect m_updateRect;
287 scoped_refptr<LayerChromium> m_maskLayer;
289 // Constructs a CCLayerImpl of the correct runtime type for this LayerChromium type.
290 virtual scoped_ptr<CCLayerImpl> createCCLayerImpl();
291 int m_layerId;
293 private:
294 friend class base::RefCounted<LayerChromium>;
296 void setParent(LayerChromium*);
297 bool hasAncestor(LayerChromium*) const;
298 bool descendantIsFixedToContainerLayer() const;
300 size_t numChildren() const { return m_children.size(); }
302 // Returns the index of the child or -1 if not found.
303 int indexOfChild(const LayerChromium*);
305 // This should only be called from removeFromParent.
306 void removeChild(LayerChromium*);
308 LayerList m_children;
309 LayerChromium* m_parent;
311 // LayerChromium instances have a weak pointer to their CCLayerTreeHost.
312 // This pointer value is nil when a LayerChromium is not in a tree and is
313 // updated via setLayerTreeHost() if a layer moves between trees.
314 CCLayerTreeHost* m_layerTreeHost;
316 scoped_ptr<CCLayerAnimationController> m_layerAnimationController;
318 // Layer properties.
319 IntSize m_bounds;
321 // Uses layer's content space.
322 IntRect m_visibleContentRect;
324 IntPoint m_scrollPosition;
325 IntSize m_maxScrollPosition;
326 bool m_scrollable;
327 bool m_shouldScrollOnMainThread;
328 bool m_haveWheelEventHandlers;
329 Region m_nonFastScrollableRegion;
330 bool m_nonFastScrollableRegionChanged;
331 FloatPoint m_position;
332 FloatPoint m_anchorPoint;
333 SkColor m_backgroundColor;
334 SkColor m_debugBorderColor;
335 float m_debugBorderWidth;
336 std::string m_debugName;
337 float m_opacity;
338 WebKit::WebFilterOperations m_filters;
339 WebKit::WebFilterOperations m_backgroundFilters;
340 float m_anchorPointZ;
341 bool m_isContainerForFixedPositionLayers;
342 bool m_fixedToContainerLayer;
343 bool m_isDrawable;
344 bool m_masksToBounds;
345 bool m_contentsOpaque;
346 bool m_doubleSided;
347 bool m_useLCDText;
348 bool m_preserves3D;
349 bool m_useParentBackfaceVisibility;
350 bool m_drawCheckerboardForMissingTiles;
351 bool m_forceRenderSurface;
353 WebKit::WebTransformationMatrix m_transform;
354 WebKit::WebTransformationMatrix m_sublayerTransform;
356 // Replica layer used for reflections.
357 scoped_refptr<LayerChromium> m_replicaLayer;
359 // Transient properties.
360 scoped_ptr<RenderSurfaceChromium> m_renderSurface;
361 float m_drawOpacity;
362 bool m_drawOpacityIsAnimating;
364 LayerChromium* m_renderTarget;
366 WebKit::WebTransformationMatrix m_drawTransform;
367 WebKit::WebTransformationMatrix m_screenSpaceTransform;
368 bool m_drawTransformIsAnimating;
369 bool m_screenSpaceTransformIsAnimating;
371 // Uses target surface space.
372 IntRect m_drawableContentRect;
373 float m_contentsScale;
374 bool m_boundsContainPageScale;
376 WebKit::WebTransformationMatrix m_implTransform;
378 WebKit::WebAnimationDelegate* m_layerAnimationDelegate;
379 WebKit::WebLayerScrollClient* m_layerScrollClient;
382 void sortLayers(std::vector<scoped_refptr<LayerChromium> >::iterator, std::vector<scoped_refptr<LayerChromium> >::iterator, void*);
384 } // namespace cc
386 #endif