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 "cc/output/context_cache_controller.h" | |
16 #include "gpu/command_buffer/common/capabilities.h" | 15 #include "gpu/command_buffer/common/capabilities.h" |
17 | 16 |
18 class GrContext; | 17 class GrContext; |
19 | 18 |
20 namespace base { | 19 namespace base { |
21 class Lock; | 20 class Lock; |
22 } | 21 } |
23 | 22 |
24 namespace gpu { | 23 namespace gpu { |
25 class ContextSupport; | 24 class ContextSupport; |
26 namespace gles2 { class GLES2Interface; } | 25 namespace gles2 { class GLES2Interface; } |
27 } | 26 } |
28 | 27 |
29 namespace cc { | 28 namespace cc { |
| 29 class ContextCacheController; |
30 struct ManagedMemoryPolicy; | 30 struct ManagedMemoryPolicy; |
31 | 31 |
32 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { | 32 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { |
33 public: | 33 public: |
34 // 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 |
35 // threads. This only works for ContextProviders that will return a valid | 35 // threads. This only works for ContextProviders that will return a valid |
36 // lock from GetLock(), so is not always supported. Most use of | 36 // lock from GetLock(), so is not always supported. Most use of |
37 // ContextProvider should be single-thread only on the thread that | 37 // ContextProvider should be single-thread only on the thread that |
38 // BindToCurrentThread is run on. | 38 // BindToCurrentThread is run on. |
39 class CC_EXPORT ScopedContextLock { | 39 class ScopedContextLock { |
40 public: | 40 public: |
41 explicit ScopedContextLock(ContextProvider* context_provider); | 41 explicit ScopedContextLock(ContextProvider* context_provider) |
42 ~ScopedContextLock(); | 42 : context_provider_(context_provider), |
| 43 context_lock_(*context_provider_->GetLock()) { |
| 44 // Allow current thread to use |context_provider_|. |
| 45 context_provider_->DetachFromThread(); |
| 46 } |
| 47 ~ScopedContextLock() { |
| 48 // Allow usage by thread for which |context_provider_| is bound to. |
| 49 context_provider_->DetachFromThread(); |
| 50 } |
43 | 51 |
44 gpu::gles2::GLES2Interface* ContextGL() { | 52 gpu::gles2::GLES2Interface* ContextGL() { |
45 return context_provider_->ContextGL(); | 53 return context_provider_->ContextGL(); |
46 } | 54 } |
47 | 55 |
48 private: | 56 private: |
49 ContextProvider* const context_provider_; | 57 ContextProvider* const context_provider_; |
50 base::AutoLock context_lock_; | 58 base::AutoLock context_lock_; |
51 std::unique_ptr<ContextCacheController::ScopedBusy> busy_; | |
52 }; | 59 }; |
53 | 60 |
54 // Bind the 3d context to the current thread. This should be called before | 61 // Bind the 3d context to the current thread. This should be called before |
55 // 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. |
56 // 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 |
57 // from the same thread unless the function has some explicitly specified | 64 // from the same thread unless the function has some explicitly specified |
58 // rules for access on a different thread. See SetupLockOnMainThread(), which | 65 // rules for access on a different thread. See SetupLockOnMainThread(), which |
59 // can be used to provide access from multiple threads. | 66 // can be used to provide access from multiple threads. |
60 virtual bool BindToCurrentThread() = 0; | 67 virtual bool BindToCurrentThread() = 0; |
61 | 68 |
(...skipping 27 matching lines...) Expand all Loading... |
89 virtual base::Lock* GetLock() = 0; | 96 virtual base::Lock* GetLock() = 0; |
90 | 97 |
91 protected: | 98 protected: |
92 friend class base::RefCountedThreadSafe<ContextProvider>; | 99 friend class base::RefCountedThreadSafe<ContextProvider>; |
93 virtual ~ContextProvider() {} | 100 virtual ~ContextProvider() {} |
94 }; | 101 }; |
95 | 102 |
96 } // namespace cc | 103 } // namespace cc |
97 | 104 |
98 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ | 105 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ |
OLD | NEW |