@geastack/apple 0.2.24 → 0.2.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/apple",
3
- "version": "0.2.24",
3
+ "version": "0.2.25",
4
4
  "description": "Generated Apple SDK bindings plus the macOS, iOS and tvOS native build targets for Gea apps.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1074,6 +1074,7 @@ MM_SOURCES=(
1074
1074
  # gea::platform::audio — the AVAudioEngine backend, shared verbatim with iOS.
1075
1075
  "$ROOT_DIR/targets/shared/apple_audio.mm"
1076
1076
  "$ROOT_DIR/targets/macos/main/macos_main.mm"
1077
+ "$ROOT_DIR/targets/macos/main/appkit_host.mm"
1077
1078
  "$ROOT_DIR/targets/macos/main/macos_native_shell.mm"
1078
1079
  "$ROOT_DIR/targets/macos/main/macos_display.mm"
1079
1080
  "$ROOT_DIR/targets/macos/main/macos_timers.mm"
@@ -0,0 +1,43 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Host extensions: native code a package (or an app) compiles into a macOS
3
+ // build to own part of the window -- typically a rendering surface such as a
4
+ // CAMetalLayer that a GL or GPU layer presents into, which the generated
5
+ // program draws through. The AppKit counterpart of gea_uikit_host.h, so a
6
+ // program that runs on tvOS runs unchanged on macOS.
7
+ //
8
+ // An extension registers itself from a static initializer:
9
+ //
10
+ // static const gea_appkit_host_extension kSurface = {
11
+ // GEA_APPKIT_HOST_EXTENSION_VERSION, "my-surface", attach, layout };
12
+ // static const bool kRegistered = (gea_appkit_register_host_extension(&kSurface), true);
13
+ //
14
+ // Every callback may be null. Sizes are in points; `scale` is device pixels
15
+ // per point.
16
+ #pragma once
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #endif
21
+
22
+ #define GEA_APPKIT_HOST_EXTENSION_VERSION 1u
23
+
24
+ typedef struct gea_appkit_host_extension {
25
+ unsigned version; // GEA_APPKIT_HOST_EXTENSION_VERSION
26
+ const char *name; // for diagnostics
27
+ // Once, after the window's root view exists and before the app's top level
28
+ // runs. `rootView` is the root NSView (a bridged NSView *): an extension adds
29
+ // its own subviews to it. Returning zero logs an error naming the extension.
30
+ int (*attach)(void *rootView, double width, double height, double scale);
31
+ // The root view's size or scale changed.
32
+ void (*layout)(double width, double height, double scale);
33
+ } gea_appkit_host_extension;
34
+
35
+ void gea_appkit_register_host_extension(const gea_appkit_host_extension *extension);
36
+
37
+ // Called by the target (macos_main.mm).
38
+ void gea_appkit_host_attach(void *rootView, double width, double height, double scale);
39
+ void gea_appkit_host_layout(double width, double height, double scale);
40
+
41
+ #ifdef __cplusplus
42
+ }
43
+ #endif
@@ -0,0 +1,43 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // The registry and life-cycle calls of macOS host extensions (gea_appkit_host.h).
3
+ #include "gea_appkit_host.h"
4
+
5
+ #include <cstdio>
6
+
7
+ namespace {
8
+
9
+ constexpr int kMaxExtensions = 8;
10
+ const gea_appkit_host_extension *gExtensions[kMaxExtensions];
11
+ int gExtensionCount = 0;
12
+
13
+ } // namespace
14
+
15
+ extern "C" void gea_appkit_register_host_extension(const gea_appkit_host_extension *extension)
16
+ {
17
+ if (!extension || extension->version != GEA_APPKIT_HOST_EXTENSION_VERSION) {
18
+ std::fprintf(stderr, "[gea] host extension %s has an unsupported version\n", extension && extension->name ? extension->name : "?");
19
+ return;
20
+ }
21
+ if (gExtensionCount >= kMaxExtensions) {
22
+ std::fprintf(stderr, "[gea] too many host extensions; %s ignored\n", extension->name ? extension->name : "?");
23
+ return;
24
+ }
25
+ gExtensions[gExtensionCount++] = extension;
26
+ }
27
+
28
+ extern "C" void gea_appkit_host_attach(void *rootView, double width, double height, double scale)
29
+ {
30
+ for (int i = 0; i < gExtensionCount; ++i) {
31
+ const auto *extension = gExtensions[i];
32
+ if (extension->attach && !extension->attach(rootView, width, height, scale)) {
33
+ std::fprintf(stderr, "[gea] host extension %s failed to attach\n", extension->name ? extension->name : "?");
34
+ }
35
+ }
36
+ }
37
+
38
+ extern "C" void gea_appkit_host_layout(double width, double height, double scale)
39
+ {
40
+ for (int i = 0; i < gExtensionCount; ++i) {
41
+ if (gExtensions[i]->layout) gExtensions[i]->layout(width, height, scale);
42
+ }
43
+ }
@@ -64,6 +64,7 @@ namespace gea::macos { void installWifiDriver(); int nodeIdForView(NSView *view)
64
64
  #include <cstdio>
65
65
  #include <cstdlib>
66
66
  #include <cstring>
67
+ #include "gea_appkit_host.h"
67
68
 
68
69
  extern "C" int gea_embedded_now_ms(void);
69
70
  // Headless text-input driver used by GEA_MACOS_SYNTH_INPUT (press_bridge.mm).
@@ -534,6 +535,10 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
534
535
  if (gea::macos::thermalright::enabled()) {
535
536
  size = NSMakeSize(gea::platform::display::kWidth, gea::platform::display::kHeight);
536
537
  }
538
+ // Host extensions (a package's rendering surface) attach before the
539
+ // program's top level runs, as on iOS and tvOS.
540
+ gea_appkit_host_attach((__bridge void *)self.rootView, size.width, size.height,
541
+ self.window.backingScaleFactor > 0 ? self.window.backingScaleFactor : 1.0);
537
542
  gea_macos_smoke_log("[gea-macos] before Application::init");
538
543
  gea::framework::app::Application::init(static_cast<int>(size.width), static_cast<int>(size.height));
539
544
  gea_macos_smoke_log("[gea-macos] after Application::init");