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

Unified Diff: ui/views/widget/desktop_aura/desktop_screen_x11.cc

Issue 659883002: Enable hidpi on Linux, refactor a bit on Windows to share Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: delete some printfs Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/widget/desktop_aura/desktop_screen_x11.cc
diff --git a/ui/views/widget/desktop_aura/desktop_screen_x11.cc b/ui/views/widget/desktop_aura/desktop_screen_x11.cc
index bb253cff17ce48e6295bbee89574a874f5733462..9ee607323ebe12bf6a1a7e0930499f27e0ffff82 100644
--- a/ui/views/widget/desktop_aura/desktop_screen_x11.cc
+++ b/ui/views/widget/desktop_aura/desktop_screen_x11.cc
@@ -20,6 +20,7 @@
#include "ui/display/util/x11/edid_parser_x11.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/display.h"
+#include "ui/gfx/linux_font_delegate.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/x/x11_types.h"
@@ -33,17 +34,31 @@ namespace {
// in |Dispatch()|.
const int64 kConfigureDelayMs = 500;
-// TODO(oshima): Consider using gtk-xft-dpi instead.
-float GetDeviceScaleFactor(int screen_pixels, int screen_mm) {
- const int kCSSDefaultDPI = 96;
- const float kInchInMm = 25.4f;
+double GetDPI() {
+ static double dpi = -1.0;
+ if (dpi < 0.0) {
+ const gfx::LinuxFontDelegate* delegate = gfx::LinuxFontDelegate::instance();
+ if (delegate)
+ dpi = delegate->GetFontDPI();
+ if (dpi <= 0.0)
+ dpi = 96.0;
+ }
+ return dpi;
+}
- float screen_inches = screen_mm / kInchInMm;
- float screen_dpi = screen_pixels / screen_inches;
- float scale = screen_dpi / kCSSDefaultDPI;
+float GetGlobalDeviceScaleFactor() {
+ return GetDPI() / 96.0;
+}
- return ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale));
+// Returns the number of pixels in a point.
+// - multiply a point size by this to get pixels ("device units")
+// - divide a pixel size by this to get points
+#if 0
+double GetPixelsInPoint() {
+ static double pixels_in_point = GetDPI() / 72.0; // 72 points per inch.
+ return pixels_in_point;
}
+#endif
std::vector<gfx::Display> GetFallbackDisplayList() {
::XDisplay* display = gfx::GetXDisplay();
@@ -56,8 +71,7 @@ std::vector<gfx::Display> GetFallbackDisplayList() {
gfx::Display gfx_display(0, bounds_in_pixels);
if (!gfx::Display::HasForceDeviceScaleFactor() &&
!ui::IsDisplaySizeBlackListed(physical_size)) {
- float device_scale_factor = GetDeviceScaleFactor(
- width, physical_size.width());
+ float device_scale_factor = GetGlobalDeviceScaleFactor();
DCHECK_LE(1.0f, device_scale_factor);
gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels);
}
@@ -279,7 +293,9 @@ std::vector<gfx::Display> DesktopScreenX11::BuildDisplaysFromXRandRInfo() {
has_work_area = true;
}
+
float device_scale_factor = 1.0f;
+ bool have_one = false;
for (int i = 0; i < resources->noutput; ++i) {
RROutput output_id = resources->outputs[i];
XRROutputInfo* output_info =
@@ -307,13 +323,13 @@ std::vector<gfx::Display> DesktopScreenX11::BuildDisplaysFromXRandRInfo() {
gfx::Display display(display_id, crtc_bounds);
if (!gfx::Display::HasForceDeviceScaleFactor()) {
- if (i == 0 && !ui::IsDisplaySizeBlackListed(
+ if (!have_one && !ui::IsDisplaySizeBlackListed(
gfx::Size(output_info->mm_width, output_info->mm_height))) {
// As per display scale factor is not supported right now,
// the primary display's scale factor is always used.
- device_scale_factor = GetDeviceScaleFactor(crtc->width,
- output_info->mm_width);
+ device_scale_factor = GetGlobalDeviceScaleFactor();
DCHECK_LE(1.0f, device_scale_factor);
+ have_one = true;
}
display.SetScaleAndBounds(device_scale_factor, crtc_bounds);
}

Powered by Google App Engine
This is Rietveld 408576698