blob: f556f7dc14ce460622de4da4e4151b5655aebe8a [file] [log] [blame]
tomhudsond968a6f2015-03-26 11:28:06 -07001/*
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
20class ResultsWriter;
21class SkBitmap;
22class SkCanvas;
23
24struct 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
39struct Target {
40 explicit Target(const Config& c) : config(c) { }
41 virtual ~Target() { }
42
43 const Config config;
44 SkAutoTDelete<SkSurface> surface;
45
46 /** Called once per target, immediately before any timing or drawing. */
47 virtual void setup() { }
48
49 /** Called *after* the clock timer is started, before the benchmark
tomhudson75a0ebb2015-03-27 12:11:44 -070050 is drawn. Most back ends just return the canvas passed in,
51 but some may replace it. */
tomhudsond968a6f2015-03-26 11:28:06 -070052 virtual SkCanvas* beginTiming(SkCanvas* canvas) { return canvas; }
53
54 /** Called *after* a benchmark is drawn, but before the clock timer
55 is stopped. */
56 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. */
61 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. */
cdaltond416a5b2015-06-23 13:23:44 -070066 virtual bool needsFrameTiming(int* frameLag) const { return false; }
tomhudsond968a6f2015-03-26 11:28:06 -070067
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. */
77 virtual void fillOptions(ResultsWriter*) { }
tomhudson75a0ebb2015-03-27 12:11:44 -070078
79 SkCanvas* getCanvas() const {
80 if (!surface.get()) {
81 return NULL;
82 }
83 return surface->getCanvas();
84 }
tomhudsond968a6f2015-03-26 11:28:06 -070085};
86
87#endif // nanobench_DEFINED