Skip to content
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

[GTK] Rename screenDPI() to fontDPI() where used for font scaling. #26954

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

gwhitney
Copy link
Contributor

@gwhitney gwhitney commented Apr 7, 2024

51f2745

[GTK] Rename screenDPI() to fontDPI() where used for font scaling.
https://bugs.webkit.org/show_bug.cgi?id=272676

Reviewed by Carlos Garcia Campos.

This commit lays the groundwork for addressing DPI scaling issues under
GTK, as described in the related bugzilla bug 247980, which seems to
have arisen by virtue of confusion between the physical DPI of the display
devices that WebKit is rendering on, and the GTK font scaling DPI that sets
the desired font sizes. Hence, in line with the concerns raised in the
references bug 272676, this commit renames WebCore::screenDPI() to
WebCore::fontDPI() to clarify its semantics and hopefully avoid future
similar confusions. For cases in which the underlying display density is
needed, it adds a new WebCore::screenDPI(PlatformDisplayID) function
to access that information, on a per-display basis.

This commit also creates a reftest that probes the status of the referenced
bug. Namely, the test compares a 1em box in a text size of 96px, with a
1in box. Note the test passes as the code stands, even though when I view
247980.html and 247980-expected.html in the minibrowser on my machine, the
two boxes are clearly very different in size, which is one key aspect of the
bug. Presumably, this pass occurs because the tests are run in an environment
insulated from my actual display resolution and GTK setup. Moreover, another
aspect of the bug is that when the two DPI measures referenced above agree,
both boxes should measure 1 physical inch on the screen, which they currently
do not (unless the display happens to have exactly 96 pixels per inch, low by
today's typical specs, and unlikely to happen to be the case even when device
scaling is employed). But I have no idea how such a condition could
practically be tested in the WebKit test framework.

* LayoutTests/fast/box-sizing/247980-expected.html: Added.
* LayoutTests/fast/box-sizing/247980.html: Added.
* Source/WebCore/accessibility/atspi/AccessibilityObjectTextAtspi.cpp:
(WebCore::AccessibilityObjectAtspi::textAttributes const):
* Source/WebCore/platform/PlatformScreen.h:
* Source/WebCore/platform/ScreenProperties.h:
* Source/WebCore/platform/graphics/gtk/SystemFontDatabaseGTK.cpp:
(WebCore::SystemFontDatabase::platformSystemFontShorthandInfo):
* Source/WebCore/platform/gtk/PlatformScreenGtk.cpp:
(WebCore::fontDPI):
(WebCore::screenDPI):
* Source/WebCore/platform/wpe/PlatformScreenWPE.cpp:
(WebCore::fontDPI):
(WebCore::screenDPI):
* Source/WebKit/UIProcess/API/glib/WebKitProtocolHandler.cpp:
(WebKit::WebKitProtocolHandler::handleGPU):
* Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp:
(webkit_settings_font_size_to_points):
(webkit_settings_font_size_to_pixels):

Canonical link: https://commits.webkit.org/277537@main

41815f5

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ›  wpe-skia
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ›  gtk
βœ… πŸ›  tv   πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-wk2-stress βœ… πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@gwhitney gwhitney requested review from zdobersek, a team and cdumez as code owners April 7, 2024 17:36
@gwhitney gwhitney changed the title [GTK]Rename dpi information accessors to clarify semantics. [GTK] Rename dpi information accessors to clarify semantics. Apr 7, 2024
@bubbleguuum
Copy link

bubbleguuum commented Apr 9, 2024

Will this PR (and the next one to follow) fix that issue that I have observed with MiniBrowser using WebKitGTK 2.44.0 on a laptop with a 17.3" 4K panel (254 physical dpi) running on i3 Window Manager.
On that setup, I use Xft.dpi: 240 (for 2.5x font scaling) and GDK_DPI_SCALE=0.5, GDK_SCALE=2 (2x GTK UI scaling).
It works fine with all my programs except WebKitGTK resulting in huge font rendering and rendering bugs (screenshot), as if Xft scaling and GTK scaling were combined.
The only combination of these 3 parameters that I found render properly (without too big fonts nor UI rendering issues) is to set Xft.dpi: 96 (with GDK_DPI_SCALE=0.5, GDK_SCALE=2), except that fonts are a bit too small (at 2x scaling instead of 2.5).
IIRC, WebKitGTK before 2.44.0 did not have this issue where Xft.dpi and GDK env variables seems to be conflicting.

@gwhitney
Copy link
Contributor Author

gwhitney commented Apr 9, 2024

Well, compare your screenshot to the ones in my issue report https://bugs.webkit.org/show_bug.cgi?id=247980 which were generated with Xft.dpi=273 (matching my physical dpi) and a couple different GDK_SCALE values. Looks like the symptoms are pretty similar. And I am now running with my proposed patches on a day-to-day basis, and the minibrowser looks just as I would like/expect. So, fingers crossed that yes it will resolve your issue once both parts are in. If you feel pretty confident you are seeing the same issue I have reported in 247980, you might want to mention that there or upvote the bug or something, since it received no attention for a year; I imagine some "metoos" might help get this patch through. And yes, I agree, something got worse in 2.44, which is what motivated me to finally attack the issue on my own. I am not quite sure what the change was in 2.44, but hopefully the renaming in this PR will help keep things straight after the real patch lands. Thanks for sharing your situation.

@bubbleguuum
Copy link

bubbleguuum commented Apr 9, 2024

Just did that.
I really don't remember of HiDpi scaling problems in 2.42.x.

@gwhitney
Copy link
Contributor Author

Well, my strong suspicion is that even in 2.42, you were not getting a CSS 1in dimension to be an actual physical one inch when displayed on your screen. After the patch, you should. However, there is a question I put in the bugzilla issue about the expected behavior of the GDK_xx_SCALE environment variables, which I am unclear on as I don't use them (but happy to support whatever the "proper" behavior should be).

@gwhitney gwhitney changed the title [GTK] Rename dpi information accessors to clarify semantics. [GTK] Rename screenDPI() to fontDPI() where used for font scaling. Apr 13, 2024
@gwhitney
Copy link
Contributor Author

OK, hopefully the revised version I just submitted addresses all of the listed concerns. Thanks for taking the time to review!

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 13, 2024
Copy link
Contributor

@carlosgcampos carlosgcampos left a comment

Choose a reason for hiding this comment

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

Looks good to me, let's just fix the wpe build.

Source/WebCore/platform/PlatformScreen.h Outdated Show resolved Hide resolved
Source/WebCore/platform/wpe/PlatformScreenWPE.cpp Outdated Show resolved Hide resolved
@mcatanzaro
Copy link
Contributor

Ah, you'll also want to create a new bug report for this, so that https://bugs.webkit.org/show_bug.cgi?id=247980 doesn't get closed when this lands. The title of the bug should match the title of your commit message here.

(Lastly, in the commit message, remove the period from the end of the URL so the link works.)

@gwhitney
Copy link
Contributor Author

Apologies about the typos. Rebased and corrected them. Hope all is well with this version. Thanks!

@gwhitney
Copy link
Contributor Author

Oh, sorry, the commit message still says "the commit does not yet fix the bug," which was in reference to the original scaling issue 247980. It does of course address the concern broken out as 272676. Let me know if you need me to amend the commit message.

@mcatanzaro
Copy link
Contributor

Make sure to click the Resolve Conversation button when you've responded to the review feedback.

@mcatanzaro
Copy link
Contributor

This commit also creates a reftest that probes the status of the referenced
bug. Namely, the test compares a 1em box in a text size of 96px, with a
1in box. Note the test passes as the code stands, even though when I view
247980.html and 247980-expected.html in the minibrowser on my machine, the
two boxes are clearly very different in size, which is one key aspect of
the bug.

This is strange. If you're using the same build of WebKit to run both MiniBrowser and the layout tests, then I would expect the results to be consistent. Anyway, the new test is surely not hurting anything, so let's land it.

@mcatanzaro
Copy link
Contributor

Maybe either (a) add </html> closing tags to the test files, or (b) remove the first two lines (pretty sure they're optional). Just looks a little strange to have an opening tag but not a close tag. Hardly a big deal.

@mcatanzaro
Copy link
Contributor

Oh, sorry, the commit message still says "the commit does not yet fix the bug," which was in reference to the original scaling issue 247980. It does of course address the concern broken out as 272676. Let me know if you need me to amend the commit message.

Again not a big deal, but since you're amending the commit one last time anyway, might as well reword it.

@gwhitney
Copy link
Contributor Author

Make sure to click the Resolve Conversation button when you've responded to the review feedback.

Oh, sorry, in some other repos the reviewer does that when they are satisfied with the response. Will go back and resolve any I believe have been taken care of.

@gwhitney
Copy link
Contributor Author

This is strange. If you're using the same build of WebKit to run both MiniBrowser and the layout tests, then I would expect the results to be consistent. Anyway, the new test is surely not hurting anything, so let's land it.

I actually don't think it is so strange. The tests are run without a connection to any physical monitor, and I believe in an environment that is telling GTK it is running on a monitor that is physically 96 dots per inch, with no device scaling, and with font scaling to 96 dots per inch - a classic old-school vanilla "standard monitor" which I don't think is particularly common anymore in actual operation. So I don't think any features responding to different dpis or font scaling in the GTK setting are getting exercised in the testing. I don't believe that I am familiar enough with the elaborate testing mechanism to try to address that; and I think it would be a separate issue/PR anyway. If you disagree and would like me to try to delve into that situation in this PR, please let me know.

@mcatanzaro
Copy link
Contributor

Ah, you're right, they are run under Xvfb. We should probably switch that to wlheadless-run at some point, but it will no doubt have the same problem. Oh well.

@gwhitney
Copy link
Contributor Author

OK, closed the html tag in the test cases and reworded the commit message. Thanks for all of the time and guidance; sorry if this is taking extra effort because I am a new contributor. Let me know if anything else is needed.

@gwhitney
Copy link
Contributor Author

gwhitney commented Apr 15, 2024

I see for the first time there is a failure of automated checks, but it's hard for me to tell if it has anything to do with what I checked in, or if it was just a transient issue, or what. Please let me know if I need to respond in any way, thanks.

@carlosgcampos carlosgcampos added merge-queue Applied to send a pull request to merge-queue and removed merging-blocked Applied to prevent a change from being merged labels Apr 16, 2024
https://bugs.webkit.org/show_bug.cgi?id=272676

Reviewed by Carlos Garcia Campos.

This commit lays the groundwork for addressing DPI scaling issues under
GTK, as described in the related bugzilla bug 247980, which seems to
have arisen by virtue of confusion between the physical DPI of the display
devices that WebKit is rendering on, and the GTK font scaling DPI that sets
the desired font sizes. Hence, in line with the concerns raised in the
references bug 272676, this commit renames WebCore::screenDPI() to
WebCore::fontDPI() to clarify its semantics and hopefully avoid future
similar confusions. For cases in which the underlying display density is
needed, it adds a new WebCore::screenDPI(PlatformDisplayID) function
to access that information, on a per-display basis.

This commit also creates a reftest that probes the status of the referenced
bug. Namely, the test compares a 1em box in a text size of 96px, with a
1in box. Note the test passes as the code stands, even though when I view
247980.html and 247980-expected.html in the minibrowser on my machine, the
two boxes are clearly very different in size, which is one key aspect of the
bug. Presumably, this pass occurs because the tests are run in an environment
insulated from my actual display resolution and GTK setup. Moreover, another
aspect of the bug is that when the two DPI measures referenced above agree,
both boxes should measure 1 physical inch on the screen, which they currently
do not (unless the display happens to have exactly 96 pixels per inch, low by
today's typical specs, and unlikely to happen to be the case even when device
scaling is employed). But I have no idea how such a condition could
practically be tested in the WebKit test framework.

* LayoutTests/fast/box-sizing/247980-expected.html: Added.
* LayoutTests/fast/box-sizing/247980.html: Added.
* Source/WebCore/accessibility/atspi/AccessibilityObjectTextAtspi.cpp:
(WebCore::AccessibilityObjectAtspi::textAttributes const):
* Source/WebCore/platform/PlatformScreen.h:
* Source/WebCore/platform/ScreenProperties.h:
* Source/WebCore/platform/graphics/gtk/SystemFontDatabaseGTK.cpp:
(WebCore::SystemFontDatabase::platformSystemFontShorthandInfo):
* Source/WebCore/platform/gtk/PlatformScreenGtk.cpp:
(WebCore::fontDPI):
(WebCore::screenDPI):
* Source/WebCore/platform/wpe/PlatformScreenWPE.cpp:
(WebCore::fontDPI):
(WebCore::screenDPI):
* Source/WebKit/UIProcess/API/glib/WebKitProtocolHandler.cpp:
(WebKit::WebKitProtocolHandler::handleGPU):
* Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp:
(webkit_settings_font_size_to_points):
(webkit_settings_font_size_to_pixels):

Canonical link: https://commits.webkit.org/277537@main
@webkit-commit-queue
Copy link
Collaborator

Committed 277537@main (51f2745): https://commits.webkit.org/277537@main

Reviewed commits have been landed. Closing PR #26954 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 51f2745 into WebKit:main Apr 16, 2024
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Apr 16, 2024
@mcatanzaro mcatanzaro added the GLib Suggested Backport Suggest this merge request be backported to current WPE/GTK stable branch label Apr 16, 2024
@aperezdc
Copy link
Contributor

aperezdc commented May 2, 2024

Backported into the 2.44 branch as commit 95b1c08

@aperezdc aperezdc removed the GLib Suggested Backport Suggest this merge request be backported to current WPE/GTK stable branch label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants