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 20 matching lines...) Expand all Loading... |
31 class TestHelper; | 31 class TestHelper; |
32 | 32 |
33 // Info about Buffers currently in the system. | 33 // Info about Buffers currently in the system. |
34 class GPU_EXPORT Buffer : public base::RefCounted<Buffer> { | 34 class GPU_EXPORT Buffer : public base::RefCounted<Buffer> { |
35 public: | 35 public: |
36 struct MappedRange { | 36 struct MappedRange { |
37 GLintptr offset; | 37 GLintptr offset; |
38 GLsizeiptr size; | 38 GLsizeiptr size; |
39 GLenum access; | 39 GLenum access; |
40 void* pointer; // Pointer returned by driver. | 40 void* pointer; // Pointer returned by driver. |
41 scoped_refptr<gpu::Buffer> shm; // Client side mem. | 41 scoped_refptr<gpu::Buffer> shm; // Client side mem buffer. |
| 42 unsigned int shm_offset; // Client side mem buffer offset. |
42 | 43 |
43 MappedRange(GLintptr offset, GLsizeiptr size, GLenum access, | 44 MappedRange(GLintptr offset, GLsizeiptr size, GLenum access, void* pointer, |
44 void* pointer, scoped_refptr<gpu::Buffer> shm); | 45 scoped_refptr<gpu::Buffer> shm, unsigned int shm_offset); |
45 ~MappedRange(); | 46 ~MappedRange(); |
46 void* GetShmPointer() const; | 47 void* GetShmPointer() const; |
47 }; | 48 }; |
48 | 49 |
49 Buffer(BufferManager* manager, GLuint service_id); | 50 Buffer(BufferManager* manager, GLuint service_id); |
50 | 51 |
51 GLuint service_id() const { | 52 GLuint service_id() const { |
52 return service_id_; | 53 return service_id_; |
53 } | 54 } |
54 | 55 |
55 GLsizeiptr size() const { | 56 GLsizeiptr size() const { |
56 return size_; | 57 return size_; |
57 } | 58 } |
58 | 59 |
59 GLenum usage() const { | 60 GLenum usage() const { |
60 return usage_; | 61 return usage_; |
61 } | 62 } |
62 | 63 |
| 64 bool shadowed() const { |
| 65 return !shadow_.empty(); |
| 66 } |
| 67 |
63 // Gets the maximum value in the buffer for the given range interpreted as | 68 // Gets the maximum value in the buffer for the given range interpreted as |
64 // the given type. Returns false if offset and count are out of range. | 69 // the given type. Returns false if offset and count are out of range. |
65 // offset is in bytes. | 70 // offset is in bytes. |
66 // count is in elements of type. | 71 // count is in elements of type. |
67 bool GetMaxValueForRange(GLuint offset, GLsizei count, GLenum type, | 72 bool GetMaxValueForRange(GLuint offset, GLsizei count, GLenum type, |
68 bool primitive_restart_enabled, GLuint* max_value); | 73 bool primitive_restart_enabled, GLuint* max_value); |
69 | 74 |
70 // Returns a pointer to shadowed data. | 75 // Returns a pointer to shadowed data. |
71 const void* GetRange(GLintptr offset, GLsizeiptr size) const; | 76 const void* GetRange(GLintptr offset, GLsizeiptr size) const; |
72 | 77 |
73 // 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. |
74 bool CheckRange(GLintptr offset, GLsizeiptr size) const; | 79 bool CheckRange(GLintptr offset, GLsizeiptr size) const; |
75 | 80 |
| 81 // Sets a range of this buffer's shadowed data. Returns false if offset/size |
| 82 // is out of range. |
| 83 bool SetRange(GLintptr offset, GLsizeiptr size, const GLvoid * data); |
| 84 |
76 bool IsDeleted() const { | 85 bool IsDeleted() const { |
77 return deleted_; | 86 return deleted_; |
78 } | 87 } |
79 | 88 |
80 bool IsValid() const { | 89 bool IsValid() const { |
81 return initial_target() && !IsDeleted(); | 90 return initial_target() && !IsDeleted(); |
82 } | 91 } |
83 | 92 |
84 bool IsClientSideArray() const { | 93 bool IsClientSideArray() const { |
85 return is_client_side_array_; | 94 return is_client_side_array_; |
86 } | 95 } |
87 | 96 |
88 void SetMappedRange(GLintptr offset, GLsizeiptr size, GLenum access, | 97 void SetMappedRange(GLintptr offset, GLsizeiptr size, GLenum access, |
89 void* pointer, scoped_refptr<gpu::Buffer> shm) { | 98 void* pointer, scoped_refptr<gpu::Buffer> shm, |
90 mapped_range_.reset(new MappedRange(offset, size, access, pointer, shm)); | 99 unsigned int shm_offset) { |
| 100 mapped_range_.reset( |
| 101 new MappedRange(offset, size, access, pointer, shm, shm_offset)); |
91 } | 102 } |
92 | 103 |
93 void RemoveMappedRange() { | 104 void RemoveMappedRange() { |
94 mapped_range_.reset(nullptr); | 105 mapped_range_.reset(nullptr); |
95 } | 106 } |
96 | 107 |
97 const MappedRange* GetMappedRange() const { | 108 const MappedRange* GetMappedRange() const { |
98 return mapped_range_.get(); | 109 return mapped_range_.get(); |
99 } | 110 } |
100 | 111 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 152 |
142 GLenum initial_target() const { | 153 GLenum initial_target() const { |
143 return initial_target_; | 154 return initial_target_; |
144 } | 155 } |
145 | 156 |
146 void set_initial_target(GLenum target) { | 157 void set_initial_target(GLenum target) { |
147 DCHECK_EQ(0u, initial_target_); | 158 DCHECK_EQ(0u, initial_target_); |
148 initial_target_ = target; | 159 initial_target_ = target; |
149 } | 160 } |
150 | 161 |
151 bool shadowed() const { return !shadow_.empty(); } | |
152 | |
153 void MarkAsDeleted() { | 162 void MarkAsDeleted() { |
154 deleted_ = true; | 163 deleted_ = true; |
155 } | 164 } |
156 | 165 |
157 // Setup the shadow buffer. This will either initialize the shadow buffer | 166 // Setup the shadow buffer. This will either initialize the shadow buffer |
158 // with the passed data or clear the shadow buffer if no shadow required. This | 167 // with the passed data or clear the shadow buffer if no shadow required. This |
159 // will return a pointer to the shadowed data if using shadow, otherwise will | 168 // will return a pointer to the shadowed data if using shadow, otherwise will |
160 // return the original data pointer. | 169 // return the original data pointer. |
161 const GLvoid* StageShadow(bool use_shadow, | 170 const GLvoid* StageShadow(bool use_shadow, |
162 GLsizeiptr size, | 171 GLsizeiptr size, |
163 const GLvoid* data); | 172 const GLvoid* data); |
164 | 173 |
165 // Sets the size, usage and initial data of a buffer. | 174 // Sets the size, usage and initial data of a buffer. |
166 // If shadow is true then if data is NULL buffer will be initialized to 0. | 175 // If shadow is true then if data is NULL buffer will be initialized to 0. |
167 void SetInfo(GLsizeiptr size, | 176 void SetInfo(GLsizeiptr size, |
168 GLenum usage, | 177 GLenum usage, |
169 bool use_shadow, | 178 bool use_shadow, |
170 bool is_client_side_array); | 179 bool is_client_side_array); |
171 | 180 |
172 // Sets a range of data for this buffer. Returns false if the offset or size | |
173 // is out of range. | |
174 bool SetRange( | |
175 GLintptr offset, GLsizeiptr size, const GLvoid * data); | |
176 | |
177 // Clears any cache of index ranges. | 181 // Clears any cache of index ranges. |
178 void ClearCache(); | 182 void ClearCache(); |
179 | 183 |
180 // The manager that owns this Buffer. | 184 // The manager that owns this Buffer. |
181 BufferManager* manager_; | 185 BufferManager* manager_; |
182 | 186 |
183 // A copy of the data in the buffer. This data is only kept if the conditions | 187 // A copy of the data in the buffer. This data is only kept if the conditions |
184 // checked in UseShadowBuffer() are true. | 188 // checked in UseShadowBuffer() are true. |
185 std::vector<uint8_t> shadow_; | 189 std::vector<uint8_t> shadow_; |
186 | 190 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 bool lost_context_; | 383 bool lost_context_; |
380 bool use_client_side_arrays_for_stream_buffers_; | 384 bool use_client_side_arrays_for_stream_buffers_; |
381 | 385 |
382 DISALLOW_COPY_AND_ASSIGN(BufferManager); | 386 DISALLOW_COPY_AND_ASSIGN(BufferManager); |
383 }; | 387 }; |
384 | 388 |
385 } // namespace gles2 | 389 } // namespace gles2 |
386 } // namespace gpu | 390 } // namespace gpu |
387 | 391 |
388 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ | 392 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ |
OLD | NEW |