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 #ifndef SkBenchmark_DEFINED
      9 #define SkBenchmark_DEFINED
     10 
     11 #include "SkRefCnt.h"
     12 #include "SkPoint.h"
     13 #include "SkTDict.h"
     14 #include "SkTRegistry.h"
     15 
     16 #ifdef SK_DEBUG
     17     #define SkBENCHLOOP(n) 1
     18 #else
     19     #define SkBENCHLOOP(n) n
     20 #endif
     21 
     22 class SkCanvas;
     23 class SkPaint;
     24 
     25 class SkTriState {
     26 public:
     27     enum State {
     28         kDefault,
     29         kTrue,
     30         kFalse
     31     };
     32 };
     33 
     34 class SkBenchmark : public SkRefCnt {
     35 public:
     36     SkBenchmark(void* defineDict);
     37 
     38     const char* getName();
     39     SkIPoint getSize();
     40     void draw(SkCanvas*);
     41 
     42     void setForceAlpha(int alpha) {
     43         fForceAlpha = alpha;
     44     }
     45 
     46     void setForceAA(bool aa) {
     47         fForceAA = aa;
     48     }
     49 
     50     void setForceFilter(bool filter) {
     51         fForceFilter = filter;
     52     }
     53 
     54     void setDither(SkTriState::State state) {
     55         fDither = state;
     56     }
     57 
     58     void setStrokeWidth(SkScalar width) {
     59       strokeWidth = width;
     60       fHasStrokeWidth = true;
     61     }
     62 
     63     SkScalar getStrokeWidth() {
     64       return strokeWidth;
     65     }
     66 
     67     bool hasStrokeWidth() {
     68       return fHasStrokeWidth;
     69     }
     70 
     71     const char* findDefine(const char* key) const;
     72     bool findDefine32(const char* key, int32_t* value) const;
     73     bool findDefineScalar(const char* key, SkScalar* value) const;
     74 
     75 protected:
     76     void setupPaint(SkPaint* paint);
     77 
     78     virtual const char* onGetName() = 0;
     79     virtual void onDraw(SkCanvas*) = 0;
     80 
     81     virtual SkIPoint onGetSize();
     82 
     83 private:
     84     const SkTDict<const char*>* fDict;
     85     int     fForceAlpha;
     86     bool    fForceAA;
     87     bool    fForceFilter;
     88     SkTriState::State  fDither;
     89     bool    fHasStrokeWidth;
     90     SkScalar strokeWidth;
     91 };
     92 
     93 typedef SkTRegistry<SkBenchmark*, void*> BenchRegistry;
     94 
     95 #endif
     96