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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( |
154 mailbox, release_callback.Pass(), requires_commit, allow_mailbox_reuse); | 154 mailbox, release_callback.Pass(), requires_commit, allow_mailbox_reuse); |
155 } | 155 } |
156 | 156 |
157 static void IgnoreReleaseCallback(uint32 sync_point, bool lost) {} | 157 static void IgnoreReleaseCallback(const gpu::SyncToken& sync_token, bool lost) { |
| 158 } |
158 | 159 |
159 void TextureLayer::SetTextureMailboxWithoutReleaseCallback( | 160 void TextureLayer::SetTextureMailboxWithoutReleaseCallback( |
160 const TextureMailbox& mailbox) { | 161 const TextureMailbox& mailbox) { |
161 // 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 |
162 // 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 |
163 // multiple times for the same mailbox. | 164 // multiple times for the same mailbox. |
164 DCHECK(!mailbox.IsValid() || !holder_ref_ || | 165 DCHECK(!mailbox.IsValid() || !holder_ref_ || |
165 !mailbox.Equals(holder_ref_->holder()->mailbox()) || | 166 !mailbox.Equals(holder_ref_->holder()->mailbox()) || |
166 mailbox.sync_point() != holder_ref_->holder()->mailbox().sync_point()); | 167 mailbox.sync_token() != holder_ref_->holder()->mailbox().sync_token()); |
167 scoped_ptr<SingleReleaseCallback> release; | 168 scoped_ptr<SingleReleaseCallback> release; |
168 bool requires_commit = true; | 169 bool requires_commit = true; |
169 bool allow_mailbox_reuse = true; | 170 bool allow_mailbox_reuse = true; |
170 if (mailbox.IsValid()) | 171 if (mailbox.IsValid()) |
171 release = SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback)); | 172 release = SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback)); |
172 SetTextureMailboxInternal( | 173 SetTextureMailboxInternal( |
173 mailbox, release.Pass(), requires_commit, allow_mailbox_reuse); | 174 mailbox, release.Pass(), requires_commit, allow_mailbox_reuse); |
174 } | 175 } |
175 | 176 |
176 void TextureLayer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) { | 177 void TextureLayer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 ~MainThreadReference() { | 261 ~MainThreadReference() { |
261 holder_->InternalRelease(); | 262 holder_->InternalRelease(); |
262 } | 263 } |
263 | 264 |
264 TextureLayer::TextureMailboxHolder::TextureMailboxHolder( | 265 TextureLayer::TextureMailboxHolder::TextureMailboxHolder( |
265 const TextureMailbox& mailbox, | 266 const TextureMailbox& mailbox, |
266 scoped_ptr<SingleReleaseCallback> release_callback) | 267 scoped_ptr<SingleReleaseCallback> release_callback) |
267 : internal_references_(0), | 268 : internal_references_(0), |
268 mailbox_(mailbox), | 269 mailbox_(mailbox), |
269 release_callback_(release_callback.Pass()), | 270 release_callback_(release_callback.Pass()), |
270 sync_point_(mailbox.sync_point()), | 271 sync_token_(mailbox.sync_token()), |
271 is_lost_(false) { | 272 is_lost_(false) {} |
272 } | |
273 | 273 |
274 TextureLayer::TextureMailboxHolder::~TextureMailboxHolder() { | 274 TextureLayer::TextureMailboxHolder::~TextureMailboxHolder() { |
275 DCHECK_EQ(0u, internal_references_); | 275 DCHECK_EQ(0u, internal_references_); |
276 } | 276 } |
277 | 277 |
278 scoped_ptr<TextureLayer::TextureMailboxHolder::MainThreadReference> | 278 scoped_ptr<TextureLayer::TextureMailboxHolder::MainThreadReference> |
279 TextureLayer::TextureMailboxHolder::Create( | 279 TextureLayer::TextureMailboxHolder::Create( |
280 const TextureMailbox& mailbox, | 280 const TextureMailbox& mailbox, |
281 scoped_ptr<SingleReleaseCallback> release_callback) { | 281 scoped_ptr<SingleReleaseCallback> release_callback) { |
282 return make_scoped_ptr(new MainThreadReference( | 282 return make_scoped_ptr(new MainThreadReference( |
283 new TextureMailboxHolder(mailbox, release_callback.Pass()))); | 283 new TextureMailboxHolder(mailbox, release_callback.Pass()))); |
284 } | 284 } |
285 | 285 |
286 void TextureLayer::TextureMailboxHolder::Return(uint32 sync_point, | 286 void TextureLayer::TextureMailboxHolder::Return( |
287 bool is_lost) { | 287 const gpu::SyncToken& sync_token, |
| 288 bool is_lost) { |
288 base::AutoLock lock(arguments_lock_); | 289 base::AutoLock lock(arguments_lock_); |
289 sync_point_ = sync_point; | 290 sync_token_ = sync_token; |
290 is_lost_ = is_lost; | 291 is_lost_ = is_lost; |
291 } | 292 } |
292 | 293 |
293 scoped_ptr<SingleReleaseCallbackImpl> | 294 scoped_ptr<SingleReleaseCallbackImpl> |
294 TextureLayer::TextureMailboxHolder::GetCallbackForImplThread() { | 295 TextureLayer::TextureMailboxHolder::GetCallbackForImplThread() { |
295 // We can't call GetCallbackForImplThread if we released the main thread | 296 // We can't call GetCallbackForImplThread if we released the main thread |
296 // reference. | 297 // reference. |
297 DCHECK_GT(internal_references_, 0u); | 298 DCHECK_GT(internal_references_, 0u); |
298 InternalAddRef(); | 299 InternalAddRef(); |
299 return SingleReleaseCallbackImpl::Create( | 300 return SingleReleaseCallbackImpl::Create( |
300 base::Bind(&TextureMailboxHolder::ReturnAndReleaseOnImplThread, this)); | 301 base::Bind(&TextureMailboxHolder::ReturnAndReleaseOnImplThread, this)); |
301 } | 302 } |
302 | 303 |
303 void TextureLayer::TextureMailboxHolder::InternalAddRef() { | 304 void TextureLayer::TextureMailboxHolder::InternalAddRef() { |
304 ++internal_references_; | 305 ++internal_references_; |
305 } | 306 } |
306 | 307 |
307 void TextureLayer::TextureMailboxHolder::InternalRelease() { | 308 void TextureLayer::TextureMailboxHolder::InternalRelease() { |
308 DCHECK(main_thread_checker_.CalledOnValidThread()); | 309 DCHECK(main_thread_checker_.CalledOnValidThread()); |
309 if (!--internal_references_) { | 310 if (!--internal_references_) { |
310 release_callback_->Run(sync_point_, is_lost_); | 311 release_callback_->Run(sync_token_, is_lost_); |
311 mailbox_ = TextureMailbox(); | 312 mailbox_ = TextureMailbox(); |
312 release_callback_ = nullptr; | 313 release_callback_ = nullptr; |
313 } | 314 } |
314 } | 315 } |
315 | 316 |
316 void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread( | 317 void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread( |
317 uint32 sync_point, | 318 const gpu::SyncToken& sync_token, |
318 bool is_lost, | 319 bool is_lost, |
319 BlockingTaskRunner* main_thread_task_runner) { | 320 BlockingTaskRunner* main_thread_task_runner) { |
320 Return(sync_point, is_lost); | 321 Return(sync_token, is_lost); |
321 main_thread_task_runner->PostTask( | 322 main_thread_task_runner->PostTask( |
322 FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this)); | 323 FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this)); |
323 } | 324 } |
324 | 325 |
325 } // namespace cc | 326 } // namespace cc |
OLD | NEW |