| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox) | 28 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox) |
| 29 : Layer(), | 29 : Layer(), |
| 30 client_(client), | 30 client_(client), |
| 31 uses_mailbox_(uses_mailbox), | 31 uses_mailbox_(uses_mailbox), |
| 32 flipped_(true), | 32 flipped_(true), |
| 33 uv_top_left_(0.f, 0.f), | 33 uv_top_left_(0.f, 0.f), |
| 34 uv_bottom_right_(1.f, 1.f), | 34 uv_bottom_right_(1.f, 1.f), |
| 35 premultiplied_alpha_(true), | 35 premultiplied_alpha_(true), |
| 36 blend_background_color_(false), | 36 blend_background_color_(false), |
| 37 rate_limit_context_(false), | 37 rate_limit_context_(false), |
| 38 content_committed_(false), | 38 impl_may_draw_client_data_(false), |
| 39 texture_id_(0), | 39 texture_id_(0), |
| 40 needs_set_mailbox_(false) { | 40 needs_set_mailbox_(false) { |
| 41 vertex_opacity_[0] = 1.0f; | 41 vertex_opacity_[0] = 1.0f; |
| 42 vertex_opacity_[1] = 1.0f; | 42 vertex_opacity_[1] = 1.0f; |
| 43 vertex_opacity_[2] = 1.0f; | 43 vertex_opacity_[2] = 1.0f; |
| 44 vertex_opacity_[3] = 1.0f; | 44 vertex_opacity_[3] = 1.0f; |
| 45 } | 45 } |
| 46 | 46 |
| 47 TextureLayer::~TextureLayer() { | 47 TextureLayer::~TextureLayer() { |
| 48 } | 48 } |
| 49 | 49 |
| 50 void TextureLayer::ClearClient() { | 50 void TextureLayer::ClearClient() { |
| 51 if (rate_limit_context_ && client_ && layer_tree_host()) | 51 if (rate_limit_context_ && client_ && layer_tree_host()) |
| 52 layer_tree_host()->StopRateLimiter(); | 52 layer_tree_host()->StopRateLimiter(); |
| 53 client_ = NULL; | 53 client_ = NULL; |
| 54 if (uses_mailbox_) | 54 ClearTexture(); |
| 55 } |
| 56 |
| 57 void TextureLayer::ClearTexture() { |
| 58 if (uses_mailbox_) { |
| 55 SetTextureMailbox(TextureMailbox(), scoped_ptr<SingleReleaseCallback>()); | 59 SetTextureMailbox(TextureMailbox(), scoped_ptr<SingleReleaseCallback>()); |
| 56 else | 60 } else if (texture_id_) { |
| 57 SetTextureId(0); | 61 if (impl_may_draw_client_data_) { |
| 62 DCHECK(layer_tree_host()); |
| 63 layer_tree_host()->AcquireLayerTextures(); |
| 64 impl_may_draw_client_data_ = false; |
| 65 } |
| 66 texture_id_ = 0; |
| 67 SetNeedsCommit(); |
| 68 // The texture id needs to be removed from the active tree before the |
| 69 // commit is called complete. |
| 70 SetNextCommitWaitsForActivation(); |
| 71 } |
| 58 } | 72 } |
| 59 | 73 |
| 60 scoped_ptr<LayerImpl> TextureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 74 scoped_ptr<LayerImpl> TextureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 61 return TextureLayerImpl::Create(tree_impl, id(), uses_mailbox_). | 75 return TextureLayerImpl::Create(tree_impl, id(), uses_mailbox_). |
| 62 PassAs<LayerImpl>(); | 76 PassAs<LayerImpl>(); |
| 63 } | 77 } |
| 64 | 78 |
| 65 void TextureLayer::SetFlipped(bool flipped) { | 79 void TextureLayer::SetFlipped(bool flipped) { |
| 66 if (flipped_ == flipped) | 80 if (flipped_ == flipped) |
| 67 return; | 81 return; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 SetNeedsCommit(); | 126 SetNeedsCommit(); |
| 113 } | 127 } |
| 114 | 128 |
| 115 void TextureLayer::SetRateLimitContext(bool rate_limit) { | 129 void TextureLayer::SetRateLimitContext(bool rate_limit) { |
| 116 if (!rate_limit && rate_limit_context_ && client_ && layer_tree_host()) | 130 if (!rate_limit && rate_limit_context_ && client_ && layer_tree_host()) |
| 117 layer_tree_host()->StopRateLimiter(); | 131 layer_tree_host()->StopRateLimiter(); |
| 118 | 132 |
| 119 rate_limit_context_ = rate_limit; | 133 rate_limit_context_ = rate_limit; |
| 120 } | 134 } |
| 121 | 135 |
| 122 void TextureLayer::SetTextureId(unsigned id) { | |
| 123 DCHECK(!uses_mailbox_); | |
| 124 if (texture_id_ == id) | |
| 125 return; | |
| 126 if (texture_id_ && layer_tree_host()) | |
| 127 layer_tree_host()->AcquireLayerTextures(); | |
| 128 texture_id_ = id; | |
| 129 SetNeedsCommit(); | |
| 130 // The texture id needs to be removed from the active tree before the | |
| 131 // commit is called complete. | |
| 132 SetNextCommitWaitsForActivation(); | |
| 133 } | |
| 134 | |
| 135 void TextureLayer::SetTextureMailboxInternal( | 136 void TextureLayer::SetTextureMailboxInternal( |
| 136 const TextureMailbox& mailbox, | 137 const TextureMailbox& mailbox, |
| 137 scoped_ptr<SingleReleaseCallback> release_callback, | 138 scoped_ptr<SingleReleaseCallback> release_callback, |
| 138 bool requires_commit, | 139 bool requires_commit, |
| 139 bool allow_mailbox_reuse) { | 140 bool allow_mailbox_reuse) { |
| 140 DCHECK(uses_mailbox_); | 141 DCHECK(uses_mailbox_); |
| 141 DCHECK(!mailbox.IsValid() || !holder_ref_ || | 142 DCHECK(!mailbox.IsValid() || !holder_ref_ || |
| 142 !mailbox.Equals(holder_ref_->holder()->mailbox()) || | 143 !mailbox.Equals(holder_ref_->holder()->mailbox()) || |
| 143 allow_mailbox_reuse); | 144 allow_mailbox_reuse); |
| 144 DCHECK_EQ(mailbox.IsValid(), !!release_callback); | 145 DCHECK_EQ(mailbox.IsValid(), !!release_callback); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 mailbox.sync_point() != holder_ref_->holder()->mailbox().sync_point()); | 184 mailbox.sync_point() != holder_ref_->holder()->mailbox().sync_point()); |
| 184 scoped_ptr<SingleReleaseCallback> release; | 185 scoped_ptr<SingleReleaseCallback> release; |
| 185 bool requires_commit = true; | 186 bool requires_commit = true; |
| 186 bool allow_mailbox_reuse = true; | 187 bool allow_mailbox_reuse = true; |
| 187 if (mailbox.IsValid()) | 188 if (mailbox.IsValid()) |
| 188 release = SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback)); | 189 release = SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback)); |
| 189 SetTextureMailboxInternal( | 190 SetTextureMailboxInternal( |
| 190 mailbox, release.Pass(), requires_commit, allow_mailbox_reuse); | 191 mailbox, release.Pass(), requires_commit, allow_mailbox_reuse); |
| 191 } | 192 } |
| 192 | 193 |
| 193 void TextureLayer::WillModifyTexture() { | |
| 194 if (!uses_mailbox_ && layer_tree_host() && (DrawsContent() || | |
| 195 content_committed_)) { | |
| 196 layer_tree_host()->AcquireLayerTextures(); | |
| 197 content_committed_ = false; | |
| 198 } | |
| 199 } | |
| 200 | |
| 201 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { | 194 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { |
| 202 Layer::SetNeedsDisplayRect(dirty_rect); | 195 Layer::SetNeedsDisplayRect(dirty_rect); |
| 203 | 196 |
| 204 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) | 197 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) |
| 205 layer_tree_host()->StartRateLimiter(); | 198 layer_tree_host()->StartRateLimiter(); |
| 206 } | 199 } |
| 207 | 200 |
| 208 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 201 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 209 if (layer_tree_host() == host) { | 202 if (layer_tree_host() == host) { |
| 210 Layer::SetLayerTreeHost(host); | 203 Layer::SetLayerTreeHost(host); |
| 211 return; | 204 return; |
| 212 } | 205 } |
| 213 | 206 |
| 214 if (layer_tree_host()) { | 207 if (layer_tree_host()) { |
| 215 if (texture_id_) { | 208 if (impl_may_draw_client_data_) { |
| 216 layer_tree_host()->AcquireLayerTextures(); | 209 layer_tree_host()->AcquireLayerTextures(); |
| 217 // The texture id needs to be removed from the active tree before the | 210 // The texture id needs to be removed from the active tree before the |
| 218 // commit is called complete. | 211 // commit is called complete. |
| 219 SetNextCommitWaitsForActivation(); | 212 SetNextCommitWaitsForActivation(); |
| 213 impl_may_draw_client_data_ = false; |
| 220 } | 214 } |
| 221 if (rate_limit_context_ && client_) | 215 if (rate_limit_context_ && client_) |
| 222 layer_tree_host()->StopRateLimiter(); | 216 layer_tree_host()->StopRateLimiter(); |
| 223 } | 217 } |
| 224 // If we're removed from the tree, the TextureLayerImpl will be destroyed, and | 218 // If we're removed from the tree, the TextureLayerImpl will be destroyed, and |
| 225 // we will need to set the mailbox again on a new TextureLayerImpl the next | 219 // we will need to set the mailbox again on a new TextureLayerImpl the next |
| 226 // time we push. | 220 // time we push. |
| 227 if (!host && uses_mailbox_ && holder_ref_) { | 221 if (!host && uses_mailbox_ && holder_ref_) { |
| 228 needs_set_mailbox_ = true; | 222 needs_set_mailbox_ = true; |
| 229 // The active frame needs to be replaced and the mailbox returned before the | 223 // The active frame needs to be replaced and the mailbox returned before the |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 scoped_ptr<SingleReleaseCallback> release_callback; | 282 scoped_ptr<SingleReleaseCallback> release_callback; |
| 289 if (holder_ref_) { | 283 if (holder_ref_) { |
| 290 TextureMailboxHolder* holder = holder_ref_->holder(); | 284 TextureMailboxHolder* holder = holder_ref_->holder(); |
| 291 texture_mailbox = holder->mailbox(); | 285 texture_mailbox = holder->mailbox(); |
| 292 release_callback = holder->GetCallbackForImplThread(); | 286 release_callback = holder->GetCallbackForImplThread(); |
| 293 } | 287 } |
| 294 texture_layer->SetTextureMailbox(texture_mailbox, release_callback.Pass()); | 288 texture_layer->SetTextureMailbox(texture_mailbox, release_callback.Pass()); |
| 295 needs_set_mailbox_ = false; | 289 needs_set_mailbox_ = false; |
| 296 } else { | 290 } else { |
| 297 texture_layer->SetTextureId(texture_id_); | 291 texture_layer->SetTextureId(texture_id_); |
| 298 content_committed_ = DrawsContent(); | 292 impl_may_draw_client_data_ = texture_id_ && Layer::DrawsContent(); |
| 299 } | 293 } |
| 300 } | 294 } |
| 301 | 295 |
| 302 Region TextureLayer::VisibleContentOpaqueRegion() const { | 296 Region TextureLayer::VisibleContentOpaqueRegion() const { |
| 303 if (contents_opaque()) | 297 if (contents_opaque()) |
| 304 return visible_content_rect(); | 298 return visible_content_rect(); |
| 305 | 299 |
| 306 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) | 300 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) |
| 307 return visible_content_rect(); | 301 return visible_content_rect(); |
| 308 | 302 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 368 |
| 375 void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread( | 369 void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread( |
| 376 uint32 sync_point, | 370 uint32 sync_point, |
| 377 bool is_lost) { | 371 bool is_lost) { |
| 378 Return(sync_point, is_lost); | 372 Return(sync_point, is_lost); |
| 379 message_loop_->PostTask( | 373 message_loop_->PostTask( |
| 380 FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this)); | 374 FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this)); |
| 381 } | 375 } |
| 382 | 376 |
| 383 } // namespace cc | 377 } // namespace cc |
| OLD | NEW |