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

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

Issue 856423002: [Ozone-Dri] Decouple the IO helper thread from DriWrapper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gbm-wrapper
Patch Set: . Created 5 years, 11 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_wrapper.h » ('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>
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 use_sync_flips) 147 DriWrapper::DriWrapper(const char* device_path)
148 : fd_(-1), 148 : fd_(-1), device_path_(device_path) {
149 use_sync_flips_(use_sync_flips),
150 device_path_(device_path),
151 io_thread_("DriIOThread") {
152 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); 149 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy());
153 } 150 }
154 151
155 DriWrapper::~DriWrapper() { 152 DriWrapper::~DriWrapper() {
156 if (fd_ >= 0) 153 if (fd_ >= 0)
157 close(fd_); 154 close(fd_);
158 155
159 if (watcher_) 156 if (watcher_)
160 watcher_->Shutdown(); 157 watcher_->Shutdown();
161 } 158 }
162 159
163 void DriWrapper::Initialize() { 160 void DriWrapper::Initialize() {
164 fd_ = open(device_path_, O_RDWR | O_CLOEXEC); 161 fd_ = open(device_path_, O_RDWR | O_CLOEXEC);
165 if (fd_ < 0) 162 if (fd_ < 0)
166 PLOG(FATAL) << "open: " << device_path_; 163 PLOG(FATAL) << "open: " << device_path_;
167 if (!plane_manager_->Initialize(this)) 164 if (!plane_manager_->Initialize(this))
168 LOG(ERROR) << "Failed to initialize the plane manager"; 165 LOG(ERROR) << "Failed to initialize the plane manager";
169 } 166 }
170 167
171 void DriWrapper::InitializeIOWatcher() { 168 void DriWrapper::InitializeTaskRunner(
172 if (!use_sync_flips_ && !watcher_) { 169 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
173 if (!io_thread_.StartWithOptions( 170 DCHECK(!task_runner_);
174 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) 171 task_runner_ = task_runner;
175 LOG(FATAL) << "Failed to start the IO helper thread"; 172 watcher_ = new IOWatcher(fd_, task_runner_);
176
177 watcher_ = new IOWatcher(fd_, io_thread_.task_runner());
178 }
179 } 173 }
180 174
181 ScopedDrmCrtcPtr DriWrapper::GetCrtc(uint32_t crtc_id) { 175 ScopedDrmCrtcPtr DriWrapper::GetCrtc(uint32_t crtc_id) {
182 DCHECK(fd_ >= 0); 176 DCHECK(fd_ >= 0);
183 return ScopedDrmCrtcPtr(drmModeGetCrtc(fd_, crtc_id)); 177 return ScopedDrmCrtcPtr(drmModeGetCrtc(fd_, crtc_id));
184 } 178 }
185 179
186 bool DriWrapper::SetCrtc(uint32_t crtc_id, 180 bool DriWrapper::SetCrtc(uint32_t crtc_id,
187 uint32_t framebuffer, 181 uint32_t framebuffer,
188 std::vector<uint32_t> connectors, 182 std::vector<uint32_t> connectors,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 "framebuffer", framebuffer); 265 "framebuffer", framebuffer);
272 266
273 // NOTE: Calling drmModeSetCrtc will immediately update the state, though 267 // NOTE: Calling drmModeSetCrtc will immediately update the state, though
274 // callbacks to already scheduled page flips will be honored by the kernel. 268 // callbacks to already scheduled page flips will be honored by the kernel.
275 scoped_ptr<PageFlipPayload> payload( 269 scoped_ptr<PageFlipPayload> payload(
276 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback)); 270 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback));
277 if (!drmModePageFlip(fd_, crtc_id, framebuffer, DRM_MODE_PAGE_FLIP_EVENT, 271 if (!drmModePageFlip(fd_, crtc_id, framebuffer, DRM_MODE_PAGE_FLIP_EVENT,
278 payload.get())) { 272 payload.get())) {
279 // If successful the payload will be removed by a PageFlip event. 273 // If successful the payload will be removed by a PageFlip event.
280 ignore_result(payload.release()); 274 ignore_result(payload.release());
281 if (use_sync_flips_) { 275
276 // If a task runner isn't installed then fall back to synchronously handling
277 // the page flip events.
278 if (!task_runner_) {
282 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd_); 279 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd_);
283 280
284 drmEventContext event; 281 drmEventContext event;
285 event.version = DRM_EVENT_CONTEXT_VERSION; 282 event.version = DRM_EVENT_CONTEXT_VERSION;
286 event.page_flip_handler = HandlePageFlipEventOnUI; 283 event.page_flip_handler = HandlePageFlipEventOnUI;
287 event.vblank_handler = nullptr; 284 event.vblank_handler = nullptr;
288 285
289 drmHandleEvent(fd_, &event); 286 drmHandleEvent(fd_, &event);
290 } else {
291 InitializeIOWatcher();
292 } 287 }
293 288
294 return true; 289 return true;
295 } 290 }
296 291
297 return false; 292 return false;
298 } 293 }
299 294
300 bool DriWrapper::PageFlipOverlay(uint32_t crtc_id, 295 bool DriWrapper::PageFlipOverlay(uint32_t crtc_id,
301 uint32_t framebuffer, 296 uint32_t framebuffer,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/dri_wrapper.h ('k') | ui/ozone/platform/dri/gbm_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698