| Differences between
and this patch
- a/Source/WebCore/ChangeLog +27 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2020-04-15  Claudio Saavedra  <csaavedra@igalia.com>
2
3
        [GTK] Make PlatformScreen::screenDPI() GTK4-ready
4
        https://bugs.webkit.org/show_bug.cgi?id=210543
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        No new tests needed.
9
10
        This method is using deprecated and removed APIs
11
        from GDK. Guard the removed API usage so that it's only
12
        used in GTK3 and update to use the replacement APIs otherwise.
13
14
        Also, make it to also use the gtk-xft-dpi GtkSettings property.
15
        This method is mostly used in response to a change in this
16
        property, so ignoring its value doesn't seem a good idea.
17
18
        The following priority is used:
19
20
        1. (GTK3 only) query gdk_screen_get_resolution().
21
        2. Use the GtkSettings::gtk-xft-dpi property.
22
        3. Calculate the actual DPI from the monitor 0's properties.
23
        4. If none of these succeed, use the default DPI, 96.
24
25
        * platform/gtk/PlatformScreenGtk.cpp:
26
        (WebCore::screenDPI):
27
1
2020-04-14  Claudio Saavedra  <csaavedra@igalia.com>
28
2020-04-14  Claudio Saavedra  <csaavedra@igalia.com>
2
29
3
        [GTK] Adapt to GdkVisual deprecation and removal
30
        [GTK] Adapt to GdkVisual deprecation and removal
- a/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp -7 / +25 lines
Lines 92-112 bool screenHasInvertedColors() a/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp_sec1
92
double screenDPI()
92
double screenDPI()
93
{
93
{
94
    static const double defaultDpi = 96;
94
    static const double defaultDpi = 96;
95
#if !USE(GTK4)
95
    GdkScreen* screen = gdk_screen_get_default();
96
    GdkScreen* screen = gdk_screen_get_default();
96
    if (!screen)
97
    if (screen) {
97
        return defaultDpi;
98
        double dpi = gdk_screen_get_resolution(screen);
99
        if (dpi != -1)
100
            return dpi;
101
    }
102
#endif
98
103
99
    double dpi = gdk_screen_get_resolution(screen);
104
    static GtkSettings* gtkSettings = gtk_settings_get_default();
100
    if (dpi != -1)
105
    if (gtkSettings) {
101
        return dpi;
106
        int gtkXftDpi;
107
        g_object_get(gtkSettings, "gtk-xft-dpi", &gtkXftDpi, NULL);
108
        return gtkXftDpi / 1024.0;
109
    }
102
110
103
    static double cachedDpi = 0;
111
    static double cachedDpi = 0;
104
    if (cachedDpi)
112
    if (cachedDpi)
105
        return cachedDpi;
113
        return cachedDpi;
106
114
107
    static const double millimetresPerInch = 25.4;
115
    static const double millimetresPerInch = 25.4;
108
    double diagonalInPixels = std::hypot(gdk_screen_get_width(screen), gdk_screen_get_height(screen));
116
109
    double diagonalInInches = std::hypot(gdk_screen_get_width_mm(screen), gdk_screen_get_height_mm(screen)) / millimetresPerInch;
117
    GdkDisplay* display = gdk_display_get_default();
118
    if (!display)
119
        return defaultDpi;
120
    GdkMonitor* monitor = gdk_display_get_monitor(display, 0);
121
    if (!monitor)
122
        return defaultDpi;
123
124
    GdkRectangle geometry;
125
    gdk_monitor_get_geometry(monitor, &geometry);
126
    double diagonalInPixels = std::hypot(geometry.width, geometry.height);
127
    double diagonalInInches = std::hypot(gdk_monitor_get_width_mm(monitor), gdk_monitor_get_height_mm(monitor)) / millimetresPerInch;
110
    cachedDpi = diagonalInPixels / diagonalInInches;
128
    cachedDpi = diagonalInPixels / diagonalInInches;
111
129
112
    return cachedDpi;
130
    return cachedDpi;

Return to Bug 210543