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

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

Issue 1070433002: device scale factor detection: use gtk-xft-dpi consistently (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months 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
« no previous file with comments | « no previous file | 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.
(...skipping 17 matching lines...) Expand all
28 #include "ui/views/widget/desktop_aura/desktop_screen.h" 28 #include "ui/views/widget/desktop_aura/desktop_screen.h"
29 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" 29 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
30 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" 30 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h"
31 31
32 namespace { 32 namespace {
33 33
34 // The delay to perform configuration after RRNotify. See the comment 34 // The delay to perform configuration after RRNotify. See the comment
35 // in |Dispatch()|. 35 // in |Dispatch()|.
36 const int64 kConfigureDelayMs = 500; 36 const int64 kConfigureDelayMs = 500;
37 37
38 // TODO(oshima): Consider using gtk-xft-dpi instead. 38 // TODO(oshima): Consider using gtk-xft-dpi instead.
oshima 2015/04/08 17:33:58 We should use gtk-xft-dpi instead, shouldn't we? T
stapelberg 2015/04/08 21:01:06 Done.
39 float GetDeviceScaleFactor(int screen_pixels, int screen_mm) { 39 float GetDeviceScaleFactor(int screen_pixels, int screen_mm) {
40 const int kCSSDefaultDPI = 96; 40 const int kCSSDefaultDPI = 96;
41 const float kInchInMm = 25.4f; 41 const float kInchInMm = 25.4f;
42 42
43 float screen_inches = screen_mm / kInchInMm; 43 float screen_inches = screen_mm / kInchInMm;
44 float screen_dpi = screen_pixels / screen_inches; 44 float screen_dpi = screen_pixels / screen_inches;
45 float scale = screen_dpi / kCSSDefaultDPI; 45 float scale = screen_dpi / kCSSDefaultDPI;
46 46
47 return ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale)); 47 return ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale));
48 } 48 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 bool has_work_area = false; 288 bool has_work_area = false;
289 gfx::Rect work_area_in_pixels; 289 gfx::Rect work_area_in_pixels;
290 std::vector<int> value; 290 std::vector<int> value;
291 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && 291 if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) &&
292 value.size() >= 4) { 292 value.size() >= 4) {
293 work_area_in_pixels = gfx::Rect(value[0], value[1], value[2], value[3]); 293 work_area_in_pixels = gfx::Rect(value[0], value[1], value[2], value[3]);
294 has_work_area = true; 294 has_work_area = true;
295 } 295 }
296 296
297 float device_scale_factor = 1.0f; 297 float device_scale_factor = 1.0f;
298 {
299 // As per-display scale factor is not supported right now,
300 // the X11 root window's scale factor is always used.
301 // This is what users can change using e.g. xrandr -dpi 96
302 std::vector<gfx::Display> fallback_displays = GetFallbackDisplayList();
303 device_scale_factor = fallback_displays[0].device_scale_factor();
304 }
298 for (int i = 0; i < resources->noutput; ++i) { 305 for (int i = 0; i < resources->noutput; ++i) {
299 RROutput output_id = resources->outputs[i]; 306 RROutput output_id = resources->outputs[i];
300 gfx::XScopedPtr<XRROutputInfo, 307 gfx::XScopedPtr<XRROutputInfo,
301 gfx::XObjectDeleter<XRROutputInfo, void, XRRFreeOutputInfo>> 308 gfx::XObjectDeleter<XRROutputInfo, void, XRRFreeOutputInfo>>
302 output_info(XRRGetOutputInfo(xdisplay_, resources.get(), output_id)); 309 output_info(XRRGetOutputInfo(xdisplay_, resources.get(), output_id));
303 310
304 bool is_connected = (output_info->connection == RR_Connected); 311 bool is_connected = (output_info->connection == RR_Connected);
305 if (!is_connected) 312 if (!is_connected)
306 continue; 313 continue;
307 314
308 if (output_info->crtc) { 315 if (output_info->crtc) {
309 gfx::XScopedPtr<XRRCrtcInfo, 316 gfx::XScopedPtr<XRRCrtcInfo,
310 gfx::XObjectDeleter<XRRCrtcInfo, void, XRRFreeCrtcInfo>> 317 gfx::XObjectDeleter<XRRCrtcInfo, void, XRRFreeCrtcInfo>>
311 crtc(XRRGetCrtcInfo(xdisplay_, resources.get(), output_info->crtc)); 318 crtc(XRRGetCrtcInfo(xdisplay_, resources.get(), output_info->crtc));
312 319
313 int64 display_id = -1; 320 int64 display_id = -1;
314 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) { 321 if (!ui::GetDisplayId(output_id, static_cast<uint8>(i), &display_id)) {
315 // It isn't ideal, but if we can't parse the EDID data, fallback on the 322 // It isn't ideal, but if we can't parse the EDID data, fallback on the
316 // display number. 323 // display number.
317 display_id = i; 324 display_id = i;
318 } 325 }
319 326
320 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height); 327 gfx::Rect crtc_bounds(crtc->x, crtc->y, crtc->width, crtc->height);
321 gfx::Display display(display_id, crtc_bounds); 328 gfx::Display display(display_id, crtc_bounds);
322 329
323 if (!gfx::Display::HasForceDeviceScaleFactor()) { 330 if (!gfx::Display::HasForceDeviceScaleFactor()) {
324 if (i == 0 && !ui::IsDisplaySizeBlackListed(
325 gfx::Size(output_info->mm_width, output_info->mm_height))) {
326 // As per display scale factor is not supported right now,
327 // the primary display's scale factor is always used.
328 device_scale_factor = GetDeviceScaleFactor(crtc->width,
329 output_info->mm_width);
330 DCHECK_LE(1.0f, device_scale_factor);
331 }
332 display.SetScaleAndBounds(device_scale_factor, crtc_bounds); 331 display.SetScaleAndBounds(device_scale_factor, crtc_bounds);
333 } 332 }
334 333
335 if (has_work_area) { 334 if (has_work_area) {
336 gfx::Rect intersection_in_pixels = crtc_bounds; 335 gfx::Rect intersection_in_pixels = crtc_bounds;
337 intersection_in_pixels.Intersect(work_area_in_pixels); 336 intersection_in_pixels.Intersect(work_area_in_pixels);
338 // SetScaleAndBounds() above does the conversion from pixels to DIP for 337 // SetScaleAndBounds() above does the conversion from pixels to DIP for
339 // us, but set_work_area does not, so we need to do it here. 338 // us, but set_work_area does not, so we need to do it here.
340 display.set_work_area(gfx::Rect( 339 display.set_work_area(gfx::Rect(
341 gfx::ToFlooredPoint( 340 gfx::ToFlooredPoint(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 change_notifier_.NotifyDisplaysChanged(old_displays, displays_); 377 change_notifier_.NotifyDisplaysChanged(old_displays, displays_);
379 } 378 }
380 379
381 //////////////////////////////////////////////////////////////////////////////// 380 ////////////////////////////////////////////////////////////////////////////////
382 381
383 gfx::Screen* CreateDesktopScreen() { 382 gfx::Screen* CreateDesktopScreen() {
384 return new DesktopScreenX11; 383 return new DesktopScreenX11;
385 } 384 }
386 385
387 } // namespace views 386 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698