Bug 1167504 - Part 9: Remove BindableName - Queries. r=jgilbert
authorDan Glastonbury <dglastonbury@mozilla.com>
Wed, 03 Jun 2015 12:51:13 +1000
changeset 271028 5756b0cdb987f4f56e6d3d2b69ad6f2716780a5c
parent 271027 d71cc076307e8373ba134e871b098e04fc979a0f
child 271029 f8e64b23ba88473ef31aca975abea63a65af3a21
push id2738
push userwcosta@mozilla.com
push dateWed, 10 Jun 2015 13:39:02 +0000
reviewersjgilbert
bugs1167504
milestone41.0a1
Bug 1167504 - Part 9: Remove BindableName - Queries. r=jgilbert
dom/canvas/WebGLExtensionDisjointTimerQuery.cpp
dom/canvas/WebGLShader.cpp
dom/canvas/WebGLTimerQuery.cpp
dom/canvas/WebGLTimerQuery.h
--- a/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp
+++ b/dom/canvas/WebGLExtensionDisjointTimerQuery.cpp
@@ -88,18 +88,18 @@ WebGLExtensionDisjointTimerQuery::BeginQ
   if (mActiveQuery) {
     mContext->ErrorInvalidOperation("beginQueryEXT: A query is already"
                                     " active.");
     return;
   }
 
   mContext->MakeContextCurrent();
   gl::GLContext* gl = mContext->GL();
-  gl->fBeginQuery(target, query->GLName());
-  query->BindTo(LOCAL_GL_TIME_ELAPSED_EXT);
+  gl->fBeginQuery(target, query->mGLName);
+  query->mTarget = LOCAL_GL_TIME_ELAPSED_EXT;
   mActiveQuery = query;
 }
 
 void
 WebGLExtensionDisjointTimerQuery::EndQueryEXT(GLenum target)
 {
   if (mIsLost)
     return;
@@ -132,18 +132,18 @@ WebGLExtensionDisjointTimerQuery::QueryC
 
   if (target != LOCAL_GL_TIMESTAMP_EXT) {
     mContext->ErrorInvalidEnumInfo("queryCounterEXT: requires"
                                    " TIMESTAMP_EXT.", target);
     return;
   }
 
   mContext->MakeContextCurrent();
-  mContext->GL()->fQueryCounter(query->GLName(), target);
-  query->BindTo(LOCAL_GL_TIMESTAMP_EXT);
+  mContext->GL()->fQueryCounter(query->mGLName, target);
+  query->mTarget = LOCAL_GL_TIMESTAMP_EXT;
 }
 
 void
 WebGLExtensionDisjointTimerQuery::GetQueryEXT(JSContext* cx, GLenum target,
                                               GLenum pname,
                                               JS::MutableHandle<JS::Value> retval)
 {
   if (mIsLost)
@@ -205,25 +205,25 @@ WebGLExtensionDisjointTimerQuery::GetQue
   mContext->MakeContextCurrent();
   // XXX: Note that the query result *may change* within the same task!
   // This does not follow the specification, which states that all calls
   // checking query results must return the same value until the event loop
   // is empty.
   switch (pname) {
   case LOCAL_GL_QUERY_RESULT_EXT: {
     GLuint64 result = 0;
-    mContext->GL()->fGetQueryObjectui64v(query->GLName(),
+    mContext->GL()->fGetQueryObjectui64v(query->mGLName,
                                          LOCAL_GL_QUERY_RESULT_EXT,
                                          &result);
     retval.set(JS::NumberValue(result));
     break;
   }
   case LOCAL_GL_QUERY_RESULT_AVAILABLE_EXT: {
     GLuint avail = 0;
-    mContext->GL()->fGetQueryObjectuiv(query->GLName(),
+    mContext->GL()->fGetQueryObjectuiv(query->mGLName,
                                        LOCAL_GL_QUERY_RESULT_AVAILABLE_EXT,
                                        &avail);
     retval.set(JS::BooleanValue(bool(avail)));
     break;
   }
   default:
     mContext->ErrorInvalidEnumInfo("getQueryObjectEXT: Invalid query"
                                    " property.", pname);
--- a/dom/canvas/WebGLShader.cpp
+++ b/dom/canvas/WebGLShader.cpp
@@ -87,16 +87,21 @@ TranslateWithoutValidation(const nsACStr
         glesslVersion = 100;
     }
 
     std::string reversionedSource = source;
     reversionedSource.erase(versionStrStart, versionStrLen);
 
     switch (glesslVersion) {
     case 100:
+        if (!versionStrLen) {
+            /* According to ARB_ES2_compatibility extension glsl
+             * should accept #version 100 for ES 2 shaders. */
+            reversionedSource.insert(versionStrStart, "#version 100\n");
+        }
         break;
     case 300:
         reversionedSource.insert(versionStrStart, "#version 330\n");
         break;
     default:
         MOZ_CRASH("Bad `glesslVersion`.");
     }
 
--- a/dom/canvas/WebGLTimerQuery.cpp
+++ b/dom/canvas/WebGLTimerQuery.cpp
@@ -15,35 +15,48 @@ namespace mozilla {
 
 JSObject*
 WebGLTimerQuery::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
 {
   return dom::WebGLTimerQueryEXTBinding::Wrap(cx, this, aGivenProto);
 }
 
 WebGLTimerQuery::WebGLTimerQuery(WebGLContext* webgl, GLuint aName)
-  : WebGLBindableName<QueryBinding>(aName)
-  , WebGLContextBoundObject(webgl)
+  : WebGLContextBoundObject(webgl)
+  , mGLName(aName)
+  , mTarget(LOCAL_GL_NONE)
 {
 }
 
+WebGLTimerQuery::~WebGLTimerQuery()
+{
+  DeleteOnce();
+}
+
 WebGLTimerQuery*
 WebGLTimerQuery::Create(WebGLContext* webgl)
 {
   GLuint name = 0;
   webgl->MakeContextCurrent();
   webgl->gl->fGenQueries(1, &name);
   return new WebGLTimerQuery(webgl, name);
 }
 
 void
 WebGLTimerQuery::Delete()
 {
   mContext->MakeContextCurrent();
   mContext->gl->fDeleteQueries(1, &mGLName);
 }
 
+WebGLContext*
+WebGLTimerQuery::GetParentObject() const
+{
+  return Context();
+}
+
+
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLTimerQuery)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLTimerQuery, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLTimerQuery, Release)
 
 } // namespace mozilla
--- a/dom/canvas/WebGLTimerQuery.h
+++ b/dom/canvas/WebGLTimerQuery.h
@@ -9,41 +9,41 @@
 
 #include "nsWrapperCache.h"
 #include "WebGLObjectModel.h"
 
 namespace mozilla {
 
 class WebGLTimerQuery final
   : public nsWrapperCache
-  , public WebGLBindableName<QueryBinding>
   , public WebGLRefCountedObject<WebGLTimerQuery>
   , public WebGLContextBoundObject
 {
 public:
   static WebGLTimerQuery* Create(WebGLContext* webgl);
 
-  // WebGLRefCountedObject
   void Delete();
 
-  // nsWrapperCache
-  WebGLContext* GetParentObject() const {
-    return Context();
-  }
+  bool HasEverBeenBound() const { return mTarget != LOCAL_GL_NONE; }
+  GLenum Target() const { return mTarget; }
+
+  WebGLContext* GetParentObject() const;
 
   // NS
   virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
 
+  const GLenum mGLName;
+
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLTimerQuery)
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLTimerQuery)
 
 private:
   explicit WebGLTimerQuery(WebGLContext* webgl, GLuint aName);
-  ~WebGLTimerQuery() {
-    DeleteOnce();
-  }
+  ~WebGLTimerQuery();
+
+  GLenum mTarget;
 
   friend class WebGLExtensionDisjointTimerQuery;
 };
 
 } // namespace mozilla
 
 #endif // WEBGL_TIMER_QUERY_H_