blob: 683151f56629b32bc21c11d13a4974f11e75a7aa [file] [log] [blame]
joshualittda7b8432015-05-27 09:19:03 -07001/*
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
9#ifndef VisualBench_DEFINED
10#define VisualBench_DEFINED
11
12#include "SkWindow.h"
13
14#include "SkPicture.h"
bsalomon45171e22015-06-16 13:52:18 -070015#include "SkString.h"
joshualittda7b8432015-05-27 09:19:03 -070016#include "SkSurface.h"
joshualitt7fe8ee42015-06-01 10:03:54 -070017#include "Timer.h"
joshualitt962cc982015-06-30 07:43:14 -070018#include "VisualBenchmarkStream.h"
joshualittda7b8432015-05-27 09:19:03 -070019#include "gl/SkGLContext.h"
20
21class GrContext;
22struct GrGLInterface;
23class GrRenderTarget;
24class SkCanvas;
25
26/*
27 * A Visual benchmarking tool for gpu benchmarking
28 */
29class VisualBench : public SkOSWindow {
30public:
31 VisualBench(void* hwnd, int argc, char** argv);
32 ~VisualBench() override;
33
34protected:
35 SkSurface* createSurface() override;
36
37 void draw(SkCanvas* canvas) override;
38
39 void onSizeChange() override;
40
41private:
42 void setTitle();
43 bool setupBackend();
joshualitt7fe8ee42015-06-01 10:03:54 -070044 void resetContext();
joshualittda7b8432015-05-27 09:19:03 -070045 void setupRenderTarget();
46 bool onHandleChar(SkUnichar unichar) override;
joshualitt7fe8ee42015-06-01 10:03:54 -070047 void printStats();
joshualitt962cc982015-06-30 07:43:14 -070048 bool advanceRecordIfNecessary(SkCanvas*);
joshualitt7fe8ee42015-06-01 10:03:54 -070049 inline void renderFrame(SkCanvas*);
joshualittda7b8432015-05-27 09:19:03 -070050
bsalomon45171e22015-06-16 13:52:18 -070051 struct Record {
joshualitt7fe8ee42015-06-01 10:03:54 -070052 SkTArray<double> fMeasurements;
53 };
54
55 enum State {
joshualitt6205af02015-06-23 07:10:59 -070056 kPreWarmLoops_State,
57 kTuneLoops_State,
58 kPreWarmTiming_State,
joshualitt7fe8ee42015-06-01 10:03:54 -070059 kTiming_State,
60 };
joshualitt6205af02015-06-23 07:10:59 -070061 void preWarm(State nextState);
joshualitt7fe8ee42015-06-01 10:03:54 -070062
joshualitt7fe8ee42015-06-01 10:03:54 -070063 int fCurrentSample;
joshualitt6205af02015-06-23 07:10:59 -070064 int fCurrentFrame;
65 int fFlushes;
66 int fLoops;
bsalomon45171e22015-06-16 13:52:18 -070067 SkTArray<Record> fRecords;
joshualitt7fe8ee42015-06-01 10:03:54 -070068 WallTimer fTimer;
69 State fState;
joshualitt962cc982015-06-30 07:43:14 -070070 SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream;
71 Benchmark* fBenchmark;
joshualittda7b8432015-05-27 09:19:03 -070072
73 // support framework
74 SkAutoTUnref<SkSurface> fSurface;
75 SkAutoTUnref<GrContext> fContext;
76 SkAutoTUnref<GrRenderTarget> fRenderTarget;
77 AttachmentInfo fAttachmentInfo;
78 SkAutoTUnref<const GrGLInterface> fInterface;
79
80 typedef SkOSWindow INHERITED;
81};
82
83#endif