Add SHARED_MEMORY_BUFFER support for SharedImageOzone
SharedImageBackingFactoryOzone currently supports NATIVE_PIXMAP GMB type. In order to pick ozone over GLImage backing for CrOS/Linux we need to add support for SHARED_MEMORY_BUFFER GMB type as well. This adds the necessary support along with implementing the Update() method in the backing. Change-Id: I51ee61ea612e0e8b8b0f351c28b13a4e3c36226c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3089434 Commit-Queue: Saifuddin Hitawala <hitawala@chromium.org> Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org> Cr-Commit-Position: refs/heads/master@{#912344}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
c99e73d9ad
commit
34a04481a9
gpu/command_buffer/service
@ -13,6 +13,7 @@
|
||||
#include "components/viz/common/resources/resource_format_utils.h"
|
||||
#include "gpu/command_buffer/common/shared_image_usage.h"
|
||||
#include "gpu/command_buffer/service/shared_image_backing_ozone.h"
|
||||
#include "gpu/command_buffer/service/shared_memory_region_wrapper.h"
|
||||
#include "gpu/vulkan/vulkan_device_queue.h"
|
||||
#include "ui/gfx/gpu_memory_buffer.h"
|
||||
#include "ui/gfx/native_pixmap.h"
|
||||
@ -132,20 +133,41 @@ SharedImageBackingFactoryOzone::CreateSharedImage(
|
||||
GrSurfaceOrigin surface_origin,
|
||||
SkAlphaType alpha_type,
|
||||
uint32_t usage) {
|
||||
ui::SurfaceFactoryOzone* surface_factory =
|
||||
ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone();
|
||||
scoped_refptr<gfx::NativePixmap> pixmap =
|
||||
surface_factory->CreateNativePixmapFromHandle(
|
||||
surface_handle, size, buffer_format,
|
||||
std::move(handle.native_pixmap_handle));
|
||||
if (!pixmap) {
|
||||
return nullptr;
|
||||
viz::ResourceFormat format = viz::GetResourceFormat(buffer_format);
|
||||
std::unique_ptr<SharedImageBackingOzone> backing;
|
||||
if (handle.type == gfx::NATIVE_PIXMAP) {
|
||||
ui::SurfaceFactoryOzone* surface_factory =
|
||||
ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone();
|
||||
scoped_refptr<gfx::NativePixmap> pixmap =
|
||||
surface_factory->CreateNativePixmapFromHandle(
|
||||
surface_handle, size, buffer_format,
|
||||
std::move(handle.native_pixmap_handle));
|
||||
if (!pixmap) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
backing = std::make_unique<SharedImageBackingOzone>(
|
||||
mailbox, format, size, color_space, surface_origin, alpha_type, usage,
|
||||
shared_context_state_, std::move(pixmap), dawn_procs_);
|
||||
backing->SetCleared();
|
||||
} else if (handle.type == gfx::SHARED_MEMORY_BUFFER) {
|
||||
SharedMemoryRegionWrapper shm_wrapper;
|
||||
if (!shm_wrapper.Initialize(handle, size, format)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
backing = CreateSharedImageInternal(mailbox, format, surface_handle, size,
|
||||
color_space, surface_origin, alpha_type,
|
||||
usage);
|
||||
if (!backing->WritePixels(shm_wrapper.GetMemoryAsSpan(),
|
||||
shared_context_state_, format, size,
|
||||
alpha_type)) {
|
||||
DLOG(ERROR) << "Failed to write pixels for shared memory.";
|
||||
return nullptr;
|
||||
}
|
||||
backing->SetSharedMemoryWrapper(std::move(shm_wrapper));
|
||||
}
|
||||
auto backing = std::make_unique<SharedImageBackingOzone>(
|
||||
mailbox, viz::GetResourceFormat(buffer_format), size, color_space,
|
||||
surface_origin, alpha_type, usage, shared_context_state_,
|
||||
std::move(pixmap), dawn_procs_);
|
||||
backing->SetCleared();
|
||||
|
||||
return backing;
|
||||
}
|
||||
|
||||
@ -157,7 +179,8 @@ bool SharedImageBackingFactoryOzone::IsSupported(
|
||||
GrContextType gr_context_type,
|
||||
bool* allow_legacy_mailbox,
|
||||
bool is_pixel_used) {
|
||||
if (gmb_type != gfx::EMPTY_BUFFER && gmb_type != gfx::NATIVE_PIXMAP) {
|
||||
if (gmb_type != gfx::EMPTY_BUFFER && gmb_type != gfx::NATIVE_PIXMAP &&
|
||||
gmb_type != gfx::SHARED_MEMORY_BUFFER) {
|
||||
return false;
|
||||
}
|
||||
// TODO(crbug.com/969114): Not all shared image factory implementations
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "gpu/command_buffer/service/shared_image_representation.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation_gl_ozone.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation_skia_gl.h"
|
||||
#include "gpu/command_buffer/service/shared_memory_region_wrapper.h"
|
||||
#include "gpu/command_buffer/service/skia_utils.h"
|
||||
#include "third_party/skia/include/core/SkPromiseImageTexture.h"
|
||||
#include "third_party/skia/include/gpu/GrBackendSemaphore.h"
|
||||
@ -109,8 +110,22 @@ class SharedImageBackingOzone::SharedImageRepresentationOverlayOzone
|
||||
SharedImageBackingOzone::~SharedImageBackingOzone() = default;
|
||||
|
||||
void SharedImageBackingOzone::Update(std::unique_ptr<gfx::GpuFence> in_fence) {
|
||||
NOTIMPLEMENTED_LOG_ONCE();
|
||||
return;
|
||||
if (shared_memory_wrapper_.IsValid()) {
|
||||
DCHECK(!in_fence);
|
||||
if (context_state_->context_lost())
|
||||
return;
|
||||
|
||||
DCHECK(context_state_->IsCurrent(nullptr));
|
||||
if (!WritePixels(shared_memory_wrapper_.GetMemoryAsSpan(),
|
||||
context_state_.get(), format(), size(), alpha_type())) {
|
||||
DLOG(ERROR) << "Failed to write pixels.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SharedImageBackingOzone::SetSharedMemoryWrapper(
|
||||
SharedMemoryRegionWrapper wrapper) {
|
||||
shared_memory_wrapper_ = std::move(wrapper);
|
||||
}
|
||||
|
||||
bool SharedImageBackingOzone::ProduceLegacyMailbox(
|
||||
@ -196,7 +211,7 @@ SharedImageBackingOzone::SharedImageBackingOzone(
|
||||
GrSurfaceOrigin surface_origin,
|
||||
SkAlphaType alpha_type,
|
||||
uint32_t usage,
|
||||
SharedContextState* context_state,
|
||||
scoped_refptr<SharedContextState> context_state,
|
||||
scoped_refptr<gfx::NativePixmap> pixmap,
|
||||
scoped_refptr<base::RefCountedData<DawnProcTable>> dawn_procs)
|
||||
: ClearTrackingSharedImageBacking(mailbox,
|
||||
@ -209,7 +224,8 @@ SharedImageBackingOzone::SharedImageBackingOzone(
|
||||
GetPixmapSizeInBytes(*pixmap),
|
||||
false),
|
||||
pixmap_(std::move(pixmap)),
|
||||
dawn_procs_(std::move(dawn_procs)) {}
|
||||
dawn_procs_(std::move(dawn_procs)),
|
||||
context_state_(std::move(context_state)) {}
|
||||
|
||||
std::unique_ptr<SharedImageRepresentationVaapi>
|
||||
SharedImageBackingOzone::ProduceVASurface(
|
||||
@ -269,6 +285,7 @@ bool SharedImageBackingOzone::WritePixels(
|
||||
DCHECK(result);
|
||||
}
|
||||
|
||||
DCHECK_EQ(size, representation->size());
|
||||
bool written = shared_context_state->gr_context()->updateBackendTexture(
|
||||
dest_scoped_access->promise_image_texture()->backendTexture(), &sk_pixmap,
|
||||
/*numLevels=*/1, representation->surface_origin(), nullptr, nullptr);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "gpu/command_buffer/service/shared_image_backing.h"
|
||||
#include "gpu/command_buffer/service/shared_image_manager.h"
|
||||
#include "gpu/command_buffer/service/shared_image_representation.h"
|
||||
#include "gpu/command_buffer/service/shared_memory_region_wrapper.h"
|
||||
#include "gpu/ipc/common/surface_handle.h"
|
||||
#include "ui/gfx/color_space.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
@ -42,7 +43,7 @@ class SharedImageBackingOzone final : public ClearTrackingSharedImageBacking {
|
||||
GrSurfaceOrigin surface_origin,
|
||||
SkAlphaType alpha_type,
|
||||
uint32_t usage,
|
||||
SharedContextState* context_state,
|
||||
scoped_refptr<SharedContextState> context_state,
|
||||
scoped_refptr<gfx::NativePixmap> pixmap,
|
||||
scoped_refptr<base::RefCountedData<DawnProcTable>> dawn_procs);
|
||||
|
||||
@ -56,6 +57,7 @@ class SharedImageBackingOzone final : public ClearTrackingSharedImageBacking {
|
||||
viz::ResourceFormat format,
|
||||
const gfx::Size& size,
|
||||
SkAlphaType alpha_type);
|
||||
void SetSharedMemoryWrapper(SharedMemoryRegionWrapper wrapper);
|
||||
|
||||
protected:
|
||||
std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn(
|
||||
@ -105,6 +107,9 @@ class SharedImageBackingOzone final : public ClearTrackingSharedImageBacking {
|
||||
scoped_refptr<base::RefCountedData<DawnProcTable>> dawn_procs_;
|
||||
gfx::GpuFenceHandle write_fence_;
|
||||
std::vector<gfx::GpuFenceHandle> read_fences_;
|
||||
// Set for shared memory GMB.
|
||||
SharedMemoryRegionWrapper shared_memory_wrapper_;
|
||||
scoped_refptr<SharedContextState> context_state_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SharedImageBackingOzone);
|
||||
};
|
||||
|
Reference in New Issue
Block a user