Backed out changeset 58dbd2146e24 (bug 944961) for bustage.
[gecko.git] / content / canvas / src / WebGLShader.h
blobef4fe6b3d57b6a53e3e119a82c9c6ebb66f251d2
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 WEBGLSHADER_H_
7 #define WEBGLSHADER_H_
9 #include "WebGLObjectModel.h"
10 #include "WebGLUniformInfo.h"
12 #include "nsWrapperCache.h"
14 #include "angle/ShaderLang.h"
16 #include "mozilla/LinkedList.h"
17 #include "mozilla/MemoryReporting.h"
19 namespace mozilla {
21 struct WebGLMappedIdentifier {
22 nsCString original, mapped; // ASCII strings
23 WebGLMappedIdentifier(const nsACString& o, const nsACString& m) : original(o), mapped(m) {}
26 class WebGLShader MOZ_FINAL
27 : public nsWrapperCache
28 , public WebGLRefCountedObject<WebGLShader>
29 , public LinkedListElement<WebGLShader>
30 , public WebGLContextBoundObject
32 friend class WebGLContext;
33 friend class WebGLProgram;
35 public:
36 WebGLShader(WebGLContext *context, GLenum stype);
38 ~WebGLShader() {
39 DeleteOnce();
42 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
44 GLuint GLName() { return mGLName; }
45 GLenum ShaderType() { return mType; }
47 void SetSource(const nsAString& src) {
48 // XXX do some quick gzip here maybe -- getting this will be very rare
49 mSource.Assign(src);
52 const nsString& Source() const { return mSource; }
54 void SetNeedsTranslation() { mNeedsTranslation = true; }
55 bool NeedsTranslation() const { return mNeedsTranslation; }
57 void SetCompileStatus (bool status) {
58 mCompileStatus = status;
61 void Delete();
63 bool CompileStatus() const {
64 return mCompileStatus;
67 void SetTranslationSuccess();
69 void SetTranslationFailure(const nsCString& msg) {
70 mTranslationLog.Assign(msg);
73 const nsCString& TranslationLog() const { return mTranslationLog; }
75 WebGLContext *GetParentObject() const {
76 return Context();
79 virtual JSObject* WrapObject(JSContext *cx,
80 JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
82 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLShader)
83 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLShader)
85 protected:
87 GLuint mGLName;
88 GLenum mType;
89 nsString mSource;
90 nsCString mTranslationLog; // The translation log should contain only ASCII characters
91 bool mNeedsTranslation;
92 nsTArray<WebGLMappedIdentifier> mAttributes;
93 nsTArray<WebGLMappedIdentifier> mUniforms;
94 nsTArray<WebGLUniformInfo> mUniformInfos;
95 int mAttribMaxNameLength;
96 bool mCompileStatus;
98 } // namespace mozilla
100 #endif