From 0945bde5999da38b2de4a0998225a25901c4e429 Mon Sep 17 00:00:00 2001 From: "djsollen@google.com" Date: Thu, 29 Nov 2012 15:28:45 +0000 Subject: [PATCH] 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 --- tests/Test.cpp | 17 +++++++++++++---- tests/Test.h | 1 + tests/skia_test.cpp | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/Test.cpp b/tests/Test.cpp index 07107bc..bebb351 100644 --- a/tests/Test.cpp +++ b/tests/Test.cpp @@ -83,15 +83,24 @@ bool Test::run() { /////////////////////////////////////////////////////////////////////////////// +#if SK_SUPPORT_GPU + static SkAutoTUnref gGLContext; + static SkAutoTUnref gGrContext; +#endif -GrContext* GpuTest::GetContext() { +void GpuTest::DestroyContext() { #if SK_SUPPORT_GPU // preserve this order, we want gGrContext destroyed after gEGLContext - static SkTLazy gGLContext; - static SkAutoTUnref gGrContext; + gGLContext.reset(NULL); + gGrContext.reset(NULL); +#endif +} + +GrContext* GpuTest::GetContext() { +#if SK_SUPPORT_GPU if (NULL == gGrContext.get()) { - gGLContext.init(); + gGLContext.reset(new SkNativeGLContext()); if (gGLContext.get()->init(800, 600)) { GrBackendContext ctx = reinterpret_cast(gGLContext.get()->gl()); gGrContext.reset(GrContext::Create(kOpenGL_GrBackend, ctx)); diff --git a/tests/Test.h b/tests/Test.h index f87a7a0..2cbd00b 100644 --- a/tests/Test.h +++ b/tests/Test.h @@ -104,6 +104,7 @@ namespace skiatest { fContext = GetContext(); } static GrContext* GetContext(); + static void DestroyContext(); protected: GrContext* fContext; private: diff --git a/tests/skia_test.cpp b/tests/skia_test.cpp index 560abb2..a744801 100644 --- a/tests/skia_test.cpp +++ b/tests/skia_test.cpp @@ -186,6 +186,7 @@ int tool_main(int argc, char** argv) { #endif SkGraphics::Term(); + GpuTest::DestroyContext(); return (failCount == 0) ? 0 : 1; } -- 2.7.4