joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 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 VisualStreamTimingModule_DEFINED |
| 9 | #define VisualStreamTimingModule_DEFINED |
| 10 | |
| 11 | #include "VisualModule.h" |
| 12 | |
| 13 | #include "TimingStateMachine.h" |
| 14 | #include "VisualBench.h" |
| 15 | #include "VisualBenchmarkStream.h" |
| 16 | |
joshualitt | c603c14 | 2015-10-15 07:18:29 -0700 | [diff] [blame^] | 17 | class SkCanvas; |
| 18 | |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 19 | /* |
| 20 | * VisualStreamTimingModule is the base class for modules which want to time a stream of Benchmarks. |
| 21 | * |
| 22 | * Subclasses should implement renderFrame, which is called for each frame, and timingFinished, |
| 23 | * which is called when a sample has finished timing. |
| 24 | */ |
| 25 | class VisualStreamTimingModule : public VisualModule { |
| 26 | public: |
| 27 | VisualStreamTimingModule(VisualBench* owner, bool preWarmBeforeSample); |
| 28 | void draw(SkCanvas* canvas) override; |
| 29 | |
| 30 | private: |
| 31 | virtual void renderFrame(SkCanvas*, Benchmark*, int loops)=0; |
| 32 | |
| 33 | // subclasses should return true to advance the stream |
| 34 | virtual bool timingFinished(Benchmark*, int loops, double measurement)=0; |
| 35 | |
joshualitt | c603c14 | 2015-10-15 07:18:29 -0700 | [diff] [blame^] | 36 | inline void handleInitState(SkCanvas*); |
| 37 | inline void handleTimingEvent(SkCanvas*, TimingStateMachine::ParentEvents); |
joshualitt | a3b8c67 | 2015-10-14 14:45:07 -0700 | [diff] [blame] | 38 | |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 39 | TimingStateMachine fTSM; |
| 40 | SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream; |
joshualitt | c603c14 | 2015-10-15 07:18:29 -0700 | [diff] [blame^] | 41 | enum InitState { |
| 42 | kNone_InitState, |
| 43 | kReset_InitState, |
| 44 | kNewBenchmark_InitState, |
| 45 | }; |
| 46 | InitState fInitState; |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 47 | bool fPreWarmBeforeSample; |
| 48 | |
| 49 | // support framework |
| 50 | VisualBench* fOwner; |
| 51 | |
| 52 | typedef VisualModule INHERITED; |
| 53 | }; |
| 54 | |
| 55 | #endif |