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, | |
52 bool is_primary_device) override { | |
53 scoped_refptr<DrmDevice> drm = | |
54 new GbmDevice(path, file.Pass(), is_primary_device); | |
55 if (drm->Initialize(use_atomic_)) | |
56 return drm; | |
57 | |
58 return nullptr; | |
59 } | |
60 | |
61 private: | |
62 bool use_atomic_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(GbmDeviceGenerator); | |
65 }; | |
66 | |
67 } // namespace | |
68 | |
69 DrmThread::DrmThread() : base::Thread("DrmThread") {} | |
70 | |
71 DrmThread::~DrmThread() { | |
72 Stop(); | |
73 } | |
74 | |
75 void DrmThread::Start() { | |
76 if (!StartWithOptions(base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) | |
77 LOG(FATAL) << "Failed to create DRM thread"; | |
78 } | |
79 | |
80 void DrmThread::Init() { | |
81 bool use_atomic = false; | |
82 #if defined(USE_DRM_ATOMIC) | |
83 use_atomic = true; | |
84 #endif | |
85 | |
86 device_manager_.reset(new DrmDeviceManager( | |
87 make_scoped_ptr(new GbmDeviceGenerator(use_atomic)))); | |
88 buffer_generator_.reset(new GbmBufferGenerator()); | |
89 screen_manager_.reset(new ScreenManager(buffer_generator_.get())); | |
90 | |
91 display_manager_.reset( | |
92 new DrmGpuDisplayManager(screen_manager_.get(), device_manager_.get())); | |
93 } | |
94 | |
95 void DrmThread::CreateBuffer(gfx::AcceleratedWidget widget, | |
96 const gfx::Size& size, | |
97 gfx::BufferFormat format, | |
98 gfx::BufferUsage usage, | |
99 scoped_refptr<GbmBuffer>* buffer) { | |
100 scoped_refptr<GbmDevice> gbm = | |
101 static_cast<GbmDevice*>(device_manager_->GetDrmDevice(widget).get()); | |
102 DCHECK(gbm); | |
103 *buffer = GbmBuffer::CreateBuffer(gbm, format, size, usage); | |
104 } | |
105 | |
106 void DrmThread::SchedulePageFlip(gfx::AcceleratedWidget widget, | |
107 const std::vector<OverlayPlane>& planes, | |
108 const SwapCompletionCallback& callback) { | |
109 DrmWindow* window = screen_manager_->GetWindow(widget); | |
110 if (window) | |
111 window->SchedulePageFlip(planes, callback); | |
spang
2015/10/05 18:08:26
Should this call the callback if there's no window
dnicoara
2015/10/05 18:57:12
Hmm, isn't required since the surface is going to
| |
112 } | |
113 | |
114 void DrmThread::GetVSyncParameters( | |
115 gfx::AcceleratedWidget widget, | |
116 const gfx::VSyncProvider::UpdateVSyncCallback& callback) { | |
117 DrmWindow* window = screen_manager_->GetWindow(widget); | |
118 if (window) | |
119 window->GetVSyncParameters(callback); | |
spang
2015/10/05 18:08:26
Should this call the callback if there's no window
dnicoara
2015/10/05 18:57:12
Not needed since the vsync provider doesn't mandat
| |
120 } | |
121 | |
122 void DrmThread::CreateWindow(gfx::AcceleratedWidget widget) { | |
123 scoped_ptr<DrmWindow> window( | |
124 new DrmWindow(widget, device_manager_.get(), screen_manager_.get())); | |
125 window->Initialize(); | |
126 screen_manager_->AddWindow(widget, window.Pass()); | |
127 } | |
128 | |
129 void DrmThread::DestroyWindow(gfx::AcceleratedWidget widget) { | |
130 scoped_ptr<DrmWindow> window = screen_manager_->RemoveWindow(widget); | |
131 window->Shutdown(); | |
132 } | |
133 | |
134 void DrmThread::WindowBoundsChanged(gfx::AcceleratedWidget widget, | |
135 const gfx::Rect& bounds) { | |
136 screen_manager_->GetWindow(widget)->OnBoundsChanged(bounds); | |
137 } | |
138 | |
139 void DrmThread::CursorSet(gfx::AcceleratedWidget widget, | |
140 const std::vector<SkBitmap>& bitmaps, | |
141 const gfx::Point& location, | |
142 int frame_delay_ms) { | |
143 screen_manager_->GetWindow(widget) | |
144 ->SetCursor(bitmaps, location, frame_delay_ms); | |
145 } | |
146 | |
147 void DrmThread::CursorMove(gfx::AcceleratedWidget widget, | |
148 const gfx::Point& location) { | |
149 screen_manager_->GetWindow(widget)->MoveCursor(location); | |
150 } | |
151 | |
152 void DrmThread::CheckOverlayCapabilities( | |
153 gfx::AcceleratedWidget widget, | |
154 const std::vector<OverlayCheck_Params>& overlays, | |
155 const base::Callback<void(gfx::AcceleratedWidget, | |
156 const std::vector<OverlayCheck_Params>&)>& | |
157 callback) { | |
158 callback.Run(widget, screen_manager_->GetWindow(widget) | |
159 ->TestPageFlip(overlays, buffer_generator_.get())); | |
160 } | |
161 | |
162 void DrmThread::RefreshNativeDisplays( | |
163 const base::Callback<void(const std::vector<DisplaySnapshot_Params>&)>& | |
164 callback) { | |
165 callback.Run(display_manager_->GetDisplays()); | |
166 } | |
167 | |
168 void DrmThread::ConfigureNativeDisplay( | |
169 int64_t id, | |
170 const DisplayMode_Params& mode, | |
171 const gfx::Point& origin, | |
172 const base::Callback<void(int64_t, bool)>& callback) { | |
173 callback.Run(id, display_manager_->ConfigureDisplay(id, mode, origin)); | |
174 } | |
175 | |
176 void DrmThread::DisableNativeDisplay( | |
177 int64_t id, | |
178 const base::Callback<void(int64_t, bool)>& callback) { | |
179 callback.Run(id, display_manager_->DisableDisplay(id)); | |
180 } | |
181 | |
182 void DrmThread::TakeDisplayControl(const base::Callback<void(bool)>& callback) { | |
183 callback.Run(display_manager_->TakeDisplayControl()); | |
184 } | |
185 | |
186 void DrmThread::RelinquishDisplayControl( | |
187 const base::Callback<void(bool)>& callback) { | |
188 display_manager_->RelinquishDisplayControl(); | |
189 callback.Run(true); | |
190 } | |
191 | |
192 void DrmThread::AddGraphicsDevice(const base::FilePath& path, | |
193 const base::FileDescriptor& fd) { | |
194 device_manager_->AddDrmDevice(path, fd); | |
195 } | |
196 | |
197 void DrmThread::RemoveGraphicsDevice(const base::FilePath& path) { | |
198 device_manager_->RemoveDrmDevice(path); | |
199 } | |
200 | |
201 void DrmThread::GetHDCPState( | |
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::SetHDCPState( | |
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::SetGammaRamp(int64_t id, | |
217 const std::vector<GammaRampRGBEntry>& lut) { | |
218 display_manager_->SetGammaRamp(id, lut); | |
219 } | |
220 | |
221 } // namespace ui | |
OLD | NEW |