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> |
(...skipping 19 matching lines...) Expand all Loading... | |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 // The DPI threshold to detect high density screen. | 33 // The DPI threshold to detect high density screen. |
34 // Higher DPI than this will use device_scale_factor=2. | 34 // Higher DPI than this will use device_scale_factor=2. |
35 const unsigned int kHighDensityDPIThreshold = 160; | 35 const unsigned int kHighDensityDPIThreshold = 160; |
36 | 36 |
37 // 1 inch in mm. | 37 // 1 inch in mm. |
38 const float kInchInMm = 25.4f; | 38 const float kInchInMm = 25.4f; |
39 | 39 |
40 // Resolution list are sorted by the area in pixels and the larger | 40 // Display mode list is sorted by the area in pixels and the larger |
41 // one comes first. | 41 // one comes first. |
oshima
2014/01/29 19:00:35
can you update the comment?
sheu
2014/01/29 22:43:36
Done.
| |
42 struct ResolutionSorter { | 42 struct DisplayModeSorter { |
43 bool operator()(const Resolution& a, const Resolution& b) { | 43 bool operator()(const DisplayMode& a, const DisplayMode& b) { |
44 return a.size.width() * a.size.height() > b.size.width() * b.size.height(); | 44 if (a.size.GetArea() == b.size.GetArea()) |
45 return (a.refresh_rate > b.refresh_rate); | |
46 return (a.size.GetArea() > b.size.GetArea()); | |
45 } | 47 } |
46 }; | 48 }; |
47 | 49 |
48 } // namespace | 50 } // namespace |
49 | 51 |
50 // static | 52 // static |
51 std::vector<Resolution> DisplayChangeObserver::GetResolutionList( | 53 std::vector<DisplayMode> DisplayChangeObserver::GetDisplayModeList( |
52 const OutputConfigurator::OutputSnapshot& output) { | 54 const OutputConfigurator::OutputSnapshot& output) { |
53 typedef std::map<std::pair<int,int>, Resolution> ResolutionMap; | 55 typedef std::map<std::pair<int, int>, DisplayMode> DisplayModeMap; |
54 ResolutionMap resolution_map; | 56 DisplayModeMap display_mode_map; |
55 | 57 |
56 for (std::map<RRMode, OutputConfigurator::ModeInfo>::const_iterator it = | 58 for (std::map<RRMode, OutputConfigurator::ModeInfo>::const_iterator it = |
57 output.mode_infos.begin(); it != output.mode_infos.end(); ++it) { | 59 output.mode_infos.begin(); it != output.mode_infos.end(); ++it) { |
58 const OutputConfigurator::ModeInfo& mode_info = it->second; | 60 const OutputConfigurator::ModeInfo& mode_info = it->second; |
59 const std::pair<int, int> size(mode_info.width, mode_info.height); | 61 const std::pair<int, int> size(mode_info.width, mode_info.height); |
60 const Resolution resolution(gfx::Size(mode_info.width, mode_info.height), | 62 const DisplayMode display_mode(gfx::Size(mode_info.width, mode_info.height), |
61 mode_info.interlaced); | 63 mode_info.refresh_rate, |
64 mode_info.interlaced, | |
65 output.native_mode == it->first); | |
62 | 66 |
63 // Add the resolution if it isn't already present and override interlaced | 67 // Add the resolution if it isn't already present and override interlaced |
oshima
2014/01/29 19:00:35
s/resolution/DisplayMode
sheu
2014/01/29 22:43:36
Done.
| |
64 // resolutions with non-interlaced ones. | 68 // resolutions with non-interlaced ones. |
65 ResolutionMap::iterator resolution_it = resolution_map.find(size); | 69 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size); |
66 if (resolution_it == resolution_map.end()) | 70 if (display_mode_it == display_mode_map.end()) |
67 resolution_map.insert(std::make_pair(size, resolution)); | 71 display_mode_map.insert(std::make_pair(size, display_mode)); |
68 else if (resolution_it->second.interlaced && !resolution.interlaced) | 72 else if (display_mode_it->second.interlaced && !display_mode.interlaced) |
69 resolution_it->second = resolution; | 73 display_mode_it->second = display_mode; |
70 } | 74 } |
71 | 75 |
72 std::vector<Resolution> resolution_list; | 76 std::vector<DisplayMode> display_mode_list; |
73 for (ResolutionMap::const_iterator iter = resolution_map.begin(); | 77 for (DisplayModeMap::const_iterator iter = display_mode_map.begin(); |
74 iter != resolution_map.end(); | 78 iter != display_mode_map.end(); |
75 ++iter) { | 79 ++iter) { |
76 resolution_list.push_back(iter->second); | 80 display_mode_list.push_back(iter->second); |
77 } | 81 } |
78 std::sort(resolution_list.begin(), resolution_list.end(), ResolutionSorter()); | 82 std::sort( |
79 return resolution_list; | 83 display_mode_list.begin(), display_mode_list.end(), DisplayModeSorter()); |
84 return display_mode_list; | |
80 } | 85 } |
81 | 86 |
82 DisplayChangeObserver::DisplayChangeObserver() { | 87 DisplayChangeObserver::DisplayChangeObserver() { |
83 Shell::GetInstance()->AddShellObserver(this); | 88 Shell::GetInstance()->AddShellObserver(this); |
84 } | 89 } |
85 | 90 |
86 DisplayChangeObserver::~DisplayChangeObserver() { | 91 DisplayChangeObserver::~DisplayChangeObserver() { |
87 Shell::GetInstance()->RemoveShellObserver(this); | 92 Shell::GetInstance()->RemoveShellObserver(this); |
88 } | 93 } |
89 | 94 |
90 chromeos::OutputState DisplayChangeObserver::GetStateForDisplayIds( | 95 chromeos::OutputState DisplayChangeObserver::GetStateForDisplayIds( |
91 const std::vector<int64>& display_ids) const { | 96 const std::vector<int64>& display_ids) const { |
92 if (CommandLine::ForCurrentProcess()->HasSwitch( | 97 if (CommandLine::ForCurrentProcess()->HasSwitch( |
93 switches::kAshForceMirrorMode)) { | 98 switches::kAshForceMirrorMode)) { |
94 return chromeos::STATE_DUAL_MIRROR; | 99 return chromeos::STATE_DUAL_MIRROR; |
95 } | 100 } |
96 | 101 |
97 CHECK_EQ(2U, display_ids.size()); | 102 CHECK_EQ(2U, display_ids.size()); |
98 DisplayIdPair pair = std::make_pair(display_ids[0], display_ids[1]); | 103 DisplayIdPair pair = std::make_pair(display_ids[0], display_ids[1]); |
99 DisplayLayout layout = Shell::GetInstance()->display_manager()-> | 104 DisplayLayout layout = Shell::GetInstance()->display_manager()-> |
100 layout_store()->GetRegisteredDisplayLayout(pair); | 105 layout_store()->GetRegisteredDisplayLayout(pair); |
101 return layout.mirrored ? | 106 return layout.mirrored ? |
102 chromeos::STATE_DUAL_MIRROR : chromeos::STATE_DUAL_EXTENDED; | 107 chromeos::STATE_DUAL_MIRROR : chromeos::STATE_DUAL_EXTENDED; |
103 } | 108 } |
104 | 109 |
105 bool DisplayChangeObserver::GetResolutionForDisplayId(int64 display_id, | 110 bool DisplayChangeObserver::GetResolutionForDisplayId(int64 display_id, |
106 int* width, | 111 int* width, |
107 int* height) const { | 112 int* height) const { |
108 gfx::Size resolution; | 113 DisplayMode mode; |
109 if (!Shell::GetInstance()->display_manager()-> | 114 if (!Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( |
110 GetSelectedResolutionForDisplayId(display_id, &resolution)) { | 115 display_id, &mode)) |
111 return false; | 116 return false; |
112 } | |
113 | 117 |
114 *width = resolution.width(); | 118 *width = mode.size.width(); |
115 *height = resolution.height(); | 119 *height = mode.size.height(); |
116 return true; | 120 return true; |
117 } | 121 } |
118 | 122 |
119 void DisplayChangeObserver::OnDisplayModeChanged( | 123 void DisplayChangeObserver::OnDisplayModeChanged( |
120 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { | 124 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { |
121 std::vector<DisplayInfo> displays; | 125 std::vector<DisplayInfo> displays; |
122 std::set<int64> ids; | 126 std::set<int64> ids; |
123 for (size_t i = 0; i < outputs.size(); ++i) { | 127 for (size_t i = 0; i < outputs.size(); ++i) { |
124 const OutputConfigurator::OutputSnapshot& output = outputs[i]; | 128 const OutputConfigurator::OutputSnapshot& output = outputs[i]; |
125 | 129 |
(...skipping 12 matching lines...) Expand all Loading... | |
138 | 142 |
139 float device_scale_factor = 1.0f; | 143 float device_scale_factor = 1.0f; |
140 if (!ui::IsXDisplaySizeBlackListed(output.width_mm, output.height_mm) && | 144 if (!ui::IsXDisplaySizeBlackListed(output.width_mm, output.height_mm) && |
141 (kInchInMm * mode_info->width / output.width_mm) > | 145 (kInchInMm * mode_info->width / output.width_mm) > |
142 kHighDensityDPIThreshold) { | 146 kHighDensityDPIThreshold) { |
143 device_scale_factor = 2.0f; | 147 device_scale_factor = 2.0f; |
144 } | 148 } |
145 gfx::Rect display_bounds( | 149 gfx::Rect display_bounds( |
146 output.x, output.y, mode_info->width, mode_info->height); | 150 output.x, output.y, mode_info->width, mode_info->height); |
147 | 151 |
148 std::vector<Resolution> resolutions; | 152 std::vector<DisplayMode> display_modes = GetDisplayModeList(output); |
149 if (output.type != chromeos::OUTPUT_TYPE_INTERNAL) | |
150 resolutions = GetResolutionList(output); | |
151 | 153 |
152 std::string name = output.type == chromeos::OUTPUT_TYPE_INTERNAL ? | 154 std::string name = output.type == chromeos::OUTPUT_TYPE_INTERNAL ? |
153 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : | 155 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : |
154 chromeos::GetDisplayName(output.output); | 156 chromeos::GetDisplayName(output.output); |
155 if (name.empty()) | 157 if (name.empty()) |
156 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); | 158 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
157 | 159 |
158 bool has_overscan = false; | 160 bool has_overscan = false; |
159 chromeos::GetOutputOverscanFlag(output.output, &has_overscan); | 161 chromeos::GetOutputOverscanFlag(output.output, &has_overscan); |
160 | 162 |
161 int64 id = output.display_id; | 163 int64 id = output.display_id; |
162 if (id == gfx::Display::kInvalidDisplayID || ids.find(id) != ids.end()) | 164 if (id == gfx::Display::kInvalidDisplayID || ids.find(id) != ids.end()) |
163 id = output.index; | 165 id = output.index; |
164 ids.insert(id); | 166 ids.insert(id); |
165 | 167 |
166 displays.push_back(DisplayInfo(id, name, has_overscan)); | 168 displays.push_back(DisplayInfo(id, name, has_overscan)); |
167 displays.back().set_device_scale_factor(device_scale_factor); | 169 displays.back().set_device_scale_factor(device_scale_factor); |
168 displays.back().SetBounds(display_bounds); | 170 displays.back().SetBounds(display_bounds); |
169 displays.back().set_native(true); | 171 displays.back().set_native(true); |
170 displays.back().set_resolutions(resolutions); | 172 displays.back().set_display_modes(display_modes); |
171 displays.back().set_touch_support( | 173 displays.back().set_touch_support( |
172 output.touch_device_id == 0 ? gfx::Display::TOUCH_SUPPORT_UNAVAILABLE : | 174 output.touch_device_id == 0 ? gfx::Display::TOUCH_SUPPORT_UNAVAILABLE : |
173 gfx::Display::TOUCH_SUPPORT_AVAILABLE); | 175 gfx::Display::TOUCH_SUPPORT_AVAILABLE); |
174 } | 176 } |
175 | 177 |
176 // DisplayManager can be null during the boot. | 178 // DisplayManager can be null during the boot. |
177 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); | 179 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); |
178 } | 180 } |
179 | 181 |
180 void DisplayChangeObserver::OnAppTerminating() { | 182 void DisplayChangeObserver::OnAppTerminating() { |
181 #if defined(USE_ASH) | 183 #if defined(USE_ASH) |
182 // Stop handling display configuration events once the shutdown | 184 // Stop handling display configuration events once the shutdown |
183 // process starts. crbug.com/177014. | 185 // process starts. crbug.com/177014. |
184 Shell::GetInstance()->output_configurator()->Stop(); | 186 Shell::GetInstance()->output_configurator()->Stop(); |
185 #endif | 187 #endif |
186 } | 188 } |
187 | 189 |
188 } // namespace internal | 190 } // namespace internal |
189 } // namespace ash | 191 } // namespace ash |
OLD | NEW |