Commit 03d4a196 authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

[ozone/wayland/drm] Refactor and place gbm_device into shared place.

This CL is a part of Wayland gpu/ui split effort, which fixes the
Ozone/Wayland and makes it functional when the gpu service is running
out of the browser process.

The patch does not bring any functionality changes, but rather
prepares Ozone/Wayland for a dmabuf based approach, which uses ozone/drm code,
to be landed in the upstream.

In particular, gbm_device.cc/h is moved into a common folder in the
ui/ozone/common/linux and renamed to gbm_device_linux.cc/h. What is more,
it is refactored in such a way that it can be used by both Wayland with
dmabuf approach and ozone/drm.

This is only compiled for wayland(downstream now) and drm backends, and
does not bring any additional load on other backends.

Bug: 820047
Change-Id: I9eb4da474eb24d6d32fe355ff37b6d0806672fde
Reviewed-on: https://chromium-review.googlesource.com/1071889
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562613}
parent 61d07188
......@@ -48,6 +48,8 @@ if (ozone_platform_gbm) {
sources = [
"linux/drm_util_linux.cc",
"linux/drm_util_linux.h",
"linux/gbm_device_linux.cc",
"linux/gbm_device_linux.h",
"linux/overlay_plane.cc",
"linux/overlay_plane.h",
"linux/scanout_buffer.h",
......
// Copyright 2018 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/common/linux/gbm_device_linux.h"
#include <gbm.h>
namespace ui {
GbmDeviceLinux::GbmDeviceLinux() {}
GbmDeviceLinux::~GbmDeviceLinux() {
if (device_)
gbm_device_destroy(device_);
}
bool GbmDeviceLinux::InitializeGbmDevice(int fd) {
device_ = gbm_create_device(fd);
return !!device_;
}
} // namespace ui
// Copyright 2018 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.
#ifndef UI_OZONE_COMMON_LINUX_GBM_DEVICE_LINUX_H_
#define UI_OZONE_COMMON_LINUX_GBM_DEVICE_LINUX_H_
#include "base/files/file.h"
#include "base/macros.h"
struct gbm_device;
namespace ui {
class GbmDeviceLinux {
public:
GbmDeviceLinux();
virtual ~GbmDeviceLinux();
gbm_device* device() const { return device_; }
bool InitializeGbmDevice(int fd);
private:
gbm_device* device_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(GbmDeviceLinux);
};
} // namespace ui
#endif // UI_OZONE_COMMON_LINUX_GBM_DEVICE_LINUX_H_
......@@ -19,6 +19,7 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/overlay_transform.h"
#include "ui/ozone/common/linux/gbm_device_linux.h"
#include "ui/ozone/platform/drm/common/scoped_drm_types.h"
typedef struct _drmEventContext drmEventContext;
......@@ -37,7 +38,8 @@ class HardwareDisplayPlaneManager;
// Wraps DRM calls into a nice interface. Used to provide different
// implementations of the DRM calls. For the actual implementation the DRM API
// would be called. In unit tests this interface would be stubbed.
class DrmDevice : public base::RefCountedThreadSafe<DrmDevice> {
class DrmDevice : public GbmDeviceLinux,
public base::RefCountedThreadSafe<DrmDevice> {
public:
using PageFlipCallback =
base::OnceCallback<void(unsigned int /* frame */,
......@@ -210,7 +212,7 @@ class DrmDevice : public base::RefCountedThreadSafe<DrmDevice> {
protected:
friend class base::RefCountedThreadSafe<DrmDevice>;
virtual ~DrmDevice();
~DrmDevice() override;
std::unique_ptr<HardwareDisplayPlaneManager> plane_manager_;
......
......@@ -4,7 +4,6 @@
#include "ui/ozone/platform/drm/gpu/gbm_device.h"
#include <gbm.h>
#include <utility>
namespace ui {
......@@ -14,17 +13,14 @@ GbmDevice::GbmDevice(const base::FilePath& device_path,
bool is_primary_device)
: DrmDevice(device_path, std::move(file), is_primary_device) {}
GbmDevice::~GbmDevice() {
if (device_)
gbm_device_destroy(device_);
}
GbmDevice::~GbmDevice() = default;
bool GbmDevice::Initialize() {
if (!DrmDevice::Initialize())
return false;
device_ = gbm_create_device(get_fd());
if (!device_) {
InitializeGbmDevice(get_fd());
if (!device()) {
PLOG(ERROR) << "Unable to initialize GBM for " << device_path().value();
return false;
}
......
......@@ -8,8 +8,6 @@
#include "base/macros.h"
#include "ui/ozone/platform/drm/gpu/drm_device.h"
struct gbm_device;
namespace ui {
class GbmDevice : public DrmDevice {
......@@ -18,16 +16,12 @@ class GbmDevice : public DrmDevice {
base::File file,
bool is_primary_device);
gbm_device* device() const { return device_; }
// DrmDevice implementation:
bool Initialize() override;
private:
~GbmDevice() override;
gbm_device* device_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(GbmDevice);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment