| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "VisualStreamTimingModule.h" | 8 #include "VisualStreamTimingModule.h" |
| 9 | 9 |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 | 11 |
| 12 VisualStreamTimingModule::VisualStreamTimingModule(VisualBench* owner, bool preW
armBeforeSample) | 12 VisualStreamTimingModule::VisualStreamTimingModule(VisualBench* owner, bool preW
armBeforeSample) |
| 13 : fReinitializeBenchmark(false) | 13 : fReinitializeBenchmark(false) |
| 14 , fPreWarmBeforeSample(preWarmBeforeSample) | 14 , fPreWarmBeforeSample(preWarmBeforeSample) |
| 15 , fOwner(owner) { | 15 , fOwner(owner) { |
| 16 fBenchmarkStream.reset(new VisualBenchmarkStream); | 16 fBenchmarkStream.reset(new VisualBenchmarkStream); |
| 17 } | 17 } |
| 18 | 18 |
| 19 bool VisualStreamTimingModule::nextBenchmarkIfNecessary(SkCanvas* canvas) { |
| 20 if (fBenchmark) { |
| 21 return true; |
| 22 } |
| 23 |
| 24 fBenchmark.reset(fBenchmarkStream->next()); |
| 25 if (!fBenchmark) { |
| 26 return false; |
| 27 } |
| 28 |
| 29 fOwner->clear(canvas, SK_ColorWHITE, 2); |
| 30 |
| 31 fBenchmark->delayedSetup(); |
| 32 fBenchmark->preTimingHooks(canvas); |
| 33 return true; |
| 34 } |
| 35 |
| 19 void VisualStreamTimingModule::draw(SkCanvas* canvas) { | 36 void VisualStreamTimingModule::draw(SkCanvas* canvas) { |
| 20 if (!fBenchmarkStream->current()) { | 37 if (!this->nextBenchmarkIfNecessary(canvas)) { |
| 21 // this should never happen but just to be safe | 38 SkDebugf("Exiting VisualBench successfully\n"); |
| 39 fOwner->closeWindow(); |
| 22 return; | 40 return; |
| 23 } | 41 } |
| 24 | 42 |
| 25 if (fReinitializeBenchmark) { | 43 if (fReinitializeBenchmark) { |
| 26 fReinitializeBenchmark = false; | 44 fReinitializeBenchmark = false; |
| 27 fBenchmarkStream->current()->preTimingHooks(canvas); | 45 fBenchmark->preTimingHooks(canvas); |
| 28 } | 46 } |
| 29 | 47 |
| 30 this->renderFrame(canvas, fBenchmarkStream->current(), fTSM.loops()); | 48 this->renderFrame(canvas, fBenchmark, fTSM.loops()); |
| 31 fOwner->present(); | 49 fOwner->present(); |
| 32 TimingStateMachine::ParentEvents event = fTSM.nextFrame(fPreWarmBeforeSample
); | 50 TimingStateMachine::ParentEvents event = fTSM.nextFrame(fPreWarmBeforeSample
); |
| 33 switch (event) { | 51 switch (event) { |
| 34 case TimingStateMachine::kReset_ParentEvents: | 52 case TimingStateMachine::kReset_ParentEvents: |
| 35 fBenchmarkStream->current()->postTimingHooks(canvas); | 53 fBenchmark->postTimingHooks(canvas); |
| 36 fOwner->reset(); | 54 fOwner->reset(); |
| 37 fReinitializeBenchmark = true; | 55 fReinitializeBenchmark = true; |
| 38 break; | 56 break; |
| 39 case TimingStateMachine::kTiming_ParentEvents: | 57 case TimingStateMachine::kTiming_ParentEvents: |
| 40 break; | 58 break; |
| 41 case TimingStateMachine::kTimingFinished_ParentEvents: | 59 case TimingStateMachine::kTimingFinished_ParentEvents: |
| 42 fBenchmarkStream->current()->postTimingHooks(canvas); | 60 fBenchmark->postTimingHooks(canvas); |
| 43 fOwner->reset(); | 61 fOwner->reset(); |
| 44 if (this->timingFinished(fBenchmarkStream->current(), fTSM.loops(), | 62 if (this->timingFinished(fBenchmark, fTSM.loops(), fTSM.lastMeasurem
ent())) { |
| 45 fTSM.lastMeasurement())) { | 63 fTSM.nextBenchmark(canvas, fBenchmark); |
| 46 fTSM.nextBenchmark(); | 64 fBenchmark.reset(nullptr); |
| 47 if (!fBenchmarkStream->next()) { | |
| 48 SkDebugf("Exiting VisualBench successfully\n"); | |
| 49 fOwner->closeWindow(); | |
| 50 } else { | |
| 51 fOwner->clear(canvas, SK_ColorWHITE, 2); | |
| 52 | |
| 53 fBenchmarkStream->current()->delayedSetup(); | |
| 54 fBenchmarkStream->current()->preTimingHooks(canvas); | |
| 55 } | |
| 56 } else { | 65 } else { |
| 57 fReinitializeBenchmark = true; | 66 fReinitializeBenchmark = true; |
| 58 } | 67 } |
| 59 break; | 68 break; |
| 60 } | 69 } |
| 61 } | 70 } |
| OLD | NEW |