content/canvas/src/WebGLShader.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/src/WebGLShader.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; 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 +#include "WebGLObjectModel.h"
    1.10 +#include "WebGLShader.h"
    1.11 +#include "WebGLContext.h"
    1.12 +#include "mozilla/MemoryReporting.h"
    1.13 +#include "mozilla/dom/WebGLRenderingContextBinding.h"
    1.14 +#include "GLContext.h"
    1.15 +
    1.16 +using namespace mozilla;
    1.17 +
    1.18 +JSObject*
    1.19 +WebGLShader::WrapObject(JSContext *cx) {
    1.20 +    return dom::WebGLShaderBinding::Wrap(cx, this);
    1.21 +}
    1.22 +
    1.23 +WebGLShader::WebGLShader(WebGLContext *context, GLenum stype)
    1.24 +    : WebGLContextBoundObject(context)
    1.25 +    , mType(stype)
    1.26 +    , mNeedsTranslation(true)
    1.27 +    , mAttribMaxNameLength(0)
    1.28 +    , mCompileStatus(false)
    1.29 +{
    1.30 +    SetIsDOMBinding();
    1.31 +    mContext->MakeContextCurrent();
    1.32 +    mGLName = mContext->gl->fCreateShader(mType);
    1.33 +    mContext->mShaders.insertBack(this);
    1.34 +}
    1.35 +
    1.36 +void
    1.37 +WebGLShader::Delete() {
    1.38 +    mSource.Truncate();
    1.39 +    mTranslationLog.Truncate();
    1.40 +    mContext->MakeContextCurrent();
    1.41 +    mContext->gl->fDeleteShader(mGLName);
    1.42 +    LinkedListElement<WebGLShader>::removeFrom(mContext->mShaders);
    1.43 +}
    1.44 +
    1.45 +size_t
    1.46 +WebGLShader::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
    1.47 +    return aMallocSizeOf(this) +
    1.48 +           mSource.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
    1.49 +           mTranslationLog.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
    1.50 +}
    1.51 +
    1.52 +void
    1.53 +WebGLShader::SetTranslationSuccess() {
    1.54 +    mTranslationLog.SetIsVoid(true);
    1.55 +    mNeedsTranslation = false;
    1.56 +}
    1.57 +
    1.58 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLShader)
    1.59 +
    1.60 +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLShader, AddRef)
    1.61 +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLShader, Release)

mercurial