diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index 2f3b4c282698c..60ac0cb6954bc 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -8,6 +8,24 @@ namespace flutter { +/// Returns true if the surface will be updated as part of the resize process. +/// +/// This is called on window resize to determine if the platform thread needs +/// to be blocked until the frame with the right size has been rendered. It +/// should be kept in-sync with how the engine deals with a new surface request +/// as seen in `CreateOrUpdateSurface` in `GPUSurfaceGL`. +static bool SurfaceWillUpdate(size_t cur_width, + size_t cur_height, + size_t target_width, + size_t target_height) { + // TODO (https://github.com/flutter/flutter/issues/65061) : Avoid special + // handling for zero dimensions. + bool non_zero_dims = target_height > 0 && target_width > 0; + bool not_same_size = + (cur_height != target_height) || (cur_width != target_width); + return non_zero_dims && not_same_size; +} + FlutterWindowsView::FlutterWindowsView( std::unique_ptr window_binding) { surface_manager_ = std::make_unique(); @@ -80,12 +98,18 @@ uint32_t FlutterWindowsView::GetFrameBufferId(size_t width, size_t height) { void FlutterWindowsView::OnWindowSizeChanged(size_t width, size_t height) { // Called on the platform thread. std::unique_lock lock(resize_mutex_); - resize_status_ = ResizeState::kResizeStarted; - resize_target_width_ = width; - resize_target_height_ = height; + + bool surface_will_update = SurfaceWillUpdate( + resize_target_width_, resize_target_height_, width, height); + if (surface_will_update) { + resize_status_ = ResizeState::kResizeStarted; + resize_target_width_ = width; + resize_target_height_ = height; + } + SendWindowMetrics(width, height, binding_handler_->GetDpiScale()); - if (width > 0 && height > 0) { + if (surface_will_update) { // Block the platform thread until: // 1. GetFrameBufferId is called with the right frame size. // 2. Any pending SwapBuffers calls have been invoked.