Commit f9945799 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

Ozone: Add OzonePlatform::IsNativePixmapConfigSupported().

Added OzonePlatform::IsNativePixmapConfigSupported() which is now used to
verify that the current ozone platform supports particular image format.
It replaces PlatformProperties::supported_buffer_format and
ClientNativePixmapFactory::IsConfigurationSupported()

Change-Id: I619f8130c09038e44bc558bdf59b816979e228a5
Reviewed-on: https://chromium-review.googlesource.com/c/1347036
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#611470}
parent 5b644f62
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/client_native_pixmap_factory.h" #include "ui/gfx/client_native_pixmap_factory.h"
#if defined(USE_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace viz { namespace viz {
namespace { namespace {
...@@ -171,34 +175,6 @@ class TestGpuService : public mojom::GpuService { ...@@ -171,34 +175,6 @@ class TestGpuService : public mojom::GpuService {
DISALLOW_COPY_AND_ASSIGN(TestGpuService); DISALLOW_COPY_AND_ASSIGN(TestGpuService);
}; };
// It is necessary to install a custom pixmap factory which claims to support
// all native configurations, so that code that deals with this can be tested
// correctly.
class FakeClientNativePixmapFactory : public gfx::ClientNativePixmapFactory {
public:
explicit FakeClientNativePixmapFactory(bool allow_native_buffers)
: allow_native_buffers_(allow_native_buffers) {}
~FakeClientNativePixmapFactory() override {}
// gfx::ClientNativePixmapFactory:
bool IsConfigurationSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const override {
return allow_native_buffers_;
}
std::unique_ptr<gfx::ClientNativePixmap> ImportFromHandle(
const gfx::NativePixmapHandle& handle,
const gfx::Size& size,
gfx::BufferUsage usage) override {
NOTREACHED();
return nullptr;
}
private:
bool allow_native_buffers_ = false;
DISALLOW_COPY_AND_ASSIGN(FakeClientNativePixmapFactory);
};
} // namespace } // namespace
class HostGpuMemoryBufferManagerTest : public ::testing::Test { class HostGpuMemoryBufferManagerTest : public ::testing::Test {
...@@ -232,32 +208,33 @@ class HostGpuMemoryBufferManagerTest : public ::testing::Test { ...@@ -232,32 +208,33 @@ class HostGpuMemoryBufferManagerTest : public ::testing::Test {
DISALLOW_COPY_AND_ASSIGN(HostGpuMemoryBufferManagerTest); DISALLOW_COPY_AND_ASSIGN(HostGpuMemoryBufferManagerTest);
}; };
std::unique_ptr<gpu::GpuMemoryBufferSupport> MakeGpuMemoryBufferSupport(
bool allow_native_buffers) {
#if defined(OS_LINUX)
return std::make_unique<gpu::GpuMemoryBufferSupport>(
std::make_unique<FakeClientNativePixmapFactory>(allow_native_buffers));
#else
return std::make_unique<gpu::GpuMemoryBufferSupport>();
#endif
}
// Tests that allocation requests from a client that goes away before allocation // Tests that allocation requests from a client that goes away before allocation
// completes are cleaned up correctly. // completes are cleaned up correctly.
TEST_F(HostGpuMemoryBufferManagerTest, AllocationRequestsForDestroyedClient) { TEST_F(HostGpuMemoryBufferManagerTest, AllocationRequestsForDestroyedClient) {
#if !defined(USE_OZONE) && !defined(OS_MACOSX) && !defined(OS_WIN) // Not all platforms support native configurations (currently only Windows,
// Not all platforms support native configurations (currently only ozone and // Mac and some Ozone platforms). Abort the test in those platforms.
// mac support it). Abort the test in those platforms. bool native_pixmap_supported = false;
gpu::GpuMemoryBufferSupport support; #if defined(USE_OZONE)
DCHECK(gpu::GetNativeGpuMemoryBufferConfigurations(&support).empty()); native_pixmap_supported =
return; ui::OzonePlatform::GetInstance()->IsNativePixmapConfigSupported(
#else gfx::BufferFormat::RGBA_8888, gfx::BufferUsage::GPU_READ);
#elif defined(OS_MACOSX) || defined(OS_WIN)
native_pixmap_supported = true;
#endif
if (!native_pixmap_supported) {
gpu::GpuMemoryBufferSupport support;
DCHECK(gpu::GetNativeGpuMemoryBufferConfigurations(&support).empty());
return;
}
// Note: HostGpuMemoryBufferManager normally operates on a mojom::GpuService // Note: HostGpuMemoryBufferManager normally operates on a mojom::GpuService
// implementation over mojo. Which means the communication from SGMBManager to // implementation over mojo. Which means the communication from SGMBManager to
// GpuService is asynchronous. In this test, the mojom::GpuService is not // GpuService is asynchronous. In this test, the mojom::GpuService is not
// bound to a mojo pipe, which means those calls are all synchronous. // bound to a mojo pipe, which means those calls are all synchronous.
TestGpuService gpu_service; TestGpuService gpu_service;
auto gpu_memory_buffer_support = MakeGpuMemoryBufferSupport(true); auto gpu_memory_buffer_support =
std::make_unique<gpu::GpuMemoryBufferSupport>();
HostGpuMemoryBufferManager manager(gpu_service.CreateProvider(), 1, HostGpuMemoryBufferManager manager(gpu_service.CreateProvider(), 1,
std::move(gpu_memory_buffer_support), std::move(gpu_memory_buffer_support),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
...@@ -282,12 +259,12 @@ TEST_F(HostGpuMemoryBufferManagerTest, AllocationRequestsForDestroyedClient) { ...@@ -282,12 +259,12 @@ TEST_F(HostGpuMemoryBufferManagerTest, AllocationRequestsForDestroyedClient) {
// should request the allocated memory to be freed. // should request the allocated memory to be freed.
gpu_service.SatisfyAllocationRequest(buffer_id, client_id); gpu_service.SatisfyAllocationRequest(buffer_id, client_id);
EXPECT_TRUE(gpu_service.HasDestructionRequest(buffer_id, client_id)); EXPECT_TRUE(gpu_service.HasDestructionRequest(buffer_id, client_id));
#endif
} }
TEST_F(HostGpuMemoryBufferManagerTest, RequestsFromUntrustedClientsValidated) { TEST_F(HostGpuMemoryBufferManagerTest, RequestsFromUntrustedClientsValidated) {
TestGpuService gpu_service; TestGpuService gpu_service;
auto gpu_memory_buffer_support = MakeGpuMemoryBufferSupport(false); auto gpu_memory_buffer_support =
std::make_unique<gpu::GpuMemoryBufferSupport>();
HostGpuMemoryBufferManager manager(gpu_service.CreateProvider(), 1, HostGpuMemoryBufferManager manager(gpu_service.CreateProvider(), 1,
std::move(gpu_memory_buffer_support), std::move(gpu_memory_buffer_support),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
...@@ -332,7 +309,8 @@ TEST_F(HostGpuMemoryBufferManagerTest, RequestsFromUntrustedClientsValidated) { ...@@ -332,7 +309,8 @@ TEST_F(HostGpuMemoryBufferManagerTest, RequestsFromUntrustedClientsValidated) {
TEST_F(HostGpuMemoryBufferManagerTest, GpuMemoryBufferDestroyed) { TEST_F(HostGpuMemoryBufferManagerTest, GpuMemoryBufferDestroyed) {
TestGpuService gpu_service; TestGpuService gpu_service;
auto gpu_memory_buffer_support = MakeGpuMemoryBufferSupport(false); auto gpu_memory_buffer_support =
std::make_unique<gpu::GpuMemoryBufferSupport>();
HostGpuMemoryBufferManager manager(gpu_service.CreateProvider(), 1, HostGpuMemoryBufferManager manager(gpu_service.CreateProvider(), 1,
std::move(gpu_memory_buffer_support), std::move(gpu_memory_buffer_support),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
...@@ -344,7 +322,8 @@ TEST_F(HostGpuMemoryBufferManagerTest, GpuMemoryBufferDestroyed) { ...@@ -344,7 +322,8 @@ TEST_F(HostGpuMemoryBufferManagerTest, GpuMemoryBufferDestroyed) {
TEST_F(HostGpuMemoryBufferManagerTest, TEST_F(HostGpuMemoryBufferManagerTest,
GpuMemoryBufferDestroyedOnDifferentThread) { GpuMemoryBufferDestroyedOnDifferentThread) {
TestGpuService gpu_service; TestGpuService gpu_service;
auto gpu_memory_buffer_support = MakeGpuMemoryBufferSupport(false); auto gpu_memory_buffer_support =
std::make_unique<gpu::GpuMemoryBufferSupport>();
HostGpuMemoryBufferManager manager(gpu_service.CreateProvider(), 1, HostGpuMemoryBufferManager manager(gpu_service.CreateProvider(), 1,
std::move(gpu_memory_buffer_support), std::move(gpu_memory_buffer_support),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#if defined(USE_OZONE) #if defined(USE_OZONE)
#include "ui/ozone/public/client_native_pixmap_factory_ozone.h" #include "ui/ozone/public/client_native_pixmap_factory_ozone.h"
#include "ui/ozone/public/ozone_platform.h"
#endif #endif
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -42,13 +43,6 @@ GpuMemoryBufferSupport::GpuMemoryBufferSupport() { ...@@ -42,13 +43,6 @@ GpuMemoryBufferSupport::GpuMemoryBufferSupport() {
#endif #endif
} }
#if defined(OS_LINUX) || defined(USE_OZONE)
GpuMemoryBufferSupport::GpuMemoryBufferSupport(
std::unique_ptr<gfx::ClientNativePixmapFactory>
client_native_pixmap_factory)
: client_native_pixmap_factory_(std::move(client_native_pixmap_factory)) {}
#endif
GpuMemoryBufferSupport::~GpuMemoryBufferSupport() {} GpuMemoryBufferSupport::~GpuMemoryBufferSupport() {}
gfx::GpuMemoryBufferType gfx::GpuMemoryBufferType
...@@ -113,7 +107,8 @@ bool GpuMemoryBufferSupport::IsNativeGpuMemoryBufferConfigurationSupported( ...@@ -113,7 +107,8 @@ bool GpuMemoryBufferSupport::IsNativeGpuMemoryBufferConfigurationSupported(
NOTREACHED(); NOTREACHED();
return false; return false;
#elif defined(USE_OZONE) #elif defined(USE_OZONE)
return client_native_pixmap_factory_->IsConfigurationSupported(format, usage); return ui::OzonePlatform::EnsureInstance()->IsNativePixmapConfigSupported(
format, usage);
#elif defined(OS_LINUX) #elif defined(OS_LINUX)
return false; // TODO(julian.isorce): Add linux support. return false; // TODO(julian.isorce): Add linux support.
#elif defined(OS_WIN) #elif defined(OS_WIN)
......
...@@ -28,10 +28,6 @@ namespace gpu { ...@@ -28,10 +28,6 @@ namespace gpu {
class GPU_EXPORT GpuMemoryBufferSupport { class GPU_EXPORT GpuMemoryBufferSupport {
public: public:
GpuMemoryBufferSupport(); GpuMemoryBufferSupport();
#if defined(OS_LINUX) || defined(USE_OZONE)
GpuMemoryBufferSupport(std::unique_ptr<gfx::ClientNativePixmapFactory>
client_native_pixmap_factory);
#endif
~GpuMemoryBufferSupport(); ~GpuMemoryBufferSupport();
// Returns the native GPU memory buffer factory type. Returns EMPTY_BUFFER // Returns the native GPU memory buffer factory type. Returns EMPTY_BUFFER
......
...@@ -25,10 +25,6 @@ class GFX_EXPORT ClientNativePixmapFactory { ...@@ -25,10 +25,6 @@ class GFX_EXPORT ClientNativePixmapFactory {
public: public:
virtual ~ClientNativePixmapFactory() {} virtual ~ClientNativePixmapFactory() {}
// Returns true if format/usage configuration is supported.
virtual bool IsConfigurationSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const = 0;
// Import the native pixmap from |handle| to be used in non-GPU processes. // Import the native pixmap from |handle| to be used in non-GPU processes.
// This function takes ownership of any file descriptors in |handle|. // This function takes ownership of any file descriptors in |handle|.
virtual std::unique_ptr<ClientNativePixmap> ImportFromHandle( virtual std::unique_ptr<ClientNativePixmap> ImportFromHandle(
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/process/memory.h" #include "base/process/memory.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
#include <linux/dma-buf.h> #include <linux/dma-buf.h>
...@@ -58,6 +59,68 @@ void PrimeSyncEnd(int dmabuf_fd) { ...@@ -58,6 +59,68 @@ void PrimeSyncEnd(int dmabuf_fd) {
} // namespace } // namespace
// static
bool ClientNativePixmapDmaBuf::IsConfigurationSupported(
gfx::BufferFormat format,
gfx::BufferUsage usage) {
switch (usage) {
case gfx::BufferUsage::GPU_READ:
return format == gfx::BufferFormat::BGR_565 ||
format == gfx::BufferFormat::RGBA_8888 ||
format == gfx::BufferFormat::RGBX_8888 ||
format == gfx::BufferFormat::BGRA_8888 ||
format == gfx::BufferFormat::BGRX_8888 ||
format == gfx::BufferFormat::YVU_420;
case gfx::BufferUsage::SCANOUT:
return format == gfx::BufferFormat::BGRX_8888 ||
format == gfx::BufferFormat::RGBX_8888 ||
format == gfx::BufferFormat::RGBA_8888 ||
format == gfx::BufferFormat::BGRA_8888;
case gfx::BufferUsage::SCANOUT_CPU_READ_WRITE:
return
#if defined(ARCH_CPU_X86_FAMILY)
// Currently only Intel driver (i.e. minigbm and Mesa) supports R_8
// RG_88, NV12 and XB30. https://crbug.com/356871
format == gfx::BufferFormat::R_8 ||
format == gfx::BufferFormat::RG_88 ||
format == gfx::BufferFormat::YUV_420_BIPLANAR ||
format == gfx::BufferFormat::RGBX_1010102 ||
#endif
format == gfx::BufferFormat::BGRX_8888 ||
format == gfx::BufferFormat::BGRA_8888 ||
format == gfx::BufferFormat::RGBX_8888 ||
format == gfx::BufferFormat::RGBA_8888;
case gfx::BufferUsage::SCANOUT_VDA_WRITE:
return false;
case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE:
case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT:
return
#if defined(ARCH_CPU_X86_FAMILY)
// Currently only Intel driver (i.e. minigbm and
// Mesa) supports R_8 RG_88 and NV12.
// https://crbug.com/356871
format == gfx::BufferFormat::R_8 ||
format == gfx::BufferFormat::RG_88 ||
format == gfx::BufferFormat::YUV_420_BIPLANAR ||
#endif
format == gfx::BufferFormat::BGRA_8888;
case gfx::BufferUsage::SCANOUT_CAMERA_READ_WRITE:
// Each platform only supports one camera buffer type. We list the
// supported buffer formats on all platforms here. When allocating a
// camera buffer the caller is responsible for making sure a buffer is
// successfully allocated. For example, allocating YUV420_BIPLANAR
// for SCANOUT_CAMERA_READ_WRITE may only work on Intel boards.
return format == gfx::BufferFormat::YUV_420_BIPLANAR;
case gfx::BufferUsage::CAMERA_AND_CPU_READ_WRITE:
// R_8 is used as the underlying pixel format for BLOB buffers.
return format == gfx::BufferFormat::R_8;
}
NOTREACHED();
return false;
}
// static // static
std::unique_ptr<gfx::ClientNativePixmap> std::unique_ptr<gfx::ClientNativePixmap>
ClientNativePixmapDmaBuf::ImportFromDmabuf( ClientNativePixmapDmaBuf::ImportFromDmabuf(
......
...@@ -11,14 +11,19 @@ ...@@ -11,14 +11,19 @@
#include "base/files/scoped_file.h" #include "base/files/scoped_file.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/client_native_pixmap.h" #include "ui/gfx/client_native_pixmap.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/gfx_export.h"
#include "ui/gfx/native_pixmap_handle.h" #include "ui/gfx/native_pixmap_handle.h"
namespace gfx { namespace gfx {
class ClientNativePixmapDmaBuf : public gfx::ClientNativePixmap { class ClientNativePixmapDmaBuf : public gfx::ClientNativePixmap {
public: public:
static GFX_EXPORT bool IsConfigurationSupported(gfx::BufferFormat format,
gfx::BufferUsage usage);
static std::unique_ptr<gfx::ClientNativePixmap> ImportFromDmabuf( static std::unique_ptr<gfx::ClientNativePixmap> ImportFromDmabuf(
const gfx::NativePixmapHandle& handle, const gfx::NativePixmapHandle& handle,
const gfx::Size& size); const gfx::Size& size);
......
...@@ -45,80 +45,9 @@ class ClientNativePixmapOpaque : public ClientNativePixmap { ...@@ -45,80 +45,9 @@ class ClientNativePixmapOpaque : public ClientNativePixmap {
class ClientNativePixmapFactoryDmabuf : public ClientNativePixmapFactory { class ClientNativePixmapFactoryDmabuf : public ClientNativePixmapFactory {
public: public:
explicit ClientNativePixmapFactoryDmabuf( explicit ClientNativePixmapFactoryDmabuf() {}
bool supports_native_pixmap_import_from_dmabuf)
: supports_native_pixmap_import_from_dmabuf_(
supports_native_pixmap_import_from_dmabuf) {}
~ClientNativePixmapFactoryDmabuf() override {} ~ClientNativePixmapFactoryDmabuf() override {}
// ClientNativePixmapFactory:
bool IsConfigurationSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const override {
switch (usage) {
case gfx::BufferUsage::GPU_READ:
return format == gfx::BufferFormat::BGR_565 ||
format == gfx::BufferFormat::RGBA_8888 ||
format == gfx::BufferFormat::RGBX_8888 ||
format == gfx::BufferFormat::BGRA_8888 ||
format == gfx::BufferFormat::BGRX_8888 ||
format == gfx::BufferFormat::YVU_420;
case gfx::BufferUsage::SCANOUT:
return format == gfx::BufferFormat::BGRX_8888 ||
format == gfx::BufferFormat::RGBX_8888 ||
format == gfx::BufferFormat::RGBA_8888 ||
format == gfx::BufferFormat::BGRA_8888;
case gfx::BufferUsage::SCANOUT_CPU_READ_WRITE:
return
#if defined(ARCH_CPU_X86_FAMILY)
// Currently only Intel driver (i.e. minigbm and Mesa) supports R_8
// RG_88, NV12 and XB30. https://crbug.com/356871
format == gfx::BufferFormat::R_8 ||
format == gfx::BufferFormat::RG_88 ||
format == gfx::BufferFormat::YUV_420_BIPLANAR ||
format == gfx::BufferFormat::RGBX_1010102 ||
#endif
format == gfx::BufferFormat::BGRX_8888 ||
format == gfx::BufferFormat::BGRA_8888 ||
format == gfx::BufferFormat::RGBX_8888 ||
format == gfx::BufferFormat::RGBA_8888;
case gfx::BufferUsage::SCANOUT_VDA_WRITE:
return false;
case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE:
case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: {
if (!supports_native_pixmap_import_from_dmabuf_)
return false;
return
#if defined(ARCH_CPU_X86_FAMILY)
// Currently only Intel driver (i.e. minigbm and
// Mesa) supports R_8 RG_88 and NV12.
// https://crbug.com/356871
format == gfx::BufferFormat::R_8 ||
format == gfx::BufferFormat::RG_88 ||
format == gfx::BufferFormat::YUV_420_BIPLANAR ||
#endif
format == gfx::BufferFormat::BGRA_8888;
}
case gfx::BufferUsage::SCANOUT_CAMERA_READ_WRITE: {
if (!supports_native_pixmap_import_from_dmabuf_)
return false;
// Each platform only supports one camera buffer type. We list the
// supported buffer formats on all platforms here. When allocating a
// camera buffer the caller is responsible for making sure a buffer is
// successfully allocated. For example, allocating YUV420_BIPLANAR
// for SCANOUT_CAMERA_READ_WRITE may only work on Intel boards.
return format == gfx::BufferFormat::YUV_420_BIPLANAR;
}
case gfx::BufferUsage::CAMERA_AND_CPU_READ_WRITE: {
if (!supports_native_pixmap_import_from_dmabuf_)
return false;
// R_8 is used as the underlying pixel format for BLOB buffers.
return format == gfx::BufferFormat::R_8;
}
}
NOTREACHED();
return false;
}
std::unique_ptr<ClientNativePixmap> ImportFromHandle( std::unique_ptr<ClientNativePixmap> ImportFromHandle(
const gfx::NativePixmapHandle& handle, const gfx::NativePixmapHandle& handle,
const gfx::Size& size, const gfx::Size& size,
...@@ -130,11 +59,7 @@ class ClientNativePixmapFactoryDmabuf : public ClientNativePixmapFactory { ...@@ -130,11 +59,7 @@ class ClientNativePixmapFactoryDmabuf : public ClientNativePixmapFactory {
case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT:
case gfx::BufferUsage::SCANOUT_CAMERA_READ_WRITE: case gfx::BufferUsage::SCANOUT_CAMERA_READ_WRITE:
case gfx::BufferUsage::CAMERA_AND_CPU_READ_WRITE: case gfx::BufferUsage::CAMERA_AND_CPU_READ_WRITE:
if (supports_native_pixmap_import_from_dmabuf_) return ClientNativePixmapDmaBuf::ImportFromDmabuf(handle, size);
return ClientNativePixmapDmaBuf::ImportFromDmabuf(handle, size);
NOTREACHED()
<< "Native GpuMemoryBuffers are not supported on this platform";
return nullptr;
case gfx::BufferUsage::GPU_READ: case gfx::BufferUsage::GPU_READ:
case gfx::BufferUsage::SCANOUT: case gfx::BufferUsage::SCANOUT:
case gfx::BufferUsage::SCANOUT_VDA_WRITE: case gfx::BufferUsage::SCANOUT_VDA_WRITE:
...@@ -148,30 +73,11 @@ class ClientNativePixmapFactoryDmabuf : public ClientNativePixmapFactory { ...@@ -148,30 +73,11 @@ class ClientNativePixmapFactoryDmabuf : public ClientNativePixmapFactory {
} }
private: private:
// Says if ClientNativePixmapDmaBuf can be used to import handle from dmabuf.
const bool supports_native_pixmap_import_from_dmabuf_ = false;
DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryDmabuf); DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryDmabuf);
}; };
ClientNativePixmapFactory* CreateClientNativePixmapFactoryDmabuf( ClientNativePixmapFactory* CreateClientNativePixmapFactoryDmabuf() {
bool supports_native_pixmap_import_from_dmabuf) { return new ClientNativePixmapFactoryDmabuf();
// |supports_native_pixmap_import_from_dmabuf| can be enabled on all linux but
// it is not a requirement to support glCreateImageChromium+Dmabuf since it uses
// gfx::BufferUsage::SCANOUT and the pixmap does not need to be mappable on the
// client side.
//
// At the moment, only Ozone/Wayland platform running on Linux is able to import
// handle from dmabuf in addition to the ChromeOS. This is set in the ozone
// level in the ClientNativePixmapFactoryWayland class.
//
// This is not ideal. The ozone platform should probably set this.
// TODO(rjkroege): do something better here.
#if defined(OS_CHROMEOS)
supports_native_pixmap_import_from_dmabuf = true;
#endif
return new ClientNativePixmapFactoryDmabuf(
supports_native_pixmap_import_from_dmabuf);
} }
} // namespace gfx } // namespace gfx
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
namespace gfx { namespace gfx {
GFX_EXPORT ClientNativePixmapFactory* CreateClientNativePixmapFactoryDmabuf( GFX_EXPORT ClientNativePixmapFactory* CreateClientNativePixmapFactoryDmabuf();
bool supports_import_from_dmabuf = false);
} // namespace gfx } // namespace gfx
......
...@@ -15,10 +15,6 @@ class StubClientNativePixmapFactory : public gfx::ClientNativePixmapFactory { ...@@ -15,10 +15,6 @@ class StubClientNativePixmapFactory : public gfx::ClientNativePixmapFactory {
~StubClientNativePixmapFactory() override {} ~StubClientNativePixmapFactory() override {}
// ClientNativePixmapFactory: // ClientNativePixmapFactory:
bool IsConfigurationSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const override {
return false;
}
std::unique_ptr<gfx::ClientNativePixmap> ImportFromHandle( std::unique_ptr<gfx::ClientNativePixmap> ImportFromHandle(
const gfx::NativePixmapHandle& handle, const gfx::NativePixmapHandle& handle,
const gfx::Size& size, const gfx::Size& size,
......
...@@ -36,12 +36,6 @@ class ClientNativePixmapCast : public gfx::ClientNativePixmap { ...@@ -36,12 +36,6 @@ class ClientNativePixmapCast : public gfx::ClientNativePixmap {
class ClientNativePixmapFactoryCast : public gfx::ClientNativePixmapFactory { class ClientNativePixmapFactoryCast : public gfx::ClientNativePixmapFactory {
public: public:
// ClientNativePixmapFactoryCast implementation: // ClientNativePixmapFactoryCast implementation:
bool IsConfigurationSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const override {
return format == gfx::BufferFormat::BGRA_8888 &&
usage == gfx::BufferUsage::SCANOUT;
}
std::unique_ptr<gfx::ClientNativePixmap> ImportFromHandle( std::unique_ptr<gfx::ClientNativePixmap> ImportFromHandle(
const gfx::NativePixmapHandle& handle, const gfx::NativePixmapHandle& handle,
const gfx::Size& size, const gfx::Size& size,
......
...@@ -102,6 +102,11 @@ class OzonePlatformCast : public OzonePlatform { ...@@ -102,6 +102,11 @@ class OzonePlatformCast : public OzonePlatform {
// On Cast platform the display is initialized by low-level non-Ozone code. // On Cast platform the display is initialized by low-level non-Ozone code.
return nullptr; return nullptr;
} }
bool IsNativePixmapConfigSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const override {
return format == gfx::BufferFormat::BGRA_8888 &&
usage == gfx::BufferUsage::SCANOUT;
}
void InitializeUI(const InitParams& params) override { void InitializeUI(const InitParams& params) override {
device_manager_ = CreateDeviceManager(); device_manager_ = CreateDeviceManager();
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "ui/events/ozone/device/device_manager.h" #include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/event_factory_evdev.h" #include "ui/events/ozone/evdev/event_factory_evdev.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/gfx/linux/client_native_pixmap_dmabuf.h"
#include "ui/ozone/platform/drm/common/drm_util.h" #include "ui/ozone/platform/drm/common/drm_util.h"
#include "ui/ozone/platform/drm/gpu/drm_device_generator.h" #include "ui/ozone/platform/drm/gpu/drm_device_generator.h"
#include "ui/ozone/platform/drm/gpu/drm_device_manager.h" #include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
...@@ -171,6 +172,12 @@ class OzonePlatformGbm : public OzonePlatform { ...@@ -171,6 +172,12 @@ class OzonePlatformGbm : public OzonePlatform {
return std::make_unique<DrmNativeDisplayDelegate>(display_manager_.get()); return std::make_unique<DrmNativeDisplayDelegate>(display_manager_.get());
} }
bool IsNativePixmapConfigSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const override {
return gfx::ClientNativePixmapDmaBuf::IsConfigurationSupported(format,
usage);
}
void InitializeUI(const InitParams& args) override { void InitializeUI(const InitParams& args) override {
// Ozone drm can operate in four modes configured at // Ozone drm can operate in four modes configured at
// runtime. Three process modes: // runtime. Three process modes:
...@@ -184,12 +191,13 @@ class OzonePlatformGbm : public OzonePlatform { ...@@ -184,12 +191,13 @@ class OzonePlatformGbm : public OzonePlatform {
// //
// and 2 connection modes // and 2 connection modes
// a. Viz is launched via content::GpuProcessHost and it notifies the // a. Viz is launched via content::GpuProcessHost and it notifies the
// ozone host when Viz becomes available. b. The ozone host uses a service // ozone host when Viz becomes available. b. The ozone host uses a
// manager to launch and connect to Viz. // service manager to launch and connect to Viz.
// //
// Combinations 1a, 2b, and 3a, and 3b are supported and expected to work. // Combinations 1a, 2b, and 3a, and 3b are supported and expected to work.
// Combination 1a will hopefully be deprecated and replaced with 3a. // Combination 1a will hopefully be deprecated and replaced with 3a.
// Combination 2b adds undesirable code-debt and the intent is to remove it. // Combination 2b adds undesirable code-debt and the intent is to remove
// it.
single_process_ = args.single_process; single_process_ = args.single_process;
using_mojo_ = args.using_mojo || args.connector != nullptr; using_mojo_ = args.using_mojo || args.connector != nullptr;
...@@ -198,6 +206,7 @@ class OzonePlatformGbm : public OzonePlatform { ...@@ -198,6 +206,7 @@ class OzonePlatformGbm : public OzonePlatform {
device_manager_ = CreateDeviceManager(); device_manager_ = CreateDeviceManager();
window_manager_.reset(new DrmWindowHostManager()); window_manager_.reset(new DrmWindowHostManager());
cursor_.reset(new DrmCursor(window_manager_.get())); cursor_.reset(new DrmCursor(window_manager_.get()));
#if BUILDFLAG(USE_XKBCOMMON) #if BUILDFLAG(USE_XKBCOMMON)
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
std::make_unique<XkbKeyboardLayoutEngine>(xkb_evdev_code_converter_)); std::make_unique<XkbKeyboardLayoutEngine>(xkb_evdev_code_converter_));
......
...@@ -34,12 +34,11 @@ namespace ui { ...@@ -34,12 +34,11 @@ namespace ui {
namespace { namespace {
const OzonePlatform::PlatformProperties kScenicPlatformProperties( constexpr OzonePlatform::PlatformProperties kScenicPlatformProperties{
/*needs_view_owner_request=*/true, /*needs_view_token=*/true,
/*custom_frame_pref_default=*/false, /*custom_frame_pref_default=*/false,
/*use_system_title_bar=*/false, /*use_system_title_bar=*/false,
/*requires_mojo=*/false, /*requires_mojo=*/false};
std::vector<gfx::BufferFormat>());
class ScenicPlatformEventSource : public ui::PlatformEventSource { class ScenicPlatformEventSource : public ui::PlatformEventSource {
public: public:
......
...@@ -4,50 +4,15 @@ ...@@ -4,50 +4,15 @@
#include "ui/ozone/platform/wayland/client_native_pixmap_factory_wayland.h" #include "ui/ozone/platform/wayland/client_native_pixmap_factory_wayland.h"
#include "ui/gfx/linux/client_native_pixmap_dmabuf.h"
#include "ui/gfx/linux/client_native_pixmap_factory_dmabuf.h" #include "ui/gfx/linux/client_native_pixmap_factory_dmabuf.h"
#include "ui/ozone/common/stub_client_native_pixmap_factory.h" #include "ui/ozone/common/stub_client_native_pixmap_factory.h"
#include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/ozone_platform.h"
namespace ui { namespace ui {
// Implements ClientNativePixmapFactory to provide a more accurate buffer format
// support when Wayland dmabuf is used.
class ClientNativePixmapFactoryWayland : public gfx::ClientNativePixmapFactory {
public:
ClientNativePixmapFactoryWayland() {
dmabuf_factory_.reset(gfx::CreateClientNativePixmapFactoryDmabuf(
true /* supports_native_pixmap_import_from_dmabuf */));
}
~ClientNativePixmapFactoryWayland() override {}
// ClientNativePixmapFactory overrides:
bool IsConfigurationSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const override {
OzonePlatform::PlatformProperties properties =
OzonePlatform::GetInstance()->GetPlatformProperties();
for (auto buffer_format : properties.supported_buffer_formats) {
if (buffer_format == format)
return dmabuf_factory_->IsConfigurationSupported(format, usage);
}
return false;
}
std::unique_ptr<gfx::ClientNativePixmap> ImportFromHandle(
const gfx::NativePixmapHandle& handle,
const gfx::Size& size,
gfx::BufferUsage usage) override {
return dmabuf_factory_->ImportFromHandle(handle, size, usage);
}
private:
std::unique_ptr<ClientNativePixmapFactory> dmabuf_factory_;
DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryWayland);
};
gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryWayland() { gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryWayland() {
#if defined(WAYLAND_GBM) #if defined(WAYLAND_GBM)
return new ClientNativePixmapFactoryWayland(); return gfx::CreateClientNativePixmapFactoryDmabuf();
#else #else
return CreateStubClientNativePixmapFactory(); return CreateStubClientNativePixmapFactory();
#endif #endif
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ui/display/manager/fake_display_delegate.h" #include "ui/display/manager/fake_display_delegate.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/system_input_injector.h" #include "ui/events/system_input_injector.h"
#include "ui/gfx/linux/client_native_pixmap_dmabuf.h"
#include "ui/ozone/common/stub_overlay_manager.h" #include "ui/ozone/common/stub_overlay_manager.h"
#include "ui/ozone/platform/wayland/gpu/wayland_connection_proxy.h" #include "ui/ozone/platform/wayland/gpu/wayland_connection_proxy.h"
#include "ui/ozone/platform/wayland/wayland_connection.h" #include "ui/ozone/platform/wayland/wayland_connection.h"
...@@ -41,21 +42,25 @@ namespace ui { ...@@ -41,21 +42,25 @@ namespace ui {
namespace { namespace {
class OzonePlatformWayland : public OzonePlatform { constexpr OzonePlatform::PlatformProperties kWaylandPlatformProperties = {
public: /*needs_view_token=*/false,
OzonePlatformWayland() {
// Supporting server-side decorations requires a support of xdg-decorations. // Supporting server-side decorations requires a support of xdg-decorations.
// But this protocol has been accepted into the upstream recently, and it // But this protocol has been accepted into the upstream recently, and it
// will take time before it is taken by compositors. For now, always use // will take time before it is taken by compositors. For now, always use
// custom frames and disallow switching to server-side frames. // custom frames and disallow switching to server-side frames.
// https://github.com/wayland-project/wayland-protocols/commit/76d1ae8c65739eff3434ef219c58a913ad34e988 // https://github.com/wayland-project/wayland-protocols/commit/76d1ae8c65739eff3434ef219c58a913ad34e988
properties_.custom_frame_pref_default = true; /*custom_frame_pref_default=*/true,
properties_.use_system_title_bar = false; /*use_system_title_bar=*/false,
// Ozone/Wayland relies on the mojo communication when running in // Ozone/Wayland relies on the mojo communication when running in
// !single_process. // !single_process.
// TODO(msisov, rjkroege): Remove after http://crbug.com/806092. // TODO(msisov, rjkroege): Remove after http://crbug.com/806092.
properties_.requires_mojo = true; /*requires_mojo=*/true};
}
class OzonePlatformWayland : public OzonePlatform {
public:
OzonePlatformWayland() {}
~OzonePlatformWayland() override {} ~OzonePlatformWayland() override {}
// OzonePlatform // OzonePlatform
...@@ -113,6 +118,18 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -113,6 +118,18 @@ class OzonePlatformWayland : public OzonePlatform {
return connection_->wayland_output_manager()->CreateWaylandScreen(); return connection_->wayland_output_manager()->CreateWaylandScreen();
} }
bool IsNativePixmapConfigSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const override {
if (std::find(supported_buffer_formats_.begin(),
supported_buffer_formats_.end(),
format) == supported_buffer_formats_.end()) {
return false;
}
return gfx::ClientNativePixmapDmaBuf::IsConfigurationSupported(format,
usage);
}
void InitializeUI(const InitParams& args) override { void InitializeUI(const InitParams& args) override {
#if BUILDFLAG(USE_XKBCOMMON) #if BUILDFLAG(USE_XKBCOMMON)
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
...@@ -135,6 +152,7 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -135,6 +152,7 @@ class OzonePlatformWayland : public OzonePlatform {
overlay_manager_.reset(new StubOverlayManager); overlay_manager_.reset(new StubOverlayManager);
input_controller_ = CreateStubInputController(); input_controller_ = CreateStubInputController();
gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost());
supported_buffer_formats_ = connection_->GetSupportedBufferFormats();
} }
void InitializeGPU(const InitParams& args) override { void InitializeGPU(const InitParams& args) override {
...@@ -163,11 +181,7 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -163,11 +181,7 @@ class OzonePlatformWayland : public OzonePlatform {
} }
const PlatformProperties& GetPlatformProperties() override { const PlatformProperties& GetPlatformProperties() override {
if (connection_ && properties_.supported_buffer_formats.empty()) { return kWaylandPlatformProperties;
properties_.supported_buffer_formats =
connection_->GetSupportedBufferFormats();
}
return properties_;
} }
void AddInterfaces(service_manager::BinderRegistry* registry) override { void AddInterfaces(service_manager::BinderRegistry* registry) override {
...@@ -199,7 +213,7 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -199,7 +213,7 @@ class OzonePlatformWayland : public OzonePlatform {
std::unique_ptr<WaylandConnectionProxy> proxy_; std::unique_ptr<WaylandConnectionProxy> proxy_;
std::unique_ptr<WaylandConnectionConnector> connector_; std::unique_ptr<WaylandConnectionConnector> connector_;
PlatformProperties properties_; std::vector<gfx::BufferFormat> supported_buffer_formats_;
DISALLOW_COPY_AND_ASSIGN(OzonePlatformWayland); DISALLOW_COPY_AND_ASSIGN(OzonePlatformWayland);
}; };
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/shared_memory.h" #include "base/memory/shared_memory.h"
#include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/core/SkSurface.h"
#include "ui/gfx/linux/client_native_pixmap_dmabuf.h"
#include "ui/gfx/vsync_provider.h" #include "ui/gfx/vsync_provider.h"
#include "ui/ozone/common/egl_util.h" #include "ui/ozone/common/egl_util.h"
#include "ui/ozone/common/gl_ozone_egl.h" #include "ui/ozone/common/gl_ozone_egl.h"
......
...@@ -35,25 +35,6 @@ base::Lock& GetOzoneInstanceLock() { ...@@ -35,25 +35,6 @@ base::Lock& GetOzoneInstanceLock() {
} // namespace } // namespace
OzonePlatform::PlatformProperties::PlatformProperties() = default;
OzonePlatform::PlatformProperties::PlatformProperties(
bool needs_view_token,
bool custom_frame_default,
bool can_use_system_title_bar,
bool requires_mojo_for_ipc,
std::vector<gfx::BufferFormat> buffer_formats)
: needs_view_token(needs_view_token),
custom_frame_pref_default(custom_frame_default),
use_system_title_bar(can_use_system_title_bar),
requires_mojo(requires_mojo_for_ipc),
supported_buffer_formats(buffer_formats) {}
OzonePlatform::PlatformProperties::~PlatformProperties() = default;
OzonePlatform::PlatformProperties::PlatformProperties(
const PlatformProperties& other) = default;
OzonePlatform::OzonePlatform() { OzonePlatform::OzonePlatform() {
GetOzoneInstanceLock().AssertAcquired(); GetOzoneInstanceLock().AssertAcquired();
DCHECK(!g_instance) << "There should only be a single OzonePlatform."; DCHECK(!g_instance) << "There should only be a single OzonePlatform.";
...@@ -141,6 +122,13 @@ std::unique_ptr<PlatformScreen> OzonePlatform::CreateScreen() { ...@@ -141,6 +122,13 @@ std::unique_ptr<PlatformScreen> OzonePlatform::CreateScreen() {
return nullptr; return nullptr;
} }
bool OzonePlatform::IsNativePixmapConfigSupported(
gfx::BufferFormat format,
gfx::BufferUsage usage) const {
// Platform that support NativePixmap must override this method.
return false;
}
const OzonePlatform::PlatformProperties& const OzonePlatform::PlatformProperties&
OzonePlatform::GetPlatformProperties() { OzonePlatform::GetPlatformProperties() {
static const base::NoDestructor<OzonePlatform::PlatformProperties> properties; static const base::NoDestructor<OzonePlatform::PlatformProperties> properties;
......
...@@ -87,15 +87,6 @@ class OZONE_EXPORT OzonePlatform { ...@@ -87,15 +87,6 @@ class OZONE_EXPORT OzonePlatform {
// Struct used to indicate platform properties. // Struct used to indicate platform properties.
struct PlatformProperties { struct PlatformProperties {
PlatformProperties();
PlatformProperties(bool needs_request,
bool custom_frame_default,
bool can_use_system_title_bar,
bool requires_mojo_for_ipc,
std::vector<gfx::BufferFormat> buffer_formats);
~PlatformProperties();
PlatformProperties(const PlatformProperties& other);
// Fuchsia only: set to true when the platforms requires |view_token| field // Fuchsia only: set to true when the platforms requires |view_token| field
// in PlatformWindowInitProperties when creating a window. // in PlatformWindowInitProperties when creating a window.
bool needs_view_token = false; bool needs_view_token = false;
...@@ -111,9 +102,6 @@ class OZONE_EXPORT OzonePlatform { ...@@ -111,9 +102,6 @@ class OZONE_EXPORT OzonePlatform {
// Determines if the platform requires mojo communication for the IPC. // Determines if the platform requires mojo communication for the IPC.
// Currently used only by the Ozone/Wayland platform. // Currently used only by the Ozone/Wayland platform.
bool requires_mojo = false; bool requires_mojo = false;
// Wayland only: carries buffer formats supported by a Wayland server.
std::vector<gfx::BufferFormat> supported_buffer_formats;
}; };
using StartupCallback = base::OnceCallback<void(OzonePlatform*)>; using StartupCallback = base::OnceCallback<void(OzonePlatform*)>;
...@@ -161,6 +149,10 @@ class OZONE_EXPORT OzonePlatform { ...@@ -161,6 +149,10 @@ class OZONE_EXPORT OzonePlatform {
CreateNativeDisplayDelegate() = 0; CreateNativeDisplayDelegate() = 0;
virtual std::unique_ptr<PlatformScreen> CreateScreen(); virtual std::unique_ptr<PlatformScreen> CreateScreen();
// Returns true if the specified buffer format is supported.
virtual bool IsNativePixmapConfigSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const;
// Returns a struct that contains configuration and requirements for the // Returns a struct that contains configuration and requirements for the
// current platform implementation. // current platform implementation.
virtual const PlatformProperties& GetPlatformProperties(); virtual const PlatformProperties& GetPlatformProperties();
......
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