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