OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/ozone/platform/dri/dri_wrapper.h" | 5 #include "ui/ozone/platform/dri/drm_device.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <sys/mman.h> | 8 #include <sys/mman.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 #include <xf86drm.h> | 10 #include <xf86drm.h> |
11 #include <xf86drmMode.h> | 11 #include <xf86drmMode.h> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
18 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
19 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
20 #include "third_party/skia/include/core/SkImageInfo.h" | 20 #include "third_party/skia/include/core/SkImageInfo.h" |
21 #include "ui/ozone/platform/dri/dri_util.h" | 21 #include "ui/ozone/platform/dri/dri_util.h" |
22 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h" | 22 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h" |
23 | 23 |
24 namespace ui { | 24 namespace ui { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 struct PageFlipPayload { | 28 struct PageFlipPayload { |
29 PageFlipPayload(const scoped_refptr<base::TaskRunner>& task_runner, | 29 PageFlipPayload(const scoped_refptr<base::TaskRunner>& task_runner, |
30 const DriWrapper::PageFlipCallback& callback) | 30 const DrmDevice::PageFlipCallback& callback) |
31 : task_runner(task_runner), callback(callback) {} | 31 : task_runner(task_runner), callback(callback) {} |
32 | 32 |
33 // Task runner for the thread scheduling the page flip event. This is used to | 33 // Task runner for the thread scheduling the page flip event. This is used to |
34 // run the callback on the same thread the callback was created on. | 34 // run the callback on the same thread the callback was created on. |
35 scoped_refptr<base::TaskRunner> task_runner; | 35 scoped_refptr<base::TaskRunner> task_runner; |
36 DriWrapper::PageFlipCallback callback; | 36 DrmDevice::PageFlipCallback callback; |
37 }; | 37 }; |
38 | 38 |
39 bool DrmCreateDumbBuffer(int fd, | 39 bool DrmCreateDumbBuffer(int fd, |
40 const SkImageInfo& info, | 40 const SkImageInfo& info, |
41 uint32_t* handle, | 41 uint32_t* handle, |
42 uint32_t* stride) { | 42 uint32_t* stride) { |
43 struct drm_mode_create_dumb request; | 43 struct drm_mode_create_dumb request; |
44 memset(&request, 0, sizeof(request)); | 44 memset(&request, 0, sizeof(request)); |
45 request.width = info.width(); | 45 request.width = info.width(); |
46 request.height = info.height(); | 46 request.height = info.height(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 bool CanQueryForResources(int fd) { | 92 bool CanQueryForResources(int fd) { |
93 drm_mode_card_res resources; | 93 drm_mode_card_res resources; |
94 memset(&resources, 0, sizeof(resources)); | 94 memset(&resources, 0, sizeof(resources)); |
95 // If there is no error getting DRM resources then assume this is a | 95 // If there is no error getting DRM resources then assume this is a |
96 // modesetting device. | 96 // modesetting device. |
97 return !drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &resources); | 97 return !drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &resources); |
98 } | 98 } |
99 | 99 |
100 } // namespace | 100 } // namespace |
101 | 101 |
102 class DriWrapper::IOWatcher | 102 class DrmDevice::IOWatcher |
103 : public base::RefCountedThreadSafe<DriWrapper::IOWatcher>, | 103 : public base::RefCountedThreadSafe<DrmDevice::IOWatcher>, |
104 public base::MessagePumpLibevent::Watcher { | 104 public base::MessagePumpLibevent::Watcher { |
105 public: | 105 public: |
106 IOWatcher(int fd, | 106 IOWatcher(int fd, |
107 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 107 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
108 : io_task_runner_(io_task_runner), paused_(true), fd_(fd) {} | 108 : io_task_runner_(io_task_runner), paused_(true), fd_(fd) {} |
109 | 109 |
110 void SetPaused(bool paused) { | 110 void SetPaused(bool paused) { |
111 if (paused_ == paused) | 111 if (paused_ == paused) |
112 return; | 112 return; |
113 | 113 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 166 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
167 | 167 |
168 base::MessagePumpLibevent::FileDescriptorWatcher controller_; | 168 base::MessagePumpLibevent::FileDescriptorWatcher controller_; |
169 | 169 |
170 bool paused_; | 170 bool paused_; |
171 int fd_; | 171 int fd_; |
172 | 172 |
173 DISALLOW_COPY_AND_ASSIGN(IOWatcher); | 173 DISALLOW_COPY_AND_ASSIGN(IOWatcher); |
174 }; | 174 }; |
175 | 175 |
176 DriWrapper::DriWrapper(const base::FilePath& device_path) | 176 DrmDevice::DrmDevice(const base::FilePath& device_path) |
177 : device_path_(device_path), | 177 : device_path_(device_path), |
178 file_(device_path, | 178 file_(device_path, |
179 base::File::FLAG_OPEN | base::File::FLAG_READ | | 179 base::File::FLAG_OPEN | base::File::FLAG_READ | |
180 base::File::FLAG_WRITE) { | 180 base::File::FLAG_WRITE) { |
181 LOG_IF(FATAL, !file_.IsValid()) | 181 LOG_IF(FATAL, !file_.IsValid()) |
182 << "Failed to open '" << device_path_.value() | 182 << "Failed to open '" << device_path_.value() |
183 << "': " << base::File::ErrorToString(file_.error_details()); | 183 << "': " << base::File::ErrorToString(file_.error_details()); |
184 } | 184 } |
185 | 185 |
186 DriWrapper::DriWrapper(const base::FilePath& device_path, base::File file) | 186 DrmDevice::DrmDevice(const base::FilePath& device_path, base::File file) |
187 : device_path_(device_path), file_(file.Pass()) { | 187 : device_path_(device_path), file_(file.Pass()) { |
188 } | 188 } |
189 | 189 |
190 DriWrapper::~DriWrapper() { | 190 DrmDevice::~DrmDevice() { |
191 if (watcher_) | 191 if (watcher_) |
192 watcher_->Shutdown(); | 192 watcher_->Shutdown(); |
193 } | 193 } |
194 | 194 |
195 bool DriWrapper::Initialize() { | 195 bool DrmDevice::Initialize() { |
196 // Ignore devices that cannot perform modesetting. | 196 // Ignore devices that cannot perform modesetting. |
197 if (!CanQueryForResources(file_.GetPlatformFile())) { | 197 if (!CanQueryForResources(file_.GetPlatformFile())) { |
198 VLOG(2) << "Cannot query for resources for '" << device_path_.value() | 198 VLOG(2) << "Cannot query for resources for '" << device_path_.value() |
199 << "'"; | 199 << "'"; |
200 return false; | 200 return false; |
201 } | 201 } |
202 | 202 |
203 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); | 203 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); |
204 if (!plane_manager_->Initialize(this)) { | 204 if (!plane_manager_->Initialize(this)) { |
205 LOG(ERROR) << "Failed to initialize the plane manager for " | 205 LOG(ERROR) << "Failed to initialize the plane manager for " |
206 << device_path_.value(); | 206 << device_path_.value(); |
207 plane_manager_.reset(); | 207 plane_manager_.reset(); |
208 return false; | 208 return false; |
209 } | 209 } |
210 | 210 |
211 return true; | 211 return true; |
212 } | 212 } |
213 | 213 |
214 void DriWrapper::InitializeTaskRunner( | 214 void DrmDevice::InitializeTaskRunner( |
215 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 215 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
216 DCHECK(!task_runner_); | 216 DCHECK(!task_runner_); |
217 task_runner_ = task_runner; | 217 task_runner_ = task_runner; |
218 watcher_ = new IOWatcher(file_.GetPlatformFile(), task_runner_); | 218 watcher_ = new IOWatcher(file_.GetPlatformFile(), task_runner_); |
219 } | 219 } |
220 | 220 |
221 ScopedDrmCrtcPtr DriWrapper::GetCrtc(uint32_t crtc_id) { | 221 ScopedDrmCrtcPtr DrmDevice::GetCrtc(uint32_t crtc_id) { |
222 DCHECK(file_.IsValid()); | 222 DCHECK(file_.IsValid()); |
223 return ScopedDrmCrtcPtr(drmModeGetCrtc(file_.GetPlatformFile(), crtc_id)); | 223 return ScopedDrmCrtcPtr(drmModeGetCrtc(file_.GetPlatformFile(), crtc_id)); |
224 } | 224 } |
225 | 225 |
226 bool DriWrapper::SetCrtc(uint32_t crtc_id, | 226 bool DrmDevice::SetCrtc(uint32_t crtc_id, |
227 uint32_t framebuffer, | 227 uint32_t framebuffer, |
228 std::vector<uint32_t> connectors, | 228 std::vector<uint32_t> connectors, |
229 drmModeModeInfo* mode) { | 229 drmModeModeInfo* mode) { |
230 DCHECK(file_.IsValid()); | 230 DCHECK(file_.IsValid()); |
231 DCHECK(!connectors.empty()); | 231 DCHECK(!connectors.empty()); |
232 DCHECK(mode); | 232 DCHECK(mode); |
233 | 233 |
234 TRACE_EVENT2("dri", "DriWrapper::SetCrtc", "crtc", crtc_id, "size", | 234 TRACE_EVENT2("dri", "DrmDevice::SetCrtc", "crtc", crtc_id, "size", |
235 gfx::Size(mode->hdisplay, mode->vdisplay).ToString()); | 235 gfx::Size(mode->hdisplay, mode->vdisplay).ToString()); |
236 return !drmModeSetCrtc(file_.GetPlatformFile(), crtc_id, framebuffer, 0, 0, | 236 return !drmModeSetCrtc(file_.GetPlatformFile(), crtc_id, framebuffer, 0, 0, |
237 vector_as_array(&connectors), connectors.size(), mode); | 237 vector_as_array(&connectors), connectors.size(), mode); |
238 } | 238 } |
239 | 239 |
240 bool DriWrapper::SetCrtc(drmModeCrtc* crtc, std::vector<uint32_t> connectors) { | 240 bool DrmDevice::SetCrtc(drmModeCrtc* crtc, std::vector<uint32_t> connectors) { |
241 DCHECK(file_.IsValid()); | 241 DCHECK(file_.IsValid()); |
242 // If there's no buffer then the CRTC was disabled. | 242 // If there's no buffer then the CRTC was disabled. |
243 if (!crtc->buffer_id) | 243 if (!crtc->buffer_id) |
244 return DisableCrtc(crtc->crtc_id); | 244 return DisableCrtc(crtc->crtc_id); |
245 | 245 |
246 DCHECK(!connectors.empty()); | 246 DCHECK(!connectors.empty()); |
247 | 247 |
248 TRACE_EVENT1("dri", "DriWrapper::RestoreCrtc", | 248 TRACE_EVENT1("dri", "DrmDevice::RestoreCrtc", "crtc", crtc->crtc_id); |
249 "crtc", crtc->crtc_id); | |
250 return !drmModeSetCrtc(file_.GetPlatformFile(), crtc->crtc_id, | 249 return !drmModeSetCrtc(file_.GetPlatformFile(), crtc->crtc_id, |
251 crtc->buffer_id, crtc->x, crtc->y, | 250 crtc->buffer_id, crtc->x, crtc->y, |
252 vector_as_array(&connectors), connectors.size(), | 251 vector_as_array(&connectors), connectors.size(), |
253 &crtc->mode); | 252 &crtc->mode); |
254 } | 253 } |
255 | 254 |
256 bool DriWrapper::DisableCrtc(uint32_t crtc_id) { | 255 bool DrmDevice::DisableCrtc(uint32_t crtc_id) { |
257 DCHECK(file_.IsValid()); | 256 DCHECK(file_.IsValid()); |
258 TRACE_EVENT1("dri", "DriWrapper::DisableCrtc", | 257 TRACE_EVENT1("dri", "DrmDevice::DisableCrtc", "crtc", crtc_id); |
259 "crtc", crtc_id); | |
260 return !drmModeSetCrtc(file_.GetPlatformFile(), crtc_id, 0, 0, 0, NULL, 0, | 258 return !drmModeSetCrtc(file_.GetPlatformFile(), crtc_id, 0, 0, 0, NULL, 0, |
261 NULL); | 259 NULL); |
262 } | 260 } |
263 | 261 |
264 ScopedDrmConnectorPtr DriWrapper::GetConnector(uint32_t connector_id) { | 262 ScopedDrmConnectorPtr DrmDevice::GetConnector(uint32_t connector_id) { |
265 DCHECK(file_.IsValid()); | 263 DCHECK(file_.IsValid()); |
266 TRACE_EVENT1("dri", "DriWrapper::GetConnector", "connector", connector_id); | 264 TRACE_EVENT1("dri", "DrmDevice::GetConnector", "connector", connector_id); |
267 return ScopedDrmConnectorPtr( | 265 return ScopedDrmConnectorPtr( |
268 drmModeGetConnector(file_.GetPlatformFile(), connector_id)); | 266 drmModeGetConnector(file_.GetPlatformFile(), connector_id)); |
269 } | 267 } |
270 | 268 |
271 bool DriWrapper::AddFramebuffer(uint32_t width, | 269 bool DrmDevice::AddFramebuffer(uint32_t width, |
272 uint32_t height, | 270 uint32_t height, |
273 uint8_t depth, | 271 uint8_t depth, |
274 uint8_t bpp, | 272 uint8_t bpp, |
275 uint32_t stride, | 273 uint32_t stride, |
276 uint32_t handle, | 274 uint32_t handle, |
277 uint32_t* framebuffer) { | 275 uint32_t* framebuffer) { |
278 DCHECK(file_.IsValid()); | 276 DCHECK(file_.IsValid()); |
279 TRACE_EVENT1("dri", "DriWrapper::AddFramebuffer", | 277 TRACE_EVENT1("dri", "DrmDevice::AddFramebuffer", "handle", handle); |
280 "handle", handle); | |
281 return !drmModeAddFB(file_.GetPlatformFile(), width, height, depth, bpp, | 278 return !drmModeAddFB(file_.GetPlatformFile(), width, height, depth, bpp, |
282 stride, handle, framebuffer); | 279 stride, handle, framebuffer); |
283 } | 280 } |
284 | 281 |
285 bool DriWrapper::RemoveFramebuffer(uint32_t framebuffer) { | 282 bool DrmDevice::RemoveFramebuffer(uint32_t framebuffer) { |
286 DCHECK(file_.IsValid()); | 283 DCHECK(file_.IsValid()); |
287 TRACE_EVENT1("dri", "DriWrapper::RemoveFramebuffer", | 284 TRACE_EVENT1("dri", "DrmDevice::RemoveFramebuffer", "framebuffer", |
288 "framebuffer", framebuffer); | 285 framebuffer); |
289 return !drmModeRmFB(file_.GetPlatformFile(), framebuffer); | 286 return !drmModeRmFB(file_.GetPlatformFile(), framebuffer); |
290 } | 287 } |
291 | 288 |
292 bool DriWrapper::PageFlip(uint32_t crtc_id, | 289 bool DrmDevice::PageFlip(uint32_t crtc_id, |
293 uint32_t framebuffer, | 290 uint32_t framebuffer, |
294 bool is_sync, | 291 bool is_sync, |
295 const PageFlipCallback& callback) { | 292 const PageFlipCallback& callback) { |
296 DCHECK(file_.IsValid()); | 293 DCHECK(file_.IsValid()); |
297 TRACE_EVENT2("dri", "DriWrapper::PageFlip", | 294 TRACE_EVENT2("dri", "DrmDevice::PageFlip", "crtc", crtc_id, "framebuffer", |
298 "crtc", crtc_id, | 295 framebuffer); |
299 "framebuffer", framebuffer); | |
300 | 296 |
301 if (watcher_) | 297 if (watcher_) |
302 watcher_->SetPaused(is_sync); | 298 watcher_->SetPaused(is_sync); |
303 | 299 |
304 // NOTE: Calling drmModeSetCrtc will immediately update the state, though | 300 // NOTE: Calling drmModeSetCrtc will immediately update the state, though |
305 // callbacks to already scheduled page flips will be honored by the kernel. | 301 // callbacks to already scheduled page flips will be honored by the kernel. |
306 scoped_ptr<PageFlipPayload> payload( | 302 scoped_ptr<PageFlipPayload> payload( |
307 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback)); | 303 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback)); |
308 if (!drmModePageFlip(file_.GetPlatformFile(), crtc_id, framebuffer, | 304 if (!drmModePageFlip(file_.GetPlatformFile(), crtc_id, framebuffer, |
309 DRM_MODE_PAGE_FLIP_EVENT, payload.get())) { | 305 DRM_MODE_PAGE_FLIP_EVENT, payload.get())) { |
(...skipping 12 matching lines...) Expand all Loading... |
322 | 318 |
323 drmHandleEvent(file_.GetPlatformFile(), &event); | 319 drmHandleEvent(file_.GetPlatformFile(), &event); |
324 } | 320 } |
325 | 321 |
326 return true; | 322 return true; |
327 } | 323 } |
328 | 324 |
329 return false; | 325 return false; |
330 } | 326 } |
331 | 327 |
332 bool DriWrapper::PageFlipOverlay(uint32_t crtc_id, | 328 bool DrmDevice::PageFlipOverlay(uint32_t crtc_id, |
333 uint32_t framebuffer, | 329 uint32_t framebuffer, |
334 const gfx::Rect& location, | 330 const gfx::Rect& location, |
335 const gfx::Rect& source, | 331 const gfx::Rect& source, |
336 int overlay_plane) { | 332 int overlay_plane) { |
337 DCHECK(file_.IsValid()); | 333 DCHECK(file_.IsValid()); |
338 TRACE_EVENT2("dri", "DriWrapper::PageFlipOverlay", | 334 TRACE_EVENT2("dri", "DrmDevice::PageFlipOverlay", "crtc", crtc_id, |
339 "crtc", crtc_id, | |
340 "framebuffer", framebuffer); | 335 "framebuffer", framebuffer); |
341 return !drmModeSetPlane(file_.GetPlatformFile(), overlay_plane, crtc_id, | 336 return !drmModeSetPlane(file_.GetPlatformFile(), overlay_plane, crtc_id, |
342 framebuffer, 0, location.x(), location.y(), | 337 framebuffer, 0, location.x(), location.y(), |
343 location.width(), location.height(), source.x(), | 338 location.width(), location.height(), source.x(), |
344 source.y(), source.width(), source.height()); | 339 source.y(), source.width(), source.height()); |
345 } | 340 } |
346 | 341 |
347 ScopedDrmFramebufferPtr DriWrapper::GetFramebuffer(uint32_t framebuffer) { | 342 ScopedDrmFramebufferPtr DrmDevice::GetFramebuffer(uint32_t framebuffer) { |
348 DCHECK(file_.IsValid()); | 343 DCHECK(file_.IsValid()); |
349 TRACE_EVENT1("dri", "DriWrapper::GetFramebuffer", | 344 TRACE_EVENT1("dri", "DrmDevice::GetFramebuffer", "framebuffer", framebuffer); |
350 "framebuffer", framebuffer); | |
351 return ScopedDrmFramebufferPtr( | 345 return ScopedDrmFramebufferPtr( |
352 drmModeGetFB(file_.GetPlatformFile(), framebuffer)); | 346 drmModeGetFB(file_.GetPlatformFile(), framebuffer)); |
353 } | 347 } |
354 | 348 |
355 ScopedDrmPropertyPtr DriWrapper::GetProperty(drmModeConnector* connector, | 349 ScopedDrmPropertyPtr DrmDevice::GetProperty(drmModeConnector* connector, |
356 const char* name) { | 350 const char* name) { |
357 TRACE_EVENT2("dri", "DriWrapper::GetProperty", | 351 TRACE_EVENT2("dri", "DrmDevice::GetProperty", "connector", |
358 "connector", connector->connector_id, | 352 connector->connector_id, "name", name); |
359 "name", name); | |
360 for (int i = 0; i < connector->count_props; ++i) { | 353 for (int i = 0; i < connector->count_props; ++i) { |
361 ScopedDrmPropertyPtr property( | 354 ScopedDrmPropertyPtr property( |
362 drmModeGetProperty(file_.GetPlatformFile(), connector->props[i])); | 355 drmModeGetProperty(file_.GetPlatformFile(), connector->props[i])); |
363 if (!property) | 356 if (!property) |
364 continue; | 357 continue; |
365 | 358 |
366 if (strcmp(property->name, name) == 0) | 359 if (strcmp(property->name, name) == 0) |
367 return property.Pass(); | 360 return property.Pass(); |
368 } | 361 } |
369 | 362 |
370 return ScopedDrmPropertyPtr(); | 363 return ScopedDrmPropertyPtr(); |
371 } | 364 } |
372 | 365 |
373 bool DriWrapper::SetProperty(uint32_t connector_id, | 366 bool DrmDevice::SetProperty(uint32_t connector_id, |
374 uint32_t property_id, | 367 uint32_t property_id, |
375 uint64_t value) { | 368 uint64_t value) { |
376 DCHECK(file_.IsValid()); | 369 DCHECK(file_.IsValid()); |
377 return !drmModeConnectorSetProperty(file_.GetPlatformFile(), connector_id, | 370 return !drmModeConnectorSetProperty(file_.GetPlatformFile(), connector_id, |
378 property_id, value); | 371 property_id, value); |
379 } | 372 } |
380 | 373 |
381 bool DriWrapper::GetCapability(uint64_t capability, uint64_t* value) { | 374 bool DrmDevice::GetCapability(uint64_t capability, uint64_t* value) { |
382 DCHECK(file_.IsValid()); | 375 DCHECK(file_.IsValid()); |
383 return !drmGetCap(file_.GetPlatformFile(), capability, value); | 376 return !drmGetCap(file_.GetPlatformFile(), capability, value); |
384 } | 377 } |
385 | 378 |
386 ScopedDrmPropertyBlobPtr DriWrapper::GetPropertyBlob( | 379 ScopedDrmPropertyBlobPtr DrmDevice::GetPropertyBlob(drmModeConnector* connector, |
387 drmModeConnector* connector, const char* name) { | 380 const char* name) { |
388 DCHECK(file_.IsValid()); | 381 DCHECK(file_.IsValid()); |
389 TRACE_EVENT2("dri", "DriWrapper::GetPropertyBlob", | 382 TRACE_EVENT2("dri", "DrmDevice::GetPropertyBlob", "connector", |
390 "connector", connector->connector_id, | 383 connector->connector_id, "name", name); |
391 "name", name); | |
392 for (int i = 0; i < connector->count_props; ++i) { | 384 for (int i = 0; i < connector->count_props; ++i) { |
393 ScopedDrmPropertyPtr property( | 385 ScopedDrmPropertyPtr property( |
394 drmModeGetProperty(file_.GetPlatformFile(), connector->props[i])); | 386 drmModeGetProperty(file_.GetPlatformFile(), connector->props[i])); |
395 if (!property) | 387 if (!property) |
396 continue; | 388 continue; |
397 | 389 |
398 if (strcmp(property->name, name) == 0 && | 390 if (strcmp(property->name, name) == 0 && |
399 property->flags & DRM_MODE_PROP_BLOB) | 391 property->flags & DRM_MODE_PROP_BLOB) |
400 return ScopedDrmPropertyBlobPtr(drmModeGetPropertyBlob( | 392 return ScopedDrmPropertyBlobPtr(drmModeGetPropertyBlob( |
401 file_.GetPlatformFile(), connector->prop_values[i])); | 393 file_.GetPlatformFile(), connector->prop_values[i])); |
402 } | 394 } |
403 | 395 |
404 return ScopedDrmPropertyBlobPtr(); | 396 return ScopedDrmPropertyBlobPtr(); |
405 } | 397 } |
406 | 398 |
407 bool DriWrapper::SetCursor(uint32_t crtc_id, | 399 bool DrmDevice::SetCursor(uint32_t crtc_id, |
408 uint32_t handle, | 400 uint32_t handle, |
409 const gfx::Size& size) { | 401 const gfx::Size& size) { |
410 DCHECK(file_.IsValid()); | 402 DCHECK(file_.IsValid()); |
411 TRACE_EVENT1("dri", "DriWrapper::SetCursor", "handle", handle); | 403 TRACE_EVENT1("dri", "DrmDevice::SetCursor", "handle", handle); |
412 return !drmModeSetCursor(file_.GetPlatformFile(), crtc_id, handle, | 404 return !drmModeSetCursor(file_.GetPlatformFile(), crtc_id, handle, |
413 size.width(), size.height()); | 405 size.width(), size.height()); |
414 } | 406 } |
415 | 407 |
416 bool DriWrapper::MoveCursor(uint32_t crtc_id, const gfx::Point& point) { | 408 bool DrmDevice::MoveCursor(uint32_t crtc_id, const gfx::Point& point) { |
417 DCHECK(file_.IsValid()); | 409 DCHECK(file_.IsValid()); |
418 return !drmModeMoveCursor(file_.GetPlatformFile(), crtc_id, point.x(), | 410 return !drmModeMoveCursor(file_.GetPlatformFile(), crtc_id, point.x(), |
419 point.y()); | 411 point.y()); |
420 } | 412 } |
421 | 413 |
422 bool DriWrapper::CreateDumbBuffer(const SkImageInfo& info, | 414 bool DrmDevice::CreateDumbBuffer(const SkImageInfo& info, |
423 uint32_t* handle, | 415 uint32_t* handle, |
424 uint32_t* stride, | 416 uint32_t* stride, |
425 void** pixels) { | 417 void** pixels) { |
426 DCHECK(file_.IsValid()); | 418 DCHECK(file_.IsValid()); |
427 | 419 |
428 TRACE_EVENT0("dri", "DriWrapper::CreateDumbBuffer"); | 420 TRACE_EVENT0("dri", "DrmDevice::CreateDumbBuffer"); |
429 if (!DrmCreateDumbBuffer(file_.GetPlatformFile(), info, handle, stride)) | 421 if (!DrmCreateDumbBuffer(file_.GetPlatformFile(), info, handle, stride)) |
430 return false; | 422 return false; |
431 | 423 |
432 if (!MapDumbBuffer(file_.GetPlatformFile(), *handle, | 424 if (!MapDumbBuffer(file_.GetPlatformFile(), *handle, |
433 info.getSafeSize(*stride), pixels)) { | 425 info.getSafeSize(*stride), pixels)) { |
434 DrmDestroyDumbBuffer(file_.GetPlatformFile(), *handle); | 426 DrmDestroyDumbBuffer(file_.GetPlatformFile(), *handle); |
435 return false; | 427 return false; |
436 } | 428 } |
437 | 429 |
438 return true; | 430 return true; |
439 } | 431 } |
440 | 432 |
441 void DriWrapper::DestroyDumbBuffer(const SkImageInfo& info, | 433 void DrmDevice::DestroyDumbBuffer(const SkImageInfo& info, |
442 uint32_t handle, | 434 uint32_t handle, |
443 uint32_t stride, | 435 uint32_t stride, |
444 void* pixels) { | 436 void* pixels) { |
445 DCHECK(file_.IsValid()); | 437 DCHECK(file_.IsValid()); |
446 TRACE_EVENT1("dri", "DriWrapper::DestroyDumbBuffer", "handle", handle); | 438 TRACE_EVENT1("dri", "DrmDevice::DestroyDumbBuffer", "handle", handle); |
447 munmap(pixels, info.getSafeSize(stride)); | 439 munmap(pixels, info.getSafeSize(stride)); |
448 DrmDestroyDumbBuffer(file_.GetPlatformFile(), handle); | 440 DrmDestroyDumbBuffer(file_.GetPlatformFile(), handle); |
449 } | 441 } |
450 | 442 |
451 bool DriWrapper::SetMaster() { | 443 bool DrmDevice::SetMaster() { |
452 DCHECK(file_.IsValid()); | 444 DCHECK(file_.IsValid()); |
453 return (drmSetMaster(file_.GetPlatformFile()) == 0); | 445 return (drmSetMaster(file_.GetPlatformFile()) == 0); |
454 } | 446 } |
455 | 447 |
456 bool DriWrapper::DropMaster() { | 448 bool DrmDevice::DropMaster() { |
457 DCHECK(file_.IsValid()); | 449 DCHECK(file_.IsValid()); |
458 return (drmDropMaster(file_.GetPlatformFile()) == 0); | 450 return (drmDropMaster(file_.GetPlatformFile()) == 0); |
459 } | 451 } |
460 | 452 |
461 } // namespace ui | 453 } // namespace ui |
OLD | NEW |