Bug 798187 part 2. Switch WebGLContextAttributes to being a dictionary. r=peterv,bjacob
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 22 Oct 2012 13:08:52 -0400
changeset 111047 0b6a823a8cfe
parent 111046 085bffb67692
child 111048 d7e67c8d00e3
push id23726
push userryanvm@gmail.com
push date2012-10-23 01:41 +0000
treeherdermozilla-central@48502b61a63e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv, bjacob
bugs798187
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 798187 part 2. Switch WebGLContextAttributes to being a dictionary. r=peterv,bjacob
content/canvas/src/WebGLContext.cpp
content/canvas/src/WebGLContext.h
dom/bindings/Bindings.conf
dom/webidl/WebGLRenderingContext.webidl
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -866,58 +866,33 @@ WebGLContext::GetCanvasLayer(nsDisplayLi
     canvasLayer->SetContentFlags(flags);
     canvasLayer->Updated();
 
     mResetLayer = false;
 
     return canvasLayer.forget().get();
 }
 
-JSObject*
-WebGLContext::GetContextAttributes(ErrorResult &rv)
+void
+WebGLContext::GetContextAttributes(dom::WebGLContextAttributes &result)
 {
     if (!IsContextStable())
     {
-        return NULL;
-    }
-
-    JSContext *cx = nsContentUtils::GetCurrentJSContext();
-    if (!cx) {
-        rv.Throw(NS_ERROR_FAILURE);
-        return NULL;
-    }
-
-    JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
-    if (!obj) {
-        rv.Throw(NS_ERROR_FAILURE);
-        return NULL;
+        // XXXbz spec says we should still return our attributes in
+        // this case!  Should we store them all in mOptions?
+        return;
     }
 
     gl::ContextFormat cf = gl->ActualFormat();
-
-    if (!JS_DefineProperty(cx, obj, "alpha", cf.alpha > 0 ? JSVAL_TRUE : JSVAL_FALSE,
-                           NULL, NULL, JSPROP_ENUMERATE) ||
-        !JS_DefineProperty(cx, obj, "depth", cf.depth > 0 ? JSVAL_TRUE : JSVAL_FALSE,
-                           NULL, NULL, JSPROP_ENUMERATE) ||
-        !JS_DefineProperty(cx, obj, "stencil", cf.stencil > 0 ? JSVAL_TRUE : JSVAL_FALSE,
-                           NULL, NULL, JSPROP_ENUMERATE) ||
-        !JS_DefineProperty(cx, obj, "antialias", cf.samples > 1 ? JSVAL_TRUE : JSVAL_FALSE,
-                           NULL, NULL, JSPROP_ENUMERATE) ||
-        !JS_DefineProperty(cx, obj, "premultipliedAlpha",
-                           mOptions.premultipliedAlpha ? JSVAL_TRUE : JSVAL_FALSE,
-                           NULL, NULL, JSPROP_ENUMERATE) ||
-        !JS_DefineProperty(cx, obj, "preserveDrawingBuffer",
-                           mOptions.preserveDrawingBuffer ? JSVAL_TRUE : JSVAL_FALSE,
-                           NULL, NULL, JSPROP_ENUMERATE))
-    {
-        rv.Throw(NS_ERROR_FAILURE);
-        return NULL;
-    }
-
-    return obj;
+    result.alpha = cf.alpha > 0;
+    result.depth = cf.depth > 0;
+    result.stencil = cf.stencil > 0;
+    result.antialias = cf.samples > 1;
+    result.premultipliedAlpha = mOptions.premultipliedAlpha;
+    result.preserveDrawingBuffer = mOptions.preserveDrawingBuffer;
 }
 
 bool
 WebGLContext::IsExtensionEnabled(WebGLExtensionID ext) const {
     return mExtensions.SafeElementAt(ext);
 }
 
 /* [noscript] DOMString mozGetUnderlyingParamString(in WebGLenum pname); */
--- a/content/canvas/src/WebGLContext.h
+++ b/content/canvas/src/WebGLContext.h
@@ -88,16 +88,20 @@ class WebGLContext;
 struct WebGLVertexAttribData;
 class WebGLMemoryPressureObserver;
 class WebGLRectangleObject;
 class WebGLContextBoundObject;
 class WebGLActiveInfo;
 class WebGLShaderPrecisionFormat;
 class WebGLExtensionBase;
 
+namespace dom {
+struct WebGLContextAttributes;
+}
+
 enum FakeBlackStatus { DoNotNeedFakeBlack, DoNeedFakeBlack, DontKnowIfNeedFakeBlack };
 
 struct VertexAttrib0Status {
     enum { Default, EmulatedUninitializedArray, EmulatedInitializedArray };
 };
 
 struct BackbufferClearingStatus {
     enum { NotClearedSinceLastPresented, ClearedToDefaultValues, HasBeenDrawnTo };
@@ -637,17 +641,17 @@ public:
         return mWidth;
     }
     WebGLsizei DrawingBufferHeight() const {
         if (!IsContextStable())
             return 0;
         return mHeight;
     }
         
-    JSObject *GetContextAttributes(ErrorResult &rv);
+    void GetContextAttributes(dom::WebGLContextAttributes& retval);
     bool IsContextLost() const { return !IsContextStable(); }
     void GetSupportedExtensions(JSContext *cx, dom::Nullable< nsTArray<nsString> > &retval);
     JSObject* GetExtension(JSContext* cx, const nsAString& aName, ErrorResult& rv);
     void ActiveTexture(WebGLenum texture);
     void AttachShader(WebGLProgram* program, WebGLShader* shader);
     void BindAttribLocation(WebGLProgram* program, WebGLuint location,
                             const nsAString& name);
     void BindBuffer(WebGLenum target, WebGLBuffer* buf);
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -641,12 +641,10 @@ addExternalIface('SVGLength')
 addExternalIface('SVGMatrix')
 addExternalIface('SVGNumber')
 addExternalIface('SVGPathSeg')
 addExternalIface('SVGPoint')
 addExternalIface('SVGTransform')
 addExternalIface('TextMetrics', headerFile='nsIDOMCanvasRenderingContext2D.h')
 addExternalIface('Touch', headerFile='nsIDOMTouchEvent.h')
 addExternalIface('URI', nativeType='nsIURI', headerFile='nsIURI.h')
-addExternalIface('WebGLContextAttributes', nativeType='JSObject',
-                 headerFile='jsapi.h')
 addExternalIface('Window')
 addExternalIface('XULElement')
--- a/dom/webidl/WebGLRenderingContext.webidl
+++ b/dom/webidl/WebGLRenderingContext.webidl
@@ -17,17 +17,16 @@
 
 // XXXbz all sorts of forward declarations for things that are not new
 // bindings yet.
 interface Event;
 interface HTMLCanvasElement;
 interface HTMLImageElement;
 interface HTMLVideoElement;
 interface ImageData;
-interface WebGLContextAttributes;
 
 typedef unsigned long  GLenum;
 typedef boolean        GLboolean;
 typedef unsigned long  GLbitfield;
 typedef byte           GLbyte;         /* 'byte' should be a signed 8 bit type. */
 typedef short          GLshort;
 typedef long           GLint;
 typedef long           GLsizei;
@@ -35,24 +34,24 @@ typedef long long      GLintptr;
 typedef long long      GLsizeiptr;
 // Ideally the typedef below would use 'unsigned byte', but that doesn't currently exist in Web IDL.
 typedef octet          GLubyte;        /* 'octet' should be an unsigned 8 bit type. */
 typedef unsigned short GLushort;
 typedef unsigned long  GLuint;
 typedef float          GLfloat;
 typedef float          GLclampf;  
 
-/*dictionary WebGLContextAttributes {
+dictionary WebGLContextAttributes {
     boolean alpha = true;
     boolean depth = true;
     boolean stencil = false;
     boolean antialias = true;
     boolean premultipliedAlpha = true;
     boolean preserveDrawingBuffer = false;
-    };*/
+};
 
 interface WebGLBuffer {
 };
 
 interface WebGLFramebuffer {
 };
 
 interface WebGLProgram {
@@ -499,17 +498,17 @@ interface WebGLRenderingContext {
     const GLenum UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243;
     const GLenum BROWSER_DEFAULT_WEBGL          = 0x9244;
 
     // The canvas might actually be null in some cases, apparently.
     readonly attribute HTMLCanvasElement? canvas;
     readonly attribute GLsizei drawingBufferWidth;
     readonly attribute GLsizei drawingBufferHeight;
 
-    [WebGLHandlesContextLoss, Throws] WebGLContextAttributes getContextAttributes();
+    [WebGLHandlesContextLoss] WebGLContextAttributes getContextAttributes();
     [WebGLHandlesContextLoss] boolean isContextLost();
 
     sequence<DOMString>? getSupportedExtensions();
 
     [Throws]
     object? getExtension(DOMString name);
 
     void activeTexture(GLenum texture);