| 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/screen_manager_ozone_internal.h" | 5 #include "services/ui/display/screen_manager_ozone_internal.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 placement->Swap(); | 53 placement->Swap(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 // static | 58 // static |
| 59 std::unique_ptr<ScreenManager> ScreenManager::Create() { | 59 std::unique_ptr<ScreenManager> ScreenManager::Create() { |
| 60 return base::MakeUnique<ScreenManagerOzoneInternal>(); | 60 return base::MakeUnique<ScreenManagerOzoneInternal>(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 ScreenManagerOzoneInternal::ScreenManagerOzoneInternal() {} | 63 ScreenManagerOzoneInternal::ScreenManagerOzoneInternal() |
| 64 : screen_owned_(base::MakeUnique<ScreenBase>()), |
| 65 screen_(screen_owned_.get()) { |
| 66 Screen::SetScreenInstance(screen_owned_.get()); |
| 67 } |
| 64 | 68 |
| 65 ScreenManagerOzoneInternal::~ScreenManagerOzoneInternal() { | 69 ScreenManagerOzoneInternal::~ScreenManagerOzoneInternal() { |
| 66 // We are shutting down and don't want to make anymore display changes. | 70 // We are shutting down and don't want to make anymore display changes. |
| 67 fake_display_controller_ = nullptr; | 71 fake_display_controller_ = nullptr; |
| 68 | 72 |
| 73 // At this point |display_manager_| likely owns the Screen instance. It never |
| 74 // cleans up the instance pointer though, which could cause problems in tests. |
| 75 Screen::SetScreenInstance(nullptr); |
| 76 |
| 69 touch_transform_controller_.reset(); | 77 touch_transform_controller_.reset(); |
| 70 | 78 |
| 71 if (display_manager_) | 79 if (display_manager_) |
| 72 display_manager_->RemoveObserver(this); | 80 display_manager_->RemoveObserver(this); |
| 73 | 81 |
| 74 if (display_change_observer_) { | 82 if (display_change_observer_) { |
| 75 display_configurator_.RemoveObserver(display_change_observer_.get()); | 83 display_configurator_.RemoveObserver(display_change_observer_.get()); |
| 76 display_change_observer_.reset(); | 84 display_change_observer_.reset(); |
| 77 } | 85 } |
| 78 | 86 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); | 160 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); |
| 153 } | 161 } |
| 154 | 162 |
| 155 // The FakeDisplayController gives us a way to make the NativeDisplayDelegate | 163 // The FakeDisplayController gives us a way to make the NativeDisplayDelegate |
| 156 // pretend something display related has happened. | 164 // pretend something display related has happened. |
| 157 if (!chromeos::IsRunningAsSystemCompositor()) { | 165 if (!chromeos::IsRunningAsSystemCompositor()) { |
| 158 fake_display_controller_ = | 166 fake_display_controller_ = |
| 159 native_display_delegate_->GetFakeDisplayController(); | 167 native_display_delegate_->GetFakeDisplayController(); |
| 160 } | 168 } |
| 161 | 169 |
| 162 // Create a new Screen instance. | |
| 163 std::unique_ptr<ScreenBase> screen = base::MakeUnique<ScreenBase>(); | |
| 164 Screen::SetScreenInstance(screen.get()); | |
| 165 screen_ = screen.get(); | |
| 166 | |
| 167 // Configure display manager. ScreenManager acts as an observer to find out | 170 // Configure display manager. ScreenManager acts as an observer to find out |
| 168 // display changes and as a delegate to find out when changes start/stop. | 171 // display changes and as a delegate to find out when changes start/stop. |
| 169 display_manager_ = base::MakeUnique<DisplayManager>(std::move(screen)); | 172 display_manager_ = base::MakeUnique<DisplayManager>(std::move(screen_owned_)); |
| 170 display_manager_->set_configure_displays(true); | 173 display_manager_->set_configure_displays(true); |
| 171 display_manager_->AddObserver(this); | 174 display_manager_->AddObserver(this); |
| 172 display_manager_->set_delegate(this); | 175 display_manager_->set_delegate(this); |
| 173 | 176 |
| 174 // DisplayChangeObserver observes DisplayConfigurator and sends updates to | 177 // DisplayChangeObserver observes DisplayConfigurator and sends updates to |
| 175 // DisplayManager. | 178 // DisplayManager. |
| 176 display_change_observer_ = base::MakeUnique<DisplayChangeObserver>( | 179 display_change_observer_ = base::MakeUnique<DisplayChangeObserver>( |
| 177 &display_configurator_, display_manager_.get()); | 180 &display_configurator_, display_manager_.get()); |
| 178 | 181 |
| 179 // We want display configuration to happen even off device to keep the control | 182 // We want display configuration to happen even off device to keep the control |
| (...skipping 13 matching lines...) Expand all Loading... |
| 193 | 196 |
| 194 void ScreenManagerOzoneInternal::RequestCloseDisplay(int64_t display_id) { | 197 void ScreenManagerOzoneInternal::RequestCloseDisplay(int64_t display_id) { |
| 195 if (!fake_display_controller_) | 198 if (!fake_display_controller_) |
| 196 return; | 199 return; |
| 197 | 200 |
| 198 // Tell the NDD to remove the display. ScreenManager will get an update | 201 // Tell the NDD to remove the display. ScreenManager will get an update |
| 199 // that the display configuration has changed and the display will be gone. | 202 // that the display configuration has changed and the display will be gone. |
| 200 fake_display_controller_->RemoveDisplay(display_id); | 203 fake_display_controller_->RemoveDisplay(display_id); |
| 201 } | 204 } |
| 202 | 205 |
| 203 int64_t ScreenManagerOzoneInternal::GetPrimaryDisplayId() const { | |
| 204 return primary_display_id_; | |
| 205 } | |
| 206 | |
| 207 void ScreenManagerOzoneInternal::ToggleAddRemoveDisplay() { | 206 void ScreenManagerOzoneInternal::ToggleAddRemoveDisplay() { |
| 208 if (!fake_display_controller_) | 207 if (!fake_display_controller_) |
| 209 return; | 208 return; |
| 210 DVLOG(1) << "ToggleAddRemoveDisplay"; | 209 DVLOG(1) << "ToggleAddRemoveDisplay"; |
| 211 | 210 |
| 212 int num_displays = display_manager_->GetNumDisplays(); | 211 int num_displays = display_manager_->GetNumDisplays(); |
| 213 if (num_displays == 1) { | 212 if (num_displays == 1) { |
| 214 const gfx::Size& pixel_size = | 213 const gfx::Size& pixel_size = |
| 215 display_manager_->GetDisplayInfo(display_manager_->GetDisplayAt(0).id()) | 214 display_manager_->GetDisplayInfo(display_manager_->GetDisplayAt(0).id()) |
| 216 .bounds_in_native() | 215 .bounds_in_native() |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 std::move(request)); | 399 std::move(request)); |
| 401 } | 400 } |
| 402 | 401 |
| 403 void ScreenManagerOzoneInternal::Create( | 402 void ScreenManagerOzoneInternal::Create( |
| 404 const service_manager::Identity& remote_identity, | 403 const service_manager::Identity& remote_identity, |
| 405 mojom::TestDisplayControllerRequest request) { | 404 mojom::TestDisplayControllerRequest request) { |
| 406 test_bindings_.AddBinding(this, std::move(request)); | 405 test_bindings_.AddBinding(this, std::move(request)); |
| 407 } | 406 } |
| 408 | 407 |
| 409 } // namespace display | 408 } // namespace display |
| OLD | NEW |