| 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/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.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/linux_font_delegate.h" |
| 23 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
| 24 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
| 25 #include "ui/gfx/x/x11_types.h" | 26 #include "ui/gfx/x/x11_types.h" |
| 26 #include "ui/views/widget/desktop_aura/desktop_screen.h" | 27 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
| 27 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 28 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 28 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" | 29 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // The delay to perform configuration after RRNotify. See the comment | 33 // The delay to perform configuration after RRNotify. See the comment |
| 33 // in |Dispatch()|. | 34 // in |Dispatch()|. |
| 34 const int64 kConfigureDelayMs = 500; | 35 const int64 kConfigureDelayMs = 500; |
| 35 | 36 |
| 36 // TODO(oshima): Consider using gtk-xft-dpi instead. | 37 double GetDPI() { |
| 37 float GetDeviceScaleFactor(int screen_pixels, int screen_mm) { | 38 static double dpi = -1.0; |
| 38 const int kCSSDefaultDPI = 96; | 39 if (dpi < 0.0) { |
| 39 const float kInchInMm = 25.4f; | 40 const gfx::LinuxFontDelegate* delegate = gfx::LinuxFontDelegate::instance(); |
| 41 if (delegate) |
| 42 dpi = delegate->GetFontDPI(); |
| 43 if (dpi <= 0.0) |
| 44 dpi = 96.0; |
| 45 } |
| 46 return dpi; |
| 47 } |
| 40 | 48 |
| 41 float screen_inches = screen_mm / kInchInMm; | 49 float GetGlobalDeviceScaleFactor() { |
| 42 float screen_dpi = screen_pixels / screen_inches; | 50 return GetDPI() / 96.0; |
| 43 float scale = screen_dpi / kCSSDefaultDPI; | 51 } |
| 44 | 52 |
| 45 return ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale)); | 53 // Returns the number of pixels in a point. |
| 54 // - multiply a point size by this to get pixels ("device units") |
| 55 // - divide a pixel size by this to get points |
| 56 #if 0 |
| 57 double GetPixelsInPoint() { |
| 58 static double pixels_in_point = GetDPI() / 72.0; // 72 points per inch. |
| 59 return pixels_in_point; |
| 46 } | 60 } |
| 61 #endif |
| 47 | 62 |
| 48 std::vector<gfx::Display> GetFallbackDisplayList() { | 63 std::vector<gfx::Display> GetFallbackDisplayList() { |
| 49 ::XDisplay* display = gfx::GetXDisplay(); | 64 ::XDisplay* display = gfx::GetXDisplay(); |
| 50 ::Screen* screen = DefaultScreenOfDisplay(display); | 65 ::Screen* screen = DefaultScreenOfDisplay(display); |
| 51 int width = WidthOfScreen(screen); | 66 int width = WidthOfScreen(screen); |
| 52 int height = HeightOfScreen(screen); | 67 int height = HeightOfScreen(screen); |
| 53 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen)); | 68 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen)); |
| 54 | 69 |
| 55 gfx::Rect bounds_in_pixels(0, 0, width, height); | 70 gfx::Rect bounds_in_pixels(0, 0, width, height); |
| 56 gfx::Display gfx_display(0, bounds_in_pixels); | 71 gfx::Display gfx_display(0, bounds_in_pixels); |
| 57 if (!gfx::Display::HasForceDeviceScaleFactor() && | 72 if (!gfx::Display::HasForceDeviceScaleFactor() && |
| 58 !ui::IsDisplaySizeBlackListed(physical_size)) { | 73 !ui::IsDisplaySizeBlackListed(physical_size)) { |
| 59 float device_scale_factor = GetDeviceScaleFactor( | 74 float device_scale_factor = GetGlobalDeviceScaleFactor(); |
| 60 width, physical_size.width()); | |
| 61 DCHECK_LE(1.0f, device_scale_factor); | 75 DCHECK_LE(1.0f, device_scale_factor); |
| 62 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); | 76 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); |
| 63 } | 77 } |
| 64 | 78 |
| 65 return std::vector<gfx::Display>(1, gfx_display); | 79 return std::vector<gfx::Display>(1, gfx_display); |
| 66 } | 80 } |
| 67 | 81 |
| 68 } // namespace | 82 } // namespace |
| 69 | 83 |
| 70 namespace views { | 84 namespace views { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 286 |
| 273 bool has_work_area = false; | 287 bool has_work_area = false; |
| 274 gfx::Rect work_area; | 288 gfx::Rect work_area; |
| 275 std::vector<int> value; | 289 std::vector<int> value; |
| 276 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && | 290 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && |
| 277 value.size() >= 4) { | 291 value.size() >= 4) { |
| 278 work_area = gfx::Rect(value[0], value[1], value[2], value[3]); | 292 work_area = gfx::Rect(value[0], value[1], value[2], value[3]); |
| 279 has_work_area = true; | 293 has_work_area = true; |
| 280 } | 294 } |
| 281 | 295 |
| 296 |
| 282 float device_scale_factor = 1.0f; | 297 float device_scale_factor = 1.0f; |
| 298 bool have_one = false; |
| 283 for (int i = 0; i < resources->noutput; ++i) { | 299 for (int i = 0; i < resources->noutput; ++i) { |
| 284 RROutput output_id = resources->outputs[i]; | 300 RROutput output_id = resources->outputs[i]; |
| 285 XRROutputInfo* output_info = | 301 XRROutputInfo* output_info = |
| 286 XRRGetOutputInfo(xdisplay_, resources, output_id); | 302 XRRGetOutputInfo(xdisplay_, resources, output_id); |
| 287 | 303 |
| 288 bool is_connected = (output_info->connection == RR_Connected); | 304 bool is_connected = (output_info->connection == RR_Connected); |
| 289 if (!is_connected) { | 305 if (!is_connected) { |
| 290 XRRFreeOutputInfo(output_info); | 306 XRRFreeOutputInfo(output_info); |
| 291 continue; | 307 continue; |
| 292 } | 308 } |
| 293 | 309 |
| 294 if (output_info->crtc) { | 310 if (output_info->crtc) { |
| 295 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_, | 311 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_, |
| 296 resources, | 312 resources, |
| 297 output_info->crtc); | 313 output_info->crtc); |
| 298 | 314 |
| 299 int64 display_id = -1; | 315 int64 display_id = -1; |
| 300 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) { | 316 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) { |
| 301 // It isn't ideal, but if we can't parse the EDID data, fallback on the | 317 // It isn't ideal, but if we can't parse the EDID data, fallback on the |
| 302 // display number. | 318 // display number. |
| 303 display_id = i; | 319 display_id = i; |
| 304 } | 320 } |
| 305 | 321 |
| 306 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); | 322 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); |
| 307 gfx::Display display(display_id, crtc_bounds); | 323 gfx::Display display(display_id, crtc_bounds); |
| 308 | 324 |
| 309 if (!gfx::Display::HasForceDeviceScaleFactor()) { | 325 if (!gfx::Display::HasForceDeviceScaleFactor()) { |
| 310 if (i == 0 && !ui::IsDisplaySizeBlackListed( | 326 if (!have_one && !ui::IsDisplaySizeBlackListed( |
| 311 gfx::Size(output_info->mm_width, output_info->mm_height))) { | 327 gfx::Size(output_info->mm_width, output_info->mm_height))) { |
| 312 // As per display scale factor is not supported right now, | 328 // As per display scale factor is not supported right now, |
| 313 // the primary display's scale factor is always used. | 329 // the primary display's scale factor is always used. |
| 314 device_scale_factor = GetDeviceScaleFactor(crtc->width, | 330 device_scale_factor = GetGlobalDeviceScaleFactor(); |
| 315 output_info->mm_width); | |
| 316 DCHECK_LE(1.0f, device_scale_factor); | 331 DCHECK_LE(1.0f, device_scale_factor); |
| 332 have_one = true; |
| 317 } | 333 } |
| 318 display.SetScaleAndBounds(device_scale_factor, crtc_bounds); | 334 display.SetScaleAndBounds(device_scale_factor, crtc_bounds); |
| 319 } | 335 } |
| 320 | 336 |
| 321 if (has_work_area) { | 337 if (has_work_area) { |
| 322 gfx::Rect intersection = crtc_bounds; | 338 gfx::Rect intersection = crtc_bounds; |
| 323 intersection.Intersect(work_area); | 339 intersection.Intersect(work_area); |
| 324 display.set_work_area(intersection); | 340 display.set_work_area(intersection); |
| 325 } | 341 } |
| 326 | 342 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); | 378 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); |
| 363 } | 379 } |
| 364 | 380 |
| 365 //////////////////////////////////////////////////////////////////////////////// | 381 //////////////////////////////////////////////////////////////////////////////// |
| 366 | 382 |
| 367 gfx::Screen* CreateDesktopScreen() { | 383 gfx::Screen* CreateDesktopScreen() { |
| 368 return new DesktopScreenX11; | 384 return new DesktopScreenX11; |
| 369 } | 385 } |
| 370 | 386 |
| 371 } // namespace views | 387 } // namespace views |
| OLD | NEW |