[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 1 | // Copyright 2010 The Chromium Authors. All rights reserved. |
[email protected] | 0fb2500 | 2012-10-12 07:20:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 4 | |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 5 | #ifndef CC_LAYERS_LAYER_H_ |
| 6 | #define CC_LAYERS_LAYER_H_ |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 7 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
| 10 | |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 11 | #include <set> |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 12 | #include <string> |
davidben | 5877ffe | 2016-01-28 00:29:51 | [diff] [blame] | 13 | #include <unordered_map> |
vmpstr | 3d1d72c | 2015-01-26 18:27:40 | [diff] [blame] | 14 | #include <vector> |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 15 | |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 16 | #include "base/callback.h" |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 17 | #include "base/macros.h" |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 18 | #include "base/memory/ref_counted.h" |
[email protected] | e10cd02 | 2012-12-18 00:32:26 | [diff] [blame] | 19 | #include "base/observer_list.h" |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 20 | #include "cc/animation/element_id.h" |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 21 | #include "cc/animation/target_property.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 22 | #include "cc/base/cc_export.h" |
| 23 | #include "cc/base/region.h" |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 24 | #include "cc/debug/micro_benchmark.h" |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 25 | #include "cc/input/input_handler.h" |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 26 | #include "cc/layers/layer_collections.h" |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 27 | #include "cc/layers/layer_position_constraint.h" |
[email protected] | 445881f | 2013-04-16 01:11:59 | [diff] [blame] | 28 | #include "cc/layers/paint_properties.h" |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 29 | #include "cc/output/filter_operations.h" |
khushalsagar | af222d9 | 2016-07-08 21:19:32 | [diff] [blame] | 30 | #include "cc/trees/mutator_host_client.h" |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 31 | #include "cc/trees/property_tree.h" |
[email protected] | ddf9df8 | 2012-10-16 06:52:46 | [diff] [blame] | 32 | #include "third_party/skia/include/core/SkColor.h" |
[email protected] | f7837a9 | 2013-08-21 03:00:05 | [diff] [blame] | 33 | #include "third_party/skia/include/core/SkPicture.h" |
[email protected] | 7bbeaf4e | 2013-11-26 10:27:22 | [diff] [blame] | 34 | #include "third_party/skia/include/core/SkXfermode.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 35 | #include "ui/gfx/geometry/point3_f.h" |
| 36 | #include "ui/gfx/geometry/rect.h" |
| 37 | #include "ui/gfx/geometry/rect_f.h" |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 38 | #include "ui/gfx/geometry/scroll_offset.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 39 | #include "ui/gfx/transform.h" |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 40 | |
[email protected] | db2586f | 2013-08-15 22:03:14 | [diff] [blame] | 41 | namespace gfx { |
| 42 | class BoxF; |
| 43 | } |
| 44 | |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 45 | namespace base { |
primiano | 1596043 | 2015-02-05 14:20:26 | [diff] [blame] | 46 | namespace trace_event { |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 47 | class ConvertableToTraceFormat; |
| 48 | } |
| 49 | } |
| 50 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 51 | namespace cc { |
| 52 | |
khushalsagar | af222d9 | 2016-07-08 21:19:32 | [diff] [blame] | 53 | class AnimationHost; |
[email protected] | 0e5f714 | 2013-05-24 06:45:36 | [diff] [blame] | 54 | class CopyOutputRequest; |
[email protected] | 7f5605c | 2013-04-08 18:08:35 | [diff] [blame] | 55 | class LayerAnimationEventObserver; |
[email protected] | ae716ce | 2013-08-16 13:04:24 | [diff] [blame] | 56 | class LayerClient; |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 57 | class LayerImpl; |
| 58 | class LayerTreeHost; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 59 | class LayerTreeHostCommon; |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 60 | class LayerTreeImpl; |
loyso | 5719778 | 2015-05-28 04:10:18 | [diff] [blame] | 61 | class LayerTreeSettings; |
[email protected] | d8411661 | 2013-03-29 05:32:49 | [diff] [blame] | 62 | class RenderingStatsInstrumentation; |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 63 | class ResourceUpdateQueue; |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 64 | class ScrollbarLayerInterface; |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 65 | class SimpleEnclosedRegion; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 66 | |
nyquist | 353b7d5 | 2015-11-06 22:26:53 | [diff] [blame] | 67 | namespace proto { |
| 68 | class LayerNode; |
nyquist | bc1290a | 2015-11-18 16:09:56 | [diff] [blame] | 69 | class LayerProperties; |
| 70 | class LayerUpdate; |
nyquist | 353b7d5 | 2015-11-06 22:26:53 | [diff] [blame] | 71 | } // namespace proto |
| 72 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 73 | // Base class for composited layers. Special layer types are derived from |
| 74 | // this class. |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 75 | class CC_EXPORT Layer : public base::RefCounted<Layer> { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 76 | public: |
davidben | 5877ffe | 2016-01-28 00:29:51 | [diff] [blame] | 77 | using LayerListType = LayerList; |
| 78 | using LayerIdMap = std::unordered_map<int, scoped_refptr<Layer>>; |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 79 | |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 80 | enum LayerIdLabels { |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 81 | INVALID_ID = -1, |
| 82 | }; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 83 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 84 | static scoped_refptr<Layer> Create(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 85 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 86 | int id() const { return inputs_.layer_id; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 87 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 88 | 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] | f659521e | 2013-07-26 00:27:06 | [diff] [blame] | 97 | bool HasAncestor(const Layer* ancestor) const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 98 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 99 | const LayerList& children() const { return inputs_.children; } |
| 100 | Layer* child_at(size_t index) { return inputs_.children[index].get(); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 101 | |
[email protected] | 0e5f714 | 2013-05-24 06:45:36 | [diff] [blame] | 102 | // 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 |
miu | a6ce94ca | 2015-03-31 20:21:22 | [diff] [blame] | 104 | // 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. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 107 | void RequestCopyOfOutput(std::unique_ptr<CopyOutputRequest> request); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 108 | bool HasCopyRequest() const { return !inputs_.copy_requests.empty(); } |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 109 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 110 | void TakeCopyRequests( |
| 111 | std::vector<std::unique_ptr<CopyOutputRequest>>* requests); |
| 112 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 113 | virtual void SetBackgroundColor(SkColor background_color); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 114 | SkColor background_color() const { return inputs_.background_color; } |
jaydasika | c6326bb | 2016-03-03 03:46:14 | [diff] [blame] | 115 | void SetSafeOpaqueBackgroundColor(SkColor background_color); |
[email protected] | 2c4cbec | 2013-06-04 21:14:50 | [diff] [blame] | 116 | // 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] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 119 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 120 | // A layer's bounds are in logical, non-page-scaled pixels (however, the |
| 121 | // root layer's bounds are in physical pixels). |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 122 | void SetBounds(const gfx::Size& bounds); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 123 | gfx::Size bounds() const { return inputs_.bounds; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 124 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 125 | void SetMasksToBounds(bool masks_to_bounds); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 126 | bool masks_to_bounds() const { return inputs_.masks_to_bounds; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 127 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 128 | void SetMaskLayer(Layer* mask_layer); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 129 | Layer* mask_layer() { return inputs_.mask_layer.get(); } |
| 130 | const Layer* mask_layer() const { return inputs_.mask_layer.get(); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 131 | |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 132 | virtual void SetNeedsDisplayRect(const gfx::Rect& dirty_rect); |
| 133 | void SetNeedsDisplay() { SetNeedsDisplayRect(gfx::Rect(bounds())); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 134 | |
jaydasika | 3093be3a | 2016-05-25 19:23:55 | [diff] [blame] | 135 | virtual void SetOpacity(float opacity); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 136 | float opacity() const { return inputs_.opacity; } |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 137 | float EffectiveOpacity() const; |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 138 | virtual bool OpacityCanAnimateOnImplThread() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 139 | |
jaydasika | ae9b7a0 | 2016-05-19 16:12:52 | [diff] [blame] | 140 | virtual bool AlwaysUseActiveTreeOpacity() const; |
| 141 | |
[email protected] | 7bbeaf4e | 2013-11-26 10:27:22 | [diff] [blame] | 142 | void SetBlendMode(SkXfermode::Mode blend_mode); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 143 | SkXfermode::Mode blend_mode() const { return inputs_.blend_mode; } |
[email protected] | 7bbeaf4e | 2013-11-26 10:27:22 | [diff] [blame] | 144 | |
jaydasika | 92239dc | 2015-08-15 02:59:26 | [diff] [blame] | 145 | 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] | 7bbeaf4e | 2013-11-26 10:27:22 | [diff] [blame] | 153 | // 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 { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 159 | return inputs_.is_root_for_isolated_group; |
[email protected] | 7bbeaf4e | 2013-11-26 10:27:22 | [diff] [blame] | 160 | } |
| 161 | |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 162 | void SetFilters(const FilterOperations& filters); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 163 | const FilterOperations& filters() const { return inputs_.filters; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 164 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 165 | // 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] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 168 | void SetBackgroundFilters(const FilterOperations& filters); |
| 169 | const FilterOperations& background_filters() const { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 170 | return inputs_.background_filters; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 171 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 172 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 173 | virtual void SetContentsOpaque(bool opaque); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 174 | bool contents_opaque() const { return inputs_.contents_opaque; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 175 | |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 176 | void SetPosition(const gfx::PointF& position); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 177 | gfx::PointF position() const { return inputs_.position; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 178 | |
ajuma | 4216ee12 | 2015-05-29 13:07:17 | [diff] [blame] | 179 | // A layer that is a container for fixed position layers cannot be both |
| 180 | // scrollable and have a non-identity transform. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 181 | void SetIsContainerForFixedPositionLayers(bool container); |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 182 | bool IsContainerForFixedPositionLayers() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 183 | |
miletus | 624d342e | 2015-03-13 03:39:44 | [diff] [blame] | 184 | gfx::Vector2dF FixedContainerSizeDelta() const { |
| 185 | return gfx::Vector2dF(); |
| 186 | } |
| 187 | |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 188 | void SetPositionConstraint(const LayerPositionConstraint& constraint); |
| 189 | const LayerPositionConstraint& position_constraint() const { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 190 | return inputs_.position_constraint; |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 191 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 192 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 193 | void SetTransform(const gfx::Transform& transform); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 194 | const gfx::Transform& transform() const { return inputs_.transform; } |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 195 | |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 196 | void SetTransformOrigin(const gfx::Point3F&); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 197 | gfx::Point3F transform_origin() const { return inputs_.transform_origin; } |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 198 | |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 199 | void SetScrollParent(Layer* parent); |
| 200 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 201 | Layer* scroll_parent() { return inputs_.scroll_parent; } |
| 202 | const Layer* scroll_parent() const { return inputs_.scroll_parent; } |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 203 | |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 204 | 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 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 211 | Layer* clip_parent() { return inputs_.clip_parent; } |
| 212 | const Layer* clip_parent() const { return inputs_.clip_parent; } |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 213 | |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 214 | std::set<Layer*>* clip_children() { return clip_children_.get(); } |
| 215 | const std::set<Layer*>* clip_children() const { |
| 216 | return clip_children_.get(); |
| 217 | } |
| 218 | |
enne | c95e662 | 2015-08-28 23:23:19 | [diff] [blame] | 219 | // TODO(enne): Fix style here (and everywhere) once LayerImpl does the same. |
enne | c95e662 | 2015-08-28 23:23:19 | [diff] [blame] | 220 | gfx::Transform screen_space_transform() const; |
[email protected] | d76806f8 | 2012-12-05 21:41:50 | [diff] [blame] | 221 | |
enne | c95e662 | 2015-08-28 23:23:19 | [diff] [blame] | 222 | void set_num_unclipped_descendants(size_t descendants) { |
| 223 | num_unclipped_descendants_ = descendants; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 224 | } |
vmpstr | 762e70d | 2015-06-10 02:12:57 | [diff] [blame] | 225 | size_t num_unclipped_descendants() const { |
enne | c95e662 | 2015-08-28 23:23:19 | [diff] [blame] | 226 | return num_unclipped_descendants_; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 227 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 228 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 229 | void SetScrollOffset(const gfx::ScrollOffset& scroll_offset); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 230 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 231 | gfx::ScrollOffset scroll_offset() const { return inputs_.scroll_offset; } |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 232 | void SetScrollOffsetFromImplSide(const gfx::ScrollOffset& scroll_offset); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 233 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 234 | void SetScrollClipLayerId(int clip_layer_id); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 235 | bool scrollable() const { return inputs_.scroll_clip_layer_id != INVALID_ID; } |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 236 | Layer* scroll_clip_layer() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 237 | |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 238 | void SetUserScrollable(bool horizontal, bool vertical); |
| 239 | bool user_scrollable_horizontal() const { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 240 | return inputs_.user_scrollable_horizontal; |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 241 | } |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 242 | bool user_scrollable_vertical() const { |
| 243 | return inputs_.user_scrollable_vertical; |
| 244 | } |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 245 | |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 246 | void AddMainThreadScrollingReasons(uint32_t main_thread_scrolling_reasons); |
ymalik | 002b8a25 | 2016-02-25 02:44:24 | [diff] [blame] | 247 | void ClearMainThreadScrollingReasons( |
| 248 | uint32_t main_thread_scrolling_reasons_to_clear); |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 249 | uint32_t main_thread_scrolling_reasons() const { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 250 | return inputs_.main_thread_scrolling_reasons; |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 251 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 252 | bool should_scroll_on_main_thread() const { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 253 | return !!inputs_.main_thread_scrolling_reasons; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 254 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 255 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 256 | void SetNonFastScrollableRegion(const Region& non_fast_scrollable_region); |
| 257 | const Region& non_fast_scrollable_region() const { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 258 | return inputs_.non_fast_scrollable_region; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 259 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 260 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 261 | void SetTouchEventHandlerRegion(const Region& touch_event_handler_region); |
| 262 | const Region& touch_event_handler_region() const { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 263 | return inputs_.touch_event_handler_region; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 264 | } |
[email protected] | 23d56be | 2012-11-08 00:33:34 | [diff] [blame] | 265 | |
[email protected] | 28096ed | 2013-07-01 07:38:58 | [diff] [blame] | 266 | void set_did_scroll_callback(const base::Closure& callback) { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 267 | inputs_.did_scroll_callback = callback; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 268 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 269 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 270 | void SetForceRenderSurfaceForTesting(bool force_render_surface); |
| 271 | bool force_render_surface_for_testing() const { |
| 272 | return force_render_surface_for_testing_; |
| 273 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 274 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 275 | gfx::ScrollOffset CurrentScrollOffset() const { |
| 276 | return inputs_.scroll_offset; |
| 277 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 278 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 279 | void SetDoubleSided(bool double_sided); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 280 | bool double_sided() const { return inputs_.double_sided; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 281 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 282 | void SetShouldFlattenTransform(bool flatten); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 283 | bool should_flatten_transform() const { |
| 284 | return inputs_.should_flatten_transform; |
| 285 | } |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 286 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 287 | bool Is3dSorted() const { return inputs_.sorting_context_id != 0; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 288 | |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 289 | void SetUseParentBackfaceVisibility(bool use); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 290 | bool use_parent_backface_visibility() const { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 291 | return inputs_.use_parent_backface_visibility; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 292 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 293 | |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 294 | 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] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 304 | virtual void SetLayerTreeHost(LayerTreeHost* host); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 305 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 306 | void SetIsDrawable(bool is_drawable); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 307 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 308 | void SetHideLayerAndSubtree(bool hide); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 309 | bool hide_layer_and_subtree() const { return inputs_.hide_layer_and_subtree; } |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 310 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 311 | void SetReplicaLayer(Layer* layer); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 312 | Layer* replica_layer() { return inputs_.replica_layer.get(); } |
| 313 | const Layer* replica_layer() const { return inputs_.replica_layer.get(); } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 314 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 315 | bool has_mask() const { return !!inputs_.mask_layer.get(); } |
| 316 | bool has_replica() const { return !!inputs_.replica_layer.get(); } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 317 | bool replica_has_mask() const { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 318 | return inputs_.replica_layer.get() && |
| 319 | (inputs_.mask_layer.get() || |
| 320 | inputs_.replica_layer->inputs_.mask_layer.get()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 321 | } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 322 | |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 323 | 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] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 327 | virtual bool DrawsContent() const; |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 328 | |
| 329 | // This methods typically need to be overwritten by derived classes. |
chrishtr | bb9af00 | 2015-12-09 02:00:11 | [diff] [blame] | 330 | // TODO(chrishtr): Blink no longer resizes anything during paint. We can |
| 331 | // remove this. |
[email protected] | 445881f | 2013-04-16 01:11:59 | [diff] [blame] | 332 | virtual void SavePaintProperties(); |
danakj | 5f46636a | 2015-06-19 00:01:40 | [diff] [blame] | 333 | // Returns true iff anything was updated that needs to be committed. |
| 334 | virtual bool Update(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 335 | virtual void SetIsMask(bool is_mask) {} |
[email protected] | a6c1b23 | 2014-05-05 23:53:08 | [diff] [blame] | 336 | virtual bool IsSuitableForGpuRasterization() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 337 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 338 | virtual std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
ssid | 911e40e | 2015-02-09 17:55:20 | [diff] [blame] | 339 | TakeDebugInfo(); |
sahel | 7827029 | 2016-07-14 14:35:10 | [diff] [blame] | 340 | virtual void didUpdateMainThreadScrollingReasons(); |
[email protected] | ae716ce | 2013-08-16 13:04:24 | [diff] [blame] | 341 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 342 | void SetLayerClient(LayerClient* client) { inputs_.client = client; } |
[email protected] | ae716ce | 2013-08-16 13:04:24 | [diff] [blame] | 343 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 344 | virtual void PushPropertiesTo(LayerImpl* layer); |
| 345 | |
nyquist | 353b7d5 | 2015-11-06 22:26:53 | [diff] [blame] | 346 | // 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 | |
khushalsagar | e64a970 | 2016-03-23 22:33:47 | [diff] [blame] | 363 | // 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 | |
nyquist | 353b7d5 | 2015-11-06 22:26:53 | [diff] [blame] | 370 | // 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, |
khushalsagar | e64a970 | 2016-03-23 22:33:47 | [diff] [blame] | 375 | const LayerIdMap& layer_map, |
| 376 | LayerTreeHost* layer_tree_host); |
nyquist | 353b7d5 | 2015-11-06 22:26:53 | [diff] [blame] | 377 | |
nyquist | bc1290a | 2015-11-18 16:09:56 | [diff] [blame] | 378 | // This method is similar to PushPropertiesTo, but instead of pushing to |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 379 | // 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); |
nyquist | bc1290a | 2015-11-18 16:09:56 | [diff] [blame] | 383 | |
| 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] | 3698e79 | 2013-08-24 00:21:16 | [diff] [blame] | 390 | LayerTreeHost* layer_tree_host() { return layer_tree_host_; } |
| 391 | const LayerTreeHost* layer_tree_host() const { return layer_tree_host_; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 392 | |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 393 | virtual ScrollbarLayerInterface* ToScrollbarLayer(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 394 | |
fmalita | 2d74328 | 2016-03-22 13:32:10 | [diff] [blame] | 395 | virtual sk_sp<SkPicture> GetPicture() const; |
[email protected] | f7837a9 | 2013-08-21 03:00:05 | [diff] [blame] | 396 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 397 | // Constructs a LayerImpl of the correct runtime type for this Layer type. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 398 | virtual std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 399 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 400 | bool NeedsDisplayForTesting() const { return !inputs_.update_rect.IsEmpty(); } |
| 401 | void ResetNeedsDisplayForTesting() { inputs_.update_rect = gfx::Rect(); } |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 402 | |
[email protected] | 445881f | 2013-04-16 01:11:59 | [diff] [blame] | 403 | const PaintProperties& paint_properties() const { |
| 404 | return paint_properties_; |
| 405 | } |
| 406 | |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 407 | void SetNeedsPushProperties(); |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 408 | void ResetNeedsPushPropertiesForTesting(); |
[email protected] | f4e25f9 | 2013-07-13 20:54:53 | [diff] [blame] | 409 | |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 410 | virtual void RunMicroBenchmark(MicroBenchmark* benchmark); |
| 411 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 412 | void Set3dSortingContextId(int id); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 413 | int sorting_context_id() const { return inputs_.sorting_context_id; } |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 414 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 415 | void set_property_tree_sequence_number(int sequence_number) { |
| 416 | property_tree_sequence_number_ = sequence_number; |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 417 | } |
nyquist | b36e0d5d | 2016-01-27 00:17:35 | [diff] [blame] | 418 | int property_tree_sequence_number() { return property_tree_sequence_number_; } |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 419 | |
| 420 | void SetTransformTreeIndex(int index); |
| 421 | int transform_tree_index() const; |
| 422 | |
| 423 | void SetClipTreeIndex(int index); |
| 424 | int clip_tree_index() const; |
| 425 | |
weiliangc | 6a52f30 | 2015-08-18 16:29:35 | [diff] [blame] | 426 | void SetEffectTreeIndex(int index); |
| 427 | int effect_tree_index() const; |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 428 | |
sunxd | 47c2a0e3 | 2016-07-25 15:34:10 | [diff] [blame] | 429 | // 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 | |
sunxd | ea1df789 | 2016-01-28 00:12:33 | [diff] [blame] | 433 | void SetScrollTreeIndex(int index); |
| 434 | int scroll_tree_index() const; |
| 435 | |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 436 | void set_offset_to_transform_parent(gfx::Vector2dF offset) { |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 437 | if (offset_to_transform_parent_ == offset) |
| 438 | return; |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 439 | offset_to_transform_parent_ = offset; |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 440 | SetNeedsPushProperties(); |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 441 | } |
| 442 | gfx::Vector2dF offset_to_transform_parent() const { |
| 443 | return offset_to_transform_parent_; |
| 444 | } |
| 445 | |
enne | c95e662 | 2015-08-28 23:23:19 | [diff] [blame] | 446 | // 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". |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 449 | void set_should_flatten_transform_from_property_tree(bool should_flatten) { |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 450 | if (should_flatten_transform_from_property_tree_ == should_flatten) |
| 451 | return; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 452 | should_flatten_transform_from_property_tree_ = should_flatten; |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 453 | SetNeedsPushProperties(); |
| 454 | } |
| 455 | bool should_flatten_transform_from_property_tree() const { |
| 456 | return should_flatten_transform_from_property_tree_; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 457 | } |
| 458 | |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 459 | const gfx::Rect& visible_layer_rect_for_testing() const { |
| 460 | return visible_layer_rect_; |
| 461 | } |
enne | c95e662 | 2015-08-28 23:23:19 | [diff] [blame] | 462 | void set_visible_layer_rect(const gfx::Rect& rect) { |
| 463 | visible_layer_rect_ = rect; |
| 464 | } |
| 465 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 466 | void set_clip_rect(const gfx::Rect& rect) {} |
enne | c95e662 | 2015-08-28 23:23:19 | [diff] [blame] | 467 | |
jaydasika | 03a99c4 | 2016-02-11 21:07:08 | [diff] [blame] | 468 | void SetSubtreePropertyChanged(); |
| 469 | bool subtree_property_changed() const { return subtree_property_changed_; } |
| 470 | |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 471 | void SetLayerPropertyChanged(); |
| 472 | bool layer_property_changed() const { return layer_property_changed_; } |
| 473 | |
caseq | 4a4b558 | 2015-03-17 18:39:35 | [diff] [blame] | 474 | void DidBeginTracing(); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 475 | |
| 476 | int num_copy_requests_in_target_subtree(); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 477 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 478 | void SetElementId(ElementId id); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 479 | ElementId element_id() const { return inputs_.element_id; } |
vollick | 933f496e | 2015-12-08 04:22:05 | [diff] [blame] | 480 | |
| 481 | void SetMutableProperties(uint32_t properties); |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 482 | uint32_t mutable_properties() const { return inputs_.mutable_properties; } |
vollick | 933f496e | 2015-12-08 04:22:05 | [diff] [blame] | 483 | |
loyso | db73537f | 2016-03-14 05:07:45 | [diff] [blame] | 484 | bool HasActiveAnimationForTesting() const; |
skyostil | e5cd474 | 2015-10-13 12:09:53 | [diff] [blame] | 485 | |
vmpstr | d6dce260 | 2016-05-18 20:19:04 | [diff] [blame] | 486 | void SetHasWillChangeTransformHint(bool has_will_change); |
| 487 | bool has_will_change_transform_hint() const { |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 488 | return inputs_.has_will_change_transform_hint; |
vmpstr | d6dce260 | 2016-05-18 20:19:04 | [diff] [blame] | 489 | } |
| 490 | |
khushalsagar | af222d9 | 2016-07-08 21:19:32 | [diff] [blame] | 491 | AnimationHost* GetAnimationHost() const; |
| 492 | |
| 493 | ElementListType GetElementTypeForAnimation() const; |
| 494 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 495 | protected: |
| 496 | friend class LayerImpl; |
| 497 | friend class TreeSynchronizer; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 498 | virtual ~Layer(); |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 499 | Layer(); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 500 | |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 501 | // 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] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 510 | void SetNeedsCommit(); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 511 | // This is identical to SetNeedsCommit, but the former requests a rebuild of |
| 512 | // the property trees. |
| 513 | void SetNeedsCommitNoRebuild(); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 514 | // Called when there's been a change in layer structure. Implies both |
| 515 | // SetNeedsUpdate and SetNeedsCommit, but not SetNeedsPushProperties. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 516 | void SetNeedsFullTreeSync(); |
[email protected] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 517 | |
| 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] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 522 | |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 523 | // 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] | 74b43cc | 2013-08-30 06:29:27 | [diff] [blame] | 531 | bool IsPropertyChangeAllowed() const; |
| 532 | |
nyquist | bc1290a | 2015-11-18 16:09:56 | [diff] [blame] | 533 | // Serialize all the necessary properties to be able to reconstruct this Layer |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 534 | // into proto::LayerProperties. This method is not marked as const |
nyquist | b0a49d0 | 2015-12-17 03:42:58 | [diff] [blame] | 535 | // as some implementations need reset member fields, similarly to |
| 536 | // PushPropertiesTo(). |
nyquist | bc1290a | 2015-11-18 16:09:56 | [diff] [blame] | 537 | virtual void LayerSpecificPropertiesToProto(proto::LayerProperties* proto); |
| 538 | |
| 539 | // Deserialize all the necessary properties from proto::LayerProperties into |
jaydasika | 9234e40 | 2016-03-21 20:44:22 | [diff] [blame] | 540 | // this Layer. |
nyquist | bc1290a | 2015-11-18 16:09:56 | [diff] [blame] | 541 | virtual void FromLayerSpecificPropertiesProto( |
| 542 | const proto::LayerProperties& proto); |
| 543 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 544 | gfx::Rect& update_rect() { return inputs_.update_rect; } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 545 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 546 | // When true, the layer is about to perform an update. Any commit requests |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 547 | // will be handled implicitly after the update completes. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 548 | bool ignore_set_needs_commit_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 549 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 550 | private: |
| 551 | friend class base::RefCounted<Layer>; |
nyquist | b0a49d0 | 2015-12-17 03:42:58 | [diff] [blame] | 552 | friend class LayerSerializationTest; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 553 | friend class LayerTreeHostCommon; |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 554 | 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); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 567 | void OnFilterIsCurrentlyAnimatingChanged(bool is_currently_animating); |
| 568 | void OnFilterIsPotentiallyAnimatingChanged(bool has_potential_animation); |
nyquist | b0a49d0 | 2015-12-17 03:42:58 | [diff] [blame] | 569 | |
khushalsagar | af222d9 | 2016-07-08 21:19:32 | [diff] [blame] | 570 | 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] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 581 | void SetParent(Layer* layer); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 582 | bool DescendantIsFixedToContainerLayer() const; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 583 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 584 | // This should only be called from RemoveFromParent(). |
| 585 | void RemoveChildOrDependent(Layer* child); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 586 | |
vollick | 66133e8 | 2014-09-13 20:36:44 | [diff] [blame] | 587 | // 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 | |
weiliangc | c4d2e74d | 2015-06-09 01:21:35 | [diff] [blame] | 595 | // When we detach or attach layer to new LayerTreeHost, all property trees' |
| 596 | // indices becomes invalid. |
| 597 | void InvalidatePropertyTreesIndices(); |
| 598 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 599 | // 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] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 688 | Layer* parent_; |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 689 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 690 | // 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] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 694 | |
khushalsagar | b51998f | 2016-07-08 01:04:21 | [diff] [blame] | 695 | Inputs inputs_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 696 | |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 697 | int num_descendants_that_draw_content_; |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 698 | int transform_tree_index_; |
weiliangc | 6a52f30 | 2015-08-18 16:29:35 | [diff] [blame] | 699 | int effect_tree_index_; |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 700 | int clip_tree_index_; |
sunxd | ea1df789 | 2016-01-28 00:12:33 | [diff] [blame] | 701 | int scroll_tree_index_; |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 702 | int property_tree_sequence_number_; |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 703 | gfx::Vector2dF offset_to_transform_parent_; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 704 | bool should_flatten_transform_from_property_tree_ : 1; |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 705 | bool draws_content_ : 1; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 706 | bool use_local_transform_for_backface_visibility_ : 1; |
| 707 | bool should_check_backface_visibility_ : 1; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 708 | bool force_render_surface_for_testing_ : 1; |
jaydasika | 03a99c4 | 2016-02-11 21:07:08 | [diff] [blame] | 709 | bool subtree_property_changed_ : 1; |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 710 | bool layer_property_changed_ : 1; |
jaydasika | c6326bb | 2016-03-03 03:46:14 | [diff] [blame] | 711 | SkColor safe_opaque_background_color_; |
jaydasika | 92239dc | 2015-08-15 02:59:26 | [diff] [blame] | 712 | // 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_; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 715 | std::unique_ptr<std::set<Layer*>> scroll_children_; |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 716 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 717 | std::unique_ptr<std::set<Layer*>> clip_children_; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 718 | |
[email protected] | 445881f | 2013-04-16 01:11:59 | [diff] [blame] | 719 | PaintProperties paint_properties_; |
| 720 | |
enne | c95e662 | 2015-08-28 23:23:19 | [diff] [blame] | 721 | // These all act like draw properties, so don't need push properties. |
| 722 | gfx::Rect visible_layer_rect_; |
enne | c95e662 | 2015-08-28 23:23:19 | [diff] [blame] | 723 | size_t num_unclipped_descendants_; |
vmpstr | 3d1d72c | 2015-01-26 18:27:40 | [diff] [blame] | 724 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 725 | DISALLOW_COPY_AND_ASSIGN(Layer); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 726 | }; |
| 727 | |
[email protected] | ddf9df8 | 2012-10-16 06:52:46 | [diff] [blame] | 728 | } // namespace cc |
| 729 | |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 730 | #endif // CC_LAYERS_LAYER_H_ |