| 1 | /* |
| 2 | * Copyright (C) 2016 Igalia, S.L. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #include "config.h" |
| 20 | #include "GLContextEGL.h" |
| 21 | |
| 22 | #if USE(EGL) && PLATFORM(WAYLAND) |
| 23 | |
| 24 | #include "PlatformDisplayWayland.h" |
| 25 | // These includes need to be in this order because wayland-egl.h defines WL_EGL_PLATFORM |
| 26 | // and egl.h checks that to decide whether it's Wayland platform. |
| 27 | #include <wayland-egl.h> |
| 28 | #include <EGL/egl.h> |
| 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurface surface, WlUniquePtr<struct wl_surface>&& wlSurface, struct wl_egl_window* wlWindow) |
| 33 | : GLContext(display) |
| 34 | , m_context(context) |
| 35 | , m_surface(surface) |
| 36 | , m_type(WindowSurface) |
| 37 | , m_wlSurface(WTFMove(wlSurface)) |
| 38 | , m_wlWindow(wlWindow) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | EGLSurface GLContextEGL::createWindowSurfaceWayland(EGLDisplay display, EGLConfig config, GLNativeWindowType window) |
| 43 | { |
| 44 | return eglCreateWindowSurface(display, config, reinterpret_cast<EGLNativeWindowType>(window), nullptr); |
| 45 | } |
| 46 | |
| 47 | std::unique_ptr<GLContextEGL> GLContextEGL::createWaylandContext(PlatformDisplay& platformDisplay, EGLContext sharingContext) |
| 48 | { |
| 49 | EGLDisplay display = platformDisplay.eglDisplay(); |
| 50 | EGLConfig config; |
| 51 | if (!getEGLConfig(display, &config, WindowSurface)) |
| 52 | return nullptr; |
| 53 | |
| 54 | EGLContext context = createContextForEGLVersion(platformDisplay, config, sharingContext); |
| 55 | if (context == EGL_NO_CONTEXT) |
| 56 | return nullptr; |
| 57 | |
| 58 | WlUniquePtr<struct wl_surface> wlSurface(downcast<PlatformDisplayWayland>(platformDisplay).createSurface()); |
| 59 | if (!wlSurface) { |
| 60 | eglDestroyContext(display, context); |
| 61 | return nullptr; |
| 62 | } |
| 63 | |
| 64 | EGLNativeWindowType window = wl_egl_window_create(wlSurface.get(), 1, 1); |
| 65 | EGLSurface surface = eglCreateWindowSurface(display, config, window, 0); |
| 66 | if (surface == EGL_NO_SURFACE) { |
| 67 | eglDestroyContext(display, context); |
| 68 | wl_egl_window_destroy(window); |
| 69 | return nullptr; |
| 70 | } |
| 71 | |
| 72 | return std::unique_ptr<GLContextEGL>(new GLContextEGL(platformDisplay, context, surface, WTFMove(wlSurface), window)); |
| 73 | } |
| 74 | |
| 75 | void GLContextEGL::destroyWaylandWindow() |
| 76 | { |
| 77 | if (m_wlWindow) |
| 78 | wl_egl_window_destroy(m_wlWindow); |
| 79 | } |
| 80 | |
| 81 | } // namespace WebCore |
| 82 | |
| 83 | #endif // USE(EGL) && PLATFORM(WAYLAND) |
| 84 | |