2015-03-26 18:28:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nanobench_DEFINED
|
|
|
|
#define nanobench_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
2022-03-14 19:18:31 +00:00
|
|
|
#include "tools/graphite/ContextFactory.h"
|
2015-03-26 18:28:06 +00:00
|
|
|
|
|
|
|
class SkBitmap;
|
|
|
|
class SkCanvas;
|
2019-01-28 19:24:29 +00:00
|
|
|
class NanoJSONResultsWriter;
|
2015-03-26 18:28:06 +00:00
|
|
|
|
|
|
|
struct Config {
|
2016-01-28 14:05:43 +00:00
|
|
|
SkString name;
|
2015-03-26 18:28:06 +00:00
|
|
|
Benchmark::Backend backend;
|
|
|
|
SkColorType color;
|
|
|
|
SkAlphaType alpha;
|
2016-06-16 20:03:24 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace;
|
2015-03-26 18:28:06 +00:00
|
|
|
int samples;
|
2016-04-05 18:06:27 +00:00
|
|
|
sk_gpu_test::GrContextFactory::ContextType ctxType;
|
2017-02-21 19:36:05 +00:00
|
|
|
sk_gpu_test::GrContextFactory::ContextOverrides ctxOverrides;
|
2022-03-14 19:18:31 +00:00
|
|
|
skiatest::graphite::ContextFactory::ContextType graphiteCtxType;
|
2021-03-17 02:49:15 +00:00
|
|
|
uint32_t surfaceFlags;
|
2015-03-26 18:28:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Target {
|
|
|
|
explicit Target(const Config& c) : config(c) { }
|
|
|
|
virtual ~Target() { }
|
|
|
|
|
|
|
|
const Config config;
|
2016-03-24 01:59:25 +00:00
|
|
|
sk_sp<SkSurface> surface;
|
2015-03-26 18:28:06 +00:00
|
|
|
|
|
|
|
/** Called once per target, immediately before any timing or drawing. */
|
|
|
|
virtual void setup() { }
|
|
|
|
|
|
|
|
/** Called *after* the clock timer is started, before the benchmark
|
2015-03-27 19:11:44 +00:00
|
|
|
is drawn. Most back ends just return the canvas passed in,
|
|
|
|
but some may replace it. */
|
2015-03-26 18:28:06 +00:00
|
|
|
virtual SkCanvas* beginTiming(SkCanvas* canvas) { return canvas; }
|
|
|
|
|
|
|
|
/** Called *after* a benchmark is drawn, but before the clock timer
|
|
|
|
is stopped. */
|
|
|
|
virtual void endTiming() { }
|
|
|
|
|
|
|
|
/** Called between benchmarks (or between calibration and measured
|
|
|
|
runs) to make sure all pending work in drivers / threads is
|
|
|
|
complete. */
|
2022-03-28 19:27:44 +00:00
|
|
|
virtual void syncCPU() { }
|
2015-03-26 18:28:06 +00:00
|
|
|
|
|
|
|
/** CPU-like targets can just be timed, but GPU-like
|
|
|
|
targets need to pay attention to frame boundaries
|
|
|
|
or other similar details. */
|
2015-06-23 20:23:44 +00:00
|
|
|
virtual bool needsFrameTiming(int* frameLag) const { return false; }
|
2015-03-26 18:28:06 +00:00
|
|
|
|
|
|
|
/** Called once per target, during program initialization.
|
|
|
|
Returns false if initialization fails. */
|
|
|
|
virtual bool init(SkImageInfo info, Benchmark* bench);
|
|
|
|
|
|
|
|
/** Stores any pixels drawn to the screen in the bitmap.
|
|
|
|
Returns false on error. */
|
|
|
|
virtual bool capturePixels(SkBitmap* bmp);
|
|
|
|
|
2017-10-11 19:34:27 +00:00
|
|
|
/** Writes gathered stats using SkDebugf. */
|
|
|
|
virtual void dumpStats() {}
|
|
|
|
|
2015-03-27 19:11:44 +00:00
|
|
|
SkCanvas* getCanvas() const {
|
2020-08-16 12:48:02 +00:00
|
|
|
if (!surface) {
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2015-03-27 19:11:44 +00:00
|
|
|
}
|
|
|
|
return surface->getCanvas();
|
|
|
|
}
|
2015-03-26 18:28:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nanobench_DEFINED
|