| 1 | /* GDK - The GIMP Drawing Kit |
| 2 | * |
| 3 | * gdkglcontext-wayland.c: Wayland specific OpenGL wrappers |
| 4 | * |
| 5 | * Copyright © 2014 Emmanuele Bassi |
| 6 | * Copyright © 2014 Alexander Larsson |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Library General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Library General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Library General Public |
| 19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #include "config.h" |
| 23 | |
| 24 | #include "gdkglcontext-wayland.h" |
| 25 | |
| 26 | #include "gdkdisplay-wayland.h" |
| 27 | #include "gdksurface-wayland.h" |
| 28 | |
| 29 | #include "gdkwaylanddisplay.h" |
| 30 | #include "gdkwaylandglcontext.h" |
| 31 | #include "gdkwaylandsurface.h" |
| 32 | #include "gdkprivate-wayland.h" |
| 33 | |
| 34 | #include "gdk-private.h" |
| 35 | #include "gdksurfaceprivate.h" |
| 36 | #include "gdkprofilerprivate.h" |
| 37 | |
| 38 | #include "gdkintl.h" |
| 39 | |
| 40 | /** |
| 41 | * GdkWaylandGLContext: |
| 42 | * |
| 43 | * The Wayland implementation of `GdkGLContext`. |
| 44 | */ |
| 45 | |
| 46 | G_DEFINE_TYPE (GdkWaylandGLContext, gdk_wayland_gl_context, GDK_TYPE_GL_CONTEXT) |
| 47 | |
| 48 | static void |
| 49 | gdk_wayland_gl_context_begin_frame (GdkDrawContext *draw_context, |
| 50 | gboolean prefers_high_depth, |
| 51 | cairo_region_t *region) |
| 52 | { |
| 53 | gdk_wayland_surface_ensure_wl_egl_window (surface: gdk_draw_context_get_surface (context: draw_context)); |
| 54 | |
| 55 | GDK_DRAW_CONTEXT_CLASS (gdk_wayland_gl_context_parent_class)->begin_frame (draw_context, prefers_high_depth, region); |
| 56 | } |
| 57 | |
| 58 | static void |
| 59 | gdk_wayland_gl_context_end_frame (GdkDrawContext *draw_context, |
| 60 | cairo_region_t *painted) |
| 61 | { |
| 62 | GdkSurface *surface = gdk_draw_context_get_surface (context: draw_context); |
| 63 | |
| 64 | gdk_wayland_surface_sync (surface); |
| 65 | gdk_wayland_surface_request_frame (surface); |
| 66 | |
| 67 | GDK_DRAW_CONTEXT_CLASS (gdk_wayland_gl_context_parent_class)->end_frame (draw_context, painted); |
| 68 | |
| 69 | gdk_wayland_surface_notify_committed (surface); |
| 70 | } |
| 71 | |
| 72 | static void |
| 73 | gdk_wayland_gl_context_class_init (GdkWaylandGLContextClass *klass) |
| 74 | { |
| 75 | GdkDrawContextClass *draw_context_class = GDK_DRAW_CONTEXT_CLASS (klass); |
| 76 | GdkGLContextClass *context_class = GDK_GL_CONTEXT_CLASS (klass); |
| 77 | |
| 78 | draw_context_class->begin_frame = gdk_wayland_gl_context_begin_frame; |
| 79 | draw_context_class->end_frame = gdk_wayland_gl_context_end_frame; |
| 80 | |
| 81 | context_class->backend_type = GDK_GL_EGL; |
| 82 | } |
| 83 | |
| 84 | static void |
| 85 | gdk_wayland_gl_context_init (GdkWaylandGLContext *self) |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * gdk_wayland_display_get_egl_display: |
| 91 | * @display: (type GdkWaylandDisplay): a Wayland display |
| 92 | * |
| 93 | * Retrieves the EGL display connection object for the given GDK display. |
| 94 | * |
| 95 | * Returns: (nullable): the EGL display |
| 96 | * |
| 97 | * Since: 4.4 |
| 98 | */ |
| 99 | gpointer |
| 100 | gdk_wayland_display_get_egl_display (GdkDisplay *display) |
| 101 | { |
| 102 | g_return_val_if_fail (GDK_IS_WAYLAND_DISPLAY (display), NULL); |
| 103 | |
| 104 | return gdk_display_get_egl_display (display); |
| 105 | } |
| 106 | |
| 107 | GdkGLContext * |
| 108 | gdk_wayland_display_init_gl (GdkDisplay *display, |
| 109 | GError **error) |
| 110 | { |
| 111 | GdkWaylandDisplay *self = GDK_WAYLAND_DISPLAY (display); |
| 112 | |
| 113 | if (!gdk_display_init_egl (display, |
| 114 | EGL_PLATFORM_WAYLAND_EXT, |
| 115 | native_display: self->wl_display, |
| 116 | TRUE, |
| 117 | error)) |
| 118 | return NULL; |
| 119 | |
| 120 | return g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT, |
| 121 | first_property_name: "display" , display, |
| 122 | NULL); |
| 123 | } |
| 124 | |
| 125 | |