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

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: Made GetDeviceScaleFactor clearer. Put unittest to 'all_sources' in .gyp 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/ui_unittests.gyp ('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 GetDeviceScaleFactor(int screen_pixels, int screen_mm) {
34 const int kCSSDefaultDPI = 96;
35 const float kInchInMm = 25.4f;
36
37 float screen_inches = screen_mm / kInchInMm;
38 float screen_dpi = screen_pixels / screen_inches;
39 float scale = screen_dpi / kCSSDefaultDPI;
40
41 return ui::GetImageScale(ui::GetSupportedScaleFactor(scale));
42 }
43
32 std::vector<gfx::Display> GetFallbackDisplayList() { 44 std::vector<gfx::Display> GetFallbackDisplayList() {
33 ::XDisplay* display = gfx::GetXDisplay(); 45 ::XDisplay* display = gfx::GetXDisplay();
34 ::Screen* screen = DefaultScreenOfDisplay(display); 46 ::Screen* screen = DefaultScreenOfDisplay(display);
35 int width = WidthOfScreen(screen); 47 int width = WidthOfScreen(screen);
36 int height = HeightOfScreen(screen); 48 int height = HeightOfScreen(screen);
49 int mm_width = WidthMMOfScreen(screen);
50 int mm_height = HeightMMOfScreen(screen);
37 51
38 return std::vector<gfx::Display>( 52 gfx::Rect bounds_in_pixels(0, 0, width, height);
39 1, gfx::Display(0, gfx::Rect(0, 0, width, height))); 53 gfx::Display gfx_display(0, bounds_in_pixels);
54 if (!gfx::Display::HasForceDeviceScaleFactor() &&
55 !ui::IsXDisplaySizeBlackListed(mm_width, mm_height)) {
56 float device_scale_factor = GetDeviceScaleFactor(width, mm_width);
57 DCHECK_LE(1.0f, device_scale_factor);
58 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels);
59 }
60
61 return std::vector<gfx::Display>(1, gfx_display);
40 } 62 }
41 63
42 } // namespace 64 } // namespace
43 65
44 namespace views { 66 namespace views {
45 67
46 //////////////////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////////////////
47 // DesktopScreenX11, public: 69 // DesktopScreenX11, public:
48 70
49 DesktopScreenX11::DesktopScreenX11() 71 DesktopScreenX11::DesktopScreenX11()
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 143 }
122 } 144 }
123 145
124 displays_ = incoming; 146 displays_ = incoming;
125 } 147 }
126 148
127 //////////////////////////////////////////////////////////////////////////////// 149 ////////////////////////////////////////////////////////////////////////////////
128 // DesktopScreenX11, gfx::Screen implementation: 150 // DesktopScreenX11, gfx::Screen implementation:
129 151
130 bool DesktopScreenX11::IsDIPEnabled() { 152 bool DesktopScreenX11::IsDIPEnabled() {
131 return false; 153 return true;
132 } 154 }
133 155
134 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { 156 gfx::Point DesktopScreenX11::GetCursorScreenPoint() {
135 XDisplay* display = gfx::GetXDisplay(); 157 XDisplay* display = gfx::GetXDisplay();
136 158
137 ::Window root, child; 159 ::Window root, child;
138 int root_x, root_y, win_x, win_y; 160 int root_x, root_y, win_x, win_y;
139 unsigned int mask; 161 unsigned int mask;
140 XQueryPointer(display, 162 XQueryPointer(display,
141 DefaultRootWindow(display), 163 DefaultRootWindow(display),
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 307
286 bool has_work_area = false; 308 bool has_work_area = false;
287 gfx::Rect work_area; 309 gfx::Rect work_area;
288 std::vector<int> value; 310 std::vector<int> value;
289 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && 311 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) &&
290 value.size() >= 4) { 312 value.size() >= 4) {
291 work_area = gfx::Rect(value[0], value[1], value[2], value[3]); 313 work_area = gfx::Rect(value[0], value[1], value[2], value[3]);
292 has_work_area = true; 314 has_work_area = true;
293 } 315 }
294 316
317 float device_scale_factor = 1.0f;
295 for (int i = 0; i < resources->noutput; ++i) { 318 for (int i = 0; i < resources->noutput; ++i) {
296 RROutput output_id = resources->outputs[i]; 319 RROutput output_id = resources->outputs[i];
297 XRROutputInfo* output_info = 320 XRROutputInfo* output_info =
298 XRRGetOutputInfo(xdisplay_, resources, output_id); 321 XRRGetOutputInfo(xdisplay_, resources, output_id);
299 322
300 bool is_connected = (output_info->connection == RR_Connected); 323 bool is_connected = (output_info->connection == RR_Connected);
301 if (!is_connected) { 324 if (!is_connected) {
302 XRRFreeOutputInfo(output_info); 325 XRRFreeOutputInfo(output_info);
303 continue; 326 continue;
304 } 327 }
305 328
306 if (output_info->crtc) { 329 if (output_info->crtc) {
307 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_, 330 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_,
308 resources, 331 resources,
309 output_info->crtc); 332 output_info->crtc);
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 device_scale_factor = GetDeviceScaleFactor(crtc->width,
350 output_info->mm_width);
Daniel Erat 2013/10/29 23:31:07 nit: fix indenting by unindenting this two spaces
351 DCHECK_LE(1.0f, device_scale_factor);
352 }
353 display.SetScaleAndBounds(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
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
OLDNEW
« no previous file with comments | « ui/ui_unittests.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698