0

[aura] Correctly adjust size for GetWindowMask() calculation

This CL ensures HWND size is correctly adjusted by window_enlargement_
in DesktopWindowTreeHostWin::GetWindowMask().

This CL also updates code in DesktopWindowTreeHostWin::GetWindowMask()
that was getting bounds from the hwnd message handler rather than using
the size passed directly from HWNDMessageHandler::ResetWindowRegion().
Logically this is not correct and the mask should be applied with
respect to the hwnd size passed into GetWindowMask().

window_enlargement_ was introduced in 2013 to address graphical
glitches reported on specific AMD graphics drivers for windows smaller
than 64x64. The resulting fix enlarged the backing hwnd of transparent
widgets to 64x64 if required, capturing the offset in
window_enlargement_, resizing as appropriate when interacting with
the hwnd_message_handler.

This specific fix is likely no longer relevant and code can be
simplified by removing this completely.

Before:
https://screenshot.googleplex.com/7R8wM2esPSEdKj5.png

After:
https://screenshot.googleplex.com/7jZ6sepEUXVKrRi.png

Bug: 399737950, 401996981
Change-Id: Ie7b6a7b429d09912bc5ffc9e465a4dc18772f9e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6337512
Reviewed-by: Keren Zhu <kerenzhu@chromium.org>
Commit-Queue: Tom Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1430350}
This commit is contained in:
Thomas Lukaszewicz
2025-03-10 10:54:13 -07:00
committed by Chromium LUCI CQ
parent 96df931a7e
commit da4040d206
3 changed files with 16 additions and 9 deletions

@ -948,11 +948,19 @@ int DesktopWindowTreeHostWin::GetNonClientComponent(
return native_widget_delegate_->GetNonClientComponent(dip_position);
}
void DesktopWindowTreeHostWin::GetWindowMask(const gfx::Size& size,
void DesktopWindowTreeHostWin::GetWindowMask(const gfx::Size& size_px,
SkPath* path) {
// Request the window mask for hwnd of `size_px`. The hwnd size must be
// adjusted by `window_enlargement` to return to the client-expected window
// size (see crbug.com/41047830).
const gfx::Size adjusted_size_in_px =
size_px - gfx::Size(window_enlargement_.x(), window_enlargement_.y());
if (Widget* widget = GetWidget(); widget && widget->non_client_view()) {
widget->non_client_view()->GetWindowMask(
display::win::ScreenWin::ScreenToDIPSize(GetHWND(), size), path);
display::win::ScreenWin::ScreenToDIPSize(GetHWND(),
adjusted_size_in_px),
path);
// Convert path in DIPs to pixels.
if (!path->isEmpty()) {
const float scale =
@ -963,11 +971,8 @@ void DesktopWindowTreeHostWin::GetWindowMask(const gfx::Size& size,
path->transform(matrix);
}
} else if (!window_enlargement_.IsZero()) {
gfx::Rect bounds(WidgetSizeIsClientSize()
? message_handler_->GetClientAreaBoundsInScreen()
: message_handler_->GetWindowBoundsInScreen());
InsetBottomRight(&bounds, window_enlargement_);
path->addRect(SkRect::MakeXYWH(0, 0, bounds.width(), bounds.height()));
path->addRect(SkRect::MakeXYWH(0, 0, adjusted_size_in_px.width(),
adjusted_size_in_px.height()));
}
}

@ -214,7 +214,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin : public DesktopWindowTreeHost,
bool IsModal() const override;
int GetInitialShowState() const override;
int GetNonClientComponent(const gfx::Point& point) const override;
void GetWindowMask(const gfx::Size& size, SkPath* path) override;
void GetWindowMask(const gfx::Size& size_px, SkPath* path) override;
bool GetClientAreaInsets(gfx::Insets* insets,
HMONITOR monitor) const override;
bool GetDwmFrameInsetsInPixels(gfx::Insets* insets) const override;
@ -316,6 +316,8 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin : public DesktopWindowTreeHost,
// Windows are enlarged to be at least 64x64 pixels, so keep track of the
// extra added here.
// TODO(crbug.com/401996981): This is likely no longer necessary and should be
// removed.
gfx::Vector2d window_enlargement_;
// Whether the window close should be converted to a hide, and then actually

@ -84,7 +84,7 @@ class VIEWS_EXPORT HWNDMessageHandlerDelegate {
virtual int GetInitialShowState() const = 0;
virtual int GetNonClientComponent(const gfx::Point& point) const = 0;
virtual void GetWindowMask(const gfx::Size& size, SkPath* mask) = 0;
virtual void GetWindowMask(const gfx::Size& size_px, SkPath* mask) = 0;
// Returns true if the delegate modifies |insets| to define a custom client
// area for the window, false if the default client area should be used. If