michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "WebGLObjectModel.h" michael@0: #include "WebGLShader.h" michael@0: #include "WebGLContext.h" michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "mozilla/dom/WebGLRenderingContextBinding.h" michael@0: #include "GLContext.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: JSObject* michael@0: WebGLShader::WrapObject(JSContext *cx) { michael@0: return dom::WebGLShaderBinding::Wrap(cx, this); michael@0: } michael@0: michael@0: WebGLShader::WebGLShader(WebGLContext *context, GLenum stype) michael@0: : WebGLContextBoundObject(context) michael@0: , mType(stype) michael@0: , mNeedsTranslation(true) michael@0: , mAttribMaxNameLength(0) michael@0: , mCompileStatus(false) michael@0: { michael@0: SetIsDOMBinding(); michael@0: mContext->MakeContextCurrent(); michael@0: mGLName = mContext->gl->fCreateShader(mType); michael@0: mContext->mShaders.insertBack(this); michael@0: } michael@0: michael@0: void michael@0: WebGLShader::Delete() { michael@0: mSource.Truncate(); michael@0: mTranslationLog.Truncate(); michael@0: mContext->MakeContextCurrent(); michael@0: mContext->gl->fDeleteShader(mGLName); michael@0: LinkedListElement::removeFrom(mContext->mShaders); michael@0: } michael@0: michael@0: size_t michael@0: WebGLShader::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { michael@0: return aMallocSizeOf(this) + michael@0: mSource.SizeOfExcludingThisIfUnshared(aMallocSizeOf) + michael@0: mTranslationLog.SizeOfExcludingThisIfUnshared(aMallocSizeOf); michael@0: } michael@0: michael@0: void michael@0: WebGLShader::SetTranslationSuccess() { michael@0: mTranslationLog.SetIsVoid(true); michael@0: mNeedsTranslation = false; michael@0: } michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLShader) michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLShader, AddRef) michael@0: NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLShader, Release)