content/canvas/src/WebGLShader.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/src/WebGLShader.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     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 WEBGLSHADER_H_
    1.10 +#define WEBGLSHADER_H_
    1.11 +
    1.12 +#include "WebGLObjectModel.h"
    1.13 +#include "WebGLUniformInfo.h"
    1.14 +
    1.15 +#include "nsWrapperCache.h"
    1.16 +
    1.17 +#include "angle/ShaderLang.h"
    1.18 +
    1.19 +#include "mozilla/LinkedList.h"
    1.20 +#include "mozilla/MemoryReporting.h"
    1.21 +
    1.22 +namespace mozilla {
    1.23 +
    1.24 +struct WebGLMappedIdentifier {
    1.25 +    nsCString original, mapped; // ASCII strings
    1.26 +    WebGLMappedIdentifier(const nsACString& o, const nsACString& m) : original(o), mapped(m) {}
    1.27 +};
    1.28 +
    1.29 +class WebGLShader MOZ_FINAL
    1.30 +    : public nsWrapperCache
    1.31 +    , public WebGLRefCountedObject<WebGLShader>
    1.32 +    , public LinkedListElement<WebGLShader>
    1.33 +    , public WebGLContextBoundObject
    1.34 +{
    1.35 +    friend class WebGLContext;
    1.36 +    friend class WebGLProgram;
    1.37 +
    1.38 +public:
    1.39 +    WebGLShader(WebGLContext *context, GLenum stype);
    1.40 +
    1.41 +    ~WebGLShader() {
    1.42 +        DeleteOnce();
    1.43 +    }
    1.44 +
    1.45 +    size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
    1.46 +
    1.47 +    GLuint GLName() { return mGLName; }
    1.48 +    GLenum ShaderType() { return mType; }
    1.49 +
    1.50 +    void SetSource(const nsAString& src) {
    1.51 +        // XXX do some quick gzip here maybe -- getting this will be very rare
    1.52 +        mSource.Assign(src);
    1.53 +    }
    1.54 +
    1.55 +    const nsString& Source() const { return mSource; }
    1.56 +
    1.57 +    void SetNeedsTranslation() { mNeedsTranslation = true; }
    1.58 +    bool NeedsTranslation() const { return mNeedsTranslation; }
    1.59 +
    1.60 +    void SetCompileStatus (bool status) {
    1.61 +        mCompileStatus = status;
    1.62 +    }
    1.63 +
    1.64 +    void Delete();
    1.65 +
    1.66 +    bool CompileStatus() const {
    1.67 +        return mCompileStatus;
    1.68 +    }
    1.69 +
    1.70 +    void SetTranslationSuccess();
    1.71 +
    1.72 +    void SetTranslationFailure(const nsCString& msg) {
    1.73 +        mTranslationLog.Assign(msg); 
    1.74 +    }
    1.75 +
    1.76 +    const nsCString& TranslationLog() const { return mTranslationLog; }
    1.77 +
    1.78 +    const nsString& TranslatedSource() const { return mTranslatedSource; }
    1.79 +
    1.80 +    WebGLContext *GetParentObject() const {
    1.81 +        return Context();
    1.82 +    }
    1.83 +
    1.84 +    virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
    1.85 +
    1.86 +    NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLShader)
    1.87 +    NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLShader)
    1.88 +
    1.89 +protected:
    1.90 +
    1.91 +    GLuint mGLName;
    1.92 +    GLenum mType;
    1.93 +    nsString mSource;
    1.94 +    nsString mTranslatedSource;
    1.95 +    nsCString mTranslationLog; // The translation log should contain only ASCII characters
    1.96 +    bool mNeedsTranslation;
    1.97 +    nsTArray<WebGLMappedIdentifier> mAttributes;
    1.98 +    nsTArray<WebGLMappedIdentifier> mUniforms;
    1.99 +    nsTArray<WebGLUniformInfo> mUniformInfos;
   1.100 +    int mAttribMaxNameLength;
   1.101 +    bool mCompileStatus;
   1.102 +};
   1.103 +} // namespace mozilla
   1.104 +
   1.105 +#endif

mercurial