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