Fix test app to ensure that we destroy our GPU resources.

The problem arises on devices like the Nexus 10 where we allow the
destruction of resources using the destructor of a static variable.
However, we have no guarentee that the GPU driver has not already
cleaned up it's resources prior to our static destructor.

Review URL: https://codereview.appspot.com/6851124

git-svn-id: http://skia.googlecode.com/svn/trunk@6599 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
djsollen@google.com 2012-11-29 15:28:45 +00:00
parent 5afbbc47df
commit 0945bde599
3 changed files with 16 additions and 5 deletions

View File

@ -83,15 +83,24 @@ bool Test::run() {
///////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
static SkAutoTUnref<SkNativeGLContext> gGLContext;
static SkAutoTUnref<GrContext> gGrContext;
#endif
void GpuTest::DestroyContext() {
#if SK_SUPPORT_GPU
// preserve this order, we want gGrContext destroyed after gEGLContext
gGLContext.reset(NULL);
gGrContext.reset(NULL);
#endif
}
GrContext* GpuTest::GetContext() {
#if SK_SUPPORT_GPU
// preserve this order, we want gGrContext destroyed after gEGLContext
static SkTLazy<SkNativeGLContext> gGLContext;
static SkAutoTUnref<GrContext> gGrContext;
if (NULL == gGrContext.get()) {
gGLContext.init();
gGLContext.reset(new SkNativeGLContext());
if (gGLContext.get()->init(800, 600)) {
GrBackendContext ctx = reinterpret_cast<GrBackendContext>(gGLContext.get()->gl());
gGrContext.reset(GrContext::Create(kOpenGL_GrBackend, ctx));

View File

@ -104,6 +104,7 @@ namespace skiatest {
fContext = GetContext();
}
static GrContext* GetContext();
static void DestroyContext();
protected:
GrContext* fContext;
private:

View File

@ -186,6 +186,7 @@ int tool_main(int argc, char** argv) {
#endif
SkGraphics::Term();
GpuTest::DestroyContext();
return (failCount == 0) ? 0 : 1;
}