summaryrefslogtreecommitdiffstats
path: root/o3d/core
diff options
context:
space:
mode:
authorgman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 02:25:11 +0000
committergman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 02:25:11 +0000
commite52146dac4696c7ef277dbd386415026ada77199 (patch)
tree625fbfc397be1d8bbda442b4ea909164e99c413e /o3d/core
parentecc8defbf718fc408c880fc984fa04552c45736b (diff)
downloadchromium_src-e52146dac4696c7ef277dbd386415026ada77199.zip
chromium_src-e52146dac4696c7ef277dbd386415026ada77199.tar.gz
chromium_src-e52146dac4696c7ef277dbd386415026ada77199.tar.bz2
Add test for texture::SetRect to make sure -pitch
works. Review URL: http://codereview.chromium.org/174037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23685 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core')
-rw-r--r--o3d/core/cross/texture_test.cc91
1 files changed, 91 insertions, 0 deletions
diff --git a/o3d/core/cross/texture_test.cc b/o3d/core/cross/texture_test.cc
index c9cb3ca..4e55d2e 100644
--- a/o3d/core/cross/texture_test.cc
+++ b/o3d/core/cross/texture_test.cc
@@ -39,6 +39,27 @@
namespace o3d {
+namespace {
+
+bool CompareTexture(Texture2D* texture, int level, const uint8* expected) {
+ Texture2D::LockHelper helper(texture, level);
+ const uint8* data = helper.GetDataAs<const uint8>();
+ unsigned mip_width = image::ComputeMipDimension(level, texture->width());
+ unsigned mip_height = image::ComputeMipDimension(level, texture->height());
+
+ int bytes_per_row = image::ComputePitch(texture->format(), mip_width);
+ for (unsigned yy = 0; yy < mip_height; ++yy) {
+ if (memcmp(data, expected, bytes_per_row) != 0) {
+ return false;
+ }
+ expected += bytes_per_row;
+ data += helper.pitch();
+ }
+ return true;
+}
+
+} // anonymous namespace.
+
class Texture2DTest : public testing::Test {
protected:
Texture2DTest()
@@ -71,6 +92,76 @@ TEST_F(Texture2DTest, Basic) {
EXPECT_FALSE(texture->render_surfaces_enabled());
}
+TEST_F(Texture2DTest, SetRect) {
+ const int kWidth = 8;
+ const int kHeight = 8;
+ const int kLevels = 2;
+ const int kDestMip = 1;
+ const unsigned kDestX = 1u;
+ const unsigned kDestY = 1u;
+ Texture2D* texture = pack()->CreateTexture2D(
+ kWidth, kHeight, Texture::ARGB8, kLevels, false);
+ ASSERT_TRUE(texture != NULL);
+ static const uint8 kExpected1[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ };
+ EXPECT_TRUE(CompareTexture(texture, 1, kExpected1));
+ const int kSrcWidth = 2;
+ const int kSrcHeight = 2;
+ static const uint8 kSourcePixels[] = {
+ 0x01, 0x01, 0x01, 0x02, 0x03, 0x03, 0x03, 0x04,
+ 0x05, 0x05, 0x05, 0x06, 0x07, 0x07, 0x07, 0x08,
+ };
+ const int kSourcePitch = sizeof(kSourcePixels[0]) * kSrcWidth * 4;
+ // normal copy
+ texture->SetRect(kDestMip, kDestX, kDestY,
+ kSrcWidth, kSrcHeight, kSourcePixels, kSourcePitch);
+ static const uint8 kExpected2[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02,
+ 0x03, 0x03, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
+
+ 0x00, 0x00, 0x00, 0x00, 0x05, 0x05, 0x05, 0x06,
+ 0x07, 0x07, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00,
+
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ };
+ EXPECT_TRUE(CompareTexture(texture, 1, kExpected2));
+ // flipped copy
+ texture->SetRect(
+ kDestMip, kDestX, kDestY,
+ kSrcWidth, kSrcHeight,
+ kSourcePixels + kSourcePitch,
+ -kSourcePitch);
+ static const uint8 kExpected3[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ 0x00, 0x00, 0x00, 0x00, 0x05, 0x05, 0x05, 0x06,
+ 0x07, 0x07, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00,
+
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02,
+ 0x03, 0x03, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
+
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ };
+ EXPECT_TRUE(CompareTexture(texture, 1, kExpected3));
+}
+
class TextureCUBETest : public testing::Test {
protected:
TextureCUBETest()