OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/display/manager/display_manager_utilities.h" | 5 #include "ui/display/manager/display_manager_utilities.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
11 #include "ui/display/manager/managed_display_info.h" | 11 #include "ui/display/manager/managed_display_info.h" |
12 #include "ui/gfx/geometry/size_conversions.h" | 12 #include "ui/gfx/geometry/size_conversions.h" |
13 #include "ui/gfx/geometry/size_f.h" | 13 #include "ui/gfx/geometry/size_f.h" |
14 | 14 |
15 namespace display { | 15 namespace display { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // List of value UI Scale values. Scales for 2x are equivalent to 640, | 19 // List of value UI Scale values. Scales for 2x are equivalent to 640, |
20 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on | 20 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on |
21 // 2560 pixel width 2x density display. Please see crbug.com/233375 | 21 // 2560 pixel width 2x density display. Please see crbug.com/233375 |
22 // for the full list of resolutions. | 22 // for the full list of resolutions. |
23 const float kUIScalesFor2x[] = {0.5f, 0.625f, 0.8f, 1.0f, | 23 constexpr float kUIScalesFor2x[] = {0.5f, 0.625f, 0.8f, 1.0f, |
24 1.125f, 1.25f, 1.5f, 2.0f}; | 24 1.125f, 1.25f, 1.5f, 2.0f}; |
25 const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f}; | 25 constexpr float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f}; |
26 const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f}; | 26 constexpr float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f}; |
27 const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f}; | 27 constexpr float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f}; |
28 | 28 |
29 std::vector<float> GetScalesForDisplay( | 29 // The default UI scales for the above display densities. |
| 30 constexpr float kDefaultUIScaleFor2x = 1.0f; |
| 31 constexpr float kDefaultUIScaleFor1_25x = 0.8f; |
| 32 constexpr float kDefaultUIScaleFor1280 = 1.0f; |
| 33 constexpr float kDefaultUIScaleFor1366 = 1.0f; |
| 34 |
| 35 // Encapsulates the list of UI scales and the default one. |
| 36 struct DisplayUIScales { |
| 37 std::vector<float> scales; |
| 38 float default_scale; |
| 39 }; |
| 40 |
| 41 DisplayUIScales GetScalesForDisplay( |
30 const scoped_refptr<display::ManagedDisplayMode>& native_mode) { | 42 const scoped_refptr<display::ManagedDisplayMode>& native_mode) { |
31 #define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a)) | 43 #define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a)) |
32 | 44 |
33 std::vector<float> ret; | 45 DisplayUIScales ret; |
34 if (native_mode->device_scale_factor() == 2.0f) { | 46 if (native_mode->device_scale_factor() == 2.0f) { |
35 ASSIGN_ARRAY(ret, kUIScalesFor2x); | 47 ASSIGN_ARRAY(ret.scales, kUIScalesFor2x); |
| 48 ret.default_scale = kDefaultUIScaleFor2x; |
36 return ret; | 49 return ret; |
37 } else if (native_mode->device_scale_factor() == 1.25f) { | 50 } else if (native_mode->device_scale_factor() == 1.25f) { |
38 ASSIGN_ARRAY(ret, kUIScalesFor1_25x); | 51 ASSIGN_ARRAY(ret.scales, kUIScalesFor1_25x); |
| 52 ret.default_scale = kDefaultUIScaleFor1_25x; |
39 return ret; | 53 return ret; |
40 } | 54 } |
41 switch (native_mode->size().width()) { | 55 switch (native_mode->size().width()) { |
42 case 1280: | 56 case 1280: |
43 ASSIGN_ARRAY(ret, kUIScalesFor1280); | 57 ASSIGN_ARRAY(ret.scales, kUIScalesFor1280); |
| 58 ret.default_scale = kDefaultUIScaleFor1280; |
44 break; | 59 break; |
45 case 1366: | 60 case 1366: |
46 ASSIGN_ARRAY(ret, kUIScalesFor1366); | 61 ASSIGN_ARRAY(ret.scales, kUIScalesFor1366); |
| 62 ret.default_scale = kDefaultUIScaleFor1366; |
47 break; | 63 break; |
48 default: | 64 default: |
49 ASSIGN_ARRAY(ret, kUIScalesFor1280); | 65 ASSIGN_ARRAY(ret.scales, kUIScalesFor1280); |
| 66 ret.default_scale = kDefaultUIScaleFor1280; |
50 #if defined(OS_CHROMEOS) | 67 #if defined(OS_CHROMEOS) |
51 if (base::SysInfo::IsRunningOnChromeOS()) | 68 if (base::SysInfo::IsRunningOnChromeOS()) |
52 NOTREACHED() << "Unknown resolution:" << native_mode->size().ToString(); | 69 NOTREACHED() << "Unknown resolution:" << native_mode->size().ToString(); |
53 #endif | 70 #endif |
54 } | 71 } |
55 return ret; | 72 return ret; |
56 } | 73 } |
57 | 74 |
58 struct ScaleComparator { | 75 struct ScaleComparator { |
59 explicit ScaleComparator(float s) : scale(s) {} | 76 explicit ScaleComparator(float s) : scale(s) {} |
(...skipping 22 matching lines...) Expand all Loading... |
82 } // namespace | 99 } // namespace |
83 | 100 |
84 display::ManagedDisplayInfo::ManagedDisplayModeList | 101 display::ManagedDisplayInfo::ManagedDisplayModeList |
85 CreateInternalManagedDisplayModeList( | 102 CreateInternalManagedDisplayModeList( |
86 const scoped_refptr<display::ManagedDisplayMode>& native_mode) { | 103 const scoped_refptr<display::ManagedDisplayMode>& native_mode) { |
87 display::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list; | 104 display::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list; |
88 | 105 |
89 float native_ui_scale = (native_mode->device_scale_factor() == 1.25f) | 106 float native_ui_scale = (native_mode->device_scale_factor() == 1.25f) |
90 ? 1.0f | 107 ? 1.0f |
91 : native_mode->device_scale_factor(); | 108 : native_mode->device_scale_factor(); |
92 for (float ui_scale : GetScalesForDisplay(native_mode)) { | 109 const DisplayUIScales display_ui_scales = GetScalesForDisplay(native_mode); |
| 110 for (float ui_scale : display_ui_scales.scales) { |
93 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( | 111 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( |
94 native_mode->size(), native_mode->refresh_rate(), | 112 native_mode->size(), native_mode->refresh_rate(), |
95 native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale, | 113 native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale, |
96 native_mode->device_scale_factor())); | 114 native_mode->device_scale_factor())); |
| 115 mode->set_is_default(ui_scale == display_ui_scales.default_scale); |
97 display_mode_list.push_back(mode); | 116 display_mode_list.push_back(mode); |
98 } | 117 } |
99 return display_mode_list; | 118 return display_mode_list; |
100 } | 119 } |
101 | 120 |
102 display::ManagedDisplayInfo::ManagedDisplayModeList | 121 display::ManagedDisplayInfo::ManagedDisplayModeList |
103 CreateUnifiedManagedDisplayModeList( | 122 CreateUnifiedManagedDisplayModeList( |
104 const scoped_refptr<display::ManagedDisplayMode>& native_mode, | 123 const scoped_refptr<display::ManagedDisplayMode>& native_mode, |
105 const std::set<std::pair<float, float>>& dsf_scale_list) { | 124 const std::set<std::pair<float, float>>& dsf_scale_list) { |
106 display::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list; | 125 display::ManagedDisplayInfo::ManagedDisplayModeList display_mode_list; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID | 308 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID |
290 // in edid_parser.cc. | 309 // in edid_parser.cc. |
291 int index_1 = id1 & 0xFF; | 310 int index_1 = id1 & 0xFF; |
292 int index_2 = id2 & 0xFF; | 311 int index_2 = id2 & 0xFF; |
293 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; | 312 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; |
294 return display::Display::IsInternalDisplayId(id1) || | 313 return display::Display::IsInternalDisplayId(id1) || |
295 (index_1 < index_2 && !display::Display::IsInternalDisplayId(id2)); | 314 (index_1 < index_2 && !display::Display::IsInternalDisplayId(id2)); |
296 } | 315 } |
297 | 316 |
298 } // namespace display | 317 } // namespace display |
OLD | NEW |