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