Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: chrome/browser/ui/libgtkui/gtk_ui.cc

Issue 2899943002: Gtk: Consider font dpi when calculating device scale factor (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/libgtkui/gtk_ui.h" 5 #include "chrome/browser/ui/libgtkui/gtk_ui.h"
6 6
7 #include <X11/Xcursor/Xcursor.h> 7 #include <X11/Xcursor/Xcursor.h>
8 #include <dlfcn.h> 8 #include <dlfcn.h>
9 #include <math.h> 9 #include <math.h>
10 #include <pango/pango.h> 10 #include <pango/pango.h>
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\""; 308 LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\"";
309 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE; 309 params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
310 } 310 }
311 311
312 g_free(hint_style); 312 g_free(hint_style);
313 g_free(rgba); 313 g_free(rgba);
314 314
315 return params; 315 return params;
316 } 316 }
317 317
318 float GetGdkWindowScalingFactor() { 318 float GtkDpiToScaleFactor(int dpi) {
319 GValue scale = G_VALUE_INIT; 319 // GTK multiplies the DPI by 1024 before storing it.
320 g_value_init(&scale, G_TYPE_INT); 320 return dpi / (1024 * kDefaultDPI);
321 if (!gdk_screen_get_setting(gdk_screen_get_default(), 321 }
322 "gdk-window-scaling-factor", &scale)) 322
323 gint GetGdkScreenSettingInt(const char* setting_name) {
324 GValue value = G_VALUE_INIT;
325 g_value_init(&value, G_TYPE_INT);
326 if (!gdk_screen_get_setting(gdk_screen_get_default(), setting_name, &value))
323 return -1; 327 return -1;
328 return g_value_get_int(&value);
329 }
324 330
325 return g_value_get_int(&scale); 331 float GetScaleFromGdkScreenSettings() {
332 gint window_scale = GetGdkScreenSettingInt("gdk-window-scaling-factor");
333 if (window_scale <= 0)
334 return -1;
335 gint font_dpi = GetGdkScreenSettingInt("gdk-unscaled-dpi");
336 if (font_dpi <= 0)
337 return -1;
338 return window_scale * GtkDpiToScaleFactor(font_dpi);
326 } 339 }
327 340
328 float GetScaleFromXftDPI() { 341 float GetScaleFromXftDPI() {
329 GtkSettings* gtk_settings = gtk_settings_get_default(); 342 GtkSettings* gtk_settings = gtk_settings_get_default();
330 CHECK(gtk_settings); 343 CHECK(gtk_settings);
331 gint gtk_dpi = -1; 344 gint gtk_dpi = -1;
332 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, nullptr); 345 g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, nullptr);
333 // GTK multiplies the DPI by 1024 before storing it. 346 if (gtk_dpi <= 0)
334 return (gtk_dpi > 0) ? gtk_dpi / (1024 * kDefaultDPI) : -1; 347 return -1;
348 return GtkDpiToScaleFactor(gtk_dpi);
335 } 349 }
336 350
337 float GetRawDeviceScaleFactor() { 351 float GetRawDeviceScaleFactor() {
338 if (display::Display::HasForceDeviceScaleFactor()) 352 if (display::Display::HasForceDeviceScaleFactor())
339 return display::Display::GetForcedDeviceScaleFactor(); 353 return display::Display::GetForcedDeviceScaleFactor();
340 354
341 float scale = GetGdkWindowScalingFactor(); 355 float scale = GetScaleFromGdkScreenSettings();
342 if (scale > 0) 356 if (scale > 0)
343 return scale; 357 return scale;
344 358
345 scale = GetScaleFromXftDPI(); 359 scale = GetScaleFromXftDPI();
346 if (scale > 0) 360 if (scale > 0)
347 return scale; 361 return scale;
348 362
349 return 1; 363 return 1;
350 } 364 }
351 365
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 1087
1074 float GtkUi::GetDeviceScaleFactor() const { 1088 float GtkUi::GetDeviceScaleFactor() const {
1075 return device_scale_factor_; 1089 return device_scale_factor_;
1076 } 1090 }
1077 1091
1078 } // namespace libgtkui 1092 } // namespace libgtkui
1079 1093
1080 views::LinuxUI* BuildGtkUi() { 1094 views::LinuxUI* BuildGtkUi() {
1081 return new libgtkui::GtkUi; 1095 return new libgtkui::GtkUi;
1082 } 1096 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698