skia2/bench/FontScalerBench.cpp
commit-bot@chromium.org 261d0153e2 Clean up global gSkSuppressFontCachePurgeSpew.
No one is using it except to flick it to true to shut up the spew,
but the spew is already guarded by #ifdef SPEW_PURGE_STATUS.  Let's
leave it to SPEW_PURGE_STATUS.

Noticed this specificially when TSAN complained about FontScalerBench
modifying it in a thread-unsafe way.

BUG=skia:1792
R=reed@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/264333008

git-svn-id: http://skia.googlecode.com/svn/trunk@14697 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-05-12 15:48:38 +00:00

53 lines
1.5 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBenchmark.h"
#include "SkCanvas.h"
#include "SkGraphics.h"
#include "SkPaint.h"
#include "SkRandom.h"
#include "SkString.h"
class FontScalerBench : public SkBenchmark {
SkString fName;
SkString fText;
bool fDoLCD;
public:
FontScalerBench(bool doLCD) {
fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa");
fText.set("abcdefghijklmnopqrstuvwxyz01234567890");
fDoLCD = doLCD;
}
protected:
virtual const char* onGetName() { return fName.c_str(); }
virtual void onDraw(const int loops, SkCanvas* canvas) {
SkPaint paint;
this->setupPaint(&paint);
paint.setLCDRenderText(fDoLCD);
for (int i = 0; i < loops; i++) {
// this is critical - we want to time the creation process, so we
// explicitly flush our cache before each run
SkGraphics::PurgeFontCache();
for (int ps = 9; ps <= 24; ps += 2) {
paint.setTextSize(SkIntToScalar(ps));
canvas->drawText(fText.c_str(), fText.size(),
0, SkIntToScalar(20), paint);
}
}
}
private:
typedef SkBenchmark INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (false)); )
DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (true)); )