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 "base/synchronization/lock.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 namespace cc { | 25 namespace cc { |
26 struct ManagedMemoryPolicy; | 26 struct ManagedMemoryPolicy; |
27 | 27 |
28 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { | 28 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { |
29 public: | 29 public: |
30 class ScopedContextLock { | 30 class ScopedContextLock { |
31 public: | 31 public: |
32 explicit ScopedContextLock(ContextProvider* context_provider) | 32 explicit ScopedContextLock(ContextProvider* context_provider) |
33 : context_provider_(context_provider), | 33 : context_provider_(context_provider), |
34 context_lock_(*context_provider_->GetLock()) { | 34 context_lock_(*context_provider_->GetLock()) { |
35 // Allow current thread to bind to |context_provider|. | 35 // Allow current thread to use |context_provider_|. |
36 context_provider_->DetachFromThread(); | 36 context_provider_->DetachFromThread(); |
37 } | 37 } |
38 ~ScopedContextLock() { | 38 ~ScopedContextLock() { |
39 // Allow a different thread to bind to |context_provider|. | 39 // Allow usage by thread for which |context_provider_| is bound to. |
40 context_provider_->DetachFromThread(); | 40 context_provider_->DetachFromThread(); |
41 } | 41 } |
42 | 42 |
43 // Returns a raw pointer to the GLES2Interface or null if context has been | |
44 // destroyed. | |
43 gpu::gles2::GLES2Interface* ContextGL() { | 45 gpu::gles2::GLES2Interface* ContextGL() { |
44 return context_provider_->ContextGL(); | 46 return context_provider_->HasBeenDestroyed() |
47 ? nullptr | |
48 : context_provider_->ContextGL(); | |
45 } | 49 } |
46 | 50 |
47 private: | 51 private: |
48 ContextProvider* const context_provider_; | 52 ContextProvider* const context_provider_; |
49 base::AutoLock context_lock_; | 53 base::AutoLock context_lock_; |
50 }; | 54 }; |
51 // Bind the 3d context to the current thread. This should be called before | 55 // 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. | 56 // 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 | 57 // Once this function has been called, the class should only be accessed |
54 // from the same thread. | 58 // from the same thread. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 virtual void SetLostContextCallback( | 104 virtual void SetLostContextCallback( |
101 const LostContextCallback& lost_context_callback) = 0; | 105 const LostContextCallback& lost_context_callback) = 0; |
102 | 106 |
103 // Sets a callback to be called when the memory policy changes. This should be | 107 // 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. | 108 // called from the same thread that the context is bound to. |
105 typedef base::Callback<void(const ManagedMemoryPolicy& policy)> | 109 typedef base::Callback<void(const ManagedMemoryPolicy& policy)> |
106 MemoryPolicyChangedCallback; | 110 MemoryPolicyChangedCallback; |
107 virtual void SetMemoryPolicyChangedCallback( | 111 virtual void SetMemoryPolicyChangedCallback( |
108 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0; | 112 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0; |
109 | 113 |
114 // Return true if the context inside the provider is no longer valid. | |
danakj
2015/09/04 18:28:07
Can we maybe make this clear that this function is
reveman
2015/09/04 18:55:50
I prefer to have this function be consistent with
danakj
2015/09/04 20:02:15
My concern is that this adds a whole other state t
| |
115 virtual bool HasBeenDestroyed() = 0; | |
116 | |
110 protected: | 117 protected: |
111 friend class base::RefCountedThreadSafe<ContextProvider>; | 118 friend class base::RefCountedThreadSafe<ContextProvider>; |
112 virtual ~ContextProvider() {} | 119 virtual ~ContextProvider() {} |
113 }; | 120 }; |
114 | 121 |
115 } // namespace cc | 122 } // namespace cc |
116 | 123 |
117 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ | 124 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ |
OLD | NEW |