| Index: ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.cc
|
| diff --git a/ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.cc b/ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.cc
|
| index 38667e51e180f2d306fc50ec87e8994da9d88e1f..c3f179c392c877fd30b45a5db7fb3d444b4e8e8c 100644
|
| --- a/ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.cc
|
| +++ b/ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.cc
|
| @@ -4,6 +4,9 @@
|
|
|
| #include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h"
|
|
|
| +#include <utility>
|
| +#include <vector>
|
| +
|
| #include "base/logging.h"
|
| #include "ui/gl/gl_image_egl.h"
|
| #include "ui/gl/gl_image_linux_dma_buffer.h"
|
| @@ -51,19 +54,34 @@ class GLImageOzoneNativePixmapDmaBuf : public gfx::GLImageLinuxDMABuffer {
|
| public:
|
| explicit GLImageOzoneNativePixmapDmaBuf(const gfx::Size& size,
|
| unsigned internalformat)
|
| - : GLImageLinuxDMABuffer(size, internalformat) {}
|
| + : GLImageLinuxDMABuffer(size, internalformat), num_pixmaps_(0) {}
|
|
|
| void Destroy(bool have_context) override {
|
| gfx::GLImageLinuxDMABuffer::Destroy(have_context);
|
| - pixmap_ = nullptr;
|
| + pixmaps_.clear();
|
| }
|
|
|
| - bool Initialize(NativePixmap* pixmap, gfx::GpuMemoryBuffer::Format format) {
|
| - base::FileDescriptor handle(pixmap->GetDmaBufFd(), false);
|
| - if (!GLImageLinuxDMABuffer::Initialize(handle, format,
|
| - pixmap->GetDmaBufPitch()))
|
| + bool Initialize(int num_pixmaps,
|
| + const std::vector<scoped_refptr<NativePixmap>>& pixmaps,
|
| + const std::vector<gfx::GpuMemoryBuffer::Format>& formats) {
|
| + if (num_pixmaps != 1) {
|
| + NOTIMPLEMENTED();
|
| + return scoped_refptr<gfx::GLImage>();
|
| + }
|
| +
|
| + std::vector<base::FileDescriptor> handles;
|
| + handles.reserve(num_pixmaps);
|
| + std::vector<int> pitches;
|
| + pitches.reserve(num_pixmaps);
|
| + for (const auto& pixmap : pixmaps) {
|
| + handles.push_back(base::FileDescriptor(pixmap->GetDmaBufFd(), false));
|
| + pitches.push_back(pixmap->GetDmaBufPitch());
|
| + }
|
| + if (!GLImageLinuxDMABuffer::Initialize(num_pixmaps, handles, formats,
|
| + pitches))
|
| return false;
|
| - pixmap_ = pixmap;
|
| + num_pixmaps_ = num_pixmaps;
|
| + pixmaps_ = pixmaps;
|
| return true;
|
| }
|
|
|
| @@ -72,15 +90,20 @@ class GLImageOzoneNativePixmapDmaBuf : public gfx::GLImageLinuxDMABuffer {
|
| gfx::OverlayTransform transform,
|
| const gfx::Rect& bounds_rect,
|
| const gfx::RectF& crop_rect) override {
|
| + if (num_pixmaps_ != 1) {
|
| + NOTIMPLEMENTED();
|
| + return false;
|
| + }
|
| return SurfaceFactoryOzone::GetInstance()->ScheduleOverlayPlane(
|
| - widget, z_order, transform, pixmap_, bounds_rect, crop_rect);
|
| + widget, z_order, transform, pixmaps_[0], bounds_rect, crop_rect);
|
| }
|
|
|
| protected:
|
| ~GLImageOzoneNativePixmapDmaBuf() override {}
|
|
|
| private:
|
| - scoped_refptr<NativePixmap> pixmap_;
|
| + int num_pixmaps_;
|
| + std::vector<scoped_refptr<NativePixmap>> pixmaps_;
|
| };
|
|
|
| SurfaceFactoryOzone::BufferFormat GetOzoneFormatFor(
|
| @@ -160,43 +183,63 @@ void GpuMemoryBufferFactoryOzoneNativeBuffer::DestroyGpuMemoryBuffer(
|
| }
|
|
|
| scoped_refptr<gfx::GLImage>
|
| -GpuMemoryBufferFactoryOzoneNativeBuffer::CreateImageForGpuMemoryBuffer(
|
| - gfx::GpuMemoryBufferId id,
|
| +GpuMemoryBufferFactoryOzoneNativeBuffer::CreateImageForGpuMemoryBuffers(
|
| + int num_buffers,
|
| + const std::vector<gfx::GpuMemoryBufferId>& ids,
|
| const gfx::Size& size,
|
| - gfx::GpuMemoryBuffer::Format format,
|
| + const std::vector<gfx::GpuMemoryBuffer::Format>& formats,
|
| unsigned internalformat,
|
| int client_id) {
|
| - NativePixmap* pixmap = nullptr;
|
| - {
|
| + std::vector<scoped_refptr<NativePixmap>> pixmaps;
|
| + pixmaps.reserve(num_buffers);
|
| + for (const auto id : ids) {
|
| base::AutoLock lock(native_pixmap_map_lock_);
|
| BufferToPixmapMap::iterator it =
|
| native_pixmap_map_.find(GetIndex(id, client_id));
|
| if (it == native_pixmap_map_.end()) {
|
| return scoped_refptr<gfx::GLImage>();
|
| }
|
| - pixmap = it->second.get();
|
| + pixmaps.push_back(it->second.get());
|
| }
|
| - return CreateImageForPixmap(pixmap, size, format, internalformat);
|
| + return CreateImageForPixmaps(num_buffers, pixmaps, size, formats,
|
| + internalformat);
|
| }
|
|
|
| scoped_refptr<gfx::GLImage>
|
| -GpuMemoryBufferFactoryOzoneNativeBuffer::CreateImageForPixmap(
|
| - scoped_refptr<NativePixmap> pixmap,
|
| +GpuMemoryBufferFactoryOzoneNativeBuffer::CreateImageForPixmaps(
|
| + int num_buffers,
|
| + const std::vector<scoped_refptr<NativePixmap>>& pixmaps,
|
| const gfx::Size& size,
|
| - gfx::GpuMemoryBuffer::Format format,
|
| + const std::vector<gfx::GpuMemoryBuffer::Format>& formats,
|
| unsigned internalformat) {
|
| - if (pixmap->GetEGLClientBuffer()) {
|
| + bool are_pixmaps_EGLClientBufs = false;
|
| + std::for_each(
|
| + pixmaps.begin(), pixmaps.end(),
|
| + [&are_pixmaps_EGLClientBufs](const scoped_refptr<NativePixmap>& p) {
|
| + are_pixmaps_EGLClientBufs |= (p->GetEGLClientBuffer() != nullptr);
|
| + });
|
| + if (are_pixmaps_EGLClientBufs) {
|
| scoped_refptr<GLImageOzoneNativePixmap> image =
|
| new GLImageOzoneNativePixmap(size);
|
| - if (!image->Initialize(pixmap.get())) {
|
| + if (num_buffers != 1) {
|
| + NOTIMPLEMENTED();
|
| + return image;
|
| + }
|
| + if (!image->Initialize(pixmaps[0].get())) {
|
| return scoped_refptr<gfx::GLImage>();
|
| }
|
| return image;
|
| }
|
| - if (pixmap->GetDmaBufFd() > 0) {
|
| +
|
| + bool are_pixmaps_DmaBufs = false;
|
| + std::for_each(pixmaps.begin(), pixmaps.end(),
|
| + [&are_pixmaps_DmaBufs](const scoped_refptr<NativePixmap>& p) {
|
| + are_pixmaps_DmaBufs |= (p->GetDmaBufFd() > 0);
|
| + });
|
| + if (are_pixmaps_DmaBufs) {
|
| scoped_refptr<GLImageOzoneNativePixmapDmaBuf> image =
|
| new GLImageOzoneNativePixmapDmaBuf(size, internalformat);
|
| - if (!image->Initialize(pixmap.get(), format)) {
|
| + if (!image->Initialize(num_buffers, pixmaps, formats)) {
|
| return scoped_refptr<gfx::GLImage>();
|
| }
|
| return image;
|
|
|