OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/display/display_change_observer_chromeos.h" | 5 #include "ash/display/display_change_observer_chromeos.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 29 matching lines...) Expand all Loading... |
40 namespace { | 40 namespace { |
41 | 41 |
42 // The DPI threshold to determine the device scale factor. | 42 // The DPI threshold to determine the device scale factor. |
43 // DPI higher than |dpi| will use |device_scale_factor|. | 43 // DPI higher than |dpi| will use |device_scale_factor|. |
44 struct DeviceScaleFactorDPIThreshold { | 44 struct DeviceScaleFactorDPIThreshold { |
45 float dpi; | 45 float dpi; |
46 float device_scale_factor; | 46 float device_scale_factor; |
47 }; | 47 }; |
48 | 48 |
49 const DeviceScaleFactorDPIThreshold kThresholdTable[] = { | 49 const DeviceScaleFactorDPIThreshold kThresholdTable[] = { |
50 {200.0f, 2.0f}, | 50 {200.0f, 2.0f}, |
51 {150.0f, 1.25f}, | 51 {150.0f, 1.25f}, |
52 {0.0f, 1.0f}, | 52 {0.0f, 1.0f}, |
53 }; | 53 }; |
54 | 54 |
55 // 1 inch in mm. | 55 // 1 inch in mm. |
56 const float kInchInMm = 25.4f; | 56 const float kInchInMm = 25.4f; |
57 | 57 |
58 // The minimum pixel width whose monitor can be called as '4K'. | 58 // The minimum pixel width whose monitor can be called as '4K'. |
59 const int kMinimumWidthFor4K = 3840; | 59 const int kMinimumWidthFor4K = 3840; |
60 | 60 |
61 // The list of device scale factors (in addition to 1.0f) which is | 61 // The list of device scale factors (in addition to 1.0f) which is |
62 // available in extrenal large monitors. | 62 // available in extrenal large monitors. |
(...skipping 12 matching lines...) Expand all Loading... |
75 | 75 |
76 } // namespace | 76 } // namespace |
77 | 77 |
78 // static | 78 // static |
79 std::vector<DisplayMode> DisplayChangeObserver::GetInternalDisplayModeList( | 79 std::vector<DisplayMode> DisplayChangeObserver::GetInternalDisplayModeList( |
80 const DisplayInfo& display_info, | 80 const DisplayInfo& display_info, |
81 const ui::DisplaySnapshot& output) { | 81 const ui::DisplaySnapshot& output) { |
82 const ui::DisplayMode* ui_native_mode = output.native_mode(); | 82 const ui::DisplayMode* ui_native_mode = output.native_mode(); |
83 DisplayMode native_mode(ui_native_mode->size(), | 83 DisplayMode native_mode(ui_native_mode->size(), |
84 ui_native_mode->refresh_rate(), | 84 ui_native_mode->refresh_rate(), |
85 ui_native_mode->is_interlaced(), | 85 ui_native_mode->is_interlaced(), true); |
86 true); | |
87 native_mode.device_scale_factor = display_info.device_scale_factor(); | 86 native_mode.device_scale_factor = display_info.device_scale_factor(); |
88 | 87 |
89 return CreateInternalDisplayModeList(native_mode); | 88 return CreateInternalDisplayModeList(native_mode); |
90 } | 89 } |
91 | 90 |
92 // static | 91 // static |
93 std::vector<DisplayMode> DisplayChangeObserver::GetExternalDisplayModeList( | 92 std::vector<DisplayMode> DisplayChangeObserver::GetExternalDisplayModeList( |
94 const ui::DisplaySnapshot& output) { | 93 const ui::DisplaySnapshot& output) { |
95 typedef std::map<std::pair<int, int>, DisplayMode> DisplayModeMap; | 94 typedef std::map<std::pair<int, int>, DisplayMode> DisplayModeMap; |
96 DisplayModeMap display_mode_map; | 95 DisplayModeMap display_mode_map; |
(...skipping 27 matching lines...) Expand all Loading... |
124 DisplayModeMap::iterator it = display_mode_map.find(size); | 123 DisplayModeMap::iterator it = display_mode_map.find(size); |
125 DCHECK(it != display_mode_map.end()) | 124 DCHECK(it != display_mode_map.end()) |
126 << "Native mode must be part of the mode list."; | 125 << "Native mode must be part of the mode list."; |
127 | 126 |
128 // If the native mode was replaced re-add it. | 127 // If the native mode was replaced re-add it. |
129 if (!it->second.native) | 128 if (!it->second.native) |
130 display_mode_list.push_back(native_mode); | 129 display_mode_list.push_back(native_mode); |
131 } | 130 } |
132 | 131 |
133 if (native_mode.size.width() >= kMinimumWidthFor4K) { | 132 if (native_mode.size.width() >= kMinimumWidthFor4K) { |
134 for (size_t i = 0; i < arraysize(kAdditionalDeviceScaleFactorsFor4k); | 133 for (size_t i = 0; i < arraysize(kAdditionalDeviceScaleFactorsFor4k); ++i) { |
135 ++i) { | |
136 DisplayMode mode = native_mode; | 134 DisplayMode mode = native_mode; |
137 mode.device_scale_factor = kAdditionalDeviceScaleFactorsFor4k[i]; | 135 mode.device_scale_factor = kAdditionalDeviceScaleFactorsFor4k[i]; |
138 mode.native = false; | 136 mode.native = false; |
139 display_mode_list.push_back(mode); | 137 display_mode_list.push_back(mode); |
140 } | 138 } |
141 } | 139 } |
142 | 140 |
143 return display_mode_list; | 141 return display_mode_list; |
144 } | 142 } |
145 | 143 |
(...skipping 15 matching lines...) Expand all Loading... |
161 display::DisplayIdList list = | 159 display::DisplayIdList list = |
162 GenerateDisplayIdList(display_states.begin(), display_states.end(), | 160 GenerateDisplayIdList(display_states.begin(), display_states.end(), |
163 [](const ui::DisplaySnapshot* display_state) { | 161 [](const ui::DisplaySnapshot* display_state) { |
164 return display_state->display_id(); | 162 return display_state->display_id(); |
165 }); | 163 }); |
166 | 164 |
167 const display::DisplayLayout& layout = Shell::GetInstance() | 165 const display::DisplayLayout& layout = Shell::GetInstance() |
168 ->display_manager() | 166 ->display_manager() |
169 ->layout_store() | 167 ->layout_store() |
170 ->GetRegisteredDisplayLayout(list); | 168 ->GetRegisteredDisplayLayout(list); |
171 return layout.mirrored ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR : | 169 return layout.mirrored ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR |
172 ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED; | 170 : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED; |
173 } | 171 } |
174 | 172 |
175 bool DisplayChangeObserver::GetResolutionForDisplayId(int64_t display_id, | 173 bool DisplayChangeObserver::GetResolutionForDisplayId(int64_t display_id, |
176 gfx::Size* size) const { | 174 gfx::Size* size) const { |
177 DisplayMode mode; | 175 DisplayMode mode; |
178 if (!Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( | 176 if (!Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( |
179 display_id, &mode)) | 177 display_id, &mode)) |
180 return false; | 178 return false; |
181 | 179 |
182 *size = mode.size; | 180 *size = mode.size; |
183 return true; | 181 return true; |
184 } | 182 } |
185 | 183 |
186 void DisplayChangeObserver::OnDisplayModeChanged( | 184 void DisplayChangeObserver::OnDisplayModeChanged( |
187 const ui::DisplayConfigurator::DisplayStateList& display_states) { | 185 const ui::DisplayConfigurator::DisplayStateList& display_states) { |
188 UpdateInternalDisplayId(display_states); | 186 UpdateInternalDisplayId(display_states); |
189 | 187 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 305 } |
308 return 1.0f; | 306 return 1.0f; |
309 } | 307 } |
310 | 308 |
311 void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() { | 309 void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() { |
312 OnDisplayModeChanged( | 310 OnDisplayModeChanged( |
313 Shell::GetInstance()->display_configurator()->cached_displays()); | 311 Shell::GetInstance()->display_configurator()->cached_displays()); |
314 } | 312 } |
315 | 313 |
316 } // namespace ash | 314 } // namespace ash |
OLD | NEW |