Adds support for samples in ContextFormat, pref 'webgl.max-samples'
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 19 Oct 2011 15:09:57 -0400
changeset 79597 4b49db2604963948bfc49f4bea2a95912b734b97
parent 79596 f1ec346a9e49289259cbed85dda4e98e9ddf05f8
child 79598 18244ca9345757ce10854cd92623d9b86bea8bb4
push id506
push userclegnitto@mozilla.com
push dateWed, 09 Nov 2011 02:03:18 +0000
treeherdermozilla-aurora@63587fc7bb93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone10.0a1
Adds support for samples in ContextFormat, pref 'webgl.max-samples'
content/canvas/src/WebGLContext.cpp
gfx/thebes/GLContext.h
gfx/thebes/GLContextProviderEGL.cpp
gfx/thebes/GLContextProviderGLX.cpp
gfx/thebes/GLContextProviderOSMesa.cpp
gfx/thebes/GLContextProviderWGL.cpp
modules/libpref/src/init/all.js
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -596,16 +596,21 @@ WebGLContext::SetDimensions(PRInt32 widt
         format.red = 5;
         format.green = 6;
         format.blue = 5;
 
         format.alpha = 0;
         format.minAlpha = 0;
     }
 
+    if (mOptions.antialias) {
+        PRUint32 msaaLevel = Preferences::GetUint("webgl.msaa-level", 2);
+        format.samples = msaaLevel*msaaLevel;
+    }
+
     if (PR_GetEnv("MOZ_WEBGL_PREFER_EGL")) {
         preferEGL = true;
     }
 
     // Ask GfxInfo about what we should use
     bool useOpenGL = true;
     bool useANGLE = true;
 
@@ -893,17 +898,17 @@ WebGLContext::GetContextAttributes(jsval
     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", JSVAL_FALSE,
+        !JS_DefineProperty(cx, obj, "antialias", cf.samples > 0 ? 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))
     {
--- a/gfx/thebes/GLContext.h
+++ b/gfx/thebes/GLContext.h
@@ -471,21 +471,21 @@ struct THEBES_API ContextFormat
         StrictBasicRGBA32,
         BasicRGB24,
         StrictBasicRGB24,
         BasicRGB16_565,
         StrictBasicRGB16_565
     };
 
     ContextFormat() {
-        memset(this, 0, sizeof(*this));
+        memset(this, 0, sizeof(ContextFormat));
     }
 
     ContextFormat(const StandardContextFormat cf) {
-        memset(this, 0, sizeof(*this));
+        memset(this, 0, sizeof(ContextFormat));
         switch (cf) {
         case BasicRGBA32:
             red = green = blue = alpha = 8;
             minRed = minGreen = minBlue = minAlpha = 1;
             break;
 
         case StrictBasicRGBA32:
             red = green = blue = alpha = 8;
@@ -514,16 +514,17 @@ struct THEBES_API ContextFormat
     }
 
     int depth, minDepth;
     int stencil, minStencil;
     int red, minRed;
     int green, minGreen;
     int blue, minBlue;
     int alpha, minAlpha;
+    int samples;
 
     int colorBits() const { return red + green + blue; }
 };
 
 class GLContext
     : public LibrarySymbolLoader
 {
     THEBES_INLINE_DECL_THREADSAFE_REFCOUNTING(GLContext)
--- a/gfx/thebes/GLContextProviderEGL.cpp
+++ b/gfx/thebes/GLContextProviderEGL.cpp
@@ -2235,24 +2235,27 @@ GLContextEGL::CreateEGLPixmapOffscreenCo
 // often without the ability to texture from them directly.
 already_AddRefed<GLContext>
 GLContextProviderEGL::CreateOffscreen(const gfxIntSize& aSize,
                                       const ContextFormat& aFormat)
 {
     if (!sEGLLibrary.EnsureInitialized()) {
         return nsnull;
     }
+    
+    ContextFormat actualFormat(aFormat);
+    actualFormat.samples = 0;
 
 #if defined(ANDROID) || defined(XP_WIN)
-    return GLContextEGL::CreateEGLPBufferOffscreenContext(aSize, aFormat);
+    return GLContextEGL::CreateEGLPBufferOffscreenContext(aSize, actualFormat);
 #elif defined(MOZ_X11) && defined(MOZ_EGL_XRENDER_COMPOSITE)
-  return GLContextEGL::CreateBasicEGLPixmapOffscreenContext(aSize, aFormat);
+    return GLContextEGL::CreateBasicEGLPixmapOffscreenContext(aSize, actualFormat);
 #elif defined(MOZ_X11)
     nsRefPtr<GLContextEGL> glContext =
-        GLContextEGL::CreateEGLPixmapOffscreenContext(aSize, aFormat, true);
+        GLContextEGL::CreateEGLPixmapOffscreenContext(aSize, actualFormat, true);
 
     if (!glContext) {
         return nsnull;
     }
     if (!glContext->GetSharedContext()) {
         // no point in returning anything if sharing failed, we can't
         // render from this
         return nsnull;
--- a/gfx/thebes/GLContextProviderGLX.cpp
+++ b/gfx/thebes/GLContextProviderGLX.cpp
@@ -1232,19 +1232,21 @@ DONE_CREATING_PIXMAP:
 
     return glContext.forget();
 }
 
 already_AddRefed<GLContext>
 GLContextProviderGLX::CreateOffscreen(const gfxIntSize& aSize,
                                       const ContextFormat& aFormat)
 {
+    ContextFormat actualFormat(aFormat);
+    actualFormat.samples = 0;
 
     nsRefPtr<GLContextGLX> glContext =
-        CreateOffscreenPixmapContext(aSize, aFormat, true);
+        CreateOffscreenPixmapContext(aSize, actualFormat, true);
 
     if (!glContext) {
         return nsnull;
     }
 
     if (!glContext->GetSharedContext()) {
         // no point in returning anything if sharing failed, we can't
         // render from this
--- a/gfx/thebes/GLContextProviderOSMesa.cpp
+++ b/gfx/thebes/GLContextProviderOSMesa.cpp
@@ -254,17 +254,20 @@ GLContextProviderOSMesa::CreateForWindow
 already_AddRefed<GLContext>
 GLContextProviderOSMesa::CreateOffscreen(const gfxIntSize& aSize,
                                          const ContextFormat& aFormat)
 {
     if (!sOSMesaLibrary.EnsureInitialized()) {
         return nsnull;
     }
 
-    nsRefPtr<GLContextOSMesa> glContext = new GLContextOSMesa(aFormat);
+    ContextFormat actualFormat(aFormat);
+    actualFormat.samples = 0;
+
+    nsRefPtr<GLContextOSMesa> glContext = new GLContextOSMesa(actualFormat);
 
     if (!glContext->Init(aSize))
     {
         return nsnull;
     }
 
     return glContext.forget();
 }
--- a/gfx/thebes/GLContextProviderWGL.cpp
+++ b/gfx/thebes/GLContextProviderWGL.cpp
@@ -604,18 +604,17 @@ CreatePBufferOffscreenContext(const gfxI
                                                         pbdc,
                                                         context,
                                                         chosenFormat);
 
     return glContext.forget();
 }
 
 static already_AddRefed<GLContextWGL>
-CreateWindowOffscreenContext(const gfxIntSize& aSize,
-                             const ContextFormat& aFormat)
+CreateWindowOffscreenContext(const ContextFormat& aFormat)
 {
     // CreateWindowOffscreenContext must return a global-shared context
     GLContextWGL *shareContext = GetGlobalContextWGL();
     if (!shareContext) {
         return nsnull;
     }
     
     HDC dc;
@@ -646,32 +645,35 @@ CreateWindowOffscreenContext(const gfxIn
 already_AddRefed<GLContext>
 GLContextProviderWGL::CreateOffscreen(const gfxIntSize& aSize,
                                       const ContextFormat& aFormat)
 {
     if (!sWGLLibrary.EnsureInitialized()) {
         return nsnull;
     }
 
+    ContextFormat actualFormat(aFormat);
+    actualFormat.samples = 0;
+
     nsRefPtr<GLContextWGL> glContext;
 
     // Always try to create a pbuffer context first, because we
     // want the context isolation.
     NS_ENSURE_TRUE(Preferences::GetRootBranch(), nsnull);
     const bool preferFBOs = Preferences::GetBool("wgl.prefer-fbo", false);
     if (!preferFBOs &&
         sWGLLibrary.fCreatePbuffer &&
         sWGLLibrary.fChoosePixelFormat)
     {
-        glContext = CreatePBufferOffscreenContext(aSize, aFormat);
+        glContext = CreatePBufferOffscreenContext(aSize, actualFormat);
     }
 
     // If it failed, then create a window context and use a FBO.
     if (!glContext) {
-        glContext = CreateWindowOffscreenContext(aSize, aFormat);
+        glContext = CreateWindowOffscreenContext(actualFormat);
     }
 
     if (!glContext ||
         !glContext->Init())
     {
         return nsnull;
     }
 
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -3286,16 +3286,17 @@ pref("webgl.force-enabled", false);
 pref("webgl.disabled", false);
 pref("webgl.shader_validator", true);
 pref("webgl.force_osmesa", false);
 pref("webgl.osmesalib", "");
 pref("webgl.verbose", false);
 pref("webgl.prefer-native-gl", false);
 pref("webgl.min_capability_mode", false);
 pref("webgl.disable-extensions", false);
+pref("webgl.msaa-level", 2);
 
 #ifdef XP_WIN
 // The default TCP send window on Windows is too small, and autotuning only occurs on receive
 pref("network.tcp.sendbuffer", 131072);
 #endif
 
 // Whether to disable acceleration for all widgets.
 #ifdef MOZ_E10S_COMPAT