Commit 3c1224ca authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

Delete most of SharedImageBackingFactoryIOSurface

This isn't used, and is mostly a copy-paste of
SharedImageBackingFactoryGLTexture.

Bug: 1092155
Change-Id: I57d919afedf074fe786bb213516ca855c888b2bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2297745Reviewed-by: default avatarGeoff Lang <geofflang@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789620}
parent 3ac52ccb
...@@ -8,45 +8,21 @@ ...@@ -8,45 +8,21 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "components/viz/common/resources/resource_format.h"
#include "gpu/command_buffer/service/shared_image_backing.h" #include "gpu/command_buffer/service/shared_image_backing.h"
#include "gpu/command_buffer/service/shared_image_backing_factory.h"
#include "gpu/command_buffer/service/shared_image_representation.h" #include "gpu/command_buffer/service/shared_image_representation.h"
#include "gpu/gpu_gles2_export.h" #include "gpu/gpu_gles2_export.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image.h" #include "ui/gl/gl_image.h"
namespace gfx {
class Size;
class ColorSpace;
} // namespace gfx
namespace gpu { namespace gpu {
class GpuDriverBugWorkarounds;
struct GpuFeatureInfo;
struct Mailbox;
// Implementation of SharedImageBackingFactory that produce IOSurface backed // Helper functions used used by SharedImageRepresentationGLImage to do
// SharedImages. This is meant to be used on macOS only. // IOSurface-specific sharing.
class GPU_GLES2_EXPORT SharedImageBackingFactoryIOSurface class GPU_GLES2_EXPORT SharedImageBackingFactoryIOSurface {
: public SharedImageBackingFactory {
public: public:
SharedImageBackingFactoryIOSurface(const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
bool use_gl);
~SharedImageBackingFactoryIOSurface() override;
// Helper functions used used by SharedImageRepresentationGLImage to do
// IOSurface-specific sharing.
static sk_sp<SkPromiseImageTexture> ProduceSkiaPromiseTextureMetal( static sk_sp<SkPromiseImageTexture> ProduceSkiaPromiseTextureMetal(
SharedImageBacking* backing, SharedImageBacking* backing,
scoped_refptr<SharedContextState> context_state, scoped_refptr<SharedContextState> context_state,
scoped_refptr<gl::GLImage> image); scoped_refptr<gl::GLImage> image);
static std::unique_ptr<SharedImageRepresentationOverlay> ProduceOverlay(
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
scoped_refptr<gl::GLImage> image);
static std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn( static std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn(
SharedImageManager* manager, SharedImageManager* manager,
SharedImageBacking* backing, SharedImageBacking* backing,
...@@ -56,42 +32,6 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryIOSurface ...@@ -56,42 +32,6 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryIOSurface
static bool InitializePixels(SharedImageBacking* backing, static bool InitializePixels(SharedImageBacking* backing,
scoped_refptr<gl::GLImage> image, scoped_refptr<gl::GLImage> image,
const uint8_t* pixel_data); const uint8_t* pixel_data);
// SharedImageBackingFactory implementation.
std::unique_ptr<SharedImageBacking> CreateSharedImage(
const Mailbox& mailbox,
viz::ResourceFormat requested_format,
SurfaceHandle surface_handle,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
bool is_thread_safe) override;
std::unique_ptr<SharedImageBacking> CreateSharedImage(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
base::span<const uint8_t> pixel_data) override;
std::unique_ptr<SharedImageBacking> CreateSharedImage(
const Mailbox& mailbox,
int client_id,
gfx::GpuMemoryBufferHandle handle,
gfx::BufferFormat format,
SurfaceHandle surface_handle,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage) override;
bool CanImportGpuMemoryBuffer(
gfx::GpuMemoryBufferType memory_buffer_type) override;
private:
void CollectGLFormatInfo(const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info);
bool format_supported_by_gl_[viz::RESOURCE_FORMAT_MAX + 1];
bool use_gl_ = false;
DISALLOW_COPY_AND_ASSIGN(SharedImageBackingFactoryIOSurface);
}; };
} // namespace gpu } // namespace gpu
......
...@@ -35,74 +35,6 @@ namespace gpu { ...@@ -35,74 +35,6 @@ namespace gpu {
namespace { namespace {
struct GLFormatInfo {
bool supported = false;
// GL internal_format/format/type triplet.
GLuint internal_format = 0;
GLenum format = 0;
GLenum type = 0;
};
// Get GL format triplets and modify them to match the logic in
// gl_image_iosurface.mm
GLFormatInfo GetGLFormatInfo(viz::ResourceFormat format) {
GLFormatInfo info = {
true,
viz::GLInternalFormat(format),
viz::GLDataFormat(format),
viz::GLDataType(format),
};
if (info.internal_format == GL_ZERO || info.format == GL_ZERO ||
info.type == GL_ZERO) {
return {false, GL_ZERO, GL_ZERO, GL_ZERO};
}
switch (format) {
case viz::BGRA_8888:
info.format = GL_RGBA;
info.internal_format = GL_RGBA;
break;
// Technically we should use GL_RGB but CGLTexImageIOSurface2D() (and
// OpenGL ES 3.0, for the case) support only GL_RGBA (the hardware ignores
// the alpha channel anyway), see https://crbug.com/797347.
case viz::BGRA_1010102:
info.format = GL_RGBA;
info.internal_format = GL_RGBA;
break;
default:
break;
}
return info;
}
void FlushIOSurfaceGLOperations() {
// The CGLTexImageIOSurface2D documentation says that we need to call
// glFlush, otherwise there is the risk of a race between different
// graphics contexts.
gl::GLApi* api = gl::g_current_gl_context;
api->glFlushFn();
}
base::Optional<WGPUTextureFormat> GetWGPUFormat(gfx::BufferFormat format) {
switch (format) {
case gfx::BufferFormat::R_8:
return WGPUTextureFormat_R8Unorm;
case gfx::BufferFormat::RG_88:
return WGPUTextureFormat_RG8Unorm;
case gfx::BufferFormat::RGBX_8888:
case gfx::BufferFormat::RGBA_8888:
case gfx::BufferFormat::BGRX_8888:
return WGPUTextureFormat_BGRA8Unorm;
default:
return {};
}
}
base::scoped_nsprotocol<id<MTLTexture>> API_AVAILABLE(macos(10.11)) base::scoped_nsprotocol<id<MTLTexture>> API_AVAILABLE(macos(10.11))
CreateMetalTexture(id<MTLDevice> mtl_device, CreateMetalTexture(id<MTLDevice> mtl_device,
IOSurfaceRef io_surface, IOSurfaceRef io_surface,
...@@ -148,125 +80,6 @@ base::ScopedCFTypeRef<IOSurfaceRef> GetIOSurfaceFromImage( ...@@ -148,125 +80,6 @@ base::ScopedCFTypeRef<IOSurfaceRef> GetIOSurfaceFromImage(
} // anonymous namespace } // anonymous namespace
// Representation of a SharedImageBackingIOSurface as a GL Texture.
class SharedImageRepresentationGLTextureIOSurface
: public SharedImageRepresentationGLTexture {
public:
SharedImageRepresentationGLTextureIOSurface(SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
gles2::Texture* texture)
: SharedImageRepresentationGLTexture(manager, backing, tracker),
texture_(texture) {
DCHECK(texture_);
}
~SharedImageRepresentationGLTextureIOSurface() override {
texture_->RemoveLightweightRef(has_context());
}
gles2::Texture* GetTexture() override { return texture_; }
bool BeginAccess(GLenum mode) override { return true; }
void EndAccess() override { FlushIOSurfaceGLOperations(); }
private:
gles2::Texture* texture_;
DISALLOW_COPY_AND_ASSIGN(SharedImageRepresentationGLTextureIOSurface);
};
class SharedImageRepresentationGLTexturePassthroughIOSurface
: public SharedImageRepresentationGLTexturePassthrough {
public:
SharedImageRepresentationGLTexturePassthroughIOSurface(
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
scoped_refptr<gles2::TexturePassthrough> texture_passthrough)
: SharedImageRepresentationGLTexturePassthrough(manager,
backing,
tracker),
texture_passthrough_(texture_passthrough) {}
const scoped_refptr<gles2::TexturePassthrough>& GetTexturePassthrough()
override {
return texture_passthrough_;
}
bool BeginAccess(GLenum mode) override { return true; }
void EndAccess() override { FlushIOSurfaceGLOperations(); }
private:
scoped_refptr<gles2::TexturePassthrough> texture_passthrough_;
DISALLOW_COPY_AND_ASSIGN(
SharedImageRepresentationGLTexturePassthroughIOSurface);
};
// Representation of a SharedImageBackingIOSurface as a Skia Texture.
class SharedImageRepresentationSkiaIOSurface
: public SharedImageRepresentationSkia {
public:
SharedImageRepresentationSkiaIOSurface(
SharedImageManager* manager,
SharedImageBacking* backing,
scoped_refptr<SharedContextState> context_state,
sk_sp<SkPromiseImageTexture> promise_texture,
MemoryTypeTracker* tracker,
gles2::Texture* gles2_texture)
: SharedImageRepresentationSkia(manager, backing, tracker),
context_state_(std::move(context_state)),
promise_texture_(std::move(promise_texture)),
gles2_texture_(gles2_texture) {
DCHECK(promise_texture_);
}
~SharedImageRepresentationSkiaIOSurface() override {
if (gles2_texture_)
gles2_texture_->RemoveLightweightRef(has_context());
}
sk_sp<SkSurface> BeginWriteAccess(
int final_msaa_count,
const SkSurfaceProps& surface_props,
std::vector<GrBackendSemaphore>* begin_semaphores,
std::vector<GrBackendSemaphore>* end_semaphores) override {
SkColorType sk_color_type = viz::ResourceFormatToClosestSkColorType(
/*gpu_compositing=*/true, format());
return SkSurface::MakeFromBackendTexture(
context_state_->gr_context(), promise_texture_->backendTexture(),
kTopLeft_GrSurfaceOrigin, final_msaa_count, sk_color_type,
backing()->color_space().ToSkColorSpace(), &surface_props);
}
void EndWriteAccess(sk_sp<SkSurface> surface) override {
if (context_state_->GrContextIsGL())
FlushIOSurfaceGLOperations();
if (gles2_texture_ &&
gles2_texture_->IsLevelCleared(gles2_texture_->target(), 0)) {
backing()->SetCleared();
}
}
sk_sp<SkPromiseImageTexture> BeginReadAccess(
std::vector<GrBackendSemaphore>* begin_semaphores,
std::vector<GrBackendSemaphore>* end_semaphores) override {
return promise_texture_;
}
void EndReadAccess() override {
if (context_state_->GrContextIsGL())
FlushIOSurfaceGLOperations();
}
private:
scoped_refptr<SharedContextState> context_state_;
sk_sp<SkPromiseImageTexture> promise_texture_;
gles2::Texture* const gles2_texture_;
};
// Representation of a SharedImageBackingIOSurface as a Dawn Texture. // Representation of a SharedImageBackingIOSurface as a Dawn Texture.
#if BUILDFLAG(USE_DAWN) #if BUILDFLAG(USE_DAWN)
class SharedImageRepresentationDawnIOSurface class SharedImageRepresentationDawnIOSurface
...@@ -364,414 +177,6 @@ class SharedImageRepresentationDawnIOSurface ...@@ -364,414 +177,6 @@ class SharedImageRepresentationDawnIOSurface
}; };
#endif // BUILDFLAG(USE_DAWN) #endif // BUILDFLAG(USE_DAWN)
// Implementation of SharedImageBacking by wrapping IOSurfaces. Disable
// unguarded availability warnings because they are incompatible with using a
// scoped_nsprotocol for the id<MTLTexture> and because all access to Metal is
// guarded on the context provider already successfully using Metal.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability"
class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking {
public:
SharedImageBackingIOSurface(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
base::ScopedCFTypeRef<IOSurfaceRef> io_surface,
base::Optional<WGPUTextureFormat> dawn_format,
size_t estimated_size)
: ClearTrackingSharedImageBacking(mailbox,
format,
size,
color_space,
usage,
estimated_size,
false /* is_thread_safe */),
io_surface_(std::move(io_surface)),
dawn_format_(dawn_format) {
DCHECK(io_surface_);
}
~SharedImageBackingIOSurface() final {
TRACE_EVENT0("gpu", "SharedImageBackingFactoryIOSurface::Destroy");
DCHECK(io_surface_);
if (legacy_texture_) {
legacy_texture_->RemoveLightweightRef(have_context());
legacy_texture_ = nullptr;
}
mtl_texture_.reset();
io_surface_.reset();
}
gfx::Rect ClearedRect() const final {
// If a |legacy_texture_| exists, defer to that. Once created,
// |legacy_texture_| is never destroyed, so no need to synchronize with
// ClearedRect.
if (legacy_texture_) {
return legacy_texture_->GetLevelClearedRect(legacy_texture_->target(), 0);
} else {
return ClearTrackingSharedImageBacking::ClearedRect();
}
}
void SetClearedRect(const gfx::Rect& cleared_rect) final {
// If a |legacy_texture_| exists, defer to that. Once created,
// |legacy_texture_| is never destroyed, so no need to synchronize with
// SetClearedRect.
if (legacy_texture_) {
legacy_texture_->SetLevelClearedRect(legacy_texture_->target(), 0,
cleared_rect);
} else {
ClearTrackingSharedImageBacking::SetClearedRect(cleared_rect);
}
}
void Update(std::unique_ptr<gfx::GpuFence> in_fence) final {}
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) final {
DCHECK(io_surface_);
GenGLTexture(&legacy_texture_, nullptr);
if (!legacy_texture_) {
return false;
}
// Make sure our |legacy_texture_| has the right initial cleared rect.
legacy_texture_->SetLevelClearedRect(
legacy_texture_->target(), 0,
ClearTrackingSharedImageBacking::ClearedRect());
mailbox_manager->ProduceTexture(mailbox(), legacy_texture_);
return true;
}
protected:
std::unique_ptr<SharedImageRepresentationGLTexture> ProduceGLTexture(
SharedImageManager* manager,
MemoryTypeTracker* tracker) final {
gles2::Texture* texture = nullptr;
GenGLTexture(&texture, nullptr);
if (!texture)
return nullptr;
return std::make_unique<SharedImageRepresentationGLTextureIOSurface>(
manager, this, tracker, texture);
}
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
ProduceGLTexturePassthrough(SharedImageManager* manager,
MemoryTypeTracker* tracker) override {
TRACE_EVENT0("gpu",
"SharedImageBackingFactoryIOSurface::GenGLTexturePassthrough");
scoped_refptr<gles2::TexturePassthrough> texture_passthrough;
GenGLTexture(nullptr, &texture_passthrough);
if (!texture_passthrough)
return nullptr;
return std::make_unique<
SharedImageRepresentationGLTexturePassthroughIOSurface>(
manager, this, tracker, texture_passthrough);
}
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) override {
gles2::Texture* gles2_texture = nullptr;
GrBackendTexture gr_backend_texture;
if (context_state->GrContextIsGL()) {
GenGLTexture(&gles2_texture, nullptr);
if (!gles2_texture)
return nullptr;
GetGrBackendTexture(
context_state->feature_info(), gles2_texture->target(), size(),
gles2_texture->service_id(), format(), &gr_backend_texture);
}
if (context_state->GrContextIsMetal()) {
if (!mtl_texture_) {
id<MTLDevice> mtl_device =
context_state->metal_context_provider()->GetMTLDevice();
mtl_texture_ =
CreateMetalTexture(mtl_device, io_surface_, size(), format());
DCHECK(mtl_texture_);
}
GrMtlTextureInfo info;
info.fTexture.retain(mtl_texture_.get());
gr_backend_texture = GrBackendTexture(size().width(), size().height(),
GrMipMapped::kNo, info);
}
sk_sp<SkPromiseImageTexture> promise_texture =
SkPromiseImageTexture::Make(gr_backend_texture);
return std::make_unique<SharedImageRepresentationSkiaIOSurface>(
manager, this, std::move(context_state), promise_texture, tracker,
gles2_texture);
}
std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
WGPUDevice device) override {
#if BUILDFLAG(USE_DAWN)
if (!dawn_format_) {
LOG(ERROR) << "Format not supported for Dawn";
return nullptr;
}
return std::make_unique<SharedImageRepresentationDawnIOSurface>(
manager, this, tracker, device, io_surface_, dawn_format_.value());
#else // BUILDFLAG(USE_DAWN)
return nullptr;
#endif // BUILDFLAG(USE_DAWN)
}
private:
bool EnsureGLImage() {
if (!gl_image_) {
GLFormatInfo gl_info = GetGLFormatInfo(format());
scoped_refptr<gl::GLImageIOSurface> gl_image(
gl::GLImageIOSurface::Create(size(), gl_info.internal_format));
if (!gl_image->Initialize(io_surface_, gfx::GenericSharedMemoryId(),
viz::BufferFormat(format()))) {
LOG(ERROR) << "Failed to create GLImageIOSurface";
} else {
gl_image_ = gl_image;
}
}
return !!gl_image_;
}
void GenGLTexture(
gles2::Texture** texture,
scoped_refptr<gles2::TexturePassthrough>* texture_passthrough) {
TRACE_EVENT0("gpu", "SharedImageBackingFactoryIOSurface::GenGLTexture");
GLFormatInfo gl_info = GetGLFormatInfo(format());
DCHECK(gl_info.supported);
if (texture)
*texture = nullptr;
if (texture_passthrough)
*texture_passthrough = nullptr;
// Wrap the IOSurface in a GLImageIOSurface
if (!EnsureGLImage())
return;
gl::GLApi* api = gl::g_current_gl_context;
// Save the currently bound rectangle texture to reset it once we are done.
GLint old_texture_binding = 0;
api->glGetIntegervFn(GL_TEXTURE_BINDING_RECTANGLE, &old_texture_binding);
// Create a gles2 rectangle texture to bind to the IOSurface.
GLuint service_id = 0;
api->glGenTexturesFn(1, &service_id);
api->glBindTextureFn(GL_TEXTURE_RECTANGLE, service_id);
api->glTexParameteriFn(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
api->glTexParameteriFn(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
api->glTexParameteriFn(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
api->glTexParameteriFn(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
// Bind the GLImageIOSurface to our texture
if (!gl_image_->BindTexImage(GL_TEXTURE_RECTANGLE)) {
LOG(ERROR) << "Failed to bind GLImageIOSurface";
api->glBindTextureFn(GL_TEXTURE_RECTANGLE, old_texture_binding);
api->glDeleteTexturesFn(1, &service_id);
return;
}
// If the backing is already cleared, no need to clear it again.
gfx::Rect cleared_rect = ClearedRect();
// Manually create a gles2::Texture wrapping our driver texture.
if (texture) {
*texture = new gles2::Texture(service_id);
(*texture)->SetLightweightRef();
(*texture)->SetTarget(GL_TEXTURE_RECTANGLE, 1);
(*texture)->set_min_filter(GL_LINEAR);
(*texture)->set_mag_filter(GL_LINEAR);
(*texture)->set_wrap_t(GL_CLAMP_TO_EDGE);
(*texture)->set_wrap_s(GL_CLAMP_TO_EDGE);
(*texture)->SetLevelInfo(GL_TEXTURE_RECTANGLE, 0, gl_info.internal_format,
size().width(), size().height(), 1, 0,
gl_info.format, gl_info.type, cleared_rect);
(*texture)->SetLevelImage(GL_TEXTURE_RECTANGLE, 0, gl_image_.get(),
gles2::Texture::BOUND);
(*texture)->SetImmutable(true, false);
}
if (texture_passthrough) {
*texture_passthrough = scoped_refptr<gles2::TexturePassthrough>(
new gles2::TexturePassthrough(service_id, GL_TEXTURE_RECTANGLE,
gl_info.internal_format, size().width(),
size().height(), 1, 0, gl_info.format,
gl_info.type));
(*texture_passthrough)
->SetLevelImage(GL_TEXTURE_RECTANGLE, 0, gl_image_.get());
}
DCHECK_EQ(gl_image_->GetInternalFormat(), gl_info.internal_format);
api->glBindTextureFn(GL_TEXTURE_RECTANGLE, old_texture_binding);
}
scoped_refptr<gl::GLImageIOSurface> gl_image_;
base::ScopedCFTypeRef<IOSurfaceRef> io_surface_;
base::Optional<WGPUTextureFormat> dawn_format_;
base::scoped_nsprotocol<id<MTLTexture>> mtl_texture_;
// A texture for the associated legacy mailbox.
gles2::Texture* legacy_texture_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(SharedImageBackingIOSurface);
};
#pragma clang diagnostic pop
// Implementation of SharedImageBackingFactoryIOSurface that creates
// SharedImageBackings wrapping IOSurfaces.
SharedImageBackingFactoryIOSurface::SharedImageBackingFactoryIOSurface(
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
bool use_gl)
: use_gl_(use_gl) {
if (use_gl_) {
CollectGLFormatInfo(workarounds, gpu_feature_info);
}
}
void SharedImageBackingFactoryIOSurface::CollectGLFormatInfo(
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info) {
scoped_refptr<gles2::FeatureInfo> feature_info =
new gles2::FeatureInfo(workarounds, gpu_feature_info);
feature_info->Initialize(ContextType::CONTEXT_TYPE_OPENGLES2, false,
gles2::DisallowedFeatures());
const gles2::Validators* validators = feature_info->validators();
// Precompute for each format if we can use it with GL.
for (int i = 0; i <= viz::RESOURCE_FORMAT_MAX; ++i) {
viz::ResourceFormat format = static_cast<viz::ResourceFormat>(i);
GLFormatInfo gl_info = GetGLFormatInfo(format);
format_supported_by_gl_[i] =
gl_info.supported &&
validators->texture_internal_format.IsValid(gl_info.internal_format) &&
validators->texture_format.IsValid(gl_info.format) &&
validators->pixel_type.IsValid(gl_info.type);
}
}
SharedImageBackingFactoryIOSurface::~SharedImageBackingFactoryIOSurface() =
default;
std::unique_ptr<SharedImageBacking>
SharedImageBackingFactoryIOSurface::CreateSharedImage(
const Mailbox& mailbox,
viz::ResourceFormat requested_format,
SurfaceHandle surface_handle,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
bool is_thread_safe) {
TRACE_EVENT0("gpu", "SharedImageBackingFactoryIOSurface::CreateSharedImage");
DCHECK(!is_thread_safe);
// Check the format is supported and for simplicity always require it to be
// supported for GL.
if (use_gl_ && !format_supported_by_gl_[requested_format]) {
LOG(ERROR) << "viz::ResourceFormat " << requested_format
<< " not supported by IOSurfaces";
return nullptr;
}
// Calculate SharedImage size in bytes.
size_t estimated_size;
if (!viz::ResourceSizes::MaybeSizeInBytes(size, requested_format,
&estimated_size)) {
LOG(ERROR) << "Failed to calculate SharedImage size";
return nullptr;
}
// Note: OpenGL textures bound to IOSurfaces won't work on macOS unless the
// internal format is BGRA. So if RGBA8 is passed into CreateIOSurface(), the
// resulting IOSurface is actually BGRA8 (see PixelFormat() in
// ui/gfx/mac/io_surface.cc).
// Explicitly override it here to avoid confusion.
viz::ResourceFormat actual_format = requested_format;
if (requested_format == viz::RGBA_8888) {
actual_format = viz::BGRA_8888;
}
base::ScopedCFTypeRef<IOSurfaceRef> io_surface(
gfx::CreateIOSurface(size, viz::BufferFormat(actual_format), false));
if (!io_surface) {
LOG(ERROR) << "Failed to allocate IOSurface.";
return nullptr;
}
gfx::IOSurfaceSetColorSpace(io_surface, color_space);
base::Optional<WGPUTextureFormat> wgpu_format =
viz::ToWGPUFormat(actual_format);
if (wgpu_format.value() == WGPUTextureFormat_Undefined) {
wgpu_format = base::nullopt;
}
return std::make_unique<SharedImageBackingIOSurface>(
mailbox, requested_format, size, color_space, usage,
std::move(io_surface), wgpu_format, estimated_size);
}
std::unique_ptr<SharedImageBacking>
SharedImageBackingFactoryIOSurface::CreateSharedImage(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
base::span<const uint8_t> pixel_data) {
NOTIMPLEMENTED();
return nullptr;
}
std::unique_ptr<SharedImageBacking>
SharedImageBackingFactoryIOSurface::CreateSharedImage(
const Mailbox& mailbox,
int client_id,
gfx::GpuMemoryBufferHandle handle,
gfx::BufferFormat format,
SurfaceHandle surface_handle,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage) {
if (handle.type != gfx::GpuMemoryBufferType::IO_SURFACE_BUFFER) {
NOTIMPLEMENTED();
return nullptr;
}
base::ScopedCFTypeRef<IOSurfaceRef> io_surface(
IOSurfaceLookupFromMachPort(handle.mach_port.get()));
if (!io_surface) {
DLOG(ERROR) << "IOSurfaceLookupFromMachPort failed.";
return nullptr;
}
viz::ResourceFormat resource_format = viz::GetResourceFormat(format);
size_t estimated_size = 0;
if (!viz::ResourceSizes::MaybeSizeInBytes(size, resource_format,
&estimated_size)) {
DLOG(ERROR) << "Failed to calculate SharedImage size";
return nullptr;
}
return std::make_unique<SharedImageBackingIOSurface>(
mailbox, resource_format, size, color_space, usage, std::move(io_surface),
GetWGPUFormat(format), estimated_size);
}
bool SharedImageBackingFactoryIOSurface::CanImportGpuMemoryBuffer(
gfx::GpuMemoryBufferType memory_buffer_type) {
return false;
}
// static // static
sk_sp<SkPromiseImageTexture> sk_sp<SkPromiseImageTexture>
SharedImageBackingFactoryIOSurface::ProduceSkiaPromiseTextureMetal( SharedImageBackingFactoryIOSurface::ProduceSkiaPromiseTextureMetal(
......
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