blob: 13fc85c6b8473ca9096addfe47f530aa84ab2ce6 [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"
15#include "SkSurface.h"
joshualitt7fe8ee42015-06-01 10:03:54 -070016#include "Timer.h"
joshualittda7b8432015-05-27 09:19:03 -070017#include "gl/SkGLContext.h"
18
19class GrContext;
20struct GrGLInterface;
21class GrRenderTarget;
22class SkCanvas;
23
24/*
25 * A Visual benchmarking tool for gpu benchmarking
26 */
27class VisualBench : public SkOSWindow {
28public:
29 VisualBench(void* hwnd, int argc, char** argv);
30 ~VisualBench() override;
31
32protected:
33 SkSurface* createSurface() override;
34
35 void draw(SkCanvas* canvas) override;
36
37 void onSizeChange() override;
38
39private:
40 void setTitle();
41 bool setupBackend();
joshualitt7fe8ee42015-06-01 10:03:54 -070042 void resetContext();
joshualittda7b8432015-05-27 09:19:03 -070043 void setupRenderTarget();
44 bool onHandleChar(SkUnichar unichar) override;
joshualitt7fe8ee42015-06-01 10:03:54 -070045 void printStats();
46 inline void timePicture(SkCanvas*);
47 inline void renderFrame(SkCanvas*);
joshualittda7b8432015-05-27 09:19:03 -070048
joshualitt7fe8ee42015-06-01 10:03:54 -070049 struct Timing {
50 SkString fName;
51 SkTArray<double> fMeasurements;
52 };
53
54 enum State {
55 kPreWarm_State,
56 kTiming_State,
57 };
58
59 int fLoop;
joshualittda7b8432015-05-27 09:19:03 -070060 int fCurrentPicture;
joshualitt7fe8ee42015-06-01 10:03:54 -070061 int fCurrentSample;
62 SkTArray<Timing> fTimings;
joshualittda7b8432015-05-27 09:19:03 -070063 SkTArray<SkPicture*> fPictures;
joshualitt7fe8ee42015-06-01 10:03:54 -070064 WallTimer fTimer;
65 State fState;
joshualittda7b8432015-05-27 09:19:03 -070066
67 // support framework
68 SkAutoTUnref<SkSurface> fSurface;
69 SkAutoTUnref<GrContext> fContext;
70 SkAutoTUnref<GrRenderTarget> fRenderTarget;
71 AttachmentInfo fAttachmentInfo;
72 SkAutoTUnref<const GrGLInterface> fInterface;
73
74 typedef SkOSWindow INHERITED;
75};
76
77#endif