Chromium Code Reviews| 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" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
| 16 #include "ui/gfx/geometry/size_conversions.h" | 16 #include "ui/gfx/geometry/size_conversions.h" |
| 17 #include "ui/gfx/geometry/size_f.h" | 17 #include "ui/gfx/geometry/size_f.h" |
| 18 | 18 |
| 19 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
| 20 #include "ui/aura/window_tree_host.h" | 20 #include "ui/aura/window_tree_host.h" |
| 21 #include "ui/gfx/win/dpi.h" | 21 #include "ui/gfx/win/dpi.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 namespace ash { | 24 namespace ash { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 bool use_125_dsf_for_ui_scaling = false; | 27 bool use_125_dsf_for_ui_scaling = true; |
| 28 | 28 |
| 29 // Check the content of |spec| and fill |bounds| and |device_scale_factor|. | 29 // Check the content of |spec| and fill |bounds| and |device_scale_factor|. |
| 30 // Returns true when |bounds| is found. | 30 // Returns true when |bounds| is found. |
| 31 bool GetDisplayBounds( | 31 bool GetDisplayBounds( |
| 32 const std::string& spec, gfx::Rect* bounds, float* device_scale_factor) { | 32 const std::string& spec, gfx::Rect* bounds, float* device_scale_factor) { |
| 33 int width = 0; | 33 int width = 0; |
| 34 int height = 0; | 34 int height = 0; |
| 35 int x = 0; | 35 int x = 0; |
| 36 int y = 0; | 36 int y = 0; |
| 37 if (sscanf(spec.c_str(), "%dx%d*%f", | 37 if (sscanf(spec.c_str(), "%dx%d*%f", |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 54 gfx::Size size_a_dip = a.GetSizeInDIP(is_internal); | 54 gfx::Size size_a_dip = a.GetSizeInDIP(is_internal); |
| 55 gfx::Size size_b_dip = b.GetSizeInDIP(is_internal); | 55 gfx::Size size_b_dip = b.GetSizeInDIP(is_internal); |
| 56 if (size_a_dip.GetArea() == size_b_dip.GetArea()) | 56 if (size_a_dip.GetArea() == size_b_dip.GetArea()) |
| 57 return (a.refresh_rate > b.refresh_rate); | 57 return (a.refresh_rate > b.refresh_rate); |
| 58 return (size_a_dip.GetArea() < size_b_dip.GetArea()); | 58 return (size_a_dip.GetArea() < size_b_dip.GetArea()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool is_internal; | 61 bool is_internal; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 bool IsInternalDisplayId(int64 id) { | |
| 65 return id == gfx::Display::InternalDisplayId() && | |
| 66 id != gfx::Display::kInvalidDisplayID; | |
| 67 } | |
| 68 | |
| 64 } // namespace | 69 } // namespace |
| 65 | 70 |
| 66 DisplayMode::DisplayMode() | 71 DisplayMode::DisplayMode() |
| 67 : refresh_rate(0.0f), | 72 : refresh_rate(0.0f), |
| 68 interlaced(false), | 73 interlaced(false), |
| 69 native(false), | 74 native(false), |
| 70 ui_scale(1.0f), | 75 ui_scale(1.0f), |
| 71 device_scale_factor(1.0f) {} | 76 device_scale_factor(1.0f) {} |
| 72 | 77 |
| 73 DisplayMode::DisplayMode(const gfx::Size& size, | 78 DisplayMode::DisplayMode(const gfx::Size& size, |
| 74 float refresh_rate, | 79 float refresh_rate, |
| 75 bool interlaced, | 80 bool interlaced, |
| 76 bool native) | 81 bool native) |
| 77 : size(size), | 82 : size(size), |
| 78 refresh_rate(refresh_rate), | 83 refresh_rate(refresh_rate), |
| 79 interlaced(interlaced), | 84 interlaced(interlaced), |
| 80 native(native), | 85 native(native), |
| 81 ui_scale(1.0f), | 86 ui_scale(1.0f), |
| 82 device_scale_factor(1.0f) {} | 87 device_scale_factor(1.0f) {} |
| 83 | 88 |
| 84 gfx::Size DisplayMode::GetSizeInDIP(bool is_internal) const { | 89 gfx::Size DisplayMode::GetSizeInDIP(bool is_internal) const { |
| 85 gfx::SizeF size_dip(size); | 90 gfx::SizeF size_dip(size); |
| 86 size_dip.Scale(ui_scale); | 91 size_dip.Scale(ui_scale); |
| 87 // DSF=1.25 is special. The screen is drawn with DSF=1.25 in some mode but it | 92 // DSF=1.25 is special on internal display. The screen is drawn with DSF=1.25 |
| 88 // doesn't affect the screen size computation. | 93 // but it doesn't affect the screen size computation. |
| 89 if (!(use_125_dsf_for_ui_scaling && is_internal) || | 94 if (is_internal && device_scale_factor == 1.25f) |
|
Jun Mukai
2015/07/22 00:51:11
doesn't use_125_dsf_for_ui_scaling affect this beh
oshima
2015/07/22 01:09:24
Done.
| |
| 90 device_scale_factor != 1.25f) { | 95 return gfx::ToFlooredSize(size_dip); |
| 91 size_dip.Scale(1.0f / device_scale_factor); | 96 size_dip.Scale(1.0f / device_scale_factor); |
| 92 } | |
| 93 return gfx::ToFlooredSize(size_dip); | 97 return gfx::ToFlooredSize(size_dip); |
| 94 } | 98 } |
| 95 | 99 |
| 96 bool DisplayMode::IsEquivalent(const DisplayMode& other) const { | 100 bool DisplayMode::IsEquivalent(const DisplayMode& other) const { |
| 97 const float kEpsilon = 0.0001f; | 101 const float kEpsilon = 0.0001f; |
| 98 return size == other.size && | 102 return size == other.size && |
| 99 std::abs(ui_scale - other.ui_scale) < kEpsilon && | 103 std::abs(ui_scale - other.ui_scale) < kEpsilon && |
| 100 std::abs(device_scale_factor - other.device_scale_factor) < kEpsilon; | 104 std::abs(device_scale_factor - other.device_scale_factor) < kEpsilon; |
| 101 } | 105 } |
| 102 | 106 |
| 103 // satic | 107 // satic |
| 104 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { | 108 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { |
| 105 return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID); | 109 return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID); |
| 106 } | 110 } |
| 107 | 111 |
| 108 // static | 112 // static |
| 109 void DisplayInfo::SetUse125DSFForUIScaling(bool enable) { | |
| 110 use_125_dsf_for_ui_scaling = enable; | |
| 111 } | |
| 112 | |
| 113 // static | |
| 114 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, | 113 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, |
| 115 int64 id) { | 114 int64 id) { |
| 116 // Use larger than max int to catch overflow early. | 115 // Use larger than max int to catch overflow early. |
| 117 static int64 synthesized_display_id = 2200000000LL; | 116 static int64 synthesized_display_id = 2200000000LL; |
| 118 | 117 |
| 119 #if defined(OS_WIN) | 118 #if defined(OS_WIN) |
| 120 gfx::Rect bounds_in_native(aura::WindowTreeHost::GetNativeScreenSize()); | 119 gfx::Rect bounds_in_native(aura::WindowTreeHost::GetNativeScreenSize()); |
| 121 #else | 120 #else |
| 122 // Default bounds for a display. | 121 // Default bounds for a display. |
| 123 const int kDefaultHostWindowX = 200; | 122 const int kDefaultHostWindowX = 200; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 int height = bounds_in_native.height() / device_scale_factor / 40; | 223 int height = bounds_in_native.height() / device_scale_factor / 40; |
| 225 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); | 224 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); |
| 226 display_info.UpdateDisplaySize(); | 225 display_info.UpdateDisplaySize(); |
| 227 } | 226 } |
| 228 | 227 |
| 229 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() | 228 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() |
| 230 << ", spec=" << spec; | 229 << ", spec=" << spec; |
| 231 return display_info; | 230 return display_info; |
| 232 } | 231 } |
| 233 | 232 |
| 233 // static | |
| 234 void DisplayInfo::SetUse125DSFForUIScalingForTest(bool enable) { | |
| 235 use_125_dsf_for_ui_scaling = enable; | |
| 236 } | |
| 237 | |
| 234 DisplayInfo::DisplayInfo() | 238 DisplayInfo::DisplayInfo() |
| 235 : id_(gfx::Display::kInvalidDisplayID), | 239 : id_(gfx::Display::kInvalidDisplayID), |
| 236 has_overscan_(false), | 240 has_overscan_(false), |
| 237 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), | 241 touch_support_(gfx::Display::TOUCH_SUPPORT_UNKNOWN), |
| 238 touch_device_id_(0), | 242 touch_device_id_(0), |
| 239 device_scale_factor_(1.0f), | 243 device_scale_factor_(1.0f), |
| 240 overscan_insets_in_dip_(0, 0, 0, 0), | 244 overscan_insets_in_dip_(0, 0, 0, 0), |
| 241 configured_ui_scale_(1.0f), | 245 configured_ui_scale_(1.0f), |
| 242 native_(false), | 246 native_(false), |
| 243 is_aspect_preserving_scaling_(false), | 247 is_aspect_preserving_scaling_(false), |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 } | 318 } |
| 315 } | 319 } |
| 316 | 320 |
| 317 void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_native) { | 321 void DisplayInfo::SetBounds(const gfx::Rect& new_bounds_in_native) { |
| 318 bounds_in_native_ = new_bounds_in_native; | 322 bounds_in_native_ = new_bounds_in_native; |
| 319 size_in_pixel_ = new_bounds_in_native.size(); | 323 size_in_pixel_ = new_bounds_in_native.size(); |
| 320 UpdateDisplaySize(); | 324 UpdateDisplaySize(); |
| 321 } | 325 } |
| 322 | 326 |
| 323 float DisplayInfo::GetEffectiveDeviceScaleFactor() const { | 327 float DisplayInfo::GetEffectiveDeviceScaleFactor() const { |
| 324 if (Use125DSFRorUIScaling() && device_scale_factor_ == 1.25f) | 328 if (Use125DSFForUIScaling() && device_scale_factor_ == 1.25f) |
| 325 return (configured_ui_scale_ == 0.8f) ? 1.25f : 1.0f; | 329 return (configured_ui_scale_ == 0.8f) ? 1.25f : 1.0f; |
| 326 if (device_scale_factor_ == configured_ui_scale_) | 330 if (device_scale_factor_ == configured_ui_scale_) |
| 327 return 1.0f; | 331 return 1.0f; |
| 328 return device_scale_factor_; | 332 return device_scale_factor_; |
| 329 } | 333 } |
| 330 | 334 |
| 331 float DisplayInfo::GetEffectiveUIScale() const { | 335 float DisplayInfo::GetEffectiveUIScale() const { |
| 332 if (Use125DSFRorUIScaling() && device_scale_factor_ == 1.25f) | 336 if (Use125DSFForUIScaling() && device_scale_factor_ == 1.25f) |
| 333 return (configured_ui_scale_ == 0.8f) ? 1.0f : configured_ui_scale_; | 337 return (configured_ui_scale_ == 0.8f) ? 1.0f : configured_ui_scale_; |
| 334 if (device_scale_factor_ == configured_ui_scale_) | 338 if (device_scale_factor_ == configured_ui_scale_) |
| 335 return 1.0f; | 339 return 1.0f; |
| 336 return configured_ui_scale_; | 340 return configured_ui_scale_; |
| 337 } | 341 } |
| 338 | 342 |
| 339 void DisplayInfo::UpdateDisplaySize() { | 343 void DisplayInfo::UpdateDisplaySize() { |
| 340 size_in_pixel_ = bounds_in_native_.size(); | 344 size_in_pixel_ = bounds_in_native_.size(); |
| 341 if (!overscan_insets_in_dip_.empty()) { | 345 if (!overscan_insets_in_dip_.empty()) { |
| 342 gfx::Insets insets_in_pixel = | 346 gfx::Insets insets_in_pixel = |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 360 } | 364 } |
| 361 | 365 |
| 362 gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const { | 366 gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const { |
| 363 return overscan_insets_in_dip_.Scale(device_scale_factor_); | 367 return overscan_insets_in_dip_.Scale(device_scale_factor_); |
| 364 } | 368 } |
| 365 | 369 |
| 366 void DisplayInfo::SetDisplayModes( | 370 void DisplayInfo::SetDisplayModes( |
| 367 const std::vector<DisplayMode>& display_modes) { | 371 const std::vector<DisplayMode>& display_modes) { |
| 368 display_modes_ = display_modes; | 372 display_modes_ = display_modes; |
| 369 std::sort(display_modes_.begin(), display_modes_.end(), | 373 std::sort(display_modes_.begin(), display_modes_.end(), |
| 370 DisplayModeSorter(id_ == gfx::Display::InternalDisplayId())); | 374 DisplayModeSorter(IsInternalDisplayId(id_))); |
| 371 } | 375 } |
| 372 | 376 |
| 373 gfx::Size DisplayInfo::GetNativeModeSize() const { | 377 gfx::Size DisplayInfo::GetNativeModeSize() const { |
| 374 for (size_t i = 0; i < display_modes_.size(); ++i) { | 378 for (size_t i = 0; i < display_modes_.size(); ++i) { |
| 375 if (display_modes_[i].native) | 379 if (display_modes_[i].native) |
| 376 return display_modes_[i].size; | 380 return display_modes_[i].size; |
| 377 } | 381 } |
| 378 | 382 |
| 379 return gfx::Size(); | 383 return gfx::Size(); |
| 380 } | 384 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 color_profile_ = profile; | 426 color_profile_ = profile; |
| 423 } | 427 } |
| 424 | 428 |
| 425 bool DisplayInfo::IsColorProfileAvailable( | 429 bool DisplayInfo::IsColorProfileAvailable( |
| 426 ui::ColorCalibrationProfile profile) const { | 430 ui::ColorCalibrationProfile profile) const { |
| 427 return std::find(available_color_profiles_.begin(), | 431 return std::find(available_color_profiles_.begin(), |
| 428 available_color_profiles_.end(), | 432 available_color_profiles_.end(), |
| 429 profile) != available_color_profiles_.end(); | 433 profile) != available_color_profiles_.end(); |
| 430 } | 434 } |
| 431 | 435 |
| 432 bool DisplayInfo::Use125DSFRorUIScaling() const { | 436 bool DisplayInfo::Use125DSFForUIScaling() const { |
| 433 return use_125_dsf_for_ui_scaling && id_ == gfx::Display::InternalDisplayId(); | 437 return use_125_dsf_for_ui_scaling && IsInternalDisplayId(id_); |
| 434 } | 438 } |
| 435 | 439 |
| 436 } // namespace ash | 440 } // namespace ash |
| OLD | NEW |