|
8 | 8 |
|
9 | 9 | namespace flutter { |
10 | 10 |
|
| 11 | +/// Returns true if the surface will be updated as part of the resize process. |
| 12 | +/// |
| 13 | +/// This is called on window resize to determine if the platform thread needs |
| 14 | +/// to be blocked until the frame with the right size has been rendered. It |
| 15 | +/// should be kept in-sync with how the engine deals with a new surface request |
| 16 | +/// as seen in `CreateOrUpdateSurface` in `GPUSurfaceGL`. |
| 17 | +static bool SurfaceWillUpdate(size_t cur_width, |
| 18 | + size_t cur_height, |
| 19 | + size_t target_width, |
| 20 | + size_t target_height) { |
| 21 | + // TODO (https://github.com/flutter/flutter/issues/65061) : Avoid special |
| 22 | + // handling for zero dimensions. |
| 23 | + bool non_zero_dims = target_height > 0 && target_width > 0; |
| 24 | + bool not_same_size = |
| 25 | + (cur_height != target_height) || (cur_width != target_width); |
| 26 | + return non_zero_dims && not_same_size; |
| 27 | +} |
| 28 | + |
11 | 29 | FlutterWindowsView::FlutterWindowsView( |
12 | 30 | std::unique_ptr<WindowBindingHandler> window_binding) { |
13 | 31 | surface_manager_ = std::make_unique<AngleSurfaceManager>(); |
@@ -80,12 +98,18 @@ uint32_t FlutterWindowsView::GetFrameBufferId(size_t width, size_t height) { |
80 | 98 | void FlutterWindowsView::OnWindowSizeChanged(size_t width, size_t height) { |
81 | 99 | // Called on the platform thread. |
82 | 100 | std::unique_lock<std::mutex> lock(resize_mutex_); |
83 | | - resize_status_ = ResizeState::kResizeStarted; |
84 | | - resize_target_width_ = width; |
85 | | - resize_target_height_ = height; |
| 101 | + |
| 102 | + bool surface_will_update = SurfaceWillUpdate( |
| 103 | + resize_target_width_, resize_target_height_, width, height); |
| 104 | + if (surface_will_update) { |
| 105 | + resize_status_ = ResizeState::kResizeStarted; |
| 106 | + resize_target_width_ = width; |
| 107 | + resize_target_height_ = height; |
| 108 | + } |
| 109 | + |
86 | 110 | SendWindowMetrics(width, height, binding_handler_->GetDpiScale()); |
87 | 111 |
|
88 | | - if (width > 0 && height > 0) { |
| 112 | + if (surface_will_update) { |
89 | 113 | // Block the platform thread until: |
90 | 114 | // 1. GetFrameBufferId is called with the right frame size. |
91 | 115 | // 2. Any pending SwapBuffers calls have been invoked. |
|
0 commit comments