Bug 779611 - part 5 - port WebGLTexture to WebIDL bindings - r=bz

This commit is contained in:
Benoit Jacob 2012-10-04 14:45:25 -04:00
parent 187558b373
commit f0b59e1bef
13 changed files with 103 additions and 65 deletions

View File

@ -49,6 +49,7 @@ CPPSRCS += \
WebGLContextReporter.cpp \
WebGLContextValidate.cpp \
WebGLTexelConversions.cpp \
WebGLTexture.cpp \
WebGLElementArrayCache.cpp \
WebGLExtensionBase.cpp \
WebGLExtensionCompressedTextureATC.cpp \

View File

@ -5,6 +5,7 @@
#include "WebGLContext.h"
#include "WebGLExtensions.h"
#include "WebGLContextUtils.h"
#include "nsIConsoleService.h"
#include "nsServiceManagerUtils.h"
@ -1014,7 +1015,7 @@ CompareWebGLExtensionName(const nsACString& name, const char *other)
}
JSObject*
WebGLContext::GetExtension(JSContext *cx, const nsAString& aName)
WebGLContext::GetExtension(JSContext *cx, const nsAString& aName, ErrorResult& rv)
{
if (!IsContextStable())
return nullptr;
@ -1101,14 +1102,7 @@ WebGLContext::GetExtension(JSContext *cx, const nsAString& aName)
mExtensions[ext] = obj;
}
// step 4: return the extension as a JS object
JS::Value v;
JSObject* wrapper = GetWrapper();
JSAutoCompartment ac(cx, wrapper);
if (!WrapNewBindingObject(cx, wrapper, mExtensions[ext], &v)) {
return nullptr;
}
return &v.toObject();
return WebGLObjectAsJSObject(cx, mExtensions[ext].get(), rv);
}
void
@ -1407,16 +1401,7 @@ NS_INTERFACE_MAP_BEGIN(WebGLBuffer)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebGLBuffer)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(WebGLTexture)
NS_IMPL_RELEASE(WebGLTexture)
DOMCI_DATA(WebGLTexture, WebGLTexture)
NS_INTERFACE_MAP_BEGIN(WebGLTexture)
NS_INTERFACE_MAP_ENTRY(nsIWebGLTexture)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebGLTexture)
NS_INTERFACE_MAP_END
// WebGLProgram
NS_IMPL_ADDREF(WebGLProgram)
NS_IMPL_RELEASE(WebGLProgram)
@ -1511,7 +1496,6 @@ NS_IMETHODIMP base::GetName(WebGLuint *aName) \
NS_IMETHODIMP base::SetName(WebGLuint aName) \
{ return NS_ERROR_NOT_IMPLEMENTED; }
NAME_NOT_SUPPORTED(WebGLTexture)
NAME_NOT_SUPPORTED(WebGLBuffer)
NAME_NOT_SUPPORTED(WebGLProgram)
NAME_NOT_SUPPORTED(WebGLShader)

View File

@ -631,7 +631,7 @@ public:
JSObject *GetContextAttributes(ErrorResult &rv);
bool IsContextLost() const { return !IsContextStable(); }
void GetSupportedExtensions(dom::Nullable< nsTArray<nsString> > &retval);
JSObject* GetExtension(JSContext* ctx, const nsAString& aName);
JSObject* GetExtension(JSContext* ctx, const nsAString& aName, ErrorResult& rv);
void ActiveTexture(WebGLenum texture);
void AttachShader(WebGLProgram* program, WebGLShader* shader);
void BindAttribLocation(WebGLProgram* program, WebGLuint location,
@ -1392,6 +1392,11 @@ protected:
void LoseOldestWebGLContextIfLimitExceeded();
void UpdateLastUseIndex();
template <typename WebGLObjectType>
JS::Value WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *, ErrorResult& rv) const;
template <typename WebGLObjectType>
JSObject* WebGLObjectAsJSObject(JSContext *cx, const WebGLObjectType *, ErrorResult& rv) const;
#ifdef XP_MACOSX
// see bug 713305. This RAII helper guarantees that we're on the discrete GPU, during its lifetime
// Debouncing note: we don't want to switch GPUs too frequently, so try to not create and destroy
@ -1574,10 +1579,11 @@ protected:
// NOTE: When this class is switched to new DOM bindings, update the (then-slow)
// WrapObject calls in GetParameter and GetFramebufferAttachmentParameter.
class WebGLTexture MOZ_FINAL
: public nsIWebGLTexture
: public nsISupports
, public WebGLRefCountedObject<WebGLTexture>
, public LinkedListElement<WebGLTexture>
, public WebGLContextBoundObject
, public nsWrapperCache
{
public:
WebGLTexture(WebGLContext *context)
@ -1593,6 +1599,7 @@ public:
, mHaveGeneratedMipmap(false)
, mFakeBlackStatus(DoNotNeedFakeBlack)
{
SetIsDOMBinding();
mContext->MakeContextCurrent();
mContext->gl->fGenTextures(1, &mGLName);
mContext->mTextures.insertBack(this);
@ -1614,8 +1621,14 @@ public:
WebGLuint GLName() { return mGLName; }
GLenum Target() const { return mTarget; }
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBGLTEXTURE
WebGLContext *GetParentObject() const {
return Context();
}
virtual JSObject* WrapObject(JSContext *cx, JSObject *scope, bool *triedToWrap);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WebGLTexture)
protected:

View File

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebGLContext.h"
#include "WebGLContextUtils.h"
#include "nsString.h"
#include "nsDebug.h"
@ -2190,25 +2191,12 @@ WebGLContext::GetParameter(JSContext* cx, WebGLenum pname, ErrorResult& rv)
case LOCAL_GL_TEXTURE_BINDING_2D:
{
JS::Value v;
if (!dom::WrapObject(cx, GetWrapper(),
mBound2DTextures[mActiveTexture].get(), &v)) {
rv = NS_ERROR_FAILURE;
return JS::NullValue();
}
return v;
return WebGLObjectAsJSValue(cx, mBound2DTextures[mActiveTexture].get(), rv);
}
case LOCAL_GL_TEXTURE_BINDING_CUBE_MAP:
{
JS::Value v;
if (!dom::WrapObject(cx, GetWrapper(),
mBoundCubeMapTextures[mActiveTexture].get(),
&v)) {
rv = NS_ERROR_FAILURE;
return JS::NullValue();
}
return v;
return WebGLObjectAsJSValue(cx, mBoundCubeMapTextures[mActiveTexture].get(), rv);
}
default:
@ -2316,14 +2304,7 @@ WebGLContext::GetFramebufferAttachmentParameter(JSContext* cx,
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
{
JS::Value v;
if (!dom::WrapObject(cx, GetWrapper(),
const_cast<WebGLTexture*>(fba.Texture()),
&v)) {
rv = NS_ERROR_FAILURE;
return JS::NullValue();
}
return v;
return WebGLObjectAsJSValue(cx, fba.Texture(), rv);
}
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:

View File

@ -11,7 +11,6 @@
DUMMY(NS_NewCanvasRenderingContextWebGL, nsIDOMWebGLRenderingContext)
DOMCI_DATA(WebGLBuffer, void)
DOMCI_DATA(WebGLTexture, void)
DOMCI_DATA(WebGLProgram, void)
DOMCI_DATA(WebGLShader, void)
DOMCI_DATA(WebGLFramebuffer, void)

View File

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef WEBGLCONTEXTUTILS_H_
#define WEBGLCONTEXTUTILS_H_
#include "WebGLContext.h"
#include "mozilla/Assertions.h"
namespace mozilla {
template <typename WebGLObjectType>
JS::Value
WebGLContext::WebGLObjectAsJSValue(JSContext *cx, const WebGLObjectType *object, ErrorResult& rv) const
{
if (!object) {
return JS::NullValue();
}
MOZ_ASSERT(this == object->Context());
JS::Value v;
JSObject* wrapper = GetWrapper();
JSAutoCompartment ac(cx, wrapper);
if (!WrapNewBindingObject(cx, wrapper, const_cast<WebGLObjectType*>(object), &v)) {
rv.Throw(NS_ERROR_FAILURE);
return JS::NullValue();
}
return v;
}
template <typename WebGLObjectType>
JSObject*
WebGLContext::WebGLObjectAsJSObject(JSContext *cx, const WebGLObjectType *object, ErrorResult& rv) const
{
JS::Value v = WebGLObjectAsJSValue(cx, object, rv);
if (v.isNull()) {
return nullptr;
}
return &v.toObject();
}
} // namespace mozilla
#endif // WEBGLCONTEXTUTILS_H_

View File

@ -0,0 +1,24 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebGLContext.h"
#include "mozilla/dom/WebGLRenderingContextBinding.h"
using namespace mozilla;
JSObject*
WebGLTexture::WrapObject(JSContext *cx, JSObject *scope, bool *triedToWrap) {
return dom::WebGLTextureBinding::Wrap(cx, scope, this, triedToWrap);
}
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLTexture)
NS_IMPL_CYCLE_COLLECTING_ADDREF(WebGLTexture)
NS_IMPL_CYCLE_COLLECTING_RELEASE(WebGLTexture)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebGLTexture)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END

View File

@ -1561,8 +1561,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(WebGLBuffer, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WebGLTexture, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WebGLProgram, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WebGLShader, nsDOMGenericSH,
@ -4220,10 +4218,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIWebGLBuffer)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(WebGLTexture, nsIWebGLTexture)
DOM_CLASSINFO_MAP_ENTRY(nsIWebGLTexture)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(WebGLProgram, nsIWebGLProgram)
DOM_CLASSINFO_MAP_ENTRY(nsIWebGLProgram)
DOM_CLASSINFO_MAP_END

View File

@ -448,7 +448,6 @@ DOMCI_CLASS(MathMLElement)
// WebGL
DOMCI_CLASS(WebGLBuffer)
DOMCI_CLASS(WebGLTexture)
DOMCI_CLASS(WebGLProgram)
DOMCI_CLASS(WebGLShader)
DOMCI_CLASS(WebGLFramebuffer)

View File

@ -396,6 +396,11 @@ DOMInterfaces = {
'wrapperCache': False
},
'WebGLTexture': {
'nativeType': 'mozilla::WebGLTexture',
'headerFile': 'WebGLContext.h'
},
'WebGLUniformLocation': {
'nativeType': 'mozilla::WebGLUniformLocation',
'headerFile': 'WebGLContext.h',
@ -594,7 +599,5 @@ addExternalIface('WebGLRenderbuffer', nativeType='mozilla::WebGLRenderbuffer',
headerFile='WebGLContext.h')
addExternalIface('WebGLShader', nativeType='mozilla::WebGLShader',
headerFile='WebGLContext.h')
addExternalIface('WebGLTexture', nativeType='mozilla::WebGLTexture',
headerFile='WebGLContext.h')
addExternalIface('Window')
addExternalIface('XULElement')

View File

@ -44,12 +44,6 @@ class Element;
// OpenGL object wrappers
//
[scriptable, builtinclass, uuid(0df9f4ed-f5ff-4e51-a6ff-2bd9785a7639)]
interface nsIWebGLTexture : nsISupports
{
[noscript] attribute WebGLuint name;
};
[scriptable, builtinclass, uuid(9eca9c32-8305-11de-b89b-000c29206271)]
interface nsIWebGLBuffer : nsISupports
{

View File

@ -59,7 +59,8 @@ interface WebGLRenderbuffer;
interface WebGLShader;
interface WebGLTexture;
interface WebGLTexture {
};
interface WebGLUniformLocation {
};
@ -499,6 +500,7 @@ interface WebGLRenderingContext {
sequence<DOMString>? getSupportedExtensions();
[Throws]
object? getExtension(DOMString name);
void activeTexture(GLenum texture);

View File

@ -461,7 +461,6 @@ irregularFilenames = {
'nsIDOMBlob': 'nsIDOMFile',
'nsIWebGLTexture': 'nsIDOMWebGLRenderingContext',
'nsIWebGLBuffer': 'nsIDOMWebGLRenderingContext',
'nsIWebGLProgram': 'nsIDOMWebGLRenderingContext',
'nsIWebGLShader': 'nsIDOMWebGLRenderingContext',