Skip to content
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

[windows] Enable smooth resizing on windows #23701

Merged
merged 3 commits into from Jan 19, 2021

Conversation

iskakaushik
Copy link
Contributor

@iskakaushik iskakaushik commented Jan 14, 2021

Brings #22279 up-to date and some minor modifications.

Related Issues

flutter/flutter#44136
flutter/flutter#66475

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

shell/platform/windows/BUILD.gn Outdated Show resolved Hide resolved
shell/platform/windows/flutter_windows_view.h Outdated Show resolved Hide resolved
shell/platform/windows/flutter_windows_view.cc Outdated Show resolved Hide resolved

if (resize_target_width_ == width && resize_target_height_ == height) {
surface_manager_->ResizeSurface(GetRenderTarget(), width, height);
surface_manager_->MakeCurrent();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we actually need these two steps to done within the lock? It's unclear to me if the mutex is also intended to protect the actual buffer swap, or just the ivars.

Relatedly, it would be helpful to annotate all these lock-using methods with the thread we expect them to be called on so it's easier to understand the flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

surface_manager_ methods here don't need to be protected by the mutex, the line immediately after this needs to be protected. That being said having these be protected by the mutex shouldn't cause any contention (for the flow as it stands now) given that all the surface manager methods will be invoked on the raster task runner.

I had a question about validating the task runner, i see this pattern a lot: GetTaskRunner()->RunsTasksOnCurrentThread(), but it looks like in the case of windows the emedding only has a handle to the platform task runner / thread. I added comments to the methods with the task runner they run on, but i suspect theres something better we can do. Any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we only have access to the task runners of threads we provide custom runners for. Comments are fine here; my concern wasn't enforcing invariants, just helping readers understand the threading flow (the assertion version is nice because then you have confidence that the comments aren't out of sync with reality, but I don't think that's a significant concern here.)

Copy link
Contributor

Choose a reason for hiding this comment

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

That being said having these be protected by the mutex shouldn't cause any contention (for the flow as it stands now) given that all the surface manager methods will be invoked on the raster task runner.

Just to make sure I'm understanding: the reason we don't care about the lock blocking the platform thread unnecessarily during these steps is that if this block is running the platform thread is blocked on this whole step completing regardless, right?

It wouldn't hurt to put a comment here to that effect so that it doesn't look like a locking mistake (which tends to be my default concern when I see non-trivial function calls happening inside a lock).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment clarifying that platform thread is blocked for the entirety of the step.

shell/platform/windows/flutter_windows_view.h Outdated Show resolved Hide resolved
Copy link
Contributor

@clarkezone clarkezone left a comment

Choose a reason for hiding this comment

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

LGTM with one suggestion

}

void FlutterWindowsView::OnWindowSizeChanged(size_t width, size_t height) {
// platform task runner
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this comment mean this method must be called from the platform thread? If that is true would be great to flesh out the comment and / or maybe also express this in the header comment for this function since callers (UWP or win32 FlutterWindow implementations) have different UI threading models and that contract may have material impact to their implementations.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1; please use style-conformant (i.e., full-sentence) comments. E.g., "Called on the platform thread."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Converted these to full comments, and also amended the headers.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

LGTM with some small comments.

@@ -98,6 +98,8 @@ source_set("flutter_windows_source") {
"win32_window_proc_delegate_manager.cc",
"win32_window_proc_delegate_manager.h",
]

libs = [ "dwmapi.lib" ]
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this still be in a !winuwp condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in an else block for if (target_os == "winuwp") already.

std::unique_ptr<WindowBindingHandler> window_binding)
: resize_status_(ResizeState::kDone),
resize_target_width_(0),
resize_target_height_(0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Initializer list is an improvement over the previous version, but I was referring to the C++11 feature of giving the initial value in the header where the value is declared: https://abseil.io/tips/61

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 done!

}

void FlutterWindowsView::OnWindowSizeChanged(size_t width, size_t height) {
// platform task runner
Copy link
Contributor

Choose a reason for hiding this comment

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

+1; please use style-conformant (i.e., full-sentence) comments. E.g., "Called on the platform thread."


if (resize_target_width_ == width && resize_target_height_ == height) {
surface_manager_->ResizeSurface(GetRenderTarget(), width, height);
surface_manager_->MakeCurrent();
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we only have access to the task runners of threads we provide custom runners for. Comments are fine here; my concern wasn't enforcing invariants, just helping readers understand the threading flow (the assertion version is nice because then you have confidence that the comments aren't out of sync with reality, but I don't think that's a significant concern here.)

@@ -255,7 +287,27 @@ bool FlutterWindowsView::ClearContext() {
}

bool FlutterWindowsView::SwapBuffers() {
return surface_manager_->SwapBuffers();
// raster task runner
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't necessarily name the specific thread for the raster thread cases since that's up to the engine; instead you could say something like "Called on an engine-controlled (non-platform) thread."

(It's particularly confusing to mention in an embedding built on the API, because the API never mentions the raster thread.)


if (resize_target_width_ == width && resize_target_height_ == height) {
surface_manager_->ResizeSurface(GetRenderTarget(), width, height);
surface_manager_->MakeCurrent();
Copy link
Contributor

Choose a reason for hiding this comment

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

That being said having these be protected by the mutex shouldn't cause any contention (for the flow as it stands now) given that all the surface manager methods will be invoked on the raster task runner.

Just to make sure I'm understanding: the reason we don't care about the lock blocking the platform thread unnecessarily during these steps is that if this block is running the platform thread is blocked on this whole step completing regardless, right?

It wouldn't hurt to put a comment here to that effect so that it doesn't look like a locking mistake (which tends to be my default concern when I see non-trivial function calls happening inside a lock).

@iskakaushik iskakaushik added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jan 19, 2021
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Linux Arm Host Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jan 19, 2021
@iskakaushik iskakaushik merged commit f6162dc into flutter:master Jan 19, 2021
@iskakaushik iskakaushik deleted the windows_resize_fixes branch January 19, 2021 19:17
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Jan 19, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 19, 2021
gspencergoog pushed a commit to gspencergoog/engine that referenced this pull request Jan 20, 2021
hjfreyer pushed a commit to hjfreyer/engine that referenced this pull request Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants