blob: 2fec36364570707340f3d6bc57fb886b51e901ee [file] [log] [blame]
[email protected]cd57cc5a2012-10-12 22:43:411// Copyright 2010 The Chromium Authors. All rights reserved.
[email protected]0fb25002012-10-12 07:20:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]cd57cc5a2012-10-12 22:43:414
[email protected]cc3cfaa2013-03-18 09:05:525#ifndef CC_LAYERS_LAYER_H_
6#define CC_LAYERS_LAYER_H_
[email protected]cd57cc5a2012-10-12 22:43:417
[email protected]0e98cdd2013-08-23 00:44:308#include <set>
[email protected]c8686a02012-11-27 08:29:009#include <string>
vmpstr3d1d72c2015-01-26 18:27:4010#include <vector>
[email protected]c8686a02012-11-27 08:29:0011
[email protected]18a70192013-04-26 16:18:2512#include "base/callback.h"
[email protected]a8461d82012-10-16 21:11:1413#include "base/memory/ref_counted.h"
[email protected]e10cd022012-12-18 00:32:2614#include "base/observer_list.h"
[email protected]95e4e1a02013-03-18 07:09:0915#include "cc/animation/layer_animation_controller.h"
[email protected]95e4e1a02013-03-18 07:09:0916#include "cc/animation/layer_animation_value_observer.h"
[email protected]b8384e22013-12-03 02:20:4817#include "cc/animation/layer_animation_value_provider.h"
[email protected]681ccff2013-03-18 06:13:5218#include "cc/base/cc_export.h"
19#include "cc/base/region.h"
[email protected]0e5f7142013-05-24 06:45:3620#include "cc/base/scoped_ptr_vector.h"
vmpstr3d1d72c2015-01-26 18:27:4021#include "cc/debug/frame_timing_request.h"
[email protected]666d7cf2013-10-12 01:30:2922#include "cc/debug/micro_benchmark.h"
[email protected]50761e92013-03-29 20:51:2823#include "cc/layers/layer_lists.h"
[email protected]fe956c9c42013-04-09 04:26:3324#include "cc/layers/layer_position_constraint.h"
[email protected]445881f2013-04-16 01:11:5925#include "cc/layers/paint_properties.h"
rbyers18779d822015-02-05 06:22:0626#include "cc/layers/scroll_blocks_on.h"
[email protected]ae6b1a72013-06-25 18:49:2927#include "cc/output/filter_operations.h"
vollick51ed1a22014-12-17 02:03:0028#include "cc/trees/property_tree.h"
[email protected]1940c4e2012-12-04 05:08:1529#include "skia/ext/refptr.h"
[email protected]ddf9df82012-10-16 06:52:4630#include "third_party/skia/include/core/SkColor.h"
[email protected]1940c4e2012-12-04 05:08:1531#include "third_party/skia/include/core/SkImageFilter.h"
[email protected]f7837a92013-08-21 03:00:0532#include "third_party/skia/include/core/SkPicture.h"
[email protected]7bbeaf4e2013-11-26 10:27:2233#include "third_party/skia/include/core/SkXfermode.h"
heejin.r.chungd28506ba2014-10-23 16:36:2034#include "ui/gfx/geometry/point3_f.h"
35#include "ui/gfx/geometry/rect.h"
36#include "ui/gfx/geometry/rect_f.h"
miletusf57925d2014-10-01 19:38:1337#include "ui/gfx/geometry/scroll_offset.h"
[email protected]c8686a02012-11-27 08:29:0038#include "ui/gfx/transform.h"
[email protected]cd57cc5a2012-10-12 22:43:4139
[email protected]db2586f2013-08-15 22:03:1440namespace gfx {
41class BoxF;
42}
43
[email protected]9f3be432013-12-03 03:53:2244namespace base {
primiano15960432015-02-05 14:20:2645namespace trace_event {
[email protected]9f3be432013-12-03 03:53:2246class ConvertableToTraceFormat;
47}
48}
49
[email protected]cd57cc5a2012-10-12 22:43:4150namespace cc {
51
[email protected]4d0786a2013-01-07 16:21:2052class Animation;
[email protected]3cae03e2013-06-26 22:13:5253class AnimationDelegate;
[email protected]96baf3e2012-10-22 23:09:5554struct AnimationEvent;
[email protected]0e5f7142013-05-24 06:45:3655class CopyOutputRequest;
[email protected]7f5605c2013-04-08 18:08:3556class LayerAnimationEventObserver;
[email protected]ae716ce2013-08-16 13:04:2457class LayerClient;
[email protected]96baf3e2012-10-22 23:09:5558class LayerImpl;
loysoa6edaaff2015-05-25 03:26:4459class LayerSettings;
[email protected]96baf3e2012-10-22 23:09:5560class LayerTreeHost;
awoloszyne83f28c2014-12-22 15:40:0061class LayerTreeHostCommon;
[email protected]8bef40572012-12-11 21:38:0862class LayerTreeImpl;
loyso57197782015-05-28 04:10:1863class LayerTreeSettings;
[email protected]d84116612013-03-29 05:32:4964class RenderingStatsInstrumentation;
[email protected]b4da2032012-10-25 21:22:5565class ResourceUpdateQueue;
[email protected]80413d72013-08-30 20:25:3366class ScrollbarLayerInterface;
[email protected]d5467eb72014-08-22 01:16:4367class SimpleEnclosedRegion;
[email protected]96baf3e2012-10-22 23:09:5568struct AnimationEvent;
[email protected]cd57cc5a2012-10-12 22:43:4169
70// Base class for composited layers. Special layer types are derived from
71// this class.
[email protected]de4afb5e2012-12-20 00:11:3472class CC_EXPORT Layer : public base::RefCounted<Layer>,
[email protected]b8384e22013-12-03 02:20:4873 public LayerAnimationValueObserver,
74 public LayerAnimationValueProvider {
[email protected]7aba6662013-03-12 10:17:3475 public:
[email protected]44d8e84c2013-10-19 19:13:2276 typedef LayerList LayerListType;
[email protected]44d8e84c2013-10-19 19:13:2277
[email protected]b7c4783f2013-03-15 23:11:4278 enum LayerIdLabels {
[email protected]b7c4783f2013-03-15 23:11:4279 INVALID_ID = -1,
80 };
[email protected]cd57cc5a2012-10-12 22:43:4181
loysoa6edaaff2015-05-25 03:26:4482 static scoped_refptr<Layer> Create(const LayerSettings& settings);
[email protected]cd57cc5a2012-10-12 22:43:4183
[email protected]7aba6662013-03-12 10:17:3484 int id() const { return layer_id_; }
[email protected]cd57cc5a2012-10-12 22:43:4185
[email protected]7aba6662013-03-12 10:17:3486 Layer* RootLayer();
87 Layer* parent() { return parent_; }
88 const Layer* parent() const { return parent_; }
89 void AddChild(scoped_refptr<Layer> child);
90 void InsertChild(scoped_refptr<Layer> child, size_t index);
91 void ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer);
92 void RemoveFromParent();
93 void RemoveAllChildren();
94 void SetChildren(const LayerList& children);
[email protected]f659521e2013-07-26 00:27:0695 bool HasAncestor(const Layer* ancestor) const;
[email protected]cd57cc5a2012-10-12 22:43:4196
[email protected]7aba6662013-03-12 10:17:3497 const LayerList& children() const { return children_; }
98 Layer* child_at(size_t index) { return children_[index].get(); }
[email protected]cd57cc5a2012-10-12 22:43:4199
[email protected]0e5f7142013-05-24 06:45:36100 // This requests the layer and its subtree be rendered and given to the
101 // callback. If the copy is unable to be produced (the layer is destroyed
miua6ce94ca2015-03-31 20:21:22102 // first), then the callback is called with a nullptr/empty result. If the
103 // request's source property is set, any prior uncommitted requests having the
104 // same source will be aborted.
[email protected]0e5f7142013-05-24 06:45:36105 void RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> request);
106 bool HasCopyRequest() const {
107 return !copy_requests_.empty();
[email protected]18a70192013-04-26 16:18:25108 }
109
[email protected]7aba6662013-03-12 10:17:34110 virtual void SetBackgroundColor(SkColor background_color);
111 SkColor background_color() const { return background_color_; }
[email protected]2c4cbec2013-06-04 21:14:50112 // If contents_opaque(), return an opaque color else return a
113 // non-opaque color. Tries to return background_color(), if possible.
114 SkColor SafeOpaqueBackgroundColor() const;
[email protected]cd57cc5a2012-10-12 22:43:41115
[email protected]7aba6662013-03-12 10:17:34116 // A layer's bounds are in logical, non-page-scaled pixels (however, the
117 // root layer's bounds are in physical pixels).
[email protected]64348ea2014-01-29 22:58:26118 void SetBounds(const gfx::Size& bounds);
[email protected]7aba6662013-03-12 10:17:34119 gfx::Size bounds() const { return bounds_; }
[email protected]cd57cc5a2012-10-12 22:43:41120
[email protected]7aba6662013-03-12 10:17:34121 void SetMasksToBounds(bool masks_to_bounds);
122 bool masks_to_bounds() const { return masks_to_bounds_; }
[email protected]cd57cc5a2012-10-12 22:43:41123
[email protected]7aba6662013-03-12 10:17:34124 void SetMaskLayer(Layer* mask_layer);
125 Layer* mask_layer() { return mask_layer_.get(); }
126 const Layer* mask_layer() const { return mask_layer_.get(); }
[email protected]cd57cc5a2012-10-12 22:43:41127
danakj19f0c9e2014-10-11 03:24:42128 virtual void SetNeedsDisplayRect(const gfx::Rect& dirty_rect);
129 void SetNeedsDisplay() { SetNeedsDisplayRect(gfx::Rect(bounds())); }
[email protected]cd57cc5a2012-10-12 22:43:41130
[email protected]7aba6662013-03-12 10:17:34131 void SetOpacity(float opacity);
132 float opacity() const { return opacity_; }
133 bool OpacityIsAnimating() const;
loysod71ece82015-07-03 13:48:50134 bool HasPotentiallyRunningOpacityAnimation() const;
[email protected]b7c4783f2013-03-15 23:11:42135 virtual bool OpacityCanAnimateOnImplThread() const;
[email protected]cd57cc5a2012-10-12 22:43:41136
[email protected]7bbeaf4e2013-11-26 10:27:22137 void SetBlendMode(SkXfermode::Mode blend_mode);
138 SkXfermode::Mode blend_mode() const { return blend_mode_; }
139
jaydasika92239dc2015-08-15 02:59:26140 void set_draw_blend_mode(SkXfermode::Mode blend_mode) {
141 if (draw_blend_mode_ == blend_mode)
142 return;
143 draw_blend_mode_ = blend_mode;
144 SetNeedsPushProperties();
145 }
146 SkXfermode::Mode draw_blend_mode() const { return draw_blend_mode_; }
147
[email protected]7bbeaf4e2013-11-26 10:27:22148 bool uses_default_blend_mode() const {
149 return blend_mode_ == SkXfermode::kSrcOver_Mode;
150 }
151
152 // A layer is root for an isolated group when it and all its descendants are
153 // drawn over a black and fully transparent background, creating an isolated
154 // group. It should be used along with SetBlendMode(), in order to restrict
155 // layers within the group to blend with layers outside this group.
156 void SetIsRootForIsolatedGroup(bool root);
157 bool is_root_for_isolated_group() const {
158 return is_root_for_isolated_group_;
159 }
160
[email protected]ae6b1a72013-06-25 18:49:29161 void SetFilters(const FilterOperations& filters);
162 const FilterOperations& filters() const { return filters_; }
[email protected]b4c6d812013-10-03 15:48:56163 bool FilterIsAnimating() const;
ajuma315a4782015-07-24 21:16:34164 bool HasPotentiallyRunningFilterAnimation() const;
[email protected]cd57cc5a2012-10-12 22:43:41165
[email protected]7aba6662013-03-12 10:17:34166 // Background filters are filters applied to what is behind this layer, when
167 // they are viewed through non-opaque regions in this layer. They are used
168 // through the WebLayer interface, and are not exposed to HTML.
[email protected]ae6b1a72013-06-25 18:49:29169 void SetBackgroundFilters(const FilterOperations& filters);
170 const FilterOperations& background_filters() const {
[email protected]7aba6662013-03-12 10:17:34171 return background_filters_;
172 }
[email protected]cd57cc5a2012-10-12 22:43:41173
[email protected]7aba6662013-03-12 10:17:34174 virtual void SetContentsOpaque(bool opaque);
175 bool contents_opaque() const { return contents_opaque_; }
[email protected]cd57cc5a2012-10-12 22:43:41176
[email protected]14bc5d682014-01-17 07:26:47177 void SetPosition(const gfx::PointF& position);
[email protected]7aba6662013-03-12 10:17:34178 gfx::PointF position() const { return position_; }
[email protected]cd57cc5a2012-10-12 22:43:41179
ajuma4216ee122015-05-29 13:07:17180 // A layer that is a container for fixed position layers cannot be both
181 // scrollable and have a non-identity transform.
[email protected]7aba6662013-03-12 10:17:34182 void SetIsContainerForFixedPositionLayers(bool container);
[email protected]fe956c9c42013-04-09 04:26:33183 bool IsContainerForFixedPositionLayers() const;
[email protected]cd57cc5a2012-10-12 22:43:41184
miletus624d342e2015-03-13 03:39:44185 gfx::Vector2dF FixedContainerSizeDelta() const {
186 return gfx::Vector2dF();
187 }
188
[email protected]fe956c9c42013-04-09 04:26:33189 void SetPositionConstraint(const LayerPositionConstraint& constraint);
190 const LayerPositionConstraint& position_constraint() const {
191 return position_constraint_;
192 }
[email protected]cd57cc5a2012-10-12 22:43:41193
[email protected]7aba6662013-03-12 10:17:34194 void SetTransform(const gfx::Transform& transform);
195 const gfx::Transform& transform() const { return transform_; }
196 bool TransformIsAnimating() const;
loysod71ece82015-07-03 13:48:50197 bool HasPotentiallyRunningTransformAnimation() const;
ajumab4a846f22015-08-24 19:13:44198 bool HasOnlyTranslationTransforms() const;
awoloszyne83f28c2014-12-22 15:40:00199 bool AnimationsPreserveAxisAlignment() const;
[email protected]08bdf1b2014-04-16 23:23:29200 bool transform_is_invertible() const { return transform_is_invertible_; }
[email protected]cd57cc5a2012-10-12 22:43:41201
ajumab4a846f22015-08-24 19:13:44202 bool MaximumTargetScale(float* max_scale) const;
203 bool AnimationStartScale(float* start_scale) const;
204
[email protected]a2566412014-06-05 03:14:20205 void SetTransformOrigin(const gfx::Point3F&);
vollick51ed1a22014-12-17 02:03:00206 gfx::Point3F transform_origin() const { return transform_origin_; }
[email protected]a2566412014-06-05 03:14:20207
ajumacaaa9b32015-08-04 15:55:29208 bool HasAnyAnimationTargetingProperty(
209 Animation::TargetProperty property) const;
210
loysod71ece82015-07-03 13:48:50211 bool ScrollOffsetAnimationWasInterrupted() const;
212
[email protected]0e98cdd2013-08-23 00:44:30213 void SetScrollParent(Layer* parent);
214
215 Layer* scroll_parent() { return scroll_parent_; }
216 const Layer* scroll_parent() const { return scroll_parent_; }
217
218 void AddScrollChild(Layer* child);
219 void RemoveScrollChild(Layer* child);
220
221 std::set<Layer*>* scroll_children() { return scroll_children_.get(); }
222 const std::set<Layer*>* scroll_children() const {
223 return scroll_children_.get();
224 }
225
226 void SetClipParent(Layer* ancestor);
227
228 Layer* clip_parent() { return clip_parent_; }
229 const Layer* clip_parent() const {
230 return clip_parent_;
231 }
232
233 void AddClipChild(Layer* child);
234 void RemoveClipChild(Layer* child);
235
236 std::set<Layer*>* clip_children() { return clip_children_.get(); }
237 const std::set<Layer*>* clip_children() const {
238 return clip_children_.get();
239 }
240
ennec95e6622015-08-28 23:23:19241 // TODO(enne): Fix style here (and everywhere) once LayerImpl does the same.
242 gfx::Transform draw_transform() const;
243 gfx::Transform screen_space_transform() const;
[email protected]d76806f82012-12-05 21:41:50244
ennec95e6622015-08-28 23:23:19245 void set_num_unclipped_descendants(size_t descendants) {
246 num_unclipped_descendants_ = descendants;
[email protected]7aba6662013-03-12 10:17:34247 }
vmpstr762e70d2015-06-10 02:12:57248 size_t num_unclipped_descendants() const {
ennec95e6622015-08-28 23:23:19249 return num_unclipped_descendants_;
[email protected]420fdf6e2013-08-26 20:36:38250 }
[email protected]cd57cc5a2012-10-12 22:43:41251
miletusf57925d2014-10-01 19:38:13252 void SetScrollOffset(const gfx::ScrollOffset& scroll_offset);
miletusff93ab72015-01-30 04:30:44253 void SetScrollCompensationAdjustment(
254 const gfx::Vector2dF& scroll_compensation_adjustment);
255 gfx::Vector2dF ScrollCompensationAdjustment() const;
miletus2c78036b2015-01-29 20:52:37256
miletusf57925d2014-10-01 19:38:13257 gfx::ScrollOffset scroll_offset() const { return scroll_offset_; }
258 void SetScrollOffsetFromImplSide(const gfx::ScrollOffset& scroll_offset);
[email protected]cd57cc5a2012-10-12 22:43:41259
[email protected]adeda572014-01-31 00:49:47260 void SetScrollClipLayerId(int clip_layer_id);
261 bool scrollable() const { return scroll_clip_layer_id_ != INVALID_ID; }
[email protected]cd57cc5a2012-10-12 22:43:41262
[email protected]59a7d552013-10-22 03:36:43263 void SetUserScrollable(bool horizontal, bool vertical);
264 bool user_scrollable_horizontal() const {
265 return user_scrollable_horizontal_;
266 }
267 bool user_scrollable_vertical() const { return user_scrollable_vertical_; }
268
[email protected]7aba6662013-03-12 10:17:34269 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread);
270 bool should_scroll_on_main_thread() const {
271 return should_scroll_on_main_thread_;
272 }
[email protected]cd57cc5a2012-10-12 22:43:41273
[email protected]7aba6662013-03-12 10:17:34274 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers);
275 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_; }
[email protected]cd57cc5a2012-10-12 22:43:41276
[email protected]f998c532014-03-31 20:02:51277 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers);
278 bool have_scroll_event_handlers() const {
279 return have_scroll_event_handlers_;
280 }
281
[email protected]7aba6662013-03-12 10:17:34282 void SetNonFastScrollableRegion(const Region& non_fast_scrollable_region);
283 const Region& non_fast_scrollable_region() const {
284 return non_fast_scrollable_region_;
285 }
[email protected]cd57cc5a2012-10-12 22:43:41286
[email protected]7aba6662013-03-12 10:17:34287 void SetTouchEventHandlerRegion(const Region& touch_event_handler_region);
288 const Region& touch_event_handler_region() const {
289 return touch_event_handler_region_;
290 }
[email protected]23d56be2012-11-08 00:33:34291
rbyers18779d822015-02-05 06:22:06292 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on);
293 ScrollBlocksOn scroll_blocks_on() const { return scroll_blocks_on_; }
294
[email protected]28096ed2013-07-01 07:38:58295 void set_did_scroll_callback(const base::Closure& callback) {
296 did_scroll_callback_ = callback;
[email protected]7aba6662013-03-12 10:17:34297 }
[email protected]cd57cc5a2012-10-12 22:43:41298
[email protected]7aba6662013-03-12 10:17:34299 void SetForceRenderSurface(bool force_render_surface);
300 bool force_render_surface() const { return force_render_surface_; }
[email protected]cd57cc5a2012-10-12 22:43:41301
miletusf57925d2014-10-01 19:38:13302 gfx::Vector2dF ScrollDelta() const { return gfx::Vector2dF(); }
aeliasd0070ba2015-01-31 13:44:49303 gfx::ScrollOffset CurrentScrollOffset() const { return scroll_offset_; }
[email protected]cd57cc5a2012-10-12 22:43:41304
[email protected]7aba6662013-03-12 10:17:34305 void SetDoubleSided(bool double_sided);
306 bool double_sided() const { return double_sided_; }
[email protected]cd57cc5a2012-10-12 22:43:41307
[email protected]56fffdd2014-02-11 19:50:57308 void SetShouldFlattenTransform(bool flatten);
309 bool should_flatten_transform() const { return should_flatten_transform_; }
310
[email protected]a9d4d4f2014-06-19 06:49:28311 bool Is3dSorted() const { return sorting_context_id_ != 0; }
[email protected]cd57cc5a2012-10-12 22:43:41312
[email protected]7aba6662013-03-12 10:17:34313 void set_use_parent_backface_visibility(bool use) {
314 use_parent_backface_visibility_ = use;
315 }
316 bool use_parent_backface_visibility() const {
317 return use_parent_backface_visibility_;
318 }
[email protected]cd57cc5a2012-10-12 22:43:41319
[email protected]7aba6662013-03-12 10:17:34320 virtual void SetLayerTreeHost(LayerTreeHost* host);
[email protected]cd57cc5a2012-10-12 22:43:41321
[email protected]ad63b2f2014-08-11 17:39:54322 virtual bool HasDelegatedContent() const;
[email protected]7aba6662013-03-12 10:17:34323 bool HasContributingDelegatedRenderPasses() const { return false; }
[email protected]cd57cc5a2012-10-12 22:43:41324
[email protected]7aba6662013-03-12 10:17:34325 void SetIsDrawable(bool is_drawable);
[email protected]cd57cc5a2012-10-12 22:43:41326
[email protected]c0ae06c12013-06-24 18:32:19327 void SetHideLayerAndSubtree(bool hide);
328 bool hide_layer_and_subtree() const { return hide_layer_and_subtree_; }
329
[email protected]7aba6662013-03-12 10:17:34330 void SetReplicaLayer(Layer* layer);
331 Layer* replica_layer() { return replica_layer_.get(); }
332 const Layer* replica_layer() const { return replica_layer_.get(); }
[email protected]cd57cc5a2012-10-12 22:43:41333
[email protected]22898ed2013-06-01 04:52:30334 bool has_mask() const { return !!mask_layer_.get(); }
335 bool has_replica() const { return !!replica_layer_.get(); }
[email protected]7aba6662013-03-12 10:17:34336 bool replica_has_mask() const {
[email protected]22898ed2013-06-01 04:52:30337 return replica_layer_.get() &&
338 (mask_layer_.get() || replica_layer_->mask_layer_.get());
[email protected]7aba6662013-03-12 10:17:34339 }
[email protected]cd57cc5a2012-10-12 22:43:41340
[email protected]ad63b2f2014-08-11 17:39:54341 int NumDescendantsThatDrawContent() const;
342
343 // This is only virtual for tests.
344 // TODO(awoloszyn): Remove this once we no longer need it for tests
[email protected]7aba6662013-03-12 10:17:34345 virtual bool DrawsContent() const;
[email protected]ad63b2f2014-08-11 17:39:54346
347 // This methods typically need to be overwritten by derived classes.
[email protected]445881f2013-04-16 01:11:59348 virtual void SavePaintProperties();
danakj5f46636a2015-06-19 00:01:40349 // Returns true iff anything was updated that needs to be committed.
350 virtual bool Update();
[email protected]7aba6662013-03-12 10:17:34351 virtual void SetIsMask(bool is_mask) {}
[email protected]a6c1b232014-05-05 23:53:08352 virtual bool IsSuitableForGpuRasterization() const;
[email protected]cd57cc5a2012-10-12 22:43:41353
ssid911e40e2015-02-09 17:55:20354 virtual scoped_refptr<base::trace_event::ConvertableToTraceFormat>
355 TakeDebugInfo();
[email protected]ae716ce2013-08-16 13:04:24356
357 void SetLayerClient(LayerClient* client) { client_ = client; }
358
[email protected]7aba6662013-03-12 10:17:34359 virtual void PushPropertiesTo(LayerImpl* layer);
360
[email protected]3698e792013-08-24 00:21:16361 LayerTreeHost* layer_tree_host() { return layer_tree_host_; }
362 const LayerTreeHost* layer_tree_host() const { return layer_tree_host_; }
[email protected]cd57cc5a2012-10-12 22:43:41363
[email protected]7aba6662013-03-12 10:17:34364 bool AddAnimation(scoped_ptr<Animation> animation);
365 void PauseAnimation(int animation_id, double time_offset);
366 void RemoveAnimation(int animation_id);
sunnypsea328be12015-02-26 06:03:27367 void RemoveAnimation(int animation_id, Animation::TargetProperty property);
loysod71ece82015-07-03 13:48:50368 LayerAnimationController* layer_animation_controller() const {
[email protected]7aba6662013-03-12 10:17:34369 return layer_animation_controller_.get();
370 }
[email protected]7f5605c2013-04-08 18:08:35371 void SetLayerAnimationControllerForTest(
[email protected]7aba6662013-03-12 10:17:34372 scoped_refptr<LayerAnimationController> controller);
[email protected]cd57cc5a2012-10-12 22:43:41373
[email protected]3cae03e2013-06-26 22:13:52374 void set_layer_animation_delegate(AnimationDelegate* delegate) {
loyso57197782015-05-28 04:10:18375 DCHECK(layer_animation_controller_);
[email protected]7f5605c2013-04-08 18:08:35376 layer_animation_controller_->set_layer_animation_delegate(delegate);
[email protected]7aba6662013-03-12 10:17:34377 }
[email protected]cd57cc5a2012-10-12 22:43:41378
[email protected]7aba6662013-03-12 10:17:34379 bool HasActiveAnimation() const;
loyso57197782015-05-28 04:10:18380 void RegisterForAnimations(AnimationRegistrar* registrar);
[email protected]cd57cc5a2012-10-12 22:43:41381
[email protected]7aba6662013-03-12 10:17:34382 void AddLayerAnimationEventObserver(
383 LayerAnimationEventObserver* animation_observer);
384 void RemoveLayerAnimationEventObserver(
385 LayerAnimationEventObserver* animation_observer);
[email protected]cd57cc5a2012-10-12 22:43:41386
[email protected]80413d72013-08-30 20:25:33387 virtual ScrollbarLayerInterface* ToScrollbarLayer();
[email protected]cd57cc5a2012-10-12 22:43:41388
[email protected]f7837a92013-08-21 03:00:05389 virtual skia::RefPtr<SkPicture> GetPicture() const;
390
[email protected]7aba6662013-03-12 10:17:34391 // Constructs a LayerImpl of the correct runtime type for this Layer type.
392 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl);
[email protected]aedf4e52013-01-09 23:24:44393
[email protected]44604642013-08-01 01:14:09394 bool NeedsDisplayForTesting() const { return !update_rect_.IsEmpty(); }
danakj19f0c9e2014-10-11 03:24:42395 void ResetNeedsDisplayForTesting() { update_rect_ = gfx::Rect(); }
[email protected]48871fc2013-01-23 07:36:51396
[email protected]d84116612013-03-29 05:32:49397 RenderingStatsInstrumentation* rendering_stats_instrumentation() const;
398
[email protected]445881f2013-04-16 01:11:59399 const PaintProperties& paint_properties() const {
400 return paint_properties_;
401 }
402
[email protected]7a5a9322014-02-25 12:54:57403 void SetNeedsPushProperties();
[email protected]f4e25f92013-07-13 20:54:53404 bool needs_push_properties() const { return needs_push_properties_; }
405 bool descendant_needs_push_properties() const {
406 return num_dependents_need_push_properties_ > 0;
407 }
[email protected]7a5a9322014-02-25 12:54:57408 void reset_needs_push_properties_for_testing() {
409 needs_push_properties_ = false;
410 }
[email protected]f4e25f92013-07-13 20:54:53411
[email protected]666d7cf2013-10-12 01:30:29412 virtual void RunMicroBenchmark(MicroBenchmark* benchmark);
413
[email protected]a9d4d4f2014-06-19 06:49:28414 void Set3dSortingContextId(int id);
415 int sorting_context_id() const { return sorting_context_id_; }
416
vollick692444f2015-05-20 15:39:14417 void set_property_tree_sequence_number(int sequence_number) {
418 property_tree_sequence_number_ = sequence_number;
ennee95b1542015-04-20 20:35:50419 }
vollick692444f2015-05-20 15:39:14420
421 void SetTransformTreeIndex(int index);
422 int transform_tree_index() const;
423
424 void SetClipTreeIndex(int index);
425 int clip_tree_index() const;
426
weiliangc6a52f302015-08-18 16:29:35427 void SetEffectTreeIndex(int index);
428 int effect_tree_index() const;
vollick51ed1a22014-12-17 02:03:00429
430 void set_offset_to_transform_parent(gfx::Vector2dF offset) {
ennee95b1542015-04-20 20:35:50431 if (offset_to_transform_parent_ == offset)
432 return;
vollick51ed1a22014-12-17 02:03:00433 offset_to_transform_parent_ = offset;
ennee95b1542015-04-20 20:35:50434 SetNeedsPushProperties();
vollick51ed1a22014-12-17 02:03:00435 }
436 gfx::Vector2dF offset_to_transform_parent() const {
437 return offset_to_transform_parent_;
438 }
439
ennec95e6622015-08-28 23:23:19440 // TODO(enne): Once LayerImpl only uses property trees, remove these
441 // functions.
vollick51ed1a22014-12-17 02:03:00442 const gfx::Rect& visible_rect_from_property_trees() const {
ennec95e6622015-08-28 23:23:19443 return visible_layer_rect();
vollick51ed1a22014-12-17 02:03:00444 }
445 void set_visible_rect_from_property_trees(const gfx::Rect& rect) {
ennec95e6622015-08-28 23:23:19446 set_visible_layer_rect(rect);
vollick51ed1a22014-12-17 02:03:00447 }
jaydasika5c41bb92015-08-10 21:47:55448 const gfx::Rect& clip_rect_in_target_space_from_property_trees() const {
ennec95e6622015-08-28 23:23:19449 return clip_rect();
jaydasika5c41bb92015-08-10 21:47:55450 }
451 void set_clip_rect_in_target_space_from_property_trees(
452 const gfx::Rect& rect) {
ennec95e6622015-08-28 23:23:19453 set_clip_rect(rect);
jaydasika5c41bb92015-08-10 21:47:55454 }
ennec95e6622015-08-28 23:23:19455 // TODO(enne): This needs a different name. It is a calculated value
456 // from the property tree builder and not a synonym for "should
457 // flatten transform".
ajumad0d64422015-03-14 04:20:08458 void set_should_flatten_transform_from_property_tree(bool should_flatten) {
ennee95b1542015-04-20 20:35:50459 if (should_flatten_transform_from_property_tree_ == should_flatten)
460 return;
ajumad0d64422015-03-14 04:20:08461 should_flatten_transform_from_property_tree_ = should_flatten;
ennee95b1542015-04-20 20:35:50462 SetNeedsPushProperties();
463 }
464 bool should_flatten_transform_from_property_tree() const {
465 return should_flatten_transform_from_property_tree_;
ajumad0d64422015-03-14 04:20:08466 }
467
ennec95e6622015-08-28 23:23:19468 const gfx::Rect& visible_layer_rect() const { return visible_layer_rect_; }
469 void set_visible_layer_rect(const gfx::Rect& rect) {
470 visible_layer_rect_ = rect;
471 }
472
473 const gfx::Rect& clip_rect() const { return clip_rect_; }
474 void set_clip_rect(const gfx::Rect& rect) { clip_rect_ = rect; }
475
vollick51ed1a22014-12-17 02:03:00476 bool has_render_surface() const {
477 return has_render_surface_;
478 }
vollick51ed1a22014-12-17 02:03:00479
vmpstr3d1d72c2015-01-26 18:27:40480 // Sets new frame timing requests for this layer.
481 void SetFrameTimingRequests(const std::vector<FrameTimingRequest>& requests);
482
mpb39c5a2ef2015-04-22 23:46:15483 // Accessor for unit tests
484 const std::vector<FrameTimingRequest>& FrameTimingRequests() const {
485 return frame_timing_requests_;
486 }
487
caseq4a4b5582015-03-17 18:39:35488 void DidBeginTracing();
enne25041932015-09-25 19:42:01489 // TODO(weiliangc): this should move to the effect tree.
ennec95e6622015-08-28 23:23:19490 void set_num_layer_or_descendant_with_copy_request(
jaydasika3d10aa62015-05-06 17:50:44491 int num_layer_or_descendants_with_copy_request) {
492 num_layer_or_descendants_with_copy_request_ =
493 num_layer_or_descendants_with_copy_request;
494 }
ennec95e6622015-08-28 23:23:19495 int num_layer_or_descendants_with_copy_request() {
496 return num_layer_or_descendants_with_copy_request_;
497 }
jaydasika3d10aa62015-05-06 17:50:44498
jaydasika976cd10b2015-05-26 15:45:24499 void set_visited(bool visited);
500 bool visited();
501 void set_layer_or_descendant_is_drawn(bool layer_or_descendant_is_drawn);
502 bool layer_or_descendant_is_drawn();
503 void set_sorted_for_recursion(bool sorted_for_recursion);
504 bool sorted_for_recursion();
505
skyostile5cd4742015-10-13 12:09:53506 // LayerAnimationValueProvider implementation.
507 gfx::ScrollOffset ScrollOffsetForAnimation() const override;
508
509 // LayerAnimationValueObserver implementation.
510 void OnFilterAnimated(const FilterOperations& filters) override;
511 void OnOpacityAnimated(float opacity) override;
512 void OnTransformAnimated(const gfx::Transform& transform) override;
513 void OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) override;
514 void OnAnimationWaitingForDeletion() override;
515 void OnTransformIsPotentiallyAnimatingChanged(bool is_animating) override;
516 bool IsActive() const override;
517
[email protected]7aba6662013-03-12 10:17:34518 protected:
519 friend class LayerImpl;
520 friend class TreeSynchronizer;
dcheng716bedf2014-10-21 09:51:08521 ~Layer() override;
[email protected]090e1a72013-01-29 07:07:45522
loysoa6edaaff2015-05-25 03:26:44523 explicit Layer(const LayerSettings& settings);
[email protected]cd57cc5a2012-10-12 22:43:41524
[email protected]3519b872013-07-30 07:17:50525 // These SetNeeds functions are in order of severity of update:
526 //
527 // Called when this layer has been modified in some way, but isn't sure
528 // that it needs a commit yet. It needs CalcDrawProperties and UpdateLayers
529 // before it knows whether or not a commit is required.
530 void SetNeedsUpdate();
531 // Called when a property has been modified in a way that the layer
532 // knows immediately that a commit is required. This implies SetNeedsUpdate
533 // as well as SetNeedsPushProperties to push that property.
[email protected]7aba6662013-03-12 10:17:34534 void SetNeedsCommit();
vollick5057e1e2015-04-17 19:12:32535 // This is identical to SetNeedsCommit, but the former requests a rebuild of
536 // the property trees.
537 void SetNeedsCommitNoRebuild();
[email protected]3519b872013-07-30 07:17:50538 // Called when there's been a change in layer structure. Implies both
539 // SetNeedsUpdate and SetNeedsCommit, but not SetNeedsPushProperties.
[email protected]7aba6662013-03-12 10:17:34540 void SetNeedsFullTreeSync();
[email protected]74b43cc2013-08-30 06:29:27541
542 // Called when the next commit should wait until the pending tree is activated
543 // before finishing the commit and unblocking the main thread. Used to ensure
544 // unused resources on the impl thread are returned before commit completes.
545 void SetNextCommitWaitsForActivation();
[email protected]cd57cc5a2012-10-12 22:43:41546
[email protected]ad63b2f2014-08-11 17:39:54547 // Will recalculate whether the layer draws content and set draws_content_
548 // appropriately.
549 void UpdateDrawsContent(bool has_drawable_content);
550 virtual bool HasDrawableContent() const;
551
552 // Called when the layer's number of drawable descendants changes.
553 void AddDrawableDescendants(int num);
554
[email protected]f4e25f92013-07-13 20:54:53555 void AddDependentNeedsPushProperties();
556 void RemoveDependentNeedsPushProperties();
557 bool parent_should_know_need_push_properties() const {
558 return needs_push_properties() || descendant_needs_push_properties();
559 }
560
[email protected]74b43cc2013-08-30 06:29:27561 bool IsPropertyChangeAllowed() const;
562
[email protected]f4e25f92013-07-13 20:54:53563 // This flag is set when the layer needs to push properties to the impl
564 // side.
565 bool needs_push_properties_;
566
567 // The number of direct children or dependent layers that need to be recursed
568 // to in order for them or a descendent of them to push properties to the impl
569 // side.
570 int num_dependents_need_push_properties_;
571
[email protected]7aba6662013-03-12 10:17:34572 // Tracks whether this layer may have changed stacking order with its
573 // siblings.
574 bool stacking_order_changed_;
[email protected]cd57cc5a2012-10-12 22:43:41575
[email protected]7aba6662013-03-12 10:17:34576 // The update rect is the region of the compositor resource that was
577 // actually updated by the compositor. For layers that may do updating
578 // outside the compositor's control (i.e. plugin layers), this information
579 // is not available and the update rect will remain empty.
580 // Note this rect is in layer space (not content space).
danakj19f0c9e2014-10-11 03:24:42581 gfx::Rect update_rect_;
[email protected]cd57cc5a2012-10-12 22:43:41582
[email protected]7aba6662013-03-12 10:17:34583 scoped_refptr<Layer> mask_layer_;
[email protected]cd57cc5a2012-10-12 22:43:41584
[email protected]7aba6662013-03-12 10:17:34585 int layer_id_;
[email protected]cd57cc5a2012-10-12 22:43:41586
[email protected]7aba6662013-03-12 10:17:34587 // When true, the layer is about to perform an update. Any commit requests
[email protected]3519b872013-07-30 07:17:50588 // will be handled implicitly after the update completes.
[email protected]7aba6662013-03-12 10:17:34589 bool ignore_set_needs_commit_;
[email protected]cd57cc5a2012-10-12 22:43:41590
[email protected]a9d4d4f2014-06-19 06:49:28591 // Layers that share a sorting context id will be sorted together in 3d
592 // space. 0 is a special value that means this layer will not be sorted and
593 // will be drawn in paint order.
594 int sorting_context_id_;
595
[email protected]7aba6662013-03-12 10:17:34596 private:
597 friend class base::RefCounted<Layer>;
awoloszyne83f28c2014-12-22 15:40:00598 friend class LayerTreeHostCommon;
[email protected]7aba6662013-03-12 10:17:34599 void SetParent(Layer* layer);
[email protected]7aba6662013-03-12 10:17:34600 bool DescendantIsFixedToContainerLayer() const;
[email protected]cd57cc5a2012-10-12 22:43:41601
awoloszyne83f28c2014-12-22 15:40:00602 // This should only be called during BeginMainFrame since it does not
603 // trigger a Commit.
604 void SetHasRenderSurface(bool has_render_surface);
605
[email protected]7aba6662013-03-12 10:17:34606 // This should only be called from RemoveFromParent().
607 void RemoveChildOrDependent(Layer* child);
[email protected]cd57cc5a2012-10-12 22:43:41608
vollick66133e82014-09-13 20:36:44609 // If this layer has a scroll parent, it removes |this| from its list of
610 // scroll children.
611 void RemoveFromScrollTree();
612
613 // If this layer has a clip parent, it removes |this| from its list of clip
614 // children.
615 void RemoveFromClipTree();
616
weiliangcc4d2e74d2015-06-09 01:21:35617 // When we detach or attach layer to new LayerTreeHost, all property trees'
618 // indices becomes invalid.
619 void InvalidatePropertyTreesIndices();
620
enne25041932015-09-25 19:42:01621 void UpdateNumCopyRequestsForSubtree(int delta);
jaydasika3d10aa62015-05-06 17:50:44622
[email protected]7aba6662013-03-12 10:17:34623 LayerList children_;
624 Layer* parent_;
[email protected]de4afb5e2012-12-20 00:11:34625
[email protected]7aba6662013-03-12 10:17:34626 // Layer instances have a weak pointer to their LayerTreeHost.
627 // This pointer value is nil when a Layer is not in a tree and is
628 // updated via SetLayerTreeHost() if a layer moves between trees.
629 LayerTreeHost* layer_tree_host_;
[email protected]cd57cc5a2012-10-12 22:43:41630
[email protected]7aba6662013-03-12 10:17:34631 scoped_refptr<LayerAnimationController> layer_animation_controller_;
[email protected]de4afb5e2012-12-20 00:11:34632
[email protected]7aba6662013-03-12 10:17:34633 // Layer properties.
634 gfx::Size bounds_;
[email protected]cd57cc5a2012-10-12 22:43:41635
miletusf57925d2014-10-01 19:38:13636 gfx::ScrollOffset scroll_offset_;
miletusff93ab72015-01-30 04:30:44637 gfx::Vector2dF scroll_compensation_adjustment_;
[email protected]adeda572014-01-31 00:49:47638 // This variable indicates which ancestor layer (if any) whose size,
639 // transformed relative to this layer, defines the maximum scroll offset for
640 // this layer.
641 int scroll_clip_layer_id_;
[email protected]ad63b2f2014-08-11 17:39:54642 int num_descendants_that_draw_content_;
vollick51ed1a22014-12-17 02:03:00643 int transform_tree_index_;
weiliangc6a52f302015-08-18 16:29:35644 int effect_tree_index_;
vollick51ed1a22014-12-17 02:03:00645 int clip_tree_index_;
vollick692444f2015-05-20 15:39:14646 int property_tree_sequence_number_;
jaydasika3d10aa62015-05-06 17:50:44647 int num_layer_or_descendants_with_copy_request_;
vollick51ed1a22014-12-17 02:03:00648 gfx::Vector2dF offset_to_transform_parent_;
ajumad0d64422015-03-14 04:20:08649 bool should_flatten_transform_from_property_tree_ : 1;
[email protected]c55f3fc2013-12-10 05:48:48650 bool should_scroll_on_main_thread_ : 1;
651 bool have_wheel_event_handlers_ : 1;
[email protected]f998c532014-03-31 20:02:51652 bool have_scroll_event_handlers_ : 1;
[email protected]c55f3fc2013-12-10 05:48:48653 bool user_scrollable_horizontal_ : 1;
654 bool user_scrollable_vertical_ : 1;
655 bool is_root_for_isolated_group_ : 1;
656 bool is_container_for_fixed_position_layers_ : 1;
657 bool is_drawable_ : 1;
[email protected]ad63b2f2014-08-11 17:39:54658 bool draws_content_ : 1;
[email protected]c55f3fc2013-12-10 05:48:48659 bool hide_layer_and_subtree_ : 1;
660 bool masks_to_bounds_ : 1;
661 bool contents_opaque_ : 1;
662 bool double_sided_ : 1;
[email protected]56fffdd2014-02-11 19:50:57663 bool should_flatten_transform_ : 1;
[email protected]c55f3fc2013-12-10 05:48:48664 bool use_parent_backface_visibility_ : 1;
[email protected]c55f3fc2013-12-10 05:48:48665 bool force_render_surface_ : 1;
[email protected]08bdf1b2014-04-16 23:23:29666 bool transform_is_invertible_ : 1;
vollick51ed1a22014-12-17 02:03:00667 bool has_render_surface_ : 1;
rbyers18779d822015-02-05 06:22:06668 ScrollBlocksOn scroll_blocks_on_ : 3;
[email protected]7aba6662013-03-12 10:17:34669 Region non_fast_scrollable_region_;
670 Region touch_event_handler_region_;
671 gfx::PointF position_;
[email protected]7aba6662013-03-12 10:17:34672 SkColor background_color_;
[email protected]7aba6662013-03-12 10:17:34673 float opacity_;
[email protected]7bbeaf4e2013-11-26 10:27:22674 SkXfermode::Mode blend_mode_;
jaydasika92239dc2015-08-15 02:59:26675 // draw_blend_mode may be different than blend_mode_,
676 // when a RenderSurface re-parents the layer's blend_mode.
677 SkXfermode::Mode draw_blend_mode_;
[email protected]ae6b1a72013-06-25 18:49:29678 FilterOperations filters_;
679 FilterOperations background_filters_;
[email protected]fe956c9c42013-04-09 04:26:33680 LayerPositionConstraint position_constraint_;
[email protected]0e98cdd2013-08-23 00:44:30681 Layer* scroll_parent_;
danakj6496cba2014-10-16 01:31:08682 scoped_ptr<std::set<Layer*>> scroll_children_;
[email protected]0e98cdd2013-08-23 00:44:30683
jaydasika976cd10b2015-05-26 15:45:24684 // The following three variables are tracker variables. They are bools
685 // wrapped inside an integer variable. If true, their value equals the
686 // LayerTreeHost's meta_information_sequence_number. This wrapping of bools
687 // inside ints is done to avoid a layer tree treewalk to reset their values.
688 int layer_or_descendant_is_drawn_tracker_;
689 int sorted_for_recursion_tracker_;
690 int visited_tracker_;
691
[email protected]0e98cdd2013-08-23 00:44:30692 Layer* clip_parent_;
danakj6496cba2014-10-16 01:31:08693 scoped_ptr<std::set<Layer*>> clip_children_;
[email protected]cd57cc5a2012-10-12 22:43:41694
[email protected]7aba6662013-03-12 10:17:34695 gfx::Transform transform_;
[email protected]a2566412014-06-05 03:14:20696 gfx::Point3F transform_origin_;
[email protected]cd57cc5a2012-10-12 22:43:41697
[email protected]7aba6662013-03-12 10:17:34698 // Replica layer used for reflections.
699 scoped_refptr<Layer> replica_layer_;
[email protected]cd57cc5a2012-10-12 22:43:41700
[email protected]ae716ce2013-08-16 13:04:24701 LayerClient* client_;
702
[email protected]0e5f7142013-05-24 06:45:36703 ScopedPtrVector<CopyOutputRequest> copy_requests_;
[email protected]18a70192013-04-26 16:18:25704
[email protected]28096ed2013-07-01 07:38:58705 base::Closure did_scroll_callback_;
[email protected]cd57cc5a2012-10-12 22:43:41706
[email protected]445881f2013-04-16 01:11:59707 PaintProperties paint_properties_;
708
ennec95e6622015-08-28 23:23:19709 // These all act like draw properties, so don't need push properties.
710 gfx::Rect visible_layer_rect_;
711 gfx::Rect clip_rect_;
712 size_t num_unclipped_descendants_;
vmpstr3d1d72c2015-01-26 18:27:40713
714 std::vector<FrameTimingRequest> frame_timing_requests_;
715 bool frame_timing_requests_dirty_;
716
[email protected]7aba6662013-03-12 10:17:34717 DISALLOW_COPY_AND_ASSIGN(Layer);
[email protected]cd57cc5a2012-10-12 22:43:41718};
719
[email protected]ddf9df82012-10-16 06:52:46720} // namespace cc
721
[email protected]cc3cfaa2013-03-18 09:05:52722#endif // CC_LAYERS_LAYER_H_