Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: ui/views/widget/desktop_aura/desktop_screen_x11.cc

Issue 27156003: linux_aura: Enable HIDPI support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Took comments from Oshima into consideration Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/resource/resource_bundle.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) {
oshima 2013/10/23 18:10:59 I thought I left the comment, but apparently not,
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 float GetDeviceScaleFactor(int screen_dim, int mm_screen_dim) {
65 const int kCSSDefaultDIPCountPerInch = 96;
66 const float kInchInMm = 25.4f;
67
68 float screen_DPI = (screen_dim * kInchInMm) / mm_screen_dim;
69 float scale = screen_DPI / kCSSDefaultDIPCountPerInch;
70
71 return ui::GetImageScale(ui::GetSupportedScaleFactor(scale));
72 }
73
32 std::vector<gfx::Display> GetFallbackDisplayList() { 74 std::vector<gfx::Display> GetFallbackDisplayList() {
33 ::XDisplay* display = gfx::GetXDisplay(); 75 ::XDisplay* display = gfx::GetXDisplay();
34 ::Screen* screen = DefaultScreenOfDisplay(display); 76 ::Screen* screen = DefaultScreenOfDisplay(display);
35 int width = WidthOfScreen(screen); 77 int width = WidthOfScreen(screen);
36 int height = HeightOfScreen(screen); 78 int height = HeightOfScreen(screen);
79 int mm_width = WidthMMOfScreen(screen);
80 int mm_height = HeightMMOfScreen(screen);
37 81
38 return std::vector<gfx::Display>( 82 gfx::Rect bounds_in_pixels(0, 0, width, height);
39 1, gfx::Display(0, gfx::Rect(0, 0, width, height))); 83 gfx::Display gfx_display(0, bounds_in_pixels);
84 if (!gfx::Display::HasForceDeviceScaleFactor()
85 && !ShouldIgnoreScreen(mm_width, mm_height)) {
Elliot Glaysher 2013/10/23 17:51:19 && on previous line.
86 g_device_scale_factor = GetDeviceScaleFactor(width, mm_width);
87 DCHECK_LE(1.0f, g_device_scale_factor);
88 gfx_display.SetScaleAndBounds(g_device_scale_factor, bounds_in_pixels);
89 }
90
91 return std::vector<gfx::Display>(1, gfx_display);
40 } 92 }
41 93
42 } // namespace 94 } // namespace
43 95
44 namespace views { 96 namespace views {
45 97
46 //////////////////////////////////////////////////////////////////////////////// 98 ////////////////////////////////////////////////////////////////////////////////
47 // DesktopScreenX11, public: 99 // DesktopScreenX11, public:
48 100
49 DesktopScreenX11::DesktopScreenX11() 101 DesktopScreenX11::DesktopScreenX11()
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 173 }
122 } 174 }
123 175
124 displays_ = incoming; 176 displays_ = incoming;
125 } 177 }
126 178
127 //////////////////////////////////////////////////////////////////////////////// 179 ////////////////////////////////////////////////////////////////////////////////
128 // DesktopScreenX11, gfx::Screen implementation: 180 // DesktopScreenX11, gfx::Screen implementation:
129 181
130 bool DesktopScreenX11::IsDIPEnabled() { 182 bool DesktopScreenX11::IsDIPEnabled() {
131 return false; 183 return true;
132 } 184 }
133 185
134 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { 186 gfx::Point DesktopScreenX11::GetCursorScreenPoint() {
135 XDisplay* display = gfx::GetXDisplay(); 187 XDisplay* display = gfx::GetXDisplay();
136 188
137 ::Window root, child; 189 ::Window root, child;
138 int root_x, root_y, win_x, win_y; 190 int root_x, root_y, win_x, win_y;
139 unsigned int mask; 191 unsigned int mask;
140 XQueryPointer(display, 192 XQueryPointer(display,
141 DefaultRootWindow(display), 193 DefaultRootWindow(display),
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 362
311 int64 display_id = -1; 363 int64 display_id = -1;
312 if (!base::GetDisplayId(output_id, i, &display_id)) { 364 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 365 // It isn't ideal, but if we can't parse the EDID data, fallback on the
314 // display number. 366 // display number.
315 display_id = i; 367 display_id = i;
316 } 368 }
317 369
318 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); 370 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height);
319 gfx::Display display(display_id, crtc_bounds); 371 gfx::Display display(display_id, crtc_bounds);
372
373 if (!gfx::Display::HasForceDeviceScaleFactor()) {
374 if (i == 0 && !ShouldIgnoreScreen(output_info->mm_width,
375 output_info->mm_height)) {
376 // As per display scale factor is not supported right now,
377 // the primary display's scale factor is always used.
378 g_device_scale_factor = GetDeviceScaleFactor(crtc->width,
379 output_info->mm_width);
380 }
381 DCHECK_LE(1.0f, g_device_scale_factor);
382 display.SetScaleAndBounds(g_device_scale_factor, crtc_bounds);
383 }
384
320 if (has_work_area) { 385 if (has_work_area) {
321 gfx::Rect intersection = crtc_bounds; 386 gfx::Rect intersection = crtc_bounds;
322 intersection.Intersect(work_area); 387 intersection.Intersect(work_area);
323 display.set_work_area(intersection); 388 display.set_work_area(intersection);
324 } 389 }
325 390
326 displays.push_back(display); 391 displays.push_back(display);
327 392
328 XRRFreeCrtcInfo(crtc); 393 XRRFreeCrtcInfo(crtc);
329 } 394 }
(...skipping 14 matching lines...) Expand all
344 ProcessDisplayChange(new_displays); 409 ProcessDisplayChange(new_displays);
345 } 410 }
346 411
347 //////////////////////////////////////////////////////////////////////////////// 412 ////////////////////////////////////////////////////////////////////////////////
348 413
349 gfx::Screen* CreateDesktopScreen() { 414 gfx::Screen* CreateDesktopScreen() {
350 return new DesktopScreenX11; 415 return new DesktopScreenX11;
351 } 416 }
352 417
353 } // namespace views 418 } // namespace views
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698