Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Unified Diff: src/gpu/GrContextFactory.h

Issue 1555053003: Revert of Make SkGLContext lifetime more well-defined (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/gpu/gl/SkGLContext.h ('k') | src/gpu/GrContextFactory.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrContextFactory.h
diff --git a/src/gpu/GrContextFactory.h b/src/gpu/GrContextFactory.h
index 7afa3108c69d8984e0d63cd76350570dc764d4be..1df99d6ff1f88d1e516ac024c302eafcc25b9159 100644
--- a/src/gpu/GrContextFactory.h
+++ b/src/gpu/GrContextFactory.h
@@ -98,47 +98,59 @@
}
}
- explicit GrContextFactory(const GrContextOptions& opts);
- GrContextFactory();
+ explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opts) { }
+ GrContextFactory() { }
- ~GrContextFactory();
+ ~GrContextFactory() { this->destroyContexts(); }
- void destroyContexts();
- void abandonContexts();
+ void destroyContexts() {
+ for (int i = 0; i < fContexts.count(); ++i) {
+ if (fContexts[i]->fGLContext) { // could be abandoned.
+ fContexts[i]->fGLContext->makeCurrent();
+ }
+ fContexts[i]->fGrContext->unref();
+ SkSafeUnref(fContexts[i]->fGLContext);
+ }
+ fContexts.reset();
+ }
+
+ void abandonContexts() {
+ for (int i = 0; i < fContexts.count(); ++i) {
+ if (fContexts[i]->fGLContext) {
+ fContexts[i]->fGLContext->testAbandon();
+ SkSafeSetNull(fContexts[i]->fGLContext);
+ }
+ fContexts[i]->fGrContext->abandonContext();
+ }
+ }
struct ContextInfo {
- ContextInfo()
- : fGrContext(nullptr), fGLContext(nullptr) { }
- ContextInfo(GrContext* grContext, SkGLContext* glContext)
- : fGrContext(grContext), fGLContext(glContext) { }
- GrContext* fGrContext;
- SkGLContext* fGLContext; //! Valid until the factory destroys it via abandonContexts() or
- //! destroyContexts().
+ GLContextType fType;
+ GLContextOptions fOptions;
+ SkGLContext* fGLContext;
+ GrContext* fGrContext;
};
-
/**
* Get a context initialized with a type of GL context. It also makes the GL context current.
+ * Pointer is valid until destroyContexts() is called.
*/
- ContextInfo getContextInfo(GLContextType type,
- GLContextOptions options = kNone_GLContextOptions);
+ ContextInfo* getContextInfo(GLContextType type,
+ GLContextOptions options = kNone_GLContextOptions);
+
/**
* Get a GrContext initialized with a type of GL context. It also makes the GL context current.
*/
- GrContext* get(GLContextType type,
- GLContextOptions options = kNone_GLContextOptions) {
- return this->getContextInfo(type, options).fGrContext;
+ GrContext* get(GLContextType type, GLContextOptions options = kNone_GLContextOptions) {
+ if (ContextInfo* info = this->getContextInfo(type, options)) {
+ return info->fGrContext;
+ }
+ return nullptr;
}
const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
private:
- struct Context {
- GLContextType fType;
- GLContextOptions fOptions;
- SkGLContext* fGLContext;
- GrContext* fGrContext;
- };
- SkTArray<Context, true> fContexts;
- const GrContextOptions fGlobalOptions;
+ SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts;
+ const GrContextOptions fGlobalOptions;
};
#endif
« no previous file with comments | « include/gpu/gl/SkGLContext.h ('k') | src/gpu/GrContextFactory.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698