blob: ffa109dc495df829c6f0e3b392c9942e259ba01a [file] [log] [blame]
joshualitt189aef72015-09-08 07:08:11 -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 VisualLightweightBenchModule_DEFINED
10#define VisualLightweightBenchModule_DEFINED
11
12#include "VisualModule.h"
13
14#include "ResultsWriter.h"
15#include "SkPicture.h"
joshualitt98d2e2f2015-10-05 07:23:30 -070016#include "TimingStateMachine.h"
joshualitt189aef72015-09-08 07:08:11 -070017#include "VisualBench.h"
18#include "VisualBenchmarkStream.h"
19
20class SkCanvas;
21
22/*
23 * This module is designed to be a minimal overhead timing module for VisualBench
24 */
25class VisualLightweightBenchModule : public VisualModule {
26public:
27 // TODO get rid of backpointer
28 VisualLightweightBenchModule(VisualBench* owner);
29
30 void draw(SkCanvas* canvas) override;
31
jvanverthf5d1b2d2015-09-15 07:40:56 -070032 bool onHandleChar(SkUnichar c) override;
33
joshualitt189aef72015-09-08 07:08:11 -070034private:
joshualitt189aef72015-09-08 07:08:11 -070035 void setTitle();
36 bool setupBackend();
37 void setupRenderTarget();
38 void printStats();
39 bool advanceRecordIfNecessary(SkCanvas*);
40 inline void renderFrame(SkCanvas*);
joshualitt189aef72015-09-08 07:08:11 -070041
42 struct Record {
43 SkTArray<double> fMeasurements;
44 };
joshualitt189aef72015-09-08 07:08:11 -070045 int fCurrentSample;
joshualitt189aef72015-09-08 07:08:11 -070046 SkTArray<Record> fRecords;
joshualitt189aef72015-09-08 07:08:11 -070047 SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream;
48 SkAutoTUnref<Benchmark> fBenchmark;
joshualitt98d2e2f2015-10-05 07:23:30 -070049 TimingStateMachine fTSM;
joshualitt189aef72015-09-08 07:08:11 -070050
51 // support framework
52 SkAutoTUnref<VisualBench> fOwner;
53 SkAutoTDelete<ResultsWriter> fResults;
54
55 typedef VisualModule INHERITED;
56};
57
58#endif