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

Side by Side Diff: ui/ozone/platform/drm/gpu/drm_thread.cc

Issue 1311043016: Switch DRM platform to using a separate thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mv-drm-calls-on-thread2
Patch Set: . Created 5 years, 3 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/ozone/platform/drm/gpu/drm_thread.h"
6
7 #include "base/command_line.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "ui/ozone/platform/drm/gpu/drm_buffer.h"
10 #include "ui/ozone/platform/drm/gpu/drm_device_generator.h"
11 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
12 #include "ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h"
13 #include "ui/ozone/platform/drm/gpu/drm_gpu_platform_support.h"
14 #include "ui/ozone/platform/drm/gpu/drm_gpu_platform_support_proxy.h"
15 #include "ui/ozone/platform/drm/gpu/drm_window.h"
16 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h"
17 #include "ui/ozone/platform/drm/gpu/gbm_device.h"
18 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h"
19 #include "ui/ozone/platform/drm/gpu/proxy_helpers.h"
20 #include "ui/ozone/platform/drm/gpu/screen_manager.h"
21 #include "ui/ozone/public/ozone_switches.h"
22
23 namespace ui {
24
25 namespace {
26
27 class GbmBufferGenerator : public ScanoutBufferGenerator {
28 public:
29 GbmBufferGenerator() {}
30 ~GbmBufferGenerator() override {}
31
32 // ScanoutBufferGenerator:
33 scoped_refptr<ScanoutBuffer> Create(const scoped_refptr<DrmDevice>& drm,
34 gfx::BufferFormat format,
35 const gfx::Size& size) override {
36 scoped_refptr<GbmDevice> gbm(static_cast<GbmDevice*>(drm.get()));
37 return GbmBuffer::CreateBuffer(gbm, format, size,
38 gfx::BufferUsage::SCANOUT);
39 }
40
41 protected:
42 DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator);
43 };
44
45 class GbmDeviceGenerator : public DrmDeviceGenerator {
46 public:
47 GbmDeviceGenerator(bool use_atomic) : use_atomic_(use_atomic) {}
48 ~GbmDeviceGenerator() override {}
49
50 // DrmDeviceGenerator:
51 scoped_refptr<DrmDevice> CreateDevice(const base::FilePath& path,
52 base::File file) override {
53 scoped_refptr<DrmDevice> drm = new GbmDevice(path, file.Pass());
54 if (drm->Initialize(use_atomic_))
55 return drm;
56
57 return nullptr;
58 }
59
60 private:
61 bool use_atomic_;
62
63 DISALLOW_COPY_AND_ASSIGN(GbmDeviceGenerator);
64 };
65
66 } // namespace
67
68 DrmThread::DrmThread() : base::Thread("DrmThread") {}
69
70 DrmThread::~DrmThread() {
71 Stop();
72 }
73
74 void DrmThread::Start() {
75 if (!StartWithOptions(base::Thread::Options(base::MessageLoop::TYPE_IO, 0)))
76 LOG(FATAL) << "Failed to create DRM thread";
77 }
78
79 base::WeakPtr<DrmGpuPlatformSupport> DrmThread::GetGpuPlatformSupport() const {
80 base::WeakPtr<DrmGpuPlatformSupport> support;
81 PostSyncTask(task_runner(),
82 base::Bind(&DrmThread::GetGpuPlatformSupportOnThread,
83 base::Unretained(this), &support));
84 return support;
85 }
86
87 base::WeakPtr<DrmWindow> DrmThread::GetWindow(
88 gfx::AcceleratedWidget widget) const {
89 base::WeakPtr<DrmWindow> window;
90 PostSyncTask(task_runner(),
91 base::Bind(&DrmThread::GetWindowOnThread, base::Unretained(this),
92 widget, &window));
93 return window;
94 }
95
96 void DrmThread::Init() {
97 bool use_atomic = false;
98 #if defined(USE_DRM_ATOMIC)
99 use_atomic = true;
100 #endif
101
102 device_manager_.reset(new DrmDeviceManager(
103 make_scoped_ptr(new GbmDeviceGenerator(use_atomic))));
104 buffer_generator_.reset(new GbmBufferGenerator());
105 screen_manager_.reset(new ScreenManager(buffer_generator_.get()));
106
107 scoped_ptr<DrmGpuDisplayManager> display_manager(
108 new DrmGpuDisplayManager(screen_manager_.get(), device_manager_.get()));
109 gpu_platform_support_.reset(new DrmGpuPlatformSupport(
110 device_manager_.get(), screen_manager_.get(), buffer_generator_.get(),
111 display_manager.Pass()));
112 }
113
114 void DrmThread::GetGpuPlatformSupportOnThread(
115 base::WeakPtr<DrmGpuPlatformSupport>* support) const {
116 *support = gpu_platform_support_->AsWeakPtr();
117 }
118
119 void DrmThread::GetWindowOnThread(gfx::AcceleratedWidget widget,
120 base::WeakPtr<DrmWindow>* weak_window) const {
121 DrmWindow* window = screen_manager_->GetWindow(widget);
122 if (window)
123 *weak_window = window->AsWeakPtr();
124 }
125
126 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698