Force VisualBench to reset GLContext on GrContext reset

BUG=skia:

Review URL: https://codereview.chromium.org/1416063002
This commit is contained in:
joshualitt 2015-10-21 08:04:24 -07:00 committed by Commit bot
parent b64b195dbd
commit fb02cdafda
4 changed files with 31 additions and 9 deletions

View File

@ -337,7 +337,7 @@ void SkOSWindow::mapWindowAndWait() {
k##name = (type) GLX_GET_PROC_ADDR(#name); \
} \
k##name(__VA_ARGS__); \
SkDebugf("using %s\n", #name); \
/*SkDebugf("using %s\n", #name);*/ \
return; \
}

View File

@ -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!");
}
}
if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) {
SkDebugf("Not possible to create backend.\n");
INHERITED::detach();
return false;
}
this->setVsync(false);
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();
SkFAIL("Could not create backend\n");
}
this->setVsync(false);
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));

View File

@ -48,6 +48,8 @@ private:
void resetContext();
void setupRenderTarget();
bool onHandleChar(SkUnichar unichar) override;
void tearDownContext();
void setupContext();
// support framework
SkAutoTDelete<VisualModule> fModule;

View File

@ -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: