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

SharedImageBackingFactoryGLTexture: Fix compatibility swizzle

Textures that are uploaded as GL_LUMINANCE_ALPHA, GL_LUMINANCE, or
GL_ALPHA, are, on some platforms, emulated using glTexParameteri with
GL_TEXTURE_SWIZZLE_R/G/B.

The call to glTexParameteri needs to be done after the glTexImage2D call
that uploads the pixel data. Do this.

Remove swizzle from the common parameters because GLImages don't support
the formats that require swizzles. Add a DCHECK in case we're trying to
do that anyway.

Bug: 1096361
Change-Id: I0b58a7ccb803108d0b3b0c43a68a6709d869aea8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2276578Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784234}
parent 2a267ddc
...@@ -621,12 +621,16 @@ void SharedImageBackingGLTexture::InitializeGLTexture( ...@@ -621,12 +621,16 @@ void SharedImageBackingGLTexture::InitializeGLTexture(
size().width(), size().height(), 1, 0, params.format, size().width(), size().height(), 1, 0, params.format,
params.type, params.type,
params.is_cleared ? gfx::Rect(size()) : gfx::Rect()); params.is_cleared ? gfx::Rect(size()) : gfx::Rect());
if (params.swizzle)
texture_->SetCompatibilitySwizzle(params.swizzle);
texture_->SetImmutable(true, params.has_immutable_storage); texture_->SetImmutable(true, params.has_immutable_storage);
} }
} }
void SharedImageBackingGLTexture::SetCompatibilitySwizzle(
const gles2::Texture::CompatibilitySwizzle* swizzle) {
if (!IsPassthrough())
texture_->SetCompatibilitySwizzle(swizzle);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// SharedImageBackingGLImage // SharedImageBackingGLImage
...@@ -910,8 +914,6 @@ bool SharedImageBackingGLImage::InitializeGLTexture() { ...@@ -910,8 +914,6 @@ bool SharedImageBackingGLImage::InitializeGLTexture() {
gl_params_.is_cleared ? gfx::Rect(size()) : gfx::Rect()); gl_params_.is_cleared ? gfx::Rect(size()) : gfx::Rect());
texture_->SetLevelImage(gl_params_.target, 0, image_.get(), texture_->SetLevelImage(gl_params_.target, 0, image_.get(),
gles2::Texture::UNBOUND); gles2::Texture::UNBOUND);
if (gl_params_.swizzle)
texture_->SetCompatibilitySwizzle(gl_params_.swizzle);
texture_->SetImmutable(true, false /* has_immutable_storage */); texture_->SetImmutable(true, false /* has_immutable_storage */);
} }
...@@ -1445,13 +1447,13 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -1445,13 +1447,13 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
params.internal_format = level_info_internal_format; params.internal_format = level_info_internal_format;
params.format = format_info.gl_format; params.format = format_info.gl_format;
params.type = format_info.gl_type; params.type = format_info.gl_type;
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 = !image && format_info.supports_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 (image) { if (image) {
DCHECK(!format_info.swizzle);
auto result = std::make_unique<SharedImageBackingGLImage>( auto result = std::make_unique<SharedImageBackingGLImage>(
image, mailbox, format, size, color_space, usage, params, attribs, image, mailbox, format, size, color_space, usage, params, attribs,
use_passthrough_); use_passthrough_);
...@@ -1496,6 +1498,7 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -1496,6 +1498,7 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
format_info.adjusted_format, format_info.gl_type, format_info.adjusted_format, format_info.gl_type,
pixel_data.data()); pixel_data.data());
} }
result->SetCompatibilitySwizzle(format_info.swizzle);
return std::move(result); return std::move(result);
} }
} }
......
...@@ -77,7 +77,6 @@ class SharedImageBackingGLCommon : public SharedImageBacking { ...@@ -77,7 +77,6 @@ class SharedImageBackingGLCommon : public SharedImageBacking {
GLenum internal_format = 0; GLenum internal_format = 0;
GLenum format = 0; GLenum format = 0;
GLenum type = 0; GLenum type = 0;
const gles2::Texture::CompatibilitySwizzle* swizzle = nullptr;
bool is_cleared = false; bool is_cleared = false;
bool is_rgb_emulation = false; bool is_rgb_emulation = false;
bool framebuffer_attachment_angle = false; bool framebuffer_attachment_angle = false;
...@@ -157,6 +156,8 @@ class SharedImageBackingGLTexture : public SharedImageBacking { ...@@ -157,6 +156,8 @@ class SharedImageBackingGLTexture : public SharedImageBacking {
void InitializeGLTexture( void InitializeGLTexture(
GLuint service_id, GLuint service_id,
const SharedImageBackingGLCommon::InitializeGLTextureParams& params); const SharedImageBackingGLCommon::InitializeGLTextureParams& params);
void SetCompatibilitySwizzle(
const gles2::Texture::CompatibilitySwizzle* swizzle);
GLenum GetGLTarget() const; GLenum GetGLTarget() const;
GLuint GetGLServiceId() const; GLuint GetGLServiceId() const;
......
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