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.
5 #ifndef CC_OUTPUT_CONTEXT_PROVIDER_H_
6 #define CC_OUTPUT_CONTEXT_PROVIDER_H_
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"
21 namespace gles2
{ class GLES2Interface
; }
25 struct ManagedMemoryPolicy
;
27 class ContextProvider
: public base::RefCountedThreadSafe
<ContextProvider
> {
29 // Bind the 3d context to the current thread. This should be called before
30 // accessing the contexts. Calling it more than once should have no effect.
31 // Once this function has been called, the class should only be accessed
32 // from the same thread.
33 virtual bool BindToCurrentThread() = 0;
34 virtual void DetachFromThread() {}
36 virtual gpu::gles2::GLES2Interface
* ContextGL() = 0;
37 virtual gpu::ContextSupport
* ContextSupport() = 0;
38 virtual class GrContext
* GrContext() = 0;
41 gpu::Capabilities gpu
;
42 size_t max_transfer_buffer_usage_bytes
;
44 CC_EXPORT
Capabilities();
47 // Invalidates the cached OpenGL state in GrContext.
48 // See skia GrContext::resetContext for details.
49 virtual void InvalidateGrContext(uint32_t state
) = 0;
51 // Sets up a lock so this context can be used from multiple threads.
52 virtual void SetupLock() = 0;
54 // Returns the lock that should be held if using this context from multiple
56 virtual base::Lock
* GetLock() = 0;
58 // Returns the capabilities of the currently bound 3d context.
59 virtual Capabilities
ContextCapabilities() = 0;
61 // Ask the provider to check if the contexts are valid or lost. If they are,
62 // this should invalidate the provider so that it can be replaced with a new
64 virtual void VerifyContexts() = 0;
66 // Delete all cached gpu resources.
67 virtual void DeleteCachedResources() = 0;
69 // A method to be called from the main thread that should return true if
70 // the context inside the provider is no longer valid.
71 virtual bool DestroyedOnMainThread() = 0;
73 // Sets a callback to be called when the context is lost. This should be
74 // called from the same thread that the context is bound to. To avoid races,
75 // it should be called before BindToCurrentThread(), or VerifyContexts()
76 // should be called after setting the callback.
77 typedef base::Closure LostContextCallback
;
78 virtual void SetLostContextCallback(
79 const LostContextCallback
& lost_context_callback
) = 0;
81 // Sets a callback to be called when the memory policy changes. This should be
82 // called from the same thread that the context is bound to.
83 typedef base::Callback
<void(const ManagedMemoryPolicy
& policy
)>
84 MemoryPolicyChangedCallback
;
85 virtual void SetMemoryPolicyChangedCallback(
86 const MemoryPolicyChangedCallback
& memory_policy_changed_callback
) = 0;
89 friend class base::RefCountedThreadSafe
<ContextProvider
>;
90 virtual ~ContextProvider() {}
95 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_