layer.h revision 868fa2fe829687343ffae624259930155e16dbd8
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_COMPOSITOR_LAYER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_COMPOSITOR_LAYER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/ref_counted.h" 137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/memory/scoped_ptr.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/message_loop.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "cc/animation/animation_events.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "cc/animation/layer_animation_event_observer.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/base/scoped_ptr_vector.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "cc/layers/content_layer_client.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "cc/layers/texture_layer_client.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/resources/texture_mailbox.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "third_party/skia/include/core/SkRegion.h" 231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/compositor/compositor.h" 24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/compositor/layer_animation_delegate.h" 256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/compositor/layer_delegate.h" 266e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/compositor/layer_type.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h" 287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "ui/gfx/transform.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class SkCanvas; 316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace cc { 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ContentLayer; 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DelegatedFrameData; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DelegatedRendererLayer; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Layer; 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ResourceUpdateQueue; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SolidColorLayer; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TextureLayer; 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct TransferableResource; 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)typedef std::vector<TransferableResource> TransferableResourceArray; 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace ui { 45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Compositor; 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class LayerAnimator; 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Texture; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Layer manages a texture, transform and a set of child Layers. Any View that 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// has enabled layers ends up creating a Layer to manage the texture. 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A Layer can also be created without a texture, in which case it renders 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// nothing and is simply used as a node in a hierarchy of layers. 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Coordinate system used in layers is DIP (Density Independent Pixel) 556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// coordinates unless explicitly mentioned as pixel coordinates. 566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// 576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// NOTE: unlike Views, each Layer does *not* own its children views. If you 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// delete a Layer and it has children, the parent of each child layer is set to 596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// NULL, but the children are not deleted. 606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class COMPOSITOR_EXPORT Layer 616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) : public LayerAnimationDelegate, 626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) NON_EXPORTED_BASE(public cc::ContentLayerClient), 636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) NON_EXPORTED_BASE(public cc::TextureLayerClient), 646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) NON_EXPORTED_BASE(public cc::LayerAnimationEventObserver) { 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Layer(); 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit Layer(LayerType type); 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Layer(); 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Retrieves the Layer's compositor. The Layer will walk up its parent chain 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to locate it. Returns NULL if the Layer is not attached to a compositor. 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Compositor* GetCompositor(); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called by the compositor when the Layer is set as its root Layer. This can 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // only ever be called on the root layer. 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetCompositor(Compositor* compositor); 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LayerDelegate* delegate() { return delegate_; } 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_delegate(LayerDelegate* delegate) { delegate_ = delegate; } 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds a new Layer to this Layer. 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Add(Layer* child); 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Removes a Layer from this Layer. 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Remove(Layer* child); 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Stacks |child| above all other children. 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StackAtTop(Layer* child); 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Stacks |child| directly above |other|. Both must be children of this 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // layer. Note that if |child| is initially stacked even higher, calling this 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // method will result in |child| being lowered in the stacking order. 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StackAbove(Layer* child, Layer* other); 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Stacks |child| below all other children. 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void StackAtBottom(Layer* child); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 986e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Stacks |child| directly below |other|. Both must be children of this 996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // layer. 1006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) void StackBelow(Layer* child, Layer* other); 1016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Returns the child Layers. 1031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const std::vector<Layer*>& children() const { return children_; } 1041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // The parent. 1061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const Layer* parent() const { return parent_; } 1071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Layer* parent() { return parent_; } 1081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci LayerType type() const { return type_; } 1101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Returns true if this Layer contains |other| somewhere in its children. 1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool Contains(const Layer* other) const; 1131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // The layer's animator is responsible for causing automatic animations when 1151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // properties are set. It also manages a queue of pending animations and 1161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // handles blending of animations. The layer takes ownership of the animator. 1171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci void SetAnimator(LayerAnimator* animator); 1181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the layer's animator. Creates a default animator of one has not 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // been set. Will not return NULL. 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LayerAnimator* GetAnimator(); 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The transform, relative to the parent. 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetTransform(const gfx::Transform& transform); 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Transform transform() const; 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Return the target transform if animator is running, or the current 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // transform otherwise. 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Transform GetTargetTransform() const; 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The bounds, relative to the parent. 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetBounds(const gfx::Rect& bounds); 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& bounds() const { return bounds_; } 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return the target bounds if animator is running, or the current bounds 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // otherwise. 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect GetTargetBounds() const; 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets/gets whether or not drawing of child layers should be clipped to the 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // bounds of this layer. 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetMasksToBounds(bool masks_to_bounds); 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetMasksToBounds() const; 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The opacity of the layer. The opacity is applied to each pixel of the 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // texture (resulting alpha = opacity * alpha). 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float opacity() const; 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetOpacity(float opacity); 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the actual opacity, which the opacity of this layer multipled by 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the combined opacity of the parent. 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float GetCombinedOpacity() const; 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Blur pixels by this amount in anything below the layer and visible through 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the layer. 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int background_blur() const { return background_blur_radius_; } 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetBackgroundBlur(int blur_radius); 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Saturate all pixels of this layer by this amount. 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This effect will get "combined" with the inverted, 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // brightness and grayscale setting. 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float layer_saturation() const { return layer_saturation_; } 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetLayerSaturation(float saturation); 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Change the brightness of all pixels from this layer by this amount. 1656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // This effect will get "combined" with the inverted, saturate 1666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // and grayscale setting. 1676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) float layer_brightness() const { return layer_brightness_; } 1686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) void SetLayerBrightness(float brightness); 1696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Return the target brightness if animator is running, or the current 1716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // brightness otherwise. 1726e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) float GetTargetBrightness() const; 1736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1746e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Change the grayscale of all pixels from this layer by this amount. 1756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // This effect will get "combined" with the inverted, saturate 1766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // and brightness setting. 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float layer_grayscale() const { return layer_grayscale_; } 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetLayerGrayscale(float grayscale); 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return the target grayscale if animator is running, or the current 181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // grayscale otherwise. 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float GetTargetGrayscale() const; 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Zoom the background by a factor of |zoom|. The effect is blended along the 1851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // edge across |inset| pixels. 1861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci void SetBackgroundZoom(float zoom, int inset); 1871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invert the layer. 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool layer_inverted() const { return layer_inverted_; } 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetLayerInverted(bool inverted); 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Return the target opacity if animator is running, or the current opacity 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // otherwise. 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float GetTargetOpacity() const; 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set a layer mask for a layer. 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note the provided layer mask can neither have a layer mask itself nor can 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it have any children. The ownership of |layer_mask| will not be 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // transferred with this call. 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Furthermore: A mask layer can only be set to one layer. 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetMaskLayer(Layer* layer_mask); 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Layer* layer_mask_layer() { return layer_mask_; } 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the visibility of the Layer. A Layer may be visible but not 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // drawn. This happens if any ancestor of a Layer is not visible. 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetVisible(bool visible); 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool visible() const { return visible_; } 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the target visibility if the animator is running. Otherwise, it 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // returns the current visibility. 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetTargetVisibility() const; 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // are visible. 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool IsDrawn() const; 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if this layer can have a texture (has_texture_ is true) 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and is not completely obscured by a child. 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool ShouldDraw() const; 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Converts a point from the coordinates of |source| to the coordinates of 2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |target|. Necessarily, |source| and |target| must inhabit the same Layer 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // tree. 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void ConvertPointToLayer(const Layer* source, 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Layer* target, 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point* point); 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Converts a transform to be relative to the given |ancestor|. Returns 2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // whether success (that is, whether the given ancestor was really an 2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ancestor of this layer). 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetTargetTransformRelativeTo(const Layer* ancestor, 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Transform* transform) const; 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Converts a ui::Layer's transform to the transform on the corresponding 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // cc::Layer. 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static gfx::Transform ConvertTransformToCCTransform( 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Transform& transform, 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float device_scale_factor); 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // See description in View for details 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetFillsBoundsOpaquely(bool fills_bounds_opaquely); 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool fills_bounds_opaquely() const { return fills_bounds_opaquely_; } 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& name() const { return name_; } 2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void set_name(const std::string& name) { name_ = name; } 2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const ui::Texture* texture() const { return texture_.get(); } 2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Assigns a new external texture. |texture| can be NULL to disable external 2505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // updates. 2516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) void SetExternalTexture(ui::Texture* texture); 2526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ui::Texture* external_texture() { return texture_.get(); } 2536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 2546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Set new TextureMailbox for this layer. Note that |mailbox| may hold a 2556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // shared memory resource or an actual mailbox for a texture. 2566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) void SetTextureMailbox(const cc::TextureMailbox& mailbox, float scale_factor); 2576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) cc::TextureMailbox GetTextureMailbox(float* scale_factor); 2586e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 2596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Sets a delegated frame, coming from a child compositor. 2606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) void SetDelegatedFrame(scoped_ptr<cc::DelegatedFrameData> frame, 2616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) gfx::Size frame_size_in_dip); 2626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 2636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Gets unused resources to recycle to the child compositor. 2646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) void TakeUnusedResourcesForChildCompositor( 2651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci cc::TransferableResourceArray* array); 2661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 2671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Sets the layer's fill color. May only be called for LAYER_SOLID_COLOR. 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetColor(SkColor color); 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds |invalid_rect| to the Layer's pending invalid rect and calls 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ScheduleDraw(). Returns false if the paint request is ignored. 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool SchedulePaint(const gfx::Rect& invalid_rect); 273f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Schedules a redraw of the layer tree at the compositor. 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note that this _does not_ invalidate any region of this layer; use 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SchedulePaint() for that. 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleDraw(); 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sends damaged rectangles recorded in |damaged_region_| to 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |compostior_| to repaint the content. 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SendDamagedRects(); 2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Suppresses painting the content by disgarding damaged region and ignoring 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // new paint requests. 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SuppressPaint(); 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notifies the layer that the device scale factor has changed. 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnDeviceScaleFactorChanged(float device_scale_factor); 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets whether the layer should scale its content. If true, the canvas will 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be scaled in software rendering mode before it is passed to 2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |LayerDelegate::OnPaint|. 2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set to false if the delegate handles scaling. 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE: if this is called during |LayerDelegate::OnPaint|, the new value will 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not apply to the canvas passed to the pending draw. 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_scale_content(bool scale_content) { scale_content_ = scale_content; } 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns true if the layer scales its content. 2995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool scale_content() const { return scale_content_; } 3005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Sometimes the Layer is being updated by something other than SetCanvas 3026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // (e.g. the GPU process on UI_COMPOSITOR_IMAGE_TRANSPORT). 3036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool layer_updated_externally() const { return layer_updated_externally_; } 3046e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 3056e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // ContentLayerClient 3066e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual void PaintContents( 3076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) SkCanvas* canvas, gfx::Rect clip, gfx::RectF* opaque) OVERRIDE; 3086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} 3096e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 3106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) cc::Layer* cc_layer() { return cc_layer_; } 3116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 3121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // TextureLayerClient 3131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual unsigned PrepareTexture(cc::ResourceUpdateQueue* queue) OVERRIDE; 3141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE; 3151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual bool PrepareTextureMailbox(cc::TextureMailbox* mailbox) OVERRIDE; 3161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 3171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci float device_scale_factor() const { return device_scale_factor_; } 3181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 3191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Forces a render surface to be used on this layer. This has no positive 3201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // impact, and is only used for benchmarking/testing purpose. 3211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci void SetForceRenderSurface(bool force); 3221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool force_render_surface() const { return force_render_surface_; } 3231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 3241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // LayerAnimationEventObserver 3251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void OnAnimationStarted(const cc::AnimationEvent& event) OVERRIDE; 3261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 3271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Whether this layer has animations waiting to get sent to its cc::Layer. 3281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool HasPendingThreadedAnimations() { 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return pending_threaded_animations_.size() != 0; 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Triggers a call to SwitchToLayer. 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SwitchCCLayerForTest(); 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335 private: 336 // Stacks |child| above or below |other|. Helper method for StackAbove() and 337 // StackBelow(). 338 void StackRelativeTo(Layer* child, Layer* other, bool above); 339 340 bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; 341 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; 342 343 // Following are invoked from the animation or if no animation exists to 344 // update the values immediately. 345 void SetBoundsImmediately(const gfx::Rect& bounds); 346 void SetTransformImmediately(const gfx::Transform& transform); 347 void SetOpacityImmediately(float opacity); 348 void SetVisibilityImmediately(bool visibility); 349 void SetBrightnessImmediately(float brightness); 350 void SetGrayscaleImmediately(float grayscale); 351 void SetColorImmediately(SkColor color); 352 353 // Implementation of LayerAnimatorDelegate 354 virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE; 355 virtual void SetTransformFromAnimation( 356 const gfx::Transform& transform) OVERRIDE; 357 virtual void SetOpacityFromAnimation(float opacity) OVERRIDE; 358 virtual void SetVisibilityFromAnimation(bool visibility) OVERRIDE; 359 virtual void SetBrightnessFromAnimation(float brightness) OVERRIDE; 360 virtual void SetGrayscaleFromAnimation(float grayscale) OVERRIDE; 361 virtual void SetColorFromAnimation(SkColor color) OVERRIDE; 362 virtual void ScheduleDrawForAnimation() OVERRIDE; 363 virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE; 364 virtual gfx::Transform GetTransformForAnimation() const OVERRIDE; 365 virtual float GetOpacityForAnimation() const OVERRIDE; 366 virtual bool GetVisibilityForAnimation() const OVERRIDE; 367 virtual float GetBrightnessForAnimation() const OVERRIDE; 368 virtual float GetGrayscaleForAnimation() const OVERRIDE; 369 virtual SkColor GetColorForAnimation() const OVERRIDE; 370 virtual float GetDeviceScaleFactor() const OVERRIDE; 371 virtual void AddThreadedAnimation( 372 scoped_ptr<cc::Animation> animation) OVERRIDE; 373 virtual void RemoveThreadedAnimation(int animation_id) OVERRIDE; 374 375 void CreateWebLayer(); 376 void RecomputeCCTransformFromTransform(const gfx::Transform& transform); 377 void RecomputeDrawsContentAndUVRect(); 378 void RecomputePosition(); 379 380 // Set all filters which got applied to the layer. 381 void SetLayerFilters(); 382 383 // Set all filters which got applied to the layer background. 384 void SetLayerBackgroundFilters(); 385 386 void UpdateIsDrawn(); 387 388 void SwitchToLayer(scoped_refptr<cc::Layer> new_layer); 389 390 // We cannot send animations to our cc_layer_ until we have been added to a 391 // layer tree. Instead, we hold on to these animations in 392 // pending_threaded_animations_, and expect SendPendingThreadedAnimations to 393 // be called once we have been added to a tree. 394 void SendPendingThreadedAnimations(); 395 396 const LayerType type_; 397 398 Compositor* compositor_; 399 400 scoped_refptr<ui::Texture> texture_; 401 402 Layer* parent_; 403 404 // This layer's children, in bottom-to-top stacking order. 405 std::vector<Layer*> children_; 406 407 gfx::Rect bounds_; 408 409 // Visibility of this layer. See SetVisible/IsDrawn for more details. 410 bool visible_; 411 412 // Computed based on the visibility of this layer and its ancestors. 413 bool is_drawn_; 414 415 bool force_render_surface_; 416 417 bool fills_bounds_opaquely_; 418 419 // If true the layer is always up to date. 420 bool layer_updated_externally_; 421 422 // Union of damaged rects, in pixel coordinates, to be used when 423 // compositor is ready to paint the content. 424 SkRegion damaged_region_; 425 426 int background_blur_radius_; 427 428 // Several variables which will change the visible representation of 429 // the layer. 430 float layer_saturation_; 431 float layer_brightness_; 432 float layer_grayscale_; 433 bool layer_inverted_; 434 435 // The associated mask layer with this layer. 436 Layer* layer_mask_; 437 // The back link from the mask layer to it's associated masked layer. 438 // We keep this reference for the case that if the mask layer gets deleted 439 // while attached to the main layer before the main layer is deleted. 440 Layer* layer_mask_back_link_; 441 442 // The zoom factor to scale the layer by. Zooming is disabled when this is 443 // set to 1. 444 float zoom_; 445 446 // Width of the border in pixels, where the scaling is blended. 447 int zoom_inset_; 448 449 std::string name_; 450 451 LayerDelegate* delegate_; 452 453 scoped_refptr<LayerAnimator> animator_; 454 455 // Animations that are passed to AddThreadedAnimation before this layer is 456 // added to a tree. 457 cc::ScopedPtrVector<cc::Animation> pending_threaded_animations_; 458 459 // Ownership of the layer is held through one of the strongly typed layer 460 // pointers, depending on which sort of layer this is. 461 scoped_refptr<cc::ContentLayer> content_layer_; 462 scoped_refptr<cc::TextureLayer> texture_layer_; 463 scoped_refptr<cc::SolidColorLayer> solid_color_layer_; 464 scoped_refptr<cc::DelegatedRendererLayer> delegated_renderer_layer_; 465 cc::Layer* cc_layer_; 466 467 // If true, the layer scales the canvas and the texture with the device scale 468 // factor as appropriate. When true, the texture size is in DIP. 469 bool scale_content_; 470 471 // A cached copy of |Compositor::device_scale_factor()|. 472 float device_scale_factor_; 473 474 // A cached copy of the TextureMailbox given texture_layer_. 475 cc::TextureMailbox mailbox_; 476 477 // Device scale factor in which mailbox_ was rendered in. 478 float mailbox_scale_factor_; 479 480 // The size of the delegated frame in DIP, set when SetDelegatedFrame was 481 // called. 482 gfx::Size delegated_frame_size_in_dip_; 483 484 DISALLOW_COPY_AND_ASSIGN(Layer); 485}; 486 487} // namespace ui 488 489#endif // UI_COMPOSITOR_LAYER_H_ 490