Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: content/common/gpu/client/context_provider_command_buffer.cc

Issue 1317743002: cc: Implement shared worker contexts. (v1) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tear down Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/gpu/client/context_provider_command_buffer.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7a0f67a3f563f6a8f96e8d4a377792f8476a6a0c 100644
--- a/content/common/gpu/client/context_provider_command_buffer.cc
+++ b/content/common/gpu/client/context_provider_command_buffer.cc
@@ -52,6 +52,7 @@ ContextProviderCommandBuffer::ContextProviderCommandBuffer(
: context3d_(context3d.Pass()),
context_type_(type),
debug_name_(CommandBufferContextTypeToString(type)),
+ lost_(false),
destroyed_(false) {
DCHECK(main_thread_checker_.CalledOnValidThread());
DCHECK(context3d_);
@@ -59,18 +60,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());
- }
- lost_context_callback_proxy_.reset();
+ DestroyWithLockAcquired();
}
@@ -78,6 +69,14 @@ CommandBufferProxyImpl* ContextProviderCommandBuffer::GetCommandBufferProxy() {
return context3d_->GetCommandBufferProxy();
}
+void ContextProviderCommandBuffer::Destroy() {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ DCHECK(context3d_);
+ // Verify that SetupLock() has been called.
+ DCHECK(context3d_->GetCommandBufferProxy()->lock());
+ DestroyWithLockAcquired();
+}
+
WebGraphicsContext3DCommandBufferImpl*
ContextProviderCommandBuffer::WebContext3D() {
DCHECK(context3d_);
@@ -151,6 +150,7 @@ void ContextProviderCommandBuffer::InvalidateGrContext(uint32_t state) {
void ContextProviderCommandBuffer::SetupLock() {
DCHECK(context3d_);
+ DCHECK(!context3d_->GetCommandBufferProxy()->lock());
context3d_->GetCommandBufferProxy()->SetLock(&context_lock_);
}
@@ -185,9 +185,9 @@ void ContextProviderCommandBuffer::OnLostContext() {
DCHECK(context_thread_checker_.CalledOnValidThread());
{
base::AutoLock lock(main_thread_lock_);
- if (destroyed_)
+ if (lost_)
return;
- destroyed_ = true;
+ lost_ = true;
}
if (!lost_context_callback_.is_null())
base::ResetAndReturn(&lost_context_callback_).Run();
@@ -217,11 +217,11 @@ void ContextProviderCommandBuffer::InitializeCapabilities() {
capabilities_ = caps;
}
-bool ContextProviderCommandBuffer::DestroyedOnMainThread() {
+bool ContextProviderCommandBuffer::HasBeenLostOnMainThread() {
DCHECK(main_thread_checker_.CalledOnValidThread());
base::AutoLock lock(main_thread_lock_);
- return destroyed_;
+ return lost_;
}
void ContextProviderCommandBuffer::SetLostContextCallback(
@@ -247,4 +247,21 @@ void ContextProviderCommandBuffer::SetMemoryPolicyChangedCallback(
}
}
+bool ContextProviderCommandBuffer::HasBeenDestroyed() {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ return destroyed_;
+}
+
+void ContextProviderCommandBuffer::DestroyWithLockAcquired() {
+ if (context3d_ && context3d_->GetCommandBufferProxy()) {
+ context3d_->GetCommandBufferProxy()->SetLock(nullptr);
+ context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback(
+ CommandBufferProxyImpl::MemoryAllocationChangedCallback());
+ }
+ lost_context_callback_proxy_.reset();
+ gr_context_.reset();
+ context3d_.reset();
+ destroyed_ = true;
+}
+
} // namespace content
« no previous file with comments | « content/common/gpu/client/context_provider_command_buffer.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698