1From eef50c94587fc30cd624adb5eb213eb9fa663dc1 Mon Sep 17 00:00:00 2001
2From: Jussi Kukkonen <jussi.kukkonen@intel.com>
3Date: Tue, 21 Jun 2016 15:11:39 +0300
4Subject: [PATCH] Add --disable-opengl configure option
5
6--disable-opengl will remove the dependency on libepoxy and on the
7OpenGL APIs. This is useful for those who want to keep using gtk+3
8without the "opengl" distro feature.
9
10GtkGLArea is still part of the API (it just doesn't work) even when
11OpenGL is disabled. GdkX11GLContext was removed from the Gtk API
12completely: that object exposes GL API elements so it had to be at
13the very least modified.
14
15The patch is _not_ great from a maintenance point of view and
16modifying the library API is also a fairly nasty thing to do.
17Next long term release (4.0) will require alternative solutions
18as it actually will depend on OpenGL.
19
20Upstream-Status: Inappropriate [Evil eye expected from upstream]
21Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>
22
23---
24 configure.ac                               | 13 ++++-
25 demos/gtk-demo/glarea.c                    | 14 ++++++
26 docs/tools/Makefile.am                     |  9 +++-
27 docs/tools/widgets.c                       |  4 +-
28 gdk/Makefile.am                            |  8 ++-
29 gdk/gdkdisplay.c                           |  4 +-
30 gdk/gdkgl.c                                | 10 ++++
31 gdk/gdkglcontext.c                         |  6 +++
32 gdk/gdkwindow.c                            | 13 +++++
33 gdk/x11/Makefile.am                        | 30 +++++++++--
34 gdk/x11/gdkdisplay-x11.c                   |  6 ++-
35 gdk/x11/gdkscreen-x11.c                    |  5 ++
36 gdk/x11/gdkwindow-x11.c                    |  4 ++
37 gdk/x11/gdkx-autocleanups.h                |  2 +
38 gdk/x11/{gdkx.h => gdkx-with-gl-context.h} |  1 -
39 gdk/x11/gdkx-without-gl-context.h          | 58 ++++++++++++++++++++++
40 gtk/Makefile.am                            |  2 +-
41 gtk/gtkglarea.c                            | 20 +++++++-
42 gtk/inspector/general.c                    |  6 +++
43 tests/Makefile.am                          | 10 ++--
44 testsuite/gtk/objects-finalize.c           |  2 +
45 21 files changed, 208 insertions(+), 19 deletions(-)
46 rename gdk/x11/{gdkx.h => gdkx-with-gl-context.h} (98%)
47 create mode 100644 gdk/x11/gdkx-without-gl-context.h
48
49diff --git a/configure.ac b/configure.ac
50index 851bcbf..6cbf6a2 100644
51--- a/configure.ac
52+++ b/configure.ac
53@@ -346,6 +346,15 @@ AC_ARG_ENABLE(cloudproviders,
54               [AS_HELP_STRING([--enable-cloudproviders],
55                               [enable libcloudproviders integration])],
56                               [cloudproviders_set=yes])
57+AC_ARG_ENABLE(opengl,
58+              [AS_HELP_STRING([--enable-opengl],
59+                              [When enabled, Gtk+ will use libepoxy and exposes GtkGLArea widget ])])
60+AS_IF([test "x$enable_opengl" != "xno"], [
61+  AC_DEFINE([HAVE_OPENGL], [1], [libepoxy and opengl APIs are available at buildtime])
62+  EPOXY_PACKAGES="epoxy >= epoxy_required_version"
63+])
64+AM_CONDITIONAL([HAVE_OPENGL],[test "x$enable_opengl" != "xno"])
65+
66 AC_ARG_ENABLE(glx,
67               [AS_HELP_STRING([--enable-glx],
68                               [When enabled Gdk will try to initialize GLX])])
69@@ -1345,7 +1354,7 @@ CFLAGS="$saved_cflags"
70 LDFLAGS="$saved_ldflags"
71
72 GDK_PACKAGES="$PANGO_PACKAGES gdk-pixbuf-2.0 >= gdk_pixbuf_required_version cairo >= cairo_required_version cairo-gobject >= cairo_required_version"
73-GDK_PRIVATE_PACKAGES="$GDK_GIO_PACKAGE $X_PACKAGES $WAYLAND_PACKAGES $cairo_backends epoxy >= epoxy_required_version $CLOUDPROVIDER_PACKAGES $PROFILER_PACKAGES fribidi >= fribidi_required_version"
74+GDK_PRIVATE_PACKAGES="$GDK_GIO_PACKAGE $X_PACKAGES $WAYLAND_PACKAGES $cairo_backends $EPOXY_PACKAGES $CLOUDPROVIDER_PACKAGES $PROFILER_PACKAGES fribidi >= fribidi_required_version"
75
76 PKG_CHECK_MODULES(GDK_DEP, $GDK_PACKAGES $GDK_PRIVATE_PACKAGES)
77 GDK_DEP_LIBS="$GDK_EXTRA_LIBS $GDK_DEP_LIBS $MATH_LIB"
78@@ -1379,7 +1388,7 @@ fi
79 PKG_CHECK_MODULES(ATK, $ATK_PACKAGES)
80
81 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"
82-GTK_PRIVATE_PACKAGES="$ATK_PACKAGES $WAYLAND_PACKAGES epoxy >= epoxy_required_version fribidi >= fribidi_required_version"
83+GTK_PRIVATE_PACKAGES="$ATK_PACKAGES $WAYLAND_PACKAGES $EPOXY_PACKAGES fribidi >= fribidi_required_version"
84 if test "x$enable_x11_backend" = xyes -o "x$enable_wayland_backend" = xyes; then
85   GTK_PRIVATE_PACKAGES="$GTK_PRIVATE_PACKAGES pangoft2"
86 fi
87diff --git a/demos/gtk-demo/glarea.c b/demos/gtk-demo/glarea.c
88index b51e4ae..82409c7 100644
89--- a/demos/gtk-demo/glarea.c
90+++ b/demos/gtk-demo/glarea.c
91@@ -3,9 +3,12 @@
92  * GtkGLArea is a widget that allows custom drawing using OpenGL calls.
93  */
94
95+#include "config.h"
96 #include <math.h>
97 #include <gtk/gtk.h>
98+#if HAVE_OPENGL
99 #include <epoxy/gl.h>
100+#endif
101
102 static GtkWidget *demo_window = NULL;
103
104@@ -23,6 +26,8 @@ enum {
105 /* Rotation angles on each axis */
106 static float rotation_angles[N_AXIS] = { 0.0 };
107
108+#ifdef HAVE_OPENGL
109+
110 /* The object we are drawing */
111 static const GLfloat vertex_data[] = {
112   0.f,   0.5f,   0.f, 1.f,
113@@ -215,6 +220,7 @@ compute_mvp (float *res,
114 static GLuint position_buffer;
115 static GLuint program;
116 static GLuint mvp_location;
117+#endif
118
119 /* We need to set up our state when we realize the GtkGLArea widget */
120 static void
121@@ -241,8 +247,10 @@ realize (GtkWidget *widget)
122       fragment_path = "/glarea/glarea-gl.fs.glsl";
123     }
124
125+#ifdef HAVE_OPENGL
126   init_buffers (&position_buffer, NULL);
127   init_shaders (vertex_path, fragment_path, &program, &mvp_location);
128+#endif
129 }
130
131 /* We should tear down the state when unrealizing */
132@@ -254,10 +262,13 @@ unrealize (GtkWidget *widget)
133   if (gtk_gl_area_get_error (GTK_GL_AREA (widget)) != NULL)
134     return;
135
136+#ifdef HAVE_OPENGL
137   glDeleteBuffers (1, &position_buffer);
138   glDeleteProgram (program);
139+#endif
140 }
141
142+#ifdef HAVE_OPENGL
143 static void
144 draw_triangle (void)
145 {
146@@ -290,6 +301,7 @@ draw_triangle (void)
147   glBindBuffer (GL_ARRAY_BUFFER, 0);
148   glUseProgram (0);
149 }
150+#endif
151
152 static gboolean
153 render (GtkGLArea    *area,
154@@ -298,6 +310,7 @@ render (GtkGLArea    *area,
155   if (gtk_gl_area_get_error (area) != NULL)
156     return FALSE;
157
158+#ifdef HAVE_OPENGL
159   /* Clear the viewport */
160   glClearColor (0.5, 0.5, 0.5, 1.0);
161   glClear (GL_COLOR_BUFFER_BIT);
162@@ -307,6 +320,7 @@ render (GtkGLArea    *area,
163
164   /* Flush the contents of the pipeline */
165   glFlush ();
166+#endif
167
168   return TRUE;
169 }
170diff --git a/docs/tools/Makefile.am b/docs/tools/Makefile.am
171index bec43e3..189e8fc 100644
172--- a/docs/tools/Makefile.am
173+++ b/docs/tools/Makefile.am
174@@ -9,13 +9,18 @@ AM_CPPFLAGS = \
175 	$(GTK_DEBUG_FLAGS)		\
176 	$(GTK_DEP_CFLAGS)
177
178+if HAVE_OPENGL
179+GEARS_LDADD = $(top_builddir)/tests/gtkgears.o
180+endif
181+
182 DEPS = \
183-	$(top_builddir)/gtk/libgtk-3.la
184+	$(top_builddir)/gtk/libgtk-3.la	\
185+	$(GEARS_LDADD)
186
187 LDADDS = \
188 	$(top_builddir)/gtk/libgtk-3.la	\
189 	$(top_builddir)/gdk/libgdk-3.la	\
190-	$(top_builddir)/tests/gtkgears.o \
191+	$(GEARS_LDADD)			\
192 	$(GTK_DEP_LIBS)			\
193 	$(GDK_DEP_LIBS)			\
194 	-lm
195diff --git a/docs/tools/widgets.c b/docs/tools/widgets.c
196index 932daf1..54239d6 100644
197--- a/docs/tools/widgets.c
198+++ b/docs/tools/widgets.c
199@@ -1526,9 +1526,11 @@ create_gl_area (void)
200   widget = gtk_frame_new (NULL);
201   gtk_frame_set_shadow_type (GTK_FRAME (widget), GTK_SHADOW_IN);
202
203+#ifdef HAVE_OPENGL
204   gears = gtk_gears_new ();
205   gtk_container_add (GTK_CONTAINER (widget), gears);
206-
207+#endif
208+
209   info = new_widget_info ("glarea", widget, MEDIUM);
210
211   return info;
212diff --git a/gdk/Makefile.am b/gdk/Makefile.am
213index 710a548..b45f631 100644
214--- a/gdk/Makefile.am
215+++ b/gdk/Makefile.am
216@@ -274,7 +274,6 @@ x11_introspection_files = 		\
217 	x11/gdkeventsource.c		\
218 	x11/gdkeventtranslator.c	\
219 	x11/gdkgeometry-x11.c		\
220-	x11/gdkglcontext-x11.c		\
221 	x11/gdkkeys-x11.c		\
222 	x11/gdkmain-x11.c		\
223 	x11/gdkmonitor-x11.c		\
224@@ -300,7 +299,6 @@ x11_introspection_files = 		\
225 	x11/gdkx11display.h		\
226 	x11/gdkx11displaymanager.h	\
227 	x11/gdkx11dnd.h			\
228-	x11/gdkx11glcontext.h		\
229 	x11/gdkx11keys.h		\
230 	x11/gdkx11monitor.h		\
231 	x11/gdkx11property.h		\
232@@ -310,6 +308,12 @@ x11_introspection_files = 		\
233 	x11/gdkx11visual.h		\
234 	x11/gdkx11window.h
235
236+if HAVE_OPENGL
237+x11_introspection_files += 		\
238+	x11/gdkglcontext-x11.c		\
239+	x11/gdkx11glcontext.h
240+endif
241+
242 GdkX11-3.0.gir: libgdk-3.la Gdk-3.0.gir Makefile
243 GdkX11_3_0_gir_SCANNERFLAGS = 		\
244 	--identifier-prefix=Gdk		\
245diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
246index 748f548..911ab2a 100644
247--- a/gdk/gdkdisplay.c
248+++ b/gdk/gdkdisplay.c
249@@ -2420,7 +2420,9 @@ gboolean
250 gdk_display_make_gl_context_current (GdkDisplay   *display,
251                                      GdkGLContext *context)
252 {
253-  return GDK_DISPLAY_GET_CLASS (display)->make_gl_context_current (display, context);
254+  if (GDK_DISPLAY_GET_CLASS (display)->make_gl_context_current)
255+    return GDK_DISPLAY_GET_CLASS (display)->make_gl_context_current (display, context);
256+  return FALSE;
257 }
258
259 GdkRenderingMode
260diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c
261index 9690077..55f85ef 100644
262--- a/gdk/gdkgl.c
263+++ b/gdk/gdkgl.c
264@@ -26,7 +26,9 @@
265 # include "win32/gdkwin32.h"
266 #endif
267
268+#ifdef HAVE_OPENGL
269 #include <epoxy/gl.h>
270+#endif
271 #include <math.h>
272 #include <string.h>
273
274@@ -40,6 +42,7 @@ gdk_cairo_surface_mark_as_direct (cairo_surface_t *surface,
275                                g_object_ref (window),  g_object_unref);
276 }
277
278+#ifdef HAVE_OPENGL
279 static const char *
280 get_vertex_type_name (int type)
281 {
282@@ -212,6 +215,7 @@ use_texture_rect_program (GdkGLContextPaintData *paint_data)
283       glUseProgram (paint_data->current_program->program);
284     }
285 }
286+#endif
287
288 void
289 gdk_gl_texture_quads (GdkGLContext *paint_context,
290@@ -220,6 +224,7 @@ gdk_gl_texture_quads (GdkGLContext *paint_context,
291                       GdkTexturedQuad *quads,
292                       gboolean flip_colors)
293 {
294+#ifdef HAVE_OPENGL
295   GdkGLContextPaintData *paint_data  = gdk_gl_context_get_paint_data (paint_context);
296   GdkGLContextProgram *program;
297   GdkWindow *window = gdk_gl_context_get_window (paint_context);
298@@ -293,6 +298,7 @@ gdk_gl_texture_quads (GdkGLContext *paint_context,
299
300   glDisableVertexAttribArray (program->position_location);
301   glDisableVertexAttribArray (program->uv_location);
302+#endif
303 }
304
305 /* x,y,width,height describes a rectangle in the gl render buffer
306@@ -341,6 +347,7 @@ gdk_cairo_draw_from_gl (cairo_t              *cr,
307                         int                   width,
308                         int                   height)
309 {
310+#ifdef HAVE_OPENGL
311   GdkGLContext *paint_context;
312   cairo_surface_t *image;
313   cairo_matrix_t matrix;
314@@ -718,6 +725,7 @@ out:
315   if (clip_region)
316     cairo_region_destroy (clip_region);
317
318+#endif
319 }
320
321 /* This is always called with the paint context current */
322@@ -725,6 +733,7 @@ void
323 gdk_gl_texture_from_surface (cairo_surface_t *surface,
324 			     cairo_region_t  *region)
325 {
326+#ifdef HAVE_OPENGL
327   GdkGLContext *paint_context;
328   cairo_surface_t *image;
329   double device_x_offset, device_y_offset;
330@@ -825,4 +834,5 @@ gdk_gl_texture_from_surface (cairo_surface_t *surface,
331
332   glDisable (GL_SCISSOR_TEST);
333   glDeleteTextures (1, &texture_id);
334+#endif
335 }
336diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
337index 3b23639..1f04f8e 100644
338--- a/gdk/gdkglcontext.c
339+++ b/gdk/gdkglcontext.c
340@@ -85,7 +85,9 @@
341 #include "gdkintl.h"
342 #include "gdk-private.h"
343
344+#ifdef HAVE_OPENGL
345 #include <epoxy/gl.h>
346+#endif
347
348 typedef struct {
349   GdkDisplay *display;
350@@ -243,6 +245,7 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
351                                int              height,
352                                guint            texture_target)
353 {
354+#ifdef HAVE_OPENGL
355   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
356
357   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
358@@ -286,6 +289,7 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
359             glTexSubImage2D (texture_target, 0, 0, i, width, 1, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (unsigned char*) data + (i * stride));
360         }
361     }
362+#endif
363 }
364
365 static gboolean
366@@ -774,6 +778,7 @@ gdk_gl_context_realize (GdkGLContext  *context,
367 static void
368 gdk_gl_context_check_extensions (GdkGLContext *context)
369 {
370+#ifdef HAVE_OPENGL
371   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
372   gboolean has_npot, has_texture_rectangle;
373
374@@ -853,6 +858,7 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
375                        priv->use_texture_rectangle ? "yes" : "no"));
376
377   priv->extensions_checked = TRUE;
378+#endif
379 }
380
381 /**
382diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
383index 2de8ba4..1883a79 100644
384--- a/gdk/gdkwindow.c
385+++ b/gdk/gdkwindow.c
386@@ -45,7 +45,9 @@
387
388 #include <math.h>
389
390+#ifdef HAVE_OPENGL
391 #include <epoxy/gl.h>
392+#endif
393
394 /* for the use of round() */
395 #include "fallback-c89.c"
396@@ -2844,6 +2846,13 @@ gdk_window_get_paint_gl_context (GdkWindow  *window,
397 {
398   GError *internal_error = NULL;
399
400+#ifndef HAVE_OPENGL
401+  g_set_error_literal (error, GDK_GL_ERROR,
402+                       GDK_GL_ERROR_NOT_AVAILABLE,
403+                       _("GL support disabled with --disable-opengl"));
404+  return NULL;
405+#endif
406+
407   if (_gdk_gl_flags & GDK_GL_DISABLE)
408     {
409       g_set_error_literal (error, GDK_GL_ERROR,
410@@ -2979,6 +2988,7 @@ gdk_window_begin_paint_internal (GdkWindow            *window,
411         }
412       else
413         {
414+#ifdef HAVE_OPENGL
415 	  gdk_gl_context_make_current (context);
416           /* With gl we always need a surface to combine the gl
417              drawing with the native drawing. */
418@@ -2993,6 +3003,7 @@ gdk_window_begin_paint_internal (GdkWindow            *window,
419           glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
420
421           glViewport (0, 0, ww, wh);
422+#endif
423         }
424     }
425
426@@ -3056,6 +3067,7 @@ gdk_window_end_paint_internal (GdkWindow *window)
427
428           gdk_gl_context_make_current (window->gl_paint_context);
429
430+#ifdef HAVE_OPENGL
431           if (!cairo_region_is_empty (opaque_region))
432             gdk_gl_texture_from_surface (window->current_paint.surface,
433                                          opaque_region);
434@@ -3066,6 +3078,7 @@ gdk_window_end_paint_internal (GdkWindow *window)
435                                            window->current_paint.need_blend_region);
436               glDisable(GL_BLEND);
437             }
438+#endif
439
440           cairo_region_destroy (opaque_region);
441
442diff --git a/gdk/x11/Makefile.am b/gdk/x11/Makefile.am
443index 32b1f24..6352313 100644
444--- a/gdk/x11/Makefile.am
445+++ b/gdk/x11/Makefile.am
446@@ -40,8 +40,6 @@ libgdk_x11_la_SOURCES = 	\
447 	gdkeventtranslator.c	\
448 	gdkeventtranslator.h	\
449 	gdkgeometry-x11.c  	\
450-	gdkglcontext-x11.c	\
451-	gdkglcontext-x11.h	\
452 	gdkkeys-x11.c		\
453 	gdkmain-x11.c		\
454 	gdkmonitor-x11.c	\
455@@ -56,14 +54,32 @@ libgdk_x11_la_SOURCES = 	\
456 	gdkwindow-x11.h		\
457 	gdkxftdefaults.c	\
458 	gdkxid.c		\
459-	gdkx.h			\
460 	gdkprivate-x11.h	\
461 	xsettings-client.h	\
462 	xsettings-client.c
463
464+if HAVE_OPENGL
465+libgdk_x11_la_SOURCES +=        \
466+	gdkglcontext-x11.c	\
467+	gdkglcontext-x11.h
468+endif
469+
470 libgdkinclude_HEADERS = 	\
471 	gdkx.h
472
473+if HAVE_OPENGL
474+GDKX_HEADER = gdkx-with-gl-context.h
475+else
476+GDKX_HEADER = gdkx-without-gl-context.h
477+endif
478+
479+BUILT_SOURCES = gdkx.h
480+
481+.PHONY: gdkx.h
482+gdkx.h:
483+	$(AM_V_GEN) cd $(srcdir) \
484+	&& (cmp -s $(GDKX_HEADER) gdkx.h || cp $(GDKX_HEADER) gdkx.h )
485+
486 libgdkx11include_HEADERS = 	\
487 	gdkx-autocleanups.h	\
488 	gdkx11applaunchcontext.h \
489@@ -77,7 +93,6 @@ libgdkx11include_HEADERS = 	\
490 	gdkx11display.h		\
491 	gdkx11displaymanager.h	\
492 	gdkx11dnd.h		\
493-	gdkx11glcontext.h	\
494 	gdkx11keys.h		\
495 	gdkx11monitor.h		\
496 	gdkx11property.h	\
497@@ -87,10 +102,17 @@ libgdkx11include_HEADERS = 	\
498 	gdkx11visual.h		\
499 	gdkx11window.h
500
501+if HAVE_OPENGL
502+libgdkx11include_HEADERS += gdkx11glcontext.h
503+endif
504+
505 # We need to include all these C files here since the conditionals
506 # don't seem to be correctly expanded for the dist files.
507 EXTRA_DIST += 			\
508+	gdkx.h			\
509 	gdksettings.c	\
510 	meson.build
511
512+MAINTAINERCLEANFILES = gdkx.h
513+
514 -include $(top_srcdir)/git.mk
515diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
516index 7e08f47..30fd7b6 100644
517--- a/gdk/x11/gdkdisplay-x11.c
518+++ b/gdk/x11/gdkdisplay-x11.c
519@@ -37,7 +37,9 @@
520 #include "gdkdisplay-x11.h"
521 #include "gdkprivate-x11.h"
522 #include "gdkscreen-x11.h"
523+#ifdef HAVE_OPENGL
524 #include "gdkglcontext-x11.h"
525+#endif
526 #include "gdk-private.h"
527 #include "gdkprofilerprivate.h"
528
529@@ -3191,7 +3193,9 @@ gdk_x11_display_class_init (GdkX11DisplayClass * class)
530   display_class->text_property_to_utf8_list = _gdk_x11_display_text_property_to_utf8_list;
531   display_class->utf8_to_string_target = _gdk_x11_display_utf8_to_string_target;
532
533-  display_class->make_gl_context_current = gdk_x11_display_make_gl_context_current;
534+#ifdef HAVE_OPENGL
535+   display_class->make_gl_context_current = gdk_x11_display_make_gl_context_current;
536+#endif
537
538   display_class->get_default_seat = gdk_x11_display_get_default_seat;
539
540diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c
541index bb4df05..46f5349 100644
542--- a/gdk/x11/gdkscreen-x11.c
543+++ b/gdk/x11/gdkscreen-x11.c
544@@ -1827,3 +1827,8 @@ gdk_x11_screen_get_current_desktop (GdkScreen *screen)
545 {
546   return get_netwm_cardinal_property (screen, "_NET_CURRENT_DESKTOP");
547 }
548+
549+#ifndef HAVE_OPENGL
550+/* Function from in gdk/x11/gdkglcontext-x11.c */
551+void _gdk_x11_screen_update_visuals_for_gl (GdkScreen *screen) {}
552+#endif
553diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c
554index 721d9bb..8e87acc 100644
555--- a/gdk/x11/gdkwindow-x11.c
556+++ b/gdk/x11/gdkwindow-x11.c
557@@ -36,7 +36,9 @@
558 #include "gdkasync.h"
559 #include "gdkeventsource.h"
560 #include "gdkdisplay-x11.h"
561+#ifdef HAVE_OPENGL
562 #include "gdkglcontext-x11.h"
563+#endif
564 #include "gdkprivate-x11.h"
565 #include "gdk-private.h"
566
567@@ -5881,7 +5883,9 @@ gdk_window_impl_x11_class_init (GdkWindowImplX11Class *klass)
568   impl_class->set_opaque_region = gdk_x11_window_set_opaque_region;
569   impl_class->set_shadow_width = gdk_x11_window_set_shadow_width;
570   impl_class->show_window_menu = gdk_x11_window_show_window_menu;
571+#ifdef HAVE_OPENGL
572   impl_class->create_gl_context = gdk_x11_window_create_gl_context;
573   impl_class->invalidate_for_new_frame = gdk_x11_window_invalidate_for_new_frame;
574+#endif
575   impl_class->get_unscaled_size = gdk_x11_window_get_unscaled_size;
576 }
577diff --git a/gdk/x11/gdkx-autocleanups.h b/gdk/x11/gdkx-autocleanups.h
578index edb0ea7..a317d61 100644
579--- a/gdk/x11/gdkx-autocleanups.h
580+++ b/gdk/x11/gdkx-autocleanups.h
581@@ -30,7 +30,9 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11DeviceXI2, g_object_unref)
582 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Display, g_object_unref)
583 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11DisplayManager, g_object_unref)
584 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11DragContext, g_object_unref)
585+#ifdef HAVE_OPENGL
586 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11GLContext, g_object_unref)
587+#endif
588 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Keymap, g_object_unref)
589 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Screen, g_object_unref)
590 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkX11Visual, g_object_unref)
591diff --git a/gdk/x11/gdkx.h b/gdk/x11/gdkx-with-gl-context.h
592similarity index 98%
593rename from gdk/x11/gdkx.h
594rename to gdk/x11/gdkx-with-gl-context.h
595index 1f64bcc..ae05fa6 100644
596--- a/gdk/x11/gdkx.h
597+++ b/gdk/x11/gdkx-with-gl-context.h
598@@ -45,7 +45,6 @@
599 #include <gdk/x11/gdkx11dnd.h>
600 #include <gdk/x11/gdkx11glcontext.h>
601 #include <gdk/x11/gdkx11keys.h>
602-#include <gdk/x11/gdkx11monitor.h>
603 #include <gdk/x11/gdkx11property.h>
604 #include <gdk/x11/gdkx11screen.h>
605 #include <gdk/x11/gdkx11selection.h>
606diff --git a/gdk/x11/gdkx-without-gl-context.h b/gdk/x11/gdkx-without-gl-context.h
607new file mode 100644
608index 0000000..c9e2617
609--- /dev/null
610+++ b/gdk/x11/gdkx-without-gl-context.h
611@@ -0,0 +1,58 @@
612+/* GDK - The GIMP Drawing Kit
613+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
614+ *
615+ * This library is free software; you can redistribute it and/or
616+ * modify it under the terms of the GNU Lesser General Public
617+ * License as published by the Free Software Foundation; either
618+ * version 2 of the License, or (at your option) any later version.
619+ *
620+ * This library is distributed in the hope that it will be useful,
621+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
622+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
623+ * Lesser General Public License for more details.
624+ *
625+ * You should have received a copy of the GNU Lesser General Public
626+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
627+ */
628+
629+/*
630+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
631+ * file for a list of people on the GTK+ Team.  See the ChangeLog
632+ * files for a list of changes.  These files are distributed with
633+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
634+ */
635+
636+#ifndef __GDK_X_H__
637+#define __GDK_X_H__
638+
639+#include <gdk/gdk.h>
640+
641+#include <X11/Xlib.h>
642+#include <X11/Xutil.h>
643+
644+#define __GDKX_H_INSIDE__
645+
646+#include <gdk/x11/gdkx11applaunchcontext.h>
647+#include <gdk/x11/gdkx11cursor.h>
648+#include <gdk/x11/gdkx11device.h>
649+#include <gdk/x11/gdkx11device-core.h>
650+#include <gdk/x11/gdkx11device-xi2.h>
651+#include <gdk/x11/gdkx11devicemanager.h>
652+#include <gdk/x11/gdkx11devicemanager-core.h>
653+#include <gdk/x11/gdkx11devicemanager-xi2.h>
654+#include <gdk/x11/gdkx11display.h>
655+#include <gdk/x11/gdkx11displaymanager.h>
656+#include <gdk/x11/gdkx11dnd.h>
657+#include <gdk/x11/gdkx11keys.h>
658+#include <gdk/x11/gdkx11property.h>
659+#include <gdk/x11/gdkx11screen.h>
660+#include <gdk/x11/gdkx11selection.h>
661+#include <gdk/x11/gdkx11utils.h>
662+#include <gdk/x11/gdkx11visual.h>
663+#include <gdk/x11/gdkx11window.h>
664+
665+#include <gdk/x11/gdkx-autocleanups.h>
666+
667+#undef __GDKX_H_INSIDE__
668+
669+#endif /* __GDK_X_H__ */
670diff --git a/gtk/Makefile.am b/gtk/Makefile.am
671index 074fb35..4fa9eb6 100644
672--- a/gtk/Makefile.am
673+++ b/gtk/Makefile.am
674@@ -1457,7 +1457,7 @@ gtktypefuncs.inc: stamp-gtktypebuiltins.h stamp-gtkprivatetypebuiltins.h $(top_s
675 	  ${CPP} $(DEFS) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) xgen-gtfsrc.c | \
676 	  $(GREP) -o '\bg[td]k_[a-zA-Z0-9_]*_get_type\b' | \
677 	  sort | uniq | \
678-	  $(SED) '{ s/^/*tp++ = /; s/$$/();/; s/^.*\(gdk_x11\|gtk_plug_\|gtk_socket_\).*$$/#ifdef GDK_WINDOWING_X11\n&\n#endif/; }' >> xgen-gtf \
679+	  $(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 \
680 	&& cp xgen-gtf $@ && rm -f xgen-gtf
681 $(srcdir)/gtktestutils.c: gtktypefuncs.inc
682
683diff --git a/gtk/gtkglarea.c b/gtk/gtkglarea.c
684index 802303e..33001cf 100644
685--- a/gtk/gtkglarea.c
686+++ b/gtk/gtkglarea.c
687@@ -29,7 +29,9 @@
688 #include "gtkprivate.h"
689 #include "gtkrender.h"
690
691+#ifdef HAVE_OPENGL
692 #include <epoxy/gl.h>
693+#endif
694
695 /**
696  * SECTION:gtkglarea
697@@ -369,9 +371,12 @@ gtk_gl_area_real_create_context (GtkGLArea *area)
698 static void
699 gtk_gl_area_resize (GtkGLArea *area, int width, int height)
700 {
701+#ifdef HAVE_OPENGL
702   glViewport (0, 0, width, height);
703+#endif
704 }
705
706+#ifdef HAVE_OPENGL
707 /*
708  * Creates all the buffer objects needed for rendering the scene
709  */
710@@ -483,6 +488,7 @@ gtk_gl_area_allocate_buffers (GtkGLArea *area)
711
712   priv->needs_render = TRUE;
713 }
714+#endif
715
716 /**
717  * gtk_gl_area_attach_buffers:
718@@ -501,6 +507,7 @@ gtk_gl_area_allocate_buffers (GtkGLArea *area)
719 void
720 gtk_gl_area_attach_buffers (GtkGLArea *area)
721 {
722+#ifdef HAVE_OPENGL
723   GtkGLAreaPrivate *priv = gtk_gl_area_get_instance_private (area);
724
725   g_return_if_fail (GTK_IS_GL_AREA (area));
726@@ -533,11 +540,13 @@ gtk_gl_area_attach_buffers (GtkGLArea *area)
727         glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
728                                    GL_RENDERBUFFER, priv->depth_stencil_buffer);
729     }
730+#endif
731 }
732
733 static void
734 gtk_gl_area_delete_buffers (GtkGLArea *area)
735 {
736+#ifdef HAVE_OPENGL
737   GtkGLAreaPrivate *priv = gtk_gl_area_get_instance_private (area);
738
739   if (priv->context == NULL)
740@@ -569,6 +578,7 @@ gtk_gl_area_delete_buffers (GtkGLArea *area)
741       glDeleteFramebuffers (1, &priv->frame_buffer);
742       priv->frame_buffer = 0;
743     }
744+#endif
745 }
746
747 static void
748@@ -679,6 +689,7 @@ gtk_gl_area_draw (GtkWidget *widget,
749   GtkGLArea *area = GTK_GL_AREA (widget);
750   GtkGLAreaPrivate *priv = gtk_gl_area_get_instance_private (area);
751   gboolean unused;
752+#ifdef HAVE_OPENGL
753   int w, h, scale;
754   GLenum status;
755
756@@ -690,7 +701,6 @@ gtk_gl_area_draw (GtkWidget *widget,
757                                      gtk_widget_get_allocated_height (widget));
758       return FALSE;
759     }
760-
761   if (priv->context == NULL)
762     return FALSE;
763
764@@ -736,6 +746,14 @@ gtk_gl_area_draw (GtkWidget *widget,
765     }
766
767   return TRUE;
768+#else
769+  if (priv->error != NULL)
770+      gtk_gl_area_draw_error_screen (area,
771+                                     cr,
772+                                     gtk_widget_get_allocated_width (widget),
773+                                     gtk_widget_get_allocated_height (widget));
774+  return FALSE;
775+#endif
776 }
777
778 static gboolean
779diff --git a/gtk/inspector/general.c b/gtk/inspector/general.c
780index 48237d1..1f9b9be 100644
781--- a/gtk/inspector/general.c
782+++ b/gtk/inspector/general.c
783@@ -33,8 +33,10 @@
784
785 #ifdef GDK_WINDOWING_X11
786 #include "x11/gdkx.h"
787+#ifdef HAVE_OPENGL
788 #include <epoxy/glx.h>
789 #endif
790+#endif
791
792 #ifdef GDK_WINDOWING_WIN32
793 #include "win32/gdkwin32.h"
794@@ -196,6 +198,7 @@ add_label_row (GtkInspectorGeneral *gen,
795   gtk_size_group_add_widget (GTK_SIZE_GROUP (gen->priv->labels), label);
796 }
797
798+#ifdef HAVE_OPENGL
799 #ifdef GDK_WINDOWING_X11
800 static void
801 append_glx_extension_row (GtkInspectorGeneral *gen,
802@@ -205,6 +208,7 @@ append_glx_extension_row (GtkInspectorGeneral *gen,
803   add_check_row (gen, GTK_LIST_BOX (gen->priv->gl_box), ext, epoxy_has_glx_extension (dpy, 0, ext), 0);
804 }
805 #endif
806+#endif
807
808 #ifdef GDK_WINDOWING_WAYLAND
809 static void
810@@ -254,6 +258,7 @@ wayland_get_display (struct wl_display *wl_display)
811 static void
812 init_gl (GtkInspectorGeneral *gen)
813 {
814+#ifdef HAVE_OPENGL
815 #ifdef GDK_WINDOWING_X11
816   if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
817     {
818@@ -280,6 +285,7 @@ init_gl (GtkInspectorGeneral *gen)
819     }
820   else
821 #endif
822+#endif
823 #ifdef GDK_WINDOWING_WAYLAND
824   if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ()))
825     {
826diff --git a/tests/Makefile.am b/tests/Makefile.am
827index f283e89..5e7180e 100644
828--- a/tests/Makefile.am
829+++ b/tests/Makefile.am
830@@ -80,8 +80,6 @@ noinst_PROGRAMS =  $(TEST_PROGS)	\
831 	testfullscreen			\
832 	testgeometry			\
833 	testgiconpixbuf			\
834-	testglarea			\
835-	testglblending			\
836 	testgrid			\
837 	testgtk				\
838 	testheaderbar			\
839@@ -172,12 +170,18 @@ noinst_PROGRAMS =  $(TEST_PROGS)	\
840 	testactionbar			\
841 	testwindowsize			\
842 	testpopover			\
843-	gdkgears			\
844 	listmodel			\
845 	testpopup			\
846 	testpopupat			\
847 	$(NULL)
848
849+if HAVE_OPENGL
850+noinst_PROGRAMS +=
851+	testglarea			\
852+	testglblending			\
853+	gdkgears
854+endif
855+
856 if USE_WAYLAND
857 noinst_PROGRAMS += testforeign
858 endif
859diff --git a/testsuite/gtk/objects-finalize.c b/testsuite/gtk/objects-finalize.c
860index 24540e3..e0f863a 100644
861--- a/testsuite/gtk/objects-finalize.c
862+++ b/testsuite/gtk/objects-finalize.c
863@@ -116,7 +116,9 @@ main (int argc, char **argv)
864 	  all_types[i] != GDK_TYPE_X11_DEVICE_MANAGER_CORE &&
865 	  all_types[i] != GDK_TYPE_X11_DEVICE_MANAGER_XI2 &&
866 	  all_types[i] != GDK_TYPE_X11_DISPLAY_MANAGER &&
867+#ifdef HAVE_OPENGL
868 	  all_types[i] != GDK_TYPE_X11_GL_CONTEXT &&
869+#endif
870 #endif
871 	  /* Not allowed to finalize a GdkPixbufLoader without calling gdk_pixbuf_loader_close() */
872 	  all_types[i] != GDK_TYPE_PIXBUF_LOADER &&
873