Chromium Code Reviews| 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(); | 64 lost_context_callback_proxy_.reset(); |
| 74 } | 65 } |
| 75 | 66 |
| 76 | 67 |
| 77 CommandBufferProxyImpl* ContextProviderCommandBuffer::GetCommandBufferProxy() { | 68 CommandBufferProxyImpl* ContextProviderCommandBuffer::GetCommandBufferProxy() { |
| 78 return context3d_->GetCommandBufferProxy(); | 69 return context3d_->GetCommandBufferProxy(); |
| 79 } | 70 } |
| 80 | 71 |
| 72 void ContextProviderCommandBuffer::Destroy() { | |
| 73 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 74 // Verify that SetupLock() has been called. | |
| 75 DCHECK(context3d_->GetCommandBufferProxy()->lock()); | |
| 76 | |
| 77 base::AutoLock lock(main_thread_lock_); | |
| 78 DestroyWithMainThreadLockAcquired(); | |
| 79 } | |
| 80 | |
| 81 WebGraphicsContext3DCommandBufferImpl* | 81 WebGraphicsContext3DCommandBufferImpl* |
| 82 ContextProviderCommandBuffer::WebContext3D() { | 82 ContextProviderCommandBuffer::WebContext3D() { |
| 83 DCHECK(context3d_); | 83 DCHECK(context3d_); |
| 84 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 84 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| 85 DCHECK(context_thread_checker_.CalledOnValidThread()); | 85 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 86 | 86 |
| 87 return context3d_.get(); | 87 return context3d_.get(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 bool ContextProviderCommandBuffer::BindToCurrentThread() { | 90 bool ContextProviderCommandBuffer::BindToCurrentThread() { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 void ContextProviderCommandBuffer::InvalidateGrContext(uint32_t state) { | 144 void ContextProviderCommandBuffer::InvalidateGrContext(uint32_t state) { |
| 145 if (gr_context_) { | 145 if (gr_context_) { |
| 146 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 146 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| 147 DCHECK(context_thread_checker_.CalledOnValidThread()); | 147 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 148 gr_context_->get()->resetContext(state); | 148 gr_context_->get()->resetContext(state); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 void ContextProviderCommandBuffer::SetupLock() { | 152 void ContextProviderCommandBuffer::SetupLock() { |
| 153 DCHECK(context3d_); | 153 DCHECK(context3d_); |
| 154 DCHECK(!context3d_->GetCommandBufferProxy()->lock()); | |
| 154 context3d_->GetCommandBufferProxy()->SetLock(&context_lock_); | 155 context3d_->GetCommandBufferProxy()->SetLock(&context_lock_); |
| 155 } | 156 } |
| 156 | 157 |
| 157 base::Lock* ContextProviderCommandBuffer::GetLock() { | 158 base::Lock* ContextProviderCommandBuffer::GetLock() { |
| 158 return &context_lock_; | 159 return &context_lock_; |
| 159 } | 160 } |
| 160 | 161 |
| 161 cc::ContextProvider::Capabilities | 162 cc::ContextProvider::Capabilities |
| 162 ContextProviderCommandBuffer::ContextCapabilities() { | 163 ContextProviderCommandBuffer::ContextCapabilities() { |
| 163 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 164 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 memory_policy_changed_callback_ = memory_policy_changed_callback; | 241 memory_policy_changed_callback_ = memory_policy_changed_callback; |
| 241 | 242 |
| 242 if (!memory_policy_changed_callback_.is_null()) { | 243 if (!memory_policy_changed_callback_.is_null()) { |
| 243 DCHECK(context3d_->GetCommandBufferProxy()); | 244 DCHECK(context3d_->GetCommandBufferProxy()); |
| 244 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( | 245 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( |
| 245 base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged, | 246 base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged, |
| 246 base::Unretained(this))); | 247 base::Unretained(this))); |
| 247 } | 248 } |
| 248 } | 249 } |
| 249 | 250 |
| 251 void ContextProviderCommandBuffer::DestroyWithMainThreadLockAcquired() { | |
| 252 main_thread_lock_.AssertAcquired(); | |
| 253 | |
| 254 if (context3d_->GetCommandBufferProxy()) { | |
| 255 context3d_->GetCommandBufferProxy()->SetLock(nullptr); | |
|
piman
2015/09/09 19:14:23
That's unsafe if the lock wasn't taken (or this is
| |
| 256 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( | |
| 257 CommandBufferProxyImpl::MemoryAllocationChangedCallback()); | |
| 258 context3d_->GetCommandBufferProxy()->Destroy(); | |
| 259 } | |
| 260 destroyed_ = true; | |
| 261 } | |
| 262 | |
| 250 } // namespace content | 263 } // namespace content |
| OLD | NEW |