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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gl/SkANGLEGLContext.h"
|
|
|
|
|
|
|
|
SkANGLEGLContext::SkANGLEGLContext()
|
|
|
|
: fContext(EGL_NO_CONTEXT)
|
|
|
|
, fDisplay(EGL_NO_DISPLAY)
|
|
|
|
, fSurface(EGL_NO_SURFACE) {
|
2012-04-02 15:04:16 +00:00
|
|
|
fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
2012-03-28 16:19:11 +00:00
|
|
|
|
|
|
|
EGLint majorVersion;
|
|
|
|
EGLint minorVersion;
|
2012-04-02 15:04:16 +00:00
|
|
|
eglInitialize(fDisplay, &majorVersion, &minorVersion);
|
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
|
|
|
|
};
|
|
|
|
|
2012-04-02 15:04:16 +00:00
|
|
|
EGLConfig surfaceConfig;
|
|
|
|
eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs);
|
2012-03-28 16:19:11 +00:00
|
|
|
|
|
|
|
static const EGLint contextAttribs[] = {
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
2012-04-02 15:04:16 +00:00
|
|
|
fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, contextAttribs);
|
2012-03-28 16:19:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const EGLint surfaceAttribs[] = {
|
|
|
|
EGL_WIDTH, 1,
|
|
|
|
EGL_HEIGHT, 1,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
2012-04-02 15:04:16 +00:00
|
|
|
fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs);
|
2012-03-28 16:19:11 +00:00
|
|
|
|
2012-04-02 15:04:16 +00:00
|
|
|
eglMakeCurrent(fDisplay, fSurface, fSurface, fContext);
|
2012-03-28 16:19:11 +00:00
|
|
|
|
2014-10-16 06:03:54 +00:00
|
|
|
fGL.reset(GrGLCreateANGLEInterface());
|
|
|
|
if (NULL == fGL.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;
|
|
|
|
}
|
|
|
|
if (!fGL->validate()) {
|
|
|
|
SkDebugf("Could not validate ANGLE GL interface!\n");
|
|
|
|
this->destroyGLContext();
|
|
|
|
return;
|
2012-03-28 16:19:11 +00:00
|
|
|
}
|
2014-10-16 06:03:54 +00:00
|
|
|
}
|
2012-03-28 16:19:11 +00:00
|
|
|
|
2014-10-16 06:03:54 +00:00
|
|
|
SkANGLEGLContext::~SkANGLEGLContext() {
|
|
|
|
this->destroyGLContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkANGLEGLContext::destroyGLContext() {
|
|
|
|
fGL.reset(NULL);
|
|
|
|
if (fDisplay) {
|
|
|
|
eglMakeCurrent(fDisplay, 0, 0, 0);
|
|
|
|
|
|
|
|
if (fContext) {
|
|
|
|
eglDestroyContext(fDisplay, fContext);
|
|
|
|
fContext = EGL_NO_CONTEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fSurface) {
|
|
|
|
eglDestroySurface(fDisplay, fSurface);
|
|
|
|
fSurface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO should we close the display?
|
|
|
|
fDisplay = EGL_NO_DISPLAY;
|
|
|
|
}
|
2012-03-28 16:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkANGLEGLContext::makeCurrent() const {
|
2012-04-02 15:04:16 +00:00
|
|
|
if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
|
2012-03-28 16:19:11 +00:00
|
|
|
SkDebugf("Could not set the context.\n");
|
|
|
|
}
|
|
|
|
}
|
2013-10-09 18:25:38 +00:00
|
|
|
|
|
|
|
void SkANGLEGLContext::swapBuffers() const {
|
|
|
|
if (!eglSwapBuffers(fDisplay, fSurface)) {
|
|
|
|
SkDebugf("Could not complete eglSwapBuffers.\n");
|
|
|
|
}
|
|
|
|
}
|