| Index: src/codec/SkSwizzler.cpp
|
| diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp
|
| index a3f14881713250203e865c7eb10c9cb194d82773..c75325a74efcdc0159ce7bdaef2af33f31c3ade4 100644
|
| --- a/src/codec/SkSwizzler.cpp
|
| +++ b/src/codec/SkSwizzler.cpp
|
| @@ -714,59 +714,70 @@ SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC
|
| fX0 * fDeltaSrc, fColorTable);
|
| }
|
|
|
| -void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstRowBytes,
|
| - uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable,
|
| - SkCodec::ZeroInitialized zeroInit) {
|
| - SkASSERT(dstStartRow != nullptr);
|
| - SkASSERT(numRows <= (uint32_t) dstInfo.height());
|
| +void SkSwizzler::Fill(void* fillDst, const SkImageInfo& fillInfo, size_t rowBytes,
|
| + uint32_t colorOrIndex, SkCodec::ZeroInitialized zeroInit) {
|
| + SkASSERT(fillDst != nullptr);
|
|
|
| // Calculate bytes to fill. We use getSafeSize since the last row may not be padded.
|
| - const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeSize(dstRowBytes);
|
| + const size_t bytesToFill = fillInfo.getSafeSize(rowBytes);
|
|
|
| // Use the proper memset routine to fill the remaining bytes
|
| - switch(dstInfo.colorType()) {
|
| - case kN32_SkColorType:
|
| - // Assume input is an index if we have a color table
|
| - uint32_t color;
|
| - if (nullptr != colorTable) {
|
| - color = colorTable[(uint8_t) colorOrIndex];
|
| - // Otherwise, assume the input is a color
|
| - } else {
|
| - color = colorOrIndex;
|
| - }
|
| -
|
| + switch(fillInfo.colorType()) {
|
| + case kN32_SkColorType: {
|
| // If memory is zero initialized, we may not need to fill
|
| + uint32_t color = colorOrIndex;
|
| if (SkCodec::kYes_ZeroInitialized == zeroInit && 0 == color) {
|
| return;
|
| }
|
|
|
| // We must fill row by row in the case of unaligned row bytes
|
| - if (SkIsAlign4((size_t) dstStartRow) && SkIsAlign4(dstRowBytes)) {
|
| - sk_memset32((uint32_t*) dstStartRow, color,
|
| + if (SkIsAlign4((size_t) fillDst) && SkIsAlign4(rowBytes)) {
|
| + sk_memset32((uint32_t*) fillDst, color,
|
| (uint32_t) bytesToFill / sizeof(SkPMColor));
|
| } else {
|
| - // This is an unlikely, slow case
|
| + // We must fill row by row in the case of unaligned row bytes. This is an
|
| + // unlikely, slow case.
|
| SkCodecPrintf("Warning: Strange number of row bytes, fill will be slow.\n");
|
| - uint32_t* dstRow = (uint32_t*) dstStartRow;
|
| - for (uint32_t row = 0; row < numRows; row++) {
|
| - for (int32_t col = 0; col < dstInfo.width(); col++) {
|
| + uint32_t* dstRow = (uint32_t*) fillDst;
|
| + for (uint32_t row = 0; row < fillInfo.height(); row++) {
|
| + for (int32_t col = 0; col < fillInfo.width(); col++) {
|
| dstRow[col] = color;
|
| }
|
| - dstRow = SkTAddOffset<uint32_t>(dstRow, dstRowBytes);
|
| + dstRow = SkTAddOffset<uint32_t>(dstRow, rowBytes);
|
| }
|
| }
|
| break;
|
| - case kRGB_565_SkColorType:
|
| + }
|
| + case kRGB_565_SkColorType: {
|
| // If the destination is k565, the caller passes in a 16-bit color.
|
| // We will not assert that the high bits of colorOrIndex must be zeroed.
|
| // This allows us to take advantage of the fact that the low 16 bits of an
|
| // SKPMColor may be a valid a 565 color. For example, the low 16
|
| // bits of SK_ColorBLACK are identical to the 565 representation
|
| // for black.
|
| - // If we ever want to fill with colorOrIndex != 0, we will probably need
|
| - // to implement this with sk_memset16().
|
| - SkASSERT((uint16_t) colorOrIndex == (uint8_t) colorOrIndex);
|
| - // Fall through
|
| +
|
| + // If memory is zero initialized, we may not need to fill
|
| + uint16_t color = (uint16_t) colorOrIndex;
|
| + if (SkCodec::kYes_ZeroInitialized == zeroInit && 0 == color) {
|
| + return;
|
| + }
|
| +
|
| + if (SkIsAlign2((size_t) fillDst) && SkIsAlign2(rowBytes)) {
|
| + sk_memset16((uint16_t*) fillDst, color, (uint32_t) bytesToFill / sizeof(uint16_t));
|
| + } else {
|
| + // We must fill row by row in the case of unaligned row bytes. This is an
|
| + // unlikely, slow case.
|
| + SkCodecPrintf("Warning: Strange number of row bytes, fill will be slow.\n");
|
| + uint16_t* dstRow = (uint16_t*) fillDst;
|
| + for (uint32_t row = 0; row < fillInfo.height(); row++) {
|
| + for (int32_t col = 0; col < fillInfo.width(); col++) {
|
| + dstRow[col] = color;
|
| + }
|
| + dstRow = SkTAddOffset<uint16_t>(dstRow, rowBytes);
|
| + }
|
| + }
|
| + break;
|
| + }
|
| case kIndex_8_SkColorType:
|
| // On an index destination color type, always assume the input is an index.
|
| // Fall through
|
| @@ -783,7 +794,7 @@ void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR
|
| return;
|
| }
|
|
|
| - memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill);
|
| + memset(fillDst, (uint8_t) colorOrIndex, bytesToFill);
|
| break;
|
| default:
|
| SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
|
|
|