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" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 SingleReleaseCallback::Create(base::Bind(&DeleteTextureOnImplThread, | 56 SingleReleaseCallback::Create(base::Bind(&DeleteTextureOnImplThread, |
57 context_provider, | 57 context_provider, |
58 texture_id)); | 58 texture_id)); |
59 | 59 |
60 impl_callbacks_.push_back(impl_callback.Pass()); | 60 impl_callbacks_.push_back(impl_callback.Pass()); |
61 | 61 |
62 // The raw pointer to the impl-side callback is valid as long as this | 62 // The raw pointer to the impl-side callback is valid as long as this |
63 // class is alive. So we guard it with a WeakPtr. | 63 // class is alive. So we guard it with a WeakPtr. |
64 ReleaseCallback run_impl_callback( | 64 ReleaseCallback run_impl_callback( |
65 base::Bind(&TextureMailboxDeleter::RunDeleteTextureOnImplThread, | 65 base::Bind(&TextureMailboxDeleter::RunDeleteTextureOnImplThread, |
66 weak_ptr_factory_.GetWeakPtr(), | 66 weak_ptr_factory_.GetWeakPtr(), impl_callbacks_.back().get())); |
67 impl_callbacks_.back())); | |
68 | 67 |
69 // Provide a callback for the main thread that posts back to the impl | 68 // Provide a callback for the main thread that posts back to the impl |
70 // thread. | 69 // thread. |
71 scoped_ptr<SingleReleaseCallback> main_callback; | 70 scoped_ptr<SingleReleaseCallback> main_callback; |
72 if (impl_task_runner_) { | 71 if (impl_task_runner_) { |
73 main_callback = SingleReleaseCallback::Create(base::Bind( | 72 main_callback = SingleReleaseCallback::Create(base::Bind( |
74 &PostTaskFromMainToImplThread, impl_task_runner_, run_impl_callback)); | 73 &PostTaskFromMainToImplThread, impl_task_runner_, run_impl_callback)); |
75 } else { | 74 } else { |
76 main_callback = SingleReleaseCallback::Create(run_impl_callback); | 75 main_callback = SingleReleaseCallback::Create(run_impl_callback); |
77 } | 76 } |
78 | 77 |
79 return main_callback.Pass(); | 78 return main_callback.Pass(); |
80 } | 79 } |
81 | 80 |
82 void TextureMailboxDeleter::RunDeleteTextureOnImplThread( | 81 void TextureMailboxDeleter::RunDeleteTextureOnImplThread( |
83 SingleReleaseCallback* impl_callback, | 82 SingleReleaseCallback* impl_callback, |
84 const gpu::SyncToken& sync_token, | 83 const gpu::SyncToken& sync_token, |
85 bool is_lost) { | 84 bool is_lost) { |
86 for (size_t i = 0; i < impl_callbacks_.size(); ++i) { | 85 for (size_t i = 0; i < impl_callbacks_.size(); ++i) { |
87 if (impl_callbacks_.at(i) == impl_callback) { | 86 if (impl_callbacks_[i].get() == impl_callback) { |
88 // Run the callback, then destroy it here on the impl thread. | 87 // Run the callback, then destroy it here on the impl thread. |
89 impl_callbacks_.at(i)->Run(sync_token, is_lost); | 88 impl_callbacks_[i]->Run(sync_token, is_lost); |
90 impl_callbacks_.erase(impl_callbacks_.begin() + i); | 89 impl_callbacks_.erase(impl_callbacks_.begin() + i); |
91 return; | 90 return; |
92 } | 91 } |
93 } | 92 } |
94 | 93 |
95 NOTREACHED() << "The Callback returned by GetDeleteCallback() was called " | 94 NOTREACHED() << "The Callback returned by GetDeleteCallback() was called " |
96 << "more than once."; | 95 << "more than once."; |
97 } | 96 } |
98 | 97 |
99 } // namespace cc | 98 } // namespace cc |
OLD | NEW |