1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/display/util/display_util.h"
7 #include "base/logging.h"
13 // A list of bogus sizes in mm that should be ignored.
14 // See crbug.com/136533. The first element maintains the minimum
15 // size required to be valid size.
16 const int kInvalidDisplaySizeList
[][2] = {
23 // The DPI threshold to detect high density screen.
24 // Higher DPI than this will use device_scale_factor=2.
25 const unsigned int kHighDensityDPIThresholdSmall
= 170;
27 // The HiDPI threshold for large (usually external) monitors. Lower threshold
28 // makes sense for large monitors, because such monitors should be located
29 // farther from the user's face usually. See http://crbug.com/348279
30 const unsigned int kHighDensityDPIThresholdLarge
= 150;
32 // The width threshold in mm for "large" monitors.
33 const int kLargeDisplayWidthThresholdMM
= 500;
36 const float kInchInMm
= 25.4f
;
40 bool IsDisplaySizeBlackListed(const gfx::Size
& physical_size
) {
41 // Ignore if the reported display is smaller than minimum size.
42 if (physical_size
.width() <= kInvalidDisplaySizeList
[0][0] ||
43 physical_size
.height() <= kInvalidDisplaySizeList
[0][1]) {
44 VLOG(1) << "Smaller than minimum display size";
47 for (size_t i
= 1; i
< arraysize(kInvalidDisplaySizeList
); ++i
) {
48 const gfx::Size
size(kInvalidDisplaySizeList
[i
][0],
49 kInvalidDisplaySizeList
[i
][1]);
50 if (physical_size
== size
) {
51 VLOG(1) << "Black listed display size detected:" << size
.ToString();
58 float GetScaleFactor(const gfx::Size
& physical_size_in_mm
,
59 const gfx::Size
& screen_size_in_pixels
) {
60 if (IsDisplaySizeBlackListed(physical_size_in_mm
))
63 const unsigned int dpi
= static_cast<unsigned int>(
64 kInchInMm
* screen_size_in_pixels
.width() / physical_size_in_mm
.width());
65 const unsigned int threshold
=
66 (physical_size_in_mm
.width() >= kLargeDisplayWidthThresholdMM
) ?
67 kHighDensityDPIThresholdLarge
: kHighDensityDPIThresholdSmall
;
68 return (dpi
> threshold
) ? 2.0f
: 1.0f
;