OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
6 | 6 |
7 #include "cc/base/thread.h" | 7 #include "cc/base/thread.h" |
8 #include "cc/layers/texture_layer_client.h" | 8 #include "cc/layers/texture_layer_client.h" |
9 #include "cc/layers/texture_layer_impl.h" | 9 #include "cc/layers/texture_layer_impl.h" |
10 #include "cc/trees/layer_tree_host.h" | 10 #include "cc/trees/layer_tree_host.h" |
11 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 11 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 | 14 |
15 static void RunCallbackOnMainThread( | 15 namespace { |
| 16 |
| 17 void RunCallback( |
16 const TextureMailbox::ReleaseCallback& callback, | 18 const TextureMailbox::ReleaseCallback& callback, |
17 unsigned sync_point, | 19 unsigned sync_point, |
18 bool lost_resource) { | 20 bool lost_resource) { |
19 callback.Run(sync_point, lost_resource); | 21 callback.Run(sync_point, lost_resource); |
20 } | 22 } |
21 | 23 |
22 static void PostCallbackToMainThread( | 24 void PostCallbackToThread( |
23 Thread* main_thread, | 25 Thread* thread, |
24 const TextureMailbox::ReleaseCallback& callback, | 26 const TextureMailbox::ReleaseCallback& callback, |
25 unsigned sync_point, | 27 unsigned sync_point, |
26 bool lost_resource) { | 28 bool lost_resource) { |
27 main_thread->PostTask(base::Bind(&RunCallbackOnMainThread, | 29 if (!callback.is_null()) { |
28 callback, | 30 thread->PostTask(base::Bind(&RunCallback, callback, |
29 sync_point, | 31 sync_point, lost_resource)); |
30 lost_resource)); | 32 } |
31 } | 33 } |
32 | 34 |
| 35 } // namespace |
| 36 |
33 scoped_refptr<TextureLayer> TextureLayer::Create(TextureLayerClient* client) { | 37 scoped_refptr<TextureLayer> TextureLayer::Create(TextureLayerClient* client) { |
34 return scoped_refptr<TextureLayer>(new TextureLayer(client, false)); | 38 return scoped_refptr<TextureLayer>(new TextureLayer(client, false)); |
35 } | 39 } |
36 | 40 |
37 scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox( | 41 scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox( |
38 TextureLayerClient* client) { | 42 TextureLayerClient* client) { |
39 return scoped_refptr<TextureLayer>(new TextureLayer(client, true)); | 43 return scoped_refptr<TextureLayer>(new TextureLayer(client, true)); |
40 } | 44 } |
41 | 45 |
42 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox) | 46 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 if (texture_id_ == id) | 140 if (texture_id_ == id) |
137 return; | 141 return; |
138 if (texture_id_ && layer_tree_host()) | 142 if (texture_id_ && layer_tree_host()) |
139 layer_tree_host()->AcquireLayerTextures(); | 143 layer_tree_host()->AcquireLayerTextures(); |
140 texture_id_ = id; | 144 texture_id_ = id; |
141 SetNeedsCommit(); | 145 SetNeedsCommit(); |
142 } | 146 } |
143 | 147 |
144 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) { | 148 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) { |
145 DCHECK(uses_mailbox_); | 149 DCHECK(uses_mailbox_); |
146 DCHECK(mailbox.IsEmpty() || !mailbox.Equals(texture_mailbox_)); | 150 if (own_mailbox_) |
| 151 DCHECK(!mailbox.IsValid() || !mailbox.Equals(texture_mailbox_)); |
147 // If we never commited the mailbox, we need to release it here | 152 // If we never commited the mailbox, we need to release it here |
148 if (own_mailbox_) | 153 if (own_mailbox_) |
149 texture_mailbox_.RunReleaseCallback(texture_mailbox_.sync_point(), false); | 154 texture_mailbox_.RunReleaseCallback(texture_mailbox_.sync_point(), false); |
150 texture_mailbox_ = mailbox; | 155 texture_mailbox_ = mailbox; |
151 own_mailbox_ = true; | 156 own_mailbox_ = true; |
152 | |
153 SetNeedsCommit(); | 157 SetNeedsCommit(); |
154 } | 158 } |
155 | 159 |
156 void TextureLayer::WillModifyTexture() { | 160 void TextureLayer::WillModifyTexture() { |
157 if (layer_tree_host() && (DrawsContent() || content_committed_)) { | 161 if (layer_tree_host() && (DrawsContent() || content_committed_)) { |
158 layer_tree_host()->AcquireLayerTextures(); | 162 layer_tree_host()->AcquireLayerTextures(); |
159 content_committed_ = false; | 163 content_committed_ = false; |
160 } | 164 } |
161 } | 165 } |
162 | 166 |
163 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { | 167 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { |
164 Layer::SetNeedsDisplayRect(dirty_rect); | 168 Layer::SetNeedsDisplayRect(dirty_rect); |
165 | 169 |
166 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) | 170 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) |
167 layer_tree_host()->StartRateLimiter(client_->Context3d()); | 171 layer_tree_host()->StartRateLimiter(client_->Context3d()); |
168 } | 172 } |
169 | 173 |
170 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 174 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
171 if (texture_id_ && layer_tree_host() && host != layer_tree_host()) | 175 if (texture_id_ && layer_tree_host() && host != layer_tree_host()) |
172 layer_tree_host()->AcquireLayerTextures(); | 176 layer_tree_host()->AcquireLayerTextures(); |
173 Layer::SetLayerTreeHost(host); | 177 Layer::SetLayerTreeHost(host); |
174 } | 178 } |
175 | 179 |
176 bool TextureLayer::DrawsContent() const { | 180 bool TextureLayer::DrawsContent() const { |
177 return (client_ || texture_id_ || !texture_mailbox_.IsEmpty()) && | 181 return (client_ || texture_id_ || texture_mailbox_.IsValid()) && |
178 !context_lost_ && Layer::DrawsContent(); | 182 !context_lost_ && Layer::DrawsContent(); |
179 } | 183 } |
180 | 184 |
181 void TextureLayer::Update(ResourceUpdateQueue* queue, | 185 void TextureLayer::Update(ResourceUpdateQueue* queue, |
182 const OcclusionTracker* occlusion, | 186 const OcclusionTracker* occlusion, |
183 RenderingStats* stats) { | 187 RenderingStats* stats) { |
184 if (client_) { | 188 if (client_) { |
185 if (uses_mailbox_) { | 189 if (uses_mailbox_) { |
186 TextureMailbox mailbox; | 190 TextureMailbox mailbox; |
187 if (client_->PrepareTextureMailbox(&mailbox)) | 191 if (client_->PrepareTextureMailbox(&mailbox)) { |
| 192 if (mailbox.IsTexture()) |
| 193 DCHECK(client_->Context3d()); |
188 SetTextureMailbox(mailbox); | 194 SetTextureMailbox(mailbox); |
| 195 } |
189 } else { | 196 } else { |
| 197 DCHECK(client_->Context3d()); |
190 texture_id_ = client_->PrepareTexture(queue); | 198 texture_id_ = client_->PrepareTexture(queue); |
191 } | 199 } |
192 context_lost_ = | 200 context_lost_ = client_->Context3d() && |
193 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR; | 201 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR; |
194 } | 202 } |
195 | 203 |
196 needs_display_ = false; | 204 needs_display_ = false; |
197 } | 205 } |
198 | 206 |
199 void TextureLayer::PushPropertiesTo(LayerImpl* layer) { | 207 void TextureLayer::PushPropertiesTo(LayerImpl* layer) { |
200 Layer::PushPropertiesTo(layer); | 208 Layer::PushPropertiesTo(layer); |
201 | 209 |
202 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); | 210 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); |
203 texture_layer->set_flipped(flipped_); | 211 texture_layer->set_flipped(flipped_); |
204 texture_layer->set_uv_top_left(uv_top_left_); | 212 texture_layer->set_uv_top_left(uv_top_left_); |
205 texture_layer->set_uv_bottom_right(uv_bottom_right_); | 213 texture_layer->set_uv_bottom_right(uv_bottom_right_); |
206 texture_layer->set_vertex_opacity(vertex_opacity_); | 214 texture_layer->set_vertex_opacity(vertex_opacity_); |
207 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); | 215 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); |
208 if (uses_mailbox_ && own_mailbox_) { | 216 if (uses_mailbox_ && own_mailbox_) { |
209 Thread* main_thread = layer_tree_host()->proxy()->MainThread(); | 217 Thread* main_thread = layer_tree_host()->proxy()->MainThread(); |
210 TextureMailbox::ReleaseCallback callback; | 218 TextureMailbox::ReleaseCallback callback = base::Bind( |
211 if (!texture_mailbox_.IsEmpty()) | 219 &PostCallbackToThread, main_thread, texture_mailbox_.callback()); |
212 callback = base::Bind( | 220 texture_layer->SetTextureMailbox( |
213 &PostCallbackToMainThread, main_thread, texture_mailbox_.callback()); | 221 texture_mailbox_.CopyWithNewCallback(callback)); |
214 texture_layer->SetTextureMailbox(TextureMailbox( | |
215 texture_mailbox_.name(), callback, texture_mailbox_.sync_point())); | |
216 own_mailbox_ = false; | 222 own_mailbox_ = false; |
217 } else { | 223 } else { |
218 texture_layer->set_texture_id(texture_id_); | 224 texture_layer->set_texture_id(texture_id_); |
219 } | 225 } |
220 content_committed_ = DrawsContent(); | 226 content_committed_ = DrawsContent(); |
221 } | 227 } |
222 | 228 |
223 bool TextureLayer::BlocksPendingCommit() const { | 229 bool TextureLayer::BlocksPendingCommit() const { |
224 // Double-buffered texture layers need to be blocked until they can be made | 230 // Double-buffered texture layers need to be blocked until they can be made |
225 // triple-buffered. Single-buffered layers already prevent draws, so | 231 // triple-buffered. Single-buffered layers already prevent draws, so |
226 // can block too for simplicity. | 232 // can block too for simplicity. |
227 return DrawsContent(); | 233 return DrawsContent(); |
228 } | 234 } |
229 | 235 |
230 bool TextureLayer::CanClipSelf() const { | 236 bool TextureLayer::CanClipSelf() const { |
231 return true; | 237 return true; |
232 } | 238 } |
233 | 239 |
234 } // namespace cc | 240 } // namespace cc |
OLD | NEW |