Commit b5981531 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

SkiaRenderer/macOS: Update IOSurface shared image factory

Add methods to create a SharedImageRepresentationOverlay for IOSurfaces.
This is based on the GLImage, so common-ize the GLImage lifetime across
all (now 3) callers.

Bug: 894929
Change-Id: Iac2e629a9e2d05089ee72889e42255b75a6fe51b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2222220Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773097}
parent e617291a
...@@ -276,6 +276,27 @@ class SharedImageRepresentationSkiaIOSurface ...@@ -276,6 +276,27 @@ class SharedImageRepresentationSkiaIOSurface
gles2::Texture* const gles2_texture_; gles2::Texture* const gles2_texture_;
}; };
class SharedImageRepresentationOverlayIOSurface
: public SharedImageRepresentationOverlay {
public:
SharedImageRepresentationOverlayIOSurface(
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
scoped_refptr<gl::GLImageIOSurface> gl_image)
: SharedImageRepresentationOverlay(manager, backing, tracker),
gl_image_(gl_image) {}
~SharedImageRepresentationOverlayIOSurface() override { EndReadAccess(); }
private:
bool BeginReadAccess() override { return true; }
void EndReadAccess() override {}
gl::GLImage* GetGLImage() override { return gl_image_.get(); }
scoped_refptr<gl::GLImageIOSurface> gl_image_;
};
// 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
...@@ -514,6 +535,15 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking { ...@@ -514,6 +535,15 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking {
gles2_texture); gles2_texture);
} }
std::unique_ptr<SharedImageRepresentationOverlay> ProduceOverlay(
SharedImageManager* manager,
MemoryTypeTracker* tracker) override {
if (!EnsureGLImage())
return nullptr;
return std::make_unique<SharedImageRepresentationOverlayIOSurface>(
manager, this, tracker, gl_image_);
}
std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn( std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn(
SharedImageManager* manager, SharedImageManager* manager,
MemoryTypeTracker* tracker, MemoryTypeTracker* tracker,
...@@ -532,6 +562,21 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking { ...@@ -532,6 +562,21 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking {
} }
private: 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( void GenGLTexture(
gles2::Texture** texture, gles2::Texture** texture,
scoped_refptr<gles2::TexturePassthrough>* texture_passthrough) { scoped_refptr<gles2::TexturePassthrough>* texture_passthrough) {
...@@ -544,13 +589,8 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking { ...@@ -544,13 +589,8 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking {
*texture_passthrough = nullptr; *texture_passthrough = nullptr;
// Wrap the IOSurface in a GLImageIOSurface // Wrap the IOSurface in a GLImageIOSurface
scoped_refptr<gl::GLImageIOSurface> image( if (!EnsureGLImage())
gl::GLImageIOSurface::Create(size(), gl_info.internal_format));
if (!image->Initialize(io_surface_, gfx::GenericSharedMemoryId(),
viz::BufferFormat(format()))) {
LOG(ERROR) << "Failed to create GLImageIOSurface";
return; return;
}
gl::GLApi* api = gl::g_current_gl_context; gl::GLApi* api = gl::g_current_gl_context;
...@@ -572,7 +612,7 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking { ...@@ -572,7 +612,7 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking {
GL_CLAMP_TO_EDGE); GL_CLAMP_TO_EDGE);
// Bind the GLImageIOSurface to our texture // Bind the GLImageIOSurface to our texture
if (!image->BindTexImage(GL_TEXTURE_RECTANGLE)) { if (!gl_image_->BindTexImage(GL_TEXTURE_RECTANGLE)) {
LOG(ERROR) << "Failed to bind GLImageIOSurface"; LOG(ERROR) << "Failed to bind GLImageIOSurface";
api->glBindTextureFn(GL_TEXTURE_RECTANGLE, old_texture_binding); api->glBindTextureFn(GL_TEXTURE_RECTANGLE, old_texture_binding);
api->glDeleteTexturesFn(1, &service_id); api->glDeleteTexturesFn(1, &service_id);
...@@ -594,7 +634,7 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking { ...@@ -594,7 +634,7 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking {
(*texture)->SetLevelInfo(GL_TEXTURE_RECTANGLE, 0, gl_info.internal_format, (*texture)->SetLevelInfo(GL_TEXTURE_RECTANGLE, 0, gl_info.internal_format,
size().width(), size().height(), 1, 0, size().width(), size().height(), 1, 0,
gl_info.format, gl_info.type, cleared_rect); gl_info.format, gl_info.type, cleared_rect);
(*texture)->SetLevelImage(GL_TEXTURE_RECTANGLE, 0, image.get(), (*texture)->SetLevelImage(GL_TEXTURE_RECTANGLE, 0, gl_image_.get(),
gles2::Texture::BOUND); gles2::Texture::BOUND);
(*texture)->SetImmutable(true, false); (*texture)->SetImmutable(true, false);
} }
...@@ -605,14 +645,15 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking { ...@@ -605,14 +645,15 @@ class SharedImageBackingIOSurface : public ClearTrackingSharedImageBacking {
size().height(), 1, 0, gl_info.format, size().height(), 1, 0, gl_info.format,
gl_info.type)); gl_info.type));
(*texture_passthrough) (*texture_passthrough)
->SetLevelImage(GL_TEXTURE_RECTANGLE, 0, image.get()); ->SetLevelImage(GL_TEXTURE_RECTANGLE, 0, gl_image_.get());
} }
DCHECK_EQ(image->GetInternalFormat(), gl_info.internal_format); DCHECK_EQ(gl_image_->GetInternalFormat(), gl_info.internal_format);
api->glBindTextureFn(GL_TEXTURE_RECTANGLE, old_texture_binding); api->glBindTextureFn(GL_TEXTURE_RECTANGLE, old_texture_binding);
} }
scoped_refptr<gl::GLImageIOSurface> gl_image_;
base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; base::ScopedCFTypeRef<IOSurfaceRef> io_surface_;
base::Optional<WGPUTextureFormat> dawn_format_; base::Optional<WGPUTextureFormat> dawn_format_;
base::scoped_nsprotocol<id<MTLTexture>> mtl_texture_; base::scoped_nsprotocol<id<MTLTexture>> mtl_texture_;
......
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