Commit d3ed6532 authored by Kenneth Russell's avatar Kenneth Russell Committed by Commit Bot

Allow Uint8ClampedArray in readPixels and tex{Sub}Image.

Firefox already allows Uint8ClampedArray in the texImage entry points,
so this is a behavioral difference that needs to be clarified.

Tested with new WebGL conformance test in
https://github.com/KhronosGroup/WebGL/pull/2887 .

Bug: 961658
Change-Id: I5e2b1591b7994a3271ead7dda2ca0aebd9364526
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1606249Reviewed-by: default avatarKai Ninomiya <kainino@chromium.org>
Commit-Queue: Kenneth Russell <kbr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658811}
parent a693ecf4
...@@ -5501,11 +5501,16 @@ bool WebGL2RenderingContextBase::ValidateReadPixelsFormatAndType( ...@@ -5501,11 +5501,16 @@ bool WebGL2RenderingContextBase::ValidateReadPixelsFormatAndType(
switch (type) { switch (type) {
case GL_UNSIGNED_BYTE: case GL_UNSIGNED_BYTE:
if (buffer && buffer->GetType() != DOMArrayBufferView::kTypeUint8) { if (buffer) {
SynthesizeGLError( auto bufferType = buffer->GetType();
GL_INVALID_OPERATION, "readPixels", if (bufferType != DOMArrayBufferView::kTypeUint8 &&
"type UNSIGNED_BYTE but ArrayBufferView not Uint8Array"); bufferType != DOMArrayBufferView::kTypeUint8Clamped) {
return false; SynthesizeGLError(
GL_INVALID_OPERATION, "readPixels",
"type UNSIGNED_BYTE but ArrayBufferView not Uint8Array or "
"Uint8ClampedArray");
return false;
}
} }
return true; return true;
case GL_BYTE: case GL_BYTE:
......
...@@ -4300,11 +4300,16 @@ bool WebGLRenderingContextBase::ValidateReadPixelsFormatAndType( ...@@ -4300,11 +4300,16 @@ bool WebGLRenderingContextBase::ValidateReadPixelsFormatAndType(
switch (type) { switch (type) {
case GL_UNSIGNED_BYTE: case GL_UNSIGNED_BYTE:
if (buffer && buffer->GetType() != DOMArrayBufferView::kTypeUint8) { if (buffer) {
SynthesizeGLError( auto bufferType = buffer->GetType();
GL_INVALID_OPERATION, "readPixels", if (bufferType != DOMArrayBufferView::kTypeUint8 &&
"type UNSIGNED_BYTE but ArrayBufferView not Uint8Array"); bufferType != DOMArrayBufferView::kTypeUint8Clamped) {
return false; SynthesizeGLError(
GL_INVALID_OPERATION, "readPixels",
"type UNSIGNED_BYTE but ArrayBufferView not Uint8Array or "
"Uint8ClampedArray");
return false;
}
} }
return true; return true;
case GL_UNSIGNED_SHORT_5_6_5: case GL_UNSIGNED_SHORT_5_6_5:
...@@ -7326,24 +7331,28 @@ bool WebGLRenderingContextBase::ValidateTexFuncData( ...@@ -7326,24 +7331,28 @@ bool WebGLRenderingContextBase::ValidateTexFuncData(
if (!ValidateSettableTexFormat(function_name, format)) if (!ValidateSettableTexFormat(function_name, format))
return false; return false;
auto pixelType = pixels->GetType();
switch (type) { switch (type) {
case GL_BYTE: case GL_BYTE:
if (pixels->GetType() != DOMArrayBufferView::kTypeInt8) { if (pixelType != DOMArrayBufferView::kTypeInt8) {
SynthesizeGLError(GL_INVALID_OPERATION, function_name, SynthesizeGLError(GL_INVALID_OPERATION, function_name,
"type BYTE but ArrayBufferView not Int8Array"); "type BYTE but ArrayBufferView not Int8Array");
return false; return false;
} }
break; break;
case GL_UNSIGNED_BYTE: case GL_UNSIGNED_BYTE:
if (pixels->GetType() != DOMArrayBufferView::kTypeUint8) { if (pixelType != DOMArrayBufferView::kTypeUint8 &&
pixelType != DOMArrayBufferView::kTypeUint8Clamped) {
SynthesizeGLError( SynthesizeGLError(
GL_INVALID_OPERATION, function_name, GL_INVALID_OPERATION, function_name,
"type UNSIGNED_BYTE but ArrayBufferView not Uint8Array"); "type UNSIGNED_BYTE but ArrayBufferView not Uint8Array or "
"Uint8ClampedArray");
return false; return false;
} }
break; break;
case GL_SHORT: case GL_SHORT:
if (pixels->GetType() != DOMArrayBufferView::kTypeInt16) { if (pixelType != DOMArrayBufferView::kTypeInt16) {
SynthesizeGLError(GL_INVALID_OPERATION, function_name, SynthesizeGLError(GL_INVALID_OPERATION, function_name,
"type SHORT but ArrayBufferView not Int16Array"); "type SHORT but ArrayBufferView not Int16Array");
return false; return false;
...@@ -7353,7 +7362,7 @@ bool WebGLRenderingContextBase::ValidateTexFuncData( ...@@ -7353,7 +7362,7 @@ bool WebGLRenderingContextBase::ValidateTexFuncData(
case GL_UNSIGNED_SHORT_5_6_5: case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_5_5_5_1:
if (pixels->GetType() != DOMArrayBufferView::kTypeUint16) { if (pixelType != DOMArrayBufferView::kTypeUint16) {
SynthesizeGLError( SynthesizeGLError(
GL_INVALID_OPERATION, function_name, GL_INVALID_OPERATION, function_name,
"type UNSIGNED_SHORT but ArrayBufferView not Uint16Array"); "type UNSIGNED_SHORT but ArrayBufferView not Uint16Array");
...@@ -7361,7 +7370,7 @@ bool WebGLRenderingContextBase::ValidateTexFuncData( ...@@ -7361,7 +7370,7 @@ bool WebGLRenderingContextBase::ValidateTexFuncData(
} }
break; break;
case GL_INT: case GL_INT:
if (pixels->GetType() != DOMArrayBufferView::kTypeInt32) { if (pixelType != DOMArrayBufferView::kTypeInt32) {
SynthesizeGLError(GL_INVALID_OPERATION, function_name, SynthesizeGLError(GL_INVALID_OPERATION, function_name,
"type INT but ArrayBufferView not Int32Array"); "type INT but ArrayBufferView not Int32Array");
return false; return false;
...@@ -7372,7 +7381,7 @@ bool WebGLRenderingContextBase::ValidateTexFuncData( ...@@ -7372,7 +7381,7 @@ bool WebGLRenderingContextBase::ValidateTexFuncData(
case GL_UNSIGNED_INT_10F_11F_11F_REV: case GL_UNSIGNED_INT_10F_11F_11F_REV:
case GL_UNSIGNED_INT_5_9_9_9_REV: case GL_UNSIGNED_INT_5_9_9_9_REV:
case GL_UNSIGNED_INT_24_8: case GL_UNSIGNED_INT_24_8:
if (pixels->GetType() != DOMArrayBufferView::kTypeUint32) { if (pixelType != DOMArrayBufferView::kTypeUint32) {
SynthesizeGLError( SynthesizeGLError(
GL_INVALID_OPERATION, function_name, GL_INVALID_OPERATION, function_name,
"type UNSIGNED_INT but ArrayBufferView not Uint32Array"); "type UNSIGNED_INT but ArrayBufferView not Uint32Array");
...@@ -7380,7 +7389,7 @@ bool WebGLRenderingContextBase::ValidateTexFuncData( ...@@ -7380,7 +7389,7 @@ bool WebGLRenderingContextBase::ValidateTexFuncData(
} }
break; break;
case GL_FLOAT: // OES_texture_float case GL_FLOAT: // OES_texture_float
if (pixels->GetType() != DOMArrayBufferView::kTypeFloat32) { if (pixelType != DOMArrayBufferView::kTypeFloat32) {
SynthesizeGLError(GL_INVALID_OPERATION, function_name, SynthesizeGLError(GL_INVALID_OPERATION, function_name,
"type FLOAT but ArrayBufferView not Float32Array"); "type FLOAT but ArrayBufferView not Float32Array");
return false; return false;
...@@ -7390,7 +7399,7 @@ bool WebGLRenderingContextBase::ValidateTexFuncData( ...@@ -7390,7 +7399,7 @@ bool WebGLRenderingContextBase::ValidateTexFuncData(
case GL_HALF_FLOAT_OES: // OES_texture_half_float case GL_HALF_FLOAT_OES: // OES_texture_half_float
// As per the specification, ArrayBufferView should be null or a // As per the specification, ArrayBufferView should be null or a
// Uint16Array when OES_texture_half_float is enabled. // Uint16Array when OES_texture_half_float is enabled.
if (pixels->GetType() != DOMArrayBufferView::kTypeUint16) { if (pixelType != DOMArrayBufferView::kTypeUint16) {
SynthesizeGLError(GL_INVALID_OPERATION, function_name, SynthesizeGLError(GL_INVALID_OPERATION, function_name,
"type HALF_FLOAT_OES but ArrayBufferView is not NULL " "type HALF_FLOAT_OES but ArrayBufferView is not NULL "
"and not Uint16Array"); "and not Uint16Array");
......
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