Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: ui/ozone/platform/dri/dri_wrapper.cc

Issue 960273003: ozone: dri: add synchronous SwapBuffers support on surfaceless (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/platform/dri/dri_wrapper.h ('k') | ui/ozone/platform/dri/gbm_surfaceless.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 void SetPaused(bool paused) {
111 if (paused_ == paused)
112 return;
113
114 paused_ = paused;
115 base::WaitableEvent done(false, false);
116 io_task_runner_->PostTask(
117 FROM_HERE, base::Bind(&IOWatcher::SetPausedOnIO, this, &done));
110 } 118 }
111 119
112 void Shutdown() { 120 void Shutdown() {
113 io_task_runner_->PostTask(FROM_HERE, 121 if (!paused_)
114 base::Bind(&IOWatcher::UnregisterOnIO, this)); 122 io_task_runner_->PostTask(FROM_HERE,
123 base::Bind(&IOWatcher::UnregisterOnIO, this));
115 } 124 }
116 125
117 private: 126 private:
118 friend class base::RefCountedThreadSafe<IOWatcher>; 127 friend class base::RefCountedThreadSafe<IOWatcher>;
119 128
120 ~IOWatcher() override {} 129 ~IOWatcher() override { SetPaused(true); }
121 130
122 void RegisterOnIO(int fd) { 131 void RegisterOnIO() {
123 DCHECK(base::MessageLoopForIO::IsCurrent()); 132 DCHECK(base::MessageLoopForIO::IsCurrent());
124 base::MessageLoopForIO::current()->WatchFileDescriptor( 133 base::MessageLoopForIO::current()->WatchFileDescriptor(
125 fd, true, base::MessageLoopForIO::WATCH_READ, &controller_, this); 134 fd_, true, base::MessageLoopForIO::WATCH_READ, &controller_, this);
126 } 135 }
127 136
128 void UnregisterOnIO() { 137 void UnregisterOnIO() {
129 DCHECK(base::MessageLoopForIO::IsCurrent()); 138 DCHECK(base::MessageLoopForIO::IsCurrent());
130 controller_.StopWatchingFileDescriptor(); 139 controller_.StopWatchingFileDescriptor();
131 } 140 }
132 141
142 void SetPausedOnIO(base::WaitableEvent* done) {
143 DCHECK(base::MessageLoopForIO::IsCurrent());
144 if (paused_)
145 UnregisterOnIO();
146 else
147 RegisterOnIO();
148 done->Signal();
149 }
150
133 // base::MessagePumpLibevent::Watcher overrides: 151 // base::MessagePumpLibevent::Watcher overrides:
134 void OnFileCanReadWithoutBlocking(int fd) override { 152 void OnFileCanReadWithoutBlocking(int fd) override {
135 DCHECK(base::MessageLoopForIO::IsCurrent()); 153 DCHECK(base::MessageLoopForIO::IsCurrent());
136 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd); 154 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd);
137 155
138 drmEventContext event; 156 drmEventContext event;
139 event.version = DRM_EVENT_CONTEXT_VERSION; 157 event.version = DRM_EVENT_CONTEXT_VERSION;
140 event.page_flip_handler = HandlePageFlipEventOnIO; 158 event.page_flip_handler = HandlePageFlipEventOnIO;
141 event.vblank_handler = nullptr; 159 event.vblank_handler = nullptr;
142 160
143 drmHandleEvent(fd, &event); 161 drmHandleEvent(fd, &event);
144 } 162 }
145 163
146 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } 164 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); }
147 165
148 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 166 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
149 167
150 base::MessagePumpLibevent::FileDescriptorWatcher controller_; 168 base::MessagePumpLibevent::FileDescriptorWatcher controller_;
151 169
170 bool paused_;
171 int fd_;
172
152 DISALLOW_COPY_AND_ASSIGN(IOWatcher); 173 DISALLOW_COPY_AND_ASSIGN(IOWatcher);
153 }; 174 };
154 175
155 DriWrapper::DriWrapper(const base::FilePath& device_path) 176 DriWrapper::DriWrapper(const base::FilePath& device_path)
156 : device_path_(device_path), 177 : device_path_(device_path),
157 file_(device_path, 178 file_(device_path,
158 base::File::FLAG_OPEN | base::File::FLAG_READ | 179 base::File::FLAG_OPEN | base::File::FLAG_READ |
159 base::File::FLAG_WRITE) { 180 base::File::FLAG_WRITE) {
160 LOG_IF(FATAL, !file_.IsValid()) 181 LOG_IF(FATAL, !file_.IsValid())
161 << "Failed to open '" << device_path_.value() 182 << "Failed to open '" << device_path_.value()
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 284
264 bool DriWrapper::RemoveFramebuffer(uint32_t framebuffer) { 285 bool DriWrapper::RemoveFramebuffer(uint32_t framebuffer) {
265 DCHECK(file_.IsValid()); 286 DCHECK(file_.IsValid());
266 TRACE_EVENT1("dri", "DriWrapper::RemoveFramebuffer", 287 TRACE_EVENT1("dri", "DriWrapper::RemoveFramebuffer",
267 "framebuffer", framebuffer); 288 "framebuffer", framebuffer);
268 return !drmModeRmFB(file_.GetPlatformFile(), framebuffer); 289 return !drmModeRmFB(file_.GetPlatformFile(), framebuffer);
269 } 290 }
270 291
271 bool DriWrapper::PageFlip(uint32_t crtc_id, 292 bool DriWrapper::PageFlip(uint32_t crtc_id,
272 uint32_t framebuffer, 293 uint32_t framebuffer,
294 bool is_sync,
273 const PageFlipCallback& callback) { 295 const PageFlipCallback& callback) {
274 DCHECK(file_.IsValid()); 296 DCHECK(file_.IsValid());
275 TRACE_EVENT2("dri", "DriWrapper::PageFlip", 297 TRACE_EVENT2("dri", "DriWrapper::PageFlip",
276 "crtc", crtc_id, 298 "crtc", crtc_id,
277 "framebuffer", framebuffer); 299 "framebuffer", framebuffer);
278 300
301 if (watcher_)
302 watcher_->SetPaused(is_sync);
303
279 // NOTE: Calling drmModeSetCrtc will immediately update the state, though 304 // NOTE: Calling drmModeSetCrtc will immediately update the state, though
280 // callbacks to already scheduled page flips will be honored by the kernel. 305 // callbacks to already scheduled page flips will be honored by the kernel.
281 scoped_ptr<PageFlipPayload> payload( 306 scoped_ptr<PageFlipPayload> payload(
282 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback)); 307 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback));
283 if (!drmModePageFlip(file_.GetPlatformFile(), crtc_id, framebuffer, 308 if (!drmModePageFlip(file_.GetPlatformFile(), crtc_id, framebuffer,
284 DRM_MODE_PAGE_FLIP_EVENT, payload.get())) { 309 DRM_MODE_PAGE_FLIP_EVENT, payload.get())) {
285 // If successful the payload will be removed by a PageFlip event. 310 // If successful the payload will be removed by a PageFlip event.
286 ignore_result(payload.release()); 311 ignore_result(payload.release());
287 312
288 // If a task runner isn't installed then fall back to synchronously handling 313 // If the flip was requested synchronous or if no watcher has been installed
289 // the page flip events. 314 // yet, then synchronously handle the page flip events.
290 if (!task_runner_) { 315 if (is_sync || !watcher_) {
291 TRACE_EVENT1("dri", "OnDrmEvent", "socket", file_.GetPlatformFile()); 316 TRACE_EVENT1("dri", "OnDrmEvent", "socket", file_.GetPlatformFile());
292 317
293 drmEventContext event; 318 drmEventContext event;
294 event.version = DRM_EVENT_CONTEXT_VERSION; 319 event.version = DRM_EVENT_CONTEXT_VERSION;
295 event.page_flip_handler = HandlePageFlipEventOnUI; 320 event.page_flip_handler = HandlePageFlipEventOnUI;
296 event.vblank_handler = nullptr; 321 event.vblank_handler = nullptr;
297 322
298 drmHandleEvent(file_.GetPlatformFile(), &event); 323 drmHandleEvent(file_.GetPlatformFile(), &event);
299 } 324 }
300 325
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 DCHECK(file_.IsValid()); 452 DCHECK(file_.IsValid());
428 return (drmSetMaster(file_.GetPlatformFile()) == 0); 453 return (drmSetMaster(file_.GetPlatformFile()) == 0);
429 } 454 }
430 455
431 bool DriWrapper::DropMaster() { 456 bool DriWrapper::DropMaster() {
432 DCHECK(file_.IsValid()); 457 DCHECK(file_.IsValid());
433 return (drmDropMaster(file_.GetPlatformFile()) == 0); 458 return (drmDropMaster(file_.GetPlatformFile()) == 0);
434 } 459 }
435 460
436 } // namespace ui 461 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/dri_wrapper.h ('k') | ui/ozone/platform/dri/gbm_surfaceless.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698