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

Side by Side Diff: gpu/command_buffer/client/gles2_implementation.h

Issue 8536045: Make command buffer free transfer buffer when switching tabs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_CLIENT_GLES2_IMPLEMENTATION_H_ 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_ 6 #define GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_
7 7
8 #include <GLES2/gl2.h> 8 #include <GLES2/gl2.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1))); 69 (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1)));
70 70
71 namespace gpu { 71 namespace gpu {
72 72
73 class MappedMemoryManager; 73 class MappedMemoryManager;
74 74
75 namespace gles2 { 75 namespace gles2 {
76 76
77 class ClientSideBufferHelper; 77 class ClientSideBufferHelper;
78 class ProgramInfoManager; 78 class ProgramInfoManager;
79 class AlignedRingBuffer;
79 80
80 // Base class for IdHandlers 81 // Base class for IdHandlers
81 class IdHandlerInterface { 82 class IdHandlerInterface {
82 public: 83 public:
83 IdHandlerInterface() { } 84 IdHandlerInterface() { }
84 virtual ~IdHandlerInterface() { } 85 virtual ~IdHandlerInterface() { }
85 86
86 // Makes some ids at or above id_offset. 87 // Makes some ids at or above id_offset.
87 virtual void MakeIds(GLuint id_offset, GLsizei n, GLuint* ids) = 0; 88 virtual void MakeIds(GLuint id_offset, GLsizei n, GLuint* ids) = 0;
88 89
89 // Frees some ids. 90 // Frees some ids.
90 virtual bool FreeIds(GLsizei n, const GLuint* ids) = 0; 91 virtual bool FreeIds(GLsizei n, const GLuint* ids) = 0;
91 92
92 // Marks an id as used for glBind functions. id = 0 does nothing. 93 // Marks an id as used for glBind functions. id = 0 does nothing.
93 virtual bool MarkAsUsedForBind(GLuint id) = 0; 94 virtual bool MarkAsUsedForBind(GLuint id) = 0;
94 }; 95 };
95 96
97 // Wraps RingBufferWrapper to provide aligned allocations.
98 class AlignedRingBuffer : public RingBufferWrapper {
99 public:
100 AlignedRingBuffer(
101 unsigned int alignment,
102 int32 shm_id,
103 RingBuffer::Offset base_offset,
104 unsigned int size,
105 CommandBufferHelper* helper,
106 void* base)
107 : RingBufferWrapper(base_offset, size, helper, base),
108 alignment_(alignment),
109 shm_id_(shm_id) {
110 }
111 ~AlignedRingBuffer();
112
113 // Overrriden from RingBufferWrapper
114 void* Alloc(unsigned int size) {
115 return RingBufferWrapper::Alloc(RoundToAlignment(size));
116 }
117
118 template <typename T>T* AllocTyped(unsigned int count) {
119 return static_cast<T*>(Alloc(count * sizeof(T)));
120 }
121
122 int32 GetShmId() const {
123 return shm_id_;
124 }
125
126 private:
127 unsigned int RoundToAlignment(unsigned int size) {
128 return (size + alignment_ - 1) & ~(alignment_ - 1);
129 }
130
131 unsigned int alignment_;
132 int32 shm_id_;
133 };
134
135 // Manages the transfer buffer.
136 class TransferBuffer {
137 public:
138 TransferBuffer(
139 CommandBufferHelper* helper,
140 int32 buffer_id,
141 void* buffer,
142 size_t buffer_size,
143 size_t result_size,
144 unsigned int alignment);
145 ~TransferBuffer();
146
147 AlignedRingBuffer* GetBuffer();
148 int GetShmId();
149 void* GetResultBuffer();
150 int GetResultOffset();
151
152 void Free();
153
154 // This is for unit testing only.
155 bool HaveBuffer() const {
156 return buffer_id_ != 0;
157 }
158
159 private:
160 void AllocateRingBuffer();
161
162 void Setup(int32 buffer_id, void* buffer);
163
164 CommandBufferHelper* helper_;
165 scoped_ptr<AlignedRingBuffer> ring_buffer_;
166 unsigned int buffer_size_;
167 unsigned int result_size_;
168 unsigned int alignment_;
169 int32 buffer_id_;
170 void* result_buffer_;
171 uint32 result_shm_offset_;
172 };
173
96 // This class emulates GLES2 over command buffers. It can be used by a client 174 // This class emulates GLES2 over command buffers. It can be used by a client
97 // program so that the program does not need deal with shared memory and command 175 // program so that the program does not need deal with shared memory and command
98 // buffer management. See gl2_lib.h. Note that there is a performance gain to 176 // buffer management. See gl2_lib.h. Note that there is a performance gain to
99 // be had by changing your code to use command buffers directly by using the 177 // be had by changing your code to use command buffers directly by using the
100 // GLES2CmdHelper but that entails changing your code to use and deal with 178 // GLES2CmdHelper but that entails changing your code to use and deal with
101 // shared memory and synchronization issues. 179 // shared memory and synchronization issues.
102 class GLES2Implementation { 180 class GLES2Implementation {
103 public: 181 public:
104 // Stores client side cached GL state. 182 // Stores client side cached GL state.
105 struct GLState { 183 struct GLState {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 return id; 271 return id;
194 } 272 }
195 273
196 void FreeTextureId(GLuint id) { 274 void FreeTextureId(GLuint id) {
197 id_handlers_[id_namespaces::kTextures]->FreeIds(1, &id); 275 id_handlers_[id_namespaces::kTextures]->FreeIds(1, &id);
198 } 276 }
199 277
200 void SetSharedMemoryChunkSizeMultiple(unsigned int multiple); 278 void SetSharedMemoryChunkSizeMultiple(unsigned int multiple);
201 279
202 void FreeUnusedSharedMemory(); 280 void FreeUnusedSharedMemory();
281 void FreeEverything();
203 282
204 private: 283 private:
205 // Used to track whether an extension is available 284 // Used to track whether an extension is available
206 enum ExtensionStatus { 285 enum ExtensionStatus {
207 kAvailableExtensionStatus, 286 kAvailableExtensionStatus,
208 kUnavailableExtensionStatus, 287 kUnavailableExtensionStatus,
209 kUnknownExtensionStatus 288 kUnknownExtensionStatus
210 }; 289 };
211 290
212 // Wraps RingBufferWrapper to provide aligned allocations.
213 class AlignedRingBuffer : public RingBufferWrapper {
214 public:
215 AlignedRingBuffer(RingBuffer::Offset base_offset,
216 unsigned int size,
217 CommandBufferHelper *helper,
218 void *base)
219 : RingBufferWrapper(base_offset, size, helper, base) {
220 }
221
222 static unsigned int RoundToAlignment(unsigned int size) {
223 return (size + kAlignment - 1) & ~(kAlignment - 1);
224 }
225
226 // Overrriden from RingBufferWrapper
227 void *Alloc(unsigned int size) {
228 return RingBufferWrapper::Alloc(RoundToAlignment(size));
229 }
230
231 // Overrriden from RingBufferWrapper
232 template <typename T> T *AllocTyped(unsigned int count) {
233 return static_cast<T *>(Alloc(count * sizeof(T)));
234 }
235 };
236
237 // Base class for mapped resources. 291 // Base class for mapped resources.
238 struct MappedResource { 292 struct MappedResource {
239 MappedResource(GLenum _access, int _shm_id, void* mem, unsigned int offset) 293 MappedResource(GLenum _access, int _shm_id, void* mem, unsigned int offset)
240 : access(_access), 294 : access(_access),
241 shm_id(_shm_id), 295 shm_id(_shm_id),
242 shm_memory(mem), 296 shm_memory(mem),
243 shm_offset(offset) { 297 shm_offset(offset) {
244 } 298 }
245 299
246 // access mode. Currently only GL_WRITE_ONLY is valid 300 // access mode. Currently only GL_WRITE_ONLY is valid
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 376 }
323 377
324 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture 378 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
325 GLuint bound_texture_2d; 379 GLuint bound_texture_2d;
326 380
327 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with 381 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
328 // glBindTexture 382 // glBindTexture
329 GLuint bound_texture_cube_map; 383 GLuint bound_texture_cube_map;
330 }; 384 };
331 385
332 // Gets the shared memory id for the result buffer. 386 // Gets the value of the result.
333 uint32 result_shm_id() const { 387 template <typename T>
334 return transfer_buffer_id_; 388 T GetResultAs() {
389 return static_cast<T>(transfer_buffer_.GetResultBuffer());
335 } 390 }
336 391
337 // Gets the shared memory offset for the result buffer. 392 int32 GetResultShmId() {
338 uint32 result_shm_offset() const { 393 return transfer_buffer_.GetShmId();
339 return result_shm_offset_;
340 } 394 }
341 395
342 // Gets the value of the result. 396 uint32 GetResultShmOffset() {
343 template <typename T> 397 return transfer_buffer_.GetResultOffset();
344 T GetResultAs() const {
345 return static_cast<T>(result_buffer_);
346 } 398 }
347 399
348 // Lazily determines if GL_ANGLE_pack_reverse_row_order is available 400 // Lazily determines if GL_ANGLE_pack_reverse_row_order is available
349 bool IsAnglePackReverseRowOrderAvailable(); 401 bool IsAnglePackReverseRowOrderAvailable();
350 402
351 // Gets the GLError through our wrapper. 403 // Gets the GLError through our wrapper.
352 GLenum GetGLError(); 404 GLenum GetGLError();
353 405
354 // Sets our wrapper for the GLError. 406 // Sets our wrapper for the GLError.
355 void SetGLError(GLenum error, const char* msg); 407 void SetGLError(GLenum error, const char* msg);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 bool GetProgramivHelper(GLuint program, GLenum pname, GLint* params); 478 bool GetProgramivHelper(GLuint program, GLenum pname, GLint* params);
427 bool GetRenderbufferParameterivHelper( 479 bool GetRenderbufferParameterivHelper(
428 GLenum target, GLenum pname, GLint* params); 480 GLenum target, GLenum pname, GLint* params);
429 bool GetShaderivHelper(GLuint shader, GLenum pname, GLint* params); 481 bool GetShaderivHelper(GLuint shader, GLenum pname, GLint* params);
430 bool GetTexParameterfvHelper(GLenum target, GLenum pname, GLfloat* params); 482 bool GetTexParameterfvHelper(GLenum target, GLenum pname, GLfloat* params);
431 bool GetTexParameterivHelper(GLenum target, GLenum pname, GLint* params); 483 bool GetTexParameterivHelper(GLenum target, GLenum pname, GLint* params);
432 484
433 GLES2Util util_; 485 GLES2Util util_;
434 GLES2CmdHelper* helper_; 486 GLES2CmdHelper* helper_;
435 scoped_ptr<IdHandlerInterface> id_handlers_[id_namespaces::kNumIdNamespaces]; 487 scoped_ptr<IdHandlerInterface> id_handlers_[id_namespaces::kNumIdNamespaces];
436 AlignedRingBuffer transfer_buffer_; 488 TransferBuffer transfer_buffer_;
437 int transfer_buffer_id_;
438 void* result_buffer_;
439 uint32 result_shm_offset_;
440 std::string last_error_; 489 std::string last_error_;
441 490
442 std::queue<int32> swap_buffers_tokens_; 491 std::queue<int32> swap_buffers_tokens_;
443 std::queue<int32> rate_limit_tokens_; 492 std::queue<int32> rate_limit_tokens_;
444 493
445 ExtensionStatus angle_pack_reverse_row_order_status; 494 ExtensionStatus angle_pack_reverse_row_order_status;
446 495
447 GLState gl_state_; 496 GLState gl_state_;
448 497
449 // pack alignment as last set by glPixelStorei 498 // pack alignment as last set by glPixelStorei
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 594
546 inline bool GLES2Implementation::GetTexParameterivHelper( 595 inline bool GLES2Implementation::GetTexParameterivHelper(
547 GLenum /* target */, GLenum /* pname */, GLint* /* params */) { 596 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
548 return false; 597 return false;
549 } 598 }
550 599
551 } // namespace gles2 600 } // namespace gles2
552 } // namespace gpu 601 } // namespace gpu
553 602
554 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_ 603 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/build_gles2_cmd_buffer.py ('k') | gpu/command_buffer/client/gles2_implementation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698