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 | 9 |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
11 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "services/shell/public/cpp/interface_registry.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
14 #include "ui/display/types/display_constants.h" | 16 #include "ui/display/types/display_constants.h" |
15 #include "ui/display/types/display_snapshot.h" | 17 #include "ui/display/types/display_snapshot.h" |
16 #include "ui/display/types/native_display_delegate.h" | 18 #include "ui/display/types/native_display_delegate.h" |
17 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
18 #include "ui/ozone/public/ozone_platform.h" | 20 #include "ui/ozone/public/ozone_platform.h" |
19 | 21 |
20 namespace display { | 22 namespace display { |
21 namespace { | 23 namespace { |
22 | 24 |
23 // Needed for DisplayConfigurator::ForceInitialConfigure. | 25 // Needed for DisplayConfigurator::ForceInitialConfigure. |
24 const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe); | 26 const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe); |
25 | 27 |
26 } // namespace | 28 } // namespace |
27 | 29 |
28 // static | 30 // static |
29 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { | 31 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { |
30 return base::MakeUnique<PlatformScreenOzone>(); | 32 return base::MakeUnique<PlatformScreenOzone>(); |
31 } | 33 } |
32 | 34 |
33 PlatformScreenOzone::PlatformScreenOzone() {} | 35 PlatformScreenOzone::PlatformScreenOzone() {} |
34 | 36 |
35 PlatformScreenOzone::~PlatformScreenOzone() { | 37 PlatformScreenOzone::~PlatformScreenOzone() { |
36 display_configurator_.RemoveObserver(this); | 38 display_configurator_.RemoveObserver(this); |
37 } | 39 } |
38 | 40 |
| 41 void PlatformScreenOzone::AddInterfaces(shell::InterfaceRegistry* registry) { |
| 42 registry->AddInterface<mojom::DisplayController>(this); |
| 43 } |
| 44 |
39 void PlatformScreenOzone::Init(PlatformScreenDelegate* delegate) { | 45 void PlatformScreenOzone::Init(PlatformScreenDelegate* delegate) { |
40 DCHECK(delegate); | 46 DCHECK(delegate); |
41 delegate_ = delegate; | 47 delegate_ = delegate; |
42 | 48 |
43 // We want display configuration to happen even off device to keep the control | 49 // We want display configuration to happen even off device to keep the control |
44 // flow similar. | 50 // flow similar. |
45 display_configurator_.set_configure_display(true); | 51 display_configurator_.set_configure_display(true); |
46 display_configurator_.AddObserver(this); | 52 display_configurator_.AddObserver(this); |
47 display_configurator_.Init( | 53 display_configurator_.Init( |
48 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(), false); | 54 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(), false); |
49 | 55 |
50 if (base::SysInfo::IsRunningOnChromeOS()) { | 56 if (base::SysInfo::IsRunningOnChromeOS()) { |
51 display_configurator_.ForceInitialConfigure(kChromeOsBootColor); | 57 display_configurator_.ForceInitialConfigure(kChromeOsBootColor); |
52 } else { | 58 } else { |
53 if (base::CommandLine::ForCurrentProcess()->HasSwitch("multi-display")) { | 59 if (base::CommandLine::ForCurrentProcess()->HasSwitch("multi-display")) { |
54 // This really doesn't work properly. Use at your own risk. | 60 // This really doesn't work properly. Use at your own risk. |
55 display_configurator_.AddVirtualDisplay(gfx::Size(800, 800)); | 61 display_configurator_.AddVirtualDisplay(gfx::Size(800, 800)); |
56 display_configurator_.AddVirtualDisplay(gfx::Size(800, 800)); | 62 display_configurator_.AddVirtualDisplay(gfx::Size(800, 800)); |
57 } else { | 63 } else { |
58 display_configurator_.AddVirtualDisplay(gfx::Size(1024, 768)); | 64 display_configurator_.AddVirtualDisplay(gfx::Size(1024, 768)); |
59 } | 65 } |
60 } | 66 } |
61 } | 67 } |
62 | 68 |
63 int64_t PlatformScreenOzone::GetPrimaryDisplayId() const { | 69 int64_t PlatformScreenOzone::GetPrimaryDisplayId() const { |
64 return primary_display_id_; | 70 return primary_display_id_; |
65 } | 71 } |
66 | 72 |
67 void PlatformScreenOzone::ToggleVirtualDisplay( | 73 void PlatformScreenOzone::ToggleVirtualDisplay() { |
68 const ToggleVirtualDisplayCallback& callback) { | 74 if (base::SysInfo::IsRunningOnChromeOS()) |
69 if (base::SysInfo::IsRunningOnChromeOS()) { | |
70 callback.Run(false); | |
71 return; | 75 return; |
72 } | |
73 | 76 |
| 77 // TODO(kylechar): Convert to use VirtualDisplayDelegate once landed. |
74 if (cached_displays_.size() == 1) { | 78 if (cached_displays_.size() == 1) { |
75 display_configurator_.AddVirtualDisplay(cached_displays_[0].bounds.size()); | 79 display_configurator_.AddVirtualDisplay(cached_displays_[0].bounds.size()); |
76 callback.Run(true); | |
77 } else if (cached_displays_.size() > 1) { | 80 } else if (cached_displays_.size() > 1) { |
78 callback.Run( | 81 display_configurator_.RemoveVirtualDisplay(cached_displays_.back().id); |
79 display_configurator_.RemoveVirtualDisplay(cached_displays_.back().id)); | |
80 } else { | 82 } else { |
81 NOTREACHED(); | 83 NOTREACHED(); |
82 callback.Run(false); | |
83 } | 84 } |
84 } | 85 } |
85 | 86 |
86 void PlatformScreenOzone::ProcessRemovedDisplays( | 87 void PlatformScreenOzone::ProcessRemovedDisplays( |
87 const ui::DisplayConfigurator::DisplayStateList& snapshots) { | 88 const ui::DisplayConfigurator::DisplayStateList& snapshots) { |
88 std::vector<int64_t> current_ids; | 89 std::vector<int64_t> current_ids; |
89 for (ui::DisplaySnapshot* snapshot : snapshots) | 90 for (ui::DisplaySnapshot* snapshot : snapshots) |
90 current_ids.push_back(snapshot->display_id()); | 91 current_ids.push_back(snapshot->display_id()); |
91 | 92 |
92 // Find cached displays with no matching snapshot and mark as removed. | 93 // Find cached displays with no matching snapshot and mark as removed. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 UpdateCachedDisplays(); | 194 UpdateCachedDisplays(); |
194 AddNewDisplays(displays); | 195 AddNewDisplays(displays); |
195 } | 196 } |
196 | 197 |
197 void PlatformScreenOzone::OnDisplayModeChangeFailed( | 198 void PlatformScreenOzone::OnDisplayModeChangeFailed( |
198 const ui::DisplayConfigurator::DisplayStateList& displays, | 199 const ui::DisplayConfigurator::DisplayStateList& displays, |
199 ui::MultipleDisplayState failed_new_state) { | 200 ui::MultipleDisplayState failed_new_state) { |
200 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; | 201 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; |
201 } | 202 } |
202 | 203 |
| 204 void PlatformScreenOzone::Create(const shell::Identity& remote_identity, |
| 205 mojom::DisplayControllerRequest request) { |
| 206 bindings_.AddBinding(this, std::move(request)); |
| 207 } |
| 208 |
203 } // namespace display | 209 } // namespace display |
OLD | NEW |