blob: 9d7b946afec9598b6e0b82850c494f219ef9d39a [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"
joshualittda7b8432015-05-27 09:19:03 -070018#include "gl/SkGLContext.h"
19
20class GrContext;
21struct GrGLInterface;
22class GrRenderTarget;
23class SkCanvas;
24
25/*
26 * A Visual benchmarking tool for gpu benchmarking
27 */
28class VisualBench : public SkOSWindow {
29public:
30 VisualBench(void* hwnd, int argc, char** argv);
31 ~VisualBench() override;
32
33protected:
34 SkSurface* createSurface() override;
35
36 void draw(SkCanvas* canvas) override;
37
38 void onSizeChange() override;
39
40private:
41 void setTitle();
42 bool setupBackend();
joshualitt7fe8ee42015-06-01 10:03:54 -070043 void resetContext();
joshualittda7b8432015-05-27 09:19:03 -070044 void setupRenderTarget();
45 bool onHandleChar(SkUnichar unichar) override;
joshualitt7fe8ee42015-06-01 10:03:54 -070046 void printStats();
bsalomon45171e22015-06-16 13:52:18 -070047 bool loadPicture();
48 bool advanceRecordIfNecessary();
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 {
52 SkString fFilename;
joshualitt7fe8ee42015-06-01 10:03:54 -070053 SkTArray<double> fMeasurements;
54 };
55
56 enum State {
57 kPreWarm_State,
58 kTiming_State,
59 };
60
61 int fLoop;
bsalomon45171e22015-06-16 13:52:18 -070062 int fCurrentPictureIdx;
63 SkAutoTUnref<SkPicture> fPicture;
joshualitt7fe8ee42015-06-01 10:03:54 -070064 int fCurrentSample;
bsalomon45171e22015-06-16 13:52:18 -070065 SkTArray<Record> fRecords;
joshualitt7fe8ee42015-06-01 10:03:54 -070066 WallTimer fTimer;
67 State fState;
joshualittda7b8432015-05-27 09:19:03 -070068
69 // support framework
70 SkAutoTUnref<SkSurface> fSurface;
71 SkAutoTUnref<GrContext> fContext;
72 SkAutoTUnref<GrRenderTarget> fRenderTarget;
73 AttachmentInfo fAttachmentInfo;
74 SkAutoTUnref<const GrGLInterface> fInterface;
75
76 typedef SkOSWindow INHERITED;
77};
78
79#endif