| OLD | NEW |
| (Empty) |
| 1 | |
| 2 /* | |
| 3 * Copyright 2014 Google Inc. | |
| 4 * | |
| 5 * Use of this source code is governed by a BSD-style license that can be | |
| 6 * found in the LICENSE file. | |
| 7 */ | |
| 8 | |
| 9 #include "GrContextFactory.h" | |
| 10 | |
| 11 #if SK_ANGLE | |
| 12 #include "gl/angle/SkANGLEGLContext.h" | |
| 13 #endif | |
| 14 #if SK_COMMAND_BUFFER | |
| 15 #include "gl/command_buffer/SkCommandBufferGLContext.h" | |
| 16 #endif | |
| 17 #include "gl/debug/SkDebugGLContext.h" | |
| 18 #if SK_MESA | |
| 19 #include "gl/mesa/SkMesaGLContext.h" | |
| 20 #endif | |
| 21 #if SK_VULKAN | |
| 22 #include "vk/GrVkBackendContext.h" | |
| 23 #endif | |
| 24 #include "gl/SkGLContext.h" | |
| 25 #include "gl/SkNullGLContext.h" | |
| 26 #include "gl/GrGLGpu.h" | |
| 27 #include "GrCaps.h" | |
| 28 | |
| 29 GrContextFactory::GrContextFactory() { } | |
| 30 | |
| 31 GrContextFactory::GrContextFactory(const GrContextOptions& opts) | |
| 32 : fGlobalOptions(opts) { | |
| 33 } | |
| 34 | |
| 35 GrContextFactory::~GrContextFactory() { | |
| 36 this->destroyContexts(); | |
| 37 } | |
| 38 | |
| 39 void GrContextFactory::destroyContexts() { | |
| 40 for (Context& context : fContexts) { | |
| 41 if (context.fGLContext) { | |
| 42 context.fGLContext->makeCurrent(); | |
| 43 } | |
| 44 if (!context.fGrContext->unique()) { | |
| 45 context.fGrContext->abandonContext(); | |
| 46 } | |
| 47 context.fGrContext->unref(); | |
| 48 delete(context.fGLContext); | |
| 49 } | |
| 50 fContexts.reset(); | |
| 51 } | |
| 52 | |
| 53 void GrContextFactory::abandonContexts() { | |
| 54 for (Context& context : fContexts) { | |
| 55 if (context.fGLContext) { | |
| 56 context.fGLContext->makeCurrent(); | |
| 57 context.fGLContext->testAbandon(); | |
| 58 delete(context.fGLContext); | |
| 59 context.fGLContext = nullptr; | |
| 60 } | |
| 61 context.fGrContext->abandonContext(); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 GrContextFactory::ContextInfo GrContextFactory::getContextInfo(GLContextType typ
e, | |
| 66 GLContextOptions
options) { | |
| 67 for (int i = 0; i < fContexts.count(); ++i) { | |
| 68 Context& context = fContexts[i]; | |
| 69 if (!context.fGLContext) { | |
| 70 continue; | |
| 71 } | |
| 72 if (context.fType == type && | |
| 73 context.fOptions == options) { | |
| 74 context.fGLContext->makeCurrent(); | |
| 75 return ContextInfo(context.fGrContext, context.fGLContext); | |
| 76 } | |
| 77 } | |
| 78 SkAutoTDelete<SkGLContext> glCtx; | |
| 79 SkAutoTUnref<GrContext> grCtx; | |
| 80 switch (type) { | |
| 81 case kNative_GLContextType: | |
| 82 glCtx.reset(SkCreatePlatformGLContext(kNone_GrGLStandard)); | |
| 83 break; | |
| 84 case kGL_GLContextType: | |
| 85 glCtx.reset(SkCreatePlatformGLContext(kGL_GrGLStandard)); | |
| 86 break; | |
| 87 case kGLES_GLContextType: | |
| 88 glCtx.reset(SkCreatePlatformGLContext(kGLES_GrGLStandard)); | |
| 89 break; | |
| 90 #if SK_ANGLE | |
| 91 #ifdef SK_BUILD_FOR_WIN | |
| 92 case kANGLE_GLContextType: | |
| 93 glCtx.reset(SkANGLEGLContext::CreateDirectX()); | |
| 94 break; | |
| 95 #endif | |
| 96 case kANGLE_GL_GLContextType: | |
| 97 glCtx.reset(SkANGLEGLContext::CreateOpenGL()); | |
| 98 break; | |
| 99 #endif | |
| 100 #if SK_COMMAND_BUFFER | |
| 101 case kCommandBuffer_GLContextType: | |
| 102 glCtx.reset(SkCommandBufferGLContext::Create()); | |
| 103 break; | |
| 104 #endif | |
| 105 #if SK_MESA | |
| 106 case kMESA_GLContextType: | |
| 107 glCtx.reset(SkMesaGLContext::Create()); | |
| 108 break; | |
| 109 #endif | |
| 110 case kNull_GLContextType: | |
| 111 glCtx.reset(SkNullGLContext::Create()); | |
| 112 break; | |
| 113 case kDebug_GLContextType: | |
| 114 glCtx.reset(SkDebugGLContext::Create()); | |
| 115 break; | |
| 116 } | |
| 117 if (nullptr == glCtx.get()) { | |
| 118 return ContextInfo(); | |
| 119 } | |
| 120 | |
| 121 SkASSERT(glCtx->isValid()); | |
| 122 | |
| 123 // Block NVPR from non-NVPR types. | |
| 124 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); | |
| 125 if (!(kEnableNVPR_GLContextOptions & options)) { | |
| 126 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); | |
| 127 if (!glInterface) { | |
| 128 return ContextInfo(); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 glCtx->makeCurrent(); | |
| 133 #ifdef SK_VULKAN | |
| 134 if (kEnableNVPR_GLContextOptions & options) { | |
| 135 return ContextInfo(); | |
| 136 } else { | |
| 137 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(GrVkBackend
Context::Create()); | |
| 138 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)
); | |
| 139 } | |
| 140 #else | |
| 141 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); | |
| 142 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); | |
| 143 #endif | |
| 144 if (!grCtx.get()) { | |
| 145 return ContextInfo(); | |
| 146 } | |
| 147 if (kEnableNVPR_GLContextOptions & options) { | |
| 148 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { | |
| 149 return ContextInfo(); | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 Context& context = fContexts.push_back(); | |
| 154 context.fGLContext = glCtx.release(); | |
| 155 context.fGrContext = SkRef(grCtx.get()); | |
| 156 context.fType = type; | |
| 157 context.fOptions = options; | |
| 158 return ContextInfo(context.fGrContext, context.fGLContext); | |
| 159 } | |
| OLD | NEW |