2012-03-28 16:19:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
#include "GLTestContext_angle.h"
|
2012-03-28 16:19:11 +00:00
|
|
|
|
2018-12-19 19:58:18 +00:00
|
|
|
#define EGL_EGL_PROTOTYPES 1
|
|
|
|
|
2016-11-14 14:53:13 +00:00
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
|
|
|
|
2015-11-22 22:51:00 +00:00
|
|
|
#include "gl/GrGLDefines.h"
|
|
|
|
#include "gl/GrGLUtil.h"
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
#include "gl/GrGLInterface.h"
|
|
|
|
#include "gl/GrGLAssembleInterface.h"
|
|
|
|
#include "../ports/SkOSLibrary.h"
|
|
|
|
|
2016-11-14 14:53:13 +00:00
|
|
|
#include <EGL/egl.h>
|
2016-03-31 01:56:19 +00:00
|
|
|
|
2015-07-21 21:50:07 +00:00
|
|
|
#define EGL_PLATFORM_ANGLE_ANGLE 0x3202
|
|
|
|
#define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3203
|
|
|
|
#define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3207
|
|
|
|
#define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208
|
2015-09-11 20:07:29 +00:00
|
|
|
#define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x320D
|
2015-02-23 16:57:23 +00:00
|
|
|
|
2016-10-14 15:13:48 +00:00
|
|
|
using sk_gpu_test::ANGLEBackend;
|
|
|
|
using sk_gpu_test::ANGLEContextVersion;
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
namespace {
|
2016-11-14 14:53:13 +00:00
|
|
|
struct Libs {
|
|
|
|
void* fGLLib;
|
|
|
|
void* fEGLLib;
|
2016-11-11 20:35:34 +00:00
|
|
|
};
|
|
|
|
|
2017-11-17 14:25:23 +00:00
|
|
|
std::function<void()> context_restorer() {
|
|
|
|
auto display = eglGetCurrentDisplay();
|
|
|
|
auto dsurface = eglGetCurrentSurface(EGL_DRAW);
|
|
|
|
auto rsurface = eglGetCurrentSurface(EGL_READ);
|
|
|
|
auto context = eglGetCurrentContext();
|
|
|
|
return [display, dsurface, rsurface, context] {
|
|
|
|
eglMakeCurrent(display, dsurface, rsurface, context);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-11-11 20:35:34 +00:00
|
|
|
static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) {
|
2016-11-14 14:53:13 +00:00
|
|
|
const Libs* libs = reinterpret_cast<const Libs*>(ctx);
|
|
|
|
GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(libs->fGLLib, name);
|
|
|
|
if (proc) {
|
|
|
|
return proc;
|
2016-11-11 20:35:34 +00:00
|
|
|
}
|
2016-11-14 14:53:13 +00:00
|
|
|
proc = (GrGLFuncPtr) GetProcedureAddress(libs->fEGLLib, name);
|
|
|
|
if (proc) {
|
|
|
|
return proc;
|
2016-11-11 20:35:34 +00:00
|
|
|
}
|
2016-11-14 14:53:13 +00:00
|
|
|
return eglGetProcAddress(name);
|
|
|
|
}
|
2016-11-11 20:35:34 +00:00
|
|
|
|
2016-11-14 14:53:13 +00:00
|
|
|
void* get_angle_egl_display(void* nativeDisplay, ANGLEBackend type) {
|
|
|
|
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT;
|
|
|
|
eglGetPlatformDisplayEXT =
|
|
|
|
(PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
|
|
|
|
|
|
|
|
// We expect ANGLE to support this extension
|
|
|
|
if (!eglGetPlatformDisplayEXT) {
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLint typeNum = 0;
|
|
|
|
switch (type) {
|
|
|
|
case ANGLEBackend::kD3D9:
|
|
|
|
typeNum = EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE;
|
|
|
|
break;
|
|
|
|
case ANGLEBackend::kD3D11:
|
|
|
|
typeNum = EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE;
|
|
|
|
break;
|
|
|
|
case ANGLEBackend::kOpenGL:
|
|
|
|
typeNum = EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const EGLint attribs[] = { EGL_PLATFORM_ANGLE_TYPE_ANGLE, typeNum, EGL_NONE };
|
|
|
|
return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, nativeDisplay, attribs);
|
|
|
|
}
|
2016-11-11 20:35:34 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
class ANGLEGLContext : public sk_gpu_test::GLTestContext {
|
2016-03-31 01:56:19 +00:00
|
|
|
public:
|
2017-06-08 22:22:53 +00:00
|
|
|
ANGLEGLContext(ANGLEBackend, ANGLEContextVersion, ANGLEGLContext* shareContext, void* display);
|
2016-03-31 01:56:19 +00:00
|
|
|
~ANGLEGLContext() override;
|
|
|
|
|
|
|
|
GrEGLImage texture2DToEGLImage(GrGLuint texID) const override;
|
|
|
|
void destroyEGLImage(GrEGLImage) const override;
|
|
|
|
GrGLuint eglImageToExternalTexture(GrEGLImage) const override;
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<sk_gpu_test::GLTestContext> makeNew() const override;
|
2016-03-31 01:56:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void destroyGLContext();
|
|
|
|
|
|
|
|
void onPlatformMakeCurrent() const override;
|
2017-11-17 14:25:23 +00:00
|
|
|
std::function<void()> onPlatformGetAutoContextRestore() const override;
|
2016-03-31 01:56:19 +00:00
|
|
|
void onPlatformSwapBuffers() const override;
|
|
|
|
GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override;
|
|
|
|
|
2016-11-14 14:53:13 +00:00
|
|
|
void* fContext;
|
|
|
|
void* fDisplay;
|
|
|
|
void* fSurface;
|
2016-10-14 15:13:48 +00:00
|
|
|
ANGLEBackend fType;
|
|
|
|
ANGLEContextVersion fVersion;
|
2017-06-08 22:22:53 +00:00
|
|
|
|
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
|
|
|
HWND fWindow;
|
|
|
|
HDC fDeviceContext;
|
|
|
|
static ATOM gWC;
|
|
|
|
#endif
|
2016-03-31 01:56:19 +00:00
|
|
|
};
|
|
|
|
|
2017-06-08 22:22:53 +00:00
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
|
|
|
ATOM ANGLEGLContext::gWC = 0;
|
|
|
|
#endif
|
|
|
|
|
2017-02-21 21:58:08 +00:00
|
|
|
ANGLEGLContext::ANGLEGLContext(ANGLEBackend type, ANGLEContextVersion version,
|
2017-06-08 22:22:53 +00:00
|
|
|
ANGLEGLContext* shareContext, void* display)
|
2016-11-14 14:53:13 +00:00
|
|
|
: fContext(EGL_NO_CONTEXT)
|
2017-06-08 22:22:53 +00:00
|
|
|
, fDisplay(display)
|
2016-10-14 15:13:48 +00:00
|
|
|
, fSurface(EGL_NO_SURFACE)
|
|
|
|
, fType(type)
|
|
|
|
, fVersion(version) {
|
2017-06-08 22:22:53 +00:00
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
|
|
|
fWindow = nullptr;
|
|
|
|
fDeviceContext = nullptr;
|
|
|
|
|
|
|
|
if (EGL_NO_DISPLAY == fDisplay) {
|
|
|
|
HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(nullptr);
|
|
|
|
|
|
|
|
if (!gWC) {
|
|
|
|
WNDCLASS wc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hbrBackground = nullptr;
|
|
|
|
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
|
|
|
wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
wc.lpfnWndProc = (WNDPROC) DefWindowProc;
|
|
|
|
wc.lpszClassName = TEXT("ANGLE-win");
|
|
|
|
wc.lpszMenuName = nullptr;
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
|
|
|
|
|
|
|
gWC = RegisterClass(&wc);
|
|
|
|
if (!gWC) {
|
|
|
|
SkDebugf("Could not register window class.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(fWindow = CreateWindow(TEXT("ANGLE-win"),
|
|
|
|
TEXT("The Invisible Man"),
|
|
|
|
WS_OVERLAPPEDWINDOW,
|
|
|
|
0, 0, 1, 1,
|
|
|
|
nullptr, nullptr,
|
|
|
|
hInstance, nullptr))) {
|
|
|
|
SkDebugf("Could not create window.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(fDeviceContext = GetDC(fWindow))) {
|
|
|
|
SkDebugf("Could not get device context.\n");
|
|
|
|
this->destroyGLContext();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fDisplay = get_angle_egl_display(fDeviceContext, type);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
SkASSERT(EGL_NO_DISPLAY == fDisplay);
|
|
|
|
fDisplay = get_angle_egl_display(EGL_DEFAULT_DISPLAY, type);
|
|
|
|
#endif
|
|
|
|
if (EGL_NO_DISPLAY == fDisplay) {
|
|
|
|
SkDebugf("Could not create EGL display!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLint majorVersion;
|
|
|
|
EGLint minorVersion;
|
|
|
|
if (!eglInitialize(fDisplay, &majorVersion, &minorVersion)) {
|
|
|
|
SkDebugf("Could not initialize display!");
|
|
|
|
this->destroyGLContext();
|
|
|
|
return;
|
|
|
|
}
|
2012-03-28 16:19:11 +00:00
|
|
|
|
|
|
|
EGLint numConfigs;
|
|
|
|
static const EGLint configAttribs[] = {
|
|
|
|
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_RED_SIZE, 8,
|
|
|
|
EGL_GREEN_SIZE, 8,
|
|
|
|
EGL_BLUE_SIZE, 8,
|
|
|
|
EGL_ALPHA_SIZE, 8,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2017-06-08 22:22:53 +00:00
|
|
|
EGLConfig surfaceConfig;
|
|
|
|
if (!eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs)) {
|
|
|
|
SkDebugf("Could not create choose config!");
|
|
|
|
this->destroyGLContext();
|
2015-02-23 16:57:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-14 15:13:48 +00:00
|
|
|
int versionNum = ANGLEContextVersion::kES2 == version ? 2 : 3;
|
|
|
|
const EGLint contextAttribs[] = {
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, versionNum,
|
2012-03-28 16:19:11 +00:00
|
|
|
EGL_NONE
|
|
|
|
};
|
2017-02-21 21:58:08 +00:00
|
|
|
EGLContext eglShareContext = shareContext ? shareContext->fContext : nullptr;
|
|
|
|
fContext = eglCreateContext(fDisplay, surfaceConfig, eglShareContext, contextAttribs);
|
2017-06-08 22:22:53 +00:00
|
|
|
if (EGL_NO_CONTEXT == fContext) {
|
|
|
|
SkDebugf("Could not create context!");
|
|
|
|
this->destroyGLContext();
|
|
|
|
return;
|
|
|
|
}
|
2012-03-28 16:19:11 +00:00
|
|
|
|
|
|
|
static const EGLint surfaceAttribs[] = {
|
2015-02-23 16:57:23 +00:00
|
|
|
EGL_WIDTH, 1,
|
|
|
|
EGL_HEIGHT, 1,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2016-11-14 14:53:13 +00:00
|
|
|
fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs);
|
2012-03-28 16:19:11 +00:00
|
|
|
|
2017-11-17 14:25:23 +00:00
|
|
|
SkScopeExit restorer(context_restorer());
|
2017-06-08 22:22:53 +00:00
|
|
|
if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
|
|
|
|
SkDebugf("Could not set the context.");
|
|
|
|
this->destroyGLContext();
|
|
|
|
return;
|
|
|
|
}
|
2012-03-28 16:19:11 +00:00
|
|
|
|
2017-12-11 15:06:31 +00:00
|
|
|
sk_sp<const GrGLInterface> gl = sk_gpu_test::CreateANGLEGLInterface();
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == gl.get()) {
|
2012-03-28 16:19:11 +00:00
|
|
|
SkDebugf("Could not create ANGLE GL interface!\n");
|
|
|
|
this->destroyGLContext();
|
2014-10-16 06:03:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-23 20:23:44 +00:00
|
|
|
if (!gl->validate()) {
|
2014-10-16 06:03:54 +00:00
|
|
|
SkDebugf("Could not validate ANGLE GL interface!\n");
|
|
|
|
this->destroyGLContext();
|
|
|
|
return;
|
2012-03-28 16:19:11 +00:00
|
|
|
}
|
2015-06-23 20:23:44 +00:00
|
|
|
|
2017-06-08 22:22:53 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
// Verify that the interface we requested was actually returned to us
|
|
|
|
const GrGLubyte* rendererUByte;
|
|
|
|
GR_GL_CALL_RET(gl.get(), rendererUByte, GetString(GR_GL_RENDERER));
|
|
|
|
const char* renderer = reinterpret_cast<const char*>(rendererUByte);
|
|
|
|
switch (type) {
|
|
|
|
case ANGLEBackend::kD3D9:
|
|
|
|
SkASSERT(strstr(renderer, "Direct3D9"));
|
|
|
|
break;
|
|
|
|
case ANGLEBackend::kD3D11:
|
|
|
|
SkASSERT(strstr(renderer, "Direct3D11"));
|
|
|
|
break;
|
|
|
|
case ANGLEBackend::kOpenGL:
|
|
|
|
SkASSERT(strstr(renderer, "OpenGL"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-12-11 15:06:31 +00:00
|
|
|
this->init(std::move(gl));
|
2014-10-16 06:03:54 +00:00
|
|
|
}
|
2012-03-28 16:19:11 +00:00
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
ANGLEGLContext::~ANGLEGLContext() {
|
2015-06-23 20:23:44 +00:00
|
|
|
this->teardown();
|
2014-10-16 06:03:54 +00:00
|
|
|
this->destroyGLContext();
|
|
|
|
}
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
GrEGLImage ANGLEGLContext::texture2DToEGLImage(GrGLuint texID) const {
|
2015-11-22 22:51:00 +00:00
|
|
|
if (!this->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) {
|
|
|
|
return GR_EGL_NO_IMAGE;
|
|
|
|
}
|
|
|
|
GrEGLImage img;
|
|
|
|
GrEGLint attribs[] = { GR_EGL_GL_TEXTURE_LEVEL, 0,
|
|
|
|
GR_EGL_IMAGE_PRESERVED, GR_EGL_TRUE,
|
|
|
|
GR_EGL_NONE };
|
|
|
|
// 64 bit cast is to shut Visual C++ up about casting 32 bit value to a pointer.
|
|
|
|
GrEGLClientBuffer clientBuffer = reinterpret_cast<GrEGLClientBuffer>((uint64_t)texID);
|
|
|
|
GR_GL_CALL_RET(this->gl(), img,
|
2016-11-14 14:53:13 +00:00
|
|
|
EGLCreateImage(fDisplay, fContext, GR_EGL_GL_TEXTURE_2D, clientBuffer,
|
2015-11-22 22:51:00 +00:00
|
|
|
attribs));
|
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
void ANGLEGLContext::destroyEGLImage(GrEGLImage image) const {
|
2016-11-14 14:53:13 +00:00
|
|
|
GR_GL_CALL(this->gl(), EGLDestroyImage(fDisplay, image));
|
2015-11-22 22:51:00 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
GrGLuint ANGLEGLContext::eglImageToExternalTexture(GrEGLImage image) const {
|
2015-11-22 22:51:00 +00:00
|
|
|
GrGLClearErr(this->gl());
|
|
|
|
if (!this->gl()->hasExtension("GL_OES_EGL_image_external")) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-11-14 14:53:13 +00:00
|
|
|
typedef GrGLvoid (EGLAPIENTRY *EGLImageTargetTexture2DProc)(GrGLenum, GrGLeglImage);
|
|
|
|
EGLImageTargetTexture2DProc glEGLImageTargetTexture2D =
|
|
|
|
(EGLImageTargetTexture2DProc)eglGetProcAddress("glEGLImageTargetTexture2DOES");
|
2015-11-22 22:51:00 +00:00
|
|
|
if (!glEGLImageTargetTexture2D) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
GrGLuint texID;
|
|
|
|
GR_GL_CALL(this->gl(), GenTextures(1, &texID));
|
|
|
|
if (!texID) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
GR_GL_CALL(this->gl(), BindTexture(GR_GL_TEXTURE_EXTERNAL, texID));
|
|
|
|
if (GR_GL_GET_ERROR(this->gl()) != GR_GL_NO_ERROR) {
|
|
|
|
GR_GL_CALL(this->gl(), DeleteTextures(1, &texID));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
glEGLImageTargetTexture2D(GR_GL_TEXTURE_EXTERNAL, image);
|
|
|
|
if (GR_GL_GET_ERROR(this->gl()) != GR_GL_NO_ERROR) {
|
|
|
|
GR_GL_CALL(this->gl(), DeleteTextures(1, &texID));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return texID;
|
|
|
|
}
|
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<sk_gpu_test::GLTestContext> ANGLEGLContext::makeNew() const {
|
2017-06-08 22:22:53 +00:00
|
|
|
// For EGLImage sharing between contexts to work in ANGLE the two contexts
|
|
|
|
// need to share the same display
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<sk_gpu_test::GLTestContext> ctx =
|
2017-06-08 22:22:53 +00:00
|
|
|
sk_gpu_test::MakeANGLETestContext(fType, fVersion, nullptr, fDisplay);
|
2015-11-22 22:51:00 +00:00
|
|
|
if (ctx) {
|
|
|
|
ctx->makeCurrent();
|
|
|
|
}
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
void ANGLEGLContext::destroyGLContext() {
|
2017-06-08 22:22:53 +00:00
|
|
|
if (EGL_NO_DISPLAY != fDisplay) {
|
2017-11-17 14:25:23 +00:00
|
|
|
if (eglGetCurrentContext() == fContext) {
|
|
|
|
// This will ensure that the context is immediately deleted.
|
|
|
|
eglMakeCurrent(fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
}
|
2014-10-16 06:03:54 +00:00
|
|
|
|
2017-06-08 22:22:53 +00:00
|
|
|
if (EGL_NO_CONTEXT != fContext) {
|
2016-11-14 14:53:13 +00:00
|
|
|
eglDestroyContext(fDisplay, fContext);
|
2014-10-16 06:03:54 +00:00
|
|
|
fContext = EGL_NO_CONTEXT;
|
|
|
|
}
|
|
|
|
|
2017-06-08 22:22:53 +00:00
|
|
|
if (EGL_NO_SURFACE != fSurface) {
|
2016-11-14 14:53:13 +00:00
|
|
|
eglDestroySurface(fDisplay, fSurface);
|
2014-10-16 06:03:54 +00:00
|
|
|
fSurface = EGL_NO_SURFACE;
|
|
|
|
}
|
2016-11-14 14:53:13 +00:00
|
|
|
|
2017-06-08 22:22:53 +00:00
|
|
|
eglTerminate(fDisplay);
|
2017-06-05 17:25:13 +00:00
|
|
|
fDisplay = EGL_NO_DISPLAY;
|
2014-10-16 06:03:54 +00:00
|
|
|
}
|
2017-06-08 22:22:53 +00:00
|
|
|
|
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
|
|
|
if (fWindow) {
|
|
|
|
if (fDeviceContext) {
|
|
|
|
ReleaseDC(fWindow, fDeviceContext);
|
|
|
|
fDeviceContext = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyWindow(fWindow);
|
|
|
|
fWindow = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-28 16:19:11 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
void ANGLEGLContext::onPlatformMakeCurrent() const {
|
2016-11-14 14:53:13 +00:00
|
|
|
if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
|
2017-06-08 22:22:53 +00:00
|
|
|
SkDebugf("Could not set the context 0x%x.\n", eglGetError());
|
2012-03-28 16:19:11 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-09 18:25:38 +00:00
|
|
|
|
2017-11-17 14:25:23 +00:00
|
|
|
std::function<void()> ANGLEGLContext::onPlatformGetAutoContextRestore() const {
|
|
|
|
if (eglGetCurrentContext() == fContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return context_restorer();
|
|
|
|
}
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
void ANGLEGLContext::onPlatformSwapBuffers() const {
|
2016-11-14 14:53:13 +00:00
|
|
|
if (!eglSwapBuffers(fDisplay, fSurface)) {
|
2013-10-09 18:25:38 +00:00
|
|
|
SkDebugf("Could not complete eglSwapBuffers.\n");
|
|
|
|
}
|
|
|
|
}
|
2015-06-23 20:23:44 +00:00
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
GrGLFuncPtr ANGLEGLContext::onPlatformGetProcAddress(const char* name) const {
|
2016-11-14 14:53:13 +00:00
|
|
|
return eglGetProcAddress(name);
|
2015-06-23 20:23:44 +00:00
|
|
|
}
|
2016-03-31 01:56:19 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace sk_gpu_test {
|
2017-12-11 15:06:31 +00:00
|
|
|
sk_sp<const GrGLInterface> CreateANGLEGLInterface() {
|
2016-11-14 14:53:13 +00:00
|
|
|
static Libs gLibs = { nullptr, nullptr };
|
|
|
|
|
|
|
|
if (nullptr == gLibs.fGLLib) {
|
|
|
|
// We load the ANGLE library and never let it go
|
|
|
|
#if defined _WIN32
|
|
|
|
gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.dll");
|
|
|
|
gLibs.fEGLLib = DynamicLoadLibrary("libEGL.dll");
|
|
|
|
#elif defined SK_BUILD_FOR_MAC
|
|
|
|
gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.dylib");
|
|
|
|
gLibs.fEGLLib = DynamicLoadLibrary("libEGL.dylib");
|
|
|
|
#else
|
|
|
|
gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.so");
|
|
|
|
gLibs.fEGLLib = DynamicLoadLibrary("libEGL.so");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nullptr == gLibs.fGLLib || nullptr == gLibs.fEGLLib) {
|
|
|
|
// We can't setup the interface correctly w/o the so
|
2016-03-31 01:56:19 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2016-11-14 14:53:13 +00:00
|
|
|
|
2017-12-11 21:36:53 +00:00
|
|
|
return GrGLMakeAssembledGLESInterface(&gLibs, angle_get_gl_proc);
|
2016-03-31 01:56:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 21:58:08 +00:00
|
|
|
std::unique_ptr<GLTestContext> MakeANGLETestContext(ANGLEBackend type, ANGLEContextVersion version,
|
2017-06-08 22:22:53 +00:00
|
|
|
GLTestContext* shareContext, void* display){
|
2017-02-21 21:58:08 +00:00
|
|
|
ANGLEGLContext* angleShareContext = reinterpret_cast<ANGLEGLContext*>(shareContext);
|
2017-06-08 22:22:53 +00:00
|
|
|
std::unique_ptr<GLTestContext> ctx(new ANGLEGLContext(type, version,
|
|
|
|
angleShareContext, display));
|
2016-03-31 01:56:19 +00:00
|
|
|
if (!ctx->isValid()) {
|
2016-11-03 18:40:50 +00:00
|
|
|
return nullptr;
|
2016-03-31 01:56:19 +00:00
|
|
|
}
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
} // namespace sk_gpu_test
|