| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrContextFactory_DEFINED | 8 #ifndef GrContextFactory_DEFINED |
| 9 #define GrContextFactory_DEFINED | 9 #define GrContextFactory_DEFINED |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opt
s) { } | 94 explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opt
s) { } |
| 95 GrContextFactory() { } | 95 GrContextFactory() { } |
| 96 | 96 |
| 97 ~GrContextFactory() { this->destroyContexts(); } | 97 ~GrContextFactory() { this->destroyContexts(); } |
| 98 | 98 |
| 99 void destroyContexts() { | 99 void destroyContexts() { |
| 100 for (int i = 0; i < fContexts.count(); ++i) { | 100 for (int i = 0; i < fContexts.count(); ++i) { |
| 101 if (fContexts[i].fGLContext) { // could be abandoned. | 101 if (fContexts[i]->fGLContext) { // could be abandoned. |
| 102 fContexts[i].fGLContext->makeCurrent(); | 102 fContexts[i]->fGLContext->makeCurrent(); |
| 103 } | 103 } |
| 104 fContexts[i].fGrContext->unref(); | 104 fContexts[i]->fGrContext->unref(); |
| 105 if (fContexts[i].fGLContext) { | 105 SkSafeUnref(fContexts[i]->fGLContext); |
| 106 fContexts[i].fGLContext->unref(); | |
| 107 } | |
| 108 } | 106 } |
| 109 fContexts.reset(); | 107 fContexts.reset(); |
| 110 } | 108 } |
| 111 | 109 |
| 112 void abandonContexts() { | 110 void abandonContexts() { |
| 113 for (int i = 0; i < fContexts.count(); ++i) { | 111 for (int i = 0; i < fContexts.count(); ++i) { |
| 114 if (fContexts[i].fGLContext) { | 112 if (fContexts[i]->fGLContext) { |
| 115 fContexts[i].fGLContext->testAbandon(); | 113 fContexts[i]->fGLContext->testAbandon(); |
| 116 SkSafeSetNull(fContexts[i].fGLContext); | 114 SkSafeSetNull(fContexts[i]->fGLContext); |
| 117 } | 115 } |
| 118 fContexts[i].fGrContext->abandonContext(); | 116 fContexts[i]->fGrContext->abandonContext(); |
| 119 } | 117 } |
| 120 } | 118 } |
| 121 | 119 |
| 120 struct ContextInfo { |
| 121 GLContextType fType; |
| 122 SkGLContext* fGLContext; |
| 123 GrContext* fGrContext; |
| 124 }; |
| 125 /** |
| 126 * Get a context initialized with a type of GL context. It also makes the GL
context current. |
| 127 * Pointer is valid until destroyContexts() is called. |
| 128 */ |
| 129 ContextInfo* getContextInfo(GLContextType type, GrGLStandard forcedGpuAPI =
kNone_GrGLStandard); |
| 130 |
| 122 /** | 131 /** |
| 123 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. | 132 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. |
| 124 */ | 133 */ |
| 125 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta
ndard); | 134 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta
ndard) { |
| 126 | 135 if (ContextInfo* info = this->getContextInfo(type, forcedGpuAPI)) { |
| 136 return info->fGrContext; |
| 137 } |
| 138 return nullptr; |
| 139 } |
| 127 | 140 |
| 128 // Returns the GLContext of the given type. If it has not been created yet, | 141 // Returns the GLContext of the given type. If it has not been created yet, |
| 129 // nullptr is returned instead. | 142 // nullptr is returned instead. |
| 130 SkGLContext* getGLContext(GLContextType type) { | 143 SkGLContext* getGLContext(GLContextType type) { |
| 131 for (int i = 0; i < fContexts.count(); ++i) { | 144 for (int i = 0; i < fContexts.count(); ++i) { |
| 132 if (fContexts[i].fType == type) { | 145 if (fContexts[i]->fType == type) { |
| 133 return fContexts[i].fGLContext; | 146 return fContexts[i]->fGLContext; |
| 134 } | 147 } |
| 135 } | 148 } |
| 136 | 149 |
| 137 return nullptr; | 150 return nullptr; |
| 138 } | 151 } |
| 139 | 152 |
| 140 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } | 153 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } |
| 141 | 154 |
| 142 private: | 155 private: |
| 143 struct GPUContext { | 156 SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts; |
| 144 GLContextType fType; | |
| 145 SkGLContext* fGLContext; | |
| 146 GrContext* fGrContext; | |
| 147 }; | |
| 148 SkTArray<GPUContext, true> fContexts; | |
| 149 const GrContextOptions fGlobalOptions; | 157 const GrContextOptions fGlobalOptions; |
| 150 }; | 158 }; |
| 151 | 159 |
| 152 #endif | 160 #endif |
| OLD | NEW |