Commit 45c785d3 by Jamie Madill

Move validation of EndQuery out of gl::Context.

BUG=angle:571 Change-Id: I8913eb1b565a4282d9d84d06933e8b854453f17d Reviewed-on: https://chromium-review.googlesource.com/199349Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent db2f14c0
...@@ -782,13 +782,18 @@ bool Context::isQueryActive() const ...@@ -782,13 +782,18 @@ bool Context::isQueryActive() const
return false; return false;
} }
GLuint Context::getActiveQuery(GLenum target) const const Query *Context::getActiveQuery(GLenum target) const
{ {
// All query types should already exist in the activeQueries map // All query types should already exist in the activeQueries map
ASSERT(mState.activeQueries.find(target) != mState.activeQueries.end()); ASSERT(mState.activeQueries.find(target) != mState.activeQueries.end());
const Query *queryObject = mState.activeQueries.at(target).get(); return mState.activeQueries.at(target).get();
return queryObject ? queryObject->id() : 0; }
GLuint Context::getActiveQueryId(GLenum target) const
{
const Query *query = getActiveQuery(target);
return (query ? query->id() : 0u);
} }
void Context::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) void Context::setEnableVertexAttribArray(unsigned int attribNum, bool enabled)
...@@ -1383,11 +1388,7 @@ void Context::beginQuery(GLenum target, GLuint query) ...@@ -1383,11 +1388,7 @@ void Context::beginQuery(GLenum target, GLuint query)
void Context::endQuery(GLenum target) void Context::endQuery(GLenum target)
{ {
Query *queryObject = mState.activeQueries[target].get(); Query *queryObject = mState.activeQueries[target].get();
ASSERT(queryObject);
if (queryObject == NULL)
{
return gl::error(GL_INVALID_OPERATION);
}
queryObject->end(); queryObject->end();
......
...@@ -228,7 +228,8 @@ class Context ...@@ -228,7 +228,8 @@ class Context
GLuint getArrayBufferHandle() const; GLuint getArrayBufferHandle() const;
bool isQueryActive() const; bool isQueryActive() const;
GLuint getActiveQuery(GLenum target) const; const Query *getActiveQuery(GLenum target) const;
GLuint getActiveQueryId(GLenum target) const;
void setEnableVertexAttribArray(unsigned int attribNum, bool enabled); void setEnableVertexAttribArray(unsigned int attribNum, bool enabled);
const VertexAttribute &getVertexAttribState(unsigned int attribNum) const; const VertexAttribute &getVertexAttribState(unsigned int attribNum) const;
......
...@@ -49,4 +49,9 @@ GLenum Query::getType() const ...@@ -49,4 +49,9 @@ GLenum Query::getType() const
return mQuery->getType(); return mQuery->getType();
} }
bool Query::isStarted() const
{
return mQuery->isStarted();
}
} }
...@@ -38,6 +38,7 @@ class Query : public RefCountObject ...@@ -38,6 +38,7 @@ class Query : public RefCountObject
GLboolean isResultAvailable(); GLboolean isResultAvailable();
GLenum getType() const; GLenum getType() const;
bool isStarted() const;
private: private:
DISALLOW_COPY_AND_ASSIGN(Query); DISALLOW_COPY_AND_ASSIGN(Query);
......
...@@ -1823,9 +1823,9 @@ void __stdcall glEndQueryEXT(GLenum target) ...@@ -1823,9 +1823,9 @@ void __stdcall glEndQueryEXT(GLenum target)
if (context) if (context)
{ {
if (!ValidQueryType(context, target)) if (!ValidateEndQuery(context, target))
{ {
return gl::error(GL_INVALID_ENUM); return;
} }
context->endQuery(target); context->endQuery(target);
...@@ -3118,7 +3118,7 @@ void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params) ...@@ -3118,7 +3118,7 @@ void __stdcall glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
switch (pname) switch (pname)
{ {
case GL_CURRENT_QUERY_EXT: case GL_CURRENT_QUERY_EXT:
params[0] = context->getActiveQuery(target); params[0] = context->getActiveQueryId(target);
break; break;
default: default:
...@@ -3149,7 +3149,7 @@ void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params) ...@@ -3149,7 +3149,7 @@ void __stdcall glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
return gl::error(GL_INVALID_OPERATION); return gl::error(GL_INVALID_OPERATION);
} }
if (context->getActiveQuery(queryObject->getType()) == id) if (context->getActiveQueryId(queryObject->getType()) == id)
{ {
return gl::error(GL_INVALID_OPERATION); return gl::error(GL_INVALID_OPERATION);
} }
...@@ -6554,7 +6554,6 @@ void __stdcall glBeginQuery(GLenum target, GLuint id) ...@@ -6554,7 +6554,6 @@ void __stdcall glBeginQuery(GLenum target, GLuint id)
{ {
return; return;
} }
context->beginQuery(target, id); context->beginQuery(target, id);
} }
} }
...@@ -6579,9 +6578,9 @@ void __stdcall glEndQuery(GLenum target) ...@@ -6579,9 +6578,9 @@ void __stdcall glEndQuery(GLenum target)
return gl::error(GL_INVALID_OPERATION); return gl::error(GL_INVALID_OPERATION);
} }
if (!ValidQueryType(context, target)) if (!ValidateEndQuery(context, target))
{ {
return gl::error(GL_INVALID_ENUM); return;
} }
context->endQuery(target); context->endQuery(target);
...@@ -6616,7 +6615,7 @@ void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params) ...@@ -6616,7 +6615,7 @@ void __stdcall glGetQueryiv(GLenum target, GLenum pname, GLint* params)
switch (pname) switch (pname)
{ {
case GL_CURRENT_QUERY: case GL_CURRENT_QUERY:
params[0] = context->getActiveQuery(target); params[0] = static_cast<GLint>(context->getActiveQueryId(target));
break; break;
default: default:
...@@ -6652,7 +6651,7 @@ void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params) ...@@ -6652,7 +6651,7 @@ void __stdcall glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
return gl::error(GL_INVALID_OPERATION); return gl::error(GL_INVALID_OPERATION);
} }
if (context->getActiveQuery(queryObject->getType()) == id) if (context->getActiveQueryId(queryObject->getType()) == id)
{ {
return gl::error(GL_INVALID_OPERATION); return gl::error(GL_INVALID_OPERATION);
} }
......
...@@ -24,6 +24,7 @@ class QueryImpl ...@@ -24,6 +24,7 @@ class QueryImpl
virtual void end() = 0; virtual void end() = 0;
virtual GLuint getResult() = 0; virtual GLuint getResult() = 0;
virtual GLboolean isResultAvailable() = 0; virtual GLboolean isResultAvailable() = 0;
virtual bool isStarted() const = 0;
GLenum getType() const { return mType; } GLenum getType() const { return mType; }
......
...@@ -59,11 +59,7 @@ void Query11::begin() ...@@ -59,11 +59,7 @@ void Query11::begin()
void Query11::end() void Query11::end()
{ {
if (mQuery == NULL) ASSERT(mQuery);
{
return gl::error(GL_INVALID_OPERATION);
}
mRenderer->getDeviceContext()->End(mQuery); mRenderer->getDeviceContext()->End(mQuery);
mStatus = GL_FALSE; mStatus = GL_FALSE;
...@@ -151,4 +147,9 @@ GLboolean Query11::testQuery() ...@@ -151,4 +147,9 @@ GLboolean Query11::testQuery()
return GL_TRUE; // prevent blocking when query is null return GL_TRUE; // prevent blocking when query is null
} }
bool Query11::isStarted() const
{
return (mQuery != NULL);
}
} }
...@@ -21,10 +21,11 @@ class Query11 : public QueryImpl ...@@ -21,10 +21,11 @@ class Query11 : public QueryImpl
Query11(rx::Renderer11 *renderer, GLenum type); Query11(rx::Renderer11 *renderer, GLenum type);
virtual ~Query11(); virtual ~Query11();
void begin(); virtual void begin();
void end(); virtual void end();
GLuint getResult(); virtual GLuint getResult();
GLboolean isResultAvailable(); virtual GLboolean isResultAvailable();
virtual bool isStarted() const;
private: private:
DISALLOW_COPY_AND_ASSIGN(Query11); DISALLOW_COPY_AND_ASSIGN(Query11);
......
...@@ -43,10 +43,7 @@ void Query9::begin() ...@@ -43,10 +43,7 @@ void Query9::begin()
void Query9::end() void Query9::end()
{ {
if (mQuery == NULL) ASSERT(mQuery);
{
return gl::error(GL_INVALID_OPERATION);
}
HRESULT result = mQuery->Issue(D3DISSUE_END); HRESULT result = mQuery->Issue(D3DISSUE_END);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
...@@ -118,4 +115,9 @@ GLboolean Query9::testQuery() ...@@ -118,4 +115,9 @@ GLboolean Query9::testQuery()
return GL_TRUE; // prevent blocking when query is null return GL_TRUE; // prevent blocking when query is null
} }
bool Query9::isStarted() const
{
return (mQuery != NULL);
}
} }
...@@ -21,10 +21,11 @@ class Query9 : public QueryImpl ...@@ -21,10 +21,11 @@ class Query9 : public QueryImpl
Query9(rx::Renderer9 *renderer, GLenum type); Query9(rx::Renderer9 *renderer, GLenum type);
virtual ~Query9(); virtual ~Query9();
void begin(); virtual void begin();
void end(); virtual void end();
GLuint getResult(); virtual GLuint getResult();
GLboolean isResultAvailable(); virtual GLboolean isResultAvailable();
virtual bool isStarted() const;
private: private:
DISALLOW_COPY_AND_ASSIGN(Query9); DISALLOW_COPY_AND_ASSIGN(Query9);
......
...@@ -924,4 +924,26 @@ bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id) ...@@ -924,4 +924,26 @@ bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id)
return true; return true;
} }
bool ValidateEndQuery(gl::Context *context, GLenum target)
{
if (!ValidQueryType(context, target))
{
return gl::error(GL_INVALID_ENUM, false);
}
const Query *queryObject = context->getActiveQuery(target);
if (queryObject == NULL)
{
return gl::error(GL_INVALID_OPERATION, false);
}
if (!queryObject->isStarted())
{
return gl::error(GL_INVALID_OPERATION, false);
}
return true;
}
} }
...@@ -46,6 +46,7 @@ bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsize ...@@ -46,6 +46,7 @@ bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsize
GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels); GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels);
bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id); bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id);
bool ValidateEndQuery(gl::Context *context, GLenum target);
} }
......
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