Index: tests/SwizzlerTest.cpp |
diff --git a/tests/SwizzlerTest.cpp b/tests/SwizzlerTest.cpp |
index 256a4b2bcded2fe3359284fc2fc1dc22e4b6297e..d7f7bcaf1097795065e1edb97245cec7d3e3fb4a 100644 |
--- a/tests/SwizzlerTest.cpp |
+++ b/tests/SwizzlerTest.cpp |
@@ -9,8 +9,21 @@ |
#include "Test.h" |
// These are the values that we will look for to indicate that the fill was successful |
-static const uint8_t kFillIndex = 0x1; |
-static const uint32_t kFillColor = 0x22334455; |
+static const uint8_t kFillIndex = 0x11; |
+static const uint8_t kFillGray = 0x22; |
+static const uint16_t kFill565 = 0x3344; |
+static const uint32_t kFillColor = 0x55667788; |
+ |
+// We just need this function to return any valid SrcConfig, so we can create a swizzler. |
+// The SrcConfig is not actually relevant to testing the fill function. |
+static SkSwizzler::SrcConfig get_valid_src_config(SkColorType colorType) { |
+ switch (colorType) { |
+ case kGray_8_SkColorType: |
+ return SkSwizzler::kGray; |
+ default: |
+ return SkSwizzler::kIndex; |
+ } |
+} |
static void check_fill(skiatest::Reporter* r, |
const SkImageInfo& imageInfo, |
@@ -18,8 +31,7 @@ static void check_fill(skiatest::Reporter* r, |
uint32_t endRow, |
size_t rowBytes, |
uint32_t offset, |
- uint32_t colorOrIndex, |
- SkPMColor* colorTable) { |
+ uint32_t colorOrIndex) { |
// Calculate the total size of the image in bytes. Use the smallest possible size. |
// The offset value tells us to adjust the pointer from the memory we allocate in order |
@@ -35,15 +47,22 @@ static void check_fill(skiatest::Reporter* r, |
uint8_t* imageData = storage.get() + offset; |
uint8_t* imageStart = imageData + rowBytes * startRow; |
- // Fill image with the fill value starting at the indicated row |
- SkSwizzler::Fill(imageStart, imageInfo, rowBytes, endRow - startRow + 1, colorOrIndex, |
- colorTable, SkCodec::kNo_ZeroInitialized); |
+ // The SrcConfig for the swizzler does not matter here. We just need to choose one that is |
+ // supported so the swizzler is created successfully. |
+ SkSwizzler::SrcConfig config = get_valid_src_config(imageInfo.colorType()); |
+ SkPMColor colorTable[256]; |
+ SkAutoTDelete<SkSwizzler> swizzler(SkSwizzler::CreateSwizzler(config, colorTable, imageInfo, |
+ SkCodec::kNo_ZeroInitialized)); |
+ SkASSERT(nullptr != swizzler); |
+ swizzler->fill(imageStart, imageInfo.colorType(), endRow - startRow + 1, rowBytes, colorOrIndex, |
+ SkCodec::kNo_ZeroInitialized); |
// Ensure that the pixels are filled properly |
// The bots should catch any memory corruption |
uint8_t* indexPtr = imageData + startRow * rowBytes; |
uint8_t* grayPtr = indexPtr; |
uint32_t* colorPtr = (uint32_t*) indexPtr; |
+ uint16_t* color565Ptr = (uint16_t*) indexPtr; |
for (uint32_t y = startRow; y <= endRow; y++) { |
for (int32_t x = 0; x < imageInfo.width(); x++) { |
switch (imageInfo.colorType()) { |
@@ -54,8 +73,10 @@ static void check_fill(skiatest::Reporter* r, |
REPORTER_ASSERT(r, kFillColor == colorPtr[x]); |
break; |
case kGray_8_SkColorType: |
- // We always fill kGray with black |
- REPORTER_ASSERT(r, (uint8_t) kFillColor == grayPtr[x]); |
+ REPORTER_ASSERT(r, kFillGray == grayPtr[x]); |
+ break; |
+ case kRGB_565_SkColorType: |
+ REPORTER_ASSERT(r, kFill565 == color565Ptr[x]); |
break; |
default: |
REPORTER_ASSERT(r, false); |
@@ -69,12 +90,6 @@ static void check_fill(skiatest::Reporter* r, |
// Test Fill() with different combinations of dimensions, alignment, and padding |
DEF_TEST(SwizzlerFill, r) { |
- // Set up a color table |
- SkPMColor colorTable[kFillIndex + 1]; |
- colorTable[kFillIndex] = kFillColor; |
- // Apart from the fill index, we will leave the other colors in the color table uninitialized. |
- // If we incorrectly try to fill with this uninitialized memory, the bots will catch it. |
- |
// Test on an invalid width and representative widths |
const uint32_t widths[] = { 0, 10, 50 }; |
@@ -90,18 +105,20 @@ DEF_TEST(SwizzlerFill, r) { |
for (uint32_t height : heights) { |
// Create image info objects |
- const SkImageInfo colorInfo = SkImageInfo::MakeN32(width, height, |
- kUnknown_SkAlphaType); |
- const SkImageInfo indexInfo = colorInfo.makeColorType(kIndex_8_SkColorType); |
+ const SkImageInfo colorInfo = SkImageInfo::MakeN32(width, height, kUnknown_SkAlphaType); |
const SkImageInfo grayInfo = colorInfo.makeColorType(kGray_8_SkColorType); |
+ const SkImageInfo indexInfo = colorInfo.makeColorType(kIndex_8_SkColorType); |
+ const SkImageInfo color565Info = colorInfo.makeColorType(kRGB_565_SkColorType); |
for (uint32_t padding : paddings) { |
// Calculate row bytes |
- size_t colorRowBytes = SkColorTypeBytesPerPixel(kN32_SkColorType) * width + |
- padding; |
- size_t indexRowBytes = width + padding; |
- size_t grayRowBytes = indexRowBytes; |
+ const size_t colorRowBytes = SkColorTypeBytesPerPixel(kN32_SkColorType) * width |
+ + padding; |
+ const size_t indexRowBytes = width + padding; |
+ const size_t grayRowBytes = indexRowBytes; |
+ const size_t color565RowBytes = |
+ SkColorTypeBytesPerPixel(kRGB_565_SkColorType) * width + padding; |
// If there is padding, we can invent an offset to change the memory alignment |
for (uint32_t offset = 0; offset <= padding; offset++) { |
@@ -110,21 +127,15 @@ DEF_TEST(SwizzlerFill, r) { |
for (uint32_t startRow = 0; startRow < height; startRow++) { |
for (uint32_t endRow = startRow; endRow < height; endRow++) { |
- // Fill with an index that we use to look up a color |
- check_fill(r, colorInfo, startRow, endRow, colorRowBytes, offset, |
- kFillIndex, colorTable); |
- |
- // Fill with a color |
+ // Test fill with each color type |
check_fill(r, colorInfo, startRow, endRow, colorRowBytes, offset, |
- kFillColor, nullptr); |
- |
- // Fill with an index |
+ kFillColor); |
check_fill(r, indexInfo, startRow, endRow, indexRowBytes, offset, |
- kFillIndex, nullptr); |
- |
- // Fill a grayscale image |
+ kFillIndex); |
check_fill(r, grayInfo, startRow, endRow, grayRowBytes, offset, |
- kFillColor, nullptr); |
+ kFillGray); |
+ check_fill(r, color565Info, startRow, endRow, color565RowBytes, offset, |
+ kFill565); |
} |
} |
} |