aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar kkinnunen <kkinnunen@nvidia.com>2015-05-21 06:15:28 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-05-21 06:15:28 -0700
commitb4a797f3aa8c10387f01cf51a65dd1a8aa5eec9d (patch)
tree988c6fac18d299111d00a4404666899011745db0
parent070e01056acdd9980619e71e2da390efb94e912e (diff)
Move font loading in gm tests and benches out of constructors
Constructing the gm tests and benches causes many calls to font loads. This is visible as profiling samples in fontconfig and freetype on Linux for all profiling runs of nanobench. This complicates analysis of test-cases that are suspected of being slow due to font-related issues. Move the font loading to GM::onOnceBeforeDraw and Benchmark::onPreDraw. This way the code is not executed if the testcase does not match the nanobench --match filter. This way the samples in font-related code are more easy to identify as legitimate occurances caused by the testcase. This should not cause differences in timings, because: * Benchmark::preDraw / onPreDraw is defined to be run outside the timer * GM::runAsBench is not enabled for any of the modified testcases. Also nanobench untimed warmup round should run the onOnceBeforeDraw. (and there are other GM::runAsBench gms already doing loading in onOnceBeforeDraw). Changes the behavior: In TextBench: Before, the test would report two different gms with the same name if the color emoji font was not loaded successfully. After, the test always reports all tests as individual names. Generally: The errors from loading fonts now print inbetween each testcase, as opposed to printing during construction phase. Sample output: ( 143/145 MB 1872) 14.7ms 8888 gm quadclosepathResource /fonts/Funkster.ttf not a valid font. ( 160/160 MB 1831) 575µs 8888 gm surfacenewResource /fonts/Funkster.ttf not a valid font. ( 163/165 MB 1816) 12.5ms 8888 gm linepathResource /fonts/Funkster.ttf not a valid font. ( 263/411 MB 1493) 118ms 8888 gm typefacestyles_kerningResource /fonts/Funkster.ttf not a valid font. ( 374/411 MB 1231) 7.16ms 565 gm getpostextpathResource /fonts/Funkster.ttf not a valid font. ( 323/411 MB 1179) 4.92ms 565 gm stringartResource /fonts/Funkster.ttf not a valid font. ( 347/493 MB 917) 191ms 565 gm patch_gridResource /fonts/Funkster.ttf not a valid font. ( 375/493 MB 857) 23.9ms gpu gm clipdrawdrawCannot render path (0) ( 393/493 MB 706) 2.91ms unit test ParsePath------ png error IEND: CRC error ( 394/493 MB 584) 166ms gpu gm hairmodesResource /fonts/Funkster.ttf not a valid font. Resource /fonts/Funkster.ttf not a valid font. Resource /fonts/Funkster.ttf not a valid font. ... Review URL: https://codereview.chromium.org/1144023002
-rw-r--r--bench/TextBench.cpp34
-rw-r--r--bench/TextBlobBench.cpp8
-rw-r--r--gm/colortype.cpp16
-rw-r--r--gm/colortypexfermode.cpp25
-rw-r--r--gm/textblob.cpp16
-rw-r--r--gm/typeface.cpp37
-rw-r--r--gm/verttext2.cpp15
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");