OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/mus/ws/platform_screen_impl_ozone.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/location.h" | |
9 #include "base/memory/ptr_util.h" | |
10 #include "base/sys_info.h" | |
11 #include "base/threading/thread_task_runner_handle.h" | |
12 #include "ui/display/types/display_snapshot.h" | |
13 #include "ui/display/types/native_display_delegate.h" | |
14 #include "ui/ozone/public/ozone_platform.h" | |
15 | |
16 namespace mus { | |
17 | |
18 namespace ws { | |
19 namespace { | |
20 | |
21 // TODO(rjkroege): Remove this code once ozone oxygen has the same | |
22 // display creation semantics as ozone drm. | |
23 // Some ozone platforms do not configure physical displays and so do not | |
24 // callback into this class via the implementation of NativeDisplayObserver. | |
25 // FixedSizeScreenConfiguration() short-circuits the implementation of display | |
26 // configuration in this case by calling the |callback| provided to | |
27 // ConfigurePhysicalDisplay() with a hard-coded |id| and |bounds|. | |
28 void FixedSizeScreenConfiguration( | |
29 const PlatformScreen::ConfiguredDisplayCallback& callback) { | |
30 callback.Run(1, gfx::Rect(1024, 768)); | |
31 } | |
32 | |
33 void GetDisplaysFinished(const std::vector<ui::DisplaySnapshot*>& displays) { | |
34 // We don't really care about list of displays, we just want the snapshots | |
35 // held by DrmDisplayManager to be updated. This only only happens when we | |
36 // call NativeDisplayDelegate::GetDisplays(). Although, this would be a good | |
37 // place to have PlatformScreen cache the snapshots if need be. | |
38 } | |
39 | |
40 } // namespace | |
41 | |
42 // static | |
43 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { | |
44 return base::WrapUnique(new PlatformScreenImplOzone); | |
45 } | |
46 | |
47 PlatformScreenImplOzone::PlatformScreenImplOzone() : weak_ptr_factory_(this) {} | |
48 | |
49 PlatformScreenImplOzone::~PlatformScreenImplOzone() {} | |
50 | |
51 void PlatformScreenImplOzone::Init() { | |
52 native_display_delegate_ = | |
53 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); | |
54 native_display_delegate_->AddObserver(this); | |
55 native_display_delegate_->Initialize(); | |
56 } | |
57 | |
58 void PlatformScreenImplOzone::ConfigurePhysicalDisplay( | |
59 const PlatformScreen::ConfiguredDisplayCallback& callback) { | |
60 #if defined(OS_CHROMEOS) | |
61 if (base::SysInfo::IsRunningOnChromeOS()) { | |
62 // Kick off the configuration of the physical displays comprising the | |
63 // |PlatformScreenImplOzone| | |
64 | |
65 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" | |
66 "OnConfigurationChanged requires a " | |
67 "native_display_delegate_ to work."; | |
68 | |
69 native_display_delegate_->GetDisplays( | |
70 base::Bind(&PlatformScreenImplOzone::OnDisplaysAquired, | |
71 weak_ptr_factory_.GetWeakPtr(), callback)); | |
72 | |
73 return; | |
74 } | |
75 #endif // defined(OS_CHROMEOS) | |
76 // PostTask()ed to maximize control flow similarity with the ChromeOS case. | |
77 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
78 FROM_HERE, base::Bind(&FixedSizeScreenConfiguration, callback)); | |
79 } | |
80 | |
81 void PlatformScreenImplOzone::OnConfigurationChanged() {} | |
82 | |
83 // The display subsystem calls |OnDisplaysAquired| to deliver |displays| | |
84 // describing the attached displays. | |
85 void PlatformScreenImplOzone::OnDisplaysAquired( | |
86 const ConfiguredDisplayCallback& callback, | |
87 const std::vector<ui::DisplaySnapshot*>& displays) { | |
88 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" | |
89 "OnConfigurationChanged requires a " | |
90 "native_display_delegate_ to work."; | |
91 CHECK(displays.size() == 1) << "Mus only supports one 1 display\n"; | |
92 gfx::Point origin; | |
93 for (auto display : displays) { | |
94 if (!display->native_mode()) { | |
95 LOG(ERROR) << "Display " << display->display_id() | |
96 << " doesn't have a native mode"; | |
97 continue; | |
98 } | |
99 // Setup each native display. This places a task on the DRM thread's | |
100 // runqueue that configures the window size correctly before the call to | |
101 // Configure. | |
102 native_display_delegate_->Configure( | |
103 *display, display->native_mode(), origin, | |
104 base::Bind(&PlatformScreenImplOzone::OnDisplayConfigured, | |
105 weak_ptr_factory_.GetWeakPtr(), callback, | |
106 display->display_id(), | |
107 gfx::Rect(origin, display->native_mode()->size()))); | |
108 origin.Offset(display->native_mode()->size().width(), 0); | |
109 } | |
110 } | |
111 | |
112 void PlatformScreenImplOzone::OnDisplayConfigured( | |
113 const ConfiguredDisplayCallback& callback, | |
114 int64_t id, | |
115 const gfx::Rect& bounds, | |
116 bool success) { | |
117 if (success) { | |
118 native_display_delegate_->GetDisplays(base::Bind(&GetDisplaysFinished)); | |
119 callback.Run(id, bounds); | |
120 } else { | |
121 LOG(FATAL) << "Failed to configure display at " << bounds.ToString(); | |
122 } | |
123 } | |
124 | |
125 } // namespace ws | |
126 } // namespace mus | |
OLD | NEW |