diff options
author | bsalomon <bsalomon@google.com> | 2014-07-28 13:48:36 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-07-28 13:48:36 -0700 |
commit | 2354f8432a7205571f04f9638a0018fb0b1fb282 (patch) | |
tree | e342688d205bb86fff9a22305e333364f74f1545 | |
parent | 4beef91ec04b2edfbe983e672d50cd8f477eda7f (diff) |
Test abandoning GL context in dm/nanobench.
Rename GrContext::contextDestroyed to GrContext::abandonContext.
Remove GrContext::resetContext.
R=robertphillips@google.com
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/422903002
-rw-r--r-- | bench/nanobench.cpp | 5 | ||||
-rw-r--r-- | dm/DMGpuSupport.h | 2 | ||||
-rw-r--r-- | dm/DMTask.cpp | 5 | ||||
-rw-r--r-- | include/gpu/GrContext.h | 29 | ||||
-rw-r--r-- | include/gpu/GrContextFactory.h | 15 | ||||
-rwxr-xr-x | src/gpu/GrContext.cpp | 7 | ||||
-rw-r--r-- | tools/flags/SkCommonFlags.cpp | 4 | ||||
-rw-r--r-- | tools/flags/SkCommonFlags.h | 1 |
8 files changed, 41 insertions, 27 deletions
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index 3cc03a805d..07ff0dd2b0 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -477,7 +477,10 @@ int nanobench_main() { targets.deleteAll(); #if SK_SUPPORT_GPU - if (FLAGS_resetGpuContext) { + if (FLAGS_abandonGpuContext) { + gGrFactory.abandonContexts(); + } + if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { gGrFactory.destroyContexts(); } #endif diff --git a/dm/DMGpuSupport.h b/dm/DMGpuSupport.h index 209f3223e5..a3c487d596 100644 --- a/dm/DMGpuSupport.h +++ b/dm/DMGpuSupport.h @@ -48,6 +48,8 @@ public: kNative_GLContextType = 0, kNull_GLContextType = 0; void destroyContexts() {} + + void abandonContexts() {} }; namespace DM { diff --git a/dm/DMTask.cpp b/dm/DMTask.cpp index d0a82b63d6..05eda4ea20 100644 --- a/dm/DMTask.cpp +++ b/dm/DMTask.cpp @@ -68,7 +68,10 @@ void GpuTask::run(GrContextFactory& factory) { this->start(); if (!FLAGS_dryRun) this->draw(&factory); this->finish(); - if (FLAGS_resetGpuContext) { + if (FLAGS_abandonGpuContext) { + factory.abandonContexts(); + } + if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { factory.destroyContexts(); } } diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index f533851ac3..103d76e8a2 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -85,24 +85,21 @@ public: } /** - * Abandons all GPU resources, assumes 3D API state is unknown. Call this - * if you have lost the associated GPU context, and thus internal texture, - * buffer, etc. references/IDs are now invalid. Should be called even when - * GrContext is no longer going to be used for two reasons: + * Abandons all GPU resources and assumes the underlying backend 3D API + * context is not longer usable. Call this if you have lost the associated + * GPU context, and thus internal texture, buffer, etc. references/IDs are + * now invalid. Should be called even when GrContext is no longer going to + * be used for two reasons: * 1) ~GrContext will not try to free the objects in the 3D API. - * 2) If you've created GrGpuResources that outlive the GrContext they - * will be marked as invalid (GrGpuResource::isValid()) and won't - * attempt to free their underlying resource in the 3D API. - * Content drawn since the last GrContext::flush() may be lost. + * 2) Any GrGpuResources created by this GrContext that outlive + * will be marked as invalid (GrGpuResource::wasDestroyed()) and + * when they're destroyed no 3D API calls will be made. + * Content drawn since the last GrContext::flush() may be lost. After this + * function is called the only valid action on the GrContext or + * GrGpuResources it created is to destroy them. */ - void contextLost(); - - /** - * Similar to contextLost, but makes no attempt to reset state. - * Use this method when GrContext destruction is pending, but - * the graphics context is destroyed first. - */ - void contextDestroyed(); + void abandonContext(); + void contextDestroyed() { this->abandonContext(); } // legacy alias /////////////////////////////////////////////////////////////////////////// // Resource Cache diff --git a/include/gpu/GrContextFactory.h b/include/gpu/GrContextFactory.h index 1f1f89df14..01e0239b1a 100644 --- a/include/gpu/GrContextFactory.h +++ b/include/gpu/GrContextFactory.h @@ -94,13 +94,24 @@ public: void destroyContexts() { for (int i = 0; i < fContexts.count(); ++i) { - fContexts[i].fGLContext->makeCurrent(); + if (NULL != fContexts[i].fGLContext) { // could be abandoned. + fContexts[i].fGLContext->makeCurrent(); + } fContexts[i].fGrContext->unref(); - fContexts[i].fGLContext->unref(); + if (NULL != fContexts[i].fGLContext) { + fContexts[i].fGLContext->unref(); + } } fContexts.reset(); } + void abandonContexts() { + for (int i = 0; i < fContexts.count(); ++i) { + SkSafeSetNull(fContexts[i].fGLContext); + fContexts[i].fGrContext->abandonContext(); + } + } + /** * Get a GrContext initialized with a type of GL context. It also makes the GL context current. */ diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index c171446440..6a35ed9d26 100755 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -175,12 +175,7 @@ GrContext::~GrContext() { fDrawState->unref(); } -void GrContext::contextLost() { - this->contextDestroyed(); - this->setupDrawBuffer(); -} - -void GrContext::contextDestroyed() { +void GrContext::abandonContext() { // abandon first to so destructors // don't try to free the resources in the API. fGpu->abandonResources(); diff --git a/tools/flags/SkCommonFlags.cpp b/tools/flags/SkCommonFlags.cpp index 7b47c58c6b..a30ba7e7fb 100644 --- a/tools/flags/SkCommonFlags.cpp +++ b/tools/flags/SkCommonFlags.cpp @@ -38,7 +38,9 @@ DEFINE_string2(match, m, NULL, DEFINE_bool2(quiet, q, false, "if true, don't print status updates."); -DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each bench."); +DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test."); +DEFINE_bool(abandonGpuContext, false, "Abandon the GrContext after running each test. " + "Implies --resetGpuContext."); DEFINE_bool2(single, z, false, "run tests on a single thread internally."); diff --git a/tools/flags/SkCommonFlags.h b/tools/flags/SkCommonFlags.h index 3c4910b6b4..a30d1ae3ed 100644 --- a/tools/flags/SkCommonFlags.h +++ b/tools/flags/SkCommonFlags.h @@ -19,6 +19,7 @@ DECLARE_bool(leaks); DECLARE_string(match); DECLARE_bool(quiet); DECLARE_bool(resetGpuContext); +DECLARE_bool(abandonGpuContext); DECLARE_bool(single); DECLARE_int32(threads); DECLARE_string(resourcePath); |