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