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 "ui/display/manager/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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
19 #include "ui/gfx/geometry/size_conversions.h" | 19 #include "ui/gfx/geometry/size_conversions.h" |
20 #include "ui/gfx/geometry/size_f.h" | 20 #include "ui/gfx/geometry/size_f.h" |
21 | 21 |
22 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
23 #include <windows.h> | 23 #include <windows.h> |
24 #include "ui/display/win/dpi.h" | 24 #include "ui/display/win/dpi.h" |
25 #endif | 25 #endif |
26 | 26 |
27 namespace ash { | 27 namespace ui { |
28 namespace { | 28 namespace { |
29 | 29 |
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 |
(...skipping 16 matching lines...) Expand all Loading... |
54 return false; | 54 return false; |
55 } | 55 } |
56 | 56 |
57 // Display mode list is sorted by: | 57 // Display mode list is sorted by: |
58 // * the area in pixels in ascending order | 58 // * the area in pixels in ascending order |
59 // * refresh rate in descending order | 59 // * refresh rate in descending order |
60 struct ManagedDisplayModeSorter { | 60 struct ManagedDisplayModeSorter { |
61 explicit ManagedDisplayModeSorter(bool is_internal) | 61 explicit ManagedDisplayModeSorter(bool is_internal) |
62 : is_internal(is_internal) {} | 62 : is_internal(is_internal) {} |
63 | 63 |
64 bool operator()(const scoped_refptr<ManagedDisplayMode>& a, | 64 bool operator()(const scoped_refptr<ui::ManagedDisplayMode>& a, |
65 const scoped_refptr<ManagedDisplayMode>& b) { | 65 const scoped_refptr<ui::ManagedDisplayMode>& b) { |
66 gfx::Size size_a_dip = a->GetSizeInDIP(is_internal); | 66 gfx::Size size_a_dip = a->GetSizeInDIP(is_internal); |
67 gfx::Size size_b_dip = b->GetSizeInDIP(is_internal); | 67 gfx::Size size_b_dip = b->GetSizeInDIP(is_internal); |
68 if (size_a_dip.GetArea() == size_b_dip.GetArea()) | 68 if (size_a_dip.GetArea() == size_b_dip.GetArea()) |
69 return (a->refresh_rate() > b->refresh_rate()); | 69 return (a->refresh_rate() > b->refresh_rate()); |
70 return (size_a_dip.GetArea() < size_b_dip.GetArea()); | 70 return (size_a_dip.GetArea() < size_b_dip.GetArea()); |
71 } | 71 } |
72 | 72 |
73 bool is_internal; | 73 bool is_internal; |
74 }; | 74 }; |
75 | 75 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // DSF=1.25 is special on internal display. The screen is drawn with DSF=1.25 | 122 // DSF=1.25 is special on internal display. The screen is drawn with DSF=1.25 |
123 // but it doesn't affect the screen size computation. | 123 // but it doesn't affect the screen size computation. |
124 if (use_125_dsf_for_ui_scaling && is_internal && | 124 if (use_125_dsf_for_ui_scaling && is_internal && |
125 device_scale_factor_ == 1.25f) | 125 device_scale_factor_ == 1.25f) |
126 return gfx::ToFlooredSize(size_dip); | 126 return gfx::ToFlooredSize(size_dip); |
127 size_dip.Scale(1.0f / device_scale_factor_); | 127 size_dip.Scale(1.0f / device_scale_factor_); |
128 return gfx::ToFlooredSize(size_dip); | 128 return gfx::ToFlooredSize(size_dip); |
129 } | 129 } |
130 | 130 |
131 bool ManagedDisplayMode::IsEquivalent( | 131 bool ManagedDisplayMode::IsEquivalent( |
132 const scoped_refptr<ManagedDisplayMode>& other) const { | 132 const scoped_refptr<ui::ManagedDisplayMode>& other) const { |
133 const float kEpsilon = 0.0001f; | 133 const float kEpsilon = 0.0001f; |
134 return size_ == other->size_ && | 134 return size_ == other->size_ && |
135 std::abs(ui_scale_ - other->ui_scale_) < kEpsilon && | 135 std::abs(ui_scale_ - other->ui_scale_) < kEpsilon && |
136 std::abs(device_scale_factor_ - other->device_scale_factor_) < | 136 std::abs(device_scale_factor_ - other->device_scale_factor_) < |
137 kEpsilon; | 137 kEpsilon; |
138 } | 138 } |
139 | 139 |
140 // static | 140 // static |
141 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { | 141 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { |
142 return CreateFromSpecWithID(spec, display::Display::kInvalidDisplayID); | 142 return CreateFromSpecWithID(spec, display::Display::kInvalidDisplayID); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // Use mode with largest area and highest refresh rate as native. | 232 // Use mode with largest area and highest refresh rate as native. |
233 largest_area = size.GetArea(); | 233 largest_area = size.GetArea(); |
234 highest_refresh_rate = refresh_rate; | 234 highest_refresh_rate = refresh_rate; |
235 native_mode = i; | 235 native_mode = i; |
236 } | 236 } |
237 display_modes.push_back(make_scoped_refptr( | 237 display_modes.push_back(make_scoped_refptr( |
238 new ManagedDisplayMode(size, refresh_rate, is_interlaced, false, | 238 new ManagedDisplayMode(size, refresh_rate, is_interlaced, false, |
239 1.0, device_scale_factor))); | 239 1.0, device_scale_factor))); |
240 } | 240 } |
241 } | 241 } |
242 scoped_refptr<ManagedDisplayMode> dm = display_modes[native_mode]; | 242 scoped_refptr<ui::ManagedDisplayMode> dm = display_modes[native_mode]; |
243 display_modes[native_mode] = new ManagedDisplayMode( | 243 display_modes[native_mode] = new ManagedDisplayMode( |
244 dm->size(), dm->refresh_rate(), dm->is_interlaced(), true, | 244 dm->size(), dm->refresh_rate(), dm->is_interlaced(), true, |
245 dm->ui_scale(), dm->device_scale_factor()); | 245 dm->ui_scale(), dm->device_scale_factor()); |
246 } | 246 } |
247 | 247 |
248 if (id == display::Display::kInvalidDisplayID) | 248 if (id == display::Display::kInvalidDisplayID) |
249 id = synthesized_display_id++; | 249 id = synthesized_display_id++; |
250 DisplayInfo display_info( | 250 ui::DisplayInfo display_info( |
251 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); | 251 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); |
252 display_info.set_device_scale_factor(device_scale_factor); | 252 display_info.set_device_scale_factor(device_scale_factor); |
253 display_info.SetRotation(rotation, display::Display::ROTATION_SOURCE_ACTIVE); | 253 display_info.SetRotation(rotation, display::Display::ROTATION_SOURCE_ACTIVE); |
254 display_info.set_configured_ui_scale(ui_scale); | 254 display_info.set_configured_ui_scale(ui_scale); |
255 display_info.SetBounds(bounds_in_native); | 255 display_info.SetBounds(bounds_in_native); |
256 display_info.SetManagedDisplayModes(display_modes); | 256 display_info.SetManagedDisplayModes(display_modes); |
257 | 257 |
258 // To test the overscan, it creates the default 5% overscan. | 258 // To test the overscan, it creates the default 5% overscan. |
259 if (has_overscan) { | 259 if (has_overscan) { |
260 int width = bounds_in_native.width() / device_scale_factor / 40; | 260 int width = bounds_in_native.width() / device_scale_factor / 40; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 } | 489 } |
490 | 490 |
491 void DisplayInfo::ClearInputDevices() { | 491 void DisplayInfo::ClearInputDevices() { |
492 input_devices_.clear(); | 492 input_devices_.clear(); |
493 } | 493 } |
494 | 494 |
495 void ResetDisplayIdForTest() { | 495 void ResetDisplayIdForTest() { |
496 synthesized_display_id = kSynthesizedDisplayIdStart; | 496 synthesized_display_id = kSynthesizedDisplayIdStart; |
497 } | 497 } |
498 | 498 |
499 } // namespace ash | 499 } // namespace ui |
OLD | NEW |