2017-05-31 13:45:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2018-05-22 20:44:53 +00:00
|
|
|
#include "GrContext.h"
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "gl/GrGLFunctions.h"
|
|
|
|
#include "gl/GrGLInterface.h"
|
2017-05-31 13:45:19 +00:00
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
2017-06-01 17:24:11 +00:00
|
|
|
#include <GLES2/gl2.h>
|
2017-05-31 13:45:19 +00:00
|
|
|
|
2018-05-22 20:44:53 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2017-05-31 13:45:19 +00:00
|
|
|
static const EGLint configAttribs[] = {
|
|
|
|
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
|
|
|
|
EGL_BLUE_SIZE, 8,
|
|
|
|
EGL_GREEN_SIZE, 8,
|
|
|
|
EGL_RED_SIZE, 8,
|
|
|
|
EGL_DEPTH_SIZE, 8,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int pbufferWidth = 9;
|
|
|
|
static const int pbufferHeight = 9;
|
|
|
|
|
|
|
|
static const EGLint pbufferAttribs[] = {
|
|
|
|
EGL_WIDTH, pbufferWidth,
|
|
|
|
EGL_HEIGHT, pbufferHeight,
|
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
// create_grcontext implementation for EGL.
|
2017-06-01 17:24:11 +00:00
|
|
|
sk_sp<GrContext> create_grcontext(std::ostringstream &driverinfo) {
|
2017-05-31 13:45:19 +00:00
|
|
|
EGLDisplay eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
|
|
if (EGL_NO_DISPLAY == eglDpy) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLint major, minor;
|
|
|
|
if (EGL_TRUE != eglInitialize(eglDpy, &major, &minor)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLint numConfigs;
|
|
|
|
EGLConfig eglCfg;
|
|
|
|
if (EGL_TRUE != eglChooseConfig(eglDpy, configAttribs, &eglCfg, 1, &numConfigs)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLSurface eglSurf = eglCreatePbufferSurface(eglDpy, eglCfg, pbufferAttribs);
|
|
|
|
if (EGL_NO_SURFACE == eglSurf) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EGL_TRUE != eglBindAPI(EGL_OPENGL_API)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-22 20:44:53 +00:00
|
|
|
EGLContext eglCtx = eglCreateContext(eglDpy, eglCfg, EGL_NO_CONTEXT, nullptr);
|
2017-05-31 13:45:19 +00:00
|
|
|
if (EGL_NO_CONTEXT == eglCtx) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (EGL_FALSE == eglMakeCurrent(eglDpy, eglSurf, eglSurf, eglCtx)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-06-01 17:24:11 +00:00
|
|
|
driverinfo << "EGL " << major << "." << minor << "\n";
|
|
|
|
GrGLGetStringProc getString = (GrGLGetStringProc )eglGetProcAddress("glGetString");
|
|
|
|
driverinfo << "GL Versionr: " << getString(GL_VERSION) << "\n";
|
|
|
|
driverinfo << "GL Vendor: " << getString(GL_VENDOR) << "\n";
|
|
|
|
driverinfo << "GL Renderer: " << getString(GL_RENDERER) << "\n";
|
|
|
|
driverinfo << "GL Extensions: " << getString(GL_EXTENSIONS) << "\n";
|
|
|
|
|
2017-12-11 15:06:31 +00:00
|
|
|
auto interface = GrGLMakeNativeInterface();
|
2017-05-31 13:45:19 +00:00
|
|
|
if (!interface) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
eglTerminate(eglDpy);
|
|
|
|
|
2017-07-25 14:05:01 +00:00
|
|
|
return sk_sp<GrContext>(GrContext::MakeGL(interface));
|
2017-05-31 13:45:19 +00:00
|
|
|
}
|