| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } | 138 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } |
| 139 | 139 |
| 140 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 140 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 141 | 141 |
| 142 base::MessagePumpLibevent::FileDescriptorWatcher controller_; | 142 base::MessagePumpLibevent::FileDescriptorWatcher controller_; |
| 143 | 143 |
| 144 DISALLOW_COPY_AND_ASSIGN(IOWatcher); | 144 DISALLOW_COPY_AND_ASSIGN(IOWatcher); |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 DriWrapper::DriWrapper(const char* device_path, bool software_mode) | 147 DriWrapper::DriWrapper(const char* device_path, bool use_sync_flips) |
| 148 : fd_(-1), | 148 : fd_(-1), |
| 149 software_mode_(software_mode), | 149 use_sync_flips_(use_sync_flips), |
| 150 device_path_(device_path), | 150 device_path_(device_path), |
| 151 io_thread_("DriIOThread") { | 151 io_thread_("DriIOThread") { |
| 152 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); | 152 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 DriWrapper::~DriWrapper() { | 155 DriWrapper::~DriWrapper() { |
| 156 if (fd_ >= 0) | 156 if (fd_ >= 0) |
| 157 close(fd_); | 157 close(fd_); |
| 158 | 158 |
| 159 if (watcher_) | 159 if (watcher_) |
| 160 watcher_->Shutdown(); | 160 watcher_->Shutdown(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void DriWrapper::Initialize() { | 163 void DriWrapper::Initialize() { |
| 164 fd_ = open(device_path_, O_RDWR | O_CLOEXEC); | 164 fd_ = open(device_path_, O_RDWR | O_CLOEXEC); |
| 165 if (fd_ < 0) | 165 if (fd_ < 0) |
| 166 PLOG(FATAL) << "open: " << device_path_; | 166 PLOG(FATAL) << "open: " << device_path_; |
| 167 if (!plane_manager_->Initialize(this)) | 167 if (!plane_manager_->Initialize(this)) |
| 168 LOG(ERROR) << "Failed to initialize the plane manager"; | 168 LOG(ERROR) << "Failed to initialize the plane manager"; |
| 169 } | 169 } |
| 170 | 170 |
| 171 void DriWrapper::InitializeIOWatcher() { | 171 void DriWrapper::InitializeIOWatcher() { |
| 172 if (!software_mode_ && !watcher_) { | 172 if (!use_sync_flips_ && !watcher_) { |
| 173 if (!io_thread_.StartWithOptions( | 173 if (!io_thread_.StartWithOptions( |
| 174 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) | 174 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) |
| 175 LOG(FATAL) << "Failed to start the IO helper thread"; | 175 LOG(FATAL) << "Failed to start the IO helper thread"; |
| 176 | 176 |
| 177 watcher_ = new IOWatcher(fd_, io_thread_.task_runner()); | 177 watcher_ = new IOWatcher(fd_, io_thread_.task_runner()); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 | 180 |
| 181 ScopedDrmCrtcPtr DriWrapper::GetCrtc(uint32_t crtc_id) { | 181 ScopedDrmCrtcPtr DriWrapper::GetCrtc(uint32_t crtc_id) { |
| 182 DCHECK(fd_ >= 0); | 182 DCHECK(fd_ >= 0); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 "framebuffer", framebuffer); | 271 "framebuffer", framebuffer); |
| 272 | 272 |
| 273 // NOTE: Calling drmModeSetCrtc will immediately update the state, though | 273 // NOTE: Calling drmModeSetCrtc will immediately update the state, though |
| 274 // callbacks to already scheduled page flips will be honored by the kernel. | 274 // callbacks to already scheduled page flips will be honored by the kernel. |
| 275 scoped_ptr<PageFlipPayload> payload( | 275 scoped_ptr<PageFlipPayload> payload( |
| 276 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback)); | 276 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback)); |
| 277 if (!drmModePageFlip(fd_, crtc_id, framebuffer, DRM_MODE_PAGE_FLIP_EVENT, | 277 if (!drmModePageFlip(fd_, crtc_id, framebuffer, DRM_MODE_PAGE_FLIP_EVENT, |
| 278 payload.get())) { | 278 payload.get())) { |
| 279 // If successful the payload will be removed by a PageFlip event. | 279 // If successful the payload will be removed by a PageFlip event. |
| 280 ignore_result(payload.release()); | 280 ignore_result(payload.release()); |
| 281 if (software_mode_) { | 281 if (use_sync_flips_) { |
| 282 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd_); | 282 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd_); |
| 283 | 283 |
| 284 drmEventContext event; | 284 drmEventContext event; |
| 285 event.version = DRM_EVENT_CONTEXT_VERSION; | 285 event.version = DRM_EVENT_CONTEXT_VERSION; |
| 286 event.page_flip_handler = HandlePageFlipEventOnUI; | 286 event.page_flip_handler = HandlePageFlipEventOnUI; |
| 287 event.vblank_handler = nullptr; | 287 event.vblank_handler = nullptr; |
| 288 | 288 |
| 289 drmHandleEvent(fd_, &event); | 289 drmHandleEvent(fd_, &event); |
| 290 } else { | 290 } else { |
| 291 InitializeIOWatcher(); | 291 InitializeIOWatcher(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 DCHECK(fd_ >= 0); | 413 DCHECK(fd_ >= 0); |
| 414 return (drmSetMaster(fd_) == 0); | 414 return (drmSetMaster(fd_) == 0); |
| 415 } | 415 } |
| 416 | 416 |
| 417 bool DriWrapper::DropMaster() { | 417 bool DriWrapper::DropMaster() { |
| 418 DCHECK(fd_ >= 0); | 418 DCHECK(fd_ >= 0); |
| 419 return (drmDropMaster(fd_) == 0); | 419 return (drmDropMaster(fd_) == 0); |
| 420 } | 420 } |
| 421 | 421 |
| 422 } // namespace ui | 422 } // namespace ui |
| OLD | NEW |