2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef nanobench_DEFINED
9 #define nanobench_DEFINED
11 #include "bench/Benchmark.h"
12 #include "include/core/SkImageInfo.h"
13 #include "include/core/SkSurface.h"
14 #include "include/core/SkTypes.h"
15 #include "tools/gpu/GrContextFactory.h"
16 #include "tools/graphite/ContextFactory.h"
20 class NanoJSONResultsWriter;
24 Benchmark::Backend backend;
27 sk_sp<SkColorSpace> colorSpace;
29 sk_gpu_test::GrContextFactory::ContextType ctxType;
30 sk_gpu_test::GrContextFactory::ContextOverrides ctxOverrides;
31 skiatest::graphite::ContextFactory::ContextType graphiteCtxType;
32 uint32_t surfaceFlags;
36 explicit Target(const Config& c) : config(c) { }
40 sk_sp<SkSurface> surface;
42 /** Called once per target, immediately before any timing or drawing. */
43 virtual void setup() { }
45 /** Called *after* the clock timer is started, before the benchmark
46 is drawn. Most back ends just return the canvas passed in,
47 but some may replace it. */
48 virtual SkCanvas* beginTiming(SkCanvas* canvas) { return canvas; }
50 /** Called *after* a benchmark is drawn, but before the clock timer
52 virtual void endTiming() { }
54 /** Called between benchmarks (or between calibration and measured
55 runs) to make sure all pending work in drivers / threads is
57 virtual void syncCPU() { }
59 /** CPU-like targets can just be timed, but GPU-like
60 targets need to pay attention to frame boundaries
61 or other similar details. */
62 virtual bool needsFrameTiming(int* frameLag) const { return false; }
64 /** Called once per target, during program initialization.
65 Returns false if initialization fails. */
66 virtual bool init(SkImageInfo info, Benchmark* bench);
68 /** Stores any pixels drawn to the screen in the bitmap.
69 Returns false on error. */
70 virtual bool capturePixels(SkBitmap* bmp);
72 /** Writes gathered stats using SkDebugf. */
73 virtual void dumpStats() {}
75 SkCanvas* getCanvas() const {
79 return surface->getCanvas();
83 #endif // nanobench_DEFINED