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