| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_util.h" | 5 #include "ash/display/display_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/common/display/display_info.h" | 9 #include "ash/common/display/display_info.h" |
| 10 #include "ash/common/system/system_notifier.h" | 10 #include "ash/common/system/system_notifier.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // List of value UI Scale values. Scales for 2x are equivalent to 640, | 61 // List of value UI Scale values. Scales for 2x are equivalent to 640, |
| 62 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on | 62 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on |
| 63 // 2560 pixel width 2x density display. Please see crbug.com/233375 | 63 // 2560 pixel width 2x density display. Please see crbug.com/233375 |
| 64 // for the full list of resolutions. | 64 // for the full list of resolutions. |
| 65 const float kUIScalesFor2x[] = {0.5f, 0.625f, 0.8f, 1.0f, | 65 const float kUIScalesFor2x[] = {0.5f, 0.625f, 0.8f, 1.0f, |
| 66 1.125f, 1.25f, 1.5f, 2.0f}; | 66 1.125f, 1.25f, 1.5f, 2.0f}; |
| 67 const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f}; | 67 const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f}; |
| 68 const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f}; | 68 const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f}; |
| 69 const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f}; | 69 const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f}; |
| 70 | 70 |
| 71 std::vector<float> GetScalesForDisplay(const DisplayMode& native_mode) { | 71 std::vector<float> GetScalesForDisplay( |
| 72 const scoped_refptr<DisplayMode>& native_mode) { |
| 72 #define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a)) | 73 #define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a)) |
| 73 | 74 |
| 74 std::vector<float> ret; | 75 std::vector<float> ret; |
| 75 if (native_mode.device_scale_factor == 2.0f) { | 76 if (native_mode->device_scale_factor() == 2.0f) { |
| 76 ASSIGN_ARRAY(ret, kUIScalesFor2x); | 77 ASSIGN_ARRAY(ret, kUIScalesFor2x); |
| 77 return ret; | 78 return ret; |
| 78 } else if (native_mode.device_scale_factor == 1.25f) { | 79 } else if (native_mode->device_scale_factor() == 1.25f) { |
| 79 ASSIGN_ARRAY(ret, kUIScalesFor1_25x); | 80 ASSIGN_ARRAY(ret, kUIScalesFor1_25x); |
| 80 return ret; | 81 return ret; |
| 81 } | 82 } |
| 82 switch (native_mode.size.width()) { | 83 switch (native_mode->size().width()) { |
| 83 case 1280: | 84 case 1280: |
| 84 ASSIGN_ARRAY(ret, kUIScalesFor1280); | 85 ASSIGN_ARRAY(ret, kUIScalesFor1280); |
| 85 break; | 86 break; |
| 86 case 1366: | 87 case 1366: |
| 87 ASSIGN_ARRAY(ret, kUIScalesFor1366); | 88 ASSIGN_ARRAY(ret, kUIScalesFor1366); |
| 88 break; | 89 break; |
| 89 default: | 90 default: |
| 90 ASSIGN_ARRAY(ret, kUIScalesFor1280); | 91 ASSIGN_ARRAY(ret, kUIScalesFor1280); |
| 91 #if defined(OS_CHROMEOS) | 92 #if defined(OS_CHROMEOS) |
| 92 if (base::SysInfo::IsRunningOnChromeOS()) | 93 if (base::SysInfo::IsRunningOnChromeOS()) |
| 93 NOTREACHED() << "Unknown resolution:" << native_mode.size.ToString(); | 94 NOTREACHED() << "Unknown resolution:" << native_mode->size().ToString(); |
| 94 #endif | 95 #endif |
| 95 } | 96 } |
| 96 return ret; | 97 return ret; |
| 97 } | 98 } |
| 98 | 99 |
| 99 struct ScaleComparator { | 100 struct ScaleComparator { |
| 100 explicit ScaleComparator(float s) : scale(s) {} | 101 explicit ScaleComparator(float s) : scale(s) {} |
| 101 | 102 |
| 102 bool operator()(const DisplayMode& mode) const { | 103 bool operator()(const scoped_refptr<DisplayMode>& mode) const { |
| 103 const float kEpsilon = 0.0001f; | 104 const float kEpsilon = 0.0001f; |
| 104 return std::abs(scale - mode.ui_scale) < kEpsilon; | 105 return std::abs(scale - mode->ui_scale()) < kEpsilon; |
| 105 } | 106 } |
| 106 float scale; | 107 float scale; |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 void ConvertPointFromScreenToNative(aura::WindowTreeHost* host, | 110 void ConvertPointFromScreenToNative(aura::WindowTreeHost* host, |
| 110 gfx::Point* point) { | 111 gfx::Point* point) { |
| 111 ::wm::ConvertPointFromScreen(host->window(), point); | 112 ::wm::ConvertPointFromScreen(host->window(), point); |
| 112 host->ConvertPointToNativeScreen(point); | 113 host->ConvertPointToNativeScreen(point); |
| 113 } | 114 } |
| 114 | 115 |
| 115 bool GetDisplayModeForUIScale(const DisplayInfo& info, | 116 scoped_refptr<DisplayMode> GetDisplayModeForUIScale(const DisplayInfo& info, |
| 116 float ui_scale, | 117 float ui_scale) { |
| 117 DisplayMode* out) { | 118 const DisplayInfo::DisplayModeList& modes = info.display_modes(); |
| 118 const std::vector<DisplayMode>& modes = info.display_modes(); | |
| 119 auto iter = std::find_if(modes.begin(), modes.end(), | 119 auto iter = std::find_if(modes.begin(), modes.end(), |
| 120 [ui_scale](const DisplayMode& mode) { | 120 [ui_scale](const scoped_refptr<DisplayMode>& mode) { |
| 121 return mode.ui_scale == ui_scale; | 121 return mode->ui_scale() == ui_scale; |
| 122 }); | 122 }); |
| 123 if (iter == modes.end()) | 123 if (iter == modes.end()) |
| 124 return false; | 124 return scoped_refptr<DisplayMode>(); |
| 125 *out = *iter; | 125 return *iter; |
| 126 return true; | |
| 127 } | 126 } |
| 128 | 127 |
| 129 DisplayMode FindNextMode(const std::vector<DisplayMode>& modes, | 128 scoped_refptr<DisplayMode> |
| 130 size_t index, | 129 FindNextMode(const DisplayInfo::DisplayModeList& modes, size_t index, bool up) { |
| 131 bool up) { | |
| 132 DCHECK_LT(index, modes.size()); | 130 DCHECK_LT(index, modes.size()); |
| 133 size_t new_index = index; | 131 size_t new_index = index; |
| 134 if (up && (index + 1 < modes.size())) | 132 if (up && (index + 1 < modes.size())) |
| 135 ++new_index; | 133 ++new_index; |
| 136 else if (!up && index != 0) | 134 else if (!up && index != 0) |
| 137 --new_index; | 135 --new_index; |
| 138 return modes[new_index]; | 136 return modes[new_index]; |
| 139 } | 137 } |
| 140 | 138 |
| 141 } // namespace | 139 } // namespace |
| 142 | 140 |
| 143 std::vector<DisplayMode> CreateInternalDisplayModeList( | 141 DisplayInfo::DisplayModeList CreateInternalDisplayModeList( |
| 144 const DisplayMode& native_mode) { | 142 const scoped_refptr<DisplayMode>& native_mode) { |
| 145 std::vector<DisplayMode> display_mode_list; | 143 DisplayInfo::DisplayModeList display_mode_list; |
| 146 | 144 |
| 147 float native_ui_scale = (native_mode.device_scale_factor == 1.25f) | 145 float native_ui_scale = (native_mode->device_scale_factor() == 1.25f) |
| 148 ? 1.0f | 146 ? 1.0f |
| 149 : native_mode.device_scale_factor; | 147 : native_mode->device_scale_factor(); |
| 150 for (float ui_scale : GetScalesForDisplay(native_mode)) { | 148 for (float ui_scale : GetScalesForDisplay(native_mode)) { |
| 151 DisplayMode mode = native_mode; | 149 scoped_refptr<DisplayMode> mode(new DisplayMode( |
| 152 mode.ui_scale = ui_scale; | 150 native_mode->size(), native_mode->refresh_rate(), |
| 153 mode.native = (ui_scale == native_ui_scale); | 151 native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale, |
| 152 native_mode->device_scale_factor())); |
| 154 display_mode_list.push_back(mode); | 153 display_mode_list.push_back(mode); |
| 155 } | 154 } |
| 156 return display_mode_list; | 155 return display_mode_list; |
| 157 } | 156 } |
| 158 | 157 |
| 159 std::vector<DisplayMode> CreateUnifiedDisplayModeList( | 158 DisplayInfo::DisplayModeList CreateUnifiedDisplayModeList( |
| 160 const DisplayMode& native_mode, | 159 const scoped_refptr<DisplayMode>& native_mode, |
| 161 const std::set<std::pair<float, float>>& dsf_scale_list) { | 160 const std::set<std::pair<float, float>>& dsf_scale_list) { |
| 162 std::vector<DisplayMode> display_mode_list; | 161 DisplayInfo::DisplayModeList display_mode_list; |
| 163 | 162 |
| 164 for (auto& pair : dsf_scale_list) { | 163 for (auto& pair : dsf_scale_list) { |
| 165 DisplayMode mode = native_mode; | 164 gfx::SizeF scaled_size(native_mode->size()); |
| 166 mode.device_scale_factor = pair.first; | |
| 167 gfx::SizeF scaled_size(native_mode.size); | |
| 168 scaled_size.Scale(pair.second); | 165 scaled_size.Scale(pair.second); |
| 169 mode.size = gfx::ToFlooredSize(scaled_size); | 166 scoped_refptr<DisplayMode> mode(new DisplayMode( |
| 170 mode.native = false; | 167 gfx::ToFlooredSize(scaled_size), native_mode->refresh_rate(), |
| 168 native_mode->is_interlaced(), false /* native */, |
| 169 native_mode->ui_scale(), pair.first /* device_scale_factor */)); |
| 171 display_mode_list.push_back(mode); | 170 display_mode_list.push_back(mode); |
| 172 } | 171 } |
| 173 // Sort the mode by the size in DIP. | 172 // Sort the mode by the size in DIP. |
| 174 std::sort(display_mode_list.begin(), display_mode_list.end(), | 173 std::sort(display_mode_list.begin(), display_mode_list.end(), |
| 175 [](const DisplayMode& a, const DisplayMode& b) { | 174 [](const scoped_refptr<DisplayMode>& a, |
| 176 return a.GetSizeInDIP(false).GetArea() < | 175 const scoped_refptr<DisplayMode>& b) { |
| 177 b.GetSizeInDIP(false).GetArea(); | 176 return a->GetSizeInDIP(false).GetArea() < |
| 177 b->GetSizeInDIP(false).GetArea(); |
| 178 }); | 178 }); |
| 179 return display_mode_list; | 179 return display_mode_list; |
| 180 } | 180 } |
| 181 | 181 |
| 182 bool GetDisplayModeForResolution(const DisplayInfo& info, | 182 scoped_refptr<DisplayMode> GetDisplayModeForResolution( |
| 183 const gfx::Size& resolution, | 183 const DisplayInfo& info, |
| 184 DisplayMode* out) { | 184 const gfx::Size& resolution) { |
| 185 if (display::Display::IsInternalDisplayId(info.id())) | 185 if (display::Display::IsInternalDisplayId(info.id())) |
| 186 return false; | 186 return scoped_refptr<DisplayMode>(); |
| 187 | 187 |
| 188 const std::vector<DisplayMode>& modes = info.display_modes(); | 188 const DisplayInfo::DisplayModeList& modes = info.display_modes(); |
| 189 DCHECK_NE(0u, modes.size()); | 189 DCHECK_NE(0u, modes.size()); |
| 190 DisplayMode target_mode; | 190 scoped_refptr<DisplayMode> target_mode; |
| 191 target_mode.size = resolution; | 191 DisplayInfo::DisplayModeList::const_iterator iter = |
| 192 std::vector<DisplayMode>::const_iterator iter = std::find_if( | 192 std::find_if(modes.begin(), modes.end(), |
| 193 modes.begin(), modes.end(), [resolution](const DisplayMode& mode) { | 193 [resolution](const scoped_refptr<DisplayMode>& mode) { |
| 194 return mode.size == resolution; | 194 return mode->size() == resolution; |
| 195 }); | 195 }); |
| 196 if (iter == modes.end()) { | 196 if (iter == modes.end()) { |
| 197 LOG(WARNING) << "Unsupported resolution was requested:" | 197 LOG(WARNING) << "Unsupported resolution was requested:" |
| 198 << resolution.ToString(); | 198 << resolution.ToString(); |
| 199 return false; | 199 return scoped_refptr<DisplayMode>(); |
| 200 } | 200 } |
| 201 *out = *iter; | 201 return *iter; |
| 202 return true; | |
| 203 } | 202 } |
| 204 | 203 |
| 205 bool GetDisplayModeForNextUIScale(const DisplayInfo& info, | 204 scoped_refptr<DisplayMode> GetDisplayModeForNextUIScale(const DisplayInfo& info, |
| 206 bool up, | 205 bool up) { |
| 207 DisplayMode* out) { | |
| 208 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 206 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 209 if (!display_manager->IsActiveDisplayId(info.id()) || | 207 if (!display_manager->IsActiveDisplayId(info.id()) || |
| 210 !display::Display::IsInternalDisplayId(info.id())) { | 208 !display::Display::IsInternalDisplayId(info.id())) { |
| 211 return false; | 209 return scoped_refptr<DisplayMode>(); |
| 212 } | 210 } |
| 213 const std::vector<DisplayMode>& modes = info.display_modes(); | 211 const DisplayInfo::DisplayModeList& modes = info.display_modes(); |
| 214 ScaleComparator comparator(info.configured_ui_scale()); | 212 ScaleComparator comparator(info.configured_ui_scale()); |
| 215 auto iter = std::find_if(modes.begin(), modes.end(), comparator); | 213 auto iter = std::find_if(modes.begin(), modes.end(), comparator); |
| 216 *out = FindNextMode(modes, iter - modes.begin(), up); | 214 return FindNextMode(modes, iter - modes.begin(), up); |
| 217 return true; | |
| 218 } | 215 } |
| 219 | 216 |
| 220 bool GetDisplayModeForNextResolution(const DisplayInfo& info, | 217 scoped_refptr<DisplayMode> GetDisplayModeForNextResolution( |
| 221 bool up, | 218 const DisplayInfo& info, |
| 222 DisplayMode* out) { | 219 bool up) { |
| 223 if (display::Display::IsInternalDisplayId(info.id())) | 220 if (display::Display::IsInternalDisplayId(info.id())) |
| 224 return false; | 221 return scoped_refptr<DisplayMode>(); |
| 225 const std::vector<DisplayMode>& modes = info.display_modes(); | 222 |
| 226 DisplayMode tmp(info.size_in_pixel(), 0.0f, false, false); | 223 const DisplayInfo::DisplayModeList& modes = info.display_modes(); |
| 227 tmp.device_scale_factor = info.device_scale_factor(); | 224 scoped_refptr<DisplayMode> tmp = new DisplayMode( |
| 228 gfx::Size resolution = tmp.GetSizeInDIP(false); | 225 info.size_in_pixel(), 0.0, false, false, 1.0, info.device_scale_factor()); |
| 229 auto iter = std::find_if(modes.begin(), modes.end(), | 226 gfx::Size resolution = tmp->GetSizeInDIP(false); |
| 230 [resolution](const DisplayMode& mode) { | 227 |
| 231 return mode.GetSizeInDIP(false) == resolution; | 228 auto iter = |
| 232 }); | 229 std::find_if(modes.begin(), modes.end(), |
| 233 *out = FindNextMode(modes, iter - modes.begin(), up); | 230 [resolution](const scoped_refptr<DisplayMode>& mode) { |
| 234 return true; | 231 return mode->GetSizeInDIP(false) == resolution; |
| 232 }); |
| 233 return FindNextMode(modes, iter - modes.begin(), up); |
| 235 } | 234 } |
| 236 | 235 |
| 237 bool SetDisplayUIScale(int64_t id, float ui_scale) { | 236 bool SetDisplayUIScale(int64_t id, float ui_scale) { |
| 238 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 237 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 239 if (!display_manager->IsActiveDisplayId(id) || | 238 if (!display_manager->IsActiveDisplayId(id) || |
| 240 !display::Display::IsInternalDisplayId(id)) { | 239 !display::Display::IsInternalDisplayId(id)) { |
| 241 return false; | 240 return false; |
| 242 } | 241 } |
| 243 const DisplayInfo& info = display_manager->GetDisplayInfo(id); | 242 const DisplayInfo& info = display_manager->GetDisplayInfo(id); |
| 244 DisplayMode mode; | 243 |
| 245 if (!GetDisplayModeForUIScale(info, ui_scale, &mode)) | 244 scoped_refptr<DisplayMode> mode = GetDisplayModeForUIScale(info, ui_scale); |
| 245 if (!mode) |
| 246 return false; | 246 return false; |
| 247 return display_manager->SetDisplayMode(id, mode); | 247 return display_manager->SetDisplayMode(id, mode); |
| 248 } | 248 } |
| 249 | 249 |
| 250 bool HasDisplayModeForUIScale(const DisplayInfo& info, float ui_scale) { | 250 bool HasDisplayModeForUIScale(const DisplayInfo& info, float ui_scale) { |
| 251 ScaleComparator comparator(ui_scale); | 251 ScaleComparator comparator(ui_scale); |
| 252 const std::vector<DisplayMode>& modes = info.display_modes(); | 252 const DisplayInfo::DisplayModeList& modes = info.display_modes(); |
| 253 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end(); | 253 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 bool ComputeBoundary(const display::Display& a_display, | 256 bool ComputeBoundary(const display::Display& a_display, |
| 257 const display::Display& b_display, | 257 const display::Display& b_display, |
| 258 gfx::Rect* a_edge_in_screen, | 258 gfx::Rect* a_edge_in_screen, |
| 259 gfx::Rect* b_edge_in_screen) { | 259 gfx::Rect* b_edge_in_screen) { |
| 260 const gfx::Rect& a_bounds = a_display.bounds(); | 260 const gfx::Rect& a_bounds = a_display.bounds(); |
| 261 const gfx::Rect& b_bounds = b_display.bounds(); | 261 const gfx::Rect& b_bounds = b_display.bounds(); |
| 262 | 262 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 message_center::NotificationList::Notifications notifications = | 467 message_center::NotificationList::Notifications notifications = |
| 468 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 468 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
| 469 for (auto* const notification : notifications) { | 469 for (auto* const notification : notifications) { |
| 470 if (notification->id() == kDisplayErrorNotificationId) | 470 if (notification->id() == kDisplayErrorNotificationId) |
| 471 return notification->message(); | 471 return notification->message(); |
| 472 } | 472 } |
| 473 return base::string16(); | 473 return base::string16(); |
| 474 } | 474 } |
| 475 | 475 |
| 476 } // namespace ash | 476 } // namespace ash |
| OLD | NEW |