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 | 10 |
11 #if SK_ANGLE | 11 #if SK_ANGLE |
12 #include "gl/angle/SkANGLEGLContext.h" | 12 #include "gl/angle/SkANGLEGLContext.h" |
13 #endif | 13 #endif |
14 #if SK_COMMAND_BUFFER | 14 #if SK_COMMAND_BUFFER |
15 #include "gl/command_buffer/SkCommandBufferGLContext.h" | 15 #include "gl/command_buffer/SkCommandBufferGLContext.h" |
16 #endif | 16 #endif |
17 #include "gl/debug/SkDebugGLContext.h" | 17 #include "gl/debug/SkDebugGLContext.h" |
18 #if SK_MESA | 18 #if SK_MESA |
19 #include "gl/mesa/SkMesaGLContext.h" | 19 #include "gl/mesa/SkMesaGLContext.h" |
20 #endif | 20 #endif |
21 #include "gl/SkGLContext.h" | 21 #include "gl/SkGLContext.h" |
22 #include "gl/SkNullGLContext.h" | 22 #include "gl/SkNullGLContext.h" |
23 #include "gl/GrGLGpu.h" | 23 #include "gl/GrGLGpu.h" |
24 #include "GrCaps.h" | 24 #include "GrCaps.h" |
25 | 25 |
26 GrContextFactory::ContextInfo* GrContextFactory::getContextInfo(GLContextType ty
pe, | 26 GrContextFactory::ContextInfo* GrContextFactory::getContextInfo(GLContextType ty
pe, |
27 GrGLStandard for
cedGpuAPI) { | 27 GrGLStandard for
cedGpuAPI, |
| 28 GLContextOptions
options) { |
28 for (int i = 0; i < fContexts.count(); ++i) { | 29 for (int i = 0; i < fContexts.count(); ++i) { |
29 if (forcedGpuAPI != kNone_GrGLStandard && | 30 if (fContexts[i]->fType == type && |
30 forcedGpuAPI != fContexts[i]->fGLContext->gl()->fStandard) | 31 fContexts[i]->fOptions == options && |
31 continue; | 32 (forcedGpuAPI == kNone_GrGLStandard || |
32 | 33 forcedGpuAPI == fContexts[i]->fGLContext->gl()->fStandard)) { |
33 if (fContexts[i]->fType == type) { | |
34 fContexts[i]->fGLContext->makeCurrent(); | 34 fContexts[i]->fGLContext->makeCurrent(); |
35 return fContexts[i]; | 35 return fContexts[i]; |
36 } | 36 } |
37 } | 37 } |
38 SkAutoTUnref<SkGLContext> glCtx; | 38 SkAutoTUnref<SkGLContext> glCtx; |
39 SkAutoTUnref<GrContext> grCtx; | 39 SkAutoTUnref<GrContext> grCtx; |
40 switch (type) { | 40 switch (type) { |
41 case kNVPR_GLContextType: // fallthru | |
42 case kNative_GLContextType: | 41 case kNative_GLContextType: |
43 glCtx.reset(SkCreatePlatformGLContext(forcedGpuAPI)); | 42 glCtx.reset(SkCreatePlatformGLContext(forcedGpuAPI)); |
44 break; | 43 break; |
45 #ifdef SK_ANGLE | 44 #ifdef SK_ANGLE |
46 case kANGLE_GLContextType: | 45 case kANGLE_GLContextType: |
47 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, false)); | 46 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, false)); |
48 break; | 47 break; |
49 case kANGLE_GL_GLContextType: | 48 case kANGLE_GL_GLContextType: |
50 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, true)); | 49 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, true)); |
51 break; | 50 break; |
(...skipping 16 matching lines...) Expand all Loading... |
68 break; | 67 break; |
69 } | 68 } |
70 if (nullptr == glCtx.get()) { | 69 if (nullptr == glCtx.get()) { |
71 return nullptr; | 70 return nullptr; |
72 } | 71 } |
73 | 72 |
74 SkASSERT(glCtx->isValid()); | 73 SkASSERT(glCtx->isValid()); |
75 | 74 |
76 // Block NVPR from non-NVPR types. | 75 // Block NVPR from non-NVPR types. |
77 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); | 76 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); |
78 if (kNVPR_GLContextType != type) { | 77 if (!(kEnableNVPR_GLContextOptions & options)) { |
79 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); | 78 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); |
80 if (!glInterface) { | 79 if (!glInterface) { |
81 return nullptr; | 80 return nullptr; |
82 } | 81 } |
83 } | 82 } |
84 | 83 |
85 glCtx->makeCurrent(); | 84 glCtx->makeCurrent(); |
86 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); | 85 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); |
87 #ifdef SK_VULKAN | 86 #ifdef SK_VULKAN |
88 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)); | 87 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)); |
89 #else | 88 #else |
90 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); | 89 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); |
91 #endif | 90 #endif |
92 if (!grCtx.get()) { | 91 if (!grCtx.get()) { |
93 return nullptr; | 92 return nullptr; |
94 } | 93 } |
95 if (kNVPR_GLContextType == type) { | 94 if (kEnableNVPR_GLContextOptions & options) { |
96 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { | 95 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { |
97 return nullptr; | 96 return nullptr; |
98 } | 97 } |
99 } | 98 } |
100 | 99 |
101 ContextInfo* ctx = fContexts.emplace_back(new ContextInfo); | 100 ContextInfo* ctx = fContexts.emplace_back(new ContextInfo); |
102 ctx->fGLContext = SkRef(glCtx.get()); | 101 ctx->fGLContext = SkRef(glCtx.get()); |
103 ctx->fGrContext = SkRef(grCtx.get()); | 102 ctx->fGrContext = SkRef(grCtx.get()); |
104 ctx->fType = type; | 103 ctx->fType = type; |
| 104 ctx->fOptions = options; |
105 return ctx; | 105 return ctx; |
106 } | 106 } |
OLD | NEW |