Adding a logging class to cast.
[chromium-blink-merge.git] / cc / layers / texture_layer.h
blobb0edb22ba1c459bf1ed0ab9d342c37756cffcdf3
1 // Copyright 2010 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.
5 #ifndef CC_LAYERS_TEXTURE_LAYER_H_
6 #define CC_LAYERS_TEXTURE_LAYER_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/synchronization/lock.h"
12 #include "cc/base/cc_export.h"
13 #include "cc/layers/layer.h"
14 #include "cc/resources/texture_mailbox.h"
16 namespace WebKit { class WebGraphicsContext3D; }
18 namespace cc {
19 class BlockingTaskRunner;
20 class SingleReleaseCallback;
21 class TextureLayerClient;
23 // A Layer containing a the rendered output of a plugin instance.
24 class CC_EXPORT TextureLayer : public Layer {
25 public:
26 class CC_EXPORT MailboxHolder
27 : public base::RefCountedThreadSafe<MailboxHolder> {
28 public:
29 class CC_EXPORT MainThreadReference {
30 public:
31 explicit MainThreadReference(MailboxHolder* holder);
32 ~MainThreadReference();
33 MailboxHolder* holder() { return holder_.get(); }
35 private:
36 scoped_refptr<MailboxHolder> holder_;
37 DISALLOW_COPY_AND_ASSIGN(MainThreadReference);
40 const TextureMailbox& mailbox() const { return mailbox_; }
41 void Return(unsigned sync_point, bool is_lost);
43 // Gets a ReleaseCallback that can be called from another thread. Note: the
44 // caller must ensure the callback is called.
45 scoped_ptr<SingleReleaseCallback> GetCallbackForImplThread();
47 protected:
48 friend class TextureLayer;
50 // Protected visiblity so only TextureLayer and unit tests can create these.
51 static scoped_ptr<MainThreadReference> Create(
52 const TextureMailbox& mailbox,
53 scoped_ptr<SingleReleaseCallback> release_callback);
54 virtual ~MailboxHolder();
56 private:
57 friend class base::RefCountedThreadSafe<MailboxHolder>;
58 friend class MainThreadReference;
59 explicit MailboxHolder(const TextureMailbox& mailbox,
60 scoped_ptr<SingleReleaseCallback> release_callback);
62 void InternalAddRef();
63 void InternalRelease();
64 void ReturnAndReleaseOnImplThread(unsigned sync_point, bool is_lost);
66 // This member is thread safe, and is accessed on main and impl threads.
67 const scoped_refptr<BlockingTaskRunner> message_loop_;
69 // These members are only accessed on the main thread, or on the impl thread
70 // during commit where the main thread is blocked.
71 unsigned internal_references_;
72 TextureMailbox mailbox_;
73 scoped_ptr<SingleReleaseCallback> release_callback_;
75 // This lock guards the sync_point_ and is_lost_ fields because they can be
76 // accessed on both the impl and main thread. We do this to ensure that the
77 // values of these fields are well-ordered such that the last call to
78 // ReturnAndReleaseOnImplThread() defines their values.
79 base::Lock arguments_lock_;
80 unsigned sync_point_;
81 bool is_lost_;
82 DISALLOW_COPY_AND_ASSIGN(MailboxHolder);
85 // If this texture layer requires special preparation logic for each frame
86 // driven by the compositor, pass in a non-nil client. Pass in a nil client
87 // pointer if texture updates are driven by an external process.
88 static scoped_refptr<TextureLayer> Create(TextureLayerClient* client);
90 // Used when mailbox names are specified instead of texture IDs.
91 static scoped_refptr<TextureLayer> CreateForMailbox(
92 TextureLayerClient* client);
94 void ClearClient();
96 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
97 OVERRIDE;
99 // Sets whether this texture should be Y-flipped at draw time. Defaults to
100 // true.
101 void SetFlipped(bool flipped);
103 // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1).
104 void SetUV(gfx::PointF top_left, gfx::PointF bottom_right);
106 // Sets an opacity value per vertex. It will be multiplied by the layer
107 // opacity value.
108 void SetVertexOpacity(float bottom_left,
109 float top_left,
110 float top_right,
111 float bottom_right);
113 // Sets whether the alpha channel is premultiplied or unpremultiplied.
114 // Defaults to true.
115 void SetPremultipliedAlpha(bool premultiplied_alpha);
117 // Sets whether the texture should be blended with the background color
118 // at draw time. Defaults to false.
119 void SetBlendBackgroundColor(bool blend);
121 // Sets whether this context should rate limit on damage to prevent too many
122 // frames from being queued up before the compositor gets a chance to run.
123 // Requires a non-nil client. Defaults to false.
124 void SetRateLimitContext(bool rate_limit);
126 // Code path for plugins which supply their own texture ID.
127 // DEPRECATED. DO NOT USE.
128 void SetTextureId(unsigned texture_id);
130 // Code path for plugins which supply their own mailbox.
131 bool uses_mailbox() const { return uses_mailbox_; }
132 void SetTextureMailbox(const TextureMailbox& mailbox,
133 scoped_ptr<SingleReleaseCallback> release_callback);
135 void WillModifyTexture();
137 virtual void SetNeedsDisplayRect(const gfx::RectF& dirty_rect) OVERRIDE;
139 virtual void SetLayerTreeHost(LayerTreeHost* layer_tree_host) OVERRIDE;
140 virtual bool DrawsContent() const OVERRIDE;
141 virtual bool Update(ResourceUpdateQueue* queue,
142 const OcclusionTracker* occlusion) OVERRIDE;
143 virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
144 virtual Region VisibleContentOpaqueRegion() const OVERRIDE;
146 protected:
147 TextureLayer(TextureLayerClient* client, bool uses_mailbox);
148 virtual ~TextureLayer();
150 private:
151 TextureLayerClient* client_;
152 bool uses_mailbox_;
154 bool flipped_;
155 gfx::PointF uv_top_left_;
156 gfx::PointF uv_bottom_right_;
157 // [bottom left, top left, top right, bottom right]
158 float vertex_opacity_[4];
159 bool premultiplied_alpha_;
160 bool blend_background_color_;
161 bool rate_limit_context_;
162 bool content_committed_;
164 unsigned texture_id_;
165 scoped_ptr<MailboxHolder::MainThreadReference> holder_ref_;
166 bool needs_set_mailbox_;
168 DISALLOW_COPY_AND_ASSIGN(TextureLayer);
171 } // namespace cc
172 #endif // CC_LAYERS_TEXTURE_LAYER_H_