Home | History | Annotate | Download | only in tools
      1 /*
      2  * Copyright 2012 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 #ifndef PictureBenchmark_DEFINED
      9 #define PictureBenchmark_DEFINED
     10 
     11 #include "SkTypes.h"
     12 #include "PictureRenderer.h"
     13 
     14 class BenchTimer;
     15 class SkBenchLogger;
     16 class SkPicture;
     17 class SkString;
     18 
     19 namespace sk_tools {
     20 
     21 class PictureBenchmark {
     22 public:
     23     PictureBenchmark();
     24 
     25     ~PictureBenchmark();
     26 
     27     /**
     28      * Draw the provided SkPicture fRepeats times while collecting timing data, and log the output
     29      * via fLogger.
     30      */
     31     void run(SkPicture* pict);
     32 
     33     void setRepeats(int repeats) {
     34         fRepeats = repeats;
     35     }
     36 
     37     /**
     38      * If true, tells run to log separate timing data for each individual tile. Each tile will be
     39      * drawn fRepeats times. Requires the PictureRenderer set by setRenderer to be a
     40      * TiledPictureRenderer.
     41      */
     42     void setTimeIndividualTiles(bool indiv) { fTimeIndividualTiles = true; }
     43 
     44     bool timeIndividualTiles() { return fTimeIndividualTiles; }
     45 
     46     PictureRenderer* setRenderer(PictureRenderer*);
     47 
     48     void setDeviceType(PictureRenderer::SkDeviceTypes deviceType) {
     49         if (fRenderer != NULL) {
     50             fRenderer->setDeviceType(deviceType);
     51         }
     52     }
     53 
     54     void setLogPerIter(bool log) { fLogPerIter = log; }
     55 
     56     void setPrintMin(bool min) { fPrintMin = min; }
     57 
     58     void setTimersToShow(bool wall, bool truncatedWall, bool cpu, bool truncatedCpu, bool gpu) {
     59         fShowWallTime = wall;
     60         fShowTruncatedWallTime = truncatedWall;
     61         fShowCpuTime = cpu;
     62         fShowTruncatedCpuTime = truncatedCpu;
     63         fShowGpuTime = gpu;
     64     }
     65 
     66     void setLogger(SkBenchLogger* logger) { fLogger = logger; }
     67 
     68 private:
     69     int              fRepeats;
     70     SkBenchLogger*   fLogger;
     71     PictureRenderer* fRenderer;
     72     bool             fLogPerIter;
     73     bool             fPrintMin;
     74     bool             fShowWallTime;
     75     bool             fShowTruncatedWallTime;
     76     bool             fShowCpuTime;
     77     bool             fShowTruncatedCpuTime;
     78     bool             fShowGpuTime;
     79     bool             fTimeIndividualTiles;
     80 
     81     void logProgress(const char msg[]);
     82 
     83     BenchTimer* setupTimer();
     84 };
     85 
     86 }
     87 
     88 #endif  // PictureBenchmark_DEFINED
     89