Refactor internal format pixel math methods.
This removes the use of the ErrorOrResult class from these methods.
This will enable more performant Error handling. Also cleans up the
ANGLE_TRY_CHECKED_MATH macro to be more general.
Bug: angleproject:2713
Change-Id: I349947d320907839ca88ec1f9251e6ddc3858a08
Reviewed-on: https://chromium-review.googlesource.com/1128920
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Frank Henigman <fjhenigman@chromium.org>
diff --git a/src/libANGLE/renderer/gl/FramebufferGL.cpp b/src/libANGLE/renderer/gl/FramebufferGL.cpp
index f42a405..2a253dd 100644
--- a/src/libANGLE/renderer/gl/FramebufferGL.cpp
+++ b/src/libANGLE/renderer/gl/FramebufferGL.cpp
@@ -464,9 +464,8 @@
const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(readFormat, readType);
GLuint rowBytes = 0;
- ANGLE_TRY_RESULT(glFormat.computeRowPitch(readType, origArea.width, packState.alignment,
- packState.rowLength),
- rowBytes);
+ ANGLE_TRY_CHECKED_MATH(glFormat.computeRowPitch(
+ readType, origArea.width, packState.alignment, packState.rowLength, &rowBytes));
pixels += leftClip * glFormat.pixelBytes + topClip * rowBytes;
}
@@ -892,10 +891,10 @@
const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(format, type);
GLuint rowBytes = 0;
- ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength),
- rowBytes);
+ ANGLE_TRY_CHECKED_MATH(
+ glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength, &rowBytes));
GLuint skipBytes = 0;
- ANGLE_TRY_RESULT(glFormat.computeSkipBytes(type, rowBytes, 0, pack, false), skipBytes);
+ ANGLE_TRY_CHECKED_MATH(glFormat.computeSkipBytes(type, rowBytes, 0, pack, false, &skipBytes));
gl::PixelPackState directPack;
directPack.alignment = 1;
@@ -934,10 +933,11 @@
const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(format, type);
GLuint rowBytes = 0;
- ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength),
- rowBytes);
+ ANGLE_TRY_CHECKED_MATH(
+ glFormat.computeRowPitch(type, area.width, pack.alignment, pack.rowLength, &rowBytes));
GLuint skipBytes = 0;
- ANGLE_TRY_RESULT(glFormat.computeSkipBytes(type, rowBytes, 0, pack, false), skipBytes);
+ ANGLE_TRY_CHECKED_MATH(
+ glFormat.computeSkipBytes(type, rowBytes, 0, pack, false, &skipBytes));
gl::PixelPackState directPack;
directPack.alignment = 1;
diff --git a/src/libANGLE/renderer/gl/TextureGL.cpp b/src/libANGLE/renderer/gl/TextureGL.cpp
index a123108..32627be 100644
--- a/src/libANGLE/renderer/gl/TextureGL.cpp
+++ b/src/libANGLE/renderer/gl/TextureGL.cpp
@@ -341,16 +341,16 @@
const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(format, type);
GLuint rowBytes = 0;
- ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, unpack.alignment, unpack.rowLength),
- rowBytes);
+ ANGLE_TRY_CHECKED_MATH(
+ glFormat.computeRowPitch(type, area.width, unpack.alignment, unpack.rowLength, &rowBytes));
GLuint imageBytes = 0;
- ANGLE_TRY_RESULT(glFormat.computeDepthPitch(area.height, unpack.imageHeight, rowBytes),
- imageBytes);
+ ANGLE_TRY_CHECKED_MATH(
+ glFormat.computeDepthPitch(area.height, unpack.imageHeight, rowBytes, &imageBytes));
bool useTexImage3D = nativegl::UseTexImage3D(getType());
GLuint skipBytes = 0;
- ANGLE_TRY_RESULT(glFormat.computeSkipBytes(type, rowBytes, imageBytes, unpack, useTexImage3D),
- skipBytes);
+ ANGLE_TRY_CHECKED_MATH(
+ glFormat.computeSkipBytes(type, rowBytes, imageBytes, unpack, useTexImage3D, &skipBytes));
const uint8_t *pixelsWithSkip = pixels + skipBytes;
if (useTexImage3D)
@@ -397,15 +397,15 @@
const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(format, type);
GLuint rowBytes = 0;
- ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, area.width, unpack.alignment, unpack.rowLength),
- rowBytes);
+ ANGLE_TRY_CHECKED_MATH(
+ glFormat.computeRowPitch(type, area.width, unpack.alignment, unpack.rowLength, &rowBytes));
GLuint imageBytes = 0;
- ANGLE_TRY_RESULT(glFormat.computeDepthPitch(area.height, unpack.imageHeight, rowBytes),
- imageBytes);
+ ANGLE_TRY_CHECKED_MATH(
+ glFormat.computeDepthPitch(area.height, unpack.imageHeight, rowBytes, &imageBytes));
bool useTexImage3D = nativegl::UseTexImage3D(getType());
GLuint skipBytes = 0;
- ANGLE_TRY_RESULT(glFormat.computeSkipBytes(type, rowBytes, imageBytes, unpack, useTexImage3D),
- skipBytes);
+ ANGLE_TRY_CHECKED_MATH(
+ glFormat.computeSkipBytes(type, rowBytes, imageBytes, unpack, useTexImage3D, &skipBytes));
stateManager->setPixelUnpackState(unpack);
stateManager->setPixelUnpackBuffer(unpackBuffer);
@@ -895,8 +895,8 @@
internalFormat);
GLuint dataSize = 0;
- ANGLE_TRY_RESULT(internalFormatInfo.computeCompressedImageSize(levelSize),
- dataSize);
+ ANGLE_TRY_CHECKED_MATH(
+ internalFormatInfo.computeCompressedImageSize(levelSize, &dataSize));
functions->compressedTexImage2D(ToGLenum(type), static_cast<GLint>(level),
compressedTexImageFormat.format,
levelSize.width, levelSize.height, 0,
@@ -925,8 +925,8 @@
internalFormat);
GLuint dataSize = 0;
- ANGLE_TRY_RESULT(internalFormatInfo.computeCompressedImageSize(levelSize),
- dataSize);
+ ANGLE_TRY_CHECKED_MATH(internalFormatInfo.computeCompressedImageSize(
+ levelSize, &dataSize));
functions->compressedTexImage2D(
ToGLenum(face), static_cast<GLint>(level),
compressedTexImageFormat.format, levelSize.width, levelSize.height,
@@ -984,9 +984,8 @@
internalFormat);
GLuint dataSize = 0;
- ANGLE_TRY_RESULT(
- internalFormatInfo.computeCompressedImageSize(levelSize),
- dataSize);
+ ANGLE_TRY_CHECKED_MATH(
+ internalFormatInfo.computeCompressedImageSize(levelSize, &dataSize));
functions->compressedTexImage3D(
ToGLenum(type), i, compressedTexImageFormat.format, levelSize.width,
levelSize.height, levelSize.depth, 0, static_cast<GLsizei>(dataSize),
@@ -1536,7 +1535,8 @@
internalFormatInfo.internalFormat);
GLuint imageSize = 0;
- ANGLE_TRY_RESULT(internalFormatInfo.computeCompressedImageSize(desc.size), imageSize);
+ ANGLE_TRY_CHECKED_MATH(
+ internalFormatInfo.computeCompressedImageSize(desc.size, &imageSize));
angle::MemoryBuffer *zero;
ANGLE_TRY(context->getZeroFilledBuffer(imageSize, &zero));
@@ -1564,10 +1564,9 @@
functions, workarounds, internalFormatInfo.format, internalFormatInfo.type);
GLuint imageSize = 0;
- ANGLE_TRY_RESULT(internalFormatInfo.computePackUnpackEndByte(
- nativeSubImageFormat.type, desc.size, unpackState,
- nativegl::UseTexImage3D(getType())),
- imageSize);
+ ANGLE_TRY_CHECKED_MATH(internalFormatInfo.computePackUnpackEndByte(
+ nativeSubImageFormat.type, desc.size, unpackState, nativegl::UseTexImage3D(getType()),
+ &imageSize));
angle::MemoryBuffer *zero;
ANGLE_TRY(context->getZeroFilledBuffer(imageSize, &zero));
diff --git a/src/libANGLE/renderer/gl/renderergl_utils.cpp b/src/libANGLE/renderer/gl/renderergl_utils.cpp
index 0e1226f..62a7df5 100644
--- a/src/libANGLE/renderer/gl/renderergl_utils.cpp
+++ b/src/libANGLE/renderer/gl/renderergl_utils.cpp
@@ -1359,27 +1359,27 @@
// We are using an pack or unpack buffer, compute what the driver thinks is going to be the
// last byte read or written. If it is past the end of the buffer, we will need to use the
// workaround otherwise the driver will generate INVALID_OPERATION and not do the operation.
- CheckedNumeric<size_t> checkedEndByte;
- CheckedNumeric<size_t> pixelBytes;
- size_t rowPitch;
const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(format, type);
- ANGLE_TRY_RESULT(glFormat.computePackUnpackEndByte(type, size, state, is3D), checkedEndByte);
- ANGLE_TRY_RESULT(glFormat.computeRowPitch(type, size.width, state.alignment, state.rowLength),
- rowPitch);
- pixelBytes = glFormat.computePixelBytes(type);
+ GLuint endByte = 0;
+ ANGLE_TRY_CHECKED_MATH(glFormat.computePackUnpackEndByte(type, size, state, is3D, &endByte));
+ GLuint rowPitch = 0;
+ ANGLE_TRY_CHECKED_MATH(
+ glFormat.computeRowPitch(type, size.width, state.alignment, state.rowLength, &rowPitch));
- checkedEndByte += reinterpret_cast<intptr_t>(pixels);
+ CheckedNumeric<size_t> checkedPixelBytes = glFormat.computePixelBytes(type);
+ CheckedNumeric<size_t> checkedEndByte =
+ angle::CheckedNumeric<size_t>(endByte) + reinterpret_cast<intptr_t>(pixels);
// At this point checkedEndByte is the actual last byte read.
// The driver adds an extra row padding (if any), mimic it.
- ANGLE_TRY_CHECKED_MATH(pixelBytes);
- if (pixelBytes.ValueOrDie() * size.width < rowPitch)
+ ANGLE_TRY_CHECKED_MATH(checkedPixelBytes.IsValid());
+ if (checkedPixelBytes.ValueOrDie() * size.width < rowPitch)
{
- checkedEndByte += rowPitch - pixelBytes * size.width;
+ checkedEndByte += rowPitch - checkedPixelBytes * size.width;
}
- ANGLE_TRY_CHECKED_MATH(checkedEndByte);
+ ANGLE_TRY_CHECKED_MATH(checkedEndByte.IsValid());
return checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelBuffer->getSize());
}