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

Side by Side Diff: ui/display/manager/chromeos/display_change_observer.cc

Issue 2613493002: Fix namespace for src/ui/display/. (Closed)
Patch Set: Rebase. Created 3 years, 11 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 "ui/display/manager/chromeos/display_change_observer.h" 5 #include "ui/display/manager/chromeos/display_change_observer.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 10 matching lines...) Expand all
21 #include "ui/display/manager/display_manager.h" 21 #include "ui/display/manager/display_manager.h"
22 #include "ui/display/manager/display_manager_utilities.h" 22 #include "ui/display/manager/display_manager_utilities.h"
23 #include "ui/display/types/display_mode.h" 23 #include "ui/display/types/display_mode.h"
24 #include "ui/display/types/display_snapshot.h" 24 #include "ui/display/types/display_snapshot.h"
25 #include "ui/display/util/display_util.h" 25 #include "ui/display/util/display_util.h"
26 #include "ui/events/devices/input_device_manager.h" 26 #include "ui/events/devices/input_device_manager.h"
27 #include "ui/events/devices/touchscreen_device.h" 27 #include "ui/events/devices/touchscreen_device.h"
28 #include "ui/strings/grit/ui_strings.h" 28 #include "ui/strings/grit/ui_strings.h"
29 29
30 namespace display { 30 namespace display {
31
32 using ui::DisplayConfigurator;
33
34 namespace { 31 namespace {
35 32
36 // The DPI threshold to determine the device scale factor. 33 // The DPI threshold to determine the device scale factor.
37 // DPI higher than |dpi| will use |device_scale_factor|. 34 // DPI higher than |dpi| will use |device_scale_factor|.
38 struct DeviceScaleFactorDPIThreshold { 35 struct DeviceScaleFactorDPIThreshold {
39 float dpi; 36 float dpi;
40 float device_scale_factor; 37 float device_scale_factor;
41 }; 38 };
42 39
43 const DeviceScaleFactorDPIThreshold kThresholdTable[] = { 40 const DeviceScaleFactorDPIThreshold kThresholdTable[] = {
44 {200.0f, 2.0f}, 41 {200.0f, 2.0f},
45 {150.0f, 1.25f}, 42 {150.0f, 1.25f},
46 {0.0f, 1.0f}, 43 {0.0f, 1.0f},
47 }; 44 };
48 45
49 // 1 inch in mm. 46 // 1 inch in mm.
50 const float kInchInMm = 25.4f; 47 const float kInchInMm = 25.4f;
51 48
52 // The minimum pixel width whose monitor can be called as '4K'. 49 // The minimum pixel width whose monitor can be called as '4K'.
53 const int kMinimumWidthFor4K = 3840; 50 const int kMinimumWidthFor4K = 3840;
54 51
55 // The list of device scale factors (in addition to 1.0f) which is 52 // The list of device scale factors (in addition to 1.0f) which is
56 // available in external large monitors. 53 // available in external large monitors.
57 const float kAdditionalDeviceScaleFactorsFor4k[] = {1.25f, 2.0f}; 54 const float kAdditionalDeviceScaleFactorsFor4k[] = {1.25f, 2.0f};
58 55
59 void UpdateInternalDisplayId( 56 void UpdateInternalDisplayId(
60 const ui::DisplayConfigurator::DisplayStateList& display_states) { 57 const DisplayConfigurator::DisplayStateList& display_states) {
61 for (auto* state : display_states) { 58 for (auto* state : display_states) {
62 if (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { 59 if (state->type() == DISPLAY_CONNECTION_TYPE_INTERNAL) {
63 if (Display::HasInternalDisplay()) 60 if (Display::HasInternalDisplay())
64 DCHECK_EQ(Display::InternalDisplayId(), state->display_id()); 61 DCHECK_EQ(Display::InternalDisplayId(), state->display_id());
65 Display::SetInternalDisplayId(state->display_id()); 62 Display::SetInternalDisplayId(state->display_id());
66 } 63 }
67 } 64 }
68 } 65 }
69 66
70 } // namespace 67 } // namespace
71 68
72 // static 69 // static
73 ManagedDisplayInfo::ManagedDisplayModeList 70 ManagedDisplayInfo::ManagedDisplayModeList
74 DisplayChangeObserver::GetInternalManagedDisplayModeList( 71 DisplayChangeObserver::GetInternalManagedDisplayModeList(
75 const ManagedDisplayInfo& display_info, 72 const ManagedDisplayInfo& display_info,
76 const ui::DisplaySnapshot& output) { 73 const DisplaySnapshot& output) {
77 const ui::DisplayMode* ui_native_mode = output.native_mode(); 74 const DisplayMode* ui_native_mode = output.native_mode();
78 scoped_refptr<ManagedDisplayMode> native_mode = new ManagedDisplayMode( 75 scoped_refptr<ManagedDisplayMode> native_mode = new ManagedDisplayMode(
79 ui_native_mode->size(), ui_native_mode->refresh_rate(), 76 ui_native_mode->size(), ui_native_mode->refresh_rate(),
80 ui_native_mode->is_interlaced(), true, 1.0, 77 ui_native_mode->is_interlaced(), true, 1.0,
81 display_info.device_scale_factor()); 78 display_info.device_scale_factor());
82 79
83 return CreateInternalManagedDisplayModeList(native_mode); 80 return CreateInternalManagedDisplayModeList(native_mode);
84 } 81 }
85 82
86 // static 83 // static
87 ManagedDisplayInfo::ManagedDisplayModeList 84 ManagedDisplayInfo::ManagedDisplayModeList
88 DisplayChangeObserver::GetExternalManagedDisplayModeList( 85 DisplayChangeObserver::GetExternalManagedDisplayModeList(
89 const ui::DisplaySnapshot& output) { 86 const DisplaySnapshot& output) {
90 using DisplayModeMap = 87 using DisplayModeMap =
91 std::map<std::pair<int, int>, scoped_refptr<ManagedDisplayMode>>; 88 std::map<std::pair<int, int>, scoped_refptr<ManagedDisplayMode>>;
92 DisplayModeMap display_mode_map; 89 DisplayModeMap display_mode_map;
93 90
94 scoped_refptr<ManagedDisplayMode> native_mode = new ManagedDisplayMode(); 91 scoped_refptr<ManagedDisplayMode> native_mode = new ManagedDisplayMode();
95 for (const auto& mode_info : output.modes()) { 92 for (const auto& mode_info : output.modes()) {
96 const std::pair<int, int> size(mode_info->size().width(), 93 const std::pair<int, int> size(mode_info->size().width(),
97 mode_info->size().height()); 94 mode_info->size().height());
98 scoped_refptr<ManagedDisplayMode> display_mode = new ManagedDisplayMode( 95 scoped_refptr<ManagedDisplayMode> display_mode = new ManagedDisplayMode(
99 mode_info->size(), mode_info->refresh_rate(), 96 mode_info->size(), mode_info->refresh_rate(),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 native_mode->is_interlaced(), false /* native */, 132 native_mode->is_interlaced(), false /* native */,
136 native_mode->ui_scale(), kAdditionalDeviceScaleFactorsFor4k[i]); 133 native_mode->ui_scale(), kAdditionalDeviceScaleFactorsFor4k[i]);
137 display_mode_list.push_back(mode); 134 display_mode_list.push_back(mode);
138 } 135 }
139 } 136 }
140 137
141 return display_mode_list; 138 return display_mode_list;
142 } 139 }
143 140
144 DisplayChangeObserver::DisplayChangeObserver( 141 DisplayChangeObserver::DisplayChangeObserver(
145 ui::DisplayConfigurator* display_configurator, 142 DisplayConfigurator* display_configurator,
146 display::DisplayManager* display_manager) 143 DisplayManager* display_manager)
147 : display_configurator_(display_configurator), 144 : display_configurator_(display_configurator),
148 display_manager_(display_manager) { 145 display_manager_(display_manager) {
149 ui::InputDeviceManager::GetInstance()->AddObserver(this); 146 ui::InputDeviceManager::GetInstance()->AddObserver(this);
150 } 147 }
151 148
152 DisplayChangeObserver::~DisplayChangeObserver() { 149 DisplayChangeObserver::~DisplayChangeObserver() {
153 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); 150 ui::InputDeviceManager::GetInstance()->RemoveObserver(this);
154 } 151 }
155 152
156 ui::MultipleDisplayState DisplayChangeObserver::GetStateForDisplayIds( 153 MultipleDisplayState DisplayChangeObserver::GetStateForDisplayIds(
157 const ui::DisplayConfigurator::DisplayStateList& display_states) const { 154 const DisplayConfigurator::DisplayStateList& display_states) const {
158 UpdateInternalDisplayId(display_states); 155 UpdateInternalDisplayId(display_states);
159 if (display_states.size() == 1) 156 if (display_states.size() == 1)
160 return ui::MULTIPLE_DISPLAY_STATE_SINGLE; 157 return MULTIPLE_DISPLAY_STATE_SINGLE;
161 DisplayIdList list = 158 DisplayIdList list =
162 GenerateDisplayIdList(display_states.begin(), display_states.end(), 159 GenerateDisplayIdList(display_states.begin(), display_states.end(),
163 [](const ui::DisplaySnapshot* display_state) { 160 [](const DisplaySnapshot* display_state) {
164 return display_state->display_id(); 161 return display_state->display_id();
165 }); 162 });
166 163
167 const DisplayLayout& layout = 164 const DisplayLayout& layout =
168 display_manager_->layout_store()->GetRegisteredDisplayLayout(list); 165 display_manager_->layout_store()->GetRegisteredDisplayLayout(list);
169 return layout.mirrored ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR 166 return layout.mirrored ? MULTIPLE_DISPLAY_STATE_DUAL_MIRROR
170 : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED; 167 : MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED;
171 } 168 }
172 169
173 bool DisplayChangeObserver::GetResolutionForDisplayId(int64_t display_id, 170 bool DisplayChangeObserver::GetResolutionForDisplayId(int64_t display_id,
174 gfx::Size* size) const { 171 gfx::Size* size) const {
175 scoped_refptr<ManagedDisplayMode> mode = 172 scoped_refptr<ManagedDisplayMode> mode =
176 display_manager_->GetSelectedModeForDisplayId(display_id); 173 display_manager_->GetSelectedModeForDisplayId(display_id);
177 if (!mode) 174 if (!mode)
178 return false; 175 return false;
179 *size = mode->size(); 176 *size = mode->size();
180 return true; 177 return true;
181 } 178 }
182 179
183 void DisplayChangeObserver::OnDisplayModeChanged( 180 void DisplayChangeObserver::OnDisplayModeChanged(
184 const ui::DisplayConfigurator::DisplayStateList& display_states) { 181 const DisplayConfigurator::DisplayStateList& display_states) {
185 UpdateInternalDisplayId(display_states); 182 UpdateInternalDisplayId(display_states);
186 183
187 std::vector<ManagedDisplayInfo> displays; 184 std::vector<ManagedDisplayInfo> displays;
188 std::set<int64_t> ids; 185 std::set<int64_t> ids;
189 for (const ui::DisplaySnapshot* state : display_states) { 186 for (const DisplaySnapshot* state : display_states) {
190 const ui::DisplayMode* mode_info = state->current_mode(); 187 const DisplayMode* mode_info = state->current_mode();
191 if (!mode_info) 188 if (!mode_info)
192 continue; 189 continue;
193 190
194 float device_scale_factor = 1.0f; 191 float device_scale_factor = 1.0f;
195 // Sets dpi only if the screen size is not blacklisted. 192 // Sets dpi only if the screen size is not blacklisted.
196 float dpi = IsDisplaySizeBlackListed(state->physical_size()) 193 float dpi = IsDisplaySizeBlackListed(state->physical_size())
197 ? 0 194 ? 0
198 : kInchInMm * mode_info->size().width() / 195 : kInchInMm * mode_info->size().width() /
199 state->physical_size().width(); 196 state->physical_size().width();
200 if (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { 197 if (state->type() == DISPLAY_CONNECTION_TYPE_INTERNAL) {
201 if (dpi) 198 if (dpi)
202 device_scale_factor = FindDeviceScaleFactor(dpi); 199 device_scale_factor = FindDeviceScaleFactor(dpi);
203 } else { 200 } else {
204 scoped_refptr<ManagedDisplayMode> mode = 201 scoped_refptr<ManagedDisplayMode> mode =
205 display_manager_->GetSelectedModeForDisplayId(state->display_id()); 202 display_manager_->GetSelectedModeForDisplayId(state->display_id());
206 if (mode) { 203 if (mode) {
207 device_scale_factor = mode->device_scale_factor(); 204 device_scale_factor = mode->device_scale_factor();
208 } else { 205 } else {
209 // For monitors that are 40 inches and 4K or above, set 206 // For monitors that are 40 inches and 4K or above, set
210 // |device_scale_factor| to 2x. For margin purposes, 100 is subtracted 207 // |device_scale_factor| to 2x. For margin purposes, 100 is subtracted
211 // from the value of |k2xThreshouldSizeSquaredFor4KInMm| 208 // from the value of |k2xThreshouldSizeSquaredFor4KInMm|
212 const int k2xThreshouldSizeSquaredFor4KInMm = 209 const int k2xThreshouldSizeSquaredFor4KInMm =
213 (40 * 40 * kInchInMm * kInchInMm) - 100; 210 (40 * 40 * kInchInMm * kInchInMm) - 100;
214 gfx::Vector2d size_in_vec(state->physical_size().width(), 211 gfx::Vector2d size_in_vec(state->physical_size().width(),
215 state->physical_size().height()); 212 state->physical_size().height());
216 if (size_in_vec.LengthSquared() > k2xThreshouldSizeSquaredFor4KInMm && 213 if (size_in_vec.LengthSquared() > k2xThreshouldSizeSquaredFor4KInMm &&
217 mode_info->size().width() >= kMinimumWidthFor4K) { 214 mode_info->size().width() >= kMinimumWidthFor4K) {
218 // Make sure that additional device scale factors table has 2x. 215 // Make sure that additional device scale factors table has 2x.
219 DCHECK_EQ(2.0f, kAdditionalDeviceScaleFactorsFor4k[1]); 216 DCHECK_EQ(2.0f, kAdditionalDeviceScaleFactorsFor4k[1]);
220 device_scale_factor = 2.0f; 217 device_scale_factor = 2.0f;
221 } 218 }
222 } 219 }
223 } 220 }
224 gfx::Rect display_bounds(state->origin(), mode_info->size()); 221 gfx::Rect display_bounds(state->origin(), mode_info->size());
225 222
226 std::string name; 223 std::string name;
227 switch (state->type()) { 224 switch (state->type()) {
228 case ui::DISPLAY_CONNECTION_TYPE_INTERNAL: 225 case DISPLAY_CONNECTION_TYPE_INTERNAL:
229 name = l10n_util::GetStringUTF8(IDS_DISPLAY_NAME_INTERNAL); 226 name = l10n_util::GetStringUTF8(IDS_DISPLAY_NAME_INTERNAL);
230 break; 227 break;
231 case ui::DISPLAY_CONNECTION_TYPE_VIRTUAL: 228 case DISPLAY_CONNECTION_TYPE_VIRTUAL:
232 name = l10n_util::GetStringUTF8(IDS_DISPLAY_NAME_VIRTUAL); 229 name = l10n_util::GetStringUTF8(IDS_DISPLAY_NAME_VIRTUAL);
233 break; 230 break;
234 default: 231 default:
235 name = state->display_name(); 232 name = state->display_name();
236 } 233 }
237 234
238 if (name.empty()) 235 if (name.empty())
239 name = l10n_util::GetStringUTF8(IDS_DISPLAY_NAME_UNKNOWN); 236 name = l10n_util::GetStringUTF8(IDS_DISPLAY_NAME_UNKNOWN);
240 237
241 bool has_overscan = state->has_overscan(); 238 bool has_overscan = state->has_overscan();
242 int64_t id = state->display_id(); 239 int64_t id = state->display_id();
243 ids.insert(id); 240 ids.insert(id);
244 241
245 displays.push_back(ManagedDisplayInfo(id, name, has_overscan)); 242 displays.push_back(ManagedDisplayInfo(id, name, has_overscan));
246 ManagedDisplayInfo& new_info = displays.back(); 243 ManagedDisplayInfo& new_info = displays.back();
247 new_info.set_sys_path(state->sys_path()); 244 new_info.set_sys_path(state->sys_path());
248 new_info.set_device_scale_factor(device_scale_factor); 245 new_info.set_device_scale_factor(device_scale_factor);
249 new_info.SetBounds(display_bounds); 246 new_info.SetBounds(display_bounds);
250 new_info.set_native(true); 247 new_info.set_native(true);
251 new_info.set_is_aspect_preserving_scaling( 248 new_info.set_is_aspect_preserving_scaling(
252 state->is_aspect_preserving_scaling()); 249 state->is_aspect_preserving_scaling());
253 if (dpi) 250 if (dpi)
254 new_info.set_device_dpi(dpi); 251 new_info.set_device_dpi(dpi);
255 252
256 ManagedDisplayInfo::ManagedDisplayModeList display_modes = 253 ManagedDisplayInfo::ManagedDisplayModeList display_modes =
257 (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) 254 (state->type() == DISPLAY_CONNECTION_TYPE_INTERNAL)
258 ? GetInternalManagedDisplayModeList(new_info, *state) 255 ? GetInternalManagedDisplayModeList(new_info, *state)
259 : GetExternalManagedDisplayModeList(*state); 256 : GetExternalManagedDisplayModeList(*state);
260 new_info.SetManagedDisplayModes(display_modes); 257 new_info.SetManagedDisplayModes(display_modes);
261 258
262 new_info.set_available_color_profiles( 259 new_info.set_available_color_profiles(
263 display_configurator_->GetAvailableColorCalibrationProfiles(id)); 260 display_configurator_->GetAvailableColorCalibrationProfiles(id));
264 new_info.set_maximum_cursor_size(state->maximum_cursor_size()); 261 new_info.set_maximum_cursor_size(state->maximum_cursor_size());
265 } 262 }
266 263
267 AssociateTouchscreens( 264 AssociateTouchscreens(
268 &displays, 265 &displays,
269 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices()); 266 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices());
270 display_manager_->OnNativeDisplaysChanged(displays); 267 display_manager_->OnNativeDisplaysChanged(displays);
271 268
272 // For the purposes of user activity detection, ignore synthetic mouse events 269 // For the purposes of user activity detection, ignore synthetic mouse events
273 // that are triggered by screen resizes: http://crbug.com/360634 270 // that are triggered by screen resizes: http://crbug.com/360634
274 ui::UserActivityDetector* user_activity_detector = 271 ui::UserActivityDetector* user_activity_detector =
275 ui::UserActivityDetector::Get(); 272 ui::UserActivityDetector::Get();
276 if (user_activity_detector) 273 if (user_activity_detector)
277 user_activity_detector->OnDisplayPowerChanging(); 274 user_activity_detector->OnDisplayPowerChanging();
278 } 275 }
279 276
280 void DisplayChangeObserver::OnDisplayModeChangeFailed( 277 void DisplayChangeObserver::OnDisplayModeChangeFailed(
281 const ui::DisplayConfigurator::DisplayStateList& displays, 278 const DisplayConfigurator::DisplayStateList& displays,
282 ui::MultipleDisplayState failed_new_state) { 279 MultipleDisplayState failed_new_state) {
283 // If display configuration failed during startup, simply update the display 280 // If display configuration failed during startup, simply update the display
284 // manager with detected displays. If no display is detected, it will 281 // manager with detected displays. If no display is detected, it will
285 // create a pseudo display. 282 // create a pseudo display.
286 if (display_manager_->GetNumDisplays() == 0) 283 if (display_manager_->GetNumDisplays() == 0)
287 OnDisplayModeChanged(displays); 284 OnDisplayModeChanged(displays);
288 } 285 }
289 286
290 void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() { 287 void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() {
291 // If there are no cached display snapshots, either there are no attached 288 // If there are no cached display snapshots, either there are no attached
292 // displays or the cached snapshots have been invalidated. For the first case 289 // displays or the cached snapshots have been invalidated. For the first case
(...skipping 10 matching lines...) Expand all
303 // static 300 // static
304 float DisplayChangeObserver::FindDeviceScaleFactor(float dpi) { 301 float DisplayChangeObserver::FindDeviceScaleFactor(float dpi) {
305 for (size_t i = 0; i < arraysize(kThresholdTable); ++i) { 302 for (size_t i = 0; i < arraysize(kThresholdTable); ++i) {
306 if (dpi > kThresholdTable[i].dpi) 303 if (dpi > kThresholdTable[i].dpi)
307 return kThresholdTable[i].device_scale_factor; 304 return kThresholdTable[i].device_scale_factor;
308 } 305 }
309 return 1.0f; 306 return 1.0f;
310 } 307 }
311 308
312 } // namespace display 309 } // namespace display
OLDNEW
« no previous file with comments | « ui/display/manager/chromeos/display_change_observer.h ('k') | ui/display/manager/chromeos/display_change_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698