| 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 "gpu/command_buffer/service/gl_utils.h" | 12 #include "gpu/command_buffer/common/value_state.h" |
| 13 #include "gpu/gpu_export.h" | 13 #include "gpu/gpu_export.h" |
| 14 | 14 |
| 15 namespace gpu { | 15 namespace gpu { |
| 16 namespace gles2 { | 16 namespace gles2 { |
| 17 | 17 |
| 18 class ValuebufferManager; | 18 class ValuebufferManager; |
| 19 | 19 |
| 20 union ValueState { | |
| 21 float float_value[4]; | |
| 22 int int_value[4]; | |
| 23 }; | |
| 24 | |
| 25 class GPU_EXPORT Valuebuffer : public base::RefCounted<Valuebuffer> { | 20 class GPU_EXPORT Valuebuffer : public base::RefCounted<Valuebuffer> { |
| 26 public: | 21 public: |
| 27 Valuebuffer(ValuebufferManager* manager, GLuint client_id); | 22 Valuebuffer(ValuebufferManager* manager, unsigned int client_id); |
| 28 | 23 |
| 29 GLuint client_id() const { return client_id_; } | 24 unsigned int client_id() const { return client_id_; } |
| 30 | 25 |
| 31 bool IsDeleted() const { return client_id_ == 0; } | 26 bool IsDeleted() const { return client_id_ == 0; } |
| 32 | 27 |
| 33 void MarkAsValid() { has_been_bound_ = true; } | 28 void MarkAsValid() { has_been_bound_ = true; } |
| 34 | 29 |
| 35 bool IsValid() const { return has_been_bound_ && !IsDeleted(); } | 30 bool IsValid() const { return has_been_bound_ && !IsDeleted(); } |
| 36 | 31 |
| 37 void AddSubscription(GLenum subscription); | 32 void AddSubscription(unsigned int subscription); |
| 38 void RemoveSubscription(GLenum subscription); | 33 void RemoveSubscription(unsigned int subscription); |
| 39 | 34 |
| 40 // Returns true if this Valuebuffer is subscribed to subscription | 35 // Returns true if this Valuebuffer is subscribed to subscription |
| 41 bool IsSubscribed(GLenum subscription); | 36 bool IsSubscribed(unsigned int subscription); |
| 42 | 37 |
| 43 // Returns the active state for a given target in this Valuebuffer | 38 // Returns the active state for a given target in this Valuebuffer |
| 44 // returns NULL if target state doesn't exist | 39 // returns NULL if target state doesn't exist |
| 45 const ValueState* GetState(GLenum target) const; | 40 const ValueState* GetState(unsigned int target) const; |
| 46 | 41 |
| 47 private: | 42 private: |
| 48 friend class ValuebufferManager; | 43 friend class ValuebufferManager; |
| 49 friend class base::RefCounted<Valuebuffer>; | 44 friend class base::RefCounted<Valuebuffer>; |
| 50 | 45 |
| 51 typedef base::hash_map<GLenum, ValueState> StateMap; | 46 typedef base::hash_map<unsigned int, ValueState> StateMap; |
| 52 typedef base::hash_set<GLenum> SubscriptionSet; | 47 typedef base::hash_set<unsigned int> SubscriptionSet; |
| 53 | 48 |
| 54 ~Valuebuffer(); | 49 ~Valuebuffer(); |
| 55 | 50 |
| 56 void UpdateState(const StateMap& pending_state); | 51 void UpdateState(const StateMap& pending_state); |
| 57 | 52 |
| 58 void MarkAsDeleted() { client_id_ = 0; } | 53 void MarkAsDeleted() { client_id_ = 0; } |
| 59 | 54 |
| 60 // ValuebufferManager that owns this Valuebuffer. | 55 // ValuebufferManager that owns this Valuebuffer. |
| 61 ValuebufferManager* manager_; | 56 ValuebufferManager* manager_; |
| 62 | 57 |
| 63 // Client side Valuebuffer id. | 58 // Client side Valuebuffer id. |
| 64 GLuint client_id_; | 59 unsigned int client_id_; |
| 65 | 60 |
| 66 // Whether this Valuebuffer has ever been bound. | 61 // Whether this Valuebuffer has ever been bound. |
| 67 bool has_been_bound_; | 62 bool has_been_bound_; |
| 68 | 63 |
| 69 SubscriptionSet subscriptions_; | 64 SubscriptionSet subscriptions_; |
| 70 | 65 |
| 71 StateMap active_state_map_; | 66 StateMap active_state_map_; |
| 72 }; | 67 }; |
| 73 | 68 |
| 74 class GPU_EXPORT ValuebufferManager { | 69 class GPU_EXPORT ValuebufferManager |
| 70 : public base::RefCounted<ValuebufferManager>{ |
| 75 public: | 71 public: |
| 76 ValuebufferManager(); | 72 ValuebufferManager(); |
| 77 ~ValuebufferManager(); | |
| 78 | |
| 79 // Must call before destruction. | |
| 80 void Destroy(); | |
| 81 | 73 |
| 82 // Creates a Valuebuffer for the given Valuebuffer ids. | 74 // Creates a Valuebuffer for the given Valuebuffer ids. |
| 83 void CreateValuebuffer(GLuint client_id); | 75 void CreateValuebuffer(unsigned int client_id); |
| 84 | 76 |
| 85 // Gets the Valuebuffer for the given Valuebuffer id. | 77 // Gets the Valuebuffer for the given Valuebuffer id. |
| 86 Valuebuffer* GetValuebuffer(GLuint client_id); | 78 Valuebuffer* GetValuebuffer(unsigned int client_id); |
| 87 | 79 |
| 88 // Removes a Valuebuffer for the given Valuebuffer id. | 80 // Removes a Valuebuffer for the given Valuebuffer id. |
| 89 void RemoveValuebuffer(GLuint client_id); | 81 void RemoveValuebuffer(unsigned int client_id); |
| 90 | 82 |
| 91 // Updates the value state for the given Valuebuffer | 83 // Updates the value state for the given Valuebuffer |
| 92 void UpdateValuebufferState(Valuebuffer* valuebuffer); | 84 void UpdateValuebufferState(Valuebuffer* valuebuffer); |
| 93 | 85 |
| 94 // Gets the state for the given subscription target | 86 // Gets the state for the given subscription target |
| 95 void UpdateValueState(GLenum target, const ValueState& state); | 87 void UpdateValueState(unsigned int target, const ValueState& state); |
| 96 | 88 |
| 97 static uint32 ApiTypeForSubscriptionTarget(GLenum target); | 89 // Gets the pending state for the given subscription target. |
| 90 // Visible for testing. |
| 91 const ValueState* GetPendingState(unsigned int target) const; |
| 92 |
| 93 static uint32 ApiTypeForSubscriptionTarget(unsigned int target); |
| 94 |
| 95 protected: |
| 96 virtual ~ValuebufferManager(); |
| 98 | 97 |
| 99 private: | 98 private: |
| 99 friend class base::RefCounted<ValuebufferManager>; |
| 100 friend class Valuebuffer; | 100 friend class Valuebuffer; |
| 101 | 101 |
| 102 typedef base::hash_map<GLuint, scoped_refptr<Valuebuffer>> ValuebufferMap; | 102 typedef base::hash_map<unsigned int, scoped_refptr<Valuebuffer>> |
| 103 ValuebufferMap; |
| 103 | 104 |
| 104 void StartTracking(Valuebuffer* valuebuffer); | 105 void StartTracking(Valuebuffer* valuebuffer); |
| 105 void StopTracking(Valuebuffer* valuebuffer); | 106 void StopTracking(Valuebuffer* valuebuffer); |
| 106 | 107 |
| 107 // Counts the number of Valuebuffer allocated with 'this' as its manager. | 108 // Counts the number of Valuebuffer allocated with 'this' as its manager. |
| 108 // Allows to check no Valuebuffer will outlive this. | 109 // Allows to check no Valuebuffer will outlive this. |
| 109 unsigned valuebuffer_count_; | 110 unsigned int valuebuffer_count_; |
| 110 | 111 |
| 111 // Info for each Valuebuffer in the system. | 112 // Info for each Valuebuffer in the system. |
| 112 ValuebufferMap valuebuffer_map_; | 113 ValuebufferMap valuebuffer_map_; |
| 113 | 114 |
| 114 // Current value state in the system | 115 // Current value state in the system |
| 115 Valuebuffer::StateMap pending_state_map_; | 116 Valuebuffer::StateMap pending_state_map_; |
| 116 | 117 |
| 117 DISALLOW_COPY_AND_ASSIGN(ValuebufferManager); | 118 DISALLOW_COPY_AND_ASSIGN(ValuebufferManager); |
| 118 }; | 119 }; |
| 119 | 120 |
| 120 } // namespace gles2 | 121 } // namespace gles2 |
| 121 } // namespace gpu | 122 } // namespace gpu |
| 122 | 123 |
| 123 #endif // GPU_COMMAND_BUFFER_SERVICE_VALUEBUFFER_MANAGER_H_ | 124 #endif // GPU_COMMAND_BUFFER_SERVICE_VALUEBUFFER_MANAGER_H_ |
| OLD | NEW |