273c0f5e87
rename subclasses Fix up the EGL native GLTestContext GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1849463002 TBR=jvanverth@google.com Committed: https://skia.googlesource.com/skia/+/4c7f0a16312c374eba4e8d5d46435ce9eb0b9971 Review URL: https://codereview.chromium.org/1849463002
80 lines
2.8 KiB
C++
80 lines
2.8 KiB
C++
/*
|
|
* Copyright 2015 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "VisualStreamTimingModule.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
DEFINE_bool(reset, true, "Reset the GL context between samples.");
|
|
|
|
VisualStreamTimingModule::VisualStreamTimingModule(VisualBench* owner)
|
|
: fInitState(kReset_InitState)
|
|
, fOwner(owner) {
|
|
fBenchmarkStream.reset(new VisualBenchmarkStream(owner->getSurfaceProps()));
|
|
}
|
|
|
|
inline void VisualStreamTimingModule::handleInitState(SkCanvas* canvas) {
|
|
switch (fInitState) {
|
|
case kNewBenchmark_InitState:
|
|
fBenchmarkStream->current()->delayedSetup();
|
|
// fallthrough
|
|
case kReset_InitState:
|
|
// This will flicker unfortunately, but as we are reseting the GLTestContext each bench,
|
|
// we unfortunately don't have a choice
|
|
fOwner->clear(canvas, SK_ColorWHITE, 3);
|
|
fBenchmarkStream->current()->preTimingHooks(canvas);
|
|
break;
|
|
case kNone_InitState:
|
|
break;
|
|
}
|
|
fInitState = kNone_InitState;
|
|
}
|
|
|
|
inline void VisualStreamTimingModule::handleTimingEvent(SkCanvas* canvas,
|
|
TimingStateMachine::ParentEvents event) {
|
|
switch (event) {
|
|
case TimingStateMachine::kTiming_ParentEvents:
|
|
break;
|
|
case TimingStateMachine::kTimingFinished_ParentEvents:
|
|
if (this->timingFinished(fBenchmarkStream->current(), fTSM.loops(),
|
|
fTSM.lastMeasurement())) {
|
|
fBenchmarkStream->current()->postTimingHooks(canvas);
|
|
fOwner->reset();
|
|
fTSM.nextBenchmark();
|
|
if (!fBenchmarkStream->next()) {
|
|
SkDebugf("Exiting VisualBench successfully\n");
|
|
fOwner->closeWindow();
|
|
} else {
|
|
fInitState = kNewBenchmark_InitState;
|
|
}
|
|
break;
|
|
}
|
|
// fallthrough
|
|
case TimingStateMachine::kReset_ParentEvents:
|
|
if (FLAGS_reset) {
|
|
fBenchmarkStream->current()->postTimingHooks(canvas);
|
|
fOwner->reset();
|
|
fInitState = kReset_InitState;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
void VisualStreamTimingModule::draw(SkCanvas* canvas) {
|
|
if (!fBenchmarkStream->current()) {
|
|
// this should never happen but just to be safe
|
|
// TODO research why this does happen on mac
|
|
return;
|
|
}
|
|
|
|
this->handleInitState(canvas);
|
|
this->renderFrame(canvas, fBenchmarkStream->current(), fTSM.loops());
|
|
fOwner->present();
|
|
TimingStateMachine::ParentEvents event = fTSM.nextFrame(FLAGS_reset);
|
|
this->handleTimingEvent(canvas, event);
|
|
}
|