1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/src/WebGLProgram.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,132 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef WEBGLPROGRAM_H_ 1.10 +#define WEBGLPROGRAM_H_ 1.11 + 1.12 +#include "WebGLObjectModel.h" 1.13 + 1.14 +#include "nsWrapperCache.h" 1.15 + 1.16 +#include "mozilla/LinkedList.h" 1.17 +#include "mozilla/CheckedInt.h" 1.18 +#include <map> 1.19 + 1.20 +namespace mozilla { 1.21 + 1.22 +class WebGLShader; 1.23 +class WebGLUniformInfo; 1.24 + 1.25 +typedef nsDataHashtable<nsCStringHashKey, nsCString> CStringMap; 1.26 +typedef nsDataHashtable<nsCStringHashKey, WebGLUniformInfo> CStringToUniformInfoMap; 1.27 + 1.28 +class WebGLProgram MOZ_FINAL 1.29 + : public nsWrapperCache 1.30 + , public WebGLRefCountedObject<WebGLProgram> 1.31 + , public LinkedListElement<WebGLProgram> 1.32 + , public WebGLContextBoundObject 1.33 +{ 1.34 +public: 1.35 + WebGLProgram(WebGLContext *context); 1.36 + 1.37 + ~WebGLProgram() { 1.38 + DeleteOnce(); 1.39 + } 1.40 + 1.41 + void Delete(); 1.42 + 1.43 + void DetachShaders() { 1.44 + mAttachedShaders.Clear(); 1.45 + } 1.46 + 1.47 + GLuint GLName() { return mGLName; } 1.48 + const nsTArray<WebGLRefPtr<WebGLShader> >& AttachedShaders() const { return mAttachedShaders; } 1.49 + bool LinkStatus() { return mLinkStatus; } 1.50 + uint32_t Generation() const { return mGeneration.value(); } 1.51 + void SetLinkStatus(bool val) { mLinkStatus = val; } 1.52 + 1.53 + bool ContainsShader(WebGLShader *shader) { 1.54 + return mAttachedShaders.Contains(shader); 1.55 + } 1.56 + 1.57 + // return true if the shader wasn't already attached 1.58 + bool AttachShader(WebGLShader *shader); 1.59 + 1.60 + // return true if the shader was found and removed 1.61 + bool DetachShader(WebGLShader *shader); 1.62 + 1.63 + bool HasAttachedShaderOfType(GLenum shaderType); 1.64 + 1.65 + bool HasBothShaderTypesAttached() { 1.66 + return 1.67 + HasAttachedShaderOfType(LOCAL_GL_VERTEX_SHADER) && 1.68 + HasAttachedShaderOfType(LOCAL_GL_FRAGMENT_SHADER); 1.69 + } 1.70 + 1.71 + bool HasBadShaderAttached(); 1.72 + 1.73 + size_t UpperBoundNumSamplerUniforms(); 1.74 + 1.75 + bool NextGeneration() 1.76 + { 1.77 + if (!(mGeneration + 1).isValid()) 1.78 + return false; // must exit without changing mGeneration 1.79 + ++mGeneration; 1.80 + return true; 1.81 + } 1.82 + 1.83 + /* Called only after LinkProgram */ 1.84 + bool UpdateInfo(); 1.85 + 1.86 + /* Getters for cached program info */ 1.87 + bool IsAttribInUse(unsigned i) const { return mAttribsInUse[i]; } 1.88 + 1.89 + /* Maps identifier |name| to the mapped identifier |*mappedName| 1.90 + * Both are ASCII strings. 1.91 + */ 1.92 + void MapIdentifier(const nsACString& name, nsCString *mappedName); 1.93 + 1.94 + /* Un-maps mapped identifier |name| to the original identifier |*reverseMappedName| 1.95 + * Both are ASCII strings. 1.96 + */ 1.97 + void ReverseMapIdentifier(const nsACString& name, nsCString *reverseMappedName); 1.98 + 1.99 + /* Returns the uniform array size (or 1 if the uniform is not an array) of 1.100 + * the uniform with given mapped identifier. 1.101 + * 1.102 + * Note: the input string |name| is the mapped identifier, not the original identifier. 1.103 + */ 1.104 + WebGLUniformInfo GetUniformInfoForMappedIdentifier(const nsACString& name); 1.105 + 1.106 + WebGLContext *GetParentObject() const { 1.107 + return Context(); 1.108 + } 1.109 + 1.110 + virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE; 1.111 + 1.112 + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLProgram) 1.113 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLProgram) 1.114 + 1.115 + // public post-link data 1.116 + std::map<GLint, nsCString> mActiveAttribMap; 1.117 + 1.118 +protected: 1.119 + 1.120 + GLuint mGLName; 1.121 + bool mLinkStatus; 1.122 + // attached shaders of the program object 1.123 + nsTArray<WebGLRefPtr<WebGLShader> > mAttachedShaders; 1.124 + CheckedUint32 mGeneration; 1.125 + 1.126 + // post-link data 1.127 + FallibleTArray<bool> mAttribsInUse; 1.128 + nsAutoPtr<CStringMap> mIdentifierMap, mIdentifierReverseMap; 1.129 + nsAutoPtr<CStringToUniformInfoMap> mUniformInfoMap; 1.130 + int mAttribMaxNameLength; 1.131 +}; 1.132 + 1.133 +} // namespace mozilla 1.134 + 1.135 +#endif