Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: ui/ozone/platform/drm/gpu/drm_thread.cc

Issue 1311043016: Switch DRM platform to using a separate thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mv-drm-calls-on-thread2
Patch Set: update & fix clang Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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);
112 else
113 callback.Run(gfx::SwapResult::SWAP_ACK);
114 }
115
116 void DrmThread::GetVSyncParameters(
117 gfx::AcceleratedWidget widget,
118 const gfx::VSyncProvider::UpdateVSyncCallback& callback) {
119 DrmWindow* window = screen_manager_->GetWindow(widget);
120 // No need to call the callback if there isn't a window since the vsync
121 // provider doesn't require the callback to be called if there isn't a vsync
122 // data source.
123 if (window)
124 window->GetVSyncParameters(callback);
125 }
126
127 void DrmThread::CreateWindow(gfx::AcceleratedWidget widget) {
128 scoped_ptr<DrmWindow> window(
129 new DrmWindow(widget, device_manager_.get(), screen_manager_.get()));
130 window->Initialize();
131 screen_manager_->AddWindow(widget, window.Pass());
132 }
133
134 void DrmThread::DestroyWindow(gfx::AcceleratedWidget widget) {
135 scoped_ptr<DrmWindow> window = screen_manager_->RemoveWindow(widget);
136 window->Shutdown();
137 }
138
139 void DrmThread::SetWindowBounds(gfx::AcceleratedWidget widget,
140 const gfx::Rect& bounds) {
141 screen_manager_->GetWindow(widget)->SetBounds(bounds);
142 }
143
144 void DrmThread::SetCursor(gfx::AcceleratedWidget widget,
145 const std::vector<SkBitmap>& bitmaps,
146 const gfx::Point& location,
147 int frame_delay_ms) {
148 screen_manager_->GetWindow(widget)
149 ->SetCursor(bitmaps, location, frame_delay_ms);
150 }
151
152 void DrmThread::MoveCursor(gfx::AcceleratedWidget widget,
153 const gfx::Point& location) {
154 screen_manager_->GetWindow(widget)->MoveCursor(location);
155 }
156
157 void DrmThread::CheckOverlayCapabilities(
158 gfx::AcceleratedWidget widget,
159 const std::vector<OverlayCheck_Params>& overlays,
160 const base::Callback<void(gfx::AcceleratedWidget,
161 const std::vector<OverlayCheck_Params>&)>&
162 callback) {
163 callback.Run(widget, screen_manager_->GetWindow(widget)
164 ->TestPageFlip(overlays, buffer_generator_.get()));
165 }
166
167 void DrmThread::RefreshNativeDisplays(
168 const base::Callback<void(const std::vector<DisplaySnapshot_Params>&)>&
169 callback) {
170 callback.Run(display_manager_->GetDisplays());
171 }
172
173 void DrmThread::ConfigureNativeDisplay(
174 int64_t id,
175 const DisplayMode_Params& mode,
176 const gfx::Point& origin,
177 const base::Callback<void(int64_t, bool)>& callback) {
178 callback.Run(id, display_manager_->ConfigureDisplay(id, mode, origin));
179 }
180
181 void DrmThread::DisableNativeDisplay(
182 int64_t id,
183 const base::Callback<void(int64_t, bool)>& callback) {
184 callback.Run(id, display_manager_->DisableDisplay(id));
185 }
186
187 void DrmThread::TakeDisplayControl(const base::Callback<void(bool)>& callback) {
188 callback.Run(display_manager_->TakeDisplayControl());
189 }
190
191 void DrmThread::RelinquishDisplayControl(
192 const base::Callback<void(bool)>& callback) {
193 display_manager_->RelinquishDisplayControl();
194 callback.Run(true);
195 }
196
197 void DrmThread::AddGraphicsDevice(const base::FilePath& path,
198 const base::FileDescriptor& fd) {
199 device_manager_->AddDrmDevice(path, fd);
200 }
201
202 void DrmThread::RemoveGraphicsDevice(const base::FilePath& path) {
203 device_manager_->RemoveDrmDevice(path);
204 }
205
206 void DrmThread::GetHDCPState(
207 int64_t display_id,
208 const base::Callback<void(int64_t, bool, HDCPState)>& callback) {
209 HDCPState state = HDCP_STATE_UNDESIRED;
210 bool success = display_manager_->GetHDCPState(display_id, &state);
211 callback.Run(display_id, success, state);
212 }
213
214 void DrmThread::SetHDCPState(
215 int64_t display_id,
216 HDCPState state,
217 const base::Callback<void(int64_t, bool)>& callback) {
218 callback.Run(display_id, display_manager_->SetHDCPState(display_id, state));
219 }
220
221 void DrmThread::SetGammaRamp(int64_t id,
222 const std::vector<GammaRampRGBEntry>& lut) {
223 display_manager_->SetGammaRamp(id, lut);
224 }
225
226 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_thread.h ('k') | ui/ozone/platform/drm/gpu/drm_thread_message_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698