Skip to content

Commit

Permalink
Add common header
Browse files Browse the repository at this point in the history
We're going to use this header to provide shared macros. Right now, we
can use it to replace the:

    #ifdef __cplusplus
    extern "C" {
    #endif

    …

    #ifdef __cplusplus
    }
    #endif

Stanzas for every installed header, with easier to read macros in the
same spirit of Cairo and GLib.
  • Loading branch information
ebassi committed Jan 25, 2017
1 parent 41bea9e commit 0625a74
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 29 deletions.
1 change: 1 addition & 0 deletions include/epoxy/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
epoxyincludedir = $(includedir)/epoxy

epoxyinclude_HEADERS = \
common.h \
gl.h \
$(EGL_INCLUDES) \
$(GLX_INCLUDES) \
Expand Down
40 changes: 40 additions & 0 deletions include/epoxy/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2017 Emmanuele Bassi
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

/** @file common.h
*
* A common header file, used to define macros and shared symbols.
*/

#ifndef EPOXY_COMMON_H
#define EPOXY_COMMON_H

#ifdef __cplusplus
# define EPOXY_BEGIN_DECLS extern "C" {
# define EPOXY_END_DECLS }
#else
# define EPOXY_BEGIN_DECLS
# define EPOXY_END_DECLS
#endif

#endif /* EPOXY_COMMON_H */
12 changes: 5 additions & 7 deletions include/epoxy/egl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@
#ifndef EPOXY_EGL_H
#define EPOXY_EGL_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>

#include "epoxy/common.h"

#if defined(__egl_h_) || defined(__eglext_h_)
#error epoxy/egl.h must be included before (or in place of) GL/egl.h
#else
Expand All @@ -45,11 +43,11 @@ extern "C" {

#include "epoxy/egl_generated.h"

EPOXY_BEGIN_DECLS

bool epoxy_has_egl_extension(EGLDisplay dpy, const char *extension);
int epoxy_egl_version(EGLDisplay dpy);

#ifdef __cplusplus
} /* extern "C" */
#endif
EPOXY_END_DECLS

#endif /* EPOXY_EGL_H */
12 changes: 5 additions & 7 deletions include/epoxy/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@
#ifndef EPOXY_GL_H
#define EPOXY_GL_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>

#include "epoxy/common.h"

#if defined(__gl_h_) || defined(__glext_h_)
#error epoxy/gl.h must be included before (or in place of) GL/gl.h
#else
Expand Down Expand Up @@ -93,12 +91,12 @@ extern "C" {

#include "epoxy/gl_generated.h"

EPOXY_BEGIN_DECLS

EPOXY_IMPORTEXPORT bool epoxy_has_gl_extension(const char *extension);
EPOXY_IMPORTEXPORT bool epoxy_is_desktop_gl(void);
EPOXY_IMPORTEXPORT int epoxy_gl_version(void);

#ifdef __cplusplus
} /* extern "C" */
#endif
EPOXY_END_DECLS

#endif /* EPOXY_GL_H */
10 changes: 3 additions & 7 deletions include/epoxy/glx.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
#ifndef EPOXY_GLX_H
#define EPOXY_GLX_H

#ifdef __cplusplus
extern "C" {
#endif

#include <epoxy/gl.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
Expand All @@ -49,11 +45,11 @@ extern "C" {

#include "epoxy/glx_generated.h"

EPOXY_BEGIN_DECLS

bool epoxy_has_glx_extension(Display *dpy, int screen, const char *extension);
int epoxy_glx_version(Display *dpy, int screen);

#ifdef __cplusplus
} /* extern "C" */
#endif
EPOXY_END_DECLS

#endif /* EPOXY_GLX_H */
4 changes: 3 additions & 1 deletion include/epoxy/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
headers = [ 'common.h' ]

gl_generated = custom_target('gl_generated.h',
input: gl_registry,
output: [
Expand All @@ -15,7 +17,7 @@ gl_generated = custom_target('gl_generated.h',
install_dir: join_paths(epoxy_includedir, 'epoxy'))

gen_headers = [ gl_generated ]
headers = [ 'gl.h', ]
headers += [ 'gl.h', ]

if build_egl
egl_generated = custom_target('egl_generated.h',
Expand Down
12 changes: 5 additions & 7 deletions include/epoxy/wgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
#ifndef EPOXY_WGL_H
#define EPOXY_WGL_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>
#include <windows.h>

#include "epoxy/common.h"

#undef wglUseFontBitmaps
#undef wglUseFontOutlines

Expand All @@ -54,11 +52,11 @@ extern "C" {

#include "epoxy/wgl_generated.h"

EPOXY_BEGIN_DECLS

EPOXY_IMPORTEXPORT bool epoxy_has_wgl_extension(HDC hdc, const char *extension);
EPOXY_IMPORTEXPORT void epoxy_handle_external_wglMakeCurrent(void);

#ifdef __cplusplus
} /* extern "C" */
#endif
EPOXY_END_DECLS

#endif /* EPOXY_WGL_H */

0 comments on commit 0625a74

Please sign in to comment.