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