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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // count is in elements of type. | 71 // count is in elements of type. |
72 bool GetMaxValueForRange(GLuint offset, GLsizei count, GLenum type, | 72 bool GetMaxValueForRange(GLuint offset, GLsizei count, GLenum type, |
73 bool primitive_restart_enabled, GLuint* max_value); | 73 bool primitive_restart_enabled, GLuint* max_value); |
74 | 74 |
75 // Returns a pointer to shadowed data. | 75 // Returns a pointer to shadowed data. |
76 const void* GetRange(GLintptr offset, GLsizeiptr size) const; | 76 const void* GetRange(GLintptr offset, GLsizeiptr size) const; |
77 | 77 |
78 // Check if an offset, size range is valid for the current buffer. | 78 // Check if an offset, size range is valid for the current buffer. |
79 bool CheckRange(GLintptr offset, GLsizeiptr size) const; | 79 bool CheckRange(GLintptr offset, GLsizeiptr size) const; |
80 | 80 |
81 // Sets a range of this buffer's shadowed data. | 81 // Sets a range of this buffer's shadowed data. Returns false if offset/size |
82 void SetRange(GLintptr offset, GLsizeiptr size, const GLvoid * data); | 82 // is out of range. |
| 83 bool SetRange(GLintptr offset, GLsizeiptr size, const GLvoid * data); |
83 | 84 |
84 bool IsDeleted() const { | 85 bool IsDeleted() const { |
85 return deleted_; | 86 return deleted_; |
86 } | 87 } |
87 | 88 |
88 bool IsValid() const { | 89 bool IsValid() const { |
89 return initial_target() && !IsDeleted(); | 90 return initial_target() && !IsDeleted(); |
90 } | 91 } |
91 | 92 |
92 bool IsClientSideArray() const { | 93 bool IsClientSideArray() const { |
93 return is_client_side_array_; | 94 return is_client_side_array_; |
94 } | 95 } |
95 | 96 |
96 void SetMappedRange(GLintptr offset, GLsizeiptr size, GLenum access, | 97 void SetMappedRange(GLintptr offset, GLsizeiptr size, GLenum access, |
97 void* pointer, scoped_refptr<gpu::Buffer> shm, | 98 void* pointer, scoped_refptr<gpu::Buffer> shm, |
98 unsigned int shm_offset); | 99 unsigned int shm_offset) { |
99 void RemoveMappedRange(); | 100 mapped_range_.reset( |
| 101 new MappedRange(offset, size, access, pointer, shm, shm_offset)); |
| 102 } |
| 103 |
| 104 void RemoveMappedRange() { |
| 105 mapped_range_.reset(nullptr); |
| 106 } |
| 107 |
100 const MappedRange* GetMappedRange() const { | 108 const MappedRange* GetMappedRange() const { |
101 return mapped_range_.get(); | 109 return mapped_range_.get(); |
102 } | 110 } |
103 | 111 |
104 private: | 112 private: |
105 friend class BufferManager; | 113 friend class BufferManager; |
106 friend class BufferManagerTestBase; | 114 friend class BufferManagerTestBase; |
107 friend class base::RefCounted<Buffer>; | 115 friend class base::RefCounted<Buffer>; |
108 | 116 |
109 // Represents a range in a buffer. | 117 // Represents a range in a buffer. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 bool UseNonZeroSizeForClientSideArrayBuffer(); | 299 bool UseNonZeroSizeForClientSideArrayBuffer(); |
292 | 300 |
293 void SetPrimitiveRestartFixedIndexIfNecessary(GLenum type); | 301 void SetPrimitiveRestartFixedIndexIfNecessary(GLenum type); |
294 | 302 |
295 Buffer* GetBufferInfoForTarget(ContextState* state, GLenum target) const; | 303 Buffer* GetBufferInfoForTarget(ContextState* state, GLenum target) const; |
296 | 304 |
297 // base::trace_event::MemoryDumpProvider implementation. | 305 // base::trace_event::MemoryDumpProvider implementation. |
298 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 306 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
299 base::trace_event::ProcessMemoryDump* pmd) override; | 307 base::trace_event::ProcessMemoryDump* pmd) override; |
300 | 308 |
301 // Validate if a buffer is bound at target, if it's unmapped, if it's | |
302 // large enough. Return the buffer bound to |target| if access is granted; | |
303 // return nullptr if a GL error is generated. | |
304 Buffer* RequestBufferAccess(ContextState* context_state, | |
305 GLenum target, | |
306 GLintptr offset, | |
307 GLsizeiptr size, | |
308 const char* func_name); | |
309 // Same as above, but assume to access the entire buffer. | |
310 Buffer* RequestBufferAccess(ContextState* context_state, | |
311 GLenum target, | |
312 const char* func_name); | |
313 // Same as above, but it can be any buffer rather than the buffer bound to | |
314 // |target|. Return true if access is granted; return false if a GL error is | |
315 // generated. | |
316 bool RequestBufferAccess(ErrorState* error_state, | |
317 Buffer* buffer, | |
318 const char* func_name, | |
319 const char* message_tag); | |
320 | |
321 uint32_t mapped_buffer_count() const { | |
322 return mapped_buffer_count_; | |
323 } | |
324 | |
325 private: | 309 private: |
326 friend class Buffer; | 310 friend class Buffer; |
327 friend class TestHelper; // Needs access to DoBufferData. | 311 friend class TestHelper; // Needs access to DoBufferData. |
328 friend class BufferManagerTestBase; // Needs access to DoBufferSubData. | 312 friend class BufferManagerTestBase; // Needs access to DoBufferSubData. |
329 friend class IndexedBufferBindingHostTest; // Needs access to SetInfo. | 313 friend class IndexedBufferBindingHostTest; // Needs access to SetInfo. |
330 | 314 |
331 void StartTracking(Buffer* buffer); | 315 void StartTracking(Buffer* buffer); |
332 void StopTracking(Buffer* buffer); | 316 void StopTracking(Buffer* buffer); |
333 | 317 |
334 // Does a glBufferSubData and updates the appropriate accounting. | 318 // Does a glBufferSubData and updates the appropriate accounting. |
335 // Assumes the values have already been validated. | 319 // Assumes the values have already been validated. |
336 void DoBufferSubData( | 320 void DoBufferSubData( |
| 321 ErrorState* error_state, |
337 Buffer* buffer, | 322 Buffer* buffer, |
338 GLenum target, | 323 GLenum target, |
339 GLintptr offset, | 324 GLintptr offset, |
340 GLsizeiptr size, | 325 GLsizeiptr size, |
341 const GLvoid* data); | 326 const GLvoid* data); |
342 | 327 |
343 // Does a glBufferData and updates the appropriate accounting. | 328 // Does a glBufferData and updates the appropriate accounting. |
344 // Assumes the values have already been validated. | 329 // Assumes the values have already been validated. |
345 void DoBufferData( | 330 void DoBufferData( |
346 ErrorState* error_state, | 331 ErrorState* error_state, |
(...skipping 18 matching lines...) Expand all Loading... |
365 bool UseShadowBuffer(GLenum target, GLenum usage); | 350 bool UseShadowBuffer(GLenum target, GLenum usage); |
366 | 351 |
367 // Sets the size, usage and initial data of a buffer. | 352 // Sets the size, usage and initial data of a buffer. |
368 // If data is NULL buffer will be initialized to 0 if shadowed. | 353 // If data is NULL buffer will be initialized to 0 if shadowed. |
369 void SetInfo(Buffer* buffer, | 354 void SetInfo(Buffer* buffer, |
370 GLenum target, | 355 GLenum target, |
371 GLsizeiptr size, | 356 GLsizeiptr size, |
372 GLenum usage, | 357 GLenum usage, |
373 bool use_shadow); | 358 bool use_shadow); |
374 | 359 |
375 void IncreaseMappedBufferCount(); | |
376 void DecreaseMappedBufferCount(); | |
377 | |
378 std::unique_ptr<MemoryTypeTracker> memory_type_tracker_; | 360 std::unique_ptr<MemoryTypeTracker> memory_type_tracker_; |
379 MemoryTracker* memory_tracker_; | 361 MemoryTracker* memory_tracker_; |
380 scoped_refptr<FeatureInfo> feature_info_; | 362 scoped_refptr<FeatureInfo> feature_info_; |
381 | 363 |
382 // Info for each buffer in the system. | 364 // Info for each buffer in the system. |
383 typedef base::hash_map<GLuint, scoped_refptr<Buffer> > BufferMap; | 365 typedef base::hash_map<GLuint, scoped_refptr<Buffer> > BufferMap; |
384 BufferMap buffers_; | 366 BufferMap buffers_; |
385 | 367 |
386 // The maximum size of buffers. | 368 // The maximum size of buffers. |
387 GLsizeiptr max_buffer_size_; | 369 GLsizeiptr max_buffer_size_; |
388 | 370 |
389 // Whether or not buffers can be bound to multiple targets. | 371 // Whether or not buffers can be bound to multiple targets. |
390 bool allow_buffers_on_multiple_targets_; | 372 bool allow_buffers_on_multiple_targets_; |
391 | 373 |
392 // Whether or not allow using GL_FIXED type for vertex attribs. | 374 // Whether or not allow using GL_FIXED type for vertex attribs. |
393 bool allow_fixed_attribs_; | 375 bool allow_fixed_attribs_; |
394 | 376 |
395 // Counts the number of Buffer allocated with 'this' as its manager. | 377 // Counts the number of Buffer allocated with 'this' as its manager. |
396 // Allows to check no Buffer will outlive this. | 378 // Allows to check no Buffer will outlive this. |
397 unsigned int buffer_count_; | 379 unsigned int buffer_count_; |
398 | 380 |
399 GLuint primitive_restart_fixed_index_; | 381 GLuint primitive_restart_fixed_index_; |
400 | 382 |
401 bool lost_context_; | 383 bool lost_context_; |
402 bool use_client_side_arrays_for_stream_buffers_; | 384 bool use_client_side_arrays_for_stream_buffers_; |
403 | 385 |
404 // Keep track of total mapped buffer count. In most use cases it should be 0, | |
405 // so we could bypass checking each individual buffer as an optimization. | |
406 uint32_t mapped_buffer_count_; | |
407 | |
408 DISALLOW_COPY_AND_ASSIGN(BufferManager); | 386 DISALLOW_COPY_AND_ASSIGN(BufferManager); |
409 }; | 387 }; |
410 | 388 |
411 } // namespace gles2 | 389 } // namespace gles2 |
412 } // namespace gpu | 390 } // namespace gpu |
413 | 391 |
414 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ | 392 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ |
OLD | NEW |