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 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_
FOR_MAC) | 77 GrContextFactory::ContextInfo GrContextFactory::getContextInfo(GLContextType typ
e, |
78 const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = | 78 GLContextOptions
options) { |
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) { | |
87 for (int i = 0; i < fContexts.count(); ++i) { | 79 for (int i = 0; i < fContexts.count(); ++i) { |
88 Context& context = fContexts[i]; | 80 Context& context = fContexts[i]; |
89 if (!context.fGLContext) { | 81 if (!context.fGLContext) { |
90 continue; | 82 continue; |
91 } | 83 } |
92 if (context.fType == type && | 84 if (context.fType == type && |
93 context.fOptions == options) { | 85 context.fOptions == options) { |
94 context.fGLContext->makeCurrent(); | 86 context.fGLContext->makeCurrent(); |
95 return ContextInfo(context.fGrContext, context.fGLContext); | 87 return ContextInfo(context.fGrContext, context.fGLContext); |
96 } | 88 } |
97 } | 89 } |
98 SkAutoTDelete<GLTestContext> glCtx; | 90 SkAutoTDelete<GLTestContext> glCtx; |
99 SkAutoTUnref<GrContext> grCtx; | 91 SkAutoTUnref<GrContext> grCtx; |
100 switch (type) { | 92 switch (type) { |
101 case kGL_ContextType: | 93 case kNative_GLContextType: |
| 94 glCtx.reset(CreatePlatformGLTestContext(kNone_GrGLStandard)); |
| 95 break; |
| 96 case kGL_GLContextType: |
102 glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); | 97 glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); |
103 break; | 98 break; |
104 case kGLES_ContextType: | 99 case kGLES_GLContextType: |
105 glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)); | 100 glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)); |
106 break; | 101 break; |
107 #if SK_ANGLE | 102 #if SK_ANGLE |
108 #ifdef SK_BUILD_FOR_WIN | 103 #ifdef SK_BUILD_FOR_WIN |
109 case kANGLE_ContextType: | 104 case kANGLE_GLContextType: |
110 glCtx.reset(CreateANGLEDirect3DGLTestContext()); | 105 glCtx.reset(CreateANGLEDirect3DGLTestContext()); |
111 break; | 106 break; |
112 #endif | 107 #endif |
113 case kANGLE_GL_ContextType: | 108 case kANGLE_GL_GLContextType: |
114 glCtx.reset(CreateANGLEOpenGLGLTestContext()); | 109 glCtx.reset(CreateANGLEOpenGLGLTestContext()); |
115 break; | 110 break; |
116 #endif | 111 #endif |
117 #if SK_COMMAND_BUFFER | 112 #if SK_COMMAND_BUFFER |
118 case kCommandBuffer_ContextType: | 113 case kCommandBuffer_GLContextType: |
119 glCtx.reset(CommandBufferGLTestContext::Create()); | 114 glCtx.reset(CommandBufferGLTestContext::Create()); |
120 break; | 115 break; |
121 #endif | 116 #endif |
122 #if SK_MESA | 117 #if SK_MESA |
123 case kMESA_ContextType: | 118 case kMESA_GLContextType: |
124 glCtx.reset(CreateMesaGLTestContext()); | 119 glCtx.reset(CreateMesaGLTestContext()); |
125 break; | 120 break; |
126 #endif | 121 #endif |
127 case kNullGL_ContextType: | 122 case kNull_GLContextType: |
128 glCtx.reset(CreateNullGLTestContext()); | 123 glCtx.reset(CreateNullGLTestContext()); |
129 break; | 124 break; |
130 case kDebugGL_ContextType: | 125 case kDebug_GLContextType: |
131 glCtx.reset(CreateDebugGLTestContext()); | 126 glCtx.reset(CreateDebugGLTestContext()); |
132 break; | 127 break; |
133 } | 128 } |
134 if (nullptr == glCtx.get()) { | 129 if (nullptr == glCtx.get()) { |
135 return ContextInfo(); | 130 return ContextInfo(); |
136 } | 131 } |
137 | 132 |
138 SkASSERT(glCtx->isValid()); | 133 SkASSERT(glCtx->isValid()); |
139 | 134 |
140 // Block NVPR from non-NVPR types. | 135 // Block NVPR from non-NVPR types. |
141 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); | 136 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); |
142 if (!(kEnableNVPR_ContextOptions & options)) { | 137 if (!(kEnableNVPR_GLContextOptions & options)) { |
143 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); | 138 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); |
144 if (!glInterface) { | 139 if (!glInterface) { |
145 return ContextInfo(); | 140 return ContextInfo(); |
146 } | 141 } |
147 } | 142 } |
148 | 143 |
149 glCtx->makeCurrent(); | 144 glCtx->makeCurrent(); |
150 #ifdef SK_VULKAN | 145 #ifdef SK_VULKAN |
151 if (kEnableNVPR_ContextOptions & options) { | 146 if (kEnableNVPR_GLContextOptions & options) { |
152 return ContextInfo(); | 147 return ContextInfo(); |
153 } else { | 148 } else { |
154 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(GrVkBackend
Context::Create()); | 149 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(GrVkBackend
Context::Create()); |
155 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)
); | 150 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)
); |
156 } | 151 } |
157 #else | 152 #else |
158 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); | 153 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); |
159 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); | 154 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); |
160 #endif | 155 #endif |
161 if (!grCtx.get()) { | 156 if (!grCtx.get()) { |
162 return ContextInfo(); | 157 return ContextInfo(); |
163 } | 158 } |
164 if (kEnableNVPR_ContextOptions & options) { | 159 if (kEnableNVPR_GLContextOptions & options) { |
165 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { | 160 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { |
166 return ContextInfo(); | 161 return ContextInfo(); |
167 } | 162 } |
168 } | 163 } |
169 if (kRequireSRGBSupport_ContextOptions & options) { | 164 if (kRequireSRGBSupport_GLContextOptions & options) { |
170 if (!grCtx->caps()->srgbSupport()) { | 165 if (!grCtx->caps()->srgbSupport()) { |
171 return ContextInfo(); | 166 return ContextInfo(); |
172 } | 167 } |
173 } | 168 } |
174 | 169 |
175 Context& context = fContexts.push_back(); | 170 Context& context = fContexts.push_back(); |
176 context.fGLContext = glCtx.release(); | 171 context.fGLContext = glCtx.release(); |
177 context.fGrContext = SkRef(grCtx.get()); | 172 context.fGrContext = SkRef(grCtx.get()); |
178 context.fType = type; | 173 context.fType = type; |
179 context.fOptions = options; | 174 context.fOptions = options; |
180 return ContextInfo(context.fGrContext, context.fGLContext); | 175 return ContextInfo(context.fGrContext, context.fGLContext); |
181 } | 176 } |
182 } // namespace sk_gpu_test | 177 } // namespace sk_gpu_test |
OLD | NEW |