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"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
14ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "base/message_loop/message_loop.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/animation/animation_events.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/animation/layer_animation_event_observer.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/base/scoped_ptr_vector.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/layers/content_layer_client.h"
19424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "cc/layers/layer_client.h"
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/layers/texture_layer_client.h"
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "cc/resources/texture_mailbox.h"
225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "cc/surfaces/surface_id.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkRegion.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/compositor.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_animation_delegate.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_delegate.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_type.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/transform.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SkCanvas;
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace cc {
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ContentLayer;
367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass CopyOutputRequest;
374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class DelegatedFrameProvider;
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DelegatedRendererLayer;
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Layer;
40116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass NinePatchLayer;
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ResourceUpdateQueue;
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SolidColorLayer;
435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class SurfaceLayer;
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TextureLayer;
453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)struct ReturnedResource;
463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)typedef std::vector<ReturnedResource> ReturnedResourceArray;
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui {
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Compositor;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LayerAnimator;
53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class LayerOwner;
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Layer manages a texture, transform and a set of child Layers. Any View that
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// has enabled layers ends up creating a Layer to manage the texture.
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A Layer can also be created without a texture, in which case it renders
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// nothing and is simply used as a node in a hierarchy of layers.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Coordinate system used in layers is DIP (Density Independent Pixel)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// coordinates unless explicitly mentioned as pixel coordinates.
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// NOTE: Unlike Views, each Layer does *not* own its child Layers. If you
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// delete a Layer and it has children, the parent of each child Layer is set to
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NULL, but the children are not deleted.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class COMPOSITOR_EXPORT Layer
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : public LayerAnimationDelegate,
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      NON_EXPORTED_BASE(public cc::ContentLayerClient),
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      NON_EXPORTED_BASE(public cc::TextureLayerClient),
69424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      NON_EXPORTED_BASE(public cc::LayerClient),
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      NON_EXPORTED_BASE(public cc::LayerAnimationEventObserver) {
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Layer();
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit Layer(LayerType type);
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~Layer();
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static bool UsingPictureLayer();
77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Retrieves the Layer's compositor. The Layer will walk up its parent chain
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to locate it. Returns NULL if the Layer is not attached to a compositor.
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Compositor* GetCompositor();
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by the compositor when the Layer is set as its root Layer. This can
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // only ever be called on the root layer.
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetCompositor(Compositor* compositor);
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LayerDelegate* delegate() { return delegate_; }
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_delegate(LayerDelegate* delegate) { delegate_ = delegate; }
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  LayerOwner* owner() { return owner_; }
90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds a new Layer to this Layer.
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Add(Layer* child);
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Removes a Layer from this Layer.
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Remove(Layer* child);
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stacks |child| above all other children.
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StackAtTop(Layer* child);
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stacks |child| directly above |other|.  Both must be children of this
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // layer.  Note that if |child| is initially stacked even higher, calling this
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // method will result in |child| being lowered in the stacking order.
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StackAbove(Layer* child, Layer* other);
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stacks |child| below all other children.
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StackAtBottom(Layer* child);
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stacks |child| directly below |other|.  Both must be children of this
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // layer.
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StackBelow(Layer* child, Layer* other);
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the child Layers.
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::vector<Layer*>& children() const { return children_; }
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The parent.
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Layer* parent() const { return parent_; }
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Layer* parent() { return parent_; }
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LayerType type() const { return type_; }
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if this Layer contains |other| somewhere in its children.
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Contains(const Layer* other) const;
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The layer's animator is responsible for causing automatic animations when
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // properties are set. It also manages a queue of pending animations and
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // handles blending of animations. The layer takes ownership of the animator.
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetAnimator(LayerAnimator* animator);
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the layer's animator. Creates a default animator of one has not
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // been set. Will not return NULL.
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LayerAnimator* GetAnimator();
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The transform, relative to the parent.
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetTransform(const gfx::Transform& transform);
1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Transform transform() const;
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Return the target transform if animator is running, or the current
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // transform otherwise.
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Transform GetTargetTransform() const;
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The bounds, relative to the parent.
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetBounds(const gfx::Rect& bounds);
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const gfx::Rect& bounds() const { return bounds_; }
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // The offset from our parent (stored in bounds.origin()) is an integer but we
146f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // may need to be at a fractional pixel offset to align properly on screen.
147f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void SetSubpixelPositionOffset(const gfx::Vector2dF offset);
148116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  const gfx::Vector2dF& subpixel_position_offset() const {
149116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return subpixel_position_offset_;
150116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
151f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Return the target bounds if animator is running, or the current bounds
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // otherwise.
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Rect GetTargetBounds() const;
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets/gets whether or not drawing of child layers should be clipped to the
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // bounds of this layer.
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetMasksToBounds(bool masks_to_bounds);
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetMasksToBounds() const;
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The opacity of the layer. The opacity is applied to each pixel of the
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // texture (resulting alpha = opacity * alpha).
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  float opacity() const;
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetOpacity(float opacity);
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the actual opacity, which the opacity of this layer multipled by
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the combined opacity of the parent.
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float GetCombinedOpacity() const;
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Blur pixels by this amount in anything below the layer and visible through
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the layer.
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int background_blur() const { return background_blur_radius_; }
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetBackgroundBlur(int blur_radius);
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Saturate all pixels of this layer by this amount.
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This effect will get "combined" with the inverted,
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // brightness and grayscale setting.
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float layer_saturation() const { return layer_saturation_; }
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetLayerSaturation(float saturation);
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Change the brightness of all pixels from this layer by this amount.
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This effect will get "combined" with the inverted, saturate
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and grayscale setting.
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float layer_brightness() const { return layer_brightness_; }
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetLayerBrightness(float brightness);
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Return the target brightness if animator is running, or the current
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // brightness otherwise.
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float GetTargetBrightness() const;
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Change the grayscale of all pixels from this layer by this amount.
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This effect will get "combined" with the inverted, saturate
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and brightness setting.
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float layer_grayscale() const { return layer_grayscale_; }
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetLayerGrayscale(float grayscale);
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Return the target grayscale if animator is running, or the current
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // grayscale otherwise.
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float GetTargetGrayscale() const;
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Zoom the background by a factor of |zoom|. The effect is blended along the
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // edge across |inset| pixels.
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SetBackgroundZoom(float zoom, int inset);
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Set the shape of this layer.
2061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  SkRegion* alpha_shape() const { return alpha_shape_.get(); }
2070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  void SetAlphaShape(scoped_ptr<SkRegion> region);
2080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Invert the layer.
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool layer_inverted() const { return layer_inverted_; }
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetLayerInverted(bool inverted);
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Return the target opacity if animator is running, or the current opacity
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // otherwise.
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float GetTargetOpacity() const;
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set a layer mask for a layer.
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note the provided layer mask can neither have a layer mask itself nor can
2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // it have any children. The ownership of |layer_mask| will not be
2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // transferred with this call.
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Furthermore: A mask layer can only be set to one layer.
2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void SetMaskLayer(Layer* layer_mask);
2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Layer* layer_mask_layer() { return layer_mask_; }
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the visibility of the Layer. A Layer may be visible but not
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // drawn. This happens if any ancestor of a Layer is not visible.
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetVisible(bool visible);
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool visible() const { return visible_; }
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the target visibility if the animator is running. Otherwise, it
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // returns the current visibility.
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetTargetVisibility() const;
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // are visible.
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsDrawn() const;
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if this layer can have a texture (has_texture_ is true)
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // and is not completely obscured by a child.
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ShouldDraw() const;
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Converts a point from the coordinates of |source| to the coordinates of
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |target|. Necessarily, |source| and |target| must inhabit the same Layer
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // tree.
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void ConvertPointToLayer(const Layer* source,
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  const Layer* target,
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  gfx::Point* point);
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Converts a transform to be relative to the given |ancestor|. Returns
2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // whether success (that is, whether the given ancestor was really an
2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // ancestor of this layer).
2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool GetTargetTransformRelativeTo(const Layer* ancestor,
2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                    gfx::Transform* transform) const;
2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // See description in View for details
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetFillsBoundsOpaquely(bool fills_bounds_opaquely);
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool fills_bounds_opaquely() const { return fills_bounds_opaquely_; }
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
259effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Set to true if this layer always paints completely within its bounds. If so
260effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // we can omit an unnecessary clear, even if the layer is transparent.
261effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  void SetFillsBoundsCompletely(bool fills_bounds_completely);
262effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::string& name() const { return name_; }
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_name(const std::string& name) { name_ = name; }
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
266868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Set new TextureMailbox for this layer. Note that |mailbox| may hold a
267868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // shared memory resource or an actual mailbox for a texture.
268d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  void SetTextureMailbox(const cc::TextureMailbox& mailbox,
269d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                         scoped_ptr<cc::SingleReleaseCallback> release_callback,
270c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                         gfx::Size texture_size_in_dip);
271c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  void SetTextureSize(gfx::Size texture_size_in_dip);
272868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Begins showing delegated frames from the |frame_provider|.
2744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void SetShowDelegatedContent(cc::DelegatedFrameProvider* frame_provider,
2754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                               gfx::Size frame_size_in_dip);
2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Begins showing content from a surface with a particular id.
2785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  void SetShowSurface(cc::SurfaceId id, gfx::Size frame_size_in_dip);
2795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2807dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bool has_external_content() {
2815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return texture_layer_.get() || delegated_renderer_layer_.get() ||
2825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)           surface_layer_.get();
2837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
2847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void SetShowPaintedContent();
2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the layer's fill color.  May only be called for LAYER_SOLID_COLOR.
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetColor(SkColor color);
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Updates the nine patch layer's bitmap, aperture and border. May only be
2911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // called for LAYER_NINE_PATCH.
2921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void UpdateNinePatchLayerBitmap(const SkBitmap& bitmap);
2931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void UpdateNinePatchLayerAperture(const gfx::Rect& aperture);
294116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void UpdateNinePatchLayerBorder(const gfx::Rect& border);
295116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds |invalid_rect| to the Layer's pending invalid rect and calls
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ScheduleDraw(). Returns false if the paint request is ignored.
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SchedulePaint(const gfx::Rect& invalid_rect);
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Schedules a redraw of the layer tree at the compositor.
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note that this _does not_ invalidate any region of this layer; use
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // SchedulePaint() for that.
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ScheduleDraw();
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Uses damaged rectangles recorded in |damaged_region_| to invalidate the
3065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |cc_layer_|.
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SendDamagedRects();
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
309a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const SkRegion& damaged_region() const { return damaged_region_; }
310a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
31146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void CompleteAllAnimations();
31246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Suppresses painting the content by disconnecting |delegate_|.
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SuppressPaint();
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notifies the layer that the device scale factor has changed.
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OnDeviceScaleFactorChanged(float device_scale_factor);
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Notifies the layer that one of its children has received a new
3201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // delegated frame.
3211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip);
3221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
3237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Requets a copy of the layer's output as a texture or bitmap.
3247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request);
3257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // ContentLayerClient
3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void PaintContents(
328010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      SkCanvas* canvas,
329010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      const gfx::Rect& clip,
330010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE;
3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
332effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  virtual bool FillsBoundsCompletely() const OVERRIDE;
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  cc::Layer* cc_layer() { return cc_layer_; }
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TextureLayerClient
337d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual bool PrepareTextureMailbox(
338d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      cc::TextureMailbox* mailbox,
339d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      scoped_ptr<cc::SingleReleaseCallback>* release_callback,
340d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      bool use_shared_memory) OVERRIDE;
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float device_scale_factor() const { return device_scale_factor_; }
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Forces a render surface to be used on this layer. This has no positive
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // impact, and is only used for benchmarking/testing purpose.
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetForceRenderSurface(bool force);
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool force_render_surface() const { return force_render_surface_; }
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
349424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // LayerClient
350a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual scoped_refptr<base::debug::ConvertableToTraceFormat>
351a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      TakeDebugInfo() OVERRIDE;
352a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // LayerAnimationEventObserver
3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAnimationStarted(const cc::AnimationEvent& event) OVERRIDE;
3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Whether this layer has animations waiting to get sent to its cc::Layer.
3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool HasPendingThreadedAnimations() {
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return pending_threaded_animations_.size() != 0;
3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Triggers a call to SwitchToLayer.
3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SwitchCCLayerForTest();
3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
365a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  friend class LayerOwner;
366a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
36746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void CollectAnimators(std::vector<scoped_refptr<LayerAnimator> >* animators);
36846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stacks |child| above or below |other|.  Helper method for StackAbove() and
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // StackBelow().
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StackRelativeTo(Layer* child, Layer* other, bool above);
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const;
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const;
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Implementation of LayerAnimatorDelegate
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE;
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetTransformFromAnimation(
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const gfx::Transform& transform) OVERRIDE;
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetOpacityFromAnimation(float opacity) OVERRIDE;
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetVisibilityFromAnimation(bool visibility) OVERRIDE;
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetBrightnessFromAnimation(float brightness) OVERRIDE;
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetGrayscaleFromAnimation(float grayscale) OVERRIDE;
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetColorFromAnimation(SkColor color) OVERRIDE;
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void ScheduleDrawForAnimation() OVERRIDE;
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE;
3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::Transform GetTransformForAnimation() const OVERRIDE;
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual float GetOpacityForAnimation() const OVERRIDE;
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool GetVisibilityForAnimation() const OVERRIDE;
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual float GetBrightnessForAnimation() const OVERRIDE;
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual float GetGrayscaleForAnimation() const OVERRIDE;
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual SkColor GetColorForAnimation() const OVERRIDE;
3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual float GetDeviceScaleFactor() const OVERRIDE;
3942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void AddThreadedAnimation(
3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      scoped_ptr<cc::Animation> animation) OVERRIDE;
3962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RemoveThreadedAnimation(int animation_id) OVERRIDE;
39746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual LayerAnimatorCollection* GetLayerAnimatorCollection() OVERRIDE;
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Creates a corresponding composited layer for |type_|.
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CreateWebLayer();
4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Recomputes and sets to |cc_layer_|.
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RecomputeDrawsContentAndUVRect();
404c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void RecomputePosition();
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set all filters which got applied to the layer.
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetLayerFilters();
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Set all filters which got applied to the layer background.
4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SetLayerBackgroundFilters();
4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Cleanup |cc_layer_| and replaces it with |new_layer|.
4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SwitchToLayer(scoped_refptr<cc::Layer> new_layer);
4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // We cannot send animations to our cc_layer_ until we have been added to a
4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // layer tree. Instead, we hold on to these animations in
4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // pending_threaded_animations_, and expect SendPendingThreadedAnimations to
4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // be called once we have been added to a tree.
4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SendPendingThreadedAnimations();
4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
42146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void AddAnimatorsInTreeToCollection(LayerAnimatorCollection* collection);
42246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void RemoveAnimatorsInTreeFromCollection(LayerAnimatorCollection* collection);
42346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
42446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Returns whether the layer has an animating LayerAnimator.
42546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  bool IsAnimating() const;
42646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const LayerType type_;
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Compositor* compositor_;
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Layer* parent_;
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This layer's children, in bottom-to-top stacking order.
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<Layer*> children_;
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Rect bounds_;
437f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  gfx::Vector2dF subpixel_position_offset_;
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Visibility of this layer. See SetVisible/IsDrawn for more details.
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool visible_;
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool force_render_surface_;
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool fills_bounds_opaquely_;
445effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  bool fills_bounds_completely_;
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Union of damaged rects, in pixel coordinates, to be used when
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // compositor is ready to paint the content.
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SkRegion damaged_region_;
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int background_blur_radius_;
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Several variables which will change the visible representation of
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the layer.
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float layer_saturation_;
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float layer_brightness_;
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float layer_grayscale_;
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool layer_inverted_;
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The associated mask layer with this layer.
4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Layer* layer_mask_;
4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The back link from the mask layer to it's associated masked layer.
4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We keep this reference for the case that if the mask layer gets deleted
4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // while attached to the main layer before the main layer is deleted.
4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Layer* layer_mask_back_link_;
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The zoom factor to scale the layer by.  Zooming is disabled when this is
4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // set to 1.
4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  float zoom_;
4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Width of the border in pixels, where the scaling is blended.
4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int zoom_inset_;
4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Shape of the window.
4750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  scoped_ptr<SkRegion> alpha_shape_;
4760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string name_;
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LayerDelegate* delegate_;
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
481a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  LayerOwner* owner_;
482a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<LayerAnimator> animator_;
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Animations that are passed to AddThreadedAnimation before this layer is
4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // added to a tree.
4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  cc::ScopedPtrVector<cc::Animation> pending_threaded_animations_;
4882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Ownership of the layer is held through one of the strongly typed layer
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // pointers, depending on which sort of layer this is.
491a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  scoped_refptr<cc::Layer> content_layer_;
492116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  scoped_refptr<cc::NinePatchLayer> nine_patch_layer_;
4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_refptr<cc::TextureLayer> texture_layer_;
4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_refptr<cc::SolidColorLayer> solid_color_layer_;
4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_refptr<cc::DelegatedRendererLayer> delegated_renderer_layer_;
4965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  scoped_refptr<cc::SurfaceLayer> surface_layer_;
4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  cc::Layer* cc_layer_;
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A cached copy of |Compositor::device_scale_factor()|.
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  float device_scale_factor_;
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
502c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // The mailbox used by texture_layer_.
503868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  cc::TextureMailbox mailbox_;
504868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
505c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // The callback to release the mailbox. This is only set after
506c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // SetTextureMailbox is called, before we give it to the TextureLayer.
507c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  scoped_ptr<cc::SingleReleaseCallback> mailbox_release_callback_;
508868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
509c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // The size of the frame or texture in DIP, set when SetShowDelegatedContent
510c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // or SetTextureMailbox was called.
511c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  gfx::Size frame_size_in_dip_;
5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(Layer);
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ui
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // UI_COMPOSITOR_LAYER_H_
519