diff options
-rw-r--r-- | src/common.c | 3 | ||||
-rw-r--r-- | src/internal.c | 35 | ||||
-rw-r--r-- | src/internal.h | 18 | ||||
-rw-r--r-- | src/mac.m | 1 | ||||
-rw-r--r-- | src/platform.h | 33 | ||||
-rw-r--r-- | src/win.c | 1 | ||||
-rw-r--r-- | src/x11.c | 1 |
7 files changed, 58 insertions, 34 deletions
diff --git a/src/common.c b/src/common.c index 313f0d0..dc01da4 100644 --- a/src/common.c +++ b/src/common.c @@ -1,8 +1,11 @@ // Copyright 2012-2022 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC +// Common implementations of public API functions in the core library + #include "internal.h" +#include "platform.h" #include "types.h" #include "pugl/pugl.h" diff --git a/src/internal.c b/src/internal.c index a3067f1..69f220e 100644 --- a/src/internal.c +++ b/src/internal.c @@ -12,17 +12,6 @@ #include <stdlib.h> #include <string.h> -void -puglSetString(char** dest, const char* string) -{ - if (*dest != string) { - const size_t len = strlen(string); - - *dest = (char*)realloc(*dest, len + 1); - strncpy(*dest, string, len + 1); - } -} - PuglStatus puglSetBlob(PuglBlob* const dest, const void* const data, const size_t len) { @@ -47,7 +36,17 @@ puglSetBlob(PuglBlob* const dest, const void* const data, const size_t len) return PUGL_SUCCESS; } -/// Return the code point for buf, or the replacement character on error +void +puglSetString(char** dest, const char* string) +{ + if (*dest != string) { + const size_t len = strlen(string); + + *dest = (char*)realloc(*dest, len + 1); + strncpy(*dest, string, len + 1); + } +} + uint32_t puglDecodeUTF8(const uint8_t* buf) { @@ -96,12 +95,6 @@ puglDecodeUTF8(const uint8_t* buf) return 0xFFFD; } -static inline bool -puglMustConfigure(PuglView* view, const PuglConfigureEvent* configure) -{ - return !!memcmp(configure, &view->lastConfigure, sizeof(PuglConfigureEvent)); -} - PuglStatus puglDispatchSimpleEvent(PuglView* view, const PuglEventType type) { @@ -113,6 +106,12 @@ puglDispatchSimpleEvent(PuglView* view, const PuglEventType type) return puglDispatchEvent(view, &event); } +static inline bool +puglMustConfigure(PuglView* view, const PuglConfigureEvent* configure) +{ + return !!memcmp(configure, &view->lastConfigure, sizeof(PuglConfigureEvent)); +} + PuglStatus puglConfigure(PuglView* view, const PuglEvent* event) { diff --git a/src/internal.h b/src/internal.h index cfd65d2..e3e7924 100644 --- a/src/internal.h +++ b/src/internal.h @@ -1,6 +1,8 @@ // Copyright 2012-2022 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC +// Internal utilities available to platform implementations + #ifndef PUGL_INTERNAL_H #define PUGL_INTERNAL_H @@ -22,22 +24,6 @@ puglSetBlob(PuglBlob* dest, const void* data, size_t len); void puglSetString(char** dest, const char* string); -/// Allocate and initialise world internals (implemented once per platform) -PuglWorldInternals* -puglInitWorldInternals(PuglWorldType type, PuglWorldFlags flags); - -/// Destroy and free world internals (implemented once per platform) -void -puglFreeWorldInternals(PuglWorld* world); - -/// Allocate and initialise view internals (implemented once per platform) -PuglInternals* -puglInitViewInternals(PuglWorld* world); - -/// Destroy and free view internals (implemented once per platform) -void -puglFreeViewInternals(PuglView* view); - /// Return the Unicode code point for `buf` or the replacement character uint32_t puglDecodeUTF8(const uint8_t* buf); @@ -7,6 +7,7 @@ #include "mac.h" #include "internal.h" +#include "platform.h" #include "pugl/pugl.h" diff --git a/src/platform.h b/src/platform.h new file mode 100644 index 0000000..ec16197 --- /dev/null +++ b/src/platform.h @@ -0,0 +1,33 @@ +// Copyright 2012-2022 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +// The API that a platform implementation must define + +#ifndef PUGL_PLATFORM_H +#define PUGL_PLATFORM_H + +#include "types.h" + +#include "pugl/pugl.h" + +PUGL_BEGIN_DECLS + +/// Allocate and initialise world internals (implemented once per platform) +PuglWorldInternals* +puglInitWorldInternals(PuglWorldType type, PuglWorldFlags flags); + +/// Destroy and free world internals (implemented once per platform) +void +puglFreeWorldInternals(PuglWorld* world); + +/// Allocate and initialise view internals (implemented once per platform) +PuglInternals* +puglInitViewInternals(PuglWorld* world); + +/// Destroy and free view internals (implemented once per platform) +void +puglFreeViewInternals(PuglView* view); + +PUGL_END_DECLS + +#endif // PUGL_PLATFORM_H @@ -4,6 +4,7 @@ #include "win.h" #include "internal.h" +#include "platform.h" #include "pugl/pugl.h" @@ -7,6 +7,7 @@ #include "attributes.h" #include "internal.h" +#include "platform.h" #include "types.h" #include "pugl/pugl.h" |