2012-12-08 12:41:02 -08:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
#ifndef WEBGL_PROGRAM_H_
|
|
|
|
#define WEBGL_PROGRAM_H_
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2014-05-21 19:03:09 -07:00
|
|
|
#include <map>
|
2014-05-12 19:11:40 -07:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2014-05-21 19:03:09 -07:00
|
|
|
#include "mozilla/LinkedList.h"
|
2015-01-15 15:40:39 -08:00
|
|
|
#include "nsString.h"
|
2014-05-21 19:03:09 -07:00
|
|
|
#include "nsWrapperCache.h"
|
2015-01-15 15:40:39 -08:00
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
2014-11-13 20:03:50 -08:00
|
|
|
#include "WebGLObjectModel.h"
|
2014-05-21 19:03:09 -07:00
|
|
|
#include "WebGLShader.h"
|
2012-12-08 12:41:02 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
class WebGLActiveInfo;
|
|
|
|
class WebGLProgram;
|
|
|
|
class WebGLUniformLocation;
|
2013-06-10 13:00:35 -07:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
namespace webgl {
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
struct LinkedProgramInfo MOZ_FINAL
|
|
|
|
: public RefCounted<LinkedProgramInfo>
|
|
|
|
, public SupportsWeakPtr<LinkedProgramInfo>
|
2012-12-08 12:41:02 -08:00
|
|
|
{
|
2015-01-15 15:40:39 -08:00
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(LinkedProgramInfo)
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
WebGLProgram* const prog;
|
|
|
|
std::vector<nsRefPtr<WebGLActiveInfo>> activeAttribs;
|
|
|
|
std::vector<nsRefPtr<WebGLActiveInfo>> activeUniforms;
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
// 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;
|
2015-01-26 17:10:25 -08:00
|
|
|
std::map<nsCString, const nsCString>* fragDataMap;
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
// Needed for draw call validation.
|
|
|
|
std::set<GLuint> activeAttribLocs;
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
explicit LinkedProgramInfo(WebGLProgram* aProg);
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
bool FindAttrib(const nsCString& baseUserName,
|
|
|
|
const WebGLActiveInfo** const out_activeInfo) const
|
|
|
|
{
|
|
|
|
auto itr = attribMap.find(baseUserName);
|
|
|
|
if (itr == attribMap.end())
|
|
|
|
return false;
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
*out_activeInfo = itr->second;
|
|
|
|
return true;
|
|
|
|
}
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
bool FindUniform(const nsCString& baseUserName,
|
|
|
|
const WebGLActiveInfo** const out_activeInfo) const
|
|
|
|
{
|
|
|
|
auto itr = uniformMap.find(baseUserName);
|
|
|
|
if (itr == uniformMap.end())
|
|
|
|
return false;
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
*out_activeInfo = itr->second;
|
|
|
|
return true;
|
2012-12-08 12:41:02 -08:00
|
|
|
}
|
|
|
|
|
2015-01-26 17:10:25 -08:00
|
|
|
bool FindFragData(const nsCString& baseUserName,
|
|
|
|
nsCString* const out_baseMappedName) const
|
|
|
|
{
|
|
|
|
if (!fragDataMap) {
|
|
|
|
*out_baseMappedName = baseUserName;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Not implemented.");
|
|
|
|
}
|
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
bool HasActiveAttrib(GLuint loc) const {
|
|
|
|
auto itr = activeAttribLocs.find(loc);
|
|
|
|
return itr != activeAttribLocs.end();
|
|
|
|
}
|
|
|
|
};
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
} // namespace webgl
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
class WebGLShader;
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
typedef nsDataHashtable<nsCStringHashKey, nsCString> CStringMap;
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
class WebGLProgram MOZ_FINAL
|
|
|
|
: public nsWrapperCache
|
|
|
|
, public WebGLRefCountedObject<WebGLProgram>
|
|
|
|
, public LinkedListElement<WebGLProgram>
|
|
|
|
, public WebGLContextBoundObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLProgram)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLProgram)
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
explicit WebGLProgram(WebGLContext* webgl);
|
2015-01-09 21:03:54 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
void Delete();
|
2015-01-13 00:07:26 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
// 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;
|
2015-01-26 17:10:25 -08:00
|
|
|
GLint GetFragDataLocation(const nsAString& name) const;
|
2015-01-15 15:40:39 -08:00
|
|
|
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;
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
bool FindAttribUserNameByMappedName(const nsACString& mappedName,
|
|
|
|
nsDependentCString* const out_userName) const;
|
|
|
|
bool FindUniformByMappedName(const nsACString& mappedName,
|
|
|
|
nsCString* const out_userName,
|
|
|
|
bool* const out_isArray) const;
|
|
|
|
|
|
|
|
bool IsLinked() const { return mMostRecentLinkInfo; }
|
|
|
|
|
|
|
|
const webgl::LinkedProgramInfo* LinkInfo() const {
|
|
|
|
return mMostRecentLinkInfo.get();
|
|
|
|
}
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLContext* GetParentObject() const {
|
2012-12-08 12:41:02 -08:00
|
|
|
return Context();
|
|
|
|
}
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> aGivenProto) MOZ_OVERRIDE;
|
2014-05-13 17:15:19 -07:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
private:
|
2014-06-26 06:30:49 -07:00
|
|
|
~WebGLProgram() {
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
2012-12-08 12:41:02 -08:00
|
|
|
|
2015-01-15 15:40:39 -08:00
|
|
|
bool LinkAndUpdate();
|
|
|
|
|
|
|
|
public:
|
|
|
|
const GLuint mGLName;
|
|
|
|
|
|
|
|
private:
|
|
|
|
WebGLRefPtr<WebGLShader> mVertShader;
|
|
|
|
WebGLRefPtr<WebGLShader> mFragShader;
|
|
|
|
std::map<nsCString, GLuint> mBoundAttribLocs;
|
|
|
|
nsCString mLinkLog;
|
|
|
|
RefPtr<const webgl::LinkedProgramInfo> mMostRecentLinkInfo;
|
2012-12-08 12:41:02 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
#endif // WEBGL_PROGRAM_H_
|