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

Unified Diff: src/gpu/GrContextFactory.h

Issue 1511773005: Make SkGLContext lifetime more well-defined (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix the test 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 1df99d6ff1f88d1e516ac024c302eafcc25b9159..7afa3108c69d8984e0d63cd76350570dc764d4be 100644
--- a/src/gpu/GrContextFactory.h
+++ b/src/gpu/GrContextFactory.h
@@ -98,59 +98,47 @@ public:
}
}
- explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opts) { }
- GrContextFactory() { }
+ explicit GrContextFactory(const GrContextOptions& opts);
+ GrContextFactory();
- ~GrContextFactory() { this->destroyContexts(); }
+ ~GrContextFactory();
- 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();
- }
- }
+ void destroyContexts();
+ void abandonContexts();
struct ContextInfo {
- GLContextType fType;
- GLContextOptions fOptions;
- SkGLContext* fGLContext;
- GrContext* fGrContext;
+ 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().
};
+
/**
* 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) {
- if (ContextInfo* info = this->getContextInfo(type, options)) {
- return info->fGrContext;
- }
- return nullptr;
+ GrContext* get(GLContextType type,
+ GLContextOptions options = kNone_GLContextOptions) {
+ return this->getContextInfo(type, options).fGrContext;
}
const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
private:
- SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts;
- const GrContextOptions fGlobalOptions;
+ struct Context {
+ GLContextType fType;
+ GLContextOptions fOptions;
+ SkGLContext* fGLContext;
+ GrContext* fGrContext;
+ };
+ SkTArray<Context, 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