summaryrefslogtreecommitdiff
path: root/platform/linux
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-11-16 17:43:09 +0100
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2016-11-27 18:50:24 +0200
commite987e406c7864440d02dc634b9d29777f353f21b (patch)
tree32b3a189ea6d45ef130f868c6c9f105564c64b69 /platform/linux
parentc810d16f0d2787f15e06651ea595020415d5a8d5 (diff)
downloadqtlocation-mapboxgl-e987e406c7864440d02dc634b9d29777f353f21b.tar.gz
[android] Use pBuffer for headless EGL backend
Diffstat (limited to 'platform/linux')
-rw-r--r--platform/linux/src/headless_backend_egl.cpp31
-rw-r--r--platform/linux/src/headless_display_egl.cpp11
2 files changed, 36 insertions, 6 deletions
diff --git a/platform/linux/src/headless_backend_egl.cpp b/platform/linux/src/headless_backend_egl.cpp
index 38bd3e0a20..87e7c1d0ed 100644
--- a/platform/linux/src/headless_backend_egl.cpp
+++ b/platform/linux/src/headless_backend_egl.cpp
@@ -10,9 +10,24 @@
namespace mbgl {
struct EGLImpl : public HeadlessBackend::Impl {
- EGLImpl(EGLContext glContext_, EGLDisplay display_)
+ EGLImpl(EGLContext glContext_, EGLDisplay display_, EGLConfig config_)
: glContext(glContext_),
- display(display_) {
+ display(display_),
+ config(config_) {
+#if __ANDROID__
+ // Create a pixel buffer surface (in conjunction with EGL_SURFACE_TYPE, EGL_PBUFFER_BIT).
+ const EGLint surfAttribs[] = {
+ EGL_WIDTH, 512,
+ EGL_HEIGHT, 512,
+ EGL_LARGEST_PBUFFER, EGL_TRUE,
+ EGL_NONE
+ };
+
+ glSurface = eglCreatePbufferSurface(display, config, surfAttribs);
+ if (glSurface == EGL_NO_SURFACE) {
+ throw std::runtime_error("Could not create surface: " + std::to_string(eglGetError()));
+ }
+#endif // __ANDROID__
}
~EGLImpl() {
@@ -22,10 +37,16 @@ struct EGLImpl : public HeadlessBackend::Impl {
if (!eglDestroyContext(display, glContext)) {
throw std::runtime_error("Failed to destroy EGL context.\n");
}
+ if (glSurface != EGL_NO_SURFACE) {
+ if (!eglDestroySurface(display, glSurface)) {
+ throw std::runtime_error("Failed to destroy EGL context.\n");
+ }
+ glSurface = EGL_NO_SURFACE;
+ }
}
void activateContext() final {
- if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, glContext)) {
+ if (!eglMakeCurrent(display, glSurface, glSurface, glContext)) {
throw std::runtime_error("Switching OpenGL context failed.\n");
}
}
@@ -38,6 +59,8 @@ struct EGLImpl : public HeadlessBackend::Impl {
EGLContext glContext = EGL_NO_CONTEXT;
EGLDisplay display = EGL_NO_DISPLAY;
+ EGLConfig config = 0;
+ EGLSurface glSurface = EGL_NO_SURFACE;
};
gl::glProc HeadlessBackend::initializeExtension(const char* name) {
@@ -74,7 +97,7 @@ void HeadlessBackend::createContext() {
throw std::runtime_error("Error creating the EGL context object.\n");
}
- impl.reset(new EGLImpl(glContext, display_));
+ impl.reset(new EGLImpl(glContext, display_, config));
}
} // namespace mbgl
diff --git a/platform/linux/src/headless_display_egl.cpp b/platform/linux/src/headless_display_egl.cpp
index e1ba0aef13..eddc05feaf 100644
--- a/platform/linux/src/headless_display_egl.cpp
+++ b/platform/linux/src/headless_display_egl.cpp
@@ -31,8 +31,15 @@ HeadlessDisplay::Impl::Impl() {
throw std::runtime_error("eglBindAPI() failed");
}
- // This shouldn't matter as we're rendering to a framebuffer.
- const EGLint attribs[] = { EGL_NONE };
+ const EGLint attribs[] = {
+#if __ANDROID__
+ // Android emulator requires a pixel buffer to generate renderable unit
+ // test results.
+ EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
+#endif // __ANDROID__
+ EGL_NONE
+ };
+
if (!eglChooseConfig(display, attribs, &config, 1, &numConfigs) || numConfigs != 1) {
throw std::runtime_error("Failed to choose ARGB config.\n");
}