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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_screen_x11.cc

Issue 1070433002: device scale factor detection: use gtk-xft-dpi consistently (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: device scale factor detection: always use X11 root window’s dpi Created 5 years, 8 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
« ui/views/linux_ui/linux_ui.h ('K') | « ui/views/linux_ui/linux_ui.h ('k') | 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 "ui/views/widget/desktop_aura/desktop_screen_x11.h" 5 #include "ui/views/widget/desktop_aura/desktop_screen_x11.h"
6 6
7 #include <X11/extensions/Xrandr.h> 7 #include <X11/extensions/Xrandr.h>
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 9
10 // It clashes with out RootWindow. 10 // It clashes with out RootWindow.
11 #undef RootWindow 11 #undef RootWindow
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h" 16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/aura/window_tree_host.h" 17 #include "ui/aura/window_tree_host.h"
18 #include "ui/base/layout.h" 18 #include "ui/base/layout.h"
19 #include "ui/display/util/display_util.h" 19 #include "ui/display/util/display_util.h"
20 #include "ui/display/util/x11/edid_parser_x11.h" 20 #include "ui/display/util/x11/edid_parser_x11.h"
21 #include "ui/events/platform/platform_event_source.h" 21 #include "ui/events/platform/platform_event_source.h"
22 #include "ui/gfx/display.h" 22 #include "ui/gfx/display.h"
23 #include "ui/gfx/geometry/point_conversions.h" 23 #include "ui/gfx/geometry/point_conversions.h"
24 #include "ui/gfx/geometry/size_conversions.h" 24 #include "ui/gfx/geometry/size_conversions.h"
25 #include "ui/gfx/native_widget_types.h" 25 #include "ui/gfx/native_widget_types.h"
26 #include "ui/gfx/screen.h" 26 #include "ui/gfx/screen.h"
27 #include "ui/gfx/x/x11_types.h" 27 #include "ui/gfx/x/x11_types.h"
28 #include "ui/views/linux_ui/linux_ui.h"
28 #include "ui/views/widget/desktop_aura/desktop_screen.h" 29 #include "ui/views/widget/desktop_aura/desktop_screen.h"
29 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" 30 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
30 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" 31 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h"
31 32
32 namespace { 33 namespace {
33 34
34 // The delay to perform configuration after RRNotify. See the comment 35 // The delay to perform configuration after RRNotify. See the comment
35 // in |Dispatch()|. 36 // in |Dispatch()|.
36 const int64 kConfigureDelayMs = 500; 37 const int64 kConfigureDelayMs = 500;
37 38
38 // TODO(oshima): Consider using gtk-xft-dpi instead.
39 float GetDeviceScaleFactor(int screen_pixels, int screen_mm) {
40 const int kCSSDefaultDPI = 96;
41 const float kInchInMm = 25.4f;
42
43 float screen_inches = screen_mm / kInchInMm;
44 float screen_dpi = screen_pixels / screen_inches;
45 float scale = screen_dpi / kCSSDefaultDPI;
46
47 return ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale));
48 }
49
50 float GetDeviceScaleFactor() {
51 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
52 return display.device_scale_factor();
53 }
54
55 gfx::Point PixelToDIPPoint(const gfx::Point& pixel_point) { 39 gfx::Point PixelToDIPPoint(const gfx::Point& pixel_point) {
56 return ToFlooredPoint(ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); 40 return ToFlooredPoint(ScalePoint(pixel_point,
41 1.0f / views::LinuxUI::instance()->GetDeviceScaleFactor()));
57 } 42 }
58 43
59 gfx::Point DIPToPixelPoint(const gfx::Point& dip_point) { 44 gfx::Point DIPToPixelPoint(const gfx::Point& dip_point) {
60 return ToFlooredPoint(gfx::ScalePoint(dip_point, GetDeviceScaleFactor())); 45 return ToFlooredPoint(gfx::ScalePoint(dip_point,
46 views::LinuxUI::instance()->GetDeviceScaleFactor()));
61 } 47 }
62 48
63 std::vector<gfx::Display> GetFallbackDisplayList() { 49 std::vector<gfx::Display> GetFallbackDisplayList() {
64 ::XDisplay* display = gfx::GetXDisplay(); 50 ::XDisplay* display = gfx::GetXDisplay();
65 ::Screen* screen = DefaultScreenOfDisplay(display); 51 ::Screen* screen = DefaultScreenOfDisplay(display);
66 int width = WidthOfScreen(screen); 52 int width = WidthOfScreen(screen);
67 int height = HeightOfScreen(screen); 53 int height = HeightOfScreen(screen);
68 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen)); 54 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen));
69 55
70 gfx::Rect bounds_in_pixels(0, 0, width, height); 56 gfx::Rect bounds_in_pixels(0, 0, width, height);
71 gfx::Display gfx_display(0, bounds_in_pixels); 57 gfx::Display gfx_display(0, bounds_in_pixels);
72 if (!gfx::Display::HasForceDeviceScaleFactor() && 58 if (!gfx::Display::HasForceDeviceScaleFactor() &&
73 !ui::IsDisplaySizeBlackListed(physical_size)) { 59 !ui::IsDisplaySizeBlackListed(physical_size)) {
74 float device_scale_factor = GetDeviceScaleFactor( 60 float device_scale_factor =
75 width, physical_size.width()); 61 views::LinuxUI::instance()->GetDeviceScaleFactor();
76 DCHECK_LE(1.0f, device_scale_factor); 62 DCHECK_LE(1.0f, device_scale_factor);
77 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); 63 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels);
78 } 64 }
79 65
80 return std::vector<gfx::Display>(1, gfx_display); 66 return std::vector<gfx::Display>(1, gfx_display);
81 } 67 }
82 68
83 } // namespace 69 } // namespace
84 70
85 namespace views { 71 namespace views {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 bool has_work_area = false; 274 bool has_work_area = false;
289 gfx::Rect work_area_in_pixels; 275 gfx::Rect work_area_in_pixels;
290 std::vector<int> value; 276 std::vector<int> value;
291 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && 277 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) &&
292 value.size() >= 4) { 278 value.size() >= 4) {
293 work_area_in_pixels = gfx::Rect(value[0], value[1], value[2], value[3]); 279 work_area_in_pixels = gfx::Rect(value[0], value[1], value[2], value[3]);
294 has_work_area = true; 280 has_work_area = true;
295 } 281 }
296 282
297 float device_scale_factor = 1.0f; 283 float device_scale_factor = 1.0f;
284 {
Elliot Glaysher 2015/04/09 16:47:27 Is there a reason this is in a block instead of ju
stapelberg 2015/04/09 18:11:29 Done.
285 // As per-display scale factor is not supported right now,
286 // the X11 root window's scale factor is always used.
287 device_scale_factor = views::LinuxUI::instance()->GetDeviceScaleFactor();
288 }
298 for (int i = 0; i < resources->noutput; ++i) { 289 for (int i = 0; i < resources->noutput; ++i) {
299 RROutput output_id = resources->outputs[i]; 290 RROutput output_id = resources->outputs[i];
300 gfx::XScopedPtr<XRROutputInfo, 291 gfx::XScopedPtr<XRROutputInfo,
301 gfx::XObjectDeleter<XRROutputInfo, void, XRRFreeOutputInfo>> 292 gfx::XObjectDeleter<XRROutputInfo, void, XRRFreeOutputInfo>>
302 output_info(XRRGetOutputInfo(xdisplay_, resources.get(), output_id)); 293 output_info(XRRGetOutputInfo(xdisplay_, resources.get(), output_id));
303 294
304 bool is_connected = (output_info->connection == RR_Connected); 295 bool is_connected = (output_info->connection == RR_Connected);
305 if (!is_connected) 296 if (!is_connected)
306 continue; 297 continue;
307 298
308 if (output_info->crtc) { 299 if (output_info->crtc) {
309 gfx::XScopedPtr<XRRCrtcInfo, 300 gfx::XScopedPtr<XRRCrtcInfo,
310 gfx::XObjectDeleter<XRRCrtcInfo, void, XRRFreeCrtcInfo>> 301 gfx::XObjectDeleter<XRRCrtcInfo, void, XRRFreeCrtcInfo>>
311 crtc(XRRGetCrtcInfo(xdisplay_, resources.get(), output_info->crtc)); 302 crtc(XRRGetCrtcInfo(xdisplay_, resources.get(), output_info->crtc));
312 303
313 int64 display_id = -1; 304 int64 display_id = -1;
314 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) { 305 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) {
315 // It isn't ideal, but if we can't parse the EDID data, fallback on the 306 // It isn't ideal, but if we can't parse the EDID data, fallback on the
316 // display number. 307 // display number.
317 display_id = i; 308 display_id = i;
318 } 309 }
319 310
320 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); 311 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height);
321 gfx::Display display(display_id, crtc_bounds); 312 gfx::Display display(display_id, crtc_bounds);
322 313
323 if (!gfx::Display::HasForceDeviceScaleFactor()) { 314 if (!gfx::Display::HasForceDeviceScaleFactor()) {
324 if (i == 0 && !ui::IsDisplaySizeBlackListed(
325 gfx::Size(output_info->mm_width, output_info->mm_height))) {
326 // As per display scale factor is not supported right now,
327 // the primary display's scale factor is always used.
328 device_scale_factor = GetDeviceScaleFactor(crtc->width,
329 output_info->mm_width);
330 DCHECK_LE(1.0f, device_scale_factor);
331 }
332 display.SetScaleAndBounds(device_scale_factor, crtc_bounds); 315 display.SetScaleAndBounds(device_scale_factor, crtc_bounds);
333 } 316 }
334 317
335 if (has_work_area) { 318 if (has_work_area) {
336 gfx::Rect intersection_in_pixels = crtc_bounds; 319 gfx::Rect intersection_in_pixels = crtc_bounds;
337 intersection_in_pixels.Intersect(work_area_in_pixels); 320 intersection_in_pixels.Intersect(work_area_in_pixels);
338 // SetScaleAndBounds() above does the conversion from pixels to DIP for 321 // SetScaleAndBounds() above does the conversion from pixels to DIP for
339 // us, but set_work_area does not, so we need to do it here. 322 // us, but set_work_area does not, so we need to do it here.
340 display.set_work_area(gfx::Rect( 323 display.set_work_area(gfx::Rect(
341 gfx::ToFlooredPoint( 324 gfx::ToFlooredPoint(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); 361 change_notifier_.NotifyDisplaysChanged(old_displays, displays_);
379 } 362 }
380 363
381 //////////////////////////////////////////////////////////////////////////////// 364 ////////////////////////////////////////////////////////////////////////////////
382 365
383 gfx::Screen* CreateDesktopScreen() { 366 gfx::Screen* CreateDesktopScreen() {
384 return new DesktopScreenX11; 367 return new DesktopScreenX11;
385 } 368 }
386 369
387 } // namespace views 370 } // namespace views
OLDNEW
« ui/views/linux_ui/linux_ui.h ('K') | « ui/views/linux_ui/linux_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698