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/dpi.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 float GetDeviceScaleFactor(int screen_pixels, int screen_mm) { | |
38 const int kCSSDefaultDPI = 96; | |
39 const float kInchInMm = 25.4f; | |
40 | |
41 float screen_inches = screen_mm / kInchInMm; | |
42 float screen_dpi = screen_pixels / screen_inches; | |
43 float scale = screen_dpi / kCSSDefaultDPI; | |
44 | |
45 return ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale)); | |
46 } | |
47 | |
48 std::vector<gfx::Display> GetFallbackDisplayList() { | 37 std::vector<gfx::Display> GetFallbackDisplayList() { |
49 ::XDisplay* display = gfx::GetXDisplay(); | 38 ::XDisplay* display = gfx::GetXDisplay(); |
50 ::Screen* screen = DefaultScreenOfDisplay(display); | 39 ::Screen* screen = DefaultScreenOfDisplay(display); |
51 int width = WidthOfScreen(screen); | 40 int width = WidthOfScreen(screen); |
52 int height = HeightOfScreen(screen); | 41 int height = HeightOfScreen(screen); |
53 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen)); | 42 gfx::Size physical_size(WidthMMOfScreen(screen), HeightMMOfScreen(screen)); |
54 | 43 |
55 gfx::Rect bounds_in_pixels(0, 0, width, height); | 44 gfx::Rect bounds_in_pixels(0, 0, width, height); |
56 gfx::Display gfx_display(0, bounds_in_pixels); | 45 gfx::Display gfx_display(0, bounds_in_pixels); |
57 if (!gfx::Display::HasForceDeviceScaleFactor() && | 46 if (!gfx::Display::HasForceDeviceScaleFactor() && |
58 !ui::IsDisplaySizeBlackListed(physical_size)) { | 47 !ui::IsDisplaySizeBlackListed(physical_size)) { |
59 float device_scale_factor = GetDeviceScaleFactor( | 48 float device_scale_factor = gfx::GetDeviceScaleFactor(); |
60 width, physical_size.width()); | |
61 DCHECK_LE(1.0f, device_scale_factor); | 49 DCHECK_LE(1.0f, device_scale_factor); |
62 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); | 50 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels); |
63 } | 51 } |
64 | 52 |
65 return std::vector<gfx::Display>(1, gfx_display); | 53 return std::vector<gfx::Display>(1, gfx_display); |
66 } | 54 } |
67 | 55 |
68 } // namespace | 56 } // namespace |
69 | 57 |
70 namespace views { | 58 namespace views { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 260 |
273 bool has_work_area = false; | 261 bool has_work_area = false; |
274 gfx::Rect work_area; | 262 gfx::Rect work_area; |
275 std::vector<int> value; | 263 std::vector<int> value; |
276 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && | 264 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && |
277 value.size() >= 4) { | 265 value.size() >= 4) { |
278 work_area = gfx::Rect(value[0], value[1], value[2], value[3]); | 266 work_area = gfx::Rect(value[0], value[1], value[2], value[3]); |
279 has_work_area = true; | 267 has_work_area = true; |
280 } | 268 } |
281 | 269 |
| 270 |
282 float device_scale_factor = 1.0f; | 271 float device_scale_factor = 1.0f; |
| 272 bool have_one = false; |
283 for (int i = 0; i < resources->noutput; ++i) { | 273 for (int i = 0; i < resources->noutput; ++i) { |
284 RROutput output_id = resources->outputs[i]; | 274 RROutput output_id = resources->outputs[i]; |
285 XRROutputInfo* output_info = | 275 XRROutputInfo* output_info = |
286 XRRGetOutputInfo(xdisplay_, resources, output_id); | 276 XRRGetOutputInfo(xdisplay_, resources, output_id); |
287 | 277 |
288 bool is_connected = (output_info->connection == RR_Connected); | 278 bool is_connected = (output_info->connection == RR_Connected); |
289 if (!is_connected) { | 279 if (!is_connected) { |
290 XRRFreeOutputInfo(output_info); | 280 XRRFreeOutputInfo(output_info); |
291 continue; | 281 continue; |
292 } | 282 } |
293 | 283 |
294 if (output_info->crtc) { | 284 if (output_info->crtc) { |
295 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_, | 285 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_, |
296 resources, | 286 resources, |
297 output_info->crtc); | 287 output_info->crtc); |
298 | 288 |
299 int64 display_id = -1; | 289 int64 display_id = -1; |
300 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) { | 290 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 | 291 // It isn't ideal, but if we can't parse the EDID data, fallback on the |
302 // display number. | 292 // display number. |
303 display_id = i; | 293 display_id = i; |
304 } | 294 } |
305 | 295 |
306 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); | 296 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); |
307 gfx::Display display(display_id, crtc_bounds); | 297 gfx::Display display(display_id, crtc_bounds); |
308 | 298 |
309 if (!gfx::Display::HasForceDeviceScaleFactor()) { | 299 if (!gfx::Display::HasForceDeviceScaleFactor()) { |
310 if (i == 0 && !ui::IsDisplaySizeBlackListed( | 300 if (!have_one && !ui::IsDisplaySizeBlackListed( |
311 gfx::Size(output_info->mm_width, output_info->mm_height))) { | 301 gfx::Size(output_info->mm_width, output_info->mm_height))) { |
312 // As per display scale factor is not supported right now, | 302 // As per display scale factor is not supported right now, |
313 // the primary display's scale factor is always used. | 303 // the primary display's scale factor is always used. |
314 device_scale_factor = GetDeviceScaleFactor(crtc->width, | 304 device_scale_factor = gfx::GetDeviceScaleFactor(); |
315 output_info->mm_width); | |
316 DCHECK_LE(1.0f, device_scale_factor); | 305 DCHECK_LE(1.0f, device_scale_factor); |
| 306 have_one = true; |
317 } | 307 } |
318 display.SetScaleAndBounds(device_scale_factor, crtc_bounds); | 308 display.SetScaleAndBounds(device_scale_factor, crtc_bounds); |
319 } | 309 } |
320 | 310 |
321 if (has_work_area) { | 311 if (has_work_area) { |
322 gfx::Rect intersection = crtc_bounds; | 312 gfx::Rect intersection = crtc_bounds; |
323 intersection.Intersect(work_area); | 313 intersection.Intersect(work_area); |
324 display.set_work_area(intersection); | 314 display.set_work_area(intersection); |
325 } | 315 } |
326 | 316 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); | 352 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); |
363 } | 353 } |
364 | 354 |
365 //////////////////////////////////////////////////////////////////////////////// | 355 //////////////////////////////////////////////////////////////////////////////// |
366 | 356 |
367 gfx::Screen* CreateDesktopScreen() { | 357 gfx::Screen* CreateDesktopScreen() { |
368 return new DesktopScreenX11; | 358 return new DesktopScreenX11; |
369 } | 359 } |
370 | 360 |
371 } // namespace views | 361 } // namespace views |
OLD | NEW |