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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/ozone/platform/drm/gpu/drm_thread.cc
diff --git a/ui/ozone/platform/drm/gpu/drm_thread.cc b/ui/ozone/platform/drm/gpu/drm_thread.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2a2855d0617ff5537fc48539cf9bbe706ee7ec64
--- /dev/null
+++ b/ui/ozone/platform/drm/gpu/drm_thread.cc
@@ -0,0 +1,126 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/ozone/platform/drm/gpu/drm_thread.h"
+
+#include "base/command_line.h"
+#include "base/thread_task_runner_handle.h"
+#include "ui/ozone/platform/drm/gpu/drm_buffer.h"
+#include "ui/ozone/platform/drm/gpu/drm_device_generator.h"
+#include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
+#include "ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h"
+#include "ui/ozone/platform/drm/gpu/drm_gpu_platform_support.h"
+#include "ui/ozone/platform/drm/gpu/drm_gpu_platform_support_proxy.h"
+#include "ui/ozone/platform/drm/gpu/drm_window.h"
+#include "ui/ozone/platform/drm/gpu/gbm_buffer.h"
+#include "ui/ozone/platform/drm/gpu/gbm_device.h"
+#include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h"
+#include "ui/ozone/platform/drm/gpu/proxy_helpers.h"
+#include "ui/ozone/platform/drm/gpu/screen_manager.h"
+#include "ui/ozone/public/ozone_switches.h"
+
+namespace ui {
+
+namespace {
+
+class GbmBufferGenerator : public ScanoutBufferGenerator {
+ public:
+ GbmBufferGenerator() {}
+ ~GbmBufferGenerator() override {}
+
+ // ScanoutBufferGenerator:
+ scoped_refptr<ScanoutBuffer> Create(const scoped_refptr<DrmDevice>& drm,
+ gfx::BufferFormat format,
+ const gfx::Size& size) override {
+ scoped_refptr<GbmDevice> gbm(static_cast<GbmDevice*>(drm.get()));
+ return GbmBuffer::CreateBuffer(gbm, format, size,
+ gfx::BufferUsage::SCANOUT);
+ }
+
+ protected:
+ DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator);
+};
+
+class GbmDeviceGenerator : public DrmDeviceGenerator {
+ public:
+ GbmDeviceGenerator(bool use_atomic) : use_atomic_(use_atomic) {}
+ ~GbmDeviceGenerator() override {}
+
+ // DrmDeviceGenerator:
+ scoped_refptr<DrmDevice> CreateDevice(const base::FilePath& path,
+ base::File file) override {
+ scoped_refptr<DrmDevice> drm = new GbmDevice(path, file.Pass());
+ if (drm->Initialize(use_atomic_))
+ return drm;
+
+ return nullptr;
+ }
+
+ private:
+ bool use_atomic_;
+
+ DISALLOW_COPY_AND_ASSIGN(GbmDeviceGenerator);
+};
+
+} // namespace
+
+DrmThread::DrmThread() : base::Thread("DrmThread") {}
+
+DrmThread::~DrmThread() {
+ Stop();
+}
+
+void DrmThread::Start() {
+ if (!StartWithOptions(base::Thread::Options(base::MessageLoop::TYPE_IO, 0)))
+ LOG(FATAL) << "Failed to create DRM thread";
+}
+
+base::WeakPtr<DrmGpuPlatformSupport> DrmThread::GetGpuPlatformSupport() const {
+ base::WeakPtr<DrmGpuPlatformSupport> support;
+ PostSyncTask(task_runner(),
+ base::Bind(&DrmThread::GetGpuPlatformSupportOnThread,
+ base::Unretained(this), &support));
+ return support;
+}
+
+base::WeakPtr<DrmWindow> DrmThread::GetWindow(
+ gfx::AcceleratedWidget widget) const {
+ base::WeakPtr<DrmWindow> window;
+ PostSyncTask(task_runner(),
+ base::Bind(&DrmThread::GetWindowOnThread, base::Unretained(this),
+ widget, &window));
+ return window;
+}
+
+void DrmThread::Init() {
+ bool use_atomic = false;
+#if defined(USE_DRM_ATOMIC)
+ use_atomic = true;
+#endif
+
+ device_manager_.reset(new DrmDeviceManager(
+ make_scoped_ptr(new GbmDeviceGenerator(use_atomic))));
+ buffer_generator_.reset(new GbmBufferGenerator());
+ screen_manager_.reset(new ScreenManager(buffer_generator_.get()));
+
+ scoped_ptr<DrmGpuDisplayManager> display_manager(
+ new DrmGpuDisplayManager(screen_manager_.get(), device_manager_.get()));
+ gpu_platform_support_.reset(new DrmGpuPlatformSupport(
+ device_manager_.get(), screen_manager_.get(), buffer_generator_.get(),
+ display_manager.Pass()));
+}
+
+void DrmThread::GetGpuPlatformSupportOnThread(
+ base::WeakPtr<DrmGpuPlatformSupport>* support) const {
+ *support = gpu_platform_support_->AsWeakPtr();
+}
+
+void DrmThread::GetWindowOnThread(gfx::AcceleratedWidget widget,
+ base::WeakPtr<DrmWindow>* weak_window) const {
+ DrmWindow* window = screen_manager_->GetWindow(widget);
+ if (window)
+ *weak_window = window->AsWeakPtr();
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698