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/gpu_export.h" | 16 #include "gpu/gpu_export.h" |
16 | 17 |
17 namespace gpu { | 18 namespace gpu { |
18 namespace gles2 { | 19 namespace gles2 { |
19 | 20 |
20 class MemoryTracker; | |
21 class MemoryTypeTracker; | |
22 | |
23 // This class keeps track of the buffers and their sizes so we can do | 21 // This class keeps track of the buffers and their sizes so we can do |
24 // bounds checking. | 22 // bounds checking. |
25 // | 23 // |
26 // NOTE: To support shared resources an instance of this class will need to be | 24 // NOTE: To support shared resources an instance of this class will need to be |
27 // shared by multiple GLES2Decoders. | 25 // shared by multiple GLES2Decoders. |
28 class GPU_EXPORT BufferManager { | 26 class GPU_EXPORT BufferManager { |
29 public: | 27 public: |
30 // Info about Buffers currently in the system. | 28 // Info about Buffers currently in the system. |
31 class GPU_EXPORT BufferInfo : public base::RefCounted<BufferInfo> { | 29 class GPU_EXPORT BufferInfo : public base::RefCounted<BufferInfo> { |
32 public: | 30 public: |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 void SetInfo(BufferInfo* info, GLsizeiptr size, GLenum usage); | 181 void SetInfo(BufferInfo* info, GLsizeiptr size, GLenum usage); |
184 | 182 |
185 // Sets the target of a buffer. Returns false if the target can not be set. | 183 // Sets the target of a buffer. Returns false if the target can not be set. |
186 bool SetTarget(BufferInfo* info, GLenum target); | 184 bool SetTarget(BufferInfo* info, GLenum target); |
187 | 185 |
188 void set_allow_buffers_on_multiple_targets(bool allow) { | 186 void set_allow_buffers_on_multiple_targets(bool allow) { |
189 allow_buffers_on_multiple_targets_ = allow; | 187 allow_buffers_on_multiple_targets_ = allow; |
190 } | 188 } |
191 | 189 |
192 size_t mem_represented() const { | 190 size_t mem_represented() const { |
193 return mem_represented_; | 191 return memory_tracker_->GetMemRepresented(); |
194 } | 192 } |
195 | 193 |
196 private: | 194 private: |
197 void UpdateMemRepresented(); | |
198 | |
199 void StartTracking(BufferInfo* info); | 195 void StartTracking(BufferInfo* info); |
200 void StopTracking(BufferInfo* info); | 196 void StopTracking(BufferInfo* info); |
201 | 197 |
202 scoped_ptr<MemoryTypeTracker> buffer_memory_tracker_; | 198 scoped_ptr<MemoryTypeTracker> memory_tracker_; |
203 | 199 |
204 // Info for each buffer in the system. | 200 // Info for each buffer in the system. |
205 typedef base::hash_map<GLuint, BufferInfo::Ref> BufferInfoMap; | 201 typedef base::hash_map<GLuint, BufferInfo::Ref> BufferInfoMap; |
206 BufferInfoMap buffer_infos_; | 202 BufferInfoMap buffer_infos_; |
207 | 203 |
208 // Whether or not buffers can be bound to multiple targets. | 204 // Whether or not buffers can be bound to multiple targets. |
209 bool allow_buffers_on_multiple_targets_; | 205 bool allow_buffers_on_multiple_targets_; |
210 | 206 |
211 size_t mem_represented_; | |
212 | |
213 // Counts the number of BufferInfo allocated with 'this' as its manager. | 207 // Counts the number of BufferInfo allocated with 'this' as its manager. |
214 // Allows to check no BufferInfo will outlive this. | 208 // Allows to check no BufferInfo will outlive this. |
215 unsigned int buffer_info_count_; | 209 unsigned int buffer_info_count_; |
216 | 210 |
217 bool have_context_; | 211 bool have_context_; |
218 | 212 |
219 DISALLOW_COPY_AND_ASSIGN(BufferManager); | 213 DISALLOW_COPY_AND_ASSIGN(BufferManager); |
220 }; | 214 }; |
221 | 215 |
222 } // namespace gles2 | 216 } // namespace gles2 |
223 } // namespace gpu | 217 } // namespace gpu |
224 | 218 |
225 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ | 219 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ |
OLD | NEW |