Index: cc/output/context_provider.h |
diff --git a/cc/output/context_provider.h b/cc/output/context_provider.h |
index c024e02328e9a3930b7593e54b986bdff3566ae5..2ea5ef1c3a86ddaebc46887e8801874d49d5cc36 100644 |
--- a/cc/output/context_provider.h |
+++ b/cc/output/context_provider.h |
@@ -32,16 +32,20 @@ class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { |
explicit ScopedContextLock(ContextProvider* context_provider) |
: context_provider_(context_provider), |
context_lock_(*context_provider_->GetLock()) { |
- // Allow current thread to bind to |context_provider|. |
+ // Allow current thread to use |context_provider_|. |
context_provider_->DetachFromThread(); |
} |
~ScopedContextLock() { |
- // Allow a different thread to bind to |context_provider|. |
+ // Allow usage by thread for which |context_provider_| is bound to. |
context_provider_->DetachFromThread(); |
} |
+ // Returns a raw pointer to the GLES2Interface or null if context has been |
+ // destroyed. |
gpu::gles2::GLES2Interface* ContextGL() { |
- return context_provider_->ContextGL(); |
+ return context_provider_->HasBeenDestroyed() |
+ ? nullptr |
+ : context_provider_->ContextGL(); |
} |
private: |
@@ -51,7 +55,9 @@ class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { |
// Bind the 3d context to the current thread. This should be called before |
// accessing the contexts. Calling it more than once should have no effect. |
// Once this function has been called, the class should only be accessed |
- // from the same thread. |
+ // from the same thread unless the function has some explicitly specified |
+ // rules for access on a different thread. See SetupLockOnMainThread(), which |
+ // can be used to provide access from multiple threads. |
virtual bool BindToCurrentThread() = 0; |
virtual void DetachFromThread() {} |
@@ -70,11 +76,13 @@ class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { |
// See skia GrContext::resetContext for details. |
virtual void InvalidateGrContext(uint32_t state) = 0; |
- // Sets up a lock so this context can be used from multiple threads. |
+ // Sets up a lock so this context can be used from multiple threads. After |
+ // calling this, all functions without explicit thread usage constraints can |
+ // be used on any thread while the lock returned by GetLock() is acquired. |
virtual void SetupLock() = 0; |
// Returns the lock that should be held if using this context from multiple |
- // threads. |
+ // threads. This can be called on any thread. |
virtual base::Lock* GetLock() = 0; |
// Returns the capabilities of the currently bound 3d context. |
@@ -89,8 +97,8 @@ class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { |
virtual void DeleteCachedResources() = 0; |
// A method to be called from the main thread that should return true if |
- // the context inside the provider is no longer valid. |
- virtual bool DestroyedOnMainThread() = 0; |
+ // the context inside the provider has been lost. |
+ virtual bool HasBeenLostOnMainThread() = 0; |
// Sets a callback to be called when the context is lost. This should be |
// called from the same thread that the context is bound to. To avoid races, |
@@ -107,6 +115,9 @@ class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { |
virtual void SetMemoryPolicyChangedCallback( |
const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0; |
+ // Return true if the context inside the provider has been destroyed. |
+ virtual bool HasBeenDestroyed() = 0; |
+ |
protected: |
friend class base::RefCountedThreadSafe<ContextProvider>; |
virtual ~ContextProvider() {} |