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 "content/common/gpu/client/context_provider_command_buffer.h" | 5 #include "content/common/gpu/client/context_provider_command_buffer.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 : context3d_(context3d.Pass()), | 52 : context3d_(context3d.Pass()), |
53 context_type_(type), | 53 context_type_(type), |
54 debug_name_(CommandBufferContextTypeToString(type)), | 54 debug_name_(CommandBufferContextTypeToString(type)), |
55 destroyed_(false) { | 55 destroyed_(false) { |
56 DCHECK(main_thread_checker_.CalledOnValidThread()); | 56 DCHECK(main_thread_checker_.CalledOnValidThread()); |
57 DCHECK(context3d_); | 57 DCHECK(context3d_); |
58 context_thread_checker_.DetachFromThread(); | 58 context_thread_checker_.DetachFromThread(); |
59 } | 59 } |
60 | 60 |
61 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { | 61 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { |
62 DCHECK(main_thread_checker_.CalledOnValidThread() || | |
63 context_thread_checker_.CalledOnValidThread()); | |
64 | |
65 base::AutoLock lock(main_thread_lock_); | 62 base::AutoLock lock(main_thread_lock_); |
66 | 63 DestroyWithMainThreadLockAcquired(); |
67 // Destroy references to the context3d_ before leaking it. | |
68 if (context3d_->GetCommandBufferProxy()) { | |
69 context3d_->GetCommandBufferProxy()->SetLock(nullptr); | |
70 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( | |
71 CommandBufferProxyImpl::MemoryAllocationChangedCallback()); | |
72 } | |
73 lost_context_callback_proxy_.reset(); | |
74 } | 64 } |
75 | 65 |
76 | 66 |
77 CommandBufferProxyImpl* ContextProviderCommandBuffer::GetCommandBufferProxy() { | 67 CommandBufferProxyImpl* ContextProviderCommandBuffer::GetCommandBufferProxy() { |
78 return context3d_->GetCommandBufferProxy(); | 68 return context3d_->GetCommandBufferProxy(); |
79 } | 69 } |
80 | 70 |
71 void ContextProviderCommandBuffer::Destroy() { | |
72 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
73 | |
74 base::AutoLock lock(main_thread_lock_); | |
75 DestroyWithMainThreadLockAcquired(); | |
76 } | |
77 | |
81 WebGraphicsContext3DCommandBufferImpl* | 78 WebGraphicsContext3DCommandBufferImpl* |
82 ContextProviderCommandBuffer::WebContext3D() { | 79 ContextProviderCommandBuffer::WebContext3D() { |
83 DCHECK(context3d_); | 80 DCHECK(context3d_); |
84 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 81 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
85 DCHECK(context_thread_checker_.CalledOnValidThread()); | 82 DCHECK(context_thread_checker_.CalledOnValidThread()); |
86 | 83 |
87 return context3d_.get(); | 84 return context3d_.get(); |
88 } | 85 } |
89 | 86 |
90 bool ContextProviderCommandBuffer::BindToCurrentThread() { | 87 bool ContextProviderCommandBuffer::BindToCurrentThread() { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 memory_policy_changed_callback_ = memory_policy_changed_callback; | 237 memory_policy_changed_callback_ = memory_policy_changed_callback; |
241 | 238 |
242 if (!memory_policy_changed_callback_.is_null()) { | 239 if (!memory_policy_changed_callback_.is_null()) { |
243 DCHECK(context3d_->GetCommandBufferProxy()); | 240 DCHECK(context3d_->GetCommandBufferProxy()); |
244 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( | 241 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( |
245 base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged, | 242 base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged, |
246 base::Unretained(this))); | 243 base::Unretained(this))); |
247 } | 244 } |
248 } | 245 } |
249 | 246 |
247 bool ContextProviderCommandBuffer::HasBeenDestroyed() { | |
piman
2015/09/04 22:19:13
I think you need to acquire main_thread_lock_ here
| |
248 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
249 return destroyed_; | |
250 } | |
251 | |
252 void ContextProviderCommandBuffer::DestroyWithMainThreadLockAcquired() { | |
253 main_thread_lock_.AssertAcquired(); | |
254 | |
255 if (context3d_->GetCommandBufferProxy()) { | |
piman
2015/09/04 22:19:13
Can we assert that if there is a context lock, it
| |
256 context3d_->GetCommandBufferProxy()->SetLock(nullptr); | |
257 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( | |
258 CommandBufferProxyImpl::MemoryAllocationChangedCallback()); | |
259 } | |
260 lost_context_callback_proxy_.reset(); | |
261 gr_context_.reset(); | |
262 context3d_.reset(); | |
263 | |
264 destroyed_ = true; | |
265 } | |
266 | |
250 } // namespace content | 267 } // namespace content |
OLD | NEW |