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

Unified Diff: gpu/command_buffer/client/gles2_implementation_unittest.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.cc ('k') | gpu/command_buffer/common/gles2_cmd_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/client/gles2_implementation_unittest.cc
===================================================================
--- gpu/command_buffer/client/gles2_implementation_unittest.cc (revision 131422)
+++ gpu/command_buffer/client/gles2_implementation_unittest.cc (working copy)
@@ -1784,31 +1784,13 @@
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), gl_->GetError());
}
-static bool ComputeImageDataSizes(
- int width, int height, int format, int type, int unpack_alignment,
- uint32* size, uint32* unpadded_row_size, uint32* padded_row_size) {
- uint32 temp_size;
- if (!GLES2Util::ComputeImageDataSize(
- width, 1, format, type, unpack_alignment, &temp_size)) {
- return false;
- }
- *unpadded_row_size = temp_size;
- if (!GLES2Util::ComputeImageDataSize(
- width, 2, format, type, unpack_alignment, &temp_size)) {
- return false;
- }
- *padded_row_size = temp_size - *unpadded_row_size;
- return GLES2Util::ComputeImageDataSize(
- width, height, format, type, unpack_alignment, size);
-}
-
static bool CheckRect(
int width, int height, GLenum format, GLenum type, int alignment,
bool flip_y, const uint8* r1, const uint8* r2) {
uint32 size = 0;
uint32 unpadded_row_size = 0;
uint32 padded_row_size = 0;
- if (!ComputeImageDataSizes(
+ if (!GLES2Util::ComputeImageDataSizes(
width, height, format, type, alignment, &size, &unpadded_row_size,
&padded_row_size)) {
return false;
@@ -1913,17 +1895,17 @@
uint32 size = 0;
uint32 unpadded_row_size = 0;
uint32 padded_row_size = 0;
- ASSERT_TRUE(ComputeImageDataSizes(
+ ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
kWidth, 2, kFormat, kType, kPixelStoreUnpackAlignment,
&size, &unpadded_row_size, &padded_row_size));
const GLsizei kHeight = (MaxTransferBufferSize() / padded_row_size) * 2;
- ASSERT_TRUE(GLES2Util::ComputeImageDataSize(
+ ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
kWidth, kHeight, kFormat, kType, kPixelStoreUnpackAlignment,
- &size));
+ &size, NULL, NULL));
uint32 half_size = 0;
- ASSERT_TRUE(GLES2Util::ComputeImageDataSize(
+ ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
kWidth, kHeight / 2, kFormat, kType, kPixelStoreUnpackAlignment,
- &half_size));
+ &half_size, NULL, NULL));
scoped_array<uint8> pixels(new uint8[size]);
for (uint32 ii = 0; ii < size; ++ii) {
@@ -2021,9 +2003,9 @@
};
uint32 sub_2_high_size = 0;
- ASSERT_TRUE(GLES2Util::ComputeImageDataSize(
+ ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
kSubImageWidth, 2, kFormat, kType, kPixelStoreUnpackAlignment,
- &sub_2_high_size));
+ &sub_2_high_size, NULL, NULL));
ExpectedMemoryInfo mem1 = GetExpectedMemory(sub_2_high_size);
ExpectedMemoryInfo mem2 = GetExpectedMemory(sub_2_high_size);
@@ -2065,6 +2047,119 @@
mem2.ptr));
}
+TEST_F(GLES2ImplementationTest, SubImageUnpack) {
+ static const GLint unpack_alignments[] = { 1, 2, 4, 8 };
+
+ static const GLenum kFormat = GL_RGB;
+ static const GLenum kType = GL_UNSIGNED_BYTE;
+ static const GLint kLevel = 0;
+ static const GLint kBorder = 0;
+ // We're testing using the unpack params to pull a subimage out of a larger
+ // source of pixels. Here we specify the subimage by its border rows /
+ // columns.
+ static const GLint kSrcWidth = 33;
+ static const GLint kSrcSubImageX0 = 11;
+ static const GLint kSrcSubImageX1 = 20;
+ static const GLint kSrcSubImageY0 = 18;
+ static const GLint kSrcSubImageY1 = 23;
+ static const GLint kSrcSubImageWidth = kSrcSubImageX1 - kSrcSubImageX0;
+ static const GLint kSrcSubImageHeight = kSrcSubImageY1 - kSrcSubImageY0;
+
+ // these are only used in the texsubimage tests
+ static const GLint kTexWidth = 1023;
+ static const GLint kTexHeight = 511;
+ static const GLint kTexSubXOffset = 419;
+ static const GLint kTexSubYOffset = 103;
+
+ struct {
+ PixelStorei pixel_store_i;
+ TexImage2D tex_image_2d;
+ } texImageExpected;
+
+ struct {
+ PixelStorei pixel_store_i;
+ TexImage2D tex_image_2d;
+ TexSubImage2D tex_sub_image_2d;
+ } texSubImageExpected;
+
+ uint32 src_size;
+ ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
+ kSrcWidth, kSrcSubImageY1, kFormat, kType, 8, &src_size, NULL, NULL));
+ scoped_array<uint8> src_pixels;
+ src_pixels.reset(new uint8[src_size]);
+ for (size_t i = 0; i < src_size; ++i) {
+ src_pixels[i] = static_cast<int8>(i);
+ }
+
+ for (int sub = 0; sub < 2; ++sub) {
+ for (int flip_y = 0; flip_y < 2; ++flip_y) {
+ for (size_t a = 0; a < arraysize(unpack_alignments); ++a) {
+ GLint alignment = unpack_alignments[a];
+ uint32 size;
+ uint32 unpadded_row_size;
+ uint32 padded_row_size;
+ ASSERT_TRUE(GLES2Util::ComputeImageDataSizes(
+ kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType, alignment,
+ &size, &unpadded_row_size, &padded_row_size));
+ ASSERT_TRUE(size <= MaxTransferBufferSize());
+ ExpectedMemoryInfo mem = GetExpectedMemory(size);
+
+ const void* commands = GetPut();
+ gl_->PixelStorei(GL_UNPACK_ALIGNMENT, alignment);
+ gl_->PixelStorei(GL_UNPACK_ROW_LENGTH, kSrcWidth);
+ gl_->PixelStorei(GL_UNPACK_SKIP_PIXELS, kSrcSubImageX0);
+ gl_->PixelStorei(GL_UNPACK_SKIP_ROWS, kSrcSubImageY0);
+ gl_->PixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y);
+ if (sub) {
+ gl_->TexImage2D(
+ GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight, kBorder,
+ kFormat, kType, NULL);
+ gl_->TexSubImage2D(
+ GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset,
+ kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType,
+ src_pixels.get());
+ texSubImageExpected.pixel_store_i.Init(
+ GL_UNPACK_ALIGNMENT, alignment);
+ texSubImageExpected.tex_image_2d.Init(
+ GL_TEXTURE_2D, kLevel, kFormat, kTexWidth, kTexHeight, kBorder,
+ kFormat, kType, 0, 0);
+ texSubImageExpected.tex_sub_image_2d.Init(
+ GL_TEXTURE_2D, kLevel, kTexSubXOffset, kTexSubYOffset,
+ kSrcSubImageWidth, kSrcSubImageHeight, kFormat, kType, mem.id,
+ mem.offset, GL_FALSE);
+ EXPECT_EQ(0, memcmp(
+ &texSubImageExpected, commands, sizeof(texSubImageExpected)));
+ } else {
+ gl_->TexImage2D(
+ GL_TEXTURE_2D, kLevel, kFormat,
+ kSrcSubImageWidth, kSrcSubImageHeight, kBorder, kFormat, kType,
+ src_pixels.get());
+ texImageExpected.pixel_store_i.Init(GL_UNPACK_ALIGNMENT, alignment);
+ texImageExpected.tex_image_2d.Init(
+ GL_TEXTURE_2D, kLevel, kFormat, kSrcSubImageWidth,
+ kSrcSubImageHeight, kBorder, kFormat, kType, mem.id, mem.offset);
+ EXPECT_EQ(0, memcmp(
+ &texImageExpected, commands, sizeof(texImageExpected)));
+ }
+ uint32 src_padded_row_size;
+ ASSERT_TRUE(GLES2Util::ComputeImagePaddedRowSize(
+ kSrcWidth, kFormat, kType, alignment, &src_padded_row_size));
+ uint32 bytes_per_group = GLES2Util::ComputeImageGroupSize(
+ kFormat, kType);
+ for (int y = 0; y < kSrcSubImageHeight; ++y) {
+ GLint src_sub_y = flip_y ? kSrcSubImageHeight - y - 1 : y;
+ const uint8* src_row = src_pixels.get() +
+ (kSrcSubImageY0 + src_sub_y) * src_padded_row_size +
+ bytes_per_group * kSrcSubImageX0;
+ const uint8* dst_row = mem.ptr + y * padded_row_size;
+ EXPECT_EQ(0, memcmp(src_row, dst_row, unpadded_row_size));
+ }
+ ClearCommands();
+ }
+ }
+ }
+}
+
// Binds can not be cached with bind_generates_resource = false because
// our id might not be valid. More specifically if you bind on contextA then
// delete on contextB the resource is still bound on contextA but GetInterger
@@ -2129,7 +2224,8 @@
const Str7 kString = {"foobar"};
// GL_CHROMIUM_map_sub GL_CHROMIUM_flipy are hard coded into
// GLES2Implementation.
- const char* expected_str = "foobar GL_CHROMIUM_map_sub GL_CHROMIUM_flipy";
+ const char* expected_str =
+ "foobar GL_CHROMIUM_map_sub GL_CHROMIUM_flipy GL_EXT_unpack_subimage";
const char kBad = 0x12;
struct Cmds {
cmd::SetBucketSize set_bucket_size1;
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.cc ('k') | gpu/command_buffer/common/gles2_cmd_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698