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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "cc/layers/texture_layer_client.h" | 10 #include "cc/layers/texture_layer_client.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox) | 26 TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox) |
| 27 : Layer(), | 27 : Layer(), |
| 28 client_(client), | 28 client_(client), |
| 29 uses_mailbox_(uses_mailbox), | 29 uses_mailbox_(uses_mailbox), |
| 30 flipped_(true), | 30 flipped_(true), |
| 31 uv_top_left_(0.f, 0.f), | 31 uv_top_left_(0.f, 0.f), |
| 32 uv_bottom_right_(1.f, 1.f), | 32 uv_bottom_right_(1.f, 1.f), |
| 33 premultiplied_alpha_(true), | 33 premultiplied_alpha_(true), |
| 34 blend_background_color_(false), | 34 blend_background_color_(false), |
| 35 rate_limit_context_(false), | 35 rate_limit_context_(false), |
| 36 content_committed_(false), | 36 impl_may_draw_client_data_(false), |
| 37 texture_id_(0), | 37 texture_id_(0), |
| 38 needs_set_mailbox_(false) { | 38 needs_set_mailbox_(false) { |
| 39 vertex_opacity_[0] = 1.0f; | 39 vertex_opacity_[0] = 1.0f; |
| 40 vertex_opacity_[1] = 1.0f; | 40 vertex_opacity_[1] = 1.0f; |
| 41 vertex_opacity_[2] = 1.0f; | 41 vertex_opacity_[2] = 1.0f; |
| 42 vertex_opacity_[3] = 1.0f; | 42 vertex_opacity_[3] = 1.0f; |
| 43 } | 43 } |
| 44 | 44 |
| 45 TextureLayer::~TextureLayer() { | 45 TextureLayer::~TextureLayer() { |
| 46 } | 46 } |
|
danakj
2013/07/15 23:25:05
Should we ClearClient() in here? Or DCHECK that it
piman
2013/07/16 00:03:12
We don't need to, we know we've been removed from
danakj
2013/07/16 00:03:53
Ah, okay cool thanks.
| |
| 47 | 47 |
| 48 void TextureLayer::ClearClient() { | 48 void TextureLayer::ClearClient() { |
| 49 if (rate_limit_context_ && client_ && layer_tree_host()) | 49 if (rate_limit_context_ && client_ && layer_tree_host()) |
| 50 layer_tree_host()->StopRateLimiter(client_->Context3d()); | 50 layer_tree_host()->StopRateLimiter(client_->Context3d()); |
| 51 client_ = NULL; | 51 client_ = NULL; |
| 52 if (uses_mailbox_) | 52 ClearTexture(); |
| 53 } | |
| 54 | |
| 55 void TextureLayer::ClearTexture() { | |
| 56 if (impl_may_draw_client_data_) { | |
| 57 DCHECK(layer_tree_host()); | |
| 58 layer_tree_host()->AcquireLayerTextures(); | |
| 59 impl_may_draw_client_data_ = false; | |
| 60 } | |
| 61 if (uses_mailbox_) { | |
| 53 SetTextureMailbox(TextureMailbox()); | 62 SetTextureMailbox(TextureMailbox()); |
| 54 else | 63 } else { |
| 55 SetTextureId(0); | 64 texture_id_ = 0; |
| 65 SetNeedsCommit(); | |
| 66 } | |
| 56 } | 67 } |
| 57 | 68 |
| 58 scoped_ptr<LayerImpl> TextureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 69 scoped_ptr<LayerImpl> TextureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 59 return TextureLayerImpl::Create(tree_impl, id(), uses_mailbox_). | 70 return TextureLayerImpl::Create(tree_impl, id(), uses_mailbox_). |
| 60 PassAs<LayerImpl>(); | 71 PassAs<LayerImpl>(); |
| 61 } | 72 } |
| 62 | 73 |
| 63 void TextureLayer::SetFlipped(bool flipped) { | 74 void TextureLayer::SetFlipped(bool flipped) { |
| 64 if (flipped_ == flipped) | 75 if (flipped_ == flipped) |
| 65 return; | 76 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 SetNeedsCommit(); | 120 SetNeedsCommit(); |
| 110 } | 121 } |
| 111 | 122 |
| 112 void TextureLayer::SetRateLimitContext(bool rate_limit) { | 123 void TextureLayer::SetRateLimitContext(bool rate_limit) { |
| 113 if (!rate_limit && rate_limit_context_ && client_ && layer_tree_host()) | 124 if (!rate_limit && rate_limit_context_ && client_ && layer_tree_host()) |
| 114 layer_tree_host()->StopRateLimiter(client_->Context3d()); | 125 layer_tree_host()->StopRateLimiter(client_->Context3d()); |
| 115 | 126 |
| 116 rate_limit_context_ = rate_limit; | 127 rate_limit_context_ = rate_limit; |
| 117 } | 128 } |
| 118 | 129 |
| 119 void TextureLayer::SetTextureId(unsigned id) { | |
| 120 DCHECK(!uses_mailbox_); | |
| 121 if (texture_id_ == id) | |
| 122 return; | |
| 123 if (texture_id_ && layer_tree_host()) | |
| 124 layer_tree_host()->AcquireLayerTextures(); | |
| 125 texture_id_ = id; | |
| 126 SetNeedsCommit(); | |
| 127 } | |
| 128 | |
| 129 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) { | 130 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) { |
| 130 DCHECK(uses_mailbox_); | 131 DCHECK(uses_mailbox_); |
| 131 DCHECK(!mailbox.IsValid() || !holder_ref_ || | 132 DCHECK(!mailbox.IsValid() || !holder_ref_ || |
| 132 !mailbox.Equals(holder_ref_->holder()->mailbox())); | 133 !mailbox.Equals(holder_ref_->holder()->mailbox())); |
| 133 // If we never commited the mailbox, we need to release it here. | 134 // If we never commited the mailbox, we need to release it here. |
| 134 if (mailbox.IsValid()) | 135 if (mailbox.IsValid()) |
| 135 holder_ref_ = MailboxHolder::Create(mailbox); | 136 holder_ref_ = MailboxHolder::Create(mailbox); |
| 136 else | 137 else |
| 137 holder_ref_.reset(); | 138 holder_ref_.reset(); |
| 138 needs_set_mailbox_ = true; | 139 needs_set_mailbox_ = true; |
| 139 SetNeedsCommit(); | 140 SetNeedsCommit(); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void TextureLayer::WillModifyTexture() { | |
| 143 if (layer_tree_host() && (DrawsContent() || content_committed_)) { | |
| 144 layer_tree_host()->AcquireLayerTextures(); | |
| 145 content_committed_ = false; | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { | 143 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { |
| 150 Layer::SetNeedsDisplayRect(dirty_rect); | 144 Layer::SetNeedsDisplayRect(dirty_rect); |
| 151 | 145 |
| 152 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) | 146 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) |
| 153 layer_tree_host()->StartRateLimiter(client_->Context3d()); | 147 layer_tree_host()->StartRateLimiter(client_->Context3d()); |
| 154 } | 148 } |
| 155 | 149 |
| 156 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 150 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 157 if (layer_tree_host() == host) { | 151 if (layer_tree_host() == host) { |
| 158 Layer::SetLayerTreeHost(host); | 152 Layer::SetLayerTreeHost(host); |
| 159 return; | 153 return; |
| 160 } | 154 } |
| 161 | 155 |
| 162 if (layer_tree_host()) { | 156 if (layer_tree_host()) { |
| 163 if (texture_id_) | 157 if (impl_may_draw_client_data_) { |
| 164 layer_tree_host()->AcquireLayerTextures(); | 158 layer_tree_host()->AcquireLayerTextures(); |
| 159 impl_may_draw_client_data_ = false; | |
| 160 } | |
| 165 if (rate_limit_context_ && client_) | 161 if (rate_limit_context_ && client_) |
| 166 layer_tree_host()->StopRateLimiter(client_->Context3d()); | 162 layer_tree_host()->StopRateLimiter(client_->Context3d()); |
| 167 } | 163 } |
| 168 // If we're removed from the tree, the TextureLayerImpl will be destroyed, and | 164 // If we're removed from the tree, the TextureLayerImpl will be destroyed, and |
| 169 // we will need to set the mailbox again on a new TextureLayerImpl the next | 165 // we will need to set the mailbox again on a new TextureLayerImpl the next |
| 170 // time we push. | 166 // time we push. |
| 171 if (!host && uses_mailbox_ && holder_ref_) | 167 if (!host && uses_mailbox_ && holder_ref_) |
| 172 needs_set_mailbox_ = true; | 168 needs_set_mailbox_ = true; |
| 173 Layer::SetLayerTreeHost(host); | 169 Layer::SetLayerTreeHost(host); |
| 174 } | 170 } |
| 175 | 171 |
| 176 bool TextureLayer::DrawsContent() const { | 172 bool TextureLayer::DrawsContent() const { |
| 177 return (client_ || texture_id_ || holder_ref_) && Layer::DrawsContent(); | 173 return (client_ || texture_id_ || holder_ref_) && Layer::DrawsContent(); |
| 178 } | 174 } |
| 179 | 175 |
| 176 bool TextureLayer::DrawsClientData() const { | |
| 177 if (!Layer::DrawsContent() || !client_) | |
| 178 return false; | |
| 179 return texture_id_ || holder_ref_; | |
| 180 } | |
| 181 | |
| 180 bool TextureLayer::Update(ResourceUpdateQueue* queue, | 182 bool TextureLayer::Update(ResourceUpdateQueue* queue, |
| 181 const OcclusionTracker* occlusion) { | 183 const OcclusionTracker* occlusion) { |
| 182 bool updated = false; | 184 bool updated = false; |
| 183 if (client_) { | 185 if (client_) { |
| 184 if (uses_mailbox_) { | 186 if (uses_mailbox_) { |
| 185 TextureMailbox mailbox; | 187 TextureMailbox mailbox; |
| 186 if (client_->PrepareTextureMailbox( | 188 if (client_->PrepareTextureMailbox( |
| 187 &mailbox, layer_tree_host()->UsingSharedMemoryResources())) { | 189 &mailbox, layer_tree_host()->UsingSharedMemoryResources())) { |
| 188 SetTextureMailbox(mailbox); | 190 SetTextureMailbox(mailbox); |
| 189 updated = true; | 191 updated = true; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 MailboxHolder* holder = holder_ref_->holder(); | 224 MailboxHolder* holder = holder_ref_->holder(); |
| 223 TextureMailbox::ReleaseCallback callback = | 225 TextureMailbox::ReleaseCallback callback = |
| 224 holder->GetCallbackForImplThread(); | 226 holder->GetCallbackForImplThread(); |
| 225 texture_mailbox = holder->mailbox().CopyWithNewCallback(callback); | 227 texture_mailbox = holder->mailbox().CopyWithNewCallback(callback); |
| 226 } | 228 } |
| 227 texture_layer->SetTextureMailbox(texture_mailbox); | 229 texture_layer->SetTextureMailbox(texture_mailbox); |
| 228 needs_set_mailbox_ = false; | 230 needs_set_mailbox_ = false; |
| 229 } else { | 231 } else { |
| 230 texture_layer->set_texture_id(texture_id_); | 232 texture_layer->set_texture_id(texture_id_); |
| 231 } | 233 } |
| 232 content_committed_ = DrawsContent(); | 234 impl_may_draw_client_data_ = DrawsClientData(); |
| 233 } | 235 } |
| 234 | 236 |
| 235 bool TextureLayer::BlocksPendingCommit() const { | 237 bool TextureLayer::BlocksPendingCommit() const { |
| 236 // Double-buffered texture layers need to be blocked until they can be made | 238 // Double-buffered texture layers need to be blocked until they can be made |
| 237 // triple-buffered. Single-buffered layers already prevent draws, so | 239 // triple-buffered. Single-buffered layers already prevent draws, so |
| 238 // can block too for simplicity. | 240 // can block too for simplicity. |
| 239 return DrawsContent(); | 241 return DrawsContent(); |
| 240 } | 242 } |
| 241 | 243 |
| 242 bool TextureLayer::CanClipSelf() const { | 244 bool TextureLayer::CanClipSelf() const { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 } | 307 } |
| 306 | 308 |
| 307 void TextureLayer::MailboxHolder::ReturnAndReleaseOnImplThread( | 309 void TextureLayer::MailboxHolder::ReturnAndReleaseOnImplThread( |
| 308 unsigned sync_point, bool is_lost) { | 310 unsigned sync_point, bool is_lost) { |
| 309 message_loop_->PostTask(FROM_HERE, base::Bind( | 311 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 310 &MailboxHolder::ReturnAndReleaseOnMainThread, | 312 &MailboxHolder::ReturnAndReleaseOnMainThread, |
| 311 this, sync_point, is_lost)); | 313 this, sync_point, is_lost)); |
| 312 } | 314 } |
| 313 | 315 |
| 314 } // namespace cc | 316 } // namespace cc |
| OLD | NEW |