| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 GPU_COMMAND_BUFFER_SERVICE_VALUEBUFFER_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_VALUEBUFFER_MANAGER_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_VALUEBUFFER_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_VALUEBUFFER_MANAGER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/observer_list.h" |
| 12 #include "gpu/command_buffer/common/value_state.h" | 13 #include "gpu/command_buffer/common/value_state.h" |
| 13 #include "gpu/gpu_export.h" | 14 #include "gpu/gpu_export.h" |
| 14 | 15 |
| 16 namespace content { |
| 17 class GpuChannel; |
| 18 } |
| 19 |
| 15 namespace gpu { | 20 namespace gpu { |
| 16 namespace gles2 { | 21 namespace gles2 { |
| 17 | 22 |
| 18 class ValuebufferManager; | 23 class ValuebufferManager; |
| 19 | 24 |
| 25 class GPU_EXPORT SubscriptionRefSet |
| 26 : public base::RefCounted<SubscriptionRefSet> { |
| 27 public: |
| 28 class GPU_EXPORT Observer { |
| 29 public: |
| 30 virtual ~Observer(); |
| 31 |
| 32 virtual void OnAddSubscription(unsigned int target) = 0; |
| 33 virtual void OnRemoveSubscription(unsigned int target) = 0; |
| 34 }; |
| 35 |
| 36 SubscriptionRefSet(); |
| 37 |
| 38 void AddObserver(Observer* observer); |
| 39 void RemoveObserver(Observer* observer); |
| 40 |
| 41 protected: |
| 42 virtual ~SubscriptionRefSet(); |
| 43 |
| 44 private: |
| 45 friend class base::RefCounted<SubscriptionRefSet>; |
| 46 friend class ValuebufferManager; |
| 47 |
| 48 typedef base::hash_map<unsigned int, int> RefSet; |
| 49 |
| 50 void AddSubscription(unsigned int target); |
| 51 void RemoveSubscription(unsigned int target); |
| 52 |
| 53 RefSet reference_set_; |
| 54 |
| 55 ObserverList<Observer, true> observers_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(SubscriptionRefSet); |
| 58 }; |
| 59 |
| 20 class GPU_EXPORT Valuebuffer : public base::RefCounted<Valuebuffer> { | 60 class GPU_EXPORT Valuebuffer : public base::RefCounted<Valuebuffer> { |
| 21 public: | 61 public: |
| 22 Valuebuffer(ValuebufferManager* manager, unsigned int client_id); | 62 Valuebuffer(ValuebufferManager* manager, unsigned int client_id); |
| 23 | 63 |
| 24 unsigned int client_id() const { return client_id_; } | 64 unsigned int client_id() const { return client_id_; } |
| 25 | 65 |
| 26 bool IsDeleted() const { return client_id_ == 0; } | 66 bool IsDeleted() const { return client_id_ == 0; } |
| 27 | 67 |
| 28 void MarkAsValid() { has_been_bound_ = true; } | 68 void MarkAsValid() { has_been_bound_ = true; } |
| 29 | 69 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 60 // Whether this Valuebuffer has ever been bound. | 100 // Whether this Valuebuffer has ever been bound. |
| 61 bool has_been_bound_; | 101 bool has_been_bound_; |
| 62 | 102 |
| 63 SubscriptionSet subscriptions_; | 103 SubscriptionSet subscriptions_; |
| 64 | 104 |
| 65 scoped_refptr<ValueStateMap> active_state_map_; | 105 scoped_refptr<ValueStateMap> active_state_map_; |
| 66 }; | 106 }; |
| 67 | 107 |
| 68 class GPU_EXPORT ValuebufferManager { | 108 class GPU_EXPORT ValuebufferManager { |
| 69 public: | 109 public: |
| 70 ValuebufferManager(ValueStateMap* state_map); | 110 ValuebufferManager(SubscriptionRefSet* ref_set, ValueStateMap* state_map); |
| 71 ~ValuebufferManager(); | 111 ~ValuebufferManager(); |
| 72 | 112 |
| 73 // Must call before destruction. | 113 // Must call before destruction. |
| 74 void Destroy(); | 114 void Destroy(); |
| 75 | 115 |
| 76 // Creates a Valuebuffer for the given Valuebuffer ids. | 116 // Creates a Valuebuffer for the given Valuebuffer ids. |
| 77 void CreateValuebuffer(unsigned int client_id); | 117 void CreateValuebuffer(unsigned int client_id); |
| 78 | 118 |
| 79 // Gets the Valuebuffer for the given Valuebuffer id. | 119 // Gets the Valuebuffer for the given Valuebuffer id. |
| 80 Valuebuffer* GetValuebuffer(unsigned int client_id); | 120 Valuebuffer* GetValuebuffer(unsigned int client_id); |
| 81 | 121 |
| 82 // Removes a Valuebuffer for the given Valuebuffer id. | 122 // Removes a Valuebuffer for the given Valuebuffer id. |
| 83 void RemoveValuebuffer(unsigned int client_id); | 123 void RemoveValuebuffer(unsigned int client_id); |
| 84 | 124 |
| 85 // Updates the value state for the given Valuebuffer | 125 // Updates the value state for the given Valuebuffer |
| 86 void UpdateValuebufferState(Valuebuffer* valuebuffer); | 126 void UpdateValuebufferState(Valuebuffer* valuebuffer); |
| 87 | 127 |
| 88 static uint32 ApiTypeForSubscriptionTarget(unsigned int target); | 128 static uint32 ApiTypeForSubscriptionTarget(unsigned int target); |
| 89 | 129 |
| 90 private: | 130 private: |
| 91 friend class Valuebuffer; | 131 friend class Valuebuffer; |
| 92 | 132 |
| 93 typedef base::hash_map<unsigned int, scoped_refptr<Valuebuffer>> | 133 typedef base::hash_map<unsigned int, scoped_refptr<Valuebuffer>> |
| 94 ValuebufferMap; | 134 ValuebufferMap; |
| 95 | 135 |
| 96 void StartTracking(Valuebuffer* valuebuffer); | 136 void StartTracking(Valuebuffer* valuebuffer); |
| 97 void StopTracking(Valuebuffer* valuebuffer); | 137 void StopTracking(Valuebuffer* valuebuffer); |
| 98 | 138 |
| 139 void NotifyAddSubscription(unsigned int target); |
| 140 void NotifyRemoveSubscription(unsigned int target); |
| 141 |
| 99 // Counts the number of Valuebuffer allocated with 'this' as its manager. | 142 // Counts the number of Valuebuffer allocated with 'this' as its manager. |
| 100 // Allows to check no Valuebuffer will outlive this. | 143 // Allows to check no Valuebuffer will outlive this. |
| 101 unsigned int valuebuffer_count_; | 144 unsigned int valuebuffer_count_; |
| 102 | 145 |
| 103 // Info for each Valuebuffer in the system. | 146 // Info for each Valuebuffer in the system. |
| 104 ValuebufferMap valuebuffer_map_; | 147 ValuebufferMap valuebuffer_map_; |
| 105 | 148 |
| 106 // Current value state in the system | 149 // Current value state in the system |
| 107 // Updated by GpuChannel | 150 // Updated by GpuChannel |
| 108 scoped_refptr<ValueStateMap> pending_state_map_; | 151 scoped_refptr<ValueStateMap> pending_state_map_; |
| 109 | 152 |
| 153 // Subscription targets which are currently subscribed and how |
| 154 // many value buffers are currently subscribed to each |
| 155 scoped_refptr<SubscriptionRefSet> subscription_ref_set_; |
| 156 |
| 110 DISALLOW_COPY_AND_ASSIGN(ValuebufferManager); | 157 DISALLOW_COPY_AND_ASSIGN(ValuebufferManager); |
| 111 }; | 158 }; |
| 112 | 159 |
| 113 } // namespace gles2 | 160 } // namespace gles2 |
| 114 } // namespace gpu | 161 } // namespace gpu |
| 115 | 162 |
| 116 #endif // GPU_COMMAND_BUFFER_SERVICE_VALUEBUFFER_MANAGER_H_ | 163 #endif // GPU_COMMAND_BUFFER_SERVICE_VALUEBUFFER_MANAGER_H_ |
| OLD | NEW |