| 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 const DeviceScaleFactorDPIThreshold kThresholdTable[] = { | 40 const DeviceScaleFactorDPIThreshold kThresholdTable[] = { |
| 41 {180.0f, 2.0f}, | 41 {180.0f, 2.0f}, |
| 42 {150.0f, 1.25f}, | 42 {150.0f, 1.25f}, |
| 43 {0.0f, 1.0f}, | 43 {0.0f, 1.0f}, |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 // 1 inch in mm. | 46 // 1 inch in mm. |
| 47 const float kInchInMm = 25.4f; | 47 const float kInchInMm = 25.4f; |
| 48 | 48 |
| 49 // Display mode list is sorted by (in descending priority): | 49 // The minimum pixel width whose monitor can be called as '4K'. |
| 50 // * the area in pixels. | 50 const int kMinimumWidthFor4K = 3840; |
| 51 // * refresh rate. | 51 |
| 52 // The list of device scale factors (in addition to 1.0f) which is |
| 53 // available in extrenal large monitors. |
| 54 const float kAdditionalDeviceScaleFactorsFor4k[] = {1.25f, 2.0f}; |
| 55 |
| 56 // Display mode list is sorted by: |
| 57 // * the area in pixels in ascending order |
| 58 // * refresh rate in descending order |
| 52 struct DisplayModeSorter { | 59 struct DisplayModeSorter { |
| 53 bool operator()(const DisplayMode& a, const DisplayMode& b) { | 60 bool operator()(const DisplayMode& a, const DisplayMode& b) { |
| 54 if (a.size.GetArea() == b.size.GetArea()) | 61 gfx::Size size_a_dip = a.GetSizeInDIP(); |
| 62 gfx::Size size_b_dip = b.GetSizeInDIP(); |
| 63 if (size_a_dip.GetArea() == size_b_dip.GetArea()) |
| 55 return (a.refresh_rate > b.refresh_rate); | 64 return (a.refresh_rate > b.refresh_rate); |
| 56 return (a.size.GetArea() > b.size.GetArea()); | 65 return (size_a_dip.GetArea() < size_b_dip.GetArea()); |
| 57 } | 66 } |
| 58 }; | 67 }; |
| 59 | 68 |
| 60 } // namespace | 69 } // namespace |
| 61 | 70 |
| 62 // static | 71 // static |
| 63 std::vector<DisplayMode> DisplayChangeObserver::GetDisplayModeList( | 72 std::vector<DisplayMode> DisplayChangeObserver::GetInternalDisplayModeList( |
| 73 const DisplayInfo& display_info, |
| 74 const DisplayConfigurator::DisplayState& output) { |
| 75 std::vector<DisplayMode> display_mode_list; |
| 76 const ui::DisplayMode* ui_native_mode = output.display->native_mode(); |
| 77 DisplayMode native_mode(ui_native_mode->size(), |
| 78 ui_native_mode->refresh_rate(), |
| 79 ui_native_mode->is_interlaced(), |
| 80 true); |
| 81 native_mode.device_scale_factor = display_info.device_scale_factor(); |
| 82 std::vector<float> ui_scales = |
| 83 DisplayManager::GetScalesForDisplay(display_info); |
| 84 for (size_t i = 0; i < ui_scales.size(); ++i) { |
| 85 DisplayMode mode = native_mode; |
| 86 mode.ui_scale = ui_scales[i]; |
| 87 mode.native = (ui_scales[i] == 1.0f); |
| 88 display_mode_list.push_back(mode); |
| 89 } |
| 90 |
| 91 std::sort( |
| 92 display_mode_list.begin(), display_mode_list.end(), DisplayModeSorter()); |
| 93 return display_mode_list; |
| 94 } |
| 95 |
| 96 // static |
| 97 std::vector<DisplayMode> DisplayChangeObserver::GetExternalDisplayModeList( |
| 64 const DisplayConfigurator::DisplayState& output) { | 98 const DisplayConfigurator::DisplayState& output) { |
| 65 typedef std::map<std::pair<int, int>, DisplayMode> DisplayModeMap; | 99 typedef std::map<std::pair<int, int>, DisplayMode> DisplayModeMap; |
| 66 DisplayModeMap display_mode_map; | 100 DisplayModeMap display_mode_map; |
| 67 | 101 |
| 102 DisplayMode native_mode; |
| 68 for (std::vector<const ui::DisplayMode*>::const_iterator it = | 103 for (std::vector<const ui::DisplayMode*>::const_iterator it = |
| 69 output.display->modes().begin(); | 104 output.display->modes().begin(); |
| 70 it != output.display->modes().end(); | 105 it != output.display->modes().end(); |
| 71 ++it) { | 106 ++it) { |
| 72 const ui::DisplayMode& mode_info = **it; | 107 const ui::DisplayMode& mode_info = **it; |
| 73 const std::pair<int, int> size(mode_info.size().width(), | 108 const std::pair<int, int> size(mode_info.size().width(), |
| 74 mode_info.size().height()); | 109 mode_info.size().height()); |
| 75 const DisplayMode display_mode(mode_info.size(), | 110 const DisplayMode display_mode(mode_info.size(), |
| 76 mode_info.refresh_rate(), | 111 mode_info.refresh_rate(), |
| 77 mode_info.is_interlaced(), | 112 mode_info.is_interlaced(), |
| 78 output.display->native_mode() == *it); | 113 output.display->native_mode() == *it); |
| 114 if (display_mode.native) |
| 115 native_mode = display_mode; |
| 79 | 116 |
| 80 // Add the display mode if it isn't already present and override interlaced | 117 // Add the display mode if it isn't already present and override interlaced |
| 81 // display modes with non-interlaced ones. | 118 // display modes with non-interlaced ones. |
| 82 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size); | 119 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size); |
| 83 if (display_mode_it == display_mode_map.end()) | 120 if (display_mode_it == display_mode_map.end()) |
| 84 display_mode_map.insert(std::make_pair(size, display_mode)); | 121 display_mode_map.insert(std::make_pair(size, display_mode)); |
| 85 else if (display_mode_it->second.interlaced && !display_mode.interlaced) | 122 else if (display_mode_it->second.interlaced && !display_mode.interlaced) |
| 86 display_mode_it->second = display_mode; | 123 display_mode_it->second = display_mode; |
| 87 } | 124 } |
| 88 | 125 |
| 89 std::vector<DisplayMode> display_mode_list; | 126 std::vector<DisplayMode> display_mode_list; |
| 90 for (DisplayModeMap::const_iterator iter = display_mode_map.begin(); | 127 for (DisplayModeMap::const_iterator iter = display_mode_map.begin(); |
| 91 iter != display_mode_map.end(); | 128 iter != display_mode_map.end(); |
| 92 ++iter) { | 129 ++iter) { |
| 93 display_mode_list.push_back(iter->second); | 130 display_mode_list.push_back(iter->second); |
| 94 } | 131 } |
| 132 |
| 133 if (native_mode.size.width() >= kMinimumWidthFor4K) { |
| 134 for (size_t i = 0; i < arraysize(kAdditionalDeviceScaleFactorsFor4k); |
| 135 ++i) { |
| 136 DisplayMode mode = native_mode; |
| 137 mode.device_scale_factor = kAdditionalDeviceScaleFactorsFor4k[i]; |
| 138 mode.native = false; |
| 139 display_mode_list.push_back(mode); |
| 140 } |
| 141 } |
| 142 |
| 95 std::sort( | 143 std::sort( |
| 96 display_mode_list.begin(), display_mode_list.end(), DisplayModeSorter()); | 144 display_mode_list.begin(), display_mode_list.end(), DisplayModeSorter()); |
| 97 return display_mode_list; | 145 return display_mode_list; |
| 98 } | 146 } |
| 99 | 147 |
| 100 DisplayChangeObserver::DisplayChangeObserver() { | 148 DisplayChangeObserver::DisplayChangeObserver() { |
| 101 Shell::GetInstance()->AddShellObserver(this); | 149 Shell::GetInstance()->AddShellObserver(this); |
| 102 } | 150 } |
| 103 | 151 |
| 104 DisplayChangeObserver::~DisplayChangeObserver() { | 152 DisplayChangeObserver::~DisplayChangeObserver() { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 continue; | 191 continue; |
| 144 | 192 |
| 145 float device_scale_factor = 1.0f; | 193 float device_scale_factor = 1.0f; |
| 146 if (!ui::IsDisplaySizeBlackListed(state.display->physical_size())) { | 194 if (!ui::IsDisplaySizeBlackListed(state.display->physical_size())) { |
| 147 device_scale_factor = | 195 device_scale_factor = |
| 148 FindDeviceScaleFactor((kInchInMm * mode_info->size().width() / | 196 FindDeviceScaleFactor((kInchInMm * mode_info->size().width() / |
| 149 state.display->physical_size().width())); | 197 state.display->physical_size().width())); |
| 150 } | 198 } |
| 151 gfx::Rect display_bounds(state.display->origin(), mode_info->size()); | 199 gfx::Rect display_bounds(state.display->origin(), mode_info->size()); |
| 152 | 200 |
| 153 std::vector<DisplayMode> display_modes = GetDisplayModeList(state); | |
| 154 | |
| 155 std::string name = | 201 std::string name = |
| 156 state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL ? | 202 state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL ? |
| 157 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : | 203 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : |
| 158 state.display->display_name(); | 204 state.display->display_name(); |
| 159 if (name.empty()) | 205 if (name.empty()) |
| 160 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); | 206 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
| 161 | 207 |
| 162 bool has_overscan = state.display->has_overscan(); | 208 bool has_overscan = state.display->has_overscan(); |
| 163 int64 id = state.display->display_id(); | 209 int64 id = state.display->display_id(); |
| 164 ids.insert(id); | 210 ids.insert(id); |
| 165 | 211 |
| 166 displays.push_back(DisplayInfo(id, name, has_overscan)); | 212 displays.push_back(DisplayInfo(id, name, has_overscan)); |
| 167 DisplayInfo& new_info = displays.back(); | 213 DisplayInfo& new_info = displays.back(); |
| 168 new_info.set_device_scale_factor(device_scale_factor); | 214 new_info.set_device_scale_factor(device_scale_factor); |
| 169 new_info.SetBounds(display_bounds); | 215 new_info.SetBounds(display_bounds); |
| 170 new_info.set_native(true); | 216 new_info.set_native(true); |
| 171 new_info.set_display_modes(display_modes); | |
| 172 new_info.set_touch_support(state.touch_device_id == 0 ? | 217 new_info.set_touch_support(state.touch_device_id == 0 ? |
| 173 gfx::Display::TOUCH_SUPPORT_UNAVAILABLE : | 218 gfx::Display::TOUCH_SUPPORT_UNAVAILABLE : |
| 174 gfx::Display::TOUCH_SUPPORT_AVAILABLE); | 219 gfx::Display::TOUCH_SUPPORT_AVAILABLE); |
| 175 new_info.set_touch_device_id(state.touch_device_id); | 220 new_info.set_touch_device_id(state.touch_device_id); |
| 176 new_info.set_is_aspect_preserving_scaling( | 221 new_info.set_is_aspect_preserving_scaling( |
| 177 state.display->is_aspect_preserving_scaling()); | 222 state.display->is_aspect_preserving_scaling()); |
| 223 |
| 224 std::vector<DisplayMode> display_modes = |
| 225 (state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) ? |
| 226 GetInternalDisplayModeList(new_info, state) : |
| 227 GetExternalDisplayModeList(state); |
| 228 new_info.set_display_modes(display_modes); |
| 229 |
| 178 new_info.set_available_color_profiles( | 230 new_info.set_available_color_profiles( |
| 179 Shell::GetInstance() | 231 Shell::GetInstance() |
| 180 ->display_configurator() | 232 ->display_configurator() |
| 181 ->GetAvailableColorCalibrationProfiles(id)); | 233 ->GetAvailableColorCalibrationProfiles(id)); |
| 182 } | 234 } |
| 183 | 235 |
| 184 // DisplayManager can be null during the boot. | 236 // DisplayManager can be null during the boot. |
| 185 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); | 237 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); |
| 186 } | 238 } |
| 187 | 239 |
| 188 void DisplayChangeObserver::OnAppTerminating() { | 240 void DisplayChangeObserver::OnAppTerminating() { |
| 189 #if defined(USE_ASH) | 241 #if defined(USE_ASH) |
| 190 // Stop handling display configuration events once the shutdown | 242 // Stop handling display configuration events once the shutdown |
| 191 // process starts. crbug.com/177014. | 243 // process starts. crbug.com/177014. |
| 192 Shell::GetInstance()->display_configurator()->PrepareForExit(); | 244 Shell::GetInstance()->display_configurator()->PrepareForExit(); |
| 193 #endif | 245 #endif |
| 194 } | 246 } |
| 195 | 247 |
| 196 // static | 248 // static |
| 197 float DisplayChangeObserver::FindDeviceScaleFactor(float dpi) { | 249 float DisplayChangeObserver::FindDeviceScaleFactor(float dpi) { |
| 198 for (size_t i = 0; i < arraysize(kThresholdTable); ++i) { | 250 for (size_t i = 0; i < arraysize(kThresholdTable); ++i) { |
| 199 if (dpi > kThresholdTable[i].dpi) | 251 if (dpi > kThresholdTable[i].dpi) |
| 200 return kThresholdTable[i].device_scale_factor; | 252 return kThresholdTable[i].device_scale_factor; |
| 201 } | 253 } |
| 202 return 1.0f; | 254 return 1.0f; |
| 203 } | 255 } |
| 204 | 256 |
| 205 } // namespace ash | 257 } // namespace ash |
| OLD | NEW |