| Index: third_party/WebKit/Source/modules/webgl/WebGLQuery.cpp
|
| diff --git a/third_party/WebKit/Source/modules/webgl/WebGLQuery.cpp b/third_party/WebKit/Source/modules/webgl/WebGLQuery.cpp
|
| index a3a7ab940d4bd9de6a6ac6f5ab36c469ae0f3fb0..74210c35738ac2c759cc92ce4a5deca4f71525af 100644
|
| --- a/third_party/WebKit/Source/modules/webgl/WebGLQuery.cpp
|
| +++ b/third_party/WebKit/Source/modules/webgl/WebGLQuery.cpp
|
| @@ -7,6 +7,7 @@
|
| #include "modules/webgl/WebGLQuery.h"
|
|
|
| #include "modules/webgl/WebGL2RenderingContextBase.h"
|
| +#include "public/platform/Platform.h"
|
|
|
| namespace blink {
|
|
|
| @@ -17,6 +18,8 @@ WebGLQuery* WebGLQuery::create(WebGL2RenderingContextBase* ctx)
|
|
|
| WebGLQuery::~WebGLQuery()
|
| {
|
| + unregisterTaskObserver();
|
| +
|
| // See the comment in WebGLObject::detachAndDeleteObject().
|
| detachAndDeleteObject();
|
| }
|
| @@ -24,6 +27,10 @@ WebGLQuery::~WebGLQuery()
|
| WebGLQuery::WebGLQuery(WebGL2RenderingContextBase* ctx)
|
| : WebGLSharedPlatform3DObject(ctx)
|
| , m_target(0)
|
| + , m_taskObserverRegistered(false)
|
| + , m_canUpdateAvailability(false)
|
| + , m_queryResultAvailable(false)
|
| + , m_queryResult(0)
|
| {
|
| setObject(ctx->webContext()->createQueryEXT());
|
| }
|
| @@ -41,4 +48,70 @@ void WebGLQuery::deleteObjectImpl(WebGraphicsContext3D* context3d)
|
| m_object = 0;
|
| }
|
|
|
| +void WebGLQuery::resetCachedResult()
|
| +{
|
| + m_canUpdateAvailability = false;
|
| + m_queryResultAvailable = false;
|
| + m_queryResult = 0;
|
| + // When this is called, the implication is that we should start
|
| + // keeping track of whether we can update the cached availability
|
| + // and result.
|
| + registerTaskObserver();
|
| +}
|
| +
|
| +void WebGLQuery::updateCachedResult(WebGraphicsContext3D* ctx)
|
| +{
|
| + if (m_queryResultAvailable)
|
| + return;
|
| +
|
| + if (!m_canUpdateAvailability)
|
| + return;
|
| +
|
| + if (!hasTarget())
|
| + return;
|
| +
|
| + // We can only update the cached result when control returns to the browser.
|
| + m_canUpdateAvailability = false;
|
| + GLuint available = 0;
|
| + ctx->getQueryObjectuivEXT(object(), GL_QUERY_RESULT_AVAILABLE_EXT, &available);
|
| + m_queryResultAvailable = !!available;
|
| + if (m_queryResultAvailable) {
|
| + GLuint result = 0;
|
| + ctx->getQueryObjectuivEXT(object(), GL_QUERY_RESULT_EXT, &result);
|
| + m_queryResult = result;
|
| + unregisterTaskObserver();
|
| + }
|
| +}
|
| +
|
| +bool WebGLQuery::isQueryResultAvailable()
|
| +{
|
| + return m_queryResultAvailable;
|
| +}
|
| +
|
| +GLuint WebGLQuery::getQueryResult()
|
| +{
|
| + return m_queryResult;
|
| +}
|
| +
|
| +void WebGLQuery::registerTaskObserver()
|
| +{
|
| + if (!m_taskObserverRegistered) {
|
| + m_taskObserverRegistered = true;
|
| + Platform::current()->currentThread()->addTaskObserver(this);
|
| + }
|
| +}
|
| +
|
| +void WebGLQuery::unregisterTaskObserver()
|
| +{
|
| + if (m_taskObserverRegistered) {
|
| + m_taskObserverRegistered = false;
|
| + Platform::current()->currentThread()->removeTaskObserver(this);
|
| + }
|
| +}
|
| +
|
| +void WebGLQuery::didProcessTask()
|
| +{
|
| + m_canUpdateAvailability = true;
|
| +}
|
| +
|
| } // namespace blink
|
|
|