OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/display/display_change_observer_chromeos.h" | 5 #include "ash/display/display_change_observer_chromeos.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "ash/ash_switches.h" | 12 #include "ash/ash_switches.h" |
13 #include "ash/display/display_info.h" | 13 #include "ash/display/display_info.h" |
14 #include "ash/display/display_layout_store.h" | 14 #include "ash/display/display_layout_store.h" |
15 #include "ash/display/display_manager.h" | 15 #include "ash/display/display_manager.h" |
16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "chromeos/display/output_util.h" | 19 #include "chromeos/display/output_util.h" |
20 #include "grit/ash_strings.h" | 20 #include "grit/ash_strings.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/x/x11_util.h" |
22 #include "ui/compositor/dip_util.h" | 23 #include "ui/compositor/dip_util.h" |
23 #include "ui/gfx/display.h" | 24 #include "ui/gfx/display.h" |
24 | 25 |
25 namespace ash { | 26 namespace ash { |
26 namespace internal { | 27 namespace internal { |
27 | 28 |
28 using chromeos::OutputConfigurator; | 29 using chromeos::OutputConfigurator; |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 // The DPI threshold to detect high density screen. | 33 // The DPI threshold to detect high density screen. |
33 // Higher DPI than this will use device_scale_factor=2. | 34 // Higher DPI than this will use device_scale_factor=2. |
34 const unsigned int kHighDensityDPIThreshold = 160; | 35 const unsigned int kHighDensityDPIThreshold = 160; |
35 | 36 |
36 // 1 inch in mm. | 37 // 1 inch in mm. |
37 const float kInchInMm = 25.4f; | 38 const float kInchInMm = 25.4f; |
38 | 39 |
39 // A list of bogus sizes in mm that X detects that should be ignored. | |
40 // See crbug.com/136533. The first element maintains the minimum | |
41 // size required to be valid size. | |
42 const unsigned long kInvalidDisplaySizeList[][2] = { | |
43 {40, 30}, | |
44 {50, 40}, | |
45 {160, 90}, | |
46 {160, 100}, | |
47 }; | |
48 | |
49 // Resolution list are sorted by the area in pixels and the larger | 40 // Resolution list are sorted by the area in pixels and the larger |
50 // one comes first. | 41 // one comes first. |
51 struct ResolutionSorter { | 42 struct ResolutionSorter { |
52 bool operator()(const Resolution& a, const Resolution& b) { | 43 bool operator()(const Resolution& a, const Resolution& b) { |
53 return a.size.width() * a.size.height() > b.size.width() * b.size.height(); | 44 return a.size.width() * a.size.height() > b.size.width() * b.size.height(); |
54 } | 45 } |
55 }; | 46 }; |
56 | 47 |
57 } // namespace | 48 } // namespace |
58 | 49 |
59 // static | 50 // static |
60 bool DisplayChangeObserver::ShouldIgnoreSize(unsigned long mm_width, | |
61 unsigned long mm_height) { | |
62 // Ignore if the reported display is smaller than minimum size. | |
63 if (mm_width <= kInvalidDisplaySizeList[0][0] || | |
64 mm_height <= kInvalidDisplaySizeList[0][1]) { | |
65 LOG(WARNING) << "Smaller than minimum display size"; | |
66 return true; | |
67 } | |
68 for (unsigned long i = 1 ; i < arraysize(kInvalidDisplaySizeList); ++i) { | |
69 const unsigned long* size = kInvalidDisplaySizeList[i]; | |
70 if (mm_width == size[0] && mm_height == size[1]) { | |
71 LOG(WARNING) << "Black listed display size detected:" | |
72 << size[0] << "x" << size[1]; | |
73 return true; | |
74 } | |
75 } | |
76 return false; | |
77 } | |
78 | |
79 // static | |
80 std::vector<Resolution> DisplayChangeObserver::GetResolutionList( | 51 std::vector<Resolution> DisplayChangeObserver::GetResolutionList( |
81 const OutputConfigurator::OutputSnapshot& output) { | 52 const OutputConfigurator::OutputSnapshot& output) { |
82 typedef std::map<std::pair<int,int>, Resolution> ResolutionMap; | 53 typedef std::map<std::pair<int,int>, Resolution> ResolutionMap; |
83 ResolutionMap resolution_map; | 54 ResolutionMap resolution_map; |
84 | 55 |
85 for (std::map<RRMode, OutputConfigurator::ModeInfo>::const_iterator it = | 56 for (std::map<RRMode, OutputConfigurator::ModeInfo>::const_iterator it = |
86 output.mode_infos.begin(); it != output.mode_infos.end(); ++it) { | 57 output.mode_infos.begin(); it != output.mode_infos.end(); ++it) { |
87 const OutputConfigurator::ModeInfo& mode_info = it->second; | 58 const OutputConfigurator::ModeInfo& mode_info = it->second; |
88 const std::pair<int, int> size(mode_info.width, mode_info.height); | 59 const std::pair<int, int> size(mode_info.width, mode_info.height); |
89 const Resolution resolution(gfx::Size(mode_info.width, mode_info.height), | 60 const Resolution resolution(gfx::Size(mode_info.width, mode_info.height), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 output.display_id == gfx::Display::kInvalidDisplayID ? output.index : | 130 output.display_id == gfx::Display::kInvalidDisplayID ? output.index : |
160 output.display_id); | 131 output.display_id); |
161 } | 132 } |
162 | 133 |
163 const OutputConfigurator::ModeInfo* mode_info = | 134 const OutputConfigurator::ModeInfo* mode_info = |
164 OutputConfigurator::GetModeInfo(output, output.current_mode); | 135 OutputConfigurator::GetModeInfo(output, output.current_mode); |
165 if (!mode_info) | 136 if (!mode_info) |
166 continue; | 137 continue; |
167 | 138 |
168 float device_scale_factor = 1.0f; | 139 float device_scale_factor = 1.0f; |
169 if (!ShouldIgnoreSize(output.width_mm, output.height_mm) && | 140 if (!ui::IsXDisplaySizeBlackListed(output.width_mm, output.height_mm) && |
170 (kInchInMm * mode_info->width / output.width_mm) > | 141 (kInchInMm * mode_info->width / output.width_mm) > |
171 kHighDensityDPIThreshold) { | 142 kHighDensityDPIThreshold) { |
172 device_scale_factor = 2.0f; | 143 device_scale_factor = 2.0f; |
173 } | 144 } |
174 gfx::Rect display_bounds( | 145 gfx::Rect display_bounds( |
175 output.x, output.y, mode_info->width, mode_info->height); | 146 output.x, output.y, mode_info->width, mode_info->height); |
176 | 147 |
177 std::vector<Resolution> resolutions; | 148 std::vector<Resolution> resolutions; |
178 if (!output.is_internal) | 149 if (!output.is_internal) |
179 resolutions = GetResolutionList(output); | 150 resolutions = GetResolutionList(output); |
(...skipping 29 matching lines...) Expand all Loading... |
209 void DisplayChangeObserver::OnAppTerminating() { | 180 void DisplayChangeObserver::OnAppTerminating() { |
210 #if defined(USE_ASH) | 181 #if defined(USE_ASH) |
211 // Stop handling display configuration events once the shutdown | 182 // Stop handling display configuration events once the shutdown |
212 // process starts. crbug.com/177014. | 183 // process starts. crbug.com/177014. |
213 Shell::GetInstance()->output_configurator()->Stop(); | 184 Shell::GetInstance()->output_configurator()->Stop(); |
214 #endif | 185 #endif |
215 } | 186 } |
216 | 187 |
217 } // namespace internal | 188 } // namespace internal |
218 } // namespace ash | 189 } // namespace ash |
OLD | NEW |