blob: 6821f12d8bd5deac88f0e7902058ee7c471b475d [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
avi02a4d172015-12-21 06:14:368#include <stddef.h>
9#include <stdint.h>
10
[email protected]0e98cdd2013-08-23 00:44:3011#include <set>
[email protected]c8686a02012-11-27 08:29:0012#include <string>
davidben5877ffe2016-01-28 00:29:5113#include <unordered_map>
vmpstr3d1d72c2015-01-26 18:27:4014#include <vector>
[email protected]c8686a02012-11-27 08:29:0015
[email protected]18a70192013-04-26 16:18:2516#include "base/callback.h"
avi02a4d172015-12-21 06:14:3617#include "base/macros.h"
[email protected]a8461d82012-10-16 21:11:1418#include "base/memory/ref_counted.h"
[email protected]e10cd022012-12-18 00:32:2619#include "base/observer_list.h"
vollickef2ae922016-06-29 17:54:2720#include "cc/animation/element_id.h"
loyso9556c732016-03-11 07:54:5821#include "cc/animation/target_property.h"
[email protected]681ccff2013-03-18 06:13:5222#include "cc/base/cc_export.h"
23#include "cc/base/region.h"
[email protected]666d7cf2013-10-12 01:30:2924#include "cc/debug/micro_benchmark.h"
tdresser81e84c672016-01-18 23:21:2225#include "cc/input/input_handler.h"
vollick83fbfc82016-03-22 18:33:2726#include "cc/layers/layer_collections.h"
[email protected]fe956c9c42013-04-09 04:26:3327#include "cc/layers/layer_position_constraint.h"
[email protected]445881f2013-04-16 01:11:5928#include "cc/layers/paint_properties.h"
[email protected]ae6b1a72013-06-25 18:49:2929#include "cc/output/filter_operations.h"
khushalsagaraf222d92016-07-08 21:19:3230#include "cc/trees/mutator_host_client.h"
vollick51ed1a22014-12-17 02:03:0031#include "cc/trees/property_tree.h"
[email protected]ddf9df82012-10-16 06:52:4632#include "third_party/skia/include/core/SkColor.h"
[email protected]f7837a92013-08-21 03:00:0533#include "third_party/skia/include/core/SkPicture.h"
[email protected]7bbeaf4e2013-11-26 10:27:2234#include "third_party/skia/include/core/SkXfermode.h"
heejin.r.chungd28506ba2014-10-23 16:36:2035#include "ui/gfx/geometry/point3_f.h"
36#include "ui/gfx/geometry/rect.h"
37#include "ui/gfx/geometry/rect_f.h"
miletusf57925d2014-10-01 19:38:1338#include "ui/gfx/geometry/scroll_offset.h"
[email protected]c8686a02012-11-27 08:29:0039#include "ui/gfx/transform.h"
[email protected]cd57cc5a2012-10-12 22:43:4140
[email protected]db2586f2013-08-15 22:03:1441namespace gfx {
42class BoxF;
43}
44
[email protected]9f3be432013-12-03 03:53:2245namespace base {
primiano15960432015-02-05 14:20:2646namespace trace_event {
[email protected]9f3be432013-12-03 03:53:2247class ConvertableToTraceFormat;
48}
49}
50
[email protected]cd57cc5a2012-10-12 22:43:4151namespace cc {
52
khushalsagaraf222d92016-07-08 21:19:3253class AnimationHost;
[email protected]0e5f7142013-05-24 06:45:3654class CopyOutputRequest;
[email protected]7f5605c2013-04-08 18:08:3555class LayerAnimationEventObserver;
[email protected]ae716ce2013-08-16 13:04:2456class LayerClient;
[email protected]96baf3e2012-10-22 23:09:5557class LayerImpl;
58class LayerTreeHost;
awoloszyne83f28c2014-12-22 15:40:0059class LayerTreeHostCommon;
[email protected]8bef40572012-12-11 21:38:0860class LayerTreeImpl;
loyso57197782015-05-28 04:10:1861class LayerTreeSettings;
[email protected]d84116612013-03-29 05:32:4962class RenderingStatsInstrumentation;
[email protected]b4da2032012-10-25 21:22:5563class ResourceUpdateQueue;
[email protected]80413d72013-08-30 20:25:3364class ScrollbarLayerInterface;
[email protected]d5467eb72014-08-22 01:16:4365class SimpleEnclosedRegion;
[email protected]cd57cc5a2012-10-12 22:43:4166
nyquist353b7d52015-11-06 22:26:5367namespace proto {
68class LayerNode;
nyquistbc1290a2015-11-18 16:09:5669class LayerProperties;
70class LayerUpdate;
nyquist353b7d52015-11-06 22:26:5371} // namespace proto
72
[email protected]cd57cc5a2012-10-12 22:43:4173// Base class for composited layers. Special layer types are derived from
74// this class.
loyso9556c732016-03-11 07:54:5875class CC_EXPORT Layer : public base::RefCounted<Layer> {
[email protected]7aba6662013-03-12 10:17:3476 public:
davidben5877ffe2016-01-28 00:29:5177 using LayerListType = LayerList;
78 using LayerIdMap = std::unordered_map<int, scoped_refptr<Layer>>;
[email protected]44d8e84c2013-10-19 19:13:2279
[email protected]b7c4783f2013-03-15 23:11:4280 enum LayerIdLabels {
[email protected]b7c4783f2013-03-15 23:11:4281 INVALID_ID = -1,
82 };
[email protected]cd57cc5a2012-10-12 22:43:4183
loyso0940d412016-03-14 01:30:3184 static scoped_refptr<Layer> Create();
[email protected]cd57cc5a2012-10-12 22:43:4185
khushalsagarb51998f2016-07-08 01:04:2186 int id() const { return inputs_.layer_id; }
[email protected]cd57cc5a2012-10-12 22:43:4187
[email protected]7aba6662013-03-12 10:17:3488 Layer* RootLayer();
89 Layer* parent() { return parent_; }
90 const Layer* parent() const { return parent_; }
91 void AddChild(scoped_refptr<Layer> child);
92 void InsertChild(scoped_refptr<Layer> child, size_t index);
93 void ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer);
94 void RemoveFromParent();
95 void RemoveAllChildren();
96 void SetChildren(const LayerList& children);
[email protected]f659521e2013-07-26 00:27:0697 bool HasAncestor(const Layer* ancestor) const;
[email protected]cd57cc5a2012-10-12 22:43:4198
khushalsagarb51998f2016-07-08 01:04:2199 const LayerList& children() const { return inputs_.children; }
100 Layer* child_at(size_t index) { return inputs_.children[index].get(); }
[email protected]cd57cc5a2012-10-12 22:43:41101
[email protected]0e5f7142013-05-24 06:45:36102 // This requests the layer and its subtree be rendered and given to the
103 // callback. If the copy is unable to be produced (the layer is destroyed
miua6ce94ca2015-03-31 20:21:22104 // first), then the callback is called with a nullptr/empty result. If the
105 // request's source property is set, any prior uncommitted requests having the
106 // same source will be aborted.
danakj60bc3bc2016-04-09 00:24:48107 void RequestCopyOfOutput(std::unique_ptr<CopyOutputRequest> request);
khushalsagarb51998f2016-07-08 01:04:21108 bool HasCopyRequest() const { return !inputs_.copy_requests.empty(); }
[email protected]18a70192013-04-26 16:18:25109
ajumae6f541b2016-05-31 16:50:50110 void TakeCopyRequests(
111 std::vector<std::unique_ptr<CopyOutputRequest>>* requests);
112
[email protected]7aba6662013-03-12 10:17:34113 virtual void SetBackgroundColor(SkColor background_color);
khushalsagarb51998f2016-07-08 01:04:21114 SkColor background_color() const { return inputs_.background_color; }
jaydasikac6326bb2016-03-03 03:46:14115 void SetSafeOpaqueBackgroundColor(SkColor background_color);
[email protected]2c4cbec2013-06-04 21:14:50116 // If contents_opaque(), return an opaque color else return a
117 // non-opaque color. Tries to return background_color(), if possible.
118 SkColor SafeOpaqueBackgroundColor() const;
[email protected]cd57cc5a2012-10-12 22:43:41119
[email protected]7aba6662013-03-12 10:17:34120 // A layer's bounds are in logical, non-page-scaled pixels (however, the
121 // root layer's bounds are in physical pixels).
[email protected]64348ea2014-01-29 22:58:26122 void SetBounds(const gfx::Size& bounds);
khushalsagarb51998f2016-07-08 01:04:21123 gfx::Size bounds() const { return inputs_.bounds; }
[email protected]cd57cc5a2012-10-12 22:43:41124
[email protected]7aba6662013-03-12 10:17:34125 void SetMasksToBounds(bool masks_to_bounds);
khushalsagarb51998f2016-07-08 01:04:21126 bool masks_to_bounds() const { return inputs_.masks_to_bounds; }
[email protected]cd57cc5a2012-10-12 22:43:41127
[email protected]7aba6662013-03-12 10:17:34128 void SetMaskLayer(Layer* mask_layer);
khushalsagarb51998f2016-07-08 01:04:21129 Layer* mask_layer() { return inputs_.mask_layer.get(); }
130 const Layer* mask_layer() const { return inputs_.mask_layer.get(); }
[email protected]cd57cc5a2012-10-12 22:43:41131
danakj19f0c9e2014-10-11 03:24:42132 virtual void SetNeedsDisplayRect(const gfx::Rect& dirty_rect);
133 void SetNeedsDisplay() { SetNeedsDisplayRect(gfx::Rect(bounds())); }
[email protected]cd57cc5a2012-10-12 22:43:41134
jaydasika3093be3a2016-05-25 19:23:55135 virtual void SetOpacity(float opacity);
khushalsagarb51998f2016-07-08 01:04:21136 float opacity() const { return inputs_.opacity; }
jaydasika86654512016-01-27 17:05:07137 float EffectiveOpacity() const;
[email protected]b7c4783f2013-03-15 23:11:42138 virtual bool OpacityCanAnimateOnImplThread() const;
[email protected]cd57cc5a2012-10-12 22:43:41139
jaydasikaae9b7a02016-05-19 16:12:52140 virtual bool AlwaysUseActiveTreeOpacity() const;
141
[email protected]7bbeaf4e2013-11-26 10:27:22142 void SetBlendMode(SkXfermode::Mode blend_mode);
khushalsagarb51998f2016-07-08 01:04:21143 SkXfermode::Mode blend_mode() const { return inputs_.blend_mode; }
[email protected]7bbeaf4e2013-11-26 10:27:22144
jaydasika92239dc2015-08-15 02:59:26145 void set_draw_blend_mode(SkXfermode::Mode blend_mode) {
146 if (draw_blend_mode_ == blend_mode)
147 return;
148 draw_blend_mode_ = blend_mode;
149 SetNeedsPushProperties();
150 }
151 SkXfermode::Mode draw_blend_mode() const { return draw_blend_mode_; }
152
[email protected]7bbeaf4e2013-11-26 10:27:22153 // A layer is root for an isolated group when it and all its descendants are
154 // drawn over a black and fully transparent background, creating an isolated
155 // group. It should be used along with SetBlendMode(), in order to restrict
156 // layers within the group to blend with layers outside this group.
157 void SetIsRootForIsolatedGroup(bool root);
158 bool is_root_for_isolated_group() const {
khushalsagarb51998f2016-07-08 01:04:21159 return inputs_.is_root_for_isolated_group;
[email protected]7bbeaf4e2013-11-26 10:27:22160 }
161
[email protected]ae6b1a72013-06-25 18:49:29162 void SetFilters(const FilterOperations& filters);
khushalsagarb51998f2016-07-08 01:04:21163 const FilterOperations& filters() const { return inputs_.filters; }
[email protected]cd57cc5a2012-10-12 22:43:41164
[email protected]7aba6662013-03-12 10:17:34165 // Background filters are filters applied to what is behind this layer, when
166 // they are viewed through non-opaque regions in this layer. They are used
167 // through the WebLayer interface, and are not exposed to HTML.
[email protected]ae6b1a72013-06-25 18:49:29168 void SetBackgroundFilters(const FilterOperations& filters);
169 const FilterOperations& background_filters() const {
khushalsagarb51998f2016-07-08 01:04:21170 return inputs_.background_filters;
[email protected]7aba6662013-03-12 10:17:34171 }
[email protected]cd57cc5a2012-10-12 22:43:41172
[email protected]7aba6662013-03-12 10:17:34173 virtual void SetContentsOpaque(bool opaque);
khushalsagarb51998f2016-07-08 01:04:21174 bool contents_opaque() const { return inputs_.contents_opaque; }
[email protected]cd57cc5a2012-10-12 22:43:41175
[email protected]14bc5d682014-01-17 07:26:47176 void SetPosition(const gfx::PointF& position);
khushalsagarb51998f2016-07-08 01:04:21177 gfx::PointF position() const { return inputs_.position; }
[email protected]cd57cc5a2012-10-12 22:43:41178
ajuma4216ee122015-05-29 13:07:17179 // A layer that is a container for fixed position layers cannot be both
180 // scrollable and have a non-identity transform.
[email protected]7aba6662013-03-12 10:17:34181 void SetIsContainerForFixedPositionLayers(bool container);
[email protected]fe956c9c42013-04-09 04:26:33182 bool IsContainerForFixedPositionLayers() const;
[email protected]cd57cc5a2012-10-12 22:43:41183
miletus624d342e2015-03-13 03:39:44184 gfx::Vector2dF FixedContainerSizeDelta() const {
185 return gfx::Vector2dF();
186 }
187
[email protected]fe956c9c42013-04-09 04:26:33188 void SetPositionConstraint(const LayerPositionConstraint& constraint);
189 const LayerPositionConstraint& position_constraint() const {
khushalsagarb51998f2016-07-08 01:04:21190 return inputs_.position_constraint;
[email protected]fe956c9c42013-04-09 04:26:33191 }
[email protected]cd57cc5a2012-10-12 22:43:41192
[email protected]7aba6662013-03-12 10:17:34193 void SetTransform(const gfx::Transform& transform);
khushalsagarb51998f2016-07-08 01:04:21194 const gfx::Transform& transform() const { return inputs_.transform; }
ajumab4a846f22015-08-24 19:13:44195
[email protected]a2566412014-06-05 03:14:20196 void SetTransformOrigin(const gfx::Point3F&);
khushalsagarb51998f2016-07-08 01:04:21197 gfx::Point3F transform_origin() const { return inputs_.transform_origin; }
[email protected]a2566412014-06-05 03:14:20198
[email protected]0e98cdd2013-08-23 00:44:30199 void SetScrollParent(Layer* parent);
200
khushalsagarb51998f2016-07-08 01:04:21201 Layer* scroll_parent() { return inputs_.scroll_parent; }
202 const Layer* scroll_parent() const { return inputs_.scroll_parent; }
[email protected]0e98cdd2013-08-23 00:44:30203
[email protected]0e98cdd2013-08-23 00:44:30204 std::set<Layer*>* scroll_children() { return scroll_children_.get(); }
205 const std::set<Layer*>* scroll_children() const {
206 return scroll_children_.get();
207 }
208
209 void SetClipParent(Layer* ancestor);
210
khushalsagarb51998f2016-07-08 01:04:21211 Layer* clip_parent() { return inputs_.clip_parent; }
212 const Layer* clip_parent() const { return inputs_.clip_parent; }
[email protected]0e98cdd2013-08-23 00:44:30213
[email protected]0e98cdd2013-08-23 00:44:30214 std::set<Layer*>* clip_children() { return clip_children_.get(); }
215 const std::set<Layer*>* clip_children() const {
216 return clip_children_.get();
217 }
218
ennec95e6622015-08-28 23:23:19219 // TODO(enne): Fix style here (and everywhere) once LayerImpl does the same.
ennec95e6622015-08-28 23:23:19220 gfx::Transform screen_space_transform() const;
[email protected]d76806f82012-12-05 21:41:50221
ennec95e6622015-08-28 23:23:19222 void set_num_unclipped_descendants(size_t descendants) {
223 num_unclipped_descendants_ = descendants;
[email protected]7aba6662013-03-12 10:17:34224 }
vmpstr762e70d2015-06-10 02:12:57225 size_t num_unclipped_descendants() const {
ennec95e6622015-08-28 23:23:19226 return num_unclipped_descendants_;
[email protected]420fdf6e2013-08-26 20:36:38227 }
[email protected]cd57cc5a2012-10-12 22:43:41228
miletusf57925d2014-10-01 19:38:13229 void SetScrollOffset(const gfx::ScrollOffset& scroll_offset);
miletus2c78036b2015-01-29 20:52:37230
khushalsagarb51998f2016-07-08 01:04:21231 gfx::ScrollOffset scroll_offset() const { return inputs_.scroll_offset; }
miletusf57925d2014-10-01 19:38:13232 void SetScrollOffsetFromImplSide(const gfx::ScrollOffset& scroll_offset);
[email protected]cd57cc5a2012-10-12 22:43:41233
[email protected]adeda572014-01-31 00:49:47234 void SetScrollClipLayerId(int clip_layer_id);
khushalsagarb51998f2016-07-08 01:04:21235 bool scrollable() const { return inputs_.scroll_clip_layer_id != INVALID_ID; }
sunxdcfccd1b32016-02-11 00:54:20236 Layer* scroll_clip_layer() const;
[email protected]cd57cc5a2012-10-12 22:43:41237
[email protected]59a7d552013-10-22 03:36:43238 void SetUserScrollable(bool horizontal, bool vertical);
239 bool user_scrollable_horizontal() const {
khushalsagarb51998f2016-07-08 01:04:21240 return inputs_.user_scrollable_horizontal;
[email protected]59a7d552013-10-22 03:36:43241 }
khushalsagarb51998f2016-07-08 01:04:21242 bool user_scrollable_vertical() const {
243 return inputs_.user_scrollable_vertical;
244 }
[email protected]59a7d552013-10-22 03:36:43245
danakj35904762016-01-21 20:49:40246 void AddMainThreadScrollingReasons(uint32_t main_thread_scrolling_reasons);
ymalik002b8a252016-02-25 02:44:24247 void ClearMainThreadScrollingReasons(
248 uint32_t main_thread_scrolling_reasons_to_clear);
sunxd29f17bf422016-02-03 02:47:48249 uint32_t main_thread_scrolling_reasons() const {
khushalsagarb51998f2016-07-08 01:04:21250 return inputs_.main_thread_scrolling_reasons;
sunxd29f17bf422016-02-03 02:47:48251 }
[email protected]7aba6662013-03-12 10:17:34252 bool should_scroll_on_main_thread() const {
khushalsagarb51998f2016-07-08 01:04:21253 return !!inputs_.main_thread_scrolling_reasons;
[email protected]7aba6662013-03-12 10:17:34254 }
[email protected]cd57cc5a2012-10-12 22:43:41255
[email protected]7aba6662013-03-12 10:17:34256 void SetNonFastScrollableRegion(const Region& non_fast_scrollable_region);
257 const Region& non_fast_scrollable_region() const {
khushalsagarb51998f2016-07-08 01:04:21258 return inputs_.non_fast_scrollable_region;
[email protected]7aba6662013-03-12 10:17:34259 }
[email protected]cd57cc5a2012-10-12 22:43:41260
[email protected]7aba6662013-03-12 10:17:34261 void SetTouchEventHandlerRegion(const Region& touch_event_handler_region);
262 const Region& touch_event_handler_region() const {
khushalsagarb51998f2016-07-08 01:04:21263 return inputs_.touch_event_handler_region;
[email protected]7aba6662013-03-12 10:17:34264 }
[email protected]23d56be2012-11-08 00:33:34265
[email protected]28096ed2013-07-01 07:38:58266 void set_did_scroll_callback(const base::Closure& callback) {
khushalsagarb51998f2016-07-08 01:04:21267 inputs_.did_scroll_callback = callback;
[email protected]7aba6662013-03-12 10:17:34268 }
[email protected]cd57cc5a2012-10-12 22:43:41269
jaydasika6b5a32bf2016-04-22 21:56:36270 void SetForceRenderSurfaceForTesting(bool force_render_surface);
271 bool force_render_surface_for_testing() const {
272 return force_render_surface_for_testing_;
273 }
[email protected]cd57cc5a2012-10-12 22:43:41274
khushalsagarb51998f2016-07-08 01:04:21275 gfx::ScrollOffset CurrentScrollOffset() const {
276 return inputs_.scroll_offset;
277 }
[email protected]cd57cc5a2012-10-12 22:43:41278
[email protected]7aba6662013-03-12 10:17:34279 void SetDoubleSided(bool double_sided);
khushalsagarb51998f2016-07-08 01:04:21280 bool double_sided() const { return inputs_.double_sided; }
[email protected]cd57cc5a2012-10-12 22:43:41281
[email protected]56fffdd2014-02-11 19:50:57282 void SetShouldFlattenTransform(bool flatten);
khushalsagarb51998f2016-07-08 01:04:21283 bool should_flatten_transform() const {
284 return inputs_.should_flatten_transform;
285 }
[email protected]56fffdd2014-02-11 19:50:57286
khushalsagarb51998f2016-07-08 01:04:21287 bool Is3dSorted() const { return inputs_.sorting_context_id != 0; }
[email protected]cd57cc5a2012-10-12 22:43:41288
jaydasika62bd3dd2016-02-04 18:52:55289 void SetUseParentBackfaceVisibility(bool use);
[email protected]7aba6662013-03-12 10:17:34290 bool use_parent_backface_visibility() const {
khushalsagarb51998f2016-07-08 01:04:21291 return inputs_.use_parent_backface_visibility;
[email protected]7aba6662013-03-12 10:17:34292 }
[email protected]cd57cc5a2012-10-12 22:43:41293
jaydasika62bd3dd2016-02-04 18:52:55294 void SetUseLocalTransformForBackfaceVisibility(bool use_local);
295 bool use_local_transform_for_backface_visibility() const {
296 return use_local_transform_for_backface_visibility_;
297 }
298
299 void SetShouldCheckBackfaceVisibility(bool should_check_backface_visibility);
300 bool should_check_backface_visibility() const {
301 return should_check_backface_visibility_;
302 }
303
[email protected]7aba6662013-03-12 10:17:34304 virtual void SetLayerTreeHost(LayerTreeHost* host);
[email protected]cd57cc5a2012-10-12 22:43:41305
[email protected]7aba6662013-03-12 10:17:34306 void SetIsDrawable(bool is_drawable);
[email protected]cd57cc5a2012-10-12 22:43:41307
[email protected]c0ae06c12013-06-24 18:32:19308 void SetHideLayerAndSubtree(bool hide);
khushalsagarb51998f2016-07-08 01:04:21309 bool hide_layer_and_subtree() const { return inputs_.hide_layer_and_subtree; }
[email protected]c0ae06c12013-06-24 18:32:19310
[email protected]7aba6662013-03-12 10:17:34311 void SetReplicaLayer(Layer* layer);
khushalsagarb51998f2016-07-08 01:04:21312 Layer* replica_layer() { return inputs_.replica_layer.get(); }
313 const Layer* replica_layer() const { return inputs_.replica_layer.get(); }
[email protected]cd57cc5a2012-10-12 22:43:41314
khushalsagarb51998f2016-07-08 01:04:21315 bool has_mask() const { return !!inputs_.mask_layer.get(); }
316 bool has_replica() const { return !!inputs_.replica_layer.get(); }
[email protected]7aba6662013-03-12 10:17:34317 bool replica_has_mask() const {
khushalsagarb51998f2016-07-08 01:04:21318 return inputs_.replica_layer.get() &&
319 (inputs_.mask_layer.get() ||
320 inputs_.replica_layer->inputs_.mask_layer.get());
[email protected]7aba6662013-03-12 10:17:34321 }
[email protected]cd57cc5a2012-10-12 22:43:41322
[email protected]ad63b2f2014-08-11 17:39:54323 int NumDescendantsThatDrawContent() const;
324
325 // This is only virtual for tests.
326 // TODO(awoloszyn): Remove this once we no longer need it for tests
[email protected]7aba6662013-03-12 10:17:34327 virtual bool DrawsContent() const;
[email protected]ad63b2f2014-08-11 17:39:54328
329 // This methods typically need to be overwritten by derived classes.
chrishtrbb9af002015-12-09 02:00:11330 // TODO(chrishtr): Blink no longer resizes anything during paint. We can
331 // remove this.
[email protected]445881f2013-04-16 01:11:59332 virtual void SavePaintProperties();
danakj5f46636a2015-06-19 00:01:40333 // Returns true iff anything was updated that needs to be committed.
334 virtual bool Update();
[email protected]7aba6662013-03-12 10:17:34335 virtual void SetIsMask(bool is_mask) {}
[email protected]a6c1b232014-05-05 23:53:08336 virtual bool IsSuitableForGpuRasterization() const;
[email protected]cd57cc5a2012-10-12 22:43:41337
danakj60bc3bc2016-04-09 00:24:48338 virtual std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
ssid911e40e2015-02-09 17:55:20339 TakeDebugInfo();
sahel78270292016-07-14 14:35:10340 virtual void didUpdateMainThreadScrollingReasons();
[email protected]ae716ce2013-08-16 13:04:24341
khushalsagarb51998f2016-07-08 01:04:21342 void SetLayerClient(LayerClient* client) { inputs_.client = client; }
[email protected]ae716ce2013-08-16 13:04:24343
[email protected]7aba6662013-03-12 10:17:34344 virtual void PushPropertiesTo(LayerImpl* layer);
345
nyquist353b7d52015-11-06 22:26:53346 // Sets the type proto::LayerType that should be used for serialization
347 // of the current layer by calling LayerNode::set_type(proto::LayerType).
348 // TODO(nyquist): Start using a forward declared enum class when
349 // https://github.com/google/protobuf/issues/67 has been fixed and rolled in.
350 // This function would preferably instead return a proto::LayerType, but
351 // since that is an enum (the protobuf library does not generate enum
352 // classes), it can't be forward declared. We don't want to include
353 // //cc/proto/layer.pb.h in this header file, as it requires that all
354 // dependent targets would have to be given the config for how to include it.
355 virtual void SetTypeForProtoSerialization(proto::LayerNode* proto) const;
356
357 // Recursively iterate over this layer and all children and write the
358 // hierarchical structure to the given LayerNode proto. In addition to the
359 // structure itself, the Layer id and type is also written to facilitate
360 // construction of the correct layer on the client.
361 void ToLayerNodeProto(proto::LayerNode* proto) const;
362
khushalsagare64a9702016-03-23 22:33:47363 // Recursively iterate over this layer and all children and reset the
364 // properties sent with the hierarchical structure in the LayerNode protos.
365 // This must be done before deserializing the new LayerTree from the Layernode
366 // protos.
367 void ClearLayerTreePropertiesForDeserializationAndAddToMap(
368 LayerIdMap* layer_map);
369
nyquist353b7d52015-11-06 22:26:53370 // Recursively iterate over the given LayerNode proto and read the structure
371 // into this node and its children. The |layer_map| should be used to look
372 // for previously existing Layers, since they should be re-used between each
373 // hierarchy update.
374 void FromLayerNodeProto(const proto::LayerNode& proto,
khushalsagare64a9702016-03-23 22:33:47375 const LayerIdMap& layer_map,
376 LayerTreeHost* layer_tree_host);
nyquist353b7d52015-11-06 22:26:53377
nyquistbc1290a2015-11-18 16:09:56378 // This method is similar to PushPropertiesTo, but instead of pushing to
jaydasika9234e402016-03-21 20:44:22379 // a LayerImpl, it pushes the properties to proto::LayerProperties. It is
380 // called only on layers that have changed properties. The properties
381 // themselves are pushed to proto::LayerProperties.
382 void ToLayerPropertiesProto(proto::LayerUpdate* layer_update);
nyquistbc1290a2015-11-18 16:09:56383
384 // Read all property values from the given LayerProperties object and update
385 // the current layer. The values for |needs_push_properties_| and
386 // |num_dependents_need_push_properties_| are always updated, but the rest
387 // of |proto| is only read if |needs_push_properties_| is set.
388 void FromLayerPropertiesProto(const proto::LayerProperties& proto);
389
[email protected]3698e792013-08-24 00:21:16390 LayerTreeHost* layer_tree_host() { return layer_tree_host_; }
391 const LayerTreeHost* layer_tree_host() const { return layer_tree_host_; }
[email protected]cd57cc5a2012-10-12 22:43:41392
[email protected]80413d72013-08-30 20:25:33393 virtual ScrollbarLayerInterface* ToScrollbarLayer();
[email protected]cd57cc5a2012-10-12 22:43:41394
fmalita2d743282016-03-22 13:32:10395 virtual sk_sp<SkPicture> GetPicture() const;
[email protected]f7837a92013-08-21 03:00:05396
[email protected]7aba6662013-03-12 10:17:34397 // Constructs a LayerImpl of the correct runtime type for this Layer type.
danakj60bc3bc2016-04-09 00:24:48398 virtual std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl);
[email protected]aedf4e52013-01-09 23:24:44399
khushalsagarb51998f2016-07-08 01:04:21400 bool NeedsDisplayForTesting() const { return !inputs_.update_rect.IsEmpty(); }
401 void ResetNeedsDisplayForTesting() { inputs_.update_rect = gfx::Rect(); }
[email protected]48871fc2013-01-23 07:36:51402
[email protected]445881f2013-04-16 01:11:59403 const PaintProperties& paint_properties() const {
404 return paint_properties_;
405 }
406
[email protected]7a5a9322014-02-25 12:54:57407 void SetNeedsPushProperties();
jaydasika9234e402016-03-21 20:44:22408 void ResetNeedsPushPropertiesForTesting();
[email protected]f4e25f92013-07-13 20:54:53409
[email protected]666d7cf2013-10-12 01:30:29410 virtual void RunMicroBenchmark(MicroBenchmark* benchmark);
411
[email protected]a9d4d4f2014-06-19 06:49:28412 void Set3dSortingContextId(int id);
khushalsagarb51998f2016-07-08 01:04:21413 int sorting_context_id() const { return inputs_.sorting_context_id; }
[email protected]a9d4d4f2014-06-19 06:49:28414
vollick692444f2015-05-20 15:39:14415 void set_property_tree_sequence_number(int sequence_number) {
416 property_tree_sequence_number_ = sequence_number;
ennee95b1542015-04-20 20:35:50417 }
nyquistb36e0d5d2016-01-27 00:17:35418 int property_tree_sequence_number() { return property_tree_sequence_number_; }
vollick692444f2015-05-20 15:39:14419
420 void SetTransformTreeIndex(int index);
421 int transform_tree_index() const;
422
423 void SetClipTreeIndex(int index);
424 int clip_tree_index() const;
425
weiliangc6a52f302015-08-18 16:29:35426 void SetEffectTreeIndex(int index);
427 int effect_tree_index() const;
vollick51ed1a22014-12-17 02:03:00428
sunxd47c2a0e32016-07-25 15:34:10429 // TODO(sunxd): Remove this when we do not compute target space transforms on
430 // main thread in tests.
431 int render_target_effect_tree_index() const;
432
sunxdea1df7892016-01-28 00:12:33433 void SetScrollTreeIndex(int index);
434 int scroll_tree_index() const;
435
vollick51ed1a22014-12-17 02:03:00436 void set_offset_to_transform_parent(gfx::Vector2dF offset) {
ennee95b1542015-04-20 20:35:50437 if (offset_to_transform_parent_ == offset)
438 return;
vollick51ed1a22014-12-17 02:03:00439 offset_to_transform_parent_ = offset;
ennee95b1542015-04-20 20:35:50440 SetNeedsPushProperties();
vollick51ed1a22014-12-17 02:03:00441 }
442 gfx::Vector2dF offset_to_transform_parent() const {
443 return offset_to_transform_parent_;
444 }
445
ennec95e6622015-08-28 23:23:19446 // TODO(enne): This needs a different name. It is a calculated value
447 // from the property tree builder and not a synonym for "should
448 // flatten transform".
ajumad0d64422015-03-14 04:20:08449 void set_should_flatten_transform_from_property_tree(bool should_flatten) {
ennee95b1542015-04-20 20:35:50450 if (should_flatten_transform_from_property_tree_ == should_flatten)
451 return;
ajumad0d64422015-03-14 04:20:08452 should_flatten_transform_from_property_tree_ = should_flatten;
ennee95b1542015-04-20 20:35:50453 SetNeedsPushProperties();
454 }
455 bool should_flatten_transform_from_property_tree() const {
456 return should_flatten_transform_from_property_tree_;
ajumad0d64422015-03-14 04:20:08457 }
458
jaydasika74bf516f2016-04-01 19:48:15459 const gfx::Rect& visible_layer_rect_for_testing() const {
460 return visible_layer_rect_;
461 }
ennec95e6622015-08-28 23:23:19462 void set_visible_layer_rect(const gfx::Rect& rect) {
463 visible_layer_rect_ = rect;
464 }
465
weiliangcbb2e8642016-03-04 00:24:42466 void set_clip_rect(const gfx::Rect& rect) {}
ennec95e6622015-08-28 23:23:19467
jaydasika03a99c42016-02-11 21:07:08468 void SetSubtreePropertyChanged();
469 bool subtree_property_changed() const { return subtree_property_changed_; }
470
ajuma50bce7e2016-06-24 20:56:04471 void SetLayerPropertyChanged();
472 bool layer_property_changed() const { return layer_property_changed_; }
473
caseq4a4b5582015-03-17 18:39:35474 void DidBeginTracing();
sunxded58688e2016-01-11 21:01:02475
476 int num_copy_requests_in_target_subtree();
jaydasika3d10aa62015-05-06 17:50:44477
vollickef2ae922016-06-29 17:54:27478 void SetElementId(ElementId id);
khushalsagarb51998f2016-07-08 01:04:21479 ElementId element_id() const { return inputs_.element_id; }
vollick933f496e2015-12-08 04:22:05480
481 void SetMutableProperties(uint32_t properties);
khushalsagarb51998f2016-07-08 01:04:21482 uint32_t mutable_properties() const { return inputs_.mutable_properties; }
vollick933f496e2015-12-08 04:22:05483
loysodb73537f2016-03-14 05:07:45484 bool HasActiveAnimationForTesting() const;
skyostile5cd4742015-10-13 12:09:53485
vmpstrd6dce2602016-05-18 20:19:04486 void SetHasWillChangeTransformHint(bool has_will_change);
487 bool has_will_change_transform_hint() const {
khushalsagarb51998f2016-07-08 01:04:21488 return inputs_.has_will_change_transform_hint;
vmpstrd6dce2602016-05-18 20:19:04489 }
490
khushalsagaraf222d92016-07-08 21:19:32491 AnimationHost* GetAnimationHost() const;
492
493 ElementListType GetElementTypeForAnimation() const;
494
[email protected]7aba6662013-03-12 10:17:34495 protected:
496 friend class LayerImpl;
497 friend class TreeSynchronizer;
loyso9556c732016-03-11 07:54:58498 virtual ~Layer();
loyso0940d412016-03-14 01:30:31499 Layer();
[email protected]cd57cc5a2012-10-12 22:43:41500
[email protected]3519b872013-07-30 07:17:50501 // These SetNeeds functions are in order of severity of update:
502 //
503 // Called when this layer has been modified in some way, but isn't sure
504 // that it needs a commit yet. It needs CalcDrawProperties and UpdateLayers
505 // before it knows whether or not a commit is required.
506 void SetNeedsUpdate();
507 // Called when a property has been modified in a way that the layer
508 // knows immediately that a commit is required. This implies SetNeedsUpdate
509 // as well as SetNeedsPushProperties to push that property.
[email protected]7aba6662013-03-12 10:17:34510 void SetNeedsCommit();
vollick5057e1e2015-04-17 19:12:32511 // This is identical to SetNeedsCommit, but the former requests a rebuild of
512 // the property trees.
513 void SetNeedsCommitNoRebuild();
[email protected]3519b872013-07-30 07:17:50514 // Called when there's been a change in layer structure. Implies both
515 // SetNeedsUpdate and SetNeedsCommit, but not SetNeedsPushProperties.
[email protected]7aba6662013-03-12 10:17:34516 void SetNeedsFullTreeSync();
[email protected]74b43cc2013-08-30 06:29:27517
518 // Called when the next commit should wait until the pending tree is activated
519 // before finishing the commit and unblocking the main thread. Used to ensure
520 // unused resources on the impl thread are returned before commit completes.
521 void SetNextCommitWaitsForActivation();
[email protected]cd57cc5a2012-10-12 22:43:41522
[email protected]ad63b2f2014-08-11 17:39:54523 // Will recalculate whether the layer draws content and set draws_content_
524 // appropriately.
525 void UpdateDrawsContent(bool has_drawable_content);
526 virtual bool HasDrawableContent() const;
527
528 // Called when the layer's number of drawable descendants changes.
529 void AddDrawableDescendants(int num);
530
[email protected]74b43cc2013-08-30 06:29:27531 bool IsPropertyChangeAllowed() const;
532
nyquistbc1290a2015-11-18 16:09:56533 // Serialize all the necessary properties to be able to reconstruct this Layer
jaydasika9234e402016-03-21 20:44:22534 // into proto::LayerProperties. This method is not marked as const
nyquistb0a49d02015-12-17 03:42:58535 // as some implementations need reset member fields, similarly to
536 // PushPropertiesTo().
nyquistbc1290a2015-11-18 16:09:56537 virtual void LayerSpecificPropertiesToProto(proto::LayerProperties* proto);
538
539 // Deserialize all the necessary properties from proto::LayerProperties into
jaydasika9234e402016-03-21 20:44:22540 // this Layer.
nyquistbc1290a2015-11-18 16:09:56541 virtual void FromLayerSpecificPropertiesProto(
542 const proto::LayerProperties& proto);
543
khushalsagarb51998f2016-07-08 01:04:21544 gfx::Rect& update_rect() { return inputs_.update_rect; }
[email protected]cd57cc5a2012-10-12 22:43:41545
[email protected]7aba6662013-03-12 10:17:34546 // When true, the layer is about to perform an update. Any commit requests
[email protected]3519b872013-07-30 07:17:50547 // will be handled implicitly after the update completes.
[email protected]7aba6662013-03-12 10:17:34548 bool ignore_set_needs_commit_;
[email protected]cd57cc5a2012-10-12 22:43:41549
[email protected]7aba6662013-03-12 10:17:34550 private:
551 friend class base::RefCounted<Layer>;
nyquistb0a49d02015-12-17 03:42:58552 friend class LayerSerializationTest;
awoloszyne83f28c2014-12-22 15:40:00553 friend class LayerTreeHostCommon;
khushalsagarb51998f2016-07-08 01:04:21554 friend class LayerTreeHost;
555 friend class LayerInternalsForTest;
556
557 // Interactions with attached animations.
558 gfx::ScrollOffset ScrollOffsetForAnimation() const;
559 void OnFilterAnimated(const FilterOperations& filters);
560 void OnOpacityAnimated(float opacity);
561 void OnTransformAnimated(const gfx::Transform& transform);
562 void OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset);
563 void OnTransformIsCurrentlyAnimatingChanged(bool is_animating);
564 void OnTransformIsPotentiallyAnimatingChanged(bool is_animating);
565 void OnOpacityIsCurrentlyAnimatingChanged(bool is_currently_animating);
566 void OnOpacityIsPotentiallyAnimatingChanged(bool has_potential_animation);
ajumacb2b74432016-07-21 19:11:15567 void OnFilterIsCurrentlyAnimatingChanged(bool is_currently_animating);
568 void OnFilterIsPotentiallyAnimatingChanged(bool has_potential_animation);
nyquistb0a49d02015-12-17 03:42:58569
khushalsagaraf222d92016-07-08 21:19:32570 bool FilterIsAnimating() const;
571 bool TransformIsAnimating() const;
572 bool ScrollOffsetAnimationWasInterrupted() const;
573 bool HasOnlyTranslationTransforms() const;
574
575 void AddScrollChild(Layer* child);
576 void RemoveScrollChild(Layer* child);
577
578 void AddClipChild(Layer* child);
579 void RemoveClipChild(Layer* child);
580
[email protected]7aba6662013-03-12 10:17:34581 void SetParent(Layer* layer);
[email protected]7aba6662013-03-12 10:17:34582 bool DescendantIsFixedToContainerLayer() const;
[email protected]cd57cc5a2012-10-12 22:43:41583
[email protected]7aba6662013-03-12 10:17:34584 // This should only be called from RemoveFromParent().
585 void RemoveChildOrDependent(Layer* child);
[email protected]cd57cc5a2012-10-12 22:43:41586
vollick66133e82014-09-13 20:36:44587 // If this layer has a scroll parent, it removes |this| from its list of
588 // scroll children.
589 void RemoveFromScrollTree();
590
591 // If this layer has a clip parent, it removes |this| from its list of clip
592 // children.
593 void RemoveFromClipTree();
594
weiliangcc4d2e74d2015-06-09 01:21:35595 // When we detach or attach layer to new LayerTreeHost, all property trees'
596 // indices becomes invalid.
597 void InvalidatePropertyTreesIndices();
598
khushalsagarb51998f2016-07-08 01:04:21599 // Encapsulates all data, callbacks or interfaces received from the embedder.
600 // TODO(khushalsagar): This is only valid when PropertyTrees are built
601 // internally in cc. Update this for the SPv2 path where blink generates
602 // PropertyTrees.
603 struct Inputs {
604 Inputs();
605 ~Inputs();
606
607 int layer_id;
608
609 LayerList children;
610
611 // The update rect is the region of the compositor resource that was
612 // actually updated by the compositor. For layers that may do updating
613 // outside the compositor's control (i.e. plugin layers), this information
614 // is not available and the update rect will remain empty.
615 // Note this rect is in layer space (not content space).
616 gfx::Rect update_rect;
617
618 gfx::Size bounds;
619 bool masks_to_bounds;
620
621 scoped_refptr<Layer> mask_layer;
622
623 // Replica layer used for reflections.
624 scoped_refptr<Layer> replica_layer;
625
626 float opacity;
627 SkXfermode::Mode blend_mode;
628
629 bool is_root_for_isolated_group : 1;
630
631 bool contents_opaque : 1;
632
633 gfx::PointF position;
634 gfx::Transform transform;
635 gfx::Point3F transform_origin;
636
637 bool is_drawable : 1;
638
639 bool double_sided : 1;
640 bool should_flatten_transform : 1;
641
642 // Layers that share a sorting context id will be sorted together in 3d
643 // space. 0 is a special value that means this layer will not be sorted
644 // and will be drawn in paint order.
645 int sorting_context_id;
646
647 bool use_parent_backface_visibility : 1;
648
649 SkColor background_color;
650
651 FilterOperations filters;
652 FilterOperations background_filters;
653
654 gfx::ScrollOffset scroll_offset;
655
656 // This variable indicates which ancestor layer (if any) whose size,
657 // transformed relative to this layer, defines the maximum scroll offset
658 // for this layer.
659 int scroll_clip_layer_id;
660 bool user_scrollable_horizontal : 1;
661 bool user_scrollable_vertical : 1;
662
663 uint32_t main_thread_scrolling_reasons;
664 Region non_fast_scrollable_region;
665
666 Region touch_event_handler_region;
667
668 bool is_container_for_fixed_position_layers : 1;
669 LayerPositionConstraint position_constraint;
670
671 ElementId element_id;
672
673 uint32_t mutable_properties;
674
675 Layer* scroll_parent;
676 Layer* clip_parent;
677
678 bool has_will_change_transform_hint : 1;
679
680 bool hide_layer_and_subtree : 1;
681
682 // The following elements can not and are not serialized.
683 LayerClient* client;
684 base::Closure did_scroll_callback;
685 std::vector<std::unique_ptr<CopyOutputRequest>> copy_requests;
686 };
687
[email protected]7aba6662013-03-12 10:17:34688 Layer* parent_;
[email protected]de4afb5e2012-12-20 00:11:34689
[email protected]7aba6662013-03-12 10:17:34690 // Layer instances have a weak pointer to their LayerTreeHost.
691 // This pointer value is nil when a Layer is not in a tree and is
692 // updated via SetLayerTreeHost() if a layer moves between trees.
693 LayerTreeHost* layer_tree_host_;
[email protected]cd57cc5a2012-10-12 22:43:41694
khushalsagarb51998f2016-07-08 01:04:21695 Inputs inputs_;
[email protected]cd57cc5a2012-10-12 22:43:41696
[email protected]ad63b2f2014-08-11 17:39:54697 int num_descendants_that_draw_content_;
vollick51ed1a22014-12-17 02:03:00698 int transform_tree_index_;
weiliangc6a52f302015-08-18 16:29:35699 int effect_tree_index_;
vollick51ed1a22014-12-17 02:03:00700 int clip_tree_index_;
sunxdea1df7892016-01-28 00:12:33701 int scroll_tree_index_;
vollick692444f2015-05-20 15:39:14702 int property_tree_sequence_number_;
vollick51ed1a22014-12-17 02:03:00703 gfx::Vector2dF offset_to_transform_parent_;
ajumad0d64422015-03-14 04:20:08704 bool should_flatten_transform_from_property_tree_ : 1;
[email protected]ad63b2f2014-08-11 17:39:54705 bool draws_content_ : 1;
jaydasika62bd3dd2016-02-04 18:52:55706 bool use_local_transform_for_backface_visibility_ : 1;
707 bool should_check_backface_visibility_ : 1;
jaydasika6b5a32bf2016-04-22 21:56:36708 bool force_render_surface_for_testing_ : 1;
jaydasika03a99c42016-02-11 21:07:08709 bool subtree_property_changed_ : 1;
ajuma50bce7e2016-06-24 20:56:04710 bool layer_property_changed_ : 1;
jaydasikac6326bb2016-03-03 03:46:14711 SkColor safe_opaque_background_color_;
jaydasika92239dc2015-08-15 02:59:26712 // draw_blend_mode may be different than blend_mode_,
713 // when a RenderSurface re-parents the layer's blend_mode.
714 SkXfermode::Mode draw_blend_mode_;
danakj60bc3bc2016-04-09 00:24:48715 std::unique_ptr<std::set<Layer*>> scroll_children_;
[email protected]0e98cdd2013-08-23 00:44:30716
danakj60bc3bc2016-04-09 00:24:48717 std::unique_ptr<std::set<Layer*>> clip_children_;
[email protected]cd57cc5a2012-10-12 22:43:41718
[email protected]445881f2013-04-16 01:11:59719 PaintProperties paint_properties_;
720
ennec95e6622015-08-28 23:23:19721 // These all act like draw properties, so don't need push properties.
722 gfx::Rect visible_layer_rect_;
ennec95e6622015-08-28 23:23:19723 size_t num_unclipped_descendants_;
vmpstr3d1d72c2015-01-26 18:27:40724
[email protected]7aba6662013-03-12 10:17:34725 DISALLOW_COPY_AND_ASSIGN(Layer);
[email protected]cd57cc5a2012-10-12 22:43:41726};
727
[email protected]ddf9df82012-10-16 06:52:46728} // namespace cc
729
[email protected]cc3cfaa2013-03-18 09:05:52730#endif // CC_LAYERS_LAYER_H_