OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 "ui/ozone/platform/drm/gpu/drm_thread.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/thread_task_runner_handle.h" | |
9 #include "ui/ozone/platform/drm/gpu/drm_buffer.h" | |
10 #include "ui/ozone/platform/drm/gpu/drm_device_generator.h" | |
11 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h" | |
12 #include "ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h" | |
13 #include "ui/ozone/platform/drm/gpu/drm_window.h" | |
14 #include "ui/ozone/platform/drm/gpu/drm_window_proxy.h" | |
15 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" | |
16 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | |
17 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" | |
18 #include "ui/ozone/platform/drm/gpu/proxy_helpers.h" | |
19 #include "ui/ozone/platform/drm/gpu/screen_manager.h" | |
20 #include "ui/ozone/public/ozone_switches.h" | |
21 | |
22 namespace ui { | |
23 | |
24 namespace { | |
25 | |
26 class GbmBufferGenerator : public ScanoutBufferGenerator { | |
27 public: | |
28 GbmBufferGenerator() {} | |
29 ~GbmBufferGenerator() override {} | |
30 | |
31 // ScanoutBufferGenerator: | |
32 scoped_refptr<ScanoutBuffer> Create(const scoped_refptr<DrmDevice>& drm, | |
33 gfx::BufferFormat format, | |
34 const gfx::Size& size) override { | |
35 scoped_refptr<GbmDevice> gbm(static_cast<GbmDevice*>(drm.get())); | |
36 return GbmBuffer::CreateBuffer(gbm, format, size, | |
37 gfx::BufferUsage::SCANOUT); | |
38 } | |
39 | |
40 protected: | |
41 DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator); | |
42 }; | |
43 | |
44 class GbmDeviceGenerator : public DrmDeviceGenerator { | |
45 public: | |
46 GbmDeviceGenerator(bool use_atomic) : use_atomic_(use_atomic) {} | |
47 ~GbmDeviceGenerator() override {} | |
48 | |
49 // DrmDeviceGenerator: | |
50 scoped_refptr<DrmDevice> CreateDevice(const base::FilePath& path, | |
51 base::File file) override { | |
52 scoped_refptr<DrmDevice> drm = new GbmDevice(path, file.Pass()); | |
53 if (drm->Initialize(use_atomic_)) | |
54 return drm; | |
55 | |
56 return nullptr; | |
57 } | |
58 | |
59 private: | |
60 bool use_atomic_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(GbmDeviceGenerator); | |
63 }; | |
64 | |
65 } // namespace | |
66 | |
67 DrmThread::DrmThread() : base::Thread("DrmThread") {} | |
68 | |
69 DrmThread::~DrmThread() { | |
70 Stop(); | |
71 } | |
72 | |
73 void DrmThread::Start() { | |
74 if (!StartWithOptions(base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) | |
75 LOG(FATAL) << "Failed to create DRM thread"; | |
76 } | |
77 | |
78 void DrmThread::Init() { | |
79 bool use_atomic = false; | |
80 #if defined(USE_DRM_ATOMIC) | |
81 use_atomic = true; | |
82 #endif | |
83 | |
84 device_manager_.reset(new DrmDeviceManager( | |
85 make_scoped_ptr(new GbmDeviceGenerator(use_atomic)))); | |
86 buffer_generator_.reset(new GbmBufferGenerator()); | |
87 screen_manager_.reset(new ScreenManager(buffer_generator_.get())); | |
88 | |
89 display_manager_.reset( | |
90 new DrmGpuDisplayManager(screen_manager_.get(), device_manager_.get())); | |
91 } | |
92 | |
93 scoped_ptr<DrmWindowProxy> DrmThread::CreateWindowProxy( | |
spang
2015/09/29 22:55:37
I think it is inconsistent to put it here. In ever
dnicoara
2015/09/30 15:17:57
Yeah, that was bugging me a bit too. The DrmWindow
| |
94 gfx::AcceleratedWidget widget) { | |
95 scoped_ptr<DrmWindowProxy> window; | |
96 // The creation is synchronous on the DRM thread since it needs to make sure | |
97 // that the window is created on the DRM thread before continuing. This is | |
98 // required since the DrmDeviceManager is accessed on the GPU IO thread | |
99 // without a posted task which could result in invalid lookups for the widget | |
100 // if the window creation is still pending. | |
101 PostSyncTask(task_runner(), | |
102 base::Bind(&DrmThread::CreateWindowProxyOnThread, | |
103 base::Unretained(this), widget, &window)); | |
104 return window; | |
105 } | |
106 | |
107 void DrmThread::SchedulePageFlip(gfx::AcceleratedWidget widget, | |
108 const std::vector<OverlayPlane>& planes, | |
109 const SwapCompletionCallback& callback) { | |
110 DrmWindow* window = screen_manager_->GetWindow(widget); | |
111 if (window) | |
112 window->SchedulePageFlip(planes, callback); | |
113 } | |
114 | |
115 void DrmThread::GetVSyncParameters( | |
116 gfx::AcceleratedWidget widget, | |
117 const gfx::VSyncProvider::UpdateVSyncCallback& callback) { | |
118 DrmWindow* window = screen_manager_->GetWindow(widget); | |
119 if (window) | |
120 window->GetVSyncParameters(callback); | |
121 } | |
122 | |
123 void DrmThread::OnCreateWindow(gfx::AcceleratedWidget widget) { | |
spang
2015/09/29 22:55:37
We should use the imperative
CreateWindow()
OnCr
dnicoara
2015/09/30 15:17:57
Done. Sounds reasonable.
| |
124 scoped_ptr<DrmWindow> window( | |
125 new DrmWindow(widget, device_manager_.get(), screen_manager_.get())); | |
126 window->Initialize(); | |
127 screen_manager_->AddWindow(widget, window.Pass()); | |
128 } | |
129 | |
130 void DrmThread::OnDestroyWindow(gfx::AcceleratedWidget widget) { | |
131 scoped_ptr<DrmWindow> window = screen_manager_->RemoveWindow(widget); | |
132 window->Shutdown(); | |
133 } | |
134 | |
135 void DrmThread::OnWindowBoundsChanged(gfx::AcceleratedWidget widget, | |
136 const gfx::Rect& bounds) { | |
137 screen_manager_->GetWindow(widget)->OnBoundsChanged(bounds); | |
138 } | |
139 | |
140 void DrmThread::OnCursorSet(gfx::AcceleratedWidget widget, | |
141 const std::vector<SkBitmap>& bitmaps, | |
142 const gfx::Point& location, | |
143 int frame_delay_ms) { | |
144 screen_manager_->GetWindow(widget) | |
145 ->SetCursor(bitmaps, location, frame_delay_ms); | |
146 } | |
147 | |
148 void DrmThread::OnCursorMove(gfx::AcceleratedWidget widget, | |
149 const gfx::Point& location) { | |
150 screen_manager_->GetWindow(widget)->MoveCursor(location); | |
151 } | |
152 | |
153 void DrmThread::OnCheckOverlayCapabilities( | |
154 gfx::AcceleratedWidget widget, | |
155 const std::vector<OverlayCheck_Params>& overlays, | |
156 const base::Callback<void(gfx::AcceleratedWidget, bool)>& callback) { | |
157 callback.Run(widget, screen_manager_->GetWindow(widget) | |
158 ->TestPageFlip(overlays, buffer_generator_.get())); | |
159 } | |
160 | |
161 void DrmThread::OnRefreshNativeDisplays( | |
162 const base::Callback<void(const std::vector<DisplaySnapshot_Params>&)>& | |
163 callback) { | |
164 callback.Run(display_manager_->GetDisplays()); | |
165 } | |
166 | |
167 void DrmThread::OnConfigureNativeDisplay( | |
168 int64_t id, | |
169 const DisplayMode_Params& mode, | |
170 const gfx::Point& origin, | |
171 const base::Callback<void(int64_t, bool)>& callback) { | |
172 callback.Run(id, display_manager_->ConfigureDisplay(id, mode, origin)); | |
173 } | |
174 | |
175 void DrmThread::OnDisableNativeDisplay( | |
176 int64_t id, | |
177 const base::Callback<void(int64_t, bool)>& callback) { | |
178 callback.Run(id, display_manager_->DisableDisplay(id)); | |
179 } | |
180 | |
181 void DrmThread::OnTakeDisplayControl( | |
182 const base::Callback<void(bool)>& callback) { | |
183 callback.Run(display_manager_->TakeDisplayControl()); | |
184 } | |
185 | |
186 void DrmThread::OnRelinquishDisplayControl( | |
187 const base::Callback<void(bool)>& callback) { | |
188 display_manager_->RelinquishDisplayControl(); | |
189 callback.Run(true); | |
190 } | |
191 | |
192 void DrmThread::OnAddGraphicsDevice(const base::FilePath& path, | |
193 const base::FileDescriptor& fd) { | |
194 device_manager_->AddDrmDevice(path, fd); | |
195 } | |
196 | |
197 void DrmThread::OnRemoveGraphicsDevice(const base::FilePath& path) { | |
198 device_manager_->RemoveDrmDevice(path); | |
199 } | |
200 | |
201 void DrmThread::OnGetHDCPState( | |
202 int64_t display_id, | |
203 const base::Callback<void(int64_t, bool, HDCPState)>& callback) { | |
204 HDCPState state = HDCP_STATE_UNDESIRED; | |
205 bool success = display_manager_->GetHDCPState(display_id, &state); | |
206 callback.Run(display_id, success, state); | |
207 } | |
208 | |
209 void DrmThread::OnSetHDCPState( | |
210 int64_t display_id, | |
211 HDCPState state, | |
212 const base::Callback<void(int64_t, bool)>& callback) { | |
213 callback.Run(display_id, display_manager_->SetHDCPState(display_id, state)); | |
214 } | |
215 | |
216 void DrmThread::OnSetGammaRamp(int64_t id, | |
217 const std::vector<GammaRampRGBEntry>& lut) { | |
218 display_manager_->SetGammaRamp(id, lut); | |
219 } | |
220 | |
221 void DrmThread::CreateWindowProxyOnThread(gfx::AcceleratedWidget widget, | |
222 scoped_ptr<DrmWindowProxy>* window) { | |
223 if (screen_manager_->GetWindow(widget)) | |
224 window->reset(new DrmWindowProxy(widget, this)); | |
225 } | |
226 | |
227 } // namespace ui | |
OLD | NEW |