npotb; canvas3d updates (osx, linux, some crash fixes)
authorvladimir@pobox.com
Sun, 04 Nov 2007 14:12:44 -0800
changeset 7333 18c57527dab1cdc233eb36976653f36e09299a99
parent 7332 490b1c8f20c943f743c84aff68d204648dc019c6
child 7334 aa0cbac5abd3ded4ac0c703157cc6ce83ad86ecb
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9a9pre
npotb; canvas3d updates (osx, linux, some crash fixes)
extensions/canvas3d/src/Makefile.in
extensions/canvas3d/src/glxew.h
extensions/canvas3d/src/nsCanvasRenderingContextGL.cpp
extensions/canvas3d/src/nsCanvasRenderingContextGL.h
extensions/canvas3d/src/nsCanvasRenderingContextGLES11.cpp
extensions/canvas3d/src/nsCanvasRenderingContextGLWeb20.cpp
extensions/canvas3d/src/nsGLPbuffer.cpp
extensions/canvas3d/src/nsGLPbuffer.h
extensions/canvas3d/test/3dtest1.html
extensions/canvas3d/test/3dtest2.html
extensions/canvas3d/test/3dtest3.html
extensions/canvas3d/test/3dtest4.html
extensions/canvas3d/test/3dtest5.html
--- a/extensions/canvas3d/src/Makefile.in
+++ b/extensions/canvas3d/src/Makefile.in
@@ -73,17 +73,17 @@ REQUIRES	= \
 		layout \
 		widget \
 		locale \
 		pref \
 		view \
 		$(NULL)
 
 ifdef MOZ_X11
-EXTRA_DSO_LIBS += GL
+EXTRA_DSO_LIBS += GL GLU X11
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 # nothing
 endif
 
 ifneq (,$(filter $(MOZ_WIDGET_TOOLKIT),mac cocoa))
 # nothing
@@ -96,37 +96,47 @@ CPPSRCS		= nsCanvas3DModule.cpp \
 		  nsCanvasRenderingContextGL.cpp \
 		  nsCanvasRenderingContextGLES11.cpp \
 		  nsCanvasRenderingContextGLWeb20.cpp \
 		  nsGLPbuffer.cpp \
 		  $(NULL)
 
 DEFINES += -DXPCOM_GLUE -DXPCOM_GLUE_USE_NSPR -DGLEW_MX -DGLEW_STATIC
 
+EXTRA_DSO_LIBS += xpcom
+
 ifdef MOZ_ENABLE_LIBXUL
-EXTRA_DSO_LIBS += js3250 xpcom xul
+ ifneq ($(MOZ_WIDGET_TOOLKIT),cocoa)
+ EXTRA_DSO_LIBS += xul
+ endif
 else
-EXTRA_DSO_LIBS += js3250 xpcom thebes
+EXTRA_DSO_LIBS += thebes
 endif
 
 # Hack for getting an extension built against static vs. dynamic versions of firefox
 ##ifeq (,$(BUILD_STATIC_LIBS))
 #EXTRA_DSO_LIBS += gkgfx
 #endif
 
 include $(topsrcdir)/config/rules.mk
 
+LOCAL_INCLUDES	+= -I$(srcdir)
+
 CFLAGS += $(RTL_FLAGS)
 CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(TK_CFLAGS)
 
 EXTRA_DSO_LIBS += $(NSPR_LIBS)
 
 ifdef MOZ_X11
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 EXTRA_DSO_LDOPTS += opengl32.lib glu32.lib usp10.lib
 endif
 
-ifneq (,$(filter $(MOZ_WIDGET_TOOLKIT),mac cocoa))
+ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
+EXTRA_DSO_LDOPTS += -framework AGL -framework OpenGL
+ ifdef MOZ_ENABLE_LIBXUL
+ EXTRA_DSO_LDOPTS += $(DIST)/bin/XUL
+ endif
 endif
 
-EXTRA_DSO_LDOPTS += $(LIBS_DIR) $(EXTRA_DSO_LIBS) $(XPCOM_GLUE_LDOPTS)
+EXTRA_DSO_LDOPTS += $(LIBS_DIR) $(EXTRA_DSO_LIBS) $(MOZ_JS_LIBS) $(XPCOM_GLUE_LDOPTS)
--- a/extensions/canvas3d/src/glxew.h
+++ b/extensions/canvas3d/src/glxew.h
@@ -57,17 +57,17 @@
 #endif
 
 #define __glxext_h_
 #define __GLX_glx_h__
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/Xmd.h>
-#include <GL/glew.h>
+#include <glew.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /* ---------------------------- GLX_VERSION_1_0 --------------------------- */
 
 #ifndef GLX_VERSION_1_0
--- a/extensions/canvas3d/src/nsCanvasRenderingContextGL.cpp
+++ b/extensions/canvas3d/src/nsCanvasRenderingContextGL.cpp
@@ -466,19 +466,17 @@ void
 nsCanvasRenderingContextGLPrivate::MakeContextCurrent()
 {
     mGLPbuffer->MakeContextCurrent();
 }
 
 void
 nsCanvasRenderingContextGLPrivate::LostCurrentContext(void *closure)
 {
-    nsCanvasRenderingContextGLPrivate* self = (nsCanvasRenderingContextGLPrivate*) closure;
-    //fprintf (stderr, "[this:%p] Lost context\n", closure);
-    fflush (stderr);
+    //nsCanvasRenderingContextGLPrivate* self = (nsCanvasRenderingContextGLPrivate*) closure;
 }
 
 //
 // nsICanvasRenderingContextInternal
 //
 
 NS_IMETHODIMP
 nsCanvasRenderingContextGLPrivate::SetCanvasElement(nsICanvasElement* aParentCanvas)
--- a/extensions/canvas3d/src/nsCanvasRenderingContextGL.h
+++ b/extensions/canvas3d/src/nsCanvasRenderingContextGL.h
@@ -103,17 +103,17 @@ class nsCanvasRenderingContextGLPrivate 
 public:
     nsCanvasRenderingContextGLPrivate();
     virtual ~nsCanvasRenderingContextGLPrivate();
 
     virtual nsICanvasRenderingContextGL *GetSelf() = 0;
 
     virtual PRBool ValidateGL() { return PR_TRUE; }
 
-    inline void MakeContextCurrent();
+    void MakeContextCurrent();
     static void LostCurrentContext(void *closure);
 
     inline GLEWContext *glewGetContext() {
         return mGLPbuffer->glewGetContext();
     }
 
 #ifdef XP_WIN
     inline WGLEWContext *wglewGetContext() {
@@ -328,25 +328,25 @@ public:
     void SetBoolRetVal (PRBool val) {
         if (val)
             SetRetVal(JSVAL_TRUE);
         else
             SetRetVal(JSVAL_FALSE);
     }
 
     void SetRetVal (PRInt32 *vp, PRUint32 len) {
-        nsAutoArrayPtr<jsval> jsvector = new jsval[len];
+        nsAutoArrayPtr<jsval> jsvector(new jsval[len]);
         for (PRUint32 i = 0; i < len; i++)
             jsvector[i] = INT_TO_JSVAL(vp[i]);
         JSObject *jsarr = JS_NewArrayObject(ctx, len, jsvector.get());
         SetRetVal(OBJECT_TO_JSVAL(jsarr));
     }
 
     void SetRetVal (float *fp, PRUint32 len) {
-        nsAutoArrayPtr<jsval> jsvector = new jsval[len];
+        nsAutoArrayPtr<jsval> jsvector(new jsval[len]);
 
         if (!JS_EnterLocalRootScope(ctx))
             return; // XXX ???
 
         for (PRUint32 i = 0; i < len; i++)
             JS_NewDoubleValue(ctx, (jsdouble) fp[i], &jsvector[i]);
         JSObject *jsarr = JS_NewArrayObject(ctx, len, jsvector.get());
         SetRetVal(OBJECT_TO_JSVAL(jsarr));
--- a/extensions/canvas3d/src/nsCanvasRenderingContextGLES11.cpp
+++ b/extensions/canvas3d/src/nsCanvasRenderingContextGLES11.cpp
@@ -156,17 +156,16 @@ NS_INTERFACE_MAP_END
 
 nsresult
 NS_NewCanvasRenderingContextGLES11(nsICanvasRenderingContextGLES11** aResult)
 {
     nsICanvasRenderingContextGLES11* ctx = new nsCanvasRenderingContextGLES11();
     if (!ctx)
         return NS_ERROR_OUT_OF_MEMORY;
 
-    fprintf (stderr, "VVVVV NS_New called\n"); fflush(stderr);
     NS_ADDREF(*aResult = ctx);
     return NS_OK;
 }
 
 nsCanvasRenderingContextGLES11::nsCanvasRenderingContextGLES11()
     : mVertexArrayEnabled(PR_FALSE),
       mNormalArrayEnabled(PR_FALSE),
       mColorArrayEnabled(PR_FALSE),
@@ -188,19 +187,16 @@ nsCanvasRenderingContextGLES11::~nsCanva
     // we need to make sure that everything is destroyed/nulled out,
     // because we won't have a context when destructors finish; destroying
     // some of these may need to call glDeleteBuffers.
     mVertexBuffer = nsnull;
     mNormalBuffer = nsnull;
     mColorBuffer = nsnull;
     for (int i = 0; i < MAX_TEXTURE_UNITS; i++)
         mTexCoordBuffer[i] = nsnull;
-
-    fprintf (stderr, "VVVVV ~nsCanvasRenderingContextGLES11\n");
-    fflush (stderr);
 }
 
 //
 // Windowing system lookalike functions
 //
 
 NS_IMETHODIMP
 nsCanvasRenderingContextGLES11::SwapBuffers()
@@ -460,21 +456,16 @@ nsCanvasRenderingContextGLES11::VertexPo
 
     MakeContextCurrent();
     glVertexPointer(newBuffer->GetSimpleBuffer().sizePerVertex,
                     newBuffer->GetSimpleBuffer().type,
                     0,
                     newBuffer->GetSimpleBuffer().data);
 
 }
-    (mVertexBuffer.get())->AddRef();
-    nsrefcnt kk = (mVertexBuffer.get())->Release();
-    fprintf (stderr, "VVVVV After VertexPointer: mVertexBuffer: %p refcount: %d\n", mVertexBuffer, kk);
-    fflush(stderr);
-
     return NS_OK;
 }
 
 /* void normalPointer (); */
 NS_IMETHODIMP
 nsCanvasRenderingContextGLES11::NormalPointer()
 {
     NativeJSContext js;
@@ -705,17 +696,17 @@ nsCanvasRenderingContextGLES11::DrawElem
         return NS_ERROR_DOM_SYNTAX_ERR;
 
     // we're always going to do this as GL_UNSIGNED_SHORT
     SimpleBuffer indexBuffer;
     JSArrayToSimpleBuffer(indexBuffer, GL_UNSIGNED_SHORT, 1, js.ctx, arrayObj, countParam);
 
     // verify that the indices are valid; we should skip this step
     // if the caller is trusted
-    PRUint32 vLen, nLen, cLen;
+    PRUint32 vLen = 0, nLen = 0, cLen = 0;
 
     if (mVertexBuffer)
         vLen = mVertexBuffer->mLength / mVertexBuffer->mSize;
     if (mNormalBuffer)
         nLen = mNormalBuffer->mLength / 3;
     if (mColorBuffer)
         cLen = mColorBuffer->mLength / 4;
 
@@ -1142,17 +1133,17 @@ nsCanvasRenderingContextGLES11::TexImage
     } else if (GLEW_ARB_texture_rectangle && target == GL_TEXTURE_RECTANGLE_ARB) {
         if (width == 0 || height == 0)
             return NS_ERROR_INVALID_ARG;
     } else {
         return NS_ERROR_INVALID_ARG;
     }
 
     if (!image_data) {
-        nsRefPtr<gfxImageSurface> tmpImageSurface =
+        tmpImageSurface =
             CanvasGLThebes::CreateImageSurface(gfxIntSize(width, height),
                                                gfxASurface::ImageFormatARGB32);
         nsRefPtr<gfxContext> cx =
             CanvasGLThebes::CreateContext(tmpImageSurface);
         cx->SetSource(surf);
         cx->SetOperator(gfxContext::OPERATOR_SOURCE);
         cx->Paint();
 
@@ -1340,17 +1331,17 @@ nsCanvasRenderingContextGLES11::GenTextu
         return NS_OK;
 
     NativeJSContext js;
     if (NS_FAILED(js.error))
         return js.error;
 
     MakeContextCurrent();
 
-    nsAutoArrayPtr<PRUint32> textures(new PRUint32[n]);
+    nsAutoArrayPtr<GLuint> textures(new GLuint[n]);
     glGenTextures(n, textures.get());
 
     nsAutoArrayPtr<jsval> jsvector(new jsval[n]);
     for (PRUint32 i = 0; i < n; i++)
         jsvector[i] = INT_TO_JSVAL(textures[i]);
 
     JSObject *obj = JS_NewArrayObject(js.ctx, n, jsvector);
     jsval *retvalPtr;
@@ -1805,17 +1796,17 @@ nsCanvasRenderingContextGLES11::GenBuffe
     if (NS_FAILED(js.error))
         return js.error;
 
     if (n == 0)
         return NS_OK;
 
     MakeContextCurrent();
 
-    nsAutoArrayPtr<PRUint32> buffers(new PRUint32[n]);
+    nsAutoArrayPtr<GLuint> buffers(new GLuint[n]);
     glGenBuffers(n, buffers.get());
 
     nsAutoArrayPtr<jsval> jsvector(new jsval[n]);
     for (PRUint32 i = 0; i < n; i++)
         jsvector[i] = INT_TO_JSVAL(buffers[i]);
 
     JSObject *obj = JS_NewArrayObject(js.ctx, n, jsvector);
     jsval *retvalPtr;
@@ -1831,18 +1822,18 @@ nsCanvasRenderingContextGLES11::DeleteBu
 {
     NativeJSContext js;
     if (NS_FAILED(js.error))
         return js.error;
 
     if (js.argc != 1)
         return NS_ERROR_DOM_SYNTAX_ERR;
 
-    JSObject *arrayObj;
-    jsuint arrayLen;
+    JSObject *arrayObj = nsnull;
+    jsuint arrayLen = 0;
     if (JSValToJSArrayAndLength(js.ctx, js.argv[0], &arrayObj, &arrayLen)) {
         return NS_ERROR_DOM_SYNTAX_ERR;
     }
 
     if (arrayLen == 0)
         return NS_OK;
 
     SimpleBuffer sbuffer;
--- a/extensions/canvas3d/src/nsCanvasRenderingContextGLWeb20.cpp
+++ b/extensions/canvas3d/src/nsCanvasRenderingContextGLWeb20.cpp
@@ -266,25 +266,25 @@ nsCanvasRenderingContextGLWeb20::BufferS
     if (NS_FAILED(rv))
         return NS_ERROR_DOM_SYNTAX_ERR;
 
     MakeContextCurrent();
     glBufferSubData(target, offset, sbuffer.length * sbuffer.ElementSize(), sbuffer.data);
     return NS_OK;
 }
 
-GL_SAME_METHOD_1(Clear, Clear, PRUint32);
+GL_SAME_METHOD_1(Clear, Clear, PRUint32)
 
-GL_SAME_METHOD_4(ClearColor, ClearColor, float, float, float, float);
+GL_SAME_METHOD_4(ClearColor, ClearColor, float, float, float, float)
 
-GL_SAME_METHOD_1(ClearDepth, ClearDepth, float);
+GL_SAME_METHOD_1(ClearDepth, ClearDepth, float)
 
-GL_SAME_METHOD_1(ClearStencil, ClearStencil, PRInt32);
+GL_SAME_METHOD_1(ClearStencil, ClearStencil, PRInt32)
 
-GL_SAME_METHOD_4(ColorMask, ColorMask, PRBool, PRBool, PRBool, PRBool);
+GL_SAME_METHOD_4(ColorMask, ColorMask, PRBool, PRBool, PRBool, PRBool)
 
 NS_IMETHODIMP
 nsCanvasRenderingContextGLWeb20::CreateProgram(PRUint32 *retval)
 {
     MakeContextCurrent();
     *retval = glCreateProgram();
     return NS_OK;
 }
@@ -292,17 +292,17 @@ nsCanvasRenderingContextGLWeb20::CreateP
 NS_IMETHODIMP
 nsCanvasRenderingContextGLWeb20::CreateShader(PRUint32 type, PRUint32 *retval)
 {
     MakeContextCurrent();
     *retval = glCreateShader(type);
     return NS_OK;
 }
 
-GL_SAME_METHOD_1(CullFace, CullFace, PRUint32);
+GL_SAME_METHOD_1(CullFace, CullFace, PRUint32)
 
 NS_IMETHODIMP
 nsCanvasRenderingContextGLWeb20::DeleteBuffers()
 {
     NativeJSContext js;
     if (NS_FAILED(js.error))
         return js.error;
 
@@ -420,26 +420,26 @@ NS_IMETHODIMP
 nsCanvasRenderingContextGLWeb20::GetActiveAttrib(PRUint32 program, PRUint32 index)
 {
     NativeJSContext js;
     if (NS_FAILED(js.error))
         return js.error;
 
     MakeContextCurrent();
 
-    int len;
+    GLint len;
     glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &len);
     if (len == 0)
         return NS_ERROR_FAILURE;
 
-    nsAutoArrayPtr<char> name = new char[len+1];
+    nsAutoArrayPtr<char> name(new char[len+1]);
     PRInt32 attrsize;
     PRUint32 attrtype;
 
-    glGetActiveAttrib(program, index, len+1, &len, &attrsize, &attrtype, name);
+    glGetActiveAttrib(program, index, len+1, &len, (GLint*) &attrsize, (GLuint*) &attrtype, name);
 
     JSObjectHelper retobj(&js);
     retobj.DefineProperty("size", attrsize);
     retobj.DefineProperty("type", attrtype);
     retobj.DefineProperty("name", name, len);
 
     js.SetRetVal(OBJECT_TO_JSVAL(retobj.Object()));
 
@@ -450,26 +450,26 @@ NS_IMETHODIMP
 nsCanvasRenderingContextGLWeb20::GetActiveUniform(PRUint32 program, PRUint32 index)
 {
     NativeJSContext js;
     if (NS_FAILED(js.error))
         return js.error;
 
     MakeContextCurrent();
 
-    int len;
+    GLint len;
     glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &len);
     if (len == 0)
         return NS_ERROR_FAILURE;
 
-    nsAutoArrayPtr<char> name = new char[len+1];
+    nsAutoArrayPtr<char> name(new char[len+1]);
     PRInt32 attrsize;
     PRUint32 attrtype;
 
-    glGetActiveUniform(program, index, len+1, &len, &attrsize, &attrtype, name);
+    glGetActiveUniform(program, index, len+1, &len, (GLint*) &attrsize, (GLenum*) &attrtype, name);
 
     JSObjectHelper retobj(&js);
     retobj.DefineProperty("size", attrsize);
     retobj.DefineProperty("type", attrtype);
     retobj.DefineProperty("name", name, len);
 
     js.SetRetVal(OBJECT_TO_JSVAL(retobj.Object()));
 
@@ -480,22 +480,22 @@ NS_IMETHODIMP
 nsCanvasRenderingContextGLWeb20::GetAttachedShaders(PRUint32 program)
 {
     NativeJSContext js;
     if (NS_FAILED(js.error))
         return js.error;
 
     MakeContextCurrent();
 
-    int count;
+    GLint count;
     glGetProgramiv(program, GL_ATTACHED_SHADERS, &count);
 
-    nsAutoArrayPtr<PRUint32> shaders = new PRUint32[count];
+    nsAutoArrayPtr<PRUint32> shaders(new PRUint32[count]);
 
-    glGetAttachedShaders(program, count, NULL, shaders);
+    glGetAttachedShaders(program, count, NULL, (GLuint*) shaders.get());
 
     JSObject *obj = ArrayToJSArray(js.ctx, shaders, count);
 
     js.AddGCRoot(obj, "GetAttachedShaders");
     js.SetRetVal(OBJECT_TO_JSVAL(obj));
     js.ReleaseGCRoot(obj);
 
     return NS_OK;
@@ -599,17 +599,17 @@ nsCanvasRenderingContextGLWeb20::GetPara
         case GL_DEPTH_BITS:
         case GL_STENCIL_BITS:
         //case GL_IMPLEMENTATION_COLOR_READ_TYPE:
         //case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
         ////case GL_RENDERBUFFER_BINDING:
         ////case GL_FRAMEBUFFER_BINDING:
         {
             PRInt32 iv;
-            glGetIntegerv(pname, &iv);
+            glGetIntegerv(pname, (GLint*) &iv);
             js.SetRetVal(iv);
         }
             break;
 
 // float
         case GL_LINE_WIDTH:
         case GL_POLYGON_OFFSET_FACTOR:
         case GL_POLYGON_OFFSET_UNITS:
@@ -652,26 +652,26 @@ nsCanvasRenderingContextGLWeb20::GetPara
             glGetFloatv(pname, &fv[0]);
             js.SetRetVal(fv, 4);
         }
             break;
 
         case GL_MAX_VIEWPORT_DIMS: // 2 ints
         {
             PRInt32 iv[2];
-            glGetIntegerv(pname, &iv[0]);
+            glGetIntegerv(pname, (GLint*) &iv[0]);
             js.SetRetVal(iv, 2);
         }
             break;
 
         case GL_SCISSOR_BOX: // 4 ints
         case GL_VIEWPORT: // 4 ints
         {
             PRInt32 iv[4];
-            glGetIntegerv(pname, &iv[0]);
+            glGetIntegerv(pname, (GLint*) &iv[0]);
             js.SetRetVal(iv, 4);
         }
             break;
 
         default:
             return NS_ERROR_NOT_IMPLEMENTED;
     }
 
@@ -689,17 +689,17 @@ nsCanvasRenderingContextGLWeb20::GetBuff
 
     switch (pname) {
         case GL_BUFFER_SIZE:
         case GL_BUFFER_USAGE:
         case GL_BUFFER_ACCESS:
         case GL_BUFFER_MAPPED:
         {
             PRInt32 iv;
-            glGetBufferParameteriv(target, pname, &iv);
+            glGetBufferParameteriv(target, pname, (GLint*) &iv);
             js.SetRetVal(iv);
         }
             break;
 
         default:
             return NS_ERROR_NOT_IMPLEMENTED;
     }
 
@@ -714,17 +714,17 @@ nsCanvasRenderingContextGLWeb20::GenBuff
         return js.error;
 
     if (n == 0)
         return NS_OK;
 
     MakeContextCurrent();
 
     nsAutoArrayPtr<PRUint32> buffers(new PRUint32[n]);
-    glGenBuffers(n, buffers.get());
+    glGenBuffers(n, (GLuint*) buffers.get());
 
     nsAutoArrayPtr<jsval> jsvector(new jsval[n]);
     for (PRUint32 i = 0; i < n; i++)
         jsvector[i] = INT_TO_JSVAL(buffers[i]);
 
     JSObject *obj = JS_NewArrayObject(js.ctx, n, jsvector);
     jsval *retvalPtr;
     js.ncc->GetRetValPtr(&retvalPtr);
@@ -742,17 +742,17 @@ nsCanvasRenderingContextGLWeb20::GenText
 
     NativeJSContext js;
     if (NS_FAILED(js.error))
         return js.error;
 
     MakeContextCurrent();
 
     nsAutoArrayPtr<PRUint32> textures(new PRUint32[n]);
-    glGenTextures(n, textures.get());
+    glGenTextures(n, (GLuint*) textures.get());
 
     nsAutoArrayPtr<jsval> jsvector(new jsval[n]);
     for (PRUint32 i = 0; i < n; i++)
         jsvector[i] = INT_TO_JSVAL(textures[i]);
 
     JSObject *obj = JS_NewArrayObject(js.ctx, n, jsvector);
     jsval *retvalPtr;
     js.ncc->GetRetValPtr(&retvalPtr);
@@ -787,17 +787,17 @@ nsCanvasRenderingContextGLWeb20::GetProg
         case GL_ATTACHED_SHADERS:
         case GL_INFO_LOG_LENGTH:
         case GL_ACTIVE_UNIFORMS:
         case GL_ACTIVE_UNIFORM_MAX_LENGTH:
         case GL_ACTIVE_ATTRIBUTES:
         case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
         {
             PRInt32 iv;
-            glGetProgramiv(program, pname, &iv);
+            glGetProgramiv(program, pname, (GLint*) &iv);
             js.SetRetVal(iv);
         }
             break;
 
         default:
             return NS_ERROR_NOT_IMPLEMENTED;
     }
 
@@ -806,25 +806,25 @@ nsCanvasRenderingContextGLWeb20::GetProg
 
 NS_IMETHODIMP
 nsCanvasRenderingContextGLWeb20::GetProgramInfoLog(PRUint32 program, char **retval)
 {
     PRInt32 k;
 
     MakeContextCurrent();
 
-    glGetProgramiv(program, GL_INFO_LOG_LENGTH, &k);
+    glGetProgramiv(program, GL_INFO_LOG_LENGTH, (GLint*) &k);
     if (k == 0) {
         *retval = nsnull;
         return NS_OK;
     }
 
     char *s = (char *) PR_Malloc(k);
 
-    glGetProgramInfoLog(program, k, &k, s);
+    glGetProgramInfoLog(program, k, (GLint*) &k, s);
 
     *retval = s;
     return NS_OK;
 }
 
 /* void texParameter (); */
 NS_IMETHODIMP
 nsCanvasRenderingContextGLWeb20::TexParameter()
@@ -925,17 +925,17 @@ nsCanvasRenderingContextGLWeb20::GetTexP
 
     switch (pname) {
         case GL_TEXTURE_MIN_FILTER:
         case GL_TEXTURE_MAG_FILTER:
         case GL_TEXTURE_WRAP_S:
         case GL_TEXTURE_WRAP_T:
         {
             PRInt32 iv;
-            glGetTexParameteriv(target, pname, &iv);
+            glGetTexParameteriv(target, pname, (GLint*) &iv);
             js.SetRetVal(iv);
         }
             break;
 
         default:
             return NS_ERROR_NOT_IMPLEMENTED;
     }
 
@@ -1056,17 +1056,17 @@ nsCanvasRenderingContextGLWeb20::TexImag
     } else if (GLEW_ARB_texture_rectangle && target == GL_TEXTURE_RECTANGLE_ARB) {
         if (width == 0 || height == 0)
             return NS_ERROR_INVALID_ARG;
     } else {
         return NS_ERROR_INVALID_ARG;
     }
 
     if (!image_data) {
-        nsRefPtr<gfxImageSurface> tmpImageSurface =
+        tmpImageSurface =
             CanvasGLThebes::CreateImageSurface(gfxIntSize(width, height),
                                                gfxASurface::ImageFormatARGB32);
         nsRefPtr<gfxContext> cx =
             CanvasGLThebes::CreateContext(tmpImageSurface);
         cx->SetSource(surf);
         cx->SetOperator(gfxContext::OPERATOR_SOURCE);
         cx->Paint();
 
@@ -1320,17 +1320,17 @@ nsCanvasRenderingContextGLWeb20::GetShad
     switch (pname) {
         case GL_SHADER_TYPE:
         case GL_DELETE_STATUS:
         case GL_COMPILE_STATUS:
         case GL_INFO_LOG_LENGTH:
         case GL_SHADER_SOURCE_LENGTH:
         {
             PRInt32 iv;
-            glGetShaderiv(shader, pname, &iv);
+            glGetShaderiv(shader, pname, (GLint*) &iv);
             js.SetRetVal(iv);
         }
             break;
 
         default:
             return NS_ERROR_NOT_IMPLEMENTED;
     }
 
@@ -1339,21 +1339,21 @@ nsCanvasRenderingContextGLWeb20::GetShad
 
 NS_IMETHODIMP
 nsCanvasRenderingContextGLWeb20::GetShaderInfoLog(PRUint32 shader, char **retval)
 {
     PRInt32 k;
 
     MakeContextCurrent();
 
-    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &k);
+    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, (GLint*) &k);
 
     char *s = (char *) PR_Malloc(k);
 
-    glGetShaderInfoLog(shader, k, &k, s);
+    glGetShaderInfoLog(shader, k, (GLint*) &k, s);
 
     *retval = s;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsCanvasRenderingContextGLWeb20::GetShaderSource(PRUint32 shader, char **retval)
 {
@@ -1456,16 +1456,13 @@ PRBool
 nsCanvasRenderingContextGLWeb20::ValidateGL()
 {
     // make sure that the opengl stuff that we need is supported
     if (!GLEW_VERSION_2_0)
         return PR_FALSE;
 
     GLint val;
     glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &val);
+    fprintf (stderr, "-- %d vertex buffers\n", val);
     mAttribBuffers.SetLength(val);
 
-    MakeContextCurrent();
-    if (mPrefWireframe)
-        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-
     return PR_TRUE;
 }
--- a/extensions/canvas3d/src/nsGLPbuffer.cpp
+++ b/extensions/canvas3d/src/nsGLPbuffer.cpp
@@ -44,20 +44,24 @@
 
 #include "gfxContext.h"
 
 void *nsGLPbuffer::sCurrentContextToken = nsnull;
 
 static PRUint32 gActiveBuffers = 0;
 
 nsGLPbuffer::nsGLPbuffer()
-    : mWidth(0), mHeight(0),
+    : mWidth(0), mHeight(0)
 #ifdef XP_WIN
-    mGlewWindow(nsnull), mGlewDC(nsnull), mGlewWglContext(nsnull),
+    , mGlewWindow(nsnull), mGlewDC(nsnull), mGlewWglContext(nsnull),
     mPbuffer(nsnull), mPbufferDC(nsnull), mPbufferContext(nsnull)
+#elif defined(XP_UNIX) && defined(MOZ_X11)
+    , mDisplay(nsnull), mFBConfig(0), mPbuffer(0), mPbufferContext(0)
+#elif defined(XP_MACOSX)
+    , mContext(nsnull), mPbuffer(nsnull)
 #endif
 {
     gActiveBuffers++;
     fprintf (stderr, "nsGLPbuffer: gActiveBuffers: %d\n", gActiveBuffers);
 }
 
 PRBool
 nsGLPbuffer::Init(nsCanvasRenderingContextGLPrivate *priv)
@@ -125,16 +129,81 @@ nsGLPbuffer::Init(nsCanvasRenderingConte
     if (wglewInit() != GLEW_OK) {
         mPriv->LogMessage(NS_LITERAL_CSTRING("Canvas 3D: WGLEW init failed"));
         return PR_FALSE;
     }
 
     PRInt64 t2 = PR_Now();
 
     fprintf (stderr, "nsGLPbuffer::Init!\n");
+#elif defined(XP_UNIX) && defined(MOZ_X11)
+    mDisplay = XOpenDisplay(NULL);
+    if (!mDisplay) {
+        mPriv->LogMessage(NS_LITERAL_CSTRING("Canvas 3D: XOpenDisplay failed"));
+        return PR_FALSE;
+    }
+
+    int attrib[] = { GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
+                     GLX_RENDER_TYPE,   GLX_RGBA_BIT,
+                     GLX_RED_SIZE, 1,
+                     GLX_GREEN_SIZE, 1,
+                     GLX_BLUE_SIZE, 1,
+                     GLX_DEPTH_SIZE, 1,
+                     None };
+
+    int num;
+    GLXFBConfig *configs = glXChooseFBConfig(mDisplay, DefaultScreen(mDisplay),
+                                             attrib, &num);
+    fprintf(stderr, "CANVAS3D FBCONFIG: %d %p\n", num, configs);
+    if (!configs) {
+        mPriv->LogMessage(NS_LITERAL_CSTRING("Canvas 3D: No GLXFBConfig found"));
+        return PR_FALSE;
+    }
+
+    // choose first matching config;
+    mFBConfig = *configs;
+
+    XFree(configs);
+
+    // create dummy pbuffer so glewInit will be happy
+
+    mPbufferContext = glXCreateNewContext(mDisplay, mFBConfig, GLX_RGBA_TYPE,
+                                          nsnull, True);
+
+    PRInt64 t1 = PR_Now();
+
+    Resize(2, 2);
+    MakeContextCurrent();
+
+    PRInt64 t2 = PR_Now();
+
+    fprintf (stderr, "nsGLPbuffer::Init!\n");
+
+#elif defined(XP_MACOSX)
+    PRInt64 t1 = PR_Now();
+    PRInt64 t2 = t1;
+
+    GLint attrib[] = {
+        AGL_RGBA,
+        AGL_PBUFFER,
+        AGL_RED_SIZE, 8,
+        AGL_GREEN_SIZE, 8,
+        AGL_BLUE_SIZE, 8,
+        AGL_ALPHA_SIZE, 8,
+        AGL_DEPTH_SIZE, 1,
+        0
+    };
+
+    mPixelFormat = aglChoosePixelFormat(NULL, 0, &attrib[0]);
+    if (!mPixelFormat)
+        return PR_FALSE;
+
+    // we need a context for glewInit
+    Resize(2, 2);
+    MakeContextCurrent();
 #else
     return PR_FALSE;
 #endif
 
     if (glewInit() != GLEW_OK) {
         mPriv->LogMessage(NS_LITERAL_CSTRING("Canvas 3D: GLEW init failed"));
         return PR_FALSE;
     }
@@ -277,63 +346,118 @@ nsGLPbuffer::Resize(PRInt32 width, PRInt
     mPbuffer = wglCreatePbufferARB(mGlewDC, chosenFormat, width, height, &pbattribs);
     if (!mPbuffer) {
         mPriv->LogMessage(NS_LITERAL_CSTRING("Canvas 3D: Failed to create pbuffer"));
         return PR_FALSE;
     }
 
     mPbufferDC = wglGetPbufferDCARB(mPbuffer);
     mPbufferContext = wglCreateContext(mPbufferDC);
+#elif defined(XP_UNIX) && defined(MOZ_X11)
+    int attrib[] = { GLX_PBUFFER_WIDTH, width,
+                     GLX_PBUFFER_HEIGHT, height,
+                     None };
+
+    mPbuffer = glXCreatePbuffer(mDisplay, mFBConfig, attrib);
+#elif defined(XP_MACOSX)
+    mContext = aglCreateContext(mPixelFormat, NULL);
+    if (!mContext)
+        return PR_FALSE;
+
+    GLint screen = aglGetVirtualScreen(mContext);
+
+    if (screen == -1
+        || !aglCreatePBuffer(width, height, GL_TEXTURE_RECTANGLE_EXT,
+                             GL_RGBA, 0, &mPbuffer)
+        || !aglSetPBuffer (mContext, mPbuffer, 0, 0, screen))
+    {
+        return PR_FALSE;
+    }
+
+    MakeContextCurrent();
 #endif
 
     mWidth = width;
     mHeight = height;
 
+    fprintf (stderr, "Resize: %d %d\n", width, height);
     return PR_TRUE;
 }
 
 void
 nsGLPbuffer::Destroy()
 {
     sCurrentContextToken = nsnull;
     mThebesSurface = nsnull;
 
 #ifdef XP_WIN
     if (mPbuffer) {
         wglDeleteContext(mPbufferContext);
         wglDestroyPbufferARB(mPbuffer);
         mPbuffer = nsnull;
     }
-#endif 
+#elif defined(XP_UNIX) && defined(MOZ_X11)
+    if (mPbuffer) {
+        glXDestroyPbuffer(mDisplay, mPbuffer);
+        mPbuffer = nsnull;
+    }
+#else defined(XP_MACOSX)
+    if (mContext) {
+        aglDestroyContext(mContext);
+        mContext = nsnull;
+    }
+    if (mPbuffer) {
+        aglDestroyPBuffer(mPbuffer);
+        mPbuffer = nsnull;
+    }
+#endif
 }
 
 nsGLPbuffer::~nsGLPbuffer()
 {
+    Destroy();
+
 #ifdef XP_WIN
     if (mGlewWindow) {
         wglDeleteContext(mGlewWglContext);
         DestroyWindow(mGlewWindow);
         mGlewWindow = nsnull;
     }
+#elif defined(XP_UNIX) && defined(MOZ_X11)
+    if (mPbuffer)
+        glXDestroyPbuffer(mDisplay, mPbuffer);
+    if (mPbufferContext)
+        glXDestroyContext(mDisplay, mPbufferContext);
+    if (mDisplay)
+        XCloseDisplay(mDisplay);
+#else defined(XP_MACOSX)
+    if (mPbuffer)
+        aglDestroyPBuffer(mPbuffer);
+    if (mContext)
+        aglDestroyContext(mContext);
 #endif
 
     gActiveBuffers--;
     fprintf (stderr, "nsGLPbuffer: gActiveBuffers: %d\n", gActiveBuffers);
     fflush (stderr);
 }
 
 void
 nsGLPbuffer::MakeContextCurrent()
 {
 #ifdef XP_WIN
     if (sCurrentContextToken == mPbufferContext)
         return;
 
     wglMakeCurrent (mPbufferDC, mPbufferContext);
     sCurrentContextToken = mPbufferContext;
+#elif defined(XP_UNIX) && defined(MOZ_X11)
+    glXMakeContextCurrent(mDisplay, mPbuffer, mPbuffer, mPbufferContext);
+#elif defined(XP_MACOSX)
+    aglSetCurrentContext(mContext);
 #endif
 }
 
 void
 nsGLPbuffer::SwapBuffers()
 {
     MakeContextCurrent();
     glReadPixels (0, 0, mWidth, mHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, mThebesSurface->Data());
--- a/extensions/canvas3d/src/nsGLPbuffer.h
+++ b/extensions/canvas3d/src/nsGLPbuffer.h
@@ -44,16 +44,24 @@
 
 #include "glew.h"
 
 #ifdef XP_WIN
 #include <windows.h>
 #include "wglew.h"
 #endif
 
+#if defined(XP_UNIX) && defined(MOZ_X11)
+#include "GL/glx.h"
+#endif
+
+#ifdef XP_MACOSX
+#include <AGL/agl.h>
+#endif
+
 class nsCanvasRenderingContextGLPrivate;
 
 class nsGLPbuffer {
 public:
     nsGLPbuffer();
     ~nsGLPbuffer();
 
     PRBool Init(nsCanvasRenderingContextGLPrivate *priv);
@@ -99,11 +107,23 @@ protected:
     // and this is the actual stuff that we need to render
     HPBUFFERARB mPbuffer;
     HDC mPbufferDC;
     HGLRC mPbufferContext;
 
     WGLEWContext mWGlewContext;
 #endif
 
+#if defined(XP_UNIX) && defined(MOZ_X11)
+    Display     *mDisplay;
+    GLXFBConfig mFBConfig;
+    GLXPbuffer mPbuffer;
+    GLXContext mPbufferContext;
+#endif
+
+#ifdef XP_MACOSX
+    AGLPixelFormat mPixelFormat;
+    AGLContext mContext;
+    AGLPbuffer mPbuffer;
+#endif
 };
 
 #endif /* NSGLPBUFFER_H_ */
--- a/extensions/canvas3d/test/3dtest1.html
+++ b/extensions/canvas3d/test/3dtest1.html
@@ -1,15 +1,15 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
   <head>
     <script type="application/x-javascript">
 function doload() {
     var cvs = document.getElementById('canvas');
-    var ctx = cvs.getContext('gles11');
+    var ctx = cvs.getContext('moz-gles11');
 
     ctx.clearColor(.2,.2,.2,1);
     ctx.clear(ctx.COLOR_BUFFER_BIT);
 
     ctx.swapBuffers();
 }
     </script>
   </head>
--- a/extensions/canvas3d/test/3dtest2.html
+++ b/extensions/canvas3d/test/3dtest2.html
@@ -17,17 +17,17 @@ function makeImageCanvas() {
     ctx.fillStyle = "red";
     ctx.fillRect(0, 0, 128, 128);
 
     return cvs;
 }
 
 function doload() {
     var cvs = document.getElementById('canvas');
-    var gl = cvs.getContext('gles11');
+    var gl = cvs.getContext('moz-gles11');
 
     gl.clearColor(.2,.2,.4,1);
     gl.clear(gl.COLOR_BUFFER_BIT);
 
     // (optinally) set up lighting
     if (0) {
         gl.enable(gl.LIGHTING);
         gl.light(gl.LIGHT0, gl.AMBIENT, [1.0, 1.0, 1.0, 1]);
--- a/extensions/canvas3d/test/3dtest3.html
+++ b/extensions/canvas3d/test/3dtest3.html
@@ -54,17 +54,17 @@ function startTextureLoad() {
         draw();
         gl.swapBuffers();
     };
     img.src = "tex.png";
 }
 
 function doload() {
     var cvs = document.getElementById('canvas');
-    gl = cvs.getContext('gles11');
+    gl = cvs.getContext('moz-gles11');
 
     gl.clearColor(.2,.2,.4,1);
     gl.clear(gl.COLOR_BUFFER_BIT);
 
     // (optionally) set up lighting
     if (0) {
         gl.enable(gl.LIGHTING);
         gl.light(gl.LIGHT0, gl.AMBIENT, [1.0, 1.0, 1.0, 1]);
--- a/extensions/canvas3d/test/3dtest4.html
+++ b/extensions/canvas3d/test/3dtest4.html
@@ -74,17 +74,17 @@ function startTextureLoad() {
         draw();
         gl.swapBuffers();
     };
     img.src = "tex.png";
 }
 
 function doload() {
     var cvs = document.getElementById('canvas');
-    gl = cvs.getContext('gles11');
+    gl = cvs.getContext('moz-gles11');
 
     gl.clearColor(.2,.2,.4,1);
     gl.clear(gl.COLOR_BUFFER_BIT);
 
     // (optionally) set up lighting
     if (0) {
         gl.enable(gl.LIGHTING);
         gl.light(gl.LIGHT0, gl.AMBIENT, [1.0, 1.0, 1.0, 1]);
--- a/extensions/canvas3d/test/3dtest5.html
+++ b/extensions/canvas3d/test/3dtest5.html
@@ -100,17 +100,17 @@ function animStep() {
     tlast = Date.now();
 
     draw ();
     gl.swapBuffers();
 }
 
 function doload() {
     var cvs = document.getElementById('canvas');
-    gl = cvs.getContext('gles11');
+    gl = cvs.getContext('moz-gles11');
 
     // (optionally) set up lighting
     if (0) {
         gl.enable(gl.LIGHTING);
         gl.light(gl.LIGHT0, gl.AMBIENT, [1.0, 1.0, 1.0, 1]);
         gl.light(gl.LIGHT0, gl.DIFFUSE, [1.0, 1.0, 1.0, 1]);
         gl.light(gl.LIGHT0, gl.POSITION, [3, 3, -5, 0]);
         gl.light(gl.LIGHT0, gl.SPECULAR, [1, 1, 1, 1]);