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

Separate SharedImageBackingGL Texture vs Image

At the beginning of this refactor there were 2 SharedImageBacking
classes: passthrough vs not-passthrough.

This is towards having 2 SharedImageBacking: GLImage vs normal
GL texture. The classes still inherit from a single Common class.
This moves some of the common code into static methods in the
Common class. In particular
* Make separate InitializeGLTexture functions, and move much of
  the common code into SharedImageBackingGLCommon::
  MakeTextureAndSetParameters.
* Make SharedImageRepresentationSkiaImpl have a method to take a
  callback to make on BeginReadAccess, rather than calling a
  method on SharedImageBackingGLCommon.
  - De-common-ize SharedImageBackingGLCommon::ProduceSkia.
  - Change it to have the caller create the SkPromiseImageTexture.
* Add SharedImageBackingGLImage::InitializePixels
  - For now this just calls glTexSubImage2D
  - In the future this will write to the GpuMemoryBuffer.

Bug: 1092155
Change-Id: If5f60356d683673e610192b7c851664a138a9951
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2248413
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarGeoff Lang <geofflang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780011}
parent 37ca7c98
...@@ -190,23 +190,6 @@ class ScopedRestoreTexture { ...@@ -190,23 +190,6 @@ class ScopedRestoreTexture {
DISALLOW_COPY_AND_ASSIGN(ScopedRestoreTexture); DISALLOW_COPY_AND_ASSIGN(ScopedRestoreTexture);
}; };
GLuint MakeTextureAndSetParameters(gl::GLApi* api,
GLenum target,
bool framebuffer_attachment_angle) {
GLuint service_id = 0;
api->glGenTexturesFn(1, &service_id);
api->glBindTextureFn(target, service_id);
api->glTexParameteriFn(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (framebuffer_attachment_angle) {
api->glTexParameteriFn(target, GL_TEXTURE_USAGE_ANGLE,
GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
}
return service_id;
}
std::unique_ptr<SharedImageRepresentationDawn> ProduceDawnCommon( std::unique_ptr<SharedImageRepresentationDawn> ProduceDawnCommon(
SharedImageFactory* factory, SharedImageFactory* factory,
SharedImageManager* manager, SharedImageManager* manager,
...@@ -385,27 +368,58 @@ GLuint SharedImageBackingGLCommon::GetGLServiceId() const { ...@@ -385,27 +368,58 @@ GLuint SharedImageBackingGLCommon::GetGLServiceId() const {
return texture_ ? texture_->service_id() : passthrough_texture_->service_id(); return texture_ ? texture_->service_id() : passthrough_texture_->service_id();
} }
// static
void SharedImageBackingGLCommon::MakeTextureAndSetParameters(
GLenum target,
GLuint service_id,
bool framebuffer_attachment_angle,
scoped_refptr<gles2::TexturePassthrough>* passthrough_texture,
gles2::Texture** texture) {
if (!service_id) {
gl::GLApi* api = gl::g_current_gl_context;
ScopedRestoreTexture scoped_restore(api, target);
api->glGenTexturesFn(1, &service_id);
api->glBindTextureFn(target, service_id);
api->glTexParameteriFn(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (framebuffer_attachment_angle) {
api->glTexParameteriFn(target, GL_TEXTURE_USAGE_ANGLE,
GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
}
}
if (passthrough_texture) {
*passthrough_texture =
base::MakeRefCounted<gles2::TexturePassthrough>(service_id, target);
}
if (texture) {
*texture = new gles2::Texture(service_id);
(*texture)->SetLightweightRef();
(*texture)->SetTarget(target, 1);
(*texture)->set_min_filter(GL_LINEAR);
(*texture)->set_mag_filter(GL_LINEAR);
(*texture)->set_wrap_s(GL_CLAMP_TO_EDGE);
(*texture)->set_wrap_t(GL_CLAMP_TO_EDGE);
}
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// SharedImageRepresentationSkiaImpl // SharedImageRepresentationSkiaImpl
SharedImageRepresentationSkiaImpl::SharedImageRepresentationSkiaImpl( SharedImageRepresentationSkiaImpl::SharedImageRepresentationSkiaImpl(
SharedImageManager* manager, SharedImageManager* manager,
SharedImageBackingGLCommon* backing, SharedImageBacking* backing,
scoped_refptr<SharedContextState> context_state, scoped_refptr<SharedContextState> context_state,
sk_sp<SkPromiseImageTexture> cached_promise_texture, sk_sp<SkPromiseImageTexture> promise_texture,
MemoryTypeTracker* tracker, MemoryTypeTracker* tracker)
GLenum target,
GLuint service_id)
: SharedImageRepresentationSkia(manager, backing, tracker), : SharedImageRepresentationSkia(manager, backing, tracker),
context_state_(std::move(context_state)), context_state_(std::move(context_state)),
promise_texture_(cached_promise_texture) { promise_texture_(promise_texture) {
if (!promise_texture_) { DCHECK(promise_texture_);
GrBackendTexture backend_texture;
GetGrBackendTexture(context_state_->feature_info(), target, size(),
service_id, format(), &backend_texture);
promise_texture_ = SkPromiseImageTexture::Make(backend_texture);
}
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
if (context_state_->GrContextIsGL())
context_ = gl::GLContext::GetCurrent(); context_ = gl::GLContext::GetCurrent();
#endif #endif
} }
...@@ -452,7 +466,8 @@ sk_sp<SkPromiseImageTexture> SharedImageRepresentationSkiaImpl::BeginReadAccess( ...@@ -452,7 +466,8 @@ sk_sp<SkPromiseImageTexture> SharedImageRepresentationSkiaImpl::BeginReadAccess(
std::vector<GrBackendSemaphore>* begin_semaphores, std::vector<GrBackendSemaphore>* begin_semaphores,
std::vector<GrBackendSemaphore>* end_semaphores) { std::vector<GrBackendSemaphore>* end_semaphores) {
CheckContext(); CheckContext();
static_cast<SharedImageBackingGLCommon*>(backing())->BeginSkiaReadAccess(); if (begin_read_access_callback_)
begin_read_access_callback_.Run();
return promise_texture_; return promise_texture_;
} }
...@@ -464,13 +479,14 @@ bool SharedImageRepresentationSkiaImpl::SupportsMultipleConcurrentReadAccess() { ...@@ -464,13 +479,14 @@ bool SharedImageRepresentationSkiaImpl::SupportsMultipleConcurrentReadAccess() {
return true; return true;
} }
sk_sp<SkPromiseImageTexture> void SharedImageRepresentationSkiaImpl::SetBeginReadAccessCallback(
SharedImageRepresentationSkiaImpl::promise_texture() { base::RepeatingClosure begin_read_access_callback) {
return promise_texture_; begin_read_access_callback_ = std::move(begin_read_access_callback);
} }
void SharedImageRepresentationSkiaImpl::CheckContext() { void SharedImageRepresentationSkiaImpl::CheckContext() {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
if (context_)
DCHECK(gl::GLContext::GetCurrent() == context_); DCHECK(gl::GLContext::GetCurrent() == context_);
#endif #endif
} }
...@@ -581,10 +597,6 @@ SharedImageBackingGLCommon::ProduceDawn(SharedImageManager* manager, ...@@ -581,10 +597,6 @@ SharedImageBackingGLCommon::ProduceDawn(SharedImageManager* manager,
IsPassthrough()); IsPassthrough());
} }
void SharedImageBackingGLTexture::BeginSkiaReadAccess() {
// This is used only by GLImage-backed shared image backings.
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// SharedImageBackingGLImage // SharedImageBackingGLImage
...@@ -604,7 +616,8 @@ SharedImageBackingGLImage::SharedImageBackingGLImage( ...@@ -604,7 +616,8 @@ SharedImageBackingGLImage::SharedImageBackingGLImage(
usage, usage,
is_passthrough), is_passthrough),
image_(image), image_(image),
attribs_(attribs) { attribs_(attribs),
weak_factory_(this) {
DCHECK(image_); DCHECK(image_);
} }
...@@ -730,34 +743,24 @@ SharedImageBackingGLImage::ProduceRGBEmulationGLTexture( ...@@ -730,34 +743,24 @@ SharedImageBackingGLImage::ProduceRGBEmulationGLTexture(
ScopedRestoreTexture scoped_restore(api, target); ScopedRestoreTexture scoped_restore(api, target);
// Set to false as this code path is only used on Mac. // Set to false as this code path is only used on Mac.
bool framebuffer_attachment_angle = false; const bool framebuffer_attachment_angle = false;
GLuint service_id = MakeTextureAndSetParameters(target, 0 /* service_id */,
MakeTextureAndSetParameters(api, target, framebuffer_attachment_angle); framebuffer_attachment_angle, nullptr,
&rgb_emulation_texture_);
api->glBindTextureFn(target, rgb_emulation_texture_->service_id());
gles2::Texture::ImageState image_state = gles2::Texture::BOUND; gles2::Texture::ImageState image_state = gles2::Texture::BOUND;
gl::GLImage* image = texture_->GetLevelImage(target, 0, &image_state); gl::GLImage* image = texture_->GetLevelImage(target, 0, &image_state);
DCHECK_EQ(image, image_.get()); DCHECK_EQ(image, image_.get());
if (!image) {
LOG(ERROR) << "Texture is not bound to an image.";
return nullptr;
}
DCHECK(image->ShouldBindOrCopy() == gl::GLImage::BIND); DCHECK(image->ShouldBindOrCopy() == gl::GLImage::BIND);
const GLenum internal_format = GL_RGB; const GLenum internal_format = GL_RGB;
if (!image->BindTexImageWithInternalformat(target, internal_format)) { if (!image->BindTexImageWithInternalformat(target, internal_format)) {
LOG(ERROR) << "Failed to bind image to rgb texture."; LOG(ERROR) << "Failed to bind image to rgb texture.";
api->glDeleteTexturesFn(1, &service_id); rgb_emulation_texture_->RemoveLightweightRef(true /* have_context */);
rgb_emulation_texture_ = nullptr;
return nullptr; return nullptr;
} }
rgb_emulation_texture_ = new gles2::Texture(service_id);
rgb_emulation_texture_->SetLightweightRef();
rgb_emulation_texture_->SetTarget(target, 1);
rgb_emulation_texture_->set_min_filter(GL_LINEAR);
rgb_emulation_texture_->set_mag_filter(GL_LINEAR);
rgb_emulation_texture_->set_wrap_t(GL_CLAMP_TO_EDGE);
rgb_emulation_texture_->set_wrap_s(GL_CLAMP_TO_EDGE);
GLenum format = GLenum format =
gles2::TextureManager::ExtractFormatFromStorageFormat(internal_format); gles2::TextureManager::ExtractFormatFromStorageFormat(internal_format);
GLenum type = GLenum type =
...@@ -777,14 +780,40 @@ SharedImageBackingGLImage::ProduceRGBEmulationGLTexture( ...@@ -777,14 +780,40 @@ SharedImageBackingGLImage::ProduceRGBEmulationGLTexture(
} }
std::unique_ptr<SharedImageRepresentationSkia> std::unique_ptr<SharedImageRepresentationSkia>
SharedImageBackingGLCommon::ProduceSkia( SharedImageBackingGLTexture::ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) {
if (!cached_promise_texture_) {
GrBackendTexture backend_texture;
GetGrBackendTexture(context_state->feature_info(), GetGLTarget(), size(),
GetGLServiceId(), format(), &backend_texture);
cached_promise_texture_ = SkPromiseImageTexture::Make(backend_texture);
}
return std::make_unique<SharedImageRepresentationSkiaImpl>(
manager, this, std::move(context_state), cached_promise_texture_,
tracker);
}
std::unique_ptr<SharedImageRepresentationSkia>
SharedImageBackingGLImage::ProduceSkia(
SharedImageManager* manager, SharedImageManager* manager,
MemoryTypeTracker* tracker, MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) { scoped_refptr<SharedContextState> context_state) {
// Sub-classes will, in the future, produce non-GL-backed a
// SkPromiseImageTexture.
if (!cached_promise_texture_) {
GrBackendTexture backend_texture;
GetGrBackendTexture(context_state->feature_info(), GetGLTarget(), size(),
GetGLServiceId(), format(), &backend_texture);
cached_promise_texture_ = SkPromiseImageTexture::Make(backend_texture);
}
auto result = std::make_unique<SharedImageRepresentationSkiaImpl>( auto result = std::make_unique<SharedImageRepresentationSkiaImpl>(
manager, this, std::move(context_state), cached_promise_texture_, tracker, manager, this, std::move(context_state), cached_promise_texture_,
GetGLTarget(), GetGLServiceId()); tracker);
cached_promise_texture_ = result->promise_texture(); result->SetBeginReadAccessCallback(
base::BindRepeating(&SharedImageBackingGLImage::BeginSkiaReadAccess,
weak_factory_.GetWeakPtr()));
return result; return result;
} }
...@@ -1014,7 +1043,7 @@ SharedImageBackingFactoryGLTexture::CreateSharedImage( ...@@ -1014,7 +1043,7 @@ SharedImageBackingFactoryGLTexture::CreateSharedImage(
params.is_rgb_emulation = is_rgb_emulation; params.is_rgb_emulation = is_rgb_emulation;
params.framebuffer_attachment_angle = params.framebuffer_attachment_angle =
for_framebuffer_attachment && texture_usage_angle_; for_framebuffer_attachment && texture_usage_angle_;
if (!result->InitializeGLTexture(0, params)) if (!result->InitializeGLTexture(params))
return nullptr; return nullptr;
return std::move(result); return std::move(result);
} }
...@@ -1074,28 +1103,17 @@ bool SharedImageBackingFactoryGLTexture::CanImportGpuMemoryBuffer( ...@@ -1074,28 +1103,17 @@ bool SharedImageBackingFactoryGLTexture::CanImportGpuMemoryBuffer(
return true; return true;
} }
bool SharedImageBackingGLCommon::InitializeGLTexture( void SharedImageBackingGLTexture::InitializeGLTexture(
GLuint service_id, GLuint service_id,
const InitializeGLTextureParams& params) { const InitializeGLTextureParams& params) {
if (!service_id) { MakeTextureAndSetParameters(params.target, service_id,
gl::GLApi* api = gl::g_current_gl_context; params.framebuffer_attachment_angle,
ScopedRestoreTexture scoped_restore(api, params.target); IsPassthrough() ? &passthrough_texture_ : nullptr,
service_id = MakeTextureAndSetParameters( IsPassthrough() ? nullptr : &texture_);
api, params.target, params.framebuffer_attachment_angle);
}
if (IsPassthrough()) { if (IsPassthrough()) {
passthrough_texture_ = base::MakeRefCounted<gles2::TexturePassthrough>(
service_id, params.target);
passthrough_texture_->SetEstimatedSize(EstimatedSize(format(), size())); passthrough_texture_->SetEstimatedSize(EstimatedSize(format(), size()));
} else { } else {
texture_ = new gles2::Texture(service_id);
texture_->SetLightweightRef();
texture_->SetTarget(params.target, 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(params.target, 0, params.internal_format, texture_->SetLevelInfo(params.target, 0, params.internal_format,
size().width(), size().height(), 1, 0, params.format, size().width(), size().height(), 1, 0, params.format,
params.type, params.type,
...@@ -1104,14 +1122,14 @@ bool SharedImageBackingGLCommon::InitializeGLTexture( ...@@ -1104,14 +1122,14 @@ bool SharedImageBackingGLCommon::InitializeGLTexture(
texture_->SetCompatibilitySwizzle(params.swizzle); texture_->SetCompatibilitySwizzle(params.swizzle);
texture_->SetImmutable(true, params.has_immutable_storage); texture_->SetImmutable(true, params.has_immutable_storage);
} }
return true;
} }
bool SharedImageBackingGLImage::InitializeGLTexture( bool SharedImageBackingGLImage::InitializeGLTexture(
GLuint service_id,
const InitializeGLTextureParams& params) { const InitializeGLTextureParams& params) {
SharedImageBackingGLCommon::InitializeGLTexture(service_id, params); MakeTextureAndSetParameters(params.target, 0 /* service_id */,
params.framebuffer_attachment_angle,
IsPassthrough() ? &passthrough_texture_ : nullptr,
IsPassthrough() ? nullptr : &texture_);
gl::GLApi* api = gl::g_current_gl_context; gl::GLApi* api = gl::g_current_gl_context;
ScopedRestoreTexture scoped_restore(api, params.target); ScopedRestoreTexture scoped_restore(api, params.target);
...@@ -1137,11 +1155,19 @@ bool SharedImageBackingGLImage::InitializeGLTexture( ...@@ -1137,11 +1155,19 @@ bool SharedImageBackingGLImage::InitializeGLTexture(
} }
if (IsPassthrough()) { if (IsPassthrough()) {
passthrough_texture_->SetEstimatedSize(EstimatedSize(format(), size()));
passthrough_texture_->SetLevelImage(params.target, 0, image_.get()); passthrough_texture_->SetLevelImage(params.target, 0, image_.get());
passthrough_texture_->set_is_bind_pending(image_state == passthrough_texture_->set_is_bind_pending(image_state ==
gles2::Texture::UNBOUND); gles2::Texture::UNBOUND);
} else { } else {
texture_->SetLevelInfo(params.target, 0, params.internal_format,
size().width(), size().height(), 1, 0, params.format,
params.type,
params.is_cleared ? gfx::Rect(size()) : gfx::Rect());
texture_->SetLevelImage(params.target, 0, image_.get(), image_state); texture_->SetLevelImage(params.target, 0, image_.get(), image_state);
if (params.swizzle)
texture_->SetCompatibilitySwizzle(params.swizzle);
texture_->SetImmutable(true, false /* has_immutable_storage */);
} }
return true; return true;
} }
...@@ -1274,15 +1300,12 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -1274,15 +1300,12 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
SHARED_IMAGE_USAGE_GLES2_FRAMEBUFFER_HINT)) != 0; SHARED_IMAGE_USAGE_GLES2_FRAMEBUFFER_HINT)) != 0;
scoped_refptr<gl::GLImage> image; scoped_refptr<gl::GLImage> image;
std::unique_ptr<SharedImageBackingGLCommon> result;
// TODO(piman): We pretend the texture was created in an ES2 context, so that // TODO(piman): We pretend the texture was created in an ES2 context, so that
// it can be used in other ES2 contexts, and so we have to pass gl_format as // it can be used in other ES2 contexts, and so we have to pass gl_format as
// the internal format in the LevelInfo. https://crbug.com/628064 // the internal format in the LevelInfo. https://crbug.com/628064
GLuint level_info_internal_format = format_info.gl_format; GLuint level_info_internal_format = format_info.gl_format;
bool is_cleared = false; bool is_cleared = false;
bool needs_subimage_upload = false;
bool has_immutable_storage = false;
if (use_buffer) { if (use_buffer) {
image = image_factory_->CreateAnonymousImage( image = image_factory_->CreateAnonymousImage(
size, format_info.buffer_format, gfx::BufferUsage::SCANOUT, size, format_info.buffer_format, gfx::BufferUsage::SCANOUT,
...@@ -1304,16 +1327,6 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -1304,16 +1327,6 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
level_info_internal_format = image->GetInternalFormat(); level_info_internal_format = image->GetInternalFormat();
if (color_space.IsValid()) if (color_space.IsValid())
image->SetColorSpace(color_space); image->SetColorSpace(color_space);
needs_subimage_upload = !pixel_data.empty();
}
if (image) {
result = std::make_unique<SharedImageBackingGLImage>(
image, mailbox, format, size, color_space, usage, attribs,
use_passthrough_);
} else {
result = std::make_unique<SharedImageBackingGLTexture>(
mailbox, format, size, color_space, usage, use_passthrough_);
} }
SharedImageBackingGLCommon::InitializeGLTextureParams params; SharedImageBackingGLCommon::InitializeGLTextureParams params;
...@@ -1323,14 +1336,26 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -1323,14 +1336,26 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
params.type = format_info.gl_type; params.type = format_info.gl_type;
params.swizzle = format_info.swizzle; params.swizzle = format_info.swizzle;
params.is_cleared = pixel_data.empty() ? is_cleared : true; params.is_cleared = pixel_data.empty() ? is_cleared : true;
params.has_immutable_storage = has_immutable_storage; params.has_immutable_storage = !image && format_info.supports_storage;
params.framebuffer_attachment_angle = params.framebuffer_attachment_angle =
for_framebuffer_attachment && texture_usage_angle_; for_framebuffer_attachment && texture_usage_angle_;
if (!result->InitializeGLTexture(0, params))
if (image) {
auto result = std::make_unique<SharedImageBackingGLImage>(
image, mailbox, format, size, color_space, usage, attribs,
use_passthrough_);
if (!result->InitializeGLTexture(params))
return nullptr; return nullptr;
if (!pixel_data.empty()) {
result->InitializePixels(format_info.adjusted_format, format_info.gl_type,
pixel_data.data());
}
return std::move(result);
} else {
auto result = std::make_unique<SharedImageBackingGLTexture>(
mailbox, format, size, color_space, usage, use_passthrough_);
result->InitializeGLTexture(0, params);
// Allocate texture storage for non-GLImage-backed textures.
if (!image) {
gl::GLApi* api = gl::g_current_gl_context; gl::GLApi* api = gl::g_current_gl_context;
ScopedRestoreTexture scoped_restore(api, target); ScopedRestoreTexture scoped_restore(api, target);
api->glBindTextureFn(target, result->GetGLServiceId()); api->glBindTextureFn(target, result->GetGLServiceId());
...@@ -1338,8 +1363,14 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -1338,8 +1363,14 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
if (format_info.supports_storage) { if (format_info.supports_storage) {
api->glTexStorage2DEXTFn(target, 1, format_info.storage_internal_format, api->glTexStorage2DEXTFn(target, 1, format_info.storage_internal_format,
size.width(), size.height()); size.width(), size.height());
has_immutable_storage = true;
needs_subimage_upload = !pixel_data.empty(); if (!pixel_data.empty()) {
ScopedResetAndRestoreUnpackState scoped_unpack_state(
api, attribs, true /* uploading_data */);
api->glTexSubImage2DFn(target, 0, 0, 0, size.width(), size.height(),
format_info.adjusted_format, format_info.gl_type,
pixel_data.data());
}
} else if (format_info.is_compressed) { } else if (format_info.is_compressed) {
ScopedResetAndRestoreUnpackState scoped_unpack_state(api, attribs, ScopedResetAndRestoreUnpackState scoped_unpack_state(api, attribs,
!pixel_data.empty()); !pixel_data.empty());
...@@ -1354,22 +1385,21 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -1354,22 +1385,21 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
format_info.adjusted_format, format_info.gl_type, format_info.adjusted_format, format_info.gl_type,
pixel_data.data()); pixel_data.data());
} }
return std::move(result);
} }
}
// If we are using a buffer or TexStorage API but have data to upload, do so void SharedImageBackingGLImage::InitializePixels(GLenum format,
// now via TexSubImage2D. GLenum type,
if (needs_subimage_upload) { const uint8_t* data) {
const GLenum target = GetGLTarget();
gl::GLApi* api = gl::g_current_gl_context; gl::GLApi* api = gl::g_current_gl_context;
ScopedRestoreTexture scoped_restore(api, target); ScopedRestoreTexture scoped_restore(api, target);
api->glBindTextureFn(target, result->GetGLServiceId()); api->glBindTextureFn(target, GetGLServiceId());
ScopedResetAndRestoreUnpackState scoped_unpack_state(api, attribs, ScopedResetAndRestoreUnpackState scoped_unpack_state(
!pixel_data.empty()); api, attribs_, true /* uploading_data */);
api->glTexSubImage2DFn(target, 0, 0, 0, size.width(), size.height(), api->glTexSubImage2DFn(target, 0, 0, 0, size().width(), size().height(),
format_info.adjusted_format, format_info.gl_type, format, type, data);
pixel_data.data());
}
return std::move(result);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
......
...@@ -79,14 +79,10 @@ class SharedImageBackingGLCommon : public SharedImageBacking { ...@@ -79,14 +79,10 @@ class SharedImageBackingGLCommon : public SharedImageBacking {
bool framebuffer_attachment_angle = false; bool framebuffer_attachment_angle = false;
bool has_immutable_storage = false; bool has_immutable_storage = false;
}; };
virtual bool InitializeGLTexture(GLuint service_id,
const InitializeGLTextureParams& params);
GLenum GetGLTarget() const; GLenum GetGLTarget() const;
GLuint GetGLServiceId() const; GLuint GetGLServiceId() const;
virtual void BeginSkiaReadAccess() = 0;
protected: protected:
// SharedImageBacking: // SharedImageBacking:
gfx::Rect ClearedRect() const final; gfx::Rect ClearedRect() const final;
...@@ -98,10 +94,6 @@ class SharedImageBackingGLCommon : public SharedImageBacking { ...@@ -98,10 +94,6 @@ class SharedImageBackingGLCommon : public SharedImageBacking {
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough> std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
ProduceGLTexturePassthrough(SharedImageManager* manager, ProduceGLTexturePassthrough(SharedImageManager* manager,
MemoryTypeTracker* tracker) final; MemoryTypeTracker* tracker) final;
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) final;
std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn( std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn(
SharedImageManager* manager, SharedImageManager* manager,
MemoryTypeTracker* tracker, MemoryTypeTracker* tracker,
...@@ -109,6 +101,14 @@ class SharedImageBackingGLCommon : public SharedImageBacking { ...@@ -109,6 +101,14 @@ class SharedImageBackingGLCommon : public SharedImageBacking {
bool IsPassthrough() const { return is_passthrough_; } bool IsPassthrough() const { return is_passthrough_; }
// Helper function to create a GL texture.
static void MakeTextureAndSetParameters(
GLenum target,
GLuint service_id,
bool framebuffer_attachment_angle,
scoped_refptr<gles2::TexturePassthrough>* passthrough_texture,
gles2::Texture** texture);
const bool is_passthrough_; const bool is_passthrough_;
gles2::Texture* texture_ = nullptr; gles2::Texture* texture_ = nullptr;
scoped_refptr<gles2::TexturePassthrough> passthrough_texture_; scoped_refptr<gles2::TexturePassthrough> passthrough_texture_;
...@@ -121,15 +121,14 @@ class SharedImageRepresentationSkiaImpl : public SharedImageRepresentationSkia { ...@@ -121,15 +121,14 @@ class SharedImageRepresentationSkiaImpl : public SharedImageRepresentationSkia {
public: public:
SharedImageRepresentationSkiaImpl( SharedImageRepresentationSkiaImpl(
SharedImageManager* manager, SharedImageManager* manager,
SharedImageBackingGLCommon* backing, SharedImageBacking* backing,
scoped_refptr<SharedContextState> context_state, scoped_refptr<SharedContextState> context_state,
sk_sp<SkPromiseImageTexture> cached_promise_texture, sk_sp<SkPromiseImageTexture> promise_texture,
MemoryTypeTracker* tracker, MemoryTypeTracker* tracker);
GLenum target,
GLuint service_id);
~SharedImageRepresentationSkiaImpl() override; ~SharedImageRepresentationSkiaImpl() override;
sk_sp<SkPromiseImageTexture> promise_texture(); void SetBeginReadAccessCallback(
base::RepeatingClosure begin_read_access_callback);
private: private:
// SharedImageRepresentationSkia: // SharedImageRepresentationSkia:
...@@ -147,6 +146,7 @@ class SharedImageRepresentationSkiaImpl : public SharedImageRepresentationSkia { ...@@ -147,6 +146,7 @@ class SharedImageRepresentationSkiaImpl : public SharedImageRepresentationSkia {
void CheckContext(); void CheckContext();
base::RepeatingClosure begin_read_access_callback_;
scoped_refptr<SharedContextState> context_state_; scoped_refptr<SharedContextState> context_state_;
sk_sp<SkPromiseImageTexture> promise_texture_; sk_sp<SkPromiseImageTexture> promise_texture_;
...@@ -171,6 +171,9 @@ class SharedImageBackingGLTexture : public SharedImageBackingGLCommon { ...@@ -171,6 +171,9 @@ class SharedImageBackingGLTexture : public SharedImageBackingGLCommon {
delete; delete;
~SharedImageBackingGLTexture() override; ~SharedImageBackingGLTexture() override;
void InitializeGLTexture(GLuint service_id,
const InitializeGLTextureParams& params);
private: private:
// SharedImageBacking: // SharedImageBacking:
void Update(std::unique_ptr<gfx::GpuFence> in_fence) override; void Update(std::unique_ptr<gfx::GpuFence> in_fence) override;
...@@ -178,9 +181,10 @@ class SharedImageBackingGLTexture : public SharedImageBackingGLCommon { ...@@ -178,9 +181,10 @@ class SharedImageBackingGLTexture : public SharedImageBackingGLCommon {
base::trace_event::MemoryAllocatorDump* dump, base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd, base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) override; uint64_t client_tracing_id) override;
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
// SharedImageBackingGLCommon: SharedImageManager* manager,
void BeginSkiaReadAccess() override; MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) override;
}; };
// Implementation of SharedImageBacking that creates a GL Texture that is backed // Implementation of SharedImageBacking that creates a GL Texture that is backed
...@@ -202,9 +206,8 @@ class SharedImageBackingGLImage : public SharedImageBackingGLCommon { ...@@ -202,9 +206,8 @@ class SharedImageBackingGLImage : public SharedImageBackingGLCommon {
delete; delete;
~SharedImageBackingGLImage() override; ~SharedImageBackingGLImage() override;
// SharedImageBackingGLCommon: bool InitializeGLTexture(const InitializeGLTextureParams& params);
bool InitializeGLTexture(GLuint service_id, void InitializePixels(GLenum format, GLenum type, const uint8_t* data);
const InitializeGLTextureParams& params) override;
private: private:
// SharedImageBacking: // SharedImageBacking:
...@@ -214,17 +217,22 @@ class SharedImageBackingGLImage : public SharedImageBackingGLCommon { ...@@ -214,17 +217,22 @@ class SharedImageBackingGLImage : public SharedImageBackingGLCommon {
base::trace_event::ProcessMemoryDump* pmd, base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) override; uint64_t client_tracing_id) override;
scoped_refptr<gfx::NativePixmap> GetNativePixmap() override; scoped_refptr<gfx::NativePixmap> GetNativePixmap() override;
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) override;
std::unique_ptr<SharedImageRepresentationGLTexture> std::unique_ptr<SharedImageRepresentationGLTexture>
ProduceRGBEmulationGLTexture(SharedImageManager* manager, ProduceRGBEmulationGLTexture(SharedImageManager* manager,
MemoryTypeTracker* tracker) override; MemoryTypeTracker* tracker) override;
// SharedImageBackingGLCommon: void BeginSkiaReadAccess();
void BeginSkiaReadAccess() override;
scoped_refptr<gl::GLImage> image_; scoped_refptr<gl::GLImage> image_;
gles2::Texture* rgb_emulation_texture_ = nullptr; gles2::Texture* rgb_emulation_texture_ = nullptr;
const SharedImageBackingFactoryGLTexture::UnpackStateAttribs attribs_; const SharedImageBackingFactoryGLTexture::UnpackStateAttribs attribs_;
scoped_refptr<gfx::NativePixmap> native_pixmap_; scoped_refptr<gfx::NativePixmap> native_pixmap_;
base::WeakPtrFactory<SharedImageBackingGLImage> weak_factory_;
}; };
} // namespace gpu } // namespace gpu
......
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