[email protected] | 036e6c97 | 2012-01-03 18:48:05 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 5 | #ifndef UI_COMPOSITOR_LAYER_H_ |
| 6 | #define UI_COMPOSITOR_LAYER_H_ |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 7 | |
[email protected] | 33699e62 | 2011-11-17 18:29:30 | [diff] [blame] | 8 | #include <string> |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
[email protected] | 51f1b48 | 2011-06-23 16:52:12 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
[email protected] | 4e2d03e2 | 2013-07-18 04:19:54 | [diff] [blame] | 14 | #include "base/message_loop/message_loop.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 15 | #include "cc/animation/animation_events.h" |
| 16 | #include "cc/animation/layer_animation_event_observer.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 17 | #include "cc/base/scoped_ptr_vector.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 18 | #include "cc/layers/content_layer_client.h" |
[email protected] | 29e17b0 | 2013-08-30 02:13:33 | [diff] [blame] | 19 | #include "cc/layers/layer_client.h" |
jbauman | dbccae1ab | 2014-11-06 23:26:44 | [diff] [blame] | 20 | #include "cc/layers/surface_layer.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 21 | #include "cc/layers/texture_layer_client.h" |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 22 | #include "cc/resources/texture_mailbox.h" |
[email protected] | ca2c3ea | 2014-07-26 19:35:30 | [diff] [blame] | 23 | #include "cc/surfaces/surface_id.h" |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 24 | #include "third_party/skia/include/core/SkColor.h" |
| 25 | #include "third_party/skia/include/core/SkRegion.h" |
| 26 | #include "ui/compositor/compositor.h" |
| 27 | #include "ui/compositor/layer_animation_delegate.h" |
| 28 | #include "ui/compositor/layer_delegate.h" |
| 29 | #include "ui/compositor/layer_type.h" |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 30 | #include "ui/gfx/rect.h" |
| 31 | #include "ui/gfx/transform.h" |
| 32 | |
[email protected] | 892ad8a | 2011-07-27 02:47:22 | [diff] [blame] | 33 | class SkCanvas; |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 34 | |
[email protected] | ec05af5 | 2012-11-21 23:07:00 | [diff] [blame] | 35 | namespace cc { |
| 36 | class ContentLayer; |
[email protected] | a7fcdda3 | 2013-07-04 02:23:07 | [diff] [blame] | 37 | class CopyOutputRequest; |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 38 | class DelegatedFrameProvider; |
[email protected] | b14d40d | 2013-03-06 03:53:27 | [diff] [blame] | 39 | class DelegatedRendererLayer; |
[email protected] | ec05af5 | 2012-11-21 23:07:00 | [diff] [blame] | 40 | class Layer; |
[email protected] | 98a5913 | 2014-07-16 22:49:52 | [diff] [blame] | 41 | class NinePatchLayer; |
[email protected] | ec05af5 | 2012-11-21 23:07:00 | [diff] [blame] | 42 | class ResourceUpdateQueue; |
| 43 | class SolidColorLayer; |
[email protected] | ca2c3ea | 2014-07-26 19:35:30 | [diff] [blame] | 44 | class SurfaceLayer; |
[email protected] | ec05af5 | 2012-11-21 23:07:00 | [diff] [blame] | 45 | class TextureLayer; |
[email protected] | e00bab02 | 2013-08-19 00:42:45 | [diff] [blame] | 46 | struct ReturnedResource; |
| 47 | typedef std::vector<ReturnedResource> ReturnedResourceArray; |
[email protected] | ec05af5 | 2012-11-21 23:07:00 | [diff] [blame] | 48 | } |
| 49 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 50 | namespace ui { |
| 51 | |
| 52 | class Compositor; |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 53 | class LayerAnimator; |
[email protected] | 07ae973e | 2014-03-05 18:51:10 | [diff] [blame] | 54 | class LayerOwner; |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 55 | |
| 56 | // Layer manages a texture, transform and a set of child Layers. Any View that |
| 57 | // has enabled layers ends up creating a Layer to manage the texture. |
[email protected] | 28cd2bb | 2011-09-19 21:04:19 | [diff] [blame] | 58 | // A Layer can also be created without a texture, in which case it renders |
| 59 | // nothing and is simply used as a node in a hierarchy of layers. |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 60 | // Coordinate system used in layers is DIP (Density Independent Pixel) |
| 61 | // coordinates unless explicitly mentioned as pixel coordinates. |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 62 | // |
[email protected] | ae2202a | 2014-01-07 11:11:10 | [diff] [blame] | 63 | // NOTE: Unlike Views, each Layer does *not* own its child Layers. If you |
| 64 | // delete a Layer and it has children, the parent of each child Layer is set to |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 65 | // NULL, but the children are not deleted. |
[email protected] | 2700daddd | 2012-07-13 19:35:37 | [diff] [blame] | 66 | class COMPOSITOR_EXPORT Layer |
| 67 | : public LayerAnimationDelegate, |
[email protected] | ec05af5 | 2012-11-21 23:07:00 | [diff] [blame] | 68 | NON_EXPORTED_BASE(public cc::ContentLayerClient), |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 69 | NON_EXPORTED_BASE(public cc::TextureLayerClient), |
[email protected] | 29e17b0 | 2013-08-30 02:13:33 | [diff] [blame] | 70 | NON_EXPORTED_BASE(public cc::LayerClient), |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 71 | NON_EXPORTED_BASE(public cc::LayerAnimationEventObserver) { |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 72 | public: |
[email protected] | 7ab3f27 | 2011-11-16 00:51:56 | [diff] [blame] | 73 | Layer(); |
| 74 | explicit Layer(LayerType type); |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 75 | ~Layer() override; |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 76 | |
[email protected] | dafdf505 | 2014-03-13 17:02:57 | [diff] [blame] | 77 | static bool UsingPictureLayer(); |
| 78 | |
[email protected] | 993d6b32 | 2011-09-27 19:14:38 | [diff] [blame] | 79 | // Retrieves the Layer's compositor. The Layer will walk up its parent chain |
| 80 | // to locate it. Returns NULL if the Layer is not attached to a compositor. |
sky | 6dd20609 | 2014-10-29 17:26:16 | [diff] [blame] | 81 | Compositor* GetCompositor() { |
| 82 | return const_cast<Compositor*>( |
| 83 | const_cast<const Layer*>(this)->GetCompositor()); |
| 84 | } |
| 85 | const Compositor* GetCompositor() const; |
[email protected] | 993d6b32 | 2011-09-27 19:14:38 | [diff] [blame] | 86 | |
| 87 | // Called by the compositor when the Layer is set as its root Layer. This can |
| 88 | // only ever be called on the root layer. |
| 89 | void SetCompositor(Compositor* compositor); |
| 90 | |
[email protected] | 00b8698 | 2011-09-01 00:02:09 | [diff] [blame] | 91 | LayerDelegate* delegate() { return delegate_; } |
| 92 | void set_delegate(LayerDelegate* delegate) { delegate_ = delegate; } |
| 93 | |
[email protected] | 07ae973e | 2014-03-05 18:51:10 | [diff] [blame] | 94 | LayerOwner* owner() { return owner_; } |
| 95 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 96 | // Adds a new Layer to this Layer. |
| 97 | void Add(Layer* child); |
| 98 | |
| 99 | // Removes a Layer from this Layer. |
| 100 | void Remove(Layer* child); |
| 101 | |
[email protected] | 5e4e61f | 2011-11-22 16:55:24 | [diff] [blame] | 102 | // Stacks |child| above all other children. |
| 103 | void StackAtTop(Layer* child); |
[email protected] | 18dab37 | 2011-10-03 21:21:44 | [diff] [blame] | 104 | |
[email protected] | ebc335f | 2011-11-23 00:43:51 | [diff] [blame] | 105 | // Stacks |child| directly above |other|. Both must be children of this |
| 106 | // layer. Note that if |child| is initially stacked even higher, calling this |
| 107 | // method will result in |child| being lowered in the stacking order. |
[email protected] | 5e4e61f | 2011-11-22 16:55:24 | [diff] [blame] | 108 | void StackAbove(Layer* child, Layer* other); |
[email protected] | 62dd7ea | 2011-11-08 15:51:47 | [diff] [blame] | 109 | |
[email protected] | 44c6f8d | 2011-12-27 23:49:04 | [diff] [blame] | 110 | // Stacks |child| below all other children. |
| 111 | void StackAtBottom(Layer* child); |
| 112 | |
| 113 | // Stacks |child| directly below |other|. Both must be children of this |
| 114 | // layer. |
| 115 | void StackBelow(Layer* child, Layer* other); |
| 116 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 117 | // Returns the child Layers. |
[email protected] | 25ae9a1 | 2011-10-12 14:55:22 | [diff] [blame] | 118 | const std::vector<Layer*>& children() const { return children_; } |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 119 | |
| 120 | // The parent. |
| 121 | const Layer* parent() const { return parent_; } |
| 122 | Layer* parent() { return parent_; } |
| 123 | |
[email protected] | 036e6c97 | 2012-01-03 18:48:05 | [diff] [blame] | 124 | LayerType type() const { return type_; } |
| 125 | |
[email protected] | ad725891 | 2011-08-29 20:33:53 | [diff] [blame] | 126 | // Returns true if this Layer contains |other| somewhere in its children. |
| 127 | bool Contains(const Layer* other) const; |
| 128 | |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 129 | // The layer's animator is responsible for causing automatic animations when |
| 130 | // properties are set. It also manages a queue of pending animations and |
| 131 | // handles blending of animations. The layer takes ownership of the animator. |
| 132 | void SetAnimator(LayerAnimator* animator); |
| 133 | |
| 134 | // Returns the layer's animator. Creates a default animator of one has not |
| 135 | // been set. Will not return NULL. |
| 136 | LayerAnimator* GetAnimator(); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 137 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 138 | // The transform, relative to the parent. |
[email protected] | 0f0453e | 2012-10-14 18:15:35 | [diff] [blame] | 139 | void SetTransform(const gfx::Transform& transform); |
[email protected] | 712f4b64 | 2013-03-14 07:09:15 | [diff] [blame] | 140 | gfx::Transform transform() const; |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 141 | |
| 142 | // Return the target transform if animator is running, or the current |
| 143 | // transform otherwise. |
[email protected] | 0f0453e | 2012-10-14 18:15:35 | [diff] [blame] | 144 | gfx::Transform GetTargetTransform() const; |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 145 | |
| 146 | // The bounds, relative to the parent. |
[email protected] | c155c25 | 2011-07-29 16:17:55 | [diff] [blame] | 147 | void SetBounds(const gfx::Rect& bounds); |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 148 | const gfx::Rect& bounds() const { return bounds_; } |
| 149 | |
[email protected] | ea291015 | 2014-06-10 12:32:35 | [diff] [blame] | 150 | // The offset from our parent (stored in bounds.origin()) is an integer but we |
| 151 | // may need to be at a fractional pixel offset to align properly on screen. |
| 152 | void SetSubpixelPositionOffset(const gfx::Vector2dF offset); |
[email protected] | e09c592ff | 2014-07-17 06:55:07 | [diff] [blame] | 153 | const gfx::Vector2dF& subpixel_position_offset() const { |
| 154 | return subpixel_position_offset_; |
| 155 | } |
[email protected] | ea291015 | 2014-06-10 12:32:35 | [diff] [blame] | 156 | |
[email protected] | 5ba9d5f | 2011-10-20 01:58:33 | [diff] [blame] | 157 | // Return the target bounds if animator is running, or the current bounds |
| 158 | // otherwise. |
| 159 | gfx::Rect GetTargetBounds() const; |
| 160 | |
[email protected] | 7adee63 | 2012-03-15 19:15:08 | [diff] [blame] | 161 | // Sets/gets whether or not drawing of child layers should be clipped to the |
| 162 | // bounds of this layer. |
| 163 | void SetMasksToBounds(bool masks_to_bounds); |
| 164 | bool GetMasksToBounds() const; |
| 165 | |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 166 | // The opacity of the layer. The opacity is applied to each pixel of the |
| 167 | // texture (resulting alpha = opacity * alpha). |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 168 | float opacity() const; |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 169 | void SetOpacity(float opacity); |
| 170 | |
[email protected] | fb4d9d1 | 2012-08-24 00:44:54 | [diff] [blame] | 171 | // Returns the actual opacity, which the opacity of this layer multipled by |
| 172 | // the combined opacity of the parent. |
| 173 | float GetCombinedOpacity() const; |
| 174 | |
[email protected] | 2a6c567 | 2012-04-23 19:37:09 | [diff] [blame] | 175 | // Blur pixels by this amount in anything below the layer and visible through |
| 176 | // the layer. |
| 177 | int background_blur() const { return background_blur_radius_; } |
| 178 | void SetBackgroundBlur(int blur_radius); |
| 179 | |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 180 | // Saturate all pixels of this layer by this amount. |
[email protected] | 815d0c38 | 2012-07-21 08:13:44 | [diff] [blame] | 181 | // This effect will get "combined" with the inverted, |
| 182 | // brightness and grayscale setting. |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 183 | float layer_saturation() const { return layer_saturation_; } |
| 184 | void SetLayerSaturation(float saturation); |
| 185 | |
| 186 | // Change the brightness of all pixels from this layer by this amount. |
[email protected] | 815d0c38 | 2012-07-21 08:13:44 | [diff] [blame] | 187 | // This effect will get "combined" with the inverted, saturate |
| 188 | // and grayscale setting. |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 189 | float layer_brightness() const { return layer_brightness_; } |
| 190 | void SetLayerBrightness(float brightness); |
| 191 | |
[email protected] | 815d0c38 | 2012-07-21 08:13:44 | [diff] [blame] | 192 | // Return the target brightness if animator is running, or the current |
| 193 | // brightness otherwise. |
| 194 | float GetTargetBrightness() const; |
| 195 | |
| 196 | // Change the grayscale of all pixels from this layer by this amount. |
| 197 | // This effect will get "combined" with the inverted, saturate |
| 198 | // and brightness setting. |
| 199 | float layer_grayscale() const { return layer_grayscale_; } |
| 200 | void SetLayerGrayscale(float grayscale); |
| 201 | |
| 202 | // Return the target grayscale if animator is running, or the current |
| 203 | // grayscale otherwise. |
| 204 | float GetTargetGrayscale() const; |
| 205 | |
[email protected] | 56322be | 2013-03-13 18:27:37 | [diff] [blame] | 206 | // Zoom the background by a factor of |zoom|. The effect is blended along the |
| 207 | // edge across |inset| pixels. |
| 208 | void SetBackgroundZoom(float zoom, int inset); |
[email protected] | 77f7c13 | 2012-11-15 06:52:54 | [diff] [blame] | 209 | |
[email protected] | fbb145c | 2014-04-16 19:21:28 | [diff] [blame] | 210 | // Set the shape of this layer. |
jackhou | 1d1fa23 | 2014-09-11 01:18:41 | [diff] [blame] | 211 | SkRegion* alpha_shape() const { return alpha_shape_.get(); } |
[email protected] | fbb145c | 2014-04-16 19:21:28 | [diff] [blame] | 212 | void SetAlphaShape(scoped_ptr<SkRegion> region); |
| 213 | |
[email protected] | f48075d | 2012-05-24 11:06:51 | [diff] [blame] | 214 | // Invert the layer. |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 215 | bool layer_inverted() const { return layer_inverted_; } |
| 216 | void SetLayerInverted(bool inverted); |
[email protected] | f48075d | 2012-05-24 11:06:51 | [diff] [blame] | 217 | |
[email protected] | 3f1f5e6a | 2011-11-11 15:09:02 | [diff] [blame] | 218 | // Return the target opacity if animator is running, or the current opacity |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 219 | // otherwise. |
| 220 | float GetTargetOpacity() const; |
| 221 | |
[email protected] | 498e623c | 2012-07-12 21:12:42 | [diff] [blame] | 222 | // Set a layer mask for a layer. |
| 223 | // Note the provided layer mask can neither have a layer mask itself nor can |
[email protected] | c0dc4b17 | 2014-01-07 11:24:09 | [diff] [blame] | 224 | // it have any children. The ownership of |layer_mask| will not be |
| 225 | // transferred with this call. |
[email protected] | 498e623c | 2012-07-12 21:12:42 | [diff] [blame] | 226 | // Furthermore: A mask layer can only be set to one layer. |
[email protected] | c0dc4b17 | 2014-01-07 11:24:09 | [diff] [blame] | 227 | void SetMaskLayer(Layer* layer_mask); |
| 228 | Layer* layer_mask_layer() { return layer_mask_; } |
[email protected] | 498e623c | 2012-07-12 21:12:42 | [diff] [blame] | 229 | |
[email protected] | e4e8afef | 2011-10-05 13:58:33 | [diff] [blame] | 230 | // Sets the visibility of the Layer. A Layer may be visible but not |
| 231 | // drawn. This happens if any ancestor of a Layer is not visible. |
[email protected] | 993d6b32 | 2011-09-27 19:14:38 | [diff] [blame] | 232 | void SetVisible(bool visible); |
[email protected] | f941f47a | 2011-10-15 18:44:51 | [diff] [blame] | 233 | bool visible() const { return visible_; } |
[email protected] | 3aa4394 | 2011-09-13 20:59:53 | [diff] [blame] | 234 | |
[email protected] | a67935f | 2012-02-10 14:26:24 | [diff] [blame] | 235 | // Returns the target visibility if the animator is running. Otherwise, it |
| 236 | // returns the current visibility. |
| 237 | bool GetTargetVisibility() const; |
| 238 | |
[email protected] | e4e8afef | 2011-10-05 13:58:33 | [diff] [blame] | 239 | // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors |
| 240 | // are visible. |
| 241 | bool IsDrawn() const; |
| 242 | |
[email protected] | c1f6730 | 2011-09-27 14:18:09 | [diff] [blame] | 243 | // Returns true if this layer can have a texture (has_texture_ is true) |
| 244 | // and is not completely obscured by a child. |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 245 | bool ShouldDraw() const; |
[email protected] | c1f6730 | 2011-09-27 14:18:09 | [diff] [blame] | 246 | |
[email protected] | ad725891 | 2011-08-29 20:33:53 | [diff] [blame] | 247 | // Converts a point from the coordinates of |source| to the coordinates of |
| 248 | // |target|. Necessarily, |source| and |target| must inhabit the same Layer |
| 249 | // tree. |
| 250 | static void ConvertPointToLayer(const Layer* source, |
| 251 | const Layer* target, |
| 252 | gfx::Point* point); |
| 253 | |
[email protected] | bdcf3bbf | 2013-03-25 18:39:03 | [diff] [blame] | 254 | // Converts a transform to be relative to the given |ancestor|. Returns |
| 255 | // whether success (that is, whether the given ancestor was really an |
| 256 | // ancestor of this layer). |
| 257 | bool GetTargetTransformRelativeTo(const Layer* ancestor, |
| 258 | gfx::Transform* transform) const; |
| 259 | |
[email protected] | c155c25 | 2011-07-29 16:17:55 | [diff] [blame] | 260 | // See description in View for details |
| 261 | void SetFillsBoundsOpaquely(bool fills_bounds_opaquely); |
| 262 | bool fills_bounds_opaquely() const { return fills_bounds_opaquely_; } |
| 263 | |
[email protected] | 1d96e03 | 2014-03-25 05:59:08 | [diff] [blame] | 264 | // Set to true if this layer always paints completely within its bounds. If so |
| 265 | // we can omit an unnecessary clear, even if the layer is transparent. |
| 266 | void SetFillsBoundsCompletely(bool fills_bounds_completely); |
| 267 | |
[email protected] | 33699e62 | 2011-11-17 18:29:30 | [diff] [blame] | 268 | const std::string& name() const { return name_; } |
| 269 | void set_name(const std::string& name) { name_ = name; } |
| 270 | |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 271 | // Set new TextureMailbox for this layer. Note that |mailbox| may hold a |
| 272 | // shared memory resource or an actual mailbox for a texture. |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 273 | void SetTextureMailbox(const cc::TextureMailbox& mailbox, |
| 274 | scoped_ptr<cc::SingleReleaseCallback> release_callback, |
[email protected] | 4508b15 | 2014-04-09 22:14:17 | [diff] [blame] | 275 | gfx::Size texture_size_in_dip); |
| 276 | void SetTextureSize(gfx::Size texture_size_in_dip); |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 277 | |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 278 | // Begins showing delegated frames from the |frame_provider|. |
| 279 | void SetShowDelegatedContent(cc::DelegatedFrameProvider* frame_provider, |
| 280 | gfx::Size frame_size_in_dip); |
[email protected] | b14d40d | 2013-03-06 03:53:27 | [diff] [blame] | 281 | |
[email protected] | ca2c3ea | 2014-07-26 19:35:30 | [diff] [blame] | 282 | // Begins showing content from a surface with a particular id. |
jbauman | dbccae1ab | 2014-11-06 23:26:44 | [diff] [blame] | 283 | void SetShowSurface(cc::SurfaceId surface_id, |
| 284 | const cc::SurfaceLayer::SatisfyCallback& satisfy_callback, |
| 285 | const cc::SurfaceLayer::RequireCallback& require_callback, |
jbauman | 5a8f0ab | 2014-11-07 01:41:16 | [diff] [blame^] | 286 | gfx::Size surface_size, |
jbauman | dbccae1ab | 2014-11-06 23:26:44 | [diff] [blame] | 287 | gfx::Size frame_size_in_dip); |
[email protected] | ca2c3ea | 2014-07-26 19:35:30 | [diff] [blame] | 288 | |
[email protected] | a7fcdda3 | 2013-07-04 02:23:07 | [diff] [blame] | 289 | bool has_external_content() { |
[email protected] | ca2c3ea | 2014-07-26 19:35:30 | [diff] [blame] | 290 | return texture_layer_.get() || delegated_renderer_layer_.get() || |
| 291 | surface_layer_.get(); |
[email protected] | a7fcdda3 | 2013-07-04 02:23:07 | [diff] [blame] | 292 | } |
| 293 | |
jbauman | f472c687 | 2014-10-13 20:06:43 | [diff] [blame] | 294 | // Show a solid color instead of delegated or surface contents. |
| 295 | void SetShowSolidColorContent(); |
[email protected] | 785b0af | 2013-10-02 18:08:41 | [diff] [blame] | 296 | |
[email protected] | da7584c | 2012-01-28 03:19:12 | [diff] [blame] | 297 | // Sets the layer's fill color. May only be called for LAYER_SOLID_COLOR. |
| 298 | void SetColor(SkColor color); |
| 299 | |
hshi | d89c83ac | 2014-09-19 17:39:28 | [diff] [blame] | 300 | // Updates the nine patch layer's bitmap, aperture and border. May only be |
| 301 | // called for LAYER_NINE_PATCH. |
| 302 | void UpdateNinePatchLayerBitmap(const SkBitmap& bitmap); |
| 303 | void UpdateNinePatchLayerAperture(const gfx::Rect& aperture); |
[email protected] | 98a5913 | 2014-07-16 22:49:52 | [diff] [blame] | 304 | void UpdateNinePatchLayerBorder(const gfx::Rect& border); |
| 305 | |
[email protected] | 870119a | 2011-09-30 18:13:22 | [diff] [blame] | 306 | // Adds |invalid_rect| to the Layer's pending invalid rect and calls |
[email protected] | f78649ea | 2012-02-23 18:39:04 | [diff] [blame] | 307 | // ScheduleDraw(). Returns false if the paint request is ignored. |
| 308 | bool SchedulePaint(const gfx::Rect& invalid_rect); |
[email protected] | 00b8698 | 2011-09-01 00:02:09 | [diff] [blame] | 309 | |
[email protected] | 870119a | 2011-09-30 18:13:22 | [diff] [blame] | 310 | // Schedules a redraw of the layer tree at the compositor. |
[email protected] | 35470cc | 2012-02-23 23:04:31 | [diff] [blame] | 311 | // Note that this _does not_ invalidate any region of this layer; use |
| 312 | // SchedulePaint() for that. |
[email protected] | 870119a | 2011-09-30 18:13:22 | [diff] [blame] | 313 | void ScheduleDraw(); |
| 314 | |
[email protected] | 1e5da63d | 2014-01-16 22:44:00 | [diff] [blame] | 315 | // Uses damaged rectangles recorded in |damaged_region_| to invalidate the |
| 316 | // |cc_layer_|. |
[email protected] | cedc395 | 2012-03-06 06:15:55 | [diff] [blame] | 317 | void SendDamagedRects(); |
[email protected] | f78649ea | 2012-02-23 18:39:04 | [diff] [blame] | 318 | |
[email protected] | 88fa18e8 | 2013-12-03 16:29:37 | [diff] [blame] | 319 | const SkRegion& damaged_region() const { return damaged_region_; } |
| 320 | |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 321 | void CompleteAllAnimations(); |
| 322 | |
[email protected] | 1e5da63d | 2014-01-16 22:44:00 | [diff] [blame] | 323 | // Suppresses painting the content by disconnecting |delegate_|. |
[email protected] | f78649ea | 2012-02-23 18:39:04 | [diff] [blame] | 324 | void SuppressPaint(); |
| 325 | |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 326 | // Notifies the layer that the device scale factor has changed. |
| 327 | void OnDeviceScaleFactorChanged(float device_scale_factor); |
| 328 | |
enne | 9a3ddb3 | 2014-08-23 21:27:46 | [diff] [blame] | 329 | // Notifies the layer that one of its children has received a new |
| 330 | // delegated frame. |
| 331 | void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip); |
| 332 | |
[email protected] | a7fcdda3 | 2013-07-04 02:23:07 | [diff] [blame] | 333 | // Requets a copy of the layer's output as a texture or bitmap. |
| 334 | void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); |
| 335 | |
[email protected] | ec05af5 | 2012-11-21 23:07:00 | [diff] [blame] | 336 | // ContentLayerClient |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 337 | void PaintContents( |
[email protected] | 276172b | 2014-05-02 21:03:03 | [diff] [blame] | 338 | SkCanvas* canvas, |
| 339 | const gfx::Rect& clip, |
mostynb | 3b3d52b | 2014-10-09 10:54:27 | [diff] [blame] | 340 | ContentLayerClient::GraphicsContextStatus gc_status) override; |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 341 | void DidChangeLayerCanUseLCDText() override {} |
| 342 | bool FillsBoundsCompletely() const override; |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 343 | |
[email protected] | ec05af5 | 2012-11-21 23:07:00 | [diff] [blame] | 344 | cc::Layer* cc_layer() { return cc_layer_; } |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 345 | |
[email protected] | ec05af5 | 2012-11-21 23:07:00 | [diff] [blame] | 346 | // TextureLayerClient |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 347 | bool PrepareTextureMailbox( |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 348 | cc::TextureMailbox* mailbox, |
| 349 | scoped_ptr<cc::SingleReleaseCallback>* release_callback, |
mostynb | 3b3d52b | 2014-10-09 10:54:27 | [diff] [blame] | 350 | bool use_shared_memory) override; |
[email protected] | 7ba5f4b6 | 2012-08-25 01:19:36 | [diff] [blame] | 351 | |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 352 | float device_scale_factor() const { return device_scale_factor_; } |
| 353 | |
[email protected] | 09c01c1 | 2012-05-26 00:07:19 | [diff] [blame] | 354 | // Forces a render surface to be used on this layer. This has no positive |
| 355 | // impact, and is only used for benchmarking/testing purpose. |
| 356 | void SetForceRenderSurface(bool force); |
| 357 | bool force_render_surface() const { return force_render_surface_; } |
| 358 | |
[email protected] | 29e17b0 | 2013-08-30 02:13:33 | [diff] [blame] | 359 | // LayerClient |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 360 | scoped_refptr<base::debug::ConvertableToTraceFormat> TakeDebugInfo() override; |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 361 | |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 362 | // LayerAnimationEventObserver |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 363 | void OnAnimationStarted(const cc::AnimationEvent& event) override; |
[email protected] | bf91227 | 2013-02-23 01:54:16 | [diff] [blame] | 364 | |
[email protected] | f289146 | 2013-03-11 23:26:51 | [diff] [blame] | 365 | // Whether this layer has animations waiting to get sent to its cc::Layer. |
| 366 | bool HasPendingThreadedAnimations() { |
| 367 | return pending_threaded_animations_.size() != 0; |
| 368 | } |
| 369 | |
[email protected] | ffd1ccb | 2013-03-15 07:48:24 | [diff] [blame] | 370 | // Triggers a call to SwitchToLayer. |
| 371 | void SwitchCCLayerForTest(); |
| 372 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 373 | private: |
[email protected] | 07ae973e | 2014-03-05 18:51:10 | [diff] [blame] | 374 | friend class LayerOwner; |
| 375 | |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 376 | void CollectAnimators(std::vector<scoped_refptr<LayerAnimator> >* animators); |
| 377 | |
[email protected] | 44c6f8d | 2011-12-27 23:49:04 | [diff] [blame] | 378 | // Stacks |child| above or below |other|. Helper method for StackAbove() and |
| 379 | // StackBelow(). |
| 380 | void StackRelativeTo(Layer* child, Layer* other, bool above); |
| 381 | |
[email protected] | ad725891 | 2011-08-29 20:33:53 | [diff] [blame] | 382 | bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; |
| 383 | bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; |
| 384 | |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 385 | // Implementation of LayerAnimatorDelegate |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 386 | void SetBoundsFromAnimation(const gfx::Rect& bounds) override; |
| 387 | void SetTransformFromAnimation(const gfx::Transform& transform) override; |
| 388 | void SetOpacityFromAnimation(float opacity) override; |
| 389 | void SetVisibilityFromAnimation(bool visibility) override; |
| 390 | void SetBrightnessFromAnimation(float brightness) override; |
| 391 | void SetGrayscaleFromAnimation(float grayscale) override; |
| 392 | void SetColorFromAnimation(SkColor color) override; |
| 393 | void ScheduleDrawForAnimation() override; |
| 394 | const gfx::Rect& GetBoundsForAnimation() const override; |
| 395 | gfx::Transform GetTransformForAnimation() const override; |
| 396 | float GetOpacityForAnimation() const override; |
| 397 | bool GetVisibilityForAnimation() const override; |
| 398 | float GetBrightnessForAnimation() const override; |
| 399 | float GetGrayscaleForAnimation() const override; |
| 400 | SkColor GetColorForAnimation() const override; |
| 401 | float GetDeviceScaleFactor() const override; |
| 402 | void AddThreadedAnimation(scoped_ptr<cc::Animation> animation) override; |
| 403 | void RemoveThreadedAnimation(int animation_id) override; |
| 404 | LayerAnimatorCollection* GetLayerAnimatorCollection() override; |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 405 | |
[email protected] | 1e5da63d | 2014-01-16 22:44:00 | [diff] [blame] | 406 | // Creates a corresponding composited layer for |type_|. |
jbauman | f472c687 | 2014-10-13 20:06:43 | [diff] [blame] | 407 | void CreateCcLayer(); |
[email protected] | 1e5da63d | 2014-01-16 22:44:00 | [diff] [blame] | 408 | |
| 409 | // Recomputes and sets to |cc_layer_|. |
[email protected] | b9616d59 | 2011-11-14 20:04:42 | [diff] [blame] | 410 | void RecomputeDrawsContentAndUVRect(); |
[email protected] | b9cff56 | 2013-04-06 00:04:42 | [diff] [blame] | 411 | void RecomputePosition(); |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 412 | |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 413 | // Set all filters which got applied to the layer. |
| 414 | void SetLayerFilters(); |
| 415 | |
[email protected] | 77f7c13 | 2012-11-15 06:52:54 | [diff] [blame] | 416 | // Set all filters which got applied to the layer background. |
| 417 | void SetLayerBackgroundFilters(); |
| 418 | |
[email protected] | 1e5da63d | 2014-01-16 22:44:00 | [diff] [blame] | 419 | // Cleanup |cc_layer_| and replaces it with |new_layer|. |
[email protected] | b14d40d | 2013-03-06 03:53:27 | [diff] [blame] | 420 | void SwitchToLayer(scoped_refptr<cc::Layer> new_layer); |
| 421 | |
[email protected] | f289146 | 2013-03-11 23:26:51 | [diff] [blame] | 422 | // We cannot send animations to our cc_layer_ until we have been added to a |
| 423 | // layer tree. Instead, we hold on to these animations in |
| 424 | // pending_threaded_animations_, and expect SendPendingThreadedAnimations to |
| 425 | // be called once we have been added to a tree. |
| 426 | void SendPendingThreadedAnimations(); |
| 427 | |
[email protected] | 9034a28 | 2014-06-05 03:11:47 | [diff] [blame] | 428 | void AddAnimatorsInTreeToCollection(LayerAnimatorCollection* collection); |
| 429 | void RemoveAnimatorsInTreeFromCollection(LayerAnimatorCollection* collection); |
| 430 | |
| 431 | // Returns whether the layer has an animating LayerAnimator. |
| 432 | bool IsAnimating() const; |
| 433 | |
[email protected] | 993d6b32 | 2011-09-27 19:14:38 | [diff] [blame] | 434 | const LayerType type_; |
| 435 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 436 | Compositor* compositor_; |
| 437 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 438 | Layer* parent_; |
| 439 | |
[email protected] | ebc335f | 2011-11-23 00:43:51 | [diff] [blame] | 440 | // This layer's children, in bottom-to-top stacking order. |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 441 | std::vector<Layer*> children_; |
| 442 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 443 | gfx::Rect bounds_; |
[email protected] | ea291015 | 2014-06-10 12:32:35 | [diff] [blame] | 444 | gfx::Vector2dF subpixel_position_offset_; |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 445 | |
[email protected] | e4e8afef | 2011-10-05 13:58:33 | [diff] [blame] | 446 | // Visibility of this layer. See SetVisible/IsDrawn for more details. |
[email protected] | 3aa4394 | 2011-09-13 20:59:53 | [diff] [blame] | 447 | bool visible_; |
| 448 | |
[email protected] | 09c01c1 | 2012-05-26 00:07:19 | [diff] [blame] | 449 | bool force_render_surface_; |
| 450 | |
[email protected] | c155c25 | 2011-07-29 16:17:55 | [diff] [blame] | 451 | bool fills_bounds_opaquely_; |
[email protected] | 1d96e03 | 2014-03-25 05:59:08 | [diff] [blame] | 452 | bool fills_bounds_completely_; |
[email protected] | c155c25 | 2011-07-29 16:17:55 | [diff] [blame] | 453 | |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 454 | // Union of damaged rects, in pixel coordinates, to be used when |
| 455 | // compositor is ready to paint the content. |
[email protected] | cedc395 | 2012-03-06 06:15:55 | [diff] [blame] | 456 | SkRegion damaged_region_; |
[email protected] | f78649ea | 2012-02-23 18:39:04 | [diff] [blame] | 457 | |
[email protected] | 2a6c567 | 2012-04-23 19:37:09 | [diff] [blame] | 458 | int background_blur_radius_; |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 459 | |
| 460 | // Several variables which will change the visible representation of |
| 461 | // the layer. |
| 462 | float layer_saturation_; |
| 463 | float layer_brightness_; |
[email protected] | 815d0c38 | 2012-07-21 08:13:44 | [diff] [blame] | 464 | float layer_grayscale_; |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 465 | bool layer_inverted_; |
[email protected] | b4bb9ca | 2011-09-23 20:53:14 | [diff] [blame] | 466 | |
[email protected] | c0dc4b17 | 2014-01-07 11:24:09 | [diff] [blame] | 467 | // The associated mask layer with this layer. |
| 468 | Layer* layer_mask_; |
| 469 | // The back link from the mask layer to it's associated masked layer. |
| 470 | // We keep this reference for the case that if the mask layer gets deleted |
| 471 | // while attached to the main layer before the main layer is deleted. |
| 472 | Layer* layer_mask_back_link_; |
[email protected] | 498e623c | 2012-07-12 21:12:42 | [diff] [blame] | 473 | |
[email protected] | 77f7c13 | 2012-11-15 06:52:54 | [diff] [blame] | 474 | // The zoom factor to scale the layer by. Zooming is disabled when this is |
| 475 | // set to 1. |
| 476 | float zoom_; |
| 477 | |
| 478 | // Width of the border in pixels, where the scaling is blended. |
| 479 | int zoom_inset_; |
| 480 | |
[email protected] | fbb145c | 2014-04-16 19:21:28 | [diff] [blame] | 481 | // Shape of the window. |
| 482 | scoped_ptr<SkRegion> alpha_shape_; |
| 483 | |
[email protected] | 33699e62 | 2011-11-17 18:29:30 | [diff] [blame] | 484 | std::string name_; |
| 485 | |
[email protected] | 00b8698 | 2011-09-01 00:02:09 | [diff] [blame] | 486 | LayerDelegate* delegate_; |
| 487 | |
[email protected] | 07ae973e | 2014-03-05 18:51:10 | [diff] [blame] | 488 | LayerOwner* owner_; |
| 489 | |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame] | 490 | scoped_refptr<LayerAnimator> animator_; |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 491 | |
[email protected] | f289146 | 2013-03-11 23:26:51 | [diff] [blame] | 492 | // Animations that are passed to AddThreadedAnimation before this layer is |
| 493 | // added to a tree. |
| 494 | cc::ScopedPtrVector<cc::Animation> pending_threaded_animations_; |
| 495 | |
[email protected] | 66efabe | 2012-08-18 03:06:06 | [diff] [blame] | 496 | // Ownership of the layer is held through one of the strongly typed layer |
| 497 | // pointers, depending on which sort of layer this is. |
[email protected] | dafdf505 | 2014-03-13 17:02:57 | [diff] [blame] | 498 | scoped_refptr<cc::Layer> content_layer_; |
[email protected] | 98a5913 | 2014-07-16 22:49:52 | [diff] [blame] | 499 | scoped_refptr<cc::NinePatchLayer> nine_patch_layer_; |
[email protected] | ec05af5 | 2012-11-21 23:07:00 | [diff] [blame] | 500 | scoped_refptr<cc::TextureLayer> texture_layer_; |
| 501 | scoped_refptr<cc::SolidColorLayer> solid_color_layer_; |
[email protected] | b14d40d | 2013-03-06 03:53:27 | [diff] [blame] | 502 | scoped_refptr<cc::DelegatedRendererLayer> delegated_renderer_layer_; |
[email protected] | ca2c3ea | 2014-07-26 19:35:30 | [diff] [blame] | 503 | scoped_refptr<cc::SurfaceLayer> surface_layer_; |
[email protected] | ec05af5 | 2012-11-21 23:07:00 | [diff] [blame] | 504 | cc::Layer* cc_layer_; |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 505 | |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 506 | // A cached copy of |Compositor::device_scale_factor()|. |
| 507 | float device_scale_factor_; |
| 508 | |
[email protected] | 4508b15 | 2014-04-09 22:14:17 | [diff] [blame] | 509 | // The mailbox used by texture_layer_. |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 510 | cc::TextureMailbox mailbox_; |
| 511 | |
[email protected] | 4508b15 | 2014-04-09 22:14:17 | [diff] [blame] | 512 | // The callback to release the mailbox. This is only set after |
| 513 | // SetTextureMailbox is called, before we give it to the TextureLayer. |
| 514 | scoped_ptr<cc::SingleReleaseCallback> mailbox_release_callback_; |
[email protected] | 42f40a5 | 2013-06-08 04:38:51 | [diff] [blame] | 515 | |
[email protected] | 4508b15 | 2014-04-09 22:14:17 | [diff] [blame] | 516 | // The size of the frame or texture in DIP, set when SetShowDelegatedContent |
| 517 | // or SetTextureMailbox was called. |
| 518 | gfx::Size frame_size_in_dip_; |
[email protected] | b14d40d | 2013-03-06 03:53:27 | [diff] [blame] | 519 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 520 | DISALLOW_COPY_AND_ASSIGN(Layer); |
| 521 | }; |
| 522 | |
| 523 | } // namespace ui |
| 524 | |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 525 | #endif // UI_COMPOSITOR_LAYER_H_ |