Skip to content

Enable support for dynamic view resizing #169605

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cbracken
Copy link
Member

@cbracken cbracken commented May 28, 2025

This enables support for dynamic view resizing in non-web embedders. While this patch enables support and exposes API for dynamic view resizing in non-web embedders and in the embedder API, it does not implement support in any embedder.

This feature is restricted to embedders with merged UI and platform thread due to the need to inform the embedder of the updated view size synchronously with presenting the content. With some effort, we could implement synchronisation logic that supports non-thread-merged embedders. See ResizeSynchronizer in the macOS embedder for details of what's involved.

When Flutter applications call FlutterView.render with a non-null size parameter, the size will be compared to the existing view size (if any), and if different, a call to PlatformView::ResizeView will be triggered. Embedders can respond to this call by resizing the underlying platform-specific FlutterView to the appropriate size.

Extracts a resize_view_callback to the embedder API that custom embedders can register to receive the updated size from the engine, and adapt their views accordingly.

Related patches:

Issue: #169147
Issue: #149033

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added platform-android Android applications specifically platform-ios iOS applications specifically engine flutter/engine repository. See also e: labels. labels May 28, 2025
@cbracken cbracken requested review from mboetger and LouiseHsu May 28, 2025 17:54
@cbracken
Copy link
Member Author

Just as a heads-up; this will NOT be submitted until @mboetger and/or @LouiseHsu have verified that this works for them in iOS/Android embedders.

@@ -32,6 +32,8 @@ class RuntimeDelegate {
std::unique_ptr<flutter::LayerTree> layer_tree,
float device_pixel_ratio) = 0;

virtual void ResizeView(int64_t view_id, double width, double height) = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider returning bool instead to indicate whether the platform could actually resize the view. The default could just return false. Then the runtime controller can log when the result is false saying something like "Could not resize platform view.". You can do thread checks on platforms that don't support off main thread resizes and the threads haven't been merged.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I like it! Will do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like keeping the thread checks in the respective platform implementations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we merge the resize view callback with the present view callback, FlutterCompositor.present_view_callback, the engine should assume the resize operation failed if the present view callback returns false.

@@ -432,6 +432,10 @@ void RuntimeController::Render(int64_t view_id,
if (view_metrics == nullptr) {
return;
}
if (width != view_metrics->physical_width ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have a NearEqual since we are doing floating point comparisons?

@@ -1725,6 +1725,11 @@ typedef void (*FlutterViewFocusChangeRequestCallback)(
const FlutterViewFocusChangeRequest* /* request */,
void* /* user data */);

typedef void (*FlutterResizeViewCallback)(int64_t /* view ID */,
double /* physical_width */,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: FlutterSize instead?

void Shell::OnEngineResizeView(int64_t view_id, double width, double height) {
FML_DCHECK(is_set_up_);

if (!task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread()) {
Copy link
Member

@chinmaygarde chinmaygarde May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer removing this. The engine shouldn't care if the platform supports off main thread merges. Fuchsia for instance does support it. An embedder could too. Each embedder should have this check though (when they don't support it).

@chinmaygarde
Copy link
Member

Barring the engine having an opinion about the platforms support for off-main-thread platform view resizes (it should not), everything else lgtm.

This enables support for dynamic view resizing in non-web embedders.
While this patch enables support and exposes API for dynamic view
resizing in non-web embedders and in the embedder API, it does not
*implement* support in any embedder.

This feature is restricted to embedders with merged UI and platform
thread due to the need to inform the embedder of the updated view size
synchronously with presenting the content. With some effort, we could
implement synchronisation logic that supports non-thread-merged
embedders. See ResizeSynchronizer in the macOS embedder for details of
what's involved.

When Flutter applications call `FlutterView.render` with a non-null
`size` parameter, the size will be compared to the existing view size
(if any), and if different, a call to `PlatformView::ResizeView` will be
triggered. Embedders can respond to this call by resizing the underlying
platform-specific FlutterView to the appropriate size.

Extracts a resize_view_callback to the embedder API that custom
embedders can register to receive the updated size from the engine, and
adapt their views accordingly.

Related patches:
* `dart:ui`: flutter/engine#48090
* framework: flutter#138648
* framework reland: flutter#140918
* Web: flutter/engine#50271

Issue: flutter#169147
Issue: flutter#149033
@cbracken cbracken force-pushed the wire-up-resize-view branch 2 times, most recently from 40f6719 to a444434 Compare May 29, 2025 17:14
@github-actions github-actions bot removed the platform-ios iOS applications specifically label May 29, 2025
@chinmaygarde
Copy link
Member

Whats the progress on this?

Copy link
Contributor

@mboetger mboetger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting on updates from feedback based on offline conversation with Loic...

@chinmaygarde
Copy link
Member

Sounds good. Consider making this a draft so triagers leave this alone maybe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine flutter/engine repository. See also e: labels. platform-android Android applications specifically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants