Chromium Code Reviews| Index: gpu/command_buffer/service/valuebuffer_manager.h |
| diff --git a/gpu/command_buffer/service/valuebuffer_manager.h b/gpu/command_buffer/service/valuebuffer_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c339c160d787b7879bd16704ff5e71bdcb6399fe |
| --- /dev/null |
| +++ b/gpu/command_buffer/service/valuebuffer_manager.h |
| @@ -0,0 +1,162 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef GPU_COMMAND_BUFFER_SERVICE_VALUEBUFFER_MANAGER_H_ |
| +#define GPU_COMMAND_BUFFER_SERVICE_VALUEBUFFER_MANAGER_H_ |
| + |
| +#include <set> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/containers/hash_tables.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "gpu/command_buffer/service/gl_utils.h" |
| +#include "gpu/gpu_export.h" |
| + |
| +namespace gpu { |
| +namespace gles2 { |
| + |
| +class ValuebufferManager; |
| + |
| +class ValueState : public base::RefCounted<ValueState> { |
| + public: |
| + ValueState(GLenum target); |
| + |
| + GLenum target() const { return target_; } |
| + |
| + protected: |
| + virtual ~ValueState() = 0; |
| + |
| + private: |
| + friend class base::RefCounted<ValueState>; |
| + |
| + GLenum target_; |
|
piman
2014/11/04 02:38:22
You only use target_ for ValuebufferManager::Updat
orglofch
2014/11/04 19:53:28
Done.
|
| +}; |
| + |
| +class IntValueState : public ValueState { |
|
orglofch
2014/11/04 01:30:06
It would be nice to simply store a void* data memb
piman
2014/11/04 02:38:22
My suggestion: given that the number of elements i
orglofch
2014/11/04 19:53:29
Nice, I didn't know about unions! Done.
|
| + public: |
| + IntValueState(GLenum target, GLint* data); |
| + |
| + const GLint* data() const { return data_.get(); } |
| + |
| + private: |
| + ~IntValueState(); |
| + |
| + scoped_ptr<GLint[]> data_; |
| +}; |
| + |
| +class FloatValueState : public ValueState { |
| + public: |
| + FloatValueState(GLenum target, GLfloat* data); |
| + |
| + const GLfloat* data() const { return data_.get(); } |
| + |
| + private: |
| + ~FloatValueState(); |
| + |
| + scoped_ptr<GLfloat[]> data_; |
| +}; |
| + |
| +class GPU_EXPORT Valuebuffer : public base::RefCounted<Valuebuffer> { |
| + public: |
| + typedef base::hash_map<GLenum, scoped_refptr<ValueState>> StateMap; |
| + |
| + Valuebuffer(ValuebufferManager* manager, GLuint client_id); |
| + |
| + GLuint client_id() const { return client_id_; } |
| + |
| + bool IsDeleted() const { return client_id_ == 0; } |
| + |
| + void MarkAsValid() { has_been_bound_ = true; } |
| + |
| + bool IsValid() const { return has_been_bound_ && !IsDeleted(); } |
| + |
| + void AddSubscription(GLenum subscription); |
| + void RemoveSubscription(GLenum subscription); |
| + |
| + // Returns true if this Valuebuffer is subscribed to subscription |
| + bool IsSubscribed(GLenum subscription); |
| + |
| + // Returns the active state for a given target in this Valuebuffer |
| + // returns NULL if target state doesn't exist |
| + const ValueState* GetState(GLenum target) const; |
| + |
| + private: |
| + friend class ValuebufferManager; |
| + friend class base::RefCounted<Valuebuffer>; |
| + |
| + typedef std::set<GLenum> SubscriptionSet; |
|
piman
2014/11/04 02:38:22
nit: make this a hash_set, since you don't care ab
orglofch
2014/11/04 19:53:29
Done. I'll leave it as a hash_set to it's more ext
|
| + |
| + ~Valuebuffer(); |
| + |
| + void UpdateState(const StateMap& pending_state); |
| + |
| + void MarkAsDeleted() { client_id_ = 0; } |
| + |
| + // ValuebufferManager that owns this Valuebuffer. |
| + ValuebufferManager* manager_; |
| + |
| + // Client side Valuebuffer id. |
| + GLuint client_id_; |
| + |
| + // Whether this Valuebuffer has ever been bound. |
| + bool has_been_bound_; |
| + |
| + SubscriptionSet subscriptions_; |
| + |
| + StateMap active_state_map_; |
| +}; |
| + |
| +class GPU_EXPORT ValuebufferManager { |
| + public: |
| + ValuebufferManager(); |
| + ~ValuebufferManager(); |
| + |
| + // Must call before destruction. |
| + void Destroy(bool have_context); |
| + |
| + // Creates a Valuebuffer for the given Valuebuffer ids. |
| + void CreateValuebuffer(GLuint client_id); |
| + |
| + // Gets the Valuebuffer for the given Valuebuffer id. |
| + Valuebuffer* GetValuebuffer(GLuint client_id); |
| + |
| + // Removes a Valuebuffer for the given Valuebuffer id. |
| + void RemoveValuebuffer(GLuint client_id); |
| + |
| + // Updates the value state for the given Valuebuffer |
| + void UpdateValuebufferState(GLuint client_id); |
| + |
| + // Gets the state for the given subscription target |
| + void UpdateValueState(ValueState* state); |
| + |
| + static uint32 ApiTypeForSubscriptionTarget(GLenum target); |
| + |
| + private: |
| + friend class Valuebuffer; |
| + |
| + typedef base::hash_map<GLuint, scoped_refptr<Valuebuffer>> ValuebufferMap; |
| + |
| + void StartTracking(Valuebuffer* valuebuffer); |
| + void StopTracking(Valuebuffer* valuebuffer); |
| + |
| + // Counts the number of Valuebuffer allocated with 'this' as its manager. |
| + // Allows to check no Valuebuffer will outlive this. |
| + unsigned valuebuffer_count_; |
| + |
| + bool have_context_; |
| + |
| + // Info for each Valuebuffer in the system. |
| + ValuebufferMap valuebuffer_map_; |
| + |
| + // Current value state in the system |
| + Valuebuffer::StateMap pending_state_map_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ValuebufferManager); |
| +}; |
| + |
| +} // namespace gles2 |
| +} // namespace gpu |
| + |
| +#endif // GPU_COMMAND_BUFFER_SERVICE_VALUEBUFFER_MANAGER_H_ |