Index: cc/output/output_surface.cc |
diff --git a/cc/output/output_surface.cc b/cc/output/output_surface.cc |
index 056879f49d84ba444142101690da109437208d14..6ba290c14a9d020b3e5c748583f305ee3eb6fe52 100644 |
--- a/cc/output/output_surface.cc |
+++ b/cc/output/output_surface.cc |
@@ -32,6 +32,7 @@ OutputSurface::OutputSurface( |
device_scale_factor_(-1), |
external_stencil_test_enabled_(false), |
weak_ptr_factory_(this) { |
+ client_thread_checker_.DetachFromThread(); |
} |
OutputSurface::OutputSurface( |
@@ -101,12 +102,8 @@ void OutputSurface::SetExternalDrawConstraints( |
} |
OutputSurface::~OutputSurface() { |
- if (context_provider_.get()) { |
- context_provider_->SetLostContextCallback( |
- ContextProvider::LostContextCallback()); |
- context_provider_->SetMemoryPolicyChangedCallback( |
- ContextProvider::MemoryPolicyChangedCallback()); |
- } |
+ if (client_) |
+ DetachFromClient(); |
} |
bool OutputSurface::HasExternalStencilTest() const { |
@@ -115,6 +112,8 @@ bool OutputSurface::HasExternalStencilTest() const { |
bool OutputSurface::BindToClient(OutputSurfaceClient* client) { |
DCHECK(client); |
+ DCHECK(!client_); |
+ DCHECK(CalledOnValidClientThread()); |
client_ = client; |
bool success = true; |
@@ -128,18 +127,30 @@ bool OutputSurface::BindToClient(OutputSurfaceClient* client) { |
} |
} |
- if (success && worker_context_provider_.get()) { |
- success = worker_context_provider_->BindToCurrentThread(); |
- if (success) |
- worker_context_provider_->SetupLock(); |
- } |
- |
if (!success) |
client_ = NULL; |
return success; |
} |
+void OutputSurface::DetachFromClient() { |
+ DCHECK(CalledOnValidClientThread()); |
+ DCHECK(client_); |
+ if (context_provider_.get()) { |
+ context_provider_->SetLostContextCallback( |
+ ContextProvider::LostContextCallback()); |
+ context_provider_->SetMemoryPolicyChangedCallback( |
+ ContextProvider::MemoryPolicyChangedCallback()); |
+ } |
+ context_provider_ = nullptr; |
+ client_ = nullptr; |
+ weak_ptr_factory_.InvalidateWeakPtrs(); |
+} |
+ |
+bool OutputSurface::CalledOnValidClientThread() { |
+ return client_thread_checker_.CalledOnValidThread(); |
+} |
+ |
void OutputSurface::EnsureBackbuffer() { |
if (software_device_) |
software_device_->EnsureBackbuffer(); |