Bug 1308057 - Use pointer-to-query-slot for is-active status. DeleteQuery should clear its slot if it has one. - r=ethlin a=gchang
authorJeff Gilbert (:jgilbert) <jgilbert@mozilla.com>
Mon, 07 Nov 2016 19:38:48 -0800
changeset 359107 297484ad6f716a70464b0811c0b88d34fc871de7
parent 359106 147f7b9a5a14fb8a63458d1ed45b301be8f64549
child 359108 6f9124acacdb28e0da1bc8744ee97d707f9f9909
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersethlin, gchang
bugs1308057
milestone51.0
Bug 1308057 - Use pointer-to-query-slot for is-active status. DeleteQuery should clear its slot if it has one. - r=ethlin a=gchang MozReview-Commit-ID: 9xY6NzwKOz3
dom/canvas/WebGL2ContextQueries.cpp
dom/canvas/WebGLQuery.cpp
dom/canvas/WebGLQuery.h
--- a/dom/canvas/WebGL2ContextQueries.cpp
+++ b/dom/canvas/WebGL2ContextQueries.cpp
@@ -129,20 +129,17 @@ WebGLContext::BeginQuery(GLenum target, 
     if (!slot)
         return;
 
     if (*slot)
         return ErrorInvalidOperation("%s: Query target already active.", funcName);
 
     ////
 
-    if (!query->BeginQuery(target))
-        return;
-
-    *slot = query;
+    query->BeginQuery(target, *slot);
 }
 
 void
 WebGLContext::EndQuery(GLenum target, const char* funcName)
 {
     if (!funcName) {
         funcName = "endQuery";
     }
@@ -154,18 +151,16 @@ WebGLContext::EndQuery(GLenum target, co
     if (!slot)
         return;
 
     const auto& query = *slot;
     if (!query)
         return ErrorInvalidOperation("%s: Query target not active.", funcName);
 
     query->EndQuery();
-
-    *slot = nullptr;
 }
 
 void
 WebGLContext::GetQuery(JSContext* cx, GLenum target, GLenum pname,
                        JS::MutableHandleValue retval, const char* funcName)
 {
     if (!funcName) {
         funcName = "getQuery";
--- a/dom/canvas/WebGLQuery.cpp
+++ b/dom/canvas/WebGLQuery.cpp
@@ -38,17 +38,17 @@ GenQuery(gl::GLContext* gl)
     gl->fGenQueries(1, &ret);
     return ret;
 }
 
 WebGLQuery::WebGLQuery(WebGLContext* webgl)
     : WebGLContextBoundObject(webgl)
     , mGLName(GenQuery(mContext->gl))
     , mTarget(0)
-    , mIsActive(false)
+    , mActiveSlot(nullptr)
     , mCanBeAvailable(false)
 {
     mContext->mQueries.insertBack(this);
 }
 
 void
 WebGLQuery::Delete()
 {
@@ -75,46 +75,46 @@ TargetForDriver(const gl::GLContext* gl,
         return target;
 
     if (gl->IsSupported(gl::GLFeature::occlusion_query2))
         return LOCAL_GL_ANY_SAMPLES_PASSED;
 
     return LOCAL_GL_SAMPLES_PASSED;
 }
 
-bool
-WebGLQuery::BeginQuery(GLenum target)
+void
+WebGLQuery::BeginQuery(GLenum target, WebGLRefPtr<WebGLQuery>& slot)
 {
     const char funcName[] = "beginQuery";
 
     if (mTarget && target != mTarget) {
         mContext->ErrorInvalidOperation("%s: Queries cannot change targets.", funcName);
-        return false;
+        return;
     }
 
     ////
 
     mTarget = target;
-    mIsActive = true;
+    mActiveSlot = &slot;
+    *mActiveSlot = this;
 
     ////
 
     const auto& gl = mContext->gl;
     gl->MakeCurrent();
 
     const auto driverTarget = TargetForDriver(gl, mTarget);
     gl->fBeginQuery(driverTarget, mGLName);
-
-    return true;
 }
 
 void
 WebGLQuery::EndQuery()
 {
-    mIsActive = false;
+    *mActiveSlot = nullptr;
+    mActiveSlot = nullptr;
     mCanBeAvailable = false;
 
     ////
 
     const auto& gl = mContext->gl;
     gl->MakeCurrent();
 
     const auto driverTarget = TargetForDriver(gl, mTarget);
@@ -141,17 +141,17 @@ WebGLQuery::GetQueryParameter(GLenum pna
         return;
     }
 
     if (!mTarget) {
         mContext->ErrorInvalidOperation("%s: Query has never been active.", funcName);
         return;
     }
 
-    if (mIsActive)
+    if (mActiveSlot)
         return mContext->ErrorInvalidOperation("%s: Query is still active.", funcName);
 
     // End of validation
     ////
 
     // We must usually wait for an event loop before the query can be available.
     const bool canBeAvailable = (mCanBeAvailable || gfxPrefs::WebGLImmediateQueries());
     if (!canBeAvailable) {
@@ -221,17 +221,17 @@ WebGLQuery::IsQuery() const
 }
 
 void
 WebGLQuery::DeleteQuery()
 {
     if (IsDeleted())
         return;
 
-    if (mIsActive) {
+    if (mActiveSlot) {
         EndQuery();
     }
 
     RequestDelete();
 }
 
 void
 WebGLQuery::QueryCounter(const char* funcName, GLenum target)
--- a/dom/canvas/WebGLQuery.h
+++ b/dom/canvas/WebGLQuery.h
@@ -22,23 +22,24 @@ class WebGLQuery final
 {
     friend class AvailableRunnable;
     friend class WebGLRefCountedObject<WebGLQuery>;
 
 public:
     const GLuint mGLName;
 private:
     GLenum mTarget;
-    bool mIsActive;
+    WebGLRefPtr<WebGLQuery>* mActiveSlot;
 
     bool mCanBeAvailable; // Track whether the event loop has spun
 
     ////
 public:
-    bool IsActive() const { return mIsActive; }
+    GLenum Target() const { return mTarget; }
+    bool IsActive() const { return bool(mActiveSlot); }
 
     ////
 
     NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLQuery)
     NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLQuery)
 
     explicit WebGLQuery(WebGLContext* webgl);
 
@@ -51,17 +52,17 @@ private:
     void Delete();
 
 public:
     WebGLContext* GetParentObject() const { return mContext; }
     virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
 
     ////
 
-    bool BeginQuery(GLenum target);
+    void BeginQuery(GLenum target, WebGLRefPtr<WebGLQuery>& slot);
     void DeleteQuery();
     void EndQuery();
     void GetQueryParameter(GLenum pname, JS::MutableHandleValue retval) const;
     bool IsQuery() const;
     void QueryCounter(const char* funcName, GLenum target);
 };
 
 } // namespace mozilla