"Initial commit to Gerrit"
[profile/ivi/cogl.git] / packaging / gl-header-include-fix.patch
1 From e99770dcc31f0382cb699bbfbb8a30b21bcdb9a8 Mon Sep 17 00:00:00 2001
2 From: Neil Roberts <neil@linux.intel.com>
3 Date: Wed, 2 May 2012 13:08:01 +0100
4 Subject: [PATCH] Don't include any GL header from the public GL headers
5
6 This splits the GL header inclusion from cogl-defines.h into a
7 separate headear called cogl-gl-header.h which we will only include
8 internally. That way we don't leak GL declarations out of our public
9 headers. The texture functions that were using GLenum and GLuint in
10 the public header have now changed to just use unsigned int. Note
11 however that if an EGL winsys is enabled then it will still publicly
12 include an EGL header. This is a bit more awkward to fix because we
13 have public API which returns an EGLDisplay and we can't determine
14 what type that is.
15
16 There is also a conformance test which just verifies that no GL header
17 has been included while compiling. The test isn't added to
18 test-conform-main because it doesn't actually test anything at
19 runtime.
20
21 Reviewed-by: Robert Bragg <robert@linux.intel.com>
22
23 (cherry picked from commit ef5680d3fda5df929dbd0b420c8f598ded58dfee)
24
25 Conflicts:
26
27         cogl/cogl-context-private.h
28         cogl/cogl-sampler-cache-private.h
29 ---
30  cogl/Makefile.am                  |    6 ++--
31  cogl/cogl-buffer-private.h        |    1 +
32  cogl/cogl-context-private.h       |    1 +
33  cogl/cogl-defines.h.in            |    4 ---
34  cogl/cogl-gl-header.h.in          |   39 +++++++++++++++++++++++++++++++++++++
35  cogl/cogl-internal.h              |    1 +
36  cogl/cogl-shader-private.h        |    1 +
37  cogl/cogl-texture.h               |   16 +++++++-------
38  cogl/tesselator/tesselator.h      |    1 +
39  configure.ac                      |    1 +
40  tests/conform/Makefile.am         |    1 +
41  tests/conform/test-no-gl-header.c |   17 ++++++++++++++++
42  12 files changed, 74 insertions(+), 15 deletions(-)
43  create mode 100644 cogl/cogl-gl-header.h.in
44  create mode 100644 tests/conform/test-no-gl-header.c
45
46 diff --git a/cogl/Makefile.am b/cogl/Makefile.am
47 index f6dbb0d..236963e 100644
48 --- a/cogl/Makefile.am
49 +++ b/cogl/Makefile.am
50 @@ -34,9 +34,9 @@ AM_CPPFLAGS = \
51  
52  AM_CFLAGS = $(COGL_DEP_CFLAGS) $(COGL_EXTRA_CFLAGS) $(MAINTAINER_CFLAGS)
53  
54 -BUILT_SOURCES += cogl-defines.h
55 -DISTCLEANFILES += cogl-defines.h
56 -EXTRA_DIST += cogl-defines.h.in
57 +BUILT_SOURCES += cogl-defines.h cogl-gl-header.h
58 +DISTCLEANFILES += cogl-defines.h cogl-gl-header.h
59 +EXTRA_DIST += cogl-defines.h.in cogl-gl-header.h.in
60  
61  # Note: The cogl-1.0/cogl-gl-1.0 files are essentially for
62  # compatability only.  I'm not really sure who could possibly be using
63 diff --git a/cogl/cogl-buffer-private.h b/cogl/cogl-buffer-private.h
64 index 62bcf45..0457af0 100644
65 --- a/cogl/cogl-buffer-private.h
66 +++ b/cogl/cogl-buffer-private.h
67 @@ -33,6 +33,7 @@
68  #include "cogl-object-private.h"
69  #include "cogl-buffer.h"
70  #include "cogl-context.h"
71 +#include "cogl-gl-header.h"
72  
73  G_BEGIN_DECLS
74  
75 diff --git a/cogl/cogl-context-private.h b/cogl/cogl-context-private.h
76 index 6d92faf..f8c691e 100644
77 --- a/cogl/cogl-context-private.h
78 +++ b/cogl/cogl-context-private.h
79 @@ -46,6 +46,7 @@
80  #include "cogl-texture-2d.h"
81  #include "cogl-texture-3d.h"
82  #include "cogl-texture-rectangle.h"
83 +#include "cogl-gl-header.h"
84  
85  typedef struct
86  {
87 diff --git a/cogl/cogl-defines.h.in b/cogl/cogl-defines.h.in
88 index 3d4b17d..ccdca06 100644
89 --- a/cogl/cogl-defines.h.in
90 +++ b/cogl/cogl-defines.h.in
91 @@ -29,7 +29,6 @@
92  #define __COGL_DEFINES_H__
93  
94  #include <glib.h>
95 -@COGL_GL_HEADER_INCLUDES@
96  
97  G_BEGIN_DECLS
98  
99 @@ -41,9 +40,6 @@ G_BEGIN_DECLS
100  #define NativeWindowType EGLNativeWindowType
101  #endif
102  
103 -#ifndef GL_OES_EGL_image
104 -#define GLeglImageOES void *
105 -#endif
106  G_END_DECLS
107  
108  #endif
109 diff --git a/cogl/cogl-gl-header.h.in b/cogl/cogl-gl-header.h.in
110 new file mode 100644
111 index 0000000..30bc837
112 --- /dev/null
113 +++ b/cogl/cogl-gl-header.h.in
114 @@ -0,0 +1,39 @@
115 +/*
116 + * Cogl
117 + *
118 + * An object oriented GL/GLES Abstraction/Utility Layer
119 + *
120 + * Copyright (C) 2012 Intel Corporation.
121 + *
122 + * This library is free software; you can redistribute it and/or
123 + * modify it under the terms of the GNU Lesser General Public
124 + * License as published by the Free Software Foundation; either
125 + * version 2 of the License, or (at your option) any later version.
126 + *
127 + * This library is distributed in the hope that it will be useful,
128 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
129 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
130 + * Lesser General Public License for more details.
131 + *
132 + * You should have received a copy of the GNU Lesser General Public
133 + * License along with this library. If not, see <http://www.gnu.org/licenses/>.
134 + *
135 + *
136 + */
137 +
138 +#if !defined(CLUTTER_COMPILATION)
139 +#error "cogl-gl-header.h should only be included when compiling Cogl"
140 +#endif
141 +
142 +#ifndef __COGL_GL_HEADER_H__
143 +#define __COGL_GL_HEADER_H__
144 +
145 +#include "cogl-defines.h"
146 +
147 +@COGL_GL_HEADER_INCLUDES@
148 +
149 +#ifndef GL_OES_EGL_image
150 +#define GLeglImageOES void *
151 +#endif
152 +
153 +#endif /* __COGL_GL_HEADER_H__ */
154 diff --git a/cogl/cogl-internal.h b/cogl/cogl-internal.h
155 index 9019859..e40b721 100644
156 --- a/cogl/cogl-internal.h
157 +++ b/cogl/cogl-internal.h
158 @@ -25,6 +25,7 @@
159  #define __COGL_INTERNAL_H
160  
161  #include "cogl-bitmask.h"
162 +#include "cogl-gl-header.h"
163  
164  #ifdef COGL_HAS_XLIB_SUPPORT
165  #include <X11/Xutil.h>
166 diff --git a/cogl/cogl-shader-private.h b/cogl/cogl-shader-private.h
167 index 6c05b3f..06575e6 100644
168 --- a/cogl/cogl-shader-private.h
169 +++ b/cogl/cogl-shader-private.h
170 @@ -26,6 +26,7 @@
171  
172  #include "cogl-handle.h"
173  #include "cogl-shader.h"
174 +#include "cogl-gl-header.h"
175  
176  typedef struct _CoglShader CoglShader;
177  
178 diff --git a/cogl/cogl-texture.h b/cogl/cogl-texture.h
179 index 4eeffb5..c73ea8a 100644
180 --- a/cogl/cogl-texture.h
181 +++ b/cogl/cogl-texture.h
182 @@ -207,12 +207,12 @@ cogl_texture_new_from_data (unsigned int      width,
183   * Since: 0.8
184   */
185  CoglTexture *
186 -cogl_texture_new_from_foreign (GLuint          gl_handle,
187 -                               GLenum          gl_target,
188 -                               GLuint          width,
189 -                               GLuint          height,
190 -                               GLuint          x_pot_waste,
191 -                               GLuint          y_pot_waste,
192 +cogl_texture_new_from_foreign (unsigned int gl_handle,
193 +                               unsigned int gl_target,
194 +                               unsigned int width,
195 +                               unsigned int height,
196 +                               unsigned int x_pot_waste,
197 +                               unsigned int y_pot_waste,
198                                 CoglPixelFormat format);
199  
200  /**
201 @@ -353,8 +353,8 @@ cogl_texture_is_sliced (CoglTexture *texture);
202   */
203  gboolean
204  cogl_texture_get_gl_texture (CoglTexture *texture,
205 -                             GLuint      *out_gl_handle,
206 -                             GLenum      *out_gl_target);
207 +                             unsigned int *out_gl_handle,
208 +                             unsigned int *out_gl_target);
209  
210  /**
211   * cogl_texture_get_data:
212 diff --git a/cogl/tesselator/tesselator.h b/cogl/tesselator/tesselator.h
213 index 69a6ece..5b651be 100644
214 --- a/cogl/tesselator/tesselator.h
215 +++ b/cogl/tesselator/tesselator.h
216 @@ -35,6 +35,7 @@
217  /* This just includes the defines needed by the tesselator code */
218  
219  #include "cogl/cogl-defines.h"
220 +#include "cogl/cogl-gl-header.h"
221  
222  typedef struct GLUtesselator GLUtesselator;
223  
224 diff --git a/configure.ac b/configure.ac
225 index ecf3d49..99fbf1a 100644
226 --- a/configure.ac
227 +++ b/configure.ac
228 @@ -1120,6 +1120,7 @@ cogl/Makefile
229  cogl/cogl-1.0.pc
230  cogl/cogl-2.0-experimental.pc
231  cogl/cogl-defines.h
232 +cogl/cogl-gl-header.h
233  cogl/cogl.rc
234  cogl-pango/Makefile
235  cogl-pango/cogl-pango-1.0.pc
236 diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
237 index e6ffc7b..5a82b46 100644
238 --- a/tests/conform/Makefile.am
239 +++ b/tests/conform/Makefile.am
240 @@ -52,6 +52,7 @@ test_sources = \
241         test-write-texture-formats.c \
242         test-point-size.c \
243         test-point-sprite.c \
244 +       test-no-gl-header.c \
245         $(NULL)
246  
247  test_conformance_SOURCES = $(common_sources) $(test_sources)
248 diff --git a/tests/conform/test-no-gl-header.c b/tests/conform/test-no-gl-header.c
249 new file mode 100644
250 index 0000000..49dae6c
251 --- /dev/null
252 +++ b/tests/conform/test-no-gl-header.c
253 @@ -0,0 +1,17 @@
254 +#include <cogl/cogl.h>
255 +
256 +#include "test-utils.h"
257 +
258 +/* If you just include cogl/cogl.h, you shouldn't end up including any
259 +   GL headers */
260 +#ifdef GL_TRUE
261 +#error "Including cogl.h shouldn't be including any GL headers"
262 +#endif
263 +
264 +void
265 +test_no_gl_header (void)
266 +{
267 +  if (cogl_test_verbose ())
268 +    g_print ("OK\n");
269 +}
270 +
271 -- 
272 1.7.3.16.g9464b
273