Commit 00689191 by Geoff Lang Committed by Commit Bot

GL: Fix the CPU readback path of CopyTextureCHROMIUM.

1. BlitGL's resources were not being intialized. 2. The format/type information was not enough to know if the destination texture was SRGB. BUG=693090 Change-Id: I3fc277a175772d3b6acace1810cb43f4a9bdc473 Reviewed-on: https://chromium-review.googlesource.com/982642Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 6ce24cf2
...@@ -633,9 +633,17 @@ gl::Error BlitGL::copySubTextureCPUReadback(const gl::Context *context, ...@@ -633,9 +633,17 @@ gl::Error BlitGL::copySubTextureCPUReadback(const gl::Context *context,
bool unpackPremultiplyAlpha, bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha) bool unpackUnmultiplyAlpha)
{ {
ANGLE_TRY(initializeResources());
ASSERT(source->getType() == gl::TextureType::_2D); ASSERT(source->getType() == gl::TextureType::_2D);
const auto &destInternalFormatInfo = gl::GetInternalFormatInfo(destFormat, destType); const auto &destInternalFormatInfo = gl::GetInternalFormatInfo(destFormat, destType);
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
source->getTextureID(), static_cast<GLint>(sourceLevel));
GLenum status = mFunctions->checkFramebufferStatus(GL_FRAMEBUFFER);
ASSERT(status == GL_FRAMEBUFFER_COMPLETE);
// Create a buffer for holding the source and destination memory // Create a buffer for holding the source and destination memory
const size_t sourcePixelSize = 4; const size_t sourcePixelSize = 4;
size_t sourceBufferSize = sourceArea.width * sourceArea.height * sourcePixelSize; size_t sourceBufferSize = sourceArea.width * sourceArea.height * sourcePixelSize;
...@@ -646,9 +654,6 @@ gl::Error BlitGL::copySubTextureCPUReadback(const gl::Context *context, ...@@ -646,9 +654,6 @@ gl::Error BlitGL::copySubTextureCPUReadback(const gl::Context *context,
uint8_t *sourceMemory = buffer->data(); uint8_t *sourceMemory = buffer->data();
uint8_t *destMemory = buffer->data() + sourceBufferSize; uint8_t *destMemory = buffer->data() + sourceBufferSize;
mStateManager->bindFramebuffer(GL_FRAMEBUFFER, mScratchFBO);
mFunctions->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
source->getTextureID(), static_cast<GLint>(sourceLevel));
GLenum readPixelsFormat = GL_NONE; GLenum readPixelsFormat = GL_NONE;
ColorReadFunction readFunction = nullptr; ColorReadFunction readFunction = nullptr;
...@@ -689,6 +694,7 @@ gl::Error BlitGL::copySubTextureCPUReadback(const gl::Context *context, ...@@ -689,6 +694,7 @@ gl::Error BlitGL::copySubTextureCPUReadback(const gl::Context *context,
nativegl::TexSubImageFormat texSubImageFormat = nativegl::TexSubImageFormat texSubImageFormat =
nativegl::GetTexSubImageFormat(mFunctions, mWorkarounds, destFormat, destType); nativegl::GetTexSubImageFormat(mFunctions, mWorkarounds, destFormat, destType);
mStateManager->bindTexture(dest->getType(), dest->getTextureID());
mFunctions->texSubImage2D(ToGLenum(destTarget), static_cast<GLint>(destLevel), destOffset.x, mFunctions->texSubImage2D(ToGLenum(destTarget), static_cast<GLint>(destLevel), destOffset.x,
destOffset.y, sourceArea.width, sourceArea.height, destOffset.y, sourceArea.width, sourceArea.height,
texSubImageFormat.format, texSubImageFormat.type, destMemory); texSubImageFormat.format, texSubImageFormat.type, destMemory);
......
...@@ -722,9 +722,10 @@ gl::Error TextureGL::copyTexture(const gl::Context *context, ...@@ -722,9 +722,10 @@ gl::Error TextureGL::copyTexture(const gl::Context *context,
reserveTexImageToBeFilled(target, level, internalFormat, sourceImageDesc.size, reserveTexImageToBeFilled(target, level, internalFormat, sourceImageDesc.size,
gl::GetUnsizedFormat(internalFormat), type); gl::GetUnsizedFormat(internalFormat), type);
const gl::InternalFormat &destFormatInfo = gl::GetInternalFormatInfo(internalFormat, type);
return copySubTextureHelper(context, target, level, gl::Offset(0, 0, 0), sourceLevel, return copySubTextureHelper(context, target, level, gl::Offset(0, 0, 0), sourceLevel,
sourceArea, gl::GetUnsizedFormat(internalFormat), type, unpackFlipY, sourceArea, destFormatInfo, unpackFlipY, unpackPremultiplyAlpha,
unpackPremultiplyAlpha, unpackUnmultiplyAlpha, source); unpackUnmultiplyAlpha, source);
} }
gl::Error TextureGL::copySubTexture(const gl::Context *context, gl::Error TextureGL::copySubTexture(const gl::Context *context,
...@@ -741,8 +742,8 @@ gl::Error TextureGL::copySubTexture(const gl::Context *context, ...@@ -741,8 +742,8 @@ gl::Error TextureGL::copySubTexture(const gl::Context *context,
size_t level = static_cast<size_t>(index.getLevelIndex()); size_t level = static_cast<size_t>(index.getLevelIndex());
const gl::InternalFormat &destFormatInfo = *mState.getImageDesc(target, level).format.info; const gl::InternalFormat &destFormatInfo = *mState.getImageDesc(target, level).format.info;
return copySubTextureHelper(context, target, level, destOffset, sourceLevel, sourceArea, return copySubTextureHelper(context, target, level, destOffset, sourceLevel, sourceArea,
destFormatInfo.format, destFormatInfo.type, unpackFlipY, destFormatInfo, unpackFlipY, unpackPremultiplyAlpha,
unpackPremultiplyAlpha, unpackUnmultiplyAlpha, source); unpackUnmultiplyAlpha, source);
} }
gl::Error TextureGL::copySubTextureHelper(const gl::Context *context, gl::Error TextureGL::copySubTextureHelper(const gl::Context *context,
...@@ -751,8 +752,7 @@ gl::Error TextureGL::copySubTextureHelper(const gl::Context *context, ...@@ -751,8 +752,7 @@ gl::Error TextureGL::copySubTextureHelper(const gl::Context *context,
const gl::Offset &destOffset, const gl::Offset &destOffset,
size_t sourceLevel, size_t sourceLevel,
const gl::Rectangle &sourceArea, const gl::Rectangle &sourceArea,
GLenum destFormat, const gl::InternalFormat &destFormat,
GLenum destType,
bool unpackFlipY, bool unpackFlipY,
bool unpackPremultiplyAlpha, bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha, bool unpackUnmultiplyAlpha,
...@@ -770,13 +770,12 @@ gl::Error TextureGL::copySubTextureHelper(const gl::Context *context, ...@@ -770,13 +770,12 @@ gl::Error TextureGL::copySubTextureHelper(const gl::Context *context,
GLenum sourceFormat = sourceImageDesc.format.info->format; GLenum sourceFormat = sourceImageDesc.format.info->format;
bool sourceFormatContainSupersetOfDestFormat = bool sourceFormatContainSupersetOfDestFormat =
(sourceFormat == destFormat && sourceFormat != GL_BGRA_EXT) || (sourceFormat == destFormat.format && sourceFormat != GL_BGRA_EXT) ||
(sourceFormat == GL_RGBA && destFormat == GL_RGB); (sourceFormat == GL_RGBA && destFormat.format == GL_RGB);
GLenum sourceComponentType = sourceImageDesc.format.info->componentType; GLenum sourceComponentType = sourceImageDesc.format.info->componentType;
const auto &destInternalFormatInfo = gl::GetInternalFormatInfo(destFormat, destType); GLenum destComponentType = destFormat.componentType;
GLenum destComponentType = destInternalFormatInfo.componentType; bool destSRGB = destFormat.colorEncoding == GL_SRGB;
bool destSRGB = destInternalFormatInfo.colorEncoding == GL_SRGB;
if (!unpackFlipY && unpackPremultiplyAlpha == unpackUnmultiplyAlpha && !needsLumaWorkaround && if (!unpackFlipY && unpackPremultiplyAlpha == unpackUnmultiplyAlpha && !needsLumaWorkaround &&
sourceFormatContainSupersetOfDestFormat && sourceComponentType == destComponentType && sourceFormatContainSupersetOfDestFormat && sourceComponentType == destComponentType &&
!destSRGB) !destSRGB)
...@@ -811,8 +810,8 @@ gl::Error TextureGL::copySubTextureHelper(const gl::Context *context, ...@@ -811,8 +810,8 @@ gl::Error TextureGL::copySubTextureHelper(const gl::Context *context,
// Fall back to CPU-readback // Fall back to CPU-readback
return mBlitter->copySubTextureCPUReadback(context, sourceGL, sourceLevel, sourceComponentType, return mBlitter->copySubTextureCPUReadback(context, sourceGL, sourceLevel, sourceComponentType,
this, target, level, destFormat, destType, this, target, level, destFormat.format,
sourceArea, destOffset, unpackFlipY, destFormat.type, sourceArea, destOffset, unpackFlipY,
unpackPremultiplyAlpha, unpackUnmultiplyAlpha); unpackPremultiplyAlpha, unpackUnmultiplyAlpha);
} }
......
...@@ -129,8 +129,7 @@ class TextureGL : public TextureImpl ...@@ -129,8 +129,7 @@ class TextureGL : public TextureImpl
const gl::Offset &destOffset, const gl::Offset &destOffset,
size_t sourceLevel, size_t sourceLevel,
const gl::Rectangle &sourceArea, const gl::Rectangle &sourceArea,
GLenum destFormat, const gl::InternalFormat &destFormat,
GLenum destType,
bool unpackFlipY, bool unpackFlipY,
bool unpackPremultiplyAlpha, bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha, bool unpackUnmultiplyAlpha,
......
...@@ -1288,6 +1288,29 @@ TEST_P(CopyTextureTestES3, ES3UnormFormats) ...@@ -1288,6 +1288,29 @@ TEST_P(CopyTextureTestES3, ES3UnormFormats)
testOutput(destTexture, expectedColor); testOutput(destTexture, expectedColor);
}; };
auto testSubCopyCombination = [this, testOutput](
GLenum sourceInternalFormat, GLenum sourceFormat,
GLenum sourceType, const GLColor &sourceColor,
GLenum destInternalFormat, GLenum destFormat, GLenum destType,
bool flipY, bool premultiplyAlpha, bool unmultiplyAlpha,
const GLColor &expectedColor) {
GLTexture sourceTexture;
glBindTexture(GL_TEXTURE_2D, sourceTexture);
glTexImage2D(GL_TEXTURE_2D, 0, sourceInternalFormat, 1, 1, 0, sourceFormat, sourceType,
&sourceColor);
GLTexture destTexture;
glBindTexture(GL_TEXTURE_2D, destTexture);
glTexImage2D(GL_TEXTURE_2D, 0, destInternalFormat, 1, 1, 0, destFormat, destType, nullptr);
glCopySubTextureCHROMIUM(sourceTexture, 0, GL_TEXTURE_2D, destTexture, 0, 0, 0, 0, 0, 1, 1,
flipY, premultiplyAlpha, unmultiplyAlpha);
ASSERT_GL_NO_ERROR();
testOutput(destTexture, expectedColor);
};
// New LUMA source formats // New LUMA source formats
testCopyCombination(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, GLColor(128, 0, 0, 0), GL_RGB, testCopyCombination(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, GLColor(128, 0, 0, 0), GL_RGB,
GL_UNSIGNED_BYTE, false, false, false, GLColor(128, 128, 128, 255)); GL_UNSIGNED_BYTE, false, false, false, GLColor(128, 128, 128, 255));
...@@ -1315,6 +1338,14 @@ TEST_P(CopyTextureTestES3, ES3UnormFormats) ...@@ -1315,6 +1338,14 @@ TEST_P(CopyTextureTestES3, ES3UnormFormats)
testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), testCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128),
GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, false, false, false, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, false, false, false,
GLColor(55, 13, 4, 128)); GLColor(55, 13, 4, 128));
testSubCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_SRGB,
GL_SRGB, GL_UNSIGNED_BYTE, false, false, false, GLColor(55, 13, 4, 255));
testSubCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128), GL_SRGB,
GL_SRGB, GL_UNSIGNED_BYTE, false, true, false, GLColor(13, 4, 1, 255));
testSubCopyCombination(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GLColor(128, 64, 32, 128),
GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, false, false,
false, GLColor(55, 13, 4, 128));
} }
// Test the newly added ES3 float formats // Test the newly added ES3 float formats
......
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