OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CC_LAYERS_TEXTURE_LAYER_H_ | |
6 #define CC_LAYERS_TEXTURE_LAYER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/synchronization/lock.h" | |
12 #include "base/threading/thread_checker.h" | |
13 #include "cc/base/cc_export.h" | |
14 #include "cc/layers/layer.h" | |
15 #include "cc/resources/texture_mailbox.h" | |
16 | |
17 namespace cc { | |
18 class BlockingTaskRunner; | |
19 class SingleReleaseCallback; | |
20 class SingleReleaseCallbackImpl; | |
21 class TextureLayerClient; | |
22 | |
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 TextureMailboxHolder | |
27 : public base::RefCountedThreadSafe<TextureMailboxHolder> { | |
28 public: | |
29 class CC_EXPORT MainThreadReference { | |
30 public: | |
31 explicit MainThreadReference(TextureMailboxHolder* holder); | |
32 ~MainThreadReference(); | |
33 TextureMailboxHolder* holder() { return holder_.get(); } | |
34 | |
35 private: | |
36 scoped_refptr<TextureMailboxHolder> holder_; | |
37 DISALLOW_COPY_AND_ASSIGN(MainThreadReference); | |
38 }; | |
39 | |
40 const TextureMailbox& mailbox() const { return mailbox_; } | |
41 void Return(uint32 sync_point, bool is_lost); | |
42 | |
43 // Gets a ReleaseCallback that can be called from another thread. Note: the | |
44 // caller must ensure the callback is called. | |
45 scoped_ptr<SingleReleaseCallbackImpl> GetCallbackForImplThread(); | |
46 | |
47 protected: | |
48 friend class TextureLayer; | |
49 | |
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 ~TextureMailboxHolder(); | |
55 | |
56 private: | |
57 friend class base::RefCountedThreadSafe<TextureMailboxHolder>; | |
58 friend class MainThreadReference; | |
59 explicit TextureMailboxHolder( | |
60 const TextureMailbox& mailbox, | |
61 scoped_ptr<SingleReleaseCallback> release_callback); | |
62 | |
63 void InternalAddRef(); | |
64 void InternalRelease(); | |
65 void ReturnAndReleaseOnImplThread( | |
66 uint32 sync_point, | |
67 bool is_lost, | |
68 BlockingTaskRunner* main_thread_task_runner); | |
69 | |
70 // These members are only accessed on the main thread, or on the impl thread | |
71 // during commit where the main thread is blocked. | |
72 unsigned internal_references_; | |
73 TextureMailbox mailbox_; | |
74 scoped_ptr<SingleReleaseCallback> release_callback_; | |
75 | |
76 // This lock guards the sync_point_ and is_lost_ fields because they can be | |
77 // accessed on both the impl and main thread. We do this to ensure that the | |
78 // values of these fields are well-ordered such that the last call to | |
79 // ReturnAndReleaseOnImplThread() defines their values. | |
80 base::Lock arguments_lock_; | |
81 uint32 sync_point_; | |
82 bool is_lost_; | |
83 base::ThreadChecker main_thread_checker_; | |
84 DISALLOW_COPY_AND_ASSIGN(TextureMailboxHolder); | |
85 }; | |
86 | |
87 // Used when mailbox names are specified instead of texture IDs. | |
88 static scoped_refptr<TextureLayer> CreateForMailbox( | |
89 TextureLayerClient* client); | |
90 | |
91 // Resets the client, which also resets the texture. | |
92 void ClearClient(); | |
93 | |
94 // Resets the texture. | |
95 void ClearTexture(); | |
96 | |
97 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; | |
98 | |
99 // Sets whether this texture should be Y-flipped at draw time. Defaults to | |
100 // true. | |
101 void SetFlipped(bool flipped); | |
102 bool flipped() const { return flipped_; } | |
103 | |
104 // Sets whether this texture should use nearest neighbor interpolation as | |
105 // opposed to bilinear. Defaults to false. | |
106 void SetNearestNeighbor(bool nearest_neighbor); | |
107 | |
108 // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1). | |
109 void SetUV(const gfx::PointF& top_left, const gfx::PointF& bottom_right); | |
110 | |
111 // Sets an opacity value per vertex. It will be multiplied by the layer | |
112 // opacity value. | |
113 void SetVertexOpacity(float bottom_left, | |
114 float top_left, | |
115 float top_right, | |
116 float bottom_right); | |
117 | |
118 // Sets whether the alpha channel is premultiplied or unpremultiplied. | |
119 // Defaults to true. | |
120 void SetPremultipliedAlpha(bool premultiplied_alpha); | |
121 | |
122 // Sets whether the texture should be blended with the background color | |
123 // at draw time. Defaults to false. | |
124 void SetBlendBackgroundColor(bool blend); | |
125 | |
126 // Sets whether this context should rate limit on damage to prevent too many | |
127 // frames from being queued up before the compositor gets a chance to run. | |
128 // Requires a non-nil client. Defaults to false. | |
129 void SetRateLimitContext(bool rate_limit); | |
130 | |
131 // Code path for plugins which supply their own mailbox. | |
132 void SetTextureMailbox(const TextureMailbox& mailbox, | |
133 scoped_ptr<SingleReleaseCallback> release_callback); | |
134 | |
135 // Use this for special cases where the same texture is used to back the | |
136 // TextureLayer across all frames. | |
137 // WARNING: DON'T ACTUALLY USE THIS WHAT YOU ARE DOING IS WRONG. | |
138 // TODO(danakj): Remove this when pepper doesn't need it. crbug.com/350204 | |
139 void SetTextureMailboxWithoutReleaseCallback(const TextureMailbox& mailbox); | |
140 | |
141 void SetNeedsDisplayRect(const gfx::Rect& dirty_rect) override; | |
142 | |
143 void SetLayerTreeHost(LayerTreeHost* layer_tree_host) override; | |
144 bool Update(ResourceUpdateQueue* queue, | |
145 const OcclusionTracker<Layer>* occlusion) override; | |
146 void PushPropertiesTo(LayerImpl* layer) override; | |
147 SimpleEnclosedRegion VisibleContentOpaqueRegion() const override; | |
148 | |
149 protected: | |
150 explicit TextureLayer(TextureLayerClient* client); | |
151 ~TextureLayer() override; | |
152 bool HasDrawableContent() const override; | |
153 | |
154 private: | |
155 void SetTextureMailboxInternal( | |
156 const TextureMailbox& mailbox, | |
157 scoped_ptr<SingleReleaseCallback> release_callback, | |
158 bool requires_commit, | |
159 bool allow_mailbox_reuse); | |
160 | |
161 TextureLayerClient* client_; | |
162 | |
163 bool flipped_; | |
164 bool nearest_neighbor_; | |
165 gfx::PointF uv_top_left_; | |
166 gfx::PointF uv_bottom_right_; | |
167 // [bottom left, top left, top right, bottom right] | |
168 float vertex_opacity_[4]; | |
169 bool premultiplied_alpha_; | |
170 bool blend_background_color_; | |
171 bool rate_limit_context_; | |
172 | |
173 scoped_ptr<TextureMailboxHolder::MainThreadReference> holder_ref_; | |
174 bool needs_set_mailbox_; | |
175 | |
176 DISALLOW_COPY_AND_ASSIGN(TextureLayer); | |
177 }; | |
178 | |
179 } // namespace cc | |
180 #endif // CC_LAYERS_TEXTURE_LAYER_H_ | |
OLD | NEW |