Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef WEBGLPROGRAM_H_
7 #define WEBGLPROGRAM_H_
9 #include "WebGLObjectModel.h"
11 #include "nsWrapperCache.h"
13 #include "mozilla/LinkedList.h"
14 #include "mozilla/CheckedInt.h"
15 #include <map>
17 namespace mozilla {
19 class WebGLShader;
20 class WebGLUniformInfo;
22 typedef nsDataHashtable<nsCStringHashKey, nsCString> CStringMap;
23 typedef nsDataHashtable<nsCStringHashKey, WebGLUniformInfo> CStringToUniformInfoMap;
25 class WebGLProgram MOZ_FINAL
26 : public nsWrapperCache
27 , public WebGLRefCountedObject<WebGLProgram>
28 , public LinkedListElement<WebGLProgram>
29 , public WebGLContextBoundObject
30 {
31 public:
32 WebGLProgram(WebGLContext *context);
34 ~WebGLProgram() {
35 DeleteOnce();
36 }
38 void Delete();
40 void DetachShaders() {
41 mAttachedShaders.Clear();
42 }
44 GLuint GLName() { return mGLName; }
45 const nsTArray<WebGLRefPtr<WebGLShader> >& AttachedShaders() const { return mAttachedShaders; }
46 bool LinkStatus() { return mLinkStatus; }
47 uint32_t Generation() const { return mGeneration.value(); }
48 void SetLinkStatus(bool val) { mLinkStatus = val; }
50 bool ContainsShader(WebGLShader *shader) {
51 return mAttachedShaders.Contains(shader);
52 }
54 // return true if the shader wasn't already attached
55 bool AttachShader(WebGLShader *shader);
57 // return true if the shader was found and removed
58 bool DetachShader(WebGLShader *shader);
60 bool HasAttachedShaderOfType(GLenum shaderType);
62 bool HasBothShaderTypesAttached() {
63 return
64 HasAttachedShaderOfType(LOCAL_GL_VERTEX_SHADER) &&
65 HasAttachedShaderOfType(LOCAL_GL_FRAGMENT_SHADER);
66 }
68 bool HasBadShaderAttached();
70 size_t UpperBoundNumSamplerUniforms();
72 bool NextGeneration()
73 {
74 if (!(mGeneration + 1).isValid())
75 return false; // must exit without changing mGeneration
76 ++mGeneration;
77 return true;
78 }
80 /* Called only after LinkProgram */
81 bool UpdateInfo();
83 /* Getters for cached program info */
84 bool IsAttribInUse(unsigned i) const { return mAttribsInUse[i]; }
86 /* Maps identifier |name| to the mapped identifier |*mappedName|
87 * Both are ASCII strings.
88 */
89 void MapIdentifier(const nsACString& name, nsCString *mappedName);
91 /* Un-maps mapped identifier |name| to the original identifier |*reverseMappedName|
92 * Both are ASCII strings.
93 */
94 void ReverseMapIdentifier(const nsACString& name, nsCString *reverseMappedName);
96 /* Returns the uniform array size (or 1 if the uniform is not an array) of
97 * the uniform with given mapped identifier.
98 *
99 * Note: the input string |name| is the mapped identifier, not the original identifier.
100 */
101 WebGLUniformInfo GetUniformInfoForMappedIdentifier(const nsACString& name);
103 WebGLContext *GetParentObject() const {
104 return Context();
105 }
107 virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
109 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLProgram)
110 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLProgram)
112 // public post-link data
113 std::map<GLint, nsCString> mActiveAttribMap;
115 protected:
117 GLuint mGLName;
118 bool mLinkStatus;
119 // attached shaders of the program object
120 nsTArray<WebGLRefPtr<WebGLShader> > mAttachedShaders;
121 CheckedUint32 mGeneration;
123 // post-link data
124 FallibleTArray<bool> mAttribsInUse;
125 nsAutoPtr<CStringMap> mIdentifierMap, mIdentifierReverseMap;
126 nsAutoPtr<CStringToUniformInfoMap> mUniformInfoMap;
127 int mAttribMaxNameLength;
128 };
130 } // namespace mozilla
132 #endif