OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_OUTPUT_CONTEXT_PROVIDER_H_ | 5 #ifndef CC_OUTPUT_CONTEXT_PROVIDER_H_ |
6 #define CC_OUTPUT_CONTEXT_PROVIDER_H_ | 6 #define CC_OUTPUT_CONTEXT_PROVIDER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "cc/base/cc_export.h" | 14 #include "cc/base/cc_export.h" |
15 #include "gpu/command_buffer/common/capabilities.h" | 15 #include "gpu/command_buffer/common/capabilities.h" |
16 | 16 |
17 class GrContext; | 17 class GrContext; |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class Lock; | 20 class Lock; |
21 } | 21 } |
22 | 22 |
23 namespace gpu { | 23 namespace gpu { |
24 class ContextSupport; | 24 class ContextSupport; |
25 namespace gles2 { class GLES2Interface; } | 25 namespace gles2 { class GLES2Interface; } |
26 } | 26 } |
27 | 27 |
28 namespace cc { | 28 namespace cc { |
| 29 class ContextCacheController; |
29 struct ManagedMemoryPolicy; | 30 struct ManagedMemoryPolicy; |
30 | 31 |
31 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { | 32 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { |
32 public: | 33 public: |
33 // Hold an instance of this lock while using a context across multiple | 34 // Hold an instance of this lock while using a context across multiple |
34 // threads. This only works for ContextProviders that will return a valid | 35 // threads. This only works for ContextProviders that will return a valid |
35 // lock from GetLock(), so is not always supported. Most use of | 36 // lock from GetLock(), so is not always supported. Most use of |
36 // ContextProvider should be single-thread only on the thread that | 37 // ContextProvider should be single-thread only on the thread that |
37 // BindToCurrentThread is run on. | 38 // BindToCurrentThread is run on. |
38 class ScopedContextLock { | 39 class ScopedContextLock { |
(...skipping 22 matching lines...) Expand all Loading... |
61 // accessing the contexts. Calling it more than once should have no effect. | 62 // accessing the contexts. Calling it more than once should have no effect. |
62 // Once this function has been called, the class should only be accessed | 63 // Once this function has been called, the class should only be accessed |
63 // from the same thread unless the function has some explicitly specified | 64 // from the same thread unless the function has some explicitly specified |
64 // rules for access on a different thread. See SetupLockOnMainThread(), which | 65 // rules for access on a different thread. See SetupLockOnMainThread(), which |
65 // can be used to provide access from multiple threads. | 66 // can be used to provide access from multiple threads. |
66 virtual bool BindToCurrentThread() = 0; | 67 virtual bool BindToCurrentThread() = 0; |
67 | 68 |
68 virtual gpu::gles2::GLES2Interface* ContextGL() = 0; | 69 virtual gpu::gles2::GLES2Interface* ContextGL() = 0; |
69 virtual gpu::ContextSupport* ContextSupport() = 0; | 70 virtual gpu::ContextSupport* ContextSupport() = 0; |
70 virtual class GrContext* GrContext() = 0; | 71 virtual class GrContext* GrContext() = 0; |
| 72 virtual ContextCacheController* CacheController() = 0; |
71 | 73 |
72 // Invalidates the cached OpenGL state in GrContext. | 74 // Invalidates the cached OpenGL state in GrContext. |
73 // See skia GrContext::resetContext for details. | 75 // See skia GrContext::resetContext for details. |
74 virtual void InvalidateGrContext(uint32_t state) = 0; | 76 virtual void InvalidateGrContext(uint32_t state) = 0; |
75 | 77 |
76 // Returns the capabilities of the currently bound 3d context. | 78 // Returns the capabilities of the currently bound 3d context. |
77 virtual gpu::Capabilities ContextCapabilities() = 0; | 79 virtual gpu::Capabilities ContextCapabilities() = 0; |
78 | 80 |
79 // Delete all cached gpu resources. | |
80 virtual void DeleteCachedResources() = 0; | |
81 | |
82 // Sets a callback to be called when the context is lost. This should be | 81 // Sets a callback to be called when the context is lost. This should be |
83 // called from the same thread that the context is bound to. To avoid races, | 82 // called from the same thread that the context is bound to. To avoid races, |
84 // it should be called before BindToCurrentThread(). | 83 // it should be called before BindToCurrentThread(). |
85 typedef base::Closure LostContextCallback; | 84 typedef base::Closure LostContextCallback; |
86 virtual void SetLostContextCallback( | 85 virtual void SetLostContextCallback( |
87 const LostContextCallback& lost_context_callback) = 0; | 86 const LostContextCallback& lost_context_callback) = 0; |
88 | 87 |
89 // Below are helper methods for ScopedContextLock. Use that instead of calling | 88 // Below are helper methods for ScopedContextLock. Use that instead of calling |
90 // these directly. | 89 // these directly. |
91 // | 90 // |
92 // Detaches debugging thread checkers to allow use of the provider from the | 91 // Detaches debugging thread checkers to allow use of the provider from the |
93 // current thread. This can be called on any thread. | 92 // current thread. This can be called on any thread. |
94 virtual void DetachFromThread() {} | 93 virtual void DetachFromThread() {} |
95 // Returns the lock that should be held if using this context from multiple | 94 // Returns the lock that should be held if using this context from multiple |
96 // threads. This can be called on any thread. | 95 // threads. This can be called on any thread. |
97 virtual base::Lock* GetLock() = 0; | 96 virtual base::Lock* GetLock() = 0; |
98 | 97 |
99 protected: | 98 protected: |
100 friend class base::RefCountedThreadSafe<ContextProvider>; | 99 friend class base::RefCountedThreadSafe<ContextProvider>; |
101 virtual ~ContextProvider() {} | 100 virtual ~ContextProvider() {} |
102 }; | 101 }; |
103 | 102 |
104 } // namespace cc | 103 } // namespace cc |
105 | 104 |
106 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ | 105 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ |
OLD | NEW |