Home | History | Annotate | Download | only in bench
      1 /*
      2  * Copyright 2011 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include "SkBenchmark.h"
      9 #include "SkCanvas.h"
     10 #include "SkGraphics.h"
     11 #include "SkPaint.h"
     12 #include "SkRandom.h"
     13 #include "SkString.h"
     14 
     15 extern bool gSkSuppressFontCachePurgeSpew;
     16 
     17 class FontScalerBench : public SkBenchmark {
     18     SkString fName;
     19     SkString fText;
     20     bool     fDoLCD;
     21 public:
     22     FontScalerBench(void* param, bool doLCD) : INHERITED(param) {
     23         fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa");
     24         fText.set("abcdefghijklmnopqrstuvwxyz01234567890");
     25         fDoLCD = doLCD;
     26     }
     27 
     28 protected:
     29     virtual const char* onGetName() { return fName.c_str(); }
     30     virtual void onDraw(SkCanvas* canvas) {
     31         SkPaint paint;
     32         this->setupPaint(&paint);
     33         paint.setLCDRenderText(fDoLCD);
     34 
     35         bool prev = gSkSuppressFontCachePurgeSpew;
     36         gSkSuppressFontCachePurgeSpew = true;
     37 
     38         // this is critical - we want to time the creation process, so we
     39         // explicitly flush our cache before each run
     40         SkGraphics::PurgeFontCache();
     41 
     42         for (int ps = 9; ps <= 24; ps += 2) {
     43             paint.setTextSize(SkIntToScalar(ps));
     44             canvas->drawText(fText.c_str(), fText.size(),
     45                              0, SkIntToScalar(20), paint);
     46         }
     47 
     48         gSkSuppressFontCachePurgeSpew = prev;
     49     }
     50 private:
     51     typedef SkBenchmark INHERITED;
     52 };
     53 
     54 ///////////////////////////////////////////////////////////////////////////////
     55 
     56 static SkBenchmark* Fact0(void* p) { return SkNEW_ARGS(FontScalerBench, (p, false)); }
     57 static SkBenchmark* Fact1(void* p) { return SkNEW_ARGS(FontScalerBench, (p, true)); }
     58 
     59 static BenchRegistry gReg0(Fact0);
     60 static BenchRegistry gReg1(Fact1);
     61