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