| 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 <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "ash/common/ash_switches.h" | 14 #include "ash/common/ash_switches.h" |
| 15 #include "ash/common/display/display_info.h" | |
| 16 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
| 17 #include "ash/display/display_layout_store.h" | 16 #include "ash/display/display_layout_store.h" |
| 18 #include "ash/display/display_manager.h" | 17 #include "ash/display/display_manager.h" |
| 19 #include "ash/display/display_util.h" | 18 #include "ash/display/display_util.h" |
| 20 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 21 #include "ash/touch/touchscreen_util.h" | 20 #include "ash/touch/touchscreen_util.h" |
| 22 #include "base/command_line.h" | 21 #include "base/command_line.h" |
| 23 #include "base/logging.h" | 22 #include "base/logging.h" |
| 24 #include "grit/ash_strings.h" | 23 #include "grit/ash_strings.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 if (display::Display::HasInternalDisplay()) | 68 if (display::Display::HasInternalDisplay()) |
| 70 DCHECK_EQ(display::Display::InternalDisplayId(), state->display_id()); | 69 DCHECK_EQ(display::Display::InternalDisplayId(), state->display_id()); |
| 71 display::Display::SetInternalDisplayId(state->display_id()); | 70 display::Display::SetInternalDisplayId(state->display_id()); |
| 72 } | 71 } |
| 73 } | 72 } |
| 74 } | 73 } |
| 75 | 74 |
| 76 } // namespace | 75 } // namespace |
| 77 | 76 |
| 78 // static | 77 // static |
| 79 std::vector<DisplayMode> DisplayChangeObserver::GetInternalDisplayModeList( | 78 DisplayInfo::DisplayModeList DisplayChangeObserver::GetInternalDisplayModeList( |
| 80 const DisplayInfo& display_info, | 79 const DisplayInfo& display_info, |
| 81 const ui::DisplaySnapshot& output) { | 80 const ui::DisplaySnapshot& output) { |
| 82 const ui::DisplayMode* ui_native_mode = output.native_mode(); | 81 const ui::DisplayMode* ui_native_mode = output.native_mode(); |
| 83 DisplayMode native_mode(ui_native_mode->size(), | 82 scoped_refptr<DisplayMode> native_mode = |
| 84 ui_native_mode->refresh_rate(), | 83 new DisplayMode(ui_native_mode->size(), ui_native_mode->refresh_rate(), |
| 85 ui_native_mode->is_interlaced(), true); | 84 ui_native_mode->is_interlaced(), true, 1.0, |
| 86 native_mode.device_scale_factor = display_info.device_scale_factor(); | 85 display_info.device_scale_factor()); |
| 87 | 86 |
| 88 return CreateInternalDisplayModeList(native_mode); | 87 return CreateInternalDisplayModeList(native_mode); |
| 89 } | 88 } |
| 90 | 89 |
| 91 // static | 90 // static |
| 92 std::vector<DisplayMode> DisplayChangeObserver::GetExternalDisplayModeList( | 91 DisplayInfo::DisplayModeList DisplayChangeObserver::GetExternalDisplayModeList( |
| 93 const ui::DisplaySnapshot& output) { | 92 const ui::DisplaySnapshot& output) { |
| 94 typedef std::map<std::pair<int, int>, DisplayMode> DisplayModeMap; | 93 using DisplayModeMap = |
| 94 std::map<std::pair<int, int>, scoped_refptr<DisplayMode>>; |
| 95 DisplayModeMap display_mode_map; | 95 DisplayModeMap display_mode_map; |
| 96 | 96 |
| 97 DisplayMode native_mode; | 97 scoped_refptr<DisplayMode> native_mode = new DisplayMode(); |
| 98 for (const auto& mode_info : output.modes()) { | 98 for (const auto& mode_info : output.modes()) { |
| 99 const std::pair<int, int> size(mode_info->size().width(), | 99 const std::pair<int, int> size(mode_info->size().width(), |
| 100 mode_info->size().height()); | 100 mode_info->size().height()); |
| 101 const DisplayMode display_mode(mode_info->size(), mode_info->refresh_rate(), | 101 scoped_refptr<DisplayMode> display_mode = |
| 102 mode_info->is_interlaced(), | 102 new DisplayMode(mode_info->size(), mode_info->refresh_rate(), |
| 103 output.native_mode() == mode_info.get()); | 103 mode_info->is_interlaced(), |
| 104 if (display_mode.native) | 104 output.native_mode() == mode_info.get(), 1.0, 1.0); |
| 105 if (display_mode->native()) |
| 105 native_mode = display_mode; | 106 native_mode = display_mode; |
| 106 | 107 |
| 107 // Add the display mode if it isn't already present and override interlaced | 108 // Add the display mode if it isn't already present and override interlaced |
| 108 // display modes with non-interlaced ones. | 109 // display modes with non-interlaced ones. |
| 109 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size); | 110 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size); |
| 110 if (display_mode_it == display_mode_map.end()) | 111 if (display_mode_it == display_mode_map.end()) |
| 111 display_mode_map.insert(std::make_pair(size, display_mode)); | 112 display_mode_map.insert(std::make_pair(size, display_mode)); |
| 112 else if (display_mode_it->second.interlaced && !display_mode.interlaced) | 113 else if (display_mode_it->second->is_interlaced() && |
| 113 display_mode_it->second = display_mode; | 114 !display_mode->is_interlaced()) |
| 115 display_mode_it->second = std::move(display_mode); |
| 114 } | 116 } |
| 115 | 117 |
| 116 std::vector<DisplayMode> display_mode_list; | 118 DisplayInfo::DisplayModeList display_mode_list; |
| 117 for (const auto& display_mode_pair : display_mode_map) | 119 for (const auto& display_mode_pair : display_mode_map) |
| 118 display_mode_list.push_back(display_mode_pair.second); | 120 display_mode_list.push_back(std::move(display_mode_pair.second)); |
| 119 | 121 |
| 120 if (output.native_mode()) { | 122 if (output.native_mode()) { |
| 121 const std::pair<int, int> size(native_mode.size.width(), | 123 const std::pair<int, int> size(native_mode->size().width(), |
| 122 native_mode.size.height()); | 124 native_mode->size().height()); |
| 123 DisplayModeMap::iterator it = display_mode_map.find(size); | 125 DisplayModeMap::iterator it = display_mode_map.find(size); |
| 124 DCHECK(it != display_mode_map.end()) | 126 DCHECK(it != display_mode_map.end()) |
| 125 << "Native mode must be part of the mode list."; | 127 << "Native mode must be part of the mode list."; |
| 126 | 128 |
| 127 // If the native mode was replaced re-add it. | 129 // If the native mode was replaced re-add it. |
| 128 if (!it->second.native) | 130 if (!it->second->native()) |
| 129 display_mode_list.push_back(native_mode); | 131 display_mode_list.push_back(native_mode); |
| 130 } | 132 } |
| 131 | 133 |
| 132 if (native_mode.size.width() >= kMinimumWidthFor4K) { | 134 if (native_mode->size().width() >= kMinimumWidthFor4K) { |
| 133 for (size_t i = 0; i < arraysize(kAdditionalDeviceScaleFactorsFor4k); ++i) { | 135 for (size_t i = 0; i < arraysize(kAdditionalDeviceScaleFactorsFor4k); ++i) { |
| 134 DisplayMode mode = native_mode; | 136 scoped_refptr<DisplayMode> mode = new DisplayMode( |
| 135 mode.device_scale_factor = kAdditionalDeviceScaleFactorsFor4k[i]; | 137 native_mode->size(), native_mode->refresh_rate(), |
| 136 mode.native = false; | 138 native_mode->is_interlaced(), false /* native */, |
| 139 native_mode->ui_scale(), kAdditionalDeviceScaleFactorsFor4k[i]); |
| 137 display_mode_list.push_back(mode); | 140 display_mode_list.push_back(mode); |
| 138 } | 141 } |
| 139 } | 142 } |
| 140 | 143 |
| 141 return display_mode_list; | 144 return display_mode_list; |
| 142 } | 145 } |
| 143 | 146 |
| 144 DisplayChangeObserver::DisplayChangeObserver() { | 147 DisplayChangeObserver::DisplayChangeObserver() { |
| 145 WmShell::Get()->AddShellObserver(this); | 148 WmShell::Get()->AddShellObserver(this); |
| 146 ui::InputDeviceManager::GetInstance()->AddObserver(this); | 149 ui::InputDeviceManager::GetInstance()->AddObserver(this); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 165 const display::DisplayLayout& layout = Shell::GetInstance() | 168 const display::DisplayLayout& layout = Shell::GetInstance() |
| 166 ->display_manager() | 169 ->display_manager() |
| 167 ->layout_store() | 170 ->layout_store() |
| 168 ->GetRegisteredDisplayLayout(list); | 171 ->GetRegisteredDisplayLayout(list); |
| 169 return layout.mirrored ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR | 172 return layout.mirrored ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR |
| 170 : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED; | 173 : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED; |
| 171 } | 174 } |
| 172 | 175 |
| 173 bool DisplayChangeObserver::GetResolutionForDisplayId(int64_t display_id, | 176 bool DisplayChangeObserver::GetResolutionForDisplayId(int64_t display_id, |
| 174 gfx::Size* size) const { | 177 gfx::Size* size) const { |
| 175 DisplayMode mode; | 178 scoped_refptr<DisplayMode> mode = |
| 176 if (!Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( | 179 Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( |
| 177 display_id, &mode)) | 180 display_id); |
| 181 if (!mode) |
| 178 return false; | 182 return false; |
| 179 | 183 *size = mode->size(); |
| 180 *size = mode.size; | |
| 181 return true; | 184 return true; |
| 182 } | 185 } |
| 183 | 186 |
| 184 void DisplayChangeObserver::OnDisplayModeChanged( | 187 void DisplayChangeObserver::OnDisplayModeChanged( |
| 185 const ui::DisplayConfigurator::DisplayStateList& display_states) { | 188 const ui::DisplayConfigurator::DisplayStateList& display_states) { |
| 186 UpdateInternalDisplayId(display_states); | 189 UpdateInternalDisplayId(display_states); |
| 187 | 190 |
| 188 std::vector<DisplayInfo> displays; | 191 std::vector<DisplayInfo> displays; |
| 189 std::set<int64_t> ids; | 192 std::set<int64_t> ids; |
| 190 for (const ui::DisplaySnapshot* state : display_states) { | 193 for (const ui::DisplaySnapshot* state : display_states) { |
| 191 const ui::DisplayMode* mode_info = state->current_mode(); | 194 const ui::DisplayMode* mode_info = state->current_mode(); |
| 192 if (!mode_info) | 195 if (!mode_info) |
| 193 continue; | 196 continue; |
| 194 | 197 |
| 195 float device_scale_factor = 1.0f; | 198 float device_scale_factor = 1.0f; |
| 196 // Sets dpi only if the screen size is not blacklisted. | 199 // Sets dpi only if the screen size is not blacklisted. |
| 197 float dpi = ui::IsDisplaySizeBlackListed(state->physical_size()) | 200 float dpi = ui::IsDisplaySizeBlackListed(state->physical_size()) |
| 198 ? 0 | 201 ? 0 |
| 199 : kInchInMm * mode_info->size().width() / | 202 : kInchInMm * mode_info->size().width() / |
| 200 state->physical_size().width(); | 203 state->physical_size().width(); |
| 201 if (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { | 204 if (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { |
| 202 if (dpi) | 205 if (dpi) |
| 203 device_scale_factor = FindDeviceScaleFactor(dpi); | 206 device_scale_factor = FindDeviceScaleFactor(dpi); |
| 204 } else { | 207 } else { |
| 205 DisplayMode mode; | 208 scoped_refptr<DisplayMode> mode = |
| 206 if (Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( | 209 Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( |
| 207 state->display_id(), &mode)) { | 210 state->display_id()); |
| 208 device_scale_factor = mode.device_scale_factor; | 211 if (mode) { |
| 212 device_scale_factor = mode->device_scale_factor(); |
| 209 } else { | 213 } else { |
| 210 // For monitors that are 40 inches and 4K or above, set | 214 // For monitors that are 40 inches and 4K or above, set |
| 211 // |device_scale_factor| to 2x. For margin purposes, 100 is subtracted | 215 // |device_scale_factor| to 2x. For margin purposes, 100 is subtracted |
| 212 // from the value of |k2xThreshouldSizeSquaredFor4KInMm| | 216 // from the value of |k2xThreshouldSizeSquaredFor4KInMm| |
| 213 const int k2xThreshouldSizeSquaredFor4KInMm = | 217 const int k2xThreshouldSizeSquaredFor4KInMm = |
| 214 (40 * 40 * kInchInMm * kInchInMm) - 100; | 218 (40 * 40 * kInchInMm * kInchInMm) - 100; |
| 215 gfx::Vector2d size_in_vec(state->physical_size().width(), | 219 gfx::Vector2d size_in_vec(state->physical_size().width(), |
| 216 state->physical_size().height()); | 220 state->physical_size().height()); |
| 217 if (size_in_vec.LengthSquared() > k2xThreshouldSizeSquaredFor4KInMm && | 221 if (size_in_vec.LengthSquared() > k2xThreshouldSizeSquaredFor4KInMm && |
| 218 mode_info->size().width() >= kMinimumWidthFor4K) { | 222 mode_info->size().width() >= kMinimumWidthFor4K) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 247 DisplayInfo& new_info = displays.back(); | 251 DisplayInfo& new_info = displays.back(); |
| 248 new_info.set_sys_path(state->sys_path()); | 252 new_info.set_sys_path(state->sys_path()); |
| 249 new_info.set_device_scale_factor(device_scale_factor); | 253 new_info.set_device_scale_factor(device_scale_factor); |
| 250 new_info.SetBounds(display_bounds); | 254 new_info.SetBounds(display_bounds); |
| 251 new_info.set_native(true); | 255 new_info.set_native(true); |
| 252 new_info.set_is_aspect_preserving_scaling( | 256 new_info.set_is_aspect_preserving_scaling( |
| 253 state->is_aspect_preserving_scaling()); | 257 state->is_aspect_preserving_scaling()); |
| 254 if (dpi) | 258 if (dpi) |
| 255 new_info.set_device_dpi(dpi); | 259 new_info.set_device_dpi(dpi); |
| 256 | 260 |
| 257 std::vector<DisplayMode> display_modes = | 261 DisplayInfo::DisplayModeList display_modes = |
| 258 (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) | 262 (state->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) |
| 259 ? GetInternalDisplayModeList(new_info, *state) | 263 ? GetInternalDisplayModeList(new_info, *state) |
| 260 : GetExternalDisplayModeList(*state); | 264 : GetExternalDisplayModeList(*state); |
| 261 new_info.SetDisplayModes(display_modes); | 265 new_info.SetDisplayModes(display_modes); |
| 262 | 266 |
| 263 new_info.set_available_color_profiles( | 267 new_info.set_available_color_profiles( |
| 264 Shell::GetInstance() | 268 Shell::GetInstance() |
| 265 ->display_configurator() | 269 ->display_configurator() |
| 266 ->GetAvailableColorCalibrationProfiles(id)); | 270 ->GetAvailableColorCalibrationProfiles(id)); |
| 267 new_info.set_maximum_cursor_size(state->maximum_cursor_size()); | 271 new_info.set_maximum_cursor_size(state->maximum_cursor_size()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 309 } |
| 306 return 1.0f; | 310 return 1.0f; |
| 307 } | 311 } |
| 308 | 312 |
| 309 void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() { | 313 void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() { |
| 310 OnDisplayModeChanged( | 314 OnDisplayModeChanged( |
| 311 Shell::GetInstance()->display_configurator()->cached_displays()); | 315 Shell::GetInstance()->display_configurator()->cached_displays()); |
| 312 } | 316 } |
| 313 | 317 |
| 314 } // namespace ash | 318 } // namespace ash |
| OLD | NEW |