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

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: Updated accordigly to r232633 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/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/x11/edid_parser_x11.h" 15 #include "base/x11/edid_parser_x11.h"
16 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/aura/window_tree_host.h" 18 #include "ui/aura/window_tree_host.h"
19 #include "ui/base/layout.h"
19 #include "ui/base/x/x11_util.h" 20 #include "ui/base/x/x11_util.h"
20 #include "ui/gfx/display.h" 21 #include "ui/gfx/display.h"
21 #include "ui/gfx/display_observer.h" 22 #include "ui/gfx/display_observer.h"
22 #include "ui/gfx/native_widget_types.h" 23 #include "ui/gfx/native_widget_types.h"
23 #include "ui/gfx/screen.h" 24 #include "ui/gfx/screen.h"
24 #include "ui/gfx/x/x11_types.h" 25 #include "ui/gfx/x/x11_types.h"
25 #include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h" 26 #include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h"
26 #include "ui/views/widget/desktop_aura/desktop_screen.h" 27 #include "ui/views/widget/desktop_aura/desktop_screen.h"
27 28
28 namespace { 29 namespace {
29 30
30 // The delay to perform configuration after RRNotify. See the comment 31 // The delay to perform configuration after RRNotify. See the comment
31 // in |Dispatch()|. 32 // in |Dispatch()|.
32 const int64 kConfigureDelayMs = 500; 33 const int64 kConfigureDelayMs = 500;
33 34
35 float GetDeviceScaleFactor(int screen_pixels, int screen_mm) {
36 const int kCSSDefaultDPI = 96;
37 const float kInchInMm = 25.4f;
38
39 float screen_inches = screen_mm / kInchInMm;
40 float screen_dpi = screen_pixels / screen_inches;
41 float scale = screen_dpi / kCSSDefaultDPI;
42
43 return ui::GetImageScale(ui::GetSupportedScaleFactor(scale));
44 }
45
34 std::vector<gfx::Display> GetFallbackDisplayList() { 46 std::vector<gfx::Display> GetFallbackDisplayList() {
35 ::XDisplay* display = gfx::GetXDisplay(); 47 ::XDisplay* display = gfx::GetXDisplay();
36 ::Screen* screen = DefaultScreenOfDisplay(display); 48 ::Screen* screen = DefaultScreenOfDisplay(display);
37 int width = WidthOfScreen(screen); 49 int width = WidthOfScreen(screen);
38 int height = HeightOfScreen(screen); 50 int height = HeightOfScreen(screen);
51 int mm_width = WidthMMOfScreen(screen);
52 int mm_height = HeightMMOfScreen(screen);
39 53
40 return std::vector<gfx::Display>( 54 gfx::Rect bounds_in_pixels(0, 0, width, height);
41 1, gfx::Display(0, gfx::Rect(0, 0, width, height))); 55 gfx::Display gfx_display(0, bounds_in_pixels);
56 if (!gfx::Display::HasForceDeviceScaleFactor() &&
57 !ui::IsXDisplaySizeBlackListed(mm_width, mm_height)) {
58 float device_scale_factor = GetDeviceScaleFactor(width, mm_width);
59 DCHECK_LE(1.0f, device_scale_factor);
60 gfx_display.SetScaleAndBounds(device_scale_factor, bounds_in_pixels);
61 }
62
63 return std::vector<gfx::Display>(1, gfx_display);
42 } 64 }
43 65
44 } // namespace 66 } // namespace
45 67
46 namespace views { 68 namespace views {
47 69
48 //////////////////////////////////////////////////////////////////////////////// 70 ////////////////////////////////////////////////////////////////////////////////
49 // DesktopScreenX11, public: 71 // DesktopScreenX11, public:
50 72
51 DesktopScreenX11::DesktopScreenX11() 73 DesktopScreenX11::DesktopScreenX11()
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 145 }
124 } 146 }
125 147
126 displays_ = incoming; 148 displays_ = incoming;
127 } 149 }
128 150
129 //////////////////////////////////////////////////////////////////////////////// 151 ////////////////////////////////////////////////////////////////////////////////
130 // DesktopScreenX11, gfx::Screen implementation: 152 // DesktopScreenX11, gfx::Screen implementation:
131 153
132 bool DesktopScreenX11::IsDIPEnabled() { 154 bool DesktopScreenX11::IsDIPEnabled() {
133 return false; 155 return true;
134 } 156 }
135 157
136 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { 158 gfx::Point DesktopScreenX11::GetCursorScreenPoint() {
137 TRACE_EVENT0("views", "DesktopScreenX11::GetCursorScreenPoint()"); 159 TRACE_EVENT0("views", "DesktopScreenX11::GetCursorScreenPoint()");
138 160
139 XDisplay* display = gfx::GetXDisplay(); 161 XDisplay* display = gfx::GetXDisplay();
140 162
141 ::Window root, child; 163 ::Window root, child;
142 int root_x, root_y, win_x, win_y; 164 int root_x, root_y, win_x, win_y;
143 unsigned int mask; 165 unsigned int mask;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 311
290 bool has_work_area = false; 312 bool has_work_area = false;
291 gfx::Rect work_area; 313 gfx::Rect work_area;
292 std::vector<int> value; 314 std::vector<int> value;
293 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && 315 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) &&
294 value.size() >= 4) { 316 value.size() >= 4) {
295 work_area = gfx::Rect(value[0], value[1], value[2], value[3]); 317 work_area = gfx::Rect(value[0], value[1], value[2], value[3]);
296 has_work_area = true; 318 has_work_area = true;
297 } 319 }
298 320
321 float device_scale_factor = 1.0f;
299 for (int i = 0; i < resources->noutput; ++i) { 322 for (int i = 0; i < resources->noutput; ++i) {
300 RROutput output_id = resources->outputs[i]; 323 RROutput output_id = resources->outputs[i];
301 XRROutputInfo* output_info = 324 XRROutputInfo* output_info =
302 XRRGetOutputInfo(xdisplay_, resources, output_id); 325 XRRGetOutputInfo(xdisplay_, resources, output_id);
303 326
304 bool is_connected = (output_info->connection == RR_Connected); 327 bool is_connected = (output_info->connection == RR_Connected);
305 if (!is_connected) { 328 if (!is_connected) {
306 XRRFreeOutputInfo(output_info); 329 XRRFreeOutputInfo(output_info);
307 continue; 330 continue;
308 } 331 }
309 332
310 if (output_info->crtc) { 333 if (output_info->crtc) {
311 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_, 334 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_,
312 resources, 335 resources,
313 output_info->crtc); 336 output_info->crtc);
314 337
315 int64 display_id = -1; 338 int64 display_id = -1;
316 if (!base::GetDisplayId(output_id, i, &display_id)) { 339 if (!base::GetDisplayId(output_id, i, &display_id)) {
317 // It isn't ideal, but if we can't parse the EDID data, fallback on the 340 // It isn't ideal, but if we can't parse the EDID data, fallback on the
318 // display number. 341 // display number.
319 display_id = i; 342 display_id = i;
320 } 343 }
321 344
322 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); 345 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height);
323 gfx::Display display(display_id, crtc_bounds); 346 gfx::Display display(display_id, crtc_bounds);
347
348 if (!gfx::Display::HasForceDeviceScaleFactor()) {
349 if (i == 0 && !ui::IsXDisplaySizeBlackListed(output_info->mm_width,
350 output_info->mm_height)) {
351 // As per display scale factor is not supported right now,
352 // the primary display's scale factor is always used.
353 device_scale_factor = GetDeviceScaleFactor(crtc->width,
354 output_info->mm_width);
355 DCHECK_LE(1.0f, device_scale_factor);
356 }
357 display.SetScaleAndBounds(device_scale_factor, crtc_bounds);
358 }
359
324 if (has_work_area) { 360 if (has_work_area) {
325 gfx::Rect intersection = crtc_bounds; 361 gfx::Rect intersection = crtc_bounds;
326 intersection.Intersect(work_area); 362 intersection.Intersect(work_area);
327 display.set_work_area(intersection); 363 display.set_work_area(intersection);
328 } 364 }
329 365
330 displays.push_back(display); 366 displays.push_back(display);
331 367
332 XRRFreeCrtcInfo(crtc); 368 XRRFreeCrtcInfo(crtc);
333 } 369 }
(...skipping 14 matching lines...) Expand all
348 ProcessDisplayChange(new_displays); 384 ProcessDisplayChange(new_displays);
349 } 385 }
350 386
351 //////////////////////////////////////////////////////////////////////////////// 387 ////////////////////////////////////////////////////////////////////////////////
352 388
353 gfx::Screen* CreateDesktopScreen() { 389 gfx::Screen* CreateDesktopScreen() {
354 return new DesktopScreenX11; 390 return new DesktopScreenX11;
355 } 391 }
356 392
357 } // namespace views 393 } // 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