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_(true), fd_(fd) { |
108 io_task_runner_->PostTask(FROM_HERE, | 109 } |
109 base::Bind(&IOWatcher::RegisterOnIO, this, fd)); | 110 |
111 void SetPaused(bool paused) { | |
112 paused = !!paused; | |
dnicoara
2015/02/26 22:16:29
remove this
llandwerlin-old
2015/02/27 10:56:47
Done.
| |
113 if (paused_ == paused) | |
114 return; | |
115 | |
116 paused_ = paused; | |
117 base::WaitableEvent done(false, false); | |
118 io_task_runner_->PostTask( | |
119 FROM_HERE, base::Bind(&IOWatcher::SetPausedOnIO, this, &done)); | |
110 } | 120 } |
111 | 121 |
112 void Shutdown() { | 122 void Shutdown() { |
113 io_task_runner_->PostTask(FROM_HERE, | 123 if (!paused_) |
114 base::Bind(&IOWatcher::UnregisterOnIO, this)); | 124 io_task_runner_->PostTask(FROM_HERE, |
125 base::Bind(&IOWatcher::UnregisterOnIO, this)); | |
115 } | 126 } |
116 | 127 |
117 private: | 128 private: |
118 friend class base::RefCountedThreadSafe<IOWatcher>; | 129 friend class base::RefCountedThreadSafe<IOWatcher>; |
119 | 130 |
120 ~IOWatcher() override {} | 131 ~IOWatcher() override { |
132 SetPaused(true); | |
133 } | |
121 | 134 |
122 void RegisterOnIO(int fd) { | 135 void RegisterOnIO() { |
123 DCHECK(base::MessageLoopForIO::IsCurrent()); | 136 DCHECK(base::MessageLoopForIO::IsCurrent()); |
124 base::MessageLoopForIO::current()->WatchFileDescriptor( | 137 base::MessageLoopForIO::current()->WatchFileDescriptor( |
125 fd, true, base::MessageLoopForIO::WATCH_READ, &controller_, this); | 138 fd_, true, base::MessageLoopForIO::WATCH_READ, &controller_, this); |
126 } | 139 } |
127 | 140 |
128 void UnregisterOnIO() { | 141 void UnregisterOnIO() { |
129 DCHECK(base::MessageLoopForIO::IsCurrent()); | 142 DCHECK(base::MessageLoopForIO::IsCurrent()); |
130 controller_.StopWatchingFileDescriptor(); | 143 controller_.StopWatchingFileDescriptor(); |
131 } | 144 } |
132 | 145 |
146 void SetPausedOnIO(base::WaitableEvent* done) { | |
147 DCHECK(base::MessageLoopForIO::IsCurrent()); | |
148 if (paused_) | |
149 UnregisterOnIO(); | |
150 else | |
151 RegisterOnIO(); | |
152 done->Signal(); | |
153 } | |
154 | |
133 // base::MessagePumpLibevent::Watcher overrides: | 155 // base::MessagePumpLibevent::Watcher overrides: |
134 void OnFileCanReadWithoutBlocking(int fd) override { | 156 void OnFileCanReadWithoutBlocking(int fd) override { |
135 DCHECK(base::MessageLoopForIO::IsCurrent()); | 157 DCHECK(base::MessageLoopForIO::IsCurrent()); |
136 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd); | 158 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd); |
137 | 159 |
138 drmEventContext event; | 160 drmEventContext event; |
139 event.version = DRM_EVENT_CONTEXT_VERSION; | 161 event.version = DRM_EVENT_CONTEXT_VERSION; |
140 event.page_flip_handler = HandlePageFlipEventOnIO; | 162 event.page_flip_handler = HandlePageFlipEventOnIO; |
141 event.vblank_handler = nullptr; | 163 event.vblank_handler = nullptr; |
142 | 164 |
143 drmHandleEvent(fd, &event); | 165 drmHandleEvent(fd, &event); |
144 } | 166 } |
145 | 167 |
146 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } | 168 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } |
147 | 169 |
148 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 170 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
149 | 171 |
150 base::MessagePumpLibevent::FileDescriptorWatcher controller_; | 172 base::MessagePumpLibevent::FileDescriptorWatcher controller_; |
151 | 173 |
174 bool paused_; | |
175 int fd_; | |
176 | |
152 DISALLOW_COPY_AND_ASSIGN(IOWatcher); | 177 DISALLOW_COPY_AND_ASSIGN(IOWatcher); |
153 }; | 178 }; |
154 | 179 |
155 DriWrapper::DriWrapper(const base::FilePath& device_path) | 180 DriWrapper::DriWrapper(const base::FilePath& device_path) |
156 : device_path_(device_path), | 181 : device_path_(device_path), |
157 file_(device_path, | 182 file_(device_path, |
158 base::File::FLAG_OPEN | base::File::FLAG_READ | | 183 base::File::FLAG_OPEN | base::File::FLAG_READ | |
159 base::File::FLAG_WRITE) { | 184 base::File::FLAG_WRITE) { |
160 LOG_IF(FATAL, !file_.IsValid()) | 185 LOG_IF(FATAL, !file_.IsValid()) |
161 << "Failed to open '" << device_path_.value() | 186 << "Failed to open '" << device_path_.value() |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 | 288 |
264 bool DriWrapper::RemoveFramebuffer(uint32_t framebuffer) { | 289 bool DriWrapper::RemoveFramebuffer(uint32_t framebuffer) { |
265 DCHECK(file_.IsValid()); | 290 DCHECK(file_.IsValid()); |
266 TRACE_EVENT1("dri", "DriWrapper::RemoveFramebuffer", | 291 TRACE_EVENT1("dri", "DriWrapper::RemoveFramebuffer", |
267 "framebuffer", framebuffer); | 292 "framebuffer", framebuffer); |
268 return !drmModeRmFB(file_.GetPlatformFile(), framebuffer); | 293 return !drmModeRmFB(file_.GetPlatformFile(), framebuffer); |
269 } | 294 } |
270 | 295 |
271 bool DriWrapper::PageFlip(uint32_t crtc_id, | 296 bool DriWrapper::PageFlip(uint32_t crtc_id, |
272 uint32_t framebuffer, | 297 uint32_t framebuffer, |
298 bool is_sync, | |
273 const PageFlipCallback& callback) { | 299 const PageFlipCallback& callback) { |
274 DCHECK(file_.IsValid()); | 300 DCHECK(file_.IsValid()); |
275 TRACE_EVENT2("dri", "DriWrapper::PageFlip", | 301 TRACE_EVENT2("dri", "DriWrapper::PageFlip", |
276 "crtc", crtc_id, | 302 "crtc", crtc_id, |
277 "framebuffer", framebuffer); | 303 "framebuffer", framebuffer); |
278 | 304 |
305 if (watcher_) | |
306 watcher_->SetPaused(is_sync); | |
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 no watcher has been installed |
289 // the page flip events. | 318 // yet, then synchronously handle the page flip events. |
290 if (!task_runner_) { | 319 if (is_sync || !watcher_) { |
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 |