OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <stdio.h> | 5 #include <stdio.h> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/display/display_info.h" | 9 #include "ash/display/display_info.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 200 } |
201 } | 201 } |
202 display_modes[native_mode].native = true; | 202 display_modes[native_mode].native = true; |
203 } | 203 } |
204 | 204 |
205 if (id == gfx::Display::kInvalidDisplayID) | 205 if (id == gfx::Display::kInvalidDisplayID) |
206 id = synthesized_display_id++; | 206 id = synthesized_display_id++; |
207 DisplayInfo display_info( | 207 DisplayInfo display_info( |
208 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); | 208 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); |
209 display_info.set_device_scale_factor(device_scale_factor); | 209 display_info.set_device_scale_factor(device_scale_factor); |
210 display_info.SetRotation(rotation, gfx::Display::ROTATION_SOURCE_ACTIVE); | 210 display_info.set_rotation(rotation); |
211 display_info.set_configured_ui_scale(ui_scale); | 211 display_info.set_configured_ui_scale(ui_scale); |
212 display_info.SetBounds(bounds_in_native); | 212 display_info.SetBounds(bounds_in_native); |
213 display_info.SetDisplayModes(display_modes); | 213 display_info.SetDisplayModes(display_modes); |
214 | 214 |
215 // To test the overscan, it creates the default 5% overscan. | 215 // To test the overscan, it creates the default 5% overscan. |
216 if (has_overscan) { | 216 if (has_overscan) { |
217 int width = bounds_in_native.width() / device_scale_factor / 40; | 217 int width = bounds_in_native.width() / device_scale_factor / 40; |
218 int height = bounds_in_native.height() / device_scale_factor / 40; | 218 int height = bounds_in_native.height() / device_scale_factor / 40; |
219 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); | 219 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); |
220 display_info.UpdateDisplaySize(); | 220 display_info.UpdateDisplaySize(); |
221 } | 221 } |
222 | 222 |
223 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() | 223 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() |
224 << ", spec=" << spec; | 224 << ", spec=" << spec; |
225 return display_info; | 225 return display_info; |
226 } | 226 } |
227 | 227 |
228 DisplayInfo::DisplayInfo() | 228 DisplayInfo::DisplayInfo() |
229 : id_(gfx::Display::kInvalidDisplayID), | 229 : id_(gfx::Display::kInvalidDisplayID), |
230 has_overscan_(false), | 230 has_overscan_(false), |
| 231 rotation_(gfx::Display::ROTATE_0), |
231 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), | 232 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), |
232 touch_device_id_(0), | 233 touch_device_id_(0), |
233 device_scale_factor_(1.0f), | 234 device_scale_factor_(1.0f), |
234 overscan_insets_in_dip_(0, 0, 0, 0), | 235 overscan_insets_in_dip_(0, 0, 0, 0), |
235 configured_ui_scale_(1.0f), | 236 configured_ui_scale_(1.0f), |
236 native_(false), | 237 native_(false), |
237 is_aspect_preserving_scaling_(false), | 238 is_aspect_preserving_scaling_(false), |
238 clear_overscan_insets_(false), | 239 clear_overscan_insets_(false), |
239 color_profile_(ui::COLOR_PROFILE_STANDARD) { | 240 color_profile_(ui::COLOR_PROFILE_STANDARD) { |
240 } | 241 } |
241 | 242 |
242 DisplayInfo::DisplayInfo(int64 id, | 243 DisplayInfo::DisplayInfo(int64 id, |
243 const std::string& name, | 244 const std::string& name, |
244 bool has_overscan) | 245 bool has_overscan) |
245 : id_(id), | 246 : id_(id), |
246 name_(name), | 247 name_(name), |
247 has_overscan_(has_overscan), | 248 has_overscan_(has_overscan), |
| 249 rotation_(gfx::Display::ROTATE_0), |
248 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), | 250 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), |
249 touch_device_id_(0), | 251 touch_device_id_(0), |
250 device_scale_factor_(1.0f), | 252 device_scale_factor_(1.0f), |
251 overscan_insets_in_dip_(0, 0, 0, 0), | 253 overscan_insets_in_dip_(0, 0, 0, 0), |
252 configured_ui_scale_(1.0f), | 254 configured_ui_scale_(1.0f), |
253 native_(false), | 255 native_(false), |
254 is_aspect_preserving_scaling_(false), | 256 is_aspect_preserving_scaling_(false), |
255 clear_overscan_insets_(false), | 257 clear_overscan_insets_(false), |
256 color_profile_(ui::COLOR_PROFILE_STANDARD) { | 258 color_profile_(ui::COLOR_PROFILE_STANDARD) { |
257 } | 259 } |
258 | 260 |
259 DisplayInfo::~DisplayInfo() { | 261 DisplayInfo::~DisplayInfo() { |
260 } | 262 } |
261 | 263 |
262 void DisplayInfo::SetRotation(gfx::Display::Rotation rotation, | |
263 gfx::Display::RotationSource source) { | |
264 rotations_[source] = rotation; | |
265 rotations_[gfx::Display::ROTATION_SOURCE_ACTIVE] = rotation; | |
266 } | |
267 | |
268 gfx::Display::Rotation DisplayInfo::GetActiveRotation() const { | |
269 return GetRotation(gfx::Display::ROTATION_SOURCE_ACTIVE); | |
270 } | |
271 | |
272 gfx::Display::Rotation DisplayInfo::GetRotation( | |
273 gfx::Display::RotationSource source) const { | |
274 if (rotations_.find(source) == rotations_.end()) | |
275 return gfx::Display::ROTATE_0; | |
276 return rotations_.at(source); | |
277 } | |
278 | |
279 void DisplayInfo::Copy(const DisplayInfo& native_info) { | 264 void DisplayInfo::Copy(const DisplayInfo& native_info) { |
280 DCHECK(id_ == native_info.id_); | 265 DCHECK(id_ == native_info.id_); |
281 name_ = native_info.name_; | 266 name_ = native_info.name_; |
282 has_overscan_ = native_info.has_overscan_; | 267 has_overscan_ = native_info.has_overscan_; |
283 | 268 |
284 touch_support_ = native_info.touch_support_; | 269 touch_support_ = native_info.touch_support_; |
285 touch_device_id_ = native_info.touch_device_id_; | 270 touch_device_id_ = native_info.touch_device_id_; |
286 device_scale_factor_ = native_info.device_scale_factor_; | 271 device_scale_factor_ = native_info.device_scale_factor_; |
287 DCHECK(!native_info.bounds_in_native_.IsEmpty()); | 272 DCHECK(!native_info.bounds_in_native_.IsEmpty()); |
288 bounds_in_native_ = native_info.bounds_in_native_; | 273 bounds_in_native_ = native_info.bounds_in_native_; |
289 size_in_pixel_ = native_info.size_in_pixel_; | 274 size_in_pixel_ = native_info.size_in_pixel_; |
290 is_aspect_preserving_scaling_ = native_info.is_aspect_preserving_scaling_; | 275 is_aspect_preserving_scaling_ = native_info.is_aspect_preserving_scaling_; |
291 display_modes_ = native_info.display_modes_; | 276 display_modes_ = native_info.display_modes_; |
292 available_color_profiles_ = native_info.available_color_profiles_; | 277 available_color_profiles_ = native_info.available_color_profiles_; |
293 | 278 |
294 // Rotation, ui_scale, color_profile and overscan are given by preference, | 279 // Rotation, ui_scale, color_profile and overscan are given by preference, |
295 // or unit tests. Don't copy if this native_info came from | 280 // or unit tests. Don't copy if this native_info came from |
296 // DisplayChangeObserver. | 281 // DisplayChangeObserver. |
297 if (!native_info.native()) { | 282 if (!native_info.native()) { |
298 // Update the overscan_insets_in_dip_ either if the inset should be | 283 // Update the overscan_insets_in_dip_ either if the inset should be |
299 // cleared, or has non empty insts. | 284 // cleared, or has non empty insts. |
300 if (native_info.clear_overscan_insets()) | 285 if (native_info.clear_overscan_insets()) |
301 overscan_insets_in_dip_.Set(0, 0, 0, 0); | 286 overscan_insets_in_dip_.Set(0, 0, 0, 0); |
302 else if (!native_info.overscan_insets_in_dip_.empty()) | 287 else if (!native_info.overscan_insets_in_dip_.empty()) |
303 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_; | 288 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_; |
304 | 289 |
305 rotations_ = native_info.rotations_; | 290 rotation_ = native_info.rotation_; |
306 configured_ui_scale_ = native_info.configured_ui_scale_; | 291 configured_ui_scale_ = native_info.configured_ui_scale_; |
307 color_profile_ = native_info.color_profile(); | 292 color_profile_ = native_info.color_profile(); |
308 } | 293 } |
309 } | 294 } |
310 | 295 |
311 void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_native) { | 296 void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_native) { |
312 bounds_in_native_ = new_bounds_in_native; | 297 bounds_in_native_ = new_bounds_in_native; |
313 size_in_pixel_ = new_bounds_in_native.size(); | 298 size_in_pixel_ = new_bounds_in_native.size(); |
314 UpdateDisplaySize(); | 299 UpdateDisplaySize(); |
315 } | 300 } |
(...skipping 17 matching lines...) Expand all Loading... |
333 void DisplayInfo::UpdateDisplaySize() { | 318 void DisplayInfo::UpdateDisplaySize() { |
334 size_in_pixel_ = bounds_in_native_.size(); | 319 size_in_pixel_ = bounds_in_native_.size(); |
335 if (!overscan_insets_in_dip_.empty()) { | 320 if (!overscan_insets_in_dip_.empty()) { |
336 gfx::Insets insets_in_pixel = | 321 gfx::Insets insets_in_pixel = |
337 overscan_insets_in_dip_.Scale(device_scale_factor_); | 322 overscan_insets_in_dip_.Scale(device_scale_factor_); |
338 size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height()); | 323 size_in_pixel_.Enlarge(-insets_in_pixel.width(), -insets_in_pixel.height()); |
339 } else { | 324 } else { |
340 overscan_insets_in_dip_.Set(0, 0, 0, 0); | 325 overscan_insets_in_dip_.Set(0, 0, 0, 0); |
341 } | 326 } |
342 | 327 |
343 if (GetActiveRotation() == gfx::Display::ROTATE_90 || | 328 if (rotation_ == gfx::Display::ROTATE_90 || |
344 GetActiveRotation() == gfx::Display::ROTATE_270) { | 329 rotation_ == gfx::Display::ROTATE_270) |
345 size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width()); | 330 size_in_pixel_.SetSize(size_in_pixel_.height(), size_in_pixel_.width()); |
346 } | |
347 gfx::SizeF size_f(size_in_pixel_); | 331 gfx::SizeF size_f(size_in_pixel_); |
348 size_f.Scale(GetEffectiveUIScale()); | 332 size_f.Scale(GetEffectiveUIScale()); |
349 size_in_pixel_ = gfx::ToFlooredSize(size_f); | 333 size_in_pixel_ = gfx::ToFlooredSize(size_f); |
350 } | 334 } |
351 | 335 |
352 void DisplayInfo::SetOverscanInsets(const gfx::Insets& insets_in_dip) { | 336 void DisplayInfo::SetOverscanInsets(const gfx::Insets& insets_in_dip) { |
353 overscan_insets_in_dip_ = insets_in_dip; | 337 overscan_insets_in_dip_ = insets_in_dip; |
354 } | 338 } |
355 | 339 |
356 gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const { | 340 gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const { |
(...skipping 10 matching lines...) Expand all Loading... |
367 gfx::Size DisplayInfo::GetNativeModeSize() const { | 351 gfx::Size DisplayInfo::GetNativeModeSize() const { |
368 for (size_t i = 0; i < display_modes_.size(); ++i) { | 352 for (size_t i = 0; i < display_modes_.size(); ++i) { |
369 if (display_modes_[i].native) | 353 if (display_modes_[i].native) |
370 return display_modes_[i].size; | 354 return display_modes_[i].size; |
371 } | 355 } |
372 | 356 |
373 return gfx::Size(); | 357 return gfx::Size(); |
374 } | 358 } |
375 | 359 |
376 std::string DisplayInfo::ToString() const { | 360 std::string DisplayInfo::ToString() const { |
377 int rotation_degree = static_cast<int>(GetActiveRotation()) * 90; | 361 int rotation_degree = static_cast<int>(rotation_) * 90; |
378 return base::StringPrintf( | 362 return base::StringPrintf( |
379 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " | 363 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " |
380 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s, " | 364 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s, " |
381 "touch-device-id=%d", | 365 "touch-device-id=%d", |
382 static_cast<long long int>(id_), | 366 static_cast<long long int>(id_), |
383 bounds_in_native_.ToString().c_str(), | 367 bounds_in_native_.ToString().c_str(), |
384 size_in_pixel_.ToString().c_str(), | 368 size_in_pixel_.ToString().c_str(), |
385 device_scale_factor_, | 369 device_scale_factor_, |
386 overscan_insets_in_dip_.ToString().c_str(), | 370 overscan_insets_in_dip_.ToString().c_str(), |
387 rotation_degree, | 371 rotation_degree, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 return std::find(available_color_profiles_.begin(), | 405 return std::find(available_color_profiles_.begin(), |
422 available_color_profiles_.end(), | 406 available_color_profiles_.end(), |
423 profile) != available_color_profiles_.end(); | 407 profile) != available_color_profiles_.end(); |
424 } | 408 } |
425 | 409 |
426 bool DisplayInfo::Use125DSFRorUIScaling() const { | 410 bool DisplayInfo::Use125DSFRorUIScaling() const { |
427 return use_125_dsf_for_ui_scaling && id_ == gfx::Display::InternalDisplayId(); | 411 return use_125_dsf_for_ui_scaling && id_ == gfx::Display::InternalDisplayId(); |
428 } | 412 } |
429 | 413 |
430 } // namespace ash | 414 } // namespace ash |
OLD | NEW |