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 GetDeviceScaleFactor(int screen_dimention, int mm_screen_dimention) { | |
|
Daniel Erat
2013/10/29 16:27:03
s/dimention/dimension/g
the units of the first ar
| |
| 34 const int kCSSDefaultDIPCountPerInch = 96; | |
|
Daniel Erat
2013/10/29 16:27:03
is something shorter like kCSSDefaultDPI still acc
| |
| 35 const float kInchInMm = 25.4f; | |
| 36 | |
| 37 float screen_dpi = (screen_dimention * kInchInMm) / mm_screen_dimention; | |
|
Daniel Erat
2013/10/29 16:27:03
maybe a bit clearer:
float screen_inches = scre
| |
| 38 float scale = screen_dpi / kCSSDefaultDIPCountPerInch; | |
| 39 | |
| 40 return ui::GetImageScale(ui::GetSupportedScaleFactor(scale)); | |
| 41 } | |
| 42 | |
| 32 std::vector<gfx::Display> GetFallbackDisplayList() { | 43 std::vector<gfx::Display> GetFallbackDisplayList() { |
| 33 ::XDisplay* display = gfx::GetXDisplay(); | 44 ::XDisplay* display = gfx::GetXDisplay(); |
| 34 ::Screen* screen = DefaultScreenOfDisplay(display); | 45 ::Screen* screen = DefaultScreenOfDisplay(display); |
| 35 int width = WidthOfScreen(screen); | 46 int width = WidthOfScreen(screen); |
| 36 int height = HeightOfScreen(screen); | 47 int height = HeightOfScreen(screen); |
| 48 int mm_width = WidthMMOfScreen(screen); | |
| 49 int mm_height = HeightMMOfScreen(screen); | |
| 37 | 50 |
| 38 return std::vector<gfx::Display>( | 51 gfx::Rect bounds_in_pixels(0, 0, width, height); |
| 39 1, gfx::Display(0, gfx::Rect(0, 0, width, height))); | 52 gfx::Display gfx_display(0, bounds_in_pixels); |
| 53 if (!gfx::Display::HasForceDeviceScaleFactor() && | |
| 54 !ui::IsXDisplaySizeBlackListed(mm_width, mm_height)) { | |
| 55 float device_scale_factor = GetDeviceScaleFactor(width, mm_width); | |
| 56 DCHECK_LE(1.0f, device_scale_factor); | |
| 57 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); | |
| 58 } | |
| 59 | |
| 60 return std::vector<gfx::Display>(1, gfx_display); | |
| 40 } | 61 } |
| 41 | 62 |
| 42 } // namespace | 63 } // namespace |
| 43 | 64 |
| 44 namespace views { | 65 namespace views { |
| 45 | 66 |
| 46 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// |
| 47 // DesktopScreenX11, public: | 68 // DesktopScreenX11, public: |
| 48 | 69 |
| 49 DesktopScreenX11::DesktopScreenX11() | 70 DesktopScreenX11::DesktopScreenX11() |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 } | 142 } |
| 122 } | 143 } |
| 123 | 144 |
| 124 displays_ = incoming; | 145 displays_ = incoming; |
| 125 } | 146 } |
| 126 | 147 |
| 127 //////////////////////////////////////////////////////////////////////////////// | 148 //////////////////////////////////////////////////////////////////////////////// |
| 128 // DesktopScreenX11, gfx::Screen implementation: | 149 // DesktopScreenX11, gfx::Screen implementation: |
| 129 | 150 |
| 130 bool DesktopScreenX11::IsDIPEnabled() { | 151 bool DesktopScreenX11::IsDIPEnabled() { |
| 131 return false; | 152 return true; |
| 132 } | 153 } |
| 133 | 154 |
| 134 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { | 155 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { |
| 135 XDisplay* display = gfx::GetXDisplay(); | 156 XDisplay* display = gfx::GetXDisplay(); |
| 136 | 157 |
| 137 ::Window root, child; | 158 ::Window root, child; |
| 138 int root_x, root_y, win_x, win_y; | 159 int root_x, root_y, win_x, win_y; |
| 139 unsigned int mask; | 160 unsigned int mask; |
| 140 XQueryPointer(display, | 161 XQueryPointer(display, |
| 141 DefaultRootWindow(display), | 162 DefaultRootWindow(display), |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 | 306 |
| 286 bool has_work_area = false; | 307 bool has_work_area = false; |
| 287 gfx::Rect work_area; | 308 gfx::Rect work_area; |
| 288 std::vector<int> value; | 309 std::vector<int> value; |
| 289 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && | 310 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && |
| 290 value.size() >= 4) { | 311 value.size() >= 4) { |
| 291 work_area = gfx::Rect(value[0], value[1], value[2], value[3]); | 312 work_area = gfx::Rect(value[0], value[1], value[2], value[3]); |
| 292 has_work_area = true; | 313 has_work_area = true; |
| 293 } | 314 } |
| 294 | 315 |
| 316 float device_scale_factor = 1.0f; | |
| 295 for (int i = 0; i < resources->noutput; ++i) { | 317 for (int i = 0; i < resources->noutput; ++i) { |
| 296 RROutput output_id = resources->outputs[i]; | 318 RROutput output_id = resources->outputs[i]; |
| 297 XRROutputInfo* output_info = | 319 XRROutputInfo* output_info = |
| 298 XRRGetOutputInfo(xdisplay_, resources, output_id); | 320 XRRGetOutputInfo(xdisplay_, resources, output_id); |
| 299 | 321 |
| 300 bool is_connected = (output_info->connection == RR_Connected); | 322 bool is_connected = (output_info->connection == RR_Connected); |
| 301 if (!is_connected) { | 323 if (!is_connected) { |
| 302 XRRFreeOutputInfo(output_info); | 324 XRRFreeOutputInfo(output_info); |
| 303 continue; | 325 continue; |
| 304 } | 326 } |
| 305 | 327 |
| 306 if (output_info->crtc) { | 328 if (output_info->crtc) { |
| 307 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_, | 329 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_, |
| 308 resources, | 330 resources, |
| 309 output_info->crtc); | 331 output_info->crtc); |
| 310 | 332 |
| 311 int64 display_id = -1; | 333 int64 display_id = -1; |
| 312 if (!base::GetDisplayId(output_id, i, &display_id)) { | 334 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 | 335 // It isn't ideal, but if we can't parse the EDID data, fallback on the |
| 314 // display number. | 336 // display number. |
| 315 display_id = i; | 337 display_id = i; |
| 316 } | 338 } |
| 317 | 339 |
| 318 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); | 340 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); |
| 319 gfx::Display display(display_id, crtc_bounds); | 341 gfx::Display display(display_id, crtc_bounds); |
| 342 | |
| 343 if (!gfx::Display::HasForceDeviceScaleFactor()) { | |
| 344 if (i == 0 && !ui::IsXDisplaySizeBlackListed(output_info->mm_width, | |
| 345 output_info->mm_height)) { | |
| 346 // As per display scale factor is not supported right now, | |
| 347 // the primary display's scale factor is always used. | |
| 348 device_scale_factor = GetDeviceScaleFactor(crtc->width, | |
| 349 output_info->mm_width); | |
| 350 DCHECK_LE(1.0f, device_scale_factor); | |
| 351 } | |
| 352 display.SetScaleAndBounds(device_scale_factor, crtc_bounds); | |
| 353 } | |
| 354 | |
| 320 if (has_work_area) { | 355 if (has_work_area) { |
| 321 gfx::Rect intersection = crtc_bounds; | 356 gfx::Rect intersection = crtc_bounds; |
| 322 intersection.Intersect(work_area); | 357 intersection.Intersect(work_area); |
| 323 display.set_work_area(intersection); | 358 display.set_work_area(intersection); |
| 324 } | 359 } |
| 325 | 360 |
| 326 displays.push_back(display); | 361 displays.push_back(display); |
| 327 | 362 |
| 328 XRRFreeCrtcInfo(crtc); | 363 XRRFreeCrtcInfo(crtc); |
| 329 } | 364 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 344 ProcessDisplayChange(new_displays); | 379 ProcessDisplayChange(new_displays); |
| 345 } | 380 } |
| 346 | 381 |
| 347 //////////////////////////////////////////////////////////////////////////////// | 382 //////////////////////////////////////////////////////////////////////////////// |
| 348 | 383 |
| 349 gfx::Screen* CreateDesktopScreen() { | 384 gfx::Screen* CreateDesktopScreen() { |
| 350 return new DesktopScreenX11; | 385 return new DesktopScreenX11; |
| 351 } | 386 } |
| 352 | 387 |
| 353 } // namespace views | 388 } // namespace views |
| OLD | NEW |