diff options
author | Greg Daniel <egdaniel@google.com> | 2018-01-16 11:20:41 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-16 17:12:53 +0000 |
commit | f0fe02fdc6a4adeb410f86a730527758f647a76c (patch) | |
tree | 23eb6320e4095c89aac0ce2c987186aff7d93dbf /tools | |
parent | d5e4d85843f92921660e704333df8afe8c582dc8 (diff) |
Delete Gr testing contexts in reverse order
This fixes issues where we create a child shared context and expect work
on that to finish before deleting the parent.
Bug: skia:
Change-Id: Iab41b22026cd4b9ec1b9d74e7841ee5051df6036
Reviewed-on: https://skia-review.googlesource.com/94962
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gpu/GrContextFactory.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp index 109d02896d..c6cceb4843 100644 --- a/tools/gpu/GrContextFactory.cpp +++ b/tools/gpu/GrContextFactory.cpp @@ -51,7 +51,12 @@ GrContextFactory::~GrContextFactory() { } void GrContextFactory::destroyContexts() { - for (Context& context : fContexts) { + // We must delete the test contexts in reverse order so that any child context is finished and + // deleted before a parent context. This relies on the fact that when we make a new context we + // append it to the end of fContexts array. + // TODO: Look into keeping a dependency dag for contexts and deletion order + for (int i = fContexts.count() - 1; i >= 0; --i) { + Context& context = fContexts[i]; SkScopeExit restore(nullptr); if (context.fTestContext) { restore = context.fTestContext->makeCurrentAndAutoRestore(); @@ -67,7 +72,12 @@ void GrContextFactory::destroyContexts() { } void GrContextFactory::abandonContexts() { - for (Context& context : fContexts) { + // We must abandon the test contexts in reverse order so that any child context is finished and + // abandoned before a parent context. This relies on the fact that when we make a new context we + // append it to the end of fContexts array. + // TODO: Look into keeping a dependency dag for contexts and deletion order + for (int i = fContexts.count() - 1; i >= 0; --i) { + Context& context = fContexts[i]; if (!context.fAbandoned) { if (context.fTestContext) { auto restore = context.fTestContext->makeCurrentAndAutoRestore(); @@ -82,7 +92,12 @@ void GrContextFactory::abandonContexts() { } void GrContextFactory::releaseResourcesAndAbandonContexts() { - for (Context& context : fContexts) { + // We must abandon the test contexts in reverse order so that any child context is finished and + // abandoned before a parent context. This relies on the fact that when we make a new context we + // append it to the end of fContexts array. + // TODO: Look into keeping a dependency dag for contexts and deletion order + for (int i = fContexts.count() - 1; i >= 0; --i) { + Context& context = fContexts[i]; SkScopeExit restore(nullptr); if (!context.fAbandoned) { if (context.fTestContext) { @@ -270,6 +285,8 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv } } + // We must always add new contexts by pushing to the back so that when we delete them we delete + // them in reverse order in which they were made. Context& context = fContexts.push_back(); context.fBackend = backend; context.fTestContext = testCtx.release(); |