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) { | |
29 for (int i = 0; i < fContexts.count(); ++i) { | 28 for (int i = 0; i < fContexts.count(); ++i) { |
30 if (fContexts[i]->fType == type && | 29 if (forcedGpuAPI != kNone_GrGLStandard && |
31 fContexts[i]->fOptions == options && | 30 forcedGpuAPI != fContexts[i]->fGLContext->gl()->fStandard) |
32 (forcedGpuAPI == kNone_GrGLStandard || | 31 continue; |
33 forcedGpuAPI == fContexts[i]->fGLContext->gl()->fStandard)) { | 32 |
| 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 |
41 case kNative_GLContextType: | 42 case kNative_GLContextType: |
42 glCtx.reset(SkCreatePlatformGLContext(forcedGpuAPI)); | 43 glCtx.reset(SkCreatePlatformGLContext(forcedGpuAPI)); |
43 break; | 44 break; |
44 #ifdef SK_ANGLE | 45 #ifdef SK_ANGLE |
45 case kANGLE_GLContextType: | 46 case kANGLE_GLContextType: |
46 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, false)); | 47 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, false)); |
47 break; | 48 break; |
48 case kANGLE_GL_GLContextType: | 49 case kANGLE_GL_GLContextType: |
49 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, true)); | 50 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, true)); |
50 break; | 51 break; |
(...skipping 16 matching lines...) Expand all Loading... |
67 break; | 68 break; |
68 } | 69 } |
69 if (nullptr == glCtx.get()) { | 70 if (nullptr == glCtx.get()) { |
70 return nullptr; | 71 return nullptr; |
71 } | 72 } |
72 | 73 |
73 SkASSERT(glCtx->isValid()); | 74 SkASSERT(glCtx->isValid()); |
74 | 75 |
75 // Block NVPR from non-NVPR types. | 76 // Block NVPR from non-NVPR types. |
76 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); | 77 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); |
77 if (!(kEnableNVPR_GLContextOptions & options)) { | 78 if (kNVPR_GLContextType != type) { |
78 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); | 79 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); |
79 if (!glInterface) { | 80 if (!glInterface) { |
80 return nullptr; | 81 return nullptr; |
81 } | 82 } |
82 } | 83 } |
83 | 84 |
84 glCtx->makeCurrent(); | 85 glCtx->makeCurrent(); |
85 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); | 86 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); |
86 #ifdef SK_VULKAN | 87 #ifdef SK_VULKAN |
87 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)); | 88 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)); |
88 #else | 89 #else |
89 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); | 90 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); |
90 #endif | 91 #endif |
91 if (!grCtx.get()) { | 92 if (!grCtx.get()) { |
92 return nullptr; | 93 return nullptr; |
93 } | 94 } |
94 if (kEnableNVPR_GLContextOptions & options) { | 95 if (kNVPR_GLContextType == type) { |
95 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { | 96 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { |
96 return nullptr; | 97 return nullptr; |
97 } | 98 } |
98 } | 99 } |
99 | 100 |
100 ContextInfo* ctx = fContexts.emplace_back(new ContextInfo); | 101 ContextInfo* ctx = fContexts.emplace_back(new ContextInfo); |
101 ctx->fGLContext = SkRef(glCtx.get()); | 102 ctx->fGLContext = SkRef(glCtx.get()); |
102 ctx->fGrContext = SkRef(grCtx.get()); | 103 ctx->fGrContext = SkRef(grCtx.get()); |
103 ctx->fType = type; | 104 ctx->fType = type; |
104 ctx->fOptions = options; | |
105 return ctx; | 105 return ctx; |
106 } | 106 } |
OLD | NEW |