提交 a2294b22 编写于 作者: S Simon Fels

Use a surfaceless EGL context if possible instead of a dummy pbuffer

上级 5be5550d
......@@ -125,6 +125,7 @@ set(SOURCES
anbox/graphics/program_family.cpp
anbox/graphics/primitives.h
anbox/graphics/renderer.h
anbox/graphics/gl_extensions.h
anbox/graphics/emugl/ColorBuffer.cpp
anbox/graphics/emugl/DisplayManager.cpp
......
......@@ -23,6 +23,8 @@
#include "OpenGLESDispatch/EGLDispatch.h"
#include "anbox/graphics/gl_extensions.h"
#include "anbox/logger.h"
#include <stdio.h>
......@@ -78,7 +80,6 @@ class ColorBufferHelper : public ColorBuffer::Helper {
private:
Renderer *mFb;
};
} // namespace
HandleType Renderer::s_nextHandle = 0;
......@@ -105,11 +106,9 @@ static char *getGLES1ExtensionString(EGLDisplay p_dpy) {
return NULL;
}
static const GLint gles1ContextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 1,
EGL_NONE};
static const GLint gles1ContextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
EGLContext ctx = s_egl.eglCreateContext(p_dpy, config, EGL_NO_CONTEXT,
gles1ContextAttribs);
EGLContext ctx = s_egl.eglCreateContext(p_dpy, config, EGL_NO_CONTEXT, gles1ContextAttribs);
if (ctx == EGL_NO_CONTEXT) {
ERROR("%s: Could not create GLES 1.x Context!", __FUNCTION__);
s_egl.eglDestroySurface(p_dpy, surface);
......@@ -156,6 +155,12 @@ bool Renderer::initialize(EGLNativeDisplayType nativeDisplay) {
return false;
}
anbox::graphics::GLExtensions egl_extensions{s_egl.eglQueryString(m_eglDisplay, EGL_EXTENSIONS)};
const auto surfaceless_supported = egl_extensions.support("EGL_KHR_surfaceless_context");
if (!surfaceless_supported)
DEBUG("EGL doesn't support surfaceless context");
s_egl.eglBindAPI(EGL_OPENGL_ES_API);
// If GLES2 plugin was loaded - try to make GLES2 context and
......@@ -201,24 +206,27 @@ bool Renderer::initialize(EGLNativeDisplayType nativeDisplay) {
// The main purpose of it is to solve a "blanking" behaviour we see on
// on Mac platform when switching binded drawable for a context however
// it is more efficient on other platforms as well.
m_pbufContext = s_egl.eglCreateContext(
m_eglDisplay, m_eglConfig, m_eglContext, glContextAttribs);
m_pbufContext = s_egl.eglCreateContext(m_eglDisplay, m_eglConfig, m_eglContext, glContextAttribs);
if (m_pbufContext == EGL_NO_CONTEXT) {
ERROR("Failed to create pbuffer context: error=0x%x", s_egl.eglGetError());
free(gles1Extensions);
return false;
}
// Create a 1x1 pbuffer surface which will be used for binding
// the FB context. The FB output will go to a subwindow, if one exist.
static const EGLint pbufAttribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
if (!surfaceless_supported) {
// Create a 1x1 pbuffer surface which will be used for binding
// the FB context. The FB output will go to a subwindow, if one exist.
static const EGLint pbufAttribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
m_pbufSurface = s_egl.eglCreatePbufferSurface(
m_eglDisplay, m_eglConfig, pbufAttribs);
if (m_pbufSurface == EGL_NO_SURFACE) {
ERROR("Failed to create pbuffer surface: error=0x%x", s_egl.eglGetError());
free(gles1Extensions);
return false;
m_pbufSurface = s_egl.eglCreatePbufferSurface(m_eglDisplay, m_eglConfig, pbufAttribs);
if (m_pbufSurface == EGL_NO_SURFACE) {
ERROR("Failed to create pbuffer surface: error=0x%x", s_egl.eglGetError());
free(gles1Extensions);
return false;
}
} else {
DEBUG("Using a surfaceless EGL context");
m_pbufSurface = EGL_NO_SURFACE;
}
// Make the context current
......
/*
* Copyright (C) 2017 Simon Fels <morphis@gravedo.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ANBOX_GRAPHICS_GL_EXTENSIONS_H_
#define ANBOX_GRAPHICS_GL_EXTENSIONS_H_
#include <stdexcept>
#include <string.h>
namespace anbox {
namespace graphics {
class GLExtensions {
public:
GLExtensions(char const* extensions) : extensions{extensions} {
if (!extensions)
throw std::runtime_error("Couldn't get list of GL extensions");
}
bool support(char const* ext) const {
char const* ext_ptr = extensions;
size_t const len = strlen(ext);
while ((ext_ptr = strstr(ext_ptr, ext)) != nullptr) {
if (ext_ptr[len] == ' ' || ext_ptr[len] == '\0')
break;
ext_ptr += len;
}
return ext_ptr != nullptr;
}
char const* raw() { return extensions; }
private:
char const* extensions;
};
} // namespace graphics
} // namespace anbox
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册