| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/output/texture_mailbox_deleter.h" | 5 #include "cc/output/texture_mailbox_deleter.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/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "cc/output/context_provider.h" | 11 #include "cc/output/context_provider.h" |
| 12 #include "cc/resources/single_release_callback.h" | 12 #include "cc/resources/single_release_callback.h" |
| 13 #include "gpu/command_buffer/client/gles2_interface.h" | 13 #include "gpu/command_buffer/client/gles2_interface.h" |
| 14 #include "gpu/command_buffer/common/sync_token.h" |
| 14 | 15 |
| 15 namespace cc { | 16 namespace cc { |
| 16 | 17 |
| 17 static void DeleteTextureOnImplThread( | 18 static void DeleteTextureOnImplThread( |
| 18 const scoped_refptr<ContextProvider>& context_provider, | 19 const scoped_refptr<ContextProvider>& context_provider, |
| 19 unsigned texture_id, | 20 unsigned texture_id, |
| 20 uint32 sync_point, | 21 uint32 sync_point, |
| 22 const gpu::SyncToken& sync_token, |
| 21 bool is_lost) { | 23 bool is_lost) { |
| 22 if (sync_point) | 24 if (sync_point || sync_token.HasData()) { |
| 23 context_provider->ContextGL()->WaitSyncPointCHROMIUM(sync_point); | 25 context_provider->ContextGL()->WaitSyncPointCHROMIUM( |
| 26 sync_point, sync_token.GetConstData()); |
| 27 } |
| 24 context_provider->ContextGL()->DeleteTextures(1, &texture_id); | 28 context_provider->ContextGL()->DeleteTextures(1, &texture_id); |
| 25 } | 29 } |
| 26 | 30 |
| 27 static void PostTaskFromMainToImplThread( | 31 static void PostTaskFromMainToImplThread( |
| 28 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | 32 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 29 ReleaseCallback run_impl_callback, | 33 ReleaseCallback run_impl_callback, |
| 30 unsigned sync_point, | 34 unsigned sync_point, |
| 35 const gpu::SyncToken& sync_token, |
| 31 bool is_lost) { | 36 bool is_lost) { |
| 32 // This posts the task to RunDeleteTextureOnImplThread(). | 37 // This posts the task to RunDeleteTextureOnImplThread(). |
| 33 impl_task_runner->PostTask( | 38 impl_task_runner->PostTask( |
| 34 FROM_HERE, base::Bind(run_impl_callback, sync_point, is_lost)); | 39 FROM_HERE, |
| 40 base::Bind(run_impl_callback, sync_point, sync_token, is_lost)); |
| 35 } | 41 } |
| 36 | 42 |
| 37 TextureMailboxDeleter::TextureMailboxDeleter( | 43 TextureMailboxDeleter::TextureMailboxDeleter( |
| 38 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) | 44 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
| 39 : impl_task_runner_(task_runner), weak_ptr_factory_(this) {} | 45 : impl_task_runner_(task_runner), weak_ptr_factory_(this) {} |
| 40 | 46 |
| 41 TextureMailboxDeleter::~TextureMailboxDeleter() { | 47 TextureMailboxDeleter::~TextureMailboxDeleter() { |
| 42 for (size_t i = 0; i < impl_callbacks_.size(); ++i) | 48 for (size_t i = 0; i < impl_callbacks_.size(); ++i) |
| 43 impl_callbacks_.at(i)->Run(0, true); | 49 impl_callbacks_.at(i)->Run(0, gpu::SyncToken(), true); |
| 44 } | 50 } |
| 45 | 51 |
| 46 scoped_ptr<SingleReleaseCallback> TextureMailboxDeleter::GetReleaseCallback( | 52 scoped_ptr<SingleReleaseCallback> TextureMailboxDeleter::GetReleaseCallback( |
| 47 const scoped_refptr<ContextProvider>& context_provider, | 53 const scoped_refptr<ContextProvider>& context_provider, |
| 48 unsigned texture_id) { | 54 unsigned texture_id) { |
| 49 // This callback owns a reference on the |context_provider|. It must be | 55 // This callback owns a reference on the |context_provider|. It must be |
| 50 // destroyed on the impl thread. Upon destruction of this class, the | 56 // destroyed on the impl thread. Upon destruction of this class, the |
| 51 // callback must immediately be destroyed. | 57 // callback must immediately be destroyed. |
| 52 scoped_ptr<SingleReleaseCallback> impl_callback = | 58 scoped_ptr<SingleReleaseCallback> impl_callback = |
| 53 SingleReleaseCallback::Create(base::Bind(&DeleteTextureOnImplThread, | 59 SingleReleaseCallback::Create(base::Bind(&DeleteTextureOnImplThread, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 72 } else { | 78 } else { |
| 73 main_callback = SingleReleaseCallback::Create(run_impl_callback); | 79 main_callback = SingleReleaseCallback::Create(run_impl_callback); |
| 74 } | 80 } |
| 75 | 81 |
| 76 return main_callback.Pass(); | 82 return main_callback.Pass(); |
| 77 } | 83 } |
| 78 | 84 |
| 79 void TextureMailboxDeleter::RunDeleteTextureOnImplThread( | 85 void TextureMailboxDeleter::RunDeleteTextureOnImplThread( |
| 80 SingleReleaseCallback* impl_callback, | 86 SingleReleaseCallback* impl_callback, |
| 81 unsigned sync_point, | 87 unsigned sync_point, |
| 88 const gpu::SyncToken& sync_token, |
| 82 bool is_lost) { | 89 bool is_lost) { |
| 83 for (size_t i = 0; i < impl_callbacks_.size(); ++i) { | 90 for (size_t i = 0; i < impl_callbacks_.size(); ++i) { |
| 84 if (impl_callbacks_.at(i) == impl_callback) { | 91 if (impl_callbacks_.at(i) == impl_callback) { |
| 85 // Run the callback, then destroy it here on the impl thread. | 92 // Run the callback, then destroy it here on the impl thread. |
| 86 impl_callbacks_.at(i)->Run(sync_point, is_lost); | 93 impl_callbacks_.at(i)->Run(sync_point, sync_token, is_lost); |
| 87 impl_callbacks_.erase(impl_callbacks_.begin() + i); | 94 impl_callbacks_.erase(impl_callbacks_.begin() + i); |
| 88 return; | 95 return; |
| 89 } | 96 } |
| 90 } | 97 } |
| 91 | 98 |
| 92 NOTREACHED() << "The Callback returned by GetDeleteCallback() was called " | 99 NOTREACHED() << "The Callback returned by GetDeleteCallback() was called " |
| 93 << "more than once."; | 100 << "more than once."; |
| 94 } | 101 } |
| 95 | 102 |
| 96 } // namespace cc | 103 } // namespace cc |
| OLD | NEW |