[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] | 00b8698 | 2011-09-01 00:02:09 | [diff] [blame] | 14 | #include "base/message_loop.h" |
[email protected] | 2a6c567 | 2012-04-23 19:37:09 | [diff] [blame] | 15 | #include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayerClient.h" |
[email protected] | 7ba5f4b6 | 2012-08-25 01:19:36 | [diff] [blame] | 16 | #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureLayerClient.h" |
[email protected] | 2a6c567 | 2012-04-23 19:37:09 | [diff] [blame] | 17 | #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" |
[email protected] | 66efabe | 2012-08-18 03:06:06 | [diff] [blame] | 18 | #include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayer.h" |
| 19 | #include "third_party/WebKit/Source/Platform/chromium/public/WebSolidColorLayer.h" |
| 20 | #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureLayer.h" |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 21 | #include "third_party/skia/include/core/SkColor.h" |
| 22 | #include "third_party/skia/include/core/SkRegion.h" |
| 23 | #include "ui/compositor/compositor.h" |
| 24 | #include "ui/compositor/layer_animation_delegate.h" |
| 25 | #include "ui/compositor/layer_delegate.h" |
| 26 | #include "ui/compositor/layer_type.h" |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 27 | #include "ui/gfx/rect.h" |
| 28 | #include "ui/gfx/transform.h" |
| 29 | |
[email protected] | 892ad8a | 2011-07-27 02:47:22 | [diff] [blame] | 30 | class SkCanvas; |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 31 | |
| 32 | namespace ui { |
| 33 | |
| 34 | class Compositor; |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 35 | class LayerAnimator; |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 36 | class Texture; |
| 37 | |
| 38 | // Layer manages a texture, transform and a set of child Layers. Any View that |
| 39 | // has enabled layers ends up creating a Layer to manage the texture. |
[email protected] | 28cd2bb | 2011-09-19 21:04:19 | [diff] [blame] | 40 | // A Layer can also be created without a texture, in which case it renders |
| 41 | // nothing and is simply used as a node in a hierarchy of layers. |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 42 | // Coordinate system used in layers is DIP (Density Independent Pixel) |
| 43 | // coordinates unless explicitly mentioned as pixel coordinates. |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 44 | // |
| 45 | // NOTE: unlike Views, each Layer does *not* own its children views. If you |
| 46 | // delete a Layer and it has children, the parent of each child layer is set to |
| 47 | // NULL, but the children are not deleted. |
[email protected] | 2700daddd | 2012-07-13 19:35:37 | [diff] [blame] | 48 | class COMPOSITOR_EXPORT Layer |
| 49 | : public LayerAnimationDelegate, |
[email protected] | 7ba5f4b6 | 2012-08-25 01:19:36 | [diff] [blame] | 50 | NON_EXPORTED_BASE(public WebKit::WebContentLayerClient), |
| 51 | NON_EXPORTED_BASE(public WebKit::WebExternalTextureLayerClient) { |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 52 | public: |
[email protected] | 7ab3f27 | 2011-11-16 00:51:56 | [diff] [blame] | 53 | Layer(); |
| 54 | explicit Layer(LayerType type); |
[email protected] | 8f2a15d | 2011-09-29 15:50:59 | [diff] [blame] | 55 | virtual ~Layer(); |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 56 | |
[email protected] | 993d6b32 | 2011-09-27 19:14:38 | [diff] [blame] | 57 | // Retrieves the Layer's compositor. The Layer will walk up its parent chain |
| 58 | // to locate it. Returns NULL if the Layer is not attached to a compositor. |
| 59 | Compositor* GetCompositor(); |
| 60 | |
| 61 | // Called by the compositor when the Layer is set as its root Layer. This can |
| 62 | // only ever be called on the root layer. |
| 63 | void SetCompositor(Compositor* compositor); |
| 64 | |
[email protected] | 00b8698 | 2011-09-01 00:02:09 | [diff] [blame] | 65 | LayerDelegate* delegate() { return delegate_; } |
| 66 | void set_delegate(LayerDelegate* delegate) { delegate_ = delegate; } |
| 67 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 68 | // Adds a new Layer to this Layer. |
| 69 | void Add(Layer* child); |
| 70 | |
| 71 | // Removes a Layer from this Layer. |
| 72 | void Remove(Layer* child); |
| 73 | |
[email protected] | 5e4e61f | 2011-11-22 16:55:24 | [diff] [blame] | 74 | // Stacks |child| above all other children. |
| 75 | void StackAtTop(Layer* child); |
[email protected] | 18dab37 | 2011-10-03 21:21:44 | [diff] [blame] | 76 | |
[email protected] | ebc335f | 2011-11-23 00:43:51 | [diff] [blame] | 77 | // Stacks |child| directly above |other|. Both must be children of this |
| 78 | // layer. Note that if |child| is initially stacked even higher, calling this |
| 79 | // method will result in |child| being lowered in the stacking order. |
[email protected] | 5e4e61f | 2011-11-22 16:55:24 | [diff] [blame] | 80 | void StackAbove(Layer* child, Layer* other); |
[email protected] | 62dd7ea | 2011-11-08 15:51:47 | [diff] [blame] | 81 | |
[email protected] | 44c6f8d | 2011-12-27 23:49:04 | [diff] [blame] | 82 | // Stacks |child| below all other children. |
| 83 | void StackAtBottom(Layer* child); |
| 84 | |
| 85 | // Stacks |child| directly below |other|. Both must be children of this |
| 86 | // layer. |
| 87 | void StackBelow(Layer* child, Layer* other); |
| 88 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 89 | // Returns the child Layers. |
[email protected] | 25ae9a1 | 2011-10-12 14:55:22 | [diff] [blame] | 90 | const std::vector<Layer*>& children() const { return children_; } |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 91 | |
| 92 | // The parent. |
| 93 | const Layer* parent() const { return parent_; } |
| 94 | Layer* parent() { return parent_; } |
| 95 | |
[email protected] | 036e6c97 | 2012-01-03 18:48:05 | [diff] [blame] | 96 | LayerType type() const { return type_; } |
| 97 | |
[email protected] | ad725891 | 2011-08-29 20:33:53 | [diff] [blame] | 98 | // Returns true if this Layer contains |other| somewhere in its children. |
| 99 | bool Contains(const Layer* other) const; |
| 100 | |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 101 | // The layer's animator is responsible for causing automatic animations when |
| 102 | // properties are set. It also manages a queue of pending animations and |
| 103 | // handles blending of animations. The layer takes ownership of the animator. |
| 104 | void SetAnimator(LayerAnimator* animator); |
| 105 | |
| 106 | // Returns the layer's animator. Creates a default animator of one has not |
| 107 | // been set. Will not return NULL. |
| 108 | LayerAnimator* GetAnimator(); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 109 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 110 | // The transform, relative to the parent. |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 111 | void SetTransform(const Transform& transform); |
| 112 | const Transform& transform() const { return transform_; } |
| 113 | |
| 114 | // Return the target transform if animator is running, or the current |
| 115 | // transform otherwise. |
| 116 | Transform GetTargetTransform() const; |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 117 | |
| 118 | // The bounds, relative to the parent. |
[email protected] | c155c25 | 2011-07-29 16:17:55 | [diff] [blame] | 119 | void SetBounds(const gfx::Rect& bounds); |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 120 | const gfx::Rect& bounds() const { return bounds_; } |
| 121 | |
[email protected] | 5ba9d5f | 2011-10-20 01:58:33 | [diff] [blame] | 122 | // Return the target bounds if animator is running, or the current bounds |
| 123 | // otherwise. |
| 124 | gfx::Rect GetTargetBounds() const; |
| 125 | |
[email protected] | 7adee63 | 2012-03-15 19:15:08 | [diff] [blame] | 126 | // Sets/gets whether or not drawing of child layers should be clipped to the |
| 127 | // bounds of this layer. |
| 128 | void SetMasksToBounds(bool masks_to_bounds); |
| 129 | bool GetMasksToBounds() const; |
| 130 | |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 131 | // The opacity of the layer. The opacity is applied to each pixel of the |
| 132 | // texture (resulting alpha = opacity * alpha). |
| 133 | float opacity() const { return opacity_; } |
| 134 | void SetOpacity(float opacity); |
| 135 | |
[email protected] | fb4d9d1 | 2012-08-24 00:44:54 | [diff] [blame] | 136 | // Returns the actual opacity, which the opacity of this layer multipled by |
| 137 | // the combined opacity of the parent. |
| 138 | float GetCombinedOpacity() const; |
| 139 | |
[email protected] | 2a6c567 | 2012-04-23 19:37:09 | [diff] [blame] | 140 | // Blur pixels by this amount in anything below the layer and visible through |
| 141 | // the layer. |
| 142 | int background_blur() const { return background_blur_radius_; } |
| 143 | void SetBackgroundBlur(int blur_radius); |
| 144 | |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 145 | // Saturate all pixels of this layer by this amount. |
[email protected] | 815d0c38 | 2012-07-21 08:13:44 | [diff] [blame] | 146 | // This effect will get "combined" with the inverted, |
| 147 | // brightness and grayscale setting. |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 148 | float layer_saturation() const { return layer_saturation_; } |
| 149 | void SetLayerSaturation(float saturation); |
| 150 | |
| 151 | // Change the brightness of all pixels from this layer by this amount. |
[email protected] | 815d0c38 | 2012-07-21 08:13:44 | [diff] [blame] | 152 | // This effect will get "combined" with the inverted, saturate |
| 153 | // and grayscale setting. |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 154 | float layer_brightness() const { return layer_brightness_; } |
| 155 | void SetLayerBrightness(float brightness); |
| 156 | |
[email protected] | 815d0c38 | 2012-07-21 08:13:44 | [diff] [blame] | 157 | // Return the target brightness if animator is running, or the current |
| 158 | // brightness otherwise. |
| 159 | float GetTargetBrightness() const; |
| 160 | |
| 161 | // Change the grayscale of all pixels from this layer by this amount. |
| 162 | // This effect will get "combined" with the inverted, saturate |
| 163 | // and brightness setting. |
| 164 | float layer_grayscale() const { return layer_grayscale_; } |
| 165 | void SetLayerGrayscale(float grayscale); |
| 166 | |
| 167 | // Return the target grayscale if animator is running, or the current |
| 168 | // grayscale otherwise. |
| 169 | float GetTargetGrayscale() const; |
| 170 | |
[email protected] | f48075d | 2012-05-24 11:06:51 | [diff] [blame] | 171 | // Invert the layer. |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 172 | bool layer_inverted() const { return layer_inverted_; } |
| 173 | void SetLayerInverted(bool inverted); |
[email protected] | f48075d | 2012-05-24 11:06:51 | [diff] [blame] | 174 | |
[email protected] | 3f1f5e6a | 2011-11-11 15:09:02 | [diff] [blame] | 175 | // Return the target opacity if animator is running, or the current opacity |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 176 | // otherwise. |
| 177 | float GetTargetOpacity() const; |
| 178 | |
[email protected] | 498e623c | 2012-07-12 21:12:42 | [diff] [blame] | 179 | // Set a layer mask for a layer. |
| 180 | // Note the provided layer mask can neither have a layer mask itself nor can |
| 181 | // it have any children. The ownership of |layer_mask| will not be |
| 182 | // transferred with this call. |
| 183 | // Furthermore: A mask layer can only be set to one layer. |
| 184 | void SetMaskLayer(Layer* layer_mask); |
| 185 | Layer* layer_mask_layer() { return layer_mask_; } |
| 186 | |
[email protected] | e4e8afef | 2011-10-05 13:58:33 | [diff] [blame] | 187 | // Sets the visibility of the Layer. A Layer may be visible but not |
| 188 | // drawn. This happens if any ancestor of a Layer is not visible. |
[email protected] | 993d6b32 | 2011-09-27 19:14:38 | [diff] [blame] | 189 | void SetVisible(bool visible); |
[email protected] | f941f47a | 2011-10-15 18:44:51 | [diff] [blame] | 190 | bool visible() const { return visible_; } |
[email protected] | 3aa4394 | 2011-09-13 20:59:53 | [diff] [blame] | 191 | |
[email protected] | a67935f | 2012-02-10 14:26:24 | [diff] [blame] | 192 | // Returns the target visibility if the animator is running. Otherwise, it |
| 193 | // returns the current visibility. |
| 194 | bool GetTargetVisibility() const; |
| 195 | |
[email protected] | e4e8afef | 2011-10-05 13:58:33 | [diff] [blame] | 196 | // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors |
| 197 | // are visible. |
| 198 | bool IsDrawn() const; |
| 199 | |
[email protected] | c1f6730 | 2011-09-27 14:18:09 | [diff] [blame] | 200 | // Returns true if this layer can have a texture (has_texture_ is true) |
| 201 | // and is not completely obscured by a child. |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 202 | bool ShouldDraw() const; |
[email protected] | c1f6730 | 2011-09-27 14:18:09 | [diff] [blame] | 203 | |
[email protected] | ad725891 | 2011-08-29 20:33:53 | [diff] [blame] | 204 | // Converts a point from the coordinates of |source| to the coordinates of |
| 205 | // |target|. Necessarily, |source| and |target| must inhabit the same Layer |
| 206 | // tree. |
| 207 | static void ConvertPointToLayer(const Layer* source, |
| 208 | const Layer* target, |
| 209 | gfx::Point* point); |
| 210 | |
[email protected] | c155c25 | 2011-07-29 16:17:55 | [diff] [blame] | 211 | // See description in View for details |
| 212 | void SetFillsBoundsOpaquely(bool fills_bounds_opaquely); |
| 213 | bool fills_bounds_opaquely() const { return fills_bounds_opaquely_; } |
| 214 | |
[email protected] | 33699e62 | 2011-11-17 18:29:30 | [diff] [blame] | 215 | const std::string& name() const { return name_; } |
| 216 | void set_name(const std::string& name) { name_ = name; } |
| 217 | |
[email protected] | 536987c8 | 2011-06-28 03:46:08 | [diff] [blame] | 218 | const ui::Texture* texture() const { return texture_.get(); } |
[email protected] | 1cbbee3c | 2011-06-24 12:32:19 | [diff] [blame] | 219 | |
[email protected] | 6aa614a | 2012-01-19 22:13:38 | [diff] [blame] | 220 | // Assigns a new external texture. |texture| can be NULL to disable external |
| 221 | // updates. |
[email protected] | 28cd2bb | 2011-09-19 21:04:19 | [diff] [blame] | 222 | void SetExternalTexture(ui::Texture* texture); |
[email protected] | b6ea1c1 | 2012-09-13 17:28:50 | [diff] [blame] | 223 | ui::Texture* external_texture() { return texture_.get(); } |
[email protected] | 28cd2bb | 2011-09-19 21:04:19 | [diff] [blame] | 224 | |
[email protected] | da7584c | 2012-01-28 03:19:12 | [diff] [blame] | 225 | // Sets the layer's fill color. May only be called for LAYER_SOLID_COLOR. |
| 226 | void SetColor(SkColor color); |
| 227 | |
[email protected] | 870119a | 2011-09-30 18:13:22 | [diff] [blame] | 228 | // Adds |invalid_rect| to the Layer's pending invalid rect and calls |
[email protected] | f78649ea | 2012-02-23 18:39:04 | [diff] [blame] | 229 | // ScheduleDraw(). Returns false if the paint request is ignored. |
| 230 | bool SchedulePaint(const gfx::Rect& invalid_rect); |
[email protected] | 00b8698 | 2011-09-01 00:02:09 | [diff] [blame] | 231 | |
[email protected] | 870119a | 2011-09-30 18:13:22 | [diff] [blame] | 232 | // Schedules a redraw of the layer tree at the compositor. |
[email protected] | 35470cc | 2012-02-23 23:04:31 | [diff] [blame] | 233 | // Note that this _does not_ invalidate any region of this layer; use |
| 234 | // SchedulePaint() for that. |
[email protected] | 870119a | 2011-09-30 18:13:22 | [diff] [blame] | 235 | void ScheduleDraw(); |
| 236 | |
[email protected] | cedc395 | 2012-03-06 06:15:55 | [diff] [blame] | 237 | // Sends damaged rectangles recorded in |damaged_region_| to |
| 238 | // |compostior_| to repaint the content. |
| 239 | void SendDamagedRects(); |
[email protected] | f78649ea | 2012-02-23 18:39:04 | [diff] [blame] | 240 | |
| 241 | // Suppresses painting the content by disgarding damaged region and ignoring |
| 242 | // new paint requests. |
| 243 | void SuppressPaint(); |
| 244 | |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 245 | // Notifies the layer that the device scale factor has changed. |
| 246 | void OnDeviceScaleFactorChanged(float device_scale_factor); |
| 247 | |
[email protected] | 2486dce | 2012-05-23 17:18:19 | [diff] [blame] | 248 | // Sets whether the layer should scale its content. If true, the canvas will |
| 249 | // be scaled in software rendering mode before it is passed to |
| 250 | // |LayerDelegate::OnPaint| and the texture will be scaled in accelerated |
| 251 | // mode. Set to false if the delegate handles scaling and the texture is |
| 252 | // the correct pixel size. |
| 253 | void set_scale_content(bool scale_content) { scale_content_ = scale_content; } |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 254 | |
[email protected] | 84ff1e9 | 2012-06-13 02:58:21 | [diff] [blame] | 255 | // Returns true if the layer scales its content. |
| 256 | bool scale_content() const { return scale_content_; } |
| 257 | |
[email protected] | a97527b | 2011-09-14 15:44:38 | [diff] [blame] | 258 | // Sometimes the Layer is being updated by something other than SetCanvas |
[email protected] | 396ecd5 | 2011-11-22 00:08:52 | [diff] [blame] | 259 | // (e.g. the GPU process on UI_COMPOSITOR_IMAGE_TRANSPORT). |
[email protected] | a97527b | 2011-09-14 15:44:38 | [diff] [blame] | 260 | bool layer_updated_externally() const { return layer_updated_externally_; } |
| 261 | |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 262 | // WebContentLayerClient |
[email protected] | fde5d7d2 | 2012-06-16 02:25:19 | [diff] [blame] | 263 | virtual void paintContents(WebKit::WebCanvas*, |
[email protected] | 4e41fda | 2012-06-19 21:31:35 | [diff] [blame] | 264 | const WebKit::WebRect& clip, |
[email protected] | 768f6e13 | 2012-06-29 13:16:23 | [diff] [blame] | 265 | WebKit::WebFloatRect& opaque); |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 266 | |
[email protected] | 66efabe | 2012-08-18 03:06:06 | [diff] [blame] | 267 | WebKit::WebLayer* web_layer() { return web_layer_; } |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 268 | |
[email protected] | 7ba5f4b6 | 2012-08-25 01:19:36 | [diff] [blame] | 269 | // WebExternalTextureLayerClient |
| 270 | virtual unsigned prepareTexture( |
| 271 | WebKit::WebTextureUpdater& /* updater */) OVERRIDE; |
| 272 | virtual WebKit::WebGraphicsContext3D* context() OVERRIDE; |
| 273 | |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 274 | float device_scale_factor() const { return device_scale_factor_; } |
| 275 | |
[email protected] | 09c01c1 | 2012-05-26 00:07:19 | [diff] [blame] | 276 | // Forces a render surface to be used on this layer. This has no positive |
| 277 | // impact, and is only used for benchmarking/testing purpose. |
| 278 | void SetForceRenderSurface(bool force); |
| 279 | bool force_render_surface() const { return force_render_surface_; } |
| 280 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 281 | private: |
[email protected] | 44c6f8d | 2011-12-27 23:49:04 | [diff] [blame] | 282 | // Stacks |child| above or below |other|. Helper method for StackAbove() and |
| 283 | // StackBelow(). |
| 284 | void StackRelativeTo(Layer* child, Layer* other, bool above); |
| 285 | |
[email protected] | ad725891 | 2011-08-29 20:33:53 | [diff] [blame] | 286 | bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; |
| 287 | bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; |
| 288 | |
| 289 | bool GetTransformRelativeTo(const Layer* ancestor, |
| 290 | Transform* transform) const; |
| 291 | |
[email protected] | b4bb9ca | 2011-09-23 20:53:14 | [diff] [blame] | 292 | // The only externally updated layers are ones that get their pixels from |
| 293 | // WebKit and WebKit does not produce valid alpha values. All other layers |
| 294 | // should have valid alpha. |
| 295 | bool has_valid_alpha_channel() const { return !layer_updated_externally_; } |
| 296 | |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 297 | // Following are invoked from the animation or if no animation exists to |
| 298 | // update the values immediately. |
| 299 | void SetBoundsImmediately(const gfx::Rect& bounds); |
| 300 | void SetTransformImmediately(const ui::Transform& transform); |
| 301 | void SetOpacityImmediately(float opacity); |
[email protected] | a67935f | 2012-02-10 14:26:24 | [diff] [blame] | 302 | void SetVisibilityImmediately(bool visibility); |
[email protected] | 815d0c38 | 2012-07-21 08:13:44 | [diff] [blame] | 303 | void SetBrightnessImmediately(float brightness); |
| 304 | void SetGrayscaleImmediately(float grayscale); |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 305 | |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 306 | // Implementation of LayerAnimatorDelegate |
| 307 | virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE; |
| 308 | virtual void SetTransformFromAnimation(const Transform& transform) OVERRIDE; |
| 309 | virtual void SetOpacityFromAnimation(float opacity) OVERRIDE; |
[email protected] | a67935f | 2012-02-10 14:26:24 | [diff] [blame] | 310 | virtual void SetVisibilityFromAnimation(bool visibility) OVERRIDE; |
[email protected] | 815d0c38 | 2012-07-21 08:13:44 | [diff] [blame] | 311 | virtual void SetBrightnessFromAnimation(float brightness) OVERRIDE; |
| 312 | virtual void SetGrayscaleFromAnimation(float grayscale) OVERRIDE; |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 313 | virtual void ScheduleDrawForAnimation() OVERRIDE; |
| 314 | virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE; |
| 315 | virtual const Transform& GetTransformForAnimation() const OVERRIDE; |
| 316 | virtual float GetOpacityForAnimation() const OVERRIDE; |
[email protected] | a67935f | 2012-02-10 14:26:24 | [diff] [blame] | 317 | virtual bool GetVisibilityForAnimation() const OVERRIDE; |
[email protected] | 815d0c38 | 2012-07-21 08:13:44 | [diff] [blame] | 318 | virtual float GetBrightnessForAnimation() const OVERRIDE; |
| 319 | virtual float GetGrayscaleForAnimation() const OVERRIDE; |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 320 | |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 321 | void CreateWebLayer(); |
| 322 | void RecomputeTransform(); |
[email protected] | b9616d59 | 2011-11-14 20:04:42 | [diff] [blame] | 323 | void RecomputeDrawsContentAndUVRect(); |
[email protected] | a77ac880 | 2011-11-26 01:59:56 | [diff] [blame] | 324 | void RecomputeDebugBorderColor(); |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 325 | |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 326 | // Set all filters which got applied to the layer. |
| 327 | void SetLayerFilters(); |
| 328 | |
[email protected] | 993d6b32 | 2011-09-27 19:14:38 | [diff] [blame] | 329 | const LayerType type_; |
| 330 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 331 | Compositor* compositor_; |
| 332 | |
[email protected] | 51f1b48 | 2011-06-23 16:52:12 | [diff] [blame] | 333 | scoped_refptr<ui::Texture> texture_; |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 334 | |
| 335 | Layer* parent_; |
| 336 | |
[email protected] | ebc335f | 2011-11-23 00:43:51 | [diff] [blame] | 337 | // This layer's children, in bottom-to-top stacking order. |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 338 | std::vector<Layer*> children_; |
| 339 | |
| 340 | ui::Transform transform_; |
| 341 | |
| 342 | gfx::Rect bounds_; |
| 343 | |
[email protected] | e4e8afef | 2011-10-05 13:58:33 | [diff] [blame] | 344 | // Visibility of this layer. See SetVisible/IsDrawn for more details. |
[email protected] | 3aa4394 | 2011-09-13 20:59:53 | [diff] [blame] | 345 | bool visible_; |
| 346 | |
[email protected] | 09c01c1 | 2012-05-26 00:07:19 | [diff] [blame] | 347 | bool force_render_surface_; |
| 348 | |
[email protected] | c155c25 | 2011-07-29 16:17:55 | [diff] [blame] | 349 | bool fills_bounds_opaquely_; |
| 350 | |
[email protected] | a97527b | 2011-09-14 15:44:38 | [diff] [blame] | 351 | // If true the layer is always up to date. |
| 352 | bool layer_updated_externally_; |
| 353 | |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 354 | // Union of damaged rects, in pixel coordinates, to be used when |
| 355 | // compositor is ready to paint the content. |
[email protected] | cedc395 | 2012-03-06 06:15:55 | [diff] [blame] | 356 | SkRegion damaged_region_; |
[email protected] | f78649ea | 2012-02-23 18:39:04 | [diff] [blame] | 357 | |
[email protected] | b4bb9ca | 2011-09-23 20:53:14 | [diff] [blame] | 358 | float opacity_; |
[email protected] | 2a6c567 | 2012-04-23 19:37:09 | [diff] [blame] | 359 | int background_blur_radius_; |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 360 | |
| 361 | // Several variables which will change the visible representation of |
| 362 | // the layer. |
| 363 | float layer_saturation_; |
| 364 | float layer_brightness_; |
[email protected] | 815d0c38 | 2012-07-21 08:13:44 | [diff] [blame] | 365 | float layer_grayscale_; |
[email protected] | e5da662 | 2012-05-30 19:58:16 | [diff] [blame] | 366 | bool layer_inverted_; |
[email protected] | b4bb9ca | 2011-09-23 20:53:14 | [diff] [blame] | 367 | |
[email protected] | 498e623c | 2012-07-12 21:12:42 | [diff] [blame] | 368 | // The associated mask layer with this layer. |
| 369 | Layer* layer_mask_; |
| 370 | // The back link from the mask layer to it's associated masked layer. |
| 371 | // We keep this reference for the case that if the mask layer gets deleted |
| 372 | // while attached to the main layer before the main layer is deleted. |
| 373 | Layer* layer_mask_back_link_; |
| 374 | |
[email protected] | 33699e62 | 2011-11-17 18:29:30 | [diff] [blame] | 375 | std::string name_; |
| 376 | |
[email protected] | 00b8698 | 2011-09-01 00:02:09 | [diff] [blame] | 377 | LayerDelegate* delegate_; |
| 378 | |
[email protected] | 5d86a11 | 2012-09-23 00:21:58 | [diff] [blame^] | 379 | scoped_refptr<LayerAnimator> animator_; |
[email protected] | 7fca53d4 | 2011-09-29 15:38:12 | [diff] [blame] | 380 | |
[email protected] | 66efabe | 2012-08-18 03:06:06 | [diff] [blame] | 381 | // Ownership of the layer is held through one of the strongly typed layer |
| 382 | // pointers, depending on which sort of layer this is. |
| 383 | scoped_ptr<WebKit::WebContentLayer> content_layer_; |
| 384 | scoped_ptr<WebKit::WebExternalTextureLayer> texture_layer_; |
| 385 | scoped_ptr<WebKit::WebSolidColorLayer> solid_color_layer_; |
| 386 | WebKit::WebLayer* web_layer_; |
[email protected] | 4b58d55 | 2011-10-26 00:54:46 | [diff] [blame] | 387 | bool web_layer_is_accelerated_; |
[email protected] | a77ac880 | 2011-11-26 01:59:56 | [diff] [blame] | 388 | bool show_debug_borders_; |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 389 | |
[email protected] | 2486dce | 2012-05-23 17:18:19 | [diff] [blame] | 390 | // If true, the layer scales the canvas and the texture with the device scale |
| 391 | // factor as appropriate. When true, the texture size is in DIP. |
| 392 | bool scale_content_; |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 393 | |
| 394 | // A cached copy of |Compositor::device_scale_factor()|. |
| 395 | float device_scale_factor_; |
| 396 | |
[email protected] | adc93fa7 | 2011-06-21 19:47:39 | [diff] [blame] | 397 | DISALLOW_COPY_AND_ASSIGN(Layer); |
| 398 | }; |
| 399 | |
| 400 | } // namespace ui |
| 401 | |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 402 | #endif // UI_COMPOSITOR_LAYER_H_ |