Roll src/third_party/skia 280a9c8:ecb8e3e
[chromium-blink-merge.git] / cc / output / context_provider.h
blob71d06bd7591d22f180f7a395b5be412d733b03bb
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"
13 class GrContext;
15 namespace base {
16 class Lock;
19 namespace gpu {
20 class ContextSupport;
21 namespace gles2 { class GLES2Interface; }
24 namespace cc {
25 struct ManagedMemoryPolicy;
27 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
28 public:
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;
40 struct Capabilities {
41 gpu::Capabilities gpu;
42 size_t max_transfer_buffer_usage_bytes;
44 CC_EXPORT Capabilities();
47 // Sets up a lock so this context can be used from multiple threads.
48 virtual void SetupLock() = 0;
50 // Returns the lock that should be held if using this context from multiple
51 // threads.
52 virtual base::Lock* GetLock() = 0;
54 // Returns the capabilities of the currently bound 3d context.
55 virtual Capabilities ContextCapabilities() = 0;
57 // Checks if the context is currently known to be lost.
58 virtual bool IsContextLost() = 0;
60 // Ask the provider to check if the contexts are valid or lost. If they are,
61 // this should invalidate the provider so that it can be replaced with a new
62 // one.
63 virtual void VerifyContexts() = 0;
65 // Delete all cached gpu resources.
66 virtual void DeleteCachedResources() = 0;
68 // A method to be called from the main thread that should return true if
69 // the context inside the provider is no longer valid.
70 virtual bool DestroyedOnMainThread() = 0;
72 // Sets a callback to be called when the context is lost. This should be
73 // called from the same thread that the context is bound to. To avoid races,
74 // it should be called before BindToCurrentThread(), or VerifyContexts()
75 // should be called after setting the callback.
76 typedef base::Closure LostContextCallback;
77 virtual void SetLostContextCallback(
78 const LostContextCallback& lost_context_callback) = 0;
80 // Sets a callback to be called when the memory policy changes. This should be
81 // called from the same thread that the context is bound to.
82 typedef base::Callback<void(const ManagedMemoryPolicy& policy)>
83 MemoryPolicyChangedCallback;
84 virtual void SetMemoryPolicyChangedCallback(
85 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0;
87 protected:
88 friend class base::RefCountedThreadSafe<ContextProvider>;
89 virtual ~ContextProvider() {}
92 } // namespace cc
94 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_