| 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 "services/ui/display/platform_screen_ozone.h" | 5 #include "services/ui/display/platform_screen_ozone.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 PlatformScreenOzone::~PlatformScreenOzone() { | 59 PlatformScreenOzone::~PlatformScreenOzone() { |
| 60 // We are shutting down and don't want to make anymore display changes. | 60 // We are shutting down and don't want to make anymore display changes. |
| 61 fake_display_controller_ = nullptr; | 61 fake_display_controller_ = nullptr; |
| 62 display_configurator_.RemoveObserver(this); | 62 display_configurator_.RemoveObserver(this); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void PlatformScreenOzone::AddInterfaces( | 65 void PlatformScreenOzone::AddInterfaces( |
| 66 service_manager::InterfaceRegistry* registry) { | 66 service_manager::InterfaceRegistry* registry) { |
| 67 registry->AddInterface<mojom::DisplayController>(this); | 67 registry->AddInterface<mojom::DisplayController>(this); |
| 68 registry->AddInterface<mojom::TestDisplayController>(this); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void PlatformScreenOzone::Init(PlatformScreenDelegate* delegate) { | 71 void PlatformScreenOzone::Init(PlatformScreenDelegate* delegate) { |
| 71 DCHECK(delegate); | 72 DCHECK(delegate); |
| 72 delegate_ = delegate; | 73 delegate_ = delegate; |
| 73 | 74 |
| 74 std::unique_ptr<ui::NativeDisplayDelegate> native_display_delegate = | 75 std::unique_ptr<ui::NativeDisplayDelegate> native_display_delegate = |
| 75 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); | 76 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); |
| 76 | 77 |
| 78 // The FakeDisplayController gives us a way to make the NativeDisplayDelegate |
| 79 // pretend something display related has happened. |
| 77 if (!base::SysInfo::IsRunningOnChromeOS()) { | 80 if (!base::SysInfo::IsRunningOnChromeOS()) { |
| 78 fake_display_controller_ = | 81 fake_display_controller_ = |
| 79 native_display_delegate->GetFakeDisplayController(); | 82 native_display_delegate->GetFakeDisplayController(); |
| 80 } | 83 } |
| 81 | 84 |
| 82 // We want display configuration to happen even off device to keep the control | 85 // We want display configuration to happen even off device to keep the control |
| 83 // flow similar. | 86 // flow similar. |
| 84 display_configurator_.set_configure_display(true); | 87 display_configurator_.set_configure_display(true); |
| 85 display_configurator_.AddObserver(this); | 88 display_configurator_.AddObserver(this); |
| 86 display_configurator_.Init(std::move(native_display_delegate), false); | 89 display_configurator_.Init(std::move(native_display_delegate), false); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 97 // that the display configuration has changed and the display will be gone. | 100 // that the display configuration has changed and the display will be gone. |
| 98 wait_for_display_config_update_ = | 101 wait_for_display_config_update_ = |
| 99 fake_display_controller_->RemoveDisplay(iter->id); | 102 fake_display_controller_->RemoveDisplay(iter->id); |
| 100 } | 103 } |
| 101 } | 104 } |
| 102 | 105 |
| 103 int64_t PlatformScreenOzone::GetPrimaryDisplayId() const { | 106 int64_t PlatformScreenOzone::GetPrimaryDisplayId() const { |
| 104 return primary_display_id_; | 107 return primary_display_id_; |
| 105 } | 108 } |
| 106 | 109 |
| 107 void PlatformScreenOzone::ToggleVirtualDisplay() { | 110 void PlatformScreenOzone::ToggleAddRemoveDisplay() { |
| 108 if (!fake_display_controller_ || wait_for_display_config_update_) | 111 if (!fake_display_controller_ || wait_for_display_config_update_) |
| 109 return; | 112 return; |
| 110 | 113 |
| 111 if (cached_displays_.size() == 1) { | 114 if (cached_displays_.size() == 1) { |
| 112 const gfx::Size& pixel_size = cached_displays_[0].pixel_size; | 115 const gfx::Size& pixel_size = cached_displays_[0].pixel_size; |
| 113 wait_for_display_config_update_ = | 116 wait_for_display_config_update_ = |
| 114 fake_display_controller_->AddDisplay(pixel_size) != | 117 fake_display_controller_->AddDisplay(pixel_size) != |
| 115 Display::kInvalidDisplayID; | 118 Display::kInvalidDisplayID; |
| 116 } else if (cached_displays_.size() > 1) { | 119 } else if (cached_displays_.size() > 1) { |
| 117 wait_for_display_config_update_ = | 120 wait_for_display_config_update_ = |
| 118 fake_display_controller_->RemoveDisplay(cached_displays_.back().id); | 121 fake_display_controller_->RemoveDisplay(cached_displays_.back().id); |
| 119 } else { | 122 } else { |
| 120 NOTREACHED(); | 123 NOTREACHED(); |
| 121 } | 124 } |
| 122 } | 125 } |
| 123 | 126 |
| 127 void PlatformScreenOzone::SwapPrimaryDisplay() { |
| 128 const size_t num_displays = cached_displays_.size(); |
| 129 if (num_displays <= 1) |
| 130 return; |
| 131 |
| 132 // Find index of current primary display. |
| 133 size_t primary_display_index = 0; |
| 134 for (size_t i = 0; i < num_displays; i++) { |
| 135 if (cached_displays_[i].id == primary_display_id_) { |
| 136 primary_display_index = i; |
| 137 break; |
| 138 } |
| 139 } |
| 140 |
| 141 // Set next display index as primary, or loop back to first display if last. |
| 142 if (primary_display_index + 1 == num_displays) { |
| 143 primary_display_id_ = cached_displays_[0].id; |
| 144 } else { |
| 145 primary_display_id_ = cached_displays_[primary_display_index + 1].id; |
| 146 } |
| 147 |
| 148 // TODO(kylechar): Update ws::DisplayManager. |
| 149 } |
| 150 |
| 151 void PlatformScreenOzone::SetDisplayWorkArea(int64_t display_id, |
| 152 const gfx::Size& size, |
| 153 const gfx::Insets& insets) { |
| 154 CachedDisplayIterator iter = GetCachedDisplayIterator(display_id); |
| 155 if (iter == cached_displays_.end()) { |
| 156 NOTREACHED() << display_id; |
| 157 return; |
| 158 } |
| 159 |
| 160 DisplayInfo& display_info = *iter; |
| 161 if (display_info.bounds.size() == size) { |
| 162 // TODO(kylechar): Change workarea and update ws::DisplayManager. |
| 163 } |
| 164 } |
| 165 |
| 124 void PlatformScreenOzone::ProcessRemovedDisplays( | 166 void PlatformScreenOzone::ProcessRemovedDisplays( |
| 125 const ui::DisplayConfigurator::DisplayStateList& snapshots) { | 167 const ui::DisplayConfigurator::DisplayStateList& snapshots) { |
| 126 std::vector<int64_t> current_ids; | 168 std::vector<int64_t> current_ids; |
| 127 for (ui::DisplaySnapshot* snapshot : snapshots) | 169 for (ui::DisplaySnapshot* snapshot : snapshots) |
| 128 current_ids.push_back(snapshot->display_id()); | 170 current_ids.push_back(snapshot->display_id()); |
| 129 | 171 |
| 130 // Find cached displays with no matching snapshot and mark as removed. | 172 // Find cached displays with no matching snapshot and mark as removed. |
| 131 for (DisplayInfo& display : cached_displays_) { | 173 for (DisplayInfo& display : cached_displays_) { |
| 132 if (std::find(current_ids.begin(), current_ids.end(), display.id) == | 174 if (std::find(current_ids.begin(), current_ids.end(), display.id) == |
| 133 current_ids.end()) { | 175 current_ids.end()) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 void PlatformScreenOzone::OnDisplayModeChangeFailed( | 301 void PlatformScreenOzone::OnDisplayModeChangeFailed( |
| 260 const ui::DisplayConfigurator::DisplayStateList& displays, | 302 const ui::DisplayConfigurator::DisplayStateList& displays, |
| 261 ui::MultipleDisplayState failed_new_state) { | 303 ui::MultipleDisplayState failed_new_state) { |
| 262 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; | 304 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; |
| 263 wait_for_display_config_update_ = false; | 305 wait_for_display_config_update_ = false; |
| 264 } | 306 } |
| 265 | 307 |
| 266 void PlatformScreenOzone::Create( | 308 void PlatformScreenOzone::Create( |
| 267 const service_manager::Identity& remote_identity, | 309 const service_manager::Identity& remote_identity, |
| 268 mojom::DisplayControllerRequest request) { | 310 mojom::DisplayControllerRequest request) { |
| 269 bindings_.AddBinding(this, std::move(request)); | 311 controller_bindings_.AddBinding(this, std::move(request)); |
| 312 } |
| 313 |
| 314 void PlatformScreenOzone::Create( |
| 315 const service_manager::Identity& remote_identity, |
| 316 mojom::TestDisplayControllerRequest request) { |
| 317 test_bindings_.AddBinding(this, std::move(request)); |
| 270 } | 318 } |
| 271 | 319 |
| 272 } // namespace display | 320 } // namespace display |
| OLD | NEW |