summaryrefslogtreecommitdiffstats
path: root/meta/recipes-gnome/gtk+/gtk+3/0003-Add-disable-opengl-configure-option.patch
blob: 852dc9dfcd38c99e32665241a36671bbd04fe527 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
From d11b41a7ff0234f3832d6aabdf498807d1463c18 Mon Sep 17 00:00:00 2001
From: Jussi Kukkonen <jussi.kukkonen@intel.com>
Date: Tue, 21 Jun 2016 15:11:39 +0300
Subject: [PATCH] Add --disable-opengl configure option

--disable-opengl will remove the dependency on libepoxy and on the
OpenGL APIs. This is useful for those who want to keep using gtk+3
without the "opengl" distro feature.

GtkGLArea is still part of the API (it just doesn't work) even when
OpenGL is disabled. GdkX11GLContext was removed from the Gtk API
completely: that object exposes GL API elements so it had to be at
the very least modified.

The patch is _not_ great from a maintenance point of view and
modifying the library API is also a fairly nasty thing to do.
Next long term release (4.0) will require alternative solutions
as it actually will depend on OpenGL.

Upstream-Status: Inappropriate [Evil eye expected from upstream]
Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>

---
 configure.ac                               | 13 ++++-
 demos/gtk-demo/glarea.c                    | 14 ++++++
 docs/tools/Makefile.am                     |  9 +++-
 docs/tools/widgets.c                       |  4 +-
 gdk/Makefile.am                            |  8 ++-
 gdk/gdkdisplay.c                           |  4 +-
 gdk/gdkgl.c                                | 10 ++++
 gdk/gdkglcontext.c                         |  6 +++
 gdk/gdkwindow.c                            | 13 +++++
 gdk/x11/Makefile.am                        | 30 +++++++++--
 gdk/x11/gdkdisplay-x11.c                   |  6 ++-
 gdk/x11/gdkscreen-x11.c                    |  5 ++
 gdk/x11/gdkwindow-x11.c                    |  4 ++
 gdk/x11/gdkx-autocleanups.h                |  2 +
 gdk/x11/{gdkx.h => gdkx-with-gl-context.h} |  1 -
 gdk/x11/gdkx-without-gl-context.h          | 58 ++++++++++++++++++++++
 gtk/Makefile.am                            |  3 +-
 gtk/gtkglarea.c                            | 20 +++++++-
 gtk/inspector/general.c                    |  6 +++
 tests/Makefile.am                          | 10 ++--
 testsuite/gtk/objects-finalize.c           |  2 +
 21 files changed, 208 insertions(+), 20 deletions(-)
 rename gdk/x11/{gdkx.h => gdkx-with-gl-context.h} (98%)
 create mode 100644 gdk/x11/gdkx-without-gl-context.h

diff --git a/configure.ac b/configure.ac
index 2c4733b..18ae66c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -352,6 +352,15 @@ AC_ARG_ENABLE(cloudproviders,
               [AS_HELP_STRING([--enable-cloudproviders],
                               [enable libcloudproviders integration])],
                               [cloudproviders_set=yes])
+AC_ARG_ENABLE(opengl,
+              [AS_HELP_STRING([--enable-opengl],
+                              [When enabled, Gtk+ will use libepoxy and exposes GtkGLArea widget ])])
+AS_IF([test "x$enable_opengl" != "xno"], [
+  AC_DEFINE([HAVE_OPENGL], [1], [libepoxy and opengl APIs are available at buildtime])
+  EPOXY_PACKAGES="epoxy >= epoxy_required_version"
+])
+AM_CONDITIONAL([HAVE_OPENGL],[test "x$enable_opengl" != "xno"])
+
 AC_ARG_ENABLE(glx,
               [AS_HELP_STRING([--enable-glx],
                               [When enabled Gdk will try to initialize GLX])])
@@ -1370,7 +1379,7 @@ CFLAGS="$saved_cflags"
 LDFLAGS="$saved_ldflags"
 
 GDK_PACKAGES="$PANGO_PACKAGES gdk-pixbuf-2.0 >= gdk_pixbuf_required_version cairo >= cairo_required_version cairo-gobject >= cairo_required_version"
-GDK_PRIVATE_PACKAGES="$GDK_GIO_PACKAGE $X_PACKAGES $WAYLAND_PACKAGES $MIR_PACKAGES $cairo_backends epoxy >= epoxy_required_version $CLOUDPROVIDER_PACKAGES fribidi >= fribidi_required_version"
+GDK_PRIVATE_PACKAGES="$GDK_GIO_PACKAGE $X_PACKAGES $WAYLAND_PACKAGES $MIR_PACKAGES $cairo_backends $EPOXY_PACKAGES $CLOUDPROVIDER_PACKAGES fribidi >= fribidi_required_version"
 
 PKG_CHECK_MODULES(GDK_DEP, $GDK_PACKAGES $GDK_PRIVATE_PACKAGES)
 GDK_DEP_LIBS="$GDK_EXTRA_LIBS $GDK_DEP_LIBS $MATH_LIB"
@@ -1404,7 +1413,7 @@ fi
 PKG_CHECK_MODULES(ATK, $ATK_PACKAGES)
 
 GTK_PACKAGES="atk >= atk_required_version cairo >= cairo_required_version cairo-gobject >= cairo_required_version gdk-pixbuf-2.0 >= gdk_pixbuf_required_version gio-2.0 >= glib_required_version"
-GTK_PRIVATE_PACKAGES="$ATK_PACKAGES $WAYLAND_PACKAGES $MIR_PACKAGES epoxy >= epoxy_required_version fribidi >= fribidi_required_version"
+GTK_PRIVATE_PACKAGES="$ATK_PACKAGES $WAYLAND_PACKAGES $MIR_PACKAGES $EPOXY_PACKAGES fribidi >= fribidi_required_version"
 if test "x$enable_x11_backend" = xyes -o "x$enable_wayland_backend" = xyes; then
   GTK_PRIVATE_PACKAGES="$GTK_PRIVATE_PACKAGES pangoft2"
 fi
diff --git a/demos/gtk-demo/glarea.c b/demos/gtk-demo/glarea.c
index b51e4ae..82409c7 100644
--- a/demos/gtk-demo/glarea.c
+++ b/demos/gtk-demo/glarea.c
@@ -3,9 +3,12 @@
  * GtkGLArea is a widget that allows custom drawing using OpenGL calls.
  */
 
+#include "config.h"
 #include <math.h>
 #include <gtk/gtk.h>
+#if HAVE_OPENGL
 #include <epoxy/gl.h>
+#endif
 
 static GtkWidget *demo_window = NULL;
 
@@ -23,6 +26,8 @@ enum {
 /* Rotation angles on each axis */
 static float rotation_angles[N_AXIS] = { 0.0 };
 
+#ifdef HAVE_OPENGL
+
 /* The object we are drawing */
 static const GLfloat vertex_data[] = {
   0.f,   0.5f,   0.f, 1.f,
@@ -215,6 +220,7 @@ compute_mvp (float *res,
 static GLuint position_buffer;
 static GLuint program;
 static GLuint mvp_location;
+#endif
 
 /* We need to set up our state when we realize the GtkGLArea widget */
 static void
@@ -241,8 +247,10 @@ realize (GtkWidget *widget)
       fragment_path = "/glarea/glarea-gl.fs.glsl";
     }
 
+#ifdef HAVE_OPENGL
   init_buffers (&position_buffer, NULL);
   init_shaders (vertex_path, fragment_path, &program, &mvp_location);
+#endif
 }
 
 /* We should tear down the state when unrealizing */
@@ -254,10 +262,13 @@ unrealize (GtkWidget *widget)
   if (gtk_gl_area_get_error (GTK_GL_AREA (widget)) != NULL)
     return;
 
+#ifdef HAVE_OPENGL
   glDeleteBuffers (1, &position_buffer);
   glDeleteProgram (program);
+#endif
 }
 
+#ifdef HAVE_OPENGL
 static void
 draw_triangle (void)
 {
@@ -290,6 +301,7 @@ draw_triangle (void)
   glBindBuffer (GL_ARRAY_BUFFER, 0);
   glUseProgram (0);
 }
+#endif
 
 static gboolean
 render (GtkGLArea    *area,
@@ -298,6 +310,7 @@ render (GtkGLArea    *area,
   if (gtk_gl_area_get_error (area) != NULL)
     return FALSE;
 
+#ifdef HAVE_OPENGL
   /* Clear the viewport */
   glClearColor (0.5, 0.5, 0.5, 1.0);
   glClear (GL_COLOR_BUFFER_BIT);
@@ -307,6 +320,7 @@ render (GtkGLArea    *area,
 
   /* Flush the contents of the pipeline */
   glFlush ();
+#endif
 
   return TRUE;
 }
diff --git a/docs/tools/Makefile.am b/docs/tools/Makefile.am
index 6a6d70f..5cdf312 100644
--- a/docs/tools/Makefile.am
+++ b/docs/tools/Makefile.am
@@ -9,13 +9,18 @@ AM_CPPFLAGS = \
 	$(GTK_DEBUG_FLAGS)		\
 	$(GTK_DEP_CFLAGS)
 
+if HAVE_OPENGL
+GEARS_LDADD = $(top_builddir)/tests/gtkgears.o
+endif
+
 DEPS = \
-	$(top_builddir)/gtk/libgtk-3.la
+	$(top_builddir)/gtk/libgtk-3.la	\
+	$(GEARS_LDADD)
 
 LDADDS = \
 	$(top_builddir)/gtk/libgtk-3.la	\
 	$(top_builddir)/gdk/libgdk-3.la	\
-	$(top_builddir)/tests/gtkgears.o \
+	$(GEARS_LDADD)			\
 	$(GTK_DEP_LIBS)			\
 	$(GDK_DEP_LIBS)			\
 	-lm
diff --git a/docs/tools/widgets.c b/docs/tools/widgets.c
index 932daf1..54239d6 100644
--- a/docs/tools/widgets.c
+++ b/docs/tools/widgets.c
@@ -1526,9 +1526,11 @@ create_gl_area (void)
   widget = gtk_frame_new (NULL);
   gtk_frame_set_shadow_type (GTK_FRAME (widget), GTK_SHADOW_IN);
 
+#ifdef HAVE_OPENGL
   gears = gtk_gears_new ();
   gtk_container_add (GTK_CONTAINER (widget), gears);
- 
+#endif
+
   info = new_widget_info ("glarea", widget, MEDIUM);
 
   return info;
diff --git a/gdk/Makefile.am b/gdk/Makefile.am
index 689ee52..d6b4e70 100644
--- a/gdk/Makefile.am
+++ b/gdk/Makefile.am
@@ -274,7 +274,6 @@ x11_introspection_files = 		\
 	x11/gdkeventsource.c		\
 	x11/gdkeventtranslator.c	\
 	x11/gdkgeometry-x11.c		\
-	x11/gdkglcontext-x11.c		\
 	x11/gdkkeys-x11.c		\
 	x11/gdkmain-x11.c		\
 	x11/gdkmonitor-x11.c		\
@@ -300,7 +299,6 @@ x11_introspection_files = 		\
 	x11/gdkx11display.h		\
 	x11/gdkx11displaymanager.h	\
 	x11/gdkx11dnd.h			\
-	x11/gdkx11glcontext.h		\
 	x11/gdkx11keys.h		\
 	x11/gdkx11monitor.h		\
 	x11/gdkx11property.h		\
@@ -310,6 +308,12 @@ x11_introspection_files = 		\
 	x11/gdkx11visual.h		\
 	x11/gdkx11window.h
 
+if HAVE_OPENGL
+x11_introspection_files += 		\
+	x11/gdkglcontext-x11.c		\
+	x11/gdkx11glcontext.h
+endif
+
 GdkX11-3.0.gir: libgdk-3.la Gdk-3.0.gir Makefile
 GdkX11_3_0_gir_SCANNERFLAGS = 		\
 	--identifier-prefix=Gdk		\
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index 06d4187..832711c 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -2416,7 +2416,9 @@ gboolean
 gdk_display_make_gl_context_current (GdkDisplay   *display,
                                      GdkGLContext *context)
 {
-  return GDK_DISPLAY_GET_CLASS (display)->make_gl_context_current (display, context);
+  if (GDK_DISPLAY_GET_CLASS (display)->make_gl_context_current)
+    return GDK_DISPLAY_GET_CLASS (display)->make_gl_context_current (display, context);
+  return FALSE;
 }
 
 GdkRenderingMode
diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c
index 933e204..1767508 100644
--- a/gdk/gdkgl.c
+++ b/gdk/gdkgl.c
@@ -26,7 +26,9 @@
 # include "win32/gdkwin32.h"
 #endif
 
+#ifdef HAVE_OPENGL
 #include <epoxy/gl.h>
+#endif
 #include <math.h>
 #include <string.h>
 
@@ -40,6 +42,7 @@ gdk_cairo_surface_mark_as_direct (cairo_surface_t *surface,
                                g_object_ref (window),  g_object_unref);
 }
 
+#ifdef HAVE_OPENGL
 static const char *
 get_vertex_type_name (int type)
 {
@@ -212,6 +215,7 @@ use_texture_rect_program (GdkGLContextPaintData *paint_data)
       glUseProgram (paint_data->current_program->program);
     }
 }
+#endif
 
 void
 gdk_gl_texture_quads (GdkGLContext *paint_context,
@@ -220,6 +224,7 @@ gdk_gl_texture_quads (GdkGLContext *paint_context,
                       GdkTexturedQuad *quads,
                       gboolean flip_colors)
 {
+#ifdef HAVE_OPENGL
   GdkGLContextPaintData *paint_data  = gdk_gl_context_get_paint_data (paint_context);
   GdkGLContextProgram *program;
   GdkWindow *window = gdk_gl_context_get_window (paint_context);
@@ -293,6 +298,7 @@ gdk_gl_texture_quads (GdkGLContext *paint_context,
 
   glDisableVertexAttribArray (program->position_location);
   glDisableVertexAttribArray (program->uv_location);
+#endif
 }
 
 /* x,y,width,height describes a rectangle in the gl render buffer
@@ -341,6 +347,7 @@ gdk_cairo_draw_from_gl (cairo_t              *cr,
                         int                   width,
                         int                   height)
 {
+#ifdef HAVE_OPENGL
   GdkGLContext *paint_context;
   cairo_surface_t *image;
   cairo_matrix_t matrix;
@@ -718,6 +725,7 @@ out:
   if (clip_region)
     cairo_region_destroy (clip_region);
 
+#endif
 }
 
 /* This is always called with the paint context current */
@@ -725,6 +733,7 @@ void
 gdk_gl_texture_from_surface (cairo_surface_t *surface,
 			     cairo_region_t  *region)
 {
+#ifdef HAVE_OPENGL
   GdkGLContext *paint_context;
   cairo_surface_t *image;
   double device_x_offset, device_y_offset;
@@ -825,4 +834,5 @@ gdk_gl_texture_from_surface (cairo_surface_t *surface,
 
   glDisable (GL_SCISSOR_TEST);
   glDeleteTextures (1, &texture_id);
+#endif
 }
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index dfbed63..556f0a3 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -85,7 +85,9 @@
 #include "gdkintl.h"
 #include "gdk-private.h"
 
+#ifdef HAVE_OPENGL
 #include <epoxy/gl.h>
+#endif
 
 typedef struct {
   GdkDisplay *display;
@@ -243,6 +245,7 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
                                int              height,
                                guint            texture_target)
 {
+#ifdef HAVE_OPENGL
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
 
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
@@ -286,6 +289,7 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
             glTexSubImage2D (texture_target, 0, 0, i, width, 1, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (unsigned char*) data + (i * stride));
         }
     }
+#endif
 }
 
 static gboolean
@@ -774,6 +778,7 @@ gdk_gl_context_realize (GdkGLContext  *context,
 static void
 gdk_gl_context_check_extensions (GdkGLContext *context)
 {
+#ifdef HAVE_OPENGL
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
   gboolean has_npot, has_texture_rectangle;
 
@@ -853,6 +858,7 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
                        priv->use_texture_rectangle ? "yes" : "no"));
 
   priv->extensions_checked = TRUE;
+#endif
 }
 
 /**
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 1416409..e3b5630 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -45,7 +45,9 @@
 
 #include <math.h>
 
+#ifdef HAVE_OPENGL
 #include <epoxy/gl.h>
+#endif
 
 /* for the use of round() */
 #include "fallback-c89.c"
@@ -2822,6 +2824,13 @@ gdk_window_get_paint_gl_context (GdkWindow  *window,
 {
   GError *internal_error = NULL;
 
+#ifndef HAVE_OPENGL
+  g_set_error_literal (error, GDK_GL_ERROR,
+                       GDK_GL_ERROR_NOT_AVAILABLE,
+                       _("GL support disabled with --disable-opengl"));
+  return NULL;
+#endif
+
   if (_gdk_gl_flags & GDK_GL_DISABLE)
     {
       g_set_error_literal (error, GDK_GL_ERROR,
@@ -2957,6 +2966,7 @@ gdk_window_begin_paint_internal (GdkWindow            *window,
         }
       else
         {
+#ifdef HAVE_OPENGL
 	  gdk_gl_context_make_current (context);
           /* With gl we always need a surface to combine the gl
              drawing with the native drawing. */
@@ -2971,6 +2981,7 @@ gdk_window_begin_paint_internal (GdkWindow            *window,
           glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 
           glViewport (0, 0, ww, wh);
+#endif
         }
     }
 
@@ -3034,6 +3045,7 @@ gdk_window_end_paint_internal (GdkWindow *window)
 
           gdk_gl_context_make_current (window->gl_paint_context);
 
+#ifdef HAVE_OPENGL
           if (!cairo_region_is_empty (opaque_region))
             gdk_gl_texture_from_surface (window->current_paint.surface,
                                          opaque_region);
@@ -3044,6 +3056,7 @@ gdk_window_end_paint_internal (GdkWindow *window)
                                            window->current_paint.need_blend_region);
               glDisable(GL_BLEND);
             }
+#endif
 
           cairo_region_destroy (opaque_region);
 
diff --git a/gdk/x11/Makefile.am b/gdk/x11/Makefile.am
index 6289f3a..cbbac79 100644
--- a/gdk/x11/Makefile.am
+++ b/gdk/x11/Makefile.am
@@ -40,8 +40,6 @@ libgdk_x11_la_SOURCES = 	\
 	gdkeventtranslator.c	\
 	gdkeventtranslator.h	\
 	gdkgeometry-x11.c  	\
-	gdkglcontext-x11.c	\
-	gdkglcontext-x11.h	\
 	gdkkeys-x11.c		\
 	gdkmain-x11.c		\
 	gdkmonitor-x11.c	\
@@ -56,14 +54,32 @@ libgdk_x11_la_SOURCES = 	\
 	gdkwindow-x11.h		\
 	gdkxftdefaults.c	\
 	gdkxid.c		\
-	gdkx.h			\
 	gdkprivate-x11.h	\
 	xsettings-client.h	\
 	xsettings-client.c
 
+if HAVE_OPENGL
+libgdk_x11_la_SOURCES +=        \
+	gdkglcontext-x11.c	\
+	gdkglcontext-x11.h
+endif
+
 libgdkinclude_HEADERS = 	\
 	gdkx.h
 
+if HAVE_OPENGL
+GDKX_HEADER = gdkx-with-gl-context.h
+else
+GDKX_HEADER = gdkx-without-gl-context.h
+endif
+
+BUILT_SOURCES = gdkx.h
+
+.PHONY: gdkx.h
+gdkx.h:
+	$(AM_V_GEN) cd $(srcdir) \
+	&& (cmp -s $(GDKX_HEADER) gdkx.h || cp $(GDKX_HEADER) gdkx.h )
+
 libgdkx11include_HEADERS = 	\
 	gdkx-autocleanups.h	\
 	gdkx11applaunchcontext.h \
@@ -77,7 +93,6 @@ libgdkx11include_HEADERS = 	\
 	gdkx11display.h		\
 	gdkx11displaymanager.h	\
 	gdkx11dnd.h		\
-	gdkx11glcontext.h	\
 	gdkx11keys.h		\
 	gdkx11monitor.h		\
 	gdkx11property.h	\
@@ -87,9 +102,16 @@ libgdkx11include_HEADERS = 	\
 	gdkx11visual.h		\
 	gdkx11window.h
 
+if HAVE_OPENGL
+libgdkx11include_HEADERS += gdkx11glcontext.h
+endif
+
 # We need to include all these C files here since the conditionals
 # don't seem to be correctly expanded for the dist files.
 EXTRA_DIST += 			\
+	gdkx.h			\
 	gdksettings.c
 
+MAINTAINERCLEANFILES = gdkx.h
+
 -include $(top_srcdir)/git.mk
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index 5b95196..9a2f2a2 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -37,7 +37,9 @@
 #include "gdkdisplay-x11.h"
 #include "gdkprivate-x11.h"
 #include "gdkscreen-x11.h"
+#ifdef HAVE_OPENGL
 #include "gdkglcontext-x11.h"
+#endif
 #include "gdk-private.h"
 
 #include <glib.h>
@@ -3184,7 +3186,9 @@ gdk_x11_display_class_init (GdkX11DisplayClass * class)
   display_class->text_property_to_utf8_list = _gdk_x11_display_text_property_to_utf8_list;
   display_class->utf8_to_string_target = _gdk_x11_display_utf8_to_string_target;
 
-  display_class->make_gl_context_current = gdk_x11_display_make_gl_context_current;
+#ifdef HAVE_OPENGL
+   display_class->make_gl_context_current = gdk_x11_display_make_gl_context_current;
+#endif
 
   display_class->get_default_seat = gdk_x11_display_get_default_seat;
 
diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c
index 272cecd..2bb34ac 100644
--- a/gdk/x11/gdkscreen-x11.c
+++ b/gdk/x11/gdkscreen-x11.c
@@ -1675,3 +1675,8 @@ gdk_x11_screen_get_current_desktop (GdkScreen *screen)
 {
   return get_netwm_cardinal_property (screen, "_NET_CURRENT_DESKTOP");
 }
+
+#ifndef HAVE_OPENGL
+/* Function from in gdk/x11/gdkglcontext-x11.c */
+void _gdk_x11_screen_update_visuals_for_gl (GdkScreen *screen) {}
+#endif
diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c
index f92a146..89f900a 100644
--- a/gdk/x11/gdkwindow-x11.c
+++ b/gdk/x11/gdkwindow-x11.c
@@ -36,7 +36,9 @@
 #include "gdkasync.h"
 #include "gdkeventsource.h"
 #include "gdkdisplay-x11.h"
+#ifdef HAVE_OPENGL
 #include "gdkglcontext-x11.h"
+#endif
 #include "gdkprivate-x11.h"
 #include "gdk-private.h"
 
@@ -5839,7 +5841,9 @@ gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
   impl_class->set_opaque_region = gdk_x11_window_set_opaque_region;
   impl_class->set_shadow_width = gdk_x11_window_set_shadow_width;
   impl_class->show_window_menu = gdk_x11_window_show_window_menu;
+#ifdef HAVE_OPENGL
   impl_class->create_gl_context = gdk_x11_window_create_gl_context;
   impl_class->invalidate_for_new_frame = gdk_x11_window_invalidate_for_new_frame;
+#endif
   impl_class->get_unscaled_size = gdk_x11_window_get_unscaled_size;
 }
diff --git a/gdk/x11/gdkx-autocleanups.h b/gdk/x11/gdkx-autocleanups.h
index edb0ea7..a317d61 100644
--- a/gdk/x11/gdkx-autocleanups.h
+++ b/gdk/x11/gdkx-autocleanups.h
@@ -30,7 +30,9 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11DeviceXI2, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Display, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11DisplayManager, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11DragContext, g_object_unref)
+#ifdef HAVE_OPENGL
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11GLContext, g_object_unref)
+#endif
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Keymap, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Screen, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Visual, g_object_unref)
diff --git a/gdk/x11/gdkx.h b/gdk/x11/gdkx-with-gl-context.h
similarity index 98%
rename from gdk/x11/gdkx.h
rename to gdk/x11/gdkx-with-gl-context.h
index 1f64bcc..ae05fa6 100644
--- a/gdk/x11/gdkx.h
+++ b/gdk/x11/gdkx-with-gl-context.h
@@ -45,7 +45,6 @@
 #include <gdk/x11/gdkx11dnd.h>
 #include <gdk/x11/gdkx11glcontext.h>
 #include <gdk/x11/gdkx11keys.h>
-#include <gdk/x11/gdkx11monitor.h>
 #include <gdk/x11/gdkx11property.h>
 #include <gdk/x11/gdkx11screen.h>
 #include <gdk/x11/gdkx11selection.h>
diff --git a/gdk/x11/gdkx-without-gl-context.h b/gdk/x11/gdkx-without-gl-context.h
new file mode 100644
index 0000000..c9e2617
--- /dev/null
+++ b/gdk/x11/gdkx-without-gl-context.h
@@ -0,0 +1,58 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#ifndef __GDK_X_H__
+#define __GDK_X_H__
+
+#include <gdk/gdk.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#define __GDKX_H_INSIDE__
+
+#include <gdk/x11/gdkx11applaunchcontext.h>
+#include <gdk/x11/gdkx11cursor.h>
+#include <gdk/x11/gdkx11device.h>
+#include <gdk/x11/gdkx11device-core.h>
+#include <gdk/x11/gdkx11device-xi2.h>
+#include <gdk/x11/gdkx11devicemanager.h>
+#include <gdk/x11/gdkx11devicemanager-core.h>
+#include <gdk/x11/gdkx11devicemanager-xi2.h>
+#include <gdk/x11/gdkx11display.h>
+#include <gdk/x11/gdkx11displaymanager.h>
+#include <gdk/x11/gdkx11dnd.h>
+#include <gdk/x11/gdkx11keys.h>
+#include <gdk/x11/gdkx11property.h>
+#include <gdk/x11/gdkx11screen.h>
+#include <gdk/x11/gdkx11selection.h>
+#include <gdk/x11/gdkx11utils.h>
+#include <gdk/x11/gdkx11visual.h>
+#include <gdk/x11/gdkx11window.h>
+
+#include <gdk/x11/gdkx-autocleanups.h>
+
+#undef __GDKX_H_INSIDE__
+
+#endif /* __GDK_X_H__ */
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index e556e9d..ce912d7 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1441,7 +1441,6 @@ gtkprivatetypebuiltins.c: $(gtk_private_type_h_sources)  gtkprivatetypebuiltins.
 	&& cp xgen-gptbc gtkprivatetypebuiltins.c  \
 	&& rm -f xgen-gptbc
 
-
 gtktypefuncs.c: stamp-gtktypebuiltins.h stamp-gtkprivatetypebuiltins.h $(top_srcdir)/gtk/*.h $(top_srcdir)/gtk/a11y/*.h $(top_srcdir)/gtk/deprecated/*.h $(top_srcdir)/gdk/*.h Makefile
 	$(AM_V_GEN) export LC_ALL=C ; \
 	  (echo '#undef GTK_COMPILATION' && echo '#include <gtk/gtkx.h>') > xgen-gtfsrc.c && \
@@ -1449,7 +1448,7 @@ gtktypefuncs.c: stamp-gtktypebuiltins.h stamp-gtkprivatetypebuiltins.h $(top_src
 	  ${CPP} $(DEFS) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) xgen-gtfsrc.c | \
 	  $(GREP) -o '\bg[td]k_[a-zA-Z0-9_]*_get_type\b' | \
 	  sort | uniq | \
-	  $(SED) '{ s/^/*tp++ = /; s/$$/();/; s/^.*\(gdk_x11\|gtk_plug_\|gtk_socket_\).*$$/#ifdef GDK_WINDOWING_X11\n&\n#endif/; }' >> xgen-gtf \
+	  $(SED) '{ s/^/*tp++ = /; s/$$/();/; s/^.*\(gdk_x11\|gtk_plug_\|gtk_socket_\).*$$/#ifdef GDK_WINDOWING_X11\n&\n#endif/; s/^.*gdk_x11_gl.*$$/#ifdef HAVE_OPENGL\n&\n#endif/; }' >> xgen-gtf \
 	&& cp xgen-gtf $@ && rm -f xgen-gtf
 $(srcdir)/gtktestutils.c: gtktypefuncs.c
 
diff --git a/gtk/gtkglarea.c b/gtk/gtkglarea.c
index ea383c0..bb4eb64 100644
--- a/gtk/gtkglarea.c
+++ b/gtk/gtkglarea.c
@@ -28,7 +28,9 @@
 #include "gtkprivate.h"
 #include "gtkrender.h"
 
+#ifdef HAVE_OPENGL
 #include <epoxy/gl.h>
+#endif
 
 /**
  * SECTION:gtkglarea
@@ -368,9 +370,12 @@ gtk_gl_area_real_create_context (GtkGLArea *area)
 static void
 gtk_gl_area_resize (GtkGLArea *area, int width, int height)
 {
+#ifdef HAVE_OPENGL
   glViewport (0, 0, width, height);
+#endif
 }
 
+#ifdef HAVE_OPENGL
 /*
  * Creates all the buffer objects needed for rendering the scene
  */
@@ -482,6 +487,7 @@ gtk_gl_area_allocate_buffers (GtkGLArea *area)
 
   priv->needs_render = TRUE;
 }
+#endif
 
 /**
  * gtk_gl_area_attach_buffers:
@@ -500,6 +506,7 @@ gtk_gl_area_allocate_buffers (GtkGLArea *area)
 void
 gtk_gl_area_attach_buffers (GtkGLArea *area)
 {
+#ifdef HAVE_OPENGL
   GtkGLAreaPrivate *priv = gtk_gl_area_get_instance_private (area);
 
   g_return_if_fail (GTK_IS_GL_AREA (area));
@@ -532,11 +539,13 @@ gtk_gl_area_attach_buffers (GtkGLArea *area)
         glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
                                       GL_RENDERBUFFER_EXT, priv->depth_stencil_buffer);
     }
+#endif
 }
 
 static void
 gtk_gl_area_delete_buffers (GtkGLArea *area)
 {
+#ifdef HAVE_OPENGL
   GtkGLAreaPrivate *priv = gtk_gl_area_get_instance_private (area);
 
   if (priv->context == NULL)
@@ -568,6 +577,7 @@ gtk_gl_area_delete_buffers (GtkGLArea *area)
       glDeleteFramebuffersEXT (1, &priv->frame_buffer);
       priv->frame_buffer = 0;
     }
+#endif
 }
 
 static void
@@ -678,6 +688,7 @@ gtk_gl_area_draw (GtkWidget *widget,
   GtkGLArea *area = GTK_GL_AREA (widget);
   GtkGLAreaPrivate *priv = gtk_gl_area_get_instance_private (area);
   gboolean unused;
+#ifdef HAVE_OPENGL
   int w, h, scale;
   GLenum status;
 
@@ -689,7 +700,6 @@ gtk_gl_area_draw (GtkWidget *widget,
                                      gtk_widget_get_allocated_height (widget));
       return FALSE;
     }
-
   if (priv->context == NULL)
     return FALSE;
 
@@ -735,6 +745,14 @@ gtk_gl_area_draw (GtkWidget *widget,
     }
 
   return TRUE;
+#else
+  if (priv->error != NULL)
+      gtk_gl_area_draw_error_screen (area,
+                                     cr,
+                                     gtk_widget_get_allocated_width (widget),
+                                     gtk_widget_get_allocated_height (widget));
+  return FALSE;
+#endif
 }
 
 static gboolean
diff --git a/gtk/inspector/general.c b/gtk/inspector/general.c
index c241ec8..24576dd 100644
--- a/gtk/inspector/general.c
+++ b/gtk/inspector/general.c
@@ -33,8 +33,10 @@
 
 #ifdef GDK_WINDOWING_X11
 #include "x11/gdkx.h"
+#ifdef HAVE_OPENGL
 #include <epoxy/glx.h>
 #endif
+#endif
 
 #ifdef GDK_WINDOWING_WIN32
 #include "win32/gdkwin32.h"
@@ -196,6 +198,7 @@ add_label_row (GtkInspectorGeneral *gen,
   gtk_size_group_add_widget (GTK_SIZE_GROUP (gen->priv->labels), label);
 }
 
+#ifdef HAVE_OPENGL
 #ifdef GDK_WINDOWING_X11
 static void
 append_glx_extension_row (GtkInspectorGeneral *gen,
@@ -205,6 +208,7 @@ append_glx_extension_row (GtkInspectorGeneral *gen,
   add_check_row (gen, GTK_LIST_BOX (gen->priv->gl_box), ext, epoxy_has_glx_extension (dpy, 0, ext), 0);
 }
 #endif
+#endif
 
 #ifdef GDK_WINDOWING_WAYLAND
 static void
@@ -254,6 +258,7 @@ wayland_get_display (struct wl_display *wl_display)
 static void
 init_gl (GtkInspectorGeneral *gen)
 {
+#ifdef HAVE_OPENGL
 #ifdef GDK_WINDOWING_X11
   if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
     {
@@ -280,6 +285,7 @@ init_gl (GtkInspectorGeneral *gen)
     }
   else
 #endif
+#endif
 #ifdef GDK_WINDOWING_WAYLAND
   if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ()))
     {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7c5ca99..e4a4546 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -80,8 +80,6 @@ noinst_PROGRAMS =  $(TEST_PROGS)	\
 	testfullscreen			\
 	testgeometry			\
 	testgiconpixbuf			\
-	testglarea			\
-	testglblending			\
 	testgrid			\
 	testgtk				\
 	testheaderbar			\
@@ -172,12 +170,18 @@ noinst_PROGRAMS =  $(TEST_PROGS)	\
 	testactionbar			\
 	testwindowsize			\
 	testpopover			\
-	gdkgears			\
 	listmodel			\
 	testpopup			\
 	testpopupat			\
 	$(NULL)
 
+if HAVE_OPENGL
+noinst_PROGRAMS +=
+	testglarea			\
+	testglblending			\
+	gdkgears
+endif
+
 if USE_WAYLAND
 noinst_PROGRAMS += testforeign
 endif
diff --git a/testsuite/gtk/objects-finalize.c b/testsuite/gtk/objects-finalize.c
index 0b3a519..07b096f 100644
--- a/testsuite/gtk/objects-finalize.c
+++ b/testsuite/gtk/objects-finalize.c
@@ -115,7 +115,9 @@ main (int argc, char **argv)
 	  all_types[i] != GDK_TYPE_X11_DEVICE_MANAGER_CORE &&
 	  all_types[i] != GDK_TYPE_X11_DEVICE_MANAGER_XI2 &&
 	  all_types[i] != GDK_TYPE_X11_DISPLAY_MANAGER &&
+#ifdef HAVE_OPENGL
 	  all_types[i] != GDK_TYPE_X11_GL_CONTEXT &&
+#endif
 #endif
 	  /* Not allowed to finalize a GdkPixbufLoader without calling gdk_pixbuf_loader_close() */
 	  all_types[i] != GDK_TYPE_PIXBUF_LOADER &&