| 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> |
| 11 #include <xf86drmMode.h> | 11 #include <xf86drmMode.h> |
| 12 | 12 |
| 13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.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 "third_party/skia/include/core/SkImageInfo.h" | 19 #include "third_party/skia/include/core/SkImageInfo.h" |
| 20 #include "ui/ozone/platform/dri/dri_helper_thread.h" |
| 20 #include "ui/ozone/platform/dri/dri_util.h" | 21 #include "ui/ozone/platform/dri/dri_util.h" |
| 21 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h" | 22 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h" |
| 22 | 23 |
| 23 namespace ui { | 24 namespace ui { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 struct PageFlipPayload { | 28 struct PageFlipPayload { |
| 28 PageFlipPayload(const scoped_refptr<base::TaskRunner>& task_runner, | 29 PageFlipPayload(const scoped_refptr<base::TaskRunner>& task_runner, |
| 29 const DriWrapper::PageFlipCallback& callback) | 30 const DriWrapper::PageFlipCallback& callback) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 138 |
| 138 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } | 139 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } |
| 139 | 140 |
| 140 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 141 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 141 | 142 |
| 142 base::MessagePumpLibevent::FileDescriptorWatcher controller_; | 143 base::MessagePumpLibevent::FileDescriptorWatcher controller_; |
| 143 | 144 |
| 144 DISALLOW_COPY_AND_ASSIGN(IOWatcher); | 145 DISALLOW_COPY_AND_ASSIGN(IOWatcher); |
| 145 }; | 146 }; |
| 146 | 147 |
| 147 DriWrapper::DriWrapper(const char* device_path, bool use_sync_flips) | 148 DriWrapper::DriWrapper(const char* device_path, DriHelperThread* helper_thread) |
| 148 : fd_(-1), | 149 : fd_(-1), device_path_(device_path), helper_thread_(helper_thread) { |
| 149 use_sync_flips_(use_sync_flips), | |
| 150 device_path_(device_path), | |
| 151 io_thread_("DriIOThread") { | |
| 152 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); | 150 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); |
| 153 } | 151 } |
| 154 | 152 |
| 155 DriWrapper::~DriWrapper() { | 153 DriWrapper::~DriWrapper() { |
| 156 if (fd_ >= 0) | 154 if (fd_ >= 0) |
| 157 close(fd_); | 155 close(fd_); |
| 158 | 156 |
| 159 if (watcher_) | 157 if (watcher_) |
| 160 watcher_->Shutdown(); | 158 watcher_->Shutdown(); |
| 161 } | 159 } |
| 162 | 160 |
| 163 void DriWrapper::Initialize() { | 161 void DriWrapper::Initialize() { |
| 164 fd_ = open(device_path_, O_RDWR | O_CLOEXEC); | 162 fd_ = open(device_path_, O_RDWR | O_CLOEXEC); |
| 165 if (fd_ < 0) | 163 if (fd_ < 0) |
| 166 PLOG(FATAL) << "open: " << device_path_; | 164 PLOG(FATAL) << "open: " << device_path_; |
| 167 if (!plane_manager_->Initialize(this)) | 165 if (!plane_manager_->Initialize(this)) |
| 168 LOG(ERROR) << "Failed to initialize the plane manager"; | 166 LOG(ERROR) << "Failed to initialize the plane manager"; |
| 169 } | 167 } |
| 170 | 168 |
| 171 void DriWrapper::InitializeIOWatcher() { | 169 void DriWrapper::InitializeIOWatcher() { |
| 172 if (!use_sync_flips_ && !watcher_) { | 170 DCHECK(helper_thread_->IsRunning()); |
| 173 if (!io_thread_.StartWithOptions( | |
| 174 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) | |
| 175 LOG(FATAL) << "Failed to start the IO helper thread"; | |
| 176 | 171 |
| 177 watcher_ = new IOWatcher(fd_, io_thread_.task_runner()); | 172 if (!watcher_) |
| 178 } | 173 watcher_ = new IOWatcher(fd_, helper_thread_->task_runner()); |
| 179 } | 174 } |
| 180 | 175 |
| 181 ScopedDrmCrtcPtr DriWrapper::GetCrtc(uint32_t crtc_id) { | 176 ScopedDrmCrtcPtr DriWrapper::GetCrtc(uint32_t crtc_id) { |
| 182 DCHECK(fd_ >= 0); | 177 DCHECK(fd_ >= 0); |
| 183 return ScopedDrmCrtcPtr(drmModeGetCrtc(fd_, crtc_id)); | 178 return ScopedDrmCrtcPtr(drmModeGetCrtc(fd_, crtc_id)); |
| 184 } | 179 } |
| 185 | 180 |
| 186 bool DriWrapper::SetCrtc(uint32_t crtc_id, | 181 bool DriWrapper::SetCrtc(uint32_t crtc_id, |
| 187 uint32_t framebuffer, | 182 uint32_t framebuffer, |
| 188 std::vector<uint32_t> connectors, | 183 std::vector<uint32_t> connectors, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 "framebuffer", framebuffer); | 266 "framebuffer", framebuffer); |
| 272 | 267 |
| 273 // NOTE: Calling drmModeSetCrtc will immediately update the state, though | 268 // NOTE: Calling drmModeSetCrtc will immediately update the state, though |
| 274 // callbacks to already scheduled page flips will be honored by the kernel. | 269 // callbacks to already scheduled page flips will be honored by the kernel. |
| 275 scoped_ptr<PageFlipPayload> payload( | 270 scoped_ptr<PageFlipPayload> payload( |
| 276 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback)); | 271 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback)); |
| 277 if (!drmModePageFlip(fd_, crtc_id, framebuffer, DRM_MODE_PAGE_FLIP_EVENT, | 272 if (!drmModePageFlip(fd_, crtc_id, framebuffer, DRM_MODE_PAGE_FLIP_EVENT, |
| 278 payload.get())) { | 273 payload.get())) { |
| 279 // If successful the payload will be removed by a PageFlip event. | 274 // If successful the payload will be removed by a PageFlip event. |
| 280 ignore_result(payload.release()); | 275 ignore_result(payload.release()); |
| 281 if (use_sync_flips_) { | 276 if (!helper_thread_) { |
| 282 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd_); | 277 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd_); |
| 283 | 278 |
| 284 drmEventContext event; | 279 drmEventContext event; |
| 285 event.version = DRM_EVENT_CONTEXT_VERSION; | 280 event.version = DRM_EVENT_CONTEXT_VERSION; |
| 286 event.page_flip_handler = HandlePageFlipEventOnUI; | 281 event.page_flip_handler = HandlePageFlipEventOnUI; |
| 287 event.vblank_handler = nullptr; | 282 event.vblank_handler = nullptr; |
| 288 | 283 |
| 289 drmHandleEvent(fd_, &event); | 284 drmHandleEvent(fd_, &event); |
| 290 } else { | 285 } else { |
| 291 InitializeIOWatcher(); | 286 InitializeIOWatcher(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 DCHECK(fd_ >= 0); | 408 DCHECK(fd_ >= 0); |
| 414 return (drmSetMaster(fd_) == 0); | 409 return (drmSetMaster(fd_) == 0); |
| 415 } | 410 } |
| 416 | 411 |
| 417 bool DriWrapper::DropMaster() { | 412 bool DriWrapper::DropMaster() { |
| 418 DCHECK(fd_ >= 0); | 413 DCHECK(fd_ >= 0); |
| 419 return (drmDropMaster(fd_) == 0); | 414 return (drmDropMaster(fd_) == 0); |
| 420 } | 415 } |
| 421 | 416 |
| 422 } // namespace ui | 417 } // namespace ui |
| OLD | NEW |