@native-sdk/cli 0.9.1 → 0.9.2
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/build/app.zig +26 -9
- package/build.zig +55 -0
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.ts +3 -1
- package/skill-data/native-ui/SKILL.md +7 -7
- package/skill-data/ts-core/SKILL.md +1 -1
- package/src/app_runner/root.zig +93 -6
- package/src/app_runner/ts_core_main.zig +4 -4
- package/src/app_runner/window_placement.zig +63 -0
- package/src/embed/app_exports.zig +2 -1
- package/src/embed/conversions.zig +1 -0
- package/src/embed/host.zig +10 -3
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +13 -1
- package/src/embed/types.zig +2 -0
- package/src/embed/ui_host.zig +26 -2
- package/src/platform/android/NativeSdkActivity.java +49 -4
- package/src/platform/android/android_host.c +3 -3
- package/src/platform/android/native_sdk_app.h +1 -1
- package/src/platform/ios/apple_image_fit.h +38 -0
- package/src/platform/ios/files.zig +1 -0
- package/src/platform/ios/native_sdk_app.h +1 -1
- package/src/platform/ios/uikit_host.m +28 -5
- package/src/platform/linux/cef_host.cpp +10 -2
- package/src/platform/linux/gtk_host.c +43 -10
- package/src/platform/linux/gtk_host.h +3 -3
- package/src/platform/linux/root.zig +22 -7
- package/src/platform/macos/appkit_host.h +7 -4
- package/src/platform/macos/appkit_host.m +192 -40
- package/src/platform/macos/cef_host.mm +132 -34
- package/src/platform/macos/image_fit_test.m +44 -0
- package/src/platform/macos/root.zig +154 -9
- package/src/platform/null_platform.zig +17 -3
- package/src/platform/null_platform_tests.zig +58 -4
- package/src/platform/root.zig +2 -0
- package/src/platform/types.zig +69 -19
- package/src/platform/windows/root.zig +22 -7
- package/src/platform/windows/webview2_host.cpp +31 -6
- package/src/primitives/app_manifest/root.zig +3 -0
- package/src/primitives/app_manifest/tests.zig +24 -0
- package/src/primitives/app_manifest/types.zig +13 -0
- package/src/primitives/app_manifest/validation.zig +24 -0
- package/src/primitives/canvas/a11y_audit.zig +9 -7
- package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
- package/src/primitives/canvas/events.zig +50 -0
- package/src/primitives/canvas/layout_audit.zig +6 -6
- package/src/primitives/canvas/markdown.zig +4 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -0
- package/src/primitives/canvas/png.zig +138 -0
- package/src/primitives/canvas/root.zig +13 -2
- package/src/primitives/canvas/text_span_tests.zig +5 -3
- package/src/primitives/canvas/text_spans.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +20 -0
- package/src/primitives/canvas/ui.zig +55 -2
- package/src/primitives/canvas/ui_markup.zig +40 -13
- package/src/primitives/canvas/ui_markup_binary.zig +8 -6
- package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
- package/src/primitives/canvas/ui_markup_tests.zig +11 -2
- package/src/primitives/canvas/ui_markup_view.zig +8 -2
- package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +47 -0
- package/src/primitives/canvas/widget_access.zig +3 -3
- package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
- package/src/primitives/canvas/widget_invalidation.zig +33 -6
- package/src/primitives/canvas/widget_layout.zig +333 -126
- package/src/primitives/canvas/widget_layout_tests.zig +169 -0
- package/src/primitives/canvas/widget_metrics.zig +7 -8
- package/src/primitives/canvas/widget_render.zig +76 -44
- package/src/primitives/canvas/widget_render_controls.zig +110 -32
- package/src/primitives/canvas/widget_render_style.zig +58 -18
- package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
- package/src/primitives/canvas/widget_routing.zig +40 -34
- package/src/primitives/canvas/widget_runtime.zig +11 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
- package/src/primitives/canvas/widget_semantics.zig +8 -3
- package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
- package/src/primitives/canvas/widget_tree.zig +99 -5
- package/src/primitives/canvas/widgets.zig +20 -7
- package/src/root.zig +3 -0
- package/src/runtime/api.zig +6 -0
- package/src/runtime/automation_widget_dispatch.zig +48 -6
- package/src/runtime/builtin_bridge.zig +5 -2
- package/src/runtime/canvas_frame_packet_tests.zig +22 -13
- package/src/runtime/canvas_image_tests.zig +146 -2
- package/src/runtime/canvas_images.zig +35 -16
- package/src/runtime/canvas_limits.zig +13 -3
- package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
- package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
- package/src/runtime/canvas_widget_control_tests.zig +31 -1
- package/src/runtime/canvas_widget_events.zig +151 -26
- package/src/runtime/canvas_widget_floating_tests.zig +48 -0
- package/src/runtime/canvas_widget_runtime.zig +322 -102
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
- package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
- package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
- package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
- package/src/runtime/canvas_widget_state.zig +33 -7
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +14 -14
- package/src/runtime/effects_image_tests.zig +91 -0
- package/src/runtime/gpu_surface_events.zig +25 -2
- package/src/runtime/root.zig +2 -0
- package/src/runtime/session_replay.zig +13 -8
- package/src/runtime/session_tests.zig +111 -4
- package/src/runtime/shell_layout_tests.zig +12 -0
- package/src/runtime/ts_core_host_tests.zig +47 -0
- package/src/runtime/ui_app.zig +9 -3
- package/src/runtime/ui_app_tests.zig +119 -19
- package/src/runtime/ui_app_window_tests.zig +13 -1
- package/src/runtime/view.zig +3 -0
- package/src/runtime/view_widget_control.zig +18 -0
- package/src/runtime/view_widget_scroll.zig +112 -18
- package/src/runtime/view_widget_tree.zig +110 -13
- package/src/runtime/widget_bridge.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +86 -0
- package/src/runtime/window_storage.zig +16 -1
- package/src/runtime/window_views.zig +1 -0
- package/src/tooling/ios.zig +3 -0
- package/src/tooling/manifest.zig +90 -2
- package/src/tooling/package.zig +67 -2
- package/src/tooling/raw_manifest.zig +10 -0
- package/src/tooling/templates.zig +128 -18
- package/src/tooling/web_engine.zig +1 -1
package/src/app_runner/root.zig
CHANGED
|
@@ -3,9 +3,16 @@ const build_options = @import("build_options");
|
|
|
3
3
|
const native_sdk = @import("native_sdk");
|
|
4
4
|
const app_manifest = @import("app_manifest_zon");
|
|
5
5
|
const built_relational_migrations = @import("relational_migrations");
|
|
6
|
+
const window_placement = @import("window_placement.zig");
|
|
6
7
|
const manifest_shortcuts = if (@hasField(@TypeOf(app_manifest), "shortcuts")) app_manifest.shortcuts else .{};
|
|
7
8
|
const manifest_windows = if (@hasField(@TypeOf(app_manifest), "windows")) app_manifest.windows else .{};
|
|
8
9
|
|
|
10
|
+
fn manifestImagePixelBudget() usize {
|
|
11
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "images")) return native_sdk.max_registered_canvas_image_pixel_bytes;
|
|
12
|
+
if (comptime !@hasField(@TypeOf(app_manifest.images), "max_image_pixel_bytes")) return native_sdk.max_registered_canvas_image_pixel_bytes;
|
|
13
|
+
return app_manifest.images.max_image_pixel_bytes;
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
pub const app_assets = @import("app_assets.zig");
|
|
10
17
|
|
|
11
18
|
pub const StdoutTraceSink = struct {
|
|
@@ -49,6 +56,8 @@ pub const RunOptions = struct {
|
|
|
49
56
|
icon_path: []const u8 = "assets/icon.png",
|
|
50
57
|
default_frame: native_sdk.geometry.RectF = native_sdk.geometry.RectF.init(0, 0, 1100, 760),
|
|
51
58
|
restore_state: bool = true,
|
|
59
|
+
restore_policy: native_sdk.WindowRestorePolicy = .clamp_to_visible_screen,
|
|
60
|
+
initial_placement: native_sdk.WindowInitialPlacement = .default,
|
|
52
61
|
bridge: ?native_sdk.BridgeDispatcher = null,
|
|
53
62
|
builtin_bridge: native_sdk.BridgePolicy = .{},
|
|
54
63
|
js_window_api: bool = false,
|
|
@@ -79,6 +88,7 @@ pub const RunOptions = struct {
|
|
|
79
88
|
.description = manifestStringField("description"),
|
|
80
89
|
.has_web_content = manifestHasWebContent(),
|
|
81
90
|
.declares_tray = manifestDeclaresTrayCapability(),
|
|
91
|
+
.dock_visible = manifestDockVisible(),
|
|
82
92
|
.window_title = self.window_title,
|
|
83
93
|
.bundle_id = self.bundle_id,
|
|
84
94
|
.icon_path = self.icon_path,
|
|
@@ -88,6 +98,8 @@ pub const RunOptions = struct {
|
|
|
88
98
|
.title = self.window_title,
|
|
89
99
|
.default_frame = self.default_frame,
|
|
90
100
|
.restore_state = self.restore_state,
|
|
101
|
+
.restore_policy = self.restore_policy,
|
|
102
|
+
.initial_placement = self.initial_placement,
|
|
91
103
|
},
|
|
92
104
|
};
|
|
93
105
|
const windows = manifestWindowOptions(buffers);
|
|
@@ -103,8 +115,12 @@ pub const RunOptions = struct {
|
|
|
103
115
|
// a canvas-first startup window is created ordered-out and
|
|
104
116
|
// shown after its first canvas frame presents, so launch
|
|
105
117
|
// never flashes a blank window.
|
|
118
|
+
info.main_window.default_frame = manifestShellStartupFrame(info.main_window.default_frame);
|
|
119
|
+
info.main_window.restore_state = manifestShellStartupRestoreState(info.main_window.restore_state);
|
|
106
120
|
info.main_window.titlebar = manifestShellStartupTitlebar();
|
|
107
121
|
info.main_window.resizable = manifestShellStartupResizable();
|
|
122
|
+
info.main_window.restore_policy = manifestShellStartupRestorePolicy(info.main_window.restore_policy);
|
|
123
|
+
info.main_window.initial_placement = manifestShellStartupInitialPlacement(info.main_window.initial_placement);
|
|
108
124
|
info.main_window.show = manifestShellStartupShowMode();
|
|
109
125
|
info.main_window.transparent = manifestShellStartupBool("transparent", false);
|
|
110
126
|
info.main_window.always_on_top = manifestShellStartupBool("always_on_top", false);
|
|
@@ -176,6 +192,7 @@ fn manifestWindow(comptime window: anytype, comptime index: usize) native_sdk.Wi
|
|
|
176
192
|
.resizable = windowBool(window, "resizable", true),
|
|
177
193
|
.restore_state = windowBool(window, "restore_state", true),
|
|
178
194
|
.restore_policy = windowRestorePolicy(window),
|
|
195
|
+
.initial_placement = if (windowHasExplicitOrigin(window)) .explicit else .default,
|
|
179
196
|
.titlebar = windowTitlebarStyle(window),
|
|
180
197
|
.show = if (windowBool(window, "initially_hidden", false)) .hidden else .immediate,
|
|
181
198
|
.transparent = windowBool(window, "transparent", false),
|
|
@@ -411,6 +428,60 @@ fn windowRestorePolicy(comptime window: anytype) native_sdk.WindowRestorePolicy
|
|
|
411
428
|
@compileError("unknown app.zon window restore_policy");
|
|
412
429
|
}
|
|
413
430
|
|
|
431
|
+
fn windowHasExplicitOrigin(comptime window: anytype) bool {
|
|
432
|
+
return @hasField(@TypeOf(window), "x") or @hasField(@TypeOf(window), "y");
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/// The host creates the first scene window before the scene loads, so its
|
|
436
|
+
/// authored frame must ride AppInfo with the other creation-time options.
|
|
437
|
+
/// Omitted fields preserve RunOptions' direct-SDK fallback independently.
|
|
438
|
+
fn manifestShellStartupFrame(fallback: native_sdk.geometry.RectF) native_sdk.geometry.RectF {
|
|
439
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
440
|
+
const shell = app_manifest.shell;
|
|
441
|
+
if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
442
|
+
if (comptime shell.windows.len == 0) return fallback;
|
|
443
|
+
const window = shell.windows[0];
|
|
444
|
+
return native_sdk.geometry.RectF.init(
|
|
445
|
+
windowFloatFallback(window, "x", fallback.x),
|
|
446
|
+
windowFloatFallback(window, "y", fallback.y),
|
|
447
|
+
windowFloatFallback(window, "width", fallback.width),
|
|
448
|
+
windowFloatFallback(window, "height", fallback.height),
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
fn windowFloatFallback(comptime window: anytype, comptime field: []const u8, fallback: f32) f32 {
|
|
453
|
+
if (comptime @hasField(@TypeOf(window), field)) return @field(window, field);
|
|
454
|
+
return fallback;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
fn manifestShellStartupRestoreState(fallback: bool) bool {
|
|
458
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
459
|
+
const shell = app_manifest.shell;
|
|
460
|
+
if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
461
|
+
if (comptime shell.windows.len == 0) return fallback;
|
|
462
|
+
const window = shell.windows[0];
|
|
463
|
+
if (comptime @hasField(@TypeOf(window), "restore_state")) return window.restore_state;
|
|
464
|
+
return fallback;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
fn manifestShellStartupRestorePolicy(fallback: native_sdk.WindowRestorePolicy) native_sdk.WindowRestorePolicy {
|
|
468
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
469
|
+
const shell = app_manifest.shell;
|
|
470
|
+
if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
471
|
+
if (comptime shell.windows.len == 0) return fallback;
|
|
472
|
+
const window = shell.windows[0];
|
|
473
|
+
const declared: ?native_sdk.WindowRestorePolicy = if (comptime @hasField(@TypeOf(window), "restore_policy")) windowRestorePolicy(window) else null;
|
|
474
|
+
return window_placement.applyShellRestorePolicy(fallback, declared);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
fn manifestShellStartupInitialPlacement(fallback: native_sdk.WindowInitialPlacement) native_sdk.WindowInitialPlacement {
|
|
478
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
479
|
+
const shell = app_manifest.shell;
|
|
480
|
+
if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
481
|
+
if (comptime shell.windows.len == 0) return fallback;
|
|
482
|
+
return window_placement.applyShellInitialPlacement(fallback, windowHasExplicitOrigin(shell.windows[0]));
|
|
483
|
+
}
|
|
484
|
+
|
|
414
485
|
/// What the window's close affordance does, from app.zon. `.hide` is
|
|
415
486
|
/// validated against the TARGET platform at comptime: a host with no
|
|
416
487
|
/// affordance to bring a hidden window back (GTK has no status item;
|
|
@@ -447,6 +518,17 @@ fn manifestDeclaresTrayCapability() bool {
|
|
|
447
518
|
return false;
|
|
448
519
|
}
|
|
449
520
|
|
|
521
|
+
/// Initial Dock/app-switcher presence. The validation is repeated at
|
|
522
|
+
/// comptime so a custom/ejected build cannot bypass the same safety
|
|
523
|
+
/// rule as `native validate` and strand an accessory app with no tray.
|
|
524
|
+
fn manifestDockVisible() bool {
|
|
525
|
+
const visible = if (comptime @hasField(@TypeOf(app_manifest), "dock_visible")) app_manifest.dock_visible else true;
|
|
526
|
+
if (comptime !visible and !manifestDeclaresTrayCapability()) {
|
|
527
|
+
@compileError("app.zon dock_visible = false requires the \"tray\" capability: an accessory app has no Dock/app-switcher route back to hidden windows - add \"tray\" to .capabilities and install a status item, or keep dock_visible = true (the default)");
|
|
528
|
+
}
|
|
529
|
+
return visible;
|
|
530
|
+
}
|
|
531
|
+
|
|
450
532
|
/// Whether app.zon declares the Tier-2 record store. This is comptime so
|
|
451
533
|
/// apps without the capability never analyze the SQLite open/deinit path.
|
|
452
534
|
fn manifestDeclaresStore() bool {
|
|
@@ -626,6 +708,7 @@ fn runNull(app: native_sdk.App, options: RunOptions, init: std.process.Init) !vo
|
|
|
626
708
|
defer runtime.deinit();
|
|
627
709
|
native_sdk.Runtime.initAt(runtime, .{
|
|
628
710
|
.platform = null_platform.platform(),
|
|
711
|
+
.max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
629
712
|
.trace_sink = runtime_trace_sink,
|
|
630
713
|
.log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
631
714
|
.bridge = options.bridge,
|
|
@@ -694,6 +777,7 @@ fn runMacos(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
694
777
|
defer runtime.deinit();
|
|
695
778
|
native_sdk.Runtime.initAt(runtime, .{
|
|
696
779
|
.platform = mac_platform.platform(),
|
|
780
|
+
.max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
697
781
|
.trace_sink = runtime_trace_sink,
|
|
698
782
|
.log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
699
783
|
.bridge = options.bridge,
|
|
@@ -759,6 +843,7 @@ fn runLinux(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
759
843
|
defer runtime.deinit();
|
|
760
844
|
native_sdk.Runtime.initAt(runtime, .{
|
|
761
845
|
.platform = linux_platform.platform(),
|
|
846
|
+
.max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
762
847
|
.trace_sink = runtime_trace_sink,
|
|
763
848
|
.log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
764
849
|
.bridge = options.bridge,
|
|
@@ -823,6 +908,7 @@ fn runWindows(app: native_sdk.App, options: RunOptions, init: std.process.Init)
|
|
|
823
908
|
defer runtime.deinit();
|
|
824
909
|
native_sdk.Runtime.initAt(runtime, .{
|
|
825
910
|
.platform = windows_platform.platform(),
|
|
911
|
+
.max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
826
912
|
.trace_sink = runtime_trace_sink,
|
|
827
913
|
.log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
828
914
|
.bridge = options.bridge,
|
|
@@ -978,6 +1064,7 @@ fn runSessionReplay(app: native_sdk.App, options: RunOptions, init: std.process.
|
|
|
978
1064
|
// the journal and restores nothing.
|
|
979
1065
|
native_sdk.Runtime.initAt(runtime, .{
|
|
980
1066
|
.platform = replay_platform,
|
|
1067
|
+
.max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
981
1068
|
.bridge = options.bridge,
|
|
982
1069
|
.builtin_bridge = options.builtin_bridge,
|
|
983
1070
|
.js_window_api = options.js_window_api,
|
|
@@ -1069,15 +1156,15 @@ fn prepareStateStore(io: std.Io, env_map: *std.process.Environ.Map, app_info: *n
|
|
|
1069
1156
|
const restored_windows = buffers.restored_windows[0..app_info.windows.len];
|
|
1070
1157
|
for (restored_windows, 0..) |*window, index| {
|
|
1071
1158
|
if (!window.restore_state) continue;
|
|
1072
|
-
if (store.loadWindow(window.label, &buffers.read) catch null)
|
|
1073
|
-
|
|
1074
|
-
|
|
1159
|
+
if (window_placement.applySavedWindow(window, store.loadWindow(window.label, &buffers.read) catch null)) {
|
|
1160
|
+
if (index == 0) {
|
|
1161
|
+
app_info.main_window.default_frame = window.default_frame;
|
|
1162
|
+
app_info.main_window.initial_placement = .restored;
|
|
1163
|
+
}
|
|
1075
1164
|
}
|
|
1076
1165
|
}
|
|
1077
1166
|
} else if (app_info.main_window.restore_state) {
|
|
1078
|
-
|
|
1079
|
-
app_info.main_window.default_frame = saved.frame;
|
|
1080
|
-
}
|
|
1167
|
+
_ = window_placement.applySavedWindow(&app_info.main_window, store.loadWindow(app_info.main_window.label, &buffers.read) catch null);
|
|
1081
1168
|
}
|
|
1082
1169
|
return store;
|
|
1083
1170
|
}
|
|
@@ -399,10 +399,10 @@ const ImageAsset = struct {
|
|
|
399
399
|
path: []const u8,
|
|
400
400
|
};
|
|
401
401
|
|
|
402
|
-
///
|
|
403
|
-
/// entry (the views keep the initials fallback)
|
|
404
|
-
/// launch path hostage to a mis-sized asset.
|
|
405
|
-
const max_boot_image_bytes: usize =
|
|
402
|
+
/// Boot images and runtime image loads share one encoded-source contract:
|
|
403
|
+
/// over-bound files skip their entry (the views keep the initials fallback)
|
|
404
|
+
/// instead of holding the launch path hostage to a mis-sized asset.
|
|
405
|
+
const max_boot_image_bytes: usize = native_sdk.max_effect_image_source_bytes;
|
|
406
406
|
|
|
407
407
|
fn manifestImages() []const ImageAsset {
|
|
408
408
|
comptime {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const native_sdk = @import("native_sdk");
|
|
3
|
+
|
|
4
|
+
/// Apply the state-store lookup result at the one layer that can distinguish
|
|
5
|
+
/// an actual restore from a fresh launch with persistence merely enabled.
|
|
6
|
+
pub fn applySavedWindow(window: *native_sdk.WindowOptions, saved: ?native_sdk.WindowState) bool {
|
|
7
|
+
const state = saved orelse return false;
|
|
8
|
+
window.default_frame = state.frame;
|
|
9
|
+
window.initial_placement = .restored;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/// An omitted shell field must not erase the caller's direct-SDK fallback.
|
|
14
|
+
pub fn applyShellRestorePolicy(fallback: native_sdk.WindowRestorePolicy, declared: ?native_sdk.WindowRestorePolicy) native_sdk.WindowRestorePolicy {
|
|
15
|
+
return declared orelse fallback;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// Only an authored shell origin overrides the caller's placement reason.
|
|
19
|
+
pub fn applyShellInitialPlacement(fallback: native_sdk.WindowInitialPlacement, has_explicit_origin: bool) native_sdk.WindowInitialPlacement {
|
|
20
|
+
return if (has_explicit_origin) .explicit else fallback;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test "fresh default-restoring window keeps default placement on a store miss" {
|
|
24
|
+
var window: native_sdk.WindowOptions = .{ .restore_state = true };
|
|
25
|
+
try std.testing.expect(!applySavedWindow(&window, null));
|
|
26
|
+
try std.testing.expectEqual(native_sdk.WindowInitialPlacement.default, window.initial_placement);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test "fresh explicitly positioned window keeps explicit placement on a store miss" {
|
|
30
|
+
var window: native_sdk.WindowOptions = .{ .initial_placement = .explicit };
|
|
31
|
+
try std.testing.expect(!applySavedWindow(&window, null));
|
|
32
|
+
try std.testing.expectEqual(native_sdk.WindowInitialPlacement.explicit, window.initial_placement);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
test "state-store hit replaces the frame and marks it restored" {
|
|
36
|
+
var window: native_sdk.WindowOptions = .{ .initial_placement = .explicit };
|
|
37
|
+
const frame = native_sdk.geometry.RectF.init(40, 60, 900, 640);
|
|
38
|
+
try std.testing.expect(applySavedWindow(&window, .{ .frame = frame }));
|
|
39
|
+
try std.testing.expectEqual(frame, window.default_frame);
|
|
40
|
+
try std.testing.expectEqual(native_sdk.WindowInitialPlacement.restored, window.initial_placement);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
test "omitted shell placement fields preserve direct runner fallbacks" {
|
|
44
|
+
try std.testing.expectEqual(
|
|
45
|
+
native_sdk.WindowRestorePolicy.center_on_primary,
|
|
46
|
+
applyShellRestorePolicy(.center_on_primary, null),
|
|
47
|
+
);
|
|
48
|
+
try std.testing.expectEqual(
|
|
49
|
+
native_sdk.WindowInitialPlacement.restored,
|
|
50
|
+
applyShellInitialPlacement(.restored, false),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
test "authored shell placement fields override direct runner fallbacks" {
|
|
55
|
+
try std.testing.expectEqual(
|
|
56
|
+
native_sdk.WindowRestorePolicy.clamp_to_visible_screen,
|
|
57
|
+
applyShellRestorePolicy(.center_on_primary, .clamp_to_visible_screen),
|
|
58
|
+
);
|
|
59
|
+
try std.testing.expectEqual(
|
|
60
|
+
native_sdk.WindowInitialPlacement.explicit,
|
|
61
|
+
applyShellInitialPlacement(.restored, true),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -9,7 +9,7 @@ const mobile_build_options = @import("mobile_build_options");
|
|
|
9
9
|
const relational_migrations = @import("relational_migrations");
|
|
10
10
|
|
|
11
11
|
comptime {
|
|
12
|
-
native_sdk.embed.exportMobileCApi(native_sdk.embed.
|
|
12
|
+
native_sdk.embed.exportMobileCApi(native_sdk.embed.UiAppHostWithStorageCredentialsAndImages(
|
|
13
13
|
@import("app"),
|
|
14
14
|
mobile_build_options.store_capability,
|
|
15
15
|
mobile_build_options.relational_capability,
|
|
@@ -18,5 +18,6 @@ comptime {
|
|
|
18
18
|
mobile_build_options.credentials_permission,
|
|
19
19
|
mobile_build_options.filesystem_permission,
|
|
20
20
|
mobile_build_options.credentials_service,
|
|
21
|
+
mobile_build_options.max_image_pixel_bytes,
|
|
21
22
|
));
|
|
22
23
|
}
|
|
@@ -283,6 +283,7 @@ pub fn mobileWidgetRole(role: canvas.WidgetRole) MobileWidgetRole {
|
|
|
283
283
|
.tab => .tab,
|
|
284
284
|
.checkbox => .checkbox,
|
|
285
285
|
.radio => .radio,
|
|
286
|
+
.radiogroup => .radiogroup,
|
|
286
287
|
.switch_control => .switch_control,
|
|
287
288
|
.slider => .slider,
|
|
288
289
|
.progressbar => .progressbar,
|
package/src/embed/host.zig
CHANGED
|
@@ -3,6 +3,7 @@ const geometry = @import("geometry");
|
|
|
3
3
|
const canvas = @import("canvas");
|
|
4
4
|
const app_manifest = @import("app_manifest");
|
|
5
5
|
const runtime = @import("../runtime/root.zig");
|
|
6
|
+
const canvas_limits = @import("../runtime/canvas_limits.zig");
|
|
6
7
|
const platform = @import("../platform/root.zig");
|
|
7
8
|
const automation = @import("../automation/root.zig");
|
|
8
9
|
const types = @import("types.zig");
|
|
@@ -288,17 +289,19 @@ fn MobileImageBridge(comptime Host: type) type {
|
|
|
288
289
|
return @alignCast(@fieldParentPtr("null_platform", null_platform));
|
|
289
290
|
}
|
|
290
291
|
|
|
291
|
-
fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!platform.DecodedImage {
|
|
292
|
+
fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8, max_pixels: usize) anyerror!platform.DecodedImage {
|
|
292
293
|
const image = &hostFromContext(context).image;
|
|
293
294
|
const decode_fn = image.service.decode orelse return error.UnsupportedService;
|
|
294
295
|
var width: usize = 0;
|
|
295
296
|
var height: usize = 0;
|
|
296
|
-
return switch (decode_fn(image.context, bytes.ptr, bytes.len, buffer.ptr, buffer.len, &width, &height)) {
|
|
297
|
+
return switch (decode_fn(image.context, bytes.ptr, bytes.len, buffer.ptr, buffer.len, max_pixels, &width, &height)) {
|
|
297
298
|
1 => {
|
|
298
299
|
if (width == 0 or height == 0) return error.ImageDecodeFailed;
|
|
299
300
|
const row_len = std.math.mul(usize, width, 4) catch return error.ImageDecodeFailed;
|
|
300
301
|
const byte_len = std.math.mul(usize, row_len, height) catch return error.ImageDecodeFailed;
|
|
301
302
|
if (byte_len > buffer.len) return error.ImageDecodeFailed;
|
|
303
|
+
const pixel_count = std.math.mul(usize, width, height) catch return error.ImageDecodeFailed;
|
|
304
|
+
if (pixel_count > max_pixels) return error.ImageTooLarge;
|
|
302
305
|
return .{ .width = width, .height = height, .rgba8 = buffer[0..byte_len] };
|
|
303
306
|
},
|
|
304
307
|
-1 => error.ImageTooLarge,
|
|
@@ -552,8 +555,12 @@ pub const EmbeddedApp = struct {
|
|
|
552
555
|
}
|
|
553
556
|
|
|
554
557
|
pub fn initInPlace(self: *EmbeddedApp, app: runtime.App, platform_value: platform.Platform) void {
|
|
558
|
+
self.initInPlaceWithImageBudget(app, platform_value, canvas_limits.max_registered_canvas_image_pixel_bytes);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
pub fn initInPlaceWithImageBudget(self: *EmbeddedApp, app: runtime.App, platform_value: platform.Platform, max_image_pixel_bytes: usize) void {
|
|
555
562
|
self.app = app;
|
|
556
|
-
runtime.Runtime.initAt(&self.runtime, .{ .platform = platform_value });
|
|
563
|
+
runtime.Runtime.initAt(&self.runtime, .{ .platform = platform_value, .max_image_pixel_bytes = max_image_pixel_bytes });
|
|
557
564
|
}
|
|
558
565
|
|
|
559
566
|
/// End of the embedded lifecycle, symmetric with `init`/`initInPlace`:
|
package/src/embed/root.zig
CHANGED
|
@@ -31,6 +31,7 @@ pub const UiAppHost = ui_host.UiAppHost;
|
|
|
31
31
|
pub const UiAppHostWithRecordStore = ui_host.UiAppHostWithRecordStore;
|
|
32
32
|
pub const UiAppHostWithStorage = ui_host.UiAppHostWithStorage;
|
|
33
33
|
pub const UiAppHostWithStorageAndCredentials = ui_host.UiAppHostWithStorageAndCredentials;
|
|
34
|
+
pub const UiAppHostWithStorageCredentialsAndImages = ui_host.UiAppHostWithStorageCredentialsAndImages;
|
|
34
35
|
pub const mobile_shell_scene = ui_host.mobile_shell_scene;
|
|
35
36
|
pub const MobileCApi = c_api.MobileCApi;
|
|
36
37
|
pub const exportMobileCApi = c_api.exportMobileCApi;
|
package/src/embed/tests.zig
CHANGED
|
@@ -651,6 +651,12 @@ test "mobile C ABI exposes GPU widget accessibility semantics" {
|
|
|
651
651
|
.layout = .{ .gap = 2 },
|
|
652
652
|
.children = &grid_rows,
|
|
653
653
|
},
|
|
654
|
+
.{
|
|
655
|
+
.id = 14,
|
|
656
|
+
.kind = .radio_group,
|
|
657
|
+
.frame = geometry.RectF.init(12, 148, 120, 28),
|
|
658
|
+
.semantics = .{ .label = "Density" },
|
|
659
|
+
},
|
|
654
660
|
};
|
|
655
661
|
var nodes: [16]canvas.WidgetLayoutNode = undefined;
|
|
656
662
|
const layout = try canvas.layoutWidgetTree(.{
|
|
@@ -661,7 +667,7 @@ test "mobile C ABI exposes GPU widget accessibility semantics" {
|
|
|
661
667
|
}, geometry.RectF.init(0, 0, 320, 180), &nodes);
|
|
662
668
|
_ = try self.embedded.runtime.setCanvasWidgetLayout(1, mobile_gpu_surface_label, layout);
|
|
663
669
|
|
|
664
|
-
try std.testing.expectEqual(@as(usize,
|
|
670
|
+
try std.testing.expectEqual(@as(usize, 14), native_sdk_app_widget_semantics_count(app));
|
|
665
671
|
|
|
666
672
|
var root_node: MobileWidgetSemantics = .{};
|
|
667
673
|
try std.testing.expectEqual(@as(c_int, 1), native_sdk_app_widget_semantics_at(app, 0, &root_node));
|
|
@@ -737,6 +743,10 @@ test "mobile C ABI exposes GPU widget accessibility semantics" {
|
|
|
737
743
|
try std.testing.expectEqual(@as(isize, 2), status_cell.grid_column_count);
|
|
738
744
|
try std.testing.expect((status_cell.actions & @intFromEnum(MobileWidgetAction.select)) != 0);
|
|
739
745
|
|
|
746
|
+
const radio_group_node = try mobileWidgetSemanticsByIdForTest(app, 14);
|
|
747
|
+
try std.testing.expectEqual(@intFromEnum(MobileWidgetRole.radiogroup), radio_group_node.role);
|
|
748
|
+
try std.testing.expectEqualStrings("Density", radio_group_node.label.?[0..radio_group_node.label_len]);
|
|
749
|
+
|
|
740
750
|
var text_geometry: MobileWidgetTextGeometry = .{};
|
|
741
751
|
try std.testing.expectEqual(@as(c_int, 1), native_sdk_app_widget_text_geometry(app, 3, &text_geometry));
|
|
742
752
|
try std.testing.expectEqual(@as(u64, 3), text_geometry.id);
|
|
@@ -2266,6 +2276,7 @@ fn recorderImageDecode(
|
|
|
2266
2276
|
bytes_len: usize,
|
|
2267
2277
|
pixels: ?[*]u8,
|
|
2268
2278
|
pixels_len: usize,
|
|
2279
|
+
max_pixels: usize,
|
|
2269
2280
|
out_width: ?*usize,
|
|
2270
2281
|
out_height: ?*usize,
|
|
2271
2282
|
) callconv(.c) c_int {
|
|
@@ -2273,6 +2284,7 @@ fn recorderImageDecode(
|
|
|
2273
2284
|
recorder.decode_count += 1;
|
|
2274
2285
|
recorder.last_bytes_len = conversions.copyInputText(&recorder.last_bytes, if (bytes) |value| value[0..bytes_len] else "");
|
|
2275
2286
|
recorder.last_pixels_len = pixels_len;
|
|
2287
|
+
_ = max_pixels;
|
|
2276
2288
|
if (recorder.result != 1) return recorder.result;
|
|
2277
2289
|
out_width.?.* = recorder.width;
|
|
2278
2290
|
out_height.?.* = recorder.height;
|
package/src/embed/types.zig
CHANGED
|
@@ -28,6 +28,7 @@ pub const MobileWidgetRole = enum(c_int) {
|
|
|
28
28
|
slider = 18,
|
|
29
29
|
progressbar = 19,
|
|
30
30
|
radio = 20,
|
|
31
|
+
radiogroup = 21,
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
pub const MobileWidgetFlag = enum(u32) {
|
|
@@ -345,6 +346,7 @@ pub const MobileImageDecodeFn = *const fn (
|
|
|
345
346
|
bytes_len: usize,
|
|
346
347
|
pixels: ?[*]u8,
|
|
347
348
|
pixels_len: usize,
|
|
349
|
+
max_pixels: usize,
|
|
348
350
|
out_width: ?*usize,
|
|
349
351
|
out_height: ?*usize,
|
|
350
352
|
) callconv(.c) c_int;
|
package/src/embed/ui_host.zig
CHANGED
|
@@ -105,6 +105,30 @@ pub fn UiAppHostWithStorageAndCredentials(
|
|
|
105
105
|
comptime credentials_permitted: bool,
|
|
106
106
|
comptime filesystem_permitted: bool,
|
|
107
107
|
comptime credentials_service: []const u8,
|
|
108
|
+
) type {
|
|
109
|
+
return UiAppHostWithStorageCredentialsAndImages(
|
|
110
|
+
AppDef,
|
|
111
|
+
record_store_enabled,
|
|
112
|
+
relational_store_enabled,
|
|
113
|
+
relational_migrations,
|
|
114
|
+
credentials_enabled,
|
|
115
|
+
credentials_permitted,
|
|
116
|
+
filesystem_permitted,
|
|
117
|
+
credentials_service,
|
|
118
|
+
1024 * 1024,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
pub fn UiAppHostWithStorageCredentialsAndImages(
|
|
123
|
+
comptime AppDef: type,
|
|
124
|
+
comptime record_store_enabled: bool,
|
|
125
|
+
comptime relational_store_enabled: bool,
|
|
126
|
+
comptime relational_migrations: []const runtime.relational_store.Migration,
|
|
127
|
+
comptime credentials_enabled: bool,
|
|
128
|
+
comptime credentials_permitted: bool,
|
|
129
|
+
comptime filesystem_permitted: bool,
|
|
130
|
+
comptime credentials_service: []const u8,
|
|
131
|
+
comptime max_image_pixel_bytes: usize,
|
|
108
132
|
) type {
|
|
109
133
|
const features: runtime.UiAppFeatures = if (@hasDecl(AppDef, "features")) AppDef.features else .{};
|
|
110
134
|
const RecordStoreType = if (record_store_enabled) runtime.RecordStore else void;
|
|
@@ -221,13 +245,13 @@ pub fn UiAppHostWithStorageAndCredentials(
|
|
|
221
245
|
MobileUi.initInPlace(&self.ui, allocator, options);
|
|
222
246
|
self.ui.model = AppDef.initModel();
|
|
223
247
|
self.inner_app = self.ui.app();
|
|
224
|
-
self.embedded.
|
|
248
|
+
self.embedded.initInPlaceWithImageBudget(.{
|
|
225
249
|
.context = self,
|
|
226
250
|
.name = options.name,
|
|
227
251
|
.scene_fn = hostScene,
|
|
228
252
|
.event_fn = hostEvent,
|
|
229
253
|
.stop_fn = hostStop,
|
|
230
|
-
}, self.null_platform.platform());
|
|
254
|
+
}, self.null_platform.platform(), max_image_pixel_bytes);
|
|
231
255
|
// The NullPlatform map is for native test only. Installed mobile
|
|
232
256
|
// apps start with no backing until the UIKit/Android shim
|
|
233
257
|
// registers its OS credential service.
|
|
@@ -116,6 +116,7 @@ import javax.crypto.SecretKey;
|
|
|
116
116
|
import javax.crypto.spec.GCMParameterSpec;
|
|
117
117
|
|
|
118
118
|
public final class NativeSdkActivity extends Activity implements SurfaceHolder.Callback, Choreographer.FrameCallback {
|
|
119
|
+
private static final int MAX_DECODED_IMAGE_DIMENSION = 8192;
|
|
119
120
|
private static final int TOUCH_MODE_IDLE = 0;
|
|
120
121
|
// Touch down seen, under slop: undecided between tap / drag / scroll.
|
|
121
122
|
private static final int TOUCH_MODE_PENDING = 1;
|
|
@@ -578,9 +579,42 @@ public final class NativeSdkActivity extends Activity implements SurfaceHolder.C
|
|
|
578
579
|
// size[0]/size[1]), -1 when the decoded pixels do not fit the buffer,
|
|
579
580
|
// 0 undecodable — the embed image service contract.
|
|
580
581
|
@SuppressWarnings("unused") // called from android_host.c
|
|
581
|
-
int imageDecode(byte[] encoded, ByteBuffer pixels, long[] size) {
|
|
582
|
-
if (encoded == null || encoded.length == 0 || pixels == null || size == null || size.length < 2) return 0;
|
|
582
|
+
int imageDecode(byte[] encoded, ByteBuffer pixels, long maxPixels, long[] size) {
|
|
583
|
+
if (encoded == null || encoded.length == 0 || pixels == null || maxPixels <= 0 || size == null || size.length < 2) return 0;
|
|
583
584
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
585
|
+
options.inJustDecodeBounds = true;
|
|
586
|
+
BitmapFactory.decodeByteArray(encoded, 0, encoded.length, options);
|
|
587
|
+
int sourceWidth = options.outWidth;
|
|
588
|
+
int sourceHeight = options.outHeight;
|
|
589
|
+
if (sourceWidth <= 0 || sourceHeight <= 0) return 0;
|
|
590
|
+
long sourcePixels = (long)sourceWidth * sourceHeight;
|
|
591
|
+
int targetWidth = sourceWidth;
|
|
592
|
+
int targetHeight = sourceHeight;
|
|
593
|
+
if (sourcePixels > maxPixels || sourceWidth > MAX_DECODED_IMAGE_DIMENSION || sourceHeight > MAX_DECODED_IMAGE_DIMENSION) {
|
|
594
|
+
double areaScale = Math.sqrt((double)maxPixels / (double)sourcePixels);
|
|
595
|
+
double axisScale = (double)MAX_DECODED_IMAGE_DIMENSION / Math.max(sourceWidth, sourceHeight);
|
|
596
|
+
double scale = Math.min(1.0, Math.min(areaScale, axisScale));
|
|
597
|
+
targetWidth = Math.max(1, (int)Math.floor(sourceWidth * scale));
|
|
598
|
+
targetHeight = Math.max(1, (int)Math.floor(sourceHeight * scale));
|
|
599
|
+
while ((long)targetWidth * targetHeight > maxPixels) {
|
|
600
|
+
if (targetWidth > 1 && (targetHeight == 1 || targetWidth > targetHeight)) targetWidth--;
|
|
601
|
+
else targetHeight--;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
int sampleSize = 1;
|
|
605
|
+
while (sampleSize <= (1 << 28)) {
|
|
606
|
+
int nextSampleSize = sampleSize << 1;
|
|
607
|
+
// BitmapFactory rounds a sampled dimension up rather than
|
|
608
|
+
// collapsing a one-pixel side to zero. Mirror that here so a
|
|
609
|
+
// panorama can still use the largest safe power-of-two decode
|
|
610
|
+
// sample before the exact resize below.
|
|
611
|
+
int sampledWidth = (sourceWidth - 1) / nextSampleSize + 1;
|
|
612
|
+
int sampledHeight = (sourceHeight - 1) / nextSampleSize + 1;
|
|
613
|
+
if (sampledWidth < targetWidth || sampledHeight < targetHeight) break;
|
|
614
|
+
sampleSize = nextSampleSize;
|
|
615
|
+
}
|
|
616
|
+
options.inJustDecodeBounds = false;
|
|
617
|
+
options.inSampleSize = sampleSize;
|
|
584
618
|
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
|
585
619
|
// Straight alpha, matching the desktop decoders: the canvas
|
|
586
620
|
// pipeline un-premultiplies nothing downstream.
|
|
@@ -603,8 +637,19 @@ public final class NativeSdkActivity extends Activity implements SurfaceHolder.C
|
|
|
603
637
|
}
|
|
604
638
|
long width = bitmap.getWidth();
|
|
605
639
|
long height = bitmap.getHeight();
|
|
606
|
-
|
|
607
|
-
if (width
|
|
640
|
+
if (width <= 0 || height <= 0) return 0;
|
|
641
|
+
if (width != targetWidth || height != targetHeight) {
|
|
642
|
+
Bitmap fitted = Bitmap.createScaledBitmap(bitmap, targetWidth, targetHeight, true);
|
|
643
|
+
bitmap.recycle();
|
|
644
|
+
if (fitted == null) return 0;
|
|
645
|
+
bitmap = fitted;
|
|
646
|
+
width = targetWidth;
|
|
647
|
+
height = targetHeight;
|
|
648
|
+
}
|
|
649
|
+
// Validate the final registered geometry, not BitmapFactory's
|
|
650
|
+
// intermediate power-of-two sample. In particular, 8193x1 must
|
|
651
|
+
// be allowed to reach the exact 8192x1 fit above.
|
|
652
|
+
if (width > MAX_DECODED_IMAGE_DIMENSION || height > MAX_DECODED_IMAGE_DIMENSION || width > maxPixels / height) return 0;
|
|
608
653
|
size[0] = width;
|
|
609
654
|
size[1] = height;
|
|
610
655
|
long byteLen = width * height * 4;
|
|
@@ -801,7 +801,7 @@ JNIEXPORT void JNICALL Java_dev_native_1sdk_host_NativeSdkActivity_nativeSetCred
|
|
|
801
801
|
// Returns 1 decoded (dimensions in out_width/out_height), -1 when the
|
|
802
802
|
// decoded pixels do not fit pixels_len, 0 undecodable — the embed image
|
|
803
803
|
// service contract (native_sdk_app.h).
|
|
804
|
-
static int host_image_decode(void *context, const uint8_t *bytes, uintptr_t bytes_len, uint8_t *pixels, uintptr_t pixels_len, uintptr_t *out_width, uintptr_t *out_height) {
|
|
804
|
+
static int host_image_decode(void *context, const uint8_t *bytes, uintptr_t bytes_len, uint8_t *pixels, uintptr_t pixels_len, uintptr_t max_pixels, uintptr_t *out_width, uintptr_t *out_height) {
|
|
805
805
|
(void)context;
|
|
806
806
|
if (out_width) *out_width = 0;
|
|
807
807
|
if (out_height) *out_height = 0;
|
|
@@ -823,7 +823,7 @@ static int host_image_decode(void *context, const uint8_t *bytes, uintptr_t byte
|
|
|
823
823
|
(*env)->DeleteLocalRef(env, encoded);
|
|
824
824
|
return 0;
|
|
825
825
|
}
|
|
826
|
-
jint result = (*env)->CallIntMethod(env, host_state.image_activity, host_state.image_decode_method, encoded, buffer, dims);
|
|
826
|
+
jint result = (*env)->CallIntMethod(env, host_state.image_activity, host_state.image_decode_method, encoded, buffer, (jlong)max_pixels, dims);
|
|
827
827
|
if ((*env)->ExceptionCheck(env)) {
|
|
828
828
|
(*env)->ExceptionClear(env);
|
|
829
829
|
result = 0;
|
|
@@ -847,7 +847,7 @@ JNIEXPORT void JNICALL Java_dev_native_1sdk_host_NativeSdkActivity_nativeSetImag
|
|
|
847
847
|
if (host_state.image_activity) (*env)->DeleteGlobalRef(env, host_state.image_activity);
|
|
848
848
|
host_state.image_activity = (*env)->NewGlobalRef(env, self);
|
|
849
849
|
jclass cls = (*env)->GetObjectClass(env, self);
|
|
850
|
-
host_state.image_decode_method = (*env)->GetMethodID(env, cls, "imageDecode", "([BLjava/nio/ByteBuffer;[J)I");
|
|
850
|
+
host_state.image_decode_method = (*env)->GetMethodID(env, cls, "imageDecode", "([BLjava/nio/ByteBuffer;J[J)I");
|
|
851
851
|
(*env)->DeleteLocalRef(env, cls);
|
|
852
852
|
if (!host_state.image_activity || !host_state.image_decode_method) {
|
|
853
853
|
NATIVE_SDK_LOGE("image_service registration failed");
|
|
@@ -239,7 +239,7 @@ void native_sdk_app_audio_event(void *app, int kind, uint64_t position_ms, uint6
|
|
|
239
239
|
// declines image decoding honestly and image/avatar widgets keep their
|
|
240
240
|
// fallback.
|
|
241
241
|
typedef struct native_sdk_image_service {
|
|
242
|
-
int (*decode)(void *context, const uint8_t *bytes, uintptr_t bytes_len, uint8_t *pixels, uintptr_t pixels_len, uintptr_t *out_width, uintptr_t *out_height);
|
|
242
|
+
int (*decode)(void *context, const uint8_t *bytes, uintptr_t bytes_len, uint8_t *pixels, uintptr_t pixels_len, uintptr_t max_pixels, uintptr_t *out_width, uintptr_t *out_height);
|
|
243
243
|
} native_sdk_image_service_t;
|
|
244
244
|
int native_sdk_app_set_image_service(void *app, const native_sdk_image_service_t *service, void *context);
|
|
245
245
|
int native_sdk_app_set_automation_dir(void *app, const char *path, uintptr_t len);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#ifndef NATIVE_SDK_APPLE_IMAGE_FIT_H
|
|
2
|
+
#define NATIVE_SDK_APPLE_IMAGE_FIT_H
|
|
3
|
+
|
|
4
|
+
#include <math.h>
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
|
|
7
|
+
#define NATIVE_SDK_MAX_DECODED_IMAGE_DIMENSION 8192
|
|
8
|
+
|
|
9
|
+
/* ImageIO accepts a longest-side bound, then derives and rounds the other
|
|
10
|
+
* side itself. Choose a longest side whose CEILING-rounded companion still
|
|
11
|
+
* fits the caller's area budget, while also constraining pathological source
|
|
12
|
+
* panoramas to the codec seam's decoded-axis ceiling. Keeping this in one C
|
|
13
|
+
* header makes AppKit, CEF, and UIKit share exactly the same contract. */
|
|
14
|
+
static inline size_t native_sdk_apple_image_thumbnail_max_dimension(
|
|
15
|
+
size_t width,
|
|
16
|
+
size_t height,
|
|
17
|
+
size_t max_pixels
|
|
18
|
+
) {
|
|
19
|
+
const size_t major = width > height ? width : height;
|
|
20
|
+
const size_t minor = width < height ? width : height;
|
|
21
|
+
if (major == 0 || minor == 0 || max_pixels == 0) return 0;
|
|
22
|
+
if (major <= max_pixels / minor && major <= NATIVE_SDK_MAX_DECODED_IMAGE_DIMENSION) return major;
|
|
23
|
+
|
|
24
|
+
const double area_scale = sqrt((double)max_pixels / (double)major / (double)minor);
|
|
25
|
+
const double axis_scale = (double)NATIVE_SDK_MAX_DECODED_IMAGE_DIMENSION / (double)major;
|
|
26
|
+
const double scale = fmin(1.0, fmin(area_scale, axis_scale));
|
|
27
|
+
size_t dimension = (size_t)floor((double)major * scale);
|
|
28
|
+
if (dimension < 1) dimension = 1;
|
|
29
|
+
if (dimension > NATIVE_SDK_MAX_DECODED_IMAGE_DIMENSION) dimension = NATIVE_SDK_MAX_DECODED_IMAGE_DIMENSION;
|
|
30
|
+
while (dimension > 1) {
|
|
31
|
+
const size_t minor_ceiling = (size_t)ceill((long double)minor * (long double)dimension / (long double)major);
|
|
32
|
+
if (dimension <= max_pixels / minor_ceiling) break;
|
|
33
|
+
dimension -= 1;
|
|
34
|
+
}
|
|
35
|
+
return dimension;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#endif
|
|
@@ -257,7 +257,7 @@ void native_sdk_app_audio_event(void *app, int kind, uint64_t position_ms, uint6
|
|
|
257
257
|
// declines image decoding honestly and image/avatar widgets keep their
|
|
258
258
|
// fallback.
|
|
259
259
|
typedef struct native_sdk_image_service {
|
|
260
|
-
int (*decode)(void *context, const uint8_t *bytes, uintptr_t bytes_len, uint8_t *pixels, uintptr_t pixels_len, uintptr_t *out_width, uintptr_t *out_height);
|
|
260
|
+
int (*decode)(void *context, const uint8_t *bytes, uintptr_t bytes_len, uint8_t *pixels, uintptr_t pixels_len, uintptr_t max_pixels, uintptr_t *out_width, uintptr_t *out_height);
|
|
261
261
|
} native_sdk_image_service_t;
|
|
262
262
|
int native_sdk_app_set_image_service(void *app, const native_sdk_image_service_t *service, void *context);
|
|
263
263
|
int native_sdk_app_set_automation_dir(void *app, const char *path, uintptr_t len);
|