| 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/dri_wrapper.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> |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 void DrmDestroyDumbBuffer(int fd, uint32_t handle) { | 55 void DrmDestroyDumbBuffer(int fd, uint32_t handle) { |
| 56 struct drm_mode_destroy_dumb destroy_request; | 56 struct drm_mode_destroy_dumb destroy_request; |
| 57 memset(&destroy_request, 0, sizeof(destroy_request)); | 57 memset(&destroy_request, 0, sizeof(destroy_request)); |
| 58 destroy_request.handle = handle; | 58 destroy_request.handle = handle; |
| 59 drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_request); | 59 drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_request); |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 DriWrapper::DriWrapper(const char* device_path) { | 64 DriWrapper::DriWrapper(const char* device_path) |
| 65 fd_ = open(device_path, O_RDWR | O_CLOEXEC); | 65 : fd_(-1), device_path_(device_path) { |
| 66 } | 66 } |
| 67 | 67 |
| 68 DriWrapper::~DriWrapper() { | 68 DriWrapper::~DriWrapper() { |
| 69 if (fd_ >= 0) | 69 if (fd_ >= 0) |
| 70 close(fd_); | 70 close(fd_); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void DriWrapper::Initialize() { |
| 74 fd_ = open(device_path_, O_RDWR | O_CLOEXEC); |
| 75 if (fd_ < 0) |
| 76 PLOG(FATAL) << "open: " << device_path_; |
| 77 } |
| 78 |
| 73 ScopedDrmCrtcPtr DriWrapper::GetCrtc(uint32_t crtc_id) { | 79 ScopedDrmCrtcPtr DriWrapper::GetCrtc(uint32_t crtc_id) { |
| 74 DCHECK(fd_ >= 0); | 80 DCHECK(fd_ >= 0); |
| 75 return ScopedDrmCrtcPtr(drmModeGetCrtc(fd_, crtc_id)); | 81 return ScopedDrmCrtcPtr(drmModeGetCrtc(fd_, crtc_id)); |
| 76 } | 82 } |
| 77 | 83 |
| 78 bool DriWrapper::SetCrtc(uint32_t crtc_id, | 84 bool DriWrapper::SetCrtc(uint32_t crtc_id, |
| 79 uint32_t framebuffer, | 85 uint32_t framebuffer, |
| 80 std::vector<uint32_t> connectors, | 86 std::vector<uint32_t> connectors, |
| 81 drmModeModeInfo* mode) { | 87 drmModeModeInfo* mode) { |
| 82 DCHECK(fd_ >= 0); | 88 DCHECK(fd_ >= 0); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 uint32_t stride, | 291 uint32_t stride, |
| 286 void* pixels) { | 292 void* pixels) { |
| 287 DCHECK(fd_ >= 0); | 293 DCHECK(fd_ >= 0); |
| 288 TRACE_EVENT1("dri", "DriWrapper::DestroyDumbBuffer", "handle", handle); | 294 TRACE_EVENT1("dri", "DriWrapper::DestroyDumbBuffer", "handle", handle); |
| 289 munmap(pixels, info.getSafeSize(stride)); | 295 munmap(pixels, info.getSafeSize(stride)); |
| 290 DrmDestroyDumbBuffer(fd_, handle); | 296 DrmDestroyDumbBuffer(fd_, handle); |
| 291 } | 297 } |
| 292 | 298 |
| 293 | 299 |
| 294 } // namespace ui | 300 } // namespace ui |
| OLD | NEW |