aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkConfig8888.cpp
diff options
context:
space:
mode:
authorGravatar lsalzman <lsalzman@mozilla.com>2016-10-11 14:29:12 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-10-11 14:29:12 -0700
commita2415accf1f184c4df6cffc2ccdd38f8d61031f6 (patch)
treef11d09373d33a01bbb5ecdbc9650f8017e910fd7 /src/core/SkConfig8888.cpp
parent0f61faa7b7041efcedd1363b11b44fa97ad97448 (diff)
implement A8 destination fast-path for SkPixelInfo::CopyPixels
Diffstat (limited to 'src/core/SkConfig8888.cpp')
-rw-r--r--src/core/SkConfig8888.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/core/SkConfig8888.cpp b/src/core/SkConfig8888.cpp
index 31def9a92d..7c3f0214e3 100644
--- a/src/core/SkConfig8888.cpp
+++ b/src/core/SkConfig8888.cpp
@@ -167,6 +167,64 @@ static void copy_32_to_g8(void* dst, size_t dstRB, const void* src, size_t srcRB
}
}
+static bool extract_alpha(void* dst, size_t dstRB, const void* src, size_t srcRB,
+ const SkImageInfo& srcInfo, SkColorTable* ctable) {
+ uint8_t* SK_RESTRICT dst8 = (uint8_t*)dst;
+
+ const int w = srcInfo.width();
+ const int h = srcInfo.height();
+ if (srcInfo.isOpaque()) {
+ // src is opaque, so just fill alpha with 0xFF
+ for (int y = 0; y < h; ++y) {
+ memset(dst8, 0xFF, w);
+ dst8 += dstRB;
+ }
+ return true;
+ }
+ switch (srcInfo.colorType()) {
+ case kN32_SkColorType: {
+ const SkPMColor* SK_RESTRICT src32 = (const SkPMColor*)src;
+ for (int y = 0; y < h; ++y) {
+ for (int x = 0; x < w; ++x) {
+ dst8[x] = SkGetPackedA32(src32[x]);
+ }
+ dst8 += dstRB;
+ src32 = (const SkPMColor*)((const char*)src32 + srcRB);
+ }
+ break;
+ }
+ case kARGB_4444_SkColorType: {
+ const SkPMColor16* SK_RESTRICT src16 = (const SkPMColor16*)src;
+ for (int y = 0; y < h; ++y) {
+ for (int x = 0; x < w; ++x) {
+ dst8[x] = SkPacked4444ToA32(src16[x]);
+ }
+ dst8 += dstRB;
+ src16 = (const SkPMColor16*)((const char*)src16 + srcRB);
+ }
+ break;
+ }
+ case kIndex_8_SkColorType: {
+ if (nullptr == ctable) {
+ return false;
+ }
+ const SkPMColor* SK_RESTRICT table = ctable->readColors();
+ const uint8_t* SK_RESTRICT src8 = (const uint8_t*)src;
+ for (int y = 0; y < h; ++y) {
+ for (int x = 0; x < w; ++x) {
+ dst8[x] = SkGetPackedA32(table[src8[x]]);
+ }
+ dst8 += dstRB;
+ src8 += srcRB;
+ }
+ break;
+ }
+ default:
+ return false;
+ }
+ return true;
+}
+
bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRB,
SkColorTable* ctable) {
@@ -241,6 +299,11 @@ bool SkPixelInfo::CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t
return true;
}
+ if (kAlpha_8_SkColorType == dstInfo.colorType() &&
+ extract_alpha(dstPixels, dstRB, srcPixels, srcRB, srcInfo, ctable)) {
+ return true;
+ }
+
// Can no longer draw directly into 4444, but we can manually whack it for a few combinations
if (kARGB_4444_SkColorType == dstInfo.colorType() &&
(kN32_SkColorType == srcInfo.colorType() || kIndex_8_SkColorType == srcInfo.colorType())) {