Commit b6664925 by Jamie Madill Committed by Commit Bot

Add error handling macro to Context.

This is a small specialized macro to remove all the redundant handleError calls and return value checking. Also add a Context::prepareForDraw member that will be used in follow-up patches to do necessary work prior to a draw call. BUG=angleproject:2107 BUG=angleproject:2116 Change-Id: I8a32d2206c218fcca5236abfd3f2ce370296ca99 Reviewed-on: https://chromium-review.googlesource.com/585288Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 14a26aea
...@@ -45,6 +45,11 @@ ...@@ -45,6 +45,11 @@
namespace namespace
{ {
#define ANGLE_HANDLE_ERR(X) \
handleError(X); \
return;
#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
template <typename T> template <typename T>
std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager, std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
GLsizei numPaths, GLsizei numPaths,
...@@ -1832,30 +1837,23 @@ void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params) ...@@ -1832,30 +1837,23 @@ void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
void Context::drawArrays(GLenum mode, GLint first, GLsizei count) void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
{ {
syncRendererState(); ANGLE_CONTEXT_TRY(prepareForDraw());
auto error = mImplementation->drawArrays(this, mode, first, count); ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
handleError(error);
if (!error.isError())
{
MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback()); MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
}
} }
void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount) void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
{ {
syncRendererState(); ANGLE_CONTEXT_TRY(prepareForDraw());
auto error = mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount); ANGLE_CONTEXT_TRY(
handleError(error); mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
if (!error.isError())
{
MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback()); MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
}
} }
void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices) void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
{ {
syncRendererState(); ANGLE_CONTEXT_TRY(prepareForDraw());
handleError(mImplementation->drawElements(this, mode, count, type, indices)); ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
} }
void Context::drawElementsInstanced(GLenum mode, void Context::drawElementsInstanced(GLenum mode,
...@@ -1864,8 +1862,8 @@ void Context::drawElementsInstanced(GLenum mode, ...@@ -1864,8 +1862,8 @@ void Context::drawElementsInstanced(GLenum mode,
const void *indices, const void *indices,
GLsizei instances) GLsizei instances)
{ {
syncRendererState(); ANGLE_CONTEXT_TRY(prepareForDraw());
handleError( ANGLE_CONTEXT_TRY(
mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances)); mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
} }
...@@ -1876,20 +1874,21 @@ void Context::drawRangeElements(GLenum mode, ...@@ -1876,20 +1874,21 @@ void Context::drawRangeElements(GLenum mode,
GLenum type, GLenum type,
const void *indices) const void *indices)
{ {
syncRendererState(); ANGLE_CONTEXT_TRY(prepareForDraw());
handleError(mImplementation->drawRangeElements(this, mode, start, end, count, type, indices)); ANGLE_CONTEXT_TRY(
mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
} }
void Context::drawArraysIndirect(GLenum mode, const void *indirect) void Context::drawArraysIndirect(GLenum mode, const void *indirect)
{ {
syncRendererState(); ANGLE_CONTEXT_TRY(prepareForDraw());
handleError(mImplementation->drawArraysIndirect(this, mode, indirect)); ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
} }
void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect) void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
{ {
syncRendererState(); ANGLE_CONTEXT_TRY(prepareForDraw());
handleError(mImplementation->drawElementsIndirect(this, mode, type, indirect)); ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
} }
void Context::flush() void Context::flush()
...@@ -2821,6 +2820,12 @@ void Context::initWorkarounds() ...@@ -2821,6 +2820,12 @@ void Context::initWorkarounds()
mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT); mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
} }
Error Context::prepareForDraw()
{
syncRendererState();
return NoError();
}
void Context::syncRendererState() void Context::syncRendererState()
{ {
const State::DirtyBits &dirtyBits = mGLState.getDirtyBits(); const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
...@@ -2915,11 +2920,11 @@ void Context::readPixels(GLint x, ...@@ -2915,11 +2920,11 @@ void Context::readPixels(GLint x,
syncStateForReadPixels(); syncStateForReadPixels();
Framebuffer *framebufferObject = mGLState.getReadFramebuffer(); Framebuffer *readFBO = mGLState.getReadFramebuffer();
ASSERT(framebufferObject); ASSERT(readFBO);
Rectangle area(x, y, width, height); Rectangle area(x, y, width, height);
handleError(framebufferObject->readPixels(this, area, format, type, pixels)); handleError(readFBO->readPixels(this, area, format, type, pixels));
} }
void Context::copyTexImage2D(GLenum target, void Context::copyTexImage2D(GLenum target,
...@@ -4645,7 +4650,6 @@ void Context::linkProgram(GLuint program) ...@@ -4645,7 +4650,6 @@ void Context::linkProgram(GLuint program)
Program *programObject = getProgram(program); Program *programObject = getProgram(program);
ASSERT(programObject); ASSERT(programObject);
handleError(programObject->link(this)); handleError(programObject->link(this));
mGLState.onProgramExecutableChange(programObject);
} }
void Context::releaseShaderCompiler() void Context::releaseShaderCompiler()
...@@ -4840,8 +4844,8 @@ void Context::programBinary(GLuint program, GLenum binaryFormat, const void *bin ...@@ -4840,8 +4844,8 @@ void Context::programBinary(GLuint program, GLenum binaryFormat, const void *bin
{ {
Program *programObject = getProgram(program); Program *programObject = getProgram(program);
ASSERT(programObject != nullptr); ASSERT(programObject != nullptr);
handleError(programObject->loadBinary(this, binaryFormat, binary, length)); handleError(programObject->loadBinary(this, binaryFormat, binary, length));
mGLState.onProgramExecutableChange(programObject);
} }
} // namespace gl } // namespace gl
...@@ -832,6 +832,7 @@ class Context final : public ValidationContext ...@@ -832,6 +832,7 @@ class Context final : public ValidationContext
egl::Surface *getCurrentReadSurface() const { return mCurrentSurface; } egl::Surface *getCurrentReadSurface() const { return mCurrentSurface; }
private: private:
Error prepareForDraw();
void syncRendererState(); void syncRendererState();
void syncRendererState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask); void syncRendererState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask);
void syncStateForReadPixels(); void syncStateForReadPixels();
......
...@@ -205,16 +205,19 @@ inline Error NoError() ...@@ -205,16 +205,19 @@ inline Error NoError()
#define ANGLE_CONCAT2(x, y) ANGLE_CONCAT1(x, y) #define ANGLE_CONCAT2(x, y) ANGLE_CONCAT1(x, y)
#define ANGLE_LOCAL_VAR ANGLE_CONCAT2(_localVar, __LINE__) #define ANGLE_LOCAL_VAR ANGLE_CONCAT2(_localVar, __LINE__)
#define ANGLE_TRY(EXPR) \ #define ANGLE_TRY_TEMPLATE(EXPR, FUNC) \
{ \ { \
auto ANGLE_LOCAL_VAR = EXPR; \ auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_LOCAL_VAR.isError()) \ if (ANGLE_LOCAL_VAR.isError()) \
{ \ { \
return ANGLE_LOCAL_VAR; \ FUNC(ANGLE_LOCAL_VAR); \
} \ } \
} \ } \
ANGLE_EMPTY_STATEMENT ANGLE_EMPTY_STATEMENT
#define ANGLE_RETURN(X) return X;
#define ANGLE_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_RETURN);
#define ANGLE_TRY_RESULT(EXPR, RESULT) \ #define ANGLE_TRY_RESULT(EXPR, RESULT) \
{ \ { \
auto ANGLE_LOCAL_VAR = EXPR; \ auto ANGLE_LOCAL_VAR = EXPR; \
......
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