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

Side by Side Diff: ui/display/manager/display_manager_utilities.cc

Issue 2522563002: Remove unnecessary display:: namespaces. (Closed)
Patch Set: Rebase. Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/display/manager/display_manager_utilities.h" 5 #include "ui/display/manager/display_manager_utilities.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
(...skipping 21 matching lines...) Expand all
32 constexpr float kDefaultUIScaleFor1280 = 1.0f; 32 constexpr float kDefaultUIScaleFor1280 = 1.0f;
33 constexpr float kDefaultUIScaleFor1366 = 1.0f; 33 constexpr float kDefaultUIScaleFor1366 = 1.0f;
34 34
35 // Encapsulates the list of UI scales and the default one. 35 // Encapsulates the list of UI scales and the default one.
36 struct DisplayUIScales { 36 struct DisplayUIScales {
37 std::vector<float> scales; 37 std::vector<float> scales;
38 float default_scale; 38 float default_scale;
39 }; 39 };
40 40
41 DisplayUIScales GetScalesForDisplay( 41 DisplayUIScales GetScalesForDisplay(
42 const scoped_refptr<display::ManagedDisplayMode>& native_mode) { 42 const scoped_refptr<ManagedDisplayMode>& native_mode) {
43 #define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a)) 43 #define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a))
44 44
45 DisplayUIScales ret; 45 DisplayUIScales ret;
46 if (native_mode->device_scale_factor() == 2.0f) { 46 if (native_mode->device_scale_factor() == 2.0f) {
47 ASSIGN_ARRAY(ret.scales, kUIScalesFor2x); 47 ASSIGN_ARRAY(ret.scales, kUIScalesFor2x);
48 ret.default_scale = kDefaultUIScaleFor2x; 48 ret.default_scale = kDefaultUIScaleFor2x;
49 return ret; 49 return ret;
50 } else if (native_mode->device_scale_factor() == 1.25f) { 50 } else if (native_mode->device_scale_factor() == 1.25f) {
51 ASSIGN_ARRAY(ret.scales, kUIScalesFor1_25x); 51 ASSIGN_ARRAY(ret.scales, kUIScalesFor1_25x);
52 ret.default_scale = kDefaultUIScaleFor1_25x; 52 ret.default_scale = kDefaultUIScaleFor1_25x;
(...skipping 15 matching lines...) Expand all
68 if (base::SysInfo::IsRunningOnChromeOS()) 68 if (base::SysInfo::IsRunningOnChromeOS())
69 NOTREACHED() << "Unknown resolution:" << native_mode->size().ToString(); 69 NOTREACHED() << "Unknown resolution:" << native_mode->size().ToString();
70 #endif 70 #endif
71 } 71 }
72 return ret; 72 return ret;
73 } 73 }
74 74
75 struct ScaleComparator { 75 struct ScaleComparator {
76 explicit ScaleComparator(float s) : scale(s) {} 76 explicit ScaleComparator(float s) : scale(s) {}
77 77
78 bool operator()( 78 bool operator()(const scoped_refptr<ManagedDisplayMode>& mode) const {
79 const scoped_refptr<display::ManagedDisplayMode>& mode) const {
80 const float kEpsilon = 0.0001f; 79 const float kEpsilon = 0.0001f;
81 return std::abs(scale - mode->ui_scale()) < kEpsilon; 80 return std::abs(scale - mode->ui_scale()) < kEpsilon;
82 } 81 }
83 float scale; 82 float scale;
84 }; 83 };
85 84
86 scoped_refptr<display::ManagedDisplayMode> FindNextMode( 85 scoped_refptr<ManagedDisplayMode> FindNextMode(
87 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes, 86 const ManagedDisplayInfo::ManagedDisplayModeList& modes,
88 size_t index, 87 size_t index,
89 bool up) { 88 bool up) {
90 DCHECK_LT(index, modes.size()); 89 DCHECK_LT(index, modes.size());
91 size_t new_index = index; 90 size_t new_index = index;
92 if (up && (index + 1 < modes.size())) 91 if (up && (index + 1 < modes.size()))
93 ++new_index; 92 ++new_index;
94 else if (!up && index != 0) 93 else if (!up && index != 0)
95 --new_index; 94 --new_index;
96 return modes[new_index]; 95 return modes[new_index];
97 } 96 }
98 97
99 } // namespace 98 } // namespace
100 99
101 display::ManagedDisplayInfo::ManagedDisplayModeList 100 ManagedDisplayInfo::ManagedDisplayModeList CreateInternalManagedDisplayModeList(
102 CreateInternalManagedDisplayModeList( 101 const scoped_refptr<ManagedDisplayMode>& native_mode) {
103 const scoped_refptr<display::ManagedDisplayMode>& native_mode) { 102 ManagedDisplayInfo::ManagedDisplayModeList display_mode_list;
104 display::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list;
105 103
106 float native_ui_scale = (native_mode->device_scale_factor() == 1.25f) 104 float native_ui_scale = (native_mode->device_scale_factor() == 1.25f)
107 ? 1.0f 105 ? 1.0f
108 : native_mode->device_scale_factor(); 106 : native_mode->device_scale_factor();
109 const DisplayUIScales display_ui_scales = GetScalesForDisplay(native_mode); 107 const DisplayUIScales display_ui_scales = GetScalesForDisplay(native_mode);
110 for (float ui_scale : display_ui_scales.scales) { 108 for (float ui_scale : display_ui_scales.scales) {
111 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( 109 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode(
112 native_mode->size(), native_mode->refresh_rate(), 110 native_mode->size(), native_mode->refresh_rate(),
113 native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale, 111 native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale,
114 native_mode->device_scale_factor())); 112 native_mode->device_scale_factor()));
115 mode->set_is_default(ui_scale == display_ui_scales.default_scale); 113 mode->set_is_default(ui_scale == display_ui_scales.default_scale);
116 display_mode_list.push_back(mode); 114 display_mode_list.push_back(mode);
117 } 115 }
118 return display_mode_list; 116 return display_mode_list;
119 } 117 }
120 118
121 display::ManagedDisplayInfo::ManagedDisplayModeList 119 ManagedDisplayInfo::ManagedDisplayModeList CreateUnifiedManagedDisplayModeList(
122 CreateUnifiedManagedDisplayModeList( 120 const scoped_refptr<ManagedDisplayMode>& native_mode,
123 const scoped_refptr<display::ManagedDisplayMode>& native_mode,
124 const std::set<std::pair<float, float>>& dsf_scale_list) { 121 const std::set<std::pair<float, float>>& dsf_scale_list) {
125 display::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list; 122 ManagedDisplayInfo::ManagedDisplayModeList display_mode_list;
126 123
127 for (auto& pair : dsf_scale_list) { 124 for (auto& pair : dsf_scale_list) {
128 gfx::SizeF scaled_size(native_mode->size()); 125 gfx::SizeF scaled_size(native_mode->size());
129 scaled_size.Scale(pair.second); 126 scaled_size.Scale(pair.second);
130 scoped_refptr<display::ManagedDisplayMode> mode( 127 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode(
131 new display::ManagedDisplayMode( 128 gfx::ToFlooredSize(scaled_size), native_mode->refresh_rate(),
132 gfx::ToFlooredSize(scaled_size), native_mode->refresh_rate(), 129 native_mode->is_interlaced(), false /* native */,
133 native_mode->is_interlaced(), false /* native */, 130 native_mode->ui_scale(), pair.first /* device_scale_factor */));
134 native_mode->ui_scale(), pair.first /* device_scale_factor */));
135 display_mode_list.push_back(mode); 131 display_mode_list.push_back(mode);
136 } 132 }
137 // Sort the mode by the size in DIP. 133 // Sort the mode by the size in DIP.
138 std::sort(display_mode_list.begin(), display_mode_list.end(), 134 std::sort(display_mode_list.begin(), display_mode_list.end(),
139 [](const scoped_refptr<display::ManagedDisplayMode>& a, 135 [](const scoped_refptr<ManagedDisplayMode>& a,
140 const scoped_refptr<display::ManagedDisplayMode>& b) { 136 const scoped_refptr<ManagedDisplayMode>& b) {
141 return a->GetSizeInDIP(false).GetArea() < 137 return a->GetSizeInDIP(false).GetArea() <
142 b->GetSizeInDIP(false).GetArea(); 138 b->GetSizeInDIP(false).GetArea();
143 }); 139 });
144 return display_mode_list; 140 return display_mode_list;
145 } 141 }
146 142
147 scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForResolution( 143 scoped_refptr<ManagedDisplayMode> GetDisplayModeForResolution(
148 const display::ManagedDisplayInfo& info, 144 const ManagedDisplayInfo& info,
149 const gfx::Size& resolution) { 145 const gfx::Size& resolution) {
150 if (display::Display::IsInternalDisplayId(info.id())) 146 if (Display::IsInternalDisplayId(info.id()))
151 return scoped_refptr<display::ManagedDisplayMode>(); 147 return scoped_refptr<ManagedDisplayMode>();
152 148
153 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = 149 const ManagedDisplayInfo::ManagedDisplayModeList& modes =
154 info.display_modes(); 150 info.display_modes();
155 DCHECK_NE(0u, modes.size()); 151 DCHECK_NE(0u, modes.size());
156 scoped_refptr<display::ManagedDisplayMode> target_mode; 152 scoped_refptr<ManagedDisplayMode> target_mode;
157 display::ManagedDisplayInfo::ManagedDisplayModeList::const_iterator iter = 153 ManagedDisplayInfo::ManagedDisplayModeList::const_iterator iter =
158 std::find_if( 154 std::find_if(modes.begin(), modes.end(),
159 modes.begin(), modes.end(), 155 [resolution](const scoped_refptr<ManagedDisplayMode>& mode) {
160 [resolution](const scoped_refptr<display::ManagedDisplayMode>& mode) { 156 return mode->size() == resolution;
161 return mode->size() == resolution; 157 });
162 });
163 if (iter == modes.end()) { 158 if (iter == modes.end()) {
164 LOG(WARNING) << "Unsupported resolution was requested:" 159 LOG(WARNING) << "Unsupported resolution was requested:"
165 << resolution.ToString(); 160 << resolution.ToString();
166 return scoped_refptr<display::ManagedDisplayMode>(); 161 return scoped_refptr<ManagedDisplayMode>();
167 } 162 }
168 return *iter; 163 return *iter;
169 } 164 }
170 165
171 scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForNextUIScale( 166 scoped_refptr<ManagedDisplayMode> GetDisplayModeForNextUIScale(
172 const display::ManagedDisplayInfo& info, 167 const ManagedDisplayInfo& info,
173 bool up) { 168 bool up) {
174 const ManagedDisplayInfo::ManagedDisplayModeList& modes = 169 const ManagedDisplayInfo::ManagedDisplayModeList& modes =
175 info.display_modes(); 170 info.display_modes();
176 ScaleComparator comparator(info.configured_ui_scale()); 171 ScaleComparator comparator(info.configured_ui_scale());
177 auto iter = std::find_if(modes.begin(), modes.end(), comparator); 172 auto iter = std::find_if(modes.begin(), modes.end(), comparator);
178 return FindNextMode(modes, iter - modes.begin(), up); 173 return FindNextMode(modes, iter - modes.begin(), up);
179 } 174 }
180 175
181 scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForNextResolution( 176 scoped_refptr<ManagedDisplayMode> GetDisplayModeForNextResolution(
182 const display::ManagedDisplayInfo& info, 177 const ManagedDisplayInfo& info,
183 bool up) { 178 bool up) {
184 if (display::Display::IsInternalDisplayId(info.id())) 179 if (Display::IsInternalDisplayId(info.id()))
185 return scoped_refptr<display::ManagedDisplayMode>(); 180 return scoped_refptr<ManagedDisplayMode>();
186 181
187 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = 182 const ManagedDisplayInfo::ManagedDisplayModeList& modes =
188 info.display_modes(); 183 info.display_modes();
189 scoped_refptr<display::ManagedDisplayMode> tmp = 184 scoped_refptr<ManagedDisplayMode> tmp = new ManagedDisplayMode(
190 new display::ManagedDisplayMode(info.size_in_pixel(), 0.0, false, false, 185 info.size_in_pixel(), 0.0, false, false, 1.0, info.device_scale_factor());
191 1.0, info.device_scale_factor());
192 gfx::Size resolution = tmp->GetSizeInDIP(false); 186 gfx::Size resolution = tmp->GetSizeInDIP(false);
193 187
194 auto iter = std::find_if( 188 auto iter =
195 modes.begin(), modes.end(), 189 std::find_if(modes.begin(), modes.end(),
196 [resolution](const scoped_refptr<display::ManagedDisplayMode>& mode) { 190 [resolution](const scoped_refptr<ManagedDisplayMode>& mode) {
197 return mode->GetSizeInDIP(false) == resolution; 191 return mode->GetSizeInDIP(false) == resolution;
198 }); 192 });
199 return FindNextMode(modes, iter - modes.begin(), up); 193 return FindNextMode(modes, iter - modes.begin(), up);
200 } 194 }
201 195
202 bool HasDisplayModeForUIScale(const ManagedDisplayInfo& info, float ui_scale) { 196 bool HasDisplayModeForUIScale(const ManagedDisplayInfo& info, float ui_scale) {
203 ScaleComparator comparator(ui_scale); 197 ScaleComparator comparator(ui_scale);
204 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = 198 const ManagedDisplayInfo::ManagedDisplayModeList& modes =
205 info.display_modes(); 199 info.display_modes();
206 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end(); 200 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end();
207 } 201 }
208 202
209 bool ComputeBoundary(const display::Display& a_display, 203 bool ComputeBoundary(const Display& a_display,
210 const display::Display& b_display, 204 const Display& b_display,
211 gfx::Rect* a_edge_in_screen, 205 gfx::Rect* a_edge_in_screen,
212 gfx::Rect* b_edge_in_screen) { 206 gfx::Rect* b_edge_in_screen) {
213 const gfx::Rect& a_bounds = a_display.bounds(); 207 const gfx::Rect& a_bounds = a_display.bounds();
214 const gfx::Rect& b_bounds = b_display.bounds(); 208 const gfx::Rect& b_bounds = b_display.bounds();
215 209
216 // Find touching side. 210 // Find touching side.
217 int rx = std::max(a_bounds.x(), b_bounds.x()); 211 int rx = std::max(a_bounds.x(), b_bounds.x());
218 int ry = std::max(a_bounds.y(), b_bounds.y()); 212 int ry = std::max(a_bounds.y(), b_bounds.y());
219 int rr = std::min(a_bounds.right(), b_bounds.right()); 213 int rr = std::min(a_bounds.right(), b_bounds.right());
220 int rb = std::min(a_bounds.bottom(), b_bounds.bottom()); 214 int rb = std::min(a_bounds.bottom(), b_bounds.bottom());
221 215
222 display::DisplayPlacement::Position position; 216 DisplayPlacement::Position position;
223 if ((rb - ry) == 0) { 217 if ((rb - ry) == 0) {
224 // top bottom 218 // top bottom
225 if (a_bounds.bottom() == b_bounds.y()) { 219 if (a_bounds.bottom() == b_bounds.y()) {
226 position = display::DisplayPlacement::BOTTOM; 220 position = DisplayPlacement::BOTTOM;
227 } else if (a_bounds.y() == b_bounds.bottom()) { 221 } else if (a_bounds.y() == b_bounds.bottom()) {
228 position = display::DisplayPlacement::TOP; 222 position = DisplayPlacement::TOP;
229 } else { 223 } else {
230 return false; 224 return false;
231 } 225 }
232 } else { 226 } else {
233 // left right 227 // left right
234 if (a_bounds.right() == b_bounds.x()) { 228 if (a_bounds.right() == b_bounds.x()) {
235 position = display::DisplayPlacement::RIGHT; 229 position = DisplayPlacement::RIGHT;
236 } else if (a_bounds.x() == b_bounds.right()) { 230 } else if (a_bounds.x() == b_bounds.right()) {
237 position = display::DisplayPlacement::LEFT; 231 position = DisplayPlacement::LEFT;
238 } else { 232 } else {
239 DCHECK_NE(rr, rx); 233 DCHECK_NE(rr, rx);
240 return false; 234 return false;
241 } 235 }
242 } 236 }
243 237
244 switch (position) { 238 switch (position) {
245 case display::DisplayPlacement::TOP: 239 case DisplayPlacement::TOP:
246 case display::DisplayPlacement::BOTTOM: { 240 case DisplayPlacement::BOTTOM: {
247 int left = std::max(a_bounds.x(), b_bounds.x()); 241 int left = std::max(a_bounds.x(), b_bounds.x());
248 int right = std::min(a_bounds.right(), b_bounds.right()); 242 int right = std::min(a_bounds.right(), b_bounds.right());
249 if (position == display::DisplayPlacement::TOP) { 243 if (position == DisplayPlacement::TOP) {
250 a_edge_in_screen->SetRect(left, a_bounds.y(), right - left, 1); 244 a_edge_in_screen->SetRect(left, a_bounds.y(), right - left, 1);
251 b_edge_in_screen->SetRect(left, b_bounds.bottom() - 1, right - left, 1); 245 b_edge_in_screen->SetRect(left, b_bounds.bottom() - 1, right - left, 1);
252 } else { 246 } else {
253 a_edge_in_screen->SetRect(left, a_bounds.bottom() - 1, right - left, 1); 247 a_edge_in_screen->SetRect(left, a_bounds.bottom() - 1, right - left, 1);
254 b_edge_in_screen->SetRect(left, b_bounds.y(), right - left, 1); 248 b_edge_in_screen->SetRect(left, b_bounds.y(), right - left, 1);
255 } 249 }
256 break; 250 break;
257 } 251 }
258 case display::DisplayPlacement::LEFT: 252 case DisplayPlacement::LEFT:
259 case display::DisplayPlacement::RIGHT: { 253 case DisplayPlacement::RIGHT: {
260 int top = std::max(a_bounds.y(), b_bounds.y()); 254 int top = std::max(a_bounds.y(), b_bounds.y());
261 int bottom = std::min(a_bounds.bottom(), b_bounds.bottom()); 255 int bottom = std::min(a_bounds.bottom(), b_bounds.bottom());
262 if (position == display::DisplayPlacement::LEFT) { 256 if (position == DisplayPlacement::LEFT) {
263 a_edge_in_screen->SetRect(a_bounds.x(), top, 1, bottom - top); 257 a_edge_in_screen->SetRect(a_bounds.x(), top, 1, bottom - top);
264 b_edge_in_screen->SetRect(b_bounds.right() - 1, top, 1, bottom - top); 258 b_edge_in_screen->SetRect(b_bounds.right() - 1, top, 1, bottom - top);
265 } else { 259 } else {
266 a_edge_in_screen->SetRect(a_bounds.right() - 1, top, 1, bottom - top); 260 a_edge_in_screen->SetRect(a_bounds.right() - 1, top, 1, bottom - top);
267 b_edge_in_screen->SetRect(b_bounds.x(), top, 1, bottom - top); 261 b_edge_in_screen->SetRect(b_bounds.x(), top, 1, bottom - top);
268 } 262 }
269 break; 263 break;
270 } 264 }
271 } 265 }
272 return true; 266 return true;
273 } 267 }
274 268
275 int FindDisplayIndexContainingPoint( 269 int FindDisplayIndexContainingPoint(const std::vector<Display>& displays,
276 const std::vector<display::Display>& displays, 270 const gfx::Point& point_in_screen) {
277 const gfx::Point& point_in_screen) {
278 auto iter = std::find_if(displays.begin(), displays.end(), 271 auto iter = std::find_if(displays.begin(), displays.end(),
279 [point_in_screen](const display::Display& display) { 272 [point_in_screen](const Display& display) {
280 return display.bounds().Contains(point_in_screen); 273 return display.bounds().Contains(point_in_screen);
281 }); 274 });
282 return iter == displays.end() ? -1 : (iter - displays.begin()); 275 return iter == displays.end() ? -1 : (iter - displays.begin());
283 } 276 }
284 277
285 display::DisplayIdList CreateDisplayIdList(const display::Displays& list) { 278 DisplayIdList CreateDisplayIdList(const Displays& list) {
286 return GenerateDisplayIdList( 279 return GenerateDisplayIdList(
287 list.begin(), list.end(), 280 list.begin(), list.end(),
288 [](const display::Display& display) { return display.id(); }); 281 [](const Display& display) { return display.id(); });
289 } 282 }
290 283
291 void SortDisplayIdList(display::DisplayIdList* ids) { 284 void SortDisplayIdList(DisplayIdList* ids) {
292 std::sort(ids->begin(), ids->end(), 285 std::sort(ids->begin(), ids->end(),
293 [](int64_t a, int64_t b) { return CompareDisplayIds(a, b); }); 286 [](int64_t a, int64_t b) { return CompareDisplayIds(a, b); });
294 } 287 }
295 288
296 std::string DisplayIdListToString(const display::DisplayIdList& list) { 289 std::string DisplayIdListToString(const DisplayIdList& list) {
297 std::stringstream s; 290 std::stringstream s;
298 const char* sep = ""; 291 const char* sep = "";
299 for (int64_t id : list) { 292 for (int64_t id : list) {
300 s << sep << id; 293 s << sep << id;
301 sep = ","; 294 sep = ",";
302 } 295 }
303 return s.str(); 296 return s.str();
304 } 297 }
305 298
306 bool CompareDisplayIds(int64_t id1, int64_t id2) { 299 bool CompareDisplayIds(int64_t id1, int64_t id2) {
307 DCHECK_NE(id1, id2); 300 DCHECK_NE(id1, id2);
308 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID 301 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID
309 // in edid_parser.cc. 302 // in edid_parser.cc.
310 int index_1 = id1 & 0xFF; 303 int index_1 = id1 & 0xFF;
311 int index_2 = id2 & 0xFF; 304 int index_2 = id2 & 0xFF;
312 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; 305 DCHECK_NE(index_1, index_2) << id1 << " and " << id2;
313 return display::Display::IsInternalDisplayId(id1) || 306 return Display::IsInternalDisplayId(id1) ||
314 (index_1 < index_2 && !display::Display::IsInternalDisplayId(id2)); 307 (index_1 < index_2 && !Display::IsInternalDisplayId(id2));
315 } 308 }
316 309
317 } // namespace display 310 } // namespace display
OLDNEW
« no previous file with comments | « ui/display/manager/display_manager_utilities.h ('k') | ui/display/manager/display_manager_utilities_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698