| 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 "ash/common/display/display_info.h" | 5 #include "ash/common/display/display_info.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // Use larger than max int to catch overflow early. | 30 // Use larger than max int to catch overflow early. |
| 31 const int64_t kSynthesizedDisplayIdStart = 2200000000LL; | 31 const int64_t kSynthesizedDisplayIdStart = 2200000000LL; |
| 32 | 32 |
| 33 int64_t synthesized_display_id = kSynthesizedDisplayIdStart; | 33 int64_t synthesized_display_id = kSynthesizedDisplayIdStart; |
| 34 | 34 |
| 35 const float kDpi96 = 96.0; | 35 const float kDpi96 = 96.0; |
| 36 bool use_125_dsf_for_ui_scaling = true; | 36 bool use_125_dsf_for_ui_scaling = true; |
| 37 | 37 |
| 38 // Check the content of |spec| and fill |bounds| and |device_scale_factor|. | 38 // Check the content of |spec| and fill |bounds| and |device_scale_factor|. |
| 39 // Returns true when |bounds| is found. | 39 // Returns true when |bounds| is found. |
| 40 bool GetDisplayBounds( | 40 bool GetDisplayBounds(const std::string& spec, |
| 41 const std::string& spec, gfx::Rect* bounds, float* device_scale_factor) { | 41 gfx::Rect* bounds, |
| 42 float* device_scale_factor) { |
| 42 int width = 0; | 43 int width = 0; |
| 43 int height = 0; | 44 int height = 0; |
| 44 int x = 0; | 45 int x = 0; |
| 45 int y = 0; | 46 int y = 0; |
| 46 if (sscanf(spec.c_str(), "%dx%d*%f", | 47 if (sscanf(spec.c_str(), "%dx%d*%f", &width, &height, device_scale_factor) >= |
| 47 &width, &height, device_scale_factor) >= 2 || | 48 2 || |
| 48 sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height, | 49 sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height, |
| 49 device_scale_factor) >= 4) { | 50 device_scale_factor) >= 4) { |
| 50 bounds->SetRect(x, y, width, height); | 51 bounds->SetRect(x, y, width, height); |
| 51 return true; | 52 return true; |
| 52 } | 53 } |
| 53 return false; | 54 return false; |
| 54 } | 55 } |
| 55 | 56 |
| 56 // Display mode list is sorted by: | 57 // Display mode list is sorted by: |
| 57 // * the area in pixels in ascending order | 58 // * the area in pixels in ascending order |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // DSF=1.25 is special on internal display. The screen is drawn with DSF=1.25 | 97 // DSF=1.25 is special on internal display. The screen is drawn with DSF=1.25 |
| 97 // but it doesn't affect the screen size computation. | 98 // but it doesn't affect the screen size computation. |
| 98 if (use_125_dsf_for_ui_scaling && is_internal && device_scale_factor == 1.25f) | 99 if (use_125_dsf_for_ui_scaling && is_internal && device_scale_factor == 1.25f) |
| 99 return gfx::ToFlooredSize(size_dip); | 100 return gfx::ToFlooredSize(size_dip); |
| 100 size_dip.Scale(1.0f / device_scale_factor); | 101 size_dip.Scale(1.0f / device_scale_factor); |
| 101 return gfx::ToFlooredSize(size_dip); | 102 return gfx::ToFlooredSize(size_dip); |
| 102 } | 103 } |
| 103 | 104 |
| 104 bool DisplayMode::IsEquivalent(const DisplayMode& other) const { | 105 bool DisplayMode::IsEquivalent(const DisplayMode& other) const { |
| 105 const float kEpsilon = 0.0001f; | 106 const float kEpsilon = 0.0001f; |
| 106 return size == other.size && | 107 return size == other.size && std::abs(ui_scale - other.ui_scale) < kEpsilon && |
| 107 std::abs(ui_scale - other.ui_scale) < kEpsilon && | 108 std::abs(device_scale_factor - other.device_scale_factor) < kEpsilon; |
| 108 std::abs(device_scale_factor - other.device_scale_factor) < kEpsilon; | |
| 109 } | 109 } |
| 110 | 110 |
| 111 // satic | 111 // satic |
| 112 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { | 112 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { |
| 113 return CreateFromSpecWithID(spec, display::Display::kInvalidDisplayID); | 113 return CreateFromSpecWithID(spec, display::Display::kInvalidDisplayID); |
| 114 } | 114 } |
| 115 | 115 |
| 116 // static | 116 // static |
| 117 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, | 117 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, |
| 118 int64_t id) { | 118 int64_t id) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 float highest_refresh_rate = -1.0f; | 184 float highest_refresh_rate = -1.0f; |
| 185 main_spec = parts[0]; | 185 main_spec = parts[0]; |
| 186 std::string resolution_list = parts[1]; | 186 std::string resolution_list = parts[1]; |
| 187 parts = base::SplitString(resolution_list, "|", base::KEEP_WHITESPACE, | 187 parts = base::SplitString(resolution_list, "|", base::KEEP_WHITESPACE, |
| 188 base::SPLIT_WANT_NONEMPTY); | 188 base::SPLIT_WANT_NONEMPTY); |
| 189 for (size_t i = 0; i < parts.size(); ++i) { | 189 for (size_t i = 0; i < parts.size(); ++i) { |
| 190 DisplayMode mode; | 190 DisplayMode mode; |
| 191 gfx::Rect mode_bounds; | 191 gfx::Rect mode_bounds; |
| 192 std::vector<std::string> resolution = base::SplitString( | 192 std::vector<std::string> resolution = base::SplitString( |
| 193 parts[i], "%", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 193 parts[i], "%", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 194 if (GetDisplayBounds( | 194 if (GetDisplayBounds(resolution[0], &mode_bounds, |
| 195 resolution[0], &mode_bounds, &mode.device_scale_factor)) { | 195 &mode.device_scale_factor)) { |
| 196 mode.size = mode_bounds.size(); | 196 mode.size = mode_bounds.size(); |
| 197 if (resolution.size() > 1) | 197 if (resolution.size() > 1) |
| 198 sscanf(resolution[1].c_str(), "%f", &mode.refresh_rate); | 198 sscanf(resolution[1].c_str(), "%f", &mode.refresh_rate); |
| 199 if (mode.size.GetArea() >= largest_area && | 199 if (mode.size.GetArea() >= largest_area && |
| 200 mode.refresh_rate > highest_refresh_rate) { | 200 mode.refresh_rate > highest_refresh_rate) { |
| 201 // Use mode with largest area and highest refresh rate as native. | 201 // Use mode with largest area and highest refresh rate as native. |
| 202 largest_area = mode.size.GetArea(); | 202 largest_area = mode.size.GetArea(); |
| 203 highest_refresh_rate = mode.refresh_rate; | 203 highest_refresh_rate = mode.refresh_rate; |
| 204 native_mode = i; | 204 native_mode = i; |
| 205 } | 205 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 device_dpi_(kDpi96), | 261 device_dpi_(kDpi96), |
| 262 overscan_insets_in_dip_(0, 0, 0, 0), | 262 overscan_insets_in_dip_(0, 0, 0, 0), |
| 263 configured_ui_scale_(1.0f), | 263 configured_ui_scale_(1.0f), |
| 264 native_(false), | 264 native_(false), |
| 265 is_aspect_preserving_scaling_(false), | 265 is_aspect_preserving_scaling_(false), |
| 266 clear_overscan_insets_(false), | 266 clear_overscan_insets_(false), |
| 267 color_profile_(ui::COLOR_PROFILE_STANDARD) {} | 267 color_profile_(ui::COLOR_PROFILE_STANDARD) {} |
| 268 | 268 |
| 269 DisplayInfo::DisplayInfo(const DisplayInfo& other) = default; | 269 DisplayInfo::DisplayInfo(const DisplayInfo& other) = default; |
| 270 | 270 |
| 271 DisplayInfo::~DisplayInfo() { | 271 DisplayInfo::~DisplayInfo() {} |
| 272 } | |
| 273 | 272 |
| 274 void DisplayInfo::SetRotation(display::Display::Rotation rotation, | 273 void DisplayInfo::SetRotation(display::Display::Rotation rotation, |
| 275 display::Display::RotationSource source) { | 274 display::Display::RotationSource source) { |
| 276 rotations_[source] = rotation; | 275 rotations_[source] = rotation; |
| 277 rotations_[display::Display::ROTATION_SOURCE_ACTIVE] = rotation; | 276 rotations_[display::Display::ROTATION_SOURCE_ACTIVE] = rotation; |
| 278 active_rotation_source_ = source; | 277 active_rotation_source_ = source; |
| 279 } | 278 } |
| 280 | 279 |
| 281 display::Display::Rotation DisplayInfo::GetActiveRotation() const { | 280 display::Display::Rotation DisplayInfo::GetActiveRotation() const { |
| 282 return GetRotation(display::Display::ROTATION_SOURCE_ACTIVE); | 281 return GetRotation(display::Display::ROTATION_SOURCE_ACTIVE); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 415 |
| 417 return result; | 416 return result; |
| 418 } | 417 } |
| 419 | 418 |
| 420 std::string DisplayInfo::ToFullString() const { | 419 std::string DisplayInfo::ToFullString() const { |
| 421 std::string display_modes_str; | 420 std::string display_modes_str; |
| 422 std::vector<DisplayMode>::const_iterator iter = display_modes_.begin(); | 421 std::vector<DisplayMode>::const_iterator iter = display_modes_.begin(); |
| 423 for (; iter != display_modes_.end(); ++iter) { | 422 for (; iter != display_modes_.end(); ++iter) { |
| 424 if (!display_modes_str.empty()) | 423 if (!display_modes_str.empty()) |
| 425 display_modes_str += ","; | 424 display_modes_str += ","; |
| 426 base::StringAppendF(&display_modes_str, | 425 base::StringAppendF(&display_modes_str, "(%dx%d@%f%c%s)", |
| 427 "(%dx%d@%f%c%s)", | 426 iter->size.width(), iter->size.height(), |
| 428 iter->size.width(), | 427 iter->refresh_rate, iter->interlaced ? 'I' : 'P', |
| 429 iter->size.height(), | |
| 430 iter->refresh_rate, | |
| 431 iter->interlaced ? 'I' : 'P', | |
| 432 iter->native ? "(N)" : ""); | 428 iter->native ? "(N)" : ""); |
| 433 } | 429 } |
| 434 return ToString() + ", display_modes==" + display_modes_str; | 430 return ToString() + ", display_modes==" + display_modes_str; |
| 435 } | 431 } |
| 436 | 432 |
| 437 void DisplayInfo::SetColorProfile(ui::ColorCalibrationProfile profile) { | 433 void DisplayInfo::SetColorProfile(ui::ColorCalibrationProfile profile) { |
| 438 if (IsColorProfileAvailable(profile)) | 434 if (IsColorProfileAvailable(profile)) |
| 439 color_profile_ = profile; | 435 color_profile_ = profile; |
| 440 } | 436 } |
| 441 | 437 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 457 | 453 |
| 458 void DisplayInfo::ClearInputDevices() { | 454 void DisplayInfo::ClearInputDevices() { |
| 459 input_devices_.clear(); | 455 input_devices_.clear(); |
| 460 } | 456 } |
| 461 | 457 |
| 462 void ResetDisplayIdForTest() { | 458 void ResetDisplayIdForTest() { |
| 463 synthesized_display_id = kSynthesizedDisplayIdStart; | 459 synthesized_display_id = kSynthesizedDisplayIdStart; |
| 464 } | 460 } |
| 465 | 461 |
| 466 } // namespace ash | 462 } // namespace ash |
| OLD | NEW |