Chromium Code Reviews| Index: src/codec/SkSwizzler.cpp |
| diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp |
| index 3e7387795b61c59b3b06f202218d78417680cae2..fd1937f4e2ccc3290dd88e4f328ecf2a2fc34709 100644 |
| --- a/src/codec/SkSwizzler.cpp |
| +++ b/src/codec/SkSwizzler.cpp |
| @@ -7,6 +7,7 @@ |
| #include "SkCodecPriv.h" |
| #include "SkColorPriv.h" |
| +#include "SkOpts.h" |
| #include "SkSwizzler.h" |
| #include "SkTemplates.h" |
| @@ -367,7 +368,6 @@ static void swizzle_rgbx_to_565( |
| } |
| } |
| - |
| // kRGBA |
| static void swizzle_rgba_to_n32_premul( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| @@ -382,6 +382,21 @@ static void swizzle_rgba_to_n32_premul( |
| } |
| } |
| +static void fast_swizzle_rgba_to_n32_premul( |
| + void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, |
| + int offset, const SkPMColor ctable[]) { |
| + |
| + // This function must not be called if we are sampling. If we are not |
| + // sampling, deltaSrc should equal bpp. |
| + SkASSERT(deltaSrc == bpp); |
| + |
| +#ifdef SK_PMCOLOR_IS_RGBA |
| + SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width); |
| +#else |
| + SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width); |
| +#endif |
| +} |
| + |
| static void swizzle_rgba_to_n32_unpremul( |
| void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| @@ -527,6 +542,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| && nullptr == ctable) { |
| return nullptr; |
| } |
| + RowProc fastProc = nullptr; |
| RowProc proc = nullptr; |
| SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; |
| switch (sc) { |
| @@ -634,7 +650,6 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| } |
| break; |
| case kRGBX: |
| - // TODO: Support other swizzles. |
| switch (dstInfo.colorType()) { |
| case kN32_SkColorType: |
| proc = &swizzle_rgbx_to_n32; |
| @@ -652,6 +667,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| // Respect zeroInit? |
| proc = &swizzle_rgba_to_n32_unpremul; |
| } else { |
| + fastProc = &fast_swizzle_rgba_to_n32_premul; |
| if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| proc = &swizzle_rgba_to_n32_premul_skipZ; |
| } else { |
| @@ -696,9 +712,6 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| default: |
| break; |
| } |
| - if (nullptr == proc) { |
| - return nullptr; |
| - } |
| // Store bpp in bytes if it is an even multiple, otherwise use bits |
| int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel(sc); |
| @@ -720,12 +733,14 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| srcWidth = frame->width(); |
| } |
| - return new SkSwizzler(proc, ctable, srcOffset, srcWidth, dstOffset, dstWidth, srcBPP, dstBPP); |
| + return new SkSwizzler(fastProc, proc, ctable, srcOffset, srcWidth, dstOffset, dstWidth, |
| + srcBPP, dstBPP); |
| } |
| -SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int srcWidth, |
| - int dstOffset, int dstWidth, int srcBPP, int dstBPP) |
| - : fRowProc(proc) |
| +SkSwizzler::SkSwizzler(RowProc fastProc, RowProc proc, const SkPMColor* ctable, int srcOffset, |
| + int srcWidth, int dstOffset, int dstWidth, int srcBPP, int dstBPP) |
| + : fFastProc(fastProc) |
| + , fProc(proc) |
| , fColorTable(ctable) |
| , fSrcOffset(srcOffset) |
| , fDstOffset(dstOffset) |
| @@ -749,11 +764,19 @@ int SkSwizzler::onSetSampleX(int sampleX) { |
| fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); |
| fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); |
| + // The optimized swizzler routines do not (yet) support sampling. |
| + fFastProc = nullptr; |
| + |
| return fAllocatedWidth; |
| } |
| void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
| SkASSERT(nullptr != dst && nullptr != src); |
| - fRowProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP, |
| - fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
| + if (fFastProc) { |
|
mtklein
2016/01/11 21:07:21
You might do
RowProc proc = fFastProc ? fFastProc
msarett
2016/01/12 14:35:51
Done.
|
| + fFastProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP, |
| + fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
| + } else { |
| + fProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP, |
| + fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable);; |
| + } |
| } |