GLContextEGLX11.cpp [plain text]
#include "config.h"
#include "GLContextEGL.h"
#if USE(EGL) && PLATFORM(X11)
#include "PlatformDisplayX11.h"
#include "XErrorTrapper.h"
#include "XUniquePtr.h"
#include <EGL/egl.h>
#include <X11/Xlib.h>
namespace WebCore {
GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, XUniquePixmap&& pixmap)
: GLContext(display)
, m_context(context)
, m_surface(surface)
, m_type(PixmapSurface)
, m_pixmap(WTFMove(pixmap))
{
}
EGLSurface GLContextEGL::createWindowSurfaceX11(EGLDisplay display, EGLConfig config, GLNativeWindowType window)
{
return eglCreateWindowSurface(display, config, static_cast<EGLNativeWindowType>(window), nullptr);
}
std::unique_ptr<GLContextEGL> GLContextEGL::createPixmapContext(PlatformDisplay& platformDisplay, EGLContext sharingContext)
{
EGLDisplay display = platformDisplay.eglDisplay();
EGLConfig config;
if (!getEGLConfig(display, &config, PixmapSurface))
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;
EGLint visualId;
if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &visualId)) {
eglDestroyContext(display, context);
return nullptr;
}
Display* x11Display = downcast<PlatformDisplayX11>(platformDisplay).native();
XVisualInfo visualInfo;
visualInfo.visualid = visualId;
int numVisuals = 0;
XUniquePtr<XVisualInfo> visualInfoList(XGetVisualInfo(x11Display, VisualIDMask, &visualInfo, &numVisuals));
if (!visualInfoList || !numVisuals) {
eglDestroyContext(display, context);
return nullptr;
}
ASSERT(numVisuals == 1);
XUniquePixmap pixmap = XCreatePixmap(x11Display, DefaultRootWindow(x11Display), 1, 1, visualInfoList.get()[0].depth);
if (!pixmap) {
eglDestroyContext(display, context);
return nullptr;
}
XErrorTrapper trapper(x11Display, XErrorTrapper::Policy::Warn, { BadDrawable });
EGLSurface surface = eglCreatePixmapSurface(display, config, reinterpret_cast<EGLNativePixmapType>(pixmap.get()), 0);
if (surface == EGL_NO_SURFACE) {
eglDestroyContext(display, context);
return nullptr;
}
return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, WTFMove(pixmap)));
}
}
#endif // USE(EGL) && PLATFORM(X11)