Chromium Code Reviews| 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> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 | 58 |
| 59 // The list of device scale factors (in addition to 1.0f) which is | 59 // The list of device scale factors (in addition to 1.0f) which is |
| 60 // available in extrenal large monitors. | 60 // available in extrenal large monitors. |
| 61 const float kAdditionalDeviceScaleFactorsFor4k[] = {1.25f, 2.0f}; | 61 const float kAdditionalDeviceScaleFactorsFor4k[] = {1.25f, 2.0f}; |
| 62 | 62 |
| 63 } // namespace | 63 } // namespace |
| 64 | 64 |
| 65 // static | 65 // static |
| 66 std::vector<DisplayMode> DisplayChangeObserver::GetInternalDisplayModeList( | 66 std::vector<DisplayMode> DisplayChangeObserver::GetInternalDisplayModeList( |
| 67 const DisplayInfo& display_info, | 67 const DisplayInfo& display_info, |
| 68 const DisplayConfigurator::DisplayState& output) { | 68 const ui::DisplaySnapshot& output) { |
| 69 const ui::DisplayMode* ui_native_mode = output.display->native_mode(); | 69 const ui::DisplayMode* ui_native_mode = output.native_mode(); |
| 70 DisplayMode native_mode(ui_native_mode->size(), | 70 DisplayMode native_mode(ui_native_mode->size(), |
| 71 ui_native_mode->refresh_rate(), | 71 ui_native_mode->refresh_rate(), |
| 72 ui_native_mode->is_interlaced(), | 72 ui_native_mode->is_interlaced(), |
| 73 true); | 73 true); |
| 74 native_mode.device_scale_factor = display_info.device_scale_factor(); | 74 native_mode.device_scale_factor = display_info.device_scale_factor(); |
| 75 | 75 |
| 76 return CreateInternalDisplayModeList(native_mode); | 76 return CreateInternalDisplayModeList(native_mode); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // static | 79 // static |
| 80 std::vector<DisplayMode> DisplayChangeObserver::GetExternalDisplayModeList( | 80 std::vector<DisplayMode> DisplayChangeObserver::GetExternalDisplayModeList( |
| 81 const DisplayConfigurator::DisplayState& output) { | 81 const ui::DisplaySnapshot& output) { |
| 82 typedef std::map<std::pair<int, int>, DisplayMode> DisplayModeMap; | 82 typedef std::map<std::pair<int, int>, DisplayMode> DisplayModeMap; |
| 83 DisplayModeMap display_mode_map; | 83 DisplayModeMap display_mode_map; |
| 84 | 84 |
| 85 DisplayMode native_mode; | 85 DisplayMode native_mode; |
| 86 for (std::vector<const ui::DisplayMode*>::const_iterator it = | 86 for (std::vector<const ui::DisplayMode*>::const_iterator it = |
| 87 output.display->modes().begin(); | 87 output.modes().begin(); |
| 88 it != output.display->modes().end(); | 88 it != output.modes().end(); ++it) { |
|
oshima
2015/03/18 23:02:45
can we use range based for loop?
dnicoara
2015/03/19 14:47:36
Done.
| |
| 89 ++it) { | |
| 90 const ui::DisplayMode& mode_info = **it; | 89 const ui::DisplayMode& mode_info = **it; |
| 91 const std::pair<int, int> size(mode_info.size().width(), | 90 const std::pair<int, int> size(mode_info.size().width(), |
| 92 mode_info.size().height()); | 91 mode_info.size().height()); |
| 93 const DisplayMode display_mode(mode_info.size(), | 92 const DisplayMode display_mode(mode_info.size(), mode_info.refresh_rate(), |
| 94 mode_info.refresh_rate(), | |
| 95 mode_info.is_interlaced(), | 93 mode_info.is_interlaced(), |
| 96 output.display->native_mode() == *it); | 94 output.native_mode() == *it); |
| 97 if (display_mode.native) | 95 if (display_mode.native) |
| 98 native_mode = display_mode; | 96 native_mode = display_mode; |
| 99 | 97 |
| 100 // Add the display mode if it isn't already present and override interlaced | 98 // Add the display mode if it isn't already present and override interlaced |
| 101 // display modes with non-interlaced ones. | 99 // display modes with non-interlaced ones. |
| 102 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size); | 100 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size); |
| 103 if (display_mode_it == display_mode_map.end()) | 101 if (display_mode_it == display_mode_map.end()) |
| 104 display_mode_map.insert(std::make_pair(size, display_mode)); | 102 display_mode_map.insert(std::make_pair(size, display_mode)); |
| 105 else if (display_mode_it->second.interlaced && !display_mode.interlaced) | 103 else if (display_mode_it->second.interlaced && !display_mode.interlaced) |
| 106 display_mode_it->second = display_mode; | 104 display_mode_it->second = display_mode; |
| 107 } | 105 } |
| 108 | 106 |
| 109 std::vector<DisplayMode> display_mode_list; | 107 std::vector<DisplayMode> display_mode_list; |
| 110 for (DisplayModeMap::const_iterator iter = display_mode_map.begin(); | 108 for (DisplayModeMap::const_iterator iter = display_mode_map.begin(); |
| 111 iter != display_mode_map.end(); | 109 iter != display_mode_map.end(); |
| 112 ++iter) { | 110 ++iter) { |
| 113 display_mode_list.push_back(iter->second); | 111 display_mode_list.push_back(iter->second); |
| 114 } | 112 } |
| 115 | 113 |
| 116 if (output.display->native_mode()) { | 114 if (output.native_mode()) { |
| 117 const std::pair<int, int> size(native_mode.size.width(), | 115 const std::pair<int, int> size(native_mode.size.width(), |
| 118 native_mode.size.height()); | 116 native_mode.size.height()); |
| 119 DisplayModeMap::iterator it = display_mode_map.find(size); | 117 DisplayModeMap::iterator it = display_mode_map.find(size); |
| 120 DCHECK(it != display_mode_map.end()) | 118 DCHECK(it != display_mode_map.end()) |
| 121 << "Native mode must be part of the mode list."; | 119 << "Native mode must be part of the mode list."; |
| 122 | 120 |
| 123 // If the native mode was replaced re-add it. | 121 // If the native mode was replaced re-add it. |
| 124 if (!it->second.native) | 122 if (!it->second.native) |
| 125 display_mode_list.push_back(native_mode); | 123 display_mode_list.push_back(native_mode); |
| 126 } | 124 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 DisplayMode mode; | 161 DisplayMode mode; |
| 164 if (!Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( | 162 if (!Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( |
| 165 display_id, &mode)) | 163 display_id, &mode)) |
| 166 return false; | 164 return false; |
| 167 | 165 |
| 168 *size = mode.size; | 166 *size = mode.size; |
| 169 return true; | 167 return true; |
| 170 } | 168 } |
| 171 | 169 |
| 172 void DisplayChangeObserver::OnDisplayModeChanged( | 170 void DisplayChangeObserver::OnDisplayModeChanged( |
| 173 const std::vector<DisplayConfigurator::DisplayState>& display_states) { | 171 const ui::DisplayConfigurator::DisplayStateList& display_states) { |
| 174 std::vector<DisplayInfo> displays; | 172 std::vector<DisplayInfo> displays; |
| 175 std::set<int64> ids; | 173 std::set<int64> ids; |
| 176 for (size_t i = 0; i < display_states.size(); ++i) { | 174 for (size_t i = 0; i < display_states.size(); ++i) { |
| 177 const DisplayConfigurator::DisplayState& state = display_states[i]; | 175 const ui::DisplaySnapshot& state = *display_states[i]; |
|
oshima
2015/03/18 23:02:45
ditto
dnicoara
2015/03/19 14:47:36
Done.
| |
| 178 | 176 |
| 179 if (state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { | 177 if (state.type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { |
| 180 if (gfx::Display::InternalDisplayId() == | 178 if (gfx::Display::InternalDisplayId() == |
| 181 gfx::Display::kInvalidDisplayID) { | 179 gfx::Display::kInvalidDisplayID) { |
| 182 gfx::Display::SetInternalDisplayId(state.display->display_id()); | 180 gfx::Display::SetInternalDisplayId(state.display_id()); |
| 183 } else { | 181 } else { |
| 184 #if defined(USE_OZONE) | 182 #if defined(USE_OZONE) |
| 185 // TODO(dnicoara) Remove when Ozone can properly perform the initial | 183 // TODO(dnicoara) Remove when Ozone can properly perform the initial |
| 186 // display configuration. | 184 // display configuration. |
| 187 gfx::Display::SetInternalDisplayId(state.display->display_id()); | 185 gfx::Display::SetInternalDisplayId(state.display_id()); |
| 188 #endif | 186 #endif |
| 189 DCHECK_EQ(gfx::Display::InternalDisplayId(), | 187 DCHECK_EQ(gfx::Display::InternalDisplayId(), state.display_id()); |
| 190 state.display->display_id()); | |
| 191 } | 188 } |
| 192 } | 189 } |
| 193 | 190 |
| 194 const ui::DisplayMode* mode_info = state.display->current_mode(); | 191 const ui::DisplayMode* mode_info = state.current_mode(); |
| 195 if (!mode_info) | 192 if (!mode_info) |
| 196 continue; | 193 continue; |
| 197 | 194 |
| 198 float device_scale_factor = 1.0f; | 195 float device_scale_factor = 1.0f; |
| 199 if (state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { | 196 if (state.type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { |
| 200 if (!ui::IsDisplaySizeBlackListed(state.display->physical_size())) { | 197 if (!ui::IsDisplaySizeBlackListed(state.physical_size())) { |
| 201 device_scale_factor = | 198 device_scale_factor = |
| 202 FindDeviceScaleFactor((kInchInMm * mode_info->size().width() / | 199 FindDeviceScaleFactor((kInchInMm * mode_info->size().width() / |
| 203 state.display->physical_size().width())); | 200 state.physical_size().width())); |
| 204 } | 201 } |
| 205 } else { | 202 } else { |
| 206 DisplayMode mode; | 203 DisplayMode mode; |
| 207 if (Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( | 204 if (Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( |
| 208 state.display->display_id(), &mode)) { | 205 state.display_id(), &mode)) { |
| 209 device_scale_factor = mode.device_scale_factor; | 206 device_scale_factor = mode.device_scale_factor; |
| 210 } | 207 } |
| 211 } | 208 } |
| 212 gfx::Rect display_bounds(state.display->origin(), mode_info->size()); | 209 gfx::Rect display_bounds(state.origin(), mode_info->size()); |
| 213 | 210 |
| 214 std::string name = | 211 std::string name = |
| 215 state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL ? | 212 state.type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL |
| 216 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : | 213 ? l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) |
| 217 state.display->display_name(); | 214 : state.display_name(); |
| 218 if (name.empty()) | 215 if (name.empty()) |
| 219 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); | 216 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
| 220 | 217 |
| 221 bool has_overscan = state.display->has_overscan(); | 218 bool has_overscan = state.has_overscan(); |
| 222 int64 id = state.display->display_id(); | 219 int64 id = state.display_id(); |
| 223 ids.insert(id); | 220 ids.insert(id); |
| 224 | 221 |
| 225 displays.push_back(DisplayInfo(id, name, has_overscan)); | 222 displays.push_back(DisplayInfo(id, name, has_overscan)); |
| 226 DisplayInfo& new_info = displays.back(); | 223 DisplayInfo& new_info = displays.back(); |
| 227 new_info.set_device_scale_factor(device_scale_factor); | 224 new_info.set_device_scale_factor(device_scale_factor); |
| 228 new_info.SetBounds(display_bounds); | 225 new_info.SetBounds(display_bounds); |
| 229 new_info.set_native(true); | 226 new_info.set_native(true); |
| 230 new_info.set_is_aspect_preserving_scaling( | 227 new_info.set_is_aspect_preserving_scaling( |
| 231 state.display->is_aspect_preserving_scaling()); | 228 state.is_aspect_preserving_scaling()); |
| 232 | 229 |
| 233 std::vector<DisplayMode> display_modes = | 230 std::vector<DisplayMode> display_modes = |
| 234 (state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) ? | 231 (state.type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) |
| 235 GetInternalDisplayModeList(new_info, state) : | 232 ? GetInternalDisplayModeList(new_info, state) |
| 236 GetExternalDisplayModeList(state); | 233 : GetExternalDisplayModeList(state); |
| 237 new_info.SetDisplayModes(display_modes); | 234 new_info.SetDisplayModes(display_modes); |
| 238 | 235 |
| 239 new_info.set_available_color_profiles( | 236 new_info.set_available_color_profiles( |
| 240 Shell::GetInstance() | 237 Shell::GetInstance() |
| 241 ->display_configurator() | 238 ->display_configurator() |
| 242 ->GetAvailableColorCalibrationProfiles(id)); | 239 ->GetAvailableColorCalibrationProfiles(id)); |
| 243 } | 240 } |
| 244 | 241 |
| 245 AssociateTouchscreens( | 242 AssociateTouchscreens( |
| 246 &displays, ui::DeviceDataManager::GetInstance()->touchscreen_devices()); | 243 &displays, ui::DeviceDataManager::GetInstance()->touchscreen_devices()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 } | 278 } |
| 282 return 1.0f; | 279 return 1.0f; |
| 283 } | 280 } |
| 284 | 281 |
| 285 void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() { | 282 void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() { |
| 286 OnDisplayModeChanged( | 283 OnDisplayModeChanged( |
| 287 Shell::GetInstance()->display_configurator()->cached_displays()); | 284 Shell::GetInstance()->display_configurator()->cached_displays()); |
| 288 } | 285 } |
| 289 | 286 |
| 290 } // namespace ash | 287 } // namespace ash |
| OLD | NEW |