| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/test/display_manager_test_api.h" | 5 #include "ui/display/test/display_manager_test_api.h" |
| 6 | 6 |
| 7 #include <cstdarg> | 7 #include <cstdarg> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "ui/display/display.h" | 11 #include "ui/display/display.h" |
| 12 #include "ui/display/manager/display_layout_builder.h" | 12 #include "ui/display/manager/display_layout_builder.h" |
| 13 #include "ui/display/manager/display_manager.h" | 13 #include "ui/display/manager/display_manager.h" |
| 14 #include "ui/display/manager/display_manager_utilities.h" | 14 #include "ui/display/manager/display_manager_utilities.h" |
| 15 #include "ui/display/manager/managed_display_info.h" | 15 #include "ui/display/manager/managed_display_info.h" |
| 16 #include "ui/display/screen.h" | 16 #include "ui/display/screen.h" |
| 17 | 17 |
| 18 namespace display { | 18 namespace display { |
| 19 namespace test { | 19 namespace test { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 DisplayInfoList CreateDisplayInfoListFromString( | 22 DisplayInfoList CreateDisplayInfoListFromString( |
| 23 const std::string specs, | 23 const std::string specs, |
| 24 DisplayManager* display_manager) { | 24 DisplayManager* display_manager) { |
| 25 DisplayInfoList display_info_list; | 25 DisplayInfoList display_info_list; |
| 26 std::vector<std::string> parts = base::SplitString( | 26 std::vector<std::string> parts = base::SplitString( |
| 27 specs, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 27 specs, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 28 size_t index = 0; | 28 size_t index = 0; |
| 29 | 29 |
| 30 display::Displays list = | 30 Displays list = display_manager->IsInUnifiedMode() |
| 31 display_manager->IsInUnifiedMode() | 31 ? display_manager->software_mirroring_display_list() |
| 32 ? display_manager->software_mirroring_display_list() | 32 : display_manager->active_display_list(); |
| 33 : display_manager->active_display_list(); | |
| 34 | 33 |
| 35 for (std::vector<std::string>::const_iterator iter = parts.begin(); | 34 for (std::vector<std::string>::const_iterator iter = parts.begin(); |
| 36 iter != parts.end(); ++iter, ++index) { | 35 iter != parts.end(); ++iter, ++index) { |
| 37 int64_t id = (index < list.size()) ? list[index].id() : kInvalidDisplayId; | 36 int64_t id = (index < list.size()) ? list[index].id() : kInvalidDisplayId; |
| 38 display_info_list.push_back( | 37 display_info_list.push_back( |
| 39 display::ManagedDisplayInfo::CreateFromSpecWithID(*iter, id)); | 38 ManagedDisplayInfo::CreateFromSpecWithID(*iter, id)); |
| 40 } | 39 } |
| 41 return display_info_list; | 40 return display_info_list; |
| 42 } | 41 } |
| 43 | 42 |
| 44 scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForUIScale( | 43 scoped_refptr<ManagedDisplayMode> GetDisplayModeForUIScale( |
| 45 const display::ManagedDisplayInfo& info, | 44 const ManagedDisplayInfo& info, |
| 46 float ui_scale) { | 45 float ui_scale) { |
| 47 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = | 46 const ManagedDisplayInfo::ManagedDisplayModeList& modes = |
| 48 info.display_modes(); | 47 info.display_modes(); |
| 49 auto iter = std::find_if( | 48 auto iter = |
| 50 modes.begin(), modes.end(), | 49 std::find_if(modes.begin(), modes.end(), |
| 51 [ui_scale](const scoped_refptr<display::ManagedDisplayMode>& mode) { | 50 [ui_scale](const scoped_refptr<ManagedDisplayMode>& mode) { |
| 52 return mode->ui_scale() == ui_scale; | 51 return mode->ui_scale() == ui_scale; |
| 53 }); | 52 }); |
| 54 if (iter == modes.end()) | 53 if (iter == modes.end()) |
| 55 return scoped_refptr<display::ManagedDisplayMode>(); | 54 return scoped_refptr<ManagedDisplayMode>(); |
| 56 return *iter; | 55 return *iter; |
| 57 } | 56 } |
| 58 | 57 |
| 59 } // namespace | 58 } // namespace |
| 60 | 59 |
| 61 DisplayManagerTestApi::DisplayManagerTestApi(DisplayManager* display_manager) | 60 DisplayManagerTestApi::DisplayManagerTestApi(DisplayManager* display_manager) |
| 62 : display_manager_(display_manager) {} | 61 : display_manager_(display_manager) {} |
| 63 | 62 |
| 64 DisplayManagerTestApi::~DisplayManagerTestApi() {} | 63 DisplayManagerTestApi::~DisplayManagerTestApi() {} |
| 65 | 64 |
| 66 void DisplayManagerTestApi::UpdateDisplay(const std::string& display_specs) { | 65 void DisplayManagerTestApi::UpdateDisplay(const std::string& display_specs) { |
| 67 DisplayInfoList display_info_list = | 66 DisplayInfoList display_info_list = |
| 68 CreateDisplayInfoListFromString(display_specs, display_manager_); | 67 CreateDisplayInfoListFromString(display_specs, display_manager_); |
| 69 bool is_host_origin_set = false; | 68 bool is_host_origin_set = false; |
| 70 for (size_t i = 0; i < display_info_list.size(); ++i) { | 69 for (size_t i = 0; i < display_info_list.size(); ++i) { |
| 71 const display::ManagedDisplayInfo& display_info = display_info_list[i]; | 70 const ManagedDisplayInfo& display_info = display_info_list[i]; |
| 72 if (display_info.bounds_in_native().origin() != gfx::Point(0, 0)) { | 71 if (display_info.bounds_in_native().origin() != gfx::Point(0, 0)) { |
| 73 is_host_origin_set = true; | 72 is_host_origin_set = true; |
| 74 break; | 73 break; |
| 75 } | 74 } |
| 76 } | 75 } |
| 77 | 76 |
| 78 // On non-testing environment, when a secondary display is connected, a new | 77 // On non-testing environment, when a secondary display is connected, a new |
| 79 // native (i.e. X) window for the display is always created below the | 78 // native (i.e. X) window for the display is always created below the |
| 80 // previous one for GPU performance reasons. Try to emulate the behavior | 79 // previous one for GPU performance reasons. Try to emulate the behavior |
| 81 // unless host origins are explicitly set. | 80 // unless host origins are explicitly set. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 92 iter->SetBounds(bounds); | 91 iter->SetBounds(bounds); |
| 93 } | 92 } |
| 94 } | 93 } |
| 95 | 94 |
| 96 display_manager_->OnNativeDisplaysChanged(display_info_list); | 95 display_manager_->OnNativeDisplaysChanged(display_info_list); |
| 97 display_manager_->UpdateInternalManagedDisplayModeListForTest(); | 96 display_manager_->UpdateInternalManagedDisplayModeListForTest(); |
| 98 display_manager_->RunPendingTasksForTest(); | 97 display_manager_->RunPendingTasksForTest(); |
| 99 } | 98 } |
| 100 | 99 |
| 101 int64_t DisplayManagerTestApi::SetFirstDisplayAsInternalDisplay() { | 100 int64_t DisplayManagerTestApi::SetFirstDisplayAsInternalDisplay() { |
| 102 const display::Display& internal = display_manager_->active_display_list_[0]; | 101 const Display& internal = display_manager_->active_display_list_[0]; |
| 103 SetInternalDisplayId(internal.id()); | 102 SetInternalDisplayId(internal.id()); |
| 104 return display::Display::InternalDisplayId(); | 103 return Display::InternalDisplayId(); |
| 105 } | 104 } |
| 106 | 105 |
| 107 void DisplayManagerTestApi::SetInternalDisplayId(int64_t id) { | 106 void DisplayManagerTestApi::SetInternalDisplayId(int64_t id) { |
| 108 display::Display::SetInternalDisplayId(id); | 107 Display::SetInternalDisplayId(id); |
| 109 display_manager_->UpdateInternalManagedDisplayModeListForTest(); | 108 display_manager_->UpdateInternalManagedDisplayModeListForTest(); |
| 110 } | 109 } |
| 111 | 110 |
| 112 void DisplayManagerTestApi::DisableChangeDisplayUponHostResize() { | 111 void DisplayManagerTestApi::DisableChangeDisplayUponHostResize() { |
| 113 display_manager_->set_change_display_upon_host_resize(false); | 112 display_manager_->set_change_display_upon_host_resize(false); |
| 114 } | 113 } |
| 115 | 114 |
| 116 void DisplayManagerTestApi::SetAvailableColorProfiles( | 115 void DisplayManagerTestApi::SetAvailableColorProfiles( |
| 117 int64_t display_id, | 116 int64_t display_id, |
| 118 const std::vector<ui::ColorCalibrationProfile>& profiles) { | 117 const std::vector<ui::ColorCalibrationProfile>& profiles) { |
| 119 display_manager_->display_info_[display_id].set_available_color_profiles( | 118 display_manager_->display_info_[display_id].set_available_color_profiles( |
| 120 profiles); | 119 profiles); |
| 121 } | 120 } |
| 122 | 121 |
| 123 const display::ManagedDisplayInfo& | 122 const ManagedDisplayInfo& DisplayManagerTestApi::GetInternalManagedDisplayInfo( |
| 124 DisplayManagerTestApi::GetInternalManagedDisplayInfo(int64_t display_id) { | 123 int64_t display_id) { |
| 125 return display_manager_->display_info_[display_id]; | 124 return display_manager_->display_info_[display_id]; |
| 126 } | 125 } |
| 127 | 126 |
| 128 bool DisplayManagerTestApi::SetDisplayUIScale(int64_t id, float ui_scale) { | 127 bool DisplayManagerTestApi::SetDisplayUIScale(int64_t id, float ui_scale) { |
| 129 if (!display_manager_->IsActiveDisplayId(id) || | 128 if (!display_manager_->IsActiveDisplayId(id) || |
| 130 !display::Display::IsInternalDisplayId(id)) { | 129 !Display::IsInternalDisplayId(id)) { |
| 131 return false; | 130 return false; |
| 132 } | 131 } |
| 133 const display::ManagedDisplayInfo& info = | 132 const ManagedDisplayInfo& info = display_manager_->GetDisplayInfo(id); |
| 134 display_manager_->GetDisplayInfo(id); | |
| 135 | 133 |
| 136 scoped_refptr<display::ManagedDisplayMode> mode = | 134 scoped_refptr<ManagedDisplayMode> mode = |
| 137 GetDisplayModeForUIScale(info, ui_scale); | 135 GetDisplayModeForUIScale(info, ui_scale); |
| 138 if (!mode) | 136 if (!mode) |
| 139 return false; | 137 return false; |
| 140 return display_manager_->SetDisplayMode(id, mode); | 138 return display_manager_->SetDisplayMode(id, mode); |
| 141 } | 139 } |
| 142 | 140 |
| 143 ScopedDisable125DSFForUIScaling::ScopedDisable125DSFForUIScaling() { | 141 ScopedDisable125DSFForUIScaling::ScopedDisable125DSFForUIScaling() { |
| 144 display::ManagedDisplayInfo::SetUse125DSFForUIScalingForTest(false); | 142 ManagedDisplayInfo::SetUse125DSFForUIScalingForTest(false); |
| 145 } | 143 } |
| 146 | 144 |
| 147 ScopedDisable125DSFForUIScaling::~ScopedDisable125DSFForUIScaling() { | 145 ScopedDisable125DSFForUIScaling::~ScopedDisable125DSFForUIScaling() { |
| 148 display::ManagedDisplayInfo::SetUse125DSFForUIScalingForTest(true); | 146 ManagedDisplayInfo::SetUse125DSFForUIScalingForTest(true); |
| 149 } | 147 } |
| 150 | 148 |
| 151 ScopedSetInternalDisplayId::ScopedSetInternalDisplayId( | 149 ScopedSetInternalDisplayId::ScopedSetInternalDisplayId( |
| 152 DisplayManager* display_manager, | 150 DisplayManager* display_manager, |
| 153 int64_t id) { | 151 int64_t id) { |
| 154 DisplayManagerTestApi(display_manager).SetInternalDisplayId(id); | 152 DisplayManagerTestApi(display_manager).SetInternalDisplayId(id); |
| 155 } | 153 } |
| 156 | 154 |
| 157 ScopedSetInternalDisplayId::~ScopedSetInternalDisplayId() { | 155 ScopedSetInternalDisplayId::~ScopedSetInternalDisplayId() { |
| 158 display::Display::SetInternalDisplayId(kInvalidDisplayId); | 156 Display::SetInternalDisplayId(kInvalidDisplayId); |
| 159 } | 157 } |
| 160 | 158 |
| 161 bool SetDisplayResolution(DisplayManager* display_manager, | 159 bool SetDisplayResolution(DisplayManager* display_manager, |
| 162 int64_t display_id, | 160 int64_t display_id, |
| 163 const gfx::Size& resolution) { | 161 const gfx::Size& resolution) { |
| 164 const display::ManagedDisplayInfo& info = | 162 const ManagedDisplayInfo& info = display_manager->GetDisplayInfo(display_id); |
| 165 display_manager->GetDisplayInfo(display_id); | 163 scoped_refptr<ManagedDisplayMode> mode = |
| 166 scoped_refptr<display::ManagedDisplayMode> mode = | |
| 167 GetDisplayModeForResolution(info, resolution); | 164 GetDisplayModeForResolution(info, resolution); |
| 168 if (!mode) | 165 if (!mode) |
| 169 return false; | 166 return false; |
| 170 return display_manager->SetDisplayMode(display_id, mode); | 167 return display_manager->SetDisplayMode(display_id, mode); |
| 171 } | 168 } |
| 172 | 169 |
| 173 std::unique_ptr<display::DisplayLayout> CreateDisplayLayout( | 170 std::unique_ptr<DisplayLayout> CreateDisplayLayout( |
| 174 DisplayManager* display_manager, | 171 DisplayManager* display_manager, |
| 175 display::DisplayPlacement::Position position, | 172 DisplayPlacement::Position position, |
| 176 int offset) { | 173 int offset) { |
| 177 display::DisplayLayoutBuilder builder( | 174 DisplayLayoutBuilder builder(Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 178 display::Screen::GetScreen()->GetPrimaryDisplay().id()); | |
| 179 builder.SetSecondaryPlacement(display_manager->GetSecondaryDisplay().id(), | 175 builder.SetSecondaryPlacement(display_manager->GetSecondaryDisplay().id(), |
| 180 position, offset); | 176 position, offset); |
| 181 return builder.Build(); | 177 return builder.Build(); |
| 182 } | 178 } |
| 183 | 179 |
| 184 display::DisplayIdList CreateDisplayIdList2(int64_t id1, int64_t id2) { | 180 DisplayIdList CreateDisplayIdList2(int64_t id1, int64_t id2) { |
| 185 display::DisplayIdList list; | 181 DisplayIdList list; |
| 186 list.push_back(id1); | 182 list.push_back(id1); |
| 187 list.push_back(id2); | 183 list.push_back(id2); |
| 188 display::SortDisplayIdList(&list); | 184 SortDisplayIdList(&list); |
| 189 return list; | 185 return list; |
| 190 } | 186 } |
| 191 | 187 |
| 192 display::DisplayIdList CreateDisplayIdListN(size_t count, ...) { | 188 DisplayIdList CreateDisplayIdListN(size_t count, ...) { |
| 193 display::DisplayIdList list; | 189 DisplayIdList list; |
| 194 va_list args; | 190 va_list args; |
| 195 va_start(args, count); | 191 va_start(args, count); |
| 196 for (size_t i = 0; i < count; i++) { | 192 for (size_t i = 0; i < count; i++) { |
| 197 int64_t id = va_arg(args, int64_t); | 193 int64_t id = va_arg(args, int64_t); |
| 198 list.push_back(id); | 194 list.push_back(id); |
| 199 } | 195 } |
| 200 display::SortDisplayIdList(&list); | 196 SortDisplayIdList(&list); |
| 201 return list; | 197 return list; |
| 202 } | 198 } |
| 203 | 199 |
| 204 } // namespace test | 200 } // namespace test |
| 205 } // namespace display | 201 } // namespace display |
| OLD | NEW |