Chromium Code Reviews| 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/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/task_runner.h" | 17 #include "base/task_runner.h" |
| 17 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 18 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 19 #include "third_party/skia/include/core/SkImageInfo.h" | 20 #include "third_party/skia/include/core/SkImageInfo.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 { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 } | 98 } |
| 98 | 99 |
| 99 } // namespace | 100 } // namespace |
| 100 | 101 |
| 101 class DriWrapper::IOWatcher | 102 class DriWrapper::IOWatcher |
| 102 : public base::RefCountedThreadSafe<DriWrapper::IOWatcher>, | 103 : public base::RefCountedThreadSafe<DriWrapper::IOWatcher>, |
| 103 public base::MessagePumpLibevent::Watcher { | 104 public base::MessagePumpLibevent::Watcher { |
| 104 public: | 105 public: |
| 105 IOWatcher(int fd, | 106 IOWatcher(int fd, |
| 106 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 107 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
| 107 : io_task_runner_(io_task_runner) { | 108 : io_task_runner_(io_task_runner), paused_(false), fd_(fd) { |
| 108 io_task_runner_->PostTask(FROM_HERE, | 109 io_task_runner_->PostTask(FROM_HERE, |
|
dnicoara
2015/02/26 18:22:21
I think we should remove this since the call to Se
llandwerlin-old
2015/02/26 22:02:56
Done.
| |
| 109 base::Bind(&IOWatcher::RegisterOnIO, this, fd)); | 110 base::Bind(&IOWatcher::RegisterOnIO, this)); |
| 111 } | |
| 112 | |
| 113 void SetPaused(bool value) { | |
|
dnicoara
2015/02/26 18:22:21
Just rename |value| to |paused| and remove the par
llandwerlin-old
2015/02/26 22:02:56
Done.
| |
| 114 bool paused = !!value; | |
| 115 if (paused_ == paused) | |
| 116 return; | |
| 117 | |
| 118 base::WaitableEvent done(false, false); | |
| 119 io_task_runner_->PostTask( | |
| 120 FROM_HERE, base::Bind(&IOWatcher::SetPausedOnIO, this, paused, &done)); | |
| 121 paused_ = paused; | |
| 110 } | 122 } |
| 111 | 123 |
| 112 void Shutdown() { | 124 void Shutdown() { |
|
dnicoara
2015/02/26 18:22:21
We should check if |paused_| is false and return i
llandwerlin-old
2015/02/26 22:02:56
Done.
| |
| 113 io_task_runner_->PostTask(FROM_HERE, | 125 io_task_runner_->PostTask(FROM_HERE, |
| 114 base::Bind(&IOWatcher::UnregisterOnIO, this)); | 126 base::Bind(&IOWatcher::UnregisterOnIO, this)); |
| 115 } | 127 } |
| 116 | 128 |
| 117 private: | 129 private: |
| 118 friend class base::RefCountedThreadSafe<IOWatcher>; | 130 friend class base::RefCountedThreadSafe<IOWatcher>; |
| 119 | 131 |
| 120 ~IOWatcher() override {} | 132 ~IOWatcher() override { |
| 133 SetPaused(true); | |
| 134 } | |
| 121 | 135 |
| 122 void RegisterOnIO(int fd) { | 136 void RegisterOnIO() { |
| 123 DCHECK(base::MessageLoopForIO::IsCurrent()); | 137 DCHECK(base::MessageLoopForIO::IsCurrent()); |
| 124 base::MessageLoopForIO::current()->WatchFileDescriptor( | 138 base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 125 fd, true, base::MessageLoopForIO::WATCH_READ, &controller_, this); | 139 fd_, true, base::MessageLoopForIO::WATCH_READ, &controller_, this); |
| 126 } | 140 } |
| 127 | 141 |
| 128 void UnregisterOnIO() { | 142 void UnregisterOnIO() { |
| 129 DCHECK(base::MessageLoopForIO::IsCurrent()); | 143 DCHECK(base::MessageLoopForIO::IsCurrent()); |
| 130 controller_.StopWatchingFileDescriptor(); | 144 controller_.StopWatchingFileDescriptor(); |
| 131 } | 145 } |
| 132 | 146 |
| 147 void SetPausedOnIO(bool paused, base::WaitableEvent* done) { | |
| 148 DCHECK(base::MessageLoopForIO::IsCurrent()); | |
| 149 if (paused) | |
| 150 UnregisterOnIO(); | |
| 151 else | |
| 152 RegisterOnIO(); | |
| 153 done->Signal(); | |
| 154 } | |
| 155 | |
| 133 // base::MessagePumpLibevent::Watcher overrides: | 156 // base::MessagePumpLibevent::Watcher overrides: |
| 134 void OnFileCanReadWithoutBlocking(int fd) override { | 157 void OnFileCanReadWithoutBlocking(int fd) override { |
| 135 DCHECK(base::MessageLoopForIO::IsCurrent()); | 158 DCHECK(base::MessageLoopForIO::IsCurrent()); |
| 136 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd); | 159 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd); |
| 137 | 160 |
| 138 drmEventContext event; | 161 drmEventContext event; |
| 139 event.version = DRM_EVENT_CONTEXT_VERSION; | 162 event.version = DRM_EVENT_CONTEXT_VERSION; |
| 140 event.page_flip_handler = HandlePageFlipEventOnIO; | 163 event.page_flip_handler = HandlePageFlipEventOnIO; |
| 141 event.vblank_handler = nullptr; | 164 event.vblank_handler = nullptr; |
| 142 | 165 |
| 143 drmHandleEvent(fd, &event); | 166 drmHandleEvent(fd, &event); |
| 144 } | 167 } |
| 145 | 168 |
| 146 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } | 169 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } |
| 147 | 170 |
| 148 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 171 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 149 | 172 |
| 150 base::MessagePumpLibevent::FileDescriptorWatcher controller_; | 173 base::MessagePumpLibevent::FileDescriptorWatcher controller_; |
| 151 | 174 |
| 175 bool paused_; | |
| 176 int fd_; | |
| 177 | |
| 152 DISALLOW_COPY_AND_ASSIGN(IOWatcher); | 178 DISALLOW_COPY_AND_ASSIGN(IOWatcher); |
| 153 }; | 179 }; |
| 154 | 180 |
| 155 DriWrapper::DriWrapper(const base::FilePath& device_path) | 181 DriWrapper::DriWrapper(const base::FilePath& device_path) |
| 156 : device_path_(device_path), | 182 : device_path_(device_path), |
| 157 file_(device_path, | 183 file_(device_path, |
| 158 base::File::FLAG_OPEN | base::File::FLAG_READ | | 184 base::File::FLAG_OPEN | base::File::FLAG_READ | |
| 159 base::File::FLAG_WRITE) { | 185 base::File::FLAG_WRITE) { |
| 160 LOG_IF(FATAL, !file_.IsValid()) | 186 LOG_IF(FATAL, !file_.IsValid()) |
| 161 << "Failed to open '" << device_path_.value() | 187 << "Failed to open '" << device_path_.value() |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 | 289 |
| 264 bool DriWrapper::RemoveFramebuffer(uint32_t framebuffer) { | 290 bool DriWrapper::RemoveFramebuffer(uint32_t framebuffer) { |
| 265 DCHECK(file_.IsValid()); | 291 DCHECK(file_.IsValid()); |
| 266 TRACE_EVENT1("dri", "DriWrapper::RemoveFramebuffer", | 292 TRACE_EVENT1("dri", "DriWrapper::RemoveFramebuffer", |
| 267 "framebuffer", framebuffer); | 293 "framebuffer", framebuffer); |
| 268 return !drmModeRmFB(file_.GetPlatformFile(), framebuffer); | 294 return !drmModeRmFB(file_.GetPlatformFile(), framebuffer); |
| 269 } | 295 } |
| 270 | 296 |
| 271 bool DriWrapper::PageFlip(uint32_t crtc_id, | 297 bool DriWrapper::PageFlip(uint32_t crtc_id, |
| 272 uint32_t framebuffer, | 298 uint32_t framebuffer, |
| 299 bool is_sync, | |
| 273 const PageFlipCallback& callback) { | 300 const PageFlipCallback& callback) { |
| 274 DCHECK(file_.IsValid()); | 301 DCHECK(file_.IsValid()); |
| 275 TRACE_EVENT2("dri", "DriWrapper::PageFlip", | 302 TRACE_EVENT2("dri", "DriWrapper::PageFlip", |
| 276 "crtc", crtc_id, | 303 "crtc", crtc_id, |
| 277 "framebuffer", framebuffer); | 304 "framebuffer", framebuffer); |
| 278 | 305 |
| 306 watcher_->SetPaused(is_sync); | |
|
dnicoara
2015/02/26 18:22:21
|watcher_| may not be initialized. you'll want to
llandwerlin-old
2015/02/26 22:02:56
Adding the check on watcher_, but on line 319 I st
| |
| 307 | |
| 279 // NOTE: Calling drmModeSetCrtc will immediately update the state, though | 308 // NOTE: Calling drmModeSetCrtc will immediately update the state, though |
| 280 // callbacks to already scheduled page flips will be honored by the kernel. | 309 // callbacks to already scheduled page flips will be honored by the kernel. |
| 281 scoped_ptr<PageFlipPayload> payload( | 310 scoped_ptr<PageFlipPayload> payload( |
| 282 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback)); | 311 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback)); |
| 283 if (!drmModePageFlip(file_.GetPlatformFile(), crtc_id, framebuffer, | 312 if (!drmModePageFlip(file_.GetPlatformFile(), crtc_id, framebuffer, |
| 284 DRM_MODE_PAGE_FLIP_EVENT, payload.get())) { | 313 DRM_MODE_PAGE_FLIP_EVENT, payload.get())) { |
| 285 // If successful the payload will be removed by a PageFlip event. | 314 // If successful the payload will be removed by a PageFlip event. |
| 286 ignore_result(payload.release()); | 315 ignore_result(payload.release()); |
| 287 | 316 |
| 288 // If a task runner isn't installed then fall back to synchronously handling | 317 // If the flip was requested synchronous or if a task runner isn't |
| 289 // the page flip events. | 318 // installed then synchronously handle the page flip events. |
| 290 if (!task_runner_) { | 319 if (is_sync || !task_runner_) { |
| 291 TRACE_EVENT1("dri", "OnDrmEvent", "socket", file_.GetPlatformFile()); | 320 TRACE_EVENT1("dri", "OnDrmEvent", "socket", file_.GetPlatformFile()); |
| 292 | 321 |
| 293 drmEventContext event; | 322 drmEventContext event; |
| 294 event.version = DRM_EVENT_CONTEXT_VERSION; | 323 event.version = DRM_EVENT_CONTEXT_VERSION; |
| 295 event.page_flip_handler = HandlePageFlipEventOnUI; | 324 event.page_flip_handler = HandlePageFlipEventOnUI; |
| 296 event.vblank_handler = nullptr; | 325 event.vblank_handler = nullptr; |
| 297 | 326 |
| 298 drmHandleEvent(file_.GetPlatformFile(), &event); | 327 drmHandleEvent(file_.GetPlatformFile(), &event); |
| 299 } | 328 } |
| 300 | 329 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 DCHECK(file_.IsValid()); | 456 DCHECK(file_.IsValid()); |
| 428 return (drmSetMaster(file_.GetPlatformFile()) == 0); | 457 return (drmSetMaster(file_.GetPlatformFile()) == 0); |
| 429 } | 458 } |
| 430 | 459 |
| 431 bool DriWrapper::DropMaster() { | 460 bool DriWrapper::DropMaster() { |
| 432 DCHECK(file_.IsValid()); | 461 DCHECK(file_.IsValid()); |
| 433 return (drmDropMaster(file_.GetPlatformFile()) == 0); | 462 return (drmDropMaster(file_.GetPlatformFile()) == 0); |
| 434 } | 463 } |
| 435 | 464 |
| 436 } // namespace ui | 465 } // namespace ui |
| OLD | NEW |