Home | History | Annotate | Download | only in bench
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 #include "SkBenchmark.h"
      9 #include "SkPaint.h"
     10 #include "SkParse.h"
     11 
     12 SK_DEFINE_INST_COUNT(SkBenchmark)
     13 
     14 template BenchRegistry* BenchRegistry::gHead;
     15 
     16 SkBenchmark::SkBenchmark(void* defineDict) {
     17     fDict = reinterpret_cast<const SkTDict<const char*>*>(defineDict);
     18     fForceAlpha = 0xFF;
     19     fForceAA = true;
     20     fDither = SkTriState::kDefault;
     21     fHasStrokeWidth = false;
     22     fIsRendering = true;
     23 }
     24 
     25 const char* SkBenchmark::getName() {
     26     return this->onGetName();
     27 }
     28 
     29 SkIPoint SkBenchmark::getSize() {
     30     return this->onGetSize();
     31 }
     32 
     33 void SkBenchmark::preDraw() {
     34     this->onPreDraw();
     35 }
     36 
     37 void SkBenchmark::draw(SkCanvas* canvas) {
     38     this->onDraw(canvas);
     39 }
     40 
     41 void SkBenchmark::postDraw() {
     42     this->onPostDraw();
     43 }
     44 
     45 void SkBenchmark::setupPaint(SkPaint* paint) {
     46     paint->setAlpha(fForceAlpha);
     47     paint->setAntiAlias(fForceAA);
     48     paint->setFilterBitmap(fForceFilter);
     49 
     50     if (SkTriState::kDefault != fDither) {
     51         paint->setDither(SkTriState::kTrue == fDither);
     52     }
     53 }
     54 
     55 const char* SkBenchmark::findDefine(const char* key) const {
     56     if (fDict) {
     57         const char* value;
     58         if (fDict->find(key, &value)) {
     59             return value;
     60         }
     61     }
     62     return NULL;
     63 }
     64 
     65 bool SkBenchmark::findDefine32(const char* key, int32_t* value) const {
     66     const char* valueStr = this->findDefine(key);
     67     if (valueStr) {
     68         SkParse::FindS32(valueStr, value);
     69         return true;
     70     }
     71     return false;
     72 }
     73 
     74 bool SkBenchmark::findDefineScalar(const char* key, SkScalar* value) const {
     75     const char* valueStr = this->findDefine(key);
     76     if (valueStr) {
     77         SkParse::FindScalar(valueStr, value);
     78         return true;
     79     }
     80     return false;
     81 }
     82 
     83 ///////////////////////////////////////////////////////////////////////////////
     84 
     85 SkIPoint SkBenchmark::onGetSize() {
     86     return SkIPoint::Make(640, 480);
     87 }
     88