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

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
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/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_util.h" 20 #include "ui/ozone/platform/dri/dri_util.h"
21 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h" 21 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h"
22 #include "ui/ozone/platform/dri/io_helper_thread.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)
30 : task_runner(task_runner), callback(callback) {} 31 : task_runner(task_runner), callback(callback) {}
31 32
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, IOHelperThread* io_thread)
148 : fd_(-1), 149 : fd_(-1), device_path_(device_path), io_thread_(io_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 if (!io_thread_->IsRunning())
alexst (slow to review) 2015/01/22 15:27:48 We should do this in https://code.google.com/p/chr
dnicoara 2015/01/22 22:50:14 Done.
173 if (!io_thread_.StartWithOptions( 171 io_thread_->Initialize();
174 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)))
175 LOG(FATAL) << "Failed to start the IO helper thread";
176 172
177 watcher_ = new IOWatcher(fd_, io_thread_.task_runner()); 173 if (!watcher_)
178 } 174 watcher_ = new IOWatcher(fd_, io_thread_->task_runner());
179 } 175 }
180 176
181 ScopedDrmCrtcPtr DriWrapper::GetCrtc(uint32_t crtc_id) { 177 ScopedDrmCrtcPtr DriWrapper::GetCrtc(uint32_t crtc_id) {
182 DCHECK(fd_ >= 0); 178 DCHECK(fd_ >= 0);
183 return ScopedDrmCrtcPtr(drmModeGetCrtc(fd_, crtc_id)); 179 return ScopedDrmCrtcPtr(drmModeGetCrtc(fd_, crtc_id));
184 } 180 }
185 181
186 bool DriWrapper::SetCrtc(uint32_t crtc_id, 182 bool DriWrapper::SetCrtc(uint32_t crtc_id,
187 uint32_t framebuffer, 183 uint32_t framebuffer,
188 std::vector<uint32_t> connectors, 184 std::vector<uint32_t> connectors,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 "framebuffer", framebuffer); 267 "framebuffer", framebuffer);
272 268
273 // NOTE: Calling drmModeSetCrtc will immediately update the state, though 269 // NOTE: Calling drmModeSetCrtc will immediately update the state, though
274 // callbacks to already scheduled page flips will be honored by the kernel. 270 // callbacks to already scheduled page flips will be honored by the kernel.
275 scoped_ptr<PageFlipPayload> payload( 271 scoped_ptr<PageFlipPayload> payload(
276 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback)); 272 new PageFlipPayload(base::ThreadTaskRunnerHandle::Get(), callback));
277 if (!drmModePageFlip(fd_, crtc_id, framebuffer, DRM_MODE_PAGE_FLIP_EVENT, 273 if (!drmModePageFlip(fd_, crtc_id, framebuffer, DRM_MODE_PAGE_FLIP_EVENT,
278 payload.get())) { 274 payload.get())) {
279 // If successful the payload will be removed by a PageFlip event. 275 // If successful the payload will be removed by a PageFlip event.
280 ignore_result(payload.release()); 276 ignore_result(payload.release());
281 if (use_sync_flips_) { 277 if (!io_thread_) {
282 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd_); 278 TRACE_EVENT1("dri", "OnDrmEvent", "socket", fd_);
283 279
284 drmEventContext event; 280 drmEventContext event;
285 event.version = DRM_EVENT_CONTEXT_VERSION; 281 event.version = DRM_EVENT_CONTEXT_VERSION;
286 event.page_flip_handler = HandlePageFlipEventOnUI; 282 event.page_flip_handler = HandlePageFlipEventOnUI;
287 event.vblank_handler = nullptr; 283 event.vblank_handler = nullptr;
288 284
289 drmHandleEvent(fd_, &event); 285 drmHandleEvent(fd_, &event);
290 } else { 286 } else {
291 InitializeIOWatcher(); 287 InitializeIOWatcher();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 DCHECK(fd_ >= 0); 409 DCHECK(fd_ >= 0);
414 return (drmSetMaster(fd_) == 0); 410 return (drmSetMaster(fd_) == 0);
415 } 411 }
416 412
417 bool DriWrapper::DropMaster() { 413 bool DriWrapper::DropMaster() {
418 DCHECK(fd_ >= 0); 414 DCHECK(fd_ >= 0);
419 return (drmDropMaster(fd_) == 0); 415 return (drmDropMaster(fd_) == 0);
420 } 416 }
421 417
422 } // namespace ui 418 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698