| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BUFFER_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "gpu/command_buffer/service/gl_utils.h" | 14 #include "gpu/command_buffer/service/gl_utils.h" |
| 15 #include "gpu/command_buffer/service/memory_tracking.h" | 15 #include "gpu/command_buffer/service/memory_tracking.h" |
| 16 #include "gpu/gpu_export.h" | 16 #include "gpu/gpu_export.h" |
| 17 | 17 |
| 18 namespace gpu { | 18 namespace gpu { |
| 19 namespace gles2 { | 19 namespace gles2 { |
| 20 | 20 |
| 21 class BufferManager; | 21 class BufferManager; |
| 22 class FeatureInfo; |
| 22 | 23 |
| 23 // Info about Buffers currently in the system. | 24 // Info about Buffers currently in the system. |
| 24 class GPU_EXPORT Buffer : public base::RefCounted<Buffer> { | 25 class GPU_EXPORT Buffer : public base::RefCounted<Buffer> { |
| 25 public: | 26 public: |
| 26 Buffer(BufferManager* manager, GLuint service_id); | 27 Buffer(BufferManager* manager, GLuint service_id); |
| 27 | 28 |
| 28 GLuint service_id() const { | 29 GLuint service_id() const { |
| 29 return service_id_; | 30 return service_id_; |
| 30 } | 31 } |
| 31 | 32 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 53 const void* GetRange(GLintptr offset, GLsizeiptr size) const; | 54 const void* GetRange(GLintptr offset, GLsizeiptr size) const; |
| 54 | 55 |
| 55 bool IsDeleted() const { | 56 bool IsDeleted() const { |
| 56 return deleted_; | 57 return deleted_; |
| 57 } | 58 } |
| 58 | 59 |
| 59 bool IsValid() const { | 60 bool IsValid() const { |
| 60 return target() && !IsDeleted(); | 61 return target() && !IsDeleted(); |
| 61 } | 62 } |
| 62 | 63 |
| 64 bool IsClientSideArray() const { |
| 65 return is_client_side_array_; |
| 66 } |
| 67 |
| 63 private: | 68 private: |
| 64 friend class BufferManager; | 69 friend class BufferManager; |
| 65 friend class BufferManagerTestBase; | 70 friend class BufferManagerTestBase; |
| 66 friend class base::RefCounted<Buffer>; | 71 friend class base::RefCounted<Buffer>; |
| 67 | 72 |
| 68 // Represents a range in a buffer. | 73 // Represents a range in a buffer. |
| 69 class Range { | 74 class Range { |
| 70 public: | 75 public: |
| 71 Range(GLuint offset, GLsizei count, GLenum type) | 76 Range(GLuint offset, GLsizei count, GLenum type) |
| 72 : offset_(offset), | 77 : offset_(offset), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 110 } |
| 106 | 111 |
| 107 bool shadowed() const { | 112 bool shadowed() const { |
| 108 return shadowed_; | 113 return shadowed_; |
| 109 } | 114 } |
| 110 | 115 |
| 111 void MarkAsDeleted() { | 116 void MarkAsDeleted() { |
| 112 deleted_ = true; | 117 deleted_ = true; |
| 113 } | 118 } |
| 114 | 119 |
| 115 void SetInfo(GLsizeiptr size, GLenum usage, bool shadow); | 120 // Sets the size, usage and initial data of a buffer. |
| 121 // If shadow is true then if data is NULL buffer will be initialized to 0. |
| 122 void SetInfo( |
| 123 GLsizeiptr size, GLenum usage, bool shadow, const GLvoid* data, |
| 124 bool is_client_side_array); |
| 116 | 125 |
| 117 // Clears any cache of index ranges. | 126 // Clears any cache of index ranges. |
| 118 void ClearCache(); | 127 void ClearCache(); |
| 119 | 128 |
| 120 // Check if an offset, size range is valid for the current buffer. | 129 // Check if an offset, size range is valid for the current buffer. |
| 121 bool CheckRange(GLintptr offset, GLsizeiptr size) const; | 130 bool CheckRange(GLintptr offset, GLsizeiptr size) const; |
| 122 | 131 |
| 123 // The manager that owns this Buffer. | 132 // The manager that owns this Buffer. |
| 124 BufferManager* manager_; | 133 BufferManager* manager_; |
| 125 | 134 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 136 | 145 |
| 137 // Size of buffer. | 146 // Size of buffer. |
| 138 GLsizeiptr size_; | 147 GLsizeiptr size_; |
| 139 | 148 |
| 140 // Usage of buffer. | 149 // Usage of buffer. |
| 141 GLenum usage_; | 150 GLenum usage_; |
| 142 | 151 |
| 143 // Whether or not the data is shadowed. | 152 // Whether or not the data is shadowed. |
| 144 bool shadowed_; | 153 bool shadowed_; |
| 145 | 154 |
| 155 // Whether or not this Buffer is not uploaded to the GPU but just |
| 156 // sitting in local memory. |
| 157 bool is_client_side_array_; |
| 158 |
| 146 // A copy of the data in the buffer. This data is only kept if the target | 159 // A copy of the data in the buffer. This data is only kept if the target |
| 147 // is backed_ = true. | 160 // is backed_ = true. |
| 148 scoped_array<int8> shadow_; | 161 scoped_array<int8> shadow_; |
| 149 | 162 |
| 150 // A map of ranges to the highest value in that range of a certain type. | 163 // A map of ranges to the highest value in that range of a certain type. |
| 151 typedef std::map<Range, GLuint, Range::Less> RangeToMaxValueMap; | 164 typedef std::map<Range, GLuint, Range::Less> RangeToMaxValueMap; |
| 152 RangeToMaxValueMap range_set_; | 165 RangeToMaxValueMap range_set_; |
| 153 }; | 166 }; |
| 154 | 167 |
| 155 // This class keeps track of the buffers and their sizes so we can do | 168 // This class keeps track of the buffers and their sizes so we can do |
| 156 // bounds checking. | 169 // bounds checking. |
| 157 // | 170 // |
| 158 // NOTE: To support shared resources an instance of this class will need to be | 171 // NOTE: To support shared resources an instance of this class will need to be |
| 159 // shared by multiple GLES2Decoders. | 172 // shared by multiple GLES2Decoders. |
| 160 class GPU_EXPORT BufferManager { | 173 class GPU_EXPORT BufferManager { |
| 161 public: | 174 public: |
| 162 BufferManager(MemoryTracker* memory_tracker); | 175 BufferManager(MemoryTracker* memory_tracker, FeatureInfo* feature_info); |
| 163 ~BufferManager(); | 176 ~BufferManager(); |
| 164 | 177 |
| 165 // Must call before destruction. | 178 // Must call before destruction. |
| 166 void Destroy(bool have_context); | 179 void Destroy(bool have_context); |
| 167 | 180 |
| 168 // Creates a Buffer for the given buffer. | 181 // Creates a Buffer for the given buffer. |
| 169 void CreateBuffer(GLuint client_id, GLuint service_id); | 182 void CreateBuffer(GLuint client_id, GLuint service_id); |
| 170 | 183 |
| 171 // Gets the buffer info for the given buffer. | 184 // Gets the buffer info for the given buffer. |
| 172 Buffer* GetBuffer(GLuint client_id); | 185 Buffer* GetBuffer(GLuint client_id); |
| 173 | 186 |
| 174 // Removes a buffer info for the given buffer. | 187 // Removes a buffer info for the given buffer. |
| 175 void RemoveBuffer(GLuint client_id); | 188 void RemoveBuffer(GLuint client_id); |
| 176 | 189 |
| 177 // Gets a client id for a given service id. | 190 // Gets a client id for a given service id. |
| 178 bool GetClientId(GLuint service_id, GLuint* client_id) const; | 191 bool GetClientId(GLuint service_id, GLuint* client_id) const; |
| 179 | 192 |
| 180 // Sets the size and usage of a buffer. | 193 // Sets the size, usage and initial data of a buffer. |
| 181 void SetInfo(Buffer* info, GLsizeiptr size, GLenum usage); | 194 // If data is NULL buffer will be initialized to 0 if shadowed. |
| 195 void SetInfo(Buffer* info, GLsizeiptr size, GLenum usage, const GLvoid* data); |
| 182 | 196 |
| 183 // Sets the target of a buffer. Returns false if the target can not be set. | 197 // Sets the target of a buffer. Returns false if the target can not be set. |
| 184 bool SetTarget(Buffer* info, GLenum target); | 198 bool SetTarget(Buffer* info, GLenum target); |
| 185 | 199 |
| 186 void set_allow_buffers_on_multiple_targets(bool allow) { | 200 void set_allow_buffers_on_multiple_targets(bool allow) { |
| 187 allow_buffers_on_multiple_targets_ = allow; | 201 allow_buffers_on_multiple_targets_ = allow; |
| 188 } | 202 } |
| 189 | 203 |
| 190 size_t mem_represented() const { | 204 size_t mem_represented() const { |
| 191 return memory_tracker_->GetMemRepresented(); | 205 return memory_tracker_->GetMemRepresented(); |
| 192 } | 206 } |
| 193 | 207 |
| 194 private: | 208 private: |
| 195 friend class Buffer; | 209 friend class Buffer; |
| 196 void StartTracking(Buffer* info); | 210 void StartTracking(Buffer* info); |
| 197 void StopTracking(Buffer* info); | 211 void StopTracking(Buffer* info); |
| 198 | 212 |
| 199 scoped_ptr<MemoryTypeTracker> memory_tracker_; | 213 scoped_ptr<MemoryTypeTracker> memory_tracker_; |
| 214 scoped_refptr<FeatureInfo> feature_info_; |
| 200 | 215 |
| 201 // Info for each buffer in the system. | 216 // Info for each buffer in the system. |
| 202 typedef base::hash_map<GLuint, scoped_refptr<Buffer> > BufferInfoMap; | 217 typedef base::hash_map<GLuint, scoped_refptr<Buffer> > BufferInfoMap; |
| 203 BufferInfoMap buffer_infos_; | 218 BufferInfoMap buffer_infos_; |
| 204 | 219 |
| 205 // Whether or not buffers can be bound to multiple targets. | 220 // Whether or not buffers can be bound to multiple targets. |
| 206 bool allow_buffers_on_multiple_targets_; | 221 bool allow_buffers_on_multiple_targets_; |
| 207 | 222 |
| 208 // Counts the number of Buffer allocated with 'this' as its manager. | 223 // Counts the number of Buffer allocated with 'this' as its manager. |
| 209 // Allows to check no Buffer will outlive this. | 224 // Allows to check no Buffer will outlive this. |
| 210 unsigned int buffer_info_count_; | 225 unsigned int buffer_info_count_; |
| 211 | 226 |
| 212 bool have_context_; | 227 bool have_context_; |
| 213 | 228 |
| 214 DISALLOW_COPY_AND_ASSIGN(BufferManager); | 229 DISALLOW_COPY_AND_ASSIGN(BufferManager); |
| 215 }; | 230 }; |
| 216 | 231 |
| 217 } // namespace gles2 | 232 } // namespace gles2 |
| 218 } // namespace gpu | 233 } // namespace gpu |
| 219 | 234 |
| 220 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ | 235 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ |
| OLD | NEW |