Reenable NullOpenerRedirectForksProcess, as the offending patch has been reverted
[chromium-blink-merge.git] / cc / layer.h
blob97bd200541ec2ccf95f1649e77c4da2721345839
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 CC_LAYER_H_
6 #define CC_LAYER_H_
8 #include "base/memory/ref_counted.h"
9 #include "cc/cc_export.h"
10 #include "cc/layer_animation_controller.h"
11 #include "cc/occlusion_tracker.h"
12 #include "cc/region.h"
13 #include "cc/render_surface.h"
14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/rect.h"
16 #include "ui/gfx/rect_f.h"
17 #include <public/WebFilterOperations.h>
18 #include <public/WebTransformationMatrix.h>
19 #include <string>
20 #include <vector>
22 namespace WebKit {
23 class WebAnimationDelegate;
24 class WebLayerScrollClient;
27 class SkImageFilter;
29 namespace cc {
31 class ActiveAnimation;
32 struct AnimationEvent;
33 class LayerAnimationDelegate;
34 class LayerImpl;
35 class LayerTreeHost;
36 class PriorityCalculator;
37 class ResourceUpdateQueue;
38 class ScrollbarLayer;
39 struct AnimationEvent;
40 struct RenderingStats;
42 // Base class for composited layers. Special layer types are derived from
43 // this class.
44 class CC_EXPORT Layer : public base::RefCounted<Layer>, public LayerAnimationControllerClient {
45 public:
46 typedef std::vector<scoped_refptr<Layer> > LayerList;
48 static scoped_refptr<Layer> create();
50 // LayerAnimationControllerClient implementation
51 virtual int id() const OVERRIDE;
52 virtual void setOpacityFromAnimation(float) OVERRIDE;
53 virtual float opacity() const OVERRIDE;
54 virtual void setTransformFromAnimation(const WebKit::WebTransformationMatrix&) OVERRIDE;
55 // A layer's transform operates layer space. That is, entirely in logical,
56 // non-page-scaled pixels (that is, they have page zoom baked in, but not page scale).
57 // The root layer is a special case -- it operates in physical pixels.
58 virtual const WebKit::WebTransformationMatrix& transform() const OVERRIDE;
60 Layer* rootLayer();
61 Layer* parent() const;
62 void addChild(scoped_refptr<Layer>);
63 void insertChild(scoped_refptr<Layer>, size_t index);
64 void replaceChild(Layer* reference, scoped_refptr<Layer> newLayer);
65 void removeFromParent();
66 void removeAllChildren();
67 void setChildren(const LayerList&);
69 const LayerList& children() const { return m_children; }
71 void setAnchorPoint(const gfx::PointF&);
72 gfx::PointF anchorPoint() const { return m_anchorPoint; }
74 void setAnchorPointZ(float);
75 float anchorPointZ() const { return m_anchorPointZ; }
77 virtual void setBackgroundColor(SkColor);
78 SkColor backgroundColor() const { return m_backgroundColor; }
80 // A layer's bounds are in logical, non-page-scaled pixels (however, the
81 // root layer's bounds are in physical pixels).
82 void setBounds(const gfx::Size&);
83 const gfx::Size& bounds() const { return m_bounds; }
84 virtual gfx::Size contentBounds() const;
86 void setMasksToBounds(bool);
87 bool masksToBounds() const { return m_masksToBounds; }
89 void setMaskLayer(Layer*);
90 Layer* maskLayer() const { return m_maskLayer.get(); }
92 virtual void setNeedsDisplayRect(const gfx::RectF& dirtyRect);
93 void setNeedsDisplay() { setNeedsDisplayRect(gfx::RectF(gfx::PointF(), bounds())); }
94 virtual bool needsDisplay() const;
96 void setOpacity(float);
97 bool opacityIsAnimating() const;
99 void setFilters(const WebKit::WebFilterOperations&);
100 const WebKit::WebFilterOperations& filters() const { return m_filters; }
102 void setFilter(SkImageFilter* filter);
103 SkImageFilter* filter() const { return m_filter; }
105 // Background filters are filters applied to what is behind this layer, when they are viewed through non-opaque
106 // regions in this layer. They are used through the WebLayer interface, and are not exposed to HTML.
107 void setBackgroundFilters(const WebKit::WebFilterOperations&);
108 const WebKit::WebFilterOperations& backgroundFilters() const { return m_backgroundFilters; }
110 virtual void setContentsOpaque(bool);
111 bool contentsOpaque() const { return m_contentsOpaque; }
113 void setPosition(const gfx::PointF&);
114 gfx::PointF position() const { return m_position; }
116 void setIsContainerForFixedPositionLayers(bool);
117 bool isContainerForFixedPositionLayers() const { return m_isContainerForFixedPositionLayers; }
119 void setFixedToContainerLayer(bool);
120 bool fixedToContainerLayer() const { return m_fixedToContainerLayer; }
122 void setSublayerTransform(const WebKit::WebTransformationMatrix&);
123 const WebKit::WebTransformationMatrix& sublayerTransform() const { return m_sublayerTransform; }
125 void setTransform(const WebKit::WebTransformationMatrix&);
126 bool transformIsAnimating() const;
128 const gfx::Rect& visibleContentRect() const { return m_visibleContentRect; }
129 void setVisibleContentRect(const gfx::Rect& visibleContentRect) { m_visibleContentRect = visibleContentRect; }
131 void setScrollOffset(gfx::Vector2d);
132 gfx::Vector2d scrollOffset() const { return m_scrollOffset; }
134 void setMaxScrollOffset(gfx::Vector2d);
135 gfx::Vector2d maxScrollOffset() const { return m_maxScrollOffset; }
137 void setScrollable(bool);
138 bool scrollable() const { return m_scrollable; }
140 void setShouldScrollOnMainThread(bool);
141 bool shouldScrollOnMainThread() const { return m_shouldScrollOnMainThread; }
143 void setHaveWheelEventHandlers(bool);
144 bool haveWheelEventHandlers() const { return m_haveWheelEventHandlers; }
146 void setNonFastScrollableRegion(const Region&);
147 void setNonFastScrollableRegionChanged() { m_nonFastScrollableRegionChanged = true; }
148 const Region& nonFastScrollableRegion() const { return m_nonFastScrollableRegion; }
150 void setTouchEventHandlerRegion(const Region&);
151 void setTouchEventHandlerRegionChanged() { m_touchEventHandlerRegionChanged = true; }
152 const Region& touchEventHandlerRegion() const { return m_touchEventHandlerRegion; }
154 void setLayerScrollClient(WebKit::WebLayerScrollClient* layerScrollClient) { m_layerScrollClient = layerScrollClient; }
156 void setDrawCheckerboardForMissingTiles(bool);
157 bool drawCheckerboardForMissingTiles() const { return m_drawCheckerboardForMissingTiles; }
159 bool forceRenderSurface() const { return m_forceRenderSurface; }
160 void setForceRenderSurface(bool);
162 gfx::Vector2d scrollDelta() const { return gfx::Vector2d(); }
164 void setImplTransform(const WebKit::WebTransformationMatrix&);
165 const WebKit::WebTransformationMatrix& implTransform() const { return m_implTransform; }
167 void setDoubleSided(bool);
168 bool doubleSided() const { return m_doubleSided; }
170 void setPreserves3D(bool preserve3D) { m_preserves3D = preserve3D; }
171 bool preserves3D() const { return m_preserves3D; }
173 void setUseParentBackfaceVisibility(bool useParentBackfaceVisibility) { m_useParentBackfaceVisibility = useParentBackfaceVisibility; }
174 bool useParentBackfaceVisibility() const { return m_useParentBackfaceVisibility; }
176 void setUseLCDText(bool);
177 bool useLCDText() const { return m_useLCDText; }
179 virtual void setLayerTreeHost(LayerTreeHost*);
181 bool hasContributingDelegatedRenderPasses() const { return false; }
183 void setIsDrawable(bool);
185 void setReplicaLayer(Layer*);
186 Layer* replicaLayer() const { return m_replicaLayer.get(); }
188 bool hasMask() const { return m_maskLayer; }
189 bool hasReplica() const { return m_replicaLayer; }
190 bool replicaHasMask() const { return m_replicaLayer && (m_maskLayer || m_replicaLayer->m_maskLayer); }
192 // These methods typically need to be overwritten by derived classes.
193 virtual bool drawsContent() const;
194 virtual void update(ResourceUpdateQueue&, const OcclusionTracker*, RenderingStats&) { }
195 virtual bool needMoreUpdates();
196 virtual void setIsMask(bool) { }
197 virtual void bindContentsTexture() { }
199 void setDebugName(const std::string&);
201 virtual void pushPropertiesTo(LayerImpl*);
203 void clearRenderSurface() { m_renderSurface.reset(); }
204 RenderSurface* renderSurface() const { return m_renderSurface.get(); }
205 void createRenderSurface();
207 float drawOpacity() const { return m_drawOpacity; }
208 void setDrawOpacity(float opacity) { m_drawOpacity = opacity; }
210 bool drawOpacityIsAnimating() const { return m_drawOpacityIsAnimating; }
211 void setDrawOpacityIsAnimating(bool drawOpacityIsAnimating) { m_drawOpacityIsAnimating = drawOpacityIsAnimating; }
213 Layer* renderTarget() const { DCHECK(!m_renderTarget || m_renderTarget->renderSurface()); return m_renderTarget; }
214 void setRenderTarget(Layer* target) { m_renderTarget = target; }
216 bool drawTransformIsAnimating() const { return m_drawTransformIsAnimating; }
217 void setDrawTransformIsAnimating(bool animating) { m_drawTransformIsAnimating = animating; }
218 bool screenSpaceTransformIsAnimating() const { return m_screenSpaceTransformIsAnimating; }
219 void setScreenSpaceTransformIsAnimating(bool animating) { m_screenSpaceTransformIsAnimating = animating; }
221 // This moves from layer space, with origin in the center to target space with origin in the top left.
222 // That is, it converts from logical, non-page-scaled, to target pixels (and if the target is the
223 // root render surface, then this converts to physical pixels).
224 const WebKit::WebTransformationMatrix& drawTransform() const { return m_drawTransform; }
225 void setDrawTransform(const WebKit::WebTransformationMatrix& matrix) { m_drawTransform = matrix; }
226 // This moves from content space, with origin the top left to screen space with origin in the top left.
227 // It converts logical, non-page-scaled pixels to physical pixels.
228 const WebKit::WebTransformationMatrix& screenSpaceTransform() const { return m_screenSpaceTransform; }
229 void setScreenSpaceTransform(const WebKit::WebTransformationMatrix& matrix) { m_screenSpaceTransform = matrix; }
230 const gfx::Rect& drawableContentRect() const { return m_drawableContentRect; }
231 void setDrawableContentRect(const gfx::Rect& rect) { m_drawableContentRect = rect; }
233 // The contentsScale converts from logical, non-page-scaled pixels to target pixels.
234 // The contentsScale is 1 for the root layer as it is already in physical pixels.
235 // By default contentsScale is forced to be 1 except for subclasses of ContentsScalingLayer.
236 virtual float contentsScaleX() const;
237 virtual float contentsScaleY() const;
238 virtual void setContentsScale(float contentsScale) { }
240 // The scale at which contents should be rastered, to match the scale at
241 // which they will drawn to the screen. This scale is a component of the
242 // contentsScale() but does not include page/device scale factors.
243 float rasterScale() const { return m_rasterScale; }
244 void setRasterScale(float scale);
246 // When true, the rasterScale() will be set by the compositor. If false, it
247 // will use whatever value is given to it by the embedder.
248 bool automaticallyComputeRasterScale() { return m_automaticallyComputeRasterScale; }
249 void setAutomaticallyComputeRasterScale(bool);
251 void forceAutomaticRasterScaleToBeRecomputed();
253 // When true, the layer's contents are not scaled by the current page scale factor.
254 // setBoundsContainPageScale recursively sets the value on all child layers.
255 void setBoundsContainPageScale(bool);
256 bool boundsContainPageScale() const { return m_boundsContainPageScale; }
258 // Returns true if any of the layer's descendants has content to draw.
259 bool descendantDrawsContent();
261 LayerTreeHost* layerTreeHost() const { return m_layerTreeHost; }
263 // Set the priority of all desired textures in this layer.
264 virtual void setTexturePriorities(const PriorityCalculator&) { }
266 bool addAnimation(scoped_ptr<ActiveAnimation>);
267 void pauseAnimation(int animationId, double timeOffset);
268 void removeAnimation(int animationId);
270 void suspendAnimations(double monotonicTime);
271 void resumeAnimations(double monotonicTime);
273 LayerAnimationController* layerAnimationController() { return m_layerAnimationController.get(); }
274 void setLayerAnimationController(scoped_ptr<LayerAnimationController>);
275 scoped_ptr<LayerAnimationController> releaseLayerAnimationController();
277 void setLayerAnimationDelegate(WebKit::WebAnimationDelegate* layerAnimationDelegate) { m_layerAnimationDelegate = layerAnimationDelegate; }
279 bool hasActiveAnimation() const;
281 virtual void notifyAnimationStarted(const AnimationEvent&, double wallClockTime);
282 virtual void notifyAnimationFinished(double wallClockTime);
284 virtual Region visibleContentOpaqueRegion() const;
286 virtual ScrollbarLayer* toScrollbarLayer();
288 gfx::Rect layerRectToContentRect(const gfx::RectF& layerRect) const;
290 protected:
291 friend class LayerImpl;
292 friend class TreeSynchronizer;
293 virtual ~Layer();
295 Layer();
297 void setNeedsCommit();
299 // This flag is set when layer need repainting/updating.
300 bool m_needsDisplay;
302 // Tracks whether this layer may have changed stacking order with its siblings.
303 bool m_stackingOrderChanged;
305 // The update rect is the region of the compositor resource that was actually updated by the compositor.
306 // For layers that may do updating outside the compositor's control (i.e. plugin layers), this information
307 // is not available and the update rect will remain empty.
308 // Note this rect is in layer space (not content space).
309 gfx::RectF m_updateRect;
311 scoped_refptr<Layer> m_maskLayer;
313 // Constructs a LayerImpl of the correct runtime type for this Layer type.
314 virtual scoped_ptr<LayerImpl> createLayerImpl();
315 int m_layerId;
317 private:
318 friend class base::RefCounted<Layer>;
320 void setParent(Layer*);
321 bool hasAncestor(Layer*) const;
322 bool descendantIsFixedToContainerLayer() const;
324 size_t numChildren() const { return m_children.size(); }
326 // Returns the index of the child or -1 if not found.
327 int indexOfChild(const Layer*);
329 // This should only be called from removeFromParent.
330 void removeChild(Layer*);
332 LayerList m_children;
333 Layer* m_parent;
335 // Layer instances have a weak pointer to their LayerTreeHost.
336 // This pointer value is nil when a Layer is not in a tree and is
337 // updated via setLayerTreeHost() if a layer moves between trees.
338 LayerTreeHost* m_layerTreeHost;
340 scoped_ptr<LayerAnimationController> m_layerAnimationController;
342 // Layer properties.
343 gfx::Size m_bounds;
345 // Uses layer's content space.
346 gfx::Rect m_visibleContentRect;
348 gfx::Vector2d m_scrollOffset;
349 gfx::Vector2d m_maxScrollOffset;
350 bool m_scrollable;
351 bool m_shouldScrollOnMainThread;
352 bool m_haveWheelEventHandlers;
353 Region m_nonFastScrollableRegion;
354 bool m_nonFastScrollableRegionChanged;
355 Region m_touchEventHandlerRegion;
356 bool m_touchEventHandlerRegionChanged;
357 gfx::PointF m_position;
358 gfx::PointF m_anchorPoint;
359 SkColor m_backgroundColor;
360 std::string m_debugName;
361 float m_opacity;
362 SkImageFilter* m_filter;
363 WebKit::WebFilterOperations m_filters;
364 WebKit::WebFilterOperations m_backgroundFilters;
365 float m_anchorPointZ;
366 bool m_isContainerForFixedPositionLayers;
367 bool m_fixedToContainerLayer;
368 bool m_isDrawable;
369 bool m_masksToBounds;
370 bool m_contentsOpaque;
371 bool m_doubleSided;
372 bool m_useLCDText;
373 bool m_preserves3D;
374 bool m_useParentBackfaceVisibility;
375 bool m_drawCheckerboardForMissingTiles;
376 bool m_forceRenderSurface;
378 WebKit::WebTransformationMatrix m_transform;
379 WebKit::WebTransformationMatrix m_sublayerTransform;
381 // Replica layer used for reflections.
382 scoped_refptr<Layer> m_replicaLayer;
384 // Transient properties.
385 scoped_ptr<RenderSurface> m_renderSurface;
386 float m_drawOpacity;
387 bool m_drawOpacityIsAnimating;
389 Layer* m_renderTarget;
391 WebKit::WebTransformationMatrix m_drawTransform;
392 WebKit::WebTransformationMatrix m_screenSpaceTransform;
393 bool m_drawTransformIsAnimating;
394 bool m_screenSpaceTransformIsAnimating;
396 // Uses target surface space.
397 gfx::Rect m_drawableContentRect;
398 float m_rasterScale;
399 bool m_automaticallyComputeRasterScale;
400 bool m_boundsContainPageScale;
402 WebKit::WebTransformationMatrix m_implTransform;
404 WebKit::WebAnimationDelegate* m_layerAnimationDelegate;
405 WebKit::WebLayerScrollClient* m_layerScrollClient;
408 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped_refptr<Layer> >::iterator, void*);
410 } // namespace cc
412 #endif // CC_LAYER_H_