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 "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/synchronization/lock.h" | |
11 #include "cc/base/cc_export.h" | 10 #include "cc/base/cc_export.h" |
12 #include "gpu/command_buffer/common/capabilities.h" | 11 #include "gpu/command_buffer/common/capabilities.h" |
13 | 12 |
14 class GrContext; | 13 class GrContext; |
15 | 14 |
16 namespace base { | 15 namespace base { |
17 class Lock; | 16 class Lock; |
18 } | 17 } |
19 | 18 |
20 namespace gpu { | 19 namespace gpu { |
21 class ContextSupport; | 20 class ContextSupport; |
22 namespace gles2 { class GLES2Interface; } | 21 namespace gles2 { class GLES2Interface; } |
23 } | 22 } |
24 | 23 |
25 namespace cc { | 24 namespace cc { |
26 struct ManagedMemoryPolicy; | 25 struct ManagedMemoryPolicy; |
27 | 26 |
28 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { | 27 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { |
29 public: | 28 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(); | |
37 } | |
38 ~ScopedContextLock() { | |
39 // Allow a different thread to bind to |context_provider|. | |
40 context_provider_->DetachFromThread(); | |
41 } | |
42 | |
43 gpu::gles2::GLES2Interface* ContextGL() { | |
44 return context_provider_->ContextGL(); | |
45 } | |
46 | |
47 private: | |
48 ContextProvider* const context_provider_; | |
49 base::AutoLock context_lock_; | |
50 }; | |
51 // Bind the 3d context to the current thread. This should be called before | 29 // 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. | 30 // 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 | 31 // Once this function has been called, the class should only be accessed |
54 // from the same thread. | 32 // from the same thread. |
55 virtual bool BindToCurrentThread() = 0; | 33 virtual bool BindToCurrentThread() = 0; |
56 virtual void DetachFromThread() {} | 34 virtual void DetachFromThread() {} |
57 | 35 |
58 virtual gpu::gles2::GLES2Interface* ContextGL() = 0; | 36 virtual gpu::gles2::GLES2Interface* ContextGL() = 0; |
59 virtual gpu::ContextSupport* ContextSupport() = 0; | 37 virtual gpu::ContextSupport* ContextSupport() = 0; |
60 virtual class GrContext* GrContext() = 0; | 38 virtual class GrContext* GrContext() = 0; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0; | 86 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0; |
109 | 87 |
110 protected: | 88 protected: |
111 friend class base::RefCountedThreadSafe<ContextProvider>; | 89 friend class base::RefCountedThreadSafe<ContextProvider>; |
112 virtual ~ContextProvider() {} | 90 virtual ~ContextProvider() {} |
113 }; | 91 }; |
114 | 92 |
115 } // namespace cc | 93 } // namespace cc |
116 | 94 |
117 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ | 95 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ |
OLD | NEW |