@geastack/apple 0.2.25 → 0.2.27
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/README.md +18 -8
- package/package.json +2 -2
- package/targets/ios/README.md +26 -11
- package/targets/ios/native-packages.mjs +3 -1
- package/targets/macos/README.md +54 -56
- package/targets/macos/build-macos.sh +45 -5
- package/targets/macos/main/font_registry.h +3 -0
- package/targets/macos/main/font_registry.mm +36 -9
- package/targets/macos/main/macos_display.mm +44 -11
- package/targets/macos/main/macos_main.mm +50 -2
- package/targets/macos/main/macos_prerender.h +8 -0
- package/targets/macos/main/macos_timers.mm +11 -0
- package/targets/macos/sync-resources.mjs +17 -0
package/README.md
CHANGED
|
@@ -10,22 +10,31 @@ npm install @geastack/apple
|
|
|
10
10
|
|
|
11
11
|
## Building an app
|
|
12
12
|
|
|
13
|
-
The `gea` CLI drives the targets:
|
|
13
|
+
The `gea` CLI drives the targets. It is a separate package: install
|
|
14
|
+
`@geastack/cli` in the app too (0.1.110 or later for tvOS), and declare each
|
|
15
|
+
target in the app's `package.json`, for example
|
|
16
|
+
`"gea": { "targets": { "macos": true, "ios": true, "tvos": true } }`. From the
|
|
17
|
+
app folder:
|
|
14
18
|
|
|
15
19
|
```sh
|
|
16
|
-
|
|
17
|
-
gea build --target
|
|
18
|
-
gea build --target
|
|
20
|
+
npm install --save-dev @geastack/cli
|
|
21
|
+
npx gea build --target macos
|
|
22
|
+
npx gea build --target ios
|
|
23
|
+
npx gea build --target tvos
|
|
19
24
|
```
|
|
20
25
|
|
|
21
26
|
The target build scripts can also be run directly from an app directory that
|
|
22
|
-
has the GeaStack packages installed
|
|
27
|
+
has the GeaStack packages (including `@geastack/cli`) installed. Run this way
|
|
28
|
+
they do not receive the app's `gea.targets.<target>.build` configuration, and
|
|
29
|
+
`build-ios.sh` boots, installs and launches the app on a simulator or device
|
|
30
|
+
after building, like `gea run`; prefix `GEA_IOS_SKIP_LAUNCH=1` to stop after
|
|
31
|
+
the build, which is what `gea build` does:
|
|
23
32
|
|
|
24
33
|
```sh
|
|
25
34
|
node_modules/@geastack/apple/targets/macos/build-macos.sh my-app
|
|
26
|
-
node_modules/@geastack/apple/targets/ios/build-ios.sh my-app simulator
|
|
35
|
+
GEA_IOS_SKIP_LAUNCH=1 node_modules/@geastack/apple/targets/ios/build-ios.sh my-app simulator
|
|
27
36
|
GEA_IOS_DEVELOPMENT_TEAM=ABCDE12345 node_modules/@geastack/apple/targets/ios/build-ios.sh my-app device
|
|
28
|
-
node_modules/@geastack/apple/targets/ios/build-ios.sh my-app simulator tvos
|
|
37
|
+
GEA_IOS_SKIP_LAUNCH=1 node_modules/@geastack/apple/targets/ios/build-ios.sh my-app simulator tvos
|
|
29
38
|
```
|
|
30
39
|
|
|
31
40
|
Requires Xcode with the macOS, iOS and tvOS SDKs you target. Each target directory has its own
|
|
@@ -138,7 +147,8 @@ string on success. A located occurrence must lie within a week of its
|
|
|
138
147
|
`occurrenceDate`.
|
|
139
148
|
|
|
140
149
|
macOS ends a process that asks for calendar access without a usage
|
|
141
|
-
description. Add both keys to `
|
|
150
|
+
description. Add both keys to `macos.json` in the app folder (next to its
|
|
151
|
+
`package.json`); its optional `infoPlist`
|
|
142
152
|
object is merged over the shared `Info.plist` template:
|
|
143
153
|
|
|
144
154
|
```json
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/apple",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.27",
|
|
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": {
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"dependencies": {
|
|
118
118
|
"@geastack/compiler": "^1.0.34",
|
|
119
119
|
"@geastack/core": "^0.1.52",
|
|
120
|
-
"@geastack/elements": "^0.1.
|
|
120
|
+
"@geastack/elements": "^0.1.7",
|
|
121
121
|
"@geastack/engine": "^0.1.23",
|
|
122
122
|
"@geastack/geaos": "^0.1.3",
|
|
123
123
|
"@geastack/geatsc-plugin-apple-native": "^0.1.4",
|
package/targets/ios/README.md
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
# iOS target
|
|
2
2
|
|
|
3
|
-
Build a
|
|
3
|
+
Build a Gea JSX app as a native UIKit app.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
The app needs `@geastack/apple` and `@geastack/cli` (0.1.110 or later for tvOS)
|
|
6
|
+
in its own dependencies and `"ios": true` under `gea.targets` in its
|
|
7
|
+
`package.json`; `npx create-geastack my-app --targets ios` sets up all three,
|
|
8
|
+
and for an existing app:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @geastack/apple
|
|
12
|
+
npm install --save-dev @geastack/cli
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
From the app folder, the CLI drives this target:
|
|
7
16
|
|
|
8
17
|
```bash
|
|
9
18
|
npx gea build --target ios # simulator .app, no launch
|
|
@@ -12,11 +21,15 @@ npx gea run --target ios # build, install and launch on a simu
|
|
|
12
21
|
npx gea run --target ios --mode device # build, sign, install and launch on an iPhone
|
|
13
22
|
```
|
|
14
23
|
|
|
15
|
-
The
|
|
16
|
-
|
|
24
|
+
The CLI runs `build-ios.sh <app-id> <simulator|device> [tvos]` from the
|
|
25
|
+
installed package, with `GEA_IOS_SKIP_LAUNCH=1` for `gea build` and the app's
|
|
26
|
+
build configuration from `gea.targets.ios`. The script can also be run
|
|
27
|
+
directly from the app folder; it then installs and launches the app after
|
|
28
|
+
building unless `GEA_IOS_SKIP_LAUNCH=1` is set, and does not apply the
|
|
29
|
+
`gea.targets.ios.build` settings:
|
|
17
30
|
|
|
18
31
|
```bash
|
|
19
|
-
node_modules/@geastack/apple/targets/ios/build-ios.sh <app-id> simulator
|
|
32
|
+
GEA_IOS_SKIP_LAUNCH=1 node_modules/@geastack/apple/targets/ios/build-ios.sh <app-id> simulator
|
|
20
33
|
```
|
|
21
34
|
|
|
22
35
|
The script resolves `@geastack/core`, `@geastack/compiler`, the apple-native
|
|
@@ -39,7 +52,7 @@ GEA_IOS_DEVELOPMENT_TEAM=ABCDE12345 npx gea run --target ios --mode device
|
|
|
39
52
|
To see the automatically detected team id:
|
|
40
53
|
|
|
41
54
|
```bash
|
|
42
|
-
targets/ios/detect-development-team.mjs
|
|
55
|
+
node node_modules/@geastack/apple/targets/ios/detect-development-team.mjs
|
|
43
56
|
```
|
|
44
57
|
|
|
45
58
|
Signed device builds auto-pick an attached iPhone with Developer Mode enabled,
|
|
@@ -63,18 +76,20 @@ the source of truth.
|
|
|
63
76
|
## tvOS
|
|
64
77
|
|
|
65
78
|
Apps that declare `gea.targets.tvos` can use the shared UIKit host on tvOS 17
|
|
66
|
-
or later. Install the tvOS platform in Xcode's Components settings.
|
|
67
|
-
|
|
79
|
+
or later. Install the tvOS platform in Xcode's Components settings. The app
|
|
80
|
+
needs the same `@geastack/apple` and `@geastack/cli` dependencies as on iOS
|
|
81
|
+
(the `three-tvos` example lists both). From the app folder, run it on an Apple
|
|
82
|
+
TV simulator:
|
|
68
83
|
|
|
69
84
|
```sh
|
|
70
|
-
gea run --target tvos
|
|
85
|
+
npx gea run --target tvos
|
|
71
86
|
```
|
|
72
87
|
|
|
73
88
|
For a physical Apple TV, pair it with Xcode over the local network and use an
|
|
74
89
|
Apple development team configured for the device:
|
|
75
90
|
|
|
76
91
|
```sh
|
|
77
|
-
GEA_IOS_DEVELOPMENT_TEAM=ABCDE12345 gea run --target tvos --mode device
|
|
92
|
+
GEA_IOS_DEVELOPMENT_TEAM=ABCDE12345 npx gea run --target tvos --mode device
|
|
78
93
|
```
|
|
79
94
|
|
|
80
95
|
Use `gea build` with the same options to generate the Xcode project and build
|
|
@@ -119,7 +119,9 @@ function buildOutputs(root, manifest, platform, build, where, log) {
|
|
|
119
119
|
if (outputs.some((file) => !fs.existsSync(file))) {
|
|
120
120
|
log(`[gea] building ${libraries.join(', ')} for ${platform} from ${manifest.name} (once; cached in ${out})`)
|
|
121
121
|
const runner = /\.sh$/.test(script) ? ['bash', [script, ...command.slice(1), '--out', out]] : [script, [...command.slice(1), '--out', out]]
|
|
122
|
-
|
|
122
|
+
// The build's own output goes to stderr: callers read this module's answer
|
|
123
|
+
// from stdout.
|
|
124
|
+
execFileSync(runner[0], runner[1], { cwd: root, stdio: ['ignore', 2, 'inherit'] })
|
|
123
125
|
for (const file of outputs) mustExist(file, `${where} (after ${command[0]})`)
|
|
124
126
|
}
|
|
125
127
|
return {
|
package/targets/macos/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# macOS target
|
|
2
2
|
|
|
3
|
-
Build a
|
|
3
|
+
Build a Gea app as a native Cocoa Mac app — `<Button>` becomes
|
|
4
4
|
`NSButton`, `<Text>` becomes `NSTextField`, `<View>` becomes `NSView`,
|
|
5
5
|
`<Image>` becomes `NSImageView`, `<canvas>` is a custom `NSView` backed by
|
|
6
6
|
CoreGraphics, `<virtual-list>` is `NSScrollView`. The flex layout engine
|
|
@@ -8,8 +8,20 @@ in `@geastack/engine`'s `ui/layout.cpp` computes frames; AppKit draws.
|
|
|
8
8
|
|
|
9
9
|
## Build
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
The app needs `@geastack/apple` and `@geastack/cli` in its dependencies and
|
|
12
|
+
`"macos": true` under `gea.targets` in its `package.json`. From the app folder:
|
|
13
|
+
|
|
14
|
+
npx gea run --target macos
|
|
15
|
+
|
|
16
|
+
builds the app and opens it. `npx gea build --target macos` builds only; the
|
|
17
|
+
bundle is `dist/macos/<app-id>/<AppName>.app`. `gea run --target macos` needs
|
|
18
|
+
`@geastack/cli` 0.1.117 or later; with an older CLI, build and then
|
|
19
|
+
`open dist/macos/<app-id>/<AppName>.app`.
|
|
20
|
+
|
|
21
|
+
`gea build --target macos` runs this package's `build-macos.sh <app-id>` with
|
|
22
|
+
the app's build configuration. The script can also be run directly from the
|
|
23
|
+
app folder as `node_modules/@geastack/apple/targets/macos/build-macos.sh
|
|
24
|
+
<app-id>`.
|
|
13
25
|
|
|
14
26
|
## Where the build writes
|
|
15
27
|
|
|
@@ -24,49 +36,22 @@ Output does not go under the package because the package lives in the app's
|
|
|
24
36
|
`node_modules`, which npm replaces on reinstall. Set `GEA_MACOS_OUTPUT_DIR` to
|
|
25
37
|
put the whole tree elsewhere.
|
|
26
38
|
|
|
27
|
-
|
|
28
|
-
`dist/macos/.generated/<app-id>/` the
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
`
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
## Hard-muted builds
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Both variables are required together. After code signing, the build writes
|
|
46
|
-
`dist/<app-id>/build/hard-mute-artifact-provenance.json` and statically proves:
|
|
47
|
-
|
|
48
|
-
- the selected source is the committed blob at the recorded dependency revision;
|
|
49
|
-
- exactly one linked object depends on that source and contains the gate;
|
|
50
|
-
- `link.sig` records that exact object;
|
|
51
|
-
- source, translation unit, depfile, link signature, object, and executable
|
|
52
|
-
SHA-256 values still match; and
|
|
53
|
-
- the signed executable contains the same gate.
|
|
54
|
-
|
|
55
|
-
Immediately before launch, rerun the no-launch check against the exact binary:
|
|
56
|
-
|
|
57
|
-
```sh
|
|
58
|
-
node targets/macos/preflight-hard-muted-artifact.mjs verify \
|
|
59
|
-
--manifest /absolute/path/to/build/hard-mute-artifact-provenance.json \
|
|
60
|
-
--executable "/absolute/path/to/App.app/Contents/MacOS/App" \
|
|
61
|
-
--source /absolute/path/to/the/committed/native/audio_source.mm \
|
|
62
|
-
--gate THE_NATIVE_MUTE_ENVIRONMENT_LITERAL
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
Do not launch unless this prints
|
|
66
|
-
`PASS artifact-static-hard-mute-gate=present`. The checker reads files and Git
|
|
67
|
-
metadata only; it does not execute the app or open an audio device. Any missing
|
|
68
|
-
manifest, gate, changed dependency revision, or changed source/object/executable
|
|
69
|
-
fails closed.
|
|
39
|
+
The build compiles the app's entry through geatsc into
|
|
40
|
+
`dist/macos/.generated/<app-id>/` and links the generated C++ into the bundle;
|
|
41
|
+
a geatsc failure for a resolved app fails the build. Only when `<app-id>`
|
|
42
|
+
resolves to no app with an entry file does the build fall back to the built-in
|
|
43
|
+
smoke app (`main/macos_smoke_app.cpp`), which exercises View / Text / Button /
|
|
44
|
+
event dispatch.
|
|
45
|
+
|
|
46
|
+
## Hard-muted builds
|
|
47
|
+
|
|
48
|
+
Setting `GEA_MACOS_HARD_MUTE_SOURCE` (absolute path to the committed native
|
|
49
|
+
audio source) and `GEA_MACOS_HARD_MUTE_GATE` (the mute literal it contains)
|
|
50
|
+
together makes the build record and check that the signed executable was built
|
|
51
|
+
from that source with the gate present. It writes
|
|
52
|
+
`dist/macos/<app-id>/build/hard-mute-artifact-provenance.json`;
|
|
53
|
+
`preflight-hard-muted-artifact.mjs verify` re-checks a binary against it
|
|
54
|
+
without launching it. Setting only one of the two variables is an error.
|
|
70
55
|
|
|
71
56
|
## Architecture
|
|
72
57
|
|
|
@@ -93,11 +78,17 @@ display list, so other targets keep calling `refresh()` unchanged.
|
|
|
93
78
|
|
|
94
79
|
## Frame loop
|
|
95
80
|
|
|
96
|
-
`macos_main.mm`
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
81
|
+
`main/macos_main.mm` drives frames from the window's `CADisplayLink` on
|
|
82
|
+
macOS 14 and later, at the screen's maximum refresh rate (following the window
|
|
83
|
+
between displays). On older macOS, or when the app's window config sets
|
|
84
|
+
`"vsync": false`, it uses a fast `NSTimer` instead; with `vsync: false` frames
|
|
85
|
+
run uncapped. Both are scheduled on `NSRunLoopCommonModes` so the loop keeps
|
|
86
|
+
firing during live window-resize and other event-tracking modes. The window
|
|
87
|
+
config is `macos.json` in the app folder overlaid with
|
|
88
|
+
`gea.targets.macos.window` from its `package.json` (`width`, `height`,
|
|
89
|
+
`vsync`, `fullscreen`, ...), bundled as `Resources/window.json`. Each tick:
|
|
90
|
+
|
|
91
|
+
1. `Application::frame(timestampMs)` lets the app update state
|
|
101
92
|
2. Force `style.width/height` on the mounted root to the current window
|
|
102
93
|
content size — this is the macOS convention that makes the root
|
|
103
94
|
viewport track resize automatically
|
|
@@ -124,8 +115,15 @@ runs the measurement harness (offline render, RMS + measured frequency);
|
|
|
124
115
|
`GEA_AUDIO_CAPTURE_RAW=<path>` captures an app run for
|
|
125
116
|
`targets/shared/analyze-audio-capture.mjs`.
|
|
126
117
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
118
|
+
Also implemented in `main/`: HTTP(S) `fetch` over `NSURLSession`
|
|
119
|
+
(`macos_network.mm`), battery level from IOKit power sources and pointer
|
|
120
|
+
input as touch (`macos_sensors.cpp`), timers (`macos_timers.mm`), launching
|
|
121
|
+
other apps' bundles (`macos_app_platform.mm`), and the `runDeviceCommand`
|
|
122
|
+
shell escape hatch (`macos_device_control.mm`).
|
|
123
|
+
|
|
124
|
+
Stubbed in `main/macos_sensors.cpp`: the accelerometer/gyroscope (tilt 0,
|
|
125
|
+
gravity on Z) and the embedded memory diagnostics (all zeros).
|
|
126
|
+
`main/macos_display.mm` keeps the framebuffer display inert because AppKit
|
|
127
|
+
draws. `main/` has no WiFi or Bluetooth backend. Code signing with
|
|
128
|
+
entitlements and notarisation are not done by the build; development bundles
|
|
129
|
+
are signed ad hoc.
|
|
@@ -396,7 +396,7 @@ resolve_app_dir() {
|
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
# Info.plist comes from the shared template plus the optional `infoPlist`
|
|
399
|
-
# object of
|
|
399
|
+
# object of the app's macos.json (usage descriptions and other per-app keys).
|
|
400
400
|
INFO_PLIST_TMP="$BUILD_DIR/Info.plist.tmp.$$"
|
|
401
401
|
sed -e "s/@APP_EXEC@/$APP_EXEC/g" \
|
|
402
402
|
-e "s/@APP_ID@/$APP_ID/g" \
|
|
@@ -590,6 +590,18 @@ generate_app() {
|
|
|
590
590
|
done
|
|
591
591
|
(( alreadySelected != 0 )) || extraArgs+=(--extra-geatsc-plugin "$declaredPluginPath")
|
|
592
592
|
done < <(node -e 'for(const p of JSON.parse(process.argv[1]).paths)console.log(p)' "$declaredAppPlugins")
|
|
593
|
+
# gea.targets.macos.tsconfig: the TypeScript project the compiler reads the
|
|
594
|
+
# program under, as build-ios.sh passes it. Without it the compiler takes the
|
|
595
|
+
# project nearest the staged entry, and an app that maps modules through
|
|
596
|
+
# `paths` (a three.js app's barrel) is read with those modules untyped -- an
|
|
597
|
+
# analysis that outgrows the compiler's heap.
|
|
598
|
+
local declaredProject
|
|
599
|
+
declaredProject="$(node -e '
|
|
600
|
+
const app = JSON.parse(process.argv[1]);
|
|
601
|
+
const tsconfig = app.targetConfig?.macos?.tsconfig;
|
|
602
|
+
if (tsconfig) console.log(require("node:path").resolve(app.root, tsconfig));
|
|
603
|
+
' "$declaredAppMetadata")" || return 1
|
|
604
|
+
[[ -z "$declaredProject" ]] || extraArgs+=(--project "$declaredProject")
|
|
593
605
|
if [[ "$appRuntime" == "apple-native" ]]; then
|
|
594
606
|
extraArgs+=(--apple-native)
|
|
595
607
|
fi
|
|
@@ -982,6 +994,7 @@ case "${GEA_MACOS_THERMALRIGHT_PRODUCT_ID:-}" in
|
|
|
982
994
|
esac
|
|
983
995
|
if [[ "$THERMALRIGHT_DISPLAY_TARGET" == "0" ]]; then
|
|
984
996
|
CXX_DEFINES+=(-DGEA_EMBEDDED_PIXEL_FORMAT=1 -DGEA_CSS_FONT_STRETCH=1) # RGBA8888 and native variable-font style for AppKit
|
|
997
|
+
CXX_DEFINES+=(-DGEA_EMBEDDED_HAS_GENERATED_FONTS=1) # Enable retained text rasterization via the runtime TTF hooks
|
|
985
998
|
fi
|
|
986
999
|
if [[ "$THERMALRIGHT_DISPLAY_TARGET" == "1" ]]; then
|
|
987
1000
|
THERMALRIGHT_WIDTH="${GEA_MACOS_THERMALRIGHT_WIDTH:-$THERMALRIGHT_DEFAULT_WIDTH}"
|
|
@@ -1112,6 +1125,8 @@ if [[ -n "$SINGLE_APP_DIR" ]]; then
|
|
|
1112
1125
|
*) full_src="$SINGLE_APP_DIR/$native_src" ;;
|
|
1113
1126
|
esac
|
|
1114
1127
|
[[ -f "$full_src" ]] || continue
|
|
1128
|
+
# Generated host calls can include headers beside their native source.
|
|
1129
|
+
INCLUDES+=(-iquote "${full_src%/*}")
|
|
1115
1130
|
case "$full_src" in
|
|
1116
1131
|
*.c) C_SOURCES+=("$full_src") ;;
|
|
1117
1132
|
*.m|*.mm) MM_SOURCES+=("$full_src") ;;
|
|
@@ -2035,8 +2050,8 @@ timing_mark link
|
|
|
2035
2050
|
|
|
2036
2051
|
# Convert the app icon only when its resolved source, manifest metadata, or the
|
|
2037
2052
|
# icon tooling changed. Ten `sips` subprocesses made this the largest historical
|
|
2038
|
-
# no-op phase.
|
|
2039
|
-
if [[ -n "$APP_META" ]]; then
|
|
2053
|
+
# no-op phase. A prerender bundle is run directly and needs no Finder icon.
|
|
2054
|
+
if [[ -n "$APP_META" && "${GEA_MACOS_PRERENDER:-0}" != "1" ]]; then
|
|
2040
2055
|
ICON_OUTPUT="$RES_DIR/AppIcon.icns"
|
|
2041
2056
|
ICON_INPUT_SIGNATURE_FILE="$BUILD_DIR/AppIcon.inputs"
|
|
2042
2057
|
ICON_INPUT_SIGNATURE="$(node "$GEA_CLI" apps apple-icons "$APP_ID" --platform macos --signature)"
|
|
@@ -2060,7 +2075,7 @@ fi
|
|
|
2060
2075
|
# Copy any TTF / OTF referenced by @font-face in CSS — for resident-app
|
|
2061
2076
|
# builds we walk every resident's app dir so fonts used by other tiles
|
|
2062
2077
|
# are also bundled.
|
|
2063
|
-
if [[ "$MACOS_PIPELINE_CACHE" == "0" ]]; then
|
|
2078
|
+
if [[ "$MACOS_PIPELINE_CACHE" == "0" && "${GEA_MACOS_PRERENDER:-0}" != "1" ]]; then
|
|
2064
2079
|
FONTS_OUT="$RES_DIR/Fonts"
|
|
2065
2080
|
mkdir -p "$FONTS_OUT"
|
|
2066
2081
|
APP_DIRS_FOR_FONTS=()
|
|
@@ -2116,7 +2131,7 @@ done
|
|
|
2116
2131
|
|
|
2117
2132
|
# Per-app window config — the macOS main reads window.json out of Resources/
|
|
2118
2133
|
# at launch to pick up size, transparent title bar, dark appearance, etc.
|
|
2119
|
-
# Source is
|
|
2134
|
+
# Source is the app's macos.json overlaid with gea.targets.macos.window from
|
|
2120
2135
|
# the app's package.json (window-config.mjs), written as window.json so the runtime path is stable
|
|
2121
2136
|
# regardless of which app id produced it.
|
|
2122
2137
|
APP_DIR_FOR_CONFIG="$(resolve_app_dir "$APP_ID")"
|
|
@@ -2197,6 +2212,31 @@ if [[ "$APP_ID" == "gea-companion" ]]; then
|
|
|
2197
2212
|
if replace_content_stable "$COMPANION_TOOLS_DIR/$(basename "$d")" "$RESOURCE_TMP"; then BUNDLE_CONTENT_CHANGED=1; fi
|
|
2198
2213
|
done
|
|
2199
2214
|
fi
|
|
2215
|
+
|
|
2216
|
+
# Libraries the program's packages build for macOS (gea-native.json "macos"
|
|
2217
|
+
# "build", e.g. native-webgl-angle's ANGLE built from WebKit's sources, once and
|
|
2218
|
+
# cached): a dynamic library goes into Contents/Frameworks, where the package's
|
|
2219
|
+
# host loads it, and its notices into Resources.
|
|
2220
|
+
if [[ -n "$SINGLE_APP_DIR" ]]; then
|
|
2221
|
+
PACKAGE_BUILDS="$(node --input-type=module -e "
|
|
2222
|
+
import { readUikitNativePackages } from '$ROOT_DIR/targets/ios/native-packages.mjs'
|
|
2223
|
+
import fs from 'node:fs'
|
|
2224
|
+
const graph = process.argv[2]
|
|
2225
|
+
const found = readUikitNativePackages({ appRoot: process.argv[1], moduleGraphPath: fs.existsSync(graph) ? graph : undefined, target: 'macos' })
|
|
2226
|
+
for (const file of found.libraries) if (file.endsWith('.dylib')) console.log('lib ' + file)
|
|
2227
|
+
for (const file of found.resources) console.log('res ' + file)
|
|
2228
|
+
" "$SINGLE_APP_DIR" "$GENERATED_DIR/module-graph/gea-module-graph.json")" || { echo "Package native builds failed for '$APP_ID'" >&2; exit 1; }
|
|
2229
|
+
while IFS= read -r line; do
|
|
2230
|
+
[[ -n "$line" ]] || continue
|
|
2231
|
+
kind="${line%% *}"; file="${line#* }"
|
|
2232
|
+
if [[ "$kind" == lib ]]; then dest="$APP_BUNDLE/Contents/Frameworks/$(basename "$file")"; else dest="$RES_DIR/$(basename "$file")"; fi
|
|
2233
|
+
mkdir -p "$(dirname "$dest")"
|
|
2234
|
+
if [[ ! -f "$dest" ]] || ! cmp -s "$file" "$dest"; then
|
|
2235
|
+
cp "$file" "$dest"
|
|
2236
|
+
BUNDLE_CONTENT_CHANGED=1
|
|
2237
|
+
fi
|
|
2238
|
+
done <<< "$PACKAGE_BUILDS"
|
|
2239
|
+
fi
|
|
2200
2240
|
timing_mark resources
|
|
2201
2241
|
|
|
2202
2242
|
# Ad-hoc sign only after an input changed. The completion stamp is deliberately
|
|
@@ -25,6 +25,9 @@ NSFont *fontForId(int fontId, int sizePx, int weight, int stretch);
|
|
|
25
25
|
// after the app bundle is known.
|
|
26
26
|
int registerCustomTtfDirectory(NSString *directoryPath);
|
|
27
27
|
|
|
28
|
+
// Match software glyph layout and paint during offscreen capture.
|
|
29
|
+
void useSoftwareTextMeasurement();
|
|
30
|
+
|
|
28
31
|
// Picks the right NSLineBreakMode for `text` rendered in `font` within
|
|
29
32
|
// `maxWidth` points. Returns word-wrap when every space-separated chunk fits
|
|
30
33
|
// on a line by itself, otherwise char-wrap so that a long unbreakable run
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
#include <cmath>
|
|
10
10
|
#include <cstdint>
|
|
11
11
|
#include <cstring>
|
|
12
|
+
#include <memory>
|
|
12
13
|
#include <mutex>
|
|
13
14
|
#include <string>
|
|
14
15
|
#include <unordered_map>
|
|
@@ -74,7 +75,8 @@ NSString *familyForId(int id)
|
|
|
74
75
|
// initializer-ordering reason as FamilyRegistry above.
|
|
75
76
|
struct TtfByteRegistry {
|
|
76
77
|
std::mutex lock;
|
|
77
|
-
std::unordered_map<std::string, std::vector<std::uint8_t
|
|
78
|
+
std::unordered_map<std::string, std::shared_ptr<const std::vector<std::uint8_t>>> byFamily;
|
|
79
|
+
std::unordered_map<std::string, std::shared_ptr<const std::vector<std::uint8_t>>> byAlias;
|
|
78
80
|
};
|
|
79
81
|
|
|
80
82
|
TtfByteRegistry &ttfByteRegistry()
|
|
@@ -90,7 +92,9 @@ std::string lowercased(const std::string &value)
|
|
|
90
92
|
return out;
|
|
91
93
|
}
|
|
92
94
|
|
|
93
|
-
|
|
95
|
+
bool softwareTextMeasurement = false;
|
|
96
|
+
|
|
97
|
+
void registerTtfBytesForFamily(NSString *path, NSArray<NSString *> *aliases)
|
|
94
98
|
{
|
|
95
99
|
NSData *data = [NSData dataWithContentsOfFile:path];
|
|
96
100
|
if (data.length == 0) return;
|
|
@@ -108,7 +112,9 @@ void registerTtfBytesForFamily(NSString *path)
|
|
|
108
112
|
std::scoped_lock guard(registry.lock);
|
|
109
113
|
// First face wins (e.g. Inter-Regular before other weights of the family):
|
|
110
114
|
// the runtime rasterizer keys on the family alone.
|
|
111
|
-
|
|
115
|
+
auto font = std::make_shared<const std::vector<std::uint8_t>>(bytes, bytes + data.length);
|
|
116
|
+
registry.byFamily.emplace(lowercased(buf), font);
|
|
117
|
+
for (NSString *alias in aliases) registry.byAlias.emplace(alias.UTF8String, font);
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
} // namespace
|
|
@@ -122,10 +128,14 @@ const std::uint8_t *runtimeTtfBytesForFamilyId(int familyId, unsigned long *leng
|
|
|
122
128
|
if (!family || family.length == 0) return nullptr;
|
|
123
129
|
TtfByteRegistry ®istry = ttfByteRegistry();
|
|
124
130
|
std::scoped_lock guard(registry.lock);
|
|
125
|
-
const auto
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
const auto key = lowercased(family.UTF8String);
|
|
132
|
+
const auto alias = registry.byAlias.find(key);
|
|
133
|
+
const auto fallback = registry.byFamily.find(key);
|
|
134
|
+
const auto *font = alias != registry.byAlias.end() ? alias->second.get()
|
|
135
|
+
: fallback != registry.byFamily.end() ? fallback->second.get() : nullptr;
|
|
136
|
+
if (!font) return nullptr;
|
|
137
|
+
if (length) *length = font->size();
|
|
138
|
+
return font->data();
|
|
129
139
|
}
|
|
130
140
|
|
|
131
141
|
static NSFont *self_resolveFont(int fontId, int sizePx, int weight, int stretch)
|
|
@@ -186,18 +196,35 @@ NSFont *fontForId(int fontId, int sizePx, int weight, int stretch)
|
|
|
186
196
|
|
|
187
197
|
NSFont *fontForId(int fontId, int sizePx) { return fontForId(fontId, sizePx, 400, 1000); }
|
|
188
198
|
|
|
199
|
+
void useSoftwareTextMeasurement()
|
|
200
|
+
{
|
|
201
|
+
softwareTextMeasurement = true;
|
|
202
|
+
}
|
|
203
|
+
|
|
189
204
|
int registerCustomTtfDirectory(NSString *directoryPath)
|
|
190
205
|
{
|
|
191
206
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
192
207
|
BOOL isDir = NO;
|
|
193
208
|
if (![fm fileExistsAtPath:directoryPath isDirectory:&isDir] || !isDir) return 0;
|
|
194
209
|
NSArray<NSString *> *entries = [fm contentsOfDirectoryAtPath:directoryPath error:nil];
|
|
210
|
+
NSString *aliasPath = [directoryPath.stringByDeletingLastPathComponent stringByAppendingPathComponent:@"font-aliases.json"];
|
|
211
|
+
NSData *aliasData = [NSData dataWithContentsOfFile:aliasPath];
|
|
212
|
+
NSDictionary *aliases = aliasData ? [NSJSONSerialization JSONObjectWithData:aliasData options:0 error:nil] : nil;
|
|
213
|
+
NSMutableDictionary<NSString *, NSMutableArray<NSString *> *> *aliasesByFile = [NSMutableDictionary dictionary];
|
|
214
|
+
if ([aliases isKindOfClass:NSDictionary.class]) {
|
|
215
|
+
for (NSString *alias in aliases) {
|
|
216
|
+
NSString *filename = aliases[alias];
|
|
217
|
+
if (![filename isKindOfClass:NSString.class]) continue;
|
|
218
|
+
if (!aliasesByFile[filename]) aliasesByFile[filename] = [NSMutableArray array];
|
|
219
|
+
[aliasesByFile[filename] addObject:alias];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
195
222
|
int count = 0;
|
|
196
223
|
for (NSString *name in entries) {
|
|
197
224
|
NSString *lower = name.lowercaseString;
|
|
198
225
|
if (![lower hasSuffix:@".ttf"] && ![lower hasSuffix:@".otf"]) continue;
|
|
199
226
|
NSString *path = [directoryPath stringByAppendingPathComponent:name];
|
|
200
|
-
registerTtfBytesForFamily(path);
|
|
227
|
+
registerTtfBytesForFamily(path, aliasesByFile[name]);
|
|
201
228
|
CFErrorRef err = NULL;
|
|
202
229
|
CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path];
|
|
203
230
|
if (CTFontManagerRegisterFontsForURL(url, kCTFontManagerScopeProcess, &err)) {
|
|
@@ -279,7 +306,7 @@ static bool measureNativeText(const char *text,
|
|
|
279
306
|
int *outWidth,
|
|
280
307
|
int *outHeight)
|
|
281
308
|
{
|
|
282
|
-
if (!outWidth || !outHeight) return false;
|
|
309
|
+
if (gea::macos::softwareTextMeasurement || !outWidth || !outHeight) return false;
|
|
283
310
|
if (!text || !text[0]) {
|
|
284
311
|
*outWidth = 0;
|
|
285
312
|
*outHeight = 0;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#import <Cocoa/Cocoa.h>
|
|
2
2
|
|
|
3
3
|
#include "display.h"
|
|
4
|
+
#include "macos_prerender.h"
|
|
4
5
|
#include "canvas.h"
|
|
5
6
|
#include "host/display_orientation.h"
|
|
6
7
|
#include "pixel.h"
|
|
@@ -29,6 +30,7 @@ int g_canvas_w = gea::platform::display::kWidth;
|
|
|
29
30
|
int g_canvas_h = gea::platform::display::kHeight;
|
|
30
31
|
int g_brightness = 100;
|
|
31
32
|
std::uint8_t g_alpha = 255;
|
|
33
|
+
bool g_prerender = false;
|
|
32
34
|
int g_flush_rows = 0;
|
|
33
35
|
int g_flush_depth = 0;
|
|
34
36
|
int g_flush_calls = 0;
|
|
@@ -43,13 +45,13 @@ void ensure_canvas()
|
|
|
43
45
|
|
|
44
46
|
bool framebuffer_target()
|
|
45
47
|
{
|
|
46
|
-
return gea::macos::thermalright::enabled();
|
|
48
|
+
return g_prerender || gea::macos::thermalright::enabled();
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
void count_rect(int x0, int y0, int x1, int y1)
|
|
50
52
|
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
const int kWidth = g_canvas_w;
|
|
54
|
+
const int kHeight = g_canvas_h;
|
|
53
55
|
if (x0 < 0) x0 = 0;
|
|
54
56
|
if (y0 < 0) y0 = 0;
|
|
55
57
|
if (x1 >= kWidth) x1 = kWidth - 1;
|
|
@@ -60,7 +62,7 @@ void count_rect(int x0, int y0, int x1, int y1)
|
|
|
60
62
|
|
|
61
63
|
void submit_full_frame()
|
|
62
64
|
{
|
|
63
|
-
if (!framebuffer_target()) return;
|
|
65
|
+
if (g_prerender || !framebuffer_target()) return;
|
|
64
66
|
ensure_canvas();
|
|
65
67
|
#if GEA_MACOS_THERMALRIGHT_DISPLAY_TARGET
|
|
66
68
|
gea::macos::thermalright::submitRgb565(g_framebuffer,
|
|
@@ -71,6 +73,37 @@ void submit_full_frame()
|
|
|
71
73
|
|
|
72
74
|
} // namespace
|
|
73
75
|
|
|
76
|
+
bool gea_macos_prepare_prerender(int width, int height)
|
|
77
|
+
{
|
|
78
|
+
g_canvas_w = width;
|
|
79
|
+
g_canvas_h = height;
|
|
80
|
+
g_prerender = true;
|
|
81
|
+
ensure_canvas();
|
|
82
|
+
return g_framebuffer != nullptr;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
bool gea_macos_write_prerender_png(NSString *path)
|
|
86
|
+
{
|
|
87
|
+
NSBitmapImageRep *image = [[NSBitmapImageRep alloc]
|
|
88
|
+
initWithBitmapDataPlanes:nullptr pixelsWide:g_canvas_w pixelsHigh:g_canvas_h
|
|
89
|
+
bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO
|
|
90
|
+
colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:0];
|
|
91
|
+
if (!image) return false;
|
|
92
|
+
for (int y = 0; y < g_canvas_h; ++y) {
|
|
93
|
+
auto *row = image.bitmapData + y * image.bytesPerRow;
|
|
94
|
+
for (int x = 0; x < g_canvas_w; ++x) {
|
|
95
|
+
int r, g, b, a;
|
|
96
|
+
gea::framework::graphics::pixel::unpackNative8(
|
|
97
|
+
g_framebuffer[static_cast<size_t>(y) * g_canvas_w + x], &r, &g, &b, &a);
|
|
98
|
+
row[x * 3] = r;
|
|
99
|
+
row[x * 3 + 1] = g;
|
|
100
|
+
row[x * 3 + 2] = b;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
NSData *png = [image representationUsingType:NSBitmapImageFileTypePNG properties:@{}];
|
|
104
|
+
return [png writeToFile:path atomically:YES];
|
|
105
|
+
}
|
|
106
|
+
|
|
74
107
|
namespace gea::platform::display {
|
|
75
108
|
|
|
76
109
|
bool Display::init() { ensure_canvas(); return true; }
|
|
@@ -129,8 +162,8 @@ void Display::flushRectsRasterized(const DisplayFlushRect *rects, int count, Dis
|
|
|
129
162
|
for (int i = 0; i < count; i++) {
|
|
130
163
|
int x0 = std::max(0, rects[i].x0);
|
|
131
164
|
int y0 = std::max(0, rects[i].y0);
|
|
132
|
-
int x1 = std::min(
|
|
133
|
-
int y1 = std::min(
|
|
165
|
+
int x1 = std::min(g_canvas_w - 1, rects[i].x1);
|
|
166
|
+
int y1 = std::min(g_canvas_h - 1, rects[i].y1);
|
|
134
167
|
if (x0 > x1 || y0 > y1) continue;
|
|
135
168
|
const int w = x1 - x0 + 1;
|
|
136
169
|
const int h = y1 - y0 + 1;
|
|
@@ -138,7 +171,7 @@ void Display::flushRectsRasterized(const DisplayFlushRect *rects, int count, Dis
|
|
|
138
171
|
raster(pixels.data(), w, h, x0, y0, user);
|
|
139
172
|
for (int row = 0; row < h; row++) {
|
|
140
173
|
for (int col = 0; col < w; ++col)
|
|
141
|
-
g_framebuffer[static_cast<std::size_t>(y0 + row) *
|
|
174
|
+
g_framebuffer[static_cast<std::size_t>(y0 + row) * g_canvas_w + x0 + col] = pixels[static_cast<std::size_t>(row) * w + col];
|
|
142
175
|
}
|
|
143
176
|
g_canvas.markDirty(x0, y0, x1, y1);
|
|
144
177
|
}
|
|
@@ -158,8 +191,8 @@ bool Display::streamRect(int x, int y, int w, int h, DisplayStreamRasterFn raste
|
|
|
158
191
|
if (!raster || w <= 0 || h <= 0) return false;
|
|
159
192
|
int x0 = std::max(0, x);
|
|
160
193
|
int y0 = std::max(0, y);
|
|
161
|
-
int x1 = std::min(
|
|
162
|
-
int y1 = std::min(
|
|
194
|
+
int x1 = std::min(g_canvas_w - 1, x + w - 1);
|
|
195
|
+
int y1 = std::min(g_canvas_h - 1, y + h - 1);
|
|
163
196
|
if (x0 > x1 || y0 > y1) return true;
|
|
164
197
|
|
|
165
198
|
const int rw = x1 - x0 + 1;
|
|
@@ -168,7 +201,7 @@ bool Display::streamRect(int x, int y, int w, int h, DisplayStreamRasterFn raste
|
|
|
168
201
|
raster(pixels.data(), rw, rh, x0, y0, user);
|
|
169
202
|
for (int row = 0; row < rh; row++) {
|
|
170
203
|
for (int col = 0; col < rw; ++col)
|
|
171
|
-
g_framebuffer[static_cast<std::size_t>(y0 + row) *
|
|
204
|
+
g_framebuffer[static_cast<std::size_t>(y0 + row) * g_canvas_w + x0 + col] = pixels[static_cast<std::size_t>(row) * rw + col];
|
|
172
205
|
}
|
|
173
206
|
g_canvas.markDirty(x0, y0, x1, y1);
|
|
174
207
|
flush();
|
|
@@ -305,7 +338,7 @@ bool Display::present(const DisplayPresentCommand *commands, int command_count)
|
|
|
305
338
|
void Display::setFlushConfig(int chunk_rows, int queue_depth) { g_flush_rows = chunk_rows; g_flush_depth = queue_depth; }
|
|
306
339
|
int Display::flushChunkRows() { return g_flush_rows; }
|
|
307
340
|
int Display::flushQueueDepth() { return g_flush_depth; }
|
|
308
|
-
int Display::flushBufferBytes() { return
|
|
341
|
+
int Display::flushBufferBytes() { return g_canvas_w * g_flush_rows * 2 * g_flush_depth; }
|
|
309
342
|
|
|
310
343
|
void Display::pushClip(int x, int y, int w, int h) { if (framebuffer_target()) canvas()->pushClip(x, y, w, h); }
|
|
311
344
|
void Display::popClip() { if (framebuffer_target()) canvas()->popClip(); }
|
|
@@ -12,6 +12,7 @@ extern void gea_macos_debugger_start();
|
|
|
12
12
|
|
|
13
13
|
#include "font_registry.h"
|
|
14
14
|
#include "macos_native_shell.h"
|
|
15
|
+
#include "macos_prerender.h"
|
|
15
16
|
#include "macos_renderer.h"
|
|
16
17
|
#include "macos_background_test.h"
|
|
17
18
|
#include "press_bridge.h"
|
|
@@ -60,6 +61,7 @@ namespace gea::macos { void installWifiDriver(); int nodeIdForView(NSView *view)
|
|
|
60
61
|
|
|
61
62
|
#include <algorithm>
|
|
62
63
|
#include <chrono>
|
|
64
|
+
#include <cmath>
|
|
63
65
|
#include <cstdint>
|
|
64
66
|
#include <cstdio>
|
|
65
67
|
#include <cstdlib>
|
|
@@ -1236,12 +1238,58 @@ void gea::apple::AppKit::setScrollDocumentTopAligned(gea::apple::AppKit::NSScrol
|
|
|
1236
1238
|
}
|
|
1237
1239
|
#endif
|
|
1238
1240
|
|
|
1241
|
+
static int prerender(int argc, const char *argv[])
|
|
1242
|
+
{
|
|
1243
|
+
if (argc != 8) return 2;
|
|
1244
|
+
const int width = std::atoi(argv[3]);
|
|
1245
|
+
const int height = std::atoi(argv[4]);
|
|
1246
|
+
const double dpr = std::atof(argv[5]);
|
|
1247
|
+
const int fps = std::atoi(argv[6]);
|
|
1248
|
+
const int targetMs = std::atoi(argv[7]);
|
|
1249
|
+
if (width < 1 || width > 8192 || height < 1 || height > 8192 ||
|
|
1250
|
+
!std::isfinite(dpr) || dpr < 0.1 || dpr > 8 ||
|
|
1251
|
+
fps < 1 || fps > 1000 || targetMs < 0) return 2;
|
|
1252
|
+
if (!gea_macos_prepare_prerender(width, height)) return 1;
|
|
1253
|
+
|
|
1254
|
+
NSString *fontsDir = [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"Fonts"];
|
|
1255
|
+
gea::macos::registerCustomTtfDirectory(fontsDir);
|
|
1256
|
+
gea::macos::useSoftwareTextMeasurement();
|
|
1257
|
+
gea::platform::storage::setMountProvider(+[]() { return true; });
|
|
1258
|
+
|
|
1259
|
+
gea_macos_set_prerender_time(0);
|
|
1260
|
+
// Seed the timer scheduler before app initialization schedules any timers.
|
|
1261
|
+
gea::host::runAnimationFrameCallbacks(0);
|
|
1262
|
+
gea::framework::app::Application::init(width, height, dpr);
|
|
1263
|
+
auto &tree = gea::embedded::ui::Tree::instance();
|
|
1264
|
+
if (tree.mountedRoot() < 0) {
|
|
1265
|
+
std::fputs("Gea prerender requires a mounted UI tree\n", stderr);
|
|
1266
|
+
return 1;
|
|
1267
|
+
}
|
|
1268
|
+
gea::css::DeclarativeAnimations::scanAndStart(0);
|
|
1269
|
+
|
|
1270
|
+
for (std::int64_t frame = 0; ; ++frame) {
|
|
1271
|
+
const auto tickMs = (frame * 1000 + fps / 2) / fps;
|
|
1272
|
+
const int timeMs = static_cast<int>(std::min<std::int64_t>(tickMs, targetMs));
|
|
1273
|
+
@autoreleasepool {
|
|
1274
|
+
gea_macos_set_prerender_time(timeMs);
|
|
1275
|
+
gea::embedded::ui::StyleSheet::instance().startCssAnimations(timeMs);
|
|
1276
|
+
gea::css::AnimationEngine::instance().tick(static_cast<std::uint32_t>(timeMs));
|
|
1277
|
+
gea::framework::app::Application::frame(timeMs);
|
|
1278
|
+
}
|
|
1279
|
+
if (timeMs == targetMs) break;
|
|
1280
|
+
}
|
|
1281
|
+
if (!gea_macos_write_prerender_png([NSString stringWithUTF8String:argv[2]])) {
|
|
1282
|
+
std::fprintf(stderr, "Could not write PNG to %s\n", argv[2]);
|
|
1283
|
+
return 1;
|
|
1284
|
+
}
|
|
1285
|
+
return 0;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1239
1288
|
int main(int argc, const char *argv[])
|
|
1240
1289
|
{
|
|
1241
1290
|
GeaNativeTerminationGuard terminationGuard;
|
|
1242
|
-
(void)argc;
|
|
1243
|
-
(void)argv;
|
|
1244
1291
|
@autoreleasepool {
|
|
1292
|
+
if (argc > 1 && std::strcmp(argv[1], "--gea-prerender") == 0) return prerender(argc, argv);
|
|
1245
1293
|
gea_macos_smoke_log("[gea-macos] main entered");
|
|
1246
1294
|
const bool backgroundTest = gea::macos::background_test::enabled();
|
|
1247
1295
|
NSApplication *app = [NSApplication sharedApplication];
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
#import <Foundation/Foundation.h>
|
|
2
2
|
#include "services/frame_scheduler.h"
|
|
3
|
+
#include "macos_prerender.h"
|
|
3
4
|
|
|
5
|
+
#include <atomic>
|
|
4
6
|
#include <mach/mach_time.h>
|
|
5
7
|
|
|
6
8
|
namespace {
|
|
7
9
|
|
|
10
|
+
std::atomic<int> prerenderMillis{-1};
|
|
11
|
+
|
|
8
12
|
int monotonicMillis()
|
|
9
13
|
{
|
|
14
|
+
const int captureTime = prerenderMillis.load(std::memory_order_relaxed);
|
|
15
|
+
if (captureTime >= 0) return captureTime;
|
|
10
16
|
static mach_timebase_info_data_t tb = {0, 0};
|
|
11
17
|
if (tb.denom == 0) mach_timebase_info(&tb);
|
|
12
18
|
static const uint64_t start = mach_absolute_time();
|
|
@@ -18,6 +24,11 @@ int g_frame_interval_ms = gea::framework::services::FrameScheduler::kDefaultFram
|
|
|
18
24
|
|
|
19
25
|
} // namespace
|
|
20
26
|
|
|
27
|
+
void gea_macos_set_prerender_time(int timestampMs)
|
|
28
|
+
{
|
|
29
|
+
prerenderMillis.store(timestampMs, std::memory_order_relaxed);
|
|
30
|
+
}
|
|
31
|
+
|
|
21
32
|
extern "C" int gea_embedded_now_ms(void)
|
|
22
33
|
{
|
|
23
34
|
return monotonicMillis();
|
|
@@ -86,6 +86,7 @@ function walkCss(root, visit) {
|
|
|
86
86
|
// not leave stale resources in the app bundle.
|
|
87
87
|
const desiredFonts = new Map()
|
|
88
88
|
const desiredFontLicenses = new Map()
|
|
89
|
+
const fontAliases = new Map()
|
|
89
90
|
for (const root of [...appDirs, ...sharedCssDirs]) {
|
|
90
91
|
walkCss(root, (cssPath) => {
|
|
91
92
|
const css = fs.readFileSync(cssPath, 'utf8').replace(/\/\*[\s\S]*?\*\//g, '')
|
|
@@ -100,6 +101,11 @@ for (const root of [...appDirs, ...sharedCssDirs]) {
|
|
|
100
101
|
const resolved = path.resolve(path.dirname(cssPath), clean)
|
|
101
102
|
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isFile()) continue
|
|
102
103
|
const basename = path.basename(resolved)
|
|
104
|
+
const family = face[1].match(/(?:^|;)\s*font-family\s*:\s*(?:"([^"]+)"|'([^']+)'|([^;]+))/i)
|
|
105
|
+
const alias = (family?.[1] || family?.[2] || family?.[3] || '').trim().toLowerCase()
|
|
106
|
+
if (alias && (!desiredFonts.has(basename) || desiredFonts.get(basename) === resolved) && !fontAliases.has(alias)) {
|
|
107
|
+
fontAliases.set(alias, basename)
|
|
108
|
+
}
|
|
103
109
|
if (!desiredFonts.has(basename)) {
|
|
104
110
|
desiredFonts.set(basename, resolved)
|
|
105
111
|
// Preserve licenses alongside packaged font bytes, using a font-specific
|
|
@@ -157,6 +163,17 @@ if (fs.existsSync(fontLicensesDir)) {
|
|
|
157
163
|
for (const [name, source] of desiredFontLicenses) syncFile(source, path.join(fontLicensesDir, name))
|
|
158
164
|
if (fs.existsSync(fontLicensesDir) && fs.readdirSync(fontLicensesDir).length === 0) fs.rmdirSync(fontLicensesDir)
|
|
159
165
|
|
|
166
|
+
const aliasesPath = path.join(resourcesDir, 'font-aliases.json')
|
|
167
|
+
if (fontAliases.size) {
|
|
168
|
+
const contents = JSON.stringify(Object.fromEntries(fontAliases), null, 2) + '\n'
|
|
169
|
+
if (!fs.existsSync(aliasesPath) || fs.readFileSync(aliasesPath, 'utf8') !== contents) {
|
|
170
|
+
const temporary = `${aliasesPath}.tmp.${process.pid}`
|
|
171
|
+
fs.writeFileSync(temporary, contents)
|
|
172
|
+
fs.renameSync(temporary, aliasesPath)
|
|
173
|
+
changed = true
|
|
174
|
+
}
|
|
175
|
+
} else removeFile(aliasesPath)
|
|
176
|
+
|
|
160
177
|
const windowConfig = path.join(resourcesDir, 'window.json')
|
|
161
178
|
for (const entry of fs.readdirSync(resourcesDir, { withFileTypes: true })) {
|
|
162
179
|
if (entry.isFile() && /^window\.json\.tmp\.\d+$/.test(entry.name)) removeFile(path.join(resourcesDir, entry.name))
|