Index: content/common/gpu/client/context_provider_command_buffer.cc |
diff --git a/content/common/gpu/client/context_provider_command_buffer.cc b/content/common/gpu/client/context_provider_command_buffer.cc |
index ba9f0ebfbed6a6f75196c29a7bf89da933557773..fb76ee481050ca01bc18abbd4d1ddd9052fe5a8c 100644 |
--- a/content/common/gpu/client/context_provider_command_buffer.cc |
+++ b/content/common/gpu/client/context_provider_command_buffer.cc |
@@ -59,17 +59,8 @@ ContextProviderCommandBuffer::ContextProviderCommandBuffer( |
} |
ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { |
- DCHECK(main_thread_checker_.CalledOnValidThread() || |
- context_thread_checker_.CalledOnValidThread()); |
- |
base::AutoLock lock(main_thread_lock_); |
- |
- // Destroy references to the context3d_ before leaking it. |
- if (context3d_->GetCommandBufferProxy()) { |
- context3d_->GetCommandBufferProxy()->SetLock(nullptr); |
- context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( |
- CommandBufferProxyImpl::MemoryAllocationChangedCallback()); |
- } |
+ DestroyWithMainThreadLockAcquired(); |
lost_context_callback_proxy_.reset(); |
} |
@@ -78,6 +69,15 @@ CommandBufferProxyImpl* ContextProviderCommandBuffer::GetCommandBufferProxy() { |
return context3d_->GetCommandBufferProxy(); |
} |
+void ContextProviderCommandBuffer::Destroy() { |
+ DCHECK(context_thread_checker_.CalledOnValidThread()); |
+ // Verify that SetupLock() has been called. |
+ DCHECK(context3d_->GetCommandBufferProxy()->lock()); |
+ |
+ base::AutoLock lock(main_thread_lock_); |
+ DestroyWithMainThreadLockAcquired(); |
+} |
+ |
WebGraphicsContext3DCommandBufferImpl* |
ContextProviderCommandBuffer::WebContext3D() { |
DCHECK(context3d_); |
@@ -151,6 +151,7 @@ void ContextProviderCommandBuffer::InvalidateGrContext(uint32_t state) { |
void ContextProviderCommandBuffer::SetupLock() { |
DCHECK(context3d_); |
+ DCHECK(!context3d_->GetCommandBufferProxy()->lock()); |
context3d_->GetCommandBufferProxy()->SetLock(&context_lock_); |
} |
@@ -247,4 +248,16 @@ void ContextProviderCommandBuffer::SetMemoryPolicyChangedCallback( |
} |
} |
+void ContextProviderCommandBuffer::DestroyWithMainThreadLockAcquired() { |
+ main_thread_lock_.AssertAcquired(); |
+ |
+ if (context3d_->GetCommandBufferProxy()) { |
+ context3d_->GetCommandBufferProxy()->SetLock(nullptr); |
piman
2015/09/09 19:14:23
That's unsafe if the lock wasn't taken (or this is
|
+ context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( |
+ CommandBufferProxyImpl::MemoryAllocationChangedCallback()); |
+ context3d_->GetCommandBufferProxy()->Destroy(); |
+ } |
+ destroyed_ = true; |
+} |
+ |
} // namespace content |