| 1 | /* |
| 2 | * Copyright (C) 2012 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 |
| 16 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #pragma once |
| 21 | |
| 22 | #if USE(EGL) |
| 23 | |
| 24 | #include "GLContext.h" |
| 25 | |
| 26 | #if PLATFORM(X11) |
| 27 | #include "XUniqueResource.h" |
| 28 | #endif |
| 29 | |
| 30 | #if PLATFORM(WAYLAND) |
| 31 | #include "WlUniquePtr.h" |
| 32 | struct wl_egl_window; |
| 33 | #endif |
| 34 | |
| 35 | #if USE(LIBWPE) |
| 36 | struct wpe_renderer_backend_egl_offscreen_target; |
| 37 | #endif |
| 38 | |
| 39 | typedef void *EGLConfig; |
| 40 | typedef void *EGLContext; |
| 41 | typedef void *EGLDisplay; |
| 42 | typedef void *EGLSurface; |
| 43 | |
| 44 | namespace WebCore { |
| 45 | |
| 46 | class GLContextEGL final : public GLContext { |
| 47 | WTF_MAKE_NONCOPYABLE(GLContextEGL); |
| 48 | public: |
| 49 | static std::unique_ptr<GLContextEGL> createContext(GLNativeWindowType, PlatformDisplay&); |
| 50 | static std::unique_ptr<GLContextEGL> createSharingContext(PlatformDisplay&); |
| 51 | |
| 52 | static const char* errorString(int statusCode); |
| 53 | static const char* lastErrorString(); |
| 54 | |
| 55 | virtual ~GLContextEGL(); |
| 56 | |
| 57 | private: |
| 58 | static EGLContext createContextForEGLVersion(PlatformDisplay&, EGLConfig, EGLContext); |
| 59 | |
| 60 | bool makeContextCurrent() override; |
| 61 | void swapBuffers() override; |
| 62 | void waitNative() override; |
| 63 | bool canRenderToDefaultFramebuffer() override; |
| 64 | IntSize defaultFrameBufferSize() override; |
| 65 | void swapInterval(int) override; |
| 66 | #if USE(CAIRO) |
| 67 | cairo_device_t* cairoDevice() override; |
| 68 | #endif |
| 69 | bool isEGLContext() const override { return true; } |
| 70 | |
| 71 | #if ENABLE(GRAPHICS_CONTEXT_3D) |
| 72 | PlatformGraphicsContext3D platformContext() override; |
| 73 | #endif |
| 74 | |
| 75 | enum EGLSurfaceType { PbufferSurface, WindowSurface, PixmapSurface, Surfaceless }; |
| 76 | |
| 77 | GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, EGLSurfaceType); |
| 78 | #if PLATFORM(X11) |
| 79 | GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, XUniquePixmap&&); |
| 80 | #endif |
| 81 | #if PLATFORM(WAYLAND) |
| 82 | GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, WlUniquePtr<struct wl_surface>&&, struct wl_egl_window*); |
| 83 | void destroyWaylandWindow(); |
| 84 | #endif |
| 85 | #if USE(LIBWPE) |
| 86 | GLContextEGL(PlatformDisplay&, EGLContext, EGLSurface, struct wpe_renderer_backend_egl_offscreen_target*); |
| 87 | void destroyWPETarget(); |
| 88 | #endif |
| 89 | |
| 90 | static std::unique_ptr<GLContextEGL> createWindowContext(GLNativeWindowType, PlatformDisplay&, EGLContext sharingContext = nullptr); |
| 91 | static std::unique_ptr<GLContextEGL> createPbufferContext(PlatformDisplay&, EGLContext sharingContext = nullptr); |
| 92 | static std::unique_ptr<GLContextEGL> createSurfacelessContext(PlatformDisplay&, EGLContext sharingContext = nullptr); |
| 93 | #if PLATFORM(X11) |
| 94 | static std::unique_ptr<GLContextEGL> createPixmapContext(PlatformDisplay&, EGLContext sharingContext = nullptr); |
| 95 | static EGLSurface createWindowSurfaceX11(EGLDisplay, EGLConfig, GLNativeWindowType); |
| 96 | #endif |
| 97 | #if PLATFORM(WAYLAND) |
| 98 | static std::unique_ptr<GLContextEGL> createWaylandContext(PlatformDisplay&, EGLContext sharingContext = nullptr); |
| 99 | static EGLSurface createWindowSurfaceWayland(EGLDisplay, EGLConfig, GLNativeWindowType); |
| 100 | #endif |
| 101 | #if USE(LIBWPE) |
| 102 | static std::unique_ptr<GLContextEGL> createWPEContext(PlatformDisplay&, EGLContext sharingContext = nullptr); |
| 103 | static EGLSurface createWindowSurfaceWPE(EGLDisplay, EGLConfig, GLNativeWindowType); |
| 104 | #endif |
| 105 | |
| 106 | static bool getEGLConfig(EGLDisplay, EGLConfig*, EGLSurfaceType); |
| 107 | |
| 108 | EGLContext m_context { nullptr }; |
| 109 | EGLSurface m_surface { nullptr }; |
| 110 | EGLSurfaceType m_type; |
| 111 | #if PLATFORM(X11) |
| 112 | XUniquePixmap m_pixmap; |
| 113 | #endif |
| 114 | #if PLATFORM(WAYLAND) |
| 115 | WlUniquePtr<struct wl_surface> m_wlSurface; |
| 116 | struct wl_egl_window* m_wlWindow { nullptr }; |
| 117 | #endif |
| 118 | #if USE(LIBWPE) |
| 119 | struct wpe_renderer_backend_egl_offscreen_target* m_wpeTarget { nullptr }; |
| 120 | #endif |
| 121 | #if USE(CAIRO) |
| 122 | cairo_device_t* m_cairoDevice { nullptr }; |
| 123 | #endif |
| 124 | }; |
| 125 | |
| 126 | } // namespace WebCore |
| 127 | |
| 128 | #endif // USE(EGL) |
| 129 | |