Chromium Code Reviews| 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 g_device_scale_factor = 1.0f; | |
| 34 | |
| 35 // A list of bogus sizes in mm that X detects that should be ignored. | |
| 36 // See crbug.com/136533. The first element maintains the minimum | |
| 37 // size required to be valid size. | |
| 38 // (Taken from ash/display/display_change_observer_chromeos.cc) | |
| 39 const unsigned long kInvalidDisplaySizeList[][2] = { | |
| 40 {40, 30}, | |
| 41 {50, 40}, | |
| 42 {160, 90}, | |
| 43 {160, 100}, | |
| 44 }; | |
| 45 | |
| 46 bool ShouldIgnoreScreen(unsigned long mm_width, unsigned long mm_height) { | |
| 47 // Ignore if the reported display is smaller than minimum size. | |
| 48 if (mm_width <= kInvalidDisplaySizeList[0][0] || | |
| 49 mm_height <= kInvalidDisplaySizeList[0][1]) { | |
| 50 LOG(WARNING) << "Smaller than minimum display size"; | |
| 51 return true; | |
| 52 } | |
| 53 for (unsigned long i = 1 ; i < arraysize(kInvalidDisplaySizeList); ++i) { | |
| 54 const unsigned long* size = kInvalidDisplaySizeList[i]; | |
| 55 if (mm_width == size[0] && mm_height == size[1]) { | |
| 56 LOG(WARNING) << "Black listed display size detected:" | |
| 57 << size[0] << "x" << size[1]; | |
| 58 return true; | |
| 59 } | |
| 60 } | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 inline void InitDeviceScaleFactor(float scale) { | |
| 65 DCHECK_NE(0.0f, scale); | |
|
oshima
2013/10/22 05:35:10
scale must be larger than 1.0f
DCHECK_LE(1.0f, sc
Mikhail
2013/10/23 17:15:02
I've done it just to enforce DCHECK, but we surely
| |
| 66 g_device_scale_factor = scale; | |
| 67 } | |
| 68 | |
| 69 void InitDeviceScaleFactorFromScreenDim(int screen_dim, int mm_screen_dim) { | |
|
oshima
2013/10/22 05:35:10
....ScreenDimension
| |
| 70 const int kCSSDefaultDIPCountPerInch = 96; | |
| 71 const float kInchInMm = 25.4f; | |
| 72 | |
| 73 float screen_DPI = (screen_dim * kInchInMm) / mm_screen_dim; | |
| 74 float scale = screen_DPI / kCSSDefaultDIPCountPerInch; | |
| 75 | |
| 76 InitDeviceScaleFactor(ui::GetImageScale(ui::GetSupportedScaleFactor(scale))); | |
| 77 } | |
| 78 | |
| 79 inline float GetDeviceScaleFactor() { | |
| 80 DCHECK_NE(0.0f, g_device_scale_factor); | |
|
oshima
2013/10/22 05:35:10
ditto. nuke "inline"
| |
| 81 return g_device_scale_factor; | |
| 82 } | |
| 83 | |
| 32 std::vector<gfx::Display> GetFallbackDisplayList() { | 84 std::vector<gfx::Display> GetFallbackDisplayList() { |
| 33 ::XDisplay* display = gfx::GetXDisplay(); | 85 ::XDisplay* display = gfx::GetXDisplay(); |
| 34 ::Screen* screen = DefaultScreenOfDisplay(display); | 86 ::Screen* screen = DefaultScreenOfDisplay(display); |
| 35 int width = WidthOfScreen(screen); | 87 int width = WidthOfScreen(screen); |
| 36 int height = HeightOfScreen(screen); | 88 int height = HeightOfScreen(screen); |
| 89 int mm_width = WidthMMOfScreen(screen); | |
| 90 int mm_height = HeightMMOfScreen(screen); | |
| 37 | 91 |
| 38 return std::vector<gfx::Display>( | 92 gfx::Rect bounds_in_pixels(0, 0, width, height); |
| 39 1, gfx::Display(0, gfx::Rect(0, 0, width, height))); | 93 gfx::Display gfx_display(0, bounds_in_pixels); |
| 94 if (!gfx::Display::HasForceDeviceScaleFactor() | |
| 95 && !ShouldIgnoreScreen(mm_width, mm_height)) { | |
| 96 InitDeviceScaleFactorFromScreenDim(width, mm_width); | |
| 97 gfx_display.SetScaleAndBounds(GetDeviceScaleFactor(), bounds_in_pixels); | |
| 98 } | |
| 99 | |
| 100 return std::vector<gfx::Display>(1, gfx_display); | |
| 40 } | 101 } |
| 41 | 102 |
| 42 } // namespace | 103 } // namespace |
| 43 | 104 |
| 44 namespace views { | 105 namespace views { |
| 45 | 106 |
| 46 //////////////////////////////////////////////////////////////////////////////// | 107 //////////////////////////////////////////////////////////////////////////////// |
| 47 // DesktopScreenX11, public: | 108 // DesktopScreenX11, public: |
| 48 | 109 |
| 49 DesktopScreenX11::DesktopScreenX11() | 110 DesktopScreenX11::DesktopScreenX11() |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 } | 182 } |
| 122 } | 183 } |
| 123 | 184 |
| 124 displays_ = incoming; | 185 displays_ = incoming; |
| 125 } | 186 } |
| 126 | 187 |
| 127 //////////////////////////////////////////////////////////////////////////////// | 188 //////////////////////////////////////////////////////////////////////////////// |
| 128 // DesktopScreenX11, gfx::Screen implementation: | 189 // DesktopScreenX11, gfx::Screen implementation: |
| 129 | 190 |
| 130 bool DesktopScreenX11::IsDIPEnabled() { | 191 bool DesktopScreenX11::IsDIPEnabled() { |
| 131 return false; | 192 return true; |
| 132 } | 193 } |
| 133 | 194 |
| 134 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { | 195 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { |
| 135 XDisplay* display = gfx::GetXDisplay(); | 196 XDisplay* display = gfx::GetXDisplay(); |
| 136 | 197 |
| 137 ::Window root, child; | 198 ::Window root, child; |
| 138 int root_x, root_y, win_x, win_y; | 199 int root_x, root_y, win_x, win_y; |
| 139 unsigned int mask; | 200 unsigned int mask; |
| 140 XQueryPointer(display, | 201 XQueryPointer(display, |
| 141 DefaultRootWindow(display), | 202 DefaultRootWindow(display), |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 | 371 |
| 311 int64 display_id = -1; | 372 int64 display_id = -1; |
| 312 if (!base::GetDisplayId(output_id, i, &display_id)) { | 373 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 | 374 // It isn't ideal, but if we can't parse the EDID data, fallback on the |
| 314 // display number. | 375 // display number. |
| 315 display_id = i; | 376 display_id = i; |
| 316 } | 377 } |
| 317 | 378 |
| 318 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); | 379 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); |
| 319 gfx::Display display(display_id, crtc_bounds); | 380 gfx::Display display(display_id, crtc_bounds); |
| 381 | |
| 382 if (!gfx::Display::HasForceDeviceScaleFactor()) { | |
| 383 if ((i == 0) // Primary display. | |
| 384 && !ShouldIgnoreScreen(output_info->mm_width, output_info->mm_height )) { | |
|
oshima
2013/10/22 05:35:10
if (i == 0 &&
!....
| |
| 385 // As Aura does not support per display scale factor right now, | |
|
oshima
2013/10/22 05:35:10
desktop aura does not support ...
I believe this
| |
| 386 // the primary display's scale factor is always used. | |
| 387 InitDeviceScaleFactorFromScreenDim(crtc->width, output_info->mm_width) ; | |
|
oshima
2013/10/22 05:35:10
indent
You may just want to pass crtc/output_info
Mikhail
2013/10/23 17:15:02
This function is also used from GetFallbackDisplay
| |
| 388 } | |
| 389 | |
| 390 display.SetScaleAndBounds(GetDeviceScaleFactor(), crtc_bounds); | |
| 391 } | |
| 392 | |
| 320 if (has_work_area) { | 393 if (has_work_area) { |
| 321 gfx::Rect intersection = crtc_bounds; | 394 gfx::Rect intersection = crtc_bounds; |
| 322 intersection.Intersect(work_area); | 395 intersection.Intersect(work_area); |
| 323 display.set_work_area(intersection); | 396 display.set_work_area(intersection); |
| 324 } | 397 } |
| 325 | 398 |
| 326 displays.push_back(display); | 399 displays.push_back(display); |
| 327 | 400 |
| 328 XRRFreeCrtcInfo(crtc); | 401 XRRFreeCrtcInfo(crtc); |
| 329 } | 402 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 344 ProcessDisplayChange(new_displays); | 417 ProcessDisplayChange(new_displays); |
| 345 } | 418 } |
| 346 | 419 |
| 347 //////////////////////////////////////////////////////////////////////////////// | 420 //////////////////////////////////////////////////////////////////////////////// |
| 348 | 421 |
| 349 gfx::Screen* CreateDesktopScreen() { | 422 gfx::Screen* CreateDesktopScreen() { |
| 350 return new DesktopScreenX11; | 423 return new DesktopScreenX11; |
| 351 } | 424 } |
| 352 | 425 |
| 353 } // namespace views | 426 } // namespace views |
| OLD | NEW |