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

Side by Side Diff: gpu/command_buffer/common/gles2_cmd_utils.cc

Issue 10012057: Add GL_EXT_unpack_subimage support to command buffer client code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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) 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 // This file is here so other GLES2 related files can have a common set of 5 // This file is here so other GLES2 related files can have a common set of
6 // includes where appropriate. 6 // includes where appropriate.
7 7
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <GLES2/gl2.h> 9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h> 10 #include <GLES2/gl2ext.h>
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 case GL_UNSIGNED_BYTE: 366 case GL_UNSIGNED_BYTE:
367 case GL_BYTE: 367 case GL_BYTE:
368 return 1; 368 return 1;
369 default: 369 default:
370 return 0; 370 return 0;
371 } 371 }
372 } 372 }
373 373
374 } // anonymous namespace 374 } // anonymous namespace
375 375
376 uint32 GLES2Util::ComputeImageGroupSize(int format, int type) {
377 return BytesPerElement(type) * ElementsPerGroup(format, type);
378 }
379
380 bool GLES2Util::ComputeImagePaddedRowSize(
381 int width, int format, int type, int unpack_alignment,
382 uint32* padded_row_size) {
383 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
384 uint32 unpadded_row_size;
385 if (!SafeMultiplyUint32(width, bytes_per_group, &unpadded_row_size)) {
386 return false;
387 }
388 uint32 temp;
389 if (!SafeAddUint32(unpadded_row_size, unpack_alignment - 1, &temp)) {
390 return false;
391 }
392 *padded_row_size = (temp / unpack_alignment) * unpack_alignment;
393 return true;
394 }
395
376 // Returns the amount of data glTexImage2D or glTexSubImage2D will access. 396 // Returns the amount of data glTexImage2D or glTexSubImage2D will access.
377 bool GLES2Util::ComputeImageDataSize( 397 bool GLES2Util::ComputeImageDataSizes(
378 int width, int height, int format, int type, int unpack_alignment, 398 int width, int height, int format, int type, int unpack_alignment,
379 uint32* size) { 399 uint32* size, uint32* ret_unpadded_row_size, uint32* ret_padded_row_size) {
380 uint32 bytes_per_group = 400 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
381 BytesPerElement(type) * ElementsPerGroup(format, type);
382 uint32 row_size; 401 uint32 row_size;
383 if (!SafeMultiplyUint32(width, bytes_per_group, &row_size)) { 402 if (!SafeMultiplyUint32(width, bytes_per_group, &row_size)) {
384 return false; 403 return false;
385 } 404 }
386 if (height > 1) { 405 if (height > 1) {
387 uint32 temp; 406 uint32 temp;
388 if (!SafeAddUint32(row_size, unpack_alignment - 1, &temp)) { 407 if (!SafeAddUint32(row_size, unpack_alignment - 1, &temp)) {
389 return false; 408 return false;
390 } 409 }
391 uint32 padded_row_size = (temp / unpack_alignment) * unpack_alignment; 410 uint32 padded_row_size = (temp / unpack_alignment) * unpack_alignment;
392 uint32 size_of_all_but_last_row; 411 uint32 size_of_all_but_last_row;
393 if (!SafeMultiplyUint32((height - 1), padded_row_size, 412 if (!SafeMultiplyUint32((height - 1), padded_row_size,
394 &size_of_all_but_last_row)) { 413 &size_of_all_but_last_row)) {
395 return false; 414 return false;
396 } 415 }
397 if (!SafeAddUint32(size_of_all_but_last_row, row_size, size)) { 416 if (!SafeAddUint32(size_of_all_but_last_row, row_size, size)) {
398 return false; 417 return false;
399 } 418 }
419 if (ret_padded_row_size) {
420 *ret_padded_row_size = padded_row_size;
421 }
400 } else { 422 } else {
401 if (!SafeMultiplyUint32(height, row_size, size)) { 423 if (!SafeMultiplyUint32(height, row_size, size)) {
402 return false; 424 return false;
403 } 425 }
426 if (ret_padded_row_size) {
427 *ret_padded_row_size = row_size;
428 }
404 } 429 }
430 if (ret_unpadded_row_size) {
431 *ret_unpadded_row_size = row_size;
432 }
433
405 return true; 434 return true;
406 } 435 }
407 436
408 size_t GLES2Util::RenderbufferBytesPerPixel(int format) { 437 size_t GLES2Util::RenderbufferBytesPerPixel(int format) {
409 switch (format) { 438 switch (format) {
410 case GL_STENCIL_INDEX8: 439 case GL_STENCIL_INDEX8:
411 return 1; 440 return 1;
412 case GL_RGBA4: 441 case GL_RGBA4:
413 case GL_RGB565: 442 case GL_RGB565:
414 case GL_RGB5_A1: 443 case GL_RGB5_A1:
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 } 744 }
716 745
717 return true; 746 return true;
718 } 747 }
719 748
720 #include "../common/gles2_cmd_utils_implementation_autogen.h" 749 #include "../common/gles2_cmd_utils_implementation_autogen.h"
721 750
722 } // namespace gles2 751 } // namespace gles2
723 } // namespace gpu 752 } // namespace gpu
724 753
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gles2_cmd_utils.h ('k') | gpu/command_buffer/common/gles2_cmd_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698