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/gpu_export.h" | 15 #include "gpu/gpu_export.h" |
16 | 16 |
17 namespace gpu { | 17 namespace gpu { |
18 namespace gles2 { | 18 namespace gles2 { |
19 | 19 |
| 20 class MemoryTracker; |
| 21 class MemoryTypeTracker; |
| 22 |
20 // This class keeps track of the buffers and their sizes so we can do | 23 // This class keeps track of the buffers and their sizes so we can do |
21 // bounds checking. | 24 // bounds checking. |
22 // | 25 // |
23 // NOTE: To support shared resources an instance of this class will need to be | 26 // NOTE: To support shared resources an instance of this class will need to be |
24 // shared by multiple GLES2Decoders. | 27 // shared by multiple GLES2Decoders. |
25 class GPU_EXPORT BufferManager { | 28 class GPU_EXPORT BufferManager { |
26 public: | 29 public: |
27 // Info about Buffers currently in the system. | 30 // Info about Buffers currently in the system. |
28 class GPU_EXPORT BufferInfo : public base::RefCounted<BufferInfo> { | 31 class GPU_EXPORT BufferInfo : public base::RefCounted<BufferInfo> { |
29 public: | 32 public: |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 151 |
149 // A copy of the data in the buffer. This data is only kept if the target | 152 // A copy of the data in the buffer. This data is only kept if the target |
150 // is backed_ = true. | 153 // is backed_ = true. |
151 scoped_array<int8> shadow_; | 154 scoped_array<int8> shadow_; |
152 | 155 |
153 // A map of ranges to the highest value in that range of a certain type. | 156 // A map of ranges to the highest value in that range of a certain type. |
154 typedef std::map<Range, GLuint, Range::Less> RangeToMaxValueMap; | 157 typedef std::map<Range, GLuint, Range::Less> RangeToMaxValueMap; |
155 RangeToMaxValueMap range_set_; | 158 RangeToMaxValueMap range_set_; |
156 }; | 159 }; |
157 | 160 |
158 BufferManager(); | 161 BufferManager(MemoryTracker* memory_tracker); |
159 ~BufferManager(); | 162 ~BufferManager(); |
160 | 163 |
161 // Must call before destruction. | 164 // Must call before destruction. |
162 void Destroy(bool have_context); | 165 void Destroy(bool have_context); |
163 | 166 |
164 // Creates a BufferInfo for the given buffer. | 167 // Creates a BufferInfo for the given buffer. |
165 void CreateBufferInfo(GLuint client_id, GLuint service_id); | 168 void CreateBufferInfo(GLuint client_id, GLuint service_id); |
166 | 169 |
167 // Gets the buffer info for the given buffer. | 170 // Gets the buffer info for the given buffer. |
168 BufferInfo* GetBufferInfo(GLuint client_id); | 171 BufferInfo* GetBufferInfo(GLuint client_id); |
(...skipping 17 matching lines...) Expand all Loading... |
186 size_t mem_represented() const { | 189 size_t mem_represented() const { |
187 return mem_represented_; | 190 return mem_represented_; |
188 } | 191 } |
189 | 192 |
190 private: | 193 private: |
191 void UpdateMemRepresented(); | 194 void UpdateMemRepresented(); |
192 | 195 |
193 void StartTracking(BufferInfo* info); | 196 void StartTracking(BufferInfo* info); |
194 void StopTracking(BufferInfo* info); | 197 void StopTracking(BufferInfo* info); |
195 | 198 |
| 199 scoped_ptr<MemoryTypeTracker> buffer_memory_tracker_; |
| 200 |
196 // Info for each buffer in the system. | 201 // Info for each buffer in the system. |
197 typedef base::hash_map<GLuint, BufferInfo::Ref> BufferInfoMap; | 202 typedef base::hash_map<GLuint, BufferInfo::Ref> BufferInfoMap; |
198 BufferInfoMap buffer_infos_; | 203 BufferInfoMap buffer_infos_; |
199 | 204 |
200 // Whether or not buffers can be bound to multiple targets. | 205 // Whether or not buffers can be bound to multiple targets. |
201 bool allow_buffers_on_multiple_targets_; | 206 bool allow_buffers_on_multiple_targets_; |
202 | 207 |
203 size_t mem_represented_; | 208 size_t mem_represented_; |
204 size_t last_reported_mem_represented_; | |
205 | 209 |
206 // Counts the number of BufferInfo allocated with 'this' as its manager. | 210 // Counts the number of BufferInfo allocated with 'this' as its manager. |
207 // Allows to check no BufferInfo will outlive this. | 211 // Allows to check no BufferInfo will outlive this. |
208 unsigned int buffer_info_count_; | 212 unsigned int buffer_info_count_; |
209 | 213 |
210 bool have_context_; | 214 bool have_context_; |
211 | 215 |
212 DISALLOW_COPY_AND_ASSIGN(BufferManager); | 216 DISALLOW_COPY_AND_ASSIGN(BufferManager); |
213 }; | 217 }; |
214 | 218 |
215 } // namespace gles2 | 219 } // namespace gles2 |
216 } // namespace gpu | 220 } // namespace gpu |
217 | 221 |
218 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ | 222 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ |
OLD | NEW |