Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: gm/variedtext.cpp

Issue 1974783002: Revert of Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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];
« no previous file with comments | « gm/typeface.cpp ('k') | gm/verttext2.cpp » ('j') | src/ports/SkFontMgr_android.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698