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