Skip to content

Commit

Permalink
8270874: JFrame paint artifacts when dragged from standard monitor to…
Browse files Browse the repository at this point in the history
… HiDPI monitor

Backport-of: 03473b4c271b2ec7f0ebdb0edabadf7f36816b9d
  • Loading branch information
mrserb committed Dec 29, 2021
1 parent f016e60 commit 493a78a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions src/java.desktop/windows/native/libawt/windows/awt_Component.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -47,6 +47,7 @@
#include "awt_Win32GraphicsDevice.h"
#include "Hashtable.h"
#include "ComCtl32Util.h"
#include "math.h"

#include <Region.h>

Expand Down Expand Up @@ -2234,8 +2235,8 @@ void AwtComponent::PaintUpdateRgn(const RECT *insets)
*/
RECT* r = (RECT*)(buffer + rgndata->rdh.dwSize);
RECT* un[2] = {0, 0};
DWORD i;
for (i = 0; i < rgndata->rdh.nCount; i++, r++) {
DWORD i;
for (i = 0; i < rgndata->rdh.nCount; i++, r++) {
int width = r->right-r->left;
int height = r->bottom-r->top;
if (width > 0 && height > 0) {
Expand All @@ -2247,13 +2248,22 @@ void AwtComponent::PaintUpdateRgn(const RECT *insets)
}
}
}
// The Windows may request to update the small region of pixels that
// cannot be represented in the user's space, in this case, we will
// request to repaint the smallest non-empty bounding box in the user's
// space
int screen = GetScreenImOn();
Devices::InstanceAccess devices;
AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
float scaleX = (device == NULL) ? 1 : device->GetScaleX();
float scaleY = (device == NULL) ? 1 : device->GetScaleY();
for(i = 0; i < 2; i++) {
if (un[i] != 0) {
DoCallback("handleExpose", "(IIII)V",
ScaleDownX(un[i]->left),
ScaleDownY(un[i]->top),
ScaleDownX(un[i]->right - un[i]->left),
ScaleDownY(un[i]->bottom - un[i]->top));
int x1 = floor(un[i]->left / scaleX);
int y1 = floor(un[i]->top / scaleY);
int x2 = ceil(un[i]->right / scaleX);
int y2 = ceil(un[i]->bottom / scaleY);
DoCallback("handleExpose", "(IIII)V", x1, y1, x2 - x1, y2 - y1);
}
}
delete [] buffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import javax.swing.SwingUtilities;

/* @test
* @bug 8147440 8147016
* @bug 8147440 8147016 8270874
* @summary HiDPI (Windows): Swing components have incorrect sizes after
* changing display resolution
* @run main/manual/othervm WindowResizingOnMovingToAnotherDisplay
Expand Down

1 comment on commit 493a78a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.