Commit 3a8f8d2d authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

Pass VkDevice to SurfaceFactoryOzone::CreateNativePixmap()

CreateNativePixmap() will need to get VkDevice to be able to allocate
buffers compatible with the target device.

Bug: 852011
Change-Id: I7294fbd48d93c0614f78440b023f63a84b01bae9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1570534
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652897}
parent 30e95af7
......@@ -165,9 +165,9 @@ ProtectedBufferManager::ProtectedNativePixmap::Create(
ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance();
ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone();
protected_pixmap->native_pixmap_ =
factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, format,
gfx::BufferUsage::SCANOUT_VDA_WRITE);
protected_pixmap->native_pixmap_ = factory->CreateNativePixmap(
gfx::kNullAcceleratedWidget, VK_NULL_HANDLE, size, format,
gfx::BufferUsage::SCANOUT_VDA_WRITE);
if (!protected_pixmap->native_pixmap_) {
VLOGF(1) << "Failed allocating a native pixmap";
......
......@@ -65,8 +65,8 @@ TEST_F(DisplayTest, DISABLED_CreateLinuxDMABufBuffer) {
scoped_refptr<gfx::NativePixmap> pixmap =
ui::OzonePlatform::GetInstance()
->GetSurfaceFactoryOzone()
->CreateNativePixmap(gfx::kNullAcceleratedWidget, buffer_size,
gfx::BufferFormat::RGBA_8888,
->CreateNativePixmap(gfx::kNullAcceleratedWidget, VK_NULL_HANDLE,
buffer_size, gfx::BufferFormat::RGBA_8888,
gfx::BufferUsage::GPU_READ);
gfx::NativePixmapHandle native_pixmap_handle = pixmap->ExportHandle();
std::unique_ptr<Buffer> buffer1 = display->CreateLinuxDMABufBuffer(
......
......@@ -136,8 +136,6 @@ GpuServiceImpl::GpuServiceImpl(
: main_runner_(base::ThreadTaskRunnerHandle::Get()),
io_runner_(std::move(io_runner)),
watchdog_thread_(std::move(watchdog_thread)),
gpu_memory_buffer_factory_(
gpu::GpuMemoryBufferFactory::CreateNativeType()),
gpu_preferences_(gpu_preferences),
gpu_info_(gpu_info),
gpu_feature_info_(gpu_feature_info),
......@@ -165,6 +163,9 @@ GpuServiceImpl::GpuServiceImpl(
}
#endif
gpu_memory_buffer_factory_ =
gpu::GpuMemoryBufferFactory::CreateNativeType(vulkan_context_provider());
weak_ptr_ = weak_ptr_factory_.GetWeakPtr();
}
......
......@@ -274,8 +274,6 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread_;
std::unique_ptr<gpu::GpuMemoryBufferFactory> gpu_memory_buffer_factory_;
const gpu::GpuPreferences gpu_preferences_;
// Information about the GPU, such as device and vendor ID.
......@@ -309,6 +307,8 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
scoped_refptr<VulkanContextProvider> vulkan_context_provider_;
#endif
std::unique_ptr<gpu::GpuMemoryBufferFactory> gpu_memory_buffer_factory_;
// An event that will be signalled when we shutdown. On some platforms it
// comes from external sources.
std::unique_ptr<base::WaitableEvent> owned_shutdown_event_;
......
......@@ -226,7 +226,7 @@ GLManager::Options::Options() = default;
GLManager::GLManager()
: gpu_memory_buffer_factory_(
gpu::GpuMemoryBufferFactory::CreateNativeType()) {
gpu::GpuMemoryBufferFactory::CreateNativeType(nullptr)) {
SetupBaseContext();
}
......
......@@ -59,7 +59,8 @@ class RasterInProcessCommandBufferTest : public ::testing::Test {
void SetUp() override {
if (!RasterInProcessContext::SupportedInTest())
return;
gpu_memory_buffer_factory_ = GpuMemoryBufferFactory::CreateNativeType();
gpu_memory_buffer_factory_ =
GpuMemoryBufferFactory::CreateNativeType(nullptr);
gpu_memory_buffer_manager_ =
std::make_unique<viz::TestGpuMemoryBufferManager>();
gpu_thread_holder_.GetGpuPreferences()->texture_target_exception_list =
......
......@@ -4,6 +4,8 @@
#include "gpu/ipc/common/gpu_memory_buffer_impl_native_pixmap.h"
#include <vulkan/vulkan.h>
#include <utility>
#include "base/bind.h"
......@@ -71,8 +73,8 @@ base::OnceClosure GpuMemoryBufferImplNativePixmap::AllocateForTesting(
scoped_refptr<gfx::NativePixmap> pixmap =
ui::OzonePlatform::GetInstance()
->GetSurfaceFactoryOzone()
->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, format,
usage);
->CreateNativePixmap(gfx::kNullAcceleratedWidget, VK_NULL_HANDLE,
size, format, usage);
handle->native_pixmap_handle = pixmap->ExportHandle();
#else
// TODO(j.isorce): use gbm_bo_create / gbm_bo_get_fd from system libgbm.
......
......@@ -2,6 +2,7 @@ include_rules = [
"+cc/paint",
"+components/crash/core/common/crash_key.h",
"+components/viz/common/features.h",
"+components/viz/common/gpu/vulkan_context_provider.h",
"+components/viz/common/resources/resource_format.h",
"+third_party/skia",
"+ui/accelerated_widget_mac",
......
......@@ -4,8 +4,8 @@
#include "gpu/ipc/service/gpu_memory_buffer_factory.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include <memory>
#include "build/build_config.h"
#if defined(OS_MACOSX)
......@@ -28,15 +28,17 @@ namespace gpu {
// static
std::unique_ptr<GpuMemoryBufferFactory>
GpuMemoryBufferFactory::CreateNativeType() {
GpuMemoryBufferFactory::CreateNativeType(
viz::VulkanContextProvider* vulkan_context_provider) {
#if defined(OS_MACOSX)
return base::WrapUnique(new GpuMemoryBufferFactoryIOSurface);
return std::make_unique<GpuMemoryBufferFactoryIOSurface>();
#elif defined(OS_ANDROID)
return base::WrapUnique(new GpuMemoryBufferFactoryAndroidHardwareBuffer);
return std::make_unique<GpuMemoryBufferFactoryAndroidHardwareBuffer>();
#elif defined(OS_LINUX) || defined(OS_FUCHSIA)
return base::WrapUnique(new GpuMemoryBufferFactoryNativePixmap);
return std::make_unique<GpuMemoryBufferFactoryNativePixmap>(
vulkan_context_provider);
#elif defined(OS_WIN)
return base::WrapUnique(new GpuMemoryBufferFactoryDXGI);
return std::make_unique<GpuMemoryBufferFactoryDXGI>();
#else
return nullptr;
#endif
......
......@@ -15,6 +15,10 @@
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gpu_memory_buffer.h"
namespace viz {
class VulkanContextProvider;
} // namespace viz
namespace gpu {
class ImageFactory;
......@@ -25,7 +29,8 @@ class GPU_IPC_SERVICE_EXPORT GpuMemoryBufferFactory {
// Creates a new factory instance for native GPU memory buffers. Returns null
// if native buffers are not supported.
static std::unique_ptr<GpuMemoryBufferFactory> CreateNativeType();
static std::unique_ptr<GpuMemoryBufferFactory> CreateNativeType(
viz::VulkanContextProvider* vulkan_context_provider);
// Creates a new GPU memory buffer instance. A valid handle is returned on
// success. It can be called on any thread.
......
......@@ -4,7 +4,9 @@
#include "gpu/ipc/service/gpu_memory_buffer_factory_native_pixmap.h"
#include "components/viz/common/gpu/vulkan_context_provider.h"
#include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
#include "gpu/vulkan/vulkan_device_queue.h"
#include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/client_native_pixmap.h"
#include "ui/gfx/linux/native_pixmap_dmabuf.h"
......@@ -20,8 +22,12 @@
namespace gpu {
GpuMemoryBufferFactoryNativePixmap::GpuMemoryBufferFactoryNativePixmap() =
default;
GpuMemoryBufferFactoryNativePixmap::GpuMemoryBufferFactoryNativePixmap()
: vulkan_context_provider_(nullptr) {}
GpuMemoryBufferFactoryNativePixmap::GpuMemoryBufferFactoryNativePixmap(
viz::VulkanContextProvider* vulkan_context_provider)
: vulkan_context_provider_(vulkan_context_provider) {}
GpuMemoryBufferFactoryNativePixmap::~GpuMemoryBufferFactoryNativePixmap() =
default;
......@@ -38,7 +44,8 @@ GpuMemoryBufferFactoryNativePixmap::CreateGpuMemoryBuffer(
scoped_refptr<gfx::NativePixmap> pixmap =
ui::OzonePlatform::GetInstance()
->GetSurfaceFactoryOzone()
->CreateNativePixmap(surface_handle, size, format, usage);
->CreateNativePixmap(surface_handle, GetVulkanDevice(), size, format,
usage);
if (!pixmap.get()) {
DLOG(ERROR) << "Failed to create pixmap " << size.ToString() << ", "
<< gfx::BufferFormatToString(format) << ", usage "
......@@ -144,10 +151,10 @@ GpuMemoryBufferFactoryNativePixmap::CreateAnonymousImage(
bool* is_cleared) {
scoped_refptr<gfx::NativePixmap> pixmap;
#if defined(USE_OZONE)
pixmap =
ui::OzonePlatform::GetInstance()
->GetSurfaceFactoryOzone()
->CreateNativePixmap(gpu::kNullSurfaceHandle, size, format, usage);
pixmap = ui::OzonePlatform::GetInstance()
->GetSurfaceFactoryOzone()
->CreateNativePixmap(gpu::kNullSurfaceHandle, GetVulkanDevice(),
size, format, usage);
#else
NOTIMPLEMENTED();
#endif
......@@ -170,4 +177,10 @@ unsigned GpuMemoryBufferFactoryNativePixmap::RequiredTextureType() {
return GL_TEXTURE_2D;
}
VkDevice GpuMemoryBufferFactoryNativePixmap::GetVulkanDevice() {
return vulkan_context_provider_
? vulkan_context_provider_->GetDeviceQueue()->GetVulkanDevice()
: VK_NULL_HANDLE;
}
} // namespace gpu
......@@ -5,6 +5,8 @@
#ifndef GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_NATIVE_PIXMAP_H_
#define GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_NATIVE_PIXMAP_H_
#include <vulkan/vulkan.h>
#include <unordered_map>
#include <utility>
......@@ -27,6 +29,8 @@ class GPU_IPC_SERVICE_EXPORT GpuMemoryBufferFactoryNativePixmap
public ImageFactory {
public:
GpuMemoryBufferFactoryNativePixmap();
explicit GpuMemoryBufferFactoryNativePixmap(
viz::VulkanContextProvider* vulkan_context_provider);
~GpuMemoryBufferFactoryNativePixmap() override;
// Overridden from GpuMemoryBufferFactory:
......@@ -61,6 +65,11 @@ class GPU_IPC_SERVICE_EXPORT GpuMemoryBufferFactoryNativePixmap
using NativePixmapMap = std::unordered_map<NativePixmapMapKey,
scoped_refptr<gfx::NativePixmap>,
NativePixmapMapKeyHash>;
VkDevice GetVulkanDevice();
scoped_refptr<viz::VulkanContextProvider> vulkan_context_provider_;
NativePixmapMap native_pixmaps_;
base::Lock native_pixmaps_lock_;
......
......@@ -37,8 +37,9 @@ scoped_refptr<VideoFrame> CreateVideoFrameOzone(VideoPixelFormat pixel_format,
gfx::BufferFormat buffer_format =
VideoPixelFormatToGfxBufferFormat(pixel_format);
auto pixmap = factory->CreateNativePixmap(
gfx::kNullAcceleratedWidget, coded_size, buffer_format, buffer_usage);
auto pixmap =
factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, VK_NULL_HANDLE,
coded_size, buffer_format, buffer_usage);
const size_t num_planes = VideoFrame::NumPlanes(pixel_format);
std::vector<VideoFrameLayout::Plane> planes(num_planes);
......
......@@ -97,9 +97,9 @@ bool VaapiPictureNativePixmapOzone::Allocate(gfx::BufferFormat format) {
ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance();
ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone();
pixmap_ =
factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size_, format,
gfx::BufferUsage::SCANOUT_VDA_WRITE);
pixmap_ = factory->CreateNativePixmap(gfx::kNullAcceleratedWidget,
VK_NULL_HANDLE, size_, format,
gfx::BufferUsage::SCANOUT_VDA_WRITE);
if (!pixmap_) {
LOG(ERROR) << "Failed allocating a pixmap";
return false;
......
......@@ -115,7 +115,8 @@ bool SurfacelessSkiaGlRenderer::BufferWrapper::Initialize(
scoped_refptr<gfx::NativePixmap> pixmap =
OzonePlatform::GetInstance()
->GetSurfaceFactoryOzone()
->CreateNativePixmap(widget, size, format, gfx::BufferUsage::SCANOUT);
->CreateNativePixmap(widget, nullptr, size, format,
gfx::BufferUsage::SCANOUT);
auto image = base::MakeRefCounted<gl::GLImageNativePixmap>(size, format);
if (!image->Initialize(std::move(pixmap))) {
LOG(ERROR) << "Failed to create GLImage";
......
......@@ -86,7 +86,8 @@ bool SurfacelessGlRenderer::BufferWrapper::Initialize(
scoped_refptr<gfx::NativePixmap> pixmap =
OzonePlatform::GetInstance()
->GetSurfaceFactoryOzone()
->CreateNativePixmap(widget, size, format, gfx::BufferUsage::SCANOUT);
->CreateNativePixmap(widget, nullptr, size, format,
gfx::BufferUsage::SCANOUT);
auto image = base::MakeRefCounted<gl::GLImageNativePixmap>(size, format);
if (!image->Initialize(std::move(pixmap))) {
LOG(ERROR) << "Failed to create GLImage";
......
......@@ -34,8 +34,8 @@ class GLImageNativePixmapTestDelegate : public GLImageTestDelegateBase {
ui::SurfaceFactoryOzone* surface_factory =
ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone();
scoped_refptr<gfx::NativePixmap> pixmap =
surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size,
format, usage);
surface_factory->CreateNativePixmap(gfx::kNullAcceleratedWidget,
nullptr, size, format, usage);
DCHECK(pixmap);
if (usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE ||
usage == gfx::BufferUsage::SCANOUT_CAMERA_READ_WRITE) {
......
......@@ -120,6 +120,7 @@ std::unique_ptr<SurfaceOzoneCanvas> SurfaceFactoryCast::CreateCanvasForWidget(
scoped_refptr<gfx::NativePixmap> SurfaceFactoryCast::CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) {
......
......@@ -35,6 +35,7 @@ class SurfaceFactoryCast : public SurfaceFactoryOzone {
gfx::AcceleratedWidget widget) override;
scoped_refptr<gfx::NativePixmap> CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) override;
......
......@@ -224,6 +224,7 @@ std::unique_ptr<SurfaceOzoneCanvas> GbmSurfaceFactory::CreateCanvasForWidget(
scoped_refptr<gfx::NativePixmap> GbmSurfaceFactory::CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) {
......
......@@ -56,6 +56,7 @@ class GbmSurfaceFactory : public SurfaceFactoryOzone {
gfx::AcceleratedWidget widget) override;
scoped_refptr<gfx::NativePixmap> CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) override;
......
......@@ -191,6 +191,7 @@ HeadlessSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) {
scoped_refptr<gfx::NativePixmap> HeadlessSurfaceFactory::CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) {
......
......@@ -29,6 +29,7 @@ class HeadlessSurfaceFactory : public SurfaceFactoryOzone {
gfx::AcceleratedWidget widget) override;
scoped_refptr<gfx::NativePixmap> CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) override;
......
......@@ -156,6 +156,7 @@ std::unique_ptr<SurfaceOzoneCanvas> ScenicSurfaceFactory::CreateCanvasForWidget(
scoped_refptr<gfx::NativePixmap> ScenicSurfaceFactory::CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) {
......
......@@ -39,6 +39,7 @@ class ScenicSurfaceFactory : public SurfaceFactoryOzone {
gfx::AcceleratedWidget widget) override;
scoped_refptr<gfx::NativePixmap> CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) override;
......
......@@ -172,6 +172,7 @@ GLOzone* WaylandSurfaceFactory::GetGLOzone(
scoped_refptr<gfx::NativePixmap> WaylandSurfaceFactory::CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) {
......
......@@ -40,6 +40,7 @@ class WaylandSurfaceFactory : public SurfaceFactoryOzone {
gfx::AcceleratedWidget widget) override;
scoped_refptr<gfx::NativePixmap> CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) override;
......
......@@ -71,6 +71,7 @@ std::unique_ptr<SurfaceOzoneCanvas> SurfaceFactoryOzone::CreateCanvasForWidget(
scoped_refptr<gfx::NativePixmap> SurfaceFactoryOzone::CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage) {
......
......@@ -116,6 +116,7 @@ class OZONE_BASE_EXPORT SurfaceFactoryOzone {
// It can be called on any thread.
virtual scoped_refptr<gfx::NativePixmap> CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage);
......
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