@geastack/apple 0.2.27 → 0.2.29
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 +3 -3
- package/targets/macos/build-macos.sh +49 -2
- package/targets/macos/main/font_registry.mm +75 -8
- package/targets/macos/main/macos_display.mm +13 -4
- package/targets/macos/main/macos_main.mm +165 -23
- package/targets/macos/runtime-glyphs.mjs +49 -0
- package/targets/macos/sync-resources.mjs +28 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/apple",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.29",
|
|
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": {
|
|
@@ -116,9 +116,9 @@
|
|
|
116
116
|
},
|
|
117
117
|
"dependencies": {
|
|
118
118
|
"@geastack/compiler": "^1.0.34",
|
|
119
|
-
"@geastack/core": "^0.1.
|
|
119
|
+
"@geastack/core": "^0.1.59",
|
|
120
120
|
"@geastack/elements": "^0.1.7",
|
|
121
|
-
"@geastack/engine": "^0.1.
|
|
121
|
+
"@geastack/engine": "^0.1.28",
|
|
122
122
|
"@geastack/geaos": "^0.1.3",
|
|
123
123
|
"@geastack/geatsc-plugin-apple-native": "^0.1.4",
|
|
124
124
|
"@geastack/geatsc-plugin-gea": "^0.1.28",
|
|
@@ -907,6 +907,10 @@ CXX_DEFINES=(
|
|
|
907
907
|
# builds keep their baked atlas: the runtime path tries first, finds no
|
|
908
908
|
# registered TTF bytes there, and falls through.
|
|
909
909
|
-DGEA_EMBEDDED_TTF_RUNTIME_FONTS=1
|
|
910
|
+
# Runtime TTF slots cover the glyphs the generated font TU declares
|
|
911
|
+
# (runtimeTtfDeclaredCodepoints: the baseline plus the app's
|
|
912
|
+
# --gea-font-charset names), not just ASCII and two extras.
|
|
913
|
+
-DGEA_EMBEDDED_TTF_RUNTIME_DECLARED_GLYPHS=128
|
|
910
914
|
)
|
|
911
915
|
if [[ "${GEA_NATIVE_DEBUGGER:-0}" == "1" ]]; then
|
|
912
916
|
[[ -f "${GEA_DEBUGGER_NATIVE_SOURCE:-}" ]] || { echo "GEA_DEBUGGER_NATIVE_SOURCE must name debugger/native/macos.mm" >&2; exit 2; }
|
|
@@ -1069,6 +1073,11 @@ if [[ ${#RESIDENT_IDS[@]} -eq 0 ]]; then
|
|
|
1069
1073
|
# apple-native mode — generated app modules may be Objective-C++, this never is.
|
|
1070
1074
|
if [[ "$THERMALRIGHT_DISPLAY_TARGET" == "1" && -f "$GENERATED_FONT_CPP" ]]; then
|
|
1071
1075
|
CXX_SOURCES+=("$GENERATED_FONT_CPP")
|
|
1076
|
+
elif [[ -f "$GENERATED_FONT_CPP" ]]; then
|
|
1077
|
+
# The windowed build skips the font TU, so carry its declared glyph set
|
|
1078
|
+
# (baseline + --gea-font-charset) to the runtime TTF slots on its own.
|
|
1079
|
+
node "$ROOT_DIR/targets/macos/runtime-glyphs.mjs" --out "$GENERATED_DIR/gea_runtime_glyphs_generated.cpp" "$GENERATED_FONT_CPP"
|
|
1080
|
+
CXX_SOURCES+=("$GENERATED_DIR/gea_runtime_glyphs_generated.cpp")
|
|
1072
1081
|
fi
|
|
1073
1082
|
[[ -f "$GENERATED_ASSETS_CPP" ]] && CXX_SOURCES+=("$GENERATED_ASSETS_CPP")
|
|
1074
1083
|
else
|
|
@@ -1079,6 +1088,12 @@ else
|
|
|
1079
1088
|
CXX_SOURCES+=("$RESIDENT_REGISTRY_CPP")
|
|
1080
1089
|
for f in "${RESIDENT_GEATSC_SOURCES[@]}"; do CXX_SOURCES+=("$f"); done
|
|
1081
1090
|
for f in "${RESIDENT_FONT_CPPS[@]}"; do CXX_SOURCES+=("$f"); done
|
|
1091
|
+
# Resident font TUs prefix their symbols; the runtime TTF slots read the
|
|
1092
|
+
# union of every resident's declared glyph set through the unprefixed hook.
|
|
1093
|
+
if [[ ${#RESIDENT_FONT_CPPS[@]} -gt 0 ]]; then
|
|
1094
|
+
node "$ROOT_DIR/targets/macos/runtime-glyphs.mjs" --out "$GENERATED_DIR/gea_runtime_glyphs_generated.cpp" "${RESIDENT_FONT_CPPS[@]}"
|
|
1095
|
+
CXX_SOURCES+=("$GENERATED_DIR/gea_runtime_glyphs_generated.cpp")
|
|
1096
|
+
fi
|
|
1082
1097
|
for f in "${RESIDENT_ASSET_CPPS[@]}"; do CXX_SOURCES+=("$f"); done
|
|
1083
1098
|
for f in "${RESIDENT_ENTRY_CPPS[@]}"; do CXX_SOURCES+=("$f"); done
|
|
1084
1099
|
fi
|
|
@@ -2000,6 +2015,13 @@ while IFS= read -r library; do [[ -z "$library" ]] || LINK_FRAMEWORKS+=("-l$libr
|
|
|
2000
2015
|
node "$GEA_CLI" apps sync-native-resources "$APP_ID" --target macos --output "$RES_DIR" > "$BUILD_DIR/native-resources.json"
|
|
2001
2016
|
if [[ "$(node -e 'process.stdout.write(String(JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")).changed))' "$BUILD_DIR/native-resources.json")" == "true" ]]; then BUNDLE_CONTENT_CHANGED=1; fi
|
|
2002
2017
|
|
|
2018
|
+
# These weak program hooks are emitted only for programs with cycle-collectable
|
|
2019
|
+
# values. ld64 requires named exceptions for unresolved executable symbols.
|
|
2020
|
+
MACOS_LINK_FLAGS=(
|
|
2021
|
+
-Wl,-no_deduplicate
|
|
2022
|
+
-Wl,-U,_gea_cycle_collection_defer_begin
|
|
2023
|
+
-Wl,-U,_gea_cycle_collection_defer_end
|
|
2024
|
+
)
|
|
2003
2025
|
LINK_OUTPUT="$MACOS_DIR/$APP_EXEC"
|
|
2004
2026
|
LINK_OUTPUT_TMP="$LINK_OUTPUT.tmp.$$"
|
|
2005
2027
|
LINK_SIGNATURE_FILE="$BUILD_DIR/link.sig"
|
|
@@ -2008,7 +2030,7 @@ LINK_SIGNATURE_TMP="$LINK_SIGNATURE_FILE.tmp.$$"
|
|
|
2008
2030
|
printf 'compiler=%s\n' "$MACOS_COMPILER_VERSION"
|
|
2009
2031
|
printf 'opt=%s\n' "$GEA_MACOS_OPT_LEVEL"
|
|
2010
2032
|
printf 'debug=%s\n' "${GEA_MACOS_DEBUG_INFO:-}"
|
|
2011
|
-
printf 'link=%s\n'
|
|
2033
|
+
printf 'link=%s\n' "${MACOS_LINK_FLAGS[@]}"
|
|
2012
2034
|
printf 'framework=%s\n' "${LINK_FRAMEWORKS[@]}"
|
|
2013
2035
|
printf 'object=%s\n' "${OBJ_FILES[@]}"
|
|
2014
2036
|
for library in ${APP_NATIVE_LIBRARIES[@]+"${APP_NATIVE_LIBRARIES[@]}"}; do shasum -a 256 "$library"; done
|
|
@@ -2035,7 +2057,7 @@ if (( LINK_NEEDED != 0 )); then
|
|
|
2035
2057
|
# entry address (CallableObject::callWithReceiver finds a method's receiver
|
|
2036
2058
|
# check by it), so a folded method template ran its twin's check.
|
|
2037
2059
|
macos_run_tracked_child clang++ -std=c++20 -ObjC++ -fobjc-arc "$GEA_MACOS_OPT_LEVEL" ${GEA_MACOS_DEBUG_INFO} \
|
|
2038
|
-
|
|
2060
|
+
"${MACOS_LINK_FLAGS[@]}" \
|
|
2039
2061
|
"${LINK_FRAMEWORKS[@]}" \
|
|
2040
2062
|
"${OBJ_FILES[@]}" \
|
|
2041
2063
|
${APP_NATIVE_LIBRARIES[@]+"${APP_NATIVE_LIBRARIES[@]}"} \
|
|
@@ -2089,6 +2111,7 @@ else
|
|
|
2089
2111
|
done
|
|
2090
2112
|
fi
|
|
2091
2113
|
for d in "${APP_DIRS_FOR_FONTS[@]}"; do
|
|
2114
|
+
GEA_FONT_MODULE_GRAPH="$GENERATED_DIR/module-graph/gea-module-graph.json" \
|
|
2092
2115
|
node -e "
|
|
2093
2116
|
const fs = require('fs');
|
|
2094
2117
|
const path = require('path');
|
|
@@ -2103,6 +2126,11 @@ for d in "${APP_DIRS_FOR_FONTS[@]}"; do
|
|
|
2103
2126
|
if (entry.name === 'node_modules' || entry.name === 'dist') continue;
|
|
2104
2127
|
walk(full);
|
|
2105
2128
|
} else if (entry.isFile() && entry.name.endsWith('.css')) {
|
|
2129
|
+
visit(full);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
function visit(full) {
|
|
2106
2134
|
const css = fs.readFileSync(full, 'utf8').replace(/\/\*[\s\S]*?\*\//g, '');
|
|
2107
2135
|
const re = /@font-face\s*\{([^}]+)\}/gi;
|
|
2108
2136
|
let m;
|
|
@@ -2121,6 +2149,19 @@ for d in "${APP_DIRS_FOR_FONTS[@]}"; do
|
|
|
2121
2149
|
fs.copyFileSync(resolved, dest);
|
|
2122
2150
|
console.log(' copied font:', base);
|
|
2123
2151
|
}
|
|
2152
|
+
}
|
|
2153
|
+
// CSS the app imports from workspace packages lives outside its own dir;
|
|
2154
|
+
// the module graph names every stylesheet the bundle actually pulled in.
|
|
2155
|
+
const graph = process.env.GEA_FONT_MODULE_GRAPH;
|
|
2156
|
+
if (graph && fs.existsSync(graph)) {
|
|
2157
|
+
const seen = new Set();
|
|
2158
|
+
const modules = JSON.parse(fs.readFileSync(graph, 'utf8')).modules || [];
|
|
2159
|
+
const list = Array.isArray(modules) ? modules : Object.values(modules);
|
|
2160
|
+
for (const m of list) {
|
|
2161
|
+
for (const p of [m.file, m.id, ...((m.imports || []).map((i) => i && i.resolvedId))]) {
|
|
2162
|
+
if (typeof p !== 'string' || !p.endsWith('.css') || seen.has(p) || !fs.existsSync(p)) continue;
|
|
2163
|
+
seen.add(p);
|
|
2164
|
+
visit(p);
|
|
2124
2165
|
}
|
|
2125
2166
|
}
|
|
2126
2167
|
}
|
|
@@ -2160,6 +2201,12 @@ else
|
|
|
2160
2201
|
for d in ${APP_DIRS_FOR_FONTS[@]+"${APP_DIRS_FOR_FONTS[@]}"}; do
|
|
2161
2202
|
RESOURCE_SYNC_ARGS+=(--app-dir "$d")
|
|
2162
2203
|
done
|
|
2204
|
+
# Stylesheets imported from workspace packages sit outside every app dir;
|
|
2205
|
+
# the module graph lists each one the bundle pulled in.
|
|
2206
|
+
for graph in "$GENERATED_DIR/module-graph/gea-module-graph.json" \
|
|
2207
|
+
"$GENERATED_DIR"/residents/*/module-graph/gea-module-graph.json; do
|
|
2208
|
+
[[ -f "$graph" ]] && RESOURCE_SYNC_ARGS+=(--module-graph "$graph")
|
|
2209
|
+
done
|
|
2163
2210
|
RESOURCE_SYNC_RESULT="$(node "$ROOT_DIR/targets/macos/sync-resources.mjs" "${RESOURCE_SYNC_ARGS[@]}")"
|
|
2164
2211
|
if [[ "$RESOURCE_SYNC_RESULT" == *'changed=1'* ]]; then BUNDLE_CONTENT_CHANGED=1; fi
|
|
2165
2212
|
fi
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
#include <memory>
|
|
13
13
|
#include <mutex>
|
|
14
14
|
#include <string>
|
|
15
|
+
#include <sys/stat.h>
|
|
15
16
|
#include <unordered_map>
|
|
16
17
|
#include <utility>
|
|
17
18
|
#include <vector>
|
|
@@ -73,10 +74,21 @@ NSString *familyForId(int id)
|
|
|
73
74
|
// the process lifetime: the rasterizer keeps stbtt_fontinfo pointers into
|
|
74
75
|
// them across atlas rebuilds. Construct-on-first-use for the same dyld-
|
|
75
76
|
// initializer-ordering reason as FamilyRegistry above.
|
|
77
|
+
using FontBytes = std::shared_ptr<const std::vector<std::uint8_t>>;
|
|
78
|
+
using FontNames = std::unordered_map<std::string, FontBytes>;
|
|
79
|
+
|
|
80
|
+
struct FontFile {
|
|
81
|
+
struct stat stamp;
|
|
82
|
+
FontBytes bytes;
|
|
83
|
+
};
|
|
84
|
+
|
|
76
85
|
struct TtfByteRegistry {
|
|
77
86
|
std::mutex lock;
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
FontNames byFamily;
|
|
88
|
+
FontNames byAlias;
|
|
89
|
+
FontNames documentFonts;
|
|
90
|
+
FontNames pendingFonts;
|
|
91
|
+
std::unordered_map<std::string, FontFile> files;
|
|
80
92
|
};
|
|
81
93
|
|
|
82
94
|
TtfByteRegistry &ttfByteRegistry()
|
|
@@ -94,19 +106,19 @@ std::string lowercased(const std::string &value)
|
|
|
94
106
|
|
|
95
107
|
bool softwareTextMeasurement = false;
|
|
96
108
|
|
|
97
|
-
|
|
109
|
+
bool registerTtfBytesForFamily(NSString *path, NSArray<NSString *> *aliases)
|
|
98
110
|
{
|
|
99
111
|
NSData *data = [NSData dataWithContentsOfFile:path];
|
|
100
|
-
if (data.length == 0) return;
|
|
112
|
+
if (data.length == 0) return false;
|
|
101
113
|
CTFontDescriptorRef desc = CTFontManagerCreateFontDescriptorFromData((__bridge CFDataRef)data);
|
|
102
|
-
if (!desc) return;
|
|
114
|
+
if (!desc) return false;
|
|
103
115
|
CFStringRef family = (CFStringRef)CTFontDescriptorCopyAttribute(desc, kCTFontFamilyNameAttribute);
|
|
104
116
|
CFRelease(desc);
|
|
105
|
-
if (!family) return;
|
|
117
|
+
if (!family) return false;
|
|
106
118
|
char buf[256] = {0};
|
|
107
119
|
const bool ok = CFStringGetCString(family, buf, sizeof(buf), kCFStringEncodingUTF8);
|
|
108
120
|
CFRelease(family);
|
|
109
|
-
if (!ok || !buf[0]) return;
|
|
121
|
+
if (!ok || !buf[0]) return false;
|
|
110
122
|
const auto *bytes = static_cast<const std::uint8_t *>(data.bytes);
|
|
111
123
|
TtfByteRegistry ®istry = ttfByteRegistry();
|
|
112
124
|
std::scoped_lock guard(registry.lock);
|
|
@@ -115,6 +127,7 @@ void registerTtfBytesForFamily(NSString *path, NSArray<NSString *> *aliases)
|
|
|
115
127
|
auto font = std::make_shared<const std::vector<std::uint8_t>>(bytes, bytes + data.length);
|
|
116
128
|
registry.byFamily.emplace(lowercased(buf), font);
|
|
117
129
|
for (NSString *alias in aliases) registry.byAlias.emplace(alias.UTF8String, font);
|
|
130
|
+
return true;
|
|
118
131
|
}
|
|
119
132
|
|
|
120
133
|
} // namespace
|
|
@@ -129,9 +142,11 @@ const std::uint8_t *runtimeTtfBytesForFamilyId(int familyId, unsigned long *leng
|
|
|
129
142
|
TtfByteRegistry ®istry = ttfByteRegistry();
|
|
130
143
|
std::scoped_lock guard(registry.lock);
|
|
131
144
|
const auto key = lowercased(family.UTF8String);
|
|
145
|
+
const auto document = registry.documentFonts.find(key);
|
|
132
146
|
const auto alias = registry.byAlias.find(key);
|
|
133
147
|
const auto fallback = registry.byFamily.find(key);
|
|
134
|
-
const auto *font =
|
|
148
|
+
const auto *font = document != registry.documentFonts.end() ? document->second.get()
|
|
149
|
+
: alias != registry.byAlias.end() ? alias->second.get()
|
|
135
150
|
: fallback != registry.byFamily.end() ? fallback->second.get() : nullptr;
|
|
136
151
|
if (!font) return nullptr;
|
|
137
152
|
if (length) *length = font->size();
|
|
@@ -240,6 +255,58 @@ int registerCustomTtfDirectory(NSString *directoryPath)
|
|
|
240
255
|
return count;
|
|
241
256
|
}
|
|
242
257
|
|
|
258
|
+
extern "C" void gea_macos_begin_runtime_fonts()
|
|
259
|
+
{
|
|
260
|
+
auto ®istry = ttfByteRegistry();
|
|
261
|
+
std::scoped_lock guard(registry.lock);
|
|
262
|
+
registry.pendingFonts.clear();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
extern "C" bool gea_macos_register_runtime_font(const char *path, const char *family)
|
|
266
|
+
{
|
|
267
|
+
struct stat stamp{};
|
|
268
|
+
if (!family || !*family || stat(path, &stamp) != 0 || !S_ISREG(stamp.st_mode) ||
|
|
269
|
+
stamp.st_size <= 0 || stamp.st_size > 16 * 1024 * 1024) return false;
|
|
270
|
+
auto ®istry = ttfByteRegistry();
|
|
271
|
+
std::scoped_lock guard(registry.lock);
|
|
272
|
+
const auto existing = registry.files.find(path);
|
|
273
|
+
FontBytes bytes;
|
|
274
|
+
if (existing != registry.files.end()) {
|
|
275
|
+
const auto &old = existing->second.stamp;
|
|
276
|
+
if (old.st_dev == stamp.st_dev && old.st_ino == stamp.st_ino &&
|
|
277
|
+
old.st_size == stamp.st_size && old.st_ctimespec.tv_sec == stamp.st_ctimespec.tv_sec &&
|
|
278
|
+
old.st_ctimespec.tv_nsec == stamp.st_ctimespec.tv_nsec) {
|
|
279
|
+
bytes = existing->second.bytes;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (!bytes) {
|
|
283
|
+
NSString *filename = [NSString stringWithUTF8String:path];
|
|
284
|
+
NSData *data = filename ? [NSData dataWithContentsOfFile:filename] : nil;
|
|
285
|
+
if (data.length != static_cast<NSUInteger>(stamp.st_size)) return false;
|
|
286
|
+
CTFontDescriptorRef descriptor = CTFontManagerCreateFontDescriptorFromData((__bridge CFDataRef)data);
|
|
287
|
+
if (!descriptor) return false;
|
|
288
|
+
CFRelease(descriptor);
|
|
289
|
+
const auto *begin = static_cast<const std::uint8_t *>(data.bytes);
|
|
290
|
+
bytes = std::make_shared<const std::vector<std::uint8_t>>(begin, begin + data.length);
|
|
291
|
+
if (registry.files.size() >= 32) registry.files.clear();
|
|
292
|
+
registry.files.insert_or_assign(path, FontFile{stamp, bytes});
|
|
293
|
+
}
|
|
294
|
+
registry.pendingFonts.emplace(lowercased(family), bytes);
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
extern "C" void gea_macos_commit_runtime_fonts()
|
|
299
|
+
{
|
|
300
|
+
auto ®istry = ttfByteRegistry();
|
|
301
|
+
std::scoped_lock guard(registry.lock);
|
|
302
|
+
if (registry.documentFonts != registry.pendingFonts) {
|
|
303
|
+
// The old tree is gone. Release glyph slots before dropping their byte buffers.
|
|
304
|
+
gea::framework::graphics::FontRegistry::invalidateRuntimeFonts();
|
|
305
|
+
registry.documentFonts.swap(registry.pendingFonts);
|
|
306
|
+
}
|
|
307
|
+
registry.pendingFonts.clear();
|
|
308
|
+
}
|
|
309
|
+
|
|
243
310
|
} // namespace gea::macos
|
|
244
311
|
|
|
245
312
|
// Strong overrides of the framework's weak font-lookup hooks for the AppKit
|
|
@@ -75,11 +75,20 @@ void submit_full_frame()
|
|
|
75
75
|
|
|
76
76
|
bool gea_macos_prepare_prerender(int width, int height)
|
|
77
77
|
{
|
|
78
|
-
g_canvas_w
|
|
79
|
-
|
|
78
|
+
if (!g_framebuffer || width != g_canvas_w || height != g_canvas_h) {
|
|
79
|
+
auto *pixels = static_cast<gea::framework::graphics::pixel::native_t *>(
|
|
80
|
+
std::calloc(static_cast<size_t>(width) * height, sizeof(*g_framebuffer)));
|
|
81
|
+
if (!pixels) return false;
|
|
82
|
+
std::free(g_framebuffer);
|
|
83
|
+
g_framebuffer = pixels;
|
|
84
|
+
g_canvas_w = width;
|
|
85
|
+
g_canvas_h = height;
|
|
86
|
+
}
|
|
80
87
|
g_prerender = true;
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
g_canvas.bindPixels(g_framebuffer, width, height);
|
|
89
|
+
g_canvas.setGlobalAlpha(255);
|
|
90
|
+
g_canvas.clear(0);
|
|
91
|
+
return true;
|
|
83
92
|
}
|
|
84
93
|
|
|
85
94
|
bool gea_macos_write_prerender_png(NSString *path)
|
|
@@ -46,6 +46,10 @@ namespace gea::macos { void installWifiDriver(); int nodeIdForView(NSView *view)
|
|
|
46
46
|
#include "css/declarative.h"
|
|
47
47
|
#include "css/engine.h"
|
|
48
48
|
#include "display.h"
|
|
49
|
+
#if __has_include("platform/prerender_video.h")
|
|
50
|
+
#include "platform/prerender_video.h"
|
|
51
|
+
#define GEA_MACOS_PRERENDER_VIDEO 1
|
|
52
|
+
#endif
|
|
49
53
|
#include "platform/file_cache.h"
|
|
50
54
|
#if __has_include("resident_apps.h")
|
|
51
55
|
#include "resident_apps.h"
|
|
@@ -66,6 +70,10 @@ namespace gea::macos { void installWifiDriver(); int nodeIdForView(NSView *view)
|
|
|
66
70
|
#include <cstdio>
|
|
67
71
|
#include <cstdlib>
|
|
68
72
|
#include <cstring>
|
|
73
|
+
#include <exception>
|
|
74
|
+
#include <iostream>
|
|
75
|
+
#include <string>
|
|
76
|
+
#include <unistd.h>
|
|
69
77
|
#include "gea_appkit_host.h"
|
|
70
78
|
|
|
71
79
|
extern "C" int gea_embedded_now_ms(void);
|
|
@@ -1238,46 +1246,89 @@ void gea::apple::AppKit::setScrollDocumentTopAligned(gea::apple::AppKit::NSScrol
|
|
|
1238
1246
|
}
|
|
1239
1247
|
#endif
|
|
1240
1248
|
|
|
1241
|
-
static
|
|
1249
|
+
static bool validPrerenderViewport(int width, int height, double dpr)
|
|
1242
1250
|
{
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
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;
|
|
1251
|
+
return width >= 1 && width <= 8192 && height >= 1 && height <= 8192 &&
|
|
1252
|
+
std::isfinite(dpr) && dpr >= 0.1 && dpr <= 8;
|
|
1253
|
+
}
|
|
1253
1254
|
|
|
1255
|
+
static void preparePrerenderHost()
|
|
1256
|
+
{
|
|
1254
1257
|
NSString *fontsDir = [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"Fonts"];
|
|
1255
1258
|
gea::macos::registerCustomTtfDirectory(fontsDir);
|
|
1256
1259
|
gea::macos::useSoftwareTextMeasurement();
|
|
1257
1260
|
gea::platform::storage::setMountProvider(+[]() { return true; });
|
|
1261
|
+
}
|
|
1258
1262
|
|
|
1263
|
+
static bool loadPrerenderPage(int width, int height, double dpr)
|
|
1264
|
+
{
|
|
1265
|
+
if (!gea_macos_prepare_prerender(width, height)) return false;
|
|
1259
1266
|
gea_macos_set_prerender_time(0);
|
|
1260
1267
|
// Seed the timer scheduler before app initialization schedules any timers.
|
|
1268
|
+
gea::host::resetAnimationFrameCallbacks();
|
|
1269
|
+
gea::host::resetScheduledTimers();
|
|
1261
1270
|
gea::host::runAnimationFrameCallbacks(0);
|
|
1262
1271
|
gea::framework::app::Application::init(width, height, dpr);
|
|
1263
|
-
|
|
1264
|
-
if (tree.mountedRoot() < 0) {
|
|
1265
|
-
std::fputs("Gea prerender requires a mounted UI tree\n", stderr);
|
|
1266
|
-
return 1;
|
|
1267
|
-
}
|
|
1272
|
+
if (gea::embedded::ui::Tree::instance().mountedRoot() < 0) return false;
|
|
1268
1273
|
gea::css::DeclarativeAnimations::scanAndStart(0);
|
|
1274
|
+
return true;
|
|
1275
|
+
}
|
|
1269
1276
|
|
|
1277
|
+
static void paintPrerenderFrame(int timeMs)
|
|
1278
|
+
{
|
|
1279
|
+
@autoreleasepool {
|
|
1280
|
+
gea_macos_set_prerender_time(timeMs);
|
|
1281
|
+
gea::embedded::ui::StyleSheet::instance().startCssAnimations(timeMs);
|
|
1282
|
+
gea::css::AnimationEngine::instance().tick(static_cast<std::uint32_t>(timeMs));
|
|
1283
|
+
gea::framework::app::Application::frame(timeMs);
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
static void drawPrerenderFrames(int fps, int targetMs)
|
|
1288
|
+
{
|
|
1270
1289
|
for (std::int64_t frame = 0; ; ++frame) {
|
|
1271
1290
|
const auto tickMs = (frame * 1000 + fps / 2) / fps;
|
|
1272
1291
|
const int timeMs = static_cast<int>(std::min<std::int64_t>(tickMs, targetMs));
|
|
1273
|
-
|
|
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
|
-
}
|
|
1292
|
+
paintPrerenderFrame(timeMs);
|
|
1279
1293
|
if (timeMs == targetMs) break;
|
|
1280
1294
|
}
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
static int prerender(int argc, const char *argv[])
|
|
1298
|
+
{
|
|
1299
|
+
const bool video = std::strcmp(argv[1], "--gea-prerender-video") == 0;
|
|
1300
|
+
if (argc != (video ? 9 : 8)) return 2;
|
|
1301
|
+
const int width = std::atoi(argv[3]);
|
|
1302
|
+
const int height = std::atoi(argv[4]);
|
|
1303
|
+
const double dpr = std::atof(argv[5]);
|
|
1304
|
+
const int fps = std::atoi(argv[6]);
|
|
1305
|
+
const int targetMs = std::atoi(argv[7]);
|
|
1306
|
+
if (!validPrerenderViewport(width, height, dpr) || fps < 1 || fps > 1000 || targetMs < 0) return 2;
|
|
1307
|
+
try {
|
|
1308
|
+
if (video) {
|
|
1309
|
+
#if defined(GEA_MACOS_PRERENDER_VIDEO)
|
|
1310
|
+
const int endMs = std::atoi(argv[8]);
|
|
1311
|
+
if (endMs <= targetMs) return 2;
|
|
1312
|
+
gea::platform::prerender::VideoFrames stream(width, height);
|
|
1313
|
+
gea::platform::prerender::VideoClock clock(fps);
|
|
1314
|
+
preparePrerenderHost();
|
|
1315
|
+
if (!loadPrerenderPage(width, height, dpr)) throw std::runtime_error("Could not mount the page");
|
|
1316
|
+
gea::platform::prerender::streamVideoFrames(stream, fps, targetMs, endMs, paintPrerenderFrame);
|
|
1317
|
+
return 0;
|
|
1318
|
+
#else
|
|
1319
|
+
throw std::runtime_error("The installed @geastack/core lacks native video export");
|
|
1320
|
+
#endif
|
|
1321
|
+
}
|
|
1322
|
+
preparePrerenderHost();
|
|
1323
|
+
if (!loadPrerenderPage(width, height, dpr)) {
|
|
1324
|
+
std::fputs("Gea prerender could not mount the page\n", stderr);
|
|
1325
|
+
return 1;
|
|
1326
|
+
}
|
|
1327
|
+
drawPrerenderFrames(fps, targetMs);
|
|
1328
|
+
} catch (const std::exception &error) {
|
|
1329
|
+
std::fprintf(stderr, "%s\n", error.what());
|
|
1330
|
+
return 1;
|
|
1331
|
+
}
|
|
1281
1332
|
if (!gea_macos_write_prerender_png([NSString stringWithUTF8String:argv[2]])) {
|
|
1282
1333
|
std::fprintf(stderr, "Could not write PNG to %s\n", argv[2]);
|
|
1283
1334
|
return 1;
|
|
@@ -1285,11 +1336,102 @@ static int prerender(int argc, const char *argv[])
|
|
|
1285
1336
|
return 0;
|
|
1286
1337
|
}
|
|
1287
1338
|
|
|
1339
|
+
static bool writePrerenderReply(FILE *stream, NSDictionary *reply)
|
|
1340
|
+
{
|
|
1341
|
+
NSData *encoded = [NSJSONSerialization dataWithJSONObject:reply options:0 error:nil];
|
|
1342
|
+
return encoded && std::fwrite(encoded.bytes, 1, encoded.length, stream) == encoded.length &&
|
|
1343
|
+
std::fputc('\n', stream) != EOF && std::fflush(stream) == 0;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
static int prerenderWorker()
|
|
1347
|
+
{
|
|
1348
|
+
// Reserve stdout for the request protocol. Engine diagnostics use stderr.
|
|
1349
|
+
const int protocolFd = dup(STDOUT_FILENO);
|
|
1350
|
+
if (protocolFd < 0) return 1;
|
|
1351
|
+
FILE *protocol = fdopen(protocolFd, "w");
|
|
1352
|
+
if (!protocol) {
|
|
1353
|
+
close(protocolFd);
|
|
1354
|
+
return 1;
|
|
1355
|
+
}
|
|
1356
|
+
if (dup2(STDERR_FILENO, STDOUT_FILENO) < 0) {
|
|
1357
|
+
std::fclose(protocol);
|
|
1358
|
+
return 1;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
preparePrerenderHost();
|
|
1362
|
+
std::string mountedInput;
|
|
1363
|
+
int mountedWidth = 0, mountedHeight = 0;
|
|
1364
|
+
double mountedDpr = 0;
|
|
1365
|
+
std::string line;
|
|
1366
|
+
bool connected = true;
|
|
1367
|
+
while (connected && std::getline(std::cin, line)) {
|
|
1368
|
+
@autoreleasepool {
|
|
1369
|
+
NSData *data = [NSData dataWithBytes:line.data() length:line.size()];
|
|
1370
|
+
id decoded = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
|
1371
|
+
NSDictionary *request = [decoded isKindOfClass:NSDictionary.class] ? decoded : nil;
|
|
1372
|
+
NSString *input = request[@"input"];
|
|
1373
|
+
NSString *output = request[@"out"];
|
|
1374
|
+
NSNumber *widthNumber = request[@"width"] ?: @480;
|
|
1375
|
+
NSNumber *heightNumber = request[@"height"] ?: @220;
|
|
1376
|
+
NSNumber *dprNumber = request[@"dpr"] ?: @1;
|
|
1377
|
+
NSNumber *reuse = request[@"reusePage"] ?: @NO;
|
|
1378
|
+
if (![input isKindOfClass:NSString.class] || input.length == 0 ||
|
|
1379
|
+
![output isKindOfClass:NSString.class] || output.length == 0 ||
|
|
1380
|
+
![widthNumber isKindOfClass:NSNumber.class] ||
|
|
1381
|
+
![heightNumber isKindOfClass:NSNumber.class] ||
|
|
1382
|
+
![dprNumber isKindOfClass:NSNumber.class] ||
|
|
1383
|
+
![reuse isKindOfClass:NSNumber.class] ||
|
|
1384
|
+
widthNumber.doubleValue != widthNumber.intValue ||
|
|
1385
|
+
heightNumber.doubleValue != heightNumber.intValue ||
|
|
1386
|
+
!validPrerenderViewport(widthNumber.intValue, heightNumber.intValue, dprNumber.doubleValue)) {
|
|
1387
|
+
connected = writePrerenderReply(protocol, @{@"ok": @NO, @"error": @"Invalid capture request"});
|
|
1388
|
+
continue;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
const int width = widthNumber.intValue, height = heightNumber.intValue;
|
|
1392
|
+
const double dpr = dprNumber.doubleValue;
|
|
1393
|
+
const bool reusePage = reuse.boolValue && mountedInput == input.UTF8String &&
|
|
1394
|
+
mountedWidth == width && mountedHeight == height && mountedDpr == dpr;
|
|
1395
|
+
const auto started = std::chrono::steady_clock::now();
|
|
1396
|
+
try {
|
|
1397
|
+
if (!reusePage) {
|
|
1398
|
+
mountedInput.clear();
|
|
1399
|
+
if (setenv("GEA_PRERENDER_INPUT", input.fileSystemRepresentation, 1) != 0 ||
|
|
1400
|
+
!loadPrerenderPage(width, height, dpr)) {
|
|
1401
|
+
connected = writePrerenderReply(protocol, @{@"ok": @NO, @"error": @"Could not mount the page"});
|
|
1402
|
+
continue;
|
|
1403
|
+
}
|
|
1404
|
+
drawPrerenderFrames(60, 0);
|
|
1405
|
+
mountedInput = input.UTF8String;
|
|
1406
|
+
mountedWidth = width;
|
|
1407
|
+
mountedHeight = height;
|
|
1408
|
+
mountedDpr = dpr;
|
|
1409
|
+
}
|
|
1410
|
+
if (!gea_macos_write_prerender_png(output)) {
|
|
1411
|
+
connected = writePrerenderReply(protocol, @{@"ok": @NO, @"error": @"Could not write the PNG"});
|
|
1412
|
+
continue;
|
|
1413
|
+
}
|
|
1414
|
+
const double ms = std::chrono::duration<double, std::milli>(
|
|
1415
|
+
std::chrono::steady_clock::now() - started).count();
|
|
1416
|
+
connected = writePrerenderReply(protocol, @{@"ok": @YES, @"ms": @(ms), @"reusedPage": @(reusePage)});
|
|
1417
|
+
} catch (const std::exception &error) {
|
|
1418
|
+
mountedInput.clear();
|
|
1419
|
+
NSString *message = [NSString stringWithUTF8String:error.what()] ?: @"Capture failed";
|
|
1420
|
+
connected = writePrerenderReply(protocol, @{@"ok": @NO, @"error": message});
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
std::fclose(protocol);
|
|
1425
|
+
return connected ? 0 : 1;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1288
1428
|
int main(int argc, const char *argv[])
|
|
1289
1429
|
{
|
|
1290
1430
|
GeaNativeTerminationGuard terminationGuard;
|
|
1291
1431
|
@autoreleasepool {
|
|
1292
|
-
if (argc > 1 && std::strcmp(argv[1], "--gea-prerender") == 0
|
|
1432
|
+
if (argc > 1 && (std::strcmp(argv[1], "--gea-prerender") == 0 ||
|
|
1433
|
+
std::strcmp(argv[1], "--gea-prerender-video") == 0)) return prerender(argc, argv);
|
|
1434
|
+
if (argc == 2 && std::strcmp(argv[1], "--gea-prerender-worker") == 0) return prerenderWorker();
|
|
1293
1435
|
gea_macos_smoke_log("[gea-macos] main entered");
|
|
1294
1436
|
const bool backgroundTest = gea::macos::background_test::enabled();
|
|
1295
1437
|
NSApplication *app = [NSApplication sharedApplication];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Writes the TU that tells the engine's runtime TTF slots which glyphs beyond
|
|
3
|
+
// printable ASCII to cover (generated::runtimeTtfDeclaredCodepoints).
|
|
4
|
+
//
|
|
5
|
+
// The font generator puts that set -- its raster baseline plus every
|
|
6
|
+
// `--gea-font-charset` the app's CSS names -- into gea_embedded_font_generated.cpp,
|
|
7
|
+
// but a windowed macOS build does not link that TU (it carries baked atlases the
|
|
8
|
+
// window never uses), and resident builds prefix its symbols. Without this file
|
|
9
|
+
// the engine's weak default applies and `·`, `€`, `–` render as `?`.
|
|
10
|
+
//
|
|
11
|
+
// usage: runtime-glyphs.mjs --out <file.cpp> <gea_embedded_font_generated.cpp>...
|
|
12
|
+
import fs from 'node:fs'
|
|
13
|
+
|
|
14
|
+
const args = process.argv.slice(2)
|
|
15
|
+
const outIndex = args.indexOf('--out')
|
|
16
|
+
if (outIndex < 0 || !args[outIndex + 1]) {
|
|
17
|
+
console.error('usage: runtime-glyphs.mjs --out <file.cpp> <font-generated.cpp>...')
|
|
18
|
+
process.exit(2)
|
|
19
|
+
}
|
|
20
|
+
const out = args[outIndex + 1]
|
|
21
|
+
const inputs = args.filter((_, i) => i !== outIndex && i !== outIndex + 1)
|
|
22
|
+
|
|
23
|
+
const codepoints = new Set()
|
|
24
|
+
for (const input of inputs) {
|
|
25
|
+
if (!fs.existsSync(input)) continue
|
|
26
|
+
const match = fs.readFileSync(input, 'utf8').match(/kRuntimeTtfDeclaredCodepoints\[\]\s*=\s*\{([^}]*)\}/)
|
|
27
|
+
if (!match) continue
|
|
28
|
+
for (const token of match[1].split(',')) {
|
|
29
|
+
const value = Number(token.trim())
|
|
30
|
+
if (Number.isInteger(value) && value > 0x7e) codepoints.add(value)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const list = [...codepoints].sort((a, b) => a - b)
|
|
34
|
+
const source = [
|
|
35
|
+
'// Generated by @geastack/apple targets/macos/runtime-glyphs.mjs. Do not edit.',
|
|
36
|
+
'namespace gea::framework::graphics::generated {',
|
|
37
|
+
'',
|
|
38
|
+
`static const int kDeclared[] = {${list.length > 0 ? list.map((cp) => `0x${cp.toString(16)}`).join(', ') : '0'}};`,
|
|
39
|
+
'',
|
|
40
|
+
'const int *runtimeTtfDeclaredCodepoints(int *count)',
|
|
41
|
+
'{',
|
|
42
|
+
` if (count) *count = ${list.length};`,
|
|
43
|
+
' return kDeclared;',
|
|
44
|
+
'}',
|
|
45
|
+
'',
|
|
46
|
+
'} // namespace gea::framework::graphics::generated',
|
|
47
|
+
'',
|
|
48
|
+
].join('\n')
|
|
49
|
+
if (!fs.existsSync(out) || fs.readFileSync(out, 'utf8') !== source) fs.writeFileSync(out, source)
|
|
@@ -30,9 +30,10 @@ const manifestPath = path.resolve(value('--manifest') || '')
|
|
|
30
30
|
const configDir = value('--config-dir') ? path.resolve(value('--config-dir')) : ''
|
|
31
31
|
const appDirs = values('--app-dir').map((item) => path.resolve(item))
|
|
32
32
|
const sharedCssDirs = values('--shared-css-dir').map((item) => path.resolve(item))
|
|
33
|
+
const moduleGraphs = values('--module-graph').map((item) => path.resolve(item))
|
|
33
34
|
|
|
34
35
|
if (!value('--resources-dir') || !value('--manifest')) {
|
|
35
|
-
fail('usage: sync-resources.mjs --resources-dir <dir> --manifest <file> [--config-dir <dir>] [--app-dir <dir> ...] [--shared-css-dir <dir> ...]')
|
|
36
|
+
fail('usage: sync-resources.mjs --resources-dir <dir> --manifest <file> [--config-dir <dir>] [--app-dir <dir> ...] [--shared-css-dir <dir> ...] [--module-graph <gea-module-graph.json> ...]')
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
fs.mkdirSync(resourcesDir, { recursive: true })
|
|
@@ -71,6 +72,28 @@ function isSafeBasename(value) {
|
|
|
71
72
|
return value !== '.' && value !== '..' && path.basename(value) === value && !value.includes('/') && !value.includes('\\')
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
// Every stylesheet the compiled app imports, from the module graph its build
|
|
76
|
+
// wrote. This is the authority on which @font-face rules the app uses:
|
|
77
|
+
// walking the app's own folder misses CSS reached through imports, such as a
|
|
78
|
+
// workspace package of shared styles (import "../../shared").
|
|
79
|
+
function moduleGraphCss(graphPath) {
|
|
80
|
+
let graph
|
|
81
|
+
try {
|
|
82
|
+
graph = JSON.parse(fs.readFileSync(graphPath, 'utf8'))
|
|
83
|
+
} catch {
|
|
84
|
+
return []
|
|
85
|
+
}
|
|
86
|
+
const files = new Set()
|
|
87
|
+
for (const module of Array.isArray(graph?.modules) ? graph.modules : []) {
|
|
88
|
+
for (const id of [module?.file, module?.id, ...(Array.isArray(module?.imports) ? module.imports.map((item) => item?.resolvedId) : [])]) {
|
|
89
|
+
if (typeof id !== 'string') continue
|
|
90
|
+
const file = id.split(/[?#]/, 1)[0]
|
|
91
|
+
if (file.endsWith('.css') && fs.existsSync(file) && fs.statSync(file).isFile()) files.add(file)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return [...files]
|
|
95
|
+
}
|
|
96
|
+
|
|
74
97
|
function walkCss(root, visit) {
|
|
75
98
|
if (!root || !fs.existsSync(root)) return
|
|
76
99
|
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
@@ -87,8 +110,7 @@ function walkCss(root, visit) {
|
|
|
87
110
|
const desiredFonts = new Map()
|
|
88
111
|
const desiredFontLicenses = new Map()
|
|
89
112
|
const fontAliases = new Map()
|
|
90
|
-
|
|
91
|
-
walkCss(root, (cssPath) => {
|
|
113
|
+
function visitCss(cssPath) {
|
|
92
114
|
const css = fs.readFileSync(cssPath, 'utf8').replace(/\/\*[\s\S]*?\*\//g, '')
|
|
93
115
|
const facePattern = /@font-face\s*\{([^}]+)\}/gi
|
|
94
116
|
let face
|
|
@@ -119,9 +141,11 @@ for (const root of [...appDirs, ...sharedCssDirs]) {
|
|
|
119
141
|
}
|
|
120
142
|
}
|
|
121
143
|
}
|
|
122
|
-
})
|
|
123
144
|
}
|
|
124
145
|
|
|
146
|
+
for (const graph of moduleGraphs) for (const cssPath of moduleGraphCss(graph)) visitCss(cssPath)
|
|
147
|
+
for (const root of [...appDirs, ...sharedCssDirs]) walkCss(root, visitCss)
|
|
148
|
+
|
|
125
149
|
let previousFonts = []
|
|
126
150
|
try {
|
|
127
151
|
const previous = JSON.parse(fs.readFileSync(manifestPath, 'utf8'))
|