Commit 01a80eeb by Jamie Madill Committed by Commit Bot

Refactor all the Bind* GLES 2.0 entry points.

This requires storing a reference the the Context's Framebuffer map in the ValidationContext. Likely we'll need to do this as well for the other non-shared object types. BUG=angleproject:747 Change-Id: I73ee8b0be3c3b9e54b7e48e49d6f738cf1d926dd Reviewed-on: https://chromium-review.googlesource.com/407843 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 62a90cf6
......@@ -245,6 +245,7 @@ Context::Context(rx::EGLImplFactory *implFactory,
mExtensions,
nullptr,
mLimitations,
mFramebufferMap,
GetNoError(attribs)),
mImplementation(implFactory->createContext(mState)),
mCompiler(nullptr),
......@@ -319,7 +320,7 @@ Context::Context(rx::EGLImplFactory *implFactory,
bindArrayBuffer(0);
bindElementArrayBuffer(0);
bindRenderbuffer(0);
bindRenderbuffer(GL_RENDERBUFFER, 0);
bindGenericUniformBuffer(0);
for (unsigned int i = 0; i < mCaps.maxCombinedUniformBlocks; i++)
......@@ -985,13 +986,6 @@ void Context::bindDrawFramebuffer(GLuint framebufferHandle)
mGLState.setDrawFramebufferBinding(framebuffer);
}
void Context::bindRenderbuffer(GLuint renderbufferHandle)
{
Renderbuffer *renderbuffer =
mResourceManager->checkRenderbufferAllocation(mImplementation.get(), renderbufferHandle);
mGLState.setRenderbufferBinding(renderbuffer);
}
void Context::bindVertexArray(GLuint vertexArrayHandle)
{
VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
......@@ -2096,27 +2090,6 @@ Framebuffer *Context::checkFramebufferAllocation(GLuint framebuffer)
return framebufferIt->second;
}
bool Context::isTextureGenerated(GLuint texture) const
{
return mResourceManager->isTextureGenerated(texture);
}
bool Context::isBufferGenerated(GLuint buffer) const
{
return mResourceManager->isBufferGenerated(buffer);
}
bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
{
return mResourceManager->isRenderbufferGenerated(renderbuffer);
}
bool Context::isFramebufferGenerated(GLuint framebuffer) const
{
ASSERT(mFramebufferMap.find(0) != mFramebufferMap.end());
return mFramebufferMap.find(framebuffer) != mFramebufferMap.end();
}
bool Context::isVertexArrayGenerated(GLuint vertexArray)
{
ASSERT(mVertexArrayMap.find(0) != mVertexArrayMap.end());
......@@ -3543,4 +3516,68 @@ void Context::copyBufferSubData(GLenum readTarget,
handleError(writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size));
}
void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
{
Program *programObject = getProgram(program);
// TODO(jmadill): Re-use this from the validation if possible.
ASSERT(programObject);
programObject->bindAttributeLocation(index, name);
}
void Context::bindBuffer(GLenum target, GLuint buffer)
{
switch (target)
{
case GL_ARRAY_BUFFER:
bindArrayBuffer(buffer);
break;
case GL_ELEMENT_ARRAY_BUFFER:
bindElementArrayBuffer(buffer);
break;
case GL_COPY_READ_BUFFER:
bindCopyReadBuffer(buffer);
break;
case GL_COPY_WRITE_BUFFER:
bindCopyWriteBuffer(buffer);
break;
case GL_PIXEL_PACK_BUFFER:
bindPixelPackBuffer(buffer);
break;
case GL_PIXEL_UNPACK_BUFFER:
bindPixelUnpackBuffer(buffer);
break;
case GL_UNIFORM_BUFFER:
bindGenericUniformBuffer(buffer);
break;
case GL_TRANSFORM_FEEDBACK_BUFFER:
bindGenericTransformFeedbackBuffer(buffer);
break;
default:
UNREACHABLE();
break;
}
}
void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
{
if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
{
bindReadFramebuffer(framebuffer);
}
if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
{
bindDrawFramebuffer(framebuffer);
}
}
void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
{
ASSERT(target == GL_RENDERBUFFER);
Renderbuffer *object =
mResourceManager->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
mGLState.setRenderbufferBinding(object);
}
} // namespace gl
......@@ -125,7 +125,6 @@ class Context final : public ValidationContext
void bindTexture(GLenum target, GLuint handle);
void bindReadFramebuffer(GLuint framebufferHandle);
void bindDrawFramebuffer(GLuint framebufferHandle);
void bindRenderbuffer(GLuint renderbufferHandle);
void bindVertexArray(GLuint vertexArrayHandle);
void bindSampler(GLuint textureUnit, GLuint samplerHandle);
void bindGenericUniformBuffer(GLuint bufferHandle);
......@@ -193,10 +192,6 @@ class Context final : public ValidationContext
bool isSampler(GLuint samplerName) const;
bool isTextureGenerated(GLuint texture) const;
bool isBufferGenerated(GLuint buffer) const;
bool isRenderbufferGenerated(GLuint renderbuffer) const;
bool isFramebufferGenerated(GLuint framebuffer) const;
bool isVertexArrayGenerated(GLuint vertexArray);
bool isTransformFeedbackGenerated(GLuint vertexArray);
......@@ -579,6 +574,10 @@ class Context final : public ValidationContext
void bufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
void bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data);
void attachShader(GLuint program, GLuint shader);
void bindAttribLocation(GLuint program, GLuint index, const GLchar *name);
void bindBuffer(GLenum target, GLuint buffer);
void bindFramebuffer(GLenum target, GLuint framebuffer);
void bindRenderbuffer(GLenum target, GLuint renderbuffer);
void copyBufferSubData(GLenum readTarget,
GLenum writeTarget,
......
......@@ -21,7 +21,8 @@ ContextState::ContextState(uintptr_t contextIn,
const TextureCapsMap &textureCapsIn,
const Extensions &extensionsIn,
const ResourceManager *resourceManagerIn,
const Limitations &limitationsIn)
const Limitations &limitationsIn,
const ResourceMap<Framebuffer> &framebufferMap)
: mClientVersion(clientVersion),
mContext(contextIn),
mState(stateIn),
......@@ -29,7 +30,8 @@ ContextState::ContextState(uintptr_t contextIn,
mTextureCaps(textureCapsIn),
mExtensions(extensionsIn),
mResourceManager(resourceManagerIn),
mLimitations(limitationsIn)
mLimitations(limitationsIn),
mFramebufferMap(framebufferMap)
{
}
......@@ -49,6 +51,7 @@ ValidationContext::ValidationContext(const Version &clientVersion,
const Extensions &extensions,
const ResourceManager *resourceManager,
const Limitations &limitations,
const ResourceMap<Framebuffer> &framebufferMap,
bool skipValidation)
: mState(reinterpret_cast<uintptr_t>(this),
clientVersion,
......@@ -57,7 +60,8 @@ ValidationContext::ValidationContext(const Version &clientVersion,
textureCaps,
extensions,
resourceManager,
limitations),
limitations,
framebufferMap),
mSkipValidation(skipValidation)
{
}
......@@ -590,4 +594,25 @@ Shader *ValidationContext::getShader(GLuint handle) const
return mState.mResourceManager->getShader(handle);
}
bool ValidationContext::isTextureGenerated(GLuint texture) const
{
return mState.mResourceManager->isTextureGenerated(texture);
}
bool ValidationContext::isBufferGenerated(GLuint buffer) const
{
return mState.mResourceManager->isBufferGenerated(buffer);
}
bool ValidationContext::isRenderbufferGenerated(GLuint renderbuffer) const
{
return mState.mResourceManager->isRenderbufferGenerated(renderbuffer);
}
bool ValidationContext::isFramebufferGenerated(GLuint framebuffer) const
{
ASSERT(mState.mFramebufferMap.find(0) != mState.mFramebufferMap.end());
return mState.mFramebufferMap.find(framebuffer) != mState.mFramebufferMap.end();
}
} // namespace gl
......@@ -32,7 +32,8 @@ class ContextState final : public angle::NonCopyable
const TextureCapsMap &textureCaps,
const Extensions &extensions,
const ResourceManager *resourceManager,
const Limitations &limitations);
const Limitations &limitations,
const ResourceMap<Framebuffer> &framebufferMap);
~ContextState();
uintptr_t getContext() const { return mContext; }
......@@ -60,6 +61,7 @@ class ContextState final : public angle::NonCopyable
const Extensions &mExtensions;
const ResourceManager *mResourceManager;
const Limitations &mLimitations;
const ResourceMap<Framebuffer> &mFramebufferMap;
};
class ValidationContext : angle::NonCopyable
......@@ -72,6 +74,7 @@ class ValidationContext : angle::NonCopyable
const Extensions &extensions,
const ResourceManager *resourceManager,
const Limitations &limitations,
const ResourceMap<Framebuffer> &framebufferMap,
bool skipValidation);
virtual ~ValidationContext() {}
......@@ -95,6 +98,11 @@ class ValidationContext : angle::NonCopyable
Program *getProgram(GLuint handle) const;
Shader *getShader(GLuint handle) const;
bool isTextureGenerated(GLuint texture) const;
bool isBufferGenerated(GLuint buffer) const;
bool isRenderbufferGenerated(GLuint renderbuffer) const;
bool isFramebufferGenerated(GLuint framebuffer) const;
protected:
ContextState mState;
bool mSkipValidation;
......
......@@ -3618,4 +3618,78 @@ bool ValidateAttachShader(ValidationContext *context, GLuint program, GLuint sha
return true;
}
bool ValidateBindAttribLocation(ValidationContext *context,
GLuint program,
GLuint index,
const GLchar *name)
{
if (index >= MAX_VERTEX_ATTRIBS)
{
context->handleError(Error(GL_INVALID_VALUE, "Index exceeds MAX_VERTEX_ATTRIBS"));
return false;
}
if (strncmp(name, "gl_", 3) == 0)
{
context->handleError(Error(GL_INVALID_OPERATION, "Cannot Bind built-in attributes"));
return false;
}
return GetValidProgram(context, program) != nullptr;
}
bool ValidateBindBuffer(ValidationContext *context, GLenum target, GLuint buffer)
{
if (!ValidBufferTarget(context, target))
{
context->handleError(Error(GL_INVALID_ENUM, "Invalid Buffer target"));
return false;
}
if (!context->getGLState().isBindGeneratesResourceEnabled() &&
!context->isBufferGenerated(buffer))
{
context->handleError(Error(GL_INVALID_OPERATION, "Buffer was not generated"));
return false;
}
return true;
}
bool ValidateBindFramebuffer(ValidationContext *context, GLenum target, GLuint framebuffer)
{
if (!ValidFramebufferTarget(target))
{
context->handleError(Error(GL_INVALID_ENUM, "Invalid Framebuffer target"));
return false;
}
if (!context->getGLState().isBindGeneratesResourceEnabled() &&
!context->isFramebufferGenerated(framebuffer))
{
context->handleError(Error(GL_INVALID_OPERATION, "Framebuffer was not generated"));
return false;
}
return true;
}
bool ValidateBindRenderbuffer(ValidationContext *context, GLenum target, GLuint renderbuffer)
{
if (target != GL_RENDERBUFFER)
{
context->handleError(Error(GL_INVALID_ENUM, "Invalid Renderbuffer target"));
return false;
}
if (!context->getGLState().isBindGeneratesResourceEnabled() &&
!context->isRenderbufferGenerated(renderbuffer))
{
context->handleError(Error(GL_INVALID_OPERATION, "Renderbuffer was not generated"));
return false;
}
return true;
}
} // namespace gl
......@@ -354,6 +354,13 @@ bool ValidateEnableExtensionANGLE(ValidationContext *context, const GLchar *name
bool ValidateActiveTexture(ValidationContext *context, GLenum texture);
bool ValidateAttachShader(ValidationContext *context, GLuint program, GLuint shader);
bool ValidateBindAttribLocation(ValidationContext *context,
GLuint program,
GLuint index,
const GLchar *name);
bool ValidateBindBuffer(ValidationContext *context, GLenum target, GLuint buffer);
bool ValidateBindFramebuffer(ValidationContext *context, GLenum target, GLuint framebuffer);
bool ValidateBindRenderbuffer(ValidationContext *context, GLenum target, GLuint renderbuffer);
} // namespace gl
......
......@@ -36,6 +36,7 @@ class MockValidationContext : public ValidationContext
const Extensions &extensions,
const ResourceManager *resourceManager,
const Limitations &limitations,
const ResourceMap<Framebuffer> &framebufferMap,
bool skipValidation);
MOCK_METHOD1(handleError, void(const Error &));
......@@ -48,6 +49,7 @@ MockValidationContext::MockValidationContext(const Version &version,
const Extensions &extensions,
const ResourceManager *resourceManager,
const Limitations &limitations,
const ResourceMap<Framebuffer> &framebufferMap,
bool skipValidation)
: ValidationContext(version,
state,
......@@ -56,6 +58,7 @@ MockValidationContext::MockValidationContext(const Version &version,
extensions,
resourceManager,
limitations,
framebufferMap,
skipValidation)
{
}
......@@ -79,6 +82,7 @@ TEST(ValidationESTest, DrawElementsWithMaxIndexGivesError)
TextureCapsMap textureCaps;
Extensions extensions;
Limitations limitations;
ResourceMap<Framebuffer> framebufferMap;
// Set some basic caps.
caps.maxElementIndex = 100;
......@@ -106,7 +110,8 @@ TEST(ValidationESTest, DrawElementsWithMaxIndexGivesError)
state.setProgram(program);
NiceMock<MockValidationContext> testContext(Version(3, 0), &state, caps, textureCaps,
extensions, nullptr, limitations, false);
extensions, nullptr, limitations, framebufferMap,
false);
// Set the expectation for the validation error here.
Error expectedError(GL_INVALID_OPERATION, g_ExceedsMaxElementErrorMessage);
......
......@@ -76,26 +76,13 @@ void GL_APIENTRY BindAttribLocation(GLuint program, GLuint index, const GLchar*
Context *context = GetValidGlobalContext();
if (context)
{
if (index >= MAX_VERTEX_ATTRIBS)
{
context->handleError(Error(GL_INVALID_VALUE));
return;
}
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
return;
}
if (strncmp(name, "gl_", 3) == 0)
if (!context->skipValidation() &&
!ValidateBindAttribLocation(context, program, index, name))
{
context->handleError(Error(GL_INVALID_OPERATION));
return;
}
programObject->bindAttributeLocation(index, name);
context->bindAttribLocation(program, index, name);
}
}
......@@ -106,50 +93,12 @@ void GL_APIENTRY BindBuffer(GLenum target, GLuint buffer)
Context *context = GetValidGlobalContext();
if (context)
{
if (!ValidBufferTarget(context, target))
{
context->handleError(Error(GL_INVALID_ENUM));
return;
}
if (!context->getGLState().isBindGeneratesResourceEnabled() &&
!context->isBufferGenerated(buffer))
if (!context->skipValidation() && !ValidateBindBuffer(context, target, buffer))
{
context->handleError(Error(GL_INVALID_OPERATION, "Buffer was not generated"));
return;
}
switch (target)
{
case GL_ARRAY_BUFFER:
context->bindArrayBuffer(buffer);
return;
case GL_ELEMENT_ARRAY_BUFFER:
context->bindElementArrayBuffer(buffer);
return;
case GL_COPY_READ_BUFFER:
context->bindCopyReadBuffer(buffer);
return;
case GL_COPY_WRITE_BUFFER:
context->bindCopyWriteBuffer(buffer);
return;
case GL_PIXEL_PACK_BUFFER:
context->bindPixelPackBuffer(buffer);
return;
case GL_PIXEL_UNPACK_BUFFER:
context->bindPixelUnpackBuffer(buffer);
return;
case GL_UNIFORM_BUFFER:
context->bindGenericUniformBuffer(buffer);
return;
case GL_TRANSFORM_FEEDBACK_BUFFER:
context->bindGenericTransformFeedbackBuffer(buffer);
return;
default:
context->handleError(Error(GL_INVALID_ENUM));
return;
}
context->bindBuffer(target, buffer);
}
}
......@@ -160,28 +109,12 @@ void GL_APIENTRY BindFramebuffer(GLenum target, GLuint framebuffer)
Context *context = GetValidGlobalContext();
if (context)
{
if (!ValidFramebufferTarget(target))
if (!context->skipValidation() && !ValidateBindFramebuffer(context, target, framebuffer))
{
context->handleError(Error(GL_INVALID_ENUM));
return;
}
if (!context->getGLState().isBindGeneratesResourceEnabled() &&
!context->isFramebufferGenerated(framebuffer))
{
context->handleError(Error(GL_INVALID_OPERATION, "Framebuffer was not generated"));
return;
}
if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
{
context->bindReadFramebuffer(framebuffer);
}
if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
{
context->bindDrawFramebuffer(framebuffer);
}
context->bindFramebuffer(target, framebuffer);
}
}
......@@ -192,20 +125,12 @@ void GL_APIENTRY BindRenderbuffer(GLenum target, GLuint renderbuffer)
Context *context = GetValidGlobalContext();
if (context)
{
if (target != GL_RENDERBUFFER)
{
context->handleError(Error(GL_INVALID_ENUM));
return;
}
if (!context->getGLState().isBindGeneratesResourceEnabled() &&
!context->isRenderbufferGenerated(renderbuffer))
if (!context->skipValidation() && !ValidateBindRenderbuffer(context, target, renderbuffer))
{
context->handleError(Error(GL_INVALID_OPERATION, "Renderbuffer was not generated"));
return;
}
context->bindRenderbuffer(renderbuffer);
context->bindRenderbuffer(target, renderbuffer);
}
}
......@@ -216,7 +141,7 @@ void GL_APIENTRY BindTexture(GLenum target, GLuint texture)
Context *context = GetValidGlobalContext();
if (context)
{
if (!ValidateBindTexture(context, target, texture))
if (!context->skipValidation() && !ValidateBindTexture(context, target, texture))
{
return;
}
......
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