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 | |
39 SkAutoTUnref<SkGLContext> glCtx; | 38 SkAutoTUnref<SkGLContext> glCtx; |
40 SkAutoTUnref<GrContext> grCtx; | 39 SkAutoTUnref<GrContext> grCtx; |
41 switch (type) { | 40 switch (type) { |
| 41 case kNVPR_GLContextType: // fallthru |
42 case kNative_GLContextType: | 42 case kNative_GLContextType: |
43 glCtx.reset(SkCreatePlatformGLContext(forcedGpuAPI)); | 43 glCtx.reset(SkCreatePlatformGLContext(forcedGpuAPI)); |
44 break; | 44 break; |
45 #ifdef SK_ANGLE | 45 #ifdef SK_ANGLE |
46 case kANGLE_GLContextType: | 46 case kANGLE_GLContextType: |
47 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, false)); | 47 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, false)); |
48 break; | 48 break; |
49 case kANGLE_GL_GLContextType: | 49 case kANGLE_GL_GLContextType: |
50 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, true)); | 50 glCtx.reset(SkANGLEGLContext::Create(forcedGpuAPI, true)); |
51 break; | 51 break; |
(...skipping 16 matching lines...) Expand all Loading... |
68 break; | 68 break; |
69 } | 69 } |
70 if (nullptr == glCtx.get()) { | 70 if (nullptr == glCtx.get()) { |
71 return nullptr; | 71 return nullptr; |
72 } | 72 } |
73 | 73 |
74 SkASSERT(glCtx->isValid()); | 74 SkASSERT(glCtx->isValid()); |
75 | 75 |
76 // Block NVPR from non-NVPR types. | 76 // Block NVPR from non-NVPR types. |
77 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); | 77 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); |
78 if (!(kEnableNVPR_GLContextOptions & options)) { | 78 if (kNVPR_GLContextType != type) { |
79 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); | 79 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); |
80 if (!glInterface) { | 80 if (!glInterface) { |
81 return nullptr; | 81 return nullptr; |
82 } | 82 } |
83 } else { | 83 } else { |
84 if (!glInterface->hasExtension("GL_NV_path_rendering")) { | 84 if (!glInterface->hasExtension("GL_NV_path_rendering")) { |
85 return nullptr; | 85 return nullptr; |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 glCtx->makeCurrent(); | 89 glCtx->makeCurrent(); |
90 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); | 90 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); |
91 #ifdef SK_VULKAN | 91 #ifdef SK_VULKAN |
92 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)); | 92 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)); |
93 #else | 93 #else |
94 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); | 94 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); |
95 #endif | 95 #endif |
96 if (!grCtx.get()) { | 96 if (!grCtx.get()) { |
97 return nullptr; | 97 return nullptr; |
98 } | 98 } |
99 // Warn if path rendering support is not available for the NVPR type. | 99 // Warn if path rendering support is not available for the NVPR type. |
100 if (kEnableNVPR_GLContextOptions & options) { | 100 if (kNVPR_GLContextType == type) { |
101 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { | 101 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { |
102 GrGpu* gpu = grCtx->getGpu(); | 102 GrGpu* gpu = grCtx->getGpu(); |
103 const GrGLContext* ctx = gpu->glContextForTesting(); | 103 const GrGLContext* ctx = gpu->glContextForTesting(); |
104 if (ctx) { | 104 if (ctx) { |
105 const GrGLubyte* verUByte; | 105 const GrGLubyte* verUByte; |
106 GR_GL_CALL_RET(ctx->interface(), verUByte, GetString(GR_GL_VERSI
ON)); | 106 GR_GL_CALL_RET(ctx->interface(), verUByte, GetString(GR_GL_VERSI
ON)); |
107 const char* ver = reinterpret_cast<const char*>(verUByte); | 107 const char* ver = reinterpret_cast<const char*>(verUByte); |
108 SkDebugf("\nWARNING: nvprmsaa config requested, but driver path
rendering " | 108 SkDebugf("\nWARNING: nvprmsaa config requested, but driver path
rendering " |
109 "support not available. Maybe update the driver? Your d
river version " | 109 "support not available. Maybe update the driver? Your d
river version " |
110 "string: \"%s\"\n", ver); | 110 "string: \"%s\"\n", ver); |
111 } else { | 111 } else { |
112 SkDebugf("\nWARNING: nvprmsaa config requested, but driver path
rendering " | 112 SkDebugf("\nWARNING: nvprmsaa config requested, but driver path
rendering " |
113 "support not available.\n"); | 113 "support not available.\n"); |
114 } | 114 } |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 ContextInfo* ctx = fContexts.emplace_back(new ContextInfo); | 118 ContextInfo* ctx = fContexts.emplace_back(new ContextInfo); |
119 ctx->fGLContext = SkRef(glCtx.get()); | 119 ctx->fGLContext = SkRef(glCtx.get()); |
120 ctx->fGrContext = SkRef(grCtx.get()); | 120 ctx->fGrContext = SkRef(grCtx.get()); |
121 ctx->fType = type; | 121 ctx->fType = type; |
122 ctx->fOptions = options; | |
123 return ctx; | 122 return ctx; |
124 } | 123 } |
OLD | NEW |