GLContextEGLWPE.cpp [plain text]
#include "config.h"
#include "GLContextEGL.h"
#if USE(EGL) && PLATFORM(WPE)
#include "PlatformDisplayWPE.h"
#define __GBM__ 1
#if USE(LIBEPOXY)
#include <epoxy/egl.h>
#else
#include <EGL/egl.h>
#endif
#include <wpe/renderer-backend-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))
return nullptr;
static const EGLint contextAttributes[] = {
#if USE(OPENGL_ES_2)
EGL_CONTEXT_CLIENT_VERSION, 2,
#endif
EGL_NONE
};
EGLContext context = eglCreateContext(display, config, sharingContext, contextAttributes);
if (context == EGL_NO_CONTEXT)
return nullptr;
auto* target = wpe_renderer_backend_egl_offscreen_target_create();
wpe_renderer_backend_egl_offscreen_target_initialize(target, downcast<PlatformDisplayWPE>(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;
}
EGLSurface surface = eglCreateWindowSurface(display, config, static_cast<EGLNativeWindowType>(window), nullptr);
if (surface == EGL_NO_SURFACE) {
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) && PLATFORM(WPE)