diff options
Diffstat (limited to 'tools/VisualBench')
-rw-r--r-- | tools/VisualBench/VisualBench.cpp | 30 | ||||
-rw-r--r-- | tools/VisualBench/VisualBench.h | 2 | ||||
-rw-r--r-- | tools/VisualBench/VisualStreamTimingModule.cpp | 4 |
3 files changed, 29 insertions, 7 deletions
diff --git a/tools/VisualBench/VisualBench.cpp b/tools/VisualBench/VisualBench.cpp index 9cc2ec1c3b..893dba6ab3 100644 --- a/tools/VisualBench/VisualBench.cpp +++ b/tools/VisualBench/VisualBench.cpp @@ -40,7 +40,7 @@ VisualBench::VisualBench(void* hwnd, int argc, char** argv) } VisualBench::~VisualBench() { - INHERITED::detach(); + this->tearDownContext(); } void VisualBench::setTitle() { @@ -68,18 +68,25 @@ bool VisualBench::setupBackend() { SkDebugf("Could not go fullscreen!"); } } + + this->resetContext(); + return true; +} + +void VisualBench::resetContext() { + this->tearDownContext(); + this->setupContext(); +} + +void VisualBench::setupContext() { if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) { SkDebugf("Not possible to create backend.\n"); INHERITED::detach(); - return false; + SkFAIL("Could not create backend\n"); } this->setVsync(false); - this->resetContext(); - return true; -} -void VisualBench::resetContext() { fSurface.reset(nullptr); fInterface.reset(GrGLCreateNativeInterface()); @@ -98,6 +105,17 @@ void VisualBench::resetContext() { this->setupRenderTarget(); } +void VisualBench::tearDownContext() { + if (fContext) { + // We abandon the context in case SkWindow has kept a ref to the surface + fContext->abandonContext(); + fContext.reset(); + fSurface.reset(); + fInterface.reset(); + this->detach(); + } +} + void VisualBench::setupRenderTarget() { if (fContext) { fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fContext)); diff --git a/tools/VisualBench/VisualBench.h b/tools/VisualBench/VisualBench.h index c1f61d9519..1920a52b2b 100644 --- a/tools/VisualBench/VisualBench.h +++ b/tools/VisualBench/VisualBench.h @@ -48,6 +48,8 @@ private: void resetContext(); void setupRenderTarget(); bool onHandleChar(SkUnichar unichar) override; + void tearDownContext(); + void setupContext(); // support framework SkAutoTDelete<VisualModule> fModule; diff --git a/tools/VisualBench/VisualStreamTimingModule.cpp b/tools/VisualBench/VisualStreamTimingModule.cpp index 0a57e67221..cecc5acca7 100644 --- a/tools/VisualBench/VisualStreamTimingModule.cpp +++ b/tools/VisualBench/VisualStreamTimingModule.cpp @@ -19,10 +19,12 @@ VisualStreamTimingModule::VisualStreamTimingModule(VisualBench* owner, bool preW inline void VisualStreamTimingModule::handleInitState(SkCanvas* canvas) { switch (fInitState) { case kNewBenchmark_InitState: - fOwner->clear(canvas, SK_ColorWHITE, 2); fBenchmarkStream->current()->delayedSetup(); // fallthrough case kReset_InitState: + // This will flicker unfortunately, but as we are reseting the GLContext each bench, + // we unfortunately don't have a choice + fOwner->clear(canvas, SK_ColorWHITE, 2); fBenchmarkStream->current()->preTimingHooks(canvas); break; case kNone_InitState: |