OLD | NEW |
| 1 |
1 /* | 2 /* |
2 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
3 * | 4 * |
4 * 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 |
5 * found in the LICENSE file. | 6 * found in the LICENSE file. |
6 */ | 7 */ |
7 | 8 |
8 #include "GrContextFactory.h" | 9 #include "GrContextFactory.h" |
| 10 #include "gl/GLContext.h" |
9 | 11 |
10 #if SK_ANGLE | 12 #if SK_ANGLE |
11 #include "gl/angle/SkANGLEGLContext.h" | 13 #include "gl/angle/GLContext_angle.h" |
12 #endif | 14 #endif |
13 #if SK_COMMAND_BUFFER | 15 #if SK_COMMAND_BUFFER |
14 #include "gl/command_buffer/SkCommandBufferGLContext.h" | 16 #include "gl/command_buffer/GLContext_command_buffer.h" |
15 #endif | 17 #endif |
16 #include "gl/debug/SkDebugGLContext.h" | 18 #include "gl/debug/DebugGLContext.h" |
17 #if SK_MESA | 19 #if SK_MESA |
18 #include "gl/mesa/SkMesaGLContext.h" | 20 #include "gl/mesa/GLContext_mesa.h" |
19 #endif | 21 #endif |
20 #if SK_VULKAN | 22 #include "gl/null/NullGLContext.h" |
21 #include "vk/GrVkBackendContext.h" | |
22 #endif | |
23 #include "gl/SkGLContext.h" | |
24 #include "gl/SkNullGLContext.h" | |
25 #include "gl/GrGLGpu.h" | 23 #include "gl/GrGLGpu.h" |
26 #include "GrCaps.h" | 24 #include "GrCaps.h" |
27 | 25 |
| 26 namespace sk_gpu_test { |
28 GrContextFactory::GrContextFactory() { } | 27 GrContextFactory::GrContextFactory() { } |
29 | 28 |
30 GrContextFactory::GrContextFactory(const GrContextOptions& opts) | 29 GrContextFactory::GrContextFactory(const GrContextOptions& opts) |
31 : fGlobalOptions(opts) { | 30 : fGlobalOptions(opts) { |
32 } | 31 } |
33 | 32 |
34 GrContextFactory::~GrContextFactory() { | 33 GrContextFactory::~GrContextFactory() { |
35 this->destroyContexts(); | 34 this->destroyContexts(); |
36 } | 35 } |
37 | 36 |
(...skipping 29 matching lines...) Expand all Loading... |
67 Context& context = fContexts[i]; | 66 Context& context = fContexts[i]; |
68 if (!context.fGLContext) { | 67 if (!context.fGLContext) { |
69 continue; | 68 continue; |
70 } | 69 } |
71 if (context.fType == type && | 70 if (context.fType == type && |
72 context.fOptions == options) { | 71 context.fOptions == options) { |
73 context.fGLContext->makeCurrent(); | 72 context.fGLContext->makeCurrent(); |
74 return ContextInfo(context.fGrContext, context.fGLContext); | 73 return ContextInfo(context.fGrContext, context.fGLContext); |
75 } | 74 } |
76 } | 75 } |
77 SkAutoTDelete<SkGLContext> glCtx; | 76 SkAutoTDelete<GLContext> glCtx; |
78 SkAutoTUnref<GrContext> grCtx; | 77 SkAutoTUnref<GrContext> grCtx; |
79 switch (type) { | 78 switch (type) { |
80 case kNative_GLContextType: | 79 case kNative_GLContextType: |
81 glCtx.reset(SkCreatePlatformGLContext(kNone_GrGLStandard)); | 80 glCtx.reset(CreatePlatformGLContext(kNone_GrGLStandard)); |
82 break; | 81 break; |
83 case kGL_GLContextType: | 82 case kGL_GLContextType: |
84 glCtx.reset(SkCreatePlatformGLContext(kGL_GrGLStandard)); | 83 glCtx.reset(CreatePlatformGLContext(kGL_GrGLStandard)); |
85 break; | 84 break; |
86 case kGLES_GLContextType: | 85 case kGLES_GLContextType: |
87 glCtx.reset(SkCreatePlatformGLContext(kGLES_GrGLStandard)); | 86 glCtx.reset(CreatePlatformGLContext(kGLES_GrGLStandard)); |
88 break; | 87 break; |
89 #if SK_ANGLE | 88 #if SK_ANGLE |
90 #ifdef SK_BUILD_FOR_WIN | 89 #ifdef SK_BUILD_FOR_WIN |
91 case kANGLE_GLContextType: | 90 case kANGLE_GLContextType: |
92 glCtx.reset(SkANGLEGLContext::CreateDirectX()); | 91 glCtx.reset(CreateANGLEDirect3DGLContext()); |
93 break; | 92 break; |
94 #endif | 93 #endif |
95 case kANGLE_GL_GLContextType: | 94 case kANGLE_GL_GLContextType: |
96 glCtx.reset(SkANGLEGLContext::CreateOpenGL()); | 95 glCtx.reset(CreateANGLEOpenGLGLContext()); |
97 break; | 96 break; |
98 #endif | 97 #endif |
99 #if SK_COMMAND_BUFFER | 98 #if SK_COMMAND_BUFFER |
100 case kCommandBuffer_GLContextType: | 99 case kCommandBuffer_GLContextType: |
101 glCtx.reset(SkCommandBufferGLContext::Create()); | 100 glCtx.reset(CommandBufferGLContext::Create()); |
102 break; | 101 break; |
103 #endif | 102 #endif |
104 #if SK_MESA | 103 #if SK_MESA |
105 case kMESA_GLContextType: | 104 case kMESA_GLContextType: |
106 glCtx.reset(SkMesaGLContext::Create()); | 105 glCtx.reset(CreateMesaGLContext()); |
107 break; | 106 break; |
108 #endif | 107 #endif |
109 case kNull_GLContextType: | 108 case kNull_GLContextType: |
110 glCtx.reset(SkNullGLContext::Create()); | 109 glCtx.reset(CreateNullGLContext()); |
111 break; | 110 break; |
112 case kDebug_GLContextType: | 111 case kDebug_GLContextType: |
113 glCtx.reset(SkDebugGLContext::Create()); | 112 glCtx.reset(CreateDebugGLContext()); |
114 break; | 113 break; |
115 } | 114 } |
116 if (nullptr == glCtx.get()) { | 115 if (nullptr == glCtx.get()) { |
117 return ContextInfo(); | 116 return ContextInfo(); |
118 } | 117 } |
119 | 118 |
120 SkASSERT(glCtx->isValid()); | 119 SkASSERT(glCtx->isValid()); |
121 | 120 |
122 // Block NVPR from non-NVPR types. | 121 // Block NVPR from non-NVPR types. |
123 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); | 122 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); |
124 if (!(kEnableNVPR_GLContextOptions & options)) { | 123 if (!(kEnableNVPR_GLContextOptions & options)) { |
125 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); | 124 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); |
126 if (!glInterface) { | 125 if (!glInterface) { |
127 return ContextInfo(); | 126 return ContextInfo(); |
128 } | 127 } |
129 } | 128 } |
130 | 129 |
131 glCtx->makeCurrent(); | 130 glCtx->makeCurrent(); |
| 131 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); |
132 #ifdef SK_VULKAN | 132 #ifdef SK_VULKAN |
133 if (kEnableNVPR_GLContextOptions & options) { | 133 if (kEnableNVPR_GLContextOptions & options) { |
134 return ContextInfo(); | 134 return ContextInfo(); |
135 } else { | 135 } else { |
136 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(GrVkBackend
Context::Create()); | |
137 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)
); | 136 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)
); |
138 } | 137 } |
139 #else | 138 #else |
140 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get
()); | |
141 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); | 139 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); |
142 #endif | 140 #endif |
143 if (!grCtx.get()) { | 141 if (!grCtx.get()) { |
144 return ContextInfo(); | 142 return ContextInfo(); |
145 } | 143 } |
146 if (kEnableNVPR_GLContextOptions & options) { | 144 if (kEnableNVPR_GLContextOptions & options) { |
147 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { | 145 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { |
148 return ContextInfo(); | 146 return ContextInfo(); |
149 } | 147 } |
150 } | 148 } |
151 if (kRequireSRGBSupport_GLContextOptions & options) { | 149 if (kRequireSRGBSupport_GLContextOptions & options) { |
152 if (!grCtx->caps()->srgbSupport()) { | 150 if (!grCtx->caps()->srgbSupport()) { |
153 return ContextInfo(); | 151 return ContextInfo(); |
154 } | 152 } |
155 } | 153 } |
156 | 154 |
157 Context& context = fContexts.push_back(); | 155 Context& context = fContexts.push_back(); |
158 context.fGLContext = glCtx.release(); | 156 context.fGLContext = glCtx.release(); |
159 context.fGrContext = SkRef(grCtx.get()); | 157 context.fGrContext = SkRef(grCtx.get()); |
160 context.fType = type; | 158 context.fType = type; |
161 context.fOptions = options; | 159 context.fOptions = options; |
162 return ContextInfo(context.fGrContext, context.fGLContext); | 160 return ContextInfo(context.fGrContext, context.fGLContext); |
163 } | 161 } |
| 162 } // namespace sk_gpu_test |
OLD | NEW |