-
-
Notifications
You must be signed in to change notification settings - Fork 133
feat(ui): BloomView — embed the Bloom engine in a Perry UI app (#2395) #5518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9252b8f
feat(ui): BloomView — embed an external GPU renderer (Bloom engine) i…
f4c42d4
fix(ui): regen API docs for BloomView + harden bloomview Win32 calls
bbf9120
feat(ui): wire BloomView across all platform UI backends (#2395)
2bb5a59
fix(ui): address CodeRabbit review on cross-platform BloomView
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //! BloomView — a native render-surface host widget (issue #2395). | ||
| //! | ||
| //! Reserves a bare `android.view.View` in the Perry UI view tree for an external | ||
| //! GPU renderer (e.g. the Bloom engine) to draw into. Perry UI only owns the | ||
| //! view; user TypeScript drives the renderer. Mirrors the Windows implementation | ||
| //! conceptually — Android has no HWND, so `bloomViewGetHwnd` echoes the registry | ||
| //! handle as a stable token (a real `SurfaceView`/`TextureView` + JNI surface | ||
| //! bridge is the follow-up for live embedding). | ||
|
|
||
| use crate::jni_bridge; | ||
| use jni::objects::JValue; | ||
|
|
||
| /// Create a BloomView host. Returns the widget handle, or 0 on JNI failure. | ||
| pub fn create(_width: f64, _height: f64) -> i64 { | ||
| let mut env = jni_bridge::get_env(); | ||
| let _ = env.push_local_frame(8); | ||
|
|
||
| let activity = super::get_activity(&mut env); | ||
| let view = match env.new_object( | ||
| "android/view/View", | ||
| "(Landroid/content/Context;)V", | ||
| &[JValue::Object(&activity)], | ||
| ) { | ||
| Ok(v) => v, | ||
| Err(_) => { | ||
| unsafe { | ||
| let _ = env.pop_local_frame(&jni::objects::JObject::null()); | ||
| } | ||
| return 0; | ||
| } | ||
| }; | ||
|
|
||
| let global_ref = match env.new_global_ref(&view) { | ||
| Ok(g) => g, | ||
| Err(_) => { | ||
| unsafe { | ||
| let _ = env.pop_local_frame(&jni::objects::JObject::null()); | ||
| } | ||
| return 0; | ||
| } | ||
| }; | ||
| unsafe { | ||
| let _ = env.pop_local_frame(&jni::objects::JObject::null()); | ||
| } | ||
|
|
||
| super::register_widget(global_ref) | ||
| } | ||
|
|
||
| /// Android has no HWND; echo the registry handle as a stable token for the | ||
| /// caller — but validate it first (return 0 for an unknown/stale handle), so | ||
| /// downstream renderers never treat a bogus handle as attachable. | ||
| pub fn get_native_handle(handle: i64) -> i64 { | ||
| match super::get_widget(handle) { | ||
| Some(_) => handle, | ||
| None => 0, | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| pub mod attributed_text; | ||
| pub mod bloomview; | ||
| pub mod bottom_nav; | ||
| pub mod button; | ||
| pub mod calendar; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| //! BloomView — a native render-surface host widget (issue #2395). | ||
| //! | ||
| //! Reserves a `GtkDrawingArea` in the Perry UI view tree for an external GPU | ||
| //! renderer (e.g. the Bloom engine) to draw into. Perry UI only owns the widget | ||
| //! and exposes its `GtkWidget*` via `bloomViewGetHwnd`; user TypeScript hands | ||
| //! that to the renderer, which targets the widget's surface (the issue's MVP | ||
| //! used GTK4 + Vulkan dmabuf). Mirrors the Windows implementation, with the | ||
| //! HWND replaced by the raw `GtkWidget*`. | ||
|
|
||
| use gtk4::prelude::*; | ||
|
|
||
| /// Create a BloomView host. Reserves the requested size, or expands to fill if | ||
| /// none is given. Returns the widget handle. | ||
| pub fn create(width: f64, height: f64) -> i64 { | ||
| crate::app::ensure_gtk_init(); | ||
| let area = gtk4::DrawingArea::new(); | ||
| // Only honor finite, sensibly-bounded sizes — NaN/inf or sub-pixel | ||
| // fractions would produce a bogus GTK size request. Otherwise expand. | ||
| if width.is_finite() && height.is_finite() && width >= 1.0 && height >= 1.0 { | ||
| let w = (width as i32).clamp(1, 16384); | ||
| let h = (height as i32).clamp(1, 16384); | ||
| area.set_size_request(w, h); | ||
| } else { | ||
| area.set_hexpand(true); | ||
| area.set_vexpand(true); | ||
| } | ||
| super::register_widget(area.upcast()) | ||
| } | ||
|
|
||
| /// Return the raw `GtkWidget*` for a BloomView handle as an integer, for handing | ||
| /// to an external GPU renderer. Returns 0 if the handle is unknown. | ||
| pub fn get_native_handle(handle: i64) -> i64 { | ||
| use gtk4::glib::translate::ToGlibPtr; | ||
| match super::get_widget(handle) { | ||
| Some(w) => { | ||
| let ptr: *mut gtk4::ffi::GtkWidget = w.to_glib_none().0; | ||
| ptr as i64 | ||
| } | ||
| None => 0, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| pub mod attributed_text; | ||
| pub mod bloomview; | ||
| pub mod bottom_nav; | ||
| pub mod button; | ||
| pub mod calendar; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //! BloomView — a native render-surface host widget (issue #2395). | ||
| //! | ||
| //! Reserves a bare `UIView` in the Perry UI view tree for an external GPU | ||
| //! renderer (e.g. the Bloom engine) to draw into. Perry UI only owns the view | ||
| //! and exposes its pointer via `bloomViewGetHwnd`; user TypeScript hands that | ||
| //! pointer to the renderer, which builds its (Metal) surface on it. Mirrors the | ||
| //! Windows implementation, with the HWND replaced by the raw `UIView*`. | ||
|
|
||
| use objc2::msg_send; | ||
| use objc2::rc::Retained; | ||
| use objc2::runtime::AnyClass; | ||
| use objc2_foundation::MainThreadMarker; | ||
| use objc2_ui_kit::UIView; | ||
|
|
||
| /// Create a BloomView host. `width`/`height` are advisory — the layout engine | ||
| /// sizes the view. Returns the widget handle (0 if called off the main thread). | ||
| pub fn create(width: f64, height: f64) -> i64 { | ||
| let _ = (width, height); | ||
| // UIKit views must be created on the main thread; don't panic across the | ||
| // FFI boundary if that contract is violated — return an invalid handle. | ||
| let Some(_mtm) = MainThreadMarker::new() else { | ||
| return 0; | ||
| }; | ||
| unsafe { | ||
| let view: Retained<UIView> = msg_send![AnyClass::get(c"UIView").unwrap(), new]; | ||
| super::register_widget(view) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| /// Return the raw `UIView*` for a BloomView handle as an integer, for handing | ||
| /// to an external GPU renderer. Returns 0 if the handle is unknown. The | ||
| /// registry retains the view; the returned pointer is non-owning. | ||
| pub fn get_native_handle(handle: i64) -> i64 { | ||
| match super::get_widget(handle) { | ||
| Some(view) => Retained::as_ptr(&view) as i64, | ||
| None => 0, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //! BloomView — a native render-surface host widget (issue #2395). | ||
| //! | ||
| //! Reserves a bare `NSView` in the Perry UI view tree for an external GPU | ||
| //! renderer (e.g. the Bloom engine) to draw into. Perry UI only owns the view | ||
| //! and exposes its pointer via `bloomViewGetHwnd`; user TypeScript hands that | ||
| //! pointer to the renderer, which builds its (Metal) surface on it. Mirrors the | ||
| //! Windows implementation (`perry-ui-windows`), with the HWND replaced by the | ||
| //! raw `NSView*`. | ||
|
|
||
| use objc2_app_kit::NSView; | ||
| use objc2_foundation::MainThreadMarker; | ||
|
|
||
| /// Create a BloomView host. `width`/`height` are advisory — the layout engine | ||
| /// sizes the view. Returns the widget handle. | ||
| pub fn create(width: f64, height: f64) -> i64 { | ||
| let _ = (width, height); | ||
| // Public C ABI entry — don't panic across the FFI boundary if called off | ||
| // the main thread; return an invalid (0) handle instead. | ||
| let Some(mtm) = MainThreadMarker::new() else { | ||
| return 0; | ||
| }; | ||
| let view = NSView::new(mtm); | ||
| super::register_widget(view) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /// Return the raw `NSView*` for a BloomView handle as an integer, for handing | ||
| /// to an external GPU renderer. Returns 0 if the handle is unknown. The | ||
| /// registry retains the view; the returned pointer is non-owning. | ||
| pub fn get_native_handle(handle: i64) -> i64 { | ||
| match super::get_widget(handle) { | ||
| Some(view) => objc2::rc::Retained::as_ptr(&view) as i64, | ||
| None => 0, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50369
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 2237
Apply the requested BloomView size on Android.
BloomView(width, height)receives dimensions, but Android drops both values before registering a plainView. Unless another Android layout layer applies these dimensions, this can reserve a zero/default-sized host while GTK/web peers size their render surfaces.Possible localized fix direction
🤖 Prompt for AI Agents