Commit abfbc0fe by Jamie Madill Committed by Commit Bot

Use angle::Result in allocation and math check macros.

Replace these with ANGLE_CHECK_*_ALLOC and ANGLE_CHECK_*_MATH depending on the specific error type. Bug: angleproject:2491 Change-Id: Ic4395101fe701c563ae2b92aa2c55c93b934a7de Reviewed-on: https://chromium-review.googlesource.com/c/1262737Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 7d81ae71
......@@ -255,17 +255,11 @@ std::string ToString(const T &value)
// TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
#define GL_INTERNAL_ERROR_ANGLEX 0x6AEE
#define ANGLE_TRY_CHECKED_MATH(result) \
if (!result) \
{ \
return gl::InternalError() << "Integer overflow."; \
}
#define ANGLE_CHECK_GL_ALLOC(context, result) \
ANGLE_CHECK(context, result, "Failed to allocate host memory", GL_OUT_OF_MEMORY)
#define ANGLE_TRY_ALLOCATION(result) \
if (!result) \
{ \
return gl::OutOfMemory() << "Failed to allocate internal buffer."; \
}
#define ANGLE_CHECK_GL_MATH(context, result) \
ANGLE_CHECK(context, result, "Integer overflow.", GL_INVALID_OPERATION)
// The below inlining code lifted from V8.
#if defined(__clang__) || (defined(__GNUC__) && defined(__has_attribute))
......
......@@ -65,7 +65,7 @@ const std::string &Buffer::getLabel() const
return mState.mLabel;
}
Error Buffer::bufferData(const Context *context,
Error Buffer::bufferData(Context *context,
BufferBinding target,
const void *data,
GLsizeiptr size,
......@@ -79,8 +79,8 @@ Error Buffer::bufferData(const Context *context,
if (context && context->getGLState().isRobustResourceInitEnabled() && !data && size > 0)
{
angle::MemoryBuffer *scratchBuffer = nullptr;
ANGLE_TRY_ALLOCATION(
context->getZeroFilledBuffer(static_cast<size_t>(size), &scratchBuffer));
ANGLE_CHECK_GL_ALLOC(
context, context->getZeroFilledBuffer(static_cast<size_t>(size), &scratchBuffer));
dataForImpl = scratchBuffer->data();
}
......
......@@ -74,7 +74,7 @@ class Buffer final : public RefCountObject, public LabeledObject
void setLabel(const std::string &label) override;
const std::string &getLabel() const override;
Error bufferData(const Context *context,
Error bufferData(Context *context,
BufferBinding target,
const void *data,
GLsizeiptr size,
......
......@@ -2618,6 +2618,15 @@ void Context::handleError(const Error &error) const
mErrors.handleError(error);
}
void Context::handleError(GLenum errorCode,
const char *message,
const char *file,
const char *function,
unsigned int line)
{
mErrors.handleError(errorCode, message, file, function, line);
}
// Get one of the recorded errors and clear its flag, if any.
// [OpenGL ES 2.0.24] section 2.5 page 13.
GLenum Context::getError()
......@@ -7955,6 +7964,20 @@ void ErrorSet::handleError(const Error &error) const
}
}
void ErrorSet::handleError(GLenum errorCode,
const char *message,
const char *file,
const char *function,
unsigned int line)
{
// TODO(jmadill): Handle error directly instead of creating object. http://anglebug.com/2491
std::stringstream errorStream;
errorStream << "Front-end Error: " << gl::FmtHex(errorCode) << ", in " << file << ", "
<< function << ":" << line << ". " << message;
handleError(gl::Error(errorCode, errorCode, errorStream.str()));
}
bool ErrorSet::empty() const
{
return mErrors.empty();
......
......@@ -75,6 +75,12 @@ class ErrorSet : angle::NonCopyable
bool empty() const;
GLenum popError();
void handleError(GLenum errorCode,
const char *message,
const char *file,
const char *function,
unsigned int line);
private:
Context *mContext;
......@@ -1550,6 +1556,11 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl
// Consumes the error.
// TODO(jmadill): Remove const. http://anglebug.com/2378
void handleError(const Error &error) const;
void handleError(GLenum errorCode,
const char *message,
const char *file,
const char *function,
unsigned int line);
GLenum getError();
void markContextLost();
......
......@@ -15,6 +15,7 @@
#include "libANGLE/Surface.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/ContextImpl.h"
#include "libANGLE/renderer/d3d/ContextD3D.h"
#include "libANGLE/renderer/d3d/RenderTargetD3D.h"
#include "libANGLE/renderer/d3d/RenderbufferD3D.h"
#include "libANGLE/renderer/d3d/RendererD3D.h"
......@@ -259,13 +260,16 @@ gl::Error FramebufferD3D::readPixels(const gl::Context *context,
const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type);
ContextD3D *contextD3D = GetImplAs<ContextD3D>(context);
GLuint outputPitch = 0;
ANGLE_TRY_CHECKED_MATH(sizedFormatInfo.computeRowPitch(
type, origArea.width, packState.alignment, packState.rowLength, &outputPitch));
ANGLE_CHECK_HR_MATH(contextD3D,
sizedFormatInfo.computeRowPitch(type, origArea.width, packState.alignment,
packState.rowLength, &outputPitch));
GLuint outputSkipBytes = 0;
ANGLE_TRY_CHECKED_MATH(
sizedFormatInfo.computeSkipBytes(type, outputPitch, 0, packState, false, &outputSkipBytes));
ANGLE_CHECK_HR_MATH(contextD3D, sizedFormatInfo.computeSkipBytes(
type, outputPitch, 0, packState, false, &outputSkipBytes));
outputSkipBytes +=
(area.x - origArea.x) * sizedFormatInfo.pixelBytes + (area.y - origArea.y) * outputPitch;
......
......@@ -664,6 +664,7 @@ gl::Error TextureD3D::onDestroy(const gl::Context *context)
gl::Error TextureD3D::initializeContents(const gl::Context *context,
const gl::ImageIndex &imageIndexIn)
{
ContextD3D *contextD3D = GetImplAs<ContextD3D>(context);
gl::ImageIndex imageIndex = imageIndexIn;
// Special case for D3D11 3D textures. We can't create render targets for individual layers of a
......@@ -729,15 +730,15 @@ gl::Error TextureD3D::initializeContents(const gl::Context *context,
const auto &formatInfo = gl::GetSizedInternalFormatInfo(image->getInternalFormat());
GLuint imageBytes = 0;
ANGLE_TRY_CHECKED_MATH(
formatInfo.computeRowPitch(formatInfo.type, image->getWidth(), 1, 0, &imageBytes));
ANGLE_CHECK_HR_MATH(contextD3D, formatInfo.computeRowPitch(formatInfo.type, image->getWidth(),
1, 0, &imageBytes));
imageBytes *= image->getHeight() * image->getDepth();
gl::PixelUnpackState zeroDataUnpackState;
zeroDataUnpackState.alignment = 1;
angle::MemoryBuffer *zeroBuffer = nullptr;
ANGLE_TRY_ALLOCATION(context->getZeroFilledBuffer(imageBytes, &zeroBuffer));
ANGLE_CHECK_HR_ALLOC(contextD3D, context->getZeroFilledBuffer(imageBytes, &zeroBuffer));
if (shouldUseSetData(image))
{
......@@ -3052,10 +3053,12 @@ gl::Error TextureD3D_2DArray::setImage(const gl::Context *context,
ANGLE_TRY(
redefineImage(context, index.getLevelIndex(), formatInfo.sizedInternalFormat, size, false));
ContextD3D *contextD3D = GetImplAs<ContextD3D>(context);
GLuint inputDepthPitch = 0;
ANGLE_TRY_CHECKED_MATH(formatInfo.computeDepthPitch(type, size.width, size.height,
unpack.alignment, unpack.rowLength,
unpack.imageHeight, &inputDepthPitch));
ANGLE_CHECK_HR_MATH(contextD3D, formatInfo.computeDepthPitch(
type, size.width, size.height, unpack.alignment,
unpack.rowLength, unpack.imageHeight, &inputDepthPitch));
for (int i = 0; i < size.depth; i++)
{
......@@ -3076,13 +3079,15 @@ gl::Error TextureD3D_2DArray::setSubImage(const gl::Context *context,
gl::Buffer *unpackBuffer,
const uint8_t *pixels)
{
ContextD3D *contextD3D = GetImplAs<ContextD3D>(context);
ASSERT(index.getTarget() == gl::TextureTarget::_2DArray);
const gl::InternalFormat &formatInfo =
gl::GetInternalFormatInfo(getInternalFormat(index.getLevelIndex()), type);
GLuint inputDepthPitch = 0;
ANGLE_TRY_CHECKED_MATH(formatInfo.computeDepthPitch(type, area.width, area.height,
unpack.alignment, unpack.rowLength,
unpack.imageHeight, &inputDepthPitch));
ANGLE_CHECK_HR_MATH(contextD3D, formatInfo.computeDepthPitch(
type, area.width, area.height, unpack.alignment,
unpack.rowLength, unpack.imageHeight, &inputDepthPitch));
for (int i = 0; i < area.depth; i++)
{
......@@ -3109,13 +3114,16 @@ gl::Error TextureD3D_2DArray::setCompressedImage(const gl::Context *context,
{
ASSERT(index.getTarget() == gl::TextureTarget::_2DArray);
ContextD3D *contextD3D = GetImplAs<ContextD3D>(context);
// compressed formats don't have separate sized internal formats-- we can just use the compressed format directly
ANGLE_TRY(redefineImage(context, index.getLevelIndex(), internalFormat, size, false));
const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat);
GLuint inputDepthPitch = 0;
ANGLE_TRY_CHECKED_MATH(formatInfo.computeDepthPitch(GL_UNSIGNED_BYTE, size.width, size.height,
1, 0, 0, &inputDepthPitch));
ANGLE_CHECK_HR_MATH(
contextD3D, formatInfo.computeDepthPitch(GL_UNSIGNED_BYTE, size.width, size.height, 1, 0, 0,
&inputDepthPitch));
for (int i = 0; i < size.depth; i++)
{
......@@ -3138,10 +3146,13 @@ gl::Error TextureD3D_2DArray::setCompressedSubImage(const gl::Context *context,
{
ASSERT(index.getTarget() == gl::TextureTarget::_2DArray);
ContextD3D *contextD3D = GetImplAs<ContextD3D>(context);
const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(format);
GLuint inputDepthPitch = 0;
ANGLE_TRY_CHECKED_MATH(formatInfo.computeDepthPitch(GL_UNSIGNED_BYTE, area.width, area.height,
1, 0, 0, &inputDepthPitch));
ANGLE_CHECK_HR_MATH(
contextD3D, formatInfo.computeDepthPitch(GL_UNSIGNED_BYTE, area.width, area.height, 1, 0, 0,
&inputDepthPitch));
for (int i = 0; i < area.depth; i++)
{
......
......@@ -523,7 +523,8 @@ gl::Error Buffer11::mapRange(const gl::Context *context,
ANGLE_TRY(getStagingStorage(context, &mMappedStorage));
}
ANGLE_TRY_ALLOCATION(mMappedStorage);
Context11 *context11 = GetImplAs<Context11>(context);
ANGLE_CHECK_HR_ALLOC(context11, mMappedStorage);
if ((access & GL_MAP_WRITE_BIT) > 0)
{
......
......@@ -116,10 +116,4 @@ struct ContextCreationTry
std::vector<ContextCreationTry> GenerateContextCreationToTry(EGLint requestedType, bool isMesaGLX);
} // namespace rx
#define ANGLE_CHECK_GL_ALLOC(context, result) \
ANGLE_CHECK(context, result, "Failed to allocate host memory", GL_OUT_OF_MEMORY)
#define ANGLE_CHECK_GL_MATH(context, result) \
ANGLE_CHECK(context, result, "Integer overflow.", GL_INVALID_OPERATION)
#endif // LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
......@@ -11,6 +11,7 @@
#include "common/debug.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/null/BufferNULL.h"
#include "libANGLE/renderer/null/CompilerNULL.h"
#include "libANGLE/renderer/null/DisplayNULL.h"
......@@ -438,4 +439,16 @@ gl::Error ContextNULL::memoryBarrierByRegion(const gl::Context *context, GLbitfi
return gl::NoError();
}
void ContextNULL::handleError(GLenum errorCode,
const char *message,
const char *file,
const char *function,
unsigned int line)
{
std::stringstream errorStream;
errorStream << "Internal OpenGL error: " << gl::FmtHex(errorCode) << ", in " << file << ", "
<< function << ":" << line << ". " << message;
mErrors->handleError(gl::Error(errorCode, errorCode, errorStream.str()));
}
} // namespace rx
......@@ -203,6 +203,12 @@ class ContextNULL : public ContextImpl
gl::Error memoryBarrier(const gl::Context *context, GLbitfield barriers) override;
gl::Error memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) override;
void handleError(GLenum errorCode,
const char *message,
const char *file,
const char *function,
unsigned int line);
private:
gl::Caps mCaps;
gl::TextureCapsMap mTextureCaps;
......
......@@ -9,11 +9,11 @@
#include "libANGLE/renderer/null/FramebufferNULL.h"
#include "common/debug.h"
#include "libANGLE/Context.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/null/BufferNULL.h"
#include "common/debug.h"
#include "libANGLE/renderer/null/ContextNULL.h"
namespace rx
{
......@@ -147,13 +147,16 @@ gl::Error FramebufferNULL::readPixels(const gl::Context *context,
// Compute size of unclipped rows and initial skip
const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(format, type);
ContextNULL *contextNull = GetImplAs<ContextNULL>(context);
GLuint rowBytes = 0;
ANGLE_TRY_CHECKED_MATH(glFormat.computeRowPitch(type, origArea.width, packState.alignment,
packState.rowLength, &rowBytes));
ANGLE_CHECK_GL_MATH(contextNull,
glFormat.computeRowPitch(type, origArea.width, packState.alignment,
packState.rowLength, &rowBytes));
GLuint skipBytes = 0;
ANGLE_TRY_CHECKED_MATH(
glFormat.computeSkipBytes(type, rowBytes, 0, packState, false, &skipBytes));
ANGLE_CHECK_GL_MATH(contextNull,
glFormat.computeSkipBytes(type, rowBytes, 0, packState, false, &skipBytes));
pixels += skipBytes;
// Skip OOB region up to first in bounds pixel
......
......@@ -363,11 +363,12 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type);
GLuint outputPitch = 0;
ANGLE_TRY_CHECKED_MATH(sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment,
packState.rowLength, &outputPitch));
ANGLE_VK_CHECK_MATH(contextVk,
sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment,
packState.rowLength, &outputPitch));
GLuint outputSkipBytes = 0;
ANGLE_TRY_CHECKED_MATH(
sizedFormatInfo.computeSkipBytes(type, outputPitch, 0, packState, false, &outputSkipBytes));
ANGLE_VK_CHECK_MATH(contextVk, sizedFormatInfo.computeSkipBytes(type, outputPitch, 0, packState,
false, &outputSkipBytes));
outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes +
(clippedArea.y - area.y) * outputPitch;
......
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