BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / cc / output / context_provider.h
blobc024e02328e9a3930b7593e54b986bdff3566ae5
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 "base/synchronization/lock.h"
11 #include "cc/base/cc_export.h"
12 #include "gpu/command_buffer/common/capabilities.h"
14 class GrContext;
16 namespace base {
17 class Lock;
20 namespace gpu {
21 class ContextSupport;
22 namespace gles2 { class GLES2Interface; }
25 namespace cc {
26 struct ManagedMemoryPolicy;
28 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
29 public:
30 class ScopedContextLock {
31 public:
32 explicit ScopedContextLock(ContextProvider* context_provider)
33 : context_provider_(context_provider),
34 context_lock_(*context_provider_->GetLock()) {
35 // Allow current thread to bind to |context_provider|.
36 context_provider_->DetachFromThread();
38 ~ScopedContextLock() {
39 // Allow a different thread to bind to |context_provider|.
40 context_provider_->DetachFromThread();
43 gpu::gles2::GLES2Interface* ContextGL() {
44 return context_provider_->ContextGL();
47 private:
48 ContextProvider* const context_provider_;
49 base::AutoLock context_lock_;
51 // Bind the 3d context to the current thread. This should be called before
52 // accessing the contexts. Calling it more than once should have no effect.
53 // Once this function has been called, the class should only be accessed
54 // from the same thread.
55 virtual bool BindToCurrentThread() = 0;
56 virtual void DetachFromThread() {}
58 virtual gpu::gles2::GLES2Interface* ContextGL() = 0;
59 virtual gpu::ContextSupport* ContextSupport() = 0;
60 virtual class GrContext* GrContext() = 0;
62 struct Capabilities {
63 gpu::Capabilities gpu;
64 size_t max_transfer_buffer_usage_bytes;
66 CC_EXPORT Capabilities();
69 // Invalidates the cached OpenGL state in GrContext.
70 // See skia GrContext::resetContext for details.
71 virtual void InvalidateGrContext(uint32_t state) = 0;
73 // Sets up a lock so this context can be used from multiple threads.
74 virtual void SetupLock() = 0;
76 // Returns the lock that should be held if using this context from multiple
77 // threads.
78 virtual base::Lock* GetLock() = 0;
80 // Returns the capabilities of the currently bound 3d context.
81 virtual Capabilities ContextCapabilities() = 0;
83 // Ask the provider to check if the contexts are valid or lost. If they are,
84 // this should invalidate the provider so that it can be replaced with a new
85 // one.
86 virtual void VerifyContexts() = 0;
88 // Delete all cached gpu resources.
89 virtual void DeleteCachedResources() = 0;
91 // A method to be called from the main thread that should return true if
92 // the context inside the provider is no longer valid.
93 virtual bool DestroyedOnMainThread() = 0;
95 // Sets a callback to be called when the context is lost. This should be
96 // called from the same thread that the context is bound to. To avoid races,
97 // it should be called before BindToCurrentThread(), or VerifyContexts()
98 // should be called after setting the callback.
99 typedef base::Closure LostContextCallback;
100 virtual void SetLostContextCallback(
101 const LostContextCallback& lost_context_callback) = 0;
103 // Sets a callback to be called when the memory policy changes. This should be
104 // called from the same thread that the context is bound to.
105 typedef base::Callback<void(const ManagedMemoryPolicy& policy)>
106 MemoryPolicyChangedCallback;
107 virtual void SetMemoryPolicyChangedCallback(
108 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0;
110 protected:
111 friend class base::RefCountedThreadSafe<ContextProvider>;
112 virtual ~ContextProvider() {}
115 } // namespace cc
117 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_