| 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 impl_may_draw_client_data_(false), | 36 content_committed_(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 } |
| 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 ClearTexture(); | 52 if (uses_mailbox_) |
| 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_) { | |
| 62 SetTextureMailbox(TextureMailbox()); | 53 SetTextureMailbox(TextureMailbox()); |
| 63 } else { | 54 else |
| 64 texture_id_ = 0; | 55 SetTextureId(0); |
| 65 SetNeedsCommit(); | |
| 66 } | |
| 67 } | 56 } |
| 68 | 57 |
| 69 scoped_ptr<LayerImpl> TextureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 58 scoped_ptr<LayerImpl> TextureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 70 return TextureLayerImpl::Create(tree_impl, id(), uses_mailbox_). | 59 return TextureLayerImpl::Create(tree_impl, id(), uses_mailbox_). |
| 71 PassAs<LayerImpl>(); | 60 PassAs<LayerImpl>(); |
| 72 } | 61 } |
| 73 | 62 |
| 74 void TextureLayer::SetFlipped(bool flipped) { | 63 void TextureLayer::SetFlipped(bool flipped) { |
| 75 if (flipped_ == flipped) | 64 if (flipped_ == flipped) |
| 76 return; | 65 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 SetNeedsCommit(); | 109 SetNeedsCommit(); |
| 121 } | 110 } |
| 122 | 111 |
| 123 void TextureLayer::SetRateLimitContext(bool rate_limit) { | 112 void TextureLayer::SetRateLimitContext(bool rate_limit) { |
| 124 if (!rate_limit && rate_limit_context_ && client_ && layer_tree_host()) | 113 if (!rate_limit && rate_limit_context_ && client_ && layer_tree_host()) |
| 125 layer_tree_host()->StopRateLimiter(client_->Context3d()); | 114 layer_tree_host()->StopRateLimiter(client_->Context3d()); |
| 126 | 115 |
| 127 rate_limit_context_ = rate_limit; | 116 rate_limit_context_ = rate_limit; |
| 128 } | 117 } |
| 129 | 118 |
| 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 |
| 130 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) { | 129 void TextureLayer::SetTextureMailbox(const TextureMailbox& mailbox) { |
| 131 DCHECK(uses_mailbox_); | 130 DCHECK(uses_mailbox_); |
| 132 DCHECK(!mailbox.IsValid() || !holder_ref_ || | 131 DCHECK(!mailbox.IsValid() || !holder_ref_ || |
| 133 !mailbox.Equals(holder_ref_->holder()->mailbox())); | 132 !mailbox.Equals(holder_ref_->holder()->mailbox())); |
| 134 // If we never commited the mailbox, we need to release it here. | 133 // If we never commited the mailbox, we need to release it here. |
| 135 if (mailbox.IsValid()) | 134 if (mailbox.IsValid()) |
| 136 holder_ref_ = MailboxHolder::Create(mailbox); | 135 holder_ref_ = MailboxHolder::Create(mailbox); |
| 137 else | 136 else |
| 138 holder_ref_.reset(); | 137 holder_ref_.reset(); |
| 139 needs_set_mailbox_ = true; | 138 needs_set_mailbox_ = true; |
| 140 SetNeedsCommit(); | 139 SetNeedsCommit(); |
| 141 } | 140 } |
| 142 | 141 |
| 142 void TextureLayer::WillModifyTexture() { |
| 143 if (layer_tree_host() && (DrawsContent() || content_committed_)) { |
| 144 layer_tree_host()->AcquireLayerTextures(); |
| 145 content_committed_ = false; |
| 146 } |
| 147 } |
| 148 |
| 143 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { | 149 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { |
| 144 Layer::SetNeedsDisplayRect(dirty_rect); | 150 Layer::SetNeedsDisplayRect(dirty_rect); |
| 145 | 151 |
| 146 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) | 152 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) |
| 147 layer_tree_host()->StartRateLimiter(client_->Context3d()); | 153 layer_tree_host()->StartRateLimiter(client_->Context3d()); |
| 148 } | 154 } |
| 149 | 155 |
| 150 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 156 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 151 if (layer_tree_host() == host) { | 157 if (layer_tree_host() == host) { |
| 152 Layer::SetLayerTreeHost(host); | 158 Layer::SetLayerTreeHost(host); |
| 153 return; | 159 return; |
| 154 } | 160 } |
| 155 | 161 |
| 156 if (layer_tree_host()) { | 162 if (layer_tree_host()) { |
| 157 if (impl_may_draw_client_data_) { | 163 if (texture_id_) |
| 158 layer_tree_host()->AcquireLayerTextures(); | 164 layer_tree_host()->AcquireLayerTextures(); |
| 159 impl_may_draw_client_data_ = false; | |
| 160 } | |
| 161 if (rate_limit_context_ && client_) | 165 if (rate_limit_context_ && client_) |
| 162 layer_tree_host()->StopRateLimiter(client_->Context3d()); | 166 layer_tree_host()->StopRateLimiter(client_->Context3d()); |
| 163 } | 167 } |
| 164 // If we're removed from the tree, the TextureLayerImpl will be destroyed, and | 168 // If we're removed from the tree, the TextureLayerImpl will be destroyed, and |
| 165 // we will need to set the mailbox again on a new TextureLayerImpl the next | 169 // we will need to set the mailbox again on a new TextureLayerImpl the next |
| 166 // time we push. | 170 // time we push. |
| 167 if (!host && uses_mailbox_ && holder_ref_) | 171 if (!host && uses_mailbox_ && holder_ref_) |
| 168 needs_set_mailbox_ = true; | 172 needs_set_mailbox_ = true; |
| 169 Layer::SetLayerTreeHost(host); | 173 Layer::SetLayerTreeHost(host); |
| 170 } | 174 } |
| 171 | 175 |
| 172 bool TextureLayer::DrawsContent() const { | 176 bool TextureLayer::DrawsContent() const { |
| 173 return (client_ || texture_id_ || holder_ref_) && Layer::DrawsContent(); | 177 return (client_ || texture_id_ || holder_ref_) && Layer::DrawsContent(); |
| 174 } | 178 } |
| 175 | 179 |
| 176 bool TextureLayer::DrawsClientData() const { | |
| 177 if (!Layer::DrawsContent() || !client_) | |
| 178 return false; | |
| 179 return texture_id_ || holder_ref_; | |
| 180 } | |
| 181 | |
| 182 bool TextureLayer::Update(ResourceUpdateQueue* queue, | 180 bool TextureLayer::Update(ResourceUpdateQueue* queue, |
| 183 const OcclusionTracker* occlusion) { | 181 const OcclusionTracker* occlusion) { |
| 184 bool updated = false; | 182 bool updated = false; |
| 185 if (client_) { | 183 if (client_) { |
| 186 if (uses_mailbox_) { | 184 if (uses_mailbox_) { |
| 187 TextureMailbox mailbox; | 185 TextureMailbox mailbox; |
| 188 if (client_->PrepareTextureMailbox( | 186 if (client_->PrepareTextureMailbox( |
| 189 &mailbox, layer_tree_host()->UsingSharedMemoryResources())) { | 187 &mailbox, layer_tree_host()->UsingSharedMemoryResources())) { |
| 190 SetTextureMailbox(mailbox); | 188 SetTextureMailbox(mailbox); |
| 191 updated = true; | 189 updated = true; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 MailboxHolder* holder = holder_ref_->holder(); | 222 MailboxHolder* holder = holder_ref_->holder(); |
| 225 TextureMailbox::ReleaseCallback callback = | 223 TextureMailbox::ReleaseCallback callback = |
| 226 holder->GetCallbackForImplThread(); | 224 holder->GetCallbackForImplThread(); |
| 227 texture_mailbox = holder->mailbox().CopyWithNewCallback(callback); | 225 texture_mailbox = holder->mailbox().CopyWithNewCallback(callback); |
| 228 } | 226 } |
| 229 texture_layer->SetTextureMailbox(texture_mailbox); | 227 texture_layer->SetTextureMailbox(texture_mailbox); |
| 230 needs_set_mailbox_ = false; | 228 needs_set_mailbox_ = false; |
| 231 } else { | 229 } else { |
| 232 texture_layer->set_texture_id(texture_id_); | 230 texture_layer->set_texture_id(texture_id_); |
| 233 } | 231 } |
| 234 impl_may_draw_client_data_ = DrawsClientData(); | 232 content_committed_ = DrawsContent(); |
| 235 } | 233 } |
| 236 | 234 |
| 237 bool TextureLayer::BlocksPendingCommit() const { | 235 bool TextureLayer::BlocksPendingCommit() const { |
| 238 // Double-buffered texture layers need to be blocked until they can be made | 236 // Double-buffered texture layers need to be blocked until they can be made |
| 239 // triple-buffered. Single-buffered layers already prevent draws, so | 237 // triple-buffered. Single-buffered layers already prevent draws, so |
| 240 // can block too for simplicity. | 238 // can block too for simplicity. |
| 241 return DrawsContent(); | 239 return DrawsContent(); |
| 242 } | 240 } |
| 243 | 241 |
| 244 bool TextureLayer::CanClipSelf() const { | 242 bool TextureLayer::CanClipSelf() const { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 } | 305 } |
| 308 | 306 |
| 309 void TextureLayer::MailboxHolder::ReturnAndReleaseOnImplThread( | 307 void TextureLayer::MailboxHolder::ReturnAndReleaseOnImplThread( |
| 310 unsigned sync_point, bool is_lost) { | 308 unsigned sync_point, bool is_lost) { |
| 311 message_loop_->PostTask(FROM_HERE, base::Bind( | 309 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 312 &MailboxHolder::ReturnAndReleaseOnMainThread, | 310 &MailboxHolder::ReturnAndReleaseOnMainThread, |
| 313 this, sync_point, is_lost)); | 311 this, sync_point, is_lost)); |
| 314 } | 312 } |
| 315 | 313 |
| 316 } // namespace cc | 314 } // namespace cc |
| OLD | NEW |