diff options
-rw-r--r-- | bench/TextBench.cpp | 34 | ||||
-rw-r--r-- | bench/TextBlobBench.cpp | 8 | ||||
-rw-r--r-- | gm/colortype.cpp | 16 | ||||
-rw-r--r-- | gm/colortypexfermode.cpp | 25 | ||||
-rw-r--r-- | gm/textblob.cpp | 16 | ||||
-rw-r--r-- | gm/typeface.cpp | 37 | ||||
-rw-r--r-- | gm/verttext2.cpp | 15 |
7 files changed, 90 insertions, 61 deletions
diff --git a/bench/TextBench.cpp b/bench/TextBench.cpp index 4ee0fd3d25..0a6af34d8f 100644 --- a/bench/TextBench.cpp +++ b/bench/TextBench.cpp @@ -52,27 +52,33 @@ class TextBench : public Benchmark { SkPoint* fPos; public: TextBench(const char text[], int ps, - SkColor color, FontQuality fq, bool doColorEmoji = false, bool doPos = false) { - fPos = NULL; - fFQ = fq; - fDoPos = doPos; - fDoColorEmoji = doColorEmoji; - fText.set(text); - + SkColor color, FontQuality fq, bool doColorEmoji = false, bool doPos = false) + : fText(text) + , fFQ(fq) + , fDoPos(doPos) + , fDoColorEmoji(doColorEmoji) + , fPos(NULL) { fPaint.setAntiAlias(kBW != fq); fPaint.setLCDRenderText(kLCD == fq); fPaint.setTextSize(SkIntToScalar(ps)); fPaint.setColor(color); + } - if (doColorEmoji) { + virtual ~TextBench() { + delete[] fPos; + } + +protected: + void onPreDraw() override { + if (fDoColorEmoji) { SkASSERT(kBW == fFQ); fColorEmojiTypeface.reset(GetResourceAsTypeface("/fonts/Funkster.ttf")); } - if (doPos) { - size_t len = strlen(text); + if (fDoPos) { + size_t len = fText.size(); SkScalar* adv = new SkScalar[len]; - fPaint.getTextWidths(text, len, adv); + fPaint.getTextWidths(fText.c_str(), len, adv); fPos = new SkPoint[len]; SkScalar x = 0; for (size_t i = 0; i < len; ++i) { @@ -83,11 +89,7 @@ public: } } - virtual ~TextBench() { - delete[] fPos; - } -protected: virtual const char* onGetName() { fName.printf("text_%g", SkScalarToFloat(fPaint.getTextSize())); if (fDoPos) { @@ -100,7 +102,7 @@ protected: fName.append("_BK"); } - if (fDoColorEmoji && fColorEmojiTypeface) { + if (fDoColorEmoji) { fName.append("_ColorEmoji"); } diff --git a/bench/TextBlobBench.cpp b/bench/TextBlobBench.cpp index 1f4b2b7120..ae71a1e41a 100644 --- a/bench/TextBlobBench.cpp +++ b/bench/TextBlobBench.cpp @@ -25,7 +25,12 @@ class TextBlobBench : public Benchmark { public: TextBlobBench() - : fTypeface(sk_tool_utils::create_portable_typeface("Times", SkTypeface::kNormal)) { + : fTypeface(NULL) { + } + +protected: + void onPreDraw() override { + fTypeface.reset(sk_tool_utils::create_portable_typeface("Times", SkTypeface::kNormal)); // make textblob SkPaint paint; paint.setTypeface(fTypeface); @@ -45,7 +50,6 @@ public: fBlob.reset(builder.build()); } -protected: const char* onGetName() { return "TextBlobBench"; } diff --git a/gm/colortype.cpp b/gm/colortype.cpp index 48e39d086e..e49f9ecb44 100644 --- a/gm/colortype.cpp +++ b/gm/colortype.cpp @@ -12,7 +12,16 @@ class ColorTypeGM : public skiagm::GM { public: - ColorTypeGM() { + ColorTypeGM() + : fColorType(NULL) { + } + + virtual ~ColorTypeGM() { + SkSafeUnref(fColorType); + } + +protected: + void onOnceBeforeDraw() override { const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW @@ -35,11 +44,6 @@ public: orig->unref(); } - virtual ~ColorTypeGM() { - fColorType->unref(); - } - -protected: SkString onShortName() override { return SkString("colortype"); } diff --git a/gm/colortypexfermode.cpp b/gm/colortypexfermode.cpp index bf86565648..855d11a1a4 100644 --- a/gm/colortypexfermode.cpp +++ b/gm/colortypexfermode.cpp @@ -16,17 +16,19 @@ namespace skiagm { static uint16_t gData[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; class ColorTypeXfermodeGM : public GM { - SkBitmap fBG; - - void onOnceBeforeDraw() override { - fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, - kOpaque_SkAlphaType), gData, 4); - } - public: const static int W = 64; const static int H = 64; - ColorTypeXfermodeGM() { + ColorTypeXfermodeGM() + : fColorType(NULL) { + } + + virtual ~ColorTypeXfermodeGM() { + SkSafeUnref(fColorType); + } + +protected: + void onOnceBeforeDraw() override { const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorYELLOW @@ -47,13 +49,11 @@ public: } fColorType = SkNEW_ARGS(SkGTypeface, (orig, paint)); orig->unref(); - } - virtual ~ColorTypeXfermodeGM() { - fColorType->unref(); + fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, + kOpaque_SkAlphaType), gData, 4); } -protected: virtual SkString onShortName() override { return SkString("colortype_xfermodes"); } @@ -157,6 +157,7 @@ protected: } private: + SkBitmap fBG; SkTypeface* fColorType; typedef GM INHERITED; diff --git a/gm/textblob.cpp b/gm/textblob.cpp index 7c0fd87546..e85571f898 100644 --- a/gm/textblob.cpp +++ b/gm/textblob.cpp @@ -67,17 +67,21 @@ const SkScalar kFontSize = 16; class TextBlobGM : public skiagm::GM { public: TextBlobGM(const char* txt) - : fTypeface(sk_tool_utils::create_portable_typeface("Times", SkTypeface::kNormal)) { + : fText(txt) { + } + +protected: + void onOnceBeforeDraw() override { + fTypeface.reset(sk_tool_utils::create_portable_typeface("Times", SkTypeface::kNormal)); SkPaint p; p.setTypeface(fTypeface); - size_t txtLen = strlen(txt); - int glyphCount = p.textToGlyphs(txt, txtLen, NULL); + size_t txtLen = strlen(fText); + int glyphCount = p.textToGlyphs(fText, txtLen, NULL); fGlyphs.append(glyphCount); - p.textToGlyphs(txt, txtLen, fGlyphs.begin()); + p.textToGlyphs(fText, txtLen, fGlyphs.begin()); } -protected: SkString onShortName() override { return SkString("textblob"); } @@ -178,7 +182,7 @@ private: SkTDArray<uint16_t> fGlyphs; SkAutoTUnref<SkTypeface> fTypeface; - + const char* fText; typedef skiagm::GM INHERITED; }; diff --git a/gm/typeface.cpp b/gm/typeface.cpp index 4114d2cc33..5ddc338449 100644 --- a/gm/typeface.cpp +++ b/gm/typeface.cpp @@ -21,21 +21,27 @@ static const char* gFaces[] = { class TypefaceGM : public skiagm::GM { public: - TypefaceGM() { - fFaces = new SkTypeface*[SK_ARRAY_COUNT(gFaces)]; - for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) { - fFaces[i] = sk_tool_utils::create_portable_typeface(gFaces[i], SkTypeface::kNormal); - } + TypefaceGM() + : fFaces(NULL) { } virtual ~TypefaceGM() { - for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) { - SkSafeUnref(fFaces[i]); + if (fFaces) { + for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) { + SkSafeUnref(fFaces[i]); + } + delete [] fFaces; } - delete [] fFaces; } protected: + void onOnceBeforeDraw() override { + fFaces = new SkTypeface*[SK_ARRAY_COUNT(gFaces)]; + for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) { + fFaces[i] = sk_tool_utils::create_portable_typeface(gFaces[i], SkTypeface::kNormal); + } + } + SkString onShortName() override { return SkString("typeface"); } @@ -157,11 +163,9 @@ class TypefaceStylesGM : public skiagm::GM { bool fApplyKerning; public: - TypefaceStylesGM(bool applyKerning) : fApplyKerning(applyKerning) { - for (int i = 0; i < gFaceStylesCount; i++) { - fFaces[i] = sk_tool_utils::create_portable_typeface(gFaceStyles[i].fName, - gFaceStyles[i].fStyle); - } + TypefaceStylesGM(bool applyKerning) + : fApplyKerning(applyKerning) { + memset(fFaces, 0, sizeof(fFaces)); } virtual ~TypefaceStylesGM() { @@ -171,6 +175,13 @@ public: } protected: + void onOnceBeforeDraw() override { + for (int i = 0; i < gFaceStylesCount; i++) { + fFaces[i] = sk_tool_utils::create_portable_typeface(gFaceStyles[i].fName, + gFaceStyles[i].fStyle); + } + } + SkString onShortName() override { SkString name("typefacestyles"); if (fApplyKerning) { diff --git a/gm/verttext2.cpp b/gm/verttext2.cpp index 77bdc92dd1..9918049f10 100644 --- a/gm/verttext2.cpp +++ b/gm/verttext2.cpp @@ -18,11 +18,9 @@ namespace skiagm { class VertText2GM : public GM { public: - VertText2GM() { - const int pointSize = 24; - textHeight = SkIntToScalar(pointSize); - fProp = sk_tool_utils::create_portable_typeface("Helvetica", SkTypeface::kNormal); - fMono = sk_tool_utils::create_portable_typeface("Courier New", SkTypeface::kNormal); + VertText2GM() + : fProp(NULL) + , fMono(NULL) { } virtual ~VertText2GM() { @@ -31,7 +29,12 @@ public: } protected: - + void onOnceBeforeDraw() override { + const int pointSize = 24; + textHeight = SkIntToScalar(pointSize); + fProp = sk_tool_utils::create_portable_typeface("Helvetica", SkTypeface::kNormal); + fMono = sk_tool_utils::create_portable_typeface("Courier New", SkTypeface::kNormal); + } SkString onShortName() override { return SkString("verttext2"); |