Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: gpu/command_buffer/service/buffer_manager.h

Issue 2435803004: Initialize buffers before allowing access to them. (Closed)
Patch Set: win failure Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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. Returns false if offset/size 81 // Sets a range of this buffer's shadowed data.
82 // is out of range. 82 void SetRange(GLintptr offset, GLsizeiptr size, const GLvoid * data);
83 bool SetRange(GLintptr offset, GLsizeiptr size, const GLvoid * data);
84 83
85 bool IsDeleted() const { 84 bool IsDeleted() const {
86 return deleted_; 85 return deleted_;
87 } 86 }
88 87
89 bool IsValid() const { 88 bool IsValid() const {
90 return initial_target() && !IsDeleted(); 89 return initial_target() && !IsDeleted();
91 } 90 }
92 91
93 bool IsClientSideArray() const { 92 bool IsClientSideArray() const {
94 return is_client_side_array_; 93 return is_client_side_array_;
95 } 94 }
96 95
97 void SetMappedRange(GLintptr offset, GLsizeiptr size, GLenum access, 96 void SetMappedRange(GLintptr offset, GLsizeiptr size, GLenum access,
98 void* pointer, scoped_refptr<gpu::Buffer> shm, 97 void* pointer, scoped_refptr<gpu::Buffer> shm,
99 unsigned int shm_offset) { 98 unsigned int shm_offset);
100 mapped_range_.reset( 99 void RemoveMappedRange();
101 new MappedRange(offset, size, access, pointer, shm, shm_offset));
102 }
103
104 void RemoveMappedRange() {
105 mapped_range_.reset(nullptr);
106 }
107
108 const MappedRange* GetMappedRange() const { 100 const MappedRange* GetMappedRange() const {
109 return mapped_range_.get(); 101 return mapped_range_.get();
110 } 102 }
111 103
112 private: 104 private:
113 friend class BufferManager; 105 friend class BufferManager;
114 friend class BufferManagerTestBase; 106 friend class BufferManagerTestBase;
115 friend class base::RefCounted<Buffer>; 107 friend class base::RefCounted<Buffer>;
116 108
117 // Represents a range in a buffer. 109 // Represents a range in a buffer.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 bool UseNonZeroSizeForClientSideArrayBuffer(); 291 bool UseNonZeroSizeForClientSideArrayBuffer();
300 292
301 void SetPrimitiveRestartFixedIndexIfNecessary(GLenum type); 293 void SetPrimitiveRestartFixedIndexIfNecessary(GLenum type);
302 294
303 Buffer* GetBufferInfoForTarget(ContextState* state, GLenum target) const; 295 Buffer* GetBufferInfoForTarget(ContextState* state, GLenum target) const;
304 296
305 // base::trace_event::MemoryDumpProvider implementation. 297 // base::trace_event::MemoryDumpProvider implementation.
306 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 298 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
307 base::trace_event::ProcessMemoryDump* pmd) override; 299 base::trace_event::ProcessMemoryDump* pmd) override;
308 300
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 {
piman 2016/10/24 22:47:11 nit: I didn't see being used. Is that for a follow
322 return mapped_buffer_count_;
323 }
324
309 private: 325 private:
310 friend class Buffer; 326 friend class Buffer;
311 friend class TestHelper; // Needs access to DoBufferData. 327 friend class TestHelper; // Needs access to DoBufferData.
312 friend class BufferManagerTestBase; // Needs access to DoBufferSubData. 328 friend class BufferManagerTestBase; // Needs access to DoBufferSubData.
313 friend class IndexedBufferBindingHostTest; // Needs access to SetInfo. 329 friend class IndexedBufferBindingHostTest; // Needs access to SetInfo.
314 330
315 void StartTracking(Buffer* buffer); 331 void StartTracking(Buffer* buffer);
316 void StopTracking(Buffer* buffer); 332 void StopTracking(Buffer* buffer);
317 333
318 // Does a glBufferSubData and updates the appropriate accounting. 334 // Does a glBufferSubData and updates the appropriate accounting.
319 // Assumes the values have already been validated. 335 // Assumes the values have already been validated.
320 void DoBufferSubData( 336 void DoBufferSubData(
321 ErrorState* error_state,
322 Buffer* buffer, 337 Buffer* buffer,
323 GLenum target, 338 GLenum target,
324 GLintptr offset, 339 GLintptr offset,
325 GLsizeiptr size, 340 GLsizeiptr size,
326 const GLvoid* data); 341 const GLvoid* data);
327 342
328 // Does a glBufferData and updates the appropriate accounting. 343 // Does a glBufferData and updates the appropriate accounting.
329 // Assumes the values have already been validated. 344 // Assumes the values have already been validated.
330 void DoBufferData( 345 void DoBufferData(
331 ErrorState* error_state, 346 ErrorState* error_state,
(...skipping 18 matching lines...) Expand all
350 bool UseShadowBuffer(GLenum target, GLenum usage); 365 bool UseShadowBuffer(GLenum target, GLenum usage);
351 366
352 // Sets the size, usage and initial data of a buffer. 367 // Sets the size, usage and initial data of a buffer.
353 // If data is NULL buffer will be initialized to 0 if shadowed. 368 // If data is NULL buffer will be initialized to 0 if shadowed.
354 void SetInfo(Buffer* buffer, 369 void SetInfo(Buffer* buffer,
355 GLenum target, 370 GLenum target,
356 GLsizeiptr size, 371 GLsizeiptr size,
357 GLenum usage, 372 GLenum usage,
358 bool use_shadow); 373 bool use_shadow);
359 374
375 void IncreaseMappedBufferCount();
376 void DecreaseMappedBufferCount();
377
360 std::unique_ptr<MemoryTypeTracker> memory_type_tracker_; 378 std::unique_ptr<MemoryTypeTracker> memory_type_tracker_;
361 MemoryTracker* memory_tracker_; 379 MemoryTracker* memory_tracker_;
362 scoped_refptr<FeatureInfo> feature_info_; 380 scoped_refptr<FeatureInfo> feature_info_;
363 381
364 // Info for each buffer in the system. 382 // Info for each buffer in the system.
365 typedef base::hash_map<GLuint, scoped_refptr<Buffer> > BufferMap; 383 typedef base::hash_map<GLuint, scoped_refptr<Buffer> > BufferMap;
366 BufferMap buffers_; 384 BufferMap buffers_;
367 385
368 // The maximum size of buffers. 386 // The maximum size of buffers.
369 GLsizeiptr max_buffer_size_; 387 GLsizeiptr max_buffer_size_;
370 388
371 // Whether or not buffers can be bound to multiple targets. 389 // Whether or not buffers can be bound to multiple targets.
372 bool allow_buffers_on_multiple_targets_; 390 bool allow_buffers_on_multiple_targets_;
373 391
374 // Whether or not allow using GL_FIXED type for vertex attribs. 392 // Whether or not allow using GL_FIXED type for vertex attribs.
375 bool allow_fixed_attribs_; 393 bool allow_fixed_attribs_;
376 394
377 // Counts the number of Buffer allocated with 'this' as its manager. 395 // Counts the number of Buffer allocated with 'this' as its manager.
378 // Allows to check no Buffer will outlive this. 396 // Allows to check no Buffer will outlive this.
379 unsigned int buffer_count_; 397 unsigned int buffer_count_;
380 398
381 GLuint primitive_restart_fixed_index_; 399 GLuint primitive_restart_fixed_index_;
382 400
383 bool lost_context_; 401 bool lost_context_;
384 bool use_client_side_arrays_for_stream_buffers_; 402 bool use_client_side_arrays_for_stream_buffers_;
385 403
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
386 DISALLOW_COPY_AND_ASSIGN(BufferManager); 408 DISALLOW_COPY_AND_ASSIGN(BufferManager);
387 }; 409 };
388 410
389 } // namespace gles2 411 } // namespace gles2
390 } // namespace gpu 412 } // namespace gpu
391 413
392 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ 414 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_
OLDNEW
« no previous file with comments | « content/test/gpu/gpu_tests/webgl_conformance_expectations.py ('k') | gpu/command_buffer/service/buffer_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698