Skip to content

Commit 493a78a

Browse files
committedDec 29, 2021
8270874: JFrame paint artifacts when dragged from standard monitor to HiDPI monitor
Backport-of: 03473b4c271b2ec7f0ebdb0edabadf7f36816b9d
1 parent f016e60 commit 493a78a

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed
 

‎src/java.desktop/windows/native/libawt/windows/awt_Component.cpp

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -47,6 +47,7 @@
4747
#include "awt_Win32GraphicsDevice.h"
4848
#include "Hashtable.h"
4949
#include "ComCtl32Util.h"
50+
#include "math.h"
5051

5152
#include <Region.h>
5253

@@ -2234,8 +2235,8 @@ void AwtComponent::PaintUpdateRgn(const RECT *insets)
22342235
*/
22352236
RECT* r = (RECT*)(buffer + rgndata->rdh.dwSize);
22362237
RECT* un[2] = {0, 0};
2237-
DWORD i;
2238-
for (i = 0; i < rgndata->rdh.nCount; i++, r++) {
2238+
DWORD i;
2239+
for (i = 0; i < rgndata->rdh.nCount; i++, r++) {
22392240
int width = r->right-r->left;
22402241
int height = r->bottom-r->top;
22412242
if (width > 0 && height > 0) {
@@ -2247,13 +2248,22 @@ void AwtComponent::PaintUpdateRgn(const RECT *insets)
22472248
}
22482249
}
22492250
}
2251+
// The Windows may request to update the small region of pixels that
2252+
// cannot be represented in the user's space, in this case, we will
2253+
// request to repaint the smallest non-empty bounding box in the user's
2254+
// space
2255+
int screen = GetScreenImOn();
2256+
Devices::InstanceAccess devices;
2257+
AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
2258+
float scaleX = (device == NULL) ? 1 : device->GetScaleX();
2259+
float scaleY = (device == NULL) ? 1 : device->GetScaleY();
22502260
for(i = 0; i < 2; i++) {
22512261
if (un[i] != 0) {
2252-
DoCallback("handleExpose", "(IIII)V",
2253-
ScaleDownX(un[i]->left),
2254-
ScaleDownY(un[i]->top),
2255-
ScaleDownX(un[i]->right - un[i]->left),
2256-
ScaleDownY(un[i]->bottom - un[i]->top));
2262+
int x1 = floor(un[i]->left / scaleX);
2263+
int y1 = floor(un[i]->top / scaleY);
2264+
int x2 = ceil(un[i]->right / scaleX);
2265+
int y2 = ceil(un[i]->bottom / scaleY);
2266+
DoCallback("handleExpose", "(IIII)V", x1, y1, x2 - x1, y2 - y1);
22572267
}
22582268
}
22592269
delete [] buffer;

‎test/jdk/java/awt/Window/WindowResizingOnDPIChanging/WindowResizingOnMovingToAnotherDisplay.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import javax.swing.SwingUtilities;
5454

5555
/* @test
56-
* @bug 8147440 8147016
56+
* @bug 8147440 8147016 8270874
5757
* @summary HiDPI (Windows): Swing components have incorrect sizes after
5858
* changing display resolution
5959
* @run main/manual/othervm WindowResizingOnMovingToAnotherDisplay

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Dec 29, 2021

@openjdk-notifier[bot]
Please sign in to comment.