• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 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 nanobench_DEFINED
9 #define nanobench_DEFINED
10 
11 #include "Benchmark.h"
12 #include "SkImageInfo.h"
13 #include "SkSurface.h"
14 #include "SkTypes.h"
15 
16 #if SK_SUPPORT_GPU
17 #include "GrContextFactory.h"
18 #endif
19 
20 class ResultsWriter;
21 class SkBitmap;
22 class SkCanvas;
23 
24 struct Config {
25     const char* name;
26     Benchmark::Backend backend;
27     SkColorType color;
28     SkAlphaType alpha;
29     int samples;
30 #if SK_SUPPORT_GPU
31     GrContextFactory::GLContextType ctxType;
32     bool useDFText;
33 #else
34     int bogusInt;
35     bool bogusBool;
36 #endif
37 };
38 
39 struct Target {
TargetTarget40     explicit Target(const Config& c) : config(c) { }
~TargetTarget41     virtual ~Target() { }
42 
43     const Config config;
44     SkAutoTDelete<SkSurface> surface;
45 
46     /** Called once per target, immediately before any timing or drawing. */
setupTarget47     virtual void setup() { }
48 
49     /** Called *after* the clock timer is started, before the benchmark
50         is drawn. Most back ends just return the canvas passed in,
51         but some may replace it. */
beginTimingTarget52     virtual SkCanvas* beginTiming(SkCanvas* canvas) { return canvas; }
53 
54     /** Called *after* a benchmark is drawn, but before the clock timer
55         is stopped.  */
endTimingTarget56     virtual void endTiming() { }
57 
58     /** Called between benchmarks (or between calibration and measured
59         runs) to make sure all pending work in drivers / threads is
60         complete. */
fenceTarget61     virtual void fence() { }
62 
63     /** CPU-like targets can just be timed, but GPU-like
64         targets need to pay attention to frame boundaries
65         or other similar details. */
needsFrameTimingTarget66     virtual bool needsFrameTiming() const { return false; }
67 
68     /** Called once per target, during program initialization.
69         Returns false if initialization fails. */
70     virtual bool init(SkImageInfo info, Benchmark* bench);
71 
72     /** Stores any pixels drawn to the screen in the bitmap.
73         Returns false on error. */
74     virtual bool capturePixels(SkBitmap* bmp);
75 
76     /** Writes any config-specific data to the log. */
fillOptionsTarget77     virtual void fillOptions(ResultsWriter*) { }
78 
getCanvasTarget79     SkCanvas* getCanvas() const {
80         if (!surface.get()) {
81             return NULL;
82         }
83         return surface->getCanvas();
84     }
85 };
86 
87 #endif  // nanobench_DEFINED
88