OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 "GLTestContext_angle.h" | 9 #include "GLTestContext_angle.h" |
10 | 10 |
11 #include <EGL/egl.h> | 11 #include <EGL/egl.h> |
12 #include <EGL/eglext.h> | 12 #include <EGL/eglext.h> |
13 | 13 |
14 #include "gl/GrGLDefines.h" | 14 #include "gl/GrGLDefines.h" |
15 #include "gl/GrGLUtil.h" | 15 #include "gl/GrGLUtil.h" |
16 | 16 |
17 #include "gl/GrGLInterface.h" | 17 #include "gl/GrGLInterface.h" |
18 #include "gl/GrGLAssembleInterface.h" | 18 #include "gl/GrGLAssembleInterface.h" |
19 #include "../ports/SkOSLibrary.h" | 19 #include "../ports/SkOSLibrary.h" |
20 | 20 |
21 #include <EGL/egl.h> | 21 #include <EGL/egl.h> |
22 | 22 |
23 #define EGL_PLATFORM_ANGLE_ANGLE 0x3202 | 23 #define EGL_PLATFORM_ANGLE_ANGLE 0x3202 |
24 #define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3203 | 24 #define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3203 |
25 #define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3207 | 25 #define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3207 |
26 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208 | 26 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208 |
27 #define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x320D | 27 #define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x320D |
28 | 28 |
29 using sk_gpu_test::ANGLEBackend; | |
30 using sk_gpu_test::ANGLEContextVersion; | |
31 | |
32 namespace { | 29 namespace { |
33 struct Libs { | 30 struct Libs { |
34 void* fGLLib; | 31 void* fGLLib; |
35 void* fEGLLib; | 32 void* fEGLLib; |
36 }; | 33 }; |
37 | 34 |
38 static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) { | 35 static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) { |
39 const Libs* libs = reinterpret_cast<const Libs*>(ctx); | 36 const Libs* libs = reinterpret_cast<const Libs*>(ctx); |
40 GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(libs->fGLLib, name); | 37 GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(libs->fGLLib, name); |
41 if (proc) { | 38 if (proc) { |
42 return proc; | 39 return proc; |
43 } | 40 } |
44 proc = (GrGLFuncPtr) GetProcedureAddress(libs->fEGLLib, name); | 41 proc = (GrGLFuncPtr) GetProcedureAddress(libs->fEGLLib, name); |
45 if (proc) { | 42 if (proc) { |
46 return proc; | 43 return proc; |
47 } | 44 } |
48 return eglGetProcAddress(name); | 45 return eglGetProcAddress(name); |
49 } | 46 } |
50 | 47 |
51 void* get_angle_egl_display(void* nativeDisplay, ANGLEBackend type) { | 48 void* get_angle_egl_display(void* nativeDisplay, bool useGLBackend) { |
52 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT; | 49 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT; |
53 eglGetPlatformDisplayEXT = | 50 eglGetPlatformDisplayEXT = |
54 (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDispla
yEXT"); | 51 (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDispla
yEXT"); |
55 | 52 |
56 // We expect ANGLE to support this extension | 53 // We expect ANGLE to support this extension |
57 if (!eglGetPlatformDisplayEXT) { | 54 if (!eglGetPlatformDisplayEXT) { |
58 return EGL_NO_DISPLAY; | 55 return EGL_NO_DISPLAY; |
59 } | 56 } |
60 | 57 |
61 EGLint typeNum; | 58 EGLDisplay display = EGL_NO_DISPLAY; |
62 switch (type) { | 59 if (useGLBackend) { |
63 case ANGLEBackend::kD3D9: | 60 EGLint attribs[3] = { |
64 typeNum = EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE; | 61 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
65 break; | 62 EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, |
66 case ANGLEBackend::kD3D11: | 63 EGL_NONE |
67 typeNum = EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE; | 64 }; |
68 break; | 65 display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, nativeDispl
ay, attribs); |
69 case ANGLEBackend::kOpenGL: | 66 } else { |
70 typeNum = EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE; | 67 // Try for an ANGLE D3D11 context, fall back to D3D9. |
71 break; | 68 EGLint attribs[3][3] = { |
| 69 { |
| 70 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
| 71 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, |
| 72 EGL_NONE |
| 73 }, |
| 74 { |
| 75 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
| 76 EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, |
| 77 EGL_NONE |
| 78 }, |
| 79 }; |
| 80 for (int i = 0; i < 3 && display == EGL_NO_DISPLAY; ++i) { |
| 81 display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,nativeDi
splay, attribs[i]); |
| 82 } |
72 } | 83 } |
73 const EGLint attribs[] = { EGL_PLATFORM_ANGLE_TYPE_ANGLE, typeNum, EGL_NONE
}; | 84 return display; |
74 return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, nativeDisplay, att
ribs); | |
75 } | 85 } |
76 | 86 |
77 class ANGLEGLContext : public sk_gpu_test::GLTestContext { | 87 class ANGLEGLContext : public sk_gpu_test::GLTestContext { |
78 public: | 88 public: |
79 ANGLEGLContext(ANGLEBackend, ANGLEContextVersion); | 89 ANGLEGLContext(bool preferGLBackend); |
80 ~ANGLEGLContext() override; | 90 ~ANGLEGLContext() override; |
81 | 91 |
82 GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; | 92 GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; |
83 void destroyEGLImage(GrEGLImage) const override; | 93 void destroyEGLImage(GrEGLImage) const override; |
84 GrGLuint eglImageToExternalTexture(GrEGLImage) const override; | 94 GrGLuint eglImageToExternalTexture(GrEGLImage) const override; |
85 sk_gpu_test::GLTestContext* createNew() const override; | 95 sk_gpu_test::GLTestContext* createNew() const override; |
86 | 96 |
87 private: | 97 private: |
88 void destroyGLContext(); | 98 void destroyGLContext(); |
89 | 99 |
90 void onPlatformMakeCurrent() const override; | 100 void onPlatformMakeCurrent() const override; |
91 void onPlatformSwapBuffers() const override; | 101 void onPlatformSwapBuffers() const override; |
92 GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override; | 102 GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override; |
93 | 103 |
94 void* fContext; | 104 void* fContext; |
95 void* fDisplay; | 105 void* fDisplay; |
96 void* fSurface; | 106 void* fSurface; |
97 ANGLEBackend fType; | 107 bool fIsGLBackend; |
98 ANGLEContextVersion fVersion; | |
99 }; | 108 }; |
100 | 109 |
101 ANGLEGLContext::ANGLEGLContext(ANGLEBackend type, ANGLEContextVersion version) | 110 ANGLEGLContext::ANGLEGLContext(bool useGLBackend) |
102 : fContext(EGL_NO_CONTEXT) | 111 : fContext(EGL_NO_CONTEXT) |
103 , fDisplay(EGL_NO_DISPLAY) | 112 , fDisplay(EGL_NO_DISPLAY) |
104 , fSurface(EGL_NO_SURFACE) | 113 , fSurface(EGL_NO_SURFACE) { |
105 , fType(type) | |
106 , fVersion(version) { | |
107 | 114 |
108 EGLint numConfigs; | 115 EGLint numConfigs; |
109 static const EGLint configAttribs[] = { | 116 static const EGLint configAttribs[] = { |
110 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, | 117 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, |
111 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 118 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
112 EGL_RED_SIZE, 8, | 119 EGL_RED_SIZE, 8, |
113 EGL_GREEN_SIZE, 8, | 120 EGL_GREEN_SIZE, 8, |
114 EGL_BLUE_SIZE, 8, | 121 EGL_BLUE_SIZE, 8, |
115 EGL_ALPHA_SIZE, 8, | 122 EGL_ALPHA_SIZE, 8, |
116 EGL_NONE | 123 EGL_NONE |
117 }; | 124 }; |
118 | 125 |
119 fDisplay = get_angle_egl_display(EGL_DEFAULT_DISPLAY, type); | 126 fIsGLBackend = useGLBackend; |
| 127 fDisplay = get_angle_egl_display(EGL_DEFAULT_DISPLAY, useGLBackend); |
120 if (EGL_NO_DISPLAY == fDisplay) { | 128 if (EGL_NO_DISPLAY == fDisplay) { |
121 SkDebugf("Could not create EGL display!"); | 129 SkDebugf("Could not create EGL display!"); |
122 return; | 130 return; |
123 } | 131 } |
124 | 132 |
125 EGLint majorVersion; | 133 EGLint majorVersion; |
126 EGLint minorVersion; | 134 EGLint minorVersion; |
127 eglInitialize(fDisplay, &majorVersion, &minorVersion); | 135 eglInitialize(fDisplay, &majorVersion, &minorVersion); |
128 | 136 |
129 EGLConfig surfaceConfig; | 137 EGLConfig surfaceConfig; |
130 eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs); | 138 eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs); |
131 | 139 |
132 int versionNum = ANGLEContextVersion::kES2 == version ? 2 : 3; | 140 static const EGLint contextAttribs[] = { |
133 const EGLint contextAttribs[] = { | 141 EGL_CONTEXT_CLIENT_VERSION, 2, |
134 EGL_CONTEXT_CLIENT_VERSION, versionNum, | |
135 EGL_NONE | 142 EGL_NONE |
136 }; | 143 }; |
137 fContext = eglCreateContext(fDisplay, surfaceConfig, nullptr, contextAttribs
); | 144 fContext = eglCreateContext(fDisplay, surfaceConfig, nullptr, contextAttribs
); |
138 | 145 |
139 | 146 |
140 static const EGLint surfaceAttribs[] = { | 147 static const EGLint surfaceAttribs[] = { |
141 EGL_WIDTH, 1, | 148 EGL_WIDTH, 1, |
142 EGL_HEIGHT, 1, | 149 EGL_HEIGHT, 1, |
143 EGL_NONE | 150 EGL_NONE |
144 }; | 151 }; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 217 } |
211 glEGLImageTargetTexture2D(GR_GL_TEXTURE_EXTERNAL, image); | 218 glEGLImageTargetTexture2D(GR_GL_TEXTURE_EXTERNAL, image); |
212 if (GR_GL_GET_ERROR(this->gl()) != GR_GL_NO_ERROR) { | 219 if (GR_GL_GET_ERROR(this->gl()) != GR_GL_NO_ERROR) { |
213 GR_GL_CALL(this->gl(), DeleteTextures(1, &texID)); | 220 GR_GL_CALL(this->gl(), DeleteTextures(1, &texID)); |
214 return 0; | 221 return 0; |
215 } | 222 } |
216 return texID; | 223 return texID; |
217 } | 224 } |
218 | 225 |
219 sk_gpu_test::GLTestContext* ANGLEGLContext::createNew() const { | 226 sk_gpu_test::GLTestContext* ANGLEGLContext::createNew() const { |
220 sk_gpu_test::GLTestContext* ctx = sk_gpu_test::CreateANGLETestContext(fType,
fVersion); | 227 #ifdef SK_BUILD_FOR_WIN |
| 228 sk_gpu_test::GLTestContext* ctx = fIsGLBackend |
| 229 ? sk_gpu_test::CreateANGLEOpenGLGLTestContext() |
| 230 : sk_gpu_test::CreateANGLEDirect3DGLTestContext(); |
| 231 #else |
| 232 sk_gpu_test::GLTestContext* ctx = sk_gpu_test::CreateANGLEOpenGLGLTestContex
t(); |
| 233 #endif |
221 if (ctx) { | 234 if (ctx) { |
222 ctx->makeCurrent(); | 235 ctx->makeCurrent(); |
223 } | 236 } |
224 return ctx; | 237 return ctx; |
225 } | 238 } |
226 | 239 |
227 void ANGLEGLContext::destroyGLContext() { | 240 void ANGLEGLContext::destroyGLContext() { |
228 if (fDisplay) { | 241 if (fDisplay) { |
229 eglMakeCurrent(fDisplay, 0, 0, 0); | 242 eglMakeCurrent(fDisplay, 0, 0, 0); |
230 | 243 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 292 } |
280 | 293 |
281 if (nullptr == gLibs.fGLLib || nullptr == gLibs.fEGLLib) { | 294 if (nullptr == gLibs.fGLLib || nullptr == gLibs.fEGLLib) { |
282 // We can't setup the interface correctly w/o the so | 295 // We can't setup the interface correctly w/o the so |
283 return nullptr; | 296 return nullptr; |
284 } | 297 } |
285 | 298 |
286 return GrGLAssembleGLESInterface(&gLibs, angle_get_gl_proc); | 299 return GrGLAssembleGLESInterface(&gLibs, angle_get_gl_proc); |
287 } | 300 } |
288 | 301 |
289 GLTestContext* CreateANGLETestContext(ANGLEBackend type, | 302 #ifdef SK_BUILD_FOR_WIN |
290 ANGLEContextVersion version) { | 303 GLTestContext* CreateANGLEDirect3DGLTestContext() { |
291 ANGLEGLContext* ctx = new ANGLEGLContext(type, version); | 304 ANGLEGLContext* ctx = new ANGLEGLContext(false); |
| 305 if (!ctx->isValid()) { |
| 306 delete ctx; |
| 307 return NULL; |
| 308 } |
| 309 return ctx; |
| 310 } |
| 311 #endif |
| 312 |
| 313 GLTestContext* CreateANGLEOpenGLGLTestContext() { |
| 314 ANGLEGLContext* ctx = new ANGLEGLContext(true); |
292 if (!ctx->isValid()) { | 315 if (!ctx->isValid()) { |
293 delete ctx; | 316 delete ctx; |
294 return NULL; | 317 return NULL; |
295 } | 318 } |
296 return ctx; | 319 return ctx; |
297 } | 320 } |
298 } // namespace sk_gpu_test | 321 } // namespace sk_gpu_test |
OLD | NEW |