| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrContextFactory.h" | 9 #include "GrContextFactory.h" |
| 10 #include "gl/GLTestContext.h" | 10 #include "gl/GLTestContext.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 for (Context& context : fContexts) { | 67 for (Context& context : fContexts) { |
| 68 if (context.fGLContext) { | 68 if (context.fGLContext) { |
| 69 context.fGLContext->makeCurrent(); | 69 context.fGLContext->makeCurrent(); |
| 70 context.fGrContext->releaseResourcesAndAbandonContext(); | 70 context.fGrContext->releaseResourcesAndAbandonContext(); |
| 71 delete(context.fGLContext); | 71 delete(context.fGLContext); |
| 72 context.fGLContext = nullptr; | 72 context.fGLContext = nullptr; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 GrContextFactory::ContextInfo GrContextFactory::getContextInfo(GLContextType typ
e, | 77 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_
FOR_MAC) |
| 78 GLContextOptions
options) { | 78 const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = |
| 79 GrContextFactory::kGL_ContextType; |
| 80 #else |
| 81 const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = |
| 82 GrContextFactory::kGLES_ContextType; |
| 83 #endif |
| 84 |
| 85 GrContextFactory::ContextInfo GrContextFactory::getContextInfo(ContextType type, |
| 86 ContextOptions op
tions) { |
| 79 for (int i = 0; i < fContexts.count(); ++i) { | 87 for (int i = 0; i < fContexts.count(); ++i) { |
| 80 Context& context = fContexts[i]; | 88 Context& context = fContexts[i]; |
| 81 if (!context.fGLContext) { | 89 if (!context.fGLContext) { |
| 82 continue; | 90 continue; |
| 83 } | 91 } |
| 84 if (context.fType == type && | 92 if (context.fType == type && |
| 85 context.fOptions == options) { | 93 context.fOptions == options) { |
| 86 context.fGLContext->makeCurrent(); | 94 context.fGLContext->makeCurrent(); |
| 87 return ContextInfo(context.fGrContext, context.fGLContext); | 95 return ContextInfo(context.fGrContext, context.fGLContext); |
| 88 } | 96 } |
| 89 } | 97 } |
| 90 SkAutoTDelete<GLTestContext> glCtx; | 98 SkAutoTDelete<GLTestContext> glCtx; |
| 91 SkAutoTUnref<GrContext> grCtx; | 99 SkAutoTUnref<GrContext> grCtx; |
| 92 switch (type) { | 100 switch (type) { |
| 93 case kNative_GLContextType: | 101 case kGL_ContextType: |
| 94 glCtx.reset(CreatePlatformGLTestContext(kNone_GrGLStandard)); | |
| 95 break; | |
| 96 case kGL_GLContextType: | |
| 97 glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); | 102 glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); |
| 98 break; | 103 break; |
| 99 case kGLES_GLContextType: | 104 case kGLES_ContextType: |
| 100 glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)); | 105 glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)); |
| 101 break; | 106 break; |
| 102 #if SK_ANGLE | 107 #if SK_ANGLE |
| 103 #ifdef SK_BUILD_FOR_WIN | 108 #ifdef SK_BUILD_FOR_WIN |
| 104 case kANGLE_GLContextType: | 109 case kANGLE_ContextType: |
| 105 glCtx.reset(CreateANGLEDirect3DGLTestContext()); | 110 glCtx.reset(CreateANGLEDirect3DGLTestContext()); |
| 106 break; | 111 break; |
| 107 #endif | 112 #endif |
| 108 case kANGLE_GL_GLContextType: | 113 case kANGLE_GL_ContextType: |
| 109 glCtx.reset(CreateANGLEOpenGLGLTestContext()); | 114 glCtx.reset(CreateANGLEOpenGLGLTestContext()); |
| 110 break; | 115 break; |
| 111 #endif | 116 #endif |
| 112 #if SK_COMMAND_BUFFER | 117 #if SK_COMMAND_BUFFER |
| 113 case kCommandBuffer_GLContextType: | 118 case kCommandBuffer_ContextType: |
| 114 glCtx.reset(CommandBufferGLTestContext::Create()); | 119 glCtx.reset(CommandBufferGLTestContext::Create()); |
| 115 break; | 120 break; |
| 116 #endif | 121 #endif |
| 117 #if SK_MESA | 122 #if SK_MESA |
| 118 case kMESA_GLContextType: | 123 case kMESA_ContextType: |
| 119 glCtx.reset(CreateMesaGLTestContext()); | 124 glCtx.reset(CreateMesaGLTestContext()); |
| 120 break; | 125 break; |
| 121 #endif | 126 #endif |
| 122 case kNull_GLContextType: | 127 case kNullGL_ContextType: |
| 123 glCtx.reset(CreateNullGLTestContext()); | 128 glCtx.reset(CreateNullGLTestContext()); |
| 124 break; | 129 break; |
| 125 case kDebug_GLContextType: | 130 case kDebugGL_ContextType: |
| 126 glCtx.reset(CreateDebugGLTestContext()); | 131 glCtx.reset(CreateDebugGLTestContext()); |
| 127 break; | 132 break; |
| 128 } | 133 } |
| 129 if (nullptr == glCtx.get()) { | 134 if (nullptr == glCtx.get()) { |
| 130 return ContextInfo(); | 135 return ContextInfo(); |
| 131 } | 136 } |
| 132 | 137 |
| 133 SkASSERT(glCtx->isValid()); | 138 SkASSERT(glCtx->isValid()); |
| 134 | 139 |
| 135 // Block NVPR from non-NVPR types. | 140 // Block NVPR from non-NVPR types. |
| 136 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); | 141 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); |
| 137 if (!(kEnableNVPR_GLContextOptions & options)) { | 142 if (!(kEnableNVPR_ContextOptions & options)) { |
| 138 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); | 143 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); |
| 139 if (!glInterface) { | 144 if (!glInterface) { |
| 140 return ContextInfo(); | 145 return ContextInfo(); |
| 141 } | 146 } |
| 142 } | 147 } |
| 143 | 148 |
| 144 glCtx->makeCurrent(); | 149 glCtx->makeCurrent(); |
| 145 #ifdef SK_VULKAN | 150 #ifdef SK_VULKAN |
| 146 if (kEnableNVPR_GLContextOptions & options) { | 151 if (kEnableNVPR_ContextOptions & options) { |
| 147 return ContextInfo(); | 152 return ContextInfo(); |
| 148 } else { | 153 } else { |
| 149 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(GrVkBackend
Context::Create()); | 154 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(GrVkBackend
Context::Create()); |
| 150 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)
); | 155 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)
); |
| 151 } | 156 } |
| 152 #else | 157 #else |
| 153 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); | 158 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); |
| 154 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); | 159 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); |
| 155 #endif | 160 #endif |
| 156 if (!grCtx.get()) { | 161 if (!grCtx.get()) { |
| 157 return ContextInfo(); | 162 return ContextInfo(); |
| 158 } | 163 } |
| 159 if (kEnableNVPR_GLContextOptions & options) { | 164 if (kEnableNVPR_ContextOptions & options) { |
| 160 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { | 165 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { |
| 161 return ContextInfo(); | 166 return ContextInfo(); |
| 162 } | 167 } |
| 163 } | 168 } |
| 164 if (kRequireSRGBSupport_GLContextOptions & options) { | 169 if (kRequireSRGBSupport_ContextOptions & options) { |
| 165 if (!grCtx->caps()->srgbSupport()) { | 170 if (!grCtx->caps()->srgbSupport()) { |
| 166 return ContextInfo(); | 171 return ContextInfo(); |
| 167 } | 172 } |
| 168 } | 173 } |
| 169 | 174 |
| 170 Context& context = fContexts.push_back(); | 175 Context& context = fContexts.push_back(); |
| 171 context.fGLContext = glCtx.release(); | 176 context.fGLContext = glCtx.release(); |
| 172 context.fGrContext = SkRef(grCtx.get()); | 177 context.fGrContext = SkRef(grCtx.get()); |
| 173 context.fType = type; | 178 context.fType = type; |
| 174 context.fOptions = options; | 179 context.fOptions = options; |
| 175 return ContextInfo(context.fGrContext, context.fGLContext); | 180 return ContextInfo(context.fGrContext, context.fGLContext); |
| 176 } | 181 } |
| 177 } // namespace sk_gpu_test | 182 } // namespace sk_gpu_test |
| OLD | NEW |