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

Unified Diff: gm/variedtext.cpp

Issue 1933393002: Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Restore deleted Android code. 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
« no previous file with comments | « gm/typeface.cpp ('k') | gm/verttext2.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/variedtext.cpp
diff --git a/gm/variedtext.cpp b/gm/variedtext.cpp
index 83fe7201fd57148409515186e7f354f499ec1177..e295cbc99802a2e2d793c1eb1efa0f925fc1e5bb 100644
--- a/gm/variedtext.cpp
+++ b/gm/variedtext.cpp
@@ -21,13 +21,6 @@ public:
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:
@@ -58,11 +51,11 @@ protected:
SkScalar w = SkIntToScalar(size.fWidth);
SkScalar h = SkIntToScalar(size.fHeight);
- 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);
+ 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);
SkRandom random;
for (int i = 0; i < kCnt; ++i) {
@@ -82,12 +75,11 @@ protected:
fPtSizes[i] = random.nextRangeScalar(kMinPtSize, kMaxPtSize);
- fTypefaces[i] = fTypefacesToUnref[
- random.nextULessThan(SK_ARRAY_COUNT(fTypefacesToUnref))];
+ fTypefaceIndices[i] = random.nextULessThan(SK_ARRAY_COUNT(fTypefaces));
SkRect r;
fPaint.setColor(fColors[i]);
- fPaint.setTypeface(fTypefaces[i]);
+ fPaint.setTypeface(fTypefaces[fTypefaceIndices[i]]);
fPaint.setTextSize(fPtSizes[i]);
fPaint.measureText(fStrings[i].c_str(), fStrings[i].size(), &r);
@@ -116,7 +108,7 @@ protected:
for (int i = 0; i < kCnt; ++i) {
fPaint.setColor(fColors[i]);
fPaint.setTextSize(fPtSizes[i]);
- fPaint.setTypeface(fTypefaces[i]);
+ fPaint.setTypeface(fTypefaces[fTypefaceIndices[i]]);
canvas->save();
canvas->clipRect(fClipRects[i]);
@@ -146,14 +138,14 @@ private:
bool fEffectiveClip;
bool fLCD;
- SkTypeface* fTypefacesToUnref[4];
+ sk_sp<SkTypeface> fTypefaces[4];
SkPaint fPaint;
// precomputed for each text draw
SkString fStrings[kCnt];
SkColor fColors[kCnt];
SkScalar fPtSizes[kCnt];
- SkTypeface* fTypefaces[kCnt];
+ int fTypefaceIndices[kCnt];
SkPoint fPositions[kCnt];
SkRect fClipRects[kCnt];
« no previous file with comments | « gm/typeface.cpp ('k') | gm/verttext2.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698