GLContextEGLLibWPE.cpp [plain text]
#include "config.h"
#include "GLContextEGL.h"
#if USE(EGL) && USE(WPE_RENDERER)
#include "PlatformDisplayLibWPE.h"
#if USE(LIBEPOXY)
#define __GBM__ 1
#include "EpoxyEGL.h"
#else
#if PLATFORM(WAYLAND)
#include <wayland-egl.h>
#endif
#include <EGL/egl.h>
#endif
#include <wpe/wpe-egl.h>
namespace WebCore {
GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, struct wpe_renderer_backend_egl_offscreen_target* target)
: GLContext(display)
, m_context(context)
, m_surface(surface)
, m_type(WindowSurface)
, m_wpeTarget(target)
{
}
EGLSurface GLContextEGL::createWindowSurfaceWPE(EGLDisplay display, EGLConfig config, GLNativeWindowType window)
{
return eglCreateWindowSurface(display, config, reinterpret_cast<EGLNativeWindowType>(window), nullptr);
}
std::unique_ptr<GLContextEGL> GLContextEGL::createWPEContext(PlatformDisplay& platformDisplay, EGLContext sharingContext)
{
EGLDisplay display = platformDisplay.eglDisplay();
EGLConfig config;
if (!getEGLConfig(display, &config, WindowSurface)) {
WTFLogAlways("Cannot obtain EGL WPE context configuration: %s\n", lastErrorString());
return nullptr;
}
auto* target = wpe_renderer_backend_egl_offscreen_target_create();
if (!target)
return nullptr;
wpe_renderer_backend_egl_offscreen_target_initialize(target, downcast<PlatformDisplayLibWPE>(platformDisplay).backend());
EGLNativeWindowType window = wpe_renderer_backend_egl_offscreen_target_get_native_window(target);
if (!window) {
wpe_renderer_backend_egl_offscreen_target_destroy(target);
return nullptr;
}
EGLContext context = createContextForEGLVersion(platformDisplay, config, sharingContext);
if (context == EGL_NO_CONTEXT) {
WTFLogAlways("Cannot create EGL WPE context: %s\n", lastErrorString());
wpe_renderer_backend_egl_offscreen_target_destroy(target);
return nullptr;
}
EGLSurface surface = eglCreateWindowSurface(display, config, static_cast<EGLNativeWindowType>(window), nullptr);
if (surface == EGL_NO_SURFACE) {
WTFLogAlways("Cannot create EGL WPE window surface: %s\n", lastErrorString());
eglDestroyContext(display, context);
wpe_renderer_backend_egl_offscreen_target_destroy(target);
return nullptr;
}
return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, target));
}
void GLContextEGL::destroyWPETarget()
{
if (m_wpeTarget)
wpe_renderer_backend_egl_offscreen_target_destroy(m_wpeTarget);
}
}
#endif // USE(EGL) && USE(WPE_RENDERER)