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

Side by Side Diff: ash/display/display_util.cc

Issue 2270553002: Move ash::DisplayInfo to ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 4 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 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"
10 #include "ash/common/new_window_delegate.h" 9 #include "ash/common/new_window_delegate.h"
11 #include "ash/common/system/system_notifier.h" 10 #include "ash/common/system/system_notifier.h"
12 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
13 #include "ash/display/display_manager.h" 12 #include "ash/display/display_manager.h"
14 #include "ash/host/ash_window_tree_host.h" 13 #include "ash/host/ash_window_tree_host.h"
15 #include "ash/shell.h" 14 #include "ash/shell.h"
16 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
17 #include "grit/ash_resources.h" 16 #include "grit/ash_resources.h"
18 #include "ui/aura/env.h" 17 #include "ui/aura/env.h"
19 #include "ui/aura/window_tree_host.h" 18 #include "ui/aura/window_tree_host.h"
20 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/display/display.h" 21 #include "ui/display/display.h"
22 #include "ui/display/manager/display_info.h"
23 #include "ui/gfx/geometry/point.h" 23 #include "ui/gfx/geometry/point.h"
24 #include "ui/gfx/geometry/rect.h" 24 #include "ui/gfx/geometry/rect.h"
25 #include "ui/gfx/geometry/size_conversions.h" 25 #include "ui/gfx/geometry/size_conversions.h"
26 #include "ui/message_center/message_center.h" 26 #include "ui/message_center/message_center.h"
27 #include "ui/message_center/notification.h" 27 #include "ui/message_center/notification.h"
28 #include "ui/message_center/notification_delegate.h" 28 #include "ui/message_center/notification_delegate.h"
29 #include "ui/message_center/notification_list.h" 29 #include "ui/message_center/notification_list.h"
30 #include "ui/wm/core/coordinate_conversion.h" 30 #include "ui/wm/core/coordinate_conversion.h"
31 31
32 #if defined(OS_CHROMEOS) 32 #if defined(OS_CHROMEOS)
(...skipping 30 matching lines...) Expand all
63 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on 63 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on
64 // 2560 pixel width 2x density display. Please see crbug.com/233375 64 // 2560 pixel width 2x density display. Please see crbug.com/233375
65 // for the full list of resolutions. 65 // for the full list of resolutions.
66 const float kUIScalesFor2x[] = {0.5f, 0.625f, 0.8f, 1.0f, 66 const float kUIScalesFor2x[] = {0.5f, 0.625f, 0.8f, 1.0f,
67 1.125f, 1.25f, 1.5f, 2.0f}; 67 1.125f, 1.25f, 1.5f, 2.0f};
68 const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f}; 68 const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f};
69 const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f}; 69 const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f};
70 const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f}; 70 const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f};
71 71
72 std::vector<float> GetScalesForDisplay( 72 std::vector<float> GetScalesForDisplay(
73 const scoped_refptr<ManagedDisplayMode>& native_mode) { 73 const scoped_refptr<ui::ManagedDisplayMode>& native_mode) {
74 #define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a)) 74 #define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a))
75 75
76 std::vector<float> ret; 76 std::vector<float> ret;
77 if (native_mode->device_scale_factor() == 2.0f) { 77 if (native_mode->device_scale_factor() == 2.0f) {
78 ASSIGN_ARRAY(ret, kUIScalesFor2x); 78 ASSIGN_ARRAY(ret, kUIScalesFor2x);
79 return ret; 79 return ret;
80 } else if (native_mode->device_scale_factor() == 1.25f) { 80 } else if (native_mode->device_scale_factor() == 1.25f) {
81 ASSIGN_ARRAY(ret, kUIScalesFor1_25x); 81 ASSIGN_ARRAY(ret, kUIScalesFor1_25x);
82 return ret; 82 return ret;
83 } 83 }
(...skipping 10 matching lines...) Expand all
94 if (base::SysInfo::IsRunningOnChromeOS()) 94 if (base::SysInfo::IsRunningOnChromeOS())
95 NOTREACHED() << "Unknown resolution:" << native_mode->size().ToString(); 95 NOTREACHED() << "Unknown resolution:" << native_mode->size().ToString();
96 #endif 96 #endif
97 } 97 }
98 return ret; 98 return ret;
99 } 99 }
100 100
101 struct ScaleComparator { 101 struct ScaleComparator {
102 explicit ScaleComparator(float s) : scale(s) {} 102 explicit ScaleComparator(float s) : scale(s) {}
103 103
104 bool operator()(const scoped_refptr<ManagedDisplayMode>& mode) const { 104 bool operator()(const scoped_refptr<ui::ManagedDisplayMode>& mode) const {
105 const float kEpsilon = 0.0001f; 105 const float kEpsilon = 0.0001f;
106 return std::abs(scale - mode->ui_scale()) < kEpsilon; 106 return std::abs(scale - mode->ui_scale()) < kEpsilon;
107 } 107 }
108 float scale; 108 float scale;
109 }; 109 };
110 110
111 void ConvertPointFromScreenToNative(aura::WindowTreeHost* host, 111 void ConvertPointFromScreenToNative(aura::WindowTreeHost* host,
112 gfx::Point* point) { 112 gfx::Point* point) {
113 ::wm::ConvertPointFromScreen(host->window(), point); 113 ::wm::ConvertPointFromScreen(host->window(), point);
114 host->ConvertPointToNativeScreen(point); 114 host->ConvertPointToNativeScreen(point);
115 } 115 }
116 116
117 scoped_refptr<ManagedDisplayMode> GetDisplayModeForUIScale( 117 scoped_refptr<ui::ManagedDisplayMode> GetDisplayModeForUIScale(
118 const DisplayInfo& info, 118 const ui::DisplayInfo& info,
119 float ui_scale) { 119 float ui_scale) {
120 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); 120 const ui::DisplayInfo::ManagedDisplayModeList& modes = info.display_modes();
121 auto iter = 121 auto iter = std::find_if(
122 std::find_if(modes.begin(), modes.end(), 122 modes.begin(), modes.end(),
123 [ui_scale](const scoped_refptr<ManagedDisplayMode>& mode) { 123 [ui_scale](const scoped_refptr<ui::ManagedDisplayMode>& mode) {
124 return mode->ui_scale() == ui_scale; 124 return mode->ui_scale() == ui_scale;
125 }); 125 });
126 if (iter == modes.end()) 126 if (iter == modes.end())
127 return scoped_refptr<ManagedDisplayMode>(); 127 return scoped_refptr<ui::ManagedDisplayMode>();
128 return *iter; 128 return *iter;
129 } 129 }
130 130
131 scoped_refptr<ManagedDisplayMode> FindNextMode( 131 scoped_refptr<ui::ManagedDisplayMode> FindNextMode(
132 const DisplayInfo::ManagedDisplayModeList& modes, 132 const ui::DisplayInfo::ManagedDisplayModeList& modes,
133 size_t index, 133 size_t index,
134 bool up) { 134 bool up) {
135 DCHECK_LT(index, modes.size()); 135 DCHECK_LT(index, modes.size());
136 size_t new_index = index; 136 size_t new_index = index;
137 if (up && (index + 1 < modes.size())) 137 if (up && (index + 1 < modes.size()))
138 ++new_index; 138 ++new_index;
139 else if (!up && index != 0) 139 else if (!up && index != 0)
140 --new_index; 140 --new_index;
141 return modes[new_index]; 141 return modes[new_index];
142 } 142 }
143 143
144 } // namespace 144 } // namespace
145 145
146 DisplayInfo::ManagedDisplayModeList CreateInternalManagedDisplayModeList( 146 ui::DisplayInfo::ManagedDisplayModeList CreateInternalManagedDisplayModeList(
147 const scoped_refptr<ManagedDisplayMode>& native_mode) { 147 const scoped_refptr<ui::ManagedDisplayMode>& native_mode) {
148 DisplayInfo::ManagedDisplayModeList display_mode_list; 148 ui::DisplayInfo::ManagedDisplayModeList display_mode_list;
149 149
150 float native_ui_scale = (native_mode->device_scale_factor() == 1.25f) 150 float native_ui_scale = (native_mode->device_scale_factor() == 1.25f)
151 ? 1.0f 151 ? 1.0f
152 : native_mode->device_scale_factor(); 152 : native_mode->device_scale_factor();
153 for (float ui_scale : GetScalesForDisplay(native_mode)) { 153 for (float ui_scale : GetScalesForDisplay(native_mode)) {
154 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( 154 scoped_refptr<ui::ManagedDisplayMode> mode(new ui::ManagedDisplayMode(
155 native_mode->size(), native_mode->refresh_rate(), 155 native_mode->size(), native_mode->refresh_rate(),
156 native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale, 156 native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale,
157 native_mode->device_scale_factor())); 157 native_mode->device_scale_factor()));
158 display_mode_list.push_back(mode); 158 display_mode_list.push_back(mode);
159 } 159 }
160 return display_mode_list; 160 return display_mode_list;
161 } 161 }
162 162
163 DisplayInfo::ManagedDisplayModeList CreateUnifiedManagedDisplayModeList( 163 ui::DisplayInfo::ManagedDisplayModeList CreateUnifiedManagedDisplayModeList(
164 const scoped_refptr<ManagedDisplayMode>& native_mode, 164 const scoped_refptr<ui::ManagedDisplayMode>& native_mode,
165 const std::set<std::pair<float, float>>& dsf_scale_list) { 165 const std::set<std::pair<float, float>>& dsf_scale_list) {
166 DisplayInfo::ManagedDisplayModeList display_mode_list; 166 ui::DisplayInfo::ManagedDisplayModeList display_mode_list;
167 167
168 for (auto& pair : dsf_scale_list) { 168 for (auto& pair : dsf_scale_list) {
169 gfx::SizeF scaled_size(native_mode->size()); 169 gfx::SizeF scaled_size(native_mode->size());
170 scaled_size.Scale(pair.second); 170 scaled_size.Scale(pair.second);
171 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( 171 scoped_refptr<ui::ManagedDisplayMode> mode(new ui::ManagedDisplayMode(
172 gfx::ToFlooredSize(scaled_size), native_mode->refresh_rate(), 172 gfx::ToFlooredSize(scaled_size), native_mode->refresh_rate(),
173 native_mode->is_interlaced(), false /* native */, 173 native_mode->is_interlaced(), false /* native */,
174 native_mode->ui_scale(), pair.first /* device_scale_factor */)); 174 native_mode->ui_scale(), pair.first /* device_scale_factor */));
175 display_mode_list.push_back(mode); 175 display_mode_list.push_back(mode);
176 } 176 }
177 // Sort the mode by the size in DIP. 177 // Sort the mode by the size in DIP.
178 std::sort(display_mode_list.begin(), display_mode_list.end(), 178 std::sort(display_mode_list.begin(), display_mode_list.end(),
179 [](const scoped_refptr<ManagedDisplayMode>& a, 179 [](const scoped_refptr<ui::ManagedDisplayMode>& a,
180 const scoped_refptr<ManagedDisplayMode>& b) { 180 const scoped_refptr<ui::ManagedDisplayMode>& b) {
181 return a->GetSizeInDIP(false).GetArea() < 181 return a->GetSizeInDIP(false).GetArea() <
182 b->GetSizeInDIP(false).GetArea(); 182 b->GetSizeInDIP(false).GetArea();
183 }); 183 });
184 return display_mode_list; 184 return display_mode_list;
185 } 185 }
186 186
187 scoped_refptr<ManagedDisplayMode> GetDisplayModeForResolution( 187 scoped_refptr<ui::ManagedDisplayMode> GetDisplayModeForResolution(
188 const DisplayInfo& info, 188 const ui::DisplayInfo& info,
189 const gfx::Size& resolution) { 189 const gfx::Size& resolution) {
190 if (display::Display::IsInternalDisplayId(info.id())) 190 if (display::Display::IsInternalDisplayId(info.id()))
191 return scoped_refptr<ManagedDisplayMode>(); 191 return scoped_refptr<ui::ManagedDisplayMode>();
192 192
193 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); 193 const ui::DisplayInfo::ManagedDisplayModeList& modes = info.display_modes();
194 DCHECK_NE(0u, modes.size()); 194 DCHECK_NE(0u, modes.size());
195 scoped_refptr<ManagedDisplayMode> target_mode; 195 scoped_refptr<ui::ManagedDisplayMode> target_mode;
196 DisplayInfo::ManagedDisplayModeList::const_iterator iter = 196 ui::DisplayInfo::ManagedDisplayModeList::const_iterator iter = std::find_if(
197 std::find_if(modes.begin(), modes.end(), 197 modes.begin(), modes.end(),
198 [resolution](const scoped_refptr<ManagedDisplayMode>& mode) { 198 [resolution](const scoped_refptr<ui::ManagedDisplayMode>& mode) {
199 return mode->size() == resolution; 199 return mode->size() == resolution;
200 }); 200 });
201 if (iter == modes.end()) { 201 if (iter == modes.end()) {
202 LOG(WARNING) << "Unsupported resolution was requested:" 202 LOG(WARNING) << "Unsupported resolution was requested:"
203 << resolution.ToString(); 203 << resolution.ToString();
204 return scoped_refptr<ManagedDisplayMode>(); 204 return scoped_refptr<ui::ManagedDisplayMode>();
205 } 205 }
206 return *iter; 206 return *iter;
207 } 207 }
208 208
209 scoped_refptr<ManagedDisplayMode> GetDisplayModeForNextUIScale( 209 scoped_refptr<ui::ManagedDisplayMode> GetDisplayModeForNextUIScale(
210 const DisplayInfo& info, 210 const ui::DisplayInfo& info,
211 bool up) { 211 bool up) {
212 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 212 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
213 if (!display_manager->IsActiveDisplayId(info.id()) || 213 if (!display_manager->IsActiveDisplayId(info.id()) ||
214 !display::Display::IsInternalDisplayId(info.id())) { 214 !display::Display::IsInternalDisplayId(info.id())) {
215 return scoped_refptr<ManagedDisplayMode>(); 215 return scoped_refptr<ui::ManagedDisplayMode>();
216 } 216 }
217 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); 217 const ui::DisplayInfo::ManagedDisplayModeList& modes = info.display_modes();
218 ScaleComparator comparator(info.configured_ui_scale()); 218 ScaleComparator comparator(info.configured_ui_scale());
219 auto iter = std::find_if(modes.begin(), modes.end(), comparator); 219 auto iter = std::find_if(modes.begin(), modes.end(), comparator);
220 return FindNextMode(modes, iter - modes.begin(), up); 220 return FindNextMode(modes, iter - modes.begin(), up);
221 } 221 }
222 222
223 scoped_refptr<ManagedDisplayMode> GetDisplayModeForNextResolution( 223 scoped_refptr<ui::ManagedDisplayMode> GetDisplayModeForNextResolution(
224 const DisplayInfo& info, 224 const ui::DisplayInfo& info,
225 bool up) { 225 bool up) {
226 if (display::Display::IsInternalDisplayId(info.id())) 226 if (display::Display::IsInternalDisplayId(info.id()))
227 return scoped_refptr<ManagedDisplayMode>(); 227 return scoped_refptr<ui::ManagedDisplayMode>();
228 228
229 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); 229 const ui::DisplayInfo::ManagedDisplayModeList& modes = info.display_modes();
230 scoped_refptr<ManagedDisplayMode> tmp = new ManagedDisplayMode( 230 scoped_refptr<ui::ManagedDisplayMode> tmp = new ui::ManagedDisplayMode(
231 info.size_in_pixel(), 0.0, false, false, 1.0, info.device_scale_factor()); 231 info.size_in_pixel(), 0.0, false, false, 1.0, info.device_scale_factor());
232 gfx::Size resolution = tmp->GetSizeInDIP(false); 232 gfx::Size resolution = tmp->GetSizeInDIP(false);
233 233
234 auto iter = 234 auto iter = std::find_if(
235 std::find_if(modes.begin(), modes.end(), 235 modes.begin(), modes.end(),
236 [resolution](const scoped_refptr<ManagedDisplayMode>& mode) { 236 [resolution](const scoped_refptr<ui::ManagedDisplayMode>& mode) {
237 return mode->GetSizeInDIP(false) == resolution; 237 return mode->GetSizeInDIP(false) == resolution;
238 }); 238 });
239 return FindNextMode(modes, iter - modes.begin(), up); 239 return FindNextMode(modes, iter - modes.begin(), up);
240 } 240 }
241 241
242 bool SetDisplayUIScale(int64_t id, float ui_scale) { 242 bool SetDisplayUIScale(int64_t id, float ui_scale) {
243 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 243 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
244 if (!display_manager->IsActiveDisplayId(id) || 244 if (!display_manager->IsActiveDisplayId(id) ||
245 !display::Display::IsInternalDisplayId(id)) { 245 !display::Display::IsInternalDisplayId(id)) {
246 return false; 246 return false;
247 } 247 }
248 const DisplayInfo& info = display_manager->GetDisplayInfo(id); 248 const ui::DisplayInfo& info = display_manager->GetDisplayInfo(id);
249 249
250 scoped_refptr<ManagedDisplayMode> mode = 250 scoped_refptr<ui::ManagedDisplayMode> mode =
251 GetDisplayModeForUIScale(info, ui_scale); 251 GetDisplayModeForUIScale(info, ui_scale);
252 if (!mode) 252 if (!mode)
253 return false; 253 return false;
254 return display_manager->SetDisplayMode(id, mode); 254 return display_manager->SetDisplayMode(id, mode);
255 } 255 }
256 256
257 bool HasDisplayModeForUIScale(const DisplayInfo& info, float ui_scale) { 257 bool HasDisplayModeForUIScale(const ui::DisplayInfo& info, float ui_scale) {
258 ScaleComparator comparator(ui_scale); 258 ScaleComparator comparator(ui_scale);
259 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); 259 const ui::DisplayInfo::ManagedDisplayModeList& modes = info.display_modes();
260 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end(); 260 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end();
261 } 261 }
262 262
263 bool ComputeBoundary(const display::Display& a_display, 263 bool ComputeBoundary(const display::Display& a_display,
264 const display::Display& b_display, 264 const display::Display& b_display,
265 gfx::Rect* a_edge_in_screen, 265 gfx::Rect* a_edge_in_screen,
266 gfx::Rect* b_edge_in_screen) { 266 gfx::Rect* b_edge_in_screen) {
267 const gfx::Rect& a_bounds = a_display.bounds(); 267 const gfx::Rect& a_bounds = a_display.bounds();
268 const gfx::Rect& b_bounds = b_display.bounds(); 268 const gfx::Rect& b_bounds = b_display.bounds();
269 269
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 message_center::NotificationList::Notifications notifications = 474 message_center::NotificationList::Notifications notifications =
475 message_center::MessageCenter::Get()->GetVisibleNotifications(); 475 message_center::MessageCenter::Get()->GetVisibleNotifications();
476 for (auto* const notification : notifications) { 476 for (auto* const notification : notifications) {
477 if (notification->id() == kDisplayErrorNotificationId) 477 if (notification->id() == kDisplayErrorNotificationId)
478 return notification->message(); 478 return notification->message();
479 } 479 }
480 return base::string16(); 480 return base::string16();
481 } 481 }
482 482
483 } // namespace ash 483 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698