[linux] Implement EGL headless backend
Original author: Tiago Vignatti <tvignatti@gmail.com> Calling X11 window system is superfluous for headless rendering. This patch implements EGL platform using GBM, which is slightly more simple than the GLX path when using X11. In principle there are no big advantages in terms of performance etc. My motivation behind this was to get in touch with the code and the project. For testing I'm using: $ unset DISPLAY && ./build/linux-x86_64/Debug/mbgl-test v2: rebased patch against the new cmake changes; walk through render node to find a valid one; remove EGLSurface completely cause windows are not needed here.
This commit is contained in:
committed by
Bruno de Oliveira Abinader
parent
50f0f919c3
commit
32b6f2fa03
56
platform/linux/src/headless_display_egl.cpp
Normal file
56
platform/linux/src/headless_display_egl.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class HeadlessDisplay::Impl {
|
||||
public:
|
||||
Impl();
|
||||
~Impl();
|
||||
|
||||
EGLDisplay display = EGL_NO_DISPLAY;
|
||||
EGLConfig config = 0;
|
||||
};
|
||||
|
||||
HeadlessDisplay::Impl::Impl() {
|
||||
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (display == EGL_NO_DISPLAY) {
|
||||
throw std::runtime_error("Failed to obtain a valid EGL display.\n");
|
||||
}
|
||||
|
||||
EGLint major, minor, numConfigs;
|
||||
if (!eglInitialize(display, &major, &minor)) {
|
||||
throw std::runtime_error("eglInitialize() failed.\n");
|
||||
}
|
||||
|
||||
// This shouldn't matter as we're rendering to a framebuffer.
|
||||
const EGLint attribs[] = { EGL_NONE };
|
||||
if (!eglChooseConfig(display, attribs, &config, 1, &numConfigs) || numConfigs != 1) {
|
||||
throw std::runtime_error("Failed to choose ARGB config.\n");
|
||||
}
|
||||
}
|
||||
|
||||
HeadlessDisplay::Impl::~Impl() {
|
||||
eglTerminate(display);
|
||||
}
|
||||
|
||||
template <>
|
||||
EGLDisplay HeadlessDisplay::attribute() const {
|
||||
return impl->display;
|
||||
}
|
||||
|
||||
template <>
|
||||
EGLConfig& HeadlessDisplay::attribute() const {
|
||||
return impl->config;
|
||||
}
|
||||
|
||||
HeadlessDisplay::HeadlessDisplay()
|
||||
: impl(std::make_unique<Impl>()) {
|
||||
}
|
||||
|
||||
HeadlessDisplay::~HeadlessDisplay() {
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user