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 3 // found in the LICENSE file. 4 5 #ifndef CC_OUTPUT_CONTEXT_PROVIDER_H_ 6 #define CC_OUTPUT_CONTEXT_PROVIDER_H_ 7 8 #include "base/callback.h" 9 #include "base/memory/ref_counted.h" 10 #include "cc/base/cc_export.h" 11 #include "gpu/command_buffer/common/capabilities.h" 12 13 class GrContext; 14 15 namespace gpu { 16 class ContextSupport; 17 namespace gles2 { class GLES2Interface; } 18 } 19 20 namespace cc { 21 struct ManagedMemoryPolicy; 22 23 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { 24 public: 25 // Bind the 3d context to the current thread. This should be called before 26 // accessing the contexts. Calling it more than once should have no effect. 27 // Once this function has been called, the class should only be accessed 28 // from the same thread. 29 virtual bool BindToCurrentThread() = 0; 30 31 virtual gpu::gles2::GLES2Interface* ContextGL() = 0; 32 virtual gpu::ContextSupport* ContextSupport() = 0; 33 virtual class GrContext* GrContext() = 0; 34 35 struct Capabilities { 36 gpu::Capabilities gpu; 37 size_t max_transfer_buffer_usage_bytes; 38 39 CC_EXPORT Capabilities(); 40 }; 41 42 // Returns the capabilities of the currently bound 3d context. 43 virtual Capabilities ContextCapabilities() = 0; 44 45 // Checks if the context is currently known to be lost. 46 virtual bool IsContextLost() = 0; 47 48 // Ask the provider to check if the contexts are valid or lost. If they are, 49 // this should invalidate the provider so that it can be replaced with a new 50 // one. 51 virtual void VerifyContexts() = 0; 52 53 // Delete all cached gpu resources. 54 virtual void DeleteCachedResources() = 0; 55 56 // A method to be called from the main thread that should return true if 57 // the context inside the provider is no longer valid. 58 virtual bool DestroyedOnMainThread() = 0; 59 60 // Sets a callback to be called when the context is lost. This should be 61 // called from the same thread that the context is bound to. To avoid races, 62 // it should be called before BindToCurrentThread(), or VerifyContexts() 63 // should be called after setting the callback. 64 typedef base::Closure LostContextCallback; 65 virtual void SetLostContextCallback( 66 const LostContextCallback& lost_context_callback) = 0; 67 68 // Sets a callback to be called when the memory policy changes. This should be 69 // called from the same thread that the context is bound to. 70 typedef base::Callback<void(const ManagedMemoryPolicy& policy)> 71 MemoryPolicyChangedCallback; 72 virtual void SetMemoryPolicyChangedCallback( 73 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0; 74 75 protected: 76 friend class base::RefCountedThreadSafe<ContextProvider>; ~ContextProvider()77 virtual ~ContextProvider() {} 78 }; 79 80 } // namespace cc 81 82 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ 83