Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
nanobench.h
Go to the documentation of this file.
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 "bench/Benchmark.h"
16#if defined(SK_GRAPHITE)
18#endif
19
20class SkBitmap;
21class SkCanvas;
23
35
36struct Target {
37 explicit Target(const Config& c) : config(c) { }
38 virtual ~Target() { }
39
42
43 /** Called once per target, immediately before any timing or drawing. */
44 void setup() {
45 this->onSetup();
46 // Make sure we're done with setup work before we start timing.
48 }
49 virtual void onSetup() { }
50
51 /** Called *after* the clock timer is started, before the benchmark
52 is drawn. Most back ends just return the canvas passed in,
53 but some may replace it. */
54 virtual SkCanvas* beginTiming(SkCanvas* canvas) { return canvas; }
55
56 /** Called *after* a benchmark is drawn, but before the clock timer
57 is stopped. */
58 virtual void endTiming() { }
59
60 /** Called between benchmarks (or between calibration and measured
61 runs) to make sure all pending work in drivers / threads is
62 complete. */
63 virtual void submitWorkAndSyncCPU() { }
64
65 /** CPU-like targets can just be timed, but GPU-like
66 targets need to pay attention to frame boundaries
67 or other similar details. */
68 virtual bool needsFrameTiming(int* frameLag) const { return false; }
69
70 /** Called once per target, during program initialization.
71 Returns false if initialization fails. */
72 virtual bool init(SkImageInfo info, Benchmark* bench);
73
74 /** Stores any pixels drawn to the screen in the bitmap.
75 Returns false on error. */
76 virtual bool capturePixels(SkBitmap* bmp);
77
78 /** Writes gathered stats using SkDebugf. */
79 virtual void dumpStats() {}
80
82 if (!surface) {
83 return nullptr;
84 }
85 return surface->getCanvas();
86 }
87};
88
89#endif // nanobench_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
SkAlphaType
Definition SkAlphaType.h:26
SkColorType
Definition SkColorType.h:19
static void bench(NanoJSONResultsWriter *log, const char *name, int bytes)
SkCanvas * getCanvas()
Definition SkSurface.cpp:82
sk_gpu_test::GrContextFactory::ContextType ctxType
Definition nanobench.h:31
int samples
Definition nanobench.h:30
Benchmark::Backend backend
Definition nanobench.h:26
sk_gpu_test::GrContextFactory::ContextOverrides ctxOverrides
Definition nanobench.h:32
SkString name
Definition nanobench.h:25
sk_sp< SkColorSpace > colorSpace
Definition nanobench.h:29
SkAlphaType alpha
Definition nanobench.h:28
SkColorType color
Definition nanobench.h:27
uint32_t surfaceFlags
Definition nanobench.h:33
virtual void endTiming()
Definition nanobench.h:58
Target(const Config &c)
Definition nanobench.h:37
void setup()
Definition nanobench.h:44
virtual ~Target()
Definition nanobench.h:38
virtual void submitWorkAndSyncCPU()
Definition nanobench.h:63
sk_sp< SkSurface > surface
Definition nanobench.h:41
virtual SkCanvas * beginTiming(SkCanvas *canvas)
Definition nanobench.h:54
virtual bool capturePixels(SkBitmap *bmp)
virtual bool needsFrameTiming(int *frameLag) const
Definition nanobench.h:68
virtual void dumpStats()
Definition nanobench.h:79
virtual bool init(SkImageInfo info, Benchmark *bench)
virtual void onSetup()
Definition nanobench.h:49
const Config config
Definition nanobench.h:40
SkCanvas * getCanvas() const
Definition nanobench.h:81