| 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 { | 
 | 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 { | 
 | 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 | 
| tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 50 |         is drawn. Most back ends just return the canvas passed in, | 
 | 51 |         but some may replace it. */ | 
| tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 52 |     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. */ | 
| cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 66 |     virtual bool needsFrameTiming(int* frameLag) const { return false; } | 
| tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 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. */ | 
 | 77 |     virtual void fillOptions(ResultsWriter*) { } | 
| tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 78 |  | 
 | 79 |     SkCanvas* getCanvas() const { | 
 | 80 |         if (!surface.get()) { | 
 | 81 |             return NULL; | 
 | 82 |         } | 
 | 83 |         return surface->getCanvas(); | 
 | 84 |     } | 
| tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 85 | }; | 
 | 86 |  | 
 | 87 | #endif  // nanobench_DEFINED |