aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-05 13:43:15 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-05 13:43:15 +0000
commit8ef51b975c2bdb8fa332f091863e5410c18576c7 (patch)
tree16d7c9bc2613cb2daa63c44ca71161c88e8df1ea /tests
parentf1f66c0c8623805fdb88f09c0d87cbdd1745e12b (diff)
remove deprecated use of bitmap config from tests
BUG=skia: R=halcanary@google.com, reed@google.com Author: reed@chromium.org Review URL: https://codereview.chromium.org/184233003 git-svn-id: http://skia.googlecode.com/svn/trunk@13666 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/BitmapCopyTest.cpp54
-rw-r--r--tests/BitmapGetColorTest.cpp25
-rw-r--r--tests/BitmapHasherTest.cpp15
-rw-r--r--tests/BlitRowTest.cpp20
-rw-r--r--tests/DrawTextTest.cpp9
-rw-r--r--tests/FontHostStreamTest.cpp9
-rw-r--r--tests/PixelRefTest.cpp36
7 files changed, 57 insertions, 111 deletions
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp
index db03e5cddb..f734ad8356 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -4,6 +4,7 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#include "SkBitmap.h"
#include "SkRect.h"
#include "Test.h"
@@ -12,7 +13,7 @@ static const char* boolStr(bool value) {
return value ? "true" : "false";
}
-// these are in the same order as the SkBitmap::Config enum
+// these are in the same order as the SkColorType enum
static const char* gColorTypeName[] = {
"None", "A8", "565", "4444", "RGBA", "BGRA", "Index8"
};
@@ -89,17 +90,15 @@ static uint32_t getPixel(int x, int y, const SkBitmap& bm) {
SkAutoLockPixels lock(bm);
const void* rawAddr = bm.getAddr(x,y);
- switch (bm.config()) {
- case SkBitmap::kARGB_8888_Config:
+ switch (bm.bytesPerPixel()) {
+ case 4:
memcpy(&val, rawAddr, sizeof(uint32_t));
break;
- case SkBitmap::kARGB_4444_Config:
- case SkBitmap::kRGB_565_Config:
+ case 2:
memcpy(&val16, rawAddr, sizeof(uint16_t));
val = val16;
break;
- case SkBitmap::kA8_Config:
- case SkBitmap::kIndex8_Config:
+ case 1:
memcpy(&val8, rawAddr, sizeof(uint8_t));
val = val8;
break;
@@ -118,17 +117,15 @@ static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) {
SkAutoLockPixels lock(bm);
void* rawAddr = bm.getAddr(x,y);
- switch (bm.config()) {
- case SkBitmap::kARGB_8888_Config:
+ switch (bm.bytesPerPixel()) {
+ case 4:
memcpy(rawAddr, &val, sizeof(uint32_t));
break;
- case SkBitmap::kARGB_4444_Config:
- case SkBitmap::kRGB_565_Config:
+ case 2:
val16 = val & 0xFFFF;
memcpy(rawAddr, &val16, sizeof(uint16_t));
break;
- case SkBitmap::kA8_Config:
- case SkBitmap::kIndex8_Config:
+ case 1:
val8 = val & 0xFF;
memcpy(rawAddr, &val8, sizeof(uint8_t));
break;
@@ -138,20 +135,6 @@ static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) {
}
}
-// Utility to return string containing name of each format, to
-// simplify diagnostic output.
-static const char* getSkConfigName(const SkBitmap& bm) {
- switch (bm.config()) {
- case SkBitmap::kNo_Config: return "SkBitmap::kNo_Config";
- case SkBitmap::kA8_Config: return "SkBitmap::kA8_Config";
- case SkBitmap::kIndex8_Config: return "SkBitmap::kIndex8_Config";
- case SkBitmap::kRGB_565_Config: return "SkBitmap::kRGB_565_Config";
- case SkBitmap::kARGB_4444_Config: return "SkBitmap::kARGB_4444_Config";
- case SkBitmap::kARGB_8888_Config: return "SkBitmap::kARGB_8888_Config";
- default: return "Unknown SkBitmap configuration.";
- }
-}
-
// Helper struct to contain pixel locations, while avoiding need for STL.
struct Coordinates {
@@ -188,7 +171,8 @@ static void reportCopyVerification(const SkBitmap& bm1, const SkBitmap& bm2,
}
if (!success) {
- ERRORF(reporter, "%s [config = %s]", msg, getSkConfigName(bm1));
+ ERRORF(reporter, "%s [colortype = %s]", msg,
+ gColorTypeName[bm1.colorType()]);
}
}
@@ -317,7 +301,7 @@ DEF_TEST(BitmapCopy, reporter) {
REPORTER_ASSERT(reporter, srcPremul.height() == dst.height());
REPORTER_ASSERT(reporter, dst.colorType() == gPairs[j].fColorType);
test_isOpaque(reporter, srcOpaque, srcPremul, dst.colorType());
- if (srcPremul.config() == dst.config()) {
+ if (srcPremul.colorType() == dst.colorType()) {
SkAutoLockPixels srcLock(srcPremul);
SkAutoLockPixels dstLock(dst);
REPORTER_ASSERT(reporter, srcPremul.readyToDraw());
@@ -333,7 +317,7 @@ DEF_TEST(BitmapCopy, reporter) {
}
} else {
// dst should be unchanged from its initial state
- REPORTER_ASSERT(reporter, dst.config() == SkBitmap::kNo_Config);
+ REPORTER_ASSERT(reporter, dst.colorType() == kUnknown_SkColorType);
REPORTER_ASSERT(reporter, dst.width() == 0);
REPORTER_ASSERT(reporter, dst.height() == 0);
}
@@ -358,7 +342,7 @@ DEF_TEST(BitmapCopy, reporter) {
int64_t safeSize = tstSafeSize.computeSafeSize64();
if (safeSize < 0) {
ERRORF(reporter, "getSafeSize64() negative: %s",
- getSkConfigName(tstSafeSize));
+ gColorTypeName[tstSafeSize.colorType()]);
}
bool sizeFail = false;
// Compare against hand-computed values.
@@ -391,7 +375,7 @@ DEF_TEST(BitmapCopy, reporter) {
}
if (sizeFail) {
ERRORF(reporter, "computeSafeSize64() wrong size: %s",
- getSkConfigName(tstSafeSize));
+ gColorTypeName[tstSafeSize.colorType()]);
}
int subW = 2;
@@ -400,7 +384,7 @@ DEF_TEST(BitmapCopy, reporter) {
// Create bitmap to act as source for copies and subsets.
SkBitmap src, subset;
SkColorTable* ct = NULL;
- if (SkBitmap::kIndex8_Config == src.config()) {
+ if (kIndex_8_SkColorType == src.colorType()) {
ct = init_ctable(kPremul_SkAlphaType);
}
@@ -419,7 +403,7 @@ DEF_TEST(BitmapCopy, reporter) {
// for subsequent calls to copyPixelsTo/From.
bool srcReady = false;
// Test relies on older behavior that extractSubset will fail on
- // no_config
+ // kUnknown_SkColorType
if (kUnknown_SkColorType != src.colorType() &&
isExtracted[copyCase]) {
// The extractedSubset() test case allows us to test copy-
@@ -440,7 +424,7 @@ DEF_TEST(BitmapCopy, reporter) {
// buf to a SkBitmap, but copies are done using the
// raw buffer pointer.
const size_t bufSize = subH *
- SkBitmap::ComputeRowBytes(src.config(), subW) * 2;
+ SkColorTypeMinRowBytes(src.colorType(), subW) * 2;
SkAutoMalloc autoBuf (bufSize);
uint8_t* buf = static_cast<uint8_t*>(autoBuf.get());
diff --git a/tests/BitmapGetColorTest.cpp b/tests/BitmapGetColorTest.cpp
index 8df8661b05..28f3cb309d 100644
--- a/tests/BitmapGetColorTest.cpp
+++ b/tests/BitmapGetColorTest.cpp
@@ -12,19 +12,19 @@
DEF_TEST(GetColor, reporter) {
static const struct Rec {
- SkBitmap::Config fConfig;
- SkColor fInColor;
- SkColor fOutColor;
+ SkColorType fColorType;
+ SkColor fInColor;
+ SkColor fOutColor;
} gRec[] = {
// todo: add some tests that involve alpha, so we exercise the
// unpremultiply aspect of getColor()
- { SkBitmap::kA8_Config, 0xFF000000, 0xFF000000 },
- { SkBitmap::kA8_Config, 0, 0 },
- { SkBitmap::kRGB_565_Config, 0xFF00FF00, 0xFF00FF00 },
- { SkBitmap::kRGB_565_Config, 0xFFFF00FF, 0xFFFF00FF },
- { SkBitmap::kARGB_8888_Config, 0xFFFFFFFF, 0xFFFFFFFF },
- { SkBitmap::kARGB_8888_Config, 0, 0 },
- { SkBitmap::kARGB_8888_Config, 0xFF224466, 0xFF224466 },
+ { kAlpha_8_SkColorType, 0xFF000000, 0xFF000000 },
+ { kAlpha_8_SkColorType, 0, 0 },
+ { kRGB_565_SkColorType, 0xFF00FF00, 0xFF00FF00 },
+ { kRGB_565_SkColorType, 0xFFFF00FF, 0xFFFF00FF },
+ { kPMColor_SkColorType, 0xFFFFFFFF, 0xFFFFFFFF },
+ { kPMColor_SkColorType, 0, 0 },
+ { kPMColor_SkColorType, 0xFF224466, 0xFF224466 },
};
// specify an area that doesn't touch (0,0) and may extend beyond the
@@ -33,10 +33,11 @@ DEF_TEST(GetColor, reporter) {
const SkIRect area = { 1, 1, 3, 3 };
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
+ SkImageInfo info = SkImageInfo::Make(2, 2, gRec[i].fColorType,
+ kPremul_SkAlphaType);
SkBitmap bm;
uint32_t storage[4];
- bm.setConfig(gRec[i].fConfig, 2, 2);
- bm.setPixels(storage);
+ bm.installPixels(info, storage, info.minRowBytes(), NULL, NULL);
bm.eraseColor(initColor);
bm.eraseArea(area, gRec[i].fInColor);
diff --git a/tests/BitmapHasherTest.cpp b/tests/BitmapHasherTest.cpp
index 2c1f4a39df..e39439a11f 100644
--- a/tests/BitmapHasherTest.cpp
+++ b/tests/BitmapHasherTest.cpp
@@ -15,12 +15,11 @@
typedef uint64_t checksum_result;
// Fill in bitmap with test data.
-static void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int width, int height,
+static void CreateTestBitmap(SkBitmap* bitmap, int width, int height,
SkColor color, skiatest::Reporter* reporter) {
- bitmap.setConfig(config, width, height);
- REPORTER_ASSERT(reporter, bitmap.allocPixels());
- bitmap.setAlphaType(kOpaque_SkAlphaType);
- bitmap.eraseColor(color);
+ SkImageInfo info = SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType);
+ REPORTER_ASSERT(reporter, bitmap->allocPixels(info));
+ bitmap->eraseColor(color);
}
DEF_TEST(BitmapHasher, reporter) {
@@ -28,15 +27,15 @@ DEF_TEST(BitmapHasher, reporter) {
SkBitmap bitmap;
uint64_t digest;
// initial test case
- CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_ColorBLUE, reporter);
+ CreateTestBitmap(&bitmap, 333, 555, SK_ColorBLUE, reporter);
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
REPORTER_ASSERT(reporter, digest == 0xfb2903562766ef87ULL);
// same pixel data but different dimensions should yield a different checksum
- CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorBLUE, reporter);
+ CreateTestBitmap(&bitmap, 555, 333, SK_ColorBLUE, reporter);
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
REPORTER_ASSERT(reporter, digest == 0xfe04023fb97d0f61ULL);
// same dimensions but different color should yield a different checksum
- CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorGREEN, reporter);
+ CreateTestBitmap(&bitmap, 555, 333, SK_ColorGREEN, reporter);
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
REPORTER_ASSERT(reporter, digest == 0x2423c51cad6d1edcULL);
}
diff --git a/tests/BlitRowTest.cpp b/tests/BlitRowTest.cpp
index 84e61f307a..b8ac0c06c7 100644
--- a/tests/BlitRowTest.cpp
+++ b/tests/BlitRowTest.cpp
@@ -13,8 +13,8 @@
#include "Test.h"
// these are in the same order as the SkColorType enum
-static const char* gConfigName[] = {
- "Unknown", "Alpha8", "565", "4444", "RGBA", "BGRA", "Index8"
+static const char* gColorTypeName[] = {
+ "None", "A8", "565", "4444", "RGBA", "BGRA", "Index8"
};
/** Returns -1 on success, else the x coord of the first bad pixel, return its
@@ -62,15 +62,15 @@ static int proc_bad(const void*, int, uint32_t, uint32_t* bad) {
static Proc find_proc(const SkBitmap& bm, SkPMColor expect32, uint16_t expect16,
uint8_t expect8, uint32_t* expect) {
- switch (bm.config()) {
- case SkBitmap::kARGB_8888_Config:
+ switch (bm.colorType()) {
+ case kPMColor_SkColorType:
*expect = expect32;
return proc_32;
- case SkBitmap::kARGB_4444_Config:
- case SkBitmap::kRGB_565_Config:
+ case kARGB_4444_SkColorType:
+ case kRGB_565_SkColorType:
*expect = expect16;
return proc_16;
- case SkBitmap::kA8_Config:
+ case kAlpha_8_SkColorType:
*expect = expect8;
return proc_8;
default:
@@ -88,8 +88,8 @@ static bool check_color(const SkBitmap& bm, SkPMColor expect32,
uint32_t bad;
int x = proc(bm.getAddr(0, y), bm.width(), expect, &bad);
if (x >= 0) {
- ERRORF(reporter, "BlitRow config=%s [%d %d] expected %x got %x",
- gConfigName[bm.config()], x, y, expect, bad);
+ ERRORF(reporter, "BlitRow colortype=%s [%d %d] expected %x got %x",
+ gColorTypeName[bm.colorType()], x, y, expect, bad);
return false;
}
}
@@ -249,7 +249,7 @@ static void test_diagonal(skiatest::Reporter* reporter) {
if (memcmp(dstBM0.getPixels(), dstBM1.getPixels(), dstBM0.getSize())) {
ERRORF(reporter, "Diagonal colortype=%s bg=0x%x dither=%d"
" alpha=0x%x src=0x%x",
- gConfigName[gDstColorType[i]], bgColor, dither,
+ gColorTypeName[gDstColorType[i]], bgColor, dither,
alpha, c);
}
}
diff --git a/tests/DrawTextTest.cpp b/tests/DrawTextTest.cpp
index bafd2cb5e2..3a96c4ff2d 100644
--- a/tests/DrawTextTest.cpp
+++ b/tests/DrawTextTest.cpp
@@ -16,9 +16,8 @@
static const SkColor bgColor = SK_ColorWHITE;
-static void create(SkBitmap* bm, SkIRect bound, SkBitmap::Config config) {
- bm->setConfig(config, bound.width(), bound.height());
- bm->allocPixels();
+static void create(SkBitmap* bm, SkIRect bound) {
+ bm->allocN32Pixels(bound.width(), bound.height());
}
static void drawBG(SkCanvas* canvas) {
@@ -67,12 +66,12 @@ DEF_TEST(DrawText, reporter) {
SkIRect drawTextRect = SkIRect::MakeWH(64, 64);
SkBitmap drawTextBitmap;
- create(&drawTextBitmap, drawTextRect, SkBitmap::kARGB_8888_Config);
+ create(&drawTextBitmap, drawTextRect);
SkCanvas drawTextCanvas(drawTextBitmap);
SkIRect drawPosTextRect = SkIRect::MakeWH(64, 64);
SkBitmap drawPosTextBitmap;
- create(&drawPosTextBitmap, drawPosTextRect, SkBitmap::kARGB_8888_Config);
+ create(&drawPosTextBitmap, drawPosTextRect);
SkCanvas drawPosTextCanvas(drawPosTextBitmap);
for (float offsetY = 0.0f; offsetY < 1.0f; offsetY += (1.0f / 16.0f)) {
diff --git a/tests/FontHostStreamTest.cpp b/tests/FontHostStreamTest.cpp
index a5f9ade4d1..5f959f3b87 100644
--- a/tests/FontHostStreamTest.cpp
+++ b/tests/FontHostStreamTest.cpp
@@ -20,9 +20,8 @@
static const SkColor bgColor = SK_ColorWHITE;
-static void create(SkBitmap* bm, SkIRect bound, SkBitmap::Config config) {
- bm->setConfig(config, bound.width(), bound.height());
- bm->allocPixels();
+static void create(SkBitmap* bm, SkIRect bound) {
+ bm->allocN32Pixels(bound.width(), bound.height());
}
static void drawBG(SkCanvas* canvas) {
@@ -76,12 +75,12 @@ DEF_TEST(FontHostStream, reporter) {
SkIRect origRect = SkIRect::MakeWH(64, 64);
SkBitmap origBitmap;
- create(&origBitmap, origRect, SkBitmap::kARGB_8888_Config);
+ create(&origBitmap, origRect);
SkCanvas origCanvas(origBitmap);
SkIRect streamRect = SkIRect::MakeWH(64, 64);
SkBitmap streamBitmap;
- create(&streamBitmap, streamRect, SkBitmap::kARGB_8888_Config);
+ create(&streamBitmap, streamRect);
SkCanvas streamCanvas(streamBitmap);
SkPoint point = SkPoint::Make(24, 32);
diff --git a/tests/PixelRefTest.cpp b/tests/PixelRefTest.cpp
index aeb3070eac..d1d3026f8d 100644
--- a/tests/PixelRefTest.cpp
+++ b/tests/PixelRefTest.cpp
@@ -3,40 +3,6 @@
#include "SkMallocPixelRef.h"
#include "SkPixelRef.h"
-static void test_info(skiatest::Reporter* reporter) {
- static const struct {
- SkBitmap::Config fConfig;
- SkAlphaType fAlphaType;
- SkColorType fExpectedColorType;
- bool fExpectedSuccess;
- } gRec[] = {
- { SkBitmap::kNo_Config, kPremul_SkAlphaType, kPMColor_SkColorType, false },
- { SkBitmap::kARGB_8888_Config, kPremul_SkAlphaType, kPMColor_SkColorType, true },
- { SkBitmap::kARGB_8888_Config, kOpaque_SkAlphaType, kPMColor_SkColorType, true },
- { SkBitmap::kRGB_565_Config, kOpaque_SkAlphaType, kRGB_565_SkColorType, true },
- { SkBitmap::kARGB_4444_Config, kPremul_SkAlphaType, kARGB_4444_SkColorType, true },
- { SkBitmap::kARGB_4444_Config, kOpaque_SkAlphaType, kARGB_4444_SkColorType, true },
- { SkBitmap::kA8_Config, kPremul_SkAlphaType, kAlpha_8_SkColorType, true },
- { SkBitmap::kA8_Config, kOpaque_SkAlphaType, kAlpha_8_SkColorType, true },
- { SkBitmap::kIndex8_Config, kPremul_SkAlphaType, kIndex_8_SkColorType, true },
- { SkBitmap::kIndex8_Config, kOpaque_SkAlphaType, kIndex_8_SkColorType, true },
- };
-
- SkBitmap bitmap;
- SkImageInfo info;
-
- for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
- bool success = bitmap.setConfig(gRec[i].fConfig, 10, 10, 0, gRec[i].fAlphaType);
- REPORTER_ASSERT(reporter, success);
- success = bitmap.asImageInfo(&info);
- REPORTER_ASSERT(reporter, success == gRec[i].fExpectedSuccess);
- if (success && gRec[i].fExpectedSuccess) {
- REPORTER_ASSERT(reporter, info.fAlphaType == gRec[i].fAlphaType);
- REPORTER_ASSERT(reporter, info.fColorType == gRec[i].fExpectedColorType);
- }
- }
-}
-
class TestListener : public SkPixelRef::GenIDChangeListener {
public:
explicit TestListener(int* ptr) : fPtr(ptr) {}
@@ -77,6 +43,4 @@ DEF_TEST(PixelRef_GenIDChange, r) {
REPORTER_ASSERT(r, 0 != pixelRef->getGenerationID());
pixelRef->addGenIDChangeListener(NULL);
pixelRef->notifyPixelsChanged();
-
- test_info(r);
}