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

Side by Side Diff: ash/display/display_change_observer_chromeos.cc

Issue 2270553002: Move ash::DisplayInfo to ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 3 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
OLDNEW
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 <string> 10 #include <string>
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 if (display::Display::HasInternalDisplay()) 68 if (display::Display::HasInternalDisplay())
69 DCHECK_EQ(display::Display::InternalDisplayId(), state->display_id()); 69 DCHECK_EQ(display::Display::InternalDisplayId(), state->display_id());
70 display::Display::SetInternalDisplayId(state->display_id()); 70 display::Display::SetInternalDisplayId(state->display_id());
71 } 71 }
72 } 72 }
73 } 73 }
74 74
75 } // namespace 75 } // namespace
76 76
77 // static 77 // static
78 DisplayInfo::ManagedDisplayModeList 78 display::ManagedDisplayInfo::ManagedDisplayModeList
79 DisplayChangeObserver::GetInternalManagedDisplayModeList( 79 DisplayChangeObserver::GetInternalManagedDisplayModeList(
80 const DisplayInfo& display_info, 80 const display::ManagedDisplayInfo& display_info,
81 const ui::DisplaySnapshot& output) { 81 const ui::DisplaySnapshot& output) {
82 const ui::DisplayMode* ui_native_mode = output.native_mode(); 82 const ui::DisplayMode* ui_native_mode = output.native_mode();
83 scoped_refptr<ManagedDisplayMode> native_mode = new ManagedDisplayMode( 83 scoped_refptr<display::ManagedDisplayMode> native_mode =
84 ui_native_mode->size(), ui_native_mode->refresh_rate(), 84 new display::ManagedDisplayMode(ui_native_mode->size(),
85 ui_native_mode->is_interlaced(), true, 1.0, 85 ui_native_mode->refresh_rate(),
86 display_info.device_scale_factor()); 86 ui_native_mode->is_interlaced(), true,
87 1.0, display_info.device_scale_factor());
87 88
88 return CreateInternalManagedDisplayModeList(native_mode); 89 return CreateInternalManagedDisplayModeList(native_mode);
89 } 90 }
90 91
91 // static 92 // static
92 DisplayInfo::ManagedDisplayModeList 93 display::ManagedDisplayInfo::ManagedDisplayModeList
93 DisplayChangeObserver::GetExternalManagedDisplayModeList( 94 DisplayChangeObserver::GetExternalManagedDisplayModeList(
94 const ui::DisplaySnapshot& output) { 95 const ui::DisplaySnapshot& output) {
95 using DisplayModeMap = 96 using DisplayModeMap =
96 std::map<std::pair<int, int>, scoped_refptr<ManagedDisplayMode>>; 97 std::map<std::pair<int, int>, scoped_refptr<display::ManagedDisplayMode>>;
97 DisplayModeMap display_mode_map; 98 DisplayModeMap display_mode_map;
98 99
99 scoped_refptr<ManagedDisplayMode> native_mode = new ManagedDisplayMode(); 100 scoped_refptr<display::ManagedDisplayMode> native_mode =
101 new display::ManagedDisplayMode();
100 for (const auto& mode_info : output.modes()) { 102 for (const auto& mode_info : output.modes()) {
101 const std::pair<int, int> size(mode_info->size().width(), 103 const std::pair<int, int> size(mode_info->size().width(),
102 mode_info->size().height()); 104 mode_info->size().height());
103 scoped_refptr<ManagedDisplayMode> display_mode = new ManagedDisplayMode( 105 scoped_refptr<display::ManagedDisplayMode> display_mode =
104 mode_info->size(), mode_info->refresh_rate(), 106 new display::ManagedDisplayMode(
105 mode_info->is_interlaced(), output.native_mode() == mode_info.get(), 107 mode_info->size(), mode_info->refresh_rate(),
106 1.0, 1.0); 108 mode_info->is_interlaced(), output.native_mode() == mode_info.get(),
109 1.0, 1.0);
107 if (display_mode->native()) 110 if (display_mode->native())
108 native_mode = display_mode; 111 native_mode = display_mode;
109 112
110 // Add the display mode if it isn't already present and override interlaced 113 // Add the display mode if it isn't already present and override interlaced
111 // display modes with non-interlaced ones. 114 // display modes with non-interlaced ones.
112 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size); 115 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size);
113 if (display_mode_it == display_mode_map.end()) 116 if (display_mode_it == display_mode_map.end())
114 display_mode_map.insert(std::make_pair(size, display_mode)); 117 display_mode_map.insert(std::make_pair(size, display_mode));
115 else if (display_mode_it->second->is_interlaced() && 118 else if (display_mode_it->second->is_interlaced() &&
116 !display_mode->is_interlaced()) 119 !display_mode->is_interlaced())
117 display_mode_it->second = std::move(display_mode); 120 display_mode_it->second = std::move(display_mode);
118 } 121 }
119 122
120 DisplayInfo::ManagedDisplayModeList display_mode_list; 123 display::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list;
121 for (const auto& display_mode_pair : display_mode_map) 124 for (const auto& display_mode_pair : display_mode_map)
122 display_mode_list.push_back(std::move(display_mode_pair.second)); 125 display_mode_list.push_back(std::move(display_mode_pair.second));
123 126
124 if (output.native_mode()) { 127 if (output.native_mode()) {
125 const std::pair<int, int> size(native_mode->size().width(), 128 const std::pair<int, int> size(native_mode->size().width(),
126 native_mode->size().height()); 129 native_mode->size().height());
127 DisplayModeMap::iterator it = display_mode_map.find(size); 130 DisplayModeMap::iterator it = display_mode_map.find(size);
128 DCHECK(it != display_mode_map.end()) 131 DCHECK(it != display_mode_map.end())
129 << "Native mode must be part of the mode list."; 132 << "Native mode must be part of the mode list.";
130 133
131 // If the native mode was replaced re-add it. 134 // If the native mode was replaced re-add it.
132 if (!it->second->native()) 135 if (!it->second->native())
133 display_mode_list.push_back(native_mode); 136 display_mode_list.push_back(native_mode);
134 } 137 }
135 138
136 if (native_mode->size().width() >= kMinimumWidthFor4K) { 139 if (native_mode->size().width() >= kMinimumWidthFor4K) {
137 for (size_t i = 0; i < arraysize(kAdditionalDeviceScaleFactorsFor4k); ++i) { 140 for (size_t i = 0; i < arraysize(kAdditionalDeviceScaleFactorsFor4k); ++i) {
138 scoped_refptr<ManagedDisplayMode> mode = new ManagedDisplayMode( 141 scoped_refptr<display::ManagedDisplayMode> mode =
139 native_mode->size(), native_mode->refresh_rate(), 142 new display::ManagedDisplayMode(
140 native_mode->is_interlaced(), false /* native */, 143 native_mode->size(), native_mode->refresh_rate(),
141 native_mode->ui_scale(), kAdditionalDeviceScaleFactorsFor4k[i]); 144 native_mode->is_interlaced(), false /* native */,
145 native_mode->ui_scale(), kAdditionalDeviceScaleFactorsFor4k[i]);
142 display_mode_list.push_back(mode); 146 display_mode_list.push_back(mode);
143 } 147 }
144 } 148 }
145 149
146 return display_mode_list; 150 return display_mode_list;
147 } 151 }
148 152
149 DisplayChangeObserver::DisplayChangeObserver() { 153 DisplayChangeObserver::DisplayChangeObserver() {
150 WmShell::Get()->AddShellObserver(this); 154 WmShell::Get()->AddShellObserver(this);
151 ui::InputDeviceManager::GetInstance()->AddObserver(this); 155 ui::InputDeviceManager::GetInstance()->AddObserver(this);
(...skipping 18 matching lines...) Expand all
170 const display::DisplayLayout& layout = Shell::GetInstance() 174 const display::DisplayLayout& layout = Shell::GetInstance()
171 ->display_manager() 175 ->display_manager()
172 ->layout_store() 176 ->layout_store()
173 ->GetRegisteredDisplayLayout(list); 177 ->GetRegisteredDisplayLayout(list);
174 return layout.mirrored ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR 178 return layout.mirrored ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR
175 : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED; 179 : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED;
176 } 180 }
177 181
178 bool DisplayChangeObserver::GetResolutionForDisplayId(int64_t display_id, 182 bool DisplayChangeObserver::GetResolutionForDisplayId(int64_t display_id,
179 gfx::Size* size) const { 183 gfx::Size* size) const {
180 scoped_refptr<ManagedDisplayMode> mode = 184 scoped_refptr<display::ManagedDisplayMode> mode =
181 Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( 185 Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId(
182 display_id); 186 display_id);
183 if (!mode) 187 if (!mode)
184 return false; 188 return false;
185 *size = mode->size(); 189 *size = mode->size();
186 return true; 190 return true;
187 } 191 }
188 192
189 void DisplayChangeObserver::OnDisplayModeChanged( 193 void DisplayChangeObserver::OnDisplayModeChanged(
190 const ui::DisplayConfigurator::DisplayStateList& display_states) { 194 const ui::DisplayConfigurator::DisplayStateList& display_states) {
191 UpdateInternalDisplayId(display_states); 195 UpdateInternalDisplayId(display_states);
192 196
193 std::vector<DisplayInfo> displays; 197 std::vector<display::ManagedDisplayInfo> displays;
194 std::set<int64_t> ids; 198 std::set<int64_t> ids;
195 for (const ui::DisplaySnapshot* state : display_states) { 199 for (const ui::DisplaySnapshot* state : display_states) {
196 const ui::DisplayMode* mode_info = state->current_mode(); 200 const ui::DisplayMode* mode_info = state->current_mode();
197 if (!mode_info) 201 if (!mode_info)
198 continue; 202 continue;
199 203
200 float device_scale_factor = 1.0f; 204 float device_scale_factor = 1.0f;
201 // Sets dpi only if the screen size is not blacklisted. 205 // Sets dpi only if the screen size is not blacklisted.
202 float dpi = ui::IsDisplaySizeBlackListed(state->physical_size()) 206 float dpi = ui::IsDisplaySizeBlackListed(state->physical_size())
203 ? 0 207 ? 0
204 : kInchInMm * mode_info->size().width() / 208 : kInchInMm * mode_info->size().width() /
205 state->physical_size().width(); 209 state->physical_size().width();
206 if (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { 210 if (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) {
207 if (dpi) 211 if (dpi)
208 device_scale_factor = FindDeviceScaleFactor(dpi); 212 device_scale_factor = FindDeviceScaleFactor(dpi);
209 } else { 213 } else {
210 scoped_refptr<ManagedDisplayMode> mode = 214 scoped_refptr<display::ManagedDisplayMode> mode =
211 Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( 215 Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId(
212 state->display_id()); 216 state->display_id());
213 if (mode) { 217 if (mode) {
214 device_scale_factor = mode->device_scale_factor(); 218 device_scale_factor = mode->device_scale_factor();
215 } else { 219 } else {
216 // For monitors that are 40 inches and 4K or above, set 220 // For monitors that are 40 inches and 4K or above, set
217 // |device_scale_factor| to 2x. For margin purposes, 100 is subtracted 221 // |device_scale_factor| to 2x. For margin purposes, 100 is subtracted
218 // from the value of |k2xThreshouldSizeSquaredFor4KInMm| 222 // from the value of |k2xThreshouldSizeSquaredFor4KInMm|
219 const int k2xThreshouldSizeSquaredFor4KInMm = 223 const int k2xThreshouldSizeSquaredFor4KInMm =
220 (40 * 40 * kInchInMm * kInchInMm) - 100; 224 (40 * 40 * kInchInMm * kInchInMm) - 100;
(...skipping 21 matching lines...) Expand all
242 name = state->display_name(); 246 name = state->display_name();
243 } 247 }
244 248
245 if (name.empty()) 249 if (name.empty())
246 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); 250 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
247 251
248 bool has_overscan = state->has_overscan(); 252 bool has_overscan = state->has_overscan();
249 int64_t id = state->display_id(); 253 int64_t id = state->display_id();
250 ids.insert(id); 254 ids.insert(id);
251 255
252 displays.push_back(DisplayInfo(id, name, has_overscan)); 256 displays.push_back(display::ManagedDisplayInfo(id, name, has_overscan));
253 DisplayInfo& new_info = displays.back(); 257 display::ManagedDisplayInfo& new_info = displays.back();
254 new_info.set_sys_path(state->sys_path()); 258 new_info.set_sys_path(state->sys_path());
255 new_info.set_device_scale_factor(device_scale_factor); 259 new_info.set_device_scale_factor(device_scale_factor);
256 new_info.SetBounds(display_bounds); 260 new_info.SetBounds(display_bounds);
257 new_info.set_native(true); 261 new_info.set_native(true);
258 new_info.set_is_aspect_preserving_scaling( 262 new_info.set_is_aspect_preserving_scaling(
259 state->is_aspect_preserving_scaling()); 263 state->is_aspect_preserving_scaling());
260 if (dpi) 264 if (dpi)
261 new_info.set_device_dpi(dpi); 265 new_info.set_device_dpi(dpi);
262 266
263 DisplayInfo::ManagedDisplayModeList display_modes = 267 display::ManagedDisplayInfo::ManagedDisplayModeList display_modes =
264 (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) 268 (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL)
265 ? GetInternalManagedDisplayModeList(new_info, *state) 269 ? GetInternalManagedDisplayModeList(new_info, *state)
266 : GetExternalManagedDisplayModeList(*state); 270 : GetExternalManagedDisplayModeList(*state);
267 new_info.SetManagedDisplayModes(display_modes); 271 new_info.SetManagedDisplayModes(display_modes);
268 272
269 new_info.set_available_color_profiles( 273 new_info.set_available_color_profiles(
270 Shell::GetInstance() 274 Shell::GetInstance()
271 ->display_configurator() 275 ->display_configurator()
272 ->GetAvailableColorCalibrationProfiles(id)); 276 ->GetAvailableColorCalibrationProfiles(id));
273 new_info.set_maximum_cursor_size(state->maximum_cursor_size()); 277 new_info.set_maximum_cursor_size(state->maximum_cursor_size());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 315 }
312 return 1.0f; 316 return 1.0f;
313 } 317 }
314 318
315 void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() { 319 void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() {
316 OnDisplayModeChanged( 320 OnDisplayModeChanged(
317 Shell::GetInstance()->display_configurator()->cached_displays()); 321 Shell::GetInstance()->display_configurator()->cached_displays());
318 } 322 }
319 323
320 } // namespace ash 324 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_change_observer_chromeos.h ('k') | ash/display/display_change_observer_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698