1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CC_LAYERS_UI_RESOURCE_LAYER_H_
6#define CC_LAYERS_UI_RESOURCE_LAYER_H_
7
8#include "base/memory/scoped_ptr.h"
9#include "cc/base/cc_export.h"
10#include "cc/layers/layer.h"
11#include "cc/resources/ui_resource_client.h"
12#include "ui/gfx/rect.h"
13
14namespace cc {
15
16class LayerTreeHost;
17class ScopedUIResource;
18
19class CC_EXPORT UIResourceLayer : public Layer {
20 public:
21  static scoped_refptr<UIResourceLayer> Create();
22
23  virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
24
25  virtual void SetLayerTreeHost(LayerTreeHost* host) OVERRIDE;
26
27  void SetBitmap(const SkBitmap& skbitmap);
28
29  // An alternative way of setting the resource to allow for sharing.
30  void SetUIResourceId(UIResourceId resource_id);
31
32  // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1).
33  void SetUV(const gfx::PointF& top_left, const gfx::PointF& bottom_right);
34
35  // Sets an opacity value per vertex. It will be multiplied by the layer
36  // opacity value.
37  void SetVertexOpacity(float bottom_left,
38                        float top_left,
39                        float top_right,
40                        float bottom_right);
41
42  class UIResourceHolder {
43   public:
44    virtual UIResourceId id() = 0;
45    virtual ~UIResourceHolder();
46  };
47
48 protected:
49  UIResourceLayer();
50  virtual ~UIResourceLayer();
51
52  virtual bool HasDrawableContent() const OVERRIDE;
53
54  scoped_ptr<UIResourceHolder> ui_resource_holder_;
55  SkBitmap bitmap_;
56
57  gfx::PointF uv_top_left_;
58  gfx::PointF uv_bottom_right_;
59  float vertex_opacity_[4];
60
61 private:
62  virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
63      OVERRIDE;
64  void RecreateUIResourceHolder();
65
66
67
68  DISALLOW_COPY_AND_ASSIGN(UIResourceLayer);
69};
70
71}  // namespace cc
72
73#endif  // CC_LAYERS_UI_RESOURCE_LAYER_H_
74