aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-06-05 20:24:51 -0400
committerDavid Robillard <d@drobilla.net>2022-06-08 19:48:13 -0400
commit27ce10b5039e931eaad33e9499a630552d4e1f06 (patch)
tree9ad33d28562935d72f768e68e9d24531b6059d8a
parentbb0fe3975df149eb45a21e39940f71e2273c8fd5 (diff)
downloadpugl-27ce10b5039e931eaad33e9499a630552d4e1f06.tar.gz
pugl-27ce10b5039e931eaad33e9499a630552d4e1f06.tar.bz2
pugl-27ce10b5039e931eaad33e9499a630552d4e1f06.zip
Separate private and public function implementations
-rw-r--r--meson.build7
-rw-r--r--src/common.c (renamed from src/implementation.c)297
-rw-r--r--src/internal.c191
-rw-r--r--src/internal.h (renamed from src/implementation.h)6
-rw-r--r--src/mac.m2
-rw-r--r--src/mac_cairo.m2
-rw-r--r--src/mac_gl.m2
-rw-r--r--src/mac_stub.m2
-rw-r--r--src/mac_vulkan.m2
-rw-r--r--src/win.c2
-rw-r--r--src/win.h2
-rw-r--r--src/x11.c2
-rw-r--r--test/test_inline_cpp.cpp3
-rw-r--r--test/test_inline_objcpp.mm9
14 files changed, 274 insertions, 255 deletions
diff --git a/meson.build b/meson.build
index ed78497..8176447 100644
--- a/meson.build
+++ b/meson.build
@@ -151,9 +151,14 @@ if library_type == 'static_library'
add_project_arguments(['-DPUGL_STATIC'], language: ['c', 'cpp', 'objc'])
endif
+common_sources = files(
+ 'src/common.c',
+ 'src/internal.c',
+)
+
libpugl = build_target(
core_name,
- files('src/implementation.c') + platform_sources,
+ common_sources + platform_sources,
version: meson.project_version(),
include_directories: includes,
c_args: library_args + core_args,
diff --git a/src/implementation.c b/src/common.c
index 84d9eea..313f0d0 100644
--- a/src/implementation.c
+++ b/src/common.c
@@ -1,13 +1,12 @@
// Copyright 2012-2022 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "implementation.h"
+#include "internal.h"
#include "types.h"
#include "pugl/pugl.h"
-#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
@@ -36,61 +35,6 @@ puglStrerror(const PuglStatus status)
return "Unknown 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);
- }
-}
-
-PuglStatus
-puglSetBlob(PuglBlob* const dest, const void* const data, const size_t len)
-{
- if (data) {
- void* const newData = realloc(dest->data, len + 1);
- if (!newData) {
- free(dest->data);
- dest->len = 0;
- return PUGL_NO_MEMORY;
- }
-
- memcpy(newData, data, len);
- ((char*)newData)[len] = 0;
-
- dest->len = len;
- dest->data = newData;
- } else {
- dest->len = 0;
- dest->data = NULL;
- }
-
- return PUGL_SUCCESS;
-}
-
-static void
-puglSetDefaultHints(PuglHints hints)
-{
- hints[PUGL_USE_COMPAT_PROFILE] = PUGL_TRUE;
- hints[PUGL_CONTEXT_VERSION_MAJOR] = 2;
- hints[PUGL_CONTEXT_VERSION_MINOR] = 0;
- hints[PUGL_RED_BITS] = 8;
- hints[PUGL_GREEN_BITS] = 8;
- hints[PUGL_BLUE_BITS] = 8;
- hints[PUGL_ALPHA_BITS] = 8;
- hints[PUGL_DEPTH_BITS] = 0;
- hints[PUGL_STENCIL_BITS] = 0;
- hints[PUGL_SAMPLES] = 0;
- hints[PUGL_DOUBLE_BUFFER] = PUGL_TRUE;
- hints[PUGL_SWAP_INTERVAL] = PUGL_DONT_CARE;
- hints[PUGL_RESIZABLE] = PUGL_FALSE;
- hints[PUGL_IGNORE_KEY_REPEAT] = PUGL_FALSE;
- hints[PUGL_REFRESH_RATE] = PUGL_DONT_CARE;
-}
-
PuglWorld*
puglNewWorld(PuglWorldType type, PuglWorldFlags flags)
{
@@ -141,6 +85,26 @@ puglGetClassName(const PuglWorld* world)
return world->className;
}
+static void
+puglSetDefaultHints(PuglHints hints)
+{
+ hints[PUGL_USE_COMPAT_PROFILE] = PUGL_TRUE;
+ hints[PUGL_CONTEXT_VERSION_MAJOR] = 2;
+ hints[PUGL_CONTEXT_VERSION_MINOR] = 0;
+ hints[PUGL_RED_BITS] = 8;
+ hints[PUGL_GREEN_BITS] = 8;
+ hints[PUGL_BLUE_BITS] = 8;
+ hints[PUGL_ALPHA_BITS] = 8;
+ hints[PUGL_DEPTH_BITS] = 0;
+ hints[PUGL_STENCIL_BITS] = 0;
+ hints[PUGL_SAMPLES] = 0;
+ hints[PUGL_DOUBLE_BUFFER] = PUGL_TRUE;
+ hints[PUGL_SWAP_INTERVAL] = PUGL_DONT_CARE;
+ hints[PUGL_RESIZABLE] = PUGL_FALSE;
+ hints[PUGL_IGNORE_KEY_REPEAT] = PUGL_FALSE;
+ hints[PUGL_REFRESH_RATE] = PUGL_DONT_CARE;
+}
+
PuglView*
puglNewView(PuglWorld* const world)
{
@@ -200,6 +164,38 @@ puglGetWorld(PuglView* view)
return view->world;
}
+void
+puglSetHandle(PuglView* view, PuglHandle handle)
+{
+ view->handle = handle;
+}
+
+PuglHandle
+puglGetHandle(PuglView* view)
+{
+ return view->handle;
+}
+
+PuglStatus
+puglSetBackend(PuglView* view, const PuglBackend* backend)
+{
+ view->backend = backend;
+ return PUGL_SUCCESS;
+}
+
+const PuglBackend*
+puglGetBackend(const PuglView* view)
+{
+ return view->backend;
+}
+
+PuglStatus
+puglSetEventFunc(PuglView* view, PuglEventFunc eventFunc)
+{
+ view->eventFunc = eventFunc;
+ return PUGL_SUCCESS;
+}
+
PuglStatus
puglSetViewHint(PuglView* view, PuglViewHint hint, int value)
{
@@ -226,6 +222,12 @@ puglGetViewHint(const PuglView* view, PuglViewHint hint)
return view->hints[hint];
}
+PuglRect
+puglGetFrame(const PuglView* view)
+{
+ return view->frame;
+}
+
const char*
puglGetWindowTitle(const PuglView* const view)
{
@@ -251,43 +253,12 @@ puglGetTransientParent(const PuglView* const view)
return view->transientParent;
}
-PuglStatus
-puglSetBackend(PuglView* view, const PuglBackend* backend)
-{
- view->backend = backend;
- return PUGL_SUCCESS;
-}
-
-const PuglBackend*
-puglGetBackend(const PuglView* view)
-{
- return view->backend;
-}
-
-void
-puglSetHandle(PuglView* view, PuglHandle handle)
-{
- view->handle = handle;
-}
-
-PuglHandle
-puglGetHandle(PuglView* view)
-{
- return view->handle;
-}
-
bool
puglGetVisible(const PuglView* view)
{
return view->visible;
}
-PuglRect
-puglGetFrame(const PuglView* view)
-{
- return view->frame;
-}
-
void*
puglGetContext(PuglView* view)
{
@@ -321,153 +292,3 @@ puglHideWindow(PuglView* view)
}
#endif
-
-PuglStatus
-puglSetEventFunc(PuglView* view, PuglEventFunc eventFunc)
-{
- view->eventFunc = eventFunc;
- return PUGL_SUCCESS;
-}
-
-/// Return the code point for buf, or the replacement character on error
-uint32_t
-puglDecodeUTF8(const uint8_t* buf)
-{
-#define FAIL_IF(cond) \
- do { \
- if (cond) \
- return 0xFFFD; \
- } while (0)
-
- // http://en.wikipedia.org/wiki/UTF-8
-
- if (buf[0] < 0x80) {
- return buf[0];
- }
-
- if (buf[0] < 0xC2) {
- return 0xFFFD;
- }
-
- if (buf[0] < 0xE0) {
- FAIL_IF((buf[1] & 0xC0u) != 0x80);
- return ((uint32_t)buf[0] << 6u) + buf[1] - 0x3080u;
- }
-
- if (buf[0] < 0xF0) {
- FAIL_IF((buf[1] & 0xC0u) != 0x80);
- FAIL_IF(buf[0] == 0xE0 && buf[1] < 0xA0);
- FAIL_IF((buf[2] & 0xC0u) != 0x80);
- return ((uint32_t)buf[0] << 12u) + //
- ((uint32_t)buf[1] << 6u) + //
- ((uint32_t)buf[2] - 0xE2080u);
- }
-
- if (buf[0] < 0xF5) {
- FAIL_IF((buf[1] & 0xC0u) != 0x80);
- FAIL_IF(buf[0] == 0xF0 && buf[1] < 0x90);
- FAIL_IF(buf[0] == 0xF4 && buf[1] >= 0x90);
- FAIL_IF((buf[2] & 0xC0u) != 0x80u);
- FAIL_IF((buf[3] & 0xC0u) != 0x80u);
- return (((uint32_t)buf[0] << 18u) + //
- ((uint32_t)buf[1] << 12u) + //
- ((uint32_t)buf[2] << 6u) + //
- ((uint32_t)buf[3] - 0x3C82080u));
- }
-
- 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)
-{
- assert(type == PUGL_CREATE || type == PUGL_DESTROY || type == PUGL_MAP ||
- type == PUGL_UNMAP || type == PUGL_UPDATE || type == PUGL_CLOSE ||
- type == PUGL_LOOP_ENTER || type == PUGL_LOOP_LEAVE);
-
- const PuglEvent event = {{type, 0}};
- return puglDispatchEvent(view, &event);
-}
-
-PuglStatus
-puglConfigure(PuglView* view, const PuglEvent* event)
-{
- PuglStatus st = PUGL_SUCCESS;
-
- assert(event->type == PUGL_CONFIGURE);
-
- view->frame.x = event->configure.x;
- view->frame.y = event->configure.y;
- view->frame.width = event->configure.width;
- view->frame.height = event->configure.height;
-
- if (puglMustConfigure(view, &event->configure)) {
- st = view->eventFunc(view, event);
- view->lastConfigure = event->configure;
- }
-
- return st;
-}
-
-PuglStatus
-puglExpose(PuglView* view, const PuglEvent* event)
-{
- return (event->expose.width > 0.0 && event->expose.height > 0.0)
- ? view->eventFunc(view, event)
- : PUGL_SUCCESS;
-}
-
-PuglStatus
-puglDispatchEvent(PuglView* view, const PuglEvent* event)
-{
- PuglStatus st0 = PUGL_SUCCESS;
- PuglStatus st1 = PUGL_SUCCESS;
-
- switch (event->type) {
- case PUGL_NOTHING:
- break;
- case PUGL_CREATE:
- case PUGL_DESTROY:
- if (!(st0 = view->backend->enter(view, NULL))) {
- st0 = view->eventFunc(view, event);
- st1 = view->backend->leave(view, NULL);
- }
- break;
- case PUGL_CONFIGURE:
- if (puglMustConfigure(view, &event->configure)) {
- if (!(st0 = view->backend->enter(view, NULL))) {
- st0 = puglConfigure(view, event);
- st1 = view->backend->leave(view, NULL);
- }
- }
- break;
- case PUGL_MAP:
- if (!view->visible) {
- view->visible = true;
- st0 = view->eventFunc(view, event);
- }
- break;
- case PUGL_UNMAP:
- if (view->visible) {
- view->visible = false;
- st0 = view->eventFunc(view, event);
- }
- break;
- case PUGL_EXPOSE:
- if (!(st0 = view->backend->enter(view, &event->expose))) {
- st0 = puglExpose(view, event);
- st1 = view->backend->leave(view, &event->expose);
- }
- break;
- default:
- st0 = view->eventFunc(view, event);
- }
-
- return st0 ? st0 : st1;
-}
diff --git a/src/internal.c b/src/internal.c
new file mode 100644
index 0000000..a3067f1
--- /dev/null
+++ b/src/internal.c
@@ -0,0 +1,191 @@
+// Copyright 2012-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#include "internal.h"
+
+#include "types.h"
+
+#include "pugl/pugl.h"
+
+#include <assert.h>
+#include <stdbool.h>
+#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)
+{
+ if (data) {
+ void* const newData = realloc(dest->data, len + 1);
+ if (!newData) {
+ free(dest->data);
+ dest->len = 0;
+ return PUGL_NO_MEMORY;
+ }
+
+ memcpy(newData, data, len);
+ ((char*)newData)[len] = 0;
+
+ dest->len = len;
+ dest->data = newData;
+ } else {
+ dest->len = 0;
+ dest->data = NULL;
+ }
+
+ return PUGL_SUCCESS;
+}
+
+/// Return the code point for buf, or the replacement character on error
+uint32_t
+puglDecodeUTF8(const uint8_t* buf)
+{
+#define FAIL_IF(cond) \
+ do { \
+ if (cond) \
+ return 0xFFFD; \
+ } while (0)
+
+ // http://en.wikipedia.org/wiki/UTF-8
+
+ if (buf[0] < 0x80) {
+ return buf[0];
+ }
+
+ if (buf[0] < 0xC2) {
+ return 0xFFFD;
+ }
+
+ if (buf[0] < 0xE0) {
+ FAIL_IF((buf[1] & 0xC0u) != 0x80);
+ return ((uint32_t)buf[0] << 6u) + buf[1] - 0x3080u;
+ }
+
+ if (buf[0] < 0xF0) {
+ FAIL_IF((buf[1] & 0xC0u) != 0x80);
+ FAIL_IF(buf[0] == 0xE0 && buf[1] < 0xA0);
+ FAIL_IF((buf[2] & 0xC0u) != 0x80);
+ return ((uint32_t)buf[0] << 12u) + //
+ ((uint32_t)buf[1] << 6u) + //
+ ((uint32_t)buf[2] - 0xE2080u);
+ }
+
+ if (buf[0] < 0xF5) {
+ FAIL_IF((buf[1] & 0xC0u) != 0x80);
+ FAIL_IF(buf[0] == 0xF0 && buf[1] < 0x90);
+ FAIL_IF(buf[0] == 0xF4 && buf[1] >= 0x90);
+ FAIL_IF((buf[2] & 0xC0u) != 0x80u);
+ FAIL_IF((buf[3] & 0xC0u) != 0x80u);
+ return (((uint32_t)buf[0] << 18u) + //
+ ((uint32_t)buf[1] << 12u) + //
+ ((uint32_t)buf[2] << 6u) + //
+ ((uint32_t)buf[3] - 0x3C82080u));
+ }
+
+ 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)
+{
+ assert(type == PUGL_CREATE || type == PUGL_DESTROY || type == PUGL_MAP ||
+ type == PUGL_UNMAP || type == PUGL_UPDATE || type == PUGL_CLOSE ||
+ type == PUGL_LOOP_ENTER || type == PUGL_LOOP_LEAVE);
+
+ const PuglEvent event = {{type, 0}};
+ return puglDispatchEvent(view, &event);
+}
+
+PuglStatus
+puglConfigure(PuglView* view, const PuglEvent* event)
+{
+ PuglStatus st = PUGL_SUCCESS;
+
+ assert(event->type == PUGL_CONFIGURE);
+
+ view->frame.x = event->configure.x;
+ view->frame.y = event->configure.y;
+ view->frame.width = event->configure.width;
+ view->frame.height = event->configure.height;
+
+ if (puglMustConfigure(view, &event->configure)) {
+ st = view->eventFunc(view, event);
+ view->lastConfigure = event->configure;
+ }
+
+ return st;
+}
+
+PuglStatus
+puglExpose(PuglView* view, const PuglEvent* event)
+{
+ return (event->expose.width > 0.0 && event->expose.height > 0.0)
+ ? view->eventFunc(view, event)
+ : PUGL_SUCCESS;
+}
+
+PuglStatus
+puglDispatchEvent(PuglView* view, const PuglEvent* event)
+{
+ PuglStatus st0 = PUGL_SUCCESS;
+ PuglStatus st1 = PUGL_SUCCESS;
+
+ switch (event->type) {
+ case PUGL_NOTHING:
+ break;
+ case PUGL_CREATE:
+ case PUGL_DESTROY:
+ if (!(st0 = view->backend->enter(view, NULL))) {
+ st0 = view->eventFunc(view, event);
+ st1 = view->backend->leave(view, NULL);
+ }
+ break;
+ case PUGL_CONFIGURE:
+ if (puglMustConfigure(view, &event->configure)) {
+ if (!(st0 = view->backend->enter(view, NULL))) {
+ st0 = puglConfigure(view, event);
+ st1 = view->backend->leave(view, NULL);
+ }
+ }
+ break;
+ case PUGL_MAP:
+ if (!view->visible) {
+ view->visible = true;
+ st0 = view->eventFunc(view, event);
+ }
+ break;
+ case PUGL_UNMAP:
+ if (view->visible) {
+ view->visible = false;
+ st0 = view->eventFunc(view, event);
+ }
+ break;
+ case PUGL_EXPOSE:
+ if (!(st0 = view->backend->enter(view, &event->expose))) {
+ st0 = puglExpose(view, event);
+ st1 = view->backend->leave(view, &event->expose);
+ }
+ break;
+ default:
+ st0 = view->eventFunc(view, event);
+ }
+
+ return st0 ? st0 : st1;
+}
diff --git a/src/implementation.h b/src/internal.h
index 7c95fd2..cfd65d2 100644
--- a/src/implementation.h
+++ b/src/internal.h
@@ -1,8 +1,8 @@
// Copyright 2012-2022 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#ifndef PUGL_IMPLEMENTATION_H
-#define PUGL_IMPLEMENTATION_H
+#ifndef PUGL_INTERNAL_H
+#define PUGL_INTERNAL_H
#include "attributes.h"
#include "types.h"
@@ -62,4 +62,4 @@ puglDispatchEvent(PuglView* view, const PuglEvent* event);
PUGL_END_DECLS
-#endif // PUGL_IMPLEMENTATION_H
+#endif // PUGL_INTERNAL_H
diff --git a/src/mac.m b/src/mac.m
index 90e4505..b2b36a5 100644
--- a/src/mac.m
+++ b/src/mac.m
@@ -6,7 +6,7 @@
#include "mac.h"
-#include "implementation.h"
+#include "internal.h"
#include "pugl/pugl.h"
diff --git a/src/mac_cairo.m b/src/mac_cairo.m
index e269955..66af5ba 100644
--- a/src/mac_cairo.m
+++ b/src/mac_cairo.m
@@ -1,7 +1,7 @@
// Copyright 2019-2022 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "implementation.h"
+#include "internal.h"
#include "mac.h"
#include "stub.h"
diff --git a/src/mac_gl.m b/src/mac_gl.m
index 25704c3..ddd9fde 100644
--- a/src/mac_gl.m
+++ b/src/mac_gl.m
@@ -1,7 +1,7 @@
// Copyright 2019-2022 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "implementation.h"
+#include "internal.h"
#include "mac.h"
#include "stub.h"
diff --git a/src/mac_stub.m b/src/mac_stub.m
index a0d0322..ceffa6e 100644
--- a/src/mac_stub.m
+++ b/src/mac_stub.m
@@ -1,7 +1,7 @@
// Copyright 2019-2022 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "implementation.h"
+#include "internal.h"
#include "mac.h"
#include "stub.h"
diff --git a/src/mac_vulkan.m b/src/mac_vulkan.m
index 619b75f..2362db1 100644
--- a/src/mac_vulkan.m
+++ b/src/mac_vulkan.m
@@ -3,7 +3,7 @@
#define VK_NO_PROTOTYPES 1
-#include "implementation.h"
+#include "internal.h"
#include "mac.h"
#include "stub.h"
#include "types.h"
diff --git a/src/win.c b/src/win.c
index 02d5bdb..bfa39c2 100644
--- a/src/win.c
+++ b/src/win.c
@@ -3,7 +3,7 @@
#include "win.h"
-#include "implementation.h"
+#include "internal.h"
#include "pugl/pugl.h"
diff --git a/src/win.h b/src/win.h
index e733c10..4a89e11 100644
--- a/src/win.h
+++ b/src/win.h
@@ -4,7 +4,7 @@
#ifndef PUGL_SRC_WIN_H
#define PUGL_SRC_WIN_H
-#include "implementation.h"
+#include "internal.h"
#include "pugl/pugl.h"
diff --git a/src/x11.c b/src/x11.c
index deae154..934b4bb 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -6,7 +6,7 @@
#include "x11.h"
#include "attributes.h"
-#include "implementation.h"
+#include "internal.h"
#include "types.h"
#include "pugl/pugl.h"
diff --git a/test/test_inline_cpp.cpp b/test/test_inline_cpp.cpp
index 5b5278e..f5694eb 100644
--- a/test/test_inline_cpp.cpp
+++ b/test/test_inline_cpp.cpp
@@ -23,7 +23,8 @@
# pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
-#include "../src/implementation.c" // IWYU pragma: keep
+#include "../src/common.c" // IWYU pragma: keep
+#include "../src/internal.c" // IWYU pragma: keep
#if defined(_WIN32)
# include "../src/win.c" // IWYU pragma: keep
diff --git a/test/test_inline_objcpp.mm b/test/test_inline_objcpp.mm
index 0c35f73..1c9079b 100644
--- a/test/test_inline_objcpp.mm
+++ b/test/test_inline_objcpp.mm
@@ -9,10 +9,11 @@
# pragma clang diagnostic ignored "-Wold-style-cast"
#endif
-#include "../src/implementation.c" // IWYU pragma: keep
-#include "../src/mac.h" // IWYU pragma: keep
-#include "../src/mac.m" // IWYU pragma: keep
-#include "../src/mac_stub.m" // IWYU pragma: keep
+#include "../src/common.c" // IWYU pragma: keep
+#include "../src/internal.c" // IWYU pragma: keep
+#include "../src/mac.h" // IWYU pragma: keep
+#include "../src/mac.m" // IWYU pragma: keep
+#include "../src/mac_stub.m" // IWYU pragma: keep
#if defined(WITH_CAIRO)
# include "../src/mac_cairo.m" // IWYU pragma: keep