Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame^] | 1 | From 4a0716f04fb25b51b08e994bd5a900b2e7f7fed5 Mon Sep 17 00:00:00 2001 |
| 2 | From: Jussi Kukkonen <jussi.kukkonen@intel.com> |
| 3 | Date: Fri, 16 Oct 2015 16:35:16 +0300 |
| 4 | Subject: [PATCH] Do not try to initialize GL without libGL |
| 5 | |
| 6 | _gdk_x11_screen_update_visuals_for_gl() will end up calling epoxys |
| 7 | GLX api which will exit() if libGL.so.1 is not present. We do not |
| 8 | want that to happen and we don't want every app to have to set |
| 9 | "GDK_GL=disabled" environment variable: so use #ifdef set based on |
| 10 | opengl distro feature. |
| 11 | |
| 12 | Upstream is not interested in the fix as it is: Either epoxy should be |
| 13 | fixed (to not exit) or GTK+ possibly could do some additional probing |
| 14 | before calling epoxy APIs. |
| 15 | |
| 16 | Upstream-Status: Denied |
| 17 | Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com> |
| 18 | --- |
| 19 | demos/gtk-demo/meson.build | 5 ++++- |
| 20 | docs/tools/meson.build | 7 +++++-- |
| 21 | docs/tools/widgets.c | 6 +++++- |
| 22 | gdk/gdkconfig.h.meson | 1 + |
| 23 | gdk/gdkdisplay.c | 4 ++++ |
| 24 | gdk/gdkgl.c | 10 ++++++++++ |
| 25 | gdk/gdkglcontext.c | 6 ++++++ |
| 26 | gdk/gdkwindow.c | 13 +++++++++++++ |
| 27 | gdk/meson.build | 8 +++++++- |
| 28 | gdk/x11/gdkdisplay-x11.c | 6 +++++- |
| 29 | gdk/x11/gdkvisual-x11.c | 5 +++++ |
| 30 | gdk/x11/gdkwindow-x11.c | 4 ++++ |
| 31 | gdk/x11/gdkx-autocleanups.h | 2 ++ |
| 32 | gdk/x11/gdkx.h | 2 ++ |
| 33 | gdk/x11/meson.build | 7 +++++-- |
| 34 | gtk/gtkglarea.c | 19 +++++++++++++++++++ |
| 35 | gtk/inspector/general.c | 6 ++++++ |
| 36 | meson.build | 17 ++++++++++++++--- |
| 37 | meson_options.txt | 2 ++ |
| 38 | tests/meson.build | 9 +++++++-- |
| 39 | testsuite/gtk/objects-finalize.c | 2 ++ |
| 40 | 21 files changed, 128 insertions(+), 13 deletions(-) |
| 41 | |
| 42 | diff --git a/demos/gtk-demo/meson.build b/demos/gtk-demo/meson.build |
| 43 | index 252da16d05..4b57cff6ac 100644 |
| 44 | --- a/demos/gtk-demo/meson.build |
| 45 | +++ b/demos/gtk-demo/meson.build |
| 46 | @@ -28,7 +28,6 @@ demos = files([ |
| 47 | 'fishbowl.c', |
| 48 | 'foreigndrawing.c', |
| 49 | 'gestures.c', |
| 50 | - 'glarea.c', |
| 51 | 'headerbar.c', |
| 52 | 'hypertext.c', |
| 53 | 'iconview.c', |
| 54 | @@ -87,6 +86,10 @@ elif harfbuzz_dep.found() and pangoft_dep.found() |
| 55 | gtkdemo_deps += [harfbuzz_dep, pangoft_dep] |
| 56 | endif |
| 57 | |
| 58 | +if opengl_enabled |
| 59 | + demos += files('glarea.c') |
| 60 | +endif |
| 61 | + |
| 62 | if os_unix |
| 63 | demos += files('pagesetup.c') |
| 64 | endif |
| 65 | diff --git a/docs/tools/meson.build b/docs/tools/meson.build |
| 66 | index 05621ee7ed..3d0a333b32 100644 |
| 67 | --- a/docs/tools/meson.build |
| 68 | +++ b/docs/tools/meson.build |
| 69 | @@ -2,10 +2,13 @@ if x11_enabled |
| 70 | doc_shooter_sources = [ |
| 71 | 'shadow.c', |
| 72 | 'shooter.c', |
| 73 | - 'widgets.c', |
| 74 | - '../../tests/gtkgears.c', |
| 75 | + 'widgets.c' |
| 76 | ] |
| 77 | |
| 78 | + if opengl_enabled |
| 79 | + doc_shooter_sources += ['../../tests/gtkgears.c'] |
| 80 | + endif |
| 81 | + |
| 82 | doc_shooter = executable('doc-shooter', doc_shooter_sources, |
| 83 | include_directories: [ confinc, gdkinc, gtkinc, testinc, ], |
| 84 | dependencies: libgtk_dep) |
| 85 | diff --git a/docs/tools/widgets.c b/docs/tools/widgets.c |
| 86 | index 932daf1746..348807e133 100644 |
| 87 | --- a/docs/tools/widgets.c |
| 88 | +++ b/docs/tools/widgets.c |
| 89 | @@ -8,7 +8,9 @@ |
| 90 | #include <X11/Xatom.h> |
| 91 | #include <gdkx.h> |
| 92 | #include "widgets.h" |
| 93 | +#ifdef HAVE_OPENGL |
| 94 | #include "gtkgears.h" |
| 95 | +#endif |
| 96 | |
| 97 | #define SMALL_WIDTH 240 |
| 98 | #define SMALL_HEIGHT 75 |
| 99 | @@ -1526,9 +1528,11 @@ create_gl_area (void) |
| 100 | widget = gtk_frame_new (NULL); |
| 101 | gtk_frame_set_shadow_type (GTK_FRAME (widget), GTK_SHADOW_IN); |
| 102 | |
| 103 | +#ifdef HAVE_OPENGL |
| 104 | gears = gtk_gears_new (); |
| 105 | gtk_container_add (GTK_CONTAINER (widget), gears); |
| 106 | - |
| 107 | +#endif |
| 108 | + |
| 109 | info = new_widget_info ("glarea", widget, MEDIUM); |
| 110 | |
| 111 | return info; |
| 112 | diff --git a/gdk/gdkconfig.h.meson b/gdk/gdkconfig.h.meson |
| 113 | index 7db19e0470..088651bafa 100644 |
| 114 | --- a/gdk/gdkconfig.h.meson |
| 115 | +++ b/gdk/gdkconfig.h.meson |
| 116 | @@ -15,6 +15,7 @@ G_BEGIN_DECLS |
| 117 | #mesondefine GDK_WINDOWING_WAYLAND |
| 118 | #mesondefine GDK_WINDOWING_WIN32 |
| 119 | #mesondefine GDK_WINDOWING_QUARTZ |
| 120 | +#mesondefine GDK_WITH_OPENGL |
| 121 | |
| 122 | G_END_DECLS |
| 123 | |
| 124 | diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c |
| 125 | index 748f54860c..04ef2c09d4 100644 |
| 126 | --- a/gdk/gdkdisplay.c |
| 127 | +++ b/gdk/gdkdisplay.c |
| 128 | @@ -2420,7 +2420,11 @@ gboolean |
| 129 | gdk_display_make_gl_context_current (GdkDisplay *display, |
| 130 | GdkGLContext *context) |
| 131 | { |
| 132 | +#ifdef HAVE_OPENGL |
| 133 | return GDK_DISPLAY_GET_CLASS (display)->make_gl_context_current (display, context); |
| 134 | +#else |
| 135 | + return FALSE; |
| 136 | +#endif |
| 137 | } |
| 138 | |
| 139 | GdkRenderingMode |
| 140 | diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c |
| 141 | index 9690077cc2..55f85ef605 100644 |
| 142 | --- a/gdk/gdkgl.c |
| 143 | +++ b/gdk/gdkgl.c |
| 144 | @@ -26,7 +26,9 @@ |
| 145 | # include "win32/gdkwin32.h" |
| 146 | #endif |
| 147 | |
| 148 | +#ifdef HAVE_OPENGL |
| 149 | #include <epoxy/gl.h> |
| 150 | +#endif |
| 151 | #include <math.h> |
| 152 | #include <string.h> |
| 153 | |
| 154 | @@ -40,6 +42,7 @@ gdk_cairo_surface_mark_as_direct (cairo_surface_t *surface, |
| 155 | g_object_ref (window), g_object_unref); |
| 156 | } |
| 157 | |
| 158 | +#ifdef HAVE_OPENGL |
| 159 | static const char * |
| 160 | get_vertex_type_name (int type) |
| 161 | { |
| 162 | @@ -212,6 +215,7 @@ use_texture_rect_program (GdkGLContextPaintData *paint_data) |
| 163 | glUseProgram (paint_data->current_program->program); |
| 164 | } |
| 165 | } |
| 166 | +#endif |
| 167 | |
| 168 | void |
| 169 | gdk_gl_texture_quads (GdkGLContext *paint_context, |
| 170 | @@ -220,6 +224,7 @@ gdk_gl_texture_quads (GdkGLContext *paint_context, |
| 171 | GdkTexturedQuad *quads, |
| 172 | gboolean flip_colors) |
| 173 | { |
| 174 | +#ifdef HAVE_OPENGL |
| 175 | GdkGLContextPaintData *paint_data = gdk_gl_context_get_paint_data (paint_context); |
| 176 | GdkGLContextProgram *program; |
| 177 | GdkWindow *window = gdk_gl_context_get_window (paint_context); |
| 178 | @@ -293,6 +298,7 @@ gdk_gl_texture_quads (GdkGLContext *paint_context, |
| 179 | |
| 180 | glDisableVertexAttribArray (program->position_location); |
| 181 | glDisableVertexAttribArray (program->uv_location); |
| 182 | +#endif |
| 183 | } |
| 184 | |
| 185 | /* x,y,width,height describes a rectangle in the gl render buffer |
| 186 | @@ -341,6 +347,7 @@ gdk_cairo_draw_from_gl (cairo_t *cr, |
| 187 | int width, |
| 188 | int height) |
| 189 | { |
| 190 | +#ifdef HAVE_OPENGL |
| 191 | GdkGLContext *paint_context; |
| 192 | cairo_surface_t *image; |
| 193 | cairo_matrix_t matrix; |
| 194 | @@ -718,6 +725,7 @@ out: |
| 195 | if (clip_region) |
| 196 | cairo_region_destroy (clip_region); |
| 197 | |
| 198 | +#endif |
| 199 | } |
| 200 | |
| 201 | /* This is always called with the paint context current */ |
| 202 | @@ -725,6 +733,7 @@ void |
| 203 | gdk_gl_texture_from_surface (cairo_surface_t *surface, |
| 204 | cairo_region_t *region) |
| 205 | { |
| 206 | +#ifdef HAVE_OPENGL |
| 207 | GdkGLContext *paint_context; |
| 208 | cairo_surface_t *image; |
| 209 | double device_x_offset, device_y_offset; |
| 210 | @@ -825,4 +834,5 @@ gdk_gl_texture_from_surface (cairo_surface_t *surface, |
| 211 | |
| 212 | glDisable (GL_SCISSOR_TEST); |
| 213 | glDeleteTextures (1, &texture_id); |
| 214 | +#endif |
| 215 | } |
| 216 | diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c |
| 217 | index 3b23639e1c..1f04f8e0b2 100644 |
| 218 | --- a/gdk/gdkglcontext.c |
| 219 | +++ b/gdk/gdkglcontext.c |
| 220 | @@ -85,7 +85,9 @@ |
| 221 | #include "gdkintl.h" |
| 222 | #include "gdk-private.h" |
| 223 | |
| 224 | +#ifdef HAVE_OPENGL |
| 225 | #include <epoxy/gl.h> |
| 226 | +#endif |
| 227 | |
| 228 | typedef struct { |
| 229 | GdkDisplay *display; |
| 230 | @@ -243,6 +245,7 @@ gdk_gl_context_upload_texture (GdkGLContext *context, |
| 231 | int height, |
| 232 | guint texture_target) |
| 233 | { |
| 234 | +#ifdef HAVE_OPENGL |
| 235 | GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context); |
| 236 | |
| 237 | g_return_if_fail (GDK_IS_GL_CONTEXT (context)); |
| 238 | @@ -286,6 +289,7 @@ gdk_gl_context_upload_texture (GdkGLContext *context, |
| 239 | glTexSubImage2D (texture_target, 0, 0, i, width, 1, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (unsigned char*) data + (i * stride)); |
| 240 | } |
| 241 | } |
| 242 | +#endif |
| 243 | } |
| 244 | |
| 245 | static gboolean |
| 246 | @@ -774,6 +778,7 @@ gdk_gl_context_realize (GdkGLContext *context, |
| 247 | static void |
| 248 | gdk_gl_context_check_extensions (GdkGLContext *context) |
| 249 | { |
| 250 | +#ifdef HAVE_OPENGL |
| 251 | GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context); |
| 252 | gboolean has_npot, has_texture_rectangle; |
| 253 | |
| 254 | @@ -853,6 +858,7 @@ gdk_gl_context_check_extensions (GdkGLContext *context) |
| 255 | priv->use_texture_rectangle ? "yes" : "no")); |
| 256 | |
| 257 | priv->extensions_checked = TRUE; |
| 258 | +#endif |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c |
| 263 | index 727b0cf1f4..d4d91b0d16 100644 |
| 264 | --- a/gdk/gdkwindow.c |
| 265 | +++ b/gdk/gdkwindow.c |
| 266 | @@ -45,7 +45,9 @@ |
| 267 | |
| 268 | #include <math.h> |
| 269 | |
| 270 | +#ifdef HAVE_OPENGL |
| 271 | #include <epoxy/gl.h> |
| 272 | +#endif |
| 273 | |
| 274 | /* for the use of round() */ |
| 275 | #include "fallback-c89.c" |
| 276 | @@ -2844,6 +2846,13 @@ gdk_window_get_paint_gl_context (GdkWindow *window, |
| 277 | { |
| 278 | GError *internal_error = NULL; |
| 279 | |
| 280 | +#ifndef HAVE_OPENGL |
| 281 | + g_set_error_literal (error, GDK_GL_ERROR, |
| 282 | + GDK_GL_ERROR_NOT_AVAILABLE, |
| 283 | + _("GL support disabled with --disable-opengl")); |
| 284 | + return NULL; |
| 285 | +#endif |
| 286 | + |
| 287 | if (_gdk_gl_flags & GDK_GL_DISABLE) |
| 288 | { |
| 289 | g_set_error_literal (error, GDK_GL_ERROR, |
| 290 | @@ -2979,6 +2988,7 @@ gdk_window_begin_paint_internal (GdkWindow *window, |
| 291 | } |
| 292 | else |
| 293 | { |
| 294 | +#ifdef HAVE_OPENGL |
| 295 | gdk_gl_context_make_current (context); |
| 296 | /* With gl we always need a surface to combine the gl |
| 297 | drawing with the native drawing. */ |
| 298 | @@ -2993,6 +3003,7 @@ gdk_window_begin_paint_internal (GdkWindow *window, |
| 299 | glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 300 | |
| 301 | glViewport (0, 0, ww, wh); |
| 302 | +#endif |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | @@ -3056,6 +3067,7 @@ gdk_window_end_paint_internal (GdkWindow *window) |
| 307 | |
| 308 | gdk_gl_context_make_current (window->gl_paint_context); |
| 309 | |
| 310 | +#ifdef HAVE_OPENGL |
| 311 | if (!cairo_region_is_empty (opaque_region)) |
| 312 | gdk_gl_texture_from_surface (window->current_paint.surface, |
| 313 | opaque_region); |
| 314 | @@ -3066,6 +3078,7 @@ gdk_window_end_paint_internal (GdkWindow *window) |
| 315 | window->current_paint.need_blend_region); |
| 316 | glDisable(GL_BLEND); |
| 317 | } |
| 318 | +#endif |
| 319 | |
| 320 | cairo_region_destroy (opaque_region); |
| 321 | |
| 322 | diff --git a/gdk/meson.build b/gdk/meson.build |
| 323 | index 4bb1bf2b6c..64172b8d3e 100644 |
| 324 | --- a/gdk/meson.build |
| 325 | +++ b/gdk/meson.build |
| 326 | @@ -56,7 +56,6 @@ gdk_gir_public_headers = files( |
| 327 | 'gdkdrawingcontext.h', |
| 328 | 'gdkevents.h', |
| 329 | 'gdkframetimings.h', |
| 330 | - 'gdkglcontext.h', |
| 331 | 'gdkkeys.h', |
| 332 | 'gdkkeysyms.h', |
| 333 | 'gdkmain.h', |
| 334 | @@ -78,6 +77,12 @@ gdk_gir_public_headers = files( |
| 335 | 'gdkwindow.h', |
| 336 | ) |
| 337 | gdk_nogir_public_headers = [files('gdkkeysyms-compat.h')] |
| 338 | +if opengl_enabled |
| 339 | +gdk_gir_public_headers += files('gdkglcontext.h') |
| 340 | +else |
| 341 | +gdk_nogir_public_headers += files('gdkglcontext.h') |
| 342 | +endif |
| 343 | + |
| 344 | gdk_public_headers = gdk_gir_public_headers + gdk_nogir_public_headers |
| 345 | install_headers(gdk_public_headers, subdir : 'gtk-3.0/gdk') |
| 346 | |
| 347 | @@ -166,6 +171,7 @@ gdkconfig_cdata.set('GDK_WINDOWING_WAYLAND', wayland_enabled) |
| 348 | gdkconfig_cdata.set('GDK_WINDOWING_WIN32', win32_enabled) |
| 349 | gdkconfig_cdata.set('GDK_WINDOWING_BROADWAY', broadway_enabled) |
| 350 | gdkconfig_cdata.set('GDK_WINDOWING_QUARTZ', quartz_enabled) |
| 351 | +gdkconfig_cdata.set('GDK_WITH_OPENGL', opengl_enabled) |
| 352 | |
| 353 | gdkconfig = configure_file( |
| 354 | input : 'gdkconfig.h.meson', |
| 355 | diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c |
| 356 | index 7e08f472cc..30fd7b6089 100644 |
| 357 | --- a/gdk/x11/gdkdisplay-x11.c |
| 358 | +++ b/gdk/x11/gdkdisplay-x11.c |
| 359 | @@ -37,7 +37,9 @@ |
| 360 | #include "gdkdisplay-x11.h" |
| 361 | #include "gdkprivate-x11.h" |
| 362 | #include "gdkscreen-x11.h" |
| 363 | +#ifdef HAVE_OPENGL |
| 364 | #include "gdkglcontext-x11.h" |
| 365 | +#endif |
| 366 | #include "gdk-private.h" |
| 367 | #include "gdkprofilerprivate.h" |
| 368 | |
| 369 | @@ -3191,7 +3193,9 @@ gdk_x11_display_class_init (GdkX11DisplayClass * class) |
| 370 | display_class->text_property_to_utf8_list = _gdk_x11_display_text_property_to_utf8_list; |
| 371 | display_class->utf8_to_string_target = _gdk_x11_display_utf8_to_string_target; |
| 372 | |
| 373 | - display_class->make_gl_context_current = gdk_x11_display_make_gl_context_current; |
| 374 | +#ifdef HAVE_OPENGL |
| 375 | + display_class->make_gl_context_current = gdk_x11_display_make_gl_context_current; |
| 376 | +#endif |
| 377 | |
| 378 | display_class->get_default_seat = gdk_x11_display_get_default_seat; |
| 379 | |
| 380 | diff --git a/gdk/x11/gdkvisual-x11.c b/gdk/x11/gdkvisual-x11.c |
| 381 | index 81479d81f4..3c8c5c02ff 100644 |
| 382 | --- a/gdk/x11/gdkvisual-x11.c |
| 383 | +++ b/gdk/x11/gdkvisual-x11.c |
| 384 | @@ -306,7 +306,12 @@ _gdk_x11_screen_init_visuals (GdkScreen *screen) |
| 385 | /* If GL is available we want to pick better default/rgba visuals, |
| 386 | as we care about glx details such as alpha/depth/stencil depth, |
| 387 | stereo and double buffering */ |
| 388 | + /* update_visuals_for_gl() will end up calling epoxy GLX api which |
| 389 | + will exit if libgl is not there: so only do this if we know GL |
| 390 | + is available */ |
| 391 | +#ifdef HAVE_GLX |
| 392 | _gdk_x11_screen_update_visuals_for_gl (screen); |
| 393 | +#endif |
| 394 | } |
| 395 | |
| 396 | gint |
| 397 | diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c |
| 398 | index 194bc82e29..0302bb68d4 100644 |
| 399 | --- a/gdk/x11/gdkwindow-x11.c |
| 400 | +++ b/gdk/x11/gdkwindow-x11.c |
| 401 | @@ -36,7 +36,9 @@ |
| 402 | #include "gdkasync.h" |
| 403 | #include "gdkeventsource.h" |
| 404 | #include "gdkdisplay-x11.h" |
| 405 | +#ifdef HAVE_OPENGL |
| 406 | #include "gdkglcontext-x11.h" |
| 407 | +#endif |
| 408 | #include "gdkprivate-x11.h" |
| 409 | #include "gdk-private.h" |
| 410 | |
| 411 | @@ -5888,7 +5890,9 @@ gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass) |
| 412 | impl_class->set_opaque_region = gdk_x11_window_set_opaque_region; |
| 413 | impl_class->set_shadow_width = gdk_x11_window_set_shadow_width; |
| 414 | impl_class->show_window_menu = gdk_x11_window_show_window_menu; |
| 415 | +#ifdef HAVE_OPENGL |
| 416 | impl_class->create_gl_context = gdk_x11_window_create_gl_context; |
| 417 | impl_class->invalidate_for_new_frame = gdk_x11_window_invalidate_for_new_frame; |
| 418 | +#endif |
| 419 | impl_class->get_unscaled_size = gdk_x11_window_get_unscaled_size; |
| 420 | } |
| 421 | diff --git a/gdk/x11/gdkx-autocleanups.h b/gdk/x11/gdkx-autocleanups.h |
| 422 | index edb0ea7dbf..a317d61cca 100644 |
| 423 | --- a/gdk/x11/gdkx-autocleanups.h |
| 424 | +++ b/gdk/x11/gdkx-autocleanups.h |
| 425 | @@ -30,7 +30,9 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11DeviceXI2, g_object_unref) |
| 426 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Display, g_object_unref) |
| 427 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11DisplayManager, g_object_unref) |
| 428 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11DragContext, g_object_unref) |
| 429 | +#ifdef HAVE_OPENGL |
| 430 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11GLContext, g_object_unref) |
| 431 | +#endif |
| 432 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Keymap, g_object_unref) |
| 433 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Screen, g_object_unref) |
| 434 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Visual, g_object_unref) |
| 435 | diff --git a/gdk/x11/gdkx.h b/gdk/x11/gdkx.h |
| 436 | index 1f64bccb6d..4db6c18351 100644 |
| 437 | --- a/gdk/x11/gdkx.h |
| 438 | +++ b/gdk/x11/gdkx.h |
| 439 | @@ -43,7 +43,9 @@ |
| 440 | #include <gdk/x11/gdkx11display.h> |
| 441 | #include <gdk/x11/gdkx11displaymanager.h> |
| 442 | #include <gdk/x11/gdkx11dnd.h> |
| 443 | +#ifdef GDK_WITH_OPENGL |
| 444 | #include <gdk/x11/gdkx11glcontext.h> |
| 445 | +#endif |
| 446 | #include <gdk/x11/gdkx11keys.h> |
| 447 | #include <gdk/x11/gdkx11monitor.h> |
| 448 | #include <gdk/x11/gdkx11property.h> |
| 449 | diff --git a/gdk/x11/meson.build b/gdk/x11/meson.build |
| 450 | index 754ae0a615..0318c83877 100644 |
| 451 | --- a/gdk/x11/meson.build |
| 452 | +++ b/gdk/x11/meson.build |
| 453 | @@ -14,7 +14,6 @@ gdk_x11_sources = files( |
| 454 | 'gdkeventsource.c', |
| 455 | 'gdkeventtranslator.c', |
| 456 | 'gdkgeometry-x11.c', |
| 457 | - 'gdkglcontext-x11.c', |
| 458 | 'gdkkeys-x11.c', |
| 459 | 'gdkmain-x11.c', |
| 460 | 'gdkproperty-x11.c', |
| 461 | @@ -42,7 +41,6 @@ gdk_x11_public_headers = files( |
| 462 | 'gdkx11display.h', |
| 463 | 'gdkx11displaymanager.h', |
| 464 | 'gdkx11dnd.h', |
| 465 | - 'gdkx11glcontext.h', |
| 466 | 'gdkx11keys.h', |
| 467 | 'gdkx11monitor.h', |
| 468 | 'gdkx11property.h', |
| 469 | @@ -53,6 +51,11 @@ gdk_x11_public_headers = files( |
| 470 | 'gdkx11window.h', |
| 471 | ) |
| 472 | |
| 473 | +if opengl_enabled |
| 474 | + gdk_x11_sources += files('gdkglcontext-x11.c') |
| 475 | + gdk_x11_public_headers += files('gdkx11glcontext.h') |
| 476 | +endif |
| 477 | + |
| 478 | install_headers(gdk_x11_public_headers, subdir: 'gtk-3.0/gdk/x11/') |
| 479 | install_headers('gdkx.h', subdir: 'gtk-3.0/gdk/') |
| 480 | |
| 481 | diff --git a/gtk/gtkglarea.c b/gtk/gtkglarea.c |
| 482 | index 802303ea9f..6439d7745d 100644 |
| 483 | --- a/gtk/gtkglarea.c |
| 484 | +++ b/gtk/gtkglarea.c |
| 485 | @@ -29,7 +29,9 @@ |
| 486 | #include "gtkprivate.h" |
| 487 | #include "gtkrender.h" |
| 488 | |
| 489 | +#ifdef HAVE_OPENGL |
| 490 | #include <epoxy/gl.h> |
| 491 | +#endif |
| 492 | |
| 493 | /** |
| 494 | * SECTION:gtkglarea |
| 495 | @@ -369,9 +371,12 @@ gtk_gl_area_real_create_context (GtkGLArea *area) |
| 496 | static void |
| 497 | gtk_gl_area_resize (GtkGLArea *area, int width, int height) |
| 498 | { |
| 499 | +#ifdef HAVE_OPENGL |
| 500 | glViewport (0, 0, width, height); |
| 501 | +#endif |
| 502 | } |
| 503 | |
| 504 | +#ifdef HAVE_OPENGL |
| 505 | /* |
| 506 | * Creates all the buffer objects needed for rendering the scene |
| 507 | */ |
| 508 | @@ -483,6 +488,7 @@ gtk_gl_area_allocate_buffers (GtkGLArea *area) |
| 509 | |
| 510 | priv->needs_render = TRUE; |
| 511 | } |
| 512 | +#endif |
| 513 | |
| 514 | /** |
| 515 | * gtk_gl_area_attach_buffers: |
| 516 | @@ -501,6 +507,7 @@ gtk_gl_area_allocate_buffers (GtkGLArea *area) |
| 517 | void |
| 518 | gtk_gl_area_attach_buffers (GtkGLArea *area) |
| 519 | { |
| 520 | +#ifdef HAVE_OPENGL |
| 521 | GtkGLAreaPrivate *priv = gtk_gl_area_get_instance_private (area); |
| 522 | |
| 523 | g_return_if_fail (GTK_IS_GL_AREA (area)); |
| 524 | @@ -533,11 +540,13 @@ gtk_gl_area_attach_buffers (GtkGLArea *area) |
| 525 | glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, |
| 526 | GL_RENDERBUFFER, priv->depth_stencil_buffer); |
| 527 | } |
| 528 | +#endif |
| 529 | } |
| 530 | |
| 531 | static void |
| 532 | gtk_gl_area_delete_buffers (GtkGLArea *area) |
| 533 | { |
| 534 | +#ifdef HAVE_OPENGL |
| 535 | GtkGLAreaPrivate *priv = gtk_gl_area_get_instance_private (area); |
| 536 | |
| 537 | if (priv->context == NULL) |
| 538 | @@ -569,6 +578,7 @@ gtk_gl_area_delete_buffers (GtkGLArea *area) |
| 539 | glDeleteFramebuffers (1, &priv->frame_buffer); |
| 540 | priv->frame_buffer = 0; |
| 541 | } |
| 542 | +#endif |
| 543 | } |
| 544 | |
| 545 | static void |
| 546 | @@ -679,6 +689,7 @@ gtk_gl_area_draw (GtkWidget *widget, |
| 547 | GtkGLArea *area = GTK_GL_AREA (widget); |
| 548 | GtkGLAreaPrivate *priv = gtk_gl_area_get_instance_private (area); |
| 549 | gboolean unused; |
| 550 | +#ifdef HAVE_OPENGL |
| 551 | int w, h, scale; |
| 552 | GLenum status; |
| 553 | |
| 554 | @@ -736,6 +747,14 @@ gtk_gl_area_draw (GtkWidget *widget, |
| 555 | } |
| 556 | |
| 557 | return TRUE; |
| 558 | +#else |
| 559 | + if (priv->error != NULL) |
| 560 | + gtk_gl_area_draw_error_screen (area, |
| 561 | + cr, |
| 562 | + gtk_widget_get_allocated_width (widget), |
| 563 | + gtk_widget_get_allocated_height (widget)); |
| 564 | + return FALSE; |
| 565 | +#endif |
| 566 | } |
| 567 | |
| 568 | static gboolean |
| 569 | diff --git a/gtk/inspector/general.c b/gtk/inspector/general.c |
| 570 | index 4fd0c3039c..a8e59ed077 100644 |
| 571 | --- a/gtk/inspector/general.c |
| 572 | +++ b/gtk/inspector/general.c |
| 573 | @@ -33,8 +33,10 @@ |
| 574 | |
| 575 | #ifdef GDK_WINDOWING_X11 |
| 576 | #include "x11/gdkx.h" |
| 577 | +#ifdef HAVE_OPENGL |
| 578 | #include <epoxy/glx.h> |
| 579 | #endif |
| 580 | +#endif |
| 581 | |
| 582 | #ifdef GDK_WINDOWING_WIN32 |
| 583 | #include "win32/gdkwin32.h" |
| 584 | @@ -217,6 +219,7 @@ add_label_row (GtkInspectorGeneral *gen, |
| 585 | gtk_size_group_add_widget (GTK_SIZE_GROUP (gen->priv->labels), label); |
| 586 | } |
| 587 | |
| 588 | +#ifdef HAVE_OPENGL |
| 589 | #ifdef GDK_WINDOWING_X11 |
| 590 | static void |
| 591 | append_glx_extension_row (GtkInspectorGeneral *gen, |
| 592 | @@ -226,6 +229,7 @@ append_glx_extension_row (GtkInspectorGeneral *gen, |
| 593 | add_check_row (gen, GTK_LIST_BOX (gen->priv->gl_box), ext, epoxy_has_glx_extension (dpy, 0, ext), 0); |
| 594 | } |
| 595 | #endif |
| 596 | +#endif |
| 597 | |
| 598 | #ifdef GDK_WINDOWING_WAYLAND |
| 599 | static void |
| 600 | @@ -275,6 +279,7 @@ wayland_get_display (struct wl_display *wl_display) |
| 601 | static void |
| 602 | init_gl (GtkInspectorGeneral *gen) |
| 603 | { |
| 604 | +#ifdef HAVE_OPENGL |
| 605 | #ifdef GDK_WINDOWING_X11 |
| 606 | if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) |
| 607 | { |
| 608 | @@ -301,6 +306,7 @@ init_gl (GtkInspectorGeneral *gen) |
| 609 | } |
| 610 | else |
| 611 | #endif |
| 612 | +#endif |
| 613 | #ifdef GDK_WINDOWING_WAYLAND |
| 614 | if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ())) |
| 615 | { |
| 616 | diff --git a/meson.build b/meson.build |
| 617 | index aed48fc3f6..bfc33af0f6 100644 |
| 618 | --- a/meson.build |
| 619 | +++ b/meson.build |
| 620 | @@ -137,6 +137,7 @@ wayland_enabled = get_option('wayland_backend') |
| 621 | broadway_enabled = get_option('broadway_backend') |
| 622 | quartz_enabled = get_option('quartz_backend') |
| 623 | win32_enabled = get_option('win32_backend') |
| 624 | +opengl_enabled = get_option('opengl') |
| 625 | |
| 626 | os_unix = false |
| 627 | os_linux = false |
| 628 | @@ -430,7 +431,7 @@ pangocairo_dep = dependency('pangocairo', version: cairo_req, |
| 629 | fallback : ['pango', 'libpangocairo_dep']) |
| 630 | pixbuf_dep = dependency('gdk-pixbuf-2.0', version: gdk_pixbuf_req, |
| 631 | fallback : ['gdk-pixbuf', 'gdkpixbuf_dep']) |
| 632 | -epoxy_dep = dependency('epoxy', version: epoxy_req, |
| 633 | +epoxy_dep = dependency('epoxy', version: epoxy_req, required: opengl_enabled, |
| 634 | fallback: ['libepoxy', 'libepoxy_dep']) |
| 635 | atk_dep = dependency('atk', version: atk_req, |
| 636 | fallback : ['atk', 'libatk_dep']) |
| 637 | @@ -476,6 +477,10 @@ if tracker3_enabled |
| 638 | endif |
| 639 | endif |
| 640 | |
| 641 | +if opengl_enabled |
| 642 | + cdata.set('HAVE_OPENGL', 1) |
| 643 | +endif |
| 644 | + |
| 645 | if iso_codes_dep.found() |
| 646 | cdata.set_quoted('ISO_CODES_PREFIX', iso_codes_dep.get_variable(pkgconfig: 'prefix')) |
| 647 | else |
| 648 | @@ -912,9 +917,15 @@ else |
| 649 | gio_packages = ['gio-2.0', glib_req] |
| 650 | endif |
| 651 | |
| 652 | +if opengl_enabled |
| 653 | + epoxy_packages = ['epoxy', epoxy_req] |
| 654 | +else |
| 655 | + epoxy_packages = [] |
| 656 | +endif |
| 657 | + |
| 658 | pkgconf.set('GDK_PRIVATE_PACKAGES', |
| 659 | ' '.join(gio_packages + x11_pkgs + wayland_pkgs + cairo_backends + |
| 660 | - ['epoxy', epoxy_req] + cloudproviders_packages + |
| 661 | + epoxy_packages + cloudproviders_packages + |
| 662 | ['fribidi', fribidi_req])) |
| 663 | |
| 664 | gtk_packages = ' '.join([ |
| 665 | @@ -928,7 +939,7 @@ pkgconf.set('GTK_PACKAGES', gtk_packages) |
| 666 | # Requires.private |
| 667 | pc_gdk_extra_libs += cairo_libs |
| 668 | |
| 669 | -gtk_private_packages = atk_pkgs + wayland_pkgs + ['epoxy', epoxy_req, 'fribidi', fribidi_req] |
| 670 | +gtk_private_packages = atk_pkgs + wayland_pkgs + epoxy_packages + ['fribidi', fribidi_req] |
| 671 | if wayland_enabled or x11_enabled |
| 672 | gtk_private_packages += ['pangoft2'] |
| 673 | endif |
| 674 | diff --git a/meson_options.txt b/meson_options.txt |
| 675 | index 94099aa01e..8bd096896d 100644 |
| 676 | --- a/meson_options.txt |
| 677 | +++ b/meson_options.txt |
| 678 | @@ -19,6 +19,8 @@ option('profiler', type: 'boolean', value: false, |
| 679 | description : 'Enable profiler support') |
| 680 | option('tracker3', type: 'boolean', value: false, |
| 681 | description : 'Enable Tracker3 filechooser search') |
| 682 | +option('opengl', type: 'boolean', value: true, |
| 683 | + description : 'Enable use of GL') |
| 684 | |
| 685 | # Print backends |
| 686 | option('print_backends', type : 'string', value : 'auto', |
| 687 | diff --git a/tests/meson.build b/tests/meson.build |
| 688 | index 586fe2f45e..6ecf317dde 100644 |
| 689 | --- a/tests/meson.build |
| 690 | +++ b/tests/meson.build |
| 691 | @@ -5,7 +5,6 @@ gtk_tests = [ |
| 692 | ['scrolling-performance', ['frame-stats.c', 'variable.c']], |
| 693 | ['blur-performance', ['../gtk/gtkcairoblur.c']], |
| 694 | ['flicker'], |
| 695 | - ['gdkgears', ['gtkgears.c']], |
| 696 | ['listmodel'], |
| 697 | ['motion-compression'], |
| 698 | ['styleexamples'], |
| 699 | @@ -54,7 +53,6 @@ gtk_tests = [ |
| 700 | ['testfullscreen'], |
| 701 | ['testgeometry'], |
| 702 | ['testgiconpixbuf'], |
| 703 | - ['testglblending', ['gtkgears.c']], |
| 704 | ['testgmenu'], |
| 705 | ['testgrid'], |
| 706 | ['testgrouping'], |
| 707 | @@ -137,6 +135,13 @@ if x11_enabled |
| 708 | ] |
| 709 | endif |
| 710 | |
| 711 | +if opengl_enabled |
| 712 | + gtk_tests += [ |
| 713 | + ['gdkgears', ['gtkgears.c']], |
| 714 | + ['testglblending', ['gtkgears.c']], |
| 715 | + ] |
| 716 | +endif |
| 717 | + |
| 718 | if os_linux |
| 719 | gtk_tests += [['testfontchooserdialog']] |
| 720 | endif |
| 721 | diff --git a/testsuite/gtk/objects-finalize.c b/testsuite/gtk/objects-finalize.c |
| 722 | index 24540e313f..e0f863ab6a 100644 |
| 723 | --- a/testsuite/gtk/objects-finalize.c |
| 724 | +++ b/testsuite/gtk/objects-finalize.c |
| 725 | @@ -116,7 +116,9 @@ main (int argc, char **argv) |
| 726 | all_types[i] != GDK_TYPE_X11_DEVICE_MANAGER_CORE && |
| 727 | all_types[i] != GDK_TYPE_X11_DEVICE_MANAGER_XI2 && |
| 728 | all_types[i] != GDK_TYPE_X11_DISPLAY_MANAGER && |
| 729 | +#ifdef HAVE_OPENGL |
| 730 | all_types[i] != GDK_TYPE_X11_GL_CONTEXT && |
| 731 | +#endif |
| 732 | #endif |
| 733 | /* Not allowed to finalize a GdkPixbufLoader without calling gdk_pixbuf_loader_close() */ |
| 734 | all_types[i] != GDK_TYPE_PIXBUF_LOADER && |
| 735 | -- |
| 736 | 2.30.2 |
| 737 | |