| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 bool requires_commit, | 121 bool requires_commit, |
| 122 bool allow_mailbox_reuse) { | 122 bool allow_mailbox_reuse) { |
| 123 DCHECK(!mailbox.IsValid() || !holder_ref_ || | 123 DCHECK(!mailbox.IsValid() || !holder_ref_ || |
| 124 !mailbox.Equals(holder_ref_->holder()->mailbox()) || | 124 !mailbox.Equals(holder_ref_->holder()->mailbox()) || |
| 125 allow_mailbox_reuse); | 125 allow_mailbox_reuse); |
| 126 DCHECK_EQ(mailbox.IsValid(), !!release_callback); | 126 DCHECK_EQ(mailbox.IsValid(), !!release_callback); |
| 127 | 127 |
| 128 // If we never commited the mailbox, we need to release it here. | 128 // If we never commited the mailbox, we need to release it here. |
| 129 if (mailbox.IsValid()) { | 129 if (mailbox.IsValid()) { |
| 130 holder_ref_ = | 130 holder_ref_ = |
| 131 TextureMailboxHolder::Create(mailbox, release_callback.Pass()); | 131 TextureMailboxHolder::Create(mailbox, std::move(release_callback)); |
| 132 } else { | 132 } else { |
| 133 holder_ref_ = nullptr; | 133 holder_ref_ = nullptr; |
| 134 } | 134 } |
| 135 needs_set_mailbox_ = true; | 135 needs_set_mailbox_ = true; |
| 136 // If we are within a commit, no need to do it again immediately after. | 136 // If we are within a commit, no need to do it again immediately after. |
| 137 if (requires_commit) | 137 if (requires_commit) |
| 138 SetNeedsCommit(); | 138 SetNeedsCommit(); |
| 139 else | 139 else |
| 140 SetNeedsPushProperties(); | 140 SetNeedsPushProperties(); |
| 141 | 141 |
| 142 UpdateDrawsContent(HasDrawableContent()); | 142 UpdateDrawsContent(HasDrawableContent()); |
| 143 // The active frame needs to be replaced and the mailbox returned before the | 143 // The active frame needs to be replaced and the mailbox returned before the |
| 144 // commit is called complete. | 144 // commit is called complete. |
| 145 SetNextCommitWaitsForActivation(); | 145 SetNextCommitWaitsForActivation(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void TextureLayer::SetTextureMailbox( | 148 void TextureLayer::SetTextureMailbox( |
| 149 const TextureMailbox& mailbox, | 149 const TextureMailbox& mailbox, |
| 150 scoped_ptr<SingleReleaseCallback> release_callback) { | 150 scoped_ptr<SingleReleaseCallback> release_callback) { |
| 151 bool requires_commit = true; | 151 bool requires_commit = true; |
| 152 bool allow_mailbox_reuse = false; | 152 bool allow_mailbox_reuse = false; |
| 153 SetTextureMailboxInternal( | 153 SetTextureMailboxInternal(mailbox, std::move(release_callback), |
| 154 mailbox, release_callback.Pass(), requires_commit, allow_mailbox_reuse); | 154 requires_commit, allow_mailbox_reuse); |
| 155 } | 155 } |
| 156 | 156 |
| 157 static void IgnoreReleaseCallback(const gpu::SyncToken& sync_token, bool lost) { | 157 static void IgnoreReleaseCallback(const gpu::SyncToken& sync_token, bool lost) { |
| 158 } | 158 } |
| 159 | 159 |
| 160 void TextureLayer::SetTextureMailboxWithoutReleaseCallback( | 160 void TextureLayer::SetTextureMailboxWithoutReleaseCallback( |
| 161 const TextureMailbox& mailbox) { | 161 const TextureMailbox& mailbox) { |
| 162 // We allow reuse of the mailbox if there is a new sync point signalling new | 162 // We allow reuse of the mailbox if there is a new sync point signalling new |
| 163 // content, and the release callback goes nowhere since we'll be calling it | 163 // content, and the release callback goes nowhere since we'll be calling it |
| 164 // multiple times for the same mailbox. | 164 // multiple times for the same mailbox. |
| 165 DCHECK(!mailbox.IsValid() || !holder_ref_ || | 165 DCHECK(!mailbox.IsValid() || !holder_ref_ || |
| 166 !mailbox.Equals(holder_ref_->holder()->mailbox()) || | 166 !mailbox.Equals(holder_ref_->holder()->mailbox()) || |
| 167 mailbox.sync_token() != holder_ref_->holder()->mailbox().sync_token()); | 167 mailbox.sync_token() != holder_ref_->holder()->mailbox().sync_token()); |
| 168 scoped_ptr<SingleReleaseCallback> release; | 168 scoped_ptr<SingleReleaseCallback> release; |
| 169 bool requires_commit = true; | 169 bool requires_commit = true; |
| 170 bool allow_mailbox_reuse = true; | 170 bool allow_mailbox_reuse = true; |
| 171 if (mailbox.IsValid()) | 171 if (mailbox.IsValid()) |
| 172 release = SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback)); | 172 release = SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback)); |
| 173 SetTextureMailboxInternal( | 173 SetTextureMailboxInternal(mailbox, std::move(release), requires_commit, |
| 174 mailbox, release.Pass(), requires_commit, allow_mailbox_reuse); | 174 allow_mailbox_reuse); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void TextureLayer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) { | 177 void TextureLayer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) { |
| 178 Layer::SetNeedsDisplayRect(dirty_rect); | 178 Layer::SetNeedsDisplayRect(dirty_rect); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 181 void TextureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 182 if (layer_tree_host() == host) { | 182 if (layer_tree_host() == host) { |
| 183 Layer::SetLayerTreeHost(host); | 183 Layer::SetLayerTreeHost(host); |
| 184 return; | 184 return; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 205 if (client_) { | 205 if (client_) { |
| 206 TextureMailbox mailbox; | 206 TextureMailbox mailbox; |
| 207 scoped_ptr<SingleReleaseCallback> release_callback; | 207 scoped_ptr<SingleReleaseCallback> release_callback; |
| 208 if (client_->PrepareTextureMailbox( | 208 if (client_->PrepareTextureMailbox( |
| 209 &mailbox, | 209 &mailbox, |
| 210 &release_callback, | 210 &release_callback, |
| 211 layer_tree_host()->UsingSharedMemoryResources())) { | 211 layer_tree_host()->UsingSharedMemoryResources())) { |
| 212 // Already within a commit, no need to do another one immediately. | 212 // Already within a commit, no need to do another one immediately. |
| 213 bool requires_commit = false; | 213 bool requires_commit = false; |
| 214 bool allow_mailbox_reuse = false; | 214 bool allow_mailbox_reuse = false; |
| 215 SetTextureMailboxInternal(mailbox, | 215 SetTextureMailboxInternal(mailbox, std::move(release_callback), |
| 216 release_callback.Pass(), | 216 requires_commit, allow_mailbox_reuse); |
| 217 requires_commit, | |
| 218 allow_mailbox_reuse); | |
| 219 updated = true; | 217 updated = true; |
| 220 } | 218 } |
| 221 } | 219 } |
| 222 | 220 |
| 223 // SetTextureMailbox could be called externally and the same mailbox used for | 221 // SetTextureMailbox could be called externally and the same mailbox used for |
| 224 // different textures. Such callers notify this layer that the texture has | 222 // different textures. Such callers notify this layer that the texture has |
| 225 // changed by calling SetNeedsDisplay, so check for that here. | 223 // changed by calling SetNeedsDisplay, so check for that here. |
| 226 return updated || !update_rect_.IsEmpty(); | 224 return updated || !update_rect_.IsEmpty(); |
| 227 } | 225 } |
| 228 | 226 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 239 texture_layer->SetBlendBackgroundColor(blend_background_color_); | 237 texture_layer->SetBlendBackgroundColor(blend_background_color_); |
| 240 if (needs_set_mailbox_) { | 238 if (needs_set_mailbox_) { |
| 241 TextureMailbox texture_mailbox; | 239 TextureMailbox texture_mailbox; |
| 242 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl; | 240 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl; |
| 243 if (holder_ref_) { | 241 if (holder_ref_) { |
| 244 TextureMailboxHolder* holder = holder_ref_->holder(); | 242 TextureMailboxHolder* holder = holder_ref_->holder(); |
| 245 texture_mailbox = holder->mailbox(); | 243 texture_mailbox = holder->mailbox(); |
| 246 release_callback_impl = holder->GetCallbackForImplThread(); | 244 release_callback_impl = holder->GetCallbackForImplThread(); |
| 247 } | 245 } |
| 248 texture_layer->SetTextureMailbox(texture_mailbox, | 246 texture_layer->SetTextureMailbox(texture_mailbox, |
| 249 release_callback_impl.Pass()); | 247 std::move(release_callback_impl)); |
| 250 needs_set_mailbox_ = false; | 248 needs_set_mailbox_ = false; |
| 251 } | 249 } |
| 252 } | 250 } |
| 253 | 251 |
| 254 TextureLayer::TextureMailboxHolder::MainThreadReference::MainThreadReference( | 252 TextureLayer::TextureMailboxHolder::MainThreadReference::MainThreadReference( |
| 255 TextureMailboxHolder* holder) | 253 TextureMailboxHolder* holder) |
| 256 : holder_(holder) { | 254 : holder_(holder) { |
| 257 holder_->InternalAddRef(); | 255 holder_->InternalAddRef(); |
| 258 } | 256 } |
| 259 | 257 |
| 260 TextureLayer::TextureMailboxHolder::MainThreadReference:: | 258 TextureLayer::TextureMailboxHolder::MainThreadReference:: |
| 261 ~MainThreadReference() { | 259 ~MainThreadReference() { |
| 262 holder_->InternalRelease(); | 260 holder_->InternalRelease(); |
| 263 } | 261 } |
| 264 | 262 |
| 265 TextureLayer::TextureMailboxHolder::TextureMailboxHolder( | 263 TextureLayer::TextureMailboxHolder::TextureMailboxHolder( |
| 266 const TextureMailbox& mailbox, | 264 const TextureMailbox& mailbox, |
| 267 scoped_ptr<SingleReleaseCallback> release_callback) | 265 scoped_ptr<SingleReleaseCallback> release_callback) |
| 268 : internal_references_(0), | 266 : internal_references_(0), |
| 269 mailbox_(mailbox), | 267 mailbox_(mailbox), |
| 270 release_callback_(release_callback.Pass()), | 268 release_callback_(std::move(release_callback)), |
| 271 sync_token_(mailbox.sync_token()), | 269 sync_token_(mailbox.sync_token()), |
| 272 is_lost_(false) {} | 270 is_lost_(false) {} |
| 273 | 271 |
| 274 TextureLayer::TextureMailboxHolder::~TextureMailboxHolder() { | 272 TextureLayer::TextureMailboxHolder::~TextureMailboxHolder() { |
| 275 DCHECK_EQ(0u, internal_references_); | 273 DCHECK_EQ(0u, internal_references_); |
| 276 } | 274 } |
| 277 | 275 |
| 278 scoped_ptr<TextureLayer::TextureMailboxHolder::MainThreadReference> | 276 scoped_ptr<TextureLayer::TextureMailboxHolder::MainThreadReference> |
| 279 TextureLayer::TextureMailboxHolder::Create( | 277 TextureLayer::TextureMailboxHolder::Create( |
| 280 const TextureMailbox& mailbox, | 278 const TextureMailbox& mailbox, |
| 281 scoped_ptr<SingleReleaseCallback> release_callback) { | 279 scoped_ptr<SingleReleaseCallback> release_callback) { |
| 282 return make_scoped_ptr(new MainThreadReference( | 280 return make_scoped_ptr(new MainThreadReference( |
| 283 new TextureMailboxHolder(mailbox, release_callback.Pass()))); | 281 new TextureMailboxHolder(mailbox, std::move(release_callback)))); |
| 284 } | 282 } |
| 285 | 283 |
| 286 void TextureLayer::TextureMailboxHolder::Return( | 284 void TextureLayer::TextureMailboxHolder::Return( |
| 287 const gpu::SyncToken& sync_token, | 285 const gpu::SyncToken& sync_token, |
| 288 bool is_lost) { | 286 bool is_lost) { |
| 289 base::AutoLock lock(arguments_lock_); | 287 base::AutoLock lock(arguments_lock_); |
| 290 sync_token_ = sync_token; | 288 sync_token_ = sync_token; |
| 291 is_lost_ = is_lost; | 289 is_lost_ = is_lost; |
| 292 } | 290 } |
| 293 | 291 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 317 void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread( | 315 void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread( |
| 318 const gpu::SyncToken& sync_token, | 316 const gpu::SyncToken& sync_token, |
| 319 bool is_lost, | 317 bool is_lost, |
| 320 BlockingTaskRunner* main_thread_task_runner) { | 318 BlockingTaskRunner* main_thread_task_runner) { |
| 321 Return(sync_token, is_lost); | 319 Return(sync_token, is_lost); |
| 322 main_thread_task_runner->PostTask( | 320 main_thread_task_runner->PostTask( |
| 323 FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this)); | 321 FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this)); |
| 324 } | 322 } |
| 325 | 323 |
| 326 } // namespace cc | 324 } // namespace cc |
| OLD | NEW |