 Chromium Code Reviews
 Chromium Code Reviews Issue 27156003:
  linux_aura: Enable HIDPI support  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 27156003:
  linux_aura: Enable HIDPI support  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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/x11/edid_parser_x11.h" | 14 #include "base/x11/edid_parser_x11.h" | 
| 15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" | 
| 16 #include "ui/aura/root_window_host.h" | 16 #include "ui/aura/root_window_host.h" | 
| 17 #include "ui/base/layout.h" | |
| 17 #include "ui/base/x/x11_util.h" | 18 #include "ui/base/x/x11_util.h" | 
| 18 #include "ui/gfx/display.h" | 19 #include "ui/gfx/display.h" | 
| 19 #include "ui/gfx/display_observer.h" | 20 #include "ui/gfx/display_observer.h" | 
| 20 #include "ui/gfx/native_widget_types.h" | 21 #include "ui/gfx/native_widget_types.h" | 
| 21 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" | 
| 22 #include "ui/gfx/x/x11_types.h" | 23 #include "ui/gfx/x/x11_types.h" | 
| 23 #include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h" | 24 #include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h" | 
| 24 #include "ui/views/widget/desktop_aura/desktop_screen.h" | 25 #include "ui/views/widget/desktop_aura/desktop_screen.h" | 
| 25 | 26 | 
| 26 namespace { | 27 namespace { | 
| 27 | 28 | 
| 28 // The delay to perform configuration after RRNotify. See the comment | 29 // The delay to perform configuration after RRNotify. See the comment | 
| 29 // in |Dispatch()|. | 30 // in |Dispatch()|. | 
| 30 const int64 kConfigureDelayMs = 500; | 31 const int64 kConfigureDelayMs = 500; | 
| 31 | 32 | 
| 33 float GetDeviceScaleFactor(int screen_dim, int screen_dim_mm) { | |
| 34 const int kCSSPixelsPerInch = 96; | |
| 
kenneth.r.christiansen
2013/10/14 08:20:54
kDefaultCSSPixelsPerInch ?
 
Mikhail
2013/10/14 09:15:52
Yeah, I would even say kDefaultDIPPerInch to be mo
 | |
| 35 const float kMillimetersPerInch = 25.4f; | |
| 36 float screen_DPI = (screen_dim * kMillimetersPerInch) | |
| 37 / screen_dim_mm; | |
| 38 | |
| 39 float scale = screen_DPI / kCSSPixelsPerInch; | |
| 40 | |
| 41 return ui::GetImageScale(ui::GetSupportedScaleFactor(scale)); | |
| 42 } | |
| 43 | |
| 32 std::vector<gfx::Display> GetFallbackDisplayList() { | 44 std::vector<gfx::Display> GetFallbackDisplayList() { | 
| 33 ::XDisplay* display = gfx::GetXDisplay(); | 45 ::XDisplay* display = gfx::GetXDisplay(); | 
| 34 ::Screen* screen = DefaultScreenOfDisplay(display); | 46 ::Screen* screen = DefaultScreenOfDisplay(display); | 
| 35 int width = WidthOfScreen(screen); | 47 int width = WidthOfScreen(screen); | 
| 36 int height = HeightOfScreen(screen); | 48 int height = HeightOfScreen(screen); | 
| 37 | 49 | 
| 38 return std::vector<gfx::Display>( | 50 gfx::Rect bounds_in_pixels(0, 0, width, height); | 
| 
kenneth.r.christiansen
2013/10/14 08:20:54
device pixels? or css pixels? not obvious
 
Mikhail
2013/10/14 09:15:52
Device pixels. From what I saw postfix "_in_pixels
 | |
| 39 1, gfx::Display(0, gfx::Rect(0, 0, width, height))); | 51 gfx::Display gfx_display(0, bounds_in_pixels); | 
| 
kenneth.r.christiansen
2013/10/14 08:20:54
Why are we assuming screen 0 here?
 
Mikhail
2013/10/14 09:15:52
Guess, this is just a fallback display number. Any
 | |
| 52 if (!gfx::Display::HasForceDeviceScaleFactor()) { | |
| 53 float device_scale_factor = GetDeviceScaleFactor(width, | |
| 54 WidthMMOfScreen(screen)); | |
| 55 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); | |
| 56 } | |
| 57 | |
| 58 return std::vector<gfx::Display>(1, gfx_display); | |
| 40 } | 59 } | 
| 41 | 60 | 
| 42 } // namespace | 61 } // namespace | 
| 43 | 62 | 
| 44 namespace views { | 63 namespace views { | 
| 45 | 64 | 
| 46 //////////////////////////////////////////////////////////////////////////////// | 65 //////////////////////////////////////////////////////////////////////////////// | 
| 47 // DesktopScreenX11, public: | 66 // DesktopScreenX11, public: | 
| 48 | 67 | 
| 49 DesktopScreenX11::DesktopScreenX11() | 68 DesktopScreenX11::DesktopScreenX11() | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 } | 140 } | 
| 122 } | 141 } | 
| 123 | 142 | 
| 124 displays_ = incoming; | 143 displays_ = incoming; | 
| 125 } | 144 } | 
| 126 | 145 | 
| 127 //////////////////////////////////////////////////////////////////////////////// | 146 //////////////////////////////////////////////////////////////////////////////// | 
| 128 // DesktopScreenX11, gfx::Screen implementation: | 147 // DesktopScreenX11, gfx::Screen implementation: | 
| 129 | 148 | 
| 130 bool DesktopScreenX11::IsDIPEnabled() { | 149 bool DesktopScreenX11::IsDIPEnabled() { | 
| 131 return false; | 150 return true; | 
| 132 } | 151 } | 
| 133 | 152 | 
| 134 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { | 153 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { | 
| 135 XDisplay* display = gfx::GetXDisplay(); | 154 XDisplay* display = gfx::GetXDisplay(); | 
| 136 | 155 | 
| 137 ::Window root, child; | 156 ::Window root, child; | 
| 138 int root_x, root_y, win_x, win_y; | 157 int root_x, root_y, win_x, win_y; | 
| 139 unsigned int mask; | 158 unsigned int mask; | 
| 140 XQueryPointer(display, | 159 XQueryPointer(display, | 
| 141 DefaultRootWindow(display), | 160 DefaultRootWindow(display), | 
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 | 329 | 
| 311 int64 display_id = -1; | 330 int64 display_id = -1; | 
| 312 if (!base::GetDisplayId(output_id, i, &display_id)) { | 331 if (!base::GetDisplayId(output_id, i, &display_id)) { | 
| 313 // It isn't ideal, but if we can't parse the EDID data, fallback on the | 332 // It isn't ideal, but if we can't parse the EDID data, fallback on the | 
| 314 // display number. | 333 // display number. | 
| 315 display_id = i; | 334 display_id = i; | 
| 316 } | 335 } | 
| 317 | 336 | 
| 318 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); | 337 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); | 
| 319 gfx::Display display(display_id, crtc_bounds); | 338 gfx::Display display(display_id, crtc_bounds); | 
| 339 | |
| 340 if (!gfx::Display::HasForceDeviceScaleFactor()) { | |
| 341 float device_scale_factor = GetDeviceScaleFactor(crtc->width, | |
| 342 output_info->mm_width); | |
| 343 display.SetScaleAndBounds(device_scale_factor, crtc_bounds); | |
| 344 } | |
| 345 | |
| 320 if (has_work_area) { | 346 if (has_work_area) { | 
| 321 gfx::Rect intersection = crtc_bounds; | 347 gfx::Rect intersection = crtc_bounds; | 
| 322 intersection.Intersect(work_area); | 348 intersection.Intersect(work_area); | 
| 323 display.set_work_area(intersection); | 349 display.set_work_area(intersection); | 
| 324 } | 350 } | 
| 325 | 351 | 
| 326 displays.push_back(display); | 352 displays.push_back(display); | 
| 327 | 353 | 
| 328 XRRFreeCrtcInfo(crtc); | 354 XRRFreeCrtcInfo(crtc); | 
| 329 } | 355 } | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 344 ProcessDisplayChange(new_displays); | 370 ProcessDisplayChange(new_displays); | 
| 345 } | 371 } | 
| 346 | 372 | 
| 347 //////////////////////////////////////////////////////////////////////////////// | 373 //////////////////////////////////////////////////////////////////////////////// | 
| 348 | 374 | 
| 349 gfx::Screen* CreateDesktopScreen() { | 375 gfx::Screen* CreateDesktopScreen() { | 
| 350 return new DesktopScreenX11; | 376 return new DesktopScreenX11; | 
| 351 } | 377 } | 
| 352 | 378 | 
| 353 } // namespace views | 379 } // namespace views | 
| OLD | NEW |