summaryrefslogtreecommitdiff
path: root/Source/WebCore/platform/graphics/egl/GLContextEGLWayland.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/platform/graphics/egl/GLContextEGLWayland.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/platform/graphics/egl/GLContextEGLWayland.cpp')
-rw-r--r--Source/WebCore/platform/graphics/egl/GLContextEGLWayland.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/Source/WebCore/platform/graphics/egl/GLContextEGLWayland.cpp b/Source/WebCore/platform/graphics/egl/GLContextEGLWayland.cpp
new file mode 100644
index 000000000..a0ed56fd9
--- /dev/null
+++ b/Source/WebCore/platform/graphics/egl/GLContextEGLWayland.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2016 Igalia, S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "GLContextEGL.h"
+
+#if USE(EGL) && PLATFORM(WAYLAND)
+
+#include "PlatformDisplayWayland.h"
+// These includes need to be in this order because wayland-egl.h defines WL_EGL_PLATFORM
+// and egl.h checks that to decide whether it's Wayland platform.
+#include <wayland-egl.h>
+#include <EGL/egl.h>
+
+namespace WebCore {
+
+GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, WlUniquePtr<struct wl_surface>&& wlSurface, struct wl_egl_window* wlWindow)
+ : GLContext(display)
+ , m_context(context)
+ , m_surface(surface)
+ , m_type(WindowSurface)
+ , m_wlSurface(WTFMove(wlSurface))
+ , m_wlWindow(wlWindow)
+{
+}
+
+EGLSurface GLContextEGL::createWindowSurfaceWayland(EGLDisplay display, EGLConfig config, GLNativeWindowType window)
+{
+ return eglCreateWindowSurface(display, config, reinterpret_cast<EGLNativeWindowType>(window), nullptr);
+}
+
+std::unique_ptr<GLContextEGL> GLContextEGL::createWaylandContext(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;
+
+ WlUniquePtr<struct wl_surface> wlSurface(downcast<PlatformDisplayWayland>(platformDisplay).createSurface());
+ if (!wlSurface) {
+ eglDestroyContext(display, context);
+ return nullptr;
+ }
+
+ EGLNativeWindowType window = wl_egl_window_create(wlSurface.get(), 1, 1);
+ EGLSurface surface = eglCreateWindowSurface(display, config, window, 0);
+ if (surface == EGL_NO_SURFACE) {
+ eglDestroyContext(display, context);
+ wl_egl_window_destroy(window);
+ return nullptr;
+ }
+
+ return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, WTFMove(wlSurface), window));
+}
+
+void GLContextEGL::destroyWaylandWindow()
+{
+ if (m_wlWindow)
+ wl_egl_window_destroy(m_wlWindow);
+}
+
+} // namespace WebCore
+
+#endif // USE(EGL) && PLATFORM(WAYLAND)