OLD | NEW |
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" | |
29 #include "ui/views/widget/desktop_aura/desktop_screen.h" | 28 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
30 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 29 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
31 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" | 30 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" |
32 | 31 |
33 namespace { | 32 namespace { |
34 | 33 |
35 // The delay to perform configuration after RRNotify. See the comment | 34 // The delay to perform configuration after RRNotify. See the comment |
36 // in |Dispatch()|. | 35 // in |Dispatch()|. |
37 const int64 kConfigureDelayMs = 500; | 36 const int64 kConfigureDelayMs = 500; |
38 | 37 |
39 double GetDeviceScaleFactor() { | 38 // TODO(oshima): Consider using gtk-xft-dpi instead. |
40 float device_scale_factor = 1.0f; | 39 float GetDeviceScaleFactor(int screen_pixels, int screen_mm) { |
41 if (views::LinuxUI::instance()) | 40 const int kCSSDefaultDPI = 96; |
42 device_scale_factor = | 41 const float kInchInMm = 25.4f; |
43 views::LinuxUI::instance()->GetDeviceScaleFactor(); | 42 |
44 return device_scale_factor; | 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(); |
45 } | 53 } |
46 | 54 |
47 gfx::Point PixelToDIPPoint(const gfx::Point& pixel_point) { | 55 gfx::Point PixelToDIPPoint(const gfx::Point& pixel_point) { |
48 return ToFlooredPoint(ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); | 56 return ToFlooredPoint(ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); |
49 } | 57 } |
50 | 58 |
51 gfx::Point DIPToPixelPoint(const gfx::Point& dip_point) { | 59 gfx::Point DIPToPixelPoint(const gfx::Point& dip_point) { |
52 return ToFlooredPoint(gfx::ScalePoint(dip_point, GetDeviceScaleFactor())); | 60 return ToFlooredPoint(gfx::ScalePoint(dip_point, GetDeviceScaleFactor())); |
53 } | 61 } |
54 | 62 |
55 std::vector<gfx::Display> GetFallbackDisplayList() { | 63 std::vector<gfx::Display> GetFallbackDisplayList() { |
56 ::XDisplay* display = gfx::GetXDisplay(); | 64 ::XDisplay* display = gfx::GetXDisplay(); |
57 ::Screen* screen = DefaultScreenOfDisplay(display); | 65 ::Screen* screen = DefaultScreenOfDisplay(display); |
58 int width = WidthOfScreen(screen); | 66 int width = WidthOfScreen(screen); |
59 int height = HeightOfScreen(screen); | 67 int height = HeightOfScreen(screen); |
60 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen)); | 68 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen)); |
61 | 69 |
62 gfx::Rect bounds_in_pixels(0, 0, width, height); | 70 gfx::Rect bounds_in_pixels(0, 0, width, height); |
63 gfx::Display gfx_display(0, bounds_in_pixels); | 71 gfx::Display gfx_display(0, bounds_in_pixels); |
64 if (!gfx::Display::HasForceDeviceScaleFactor() && | 72 if (!gfx::Display::HasForceDeviceScaleFactor() && |
65 !ui::IsDisplaySizeBlackListed(physical_size)) { | 73 !ui::IsDisplaySizeBlackListed(physical_size)) { |
66 const float device_scale_factor = GetDeviceScaleFactor(); | 74 float device_scale_factor = GetDeviceScaleFactor( |
| 75 width, physical_size.width()); |
67 DCHECK_LE(1.0f, device_scale_factor); | 76 DCHECK_LE(1.0f, device_scale_factor); |
68 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); | 77 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); |
69 } | 78 } |
70 | 79 |
71 return std::vector<gfx::Display>(1, gfx_display); | 80 return std::vector<gfx::Display>(1, gfx_display); |
72 } | 81 } |
73 | 82 |
74 } // namespace | 83 } // namespace |
75 | 84 |
76 namespace views { | 85 namespace views { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 287 |
279 bool has_work_area = false; | 288 bool has_work_area = false; |
280 gfx::Rect work_area_in_pixels; | 289 gfx::Rect work_area_in_pixels; |
281 std::vector<int> value; | 290 std::vector<int> value; |
282 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && | 291 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && |
283 value.size() >= 4) { | 292 value.size() >= 4) { |
284 work_area_in_pixels = gfx::Rect(value[0], value[1], value[2], value[3]); | 293 work_area_in_pixels = gfx::Rect(value[0], value[1], value[2], value[3]); |
285 has_work_area = true; | 294 has_work_area = true; |
286 } | 295 } |
287 | 296 |
288 // As per-display scale factor is not supported right now, | 297 float device_scale_factor = 1.0f; |
289 // the X11 root window's scale factor is always used. | |
290 const float device_scale_factor = | |
291 views::LinuxUI::instance()->GetDeviceScaleFactor(); | |
292 for (int i = 0; i < resources->noutput; ++i) { | 298 for (int i = 0; i < resources->noutput; ++i) { |
293 RROutput output_id = resources->outputs[i]; | 299 RROutput output_id = resources->outputs[i]; |
294 gfx::XScopedPtr<XRROutputInfo, | 300 gfx::XScopedPtr<XRROutputInfo, |
295 gfx::XObjectDeleter<XRROutputInfo, void, XRRFreeOutputInfo>> | 301 gfx::XObjectDeleter<XRROutputInfo, void, XRRFreeOutputInfo>> |
296 output_info(XRRGetOutputInfo(xdisplay_, resources.get(), output_id)); | 302 output_info(XRRGetOutputInfo(xdisplay_, resources.get(), output_id)); |
297 | 303 |
298 bool is_connected = (output_info->connection == RR_Connected); | 304 bool is_connected = (output_info->connection == RR_Connected); |
299 if (!is_connected) | 305 if (!is_connected) |
300 continue; | 306 continue; |
301 | 307 |
302 if (output_info->crtc) { | 308 if (output_info->crtc) { |
303 gfx::XScopedPtr<XRRCrtcInfo, | 309 gfx::XScopedPtr<XRRCrtcInfo, |
304 gfx::XObjectDeleter<XRRCrtcInfo, void, XRRFreeCrtcInfo>> | 310 gfx::XObjectDeleter<XRRCrtcInfo, void, XRRFreeCrtcInfo>> |
305 crtc(XRRGetCrtcInfo(xdisplay_, resources.get(), output_info->crtc)); | 311 crtc(XRRGetCrtcInfo(xdisplay_, resources.get(), output_info->crtc)); |
306 | 312 |
307 int64 display_id = -1; | 313 int64 display_id = -1; |
308 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) { | 314 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) { |
309 // It isn't ideal, but if we can't parse the EDID data, fallback on the | 315 // It isn't ideal, but if we can't parse the EDID data, fallback on the |
310 // display number. | 316 // display number. |
311 display_id = i; | 317 display_id = i; |
312 } | 318 } |
313 | 319 |
314 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); | 320 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); |
315 gfx::Display display(display_id, crtc_bounds); | 321 gfx::Display display(display_id, crtc_bounds); |
316 | 322 |
317 if (!gfx::Display::HasForceDeviceScaleFactor()) { | 323 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 } |
318 display.SetScaleAndBounds(device_scale_factor, crtc_bounds); | 332 display.SetScaleAndBounds(device_scale_factor, crtc_bounds); |
319 } | 333 } |
320 | 334 |
321 if (has_work_area) { | 335 if (has_work_area) { |
322 gfx::Rect intersection_in_pixels = crtc_bounds; | 336 gfx::Rect intersection_in_pixels = crtc_bounds; |
323 intersection_in_pixels.Intersect(work_area_in_pixels); | 337 intersection_in_pixels.Intersect(work_area_in_pixels); |
324 // SetScaleAndBounds() above does the conversion from pixels to DIP for | 338 // SetScaleAndBounds() above does the conversion from pixels to DIP for |
325 // us, but set_work_area does not, so we need to do it here. | 339 // us, but set_work_area does not, so we need to do it here. |
326 display.set_work_area(gfx::Rect( | 340 display.set_work_area(gfx::Rect( |
327 gfx::ToFlooredPoint( | 341 gfx::ToFlooredPoint( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); | 378 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); |
365 } | 379 } |
366 | 380 |
367 //////////////////////////////////////////////////////////////////////////////// | 381 //////////////////////////////////////////////////////////////////////////////// |
368 | 382 |
369 gfx::Screen* CreateDesktopScreen() { | 383 gfx::Screen* CreateDesktopScreen() { |
370 return new DesktopScreenX11; | 384 return new DesktopScreenX11; |
371 } | 385 } |
372 | 386 |
373 } // namespace views | 387 } // namespace views |
OLD | NEW |