Chromium Code Reviews| 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/Source/Platform/chromium/public/WebGraphicsContext3 D.h" | 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.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)); | |
| 31 } | 32 } |
| 32 | 33 |
| 34 } // namespace | |
| 35 | |
| 33 scoped_refptr<TextureLayer> TextureLayer::Create(TextureLayerClient* client) { | 36 scoped_refptr<TextureLayer> TextureLayer::Create(TextureLayerClient* client) { |
| 34 return scoped_refptr<TextureLayer>(new TextureLayer(client, false)); | 37 return scoped_refptr<TextureLayer>(new TextureLayer(client, false)); |
| 35 } | 38 } |
| 36 | 39 |
| 37 scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox( | 40 scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox( |
| 38 TextureLayerClient* client) { | 41 TextureLayerClient* client) { |
| 39 return scoped_refptr<TextureLayer>(new TextureLayer(client, true)); | 42 return scoped_refptr<TextureLayer>(new TextureLayer(client, true)); |
| 40 } | 43 } |
| 41 | 44 |
| 42 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox) | 45 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 59 } | 62 } |
| 60 | 63 |
| 61 TextureLayer::~TextureLayer() { | 64 TextureLayer::~TextureLayer() { |
| 62 if (layer_tree_host()) { | 65 if (layer_tree_host()) { |
| 63 if (texture_id_) | 66 if (texture_id_) |
| 64 layer_tree_host()->AcquireLayerTextures(); | 67 layer_tree_host()->AcquireLayerTextures(); |
| 65 if (rate_limit_context_ && client_) | 68 if (rate_limit_context_ && client_) |
| 66 layer_tree_host()->StopRateLimiter(client_->Context3d()); | 69 layer_tree_host()->StopRateLimiter(client_->Context3d()); |
| 67 } | 70 } |
| 68 if (own_mailbox_) | 71 if (own_mailbox_) |
| 69 texture_mailbox_.RunReleaseCallback(texture_mailbox_.sync_point(), false); | 72 mailbox_.RunReleaseCallback(mailbox_.sync_point(), false); |
| 70 } | 73 } |
| 71 | 74 |
| 72 void TextureLayer::ClearClient() { | 75 void TextureLayer::ClearClient() { |
| 73 client_ = NULL; | 76 client_ = NULL; |
| 74 if (uses_mailbox_) | 77 if (uses_mailbox_) |
| 75 SetTextureMailbox(TextureMailbox()); | 78 SetTextureMailbox(TextureMailbox()); |
| 76 else | 79 else |
| 77 SetTextureId(0); | 80 SetTextureId(0); |
| 78 } | 81 } |
| 79 | 82 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 if (texture_id_ == id) | 139 if (texture_id_ == id) |
| 137 return; | 140 return; |
| 138 if (texture_id_ && layer_tree_host()) | 141 if (texture_id_ && layer_tree_host()) |
| 139 layer_tree_host()->AcquireLayerTextures(); | 142 layer_tree_host()->AcquireLayerTextures(); |
| 140 texture_id_ = id; | 143 texture_id_ = id; |
| 141 SetNeedsCommit(); | 144 SetNeedsCommit(); |
| 142 } | 145 } |
| 143 | 146 |
| 144 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) { | 147 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) { |
| 145 DCHECK(uses_mailbox_); | 148 DCHECK(uses_mailbox_); |
| 146 DCHECK(mailbox.IsEmpty() || !mailbox.Equals(texture_mailbox_)); | 149 DCHECK(!mailbox.IsValid() || !mailbox.Equals(mailbox_)); |
| 147 // If we never commited the mailbox, we need to release it here | 150 // If we never commited the mailbox, we need to release it here |
| 148 if (own_mailbox_) | 151 if (own_mailbox_) |
| 149 texture_mailbox_.RunReleaseCallback(texture_mailbox_.sync_point(), false); | 152 mailbox_.RunReleaseCallback(mailbox_.sync_point(), false); |
| 150 texture_mailbox_ = mailbox; | 153 mailbox_ = mailbox; |
| 151 own_mailbox_ = true; | 154 own_mailbox_ = true; |
| 152 | |
| 153 SetNeedsCommit(); | 155 SetNeedsCommit(); |
| 154 } | 156 } |
| 155 | 157 |
| 156 void TextureLayer::WillModifyTexture() { | 158 void TextureLayer::WillModifyTexture() { |
| 157 if (layer_tree_host() && (DrawsContent() || content_committed_)) { | 159 if (layer_tree_host() && (DrawsContent() || content_committed_)) { |
| 158 layer_tree_host()->AcquireLayerTextures(); | 160 layer_tree_host()->AcquireLayerTextures(); |
| 159 content_committed_ = false; | 161 content_committed_ = false; |
| 160 } | 162 } |
| 161 } | 163 } |
| 162 | 164 |
| 163 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { | 165 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { |
| 164 Layer::SetNeedsDisplayRect(dirty_rect); | 166 Layer::SetNeedsDisplayRect(dirty_rect); |
| 165 | 167 |
| 166 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) | 168 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) |
| 167 layer_tree_host()->StartRateLimiter(client_->Context3d()); | 169 layer_tree_host()->StartRateLimiter(client_->Context3d()); |
| 168 } | 170 } |
| 169 | 171 |
| 170 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 172 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 171 if (texture_id_ && layer_tree_host() && host != layer_tree_host()) | 173 if (texture_id_ && layer_tree_host() && host != layer_tree_host()) |
| 172 layer_tree_host()->AcquireLayerTextures(); | 174 layer_tree_host()->AcquireLayerTextures(); |
| 173 Layer::SetLayerTreeHost(host); | 175 Layer::SetLayerTreeHost(host); |
| 174 } | 176 } |
| 175 | 177 |
| 176 bool TextureLayer::DrawsContent() const { | 178 bool TextureLayer::DrawsContent() const { |
| 177 return (client_ || texture_id_ || !texture_mailbox_.IsEmpty()) && | 179 return (client_ || texture_id_ || mailbox_.IsValid()) && |
| 178 !context_lost_ && Layer::DrawsContent(); | 180 !context_lost_ && Layer::DrawsContent(); |
| 179 } | 181 } |
| 180 | 182 |
| 181 void TextureLayer::Update(ResourceUpdateQueue* queue, | 183 void TextureLayer::Update(ResourceUpdateQueue* queue, |
| 182 const OcclusionTracker* occlusion, | 184 const OcclusionTracker* occlusion, |
| 183 RenderingStats* stats) { | 185 RenderingStats* stats) { |
| 184 if (client_) { | 186 if (client_) { |
| 185 if (uses_mailbox_) { | 187 if (uses_mailbox_) { |
| 186 TextureMailbox mailbox; | 188 TextureMailbox mailbox; |
| 187 if (client_->PrepareTextureMailbox(&mailbox)) | 189 if (client_->PrepareTextureMailbox(&mailbox)) |
| 188 SetTextureMailbox(mailbox); | 190 SetTextureMailbox(mailbox); |
| 189 } else { | 191 } else { |
| 190 texture_id_ = client_->PrepareTexture(queue); | 192 texture_id_ = client_->PrepareTexture(queue); |
| 191 } | 193 } |
| 192 context_lost_ = | 194 context_lost_ = client_->Context3d() && |
|
danakj
2013/05/23 15:34:32
Can you DCHECK that Context3d() is not NULL when t
slavi
2013/05/28 18:55:13
Done.
| |
| 193 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR; | 195 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR; |
| 194 } | 196 } |
| 195 | 197 |
| 196 needs_display_ = false; | 198 needs_display_ = false; |
| 197 } | 199 } |
| 198 | 200 |
| 199 void TextureLayer::PushPropertiesTo(LayerImpl* layer) { | 201 void TextureLayer::PushPropertiesTo(LayerImpl* layer) { |
| 200 Layer::PushPropertiesTo(layer); | 202 Layer::PushPropertiesTo(layer); |
| 201 | 203 |
| 202 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); | 204 TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer); |
| 203 texture_layer->set_flipped(flipped_); | 205 texture_layer->set_flipped(flipped_); |
| 204 texture_layer->set_uv_top_left(uv_top_left_); | 206 texture_layer->set_uv_top_left(uv_top_left_); |
| 205 texture_layer->set_uv_bottom_right(uv_bottom_right_); | 207 texture_layer->set_uv_bottom_right(uv_bottom_right_); |
| 206 texture_layer->set_vertex_opacity(vertex_opacity_); | 208 texture_layer->set_vertex_opacity(vertex_opacity_); |
| 207 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); | 209 texture_layer->set_premultiplied_alpha(premultiplied_alpha_); |
| 208 if (uses_mailbox_ && own_mailbox_) { | 210 if (uses_mailbox_ && own_mailbox_) { |
| 209 Thread* main_thread = layer_tree_host()->proxy()->MainThread(); | 211 Thread* main_thread = layer_tree_host()->proxy()->MainThread(); |
| 210 TextureMailbox::ReleaseCallback callback; | 212 TextureMailbox::ReleaseCallback callback = base::Bind( |
| 211 if (!texture_mailbox_.IsEmpty()) | 213 &PostCallbackToThread, main_thread, mailbox_.callback()); |
| 212 callback = base::Bind( | 214 if (mailbox_.IsTexture()) { |
| 213 &PostCallbackToMainThread, main_thread, texture_mailbox_.callback()); | 215 texture_layer->SetTextureMailbox(TextureMailbox( |
| 214 texture_layer->SetTextureMailbox(TextureMailbox( | 216 mailbox_.name(), callback, mailbox_.sync_point())); |
| 215 texture_mailbox_.name(), callback, texture_mailbox_.sync_point())); | 217 } else if (mailbox_.IsSharedMemory()) { |
| 218 texture_layer->SetTextureMailbox(TextureMailbox( | |
| 219 mailbox_.handle(), mailbox_.size(), callback)); | |
| 220 } else { | |
| 221 texture_layer->SetTextureMailbox(TextureMailbox()); | |
|
danakj
2013/05/23 15:34:33
DCHECK that the texture_mailbox_ is not valid?
slavi
2013/05/28 18:55:13
Done.
| |
| 222 } | |
| 216 own_mailbox_ = false; | 223 own_mailbox_ = false; |
| 217 } else { | 224 } else { |
| 218 texture_layer->set_texture_id(texture_id_); | 225 texture_layer->set_texture_id(texture_id_); |
| 219 } | 226 } |
| 220 content_committed_ = DrawsContent(); | 227 content_committed_ = DrawsContent(); |
| 221 } | 228 } |
| 222 | 229 |
| 223 bool TextureLayer::BlocksPendingCommit() const { | 230 bool TextureLayer::BlocksPendingCommit() const { |
| 224 // Double-buffered texture layers need to be blocked until they can be made | 231 // Double-buffered texture layers need to be blocked until they can be made |
| 225 // triple-buffered. Single-buffered layers already prevent draws, so | 232 // triple-buffered. Single-buffered layers already prevent draws, so |
| 226 // can block too for simplicity. | 233 // can block too for simplicity. |
| 227 return DrawsContent(); | 234 return DrawsContent(); |
| 228 } | 235 } |
| 229 | 236 |
| 230 bool TextureLayer::CanClipSelf() const { | 237 bool TextureLayer::CanClipSelf() const { |
| 231 return true; | 238 return true; |
| 232 } | 239 } |
| 233 | 240 |
| 234 } // namespace cc | 241 } // namespace cc |
| OLD | NEW |