From ace394727ba248dc8efd394a20ac2b259b6eeeb0 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 27 Jan 2021 09:21:01 -0800 Subject: [PATCH 1/2] [windows] Honor only valid resize requests Fixes: https://github.com/flutter/flutter/issues/74797 --- .../platform/windows/flutter_windows_view.cc | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index 2f3b4c282698c..ff1882e351013 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -8,6 +8,19 @@ namespace flutter { +/// Returns true if the surface will be updated as part of the resize process. +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 +93,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. From 539477459146acc763711651b8ceede77e2ab416 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 27 Jan 2021 16:09:16 -0600 Subject: [PATCH 2/2] Update flutter_windows_view.cc Add more context around resizing. --- shell/platform/windows/flutter_windows_view.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shell/platform/windows/flutter_windows_view.cc b/shell/platform/windows/flutter_windows_view.cc index ff1882e351013..60ac0cb6954bc 100644 --- a/shell/platform/windows/flutter_windows_view.cc +++ b/shell/platform/windows/flutter_windows_view.cc @@ -9,6 +9,11 @@ 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,