Index: gm/variedtext.cpp |
diff --git a/gm/variedtext.cpp b/gm/variedtext.cpp |
index e295cbc99802a2e2d793c1eb1efa0f925fc1e5bb..83fe7201fd57148409515186e7f354f499ec1177 100644 |
--- a/gm/variedtext.cpp |
+++ b/gm/variedtext.cpp |
@@ -21,6 +21,13 @@ |
VariedTextGM(bool effectiveClip, bool lcd) |
: fEffectiveClip(effectiveClip) |
, fLCD(lcd) { |
+ memset(fTypefacesToUnref, 0, sizeof(fTypefacesToUnref)); |
+ } |
+ |
+ ~VariedTextGM() { |
+ for (size_t i = 0; i < SK_ARRAY_COUNT(fTypefacesToUnref); ++i) { |
+ SkSafeUnref(fTypefacesToUnref[i]); |
+ } |
} |
protected: |
@@ -51,11 +58,11 @@ |
SkScalar w = SkIntToScalar(size.fWidth); |
SkScalar h = SkIntToScalar(size.fHeight); |
- static_assert(4 == SK_ARRAY_COUNT(fTypefaces), "typeface_cnt"); |
- fTypefaces[0] = sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kNormal); |
- fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kBold); |
- fTypefaces[2] = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal); |
- fTypefaces[3] = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold); |
+ static_assert(4 == SK_ARRAY_COUNT(fTypefacesToUnref), "typeface_cnt"); |
+ fTypefacesToUnref[0] = sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kNormal); |
+ fTypefacesToUnref[1] = sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kBold); |
+ fTypefacesToUnref[2] = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal); |
+ fTypefacesToUnref[3] = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold); |
SkRandom random; |
for (int i = 0; i < kCnt; ++i) { |
@@ -75,11 +82,12 @@ |
fPtSizes[i] = random.nextRangeScalar(kMinPtSize, kMaxPtSize); |
- fTypefaceIndices[i] = random.nextULessThan(SK_ARRAY_COUNT(fTypefaces)); |
+ fTypefaces[i] = fTypefacesToUnref[ |
+ random.nextULessThan(SK_ARRAY_COUNT(fTypefacesToUnref))]; |
SkRect r; |
fPaint.setColor(fColors[i]); |
- fPaint.setTypeface(fTypefaces[fTypefaceIndices[i]]); |
+ fPaint.setTypeface(fTypefaces[i]); |
fPaint.setTextSize(fPtSizes[i]); |
fPaint.measureText(fStrings[i].c_str(), fStrings[i].size(), &r); |
@@ -108,7 +116,7 @@ |
for (int i = 0; i < kCnt; ++i) { |
fPaint.setColor(fColors[i]); |
fPaint.setTextSize(fPtSizes[i]); |
- fPaint.setTypeface(fTypefaces[fTypefaceIndices[i]]); |
+ fPaint.setTypeface(fTypefaces[i]); |
canvas->save(); |
canvas->clipRect(fClipRects[i]); |
@@ -138,14 +146,14 @@ |
bool fEffectiveClip; |
bool fLCD; |
- sk_sp<SkTypeface> fTypefaces[4]; |
+ SkTypeface* fTypefacesToUnref[4]; |
SkPaint fPaint; |
// precomputed for each text draw |
SkString fStrings[kCnt]; |
SkColor fColors[kCnt]; |
SkScalar fPtSizes[kCnt]; |
- int fTypefaceIndices[kCnt]; |
+ SkTypeface* fTypefaces[kCnt]; |
SkPoint fPositions[kCnt]; |
SkRect fClipRects[kCnt]; |