Commit 47661a7f authored by vince.h's avatar vince.h Committed by Commit bot

Add format modifier IDs for EGL_EXT_image_dma_buf_import extension

And use them when creating a eglImageKHR for a EGL_LINUX_DMA_BUF_EXT target.

BUG=chromium:478339
TEST=none
Signed-off-by: default avatarVince Hsu <vince.h@nvidia.com>
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_optional_gpu_tests_rel;tryserver.chromium.mac:mac_optional_gpu_tests_rel;tryserver.chromium.win:win_optional_gpu_tests_rel

Committed: https://crrev.com/29292a32f6f429a790e8663ce09bf67d165f49e9
Review-Url: https://codereview.chromium.org/2039813002
Cr-Original-Commit-Position: refs/heads/master@{#402656}
Cr-Commit-Position: refs/heads/master@{#403418}
parent 445de0ec
......@@ -294,8 +294,7 @@ void ArcGpuVideoDecodeAccelerator::UseBuffer(PortType port,
#if defined(USE_OZONE)
handle.native_pixmap_handle.fds.emplace_back(
base::FileDescriptor(info.handle.release(), true));
handle.native_pixmap_handle.strides_and_offsets.emplace_back(
info.stride, 0);
handle.native_pixmap_handle.planes.emplace_back(info.stride, 0, 0);
#endif
vda_->ImportBufferForPicture(index, handle);
} else {
......
......@@ -62,8 +62,7 @@ std::unique_ptr<SharedMemory> Display::CreateSharedMemory(
std::unique_ptr<Buffer> Display::CreateLinuxDMABufBuffer(
const gfx::Size& size,
gfx::BufferFormat format,
const std::vector<int>& strides,
const std::vector<int>& offsets,
const std::vector<gfx::NativePixmapPlane>& planes,
std::vector<base::ScopedFD>&& fds) {
TRACE_EVENT1("exo", "Display::CreateLinuxDMABufBuffer", "size",
size.ToString());
......@@ -73,11 +72,8 @@ std::unique_ptr<Buffer> Display::CreateLinuxDMABufBuffer(
for (auto& fd : fds)
handle.native_pixmap_handle.fds.emplace_back(std::move(fd));
DCHECK_EQ(strides.size(), offsets.size());
for (size_t plane = 0; plane < strides.size(); ++plane) {
handle.native_pixmap_handle.strides_and_offsets.emplace_back(
strides[plane], offsets[plane]);
}
for (auto& plane : planes)
handle.native_pixmap_handle.planes.push_back(plane);
std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer =
aura::Env::GetInstance()
......
......@@ -17,6 +17,7 @@
#include "base/files/scoped_file.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_pixmap_handle_ozone.h"
#endif
namespace gfx {
......@@ -58,8 +59,7 @@ class Display {
std::unique_ptr<Buffer> CreateLinuxDMABufBuffer(
const gfx::Size& size,
gfx::BufferFormat format,
const std::vector<int>& strides,
const std::vector<int>& offsets,
const std::vector<gfx::NativePixmapPlane>& planes,
std::vector<base::ScopedFD>&& fds);
#endif
......
......@@ -68,23 +68,20 @@ TEST_F(DisplayTest, DISABLED_CreateLinuxDMABufBuffer) {
gfx::BufferFormat::RGBA_8888,
gfx::BufferUsage::GPU_READ);
gfx::NativePixmapHandle native_pixmap_handle = pixmap->ExportHandle();
std::vector<int> strides;
std::vector<int> offsets;
std::vector<gfx::NativePixmapPlane> planes;
std::vector<base::ScopedFD> fds;
strides.push_back(native_pixmap_handle.strides_and_offsets[0].first);
offsets.push_back(native_pixmap_handle.strides_and_offsets[0].second);
planes.push_back(native_pixmap_handle.planes[0]);
fds.push_back(base::ScopedFD(native_pixmap_handle.fds[0].fd));
std::unique_ptr<Buffer> buffer1 = display->CreateLinuxDMABufBuffer(
buffer_size, gfx::BufferFormat::RGBA_8888, strides, offsets,
std::move(fds));
buffer_size, gfx::BufferFormat::RGBA_8888, planes, std::move(fds));
EXPECT_TRUE(buffer1);
std::vector<base::ScopedFD> invalid_fds;
invalid_fds.push_back(base::ScopedFD());
// Creating a prime buffer using an invalid fd should fail.
std::unique_ptr<Buffer> buffer2 = display->CreateLinuxDMABufBuffer(
buffer_size, gfx::BufferFormat::RGBA_8888, strides, offsets,
buffer_size, gfx::BufferFormat::RGBA_8888, planes,
std::move(invalid_fds));
EXPECT_FALSE(buffer2);
}
......
......@@ -521,20 +521,21 @@ void drm_create_prime_buffer(wl_client* client,
return;
}
std::vector<int> strides{stride0, stride1, stride2};
std::vector<int> offsets{offset0, offset1, offset2};
std::vector<gfx::NativePixmapPlane> planes;
planes.emplace_back(stride0, offset0, 0);
planes.emplace_back(stride1, offset1, 0);
planes.emplace_back(stride2, offset2, 0);
std::vector<base::ScopedFD> fds;
int planes =
size_t num_planes =
gfx::NumberOfPlanesForBufferFormat(supported_format->buffer_format);
strides.resize(planes);
offsets.resize(planes);
planes.resize(num_planes);
fds.push_back(base::ScopedFD(name));
std::unique_ptr<Buffer> buffer =
GetUserDataAs<Display>(resource)->CreateLinuxDMABufBuffer(
gfx::Size(width, height), supported_format->buffer_format, strides,
offsets, std::move(fds));
gfx::Size(width, height), supported_format->buffer_format, planes,
std::move(fds));
if (!buffer) {
wl_resource_post_no_memory(resource);
return;
......@@ -667,8 +668,7 @@ void linux_buffer_params_create(wl_client* client,
return;
}
std::vector<int> strides;
std::vector<int> offsets;
std::vector<gfx::NativePixmapPlane> planes;
std::vector<base::ScopedFD> fds;
for (uint32_t i = 0; i < num_planes; ++i) {
......@@ -680,16 +680,15 @@ void linux_buffer_params_create(wl_client* client,
return;
}
LinuxBufferParams::Plane& plane = plane_it->second;
strides.push_back(plane.stride);
offsets.push_back(plane.offset);
planes.emplace_back(plane.stride, plane.offset, 0);
if (plane.fd.is_valid())
fds.push_back(std::move(plane.fd));
}
std::unique_ptr<Buffer> buffer =
linux_buffer_params->display->CreateLinuxDMABufBuffer(
gfx::Size(width, height), supported_format->buffer_format, strides,
offsets, std::move(fds));
gfx::Size(width, height), supported_format->buffer_format, planes,
std::move(fds));
if (!buffer) {
zwp_linux_buffer_params_v1_send_failed(resource);
return;
......
......@@ -260,8 +260,8 @@ gfx::GpuMemoryBufferHandle GpuChannelHost::ShareGpuMemoryBufferToGpuProcess(
handle.native_pixmap_handle.fds.emplace_back(scoped_fd.release(),
true /* auto_close */);
}
handle.native_pixmap_handle.strides_and_offsets =
source_handle.native_pixmap_handle.strides_and_offsets;
handle.native_pixmap_handle.planes =
source_handle.native_pixmap_handle.planes;
*requires_sync_point = false;
return handle;
}
......
......@@ -30,11 +30,11 @@ GpuMemoryBufferImplOzoneNativePixmap::GpuMemoryBufferImplOzoneNativePixmap(
gfx::BufferFormat format,
const DestructionCallback& callback,
std::unique_ptr<ui::ClientNativePixmap> pixmap,
const std::vector<std::pair<int, int>>& strides_and_offsets,
const std::vector<gfx::NativePixmapPlane>& planes,
base::ScopedFD fd)
: GpuMemoryBufferImpl(id, size, format, callback),
pixmap_(std::move(pixmap)),
strides_and_offsets_(strides_and_offsets),
planes_(planes),
fd_(std::move(fd)),
data_(nullptr) {}
......@@ -64,8 +64,7 @@ GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle(
gfx::NativePixmapHandle native_pixmap_handle;
native_pixmap_handle.fds.emplace_back(handle.native_pixmap_handle.fds[0].fd,
true /* auto_close */);
native_pixmap_handle.strides_and_offsets =
handle.native_pixmap_handle.strides_and_offsets;
native_pixmap_handle.planes = handle.native_pixmap_handle.planes;
std::unique_ptr<ui::ClientNativePixmap> native_pixmap =
ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle(
native_pixmap_handle, size, usage);
......@@ -73,7 +72,7 @@ GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle(
return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap(
handle.id, size, format, callback, std::move(native_pixmap),
handle.native_pixmap_handle.strides_and_offsets, std::move(scoped_fd)));
handle.native_pixmap_handle.planes, std::move(scoped_fd)));
}
// static
......@@ -138,7 +137,7 @@ gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle()
handle.id = id_;
handle.native_pixmap_handle.fds.emplace_back(fd_.get(),
false /* auto_close */);
handle.native_pixmap_handle.strides_and_offsets = strides_and_offsets_;
handle.native_pixmap_handle.planes = planes_;
return handle;
}
......
......@@ -54,11 +54,11 @@ class GPU_EXPORT GpuMemoryBufferImplOzoneNativePixmap
gfx::BufferFormat format,
const DestructionCallback& callback,
std::unique_ptr<ui::ClientNativePixmap> native_pixmap,
const std::vector<std::pair<int, int>>& strides_and_offsets,
const std::vector<gfx::NativePixmapPlane>& planes,
base::ScopedFD fd);
std::unique_ptr<ui::ClientNativePixmap> pixmap_;
std::vector<std::pair<int, int>> strides_and_offsets_;
std::vector<gfx::NativePixmapPlane> planes_;
base::ScopedFD fd_;
void* data_;
......
......@@ -371,8 +371,9 @@ gfx::GpuMemoryBufferHandle TextureRef::ExportGpuMemoryBufferHandle() const {
handle.type = gfx::OZONE_NATIVE_PIXMAP;
handle.native_pixmap_handle.fds.emplace_back(
base::FileDescriptor(duped_fd, true));
handle.native_pixmap_handle.strides_and_offsets.emplace_back(
pixmap_->GetDmaBufPitch(0), pixmap_->GetDmaBufOffset(0));
handle.native_pixmap_handle.planes.emplace_back(
pixmap_->GetDmaBufPitch(0), pixmap_->GetDmaBufOffset(0),
pixmap_->GetDmaBufModifier(0));
#endif
return handle;
}
......
......@@ -561,6 +561,12 @@ typedef EGLint (EGLAPIENTRYP PFNEGLDUPNATIVEFENCEFDANDROIDPROC)(EGLDisplay dpy,
#define EGL_YUV_NARROW_RANGE_EXT 0x3283
#define EGL_YUV_CHROMA_SITING_0_EXT 0x3284
#define EGL_YUV_CHROMA_SITING_0_5_EXT 0x3285
#define EGL_LINUX_DRM_PLANE0_MODIFIER0_EXT 0x3286
#define EGL_LINUX_DRM_PLANE0_MODIFIER1_EXT 0x3287
#define EGL_LINUX_DRM_PLANE1_MODIFIER0_EXT 0x3288
#define EGL_LINUX_DRM_PLANE1_MODIFIER1_EXT 0x3289
#define EGL_LINUX_DRM_PLANE2_MODIFIER0_EXT 0x328a
#define EGL_LINUX_DRM_PLANE2_MODIFIER1_EXT 0x328b
#endif
#ifndef EGL_ARM_implicit_external_sync
......
......@@ -35,6 +35,7 @@ EGL/eglplatform.h
- Added EGLNative*Type for native linux framebuffers.
EGL/eglext.h
- Added EGL_ARM_implicit_external_sync extension tokens
- Added format modifier for EGL_EXT_image_dma_buf_import extension
KHR/khrplatform.h
- Modified KHRONOS_APICALL
DEPS
......
......@@ -51,9 +51,15 @@ IPC_STRUCT_TRAITS_BEGIN(gfx::GpuMemoryBufferId)
IPC_STRUCT_TRAITS_END()
#if defined(USE_OZONE)
IPC_STRUCT_TRAITS_BEGIN(gfx::NativePixmapPlane)
IPC_STRUCT_TRAITS_MEMBER(stride)
IPC_STRUCT_TRAITS_MEMBER(offset)
IPC_STRUCT_TRAITS_MEMBER(modifier)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(gfx::NativePixmapHandle)
IPC_STRUCT_TRAITS_MEMBER(fds)
IPC_STRUCT_TRAITS_MEMBER(strides_and_offsets)
IPC_STRUCT_TRAITS_MEMBER(planes)
IPC_STRUCT_TRAITS_END()
#endif
......
......@@ -6,6 +6,15 @@
namespace gfx {
NativePixmapPlane::NativePixmapPlane() : stride(0), offset(0), modifier(0) {}
NativePixmapPlane::NativePixmapPlane(int stride, int offset, uint64_t modifier)
: stride(stride), offset(offset), modifier(modifier) {}
NativePixmapPlane::NativePixmapPlane(const NativePixmapPlane& other) = default;
NativePixmapPlane::~NativePixmapPlane() {}
NativePixmapHandle::NativePixmapHandle() {}
NativePixmapHandle::NativePixmapHandle(const NativePixmapHandle& other) =
default;
......
......@@ -13,6 +13,24 @@
namespace gfx {
// NativePixmapPlane is used to carry the plane related information for GBM
// buffer. More fields can be added if they are plane specific.
struct GFX_EXPORT NativePixmapPlane {
NativePixmapPlane();
NativePixmapPlane(int stride, int offset, uint64_t modifier);
NativePixmapPlane(const NativePixmapPlane& other);
~NativePixmapPlane();
// The strides and offsets in bytes to be used when accessing the buffers via
// a memory mapping. One per plane per entry.
int stride;
int offset;
// The modifier is retrieved from GBM library and passed to EGL driver.
// Generally it's platform specific, and we don't need to modify it in
// Chromium code. Also one per plane per entry.
uint64_t modifier;
};
struct GFX_EXPORT NativePixmapHandle {
NativePixmapHandle();
NativePixmapHandle(const NativePixmapHandle& other);
......@@ -21,9 +39,7 @@ struct GFX_EXPORT NativePixmapHandle {
// File descriptors for the underlying memory objects (usually dmabufs).
std::vector<base::FileDescriptor> fds;
// The strides and offsets in bytes to be used when accessing the buffers via
// a memory mapping. One per plane per entry.
std::vector<std::pair<int, int>> strides_and_offsets;
std::vector<NativePixmapPlane> planes;
};
} // namespace gfx
......
......@@ -4,6 +4,7 @@
#include "ui/gfx/buffer_format_util.h"
#include "ui/gl/gl_image_ozone_native_pixmap.h"
#include "ui/gl/gl_surface_egl.h"
#define FOURCC(a, b, c, d) \
((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \
......@@ -137,6 +138,12 @@ bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap,
attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT);
attrs.push_back(FourCC(format));
const EGLint kLinuxDrmModifiers[] = {EGL_LINUX_DRM_PLANE0_MODIFIER0_EXT,
EGL_LINUX_DRM_PLANE1_MODIFIER0_EXT,
EGL_LINUX_DRM_PLANE2_MODIFIER0_EXT};
bool has_dma_buf_import_modifier =
GLSurfaceEGL::HasEGLExtension("EGL_EXT_image_dma_buf_import_modifiers");
for (size_t plane = 0;
plane < gfx::NumberOfPlanesForBufferFormat(pixmap->GetBufferFormat());
++plane) {
......@@ -147,6 +154,14 @@ bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap,
attrs.push_back(pixmap->GetDmaBufOffset(plane));
attrs.push_back(EGL_DMA_BUF_PLANE0_PITCH_EXT + plane * 3);
attrs.push_back(pixmap->GetDmaBufPitch(plane));
if (has_dma_buf_import_modifier) {
uint64_t modifier = pixmap->GetDmaBufModifier(plane);
DCHECK(plane < arraysize(kLinuxDrmModifiers));
attrs.push_back(kLinuxDrmModifiers[plane]);
attrs.push_back(modifier & 0xffffffff);
attrs.push_back(kLinuxDrmModifiers[plane] + 1);
attrs.push_back(static_cast<uint32_t>(modifier >> 32));
}
}
attrs.push_back(EGL_NONE);
......
......@@ -89,7 +89,7 @@ scoped_refptr<ui::NativePixmap> CreateYVU420Pixmap(const gfx::Size& size,
gfx::NativePixmapHandle pixmap_handle;
pixmap_handle.fds.emplace_back(fd, false);
for (int i = 0; i < 3; i++) {
pixmap_handle.strides_and_offsets.emplace_back(pitches[i], offsets[i]);
pixmap_handle.planes.emplace_back(pitches[i], offsets[i], 0);
}
ui::SurfaceFactoryOzone* surface_factory =
ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone();
......
......@@ -258,6 +258,7 @@ scoped_refptr<NativePixmap> SurfaceFactoryCast::CreateNativePixmap(
int GetDmaBufFd(size_t plane) const override { return -1; }
int GetDmaBufPitch(size_t plane) const override { return 0; }
int GetDmaBufOffset(size_t plane) const override { return 0; }
uint64_t GetDmaBufModifier(size_t plane) const override { return 0; }
gfx::BufferFormat GetBufferFormat() const override {
return gfx::BufferFormat::BGRA_8888;
}
......
......@@ -80,7 +80,7 @@ class ClientNativePixmapFactoryGbm : public ClientNativePixmapFactory {
// TODO(dcastagna): Add support for pixmaps with multiple FDs for non
// scanout buffers.
return ClientNativePixmapDmaBuf::ImportFromDmabuf(
scoped_fd.release(), size, handle.strides_and_offsets[0].first);
scoped_fd.release(), size, handle.planes[0].stride);
#else
NOTREACHED();
return nullptr;
......
......@@ -110,17 +110,17 @@ void DrmThread::CreateBuffer(gfx::AcceleratedWidget widget,
*buffer = GbmBuffer::CreateBuffer(gbm, format, size, usage);
}
void DrmThread::CreateBufferFromFds(const gfx::Size& size,
gfx::BufferFormat format,
std::vector<base::ScopedFD>&& fds,
std::vector<int> strides,
std::vector<int> offsets,
scoped_refptr<GbmBuffer>* buffer) {
void DrmThread::CreateBufferFromFds(
const gfx::Size& size,
gfx::BufferFormat format,
std::vector<base::ScopedFD>&& fds,
const std::vector<gfx::NativePixmapPlane>& planes,
scoped_refptr<GbmBuffer>* buffer) {
scoped_refptr<GbmDevice> gbm =
static_cast<GbmDevice*>(device_manager_->GetPrimaryDrmDevice().get());
DCHECK(gbm);
*buffer = GbmBuffer::CreateBufferFromFds(gbm, format, size, std::move(fds),
strides, offsets);
*buffer =
GbmBuffer::CreateBufferFromFds(gbm, format, size, std::move(fds), planes);
}
void DrmThread::GetScanoutFormats(
......
......@@ -13,6 +13,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
#include "ui/gfx/native_pixmap_handle_ozone.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/vsync_provider.h"
#include "ui/ozone/common/gpu/ozone_gpu_message_params.h"
......@@ -63,8 +64,7 @@ class DrmThread : public base::Thread {
void CreateBufferFromFds(const gfx::Size& size,
gfx::BufferFormat format,
std::vector<base::ScopedFD>&& fds,
std::vector<int> strides,
std::vector<int> offsets,
const std::vector<gfx::NativePixmapPlane>& planes,
scoped_refptr<GbmBuffer>* buffer);
void GetScanoutFormats(gfx::AcceleratedWidget widget,
......
......@@ -44,14 +44,12 @@ scoped_refptr<GbmBuffer> DrmThreadProxy::CreateBufferFromFds(
const gfx::Size& size,
gfx::BufferFormat format,
std::vector<base::ScopedFD>&& fds,
std::vector<int> strides,
std::vector<int> offsets) {
const std::vector<gfx::NativePixmapPlane>& planes) {
scoped_refptr<GbmBuffer> buffer;
PostSyncTask(
drm_thread_.task_runner(),
base::Bind(&DrmThread::CreateBufferFromFds,
base::Unretained(&drm_thread_), size, format,
base::Passed(std::move(fds)), strides, offsets, &buffer));
PostSyncTask(drm_thread_.task_runner(),
base::Bind(&DrmThread::CreateBufferFromFds,
base::Unretained(&drm_thread_), size, format,
base::Passed(std::move(fds)), planes, &buffer));
return buffer;
}
......
......@@ -38,8 +38,7 @@ class DrmThreadProxy {
const gfx::Size& size,
gfx::BufferFormat format,
std::vector<base::ScopedFD>&& fds,
std::vector<int> strides,
std::vector<int> offsets);
const std::vector<gfx::NativePixmapPlane>& planes);
void GetScanoutFormats(gfx::AcceleratedWidget widget,
std::vector<gfx::BufferFormat>* scanout_formats);
......
......@@ -32,15 +32,13 @@ GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm,
gfx::BufferUsage usage,
std::vector<base::ScopedFD>&& fds,
const gfx::Size& size,
const std::vector<int>& strides,
const std::vector<int>& offsets)
const std::vector<gfx::NativePixmapPlane>&& planes)
: GbmBufferBase(gbm, bo, format, usage),
format_(format),
usage_(usage),
fds_(std::move(fds)),
size_(size),
strides_(strides),
offsets_(offsets) {}
planes_(std::move(planes)) {}
GbmBuffer::~GbmBuffer() {
if (bo())
......@@ -62,19 +60,24 @@ size_t GbmBuffer::GetFdCount() const {
return fds_.size();
}
int GbmBuffer::GetFd(size_t plane) const {
DCHECK_LT(plane, fds_.size());
return fds_[plane].get();
int GbmBuffer::GetFd(size_t index) const {
DCHECK_LT(index, fds_.size());
return fds_[index].get();
}
int GbmBuffer::GetStride(size_t plane) const {
DCHECK_LT(plane, strides_.size());
return strides_[plane];
int GbmBuffer::GetStride(size_t index) const {
DCHECK_LT(index, planes_.size());
return planes_[index].stride;
}
int GbmBuffer::GetOffset(size_t plane) const {
DCHECK_LT(plane, offsets_.size());
return offsets_[plane];
int GbmBuffer::GetOffset(size_t index) const {
DCHECK_LT(index, planes_.size());
return planes_[index].offset;
}
uint64_t GbmBuffer::GetFormatModifier(size_t index) const {
DCHECK_LT(index, planes_.size());
return planes_[index].modifier;
}
// TODO(reveman): This should not be needed once crbug.com/597932 is fixed,
......@@ -120,12 +123,11 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer(
}
std::vector<base::ScopedFD> fds;
fds.emplace_back(std::move(fd));
std::vector<int> strides;
strides.push_back(gbm_bo_get_stride(bo));
std::vector<int> offsets;
offsets.push_back(gbm_bo_get_plane_offset(bo, 0));
std::vector<gfx::NativePixmapPlane> planes;
planes.emplace_back(gbm_bo_get_stride(bo), gbm_bo_get_plane_offset(bo, 0),
gbm_bo_get_format_modifier(bo));
scoped_refptr<GbmBuffer> buffer(new GbmBuffer(
gbm, bo, format, usage, std::move(fds), size, strides, offsets));
gbm, bo, format, usage, std::move(fds), size, std::move(planes)));
if (usage == gfx::BufferUsage::SCANOUT && !buffer->GetFramebufferId())
return nullptr;
......@@ -138,13 +140,11 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds(
gfx::BufferFormat format,
const gfx::Size& size,
std::vector<base::ScopedFD>&& fds,
const std::vector<int>& strides,
const std::vector<int>& offsets) {
const std::vector<gfx::NativePixmapPlane>& planes) {
TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device",
gbm->device_path().value(), "size", size.ToString());
DCHECK_LE(fds.size(), strides.size());
DCHECK_EQ(strides.size(), offsets.size());
DCHECK_EQ(offsets[0], 0);
DCHECK_LE(fds.size(), planes.size());
DCHECK_EQ(planes[0].offset, 0);
uint32_t fourcc_format = GetFourCCFormatFromBufferFormat(format);
......@@ -158,7 +158,7 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds(
fd_data.fd = fds[0].get();
fd_data.width = size.width();
fd_data.height = size.height();
fd_data.stride = strides[0];
fd_data.stride = planes[0].stride;
fd_data.format = fourcc_format;
// The fd passed to gbm_bo_import is not ref-counted and need to be
......@@ -174,7 +174,7 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds(
scoped_refptr<GbmBuffer> buffer(new GbmBuffer(
gbm, bo, format,
use_scanout ? gfx::BufferUsage::SCANOUT : gfx::BufferUsage::GPU_READ,
std::move(fds), size, strides, offsets));
std::move(fds), size, std::move(planes)));
// If scanout support for buffer is expected then make sure we managed to
// create a framebuffer for it as otherwise using it for scanout will fail.
if (use_scanout && !buffer->GetFramebufferId())
......@@ -207,8 +207,8 @@ gfx::NativePixmapHandle GbmPixmap::ExportHandle() {
handle.fds.emplace_back(
base::FileDescriptor(scoped_fd.release(), true /* auto_close */));
}
handle.strides_and_offsets.emplace_back(buffer_->GetStride(i),
buffer_->GetOffset(i));
handle.planes.emplace_back(buffer_->GetStride(i), buffer_->GetOffset(i),
buffer_->GetFormatModifier(i));
}
return handle;
}
......@@ -240,6 +240,10 @@ int GbmPixmap::GetDmaBufOffset(size_t plane) const {
return buffer_->GetOffset(plane);
}
uint64_t GbmPixmap::GetDmaBufModifier(size_t plane) const {
return buffer_->GetFormatModifier(plane);
}
gfx::BufferFormat GbmPixmap::GetBufferFormat() const {
return buffer_->GetFormat();
}
......
......@@ -33,8 +33,7 @@ class GbmBuffer : public GbmBufferBase {
gfx::BufferFormat format,
const gfx::Size& size,
std::vector<base::ScopedFD>&& fds,
const std::vector<int>& strides,
const std::vector<int>& offsets);
const std::vector<gfx::NativePixmapPlane>& planes);
gfx::BufferFormat GetFormat() const { return format_; }
gfx::BufferUsage GetUsage() const { return usage_; }
bool AreFdsValid() const;
......@@ -42,6 +41,7 @@ class GbmBuffer : public GbmBufferBase {
int GetFd(size_t plane) const;
int GetStride(size_t plane) const;
int GetOffset(size_t plane) const;
uint64_t GetFormatModifier(size_t plane) const;
gfx::Size GetSize() const override;
private:
......@@ -51,16 +51,15 @@ class GbmBuffer : public GbmBufferBase {
gfx::BufferUsage usage,
std::vector<base::ScopedFD>&& fds,
const gfx::Size& size,
const std::vector<int>& strides,
const std::vector<int>& offsets);
const std::vector<gfx::NativePixmapPlane>&& planes);
~GbmBuffer() override;
gfx::BufferFormat format_;
gfx::BufferUsage usage_;
std::vector<base::ScopedFD> fds_;
gfx::Size size_;
std::vector<int> strides_;
std::vector<int> offsets_;
std::vector<gfx::NativePixmapPlane> planes_;
DISALLOW_COPY_AND_ASSIGN(GbmBuffer);
};
......@@ -80,6 +79,7 @@ class GbmPixmap : public NativePixmap {
int GetDmaBufFd(size_t plane) const override;
int GetDmaBufPitch(size_t plane) const override;
int GetDmaBufOffset(size_t plane) const override;
uint64_t GetDmaBufModifier(size_t plane) const override;
gfx::BufferFormat GetBufferFormat() const override;
gfx::Size GetBufferSize() const override;
bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
......
......@@ -114,9 +114,9 @@ scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmapFromHandle(
gfx::Size size,
gfx::BufferFormat format,
const gfx::NativePixmapHandle& handle) {
size_t planes = gfx::NumberOfPlanesForBufferFormat(format);
if (handle.strides_and_offsets.size() != planes ||
(handle.fds.size() != 1 && handle.fds.size() != planes)) {
size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
if (handle.planes.size() != num_planes ||
(handle.fds.size() != 1 && handle.fds.size() != num_planes)) {
return nullptr;
}
std::vector<base::ScopedFD> scoped_fds;
......@@ -124,16 +124,14 @@ scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmapFromHandle(
scoped_fds.emplace_back(fd.fd);
}
std::vector<int> strides;
std::vector<int> offsets;
std::vector<gfx::NativePixmapPlane> planes;
for (const auto& stride_and_offset : handle.strides_and_offsets) {
strides.push_back(stride_and_offset.first);
offsets.push_back(stride_and_offset.second);
for (const auto& plane : handle.planes) {
planes.push_back(plane);
}
scoped_refptr<GbmBuffer> buffer = drm_thread_->CreateBufferFromFds(
size, format, std::move(scoped_fds), strides, offsets);
size, format, std::move(scoped_fds), planes);
if (!buffer)
return nullptr;
return make_scoped_refptr(new GbmPixmap(this, buffer));
......
......@@ -76,6 +76,7 @@ class TestPixmap : public ui::NativePixmap {
int GetDmaBufFd(size_t plane) const override { return -1; }
int GetDmaBufPitch(size_t plane) const override { return 0; }
int GetDmaBufOffset(size_t plane) const override { return 0; }
uint64_t GetDmaBufModifier(size_t plane) const override { return 0; }
gfx::BufferFormat GetBufferFormat() const override { return format_; }
gfx::Size GetBufferSize() const override { return gfx::Size(); }
bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
......
......@@ -31,6 +31,7 @@ class NativePixmap : public base::RefCountedThreadSafe<NativePixmap> {
virtual int GetDmaBufFd(size_t plane) const = 0;
virtual int GetDmaBufPitch(size_t plane) const = 0;
virtual int GetDmaBufOffset(size_t plane) const = 0;
virtual uint64_t GetDmaBufModifier(size_t plane) const = 0;
virtual gfx::BufferFormat GetBufferFormat() const = 0;
virtual gfx::Size GetBufferSize() const = 0;
......
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