OLD | NEW |
(Empty) | |
| 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 |
| 9 #include "VisualStreamTimingModule.h" |
| 10 |
| 11 #include "SkCanvas.h" |
| 12 |
| 13 VisualStreamTimingModule::VisualStreamTimingModule(VisualBench* owner, bool preW
armBeforeSample) |
| 14 : fHasBeenReset(false) |
| 15 , fPreWarmBeforeSample(preWarmBeforeSample) |
| 16 , fOwner(SkRef(owner)) { |
| 17 fBenchmarkStream.reset(new VisualBenchmarkStream); |
| 18 } |
| 19 |
| 20 bool VisualStreamTimingModule::nextBenchmarkIfNecessary(SkCanvas* canvas) { |
| 21 if (fBenchmark) { |
| 22 return true; |
| 23 } |
| 24 |
| 25 fBenchmark.reset(fBenchmarkStream->next()); |
| 26 if (!fBenchmark) { |
| 27 return false; |
| 28 } |
| 29 |
| 30 fOwner->clear(canvas, SK_ColorWHITE, 2); |
| 31 |
| 32 fBenchmark->delayedSetup(); |
| 33 fBenchmark->preTimingHooks(canvas); |
| 34 return true; |
| 35 } |
| 36 |
| 37 void VisualStreamTimingModule::draw(SkCanvas* canvas) { |
| 38 if (!this->nextBenchmarkIfNecessary(canvas)) { |
| 39 SkDebugf("Exiting VisualBench successfully\n"); |
| 40 fOwner->closeWindow(); |
| 41 return; |
| 42 } |
| 43 |
| 44 if (fHasBeenReset) { |
| 45 fHasBeenReset = false; |
| 46 fBenchmark->preTimingHooks(canvas); |
| 47 } |
| 48 |
| 49 this->renderFrame(canvas, fBenchmark, fTSM.loops()); |
| 50 fOwner->present(); |
| 51 TimingStateMachine::ParentEvents event = fTSM.nextFrame(fPreWarmBeforeSample
); |
| 52 switch (event) { |
| 53 case TimingStateMachine::kReset_ParentEvents: |
| 54 fBenchmark->postTimingHooks(canvas); |
| 55 fOwner->reset(); |
| 56 fHasBeenReset = true; |
| 57 break; |
| 58 case TimingStateMachine::kTiming_ParentEvents: |
| 59 break; |
| 60 case TimingStateMachine::kTimingFinished_ParentEvents: |
| 61 fBenchmark->postTimingHooks(canvas); |
| 62 fOwner->reset(); |
| 63 if (this->timingFinished(fBenchmark, fTSM.loops(), fTSM.lastMeasurem
ent())) { |
| 64 fTSM.nextBenchmark(canvas, fBenchmark); |
| 65 fBenchmark.reset(nullptr); |
| 66 } else { |
| 67 fHasBeenReset = true; |
| 68 } |
| 69 break; |
| 70 } |
| 71 } |
OLD | NEW |