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/client/gles2_implementation.cc

Issue 1796002: Changes the GLES2Implementation to use a RingBuffer... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 // A class to emluate GLES2 over command buffers. 5 // A class to emluate GLES2 over command buffers.
6 6
7 #include "../client/gles2_implementation.h" 7 #include "../client/gles2_implementation.h"
8 #include "../common/gles2_cmd_utils.h" 8 #include "../common/gles2_cmd_utils.h"
9 9
10 namespace gpu { 10 namespace gpu {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 COMPILE_ASSERT(gpu::kInvalidResource == 0, 327 COMPILE_ASSERT(gpu::kInvalidResource == 0,
328 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS); 328 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS);
329 329
330 GLES2Implementation::GLES2Implementation( 330 GLES2Implementation::GLES2Implementation(
331 GLES2CmdHelper* helper, 331 GLES2CmdHelper* helper,
332 size_t transfer_buffer_size, 332 size_t transfer_buffer_size,
333 void* transfer_buffer, 333 void* transfer_buffer,
334 int32 transfer_buffer_id) 334 int32 transfer_buffer_id)
335 : util_(0), // TODO(gman): Get real number of compressed texture formats. 335 : util_(0), // TODO(gman): Get real number of compressed texture formats.
336 helper_(helper), 336 helper_(helper),
337 transfer_buffer_(transfer_buffer_size, helper, transfer_buffer), 337 transfer_buffer_(
338 kStartingOffset,
339 transfer_buffer_size - kStartingOffset,
340 helper,
341 static_cast<char*>(transfer_buffer) + kStartingOffset),
338 transfer_buffer_id_(transfer_buffer_id), 342 transfer_buffer_id_(transfer_buffer_id),
339 pack_alignment_(4), 343 pack_alignment_(4),
340 unpack_alignment_(4), 344 unpack_alignment_(4),
341 #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) 345 #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS)
342 bound_array_buffer_id_(0), 346 bound_array_buffer_id_(0),
343 bound_element_array_buffer_id_(0), 347 bound_element_array_buffer_id_(0),
344 #endif 348 #endif
345 error_bits_(0) { 349 error_bits_(0) {
346 // Allocate space for simple GL results. 350 // Allocate space for simple GL results.
347 result_buffer_ = transfer_buffer_.Alloc(kMaxSizeOfSimpleResult); 351 result_buffer_ = transfer_buffer;
348 result_shm_offset_ = transfer_buffer_.GetOffset(result_buffer_); 352 result_shm_offset_ = 0;
349 353
350 #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) 354 #if defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS)
351 GLint max_vertex_attribs; 355 GLint max_vertex_attribs;
352 GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs); 356 GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs);
353 buffer_id_allocator_.MarkAsUsed(kClientSideArrayId); 357 buffer_id_allocator_.MarkAsUsed(kClientSideArrayId);
354 buffer_id_allocator_.MarkAsUsed(kClientSideElementArrayId); 358 buffer_id_allocator_.MarkAsUsed(kClientSideElementArrayId);
355 359
356 reserved_ids_[0] = kClientSideArrayId; 360 reserved_ids_[0] = kClientSideArrayId;
357 reserved_ids_[1] = kClientSideElementArrayId; 361 reserved_ids_[1] = kClientSideElementArrayId;
358 362
359 client_side_buffer_helper_.reset(new ClientSideBufferHelper( 363 client_side_buffer_helper_.reset(new ClientSideBufferHelper(
360 max_vertex_attribs, 364 max_vertex_attribs,
361 kClientSideArrayId, 365 kClientSideArrayId,
362 kClientSideElementArrayId)); 366 kClientSideElementArrayId));
363 #endif 367 #endif
364 } 368 }
365 369
366 GLES2Implementation::~GLES2Implementation() { 370 GLES2Implementation::~GLES2Implementation() {
367 GLuint buffers[] = { kClientSideArrayId, kClientSideElementArrayId, }; 371 GLuint buffers[] = { kClientSideArrayId, kClientSideElementArrayId, };
368 DeleteBuffers(arraysize(buffers), &buffers[0]); 372 DeleteBuffers(arraysize(buffers), &buffers[0]);
369 transfer_buffer_.Free(result_buffer_);
370 } 373 }
371 374
372 void GLES2Implementation::MakeIds( 375 void GLES2Implementation::MakeIds(
373 IdAllocator* id_allocator, GLsizei n, GLuint* ids) { 376 IdAllocator* id_allocator, GLsizei n, GLuint* ids) {
374 for (GLsizei ii = 0; ii < n; ++ii) { 377 for (GLsizei ii = 0; ii < n; ++ii) {
375 ids[ii] = id_allocator->AllocateID(); 378 ids[ii] = id_allocator->AllocateID();
376 } 379 }
377 } 380 }
378 381
379 void GLES2Implementation::FreeIds( 382 void GLES2Implementation::FreeIds(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 uint32 max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 436 uint32 max_size = transfer_buffer_.GetLargestFreeOrPendingSize();
434 uint32 offset = 0; 437 uint32 offset = 0;
435 while (size) { 438 while (size) {
436 uint32 part_size = std::min(max_size, size); 439 uint32 part_size = std::min(max_size, size);
437 void* buffer = transfer_buffer_.Alloc(part_size); 440 void* buffer = transfer_buffer_.Alloc(part_size);
438 helper_->GetBucketData( 441 helper_->GetBucketData(
439 bucket_id, offset, part_size, 442 bucket_id, offset, part_size,
440 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer)); 443 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer));
441 WaitForCmd(); 444 WaitForCmd();
442 memcpy(&(*data)[offset], buffer, part_size); 445 memcpy(&(*data)[offset], buffer, part_size);
443 transfer_buffer_.Free(buffer); 446 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken());
444 offset += part_size; 447 offset += part_size;
445 size -= part_size; 448 size -= part_size;
446 } 449 }
447 // Free the bucket. This is not required but it does free up the memory. 450 // Free the bucket. This is not required but it does free up the memory.
448 // and we don't have to wait for the result so from the client's perspective 451 // and we don't have to wait for the result so from the client's perspective
449 // it's cheap. 452 // it's cheap.
450 helper_->SetBucketSize(bucket_id, 0); 453 helper_->SetBucketSize(bucket_id, 0);
451 } 454 }
452 } 455 }
453 456
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 if (*result == 0) { 1136 if (*result == 0) {
1134 return; 1137 return;
1135 } 1138 }
1136 // We have to copy 1 row at a time to avoid writing pad bytes. 1139 // We have to copy 1 row at a time to avoid writing pad bytes.
1137 const int8* src = static_cast<const int8*>(buffer); 1140 const int8* src = static_cast<const int8*>(buffer);
1138 for (GLint yy = 0; yy < num_rows; ++yy) { 1141 for (GLint yy = 0; yy < num_rows; ++yy) {
1139 memcpy(dest, src, unpadded_row_size); 1142 memcpy(dest, src, unpadded_row_size);
1140 dest += padded_row_size; 1143 dest += padded_row_size;
1141 src += padded_row_size; 1144 src += padded_row_size;
1142 } 1145 }
1143 transfer_buffer_.Free(buffer); 1146 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken());
1144 yoffset += num_rows; 1147 yoffset += num_rows;
1145 height -= num_rows; 1148 height -= num_rows;
1146 } 1149 }
1147 } else { 1150 } else {
1148 // Transfer by sub rows. Beacuse GL has no maximum texture dimensions. 1151 // Transfer by sub rows. Beacuse GL has no maximum texture dimensions.
1149 GLES2Util::ComputeImageDataSize( 1152 GLES2Util::ComputeImageDataSize(
1150 1, 1, format, type, pack_alignment_, &temp_size); 1153 1, 1, format, type, pack_alignment_, &temp_size);
1151 GLsizeiptr element_size = temp_size; 1154 GLsizeiptr element_size = temp_size;
1152 max_size -= max_size % element_size; 1155 max_size -= max_size % element_size;
1153 GLint max_sub_row_pixels = max_size / element_size; 1156 GLint max_sub_row_pixels = max_size / element_size;
1154 for (; height; --height) { 1157 for (; height; --height) {
1155 GLint temp_width = width; 1158 GLint temp_width = width;
1156 GLint temp_xoffset = xoffset; 1159 GLint temp_xoffset = xoffset;
1157 int8* row_dest = dest; 1160 int8* row_dest = dest;
1158 while (temp_width) { 1161 while (temp_width) {
1159 GLint num_pixels = std::min(width, max_sub_row_pixels); 1162 GLint num_pixels = std::min(width, max_sub_row_pixels);
1160 GLsizeiptr part_size = num_pixels * element_size; 1163 GLsizeiptr part_size = num_pixels * element_size;
1161 void* buffer = transfer_buffer_.Alloc(part_size); 1164 void* buffer = transfer_buffer_.Alloc(part_size);
1162 *result = 0; // mark as failed. 1165 *result = 0; // mark as failed.
1163 helper_->ReadPixels( 1166 helper_->ReadPixels(
1164 temp_xoffset, yoffset, temp_width, 1, format, type, 1167 temp_xoffset, yoffset, temp_width, 1, format, type,
1165 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), 1168 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer),
1166 result_shm_id(), result_shm_offset()); 1169 result_shm_id(), result_shm_offset());
1167 WaitForCmd(); 1170 WaitForCmd();
1168 // If it was not marked as successful exit. 1171 // If it was not marked as successful exit.
1169 if (*result == 0) { 1172 if (*result == 0) {
1170 return; 1173 return;
1171 } 1174 }
1172 memcpy(row_dest, buffer, part_size); 1175 memcpy(row_dest, buffer, part_size);
1173 transfer_buffer_.Free(buffer); 1176 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken());
1174 row_dest += part_size; 1177 row_dest += part_size;
1175 temp_xoffset += num_pixels; 1178 temp_xoffset += num_pixels;
1176 temp_width -= num_pixels; 1179 temp_width -= num_pixels;
1177 } 1180 }
1178 ++yoffset; 1181 ++yoffset;
1179 dest += padded_row_size; 1182 dest += padded_row_size;
1180 } 1183 }
1181 } 1184 }
1182 } 1185 }
1183 1186
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 helper_->GetVertexAttribiv( 1332 helper_->GetVertexAttribiv(
1330 index, pname, result_shm_id(), result_shm_offset()); 1333 index, pname, result_shm_id(), result_shm_offset());
1331 WaitForCmd(); 1334 WaitForCmd();
1332 result->CopyResult(params); 1335 result->CopyResult(params);
1333 } 1336 }
1334 1337
1335 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS) 1338 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_BUFFERS)
1336 1339
1337 } // namespace gles2 1340 } // namespace gles2
1338 } // namespace gpu 1341 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.h ('k') | gpu/command_buffer/client/ring_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698