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; | |
Daniel Erat
2013/10/29 14:28:25
why does this need to be global? it looks like it
Mikhail
2013/10/29 14:50:55
Indeed! Thanks for noticing it!
| |
34 | |
35 float GetDeviceScaleFactor(int screen_dim, int mm_screen_dim) { | |
Daniel Erat
2013/10/29 14:28:25
what does "dim" stand for here?
Mikhail
2013/10/29 14:50:55
dimention, probably I should put the whole word.
| |
36 const int kCSSDefaultDIPCountPerInch = 96; | |
Daniel Erat
2013/10/29 14:28:25
where does this number come from?
Mikhail
2013/10/29 14:50:55
We always assume 96 CSS pixels in an inch
| |
37 const float kInchInMm = 25.4f; | |
38 | |
39 float screen_DPI = (screen_dim * kInchInMm) / mm_screen_dim; | |
Daniel Erat
2013/10/29 14:28:25
nit: screen_dpi
| |
40 float scale = screen_DPI / kCSSDefaultDIPCountPerInch; | |
41 | |
42 return ui::GetImageScale(ui::GetSupportedScaleFactor(scale)); | |
43 } | |
44 | |
32 std::vector<gfx::Display> GetFallbackDisplayList() { | 45 std::vector<gfx::Display> GetFallbackDisplayList() { |
33 ::XDisplay* display = gfx::GetXDisplay(); | 46 ::XDisplay* display = gfx::GetXDisplay(); |
34 ::Screen* screen = DefaultScreenOfDisplay(display); | 47 ::Screen* screen = DefaultScreenOfDisplay(display); |
35 int width = WidthOfScreen(screen); | 48 int width = WidthOfScreen(screen); |
36 int height = HeightOfScreen(screen); | 49 int height = HeightOfScreen(screen); |
50 int mm_width = WidthMMOfScreen(screen); | |
51 int mm_height = HeightMMOfScreen(screen); | |
37 | 52 |
38 return std::vector<gfx::Display>( | 53 gfx::Rect bounds_in_pixels(0, 0, width, height); |
39 1, gfx::Display(0, gfx::Rect(0, 0, width, height))); | 54 gfx::Display gfx_display(0, bounds_in_pixels); |
55 if (!gfx::Display::HasForceDeviceScaleFactor() && | |
56 !ui::IsXDisplaySizeBlackListed(mm_width, mm_height)) { | |
57 g_device_scale_factor = GetDeviceScaleFactor(width, mm_width); | |
58 DCHECK_LE(1.0f, g_device_scale_factor); | |
59 gfx_display.SetScaleAndBounds(g_device_scale_factor, bounds_in_pixels); | |
60 } | |
61 | |
62 return std::vector<gfx::Display>(1, gfx_display); | |
40 } | 63 } |
41 | 64 |
42 } // namespace | 65 } // namespace |
43 | 66 |
44 namespace views { | 67 namespace views { |
45 | 68 |
46 //////////////////////////////////////////////////////////////////////////////// | 69 //////////////////////////////////////////////////////////////////////////////// |
47 // DesktopScreenX11, public: | 70 // DesktopScreenX11, public: |
48 | 71 |
49 DesktopScreenX11::DesktopScreenX11() | 72 DesktopScreenX11::DesktopScreenX11() |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 } | 144 } |
122 } | 145 } |
123 | 146 |
124 displays_ = incoming; | 147 displays_ = incoming; |
125 } | 148 } |
126 | 149 |
127 //////////////////////////////////////////////////////////////////////////////// | 150 //////////////////////////////////////////////////////////////////////////////// |
128 // DesktopScreenX11, gfx::Screen implementation: | 151 // DesktopScreenX11, gfx::Screen implementation: |
129 | 152 |
130 bool DesktopScreenX11::IsDIPEnabled() { | 153 bool DesktopScreenX11::IsDIPEnabled() { |
131 return false; | 154 return true; |
132 } | 155 } |
133 | 156 |
134 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { | 157 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { |
135 XDisplay* display = gfx::GetXDisplay(); | 158 XDisplay* display = gfx::GetXDisplay(); |
136 | 159 |
137 ::Window root, child; | 160 ::Window root, child; |
138 int root_x, root_y, win_x, win_y; | 161 int root_x, root_y, win_x, win_y; |
139 unsigned int mask; | 162 unsigned int mask; |
140 XQueryPointer(display, | 163 XQueryPointer(display, |
141 DefaultRootWindow(display), | 164 DefaultRootWindow(display), |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 | 333 |
311 int64 display_id = -1; | 334 int64 display_id = -1; |
312 if (!base::GetDisplayId(output_id, i, &display_id)) { | 335 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 | 336 // It isn't ideal, but if we can't parse the EDID data, fallback on the |
314 // display number. | 337 // display number. |
315 display_id = i; | 338 display_id = i; |
316 } | 339 } |
317 | 340 |
318 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); | 341 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); |
319 gfx::Display display(display_id, crtc_bounds); | 342 gfx::Display display(display_id, crtc_bounds); |
343 | |
344 if (!gfx::Display::HasForceDeviceScaleFactor()) { | |
345 if (i == 0 && !ui::IsXDisplaySizeBlackListed(output_info->mm_width, | |
346 output_info->mm_height)) { | |
347 // As per display scale factor is not supported right now, | |
348 // the primary display's scale factor is always used. | |
349 g_device_scale_factor = GetDeviceScaleFactor(crtc->width, | |
350 output_info->mm_width); | |
351 } | |
352 DCHECK_LE(1.0f, g_device_scale_factor); | |
353 display.SetScaleAndBounds(g_device_scale_factor, crtc_bounds); | |
354 } | |
355 | |
320 if (has_work_area) { | 356 if (has_work_area) { |
321 gfx::Rect intersection = crtc_bounds; | 357 gfx::Rect intersection = crtc_bounds; |
322 intersection.Intersect(work_area); | 358 intersection.Intersect(work_area); |
323 display.set_work_area(intersection); | 359 display.set_work_area(intersection); |
324 } | 360 } |
325 | 361 |
326 displays.push_back(display); | 362 displays.push_back(display); |
327 | 363 |
328 XRRFreeCrtcInfo(crtc); | 364 XRRFreeCrtcInfo(crtc); |
329 } | 365 } |
(...skipping 14 matching lines...) Expand all Loading... | |
344 ProcessDisplayChange(new_displays); | 380 ProcessDisplayChange(new_displays); |
345 } | 381 } |
346 | 382 |
347 //////////////////////////////////////////////////////////////////////////////// | 383 //////////////////////////////////////////////////////////////////////////////// |
348 | 384 |
349 gfx::Screen* CreateDesktopScreen() { | 385 gfx::Screen* CreateDesktopScreen() { |
350 return new DesktopScreenX11; | 386 return new DesktopScreenX11; |
351 } | 387 } |
352 | 388 |
353 } // namespace views | 389 } // namespace views |
OLD | NEW |