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
This commit is contained in:
kkinnunen 2015-05-21 06:15:28 -07:00 committed by Commit bot
parent 070e01056a
commit b4a797f3aa
7 changed files with 95 additions and 66 deletions

View File

@ -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");
}

View File

@ -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";
}

View File

@ -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");
}

View File

@ -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();
fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType,
kOpaque_SkAlphaType), gData, 4);
}
virtual ~ColorTypeXfermodeGM() {
fColorType->unref();
}
protected:
virtual SkString onShortName() override {
return SkString("colortype_xfermodes");
}
@ -157,6 +157,7 @@ protected:
}
private:
SkBitmap fBG;
SkTypeface* fColorType;
typedef GM INHERITED;

View File

@ -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)) {
SkPaint p;
p.setTypeface(fTypeface);
size_t txtLen = strlen(txt);
int glyphCount = p.textToGlyphs(txt, txtLen, NULL);
fGlyphs.append(glyphCount);
p.textToGlyphs(txt, txtLen, fGlyphs.begin());
: 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(fText);
int glyphCount = p.textToGlyphs(fText, txtLen, NULL);
fGlyphs.append(glyphCount);
p.textToGlyphs(fText, txtLen, fGlyphs.begin());
}
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;
};

View File

@ -21,21 +21,27 @@ static const char* gFaces[] = {
class TypefaceGM : public skiagm::GM {
public:
TypefaceGM() {
TypefaceGM()
: fFaces(NULL) {
}
virtual ~TypefaceGM() {
if (fFaces) {
for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) {
SkSafeUnref(fFaces[i]);
}
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);
}
}
virtual ~TypefaceGM() {
for (size_t i = 0; i < SK_ARRAY_COUNT(gFaces); i++) {
SkSafeUnref(fFaces[i]);
}
delete [] fFaces;
}
protected:
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) {

View File

@ -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");