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