-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fixes high DPI compatibility on Windows platform #19133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3.8.8
Are you sure you want to change the base?
Changes from 3 commits
3ff98ad
27daae8
b5dac29
31a930a
59ef482
7990980
cb0b313
c3f7f8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,19 +31,26 @@ | |||||||||||||
| namespace cc { | ||||||||||||||
|
|
||||||||||||||
| int Screen::getDPI() const { | ||||||||||||||
| // 参考:https://learn.microsoft.com/zh-cn/windows/win32/api/wingdi/nf-wingdi-getdevicecaps | ||||||||||||||
| static int dpi = -1; | ||||||||||||||
| if (dpi == -1) { | ||||||||||||||
|
|
||||||||||||||
| dpi = 96; | ||||||||||||||
| HDC hScreenDC = GetDC(nullptr); | ||||||||||||||
| int PixelsX = GetDeviceCaps(hScreenDC, HORZRES); | ||||||||||||||
| int MMX = GetDeviceCaps(hScreenDC, HORZSIZE); | ||||||||||||||
| ReleaseDC(nullptr, hScreenDC); | ||||||||||||||
| dpi = static_cast<int>(254.0f * PixelsX / MMX / 10); | ||||||||||||||
| if (hScreenDC) { | ||||||||||||||
| // LOGPIXELSX 对应水平方向每逻辑英寸的像素点数 | ||||||||||||||
| dpi = GetDeviceCaps(hScreenDC, LOGPIXELSX); | ||||||||||||||
| ReleaseDC(nullptr, hScreenDC); | ||||||||||||||
| } | ||||||||||||||
| // win10 1607 以上 | ||||||||||||||
| // HWND hDesktop = GetDesktopWindow(); | ||||||||||||||
| // dpi = GetDpiForWindow(hDesktop); | ||||||||||||||
|
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented code or convert to a version-detection strategy if
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: native/cocos/platform/win32/modules/Screen.cpp
Line: 45:47
Comment:
Remove commented code or convert to a version-detection strategy if `GetDpiForWindow` is needed for Windows 10 1607+.
```suggestion
// Note: GetDpiForWindow is available on Windows 10 1607+ and provides per-window DPI
// but requires runtime OS version detection. Current implementation uses GetDeviceCaps
// for broader compatibility.
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented code - it creates clutter and is tracked in version control history if needed Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: native/cocos/platform/win32/modules/Screen.cpp
Line: 45:47
Comment:
Remove commented code - it creates clutter and is tracked in version control history if needed
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||
| } | ||||||||||||||
| return dpi; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| float Screen::getDevicePixelRatio() const { | ||||||||||||||
| return 1; | ||||||||||||||
| return getDPI() / 96.0f; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| void Screen::setKeepScreenOn(bool value) { | ||||||||||||||
|
|
@@ -73,4 +80,4 @@ void Screen::setDisplayStats(bool isShow) { | |||||||||||||
| se::ScriptEngine::getInstance()->evalString(commandBuf); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| } // namespace cc | ||||||||||||||
| } // namespace cc | ||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -116,7 +116,10 @@ export class MouseInputSource { | |||||||||||
| private _getLocation (event: jsb.MouseEvent): Vec2 { | ||||||||||||
| const window = this._windowManager.getWindow(event.windowId); | ||||||||||||
| const windowSize = window.getViewSize(); | ||||||||||||
| const dpr = screenAdapter.devicePixelRatio; | ||||||||||||
| let dpr = screenAdapter.devicePixelRatio; | ||||||||||||
| if (systemInfo.os === OS.WINDOWS) { // 在windows下DPI变化时下发的是实际坐标 | ||||||||||||
| dpr = 1; | ||||||||||||
|
Comment on lines
+120
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Touch input in
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: pal/input/native/mouse-input.ts
Line: 120:121
Comment:
**logic:** Touch input in `touch-input.ts` doesn't have the same Windows-specific DPR handling. Touch coordinates will be incorrectly scaled by DPR on Windows while mouse coordinates won't, causing inconsistent behavior.
```suggestion
if (systemInfo.os === OS.WINDOWS) {
dpr = 1; // Native Windows coordinates are already in physical pixels after DPI awareness is enabled
}
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||
| } | ||||||||||||
| const x = event.x * dpr; | ||||||||||||
| const y = windowSize.height - event.y * dpr; | ||||||||||||
| return new Vec2(x, y); | ||||||||||||
|
|
@@ -187,7 +190,10 @@ export class MouseInputSource { | |||||||||||
| const eventMouse = new EventMouse(eventType, false, this._preMousePos, mouseEvent.windowId); | ||||||||||||
| eventMouse.setLocation(location.x, location.y); | ||||||||||||
| eventMouse.setButton(button); | ||||||||||||
| const dpr = screenAdapter.devicePixelRatio; | ||||||||||||
| let dpr = screenAdapter.devicePixelRatio; | ||||||||||||
| if (systemInfo.os === OS.WINDOWS) { // 在windows下DPI变化时下发的是实际坐标 | ||||||||||||
| dpr = 1; | ||||||||||||
| } | ||||||||||||
|
Comment on lines
+194
to
+196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Duplicated DPR adjustment logic - consider extracting to a helper method to avoid duplication and potential inconsistency Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: pal/input/native/mouse-input.ts
Line: 194:196
Comment:
**style:** Duplicated DPR adjustment logic - consider extracting to a helper method to avoid duplication and potential inconsistency
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||
| eventMouse.movementX = typeof mouseEvent.xDelta === 'undefined' ? 0 : mouseEvent.xDelta * dpr; | ||||||||||||
| eventMouse.movementY = typeof mouseEvent.yDelta === 'undefined' ? 0 : mouseEvent.yDelta * dpr; | ||||||||||||
| // update previous mouse position. | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Remove or document this commented alternative implementation. If
GetDpiForWindowis preferred for Windows 10 1607+, consider implementing version detection and using the appropriate API.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI