diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-11-03 13:45:38 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-11-03 13:45:38 +0000 |
commit | 8e372c98bf027d2b10bd10b05eddd0087403cd2b (patch) | |
tree | 1734ae54ec97bca788d0a9937a8cbd22afdd7031 | |
parent | 51c2fa7bb19af4e1ecae00c62c61b2b6d0669728 (diff) |
custom memset32 to speed up erasing the offscreen when its width is small.
git-svn-id: http://skia.googlecode.com/svn/trunk@2594 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | bench/FontScalerBench.cpp | 13 | ||||
-rw-r--r-- | src/ports/SkFontHost_mac_coretext.cpp | 50 |
2 files changed, 58 insertions, 5 deletions
diff --git a/bench/FontScalerBench.cpp b/bench/FontScalerBench.cpp index 596b830809..4255f67bad 100644 --- a/bench/FontScalerBench.cpp +++ b/bench/FontScalerBench.cpp @@ -17,10 +17,12 @@ extern bool gSkSuppressFontCachePurgeSpew; class FontScalerBench : public SkBenchmark { SkString fName; SkString fText; + bool fDoLCD; public: - FontScalerBench(void* param) : INHERITED(param) { - fName.set("fontscaler"); + FontScalerBench(void* param, bool doLCD) : INHERITED(param) { + fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa"); fText.set("abcdefghijklmnopqrstuvwxyz01234567890"); + fDoLCD = doLCD; } protected: @@ -28,6 +30,7 @@ protected: virtual void onDraw(SkCanvas* canvas) { SkPaint paint; this->setupPaint(&paint); + paint.setLCDRenderText(fDoLCD); bool prev = gSkSuppressFontCachePurgeSpew; gSkSuppressFontCachePurgeSpew = true; @@ -49,6 +52,8 @@ private: /////////////////////////////////////////////////////////////////////////////// -static SkBenchmark* Fact(void* p) { return SkNEW_ARGS(FontScalerBench, (p)); } +static SkBenchmark* Fact0(void* p) { return SkNEW_ARGS(FontScalerBench, (p, false)); } +static SkBenchmark* Fact1(void* p) { return SkNEW_ARGS(FontScalerBench, (p, true)); } -static BenchRegistry gReg(Fact); +static BenchRegistry gReg0(Fact0); +static BenchRegistry gReg1(Fact1); diff --git a/src/ports/SkFontHost_mac_coretext.cpp b/src/ports/SkFontHost_mac_coretext.cpp index 79a0c14fa4..61919c1a3f 100644 --- a/src/ports/SkFontHost_mac_coretext.cpp +++ b/src/ports/SkFontHost_mac_coretext.cpp @@ -29,6 +29,50 @@ #include "SkUtils.h" #include "SkTypefaceCache.h" +static void sk_memset_rect32(uint32_t* ptr, uint32_t value, size_t width, + size_t height, size_t rowBytes) { + SkASSERT(width); + SkASSERT(width * sizeof(uint32_t) <= rowBytes); + + if (width >= 32) { + while (height) { + sk_memset32(ptr, value, width); + ptr = (uint32_t*)((char*)ptr + rowBytes); + height -= 1; + } + return; + } + + rowBytes -= width * sizeof(uint32_t); + + if (width >= 8) { + while (height) { + int w = width; + do { + *ptr++ = value; *ptr++ = value; + *ptr++ = value; *ptr++ = value; + *ptr++ = value; *ptr++ = value; + *ptr++ = value; *ptr++ = value; + w -= 8; + } while (w >= 8); + while (--w >= 0) { + *ptr++ = value; + } + ptr = (uint32_t*)((char*)ptr + rowBytes); + height -= 1; + } + } else { + while (height) { + int w = width; + do { + *ptr++ = value; + } while (--w > 0); + ptr = (uint32_t*)((char*)ptr + rowBytes); + height -= 1; + } + } +} + // Potentially this should be made (1) public (2) optimized when width is small. // Also might want 16 and 32 bit version // @@ -299,9 +343,13 @@ CGRGBPixel* Offscreen::getCG(const SkGlyph& glyph, bool fgColorIsWhite, image += (fSize.fHeight - glyph.fHeight) * fSize.fWidth; // erase with the "opposite" of the fgColor - uint8_t erase = fgColorIsWhite ? 0 : 0xFF; + uint32_t erase = fgColorIsWhite ? 0 : ~0; +#if 0 sk_memset_rect(image, erase, glyph.fWidth * sizeof(CGRGBPixel), glyph.fHeight, rowBytes); +#else + sk_memset_rect32(image, erase, glyph.fWidth, glyph.fHeight, rowBytes); +#endif float subX = 0; float subY = 0; |