diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-09 20:55:41 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-09 20:55:41 +0000 |
commit | 061f1bdc2a119349e78911e9f3d76c2ea1f3d292 (patch) | |
tree | bdb152af816d76f52f91d5f2a20d616d62112f27 /gpu | |
parent | c357acb4058ca346d8e22d29a9d12c72f5d327b4 (diff) | |
download | chromium_src-061f1bdc2a119349e78911e9f3d76c2ea1f3d292.zip chromium_src-061f1bdc2a119349e78911e9f3d76c2ea1f3d292.tar.gz chromium_src-061f1bdc2a119349e78911e9f3d76c2ea1f3d292.tar.bz2 |
Resubmit http://codereview.chromium.org/7046057
that was reverted
http://codereview.chromium.org/6995100/
TEST=unit tests
BUG=85046
TBR=apatrick@chromium.org
Review URL: http://codereview.chromium.org/6995114
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88584 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/common/gles2_cmd_utils.cc | 3 | ||||
-rw-r--r-- | gpu/command_buffer/common/gles2_cmd_utils_unittest.cc | 98 | ||||
-rw-r--r-- | gpu/gpu.gyp | 1 |
3 files changed, 101 insertions, 1 deletions
diff --git a/gpu/command_buffer/common/gles2_cmd_utils.cc b/gpu/command_buffer/common/gles2_cmd_utils.cc index ddab126..b626ac0 100644 --- a/gpu/command_buffer/common/gles2_cmd_utils.cc +++ b/gpu/command_buffer/common/gles2_cmd_utils.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -323,6 +323,7 @@ int ElementsPerGroup(int format, int type) { case GL_RGB: return 3; case GL_LUMINANCE_ALPHA: + return 2; case GL_RGBA: case GL_BGRA_EXT: return 4; diff --git a/gpu/command_buffer/common/gles2_cmd_utils_unittest.cc b/gpu/command_buffer/common/gles2_cmd_utils_unittest.cc new file mode 100644 index 0000000..3a1da0a --- /dev/null +++ b/gpu/command_buffer/common/gles2_cmd_utils_unittest.cc @@ -0,0 +1,98 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gpu/command_buffer/common/gles2_cmd_utils.h" + +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> +#include <GLES2/gles2_command_buffer.h> + +#include "testing/gtest/include/gtest/gtest.h" + +namespace gpu { +namespace gles2 { + +class GLES2UtilTest : public testing:: Test { + public: + GLES2UtilTest() + : util_(0) { + } + + protected: + GLES2Util util_; +}; + +TEST_F(GLES2UtilTest, ComputeImageDataSizeFormats) { + const uint32 kWidth = 16; + const uint32 kHeight = 12; + uint32 size; + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_RGB, GL_UNSIGNED_BYTE, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 3, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 4, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 1, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 2, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_BGRA_EXT, GL_UNSIGNED_BYTE, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 4, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_ALPHA, GL_UNSIGNED_BYTE, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 1, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 2, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, 1, + &size)); + EXPECT_EQ(kWidth * kHeight * 4, size); +} + +TEST_F(GLES2UtilTest, ComputeImageDataSizeTypes) { + const uint32 kWidth = 16; + const uint32 kHeight = 12; + uint32 size; + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 4, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 2, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 2, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 2, size); +} + +TEST_F(GLES2UtilTest, ComputeImageDataSizeUnpackAlignment) { + const uint32 kWidth = 19; + const uint32 kHeight = 12; + uint32 size; + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_RGB, GL_UNSIGNED_BYTE, 1, &size)); + EXPECT_EQ(kWidth * kHeight * 3, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_RGB, GL_UNSIGNED_BYTE, 2, &size)); + EXPECT_EQ((kWidth * 3 + 1) * (kHeight - 1) + + kWidth * 3, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_RGB, GL_UNSIGNED_BYTE, 4, &size)); + EXPECT_EQ((kWidth * 3 + 3) * (kHeight - 1) + + kWidth * 3, size); + EXPECT_TRUE(GLES2Util::ComputeImageDataSize( + kWidth, kHeight, GL_RGB, GL_UNSIGNED_BYTE, 8, &size)); + EXPECT_EQ((kWidth * 3 + 7) * (kHeight - 1) + + kWidth * 3, size); +} + +} // namespace gles2 +} // namespace gpu + diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp index 4cf9b82..d9ddf7c 100644 --- a/gpu/gpu.gyp +++ b/gpu/gpu.gyp @@ -269,6 +269,7 @@ 'command_buffer/common/gles2_cmd_format_test_autogen.h', 'command_buffer/common/gles2_cmd_id_test.cc', 'command_buffer/common/gles2_cmd_id_test_autogen.h', + 'command_buffer/common/gles2_cmd_utils_unittest.cc', 'command_buffer/common/id_allocator_test.cc', 'command_buffer/common/trace_event.h', 'command_buffer/common/unittest_main.cc', |