Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / bench / nanobench.h
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"
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"
17
18 class SkBitmap;
19 class SkCanvas;
20 class NanoJSONResultsWriter;
21
22 struct Config {
23     SkString name;
24     Benchmark::Backend backend;
25     SkColorType color;
26     SkAlphaType alpha;
27     sk_sp<SkColorSpace> colorSpace;
28     int samples;
29     sk_gpu_test::GrContextFactory::ContextType ctxType;
30     sk_gpu_test::GrContextFactory::ContextOverrides ctxOverrides;
31     skiatest::graphite::ContextFactory::ContextType graphiteCtxType;
32     uint32_t surfaceFlags;
33 };
34
35 struct Target {
36     explicit Target(const Config& c) : config(c) { }
37     virtual ~Target() { }
38
39     const Config config;
40     sk_sp<SkSurface> surface;
41
42     /** Called once per target, immediately before any timing or drawing. */
43     virtual void setup() { }
44
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; }
49
50     /** Called *after* a benchmark is drawn, but before the clock timer
51         is stopped.  */
52     virtual void endTiming() { }
53
54     /** Called between benchmarks (or between calibration and measured
55         runs) to make sure all pending work in drivers / threads is
56         complete. */
57     virtual void syncCPU() { }
58
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; }
63
64     /** Called once per target, during program initialization.
65         Returns false if initialization fails. */
66     virtual bool init(SkImageInfo info, Benchmark* bench);
67
68     /** Stores any pixels drawn to the screen in the bitmap.
69         Returns false on error. */
70     virtual bool capturePixels(SkBitmap* bmp);
71
72     /** Writes gathered stats using SkDebugf. */
73     virtual void dumpStats() {}
74
75     SkCanvas* getCanvas() const {
76         if (!surface) {
77             return nullptr;
78         }
79         return surface->getCanvas();
80     }
81 };
82
83 #endif  // nanobench_DEFINED