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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 TextureMailboxDeleter::TextureMailboxDeleter( | 42 TextureMailboxDeleter::TextureMailboxDeleter( |
43 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 43 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
44 : impl_task_runner_(std::move(task_runner)), weak_ptr_factory_(this) {} | 44 : impl_task_runner_(std::move(task_runner)), weak_ptr_factory_(this) {} |
45 | 45 |
46 TextureMailboxDeleter::~TextureMailboxDeleter() { | 46 TextureMailboxDeleter::~TextureMailboxDeleter() { |
47 for (size_t i = 0; i < impl_callbacks_.size(); ++i) | 47 for (size_t i = 0; i < impl_callbacks_.size(); ++i) |
48 impl_callbacks_.at(i)->Run(gpu::SyncToken(), true); | 48 impl_callbacks_.at(i)->Run(gpu::SyncToken(), true); |
49 } | 49 } |
50 | 50 |
51 scoped_ptr<SingleReleaseCallback> TextureMailboxDeleter::GetReleaseCallback( | 51 std::unique_ptr<SingleReleaseCallback> |
| 52 TextureMailboxDeleter::GetReleaseCallback( |
52 scoped_refptr<ContextProvider> context_provider, | 53 scoped_refptr<ContextProvider> context_provider, |
53 unsigned texture_id) { | 54 unsigned texture_id) { |
54 // This callback owns the |context_provider|. It must be destroyed on the impl | 55 // This callback owns the |context_provider|. It must be destroyed on the impl |
55 // thread. Upon destruction of this class, the callback must immediately be | 56 // thread. Upon destruction of this class, the callback must immediately be |
56 // destroyed. | 57 // destroyed. |
57 scoped_ptr<SingleReleaseCallback> impl_callback = | 58 std::unique_ptr<SingleReleaseCallback> impl_callback = |
58 SingleReleaseCallback::Create(base::Bind( | 59 SingleReleaseCallback::Create(base::Bind( |
59 &DeleteTextureOnImplThread, std::move(context_provider), texture_id)); | 60 &DeleteTextureOnImplThread, std::move(context_provider), texture_id)); |
60 | 61 |
61 impl_callbacks_.push_back(std::move(impl_callback)); | 62 impl_callbacks_.push_back(std::move(impl_callback)); |
62 | 63 |
63 // The raw pointer to the impl-side callback is valid as long as this | 64 // The raw pointer to the impl-side callback is valid as long as this |
64 // class is alive. So we guard it with a WeakPtr. | 65 // class is alive. So we guard it with a WeakPtr. |
65 ReleaseCallback run_impl_callback( | 66 ReleaseCallback run_impl_callback( |
66 base::Bind(&TextureMailboxDeleter::RunDeleteTextureOnImplThread, | 67 base::Bind(&TextureMailboxDeleter::RunDeleteTextureOnImplThread, |
67 weak_ptr_factory_.GetWeakPtr(), impl_callbacks_.back().get())); | 68 weak_ptr_factory_.GetWeakPtr(), impl_callbacks_.back().get())); |
68 | 69 |
69 // Provide a callback for the main thread that posts back to the impl | 70 // Provide a callback for the main thread that posts back to the impl |
70 // thread. | 71 // thread. |
71 scoped_ptr<SingleReleaseCallback> main_callback; | 72 std::unique_ptr<SingleReleaseCallback> main_callback; |
72 if (impl_task_runner_) { | 73 if (impl_task_runner_) { |
73 main_callback = SingleReleaseCallback::Create(base::Bind( | 74 main_callback = SingleReleaseCallback::Create(base::Bind( |
74 &PostTaskFromMainToImplThread, impl_task_runner_, run_impl_callback)); | 75 &PostTaskFromMainToImplThread, impl_task_runner_, run_impl_callback)); |
75 } else { | 76 } else { |
76 main_callback = SingleReleaseCallback::Create(run_impl_callback); | 77 main_callback = SingleReleaseCallback::Create(run_impl_callback); |
77 } | 78 } |
78 | 79 |
79 return main_callback; | 80 return main_callback; |
80 } | 81 } |
81 | 82 |
82 void TextureMailboxDeleter::RunDeleteTextureOnImplThread( | 83 void TextureMailboxDeleter::RunDeleteTextureOnImplThread( |
83 SingleReleaseCallback* impl_callback, | 84 SingleReleaseCallback* impl_callback, |
84 const gpu::SyncToken& sync_token, | 85 const gpu::SyncToken& sync_token, |
85 bool is_lost) { | 86 bool is_lost) { |
86 for (size_t i = 0; i < impl_callbacks_.size(); ++i) { | 87 for (size_t i = 0; i < impl_callbacks_.size(); ++i) { |
87 if (impl_callbacks_[i].get() == impl_callback) { | 88 if (impl_callbacks_[i].get() == impl_callback) { |
88 // Run the callback, then destroy it here on the impl thread. | 89 // Run the callback, then destroy it here on the impl thread. |
89 impl_callbacks_[i]->Run(sync_token, is_lost); | 90 impl_callbacks_[i]->Run(sync_token, is_lost); |
90 impl_callbacks_.erase(impl_callbacks_.begin() + i); | 91 impl_callbacks_.erase(impl_callbacks_.begin() + i); |
91 return; | 92 return; |
92 } | 93 } |
93 } | 94 } |
94 | 95 |
95 NOTREACHED() << "The Callback returned by GetDeleteCallback() was called " | 96 NOTREACHED() << "The Callback returned by GetDeleteCallback() was called " |
96 << "more than once."; | 97 << "more than once."; |
97 } | 98 } |
98 | 99 |
99 } // namespace cc | 100 } // namespace cc |
OLD | NEW |