tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 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 { |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 25 | SkString name; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 26 | Benchmark::Backend backend; |
| 27 | SkColorType color; |
| 28 | SkAlphaType alpha; |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 29 | sk_sp<SkColorSpace> colorSpace; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 30 | int samples; |
| 31 | #if SK_SUPPORT_GPU |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 32 | sk_gpu_test::GrContextFactory::ContextType ctxType; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 33 | sk_gpu_test::GrContextFactory::ContextOverrides ctxOverrides; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 34 | bool useDFText; |
| 35 | #else |
| 36 | int bogusInt; |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 37 | int bogusIntOption; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 38 | bool bogusBool; |
| 39 | #endif |
| 40 | }; |
| 41 | |
| 42 | struct Target { |
| 43 | explicit Target(const Config& c) : config(c) { } |
| 44 | virtual ~Target() { } |
| 45 | |
| 46 | const Config config; |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 47 | sk_sp<SkSurface> surface; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 48 | |
| 49 | /** Called once per target, immediately before any timing or drawing. */ |
| 50 | virtual void setup() { } |
| 51 | |
| 52 | /** Called *after* the clock timer is started, before the benchmark |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 53 | is drawn. Most back ends just return the canvas passed in, |
| 54 | but some may replace it. */ |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 55 | virtual SkCanvas* beginTiming(SkCanvas* canvas) { return canvas; } |
| 56 | |
| 57 | /** Called *after* a benchmark is drawn, but before the clock timer |
| 58 | is stopped. */ |
| 59 | virtual void endTiming() { } |
| 60 | |
| 61 | /** Called between benchmarks (or between calibration and measured |
| 62 | runs) to make sure all pending work in drivers / threads is |
| 63 | complete. */ |
| 64 | virtual void fence() { } |
| 65 | |
| 66 | /** CPU-like targets can just be timed, but GPU-like |
| 67 | targets need to pay attention to frame boundaries |
| 68 | or other similar details. */ |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 69 | virtual bool needsFrameTiming(int* frameLag) const { return false; } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 70 | |
| 71 | /** Called once per target, during program initialization. |
| 72 | Returns false if initialization fails. */ |
| 73 | virtual bool init(SkImageInfo info, Benchmark* bench); |
| 74 | |
| 75 | /** Stores any pixels drawn to the screen in the bitmap. |
| 76 | Returns false on error. */ |
| 77 | virtual bool capturePixels(SkBitmap* bmp); |
| 78 | |
| 79 | /** Writes any config-specific data to the log. */ |
| 80 | virtual void fillOptions(ResultsWriter*) { } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 81 | |
| 82 | SkCanvas* getCanvas() const { |
| 83 | if (!surface.get()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 84 | return nullptr; |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 85 | } |
| 86 | return surface->getCanvas(); |
| 87 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | #endif // nanobench_DEFINED |