From 6e4ab692e71785ae94860e33fcae9ccd51975f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Sharma?= <737941+loic-sharma@users.noreply.github.com> Date: Thu, 21 Dec 2023 13:58:41 -0800 Subject: [PATCH] [Windows] Fix incorrect surface manager comment (flutter/engine#49335) https://github.com/flutter/engine/pull/24428 attempted to make surface resizing less expensive by using ANGLE's automatic resizing instead of manually destroying and then re-creating the surface. This caused some issues: 1. Flutter's surface size synchronization logic broke: https://github.com/flutter/engine/pull/24682 2. Resizing frameless windows caused the content to wiggle: https://github.com/flutter/flutter/issues/76465 The second issue caused the automatic resizing change to be reverted. However, the first fix was not reverted resulting in an incorrect comment. Relanding this resizing performance improvement is tracked by https://github.com/flutter/flutter/issues/79427 --- .../shell/platform/windows/angle_surface_manager.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/windows/angle_surface_manager.cc b/engine/src/flutter/shell/platform/windows/angle_surface_manager.cc index 6d972ae723..9d5a9ed2b3 100644 --- a/engine/src/flutter/shell/platform/windows/angle_surface_manager.cc +++ b/engine/src/flutter/shell/platform/windows/angle_surface_manager.cc @@ -238,6 +238,9 @@ bool AngleSurfaceManager::CreateSurface(WindowsRenderTarget* render_target, EGLSurface surface = EGL_NO_SURFACE; + // Disable ANGLE's automatic surface resizing and provide an explicit size. + // The surface will need to be destroyed and re-created if the HWND is + // resized. const EGLint surfaceAttributes[] = { EGL_FIXED_SIZE_ANGLE, EGL_TRUE, EGL_WIDTH, width, EGL_HEIGHT, height, EGL_NONE}; @@ -267,6 +270,9 @@ void AngleSurfaceManager::ResizeSurface(WindowsRenderTarget* render_target, surface_width_ = width; surface_height_ = height; + // TODO: Destroying the surface and re-creating it is expensive. + // Ideally this would use ANGLE's automatic surface sizing instead. + // See: https://github.com/flutter/flutter/issues/79427 ClearContext(); DestroySurface(); if (!CreateSurface(render_target, width, height)) { @@ -285,9 +291,10 @@ void AngleSurfaceManager::GetSurfaceDimensions(EGLint* width, EGLint* height) { return; } - // Can't use eglQuerySurface here; Because we're not using - // EGL_FIXED_SIZE_ANGLE flag anymore, Angle may resize the surface before - // Flutter asks it to, which breaks resize redraw synchronization + // This avoids eglQuerySurface as ideally surfaces would be automatically + // sized by ANGLE to avoid expensive surface destroy & re-create. With + // automatic sizing, ANGLE could resize the surface before Flutter asks it to, + // which would break resize redraw synchronization. *width = surface_width_; *height = surface_height_; }