layer.h revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
1f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (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)
5f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#ifndef UI_COMPOSITOR_LAYER_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_COMPOSITOR_LAYER_H_
77dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <string>
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/compiler_specific.h"
12eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/memory/ref_counted.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
14f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "base/message_loop/message_loop.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "cc/animation/animation_events.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "cc/animation/layer_animation_event_observer.h"
177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "cc/base/scoped_ptr_vector.h"
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "cc/layers/content_layer_client.h"
1958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "cc/layers/texture_layer_client.h"
2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "cc/resources/texture_mailbox.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h"
22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "third_party/skia/include/core/SkRegion.h"
237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/compositor/compositor.h"
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/compositor/layer_animation_delegate.h"
25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/compositor/layer_delegate.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_type.h"
27f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "ui/gfx/rect.h"
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/transform.h"
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class SkCanvas;
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace cc {
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class ContentLayer;
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class CopyOutputRequest;
3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class DelegatedFrameData;
3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class DelegatedRendererLayer;
3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class Layer;
387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class ResourceUpdateQueue;
39f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class SolidColorLayer;
407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class TextureLayer;
417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)struct TransferableResource;
427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)typedef std::vector<TransferableResource> TransferableResourceArray;
437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
4458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)namespace ui {
4658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
47f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class Compositor;
4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class LayerAnimator;
4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class Texture;
5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Layer manages a texture, transform and a set of child Layers. Any View that
52f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// has enabled layers ends up creating a Layer to manage the texture.
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// A Layer can also be created without a texture, in which case it renders
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// nothing and is simply used as a node in a hierarchy of layers.
55f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// Coordinate system used in layers is DIP (Density Independent Pixel)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// coordinates unless explicitly mentioned as pixel coordinates.
57f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)//
5858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// NOTE: unlike Views, each Layer does *not* own its children views. If you
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// delete a Layer and it has children, the parent of each child layer is set to
6058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// NULL, but the children are not deleted.
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class COMPOSITOR_EXPORT Layer
62f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    : public LayerAnimationDelegate,
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      NON_EXPORTED_BASE(public cc::ContentLayerClient),
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      NON_EXPORTED_BASE(public cc::TextureLayerClient),
6558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      NON_EXPORTED_BASE(public cc::LayerAnimationEventObserver) {
6658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) public:
6758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  Layer();
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit Layer(LayerType type);
6958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual ~Layer();
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Retrieves the Layer's compositor. The Layer will walk up its parent chain
72f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // to locate it. Returns NULL if the Layer is not attached to a compositor.
7358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  Compositor* GetCompositor();
741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
7558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Called by the compositor when the Layer is set as its root Layer. This can
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // only ever be called on the root layer.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetCompositor(Compositor* compositor);
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
79f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  LayerDelegate* delegate() { return delegate_; }
80f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void set_delegate(LayerDelegate* delegate) { delegate_ = delegate; }
8158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
8258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Adds a new Layer to this Layer.
8358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void Add(Layer* child);
8458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
8558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Removes a Layer from this Layer.
8658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void Remove(Layer* child);
8758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
8858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Stacks |child| above all other children.
89f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void StackAtTop(Layer* child);
90f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
9158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Stacks |child| directly above |other|.  Both must be children of this
9258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // layer.  Note that if |child| is initially stacked even higher, calling this
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // method will result in |child| being lowered in the stacking order.
94f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void StackAbove(Layer* child, Layer* other);
9558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
9658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Stacks |child| below all other children.
9758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void StackAtBottom(Layer* child);
98f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Stacks |child| directly below |other|.  Both must be children of this
1007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // layer.
101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void StackBelow(Layer* child, Layer* other);
102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Returns the child Layers.
104f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const std::vector<Layer*>& children() const { return children_; }
1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // The parent.
1077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  const Layer* parent() const { return parent_; }
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Layer* parent() { return parent_; }
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
110f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  LayerType type() const { return type_; }
111f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
11258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Returns true if this Layer contains |other| somewhere in its children.
113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool Contains(const Layer* other) const;
1147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The layer's animator is responsible for causing automatic animations when
1167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // properties are set. It also manages a queue of pending animations and
11758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // handles blending of animations. The layer takes ownership of the animator.
1187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetAnimator(LayerAnimator* animator);
1197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Returns the layer's animator. Creates a default animator of one has not
12158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // been set. Will not return NULL.
1227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  LayerAnimator* GetAnimator();
1237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // The transform, relative to the parent.
1257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetTransform(const gfx::Transform& transform);
1267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  gfx::Transform transform() const;
1277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Return the target transform if animator is running, or the current
1297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // transform otherwise.
13058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Transform GetTargetTransform() const;
13158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
13258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // The bounds, relative to the parent.
1337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetBounds(const gfx::Rect& bounds);
1347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  const gfx::Rect& bounds() const { return bounds_; }
1357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Return the target bounds if animator is running, or the current bounds
137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // otherwise.
138f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Rect GetTargetBounds() const;
1397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Sets/gets whether or not drawing of child layers should be clipped to the
141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // bounds of this layer.
14258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void SetMasksToBounds(bool masks_to_bounds);
143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  bool GetMasksToBounds() const;
14458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // The opacity of the layer. The opacity is applied to each pixel of the
14658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // texture (resulting alpha = opacity * alpha).
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float opacity() const;
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetOpacity(float opacity);
1497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
150f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Returns the actual opacity, which the opacity of this layer multipled by
1517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // the combined opacity of the parent.
1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  float GetCombinedOpacity() const;
1537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
15458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Blur pixels by this amount in anything below the layer and visible through
1557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // the layer.
1567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  int background_blur() const { return background_blur_radius_; }
1577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetBackgroundBlur(int blur_radius);
1587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Saturate all pixels of this layer by this amount.
1607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // This effect will get "combined" with the inverted,
161f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // brightness and grayscale setting.
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float layer_saturation() const { return layer_saturation_; }
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetLayerSaturation(float saturation);
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Change the brightness of all pixels from this layer by this amount.
16690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // This effect will get "combined" with the inverted, saturate
16790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // and grayscale setting.
16890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  float layer_brightness() const { return layer_brightness_; }
16990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void SetLayerBrightness(float brightness);
170f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
17190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Return the target brightness if animator is running, or the current
17290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // brightness otherwise.
1737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  float GetTargetBrightness() const;
1747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Change the grayscale of all pixels from this layer by this amount.
17690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // This effect will get "combined" with the inverted, saturate
17790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // and brightness setting.
178f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  float layer_grayscale() const { return layer_grayscale_; }
179f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void SetLayerGrayscale(float grayscale);
18090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Return the target grayscale if animator is running, or the current
182f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // grayscale otherwise.
183f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  float GetTargetGrayscale() const;
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Zoom the background by a factor of |zoom|. The effect is blended along the
18690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // edge across |inset| pixels.
1877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetBackgroundZoom(float zoom, int inset);
1887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
18958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Invert the layer.
19090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool layer_inverted() const { return layer_inverted_; }
1917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetLayerInverted(bool inverted);
1927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
19390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Return the target opacity if animator is running, or the current opacity
1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // otherwise.
1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  float GetTargetOpacity() const;
1967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Set a layer mask for a layer.
1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Note the provided layer mask can neither have a layer mask itself nor can
19958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // it have any children. The ownership of |layer_mask| will not be
2007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // transferred with this call.
2017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Furthermore: A mask layer can only be set to one layer.
2027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetMaskLayer(Layer* layer_mask);
2037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  Layer* layer_mask_layer() { return layer_mask_; }
2047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
20590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Sets the visibility of the Layer. A Layer may be visible but not
2067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // drawn. This happens if any ancestor of a Layer is not visible.
20790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void SetVisible(bool visible);
208f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool visible() const { return visible_; }
2097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Returns the target visibility if the animator is running. Otherwise, it
2117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // returns the current visibility.
2127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool GetTargetVisibility() const;
2137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors
2157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // are visible.
2167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool IsDrawn() const;
21790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
21890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Returns true if this layer can have a texture (has_texture_ is true)
21990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // and is not completely obscured by a child.
220f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool ShouldDraw() const;
221f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
22290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Converts a point from the coordinates of |source| to the coordinates of
22390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // |target|. Necessarily, |source| and |target| must inhabit the same Layer
22490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // tree.
22590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static void ConvertPointToLayer(const Layer* source,
226f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                  const Layer* target,
22758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                                  gfx::Point* point);
228f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
22990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Converts a transform to be relative to the given |ancestor|. Returns
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // whether success (that is, whether the given ancestor was really an
2317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // ancestor of this layer).
23258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool GetTargetTransformRelativeTo(const Layer* ancestor,
23390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                    gfx::Transform* transform) const;
2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Converts a ui::Layer's transform to the transform on the corresponding
2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // cc::Layer.
2377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static gfx::Transform ConvertTransformToCCTransform(
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const gfx::Transform& transform,
2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      float device_scale_factor);
24058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
24158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // See description in View for details
2427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetFillsBoundsOpaquely(bool fills_bounds_opaquely);
2437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool fills_bounds_opaquely() const { return fills_bounds_opaquely_; }
2447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
24590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const std::string& name() const { return name_; }
24690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void set_name(const std::string& name) { name_ = name; }
24790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
248f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const ui::Texture* texture() const { return texture_.get(); }
24990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
25090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Assigns a new external texture.  |texture| can be NULL to disable external
25190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // updates.
25290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void SetExternalTexture(ui::Texture* texture);
25390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ui::Texture* external_texture() { return texture_.get(); }
254f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
255f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Set new TextureMailbox for this layer. Note that |mailbox| may hold a
25690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // shared memory resource or an actual mailbox for a texture.
257f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void SetTextureMailbox(const cc::TextureMailbox& mailbox, float scale_factor);
2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  cc::TextureMailbox GetTextureMailbox(float* scale_factor);
25990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
26090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Sets a delegated frame, coming from a child compositor.
26190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void SetDelegatedFrame(scoped_ptr<cc::DelegatedFrameData> frame,
2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         gfx::Size frame_size_in_dip);
263f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
2647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool has_external_content() {
26590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return texture_layer_.get() || delegated_renderer_layer_.get();
2667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
26790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
26890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Gets unused resources to recycle to the child compositor.
2697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void TakeUnusedResourcesForChildCompositor(
27090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      cc::TransferableResourceArray* array);
2717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
27290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Sets the layer's fill color.  May only be called for LAYER_SOLID_COLOR.
27390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void SetColor(SkColor color);
27490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Adds |invalid_rect| to the Layer's pending invalid rect and calls
2767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // ScheduleDraw(). Returns false if the paint request is ignored.
2777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool SchedulePaint(const gfx::Rect& invalid_rect);
27890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
27990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Schedules a redraw of the layer tree at the compositor.
28090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Note that this _does not_ invalidate any region of this layer; use
28190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // SchedulePaint() for that.
28290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void ScheduleDraw();
28390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
28490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Sends damaged rectangles recorded in |damaged_region_| to
28590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // |compostior_| to repaint the content.
2867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SendDamagedRects();
2877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
28858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Suppresses painting the content by disgarding damaged region and ignoring
2897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // new paint requests.
2907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SuppressPaint();
29190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
29290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Notifies the layer that the device scale factor has changed.
29390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void OnDeviceScaleFactorChanged(float device_scale_factor);
294f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
295f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Sets whether the layer should scale its content. If true, the canvas will
29658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // be scaled in software rendering mode before it is passed to
297f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // |LayerDelegate::OnPaint|.
29858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Set to false if the delegate handles scaling.
29958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // NOTE: if this is called during |LayerDelegate::OnPaint|, the new value will
30058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // not apply to the canvas passed to the pending draw.
3017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void set_scale_content(bool scale_content) { scale_content_ = scale_content; }
3027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
303f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Returns true if the layer scales its content.
3047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool scale_content() const { return scale_content_; }
3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Sometimes the Layer is being updated by something other than SetCanvas
3077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // (e.g. the GPU process on UI_COMPOSITOR_IMAGE_TRANSPORT).
3087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  bool layer_updated_externally() const { return layer_updated_externally_; }
3097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Requets a copy of the layer's output as a texture or bitmap.
3117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request);
3127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // ContentLayerClient
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void PaintContents(
3157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      SkCanvas* canvas, gfx::Rect clip, gfx::RectF* opaque) OVERRIDE;
3167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
3177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
318f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  cc::Layer* cc_layer() { return cc_layer_; }
319f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
3207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // TextureLayerClient
3217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual unsigned PrepareTexture() OVERRIDE;
3227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE;
323f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual bool PrepareTextureMailbox(cc::TextureMailbox* mailbox,
3247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                     bool use_shared_memory) OVERRIDE;
3257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  float device_scale_factor() const { return device_scale_factor_; }
327f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
3287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Forces a render surface to be used on this layer. This has no positive
3297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // impact, and is only used for benchmarking/testing purpose.
3307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetForceRenderSurface(bool force);
331f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool force_render_surface() const { return force_render_surface_; }
3327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // LayerAnimationEventObserver
3347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void OnAnimationStarted(const cc::AnimationEvent& event) OVERRIDE;
3357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Whether this layer has animations waiting to get sent to its cc::Layer.
3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool HasPendingThreadedAnimations() {
3387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return pending_threaded_animations_.size() != 0;
3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
3407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Triggers a call to SwitchToLayer.
3427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SwitchCCLayerForTest();
3437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) private:
3457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Stacks |child| above or below |other|.  Helper method for StackAbove() and
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // StackBelow().
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StackRelativeTo(Layer* child, Layer* other, bool above);
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
349f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const;
35058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const;
35158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
35258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Following are invoked from the animation or if no animation exists to
35358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // update the values immediately.
3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void SetBoundsImmediately(const gfx::Rect& bounds);
3557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetTransformImmediately(const gfx::Transform& transform);
3565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void SetOpacityImmediately(float opacity);
3575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void SetVisibilityImmediately(bool visibility);
3587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetBrightnessImmediately(float brightness);
35958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void SetGrayscaleImmediately(float grayscale);
3607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void SetColorImmediately(SkColor color);
3617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
36258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Implementation of LayerAnimatorDelegate
3637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE;
3647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void SetTransformFromAnimation(
3655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const gfx::Transform& transform) OVERRIDE;
3665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetOpacityFromAnimation(float opacity) OVERRIDE;
3677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void SetVisibilityFromAnimation(bool visibility) OVERRIDE;
36858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void SetBrightnessFromAnimation(float brightness) OVERRIDE;
3697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void SetGrayscaleFromAnimation(float grayscale) OVERRIDE;
3707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void SetColorFromAnimation(SkColor color) OVERRIDE;
37158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void ScheduleDrawForAnimation() OVERRIDE;
372c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE;
37358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual gfx::Transform GetTransformForAnimation() const OVERRIDE;
37458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual float GetOpacityForAnimation() const OVERRIDE;
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool GetVisibilityForAnimation() const OVERRIDE;
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual float GetBrightnessForAnimation() const OVERRIDE;
377f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual float GetGrayscaleForAnimation() const OVERRIDE;
37858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual SkColor GetColorForAnimation() const OVERRIDE;
37958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual float GetDeviceScaleFactor() const OVERRIDE;
38058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void AddThreadedAnimation(
38158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      scoped_ptr<cc::Animation> animation) OVERRIDE;
38258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void RemoveThreadedAnimation(int animation_id) OVERRIDE;
38358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
38458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void CreateWebLayer();
38558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void RecomputeCCTransformFromTransform(const gfx::Transform& transform);
38658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  void RecomputeDrawsContentAndUVRect();
387  void RecomputePosition();
388
389  // Set all filters which got applied to the layer.
390  void SetLayerFilters();
391
392  // Set all filters which got applied to the layer background.
393  void SetLayerBackgroundFilters();
394
395  void UpdateIsDrawn();
396
397  void SwitchToLayer(scoped_refptr<cc::Layer> new_layer);
398
399  // We cannot send animations to our cc_layer_ until we have been added to a
400  // layer tree. Instead, we hold on to these animations in
401  // pending_threaded_animations_, and expect SendPendingThreadedAnimations to
402  // be called once we have been added to a tree.
403  void SendPendingThreadedAnimations();
404
405  const LayerType type_;
406
407  Compositor* compositor_;
408
409  scoped_refptr<ui::Texture> texture_;
410
411  Layer* parent_;
412
413  // This layer's children, in bottom-to-top stacking order.
414  std::vector<Layer*> children_;
415
416  gfx::Rect bounds_;
417
418  // Visibility of this layer. See SetVisible/IsDrawn for more details.
419  bool visible_;
420
421  bool force_render_surface_;
422
423  bool fills_bounds_opaquely_;
424
425  // If true the layer is always up to date.
426  bool layer_updated_externally_;
427
428  // Union of damaged rects, in pixel coordinates, to be used when
429  // compositor is ready to paint the content.
430  SkRegion damaged_region_;
431
432  int background_blur_radius_;
433
434  // Several variables which will change the visible representation of
435  // the layer.
436  float layer_saturation_;
437  float layer_brightness_;
438  float layer_grayscale_;
439  bool layer_inverted_;
440
441  // The associated mask layer with this layer.
442  Layer* layer_mask_;
443  // The back link from the mask layer to it's associated masked layer.
444  // We keep this reference for the case that if the mask layer gets deleted
445  // while attached to the main layer before the main layer is deleted.
446  Layer* layer_mask_back_link_;
447
448  // The zoom factor to scale the layer by.  Zooming is disabled when this is
449  // set to 1.
450  float zoom_;
451
452  // Width of the border in pixels, where the scaling is blended.
453  int zoom_inset_;
454
455  std::string name_;
456
457  LayerDelegate* delegate_;
458
459  scoped_refptr<LayerAnimator> animator_;
460
461  // Animations that are passed to AddThreadedAnimation before this layer is
462  // added to a tree.
463  cc::ScopedPtrVector<cc::Animation> pending_threaded_animations_;
464
465  // Ownership of the layer is held through one of the strongly typed layer
466  // pointers, depending on which sort of layer this is.
467  scoped_refptr<cc::ContentLayer> content_layer_;
468  scoped_refptr<cc::TextureLayer> texture_layer_;
469  scoped_refptr<cc::SolidColorLayer> solid_color_layer_;
470  scoped_refptr<cc::DelegatedRendererLayer> delegated_renderer_layer_;
471  cc::Layer* cc_layer_;
472
473  // If true, the layer scales the canvas and the texture with the device scale
474  // factor as appropriate. When true, the texture size is in DIP.
475  bool scale_content_;
476
477  // A cached copy of |Compositor::device_scale_factor()|.
478  float device_scale_factor_;
479
480  // A cached copy of the TextureMailbox given texture_layer_.
481  cc::TextureMailbox mailbox_;
482
483  // Device scale factor in which mailbox_ was rendered in.
484  float mailbox_scale_factor_;
485
486  // The size of the delegated frame in DIP, set when SetDelegatedFrame was
487  // called.
488  gfx::Size delegated_frame_size_in_dip_;
489
490  DISALLOW_COPY_AND_ASSIGN(Layer);
491};
492
493}  // namespace ui
494
495#endif  // UI_COMPOSITOR_LAYER_H_
496