Commit de0cbe8b authored by Michael Spang's avatar Michael Spang Committed by Commit Bot

ozone: drm: Concretize DrmFramebuffer and compose it into {Gbm,Drm}Buffer

Change DrmFramebuffer from a virtual interface to a concrete wrapper for
a DRM framebuffer. This is what used to be ScanoutBuffer and is all that
is needed for modesetting. In particular, we don't need access to gbm_bo,
skia surfaces backed by dumb buffer mmaps, or other bits from
{Gbm,Drm}Buffer in the modesetting internals.

DrmFramebuffer is composed into GbmBuffer and DrmBuffer so that we can
still access framebuffers for those types when presenting a buffer.
GbmBuffer and DrmBuffer are no longer refcounted after this change.

Bug: 868010

Change-Id: I6d31b000b35bc4a6caa6280bee4156ca9b271bb9
Reviewed-on: https://chromium-review.googlesource.com/1155916
Commit-Queue: Michael Spang <spang@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579605}
parent 9080a8ec
...@@ -38,6 +38,8 @@ source_set("gbm") { ...@@ -38,6 +38,8 @@ source_set("gbm") {
"gpu/drm_device_manager.h", "gpu/drm_device_manager.h",
"gpu/drm_display.cc", "gpu/drm_display.cc",
"gpu/drm_display.h", "gpu/drm_display.h",
"gpu/drm_framebuffer.cc",
"gpu/drm_framebuffer.h",
"gpu/drm_gpu_display_manager.cc", "gpu/drm_gpu_display_manager.cc",
"gpu/drm_gpu_display_manager.h", "gpu/drm_gpu_display_manager.h",
"gpu/drm_gpu_util.cc", "gpu/drm_gpu_util.cc",
......
...@@ -40,11 +40,11 @@ CrtcController::~CrtcController() { ...@@ -40,11 +40,11 @@ CrtcController::~CrtcController() {
bool CrtcController::Modeset(const DrmOverlayPlane& plane, bool CrtcController::Modeset(const DrmOverlayPlane& plane,
drmModeModeInfo mode) { drmModeModeInfo mode) {
if (!drm_->SetCrtc(crtc_, plane.buffer->GetOpaqueFramebufferId(), if (!drm_->SetCrtc(crtc_, plane.buffer->opaque_framebuffer_id(),
std::vector<uint32_t>(1, connector_), &mode)) { std::vector<uint32_t>(1, connector_), &mode)) {
PLOG(ERROR) << "Failed to modeset: crtc=" << crtc_ PLOG(ERROR) << "Failed to modeset: crtc=" << crtc_
<< " connector=" << connector_ << " connector=" << connector_
<< " framebuffer_id=" << plane.buffer->GetOpaqueFramebufferId() << " framebuffer_id=" << plane.buffer->opaque_framebuffer_id()
<< " mode=" << mode.hdisplay << "x" << mode.vdisplay << "@" << " mode=" << mode.hdisplay << "x" << mode.vdisplay << "@"
<< mode.vrefresh; << mode.vrefresh;
return false; return false;
...@@ -73,7 +73,7 @@ bool CrtcController::AssignOverlayPlanes(HardwareDisplayPlaneList* plane_list, ...@@ -73,7 +73,7 @@ bool CrtcController::AssignOverlayPlanes(HardwareDisplayPlaneList* plane_list,
if (primary && !drm_->plane_manager()->ValidatePrimarySize(*primary, mode_)) { if (primary && !drm_->plane_manager()->ValidatePrimarySize(*primary, mode_)) {
VLOG(2) << "Trying to pageflip a buffer with the wrong size. Expected " VLOG(2) << "Trying to pageflip a buffer with the wrong size. Expected "
<< mode_.hdisplay << "x" << mode_.vdisplay << " got " << mode_.hdisplay << "x" << mode_.vdisplay << " got "
<< primary->buffer->GetSize().ToString() << " for" << primary->buffer->size().ToString() << " for"
<< " crtc=" << crtc_ << " connector=" << connector_; << " crtc=" << crtc_ << " connector=" << connector_;
return true; return true;
} }
......
...@@ -31,15 +31,29 @@ uint32_t GetFourCCCodeForSkColorType(SkColorType type) { ...@@ -31,15 +31,29 @@ uint32_t GetFourCCCodeForSkColorType(SkColorType type) {
} }
} }
scoped_refptr<DrmFramebuffer> AddFramebufferForDumbBuffer(
const scoped_refptr<DrmDevice>& drm,
uint32_t handle,
uint32_t stride,
const SkImageInfo& info) {
DrmFramebuffer::AddFramebufferParams params;
params.flags = 0;
params.format = GetFourCCCodeForSkColorType(info.colorType());
params.modifier = DRM_FORMAT_MOD_INVALID;
params.width = info.width();
params.height = info.height();
params.num_planes = 1;
params.handles[0] = handle;
params.strides[0] = stride;
return DrmFramebuffer::AddFramebuffer(drm, params);
}
} // namespace } // namespace
DrmBuffer::DrmBuffer(const scoped_refptr<DrmDevice>& drm) : drm_(drm) { DrmBuffer::DrmBuffer(const scoped_refptr<DrmDevice>& drm) : drm_(drm) {
} }
DrmBuffer::~DrmBuffer() { DrmBuffer::~DrmBuffer() {
if (framebuffer_ && !drm_->RemoveFramebuffer(framebuffer_))
PLOG(ERROR) << "DrmBuffer: RemoveFramebuffer: fb " << framebuffer_;
if (mmap_base_ && !drm_->UnmapDumbBuffer(mmap_base_, mmap_size_)) if (mmap_base_ && !drm_->UnmapDumbBuffer(mmap_base_, mmap_size_))
PLOG(ERROR) << "DrmBuffer: UnmapDumbBuffer: handle " << handle_; PLOG(ERROR) << "DrmBuffer: UnmapDumbBuffer: handle " << handle_;
...@@ -62,18 +76,9 @@ bool DrmBuffer::Initialize(const SkImageInfo& info, ...@@ -62,18 +76,9 @@ bool DrmBuffer::Initialize(const SkImageInfo& info,
} }
if (should_register_framebuffer) { if (should_register_framebuffer) {
uint32_t handles[4] = {0}; framebuffer_ = AddFramebufferForDumbBuffer(drm_, handle_, stride_, info);
handles[0] = handle_; if (!framebuffer_)
uint32_t strides[4] = {0};
strides[0] = stride_;
uint32_t offsets[4] = {0};
fb_pixel_format_ = GetFourCCCodeForSkColorType(info.colorType());
if (!drm_->AddFramebuffer2(info.width(), info.height(), fb_pixel_format_,
handles, strides, offsets, nullptr,
&framebuffer_, 0)) {
PLOG(ERROR) << "DrmBuffer: AddFramebuffer2: handle " << handle_;
return false; return false;
}
} }
surface_ = SkSurface::MakeRasterDirect(info, mmap_base_, stride_); surface_ = SkSurface::MakeRasterDirect(info, mmap_base_, stride_);
...@@ -93,32 +98,8 @@ uint32_t DrmBuffer::GetHandle() const { ...@@ -93,32 +98,8 @@ uint32_t DrmBuffer::GetHandle() const {
return handle_; return handle_;
} }
uint32_t DrmBuffer::GetFramebufferId() const {
return framebuffer_;
}
uint32_t DrmBuffer::GetFramebufferPixelFormat() const {
return fb_pixel_format_;
}
uint32_t DrmBuffer::GetOpaqueFramebufferId() const {
return framebuffer_;
}
uint32_t DrmBuffer::GetOpaqueFramebufferPixelFormat() const {
return fb_pixel_format_;
}
uint64_t DrmBuffer::GetFormatModifier() const {
return DRM_FORMAT_MOD_NONE;
}
gfx::Size DrmBuffer::GetSize() const { gfx::Size DrmBuffer::GetSize() const {
return gfx::Size(surface_->width(), surface_->height()); return gfx::Size(surface_->width(), surface_->height());
} }
const DrmDevice* DrmBuffer::GetDrmDevice() const {
return drm_.get();
}
} // namespace ui } // namespace ui
...@@ -23,9 +23,10 @@ class DrmDevice; ...@@ -23,9 +23,10 @@ class DrmDevice;
// Wrapper for a DRM allocated buffer. Keeps track of the native properties of // Wrapper for a DRM allocated buffer. Keeps track of the native properties of
// the buffer and wraps the pixel memory into a SkSurface which can be used to // the buffer and wraps the pixel memory into a SkSurface which can be used to
// draw into using Skia. // draw into using Skia.
class DrmBuffer : public DrmFramebuffer { class DrmBuffer {
public: public:
DrmBuffer(const scoped_refptr<DrmDevice>& drm); DrmBuffer(const scoped_refptr<DrmDevice>& drm);
~DrmBuffer();
// Allocates the backing pixels and wraps them in |surface_|. |info| is used // Allocates the backing pixels and wraps them in |surface_|. |info| is used
// to describe the buffer characteristics (size, color format). // to describe the buffer characteristics (size, color format).
...@@ -36,20 +37,15 @@ class DrmBuffer : public DrmFramebuffer { ...@@ -36,20 +37,15 @@ class DrmBuffer : public DrmFramebuffer {
SkCanvas* GetCanvas() const; SkCanvas* GetCanvas() const;
uint32_t GetHandle() const; uint32_t GetHandle() const;
gfx::Size GetSize() const;
// DrmFramebuffer: const scoped_refptr<DrmFramebuffer>& framebuffer() const {
uint32_t GetFramebufferId() const override; return framebuffer_;
uint32_t GetFramebufferPixelFormat() const override; }
uint32_t GetOpaqueFramebufferId() const override;
uint32_t GetOpaqueFramebufferPixelFormat() const override;
uint64_t GetFormatModifier() const override;
gfx::Size GetSize() const override;
const DrmDevice* GetDrmDevice() const override;
protected: protected:
~DrmBuffer() override; const scoped_refptr<DrmDevice> drm_;
scoped_refptr<DrmFramebuffer> framebuffer_;
scoped_refptr<DrmDevice> drm_;
// Length of a row of pixels. // Length of a row of pixels.
uint32_t stride_ = 0; uint32_t stride_ = 0;
...@@ -63,13 +59,6 @@ class DrmBuffer : public DrmFramebuffer { ...@@ -63,13 +59,6 @@ class DrmBuffer : public DrmFramebuffer {
// Size for memory mapping. // Size for memory mapping.
size_t mmap_size_ = 0; size_t mmap_size_ = 0;
// Buffer ID used by the DRM modesettings API. This is set when the buffer is
// registered with the CRTC.
uint32_t framebuffer_ = 0;
// Pixel format of |framebuffer_|
uint32_t fb_pixel_format_ = 0;
// Wrapper around the native pixel memory. // Wrapper around the native pixel memory.
sk_sp<SkSurface> surface_; sk_sp<SkSurface> surface_;
......
// 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/platform/drm/gpu/drm_framebuffer.h"
#include "ui/ozone/common/linux/drm_util_linux.h"
#include "ui/ozone/platform/drm/common/drm_util.h"
#include "ui/ozone/platform/drm/gpu/drm_device.h"
namespace ui {
// static
scoped_refptr<DrmFramebuffer> DrmFramebuffer::AddFramebuffer(
scoped_refptr<DrmDevice> drm_device,
DrmFramebuffer::AddFramebufferParams params) {
uint64_t modifiers[4] = {0};
if (params.modifier != DRM_FORMAT_MOD_INVALID) {
for (size_t i = 0; i < params.num_planes; ++i)
modifiers[i] = params.modifier;
}
uint32_t framebuffer_id = 0;
if (!drm_device->AddFramebuffer2(params.width, params.height, params.format,
params.handles, params.strides,
params.offsets, modifiers, &framebuffer_id,
params.flags)) {
PLOG(ERROR) << "AddFramebuffer2";
return nullptr;
}
uint32_t opaque_format = GetFourCCFormatForOpaqueFramebuffer(
GetBufferFormatFromFourCCFormat(params.format));
uint32_t opaque_framebuffer_id = 0;
if (opaque_format != params.format &&
!drm_device->AddFramebuffer2(params.width, params.height, opaque_format,
params.handles, params.strides,
params.offsets, modifiers,
&opaque_framebuffer_id, params.flags)) {
PLOG(ERROR) << "AddFramebuffer2";
drm_device->RemoveFramebuffer(framebuffer_id);
return nullptr;
}
return base::MakeRefCounted<DrmFramebuffer>(
std::move(drm_device), framebuffer_id, params.format,
opaque_framebuffer_id, opaque_format, params.modifier,
gfx::Size(params.width, params.height));
}
DrmFramebuffer::DrmFramebuffer(scoped_refptr<DrmDevice> drm_device,
uint32_t framebuffer_id,
uint32_t framebuffer_pixel_format,
uint32_t opaque_framebuffer_id,
uint32_t opaque_framebuffer_pixel_format,
uint64_t format_modifier,
const gfx::Size& size)
: drm_device_(std::move(drm_device)),
framebuffer_id_(framebuffer_id),
framebuffer_pixel_format_(framebuffer_pixel_format),
opaque_framebuffer_id_(opaque_framebuffer_id),
opaque_framebuffer_pixel_format_(opaque_framebuffer_pixel_format),
format_modifier_(format_modifier),
size_(size) {}
DrmFramebuffer::~DrmFramebuffer() {
if (!drm_device_->RemoveFramebuffer(framebuffer_id_))
PLOG(WARNING) << "RemoveFramebuffer";
if (opaque_framebuffer_id_ &&
!drm_device_->RemoveFramebuffer(opaque_framebuffer_id_))
PLOG(WARNING) << "RemoveFramebuffer";
}
} // namespace ui
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef UI_OZONE_PLATFORM_DRM_GPU_SCANOUT_BUFFER_H_ #ifndef UI_OZONE_PLATFORM_DRM_GPU_SCANOUT_BUFFER_H_
#define UI_OZONE_PLATFORM_DRM_GPU_SCANOUT_BUFFER_H_ #define UI_OZONE_PLATFORM_DRM_GPU_SCANOUT_BUFFER_H_
#include <drm_fourcc.h>
#include <stdint.h> #include <stdint.h>
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
...@@ -18,33 +19,73 @@ class DrmDevice; ...@@ -18,33 +19,73 @@ class DrmDevice;
// Abstraction for a DRM buffer that can be scanned-out of. // Abstraction for a DRM buffer that can be scanned-out of.
class DrmFramebuffer : public base::RefCountedThreadSafe<DrmFramebuffer> { class DrmFramebuffer : public base::RefCountedThreadSafe<DrmFramebuffer> {
public: public:
struct AddFramebufferParams {
uint32_t flags = 0;
uint32_t format = DRM_FORMAT_XRGB8888;
uint64_t modifier = DRM_FORMAT_MOD_INVALID;
uint32_t width = 0;
uint32_t height = 0;
size_t num_planes = 0;
uint32_t handles[4] = {0};
uint32_t strides[4] = {0};
uint32_t offsets[4] = {0};
};
static scoped_refptr<DrmFramebuffer> AddFramebuffer(
scoped_refptr<DrmDevice> drm_device,
AddFramebufferParams params);
DrmFramebuffer(scoped_refptr<DrmDevice> drm_device,
uint32_t framebuffer_id,
uint32_t framebuffer_pixel_format,
uint32_t opaque_framebuffer_id,
uint32_t opaque_framebuffer_pixel_format,
uint64_t format_modifier,
const gfx::Size& size);
// ID allocated by the KMS API when the buffer is registered (via the handle). // ID allocated by the KMS API when the buffer is registered (via the handle).
virtual uint32_t GetFramebufferId() const = 0; uint32_t framebuffer_id() { return framebuffer_id_; }
// ID allocated if the buffer is also registered with a different pixel format // ID allocated if the buffer is also registered with a different pixel format
// so that it can be scheduled as an opaque buffer. // so that it can be scheduled as an opaque buffer.
virtual uint32_t GetOpaqueFramebufferId() const = 0; uint32_t opaque_framebuffer_id() {
return opaque_framebuffer_id_ ? opaque_framebuffer_id_ : framebuffer_id_;
}
// Returns FourCC format representing the way pixel data has been encoded in // Returns FourCC format representing the way pixel data has been encoded in
// memory for the registered framebuffer. This can be used to check if frame // memory for the registered framebuffer. This can be used to check if frame
// buffer is compatible with a given hardware plane. // buffer is compatible with a given hardware plane.
virtual uint32_t GetFramebufferPixelFormat() const = 0; uint32_t framebuffer_pixel_format() { return framebuffer_pixel_format_; }
// Returns FourCC format that should be used to schedule this buffer for // Returns FourCC format that should be used to schedule this buffer for
// scanout when used as an opaque buffer. // scanout when used as an opaque buffer.
virtual uint32_t GetOpaqueFramebufferPixelFormat() const = 0; uint32_t opaque_framebuffer_pixel_format() {
return opaque_framebuffer_pixel_format_;
}
// Returns format modifier for buffer. // Returns format modifier for buffer.
virtual uint64_t GetFormatModifier() const = 0; uint64_t format_modifier() { return format_modifier_; }
// Size of the buffer. // Size of the buffer.
virtual gfx::Size GetSize() const = 0; gfx::Size size() { return size_; }
// Device on which the buffer was created. // Device on which the buffer was created.
virtual const DrmDevice* GetDrmDevice() const = 0; const scoped_refptr<DrmDevice>& drm_device() const { return drm_device_; }
protected: private:
virtual ~DrmFramebuffer() {} ~DrmFramebuffer();
scoped_refptr<DrmDevice> drm_device_;
uint32_t framebuffer_id_ = 0;
uint32_t framebuffer_pixel_format_ = 0;
// If |opaque_framebuffer_pixel_format_| differs from
// |framebuffer_pixel_format_| the following member is set to a valid fb,
// otherwise it is set to 0.
uint32_t opaque_framebuffer_id_ = 0;
uint32_t opaque_framebuffer_pixel_format_ = 0;
uint64_t format_modifier_ = 0;
gfx::Size size_;
friend class base::RefCountedThreadSafe<DrmFramebuffer>; friend class base::RefCountedThreadSafe<DrmFramebuffer>;
}; };
......
...@@ -27,7 +27,7 @@ DrmOverlayPlane::DrmOverlayPlane(const scoped_refptr<DrmFramebuffer>& buffer, ...@@ -27,7 +27,7 @@ DrmOverlayPlane::DrmOverlayPlane(const scoped_refptr<DrmFramebuffer>& buffer,
std::unique_ptr<gfx::GpuFence> gpu_fence) std::unique_ptr<gfx::GpuFence> gpu_fence)
: buffer(buffer), : buffer(buffer),
plane_transform(gfx::OVERLAY_TRANSFORM_NONE), plane_transform(gfx::OVERLAY_TRANSFORM_NONE),
display_bounds(gfx::Point(), buffer->GetSize()), display_bounds(gfx::Point(), buffer->size()),
crop_rect(0, 0, 1, 1), crop_rect(0, 0, 1, 1),
enable_blend(false), enable_blend(false),
gpu_fence(std::move(gpu_fence)) {} gpu_fence(std::move(gpu_fence)) {}
......
...@@ -29,8 +29,8 @@ scoped_refptr<DrmFramebuffer> GetBufferForPageFlipTest( ...@@ -29,8 +29,8 @@ scoped_refptr<DrmFramebuffer> GetBufferForPageFlipTest(
std::vector<scoped_refptr<DrmFramebuffer>>* reusable_buffers) { std::vector<scoped_refptr<DrmFramebuffer>>* reusable_buffers) {
// Check if we can re-use existing buffers. // Check if we can re-use existing buffers.
for (const auto& buffer : *reusable_buffers) { for (const auto& buffer : *reusable_buffers) {
if (buffer->GetFramebufferPixelFormat() == format && if (buffer->framebuffer_pixel_format() == format &&
buffer->GetSize() == size) { buffer->size() == size) {
return buffer; return buffer;
} }
} }
......
...@@ -47,10 +47,13 @@ class GbmBufferGenerator : public DrmFramebufferGenerator { ...@@ -47,10 +47,13 @@ class GbmBufferGenerator : public DrmFramebufferGenerator {
const gfx::Size& size) override { const gfx::Size& size) override {
scoped_refptr<GbmDevice> gbm(static_cast<GbmDevice*>(drm.get())); scoped_refptr<GbmDevice> gbm(static_cast<GbmDevice*>(drm.get()));
if (modifiers.size() > 0) { if (modifiers.size() > 0) {
return GbmBuffer::CreateBufferWithModifiers( auto buffer = GbmBuffer::CreateBufferWithModifiers(
gbm, format, size, GBM_BO_USE_SCANOUT, modifiers); gbm, format, size, GBM_BO_USE_SCANOUT, modifiers);
return buffer->framebuffer();
} else { } else {
return GbmBuffer::CreateBuffer(gbm, format, size, GBM_BO_USE_SCANOUT); auto buffer =
GbmBuffer::CreateBuffer(gbm, format, size, GBM_BO_USE_SCANOUT);
return buffer->framebuffer();
} }
} }
...@@ -120,7 +123,7 @@ void DrmThread::CreateBuffer(gfx::AcceleratedWidget widget, ...@@ -120,7 +123,7 @@ void DrmThread::CreateBuffer(gfx::AcceleratedWidget widget,
gfx::BufferFormat format, gfx::BufferFormat format,
gfx::BufferUsage usage, gfx::BufferUsage usage,
uint32_t client_flags, uint32_t client_flags,
scoped_refptr<GbmBuffer>* buffer) { std::unique_ptr<GbmBuffer>* buffer) {
scoped_refptr<GbmDevice> gbm = scoped_refptr<GbmDevice> gbm =
static_cast<GbmDevice*>(device_manager_->GetDrmDevice(widget).get()); static_cast<GbmDevice*>(device_manager_->GetDrmDevice(widget).get());
DCHECK(gbm); DCHECK(gbm);
...@@ -188,7 +191,7 @@ void DrmThread::CreateBufferFromFds( ...@@ -188,7 +191,7 @@ void DrmThread::CreateBufferFromFds(
gfx::BufferFormat format, gfx::BufferFormat format,
std::vector<base::ScopedFD> fds, std::vector<base::ScopedFD> fds,
const std::vector<gfx::NativePixmapPlane>& planes, const std::vector<gfx::NativePixmapPlane>& planes,
scoped_refptr<GbmBuffer>* buffer) { std::unique_ptr<GbmBuffer>* buffer) {
scoped_refptr<GbmDevice> gbm = scoped_refptr<GbmDevice> gbm =
static_cast<GbmDevice*>(device_manager_->GetDrmDevice(widget).get()); static_cast<GbmDevice*>(device_manager_->GetDrmDevice(widget).get());
DCHECK(gbm); DCHECK(gbm);
......
...@@ -71,13 +71,13 @@ class DrmThread : public base::Thread, ...@@ -71,13 +71,13 @@ class DrmThread : public base::Thread,
gfx::BufferFormat format, gfx::BufferFormat format,
gfx::BufferUsage usage, gfx::BufferUsage usage,
uint32_t flags, uint32_t flags,
scoped_refptr<GbmBuffer>* buffer); std::unique_ptr<GbmBuffer>* buffer);
void CreateBufferFromFds(gfx::AcceleratedWidget widget, void CreateBufferFromFds(gfx::AcceleratedWidget widget,
const gfx::Size& size, const gfx::Size& size,
gfx::BufferFormat format, gfx::BufferFormat format,
std::vector<base::ScopedFD> fds, std::vector<base::ScopedFD> fds,
const std::vector<gfx::NativePixmapPlane>& planes, const std::vector<gfx::NativePixmapPlane>& planes,
scoped_refptr<GbmBuffer>* buffer); std::unique_ptr<GbmBuffer>* buffer);
void GetScanoutFormats(gfx::AcceleratedWidget widget, void GetScanoutFormats(gfx::AcceleratedWidget widget,
std::vector<gfx::BufferFormat>* scanout_formats); std::vector<gfx::BufferFormat>* scanout_formats);
void AddBindingCursorDevice(ozone::mojom::DeviceCursorRequest request); void AddBindingCursorDevice(ozone::mojom::DeviceCursorRequest request);
......
...@@ -32,7 +32,7 @@ std::unique_ptr<DrmWindowProxy> DrmThreadProxy::CreateDrmWindowProxy( ...@@ -32,7 +32,7 @@ std::unique_ptr<DrmWindowProxy> DrmThreadProxy::CreateDrmWindowProxy(
return std::make_unique<DrmWindowProxy>(widget, &drm_thread_); return std::make_unique<DrmWindowProxy>(widget, &drm_thread_);
} }
scoped_refptr<GbmBuffer> DrmThreadProxy::CreateBuffer( std::unique_ptr<GbmBuffer> DrmThreadProxy::CreateBuffer(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget,
const gfx::Size& size, const gfx::Size& size,
gfx::BufferFormat format, gfx::BufferFormat format,
...@@ -40,7 +40,7 @@ scoped_refptr<GbmBuffer> DrmThreadProxy::CreateBuffer( ...@@ -40,7 +40,7 @@ scoped_refptr<GbmBuffer> DrmThreadProxy::CreateBuffer(
uint32_t flags) { uint32_t flags) {
DCHECK(drm_thread_.task_runner()) DCHECK(drm_thread_.task_runner())
<< "no task runner! in DrmThreadProxy::CreateBuffer"; << "no task runner! in DrmThreadProxy::CreateBuffer";
scoped_refptr<GbmBuffer> buffer; std::unique_ptr<GbmBuffer> buffer;
PostSyncTask( PostSyncTask(
drm_thread_.task_runner(), drm_thread_.task_runner(),
...@@ -49,13 +49,13 @@ scoped_refptr<GbmBuffer> DrmThreadProxy::CreateBuffer( ...@@ -49,13 +49,13 @@ scoped_refptr<GbmBuffer> DrmThreadProxy::CreateBuffer(
return buffer; return buffer;
} }
scoped_refptr<GbmBuffer> DrmThreadProxy::CreateBufferFromFds( std::unique_ptr<GbmBuffer> DrmThreadProxy::CreateBufferFromFds(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget,
const gfx::Size& size, const gfx::Size& size,
gfx::BufferFormat format, gfx::BufferFormat format,
std::vector<base::ScopedFD> fds, std::vector<base::ScopedFD> fds,
const std::vector<gfx::NativePixmapPlane>& planes) { const std::vector<gfx::NativePixmapPlane>& planes) {
scoped_refptr<GbmBuffer> buffer; std::unique_ptr<GbmBuffer> buffer;
PostSyncTask( PostSyncTask(
drm_thread_.task_runner(), drm_thread_.task_runner(),
base::BindOnce(&DrmThread::CreateBufferFromFds, base::BindOnce(&DrmThread::CreateBufferFromFds,
......
...@@ -32,13 +32,13 @@ class DrmThreadProxy { ...@@ -32,13 +32,13 @@ class DrmThreadProxy {
std::unique_ptr<DrmWindowProxy> CreateDrmWindowProxy( std::unique_ptr<DrmWindowProxy> CreateDrmWindowProxy(
gfx::AcceleratedWidget widget); gfx::AcceleratedWidget widget);
scoped_refptr<GbmBuffer> CreateBuffer(gfx::AcceleratedWidget widget, std::unique_ptr<GbmBuffer> CreateBuffer(gfx::AcceleratedWidget widget,
const gfx::Size& size, const gfx::Size& size,
gfx::BufferFormat format, gfx::BufferFormat format,
gfx::BufferUsage usage, gfx::BufferUsage usage,
uint32_t flags); uint32_t flags);
scoped_refptr<GbmBuffer> CreateBufferFromFds( std::unique_ptr<GbmBuffer> CreateBufferFromFds(
gfx::AcceleratedWidget widget, gfx::AcceleratedWidget widget,
const gfx::Size& size, const gfx::Size& size,
gfx::BufferFormat format, gfx::BufferFormat format,
......
...@@ -98,7 +98,7 @@ void DrmWindow::SchedulePageFlip( ...@@ -98,7 +98,7 @@ void DrmWindow::SchedulePageFlip(
if (controller_) { if (controller_) {
const DrmDevice* drm = controller_->GetDrmDevice().get(); const DrmDevice* drm = controller_->GetDrmDevice().get();
for (const auto& plane : planes) { for (const auto& plane : planes) {
if (plane.buffer && plane.buffer->GetDrmDevice() != drm) { if (plane.buffer && plane.buffer->drm_device() != drm) {
// Although |force_buffer_reallocation_| is set to true during window // Although |force_buffer_reallocation_| is set to true during window
// bounds update, this may still be needed because of in-flight buffers. // bounds update, this may still be needed because of in-flight buffers.
force_buffer_reallocation_ = true; force_buffer_reallocation_ = true;
......
...@@ -31,6 +31,39 @@ ...@@ -31,6 +31,39 @@
namespace ui { namespace ui {
namespace {
scoped_refptr<DrmFramebuffer> AddFramebuffersForBo(
const scoped_refptr<GbmDevice>& gbm,
gbm_bo* bo,
uint32_t format,
uint64_t format_modifier) {
DrmFramebuffer::AddFramebufferParams params;
params.format = format;
params.modifier = format_modifier;
params.width = gbm_bo_get_width(bo);
params.height = gbm_bo_get_height(bo);
params.num_planes = gbm_bo_get_num_planes(bo);
for (size_t i = 0; i < params.num_planes; ++i) {
params.handles[i] = gbm_bo_get_plane_handle(bo, i).u32;
params.strides[i] = gbm_bo_get_plane_stride(bo, i);
params.offsets[i] = gbm_bo_get_plane_offset(bo, i);
}
// AddFramebuffer2 only considers the modifiers if addfb_flags has
// DRM_MODE_FB_MODIFIERS set. We only set that when we've created
// a bo with modifiers, otherwise, we rely on the "no modifiers"
// behavior doing the right thing.
params.flags = 0;
if (gbm->allow_addfb2_modifiers() &&
params.modifier != DRM_FORMAT_MOD_INVALID)
params.flags |= DRM_MODE_FB_MODIFIERS;
return DrmFramebuffer::AddFramebuffer(gbm.get(), params);
}
} // namespace
GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm,
struct gbm_bo* bo, struct gbm_bo* bo,
uint32_t format, uint32_t format,
...@@ -48,86 +81,14 @@ GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, ...@@ -48,86 +81,14 @@ GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm,
size, size,
std::move(planes)) { std::move(planes)) {
if (gbm_bo_.flags() & GBM_BO_USE_SCANOUT) { if (gbm_bo_.flags() & GBM_BO_USE_SCANOUT) {
struct gbm_bo* bo = gbm_bo_.bo(); framebuffer_ = AddFramebuffersForBo(
DCHECK(bo); drm_.get(), gbm_bo_.bo(), gbm_bo_.format(), gbm_bo_.format_modifier());
framebuffer_pixel_format_ = gbm_bo_.format();
opaque_framebuffer_pixel_format_ = GetFourCCFormatForOpaqueFramebuffer(
GetBufferFormatFromFourCCFormat(framebuffer_pixel_format_));
uint32_t handles[4] = {0};
uint32_t strides[4] = {0};
uint32_t offsets[4] = {0};
uint64_t modifiers[4] = {0};
uint64_t modifier = gbm_bo_.format_modifier();
for (size_t i = 0; i < gbm_bo_get_num_planes(bo); ++i) {
handles[i] = gbm_bo_get_plane_handle(bo, i).u32;
strides[i] = gbm_bo_get_plane_stride(bo, i);
offsets[i] = gbm_bo_get_plane_offset(bo, i);
if (modifier != DRM_FORMAT_MOD_INVALID)
modifiers[i] = modifier;
}
// AddFramebuffer2 only considers the modifiers if addfb_flags has
// DRM_MODE_FB_MODIFIERS set. We only set that when we've created
// a bo with modifiers, otherwise, we rely on the "no modifiers"
// behavior doing the right thing.
const uint32_t addfb_flags =
gbm->allow_addfb2_modifiers() &&
modifier != DRM_FORMAT_MOD_INVALID ? DRM_MODE_FB_MODIFIERS : 0;
bool ret = drm_->AddFramebuffer2(
gbm_bo_get_width(bo), gbm_bo_get_height(bo), framebuffer_pixel_format_,
handles, strides, offsets, modifiers, &framebuffer_, addfb_flags);
PLOG_IF(ERROR, !ret) << "AddFramebuffer2 failed";
if (opaque_framebuffer_pixel_format_ != framebuffer_pixel_format_) {
ret = drm_->AddFramebuffer2(gbm_bo_get_width(bo), gbm_bo_get_height(bo),
opaque_framebuffer_pixel_format_, handles,
strides, offsets, modifiers,
&opaque_framebuffer_, addfb_flags);
PLOG_IF(ERROR, !ret) << "AddFramebuffer2 failed";
}
} }
} }
GbmBuffer::~GbmBuffer() { GbmBuffer::~GbmBuffer() {}
if (framebuffer_)
drm_->RemoveFramebuffer(framebuffer_);
if (opaque_framebuffer_)
drm_->RemoveFramebuffer(opaque_framebuffer_);
}
uint32_t GbmBuffer::GetFramebufferId() const {
return framebuffer_;
}
uint32_t GbmBuffer::GetOpaqueFramebufferId() const { std::unique_ptr<GbmBuffer> GbmBuffer::CreateBufferForBO(
return opaque_framebuffer_ ? opaque_framebuffer_ : framebuffer_;
}
uint64_t GbmBuffer::GetFormatModifier() const {
return gbm_bo_.format_modifier();
}
gfx::Size GbmBuffer::GetSize() const {
return gbm_bo_.size();
}
uint32_t GbmBuffer::GetFramebufferPixelFormat() const {
DCHECK(framebuffer_);
return framebuffer_pixel_format_;
}
uint32_t GbmBuffer::GetOpaqueFramebufferPixelFormat() const {
DCHECK(framebuffer_);
return opaque_framebuffer_pixel_format_;
}
const DrmDevice* GbmBuffer::GetDrmDevice() const {
return drm_.get();
}
scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferForBO(
const scoped_refptr<GbmDevice>& gbm, const scoped_refptr<GbmDevice>& gbm,
struct gbm_bo* bo, struct gbm_bo* bo,
uint32_t format, uint32_t format,
...@@ -158,17 +119,17 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferForBO( ...@@ -158,17 +119,17 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferForBO(
gbm_bo_get_plane_offset(bo, i), gbm_bo_get_plane_offset(bo, i),
gbm_bo_get_plane_size(bo, i), modifier); gbm_bo_get_plane_size(bo, i), modifier);
} }
scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, format, flags, auto buffer =
modifier, std::move(fds), size, std::make_unique<GbmBuffer>(gbm, bo, format, flags, modifier,
std::move(planes))); std::move(fds), size, std::move(planes));
if (flags & GBM_BO_USE_SCANOUT && !buffer->GetFramebufferId()) if (flags & GBM_BO_USE_SCANOUT && !buffer->framebuffer())
return nullptr; return nullptr;
return buffer; return buffer;
} }
// static // static
scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferWithModifiers( std::unique_ptr<GbmBuffer> GbmBuffer::CreateBufferWithModifiers(
const scoped_refptr<GbmDevice>& gbm, const scoped_refptr<GbmDevice>& gbm,
uint32_t format, uint32_t format,
const gfx::Size& size, const gfx::Size& size,
...@@ -187,7 +148,7 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferWithModifiers( ...@@ -187,7 +148,7 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferWithModifiers(
} }
// static // static
scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( std::unique_ptr<GbmBuffer> GbmBuffer::CreateBuffer(
const scoped_refptr<GbmDevice>& gbm, const scoped_refptr<GbmDevice>& gbm,
uint32_t format, uint32_t format,
const gfx::Size& size, const gfx::Size& size,
...@@ -204,7 +165,7 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( ...@@ -204,7 +165,7 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer(
} }
// static // static
scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( std::unique_ptr<GbmBuffer> GbmBuffer::CreateBufferFromFds(
const scoped_refptr<GbmDevice>& gbm, const scoped_refptr<GbmDevice>& gbm,
uint32_t format, uint32_t format,
const gfx::Size& size, const gfx::Size& size,
...@@ -245,16 +206,14 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( ...@@ -245,16 +206,14 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds(
} }
} }
scoped_refptr<GbmBuffer> buffer( return std::make_unique<GbmBuffer>(gbm, bo, format, gbm_flags,
new GbmBuffer(gbm, bo, format, gbm_flags, planes[0].modifier, planes[0].modifier, std::move(fds), size,
std::move(fds), size, std::move(planes))); std::move(planes));
return buffer;
} }
GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager,
const scoped_refptr<GbmBuffer>& buffer) std::unique_ptr<GbmBuffer> buffer)
: surface_manager_(surface_manager), buffer_(buffer) {} : surface_manager_(surface_manager), buffer_(std::move(buffer)) {}
gfx::NativePixmapHandle GbmPixmap::ExportHandle() { gfx::NativePixmapHandle GbmPixmap::ExportHandle() {
gfx::NativePixmapHandle handle; gfx::NativePixmapHandle handle;
...@@ -305,7 +264,7 @@ int GbmPixmap::GetDmaBufOffset(size_t plane) const { ...@@ -305,7 +264,7 @@ int GbmPixmap::GetDmaBufOffset(size_t plane) const {
} }
uint64_t GbmPixmap::GetDmaBufModifier(size_t plane) const { uint64_t GbmPixmap::GetDmaBufModifier(size_t plane) const {
return buffer_->GetFormatModifier(); return buffer_->gbm_bo()->format_modifier();
} }
gfx::BufferFormat GbmPixmap::GetBufferFormat() const { gfx::BufferFormat GbmPixmap::GetBufferFormat() const {
...@@ -331,10 +290,10 @@ bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, ...@@ -331,10 +290,10 @@ bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
// |framebuffer_id| might be 0 if AddFramebuffer2 failed, in that case we // |framebuffer_id| might be 0 if AddFramebuffer2 failed, in that case we
// already logged the error in GbmBuffer ctor. We avoid logging the error // already logged the error in GbmBuffer ctor. We avoid logging the error
// here since this method might be called every pageflip. // here since this method might be called every pageflip.
if (buffer_->GetFramebufferId()) { if (buffer_->framebuffer()) {
surface_manager_->GetSurface(widget)->QueueOverlayPlane( surface_manager_->GetSurface(widget)->QueueOverlayPlane(DrmOverlayPlane(
DrmOverlayPlane(buffer_, plane_z_order, plane_transform, display_bounds, buffer_->framebuffer(), plane_z_order, plane_transform, display_bounds,
crop_rect, enable_blend, std::move(gpu_fence))); crop_rect, enable_blend, std::move(gpu_fence)));
} }
return true; return true;
......
...@@ -18,40 +18,28 @@ namespace ui { ...@@ -18,40 +18,28 @@ namespace ui {
class GbmDevice; class GbmDevice;
class GbmSurfaceFactory; class GbmSurfaceFactory;
class GbmBuffer : public DrmFramebuffer { class GbmBuffer {
public: public:
static constexpr uint32_t kFlagNoModifiers = 1U << 0; static constexpr uint32_t kFlagNoModifiers = 1U << 0;
static scoped_refptr<GbmBuffer> CreateBuffer( static std::unique_ptr<GbmBuffer> CreateBuffer(
const scoped_refptr<GbmDevice>& gbm, const scoped_refptr<GbmDevice>& gbm,
uint32_t format, uint32_t format,
const gfx::Size& size, const gfx::Size& size,
uint32_t flags); uint32_t flags);
static scoped_refptr<GbmBuffer> CreateBufferWithModifiers( static std::unique_ptr<GbmBuffer> CreateBufferWithModifiers(
const scoped_refptr<GbmDevice>& gbm, const scoped_refptr<GbmDevice>& gbm,
uint32_t format, uint32_t format,
const gfx::Size& size, const gfx::Size& size,
uint32_t flags, uint32_t flags,
const std::vector<uint64_t>& modifiers); const std::vector<uint64_t>& modifiers);
static scoped_refptr<GbmBuffer> CreateBufferFromFds( static std::unique_ptr<GbmBuffer> CreateBufferFromFds(
const scoped_refptr<GbmDevice>& gbm, const scoped_refptr<GbmDevice>& gbm,
uint32_t format, uint32_t format,
const gfx::Size& size, const gfx::Size& size,
std::vector<base::ScopedFD> fds, std::vector<base::ScopedFD> fds,
const std::vector<gfx::NativePixmapPlane>& planes); const std::vector<gfx::NativePixmapPlane>& planes);
const GbmBoWrapper* gbm_bo() const { return &gbm_bo_; }
// DrmFramebuffer:
uint32_t GetFramebufferId() const override;
uint32_t GetOpaqueFramebufferId() const override;
uint32_t GetFramebufferPixelFormat() const override;
uint32_t GetOpaqueFramebufferPixelFormat() const override;
uint64_t GetFormatModifier() const override;
gfx::Size GetSize() const override;
const DrmDevice* GetDrmDevice() const override;
private:
GbmBuffer(const scoped_refptr<GbmDevice>& gbm, GbmBuffer(const scoped_refptr<GbmDevice>& gbm,
struct gbm_bo* bo, struct gbm_bo* bo,
uint32_t format, uint32_t format,
...@@ -60,35 +48,34 @@ class GbmBuffer : public DrmFramebuffer { ...@@ -60,35 +48,34 @@ class GbmBuffer : public DrmFramebuffer {
std::vector<base::ScopedFD> fds, std::vector<base::ScopedFD> fds,
const gfx::Size& size, const gfx::Size& size,
std::vector<gfx::NativePixmapPlane> planes); std::vector<gfx::NativePixmapPlane> planes);
~GbmBuffer() override; ~GbmBuffer();
static scoped_refptr<GbmBuffer> CreateBufferForBO( const GbmBoWrapper* gbm_bo() const { return &gbm_bo_; }
const scoped_refptr<DrmFramebuffer>& framebuffer() const {
return framebuffer_;
}
private:
static std::unique_ptr<GbmBuffer> CreateBufferForBO(
const scoped_refptr<GbmDevice>& gbm, const scoped_refptr<GbmDevice>& gbm,
struct gbm_bo* bo, struct gbm_bo* bo,
uint32_t format, uint32_t format,
const gfx::Size& size, const gfx::Size& size,
uint32_t flags); uint32_t flags);
scoped_refptr<GbmDevice> drm_; scoped_refptr<DrmFramebuffer> framebuffer_;
const scoped_refptr<GbmDevice> drm_;
// Owned gbm_bo wrapper. // Owned gbm_bo wrapper.
GbmBoWrapper gbm_bo_; GbmBoWrapper gbm_bo_;
uint32_t framebuffer_ = 0;
uint32_t framebuffer_pixel_format_ = 0;
// If |opaque_framebuffer_pixel_format_| differs from
// |framebuffer_pixel_format_| the following member is set to a valid fb,
// otherwise it is set to 0.
uint32_t opaque_framebuffer_ = 0;
uint32_t opaque_framebuffer_pixel_format_ = 0;
DISALLOW_COPY_AND_ASSIGN(GbmBuffer); DISALLOW_COPY_AND_ASSIGN(GbmBuffer);
}; };
class GbmPixmap : public gfx::NativePixmap { class GbmPixmap : public gfx::NativePixmap {
public: public:
GbmPixmap(GbmSurfaceFactory* surface_manager, GbmPixmap(GbmSurfaceFactory* surface_manager,
const scoped_refptr<GbmBuffer>& buffer); std::unique_ptr<GbmBuffer> buffer);
// NativePixmap: // NativePixmap:
bool AreDmaBufFdsValid() const override; bool AreDmaBufFdsValid() const override;
...@@ -109,7 +96,7 @@ class GbmPixmap : public gfx::NativePixmap { ...@@ -109,7 +96,7 @@ class GbmPixmap : public gfx::NativePixmap {
std::unique_ptr<gfx::GpuFence> gpu_fence) override; std::unique_ptr<gfx::GpuFence> gpu_fence) override;
gfx::NativePixmapHandle ExportHandle() override; gfx::NativePixmapHandle ExportHandle() override;
scoped_refptr<GbmBuffer> buffer() { return buffer_; } GbmBuffer* buffer() { return buffer_.get(); }
private: private:
~GbmPixmap() override; ~GbmPixmap() override;
...@@ -117,7 +104,7 @@ class GbmPixmap : public gfx::NativePixmap { ...@@ -117,7 +104,7 @@ class GbmPixmap : public gfx::NativePixmap {
uint32_t format); uint32_t format);
GbmSurfaceFactory* surface_manager_; GbmSurfaceFactory* surface_manager_;
scoped_refptr<GbmBuffer> buffer_; std::unique_ptr<GbmBuffer> buffer_;
DISALLOW_COPY_AND_ASSIGN(GbmPixmap); DISALLOW_COPY_AND_ASSIGN(GbmPixmap);
}; };
......
...@@ -37,9 +37,9 @@ void GbmOverlaySurface::SubmitFrame(std::vector<OverlayPlane> overlay_planes, ...@@ -37,9 +37,9 @@ void GbmOverlaySurface::SubmitFrame(std::vector<OverlayPlane> overlay_planes,
unsubmitted_frame.overlay_planes.reserve(overlay_planes.size()); unsubmitted_frame.overlay_planes.reserve(overlay_planes.size());
for (auto& plane : overlay_planes) { for (auto& plane : overlay_planes) {
unsubmitted_frame.overlay_planes.push_back(ui::DrmOverlayPlane( unsubmitted_frame.overlay_planes.push_back(ui::DrmOverlayPlane(
static_cast<GbmPixmap*>(plane.pixmap.get())->buffer(), plane.z_order, static_cast<GbmPixmap*>(plane.pixmap.get())->buffer()->framebuffer(),
plane.plane_transform, plane.display_bounds, plane.crop_rect, plane.z_order, plane.plane_transform, plane.display_bounds,
plane.enable_blend, std::move(plane.gpu_fence))); plane.crop_rect, plane.enable_blend, std::move(plane.gpu_fence)));
} }
unsubmitted_frame.submission_callback = std::move(submission_callback); unsubmitted_frame.submission_callback = std::move(submission_callback);
unsubmitted_frame.presentation_callback = std::move(presentation_callback); unsubmitted_frame.presentation_callback = std::move(presentation_callback);
......
...@@ -164,7 +164,7 @@ scoped_refptr<gfx::NativePixmap> GbmSurfaceFactory::CreateNativePixmapForVulkan( ...@@ -164,7 +164,7 @@ scoped_refptr<gfx::NativePixmap> GbmSurfaceFactory::CreateNativePixmapForVulkan(
VkDeviceMemory* vk_device_memory, VkDeviceMemory* vk_device_memory,
VkImage* vk_image) { VkImage* vk_image) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
scoped_refptr<GbmBuffer> buffer = drm_thread_proxy_->CreateBuffer( std::unique_ptr<GbmBuffer> buffer = drm_thread_proxy_->CreateBuffer(
widget, size, format, usage, GbmBuffer::kFlagNoModifiers); widget, size, format, usage, GbmBuffer::kFlagNoModifiers);
if (!buffer.get()) if (!buffer.get())
return nullptr; return nullptr;
...@@ -201,7 +201,7 @@ scoped_refptr<gfx::NativePixmap> GbmSurfaceFactory::CreateNativePixmapForVulkan( ...@@ -201,7 +201,7 @@ scoped_refptr<gfx::NativePixmap> GbmSurfaceFactory::CreateNativePixmapForVulkan(
return nullptr; return nullptr;
} }
return base::MakeRefCounted<GbmPixmap>(this, buffer); return base::MakeRefCounted<GbmPixmap>(this, std::move(buffer));
#else #else
return nullptr; return nullptr;
#endif #endif
...@@ -233,12 +233,12 @@ scoped_refptr<gfx::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( ...@@ -233,12 +233,12 @@ scoped_refptr<gfx::NativePixmap> GbmSurfaceFactory::CreateNativePixmap(
gfx::Size size, gfx::Size size,
gfx::BufferFormat format, gfx::BufferFormat format,
gfx::BufferUsage usage) { gfx::BufferUsage usage) {
scoped_refptr<GbmBuffer> buffer = drm_thread_proxy_->CreateBuffer( std::unique_ptr<GbmBuffer> buffer = drm_thread_proxy_->CreateBuffer(
widget, size, format, usage, 0 /* flags */); widget, size, format, usage, 0 /* flags */);
if (!buffer.get()) if (!buffer.get())
return nullptr; return nullptr;
return base::MakeRefCounted<GbmPixmap>(this, buffer); return base::MakeRefCounted<GbmPixmap>(this, std::move(buffer));
} }
scoped_refptr<gfx::NativePixmap> scoped_refptr<gfx::NativePixmap>
...@@ -262,12 +262,12 @@ GbmSurfaceFactory::CreateNativePixmapFromHandleInternal( ...@@ -262,12 +262,12 @@ GbmSurfaceFactory::CreateNativePixmapFromHandleInternal(
planes.push_back(plane); planes.push_back(plane);
} }
scoped_refptr<GbmBuffer> buffer = drm_thread_proxy_->CreateBufferFromFds( std::unique_ptr<GbmBuffer> buffer = drm_thread_proxy_->CreateBufferFromFds(
widget, size, format, std::move(scoped_fds), planes); widget, size, format, std::move(scoped_fds), planes);
if (!buffer) if (!buffer)
return nullptr; return nullptr;
return base::MakeRefCounted<GbmPixmap>(this, buffer); return base::MakeRefCounted<GbmPixmap>(this, std::move(buffer));
} }
scoped_refptr<gfx::NativePixmap> scoped_refptr<gfx::NativePixmap>
......
...@@ -46,8 +46,7 @@ GbmSurfaceless::GbmSurfaceless(GbmSurfaceFactory* surface_factory, ...@@ -46,8 +46,7 @@ GbmSurfaceless::GbmSurfaceless(GbmSurfaceFactory* surface_factory,
} }
void GbmSurfaceless::QueueOverlayPlane(DrmOverlayPlane plane) { void GbmSurfaceless::QueueOverlayPlane(DrmOverlayPlane plane) {
is_on_external_drm_device_ = is_on_external_drm_device_ = !plane.buffer->drm_device()->is_primary_device();
!plane.buffer->GetDrmDevice()->is_primary_device();
planes_.push_back(std::move(plane)); planes_.push_back(std::move(plane));
} }
......
...@@ -359,7 +359,7 @@ void HardwareDisplayController::AllocateCursorBuffers() { ...@@ -359,7 +359,7 @@ void HardwareDisplayController::AllocateCursorBuffers() {
SkImageInfo info = SkImageInfo::MakeN32Premul(max_cursor_size.width(), SkImageInfo info = SkImageInfo::MakeN32Premul(max_cursor_size.width(),
max_cursor_size.height()); max_cursor_size.height());
for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) { for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) {
cursor_buffers_[i] = new DrmBuffer(GetDrmDevice()); cursor_buffers_[i] = std::make_unique<DrmBuffer>(GetDrmDevice());
// Don't register a framebuffer for cursors since they are special (they // Don't register a framebuffer for cursors since they are special (they
// aren't modesetting buffers and drivers may fail to register them due to // aren't modesetting buffers and drivers may fail to register them due to
// their small sizes). // their small sizes).
......
...@@ -195,7 +195,7 @@ class HardwareDisplayController { ...@@ -195,7 +195,7 @@ class HardwareDisplayController {
DrmOverlayPlaneList current_planes_; DrmOverlayPlaneList current_planes_;
base::TimeTicks time_of_last_flip_; base::TimeTicks time_of_last_flip_;
scoped_refptr<DrmBuffer> cursor_buffers_[2]; std::unique_ptr<DrmBuffer> cursor_buffers_[2];
gfx::Point cursor_location_; gfx::Point cursor_location_;
int cursor_frontbuffer_ = 0; int cursor_frontbuffer_ = 0;
DrmBuffer* current_cursor_ = nullptr; DrmBuffer* current_cursor_ = nullptr;
......
...@@ -114,9 +114,9 @@ bool HardwareDisplayPlaneManager::IsCompatible(HardwareDisplayPlane* plane, ...@@ -114,9 +114,9 @@ bool HardwareDisplayPlaneManager::IsCompatible(HardwareDisplayPlane* plane,
!plane->CanUseForCrtc(crtc_index)) !plane->CanUseForCrtc(crtc_index))
return false; return false;
const uint32_t format = overlay.enable_blend ? const uint32_t format =
overlay.buffer->GetFramebufferPixelFormat() : overlay.enable_blend ? overlay.buffer->framebuffer_pixel_format()
overlay.buffer->GetOpaqueFramebufferPixelFormat(); : overlay.buffer->opaque_framebuffer_pixel_format();
if (!plane->IsSupportedFormat(format)) if (!plane->IsSupportedFormat(format))
return false; return false;
...@@ -181,7 +181,7 @@ bool HardwareDisplayPlaneManager::AssignOverlayPlanes( ...@@ -181,7 +181,7 @@ bool HardwareDisplayPlaneManager::AssignOverlayPlanes(
gfx::Rect fixed_point_rect; gfx::Rect fixed_point_rect;
if (hw_plane->type() != HardwareDisplayPlane::kDummy) { if (hw_plane->type() != HardwareDisplayPlane::kDummy) {
const gfx::Size& size = plane.buffer->GetSize(); const gfx::Size& size = plane.buffer->size();
gfx::RectF crop_rect = plane.crop_rect; gfx::RectF crop_rect = plane.crop_rect;
crop_rect.Scale(size.width(), size.height()); crop_rect.Scale(size.width(), size.height());
......
...@@ -222,8 +222,8 @@ bool HardwareDisplayPlaneManagerAtomic::SetPlaneData( ...@@ -222,8 +222,8 @@ bool HardwareDisplayPlaneManagerAtomic::SetPlaneData(
HardwareDisplayPlaneAtomic* atomic_plane = HardwareDisplayPlaneAtomic* atomic_plane =
static_cast<HardwareDisplayPlaneAtomic*>(hw_plane); static_cast<HardwareDisplayPlaneAtomic*>(hw_plane);
uint32_t framebuffer_id = overlay.enable_blend uint32_t framebuffer_id = overlay.enable_blend
? overlay.buffer->GetFramebufferId() ? overlay.buffer->framebuffer_id()
: overlay.buffer->GetOpaqueFramebufferId(); : overlay.buffer->opaque_framebuffer_id();
int fence_fd = base::kInvalidPlatformFile; int fence_fd = base::kInvalidPlatformFile;
if (overlay.gpu_fence) { if (overlay.gpu_fence) {
......
...@@ -112,7 +112,7 @@ bool HardwareDisplayPlaneManagerLegacy::ValidatePrimarySize( ...@@ -112,7 +112,7 @@ bool HardwareDisplayPlaneManagerLegacy::ValidatePrimarySize(
const drmModeModeInfo& mode) { const drmModeModeInfo& mode) {
DCHECK(primary.buffer.get()); DCHECK(primary.buffer.get());
return primary.buffer->GetSize() == gfx::Size(mode.hdisplay, mode.vdisplay); return primary.buffer->size() == gfx::Size(mode.hdisplay, mode.vdisplay);
} }
void HardwareDisplayPlaneManagerLegacy::RequestPlanesReadyCallback( void HardwareDisplayPlaneManagerLegacy::RequestPlanesReadyCallback(
...@@ -184,7 +184,7 @@ bool HardwareDisplayPlaneManagerLegacy::SetPlaneData( ...@@ -184,7 +184,7 @@ bool HardwareDisplayPlaneManagerLegacy::SetPlaneData(
plane_list->legacy_page_flips.back().crtc_id != crtc_id) { plane_list->legacy_page_flips.back().crtc_id != crtc_id) {
plane_list->legacy_page_flips.push_back( plane_list->legacy_page_flips.push_back(
HardwareDisplayPlaneList::PageFlipInfo( HardwareDisplayPlaneList::PageFlipInfo(
crtc_id, overlay.buffer->GetOpaqueFramebufferId(), crtc)); crtc_id, overlay.buffer->opaque_framebuffer_id(), crtc));
} else { } else {
return false; return false;
} }
...@@ -202,7 +202,7 @@ bool HardwareDisplayPlaneManagerLegacy::IsCompatible( ...@@ -202,7 +202,7 @@ bool HardwareDisplayPlaneManagerLegacy::IsCompatible(
// When using legacy kms we always scanout only one plane (the primary), // When using legacy kms we always scanout only one plane (the primary),
// and we always use the opaque fb. Refer to SetPlaneData above. // and we always use the opaque fb. Refer to SetPlaneData above.
const uint32_t format = overlay.buffer->GetOpaqueFramebufferPixelFormat(); const uint32_t format = overlay.buffer->opaque_framebuffer_pixel_format();
return plane->IsSupportedFormat(format); return plane->IsSupportedFormat(format);
} }
......
...@@ -39,7 +39,6 @@ constexpr uint32_t kDegammaLutSizePropId = 307; ...@@ -39,7 +39,6 @@ constexpr uint32_t kDegammaLutSizePropId = 307;
constexpr uint32_t kOutFencePtrPropId = 308; constexpr uint32_t kOutFencePtrPropId = 308;
constexpr uint32_t kInFormatsBlobPropId = 400; constexpr uint32_t kInFormatsBlobPropId = 400;
const uint32_t kDummyFormat = 0;
const gfx::Size kDefaultBufferSize(2, 2); const gfx::Size kDefaultBufferSize(2, 2);
class HardwareDisplayPlaneManagerTest class HardwareDisplayPlaneManagerTest
...@@ -299,7 +298,7 @@ TEST_P(HardwareDisplayPlaneManagerLegacyTest, MultiplePlanesAndCrtcs) { ...@@ -299,7 +298,7 @@ TEST_P(HardwareDisplayPlaneManagerLegacyTest, MultiplePlanesAndCrtcs) {
TEST_P(HardwareDisplayPlaneManagerLegacyTest, CheckFramebufferFormatMatch) { TEST_P(HardwareDisplayPlaneManagerLegacyTest, CheckFramebufferFormatMatch) {
ui::DrmOverlayPlaneList assigns; ui::DrmOverlayPlaneList assigns;
scoped_refptr<ui::DrmFramebuffer> buffer = scoped_refptr<ui::DrmFramebuffer> buffer =
CreateBufferWithFormat(kDefaultBufferSize, kDummyFormat); CreateBufferWithFormat(kDefaultBufferSize, DRM_FORMAT_NV12);
assigns.push_back(ui::DrmOverlayPlane(buffer, nullptr)); assigns.push_back(ui::DrmOverlayPlane(buffer, nullptr));
InitializeDrmState(/*crtc_count=*/2, /*planes_per_crtc=*/1); InitializeDrmState(/*crtc_count=*/2, /*planes_per_crtc=*/1);
...@@ -939,12 +938,12 @@ TEST(HardwareDisplayPlaneManagerAtomic, EnableBlend) { ...@@ -939,12 +938,12 @@ TEST(HardwareDisplayPlaneManagerAtomic, EnableBlend) {
overlay.enable_blend = true; overlay.enable_blend = true;
plane_manager->SetPlaneData(&plane_list, &hw_plane, overlay, 1, gfx::Rect(), plane_manager->SetPlaneData(&plane_list, &hw_plane, overlay, 1, gfx::Rect(),
nullptr); nullptr);
EXPECT_EQ(hw_plane.framebuffer(), buffer->GetFramebufferId()); EXPECT_EQ(hw_plane.framebuffer(), buffer->framebuffer_id());
overlay.enable_blend = false; overlay.enable_blend = false;
plane_manager->SetPlaneData(&plane_list, &hw_plane, overlay, 1, gfx::Rect(), plane_manager->SetPlaneData(&plane_list, &hw_plane, overlay, 1, gfx::Rect(),
nullptr); nullptr);
EXPECT_EQ(hw_plane.framebuffer(), buffer->GetOpaqueFramebufferId()); EXPECT_EQ(hw_plane.framebuffer(), buffer->opaque_framebuffer_id());
} }
} // namespace } // namespace
...@@ -13,42 +13,7 @@ namespace ui { ...@@ -13,42 +13,7 @@ namespace ui {
namespace { namespace {
uint32_t g_current_framebuffer_id = 1; uint32_t g_current_mock_buffer_handle = 0x1111;
class MockDrmFramebuffer : public DrmFramebuffer {
public:
MockDrmFramebuffer(const gfx::Size& size,
uint32_t format,
uint64_t modifier,
const scoped_refptr<DrmDevice>& drm)
: size_(size),
format_(format),
modifier_(modifier),
id_(g_current_framebuffer_id++),
opaque_id_(g_current_framebuffer_id++),
drm_(drm) {}
// DrmFramebuffer:
uint32_t GetFramebufferId() const override { return id_; }
uint32_t GetOpaqueFramebufferId() const override { return opaque_id_; }
gfx::Size GetSize() const override { return size_; }
uint32_t GetFramebufferPixelFormat() const override { return format_; }
uint32_t GetOpaqueFramebufferPixelFormat() const override { return format_; }
uint64_t GetFormatModifier() const override { return modifier_; }
const DrmDevice* GetDrmDevice() const override { return drm_.get(); }
private:
~MockDrmFramebuffer() override {}
gfx::Size size_;
uint32_t format_;
uint64_t modifier_;
uint32_t id_;
uint32_t opaque_id_;
scoped_refptr<DrmDevice> drm_;
DISALLOW_COPY_AND_ASSIGN(MockDrmFramebuffer);
};
} // namespace } // namespace
...@@ -74,10 +39,15 @@ scoped_refptr<DrmFramebuffer> MockDrmFramebufferGenerator::CreateWithModifier( ...@@ -74,10 +39,15 @@ scoped_refptr<DrmFramebuffer> MockDrmFramebufferGenerator::CreateWithModifier(
if (allocation_failure_) if (allocation_failure_)
return nullptr; return nullptr;
scoped_refptr<DrmFramebuffer> buffer( DrmFramebuffer::AddFramebufferParams params;
new MockDrmFramebuffer(size, format, modifier, drm)); params.format = format;
params.modifier = modifier;
params.width = size.width();
params.height = size.height();
params.num_planes = 1;
params.handles[0] = g_current_mock_buffer_handle++;
return buffer; return DrmFramebuffer::AddFramebuffer(drm, params);
} }
} // namespace ui } // namespace ui
...@@ -18,12 +18,12 @@ scoped_refptr<DrmFramebuffer> MockDumbBufferGenerator::Create( ...@@ -18,12 +18,12 @@ scoped_refptr<DrmFramebuffer> MockDumbBufferGenerator::Create(
uint32_t format, uint32_t format,
const std::vector<uint64_t>& modifiers, const std::vector<uint64_t>& modifiers,
const gfx::Size& size) { const gfx::Size& size) {
scoped_refptr<DrmBuffer> buffer(new DrmBuffer(drm)); std::unique_ptr<DrmBuffer> buffer(new DrmBuffer(drm));
SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
if (!buffer->Initialize(info, true /* should_register_framebuffer */)) if (!buffer->Initialize(info, true /* should_register_framebuffer */))
return NULL; return NULL;
return buffer; return buffer->framebuffer();
} }
} // namespace ui } // namespace ui
...@@ -33,9 +33,9 @@ namespace { ...@@ -33,9 +33,9 @@ namespace {
void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm, void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm,
HardwareDisplayController* controller, HardwareDisplayController* controller,
DrmFramebuffer* buffer) { DrmFramebuffer* buffer) {
DrmConsoleBuffer modeset_buffer(drm, buffer->GetOpaqueFramebufferId()); DrmConsoleBuffer modeset_buffer(drm, buffer->opaque_framebuffer_id());
if (!modeset_buffer.Initialize()) { if (!modeset_buffer.Initialize()) {
VLOG(2) << "Failed to grab framebuffer " << buffer->GetOpaqueFramebufferId(); VLOG(2) << "Failed to grab framebuffer " << buffer->opaque_framebuffer_id();
return; return;
} }
...@@ -47,7 +47,7 @@ void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm, ...@@ -47,7 +47,7 @@ void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm,
return; return;
} }
uint32_t fourcc_format = buffer->GetFramebufferPixelFormat(); uint32_t fourcc_format = buffer->framebuffer_pixel_format();
const auto& modifiers = controller->GetFormatModifiers(fourcc_format); const auto& modifiers = controller->GetFormatModifiers(fourcc_format);
for (const uint64_t modifier : modifiers) { for (const uint64_t modifier : modifiers) {
// A value of 0 means DRM_FORMAT_MOD_NONE. If the CRTC has any other // A value of 0 means DRM_FORMAT_MOD_NONE. If the CRTC has any other
...@@ -371,8 +371,8 @@ DrmOverlayPlane ScreenManager::GetModesetBuffer( ...@@ -371,8 +371,8 @@ DrmOverlayPlane ScreenManager::GetModesetBuffer(
if (window) { if (window) {
const DrmOverlayPlane* primary = window->GetLastModesetBuffer(); const DrmOverlayPlane* primary = window->GetLastModesetBuffer();
const DrmDevice* drm = controller->GetDrmDevice().get(); const DrmDevice* drm = controller->GetDrmDevice().get();
if (primary && primary->buffer->GetSize() == bounds.size() && if (primary && primary->buffer->size() == bounds.size() &&
primary->buffer->GetDrmDevice() == drm) { primary->buffer->drm_device() == drm) {
// If the controller doesn't advertise modifiers, wont have a // If the controller doesn't advertise modifiers, wont have a
// modifier either and we can reuse the buffer. Otherwise, check // modifier either and we can reuse the buffer. Otherwise, check
// to see if the controller supports the buffers format // to see if the controller supports the buffers format
...@@ -380,7 +380,7 @@ DrmOverlayPlane ScreenManager::GetModesetBuffer( ...@@ -380,7 +380,7 @@ DrmOverlayPlane ScreenManager::GetModesetBuffer(
if (modifiers.empty()) if (modifiers.empty())
return primary->Clone(); return primary->Clone();
for (const uint64_t modifier : modifiers) { for (const uint64_t modifier : modifiers) {
if (modifier == primary->buffer->GetFormatModifier()) if (modifier == primary->buffer->format_modifier())
return primary->Clone(); return primary->Clone();
} }
} }
......
...@@ -518,7 +518,7 @@ TEST_F(ScreenManagerTest, EnableControllerWhenWindowHasBuffer) { ...@@ -518,7 +518,7 @@ TEST_F(ScreenManagerTest, EnableControllerWhenWindowHasBuffer) {
drm_, kPrimaryCrtc, kPrimaryConnector, GetPrimaryBounds().origin(), drm_, kPrimaryCrtc, kPrimaryConnector, GetPrimaryBounds().origin(),
kDefaultMode); kDefaultMode);
EXPECT_EQ(buffer->GetOpaqueFramebufferId(), drm_->current_framebuffer()); EXPECT_EQ(buffer->opaque_framebuffer_id(), drm_->current_framebuffer());
window = screen_manager_->RemoveWindow(1); window = screen_manager_->RemoveWindow(1);
window->Shutdown(); window->Shutdown();
...@@ -550,8 +550,8 @@ TEST_F(ScreenManagerTest, DISABLED_RejectBufferWithIncompatibleModifiers) { ...@@ -550,8 +550,8 @@ TEST_F(ScreenManagerTest, DISABLED_RejectBufferWithIncompatibleModifiers) {
// modeset the new controller) should reject the buffer with // modeset the new controller) should reject the buffer with
// I915_FORMAT_MOD_X_TILED modifier we created above and the two // I915_FORMAT_MOD_X_TILED modifier we created above and the two
// framebuffer IDs should be different. // framebuffer IDs should be different.
EXPECT_NE(buffer->GetFramebufferId(), drm_->current_framebuffer()); EXPECT_NE(buffer->framebuffer_id(), drm_->current_framebuffer());
EXPECT_NE(buffer->GetOpaqueFramebufferId(), drm_->current_framebuffer()); EXPECT_NE(buffer->opaque_framebuffer_id(), drm_->current_framebuffer());
window = screen_manager_->RemoveWindow(1); window = screen_manager_->RemoveWindow(1);
window->Shutdown(); window->Shutdown();
......
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