RESOLVED FIXED Bug 146335
[Win] Implement High DPI support features for non-layer drawing
https://bugs.webkit.org/show_bug.cgi?id=146335
Summary [Win] Implement High DPI support features for non-layer drawing
Brent Fulgham
Reported 2015-06-25 18:29:25 PDT
Extend the existing Windows High DPI features so that we satisfy the elements discussed in the MSDN article <https://msdn.microsoft.com/en-us/library/windows/desktop/dd464659(v=vs.85).aspx>. Specifically: 1. Listen for WM_DPICHANGED messages and react accordingly. 2. Check for Windows 8.1 High DPI features, linking to them dynamically so we still run on Windows 7 and Windows 8. 3. Set the correct Process DPI Awareness in our test applications to avoid scaling behavior.
Attachments
WIP Patch (28.93 KB, patch)
2015-06-27 15:02 PDT, Brent Fulgham
no flags
WIP Do NOT REVIEW! (31.66 KB, patch)
2015-07-01 12:11 PDT, Brent Fulgham
no flags
Patch (30.09 KB, patch)
2015-07-16 16:24 PDT, Brent Fulgham
no flags
Patch (41.34 KB, patch)
2015-07-21 17:38 PDT, Brent Fulgham
no flags
Patch (35.03 KB, patch)
2015-07-21 18:38 PDT, Brent Fulgham
no flags
Patch (38.96 KB, patch)
2015-07-22 09:27 PDT, Brent Fulgham
no flags
Patch (34.61 KB, patch)
2015-07-22 09:53 PDT, Brent Fulgham
no flags
Patch (39.30 KB, patch)
2015-07-22 13:38 PDT, Brent Fulgham
no flags
Patch (45.92 KB, patch)
2015-07-22 17:22 PDT, Brent Fulgham
no flags
Patch (49.48 KB, patch)
2015-07-22 22:06 PDT, Brent Fulgham
achristensen: review+
Radar WebKit Bug Importer
Comment 1 2015-06-25 18:29:49 PDT
Brent Fulgham
Comment 2 2015-06-27 15:02:04 PDT
Created attachment 255708 [details] WIP Patch
Brent Fulgham
Comment 3 2015-06-27 15:02:33 PDT
Comment on attachment 255708 [details] WIP Patch Works, except for layer-backed content.
WebKit Commit Bot
Comment 4 2015-06-27 15:03:34 PDT
Attachment 255708 [details] did not pass style-queue: ERROR: Source/WebKit/win/WebView.cpp:965: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] ERROR: Source/WebKit/win/WebView.cpp:1249: Should have a space between // and comment [whitespace/comments] [4] ERROR: Source/WebKit/win/WebView.cpp:1292: Should have a space between // and comment [whitespace/comments] [4] ERROR: Source/WebCore/platform/win/ScrollbarThemeWin.cpp:29: Alphabetical sorting problem. [build/include_order] [4] ERROR: Tools/WinLauncher/WinLauncher.cpp:486: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] ERROR: Source/WebCore/platform/win/PlatformMouseEventWin.cpp:33: Alphabetical sorting problem. [build/include_order] [4] ERROR: Source/WebCore/ChangeLog:9: You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible. [changelog/nonewtests] [5] Total errors found: 7 in 17 files If any of these errors are false positives, please file a bug against check-webkit-style.
Darin Adler
Comment 5 2015-06-27 15:21:43 PDT
Comment on attachment 255708 [details] WIP Patch View in context: https://bugs.webkit.org/attachment.cgi?id=255708&action=review > Source/WebCore/platform/win/ScrollbarThemeWin.cpp:124 > + HWndDC dc(0); > + float scaleFactor = 96.0f / ::GetDeviceCaps(dc, LOGPIXELSX); > + return clampTo<int>(scaleFactor * scrollbarThicknessInPixels()); Seems like this won’t do the right thing if there are multiple screens. > Source/WebKit/win/ChangeLog:3 > + [Win] Implement proper High DPI support features “proper” eh? > Source/WebKit/win/WebView.cpp:966 > + // DDDDDD ? > Source/WebKit/win/WebView.cpp:1002 > + IntSize logicalSize = newSize; > + logicalSize.scale(1.0f / deviceScaleFactor()); This will truncate; is that what we want rather than, say, rounding or doing a ceiling operation? > Source/WebKit/win/WebView.cpp:1249 > +#if 1 //FLASH_BACKING_STORE_REDRAW ? > Source/WebKit/win/WebView.cpp:1292 > +#if 1 //FLASH_WINDOW_REDRAW ?
Brent Fulgham
Comment 6 2015-07-01 12:11:27 PDT
Created attachment 255945 [details] WIP Do NOT REVIEW!
WebKit Commit Bot
Comment 7 2015-07-01 12:12:55 PDT
Attachment 255945 [details] did not pass style-queue: ERROR: Source/WebKit/win/WebView.cpp:965: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] ERROR: Source/WebCore/platform/win/ScrollbarThemeWin.cpp:29: Alphabetical sorting problem. [build/include_order] [4] ERROR: Source/WebCore/platform/graphics/ca/win/PlatformCALayerWinInternal.cpp:427: Multi line control clauses should use braces. [whitespace/braces] [4] ERROR: Source/WebCore/platform/graphics/ca/win/PlatformCALayerWinInternal.cpp:427: Should have a space between // and comment [whitespace/comments] [4] ERROR: Tools/WinLauncher/WinLauncher.cpp:486: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] ERROR: Source/WebCore/platform/win/PlatformMouseEventWin.cpp:33: Alphabetical sorting problem. [build/include_order] [4] ERROR: Source/WebCore/ChangeLog:9: You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible. [changelog/nonewtests] [5] Total errors found: 7 in 20 files If any of these errors are false positives, please file a bug against check-webkit-style.
Brent Fulgham
Comment 8 2015-07-16 16:24:24 PDT
WebKit Commit Bot
Comment 9 2015-07-16 16:27:34 PDT
Attachment 256938 [details] did not pass style-queue: ERROR: Source/WebKit/win/WebView.cpp:967: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] ERROR: Source/WebCore/platform/win/ScrollbarThemeWin.cpp:29: Alphabetical sorting problem. [build/include_order] [4] ERROR: Tools/WinLauncher/WinLauncher.cpp:486: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] ERROR: Source/WebCore/platform/win/PlatformMouseEventWin.cpp:33: Alphabetical sorting problem. [build/include_order] [4] Total errors found: 4 in 18 files If any of these errors are false positives, please file a bug against check-webkit-style.
Brent Fulgham
Comment 10 2015-07-21 17:38:43 PDT
WebKit Commit Bot
Comment 11 2015-07-21 17:41:24 PDT
Attachment 257223 [details] did not pass style-queue: ERROR: Source/WebKit/win/WebView.cpp:366: WM_DPICHANGED is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Tools/WinLauncher/WinLauncher.cpp:486: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] ERROR: Source/WebCore/platform/win/PlatformMouseEventWin.cpp:33: Alphabetical sorting problem. [build/include_order] [4] ERROR: Tools/WinLauncher/WinMain.cpp:73: Declaration has space between type name and * in scaleFactor * s_windowPosition [whitespace/declaration] [3] ERROR: Tools/WinLauncher/Common.cpp:108: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] Total errors found: 5 in 17 files If any of these errors are false positives, please file a bug against check-webkit-style.
Brent Fulgham
Comment 12 2015-07-21 18:38:42 PDT
WebKit Commit Bot
Comment 13 2015-07-21 18:40:01 PDT
Attachment 257235 [details] did not pass style-queue: ERROR: Tools/WinLauncher/WinLauncher.cpp:486: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] ERROR: Source/WebCore/platform/win/PlatformMouseEventWin.cpp:33: Alphabetical sorting problem. [build/include_order] [4] ERROR: Tools/WinLauncher/WinMain.cpp:73: Declaration has space between type name and * in scaleFactor * s_windowPosition [whitespace/declaration] [3] ERROR: Tools/WinLauncher/Common.cpp:108: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] Total errors found: 4 in 16 files If any of these errors are false positives, please file a bug against check-webkit-style.
Brent Fulgham
Comment 14 2015-07-22 09:27:03 PDT
WebKit Commit Bot
Comment 15 2015-07-22 09:28:42 PDT
Attachment 257277 [details] did not pass style-queue: ERROR: Tools/WinLauncher/Common.cpp:108: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] ERROR: Source/WebCore/platform/win/ScrollbarThemeWin.cpp:29: Alphabetical sorting problem. [build/include_order] [4] ERROR: Tools/WinLauncher/WinLauncher.cpp:486: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] ERROR: Source/WebCore/platform/win/PlatformMouseEventWin.cpp:33: Alphabetical sorting problem. [build/include_order] [4] ERROR: Tools/WinLauncher/WinMain.cpp:73: Declaration has space between type name and * in scaleFactor * s_windowPosition [whitespace/declaration] [3] Total errors found: 5 in 20 files If any of these errors are false positives, please file a bug against check-webkit-style.
Brent Fulgham
Comment 16 2015-07-22 09:53:06 PDT
WebKit Commit Bot
Comment 17 2015-07-22 09:54:31 PDT
Attachment 257279 [details] did not pass style-queue: ERROR: Tools/WinLauncher/Common.cpp:108: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] ERROR: Tools/WinLauncher/WinLauncher.cpp:486: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] ERROR: Source/WebCore/platform/win/PlatformMouseEventWin.cpp:33: Alphabetical sorting problem. [build/include_order] [4] ERROR: Tools/WinLauncher/WinMain.cpp:73: Declaration has space between type name and * in scaleFactor * s_windowPosition [whitespace/declaration] [3] Total errors found: 4 in 17 files If any of these errors are false positives, please file a bug against check-webkit-style.
Brent Fulgham
Comment 18 2015-07-22 13:38:11 PDT
WebKit Commit Bot
Comment 19 2015-07-22 13:39:21 PDT
Attachment 257291 [details] did not pass style-queue: ERROR: Tools/WinLauncher/Common.cpp:108: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] ERROR: Tools/WinLauncher/WinLauncher.cpp:486: Use the class HWndDC instead of calling GetDC to avoid potential memory leaks. [runtime/leaky_pattern] [5] ERROR: Source/WebCore/platform/win/PlatformMouseEventWin.cpp:33: Alphabetical sorting problem. [build/include_order] [4] ERROR: Tools/WinLauncher/WinMain.cpp:73: Declaration has space between type name and * in scaleFactor * s_windowPosition [whitespace/declaration] [3] Total errors found: 4 in 17 files If any of these errors are false positives, please file a bug against check-webkit-style.
Darin Adler
Comment 20 2015-07-22 14:33:32 PDT
Comment on attachment 257291 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=257291&action=review How did you test this? There are lots of different changes; were they all tested? I’d like to see us consistently use one name for the inverse scale factor. Currently the patch sometimes calls it just “scale factor”, other times “inverse scale factor”, other times “inverted scale factor”. > Source/WebCore/platform/win/PlatformMouseEventWin.cpp:52 > + float scaleFactor = deviceScaleFactor(hWnd); > + point.x = clampTo<int>(point.x / scaleFactor); > + point.y = clampTo<int>(point.y / scaleFactor); In ScrollbarThemeWin.cpp you made the scale factor be the inverse of what it is here, and so were able to do more multiplication and less division. Why the different approaches in the different source files? > Source/WebCore/platform/win/ScrollbarThemeWin.cpp:115 > static int thickness; > if (!thickness) > thickness = ::GetSystemMetrics(SM_CXVSCROLL); This seems strange. Why not just write this? static int thickness = ::GetSystemMetrics(SM_CXVSCROLL); > Source/WebCore/platform/win/ScrollbarThemeWin.cpp:122 > + HWndDC dc(0); Is the 0 here really needed? How about using nothing at all? How about nullptr? > Source/WebCore/platform/win/WheelEventWin.cpp:44 > +static float deviceScaleFactor(HWND window) > +{ > + HWndDC dc(window); > + return ::GetDeviceCaps(dc, LOGPIXELSX) / 96.0f; > +} Why write this function multiple times? Lets put it in a header. > Source/WebKit/win/WebPreferences.cpp:197 > - CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Segoe UI")); > + CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Times New Roman")); No explanation of this in the change log. > Source/WebKit/win/WebView.cpp:1255 > + float inverseScaleFactor = 1.0f / scaleFactor; Seems like this should consistently be called inverseScaleFactor in all the source files. > Source/WebKit/win/WebView.cpp:1481 > + POINT point = { logicalPoint.x() * scaleFactor, logicalPoint.y() * scaleFactor }; I don’t think you need the "=" here. > Source/WebKit/win/WebView.cpp:1678 > + IntPoint logicalGestureBeginPoint(gestureBeginPoint.x / scaleFactor, gestureBeginPoint.y / scaleFactor); Is truncation what we want in all these places where we convert to int? Why not ceiling, rounding, or pixel snapping instead? > Tools/WinLauncher/Common.cpp:110 > + HDC dc = ::GetDC(window); > + float deviceScaleFactor = ::GetDeviceCaps(dc, LOGPIXELSX) / 96.0f; > + ::ReleaseDC(window, dc); Why not use HWndDC here? Also, it’s annoying to have another duplication copy of this same function! > Tools/WinLauncher/Common.cpp:135 > + if (!hURLFont) { > + hURLFont = ::CreateFont(scaleFactor * 18, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, > + OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE, L"Times New Roman"); > + } Why is it safe to cache this in a global and not regenerate it? What if the scale factor is different, the next time through? > Tools/WinLauncher/Common.cpp:158 > + float scaleFactor = deviceScaleFactorForWindow(0); How about nullptr instead of 0? > Tools/WinLauncher/Common.cpp:455 > + if ((y > window.top) && (y < window.top + (dragBarHeight * gWinLauncher->deviceScaleFactor()))) Too many parentheses I think. > Tools/WinLauncher/WinLauncher.cpp:488 > + HDC dc = ::GetDC(m_hMainWnd); > + m_deviceScaleFactor = ::GetDeviceCaps(dc, LOGPIXELSX) / 96.0f; > + ::ReleaseDC(m_hMainWnd, dc); Another place that could share the deviceScaleFactor function? > Tools/WinLauncher/WinLauncherWebHost.h:79 > + HWND m_hURLBarWnd { 0 }; nullptr > Tools/WinLauncher/WinLauncherWebHost.h:80 > + HGDIOBJ m_URLBarFont { 0 }; nullptr > Tools/WinLauncher/WinLauncherWebHost.h:81 > + HGDIOBJ m_oldFont { 0 }; nullptr > Tools/WinLauncher/WinMain.cpp:68 > + float scaleFactor = deviceScaleFactorForWindow(0); nullptr
Brent Fulgham
Comment 21 2015-07-22 17:17:38 PDT
Comment on attachment 257291 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=257291&action=review >> Source/WebCore/platform/win/PlatformMouseEventWin.cpp:52 >> + point.y = clampTo<int>(point.y / scaleFactor); > > In ScrollbarThemeWin.cpp you made the scale factor be the inverse of what it is here, and so were able to do more multiplication and less division. Why the different approaches in the different source files? No, it should be consistent. I'll fix that. >> Source/WebCore/platform/win/ScrollbarThemeWin.cpp:115 >> thickness = ::GetSystemMetrics(SM_CXVSCROLL); > > This seems strange. Why not just write this? > > static int thickness = ::GetSystemMetrics(SM_CXVSCROLL); Good idea. I'll correct. >> Source/WebCore/platform/win/ScrollbarThemeWin.cpp:122 >> + HWndDC dc(0); > > Is the 0 here really needed? How about using nothing at all? How about nullptr? It takes a window as its argument, so it does need something. But nullptr is fine, and I'll switch to that. >> Source/WebCore/platform/win/WheelEventWin.cpp:44 >> +} > > Why write this function multiple times? Lets put it in a header. Done. >> Source/WebKit/win/WebPreferences.cpp:197 >> + CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Times New Roman")); > > No explanation of this in the change log. I'll correct that. This was just a drive-by fix. >> Source/WebKit/win/WebView.cpp:1255 >> + float inverseScaleFactor = 1.0f / scaleFactor; > > Seems like this should consistently be called inverseScaleFactor in all the source files. Agreed. Fixed. >> Source/WebKit/win/WebView.cpp:1481 >> + POINT point = { logicalPoint.x() * scaleFactor, logicalPoint.y() * scaleFactor }; > > I don’t think you need the "=" here. Ok. I should also be using the IntPoint's scale method to make sure the right things are being done for float->int. >> Source/WebKit/win/WebView.cpp:1678 >> + IntPoint logicalGestureBeginPoint(gestureBeginPoint.x / scaleFactor, gestureBeginPoint.y / scaleFactor); > > Is truncation what we want in all these places where we convert to int? Why not ceiling, rounding, or pixel snapping instead? I'll make sure to use IntPoint.scale() so that it does the right thing. >> Tools/WinLauncher/Common.cpp:110 >> + ::ReleaseDC(window, dc); > > Why not use HWndDC here? Also, it’s annoying to have another duplication copy of this same function! HWndDC is internal to WebCore, so we can't use it in the Tools section of our sources. However, I can expose the deviceScaleFactorForWindow() as a utility function, and I'll use that instead. That function uses HWndDC internally. >> Tools/WinLauncher/Common.cpp:135 >> + } > > Why is it safe to cache this in a global and not regenerate it? What if the scale factor is different, the next time through? I'll correct the life cycle handling for this. >> Tools/WinLauncher/Common.cpp:158 >> + float scaleFactor = deviceScaleFactorForWindow(0); > > How about nullptr instead of 0? OK! >> Tools/WinLauncher/Common.cpp:455 >> + if ((y > window.top) && (y < window.top + (dragBarHeight * gWinLauncher->deviceScaleFactor()))) > > Too many parentheses I think. OK! >> Tools/WinLauncher/WinLauncher.cpp:488 >> + ::ReleaseDC(m_hMainWnd, dc); > > Another place that could share the deviceScaleFactor function? Yup. >> Tools/WinLauncher/WinLauncherWebHost.h:79 >> + HWND m_hURLBarWnd { 0 }; > > nullptr Done. >> Tools/WinLauncher/WinLauncherWebHost.h:80 >> + HGDIOBJ m_URLBarFont { 0 }; > > nullptr Done. >> Tools/WinLauncher/WinLauncherWebHost.h:81 >> + HGDIOBJ m_oldFont { 0 }; > > nullptr Done. >> Tools/WinLauncher/WinMain.cpp:68 >> + float scaleFactor = deviceScaleFactorForWindow(0); > > nullptr Done.
Brent Fulgham
Comment 22 2015-07-22 17:22:17 PDT
WebKit Commit Bot
Comment 23 2015-07-22 17:24:55 PDT
Attachment 257312 [details] did not pass style-queue: ERROR: Source/WebKit/win/WebView.cpp:368: WM_DPICHANGED is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WebCore/platform/win/PlatformMouseEventWin.cpp:34: Alphabetical sorting problem. [build/include_order] [4] ERROR: Tools/WinLauncher/WinMain.cpp:77: Declaration has space between type name and * in scaleFactor * s_windowPosition [whitespace/declaration] [3] Total errors found: 3 in 19 files If any of these errors are false positives, please file a bug against check-webkit-style.
Brent Fulgham
Comment 24 2015-07-22 17:48:43 PDT
(In reply to comment #20) > Comment on attachment 257291 [details] > How did you test this? There are lots of different changes; were they all > tested? This code is dormant until a WebKit client activates High DPI mode, so all scaling factors will be 1.0, rending all of these changes kind of useless unless you are playing with High DPI settings on Windows (and Opt-in in your application). I've turned this on for WinLauncher, but DumpRenderTree and the other programs are still blissfully unaware of High DPI. These changes should have no impact on any rendering behavior, so our existing regression suites cover the changes. We will be creating new high DPI test cases for Windows once we complete the second part of this work (getting CALayer drawing working properly).
Brent Fulgham
Comment 25 2015-07-22 22:06:50 PDT
WebKit Commit Bot
Comment 26 2015-07-22 22:09:49 PDT
Attachment 257340 [details] did not pass style-queue: ERROR: Source/WebKit/win/WebView.cpp:368: WM_DPICHANGED is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Tools/WinLauncher/WinMain.cpp:77: Declaration has space between type name and * in scaleFactor * s_windowPosition [whitespace/declaration] [3] ERROR: Source/WebCore/platform/win/PlatformMouseEventWin.cpp:34: Alphabetical sorting problem. [build/include_order] [4] ERROR: Source/WebCore/platform/win/GDIUtilities.h:26: #ifndef header guard has wrong style, please use: GDIUtilities_h [build/header_guard] [5] Total errors found: 4 in 21 files If any of these errors are false positives, please file a bug against check-webkit-style.
Brent Fulgham
Comment 27 2015-07-22 23:39:13 PDT
I confirmed that this patch passes Windows tests locally; it clearly passes the EWS.
Brent Fulgham
Comment 28 2015-07-23 12:31:20 PDT
Csaba Osztrogonác
Comment 29 2015-07-23 13:06:44 PDT
(In reply to comment #28) > Committed r187245: <http://trac.webkit.org/changeset/187245> It broke the Apple Windows build.
Brent Fulgham
Comment 30 2015-07-23 14:10:13 PDT
(In reply to comment #29) > (In reply to comment #28) > > Committed r187245: <http://trac.webkit.org/changeset/187245> > > It broke the Apple Windows build. I'm looking at this now. I'm in the process of fixing some bot configuration issues, so this build failure may not be due to the patch.
Brent Fulgham
Comment 31 2015-07-23 14:15:23 PDT
(In reply to comment #30) > (In reply to comment #29) > > (In reply to comment #28) > > > Committed r187245: <http://trac.webkit.org/changeset/187245> > > > > It broke the Apple Windows build. > > I'm looking at this now. I'm in the process of fixing some bot configuration > issues, so this build failure may not be due to the patch. This build failure is actually due to a mixture of Windows SDK's being used during the build. A clean build corrects the problem.
Note You need to log in before you can comment on or make changes to this bug.