Commit db2f14c0 by Jamie Madill

Refactor BeginQuery validation out of gl::Context.

Part of our effort to relocate all validation logic to a preliminary pass outside of our state tracking or rendering layers. BUG=angle:571 Change-Id: I5241daef6249910a781e78fd066debe0ab1d3f2b Reviewed-on: https://chromium-review.googlesource.com/199348Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 2e660d56
......@@ -768,6 +768,20 @@ GLuint Context::getArrayBufferHandle() const
return mState.arrayBuffer.id();
}
bool Context::isQueryActive() const
{
for (State::ActiveQueryMap::const_iterator i = mState.activeQueries.begin();
i != mState.activeQueries.end(); i++)
{
if (i->second.get() != NULL)
{
return true;
}
}
return false;
}
GLuint Context::getActiveQuery(GLenum target) const
{
// All query types should already exist in the activeQueries map
......@@ -1356,42 +1370,8 @@ void Context::bindTransformFeedback(GLuint transformFeedback)
void Context::beginQuery(GLenum target, GLuint query)
{
// From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
// of zero, if the active query object name for <target> is non-zero (for the
// targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
// the active query for either target is non-zero), if <id> is the name of an
// existing query object whose type does not match <target>, or if <id> is the
// active query object name for any query type, the error INVALID_OPERATION is
// generated.
// Ensure no other queries are active
// NOTE: If other queries than occlusion are supported, we will need to check
// separately that:
// a) The query ID passed is not the current active query for any target/type
// b) There are no active queries for the requested target (and in the case
// of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
// no query may be active for either if glBeginQuery targets either.
for (State::ActiveQueryMap::iterator i = mState.activeQueries.begin(); i != mState.activeQueries.end(); i++)
{
if (i->second.get() != NULL)
{
return gl::error(GL_INVALID_OPERATION);
}
}
Query *queryObject = getQuery(query, true, target);
// check that name was obtained with glGenQueries
if (!queryObject)
{
return gl::error(GL_INVALID_OPERATION);
}
// check for type mismatch
if (queryObject->getType() != target)
{
return gl::error(GL_INVALID_OPERATION);
}
ASSERT(queryObject);
// set query as active for specified target
mState.activeQueries[target].set(queryObject);
......
......@@ -227,6 +227,7 @@ class Context
GLuint getArrayBufferHandle() const;
bool isQueryActive() const;
GLuint getActiveQuery(GLenum target) const;
void setEnableVertexAttribArray(unsigned int attribNum, bool enabled);
......
......@@ -117,14 +117,9 @@ void __stdcall glBeginQueryEXT(GLenum target, GLuint id)
if (context)
{
if (!ValidQueryType(context, target))
if (!ValidateBeginQuery(context, target, id))
{
return gl::error(GL_INVALID_ENUM);
}
if (id == 0)
{
return gl::error(GL_INVALID_OPERATION);
return;
}
context->beginQuery(target, id);
......@@ -6555,14 +6550,9 @@ void __stdcall glBeginQuery(GLenum target, GLuint id)
return gl::error(GL_INVALID_OPERATION);
}
if (!ValidQueryType(context, target))
if (!ValidateBeginQuery(context, target, id))
{
return gl::error(GL_INVALID_ENUM);
}
if (id == 0)
{
return gl::error(GL_INVALID_OPERATION);
return;
}
context->beginQuery(target, id);
......
......@@ -16,6 +16,7 @@
#include "libGLESv2/Renderbuffer.h"
#include "libGLESv2/formatutils.h"
#include "libGLESv2/main.h"
#include "libGLESv2/Query.h"
#include "common/mathutil.h"
#include "common/utilities.h"
......@@ -874,4 +875,53 @@ bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsize
return true;
}
bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id)
{
if (!ValidQueryType(context, target))
{
return gl::error(GL_INVALID_ENUM, false);
}
if (id == 0)
{
return gl::error(GL_INVALID_OPERATION, false);
}
// From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
// of zero, if the active query object name for <target> is non-zero (for the
// targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
// the active query for either target is non-zero), if <id> is the name of an
// existing query object whose type does not match <target>, or if <id> is the
// active query object name for any query type, the error INVALID_OPERATION is
// generated.
// Ensure no other queries are active
// NOTE: If other queries than occlusion are supported, we will need to check
// separately that:
// a) The query ID passed is not the current active query for any target/type
// b) There are no active queries for the requested target (and in the case
// of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
// no query may be active for either if glBeginQuery targets either.
if (context->isQueryActive())
{
return gl::error(GL_INVALID_OPERATION, false);
}
Query *queryObject = context->getQuery(id, true, target);
// check that name was obtained with glGenQueries
if (!queryObject)
{
return gl::error(GL_INVALID_OPERATION, false);
}
// check for type mismatch
if (queryObject->getType() != target)
{
return gl::error(GL_INVALID_OPERATION, false);
}
return true;
}
}
......@@ -45,6 +45,8 @@ bool ValidateSamplerObjectParameter(GLenum pname);
bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels);
bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id);
}
#endif // LIBGLESV2_VALIDATION_ES_H
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