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

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

Issue 659883002: Enable hidpi on Linux, refactor a bit on Windows to share Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: constants Created 6 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
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 "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
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
282 float device_scale_factor = 1.0f; 270 float device_scale_factor = gfx::GetDeviceScaleFactor();
283 for (int i = 0; i < resources->noutput; ++i) { 271 for (int i = 0; i < resources->noutput; ++i) {
284 RROutput output_id = resources->outputs[i]; 272 RROutput output_id = resources->outputs[i];
285 XRROutputInfo* output_info = 273 XRROutputInfo* output_info =
286 XRRGetOutputInfo(xdisplay_, resources, output_id); 274 XRRGetOutputInfo(xdisplay_, resources, output_id);
287 275
288 bool is_connected = (output_info->connection == RR_Connected); 276 bool is_connected = (output_info->connection == RR_Connected);
289 if (!is_connected) { 277 if (!is_connected) {
290 XRRFreeOutputInfo(output_info); 278 XRRFreeOutputInfo(output_info);
291 continue; 279 continue;
292 } 280 }
293 281
294 if (output_info->crtc) { 282 if (output_info->crtc) {
295 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_, 283 XRRCrtcInfo *crtc = XRRGetCrtcInfo(xdisplay_,
296 resources, 284 resources,
297 output_info->crtc); 285 output_info->crtc);
298 286
299 int64 display_id = -1; 287 int64 display_id = -1;
300 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) { 288 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 289 // It isn't ideal, but if we can't parse the EDID data, fallback on the
302 // display number. 290 // display number.
303 display_id = i; 291 display_id = i;
304 } 292 }
305 293
306 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); 294 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height);
307 gfx::Display display(display_id, crtc_bounds); 295 gfx::Display display(display_id, crtc_bounds);
308 296
309 if (!gfx::Display::HasForceDeviceScaleFactor()) { 297 if (!gfx::Display::HasForceDeviceScaleFactor())
310 if (i == 0 && !ui::IsDisplaySizeBlackListed(
311 gfx::Size(output_info->mm_width, output_info->mm_height))) {
312 // As per display scale factor is not supported right now,
313 // the primary display's scale factor is always used.
314 device_scale_factor = GetDeviceScaleFactor(crtc->width,
315 output_info->mm_width);
316 DCHECK_LE(1.0f, device_scale_factor);
317 }
318 display.SetScaleAndBounds(device_scale_factor, crtc_bounds); 298 display.SetScaleAndBounds(device_scale_factor, crtc_bounds);
319 }
320 299
321 if (has_work_area) { 300 if (has_work_area) {
322 gfx::Rect intersection = crtc_bounds; 301 gfx::Rect intersection = crtc_bounds;
323 intersection.Intersect(work_area); 302 intersection.Intersect(work_area);
324 display.set_work_area(intersection); 303 display.set_work_area(intersection);
325 } 304 }
326 305
327 switch (crtc->rotation) { 306 switch (crtc->rotation) {
328 case RR_Rotate_0: 307 case RR_Rotate_0:
329 display.set_rotation(gfx::Display::ROTATE_0); 308 display.set_rotation(gfx::Display::ROTATE_0);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); 341 change_notifier_.NotifyDisplaysChanged(old_displays, displays_);
363 } 342 }
364 343
365 //////////////////////////////////////////////////////////////////////////////// 344 ////////////////////////////////////////////////////////////////////////////////
366 345
367 gfx::Screen* CreateDesktopScreen() { 346 gfx::Screen* CreateDesktopScreen() {
368 return new DesktopScreenX11; 347 return new DesktopScreenX11;
369 } 348 }
370 349
371 } // namespace views 350 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698