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