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

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: build Created 4 years, 3 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/managed_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::ManagedDisplayInfo& info,
119 float ui_scale) { 119 float ui_scale) {
120 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); 120 const ui::ManagedDisplayInfo::ManagedDisplayModeList& modes =
121 auto iter = 121 info.display_modes();
122 std::find_if(modes.begin(), modes.end(), 122 auto iter = std::find_if(
123 [ui_scale](const scoped_refptr<ManagedDisplayMode>& mode) { 123 modes.begin(), modes.end(),
124 return mode->ui_scale() == ui_scale; 124 [ui_scale](const scoped_refptr<ui::ManagedDisplayMode>& mode) {
125 }); 125 return mode->ui_scale() == ui_scale;
126 });
126 if (iter == modes.end()) 127 if (iter == modes.end())
127 return scoped_refptr<ManagedDisplayMode>(); 128 return scoped_refptr<ui::ManagedDisplayMode>();
128 return *iter; 129 return *iter;
129 } 130 }
130 131
131 scoped_refptr<ManagedDisplayMode> FindNextMode( 132 scoped_refptr<ui::ManagedDisplayMode> FindNextMode(
132 const DisplayInfo::ManagedDisplayModeList& modes, 133 const ui::ManagedDisplayInfo::ManagedDisplayModeList& modes,
133 size_t index, 134 size_t index,
134 bool up) { 135 bool up) {
135 DCHECK_LT(index, modes.size()); 136 DCHECK_LT(index, modes.size());
136 size_t new_index = index; 137 size_t new_index = index;
137 if (up && (index + 1 < modes.size())) 138 if (up && (index + 1 < modes.size()))
138 ++new_index; 139 ++new_index;
139 else if (!up && index != 0) 140 else if (!up && index != 0)
140 --new_index; 141 --new_index;
141 return modes[new_index]; 142 return modes[new_index];
142 } 143 }
143 144
144 } // namespace 145 } // namespace
145 146
146 DisplayInfo::ManagedDisplayModeList CreateInternalManagedDisplayModeList( 147 ui::ManagedDisplayInfo::ManagedDisplayModeList
147 const scoped_refptr<ManagedDisplayMode>& native_mode) { 148 CreateInternalManagedDisplayModeList(
148 DisplayInfo::ManagedDisplayModeList display_mode_list; 149 const scoped_refptr<ui::ManagedDisplayMode>& native_mode) {
150 ui::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list;
149 151
150 float native_ui_scale = (native_mode->device_scale_factor() == 1.25f) 152 float native_ui_scale = (native_mode->device_scale_factor() == 1.25f)
151 ? 1.0f 153 ? 1.0f
152 : native_mode->device_scale_factor(); 154 : native_mode->device_scale_factor();
153 for (float ui_scale : GetScalesForDisplay(native_mode)) { 155 for (float ui_scale : GetScalesForDisplay(native_mode)) {
154 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( 156 scoped_refptr<ui::ManagedDisplayMode> mode(new ui::ManagedDisplayMode(
155 native_mode->size(), native_mode->refresh_rate(), 157 native_mode->size(), native_mode->refresh_rate(),
156 native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale, 158 native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale,
157 native_mode->device_scale_factor())); 159 native_mode->device_scale_factor()));
158 display_mode_list.push_back(mode); 160 display_mode_list.push_back(mode);
159 } 161 }
160 return display_mode_list; 162 return display_mode_list;
161 } 163 }
162 164
163 DisplayInfo::ManagedDisplayModeList CreateUnifiedManagedDisplayModeList( 165 ui::ManagedDisplayInfo::ManagedDisplayModeList
164 const scoped_refptr<ManagedDisplayMode>& native_mode, 166 CreateUnifiedManagedDisplayModeList(
167 const scoped_refptr<ui::ManagedDisplayMode>& native_mode,
165 const std::set<std::pair<float, float>>& dsf_scale_list) { 168 const std::set<std::pair<float, float>>& dsf_scale_list) {
166 DisplayInfo::ManagedDisplayModeList display_mode_list; 169 ui::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list;
167 170
168 for (auto& pair : dsf_scale_list) { 171 for (auto& pair : dsf_scale_list) {
169 gfx::SizeF scaled_size(native_mode->size()); 172 gfx::SizeF scaled_size(native_mode->size());
170 scaled_size.Scale(pair.second); 173 scaled_size.Scale(pair.second);
171 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( 174 scoped_refptr<ui::ManagedDisplayMode> mode(new ui::ManagedDisplayMode(
172 gfx::ToFlooredSize(scaled_size), native_mode->refresh_rate(), 175 gfx::ToFlooredSize(scaled_size), native_mode->refresh_rate(),
173 native_mode->is_interlaced(), false /* native */, 176 native_mode->is_interlaced(), false /* native */,
174 native_mode->ui_scale(), pair.first /* device_scale_factor */)); 177 native_mode->ui_scale(), pair.first /* device_scale_factor */));
175 display_mode_list.push_back(mode); 178 display_mode_list.push_back(mode);
176 } 179 }
177 // Sort the mode by the size in DIP. 180 // Sort the mode by the size in DIP.
178 std::sort(display_mode_list.begin(), display_mode_list.end(), 181 std::sort(display_mode_list.begin(), display_mode_list.end(),
179 [](const scoped_refptr<ManagedDisplayMode>& a, 182 [](const scoped_refptr<ui::ManagedDisplayMode>& a,
180 const scoped_refptr<ManagedDisplayMode>& b) { 183 const scoped_refptr<ui::ManagedDisplayMode>& b) {
181 return a->GetSizeInDIP(false).GetArea() < 184 return a->GetSizeInDIP(false).GetArea() <
182 b->GetSizeInDIP(false).GetArea(); 185 b->GetSizeInDIP(false).GetArea();
183 }); 186 });
184 return display_mode_list; 187 return display_mode_list;
185 } 188 }
186 189
187 scoped_refptr<ManagedDisplayMode> GetDisplayModeForResolution( 190 scoped_refptr<ui::ManagedDisplayMode> GetDisplayModeForResolution(
188 const DisplayInfo& info, 191 const ui::ManagedDisplayInfo& info,
189 const gfx::Size& resolution) { 192 const gfx::Size& resolution) {
190 if (display::Display::IsInternalDisplayId(info.id())) 193 if (display::Display::IsInternalDisplayId(info.id()))
191 return scoped_refptr<ManagedDisplayMode>(); 194 return scoped_refptr<ui::ManagedDisplayMode>();
192 195
193 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); 196 const ui::ManagedDisplayInfo::ManagedDisplayModeList& modes =
197 info.display_modes();
194 DCHECK_NE(0u, modes.size()); 198 DCHECK_NE(0u, modes.size());
195 scoped_refptr<ManagedDisplayMode> target_mode; 199 scoped_refptr<ui::ManagedDisplayMode> target_mode;
196 DisplayInfo::ManagedDisplayModeList::const_iterator iter = 200 ui::ManagedDisplayInfo::ManagedDisplayModeList::const_iterator iter =
197 std::find_if(modes.begin(), modes.end(), 201 std::find_if(
198 [resolution](const scoped_refptr<ManagedDisplayMode>& mode) { 202 modes.begin(), modes.end(),
199 return mode->size() == resolution; 203 [resolution](const scoped_refptr<ui::ManagedDisplayMode>& mode) {
200 }); 204 return mode->size() == resolution;
205 });
201 if (iter == modes.end()) { 206 if (iter == modes.end()) {
202 LOG(WARNING) << "Unsupported resolution was requested:" 207 LOG(WARNING) << "Unsupported resolution was requested:"
203 << resolution.ToString(); 208 << resolution.ToString();
204 return scoped_refptr<ManagedDisplayMode>(); 209 return scoped_refptr<ui::ManagedDisplayMode>();
205 } 210 }
206 return *iter; 211 return *iter;
207 } 212 }
208 213
209 scoped_refptr<ManagedDisplayMode> GetDisplayModeForNextUIScale( 214 scoped_refptr<ui::ManagedDisplayMode> GetDisplayModeForNextUIScale(
210 const DisplayInfo& info, 215 const ui::ManagedDisplayInfo& info,
211 bool up) { 216 bool up) {
212 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 217 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
213 if (!display_manager->IsActiveDisplayId(info.id()) || 218 if (!display_manager->IsActiveDisplayId(info.id()) ||
214 !display::Display::IsInternalDisplayId(info.id())) { 219 !display::Display::IsInternalDisplayId(info.id())) {
215 return scoped_refptr<ManagedDisplayMode>(); 220 return scoped_refptr<ui::ManagedDisplayMode>();
216 } 221 }
217 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); 222 const ui::ManagedDisplayInfo::ManagedDisplayModeList& modes =
223 info.display_modes();
218 ScaleComparator comparator(info.configured_ui_scale()); 224 ScaleComparator comparator(info.configured_ui_scale());
219 auto iter = std::find_if(modes.begin(), modes.end(), comparator); 225 auto iter = std::find_if(modes.begin(), modes.end(), comparator);
220 return FindNextMode(modes, iter - modes.begin(), up); 226 return FindNextMode(modes, iter - modes.begin(), up);
221 } 227 }
222 228
223 scoped_refptr<ManagedDisplayMode> GetDisplayModeForNextResolution( 229 scoped_refptr<ui::ManagedDisplayMode> GetDisplayModeForNextResolution(
224 const DisplayInfo& info, 230 const ui::ManagedDisplayInfo& info,
225 bool up) { 231 bool up) {
226 if (display::Display::IsInternalDisplayId(info.id())) 232 if (display::Display::IsInternalDisplayId(info.id()))
227 return scoped_refptr<ManagedDisplayMode>(); 233 return scoped_refptr<ui::ManagedDisplayMode>();
228 234
229 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); 235 const ui::ManagedDisplayInfo::ManagedDisplayModeList& modes =
230 scoped_refptr<ManagedDisplayMode> tmp = new ManagedDisplayMode( 236 info.display_modes();
237 scoped_refptr<ui::ManagedDisplayMode> tmp = new ui::ManagedDisplayMode(
231 info.size_in_pixel(), 0.0, false, false, 1.0, info.device_scale_factor()); 238 info.size_in_pixel(), 0.0, false, false, 1.0, info.device_scale_factor());
232 gfx::Size resolution = tmp->GetSizeInDIP(false); 239 gfx::Size resolution = tmp->GetSizeInDIP(false);
233 240
234 auto iter = 241 auto iter = std::find_if(
235 std::find_if(modes.begin(), modes.end(), 242 modes.begin(), modes.end(),
236 [resolution](const scoped_refptr<ManagedDisplayMode>& mode) { 243 [resolution](const scoped_refptr<ui::ManagedDisplayMode>& mode) {
237 return mode->GetSizeInDIP(false) == resolution; 244 return mode->GetSizeInDIP(false) == resolution;
238 }); 245 });
239 return FindNextMode(modes, iter - modes.begin(), up); 246 return FindNextMode(modes, iter - modes.begin(), up);
240 } 247 }
241 248
242 bool SetDisplayUIScale(int64_t id, float ui_scale) { 249 bool SetDisplayUIScale(int64_t id, float ui_scale) {
243 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 250 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
244 if (!display_manager->IsActiveDisplayId(id) || 251 if (!display_manager->IsActiveDisplayId(id) ||
245 !display::Display::IsInternalDisplayId(id)) { 252 !display::Display::IsInternalDisplayId(id)) {
246 return false; 253 return false;
247 } 254 }
248 const DisplayInfo& info = display_manager->GetDisplayInfo(id); 255 const ui::ManagedDisplayInfo& info = display_manager->GetDisplayInfo(id);
249 256
250 scoped_refptr<ManagedDisplayMode> mode = 257 scoped_refptr<ui::ManagedDisplayMode> mode =
251 GetDisplayModeForUIScale(info, ui_scale); 258 GetDisplayModeForUIScale(info, ui_scale);
252 if (!mode) 259 if (!mode)
253 return false; 260 return false;
254 return display_manager->SetDisplayMode(id, mode); 261 return display_manager->SetDisplayMode(id, mode);
255 } 262 }
256 263
257 bool HasDisplayModeForUIScale(const DisplayInfo& info, float ui_scale) { 264 bool HasDisplayModeForUIScale(const ui::ManagedDisplayInfo& info,
265 float ui_scale) {
258 ScaleComparator comparator(ui_scale); 266 ScaleComparator comparator(ui_scale);
259 const DisplayInfo::ManagedDisplayModeList& modes = info.display_modes(); 267 const ui::ManagedDisplayInfo::ManagedDisplayModeList& modes =
268 info.display_modes();
260 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end(); 269 return std::find_if(modes.begin(), modes.end(), comparator) != modes.end();
261 } 270 }
262 271
263 bool ComputeBoundary(const display::Display& a_display, 272 bool ComputeBoundary(const display::Display& a_display,
264 const display::Display& b_display, 273 const display::Display& b_display,
265 gfx::Rect* a_edge_in_screen, 274 gfx::Rect* a_edge_in_screen,
266 gfx::Rect* b_edge_in_screen) { 275 gfx::Rect* b_edge_in_screen) {
267 const gfx::Rect& a_bounds = a_display.bounds(); 276 const gfx::Rect& a_bounds = a_display.bounds();
268 const gfx::Rect& b_bounds = b_display.bounds(); 277 const gfx::Rect& b_bounds = b_display.bounds();
269 278
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 message_center::NotificationList::Notifications notifications = 483 message_center::NotificationList::Notifications notifications =
475 message_center::MessageCenter::Get()->GetVisibleNotifications(); 484 message_center::MessageCenter::Get()->GetVisibleNotifications();
476 for (auto* const notification : notifications) { 485 for (auto* const notification : notifications) {
477 if (notification->id() == kDisplayErrorNotificationId) 486 if (notification->id() == kDisplayErrorNotificationId)
478 return notification->message(); 487 return notification->message();
479 } 488 }
480 return base::string16(); 489 return base::string16();
481 } 490 }
482 491
483 } // namespace ash 492 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698