OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/compositor/test/in_process_context_provider.h" | 5 #include "ui/compositor/test/in_process_context_provider.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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 const gpu::gles2::ContextCreationAttribHelper& attribs, | 73 const gpu::gles2::ContextCreationAttribHelper& attribs, |
74 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 74 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
75 gpu::ImageFactory* image_factory, | 75 gpu::ImageFactory* image_factory, |
76 gfx::AcceleratedWidget window, | 76 gfx::AcceleratedWidget window, |
77 const std::string& debug_name) | 77 const std::string& debug_name) |
78 : attribs_(attribs), | 78 : attribs_(attribs), |
79 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 79 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
80 image_factory_(image_factory), | 80 image_factory_(image_factory), |
81 window_(window), | 81 window_(window), |
82 debug_name_(debug_name), | 82 debug_name_(debug_name), |
| 83 lost_(false), |
83 destroyed_(false) { | 84 destroyed_(false) { |
84 DCHECK(main_thread_checker_.CalledOnValidThread()); | 85 DCHECK(main_thread_checker_.CalledOnValidThread()); |
85 context_thread_checker_.DetachFromThread(); | 86 context_thread_checker_.DetachFromThread(); |
86 } | 87 } |
87 | 88 |
88 InProcessContextProvider::~InProcessContextProvider() { | 89 InProcessContextProvider::~InProcessContextProvider() {} |
89 DCHECK(main_thread_checker_.CalledOnValidThread() || | 90 |
90 context_thread_checker_.CalledOnValidThread()); | 91 void InProcessContextProvider::Destroy() { |
| 92 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 93 gr_context_ = nullptr; |
| 94 context_.reset(); |
| 95 destroyed_ = true; |
91 } | 96 } |
92 | 97 |
93 bool InProcessContextProvider::BindToCurrentThread() { | 98 bool InProcessContextProvider::BindToCurrentThread() { |
94 // This is called on the thread the context will be used. | 99 // This is called on the thread the context will be used. |
95 DCHECK(context_thread_checker_.CalledOnValidThread()); | 100 DCHECK(context_thread_checker_.CalledOnValidThread()); |
96 | 101 |
97 if (!context_) { | 102 if (!context_) { |
98 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 103 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
99 context_.reset(gpu::GLInProcessContext::Create( | 104 context_.reset(gpu::GLInProcessContext::Create( |
100 nullptr, /* service */ | 105 nullptr, /* service */ |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 void InProcessContextProvider::DeleteCachedResources() { | 198 void InProcessContextProvider::DeleteCachedResources() { |
194 DCHECK(context_thread_checker_.CalledOnValidThread()); | 199 DCHECK(context_thread_checker_.CalledOnValidThread()); |
195 | 200 |
196 if (gr_context_) { | 201 if (gr_context_) { |
197 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", | 202 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", |
198 TRACE_EVENT_SCOPE_THREAD); | 203 TRACE_EVENT_SCOPE_THREAD); |
199 gr_context_->freeGpuResources(); | 204 gr_context_->freeGpuResources(); |
200 } | 205 } |
201 } | 206 } |
202 | 207 |
203 bool InProcessContextProvider::DestroyedOnMainThread() { | 208 bool InProcessContextProvider::HasBeenLostOnMainThread() { |
204 DCHECK(main_thread_checker_.CalledOnValidThread()); | 209 DCHECK(main_thread_checker_.CalledOnValidThread()); |
205 | 210 |
206 base::AutoLock lock(destroyed_lock_); | 211 base::AutoLock lock(lost_lock_); |
207 return destroyed_; | 212 return lost_; |
208 } | 213 } |
209 | 214 |
210 void InProcessContextProvider::SetLostContextCallback( | 215 void InProcessContextProvider::SetLostContextCallback( |
211 const LostContextCallback& lost_context_callback) { | 216 const LostContextCallback& lost_context_callback) { |
212 lost_context_callback_ = lost_context_callback; | 217 lost_context_callback_ = lost_context_callback; |
213 } | 218 } |
214 | 219 |
215 void InProcessContextProvider::SetMemoryPolicyChangedCallback( | 220 void InProcessContextProvider::SetMemoryPolicyChangedCallback( |
216 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { | 221 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { |
217 // There's no memory manager for the in-process implementation. | 222 // There's no memory manager for the in-process implementation. |
218 } | 223 } |
219 | 224 |
220 void InProcessContextProvider::OnLostContext() { | 225 void InProcessContextProvider::OnLostContext() { |
221 DCHECK(context_thread_checker_.CalledOnValidThread()); | 226 DCHECK(context_thread_checker_.CalledOnValidThread()); |
222 { | 227 { |
223 base::AutoLock lock(destroyed_lock_); | 228 base::AutoLock lock(lost_lock_); |
224 if (destroyed_) | 229 if (lost_) |
225 return; | 230 return; |
226 destroyed_ = true; | 231 lost_ = true; |
227 } | 232 } |
228 if (!lost_context_callback_.is_null()) | 233 if (!lost_context_callback_.is_null()) |
229 base::ResetAndReturn(&lost_context_callback_).Run(); | 234 base::ResetAndReturn(&lost_context_callback_).Run(); |
230 if (gr_context_) | 235 if (gr_context_) |
231 gr_context_->abandonContext(); | 236 gr_context_->abandonContext(); |
232 } | 237 } |
233 | 238 |
| 239 bool InProcessContextProvider::HasBeenDestroyed() { |
| 240 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 241 return destroyed_; |
| 242 } |
| 243 |
234 } // namespace ui | 244 } // namespace ui |
OLD | NEW |