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 17 matching lines...) Expand all Loading... |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 // static | 30 // static |
31 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { | 31 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { |
32 return base::MakeUnique<PlatformScreenOzone>(); | 32 return base::MakeUnique<PlatformScreenOzone>(); |
33 } | 33 } |
34 | 34 |
35 PlatformScreenOzone::PlatformScreenOzone() {} | 35 PlatformScreenOzone::PlatformScreenOzone() {} |
36 | 36 |
37 PlatformScreenOzone::~PlatformScreenOzone() { | 37 PlatformScreenOzone::~PlatformScreenOzone() { |
| 38 // We are shutting down and don't want to make anymore display changes. |
| 39 fake_display_controller_ = nullptr; |
38 display_configurator_.RemoveObserver(this); | 40 display_configurator_.RemoveObserver(this); |
39 } | 41 } |
40 | 42 |
41 void PlatformScreenOzone::AddInterfaces(shell::InterfaceRegistry* registry) { | 43 void PlatformScreenOzone::AddInterfaces(shell::InterfaceRegistry* registry) { |
42 registry->AddInterface<mojom::DisplayController>(this); | 44 registry->AddInterface<mojom::DisplayController>(this); |
43 } | 45 } |
44 | 46 |
45 void PlatformScreenOzone::Init(PlatformScreenDelegate* delegate) { | 47 void PlatformScreenOzone::Init(PlatformScreenDelegate* delegate) { |
46 DCHECK(delegate); | 48 DCHECK(delegate); |
47 delegate_ = delegate; | 49 delegate_ = delegate; |
48 | 50 |
| 51 std::unique_ptr<ui::NativeDisplayDelegate> native_display_delegate = |
| 52 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); |
| 53 |
| 54 if (!base::SysInfo::IsRunningOnChromeOS()) { |
| 55 fake_display_controller_ = |
| 56 native_display_delegate->GetFakeDisplayController(); |
| 57 } |
| 58 |
49 // We want display configuration to happen even off device to keep the control | 59 // We want display configuration to happen even off device to keep the control |
50 // flow similar. | 60 // flow similar. |
51 display_configurator_.set_configure_display(true); | 61 display_configurator_.set_configure_display(true); |
52 display_configurator_.AddObserver(this); | 62 display_configurator_.AddObserver(this); |
53 display_configurator_.Init( | 63 display_configurator_.Init(std::move(native_display_delegate), false); |
54 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(), false); | 64 display_configurator_.ForceInitialConfigure(kChromeOsBootColor); |
55 | |
56 if (base::SysInfo::IsRunningOnChromeOS()) { | |
57 display_configurator_.ForceInitialConfigure(kChromeOsBootColor); | |
58 } else { | |
59 if (base::CommandLine::ForCurrentProcess()->HasSwitch("multi-display")) { | |
60 // This really doesn't work properly. Use at your own risk. | |
61 display_configurator_.AddVirtualDisplay(gfx::Size(800, 800)); | |
62 display_configurator_.AddVirtualDisplay(gfx::Size(800, 800)); | |
63 } else { | |
64 display_configurator_.AddVirtualDisplay(gfx::Size(1024, 768)); | |
65 } | |
66 } | |
67 } | 65 } |
68 | 66 |
69 int64_t PlatformScreenOzone::GetPrimaryDisplayId() const { | 67 int64_t PlatformScreenOzone::GetPrimaryDisplayId() const { |
70 return primary_display_id_; | 68 return primary_display_id_; |
71 } | 69 } |
72 | 70 |
73 void PlatformScreenOzone::ToggleVirtualDisplay() { | 71 void PlatformScreenOzone::ToggleVirtualDisplay() { |
74 if (base::SysInfo::IsRunningOnChromeOS()) | 72 if (!fake_display_controller_ || wait_for_display_config_update_) |
75 return; | 73 return; |
76 | 74 |
77 // TODO(kylechar): Convert to use VirtualDisplayDelegate once landed. | |
78 if (cached_displays_.size() == 1) { | 75 if (cached_displays_.size() == 1) { |
79 display_configurator_.AddVirtualDisplay(cached_displays_[0].bounds.size()); | 76 const gfx::Size& display_size = cached_displays_[0].bounds.size(); |
| 77 wait_for_display_config_update_ = |
| 78 fake_display_controller_->AddDisplay(display_size) != |
| 79 Display::kInvalidDisplayID; |
80 } else if (cached_displays_.size() > 1) { | 80 } else if (cached_displays_.size() > 1) { |
81 display_configurator_.RemoveVirtualDisplay(cached_displays_.back().id); | 81 wait_for_display_config_update_ = |
| 82 fake_display_controller_->RemoveDisplay(cached_displays_.back().id); |
82 } else { | 83 } else { |
83 NOTREACHED(); | 84 NOTREACHED(); |
84 } | 85 } |
85 } | 86 } |
86 | 87 |
87 void PlatformScreenOzone::ProcessRemovedDisplays( | 88 void PlatformScreenOzone::ProcessRemovedDisplays( |
88 const ui::DisplayConfigurator::DisplayStateList& snapshots) { | 89 const ui::DisplayConfigurator::DisplayStateList& snapshots) { |
89 std::vector<int64_t> current_ids; | 90 std::vector<int64_t> current_ids; |
90 for (ui::DisplaySnapshot* snapshot : snapshots) | 91 for (ui::DisplaySnapshot* snapshot : snapshots) |
91 current_ids.push_back(snapshot->display_id()); | 92 current_ids.push_back(snapshot->display_id()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 return display_info.id == display_id; | 187 return display_info.id == display_id; |
187 }); | 188 }); |
188 } | 189 } |
189 | 190 |
190 void PlatformScreenOzone::OnDisplayModeChanged( | 191 void PlatformScreenOzone::OnDisplayModeChanged( |
191 const ui::DisplayConfigurator::DisplayStateList& displays) { | 192 const ui::DisplayConfigurator::DisplayStateList& displays) { |
192 ProcessRemovedDisplays(displays); | 193 ProcessRemovedDisplays(displays); |
193 ProcessModifiedDisplays(displays); | 194 ProcessModifiedDisplays(displays); |
194 UpdateCachedDisplays(); | 195 UpdateCachedDisplays(); |
195 AddNewDisplays(displays); | 196 AddNewDisplays(displays); |
| 197 wait_for_display_config_update_ = false; |
196 } | 198 } |
197 | 199 |
198 void PlatformScreenOzone::OnDisplayModeChangeFailed( | 200 void PlatformScreenOzone::OnDisplayModeChangeFailed( |
199 const ui::DisplayConfigurator::DisplayStateList& displays, | 201 const ui::DisplayConfigurator::DisplayStateList& displays, |
200 ui::MultipleDisplayState failed_new_state) { | 202 ui::MultipleDisplayState failed_new_state) { |
201 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; | 203 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; |
| 204 wait_for_display_config_update_ = false; |
202 } | 205 } |
203 | 206 |
204 void PlatformScreenOzone::Create(const shell::Identity& remote_identity, | 207 void PlatformScreenOzone::Create(const shell::Identity& remote_identity, |
205 mojom::DisplayControllerRequest request) { | 208 mojom::DisplayControllerRequest request) { |
206 bindings_.AddBinding(this, std::move(request)); | 209 bindings_.AddBinding(this, std::move(request)); |
207 } | 210 } |
208 | 211 |
209 } // namespace display | 212 } // namespace display |
OLD | NEW |