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 "Benchmark.h"
      9 
     10 #include "SkCanvas.h"
     11 #include "SkPaint.h"
     12 #include "SkParse.h"
     13 
     14 const char* SkTriState::Name[] = { "default", "true", "false" };
     15 
     16 template BenchRegistry* BenchRegistry::gHead;
     17 
     18 Benchmark::Benchmark() {
     19     fForceAlpha = 0xFF;
     20     fDither = SkTriState::kDefault;
     21     fOrMask = fClearMask = 0;
     22 }
     23 
     24 const char* Benchmark::getName() {
     25     return this->onGetName();
     26 }
     27 
     28 const char* Benchmark::getUniqueName() {
     29     return this->onGetUniqueName();
     30 }
     31 
     32 SkIPoint Benchmark::getSize() {
     33     return this->onGetSize();
     34 }
     35 
     36 void Benchmark::delayedSetup() {
     37     this->onDelayedSetup();
     38 }
     39 
     40 void Benchmark::perCanvasPreDraw(SkCanvas* canvas) {
     41     this->onPerCanvasPreDraw(canvas);
     42 }
     43 
     44 void Benchmark::preDraw(SkCanvas* canvas) {
     45     this->onPreDraw(canvas);
     46 }
     47 
     48 void Benchmark::postDraw(SkCanvas* canvas) {
     49     this->onPostDraw(canvas);
     50 }
     51 
     52 void Benchmark::perCanvasPostDraw(SkCanvas* canvas) {
     53     this->onPerCanvasPostDraw(canvas);
     54 }
     55 
     56 void Benchmark::draw(int loops, SkCanvas* canvas) {
     57     SkAutoCanvasRestore ar(canvas, true/*save now*/);
     58     this->onDraw(loops, canvas);
     59 }
     60 
     61 void Benchmark::setupPaint(SkPaint* paint) {
     62     paint->setAlpha(fForceAlpha);
     63     paint->setAntiAlias(true);
     64     paint->setFilterQuality(kNone_SkFilterQuality);
     65 
     66     paint->setFlags((paint->getFlags() & ~fClearMask) | fOrMask);
     67 
     68     if (SkTriState::kDefault != fDither) {
     69         paint->setDither(SkTriState::kTrue == fDither);
     70     }
     71 }
     72 
     73 SkIPoint Benchmark::onGetSize() {
     74     return SkIPoint::Make(640, 480);
     75 }
     76