| 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 #endif |   91 #endif | 
|   92             case kNull_GLContextType: |   92             case kNull_GLContextType: | 
|   93                 return "null"; |   93                 return "null"; | 
|   94             case kDebug_GLContextType: |   94             case kDebug_GLContextType: | 
|   95                 return "debug"; |   95                 return "debug"; | 
|   96             default: |   96             default: | 
|   97                 SkFAIL("Unknown GL Context type."); |   97                 SkFAIL("Unknown GL Context type."); | 
|   98         } |   98         } | 
|   99     } |   99     } | 
|  100  |  100  | 
|  101     explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opt
     s) { } |  101     explicit GrContextFactory(const GrContextOptions& opts); | 
|  102     GrContextFactory() { } |  102     GrContextFactory(); | 
|  103  |  103  | 
|  104     ~GrContextFactory() { this->destroyContexts(); } |  104     ~GrContextFactory(); | 
|  105  |  105  | 
|  106     void destroyContexts() { |  106     void destroyContexts(); | 
|  107         for (int i = 0; i < fContexts.count(); ++i) { |  107     void abandonContexts(); | 
|  108             if (fContexts[i]->fGLContext) {  //  could be abandoned. |  | 
|  109                 fContexts[i]->fGLContext->makeCurrent(); |  | 
|  110             } |  | 
|  111             fContexts[i]->fGrContext->unref(); |  | 
|  112             SkSafeUnref(fContexts[i]->fGLContext); |  | 
|  113         } |  | 
|  114         fContexts.reset(); |  | 
|  115     } |  | 
|  116  |  | 
|  117     void abandonContexts() { |  | 
|  118         for (int i = 0; i < fContexts.count(); ++i) { |  | 
|  119             if (fContexts[i]->fGLContext) { |  | 
|  120                 fContexts[i]->fGLContext->testAbandon(); |  | 
|  121                 SkSafeSetNull(fContexts[i]->fGLContext); |  | 
|  122             } |  | 
|  123             fContexts[i]->fGrContext->abandonContext(); |  | 
|  124         } |  | 
|  125     } |  | 
|  126  |  108  | 
|  127     struct ContextInfo { |  109     struct ContextInfo { | 
|  128         GLContextType             fType; |  110         ContextInfo() | 
|  129         GLContextOptions          fOptions; |  111             : fGrContext(nullptr), fGLContext(nullptr) { } | 
|  130         SkGLContext*              fGLContext; |  112         ContextInfo(GrContext* grContext, SkGLContext* glContext) | 
|  131         GrContext*                fGrContext; |  113             : fGrContext(grContext), fGLContext(glContext) { } | 
 |  114         GrContext* fGrContext; | 
 |  115         SkGLContext* fGLContext; //! Valid until the factory destroys it via aba
     ndonContexts() or | 
 |  116                                  //! destroyContexts(). | 
|  132     }; |  117     }; | 
 |  118  | 
|  133     /** |  119     /** | 
|  134      * Get a context initialized with a type of GL context. It also makes the GL
      context current. |  120      * Get a context initialized with a type of GL context. It also makes the GL
      context current. | 
|  135      * Pointer is valid until destroyContexts() is called. |  | 
|  136      */ |  121      */ | 
|  137     ContextInfo* getContextInfo(GLContextType type, |  122     ContextInfo getContextInfo(GLContextType type, | 
|  138                                 GLContextOptions options = kNone_GLContextOption
     s); |  123                                GLContextOptions options = kNone_GLContextOptions
     ); | 
|  139  |  | 
|  140     /** |  124     /** | 
|  141      * Get a GrContext initialized with a type of GL context. It also makes the 
     GL context current. |  125      * Get a GrContext initialized with a type of GL context. It also makes the 
     GL context current. | 
|  142      */ |  126      */ | 
|  143     GrContext* get(GLContextType type, GLContextOptions options = kNone_GLContex
     tOptions) { |  127     GrContext* get(GLContextType type, | 
|  144         if (ContextInfo* info = this->getContextInfo(type, options)) { |  128                    GLContextOptions options = kNone_GLContextOptions) { | 
|  145             return info->fGrContext; |  129         return this->getContextInfo(type, options).fGrContext; | 
|  146         } |  | 
|  147         return nullptr; |  | 
|  148     } |  130     } | 
|  149     const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } |  131     const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } | 
|  150  |  132  | 
|  151 private: |  133 private: | 
|  152     SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts; |  134     struct Context { | 
|  153     const GrContextOptions        fGlobalOptions; |  135         GLContextType fType; | 
 |  136         GLContextOptions fOptions; | 
 |  137         SkGLContext*  fGLContext; | 
 |  138         GrContext*    fGrContext; | 
 |  139     }; | 
 |  140     SkTArray<Context, true> fContexts; | 
 |  141     const GrContextOptions  fGlobalOptions; | 
|  154 }; |  142 }; | 
|  155  |  143  | 
|  156 #endif |  144 #endif | 
| OLD | NEW |