Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1555)

Unified Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 2702403005: debug-depth-video-with-copy-texture (Closed)
Patch Set: update cts expectations Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
diff --git a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
index 0960615b9382ddd8515f3daff969a8b748bc5cfc..bd63600b99cbafba9750e686f9a3207b343243e0 100644
--- a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
+++ b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
@@ -818,9 +818,13 @@ sk_sp<SkImage> WebGLRenderingContextBase::makeImageSnapshot(
surface->getTextureHandle(
SkSurface::kDiscardWrite_TextureHandleAccess))
->fID;
+ GLenum textureTarget = skia::GrBackendObjectToGrGLTextureInfo(
+ surface->getTextureHandle(
+ SkSurface::kDiscardWrite_TextureHandleAccess))
+ ->fTarget;
drawingBuffer()->copyToPlatformTexture(
- gl, textureId, GL_RGBA, GL_UNSIGNED_BYTE, 0, true, false, IntPoint(0, 0),
+ gl, textureTarget, textureId, true, false, IntPoint(0, 0),
IntRect(IntPoint(0, 0), drawingBuffer()->size()), BackBuffer);
return surface->makeImageSnapshot();
}
@@ -984,64 +988,6 @@ static const GLenum kSupportedTypesTexImageSourceES3[] = {
GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_INT_10F_11F_11F_REV,
};
-bool isUnsignedIntegerFormat(GLenum internalformat) {
- switch (internalformat) {
- case GL_R8UI:
- case GL_R16UI:
- case GL_R32UI:
- case GL_RG8UI:
- case GL_RG16UI:
- case GL_RG32UI:
- case GL_RGB8UI:
- case GL_RGB16UI:
- case GL_RGB32UI:
- case GL_RGBA8UI:
- case GL_RGB10_A2UI:
- case GL_RGBA16UI:
- case GL_RGBA32UI:
- return true;
- default:
- return false;
- }
-}
-
-bool isSignedIntegerFormat(GLenum internalformat) {
- switch (internalformat) {
- case GL_R8I:
- case GL_R16I:
- case GL_R32I:
- case GL_RG8I:
- case GL_RG16I:
- case GL_RG32I:
- case GL_RGB8I:
- case GL_RGB16I:
- case GL_RGB32I:
- case GL_RGBA8I:
- case GL_RGBA16I:
- case GL_RGBA32I:
- return true;
- default:
- return false;
- }
-}
-
-bool isIntegerFormat(GLenum internalformat) {
- return (isUnsignedIntegerFormat(internalformat) ||
- isSignedIntegerFormat(internalformat));
-}
-
-bool isFloatType(GLenum type) {
- switch (type) {
- case GL_FLOAT:
- case GL_HALF_FLOAT:
- case GL_HALF_FLOAT_OES:
- case GL_UNSIGNED_INT_10F_11F_11F_REV:
- return true;
- default:
- return false;
- }
-}
-
bool isSRGBFormat(GLenum internalformat) {
switch (internalformat) {
case GL_SRGB_EXT:
@@ -4953,17 +4899,26 @@ bool WebGLRenderingContextBase::canUseTexImageByGPU(
TexImageFunctionID functionID,
GLint internalformat,
GLenum type) {
- if (functionID == TexImage2D &&
- (isFloatType(type) || isIntegerFormat(internalformat) ||
- isSRGBFormat(internalformat)))
+ if (isSRGBFormat(internalformat))
+ return false;
+#if OS(MACOSX)
+ // RGB5_A1 is not color-renderable on NVIDIA Mac, see crbug.com/676209.
+ if (type == GL_UNSIGNED_SHORT_5_5_5_1)
return false;
- // TODO(crbug.com/622958): Implement GPU-to-GPU path for WebGL 2 and more
- // internal formats.
- if (functionID == TexSubImage2D &&
- (isWebGL2OrHigher() || extensionEnabled(OESTextureFloatName) ||
- extensionEnabled(OESTextureHalfFloatName) ||
- extensionEnabled(EXTsRGBName)))
+#endif
+ // OES_texture_half_float doesn't support HALF_FLOAT_OES type for
+ // CopyTexImage/CopyTexSubImage. And OES_texture_half_float doesn't require
+ // HALF_FLOAT_OES type texture to be renderable. So, HALF_FLOAT_OES type
+ // texture cannot be copied to or drawn to by glCopyTextureCHROMIUM.
+ if (type == GL_HALF_FLOAT_OES)
return false;
+ // SRGB format has color-space conversion issue, see
+ // https://github.com/KhronosGroup/WebGL/issues/2165. Before we can detect
+ // internalformat in TexSubImage2D, we disable GPU path if the context is
+ // WebGL 2.0 or EXT_sRGB extension is enabled.
+ if (functionID == TexSubImage2D && extensionEnabled(EXTsRGBName))
+ return false;
+
return true;
}
@@ -4986,10 +4941,8 @@ SnapshotReason WebGLRenderingContextBase::functionIDToSnapshotReason(
void WebGLRenderingContextBase::texImageCanvasByGPU(
TexImageFunctionID functionID,
HTMLCanvasElement* canvas,
+ GLenum target,
GLuint targetTexture,
- GLenum targetInternalformat,
- GLenum targetType,
- GLint targetLevel,
GLint xoffset,
GLint yoffset,
const IntRect& sourceSubRectangle) {
@@ -4997,10 +4950,9 @@ void WebGLRenderingContextBase::texImageCanvasByGPU(
ImageBuffer* buffer = canvas->buffer();
if (buffer &&
!buffer->copyToPlatformTexture(
- functionIDToSnapshotReason(functionID), contextGL(), targetTexture,
- targetInternalformat, targetType, targetLevel,
- m_unpackPremultiplyAlpha, m_unpackFlipY, IntPoint(xoffset, yoffset),
- sourceSubRectangle)) {
+ functionIDToSnapshotReason(functionID), contextGL(), target,
+ targetTexture, m_unpackPremultiplyAlpha, m_unpackFlipY,
+ IntPoint(xoffset, yoffset), sourceSubRectangle)) {
NOTREACHED();
}
} else {
@@ -5008,9 +4960,9 @@ void WebGLRenderingContextBase::texImageCanvasByGPU(
toWebGLRenderingContextBase(canvas->renderingContext());
ScopedTexture2DRestorer restorer(gl);
if (!gl->drawingBuffer()->copyToPlatformTexture(
- contextGL(), targetTexture, targetInternalformat, targetType,
- targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY,
- IntPoint(xoffset, yoffset), sourceSubRectangle, BackBuffer)) {
+ contextGL(), target, targetTexture, m_unpackPremultiplyAlpha,
+ !m_unpackFlipY, IntPoint(xoffset, yoffset), sourceSubRectangle,
+ BackBuffer)) {
NOTREACHED();
}
}
@@ -5021,8 +4973,6 @@ void WebGLRenderingContextBase::texImageByGPU(
WebGLTexture* texture,
GLenum target,
GLint level,
- GLint internalformat,
- GLenum type,
GLint xoffset,
GLint yoffset,
GLint zoffset,
@@ -5035,24 +4985,18 @@ void WebGLRenderingContextBase::texImageByGPU(
ScopedTexture2DRestorer restorer(this);
GLuint targetTexture = texture->object();
- GLenum targetType = type;
- GLenum targetInternalformat = internalformat;
- GLint targetLevel = level;
bool possibleDirectCopy = false;
- if (functionID == TexImage2D) {
- possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM(
- target, internalformat, type, level);
+ if (functionID == TexImage2D || functionID == TexSubImage2D) {
+ possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM(target);
}
GLint copyXOffset = xoffset;
GLint copyYOffset = yoffset;
+ GLenum copyTarget = target;
// if direct copy is not possible, create a temporary texture and then copy
// from canvas to temporary texture to target texture.
if (!possibleDirectCopy) {
- targetLevel = 0;
- targetInternalformat = GL_RGBA;
- targetType = GL_UNSIGNED_BYTE;
contextGL()->GenTextures(1, &targetTexture);
contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture);
contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
@@ -5063,21 +5007,21 @@ void WebGLRenderingContextBase::texImageByGPU(
GL_CLAMP_TO_EDGE);
contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
- contextGL()->TexImage2D(GL_TEXTURE_2D, 0, targetInternalformat, width,
- height, 0, GL_RGBA, targetType, 0);
+ contextGL()->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, 0);
copyXOffset = 0;
copyYOffset = 0;
+ copyTarget = GL_TEXTURE_2D;
}
if (image->isCanvasElement()) {
texImageCanvasByGPU(functionID, static_cast<HTMLCanvasElement*>(image),
- targetTexture, targetInternalformat, targetType,
- targetLevel, copyXOffset, copyYOffset,
+ copyTarget, targetTexture, copyXOffset, copyYOffset,
sourceSubRectangle);
} else {
- texImageBitmapByGPU(static_cast<ImageBitmap*>(image), targetTexture,
- targetInternalformat, targetType, targetLevel,
- !m_unpackFlipY);
+ texImageBitmapByGPU(static_cast<ImageBitmap*>(image), copyTarget,
+ targetTexture, !m_unpackFlipY, copyXOffset, copyYOffset,
+ sourceSubRectangle);
}
if (!possibleDirectCopy) {
@@ -5177,11 +5121,11 @@ void WebGLRenderingContextBase::texImageHelperHTMLCanvasElement(
if (functionID == TexImage2D) {
texImage2DBase(target, level, internalformat, sourceSubRectangle.width(),
sourceSubRectangle.height(), 0, format, type, 0);
- texImageByGPU(functionID, texture, target, level, internalformat, type, 0,
- 0, 0, canvas, adjustedSourceSubRectangle);
+ texImageByGPU(functionID, texture, target, level, 0, 0, 0, canvas,
+ adjustedSourceSubRectangle);
} else {
- texImageByGPU(functionID, texture, target, level, GL_RGBA, type, xoffset,
- yoffset, 0, canvas, adjustedSourceSubRectangle);
+ texImageByGPU(functionID, texture, target, level, xoffset, yoffset, 0,
+ canvas, adjustedSourceSubRectangle);
}
} else {
// 3D functions.
@@ -5263,9 +5207,14 @@ void WebGLRenderingContextBase::texImageHelperHTMLVideoElement(
sourceImageRect == sentinelEmptyRect() ||
sourceImageRect ==
IntRect(0, 0, video->videoWidth(), video->videoHeight());
+ // Format of source video may be 16-bit format, e.g. Y16 format.
+ // glCopyTextureCHROMIUM will cause precision lost when uploading such video
+ // texture to half float or float texture.
if (functionID == TexImage2D && sourceImageRectIsDefault && depth == 1 &&
- GL_TEXTURE_2D == target && Extensions3DUtil::canUseCopyTextureCHROMIUM(
- target, internalformat, type, level)) {
+ GL_TEXTURE_2D == target &&
+ canUseTexImageByGPU(functionID, internalformat, type) &&
+ (type != GL_FLOAT && type != GL_HALF_FLOAT &&
+ type != GL_UNSIGNED_INT_10F_11F_11F_REV)) {
DCHECK_EQ(xoffset, 0);
DCHECK_EQ(yoffset, 0);
DCHECK_EQ(zoffset, 0);
@@ -5307,9 +5256,9 @@ void WebGLRenderingContextBase::texImageHelperHTMLVideoElement(
// was handled in the paintCurrentFrameInContext() call.
if (imageBuffer->copyToPlatformTexture(
- functionIDToSnapshotReason(functionID), contextGL(),
- texture->object(), internalformat, type, level,
- m_unpackPremultiplyAlpha, m_unpackFlipY, IntPoint(0, 0),
+ functionIDToSnapshotReason(functionID), contextGL(), target,
+ texture->object(), m_unpackPremultiplyAlpha, m_unpackFlipY,
+ IntPoint(0, 0),
IntRect(0, 0, video->videoWidth(), video->videoHeight()))) {
return;
}
@@ -5341,15 +5290,17 @@ void WebGLRenderingContextBase::texImageHelperHTMLVideoElement(
unpackImageHeight);
}
-void WebGLRenderingContextBase::texImageBitmapByGPU(ImageBitmap* bitmap,
- GLuint targetTexture,
- GLenum targetInternalformat,
- GLenum targetType,
- GLint targetLevel,
- bool flipY) {
- bitmap->bitmapImage()->copyToTexture(drawingBuffer()->contextProvider(),
- targetTexture, targetInternalformat,
- targetType, flipY);
+void WebGLRenderingContextBase::texImageBitmapByGPU(
+ ImageBitmap* bitmap,
+ GLenum target,
+ GLuint targetTexture,
+ bool flipY,
+ GLint xoffset,
+ GLint yoffset,
+ const IntRect& sourceSubRectangle) {
+ bitmap->bitmapImage()->copyToTexture(
+ drawingBuffer()->contextProvider(), target, targetTexture, flipY,
+ IntPoint(xoffset, yoffset), sourceSubRectangle);
}
void WebGLRenderingContextBase::texImage2D(GLenum target,
@@ -5417,11 +5368,11 @@ void WebGLRenderingContextBase::texImageHelperImageBitmap(
if (functionID == TexImage2D) {
texImage2DBase(target, level, internalformat, width, height, 0, format,
type, 0);
- texImageByGPU(functionID, texture, target, level, internalformat, type, 0,
- 0, 0, bitmap, sourceSubRect);
+ texImageByGPU(functionID, texture, target, level, 0, 0, 0, bitmap,
+ sourceSubRect);
} else if (functionID == TexSubImage2D) {
- texImageByGPU(functionID, texture, target, level, GL_RGBA, type, xoffset,
- yoffset, 0, bitmap, sourceSubRect);
+ texImageByGPU(functionID, texture, target, level, xoffset, yoffset, 0,
+ bitmap, sourceSubRect);
}
return;
}

Powered by Google App Engine
This is Rietveld 408576698