| 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/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
| 10 #include "cc/layers/texture_layer_client.h" | 10 #include "cc/layers/texture_layer_client.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 DCHECK(uses_mailbox_); | 131 DCHECK(uses_mailbox_); |
| 132 DCHECK(!mailbox.IsValid() || !holder_ref_ || | 132 DCHECK(!mailbox.IsValid() || !holder_ref_ || |
| 133 !mailbox.Equals(holder_ref_->holder()->mailbox())); | 133 !mailbox.Equals(holder_ref_->holder()->mailbox())); |
| 134 // 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. |
| 135 if (mailbox.IsValid()) | 135 if (mailbox.IsValid()) |
| 136 holder_ref_ = MailboxHolder::Create(mailbox); | 136 holder_ref_ = MailboxHolder::Create(mailbox); |
| 137 else | 137 else |
| 138 holder_ref_.reset(); | 138 holder_ref_.reset(); |
| 139 needs_set_mailbox_ = true; | 139 needs_set_mailbox_ = true; |
| 140 SetNeedsCommit(); | 140 SetNeedsCommit(); |
| 141 // The active frame needs to be replaced and the mailbox returned before the | |
| 142 // commit is called complete. | |
| 143 SetNextCommitWaitsForActivation(); | |
| 144 } | 141 } |
| 145 | 142 |
| 146 void TextureLayer::WillModifyTexture() { | 143 void TextureLayer::WillModifyTexture() { |
| 147 if (layer_tree_host() && (DrawsContent() || content_committed_)) { | 144 if (layer_tree_host() && (DrawsContent() || content_committed_)) { |
| 148 layer_tree_host()->AcquireLayerTextures(); | 145 layer_tree_host()->AcquireLayerTextures(); |
| 149 content_committed_ = false; | 146 content_committed_ = false; |
| 150 } | 147 } |
| 151 } | 148 } |
| 152 | 149 |
| 153 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { | 150 void TextureLayer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) { |
| 154 Layer::SetNeedsDisplayRect(dirty_rect); | 151 Layer::SetNeedsDisplayRect(dirty_rect); |
| 155 | 152 |
| 156 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) | 153 if (rate_limit_context_ && client_ && layer_tree_host() && DrawsContent()) |
| 157 layer_tree_host()->StartRateLimiter(client_->Context3d()); | 154 layer_tree_host()->StartRateLimiter(client_->Context3d()); |
| 158 } | 155 } |
| 159 | 156 |
| 160 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 157 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 161 if (layer_tree_host() == host) { | 158 if (layer_tree_host() == host) { |
| 162 Layer::SetLayerTreeHost(host); | 159 Layer::SetLayerTreeHost(host); |
| 163 return; | 160 return; |
| 164 } | 161 } |
| 165 | 162 |
| 166 if (layer_tree_host()) { | 163 if (layer_tree_host()) { |
| 167 if (texture_id_) { | 164 if (texture_id_) |
| 168 layer_tree_host()->AcquireLayerTextures(); | 165 layer_tree_host()->AcquireLayerTextures(); |
| 169 // The texture id needs to be removed from the active tree before the | |
| 170 // commit is called complete. | |
| 171 SetNextCommitWaitsForActivation(); | |
| 172 } | |
| 173 if (rate_limit_context_ && client_) | 166 if (rate_limit_context_ && client_) |
| 174 layer_tree_host()->StopRateLimiter(client_->Context3d()); | 167 layer_tree_host()->StopRateLimiter(client_->Context3d()); |
| 175 } | 168 } |
| 176 // If we're removed from the tree, the TextureLayerImpl will be destroyed, and | 169 // If we're removed from the tree, the TextureLayerImpl will be destroyed, and |
| 177 // we will need to set the mailbox again on a new TextureLayerImpl the next | 170 // we will need to set the mailbox again on a new TextureLayerImpl the next |
| 178 // time we push. | 171 // time we push. |
| 179 if (!host && uses_mailbox_ && holder_ref_) { | 172 if (!host && uses_mailbox_ && holder_ref_) |
| 180 needs_set_mailbox_ = true; | 173 needs_set_mailbox_ = true; |
| 181 // The active frame needs to be replaced and the mailbox returned before the | |
| 182 // commit is called complete. | |
| 183 SetNextCommitWaitsForActivation(); | |
| 184 } | |
| 185 Layer::SetLayerTreeHost(host); | 174 Layer::SetLayerTreeHost(host); |
| 186 } | 175 } |
| 187 | 176 |
| 188 bool TextureLayer::DrawsContent() const { | 177 bool TextureLayer::DrawsContent() const { |
| 189 return (client_ || texture_id_ || holder_ref_) && Layer::DrawsContent(); | 178 return (client_ || texture_id_ || holder_ref_) && Layer::DrawsContent(); |
| 190 } | 179 } |
| 191 | 180 |
| 192 bool TextureLayer::Update(ResourceUpdateQueue* queue, | 181 bool TextureLayer::Update(ResourceUpdateQueue* queue, |
| 193 const OcclusionTracker* occlusion) { | 182 const OcclusionTracker* occlusion) { |
| 194 bool updated = Layer::Update(queue, occlusion); | 183 bool updated = Layer::Update(queue, occlusion); |
| 195 if (client_) { | 184 if (client_) { |
| 196 if (uses_mailbox_) { | 185 if (uses_mailbox_) { |
| 197 TextureMailbox mailbox; | 186 TextureMailbox mailbox; |
| 198 if (client_->PrepareTextureMailbox( | 187 if (client_->PrepareTextureMailbox( |
| 199 &mailbox, layer_tree_host()->UsingSharedMemoryResources())) { | 188 &mailbox, layer_tree_host()->UsingSharedMemoryResources())) { |
| 200 SetTextureMailbox(mailbox); | 189 SetTextureMailbox(mailbox); |
| 201 updated = true; | 190 updated = true; |
| 202 } | 191 } |
| 203 } else { | 192 } else { |
| 204 texture_id_ = client_->PrepareTexture(); | 193 texture_id_ = client_->PrepareTexture(); |
| 205 DCHECK_EQ(!!texture_id_, !!client_->Context3d()); | 194 DCHECK_EQ(!!texture_id_, !!client_->Context3d()); |
| 206 if (client_->Context3d() && | 195 if (client_->Context3d() && |
| 207 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR) | 196 client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR) |
| 208 texture_id_ = 0; | 197 texture_id_ = 0; |
| 209 updated = true; | 198 updated = true; |
| 210 // The texture id needs to be removed from the active tree before the | |
| 211 // commit is called complete. | |
| 212 SetNextCommitWaitsForActivation(); | |
| 213 } | 199 } |
| 214 } | 200 } |
| 215 | 201 |
| 216 // SetTextureMailbox could be called externally and the same mailbox used for | 202 // SetTextureMailbox could be called externally and the same mailbox used for |
| 217 // different textures. Such callers notify this layer that the texture has | 203 // different textures. Such callers notify this layer that the texture has |
| 218 // changed by calling SetNeedsDisplay, so check for that here. | 204 // changed by calling SetNeedsDisplay, so check for that here. |
| 219 return updated || !update_rect_.IsEmpty(); | 205 return updated || !update_rect_.IsEmpty(); |
| 220 } | 206 } |
| 221 | 207 |
| 222 void TextureLayer::PushPropertiesTo(LayerImpl* layer) { | 208 void TextureLayer::PushPropertiesTo(LayerImpl* layer) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 248 Region TextureLayer::VisibleContentOpaqueRegion() const { | 234 Region TextureLayer::VisibleContentOpaqueRegion() const { |
| 249 if (contents_opaque()) | 235 if (contents_opaque()) |
| 250 return visible_content_rect(); | 236 return visible_content_rect(); |
| 251 | 237 |
| 252 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) | 238 if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF)) |
| 253 return visible_content_rect(); | 239 return visible_content_rect(); |
| 254 | 240 |
| 255 return Region(); | 241 return Region(); |
| 256 } | 242 } |
| 257 | 243 |
| 244 bool TextureLayer::BlocksPendingCommit() const { |
| 245 // Double-buffered texture layers need to be blocked until they can be made |
| 246 // triple-buffered. Single-buffered layers already prevent draws, so |
| 247 // can block too for simplicity. |
| 248 return DrawsContent(); |
| 249 } |
| 250 |
| 258 bool TextureLayer::CanClipSelf() const { | 251 bool TextureLayer::CanClipSelf() const { |
| 259 return true; | 252 return true; |
| 260 } | 253 } |
| 261 | 254 |
| 262 TextureLayer::MailboxHolder::MainThreadReference::MainThreadReference( | 255 TextureLayer::MailboxHolder::MainThreadReference::MainThreadReference( |
| 263 MailboxHolder* holder) | 256 MailboxHolder* holder) |
| 264 : holder_(holder) { | 257 : holder_(holder) { |
| 265 holder_->InternalAddRef(); | 258 holder_->InternalAddRef(); |
| 266 } | 259 } |
| 267 | 260 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 308 } |
| 316 | 309 |
| 317 void TextureLayer::MailboxHolder::ReturnAndReleaseOnImplThread( | 310 void TextureLayer::MailboxHolder::ReturnAndReleaseOnImplThread( |
| 318 unsigned sync_point, bool is_lost) { | 311 unsigned sync_point, bool is_lost) { |
| 319 Return(sync_point, is_lost); | 312 Return(sync_point, is_lost); |
| 320 message_loop_->PostTask(FROM_HERE, | 313 message_loop_->PostTask(FROM_HERE, |
| 321 base::Bind(&MailboxHolder::InternalRelease, this)); | 314 base::Bind(&MailboxHolder::InternalRelease, this)); |
| 322 } | 315 } |
| 323 | 316 |
| 324 } // namespace cc | 317 } // namespace cc |
| OLD | NEW |