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