| 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 | 
| 11 #include "GrContext.h" | 11 #include "GrContext.h" | 
| 12 #include "GrContextOptions.h" | 12 #include "GrContextOptions.h" | 
| 13 | 13 | 
| 14 #include "gl/GLTestContext.h" | 14 #include "gl/GLTestContext.h" | 
| 15 #include "SkTArray.h" | 15 #include "SkTArray.h" | 
| 16 | 16 | 
|  | 17 struct GrVkBackendContext; | 
|  | 18 | 
| 17 namespace sk_gpu_test { | 19 namespace sk_gpu_test { | 
| 18 | 20 | 
| 19 struct ContextInfo { | 21 struct ContextInfo { | 
| 20     ContextInfo() | 22     ContextInfo() | 
| 21         : fGrContext(nullptr), fGLContext(nullptr) { } | 23         : fGrContext(nullptr), fGLContext(nullptr) { } | 
| 22     ContextInfo(GrContext* grContext, GLTestContext* glContext) | 24     ContextInfo(GrContext* grContext, GLTestContext* glContext) | 
| 23         : fGrContext(grContext), fGLContext(glContext) { } | 25         : fGrContext(grContext), fGLContext(glContext) { } | 
| 24     GrContext* fGrContext; | 26     GrContext* fGrContext; | 
| 25     GLTestContext* fGLContext; //! Valid until the factory destroys it via aband
     onContexts() or | 27     GLTestContext* fGLContext; //! Valid until the factory destroys it via aband
     onContexts() or | 
| 26                                //! destroyContexts(). | 28                                //! destroyContexts(). Null if context is not bas
     ed on OpenGL. | 
| 27 }; | 29 }; | 
| 28 | 30 | 
| 29 /** | 31 /** | 
| 30  * This is a simple class that is useful in test apps that use different | 32  * This is a simple class that is useful in test apps that use different | 
| 31  * GrContexts backed by different types of GL contexts. It manages creating the | 33  * GrContexts backed by different types of GL contexts. It manages creating the | 
| 32  * GL context and a GrContext that uses it. The GL/Gr contexts persist until the | 34  * GL context and a GrContext that uses it. The GL/Gr contexts persist until the | 
| 33  * factory is destroyed (though the caller can always grab a ref on the returned | 35  * factory is destroyed (though the caller can always grab a ref on the returned | 
| 34  * Gr and GL contexts to make them outlive the factory). | 36  * Gr and GL contexts to make them outlive the factory). | 
| 35  */ | 37  */ | 
| 36 class GrContextFactory : SkNoncopyable { | 38 class GrContextFactory : SkNoncopyable { | 
| 37 public: | 39 public: | 
|  | 40     // The availability of context types is subject to platform and build config
     uration | 
|  | 41     // restrictions. | 
| 38     enum ContextType { | 42     enum ContextType { | 
| 39         kGL_ContextType,            //! OpenGL context. | 43         kGL_ContextType,            //! OpenGL context. | 
| 40         kGLES_ContextType,          //! OpenGL ES context. | 44         kGLES_ContextType,          //! OpenGL ES context. | 
| 41 #if SK_ANGLE |  | 
| 42 #ifdef SK_BUILD_FOR_WIN |  | 
| 43         kANGLE_ContextType,         //! ANGLE on DirectX OpenGL ES context. | 45         kANGLE_ContextType,         //! ANGLE on DirectX OpenGL ES context. | 
| 44 #endif |  | 
| 45         kANGLE_GL_ContextType,      //! ANGLE on OpenGL OpenGL ES context. | 46         kANGLE_GL_ContextType,      //! ANGLE on OpenGL OpenGL ES context. | 
| 46 #endif |  | 
| 47 #if SK_COMMAND_BUFFER |  | 
| 48         kCommandBuffer_ContextType, //! Chromium command buffer OpenGL ES contex
     t. | 47         kCommandBuffer_ContextType, //! Chromium command buffer OpenGL ES contex
     t. | 
| 49 #endif |  | 
| 50 #if SK_MESA |  | 
| 51         kMESA_ContextType,          //! MESA OpenGL context | 48         kMESA_ContextType,          //! MESA OpenGL context | 
| 52 #endif |  | 
| 53         kNullGL_ContextType,        //! Non-rendering OpenGL mock context. | 49         kNullGL_ContextType,        //! Non-rendering OpenGL mock context. | 
| 54         kDebugGL_ContextType,       //! Non-rendering, state verifying OpenGL co
     ntext. | 50         kDebugGL_ContextType,       //! Non-rendering, state verifying OpenGL co
     ntext. | 
| 55         kLastContextType = kDebugGL_ContextType | 51         kVulkan_ContextType,        //! Vulkan | 
|  | 52         kLastContextType = kVulkan_ContextType | 
| 56     }; | 53     }; | 
| 57 | 54 | 
| 58     //! OpenGL or OpenGL ES context depending on the platform. To be removed. | 55     //! OpenGL or OpenGL ES context depending on the platform. To be removed. | 
| 59     static const ContextType kNativeGL_ContextType; | 56     static const ContextType kNativeGL_ContextType; | 
| 60 | 57 | 
| 61     static const int kContextTypeCnt = kLastContextType + 1; | 58     static const int kContextTypeCnt = kLastContextType + 1; | 
| 62 | 59 | 
| 63     /** | 60     /** | 
| 64      * Options for GL context creation. For historical and testing reasons the o
     ptions will default | 61      * Options for GL context creation. For historical and testing reasons the o
     ptions will default | 
| 65      * to not using GL_NV_path_rendering extension  even when the driver support
     s it. | 62      * to not using GL_NV_path_rendering extension  even when the driver support
     s it. | 
| 66      */ | 63      */ | 
| 67     enum ContextOptions { | 64     enum ContextOptions { | 
| 68         kNone_ContextOptions                = 0x0, | 65         kNone_ContextOptions                = 0x0, | 
| 69         kEnableNVPR_ContextOptions          = 0x1, | 66         kEnableNVPR_ContextOptions          = 0x1, | 
| 70         kRequireSRGBSupport_ContextOptions  = 0x2, | 67         kRequireSRGBSupport_ContextOptions  = 0x2, | 
| 71     }; | 68     }; | 
| 72 | 69 | 
| 73     static bool IsRenderingContext(ContextType type) { | 70     static bool IsRenderingContext(ContextType type) { | 
| 74         switch (type) { | 71         switch (type) { | 
| 75             case kNullGL_ContextType: | 72             case kNullGL_ContextType: | 
| 76             case kDebugGL_ContextType: | 73             case kDebugGL_ContextType: | 
| 77                 return false; | 74                 return false; | 
| 78             default: | 75             default: | 
| 79                 return true; | 76                 return true; | 
| 80         } | 77         } | 
| 81     } | 78     } | 
| 82 | 79 | 
| 83     static GrBackend ContextTypeBackend(ContextType type) { | 80     static GrBackend ContextTypeBackend(ContextType type) { | 
| 84         // Currently all the context types use the GL backed | 81         switch (type) { | 
| 85         return kOpenGL_GrBackend; | 82             case kVulkan_ContextType: | 
|  | 83                 return kVulkan_GrBackend; | 
|  | 84             default: | 
|  | 85                 return kOpenGL_GrBackend; | 
|  | 86         } | 
| 86     } | 87     } | 
| 87 | 88 | 
| 88     static const char* ContextTypeName(ContextType type) { | 89     static const char* ContextTypeName(ContextType type) { | 
| 89         switch (type) { | 90         switch (type) { | 
| 90             case kGL_ContextType: | 91             case kGL_ContextType: | 
| 91                 return "gl"; | 92                 return "gl"; | 
| 92             case kGLES_ContextType: | 93             case kGLES_ContextType: | 
| 93                 return "gles"; | 94                 return "gles"; | 
| 94 #if SK_ANGLE |  | 
| 95 #ifdef SK_BUILD_FOR_WIN |  | 
| 96             case kANGLE_ContextType: | 95             case kANGLE_ContextType: | 
| 97                 return "angle"; | 96                 return "angle"; | 
| 98 #endif |  | 
| 99             case kANGLE_GL_ContextType: | 97             case kANGLE_GL_ContextType: | 
| 100                 return "angle-gl"; | 98                 return "angle-gl"; | 
| 101 #endif |  | 
| 102 #if SK_COMMAND_BUFFER |  | 
| 103             case kCommandBuffer_ContextType: | 99             case kCommandBuffer_ContextType: | 
| 104                 return "commandbuffer"; | 100                 return "commandbuffer"; | 
| 105 #endif |  | 
| 106 #if SK_MESA |  | 
| 107             case kMESA_ContextType: | 101             case kMESA_ContextType: | 
| 108                 return "mesa"; | 102                 return "mesa"; | 
| 109 #endif |  | 
| 110             case kNullGL_ContextType: | 103             case kNullGL_ContextType: | 
| 111                 return "null"; | 104                 return "nullgl"; | 
| 112             case kDebugGL_ContextType: | 105             case kDebugGL_ContextType: | 
| 113                 return "debug"; | 106                 return "debuggl"; | 
| 114             default: | 107             case kVulkan_ContextType: | 
| 115                 SkFAIL("Unknown GL Context type."); | 108                 return "vulkan"; | 
| 116         } | 109         } | 
| 117     } | 110     } | 
| 118 | 111 | 
| 119     explicit GrContextFactory(const GrContextOptions& opts); | 112     explicit GrContextFactory(const GrContextOptions& opts); | 
| 120     GrContextFactory(); | 113     GrContextFactory(); | 
| 121 | 114 | 
| 122     ~GrContextFactory(); | 115     ~GrContextFactory(); | 
| 123 | 116 | 
| 124     void destroyContexts(); | 117     void destroyContexts(); | 
| 125     void abandonContexts(); | 118     void abandonContexts(); | 
| 126     void releaseResourcesAndAbandonContexts(); | 119     void releaseResourcesAndAbandonContexts(); | 
| 127 | 120 | 
| 128     /** | 121     /** | 
| 129      * Get a context initialized with a type of GL context. It also makes the GL
      context current. | 122      * Get a context initialized with a type of GL context. It also makes the GL
      context current. | 
| 130      */ | 123      */ | 
| 131     ContextInfo getContextInfo(ContextType type, | 124     ContextInfo getContextInfo(ContextType type, | 
| 132                                ContextOptions options = kNone_ContextOptions); | 125                                ContextOptions options = kNone_ContextOptions); | 
| 133     /** | 126     /** | 
| 134      * Get a GrContext initialized with a type of GL context. It also makes the 
     GL context current. | 127      * Get a GrContext initialized with a type of GL context. It also makes the 
     GL context current. | 
| 135      */ | 128      */ | 
| 136     GrContext* get(ContextType type, ContextOptions options = kNone_ContextOptio
     ns) { | 129     GrContext* get(ContextType type, ContextOptions options = kNone_ContextOptio
     ns) { | 
| 137         return this->getContextInfo(type, options).fGrContext; | 130         return this->getContextInfo(type, options).fGrContext; | 
| 138     } | 131     } | 
| 139     const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } | 132     const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } | 
| 140 | 133 | 
| 141 private: | 134 private: | 
| 142     struct Context { | 135     struct Context { | 
| 143         ContextType         fType; | 136         ContextType     fType; | 
| 144         ContextOptions      fOptions; | 137         ContextOptions  fOptions; | 
| 145         GLTestContext*      fGLContext; //  null if non-GL | 138         GLTestContext*  fGLContext; //  null if non-GL | 
| 146         GrContext*          fGrContext; | 139         GrContext*      fGrContext; | 
|  | 140         bool            fAbandoned; | 
| 147     }; | 141     }; | 
| 148     SkTArray<Context, true> fContexts; | 142     SkTArray<Context, true>         fContexts; | 
| 149     const GrContextOptions  fGlobalOptions; | 143     SkAutoTDelete<GLTestContext>    fSentinelGLContext; | 
|  | 144     const GrContextOptions          fGlobalOptions; | 
| 150 }; | 145 }; | 
| 151 }  // namespace sk_gpu_test | 146 }  // namespace sk_gpu_test | 
| 152 #endif | 147 #endif | 
| OLD | NEW | 
|---|