Index: src/gpu/GrContextFactory.h |
diff --git a/src/gpu/GrContextFactory.h b/src/gpu/GrContextFactory.h |
index 130c333dd0f066c0e9fce39fca1e680944c4f94b..6d174323180b2a3eb651445549b2ec54c0dfeb32 100644 |
--- a/src/gpu/GrContextFactory.h |
+++ b/src/gpu/GrContextFactory.h |
@@ -98,39 +98,52 @@ public: |
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(); |
- if (fContexts[i].fGLContext) { |
- fContexts[i].fGLContext->unref(); |
+ 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); |
+ if (fContexts[i]->fGLContext) { |
+ fContexts[i]->fGLContext->testAbandon(); |
+ SkSafeSetNull(fContexts[i]->fGLContext); |
} |
- fContexts[i].fGrContext->abandonContext(); |
+ fContexts[i]->fGrContext->abandonContext(); |
} |
} |
+ struct ContextInfo { |
+ GLContextType fType; |
+ SkGLContext* fGLContext; |
+ GrContext* fGrContext; |
+ }; |
/** |
- * Get a GrContext initialized with a type of GL context. It also makes the GL context current. |
+ * Get a context initialized with a type of GL context. It also makes the GL context current. |
+ * Pointer is valid until destroyContexts() is called. |
*/ |
- GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLStandard); |
+ ContextInfo* getContextInfo(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLStandard); |
+ /** |
+ * Get a GrContext initialized with a type of GL context. It also makes the GL context current. |
+ */ |
+ GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLStandard) { |
+ if (ContextInfo* info = this->getContextInfo(type, forcedGpuAPI)) { |
+ return info->fGrContext; |
+ } |
+ return nullptr; |
+ } |
// Returns the GLContext of the given type. If it has not been created yet, |
// nullptr is returned instead. |
SkGLContext* getGLContext(GLContextType type) { |
for (int i = 0; i < fContexts.count(); ++i) { |
- if (fContexts[i].fType == type) { |
- return fContexts[i].fGLContext; |
+ if (fContexts[i]->fType == type) { |
+ return fContexts[i]->fGLContext; |
} |
} |
@@ -140,12 +153,7 @@ public: |
const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } |
private: |
- struct GPUContext { |
- GLContextType fType; |
- SkGLContext* fGLContext; |
- GrContext* fGrContext; |
- }; |
- SkTArray<GPUContext, true> fContexts; |
+ SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts; |
const GrContextOptions fGlobalOptions; |
}; |