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

Unified Diff: tests/TextureCompressionTest.cpp

Issue 330453005: Texture compression unit tests along with a couple of bug fixes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 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 | « src/utils/SkTextureCompressor.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/TextureCompressionTest.cpp
diff --git a/tests/TextureCompressionTest.cpp b/tests/TextureCompressionTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d0671408e9ff70eae24b0a16e2318f88315ce757
--- /dev/null
+++ b/tests/TextureCompressionTest.cpp
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBitmap.h"
+#include "SkData.h"
+#include "SkEndian.h"
+#include "SkImageInfo.h"
+#include "SkTextureCompressor.h"
+#include "Test.h"
+
+static const int kLATCBlockDimension = 4;
+static const int kLATCEncodedBlockSize = 8;
+
+/**
+ * Make sure that we properly fail when we don't have multiple of four image dimensions.
+ */
+DEF_TEST(CompressLATCFailure, reporter) {
+ SkBitmap bitmap;
robertphillips 2014/06/11 18:16:35 kWidth & kHeight ?
krajcevski 2014/06/11 18:51:10 Done.
+ static const int width = 63;
+ static const int height = 63;
robertphillips 2014/06/11 18:16:35 MakeA8? kOpaque ??
krajcevski 2014/06/11 18:51:10 Done.
+ SkImageInfo info = SkImageInfo::Make(width, height,
+ kAlpha_8_SkColorType,
+ kOpaque_SkAlphaType);
+ REPORTER_ASSERT(reporter, width % kLATCBlockDimension != 0);
+ REPORTER_ASSERT(reporter, height % kLATCBlockDimension != 0);
+
robertphillips 2014/06/11 18:16:36 Make the next two lines one line ?
krajcevski 2014/06/11 18:51:10 Done.
+ bool setInfoSuccess = false;
+ setInfoSuccess = bitmap.setInfo(info);
+ REPORTER_ASSERT(reporter, setInfoSuccess);
+
robertphillips 2014/06/11 18:16:35 1 line?
krajcevski 2014/06/11 18:51:10 Done.
+ bool allocPixelsSuccess = false;
+ allocPixelsSuccess = bitmap.allocPixels(info);
+ REPORTER_ASSERT(reporter, allocPixelsSuccess);
+ bitmap.unlockPixels();
+
+ const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_Format;
robertphillips 2014/06/11 18:16:35 What makes this bitmap white?
krajcevski 2014/06/11 18:51:10 Artifact of copypasta. Fixed.
+ SkAutoDataUnref whiteLATC(SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat));
+ REPORTER_ASSERT(reporter, NULL == whiteLATC);
+}
+
+/**
+ * Make sure that if we pass in a solid color bitmap that we get the appropriate results
+ */
+DEF_TEST(CompressLATC, reporter) {
+ SkBitmap bitmap;
robertphillips 2014/06/11 18:16:35 kWidth, kHeight?
krajcevski 2014/06/11 18:51:11 Done.
+ static const int width = 8;
+ static const int height = 8;
robertphillips 2014/06/11 18:16:35 Same as above ?
krajcevski 2014/06/11 18:51:11 Done.
+ SkImageInfo info = SkImageInfo::Make(width, height,
+ kAlpha_8_SkColorType,
+ kOpaque_SkAlphaType);
+
robertphillips 2014/06/11 18:16:36 1 line ?
krajcevski 2014/06/11 18:51:11 Done.
+ bool setInfoSuccess = false;
+ setInfoSuccess = bitmap.setInfo(info);
+ REPORTER_ASSERT(reporter, setInfoSuccess);
+
robertphillips 2014/06/11 18:16:36 1 line ?
krajcevski 2014/06/11 18:51:10 Done.
+ bool allocPixelsSuccess = false;
+ allocPixelsSuccess = bitmap.allocPixels(info);
+ REPORTER_ASSERT(reporter, allocPixelsSuccess);
+
robertphillips 2014/06/11 18:16:35 I would just ditch this test here and check it eve
krajcevski 2014/06/11 18:51:10 Done.
+ uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
+ bitmap.unlockPixels();
+ REPORTER_ASSERT(reporter, NULL != pixels);
+
+ REPORTER_ASSERT(reporter, width % kLATCBlockDimension == 0);
+ REPORTER_ASSERT(reporter, height % kLATCBlockDimension == 0);
+ int numBlocks = (width / kLATCBlockDimension) * (height / kLATCBlockDimension);
+
+ for (int lum = 0; lum < 256; ++lum) {
robertphillips 2014/06/11 18:16:36 regrab the pixels in here ?
krajcevski 2014/06/11 18:51:11 Done.
+ bitmap.lockPixels();
+ for (int i = 0; i < width*height; ++i) {
+ pixels[i] = lum;
+ }
+ bitmap.unlockPixels();
+
+ const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_Format;
+ SkAutoDataUnref latcData(
+ SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat));
+ REPORTER_ASSERT(reporter, NULL != latcData);
+
robertphillips 2014/06/11 18:16:36 Move kSizeToBe out of the loop?
krajcevski 2014/06/11 18:51:11 Done.
+ const size_t kSizeToBe = static_cast<size_t>(kLATCEncodedBlockSize * numBlocks);
+ REPORTER_ASSERT(reporter, kSizeToBe == latcData->size());
+
+ // Make sure that it all matches a given block encoding.
robertphillips 2014/06/11 18:16:35 Rename 'encoding' 'encodedConstColorBlock' - or so
krajcevski 2014/06/11 18:51:10 Done.
+ const uint64_t encoding = SkEndian_SwapLE64(lum | (lum << 8));
+ const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->data());
robertphillips 2014/06/11 18:16:36 ++i ?
krajcevski 2014/06/11 18:51:11 Done.
+ for (int i = 0; i < numBlocks; i++) {
+ REPORTER_ASSERT(reporter, blockPtr[i] == encoding);
+ }
+ }
+}
« no previous file with comments | « src/utils/SkTextureCompressor.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698