Bug 1124430 - Implement GetFragDataLocation. - r=kamidphish
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 26 Jan 2015 17:10:25 -0800
changeset 253022 08f5812826e7bbfe02325782e0199ebf85ce4226
parent 253021 a0f9be26c71e854ab8223bdae6f019ec3cd11dc2
child 253023 783d0fe2770b5bd177c4efaf34db970849117952
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1124430
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1124430 - Implement GetFragDataLocation. - r=kamidphish
dom/canvas/WebGL2ContextPrograms.cpp
dom/canvas/WebGLProgram.cpp
dom/canvas/WebGLProgram.h
--- a/dom/canvas/WebGL2ContextPrograms.cpp
+++ b/dom/canvas/WebGL2ContextPrograms.cpp
@@ -1,19 +1,28 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebGL2Context.h"
-#include "GLContext.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+#include "GLContext.h"
+#include "WebGLProgram.h"
+
+namespace mozilla {
 
 // -------------------------------------------------------------------------
 // Programs and shaders
+
 GLint
-WebGL2Context::GetFragDataLocation(WebGLProgram* program, const nsAString& name)
+WebGL2Context::GetFragDataLocation(WebGLProgram* prog, const nsAString& name)
 {
-    MOZ_CRASH("Not Implemented.");
-    return 0;
+    if (IsContextLost())
+        return -1;
+
+    if (!ValidateObject("getFragDataLocation: program", prog))
+        return -1;
+
+    return prog->GetFragDataLocation(name);
 }
+
+} // namespace mozilla
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -207,16 +207,17 @@ QueryProgramInfo(WebGLProgram* prog, gl:
     return info.forget();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 
 webgl::LinkedProgramInfo::LinkedProgramInfo(WebGLProgram* aProg)
     : prog(aProg)
+    , fragDataMap(nullptr)
 { }
 
 ////////////////////////////////////////////////////////////////////////////////
 // WebGLProgram
 
 static GLuint
 CreateProgram(gl::GLContext* gl)
 {
@@ -412,16 +413,39 @@ WebGLProgram::GetAttribLocation(const ns
     const nsCString& mappedName = info->mBaseMappedName;
 
     gl::GLContext* gl = mContext->GL();
     gl->MakeCurrent();
 
     return gl->fGetAttribLocation(mGLName, mappedName.BeginReading());
 }
 
+GLint
+WebGLProgram::GetFragDataLocation(const nsAString& userName_wide) const
+{
+    if (!ValidateGLSLVariableName(userName_wide, mContext, "getFragDataLocation"))
+        return -1;
+
+    if (!IsLinked()) {
+        mContext->ErrorInvalidOperation("getFragDataLocation: `program` must be linked.");
+        return -1;
+    }
+
+    const NS_LossyConvertUTF16toASCII userName(userName_wide);
+
+    nsCString mappedName;
+    if (!LinkInfo()->FindFragData(userName, &mappedName))
+        return -1;
+
+    gl::GLContext* gl = mContext->GL();
+    gl->MakeCurrent();
+
+    return gl->fGetFragDataLocation(mGLName, mappedName.BeginReading());
+}
+
 void
 WebGLProgram::GetProgramInfoLog(nsAString* const out) const
 {
     CopyASCIItoUTF16(mLinkLog, *out);
 }
 
 static GLint
 GetProgramiv(gl::GLContext* gl, GLuint program, GLenum pname)
--- a/dom/canvas/WebGLProgram.h
+++ b/dom/canvas/WebGLProgram.h
@@ -33,16 +33,17 @@ struct LinkedProgramInfo MOZ_FINAL
     WebGLProgram* const prog;
     std::vector<nsRefPtr<WebGLActiveInfo>> activeAttribs;
     std::vector<nsRefPtr<WebGLActiveInfo>> activeUniforms;
 
     // Needed for Get{Attrib,Uniform}Location. The keys for these are non-mapped
     // user-facing `GLActiveInfo::name`s, without any final "[0]".
     std::map<nsCString, const WebGLActiveInfo*> attribMap;
     std::map<nsCString, const WebGLActiveInfo*> uniformMap;
+    std::map<nsCString, const nsCString>* fragDataMap;
 
     // Needed for draw call validation.
     std::set<GLuint> activeAttribLocs;
 
     explicit LinkedProgramInfo(WebGLProgram* aProg);
 
     bool FindAttrib(const nsCString& baseUserName,
                     const WebGLActiveInfo** const out_activeInfo) const
@@ -61,16 +62,27 @@ struct LinkedProgramInfo MOZ_FINAL
         auto itr = uniformMap.find(baseUserName);
         if (itr == uniformMap.end())
             return false;
 
         *out_activeInfo = itr->second;
         return true;
     }
 
+    bool FindFragData(const nsCString& baseUserName,
+                      nsCString* const out_baseMappedName) const
+    {
+        if (!fragDataMap) {
+            *out_baseMappedName = baseUserName;
+            return true;
+        }
+
+        MOZ_CRASH("Not implemented.");
+    }
+
     bool HasActiveAttrib(GLuint loc) const {
         auto itr = activeAttribLocs.find(loc);
         return itr != activeAttribLocs.end();
     }
 };
 
 } // namespace webgl
 
@@ -95,16 +107,17 @@ public:
     // GL funcs
     void AttachShader(WebGLShader* shader);
     void BindAttribLocation(GLuint index, const nsAString& name);
     void DetachShader(WebGLShader* shader);
     already_AddRefed<WebGLActiveInfo> GetActiveAttrib(GLuint index) const;
     already_AddRefed<WebGLActiveInfo> GetActiveUniform(GLuint index) const;
     void GetAttachedShaders(nsTArray<nsRefPtr<WebGLShader>>* const out) const;
     GLint GetAttribLocation(const nsAString& name) const;
+    GLint GetFragDataLocation(const nsAString& name) const;
     void GetProgramInfoLog(nsAString* const out) const;
     JS::Value GetProgramParameter(GLenum pname) const;
     already_AddRefed<WebGLUniformLocation> GetUniformLocation(const nsAString& name) const;
     bool LinkProgram();
     bool UseProgram() const;
     void ValidateProgram() const;
 
     ////////////////