Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / output / context_provider.h
blobdfaab4a15b214d6e55d4b7a7e3b743f193be3801
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 // 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
55 // threads.
56 virtual base::Lock* GetLock() = 0;
58 // Returns the capabilities of the currently bound 3d context.
59 virtual Capabilities ContextCapabilities() = 0;
61 // Checks if the context is currently known to be lost.
62 virtual bool IsContextLost() = 0;
64 // Ask the provider to check if the contexts are valid or lost. If they are,
65 // this should invalidate the provider so that it can be replaced with a new
66 // one.
67 virtual void VerifyContexts() = 0;
69 // Delete all cached gpu resources.
70 virtual void DeleteCachedResources() = 0;
72 // A method to be called from the main thread that should return true if
73 // the context inside the provider is no longer valid.
74 virtual bool DestroyedOnMainThread() = 0;
76 // Sets a callback to be called when the context is lost. This should be
77 // called from the same thread that the context is bound to. To avoid races,
78 // it should be called before BindToCurrentThread(), or VerifyContexts()
79 // should be called after setting the callback.
80 typedef base::Closure LostContextCallback;
81 virtual void SetLostContextCallback(
82 const LostContextCallback& lost_context_callback) = 0;
84 // Sets a callback to be called when the memory policy changes. This should be
85 // called from the same thread that the context is bound to.
86 typedef base::Callback<void(const ManagedMemoryPolicy& policy)>
87 MemoryPolicyChangedCallback;
88 virtual void SetMemoryPolicyChangedCallback(
89 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0;
91 protected:
92 friend class base::RefCountedThreadSafe<ContextProvider>;
93 virtual ~ContextProvider() {}
96 } // namespace cc
98 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_