b=619485; add WebGL info to about:support; r=jrmuizel,a=beltzner
authorVladimir Vukicevic <vladimir@pobox.com>
Thu, 16 Dec 2010 12:49:54 -0800
changeset 59414 075bb085d7552d94be7b00aa724cb0e8228049be
parent 59413 2c2aed8d77031c30b3986ab55baad2ae3a7ebee0
child 59415 7c40cabc296eece93011bff306001ffac5ce3779
push idunknown
push userunknown
push dateunknown
reviewersjrmuizel, beltzner
bugs619485
milestone2.0b9pre
b=619485; add WebGL info to about:support; r=jrmuizel,a=beltzner
content/canvas/src/WebGLContext.cpp
dom/interfaces/canvas/nsIDOMWebGLRenderingContext.idl
toolkit/content/aboutSupport.js
toolkit/locales/en-US/chrome/global/aboutSupport.properties
widget/public/nsIGfxInfo.idl
widget/src/cocoa/GfxInfo.mm
widget/src/windows/GfxInfo.cpp
widget/src/xpwidgets/GfxInfoWebGL.cpp
widget/src/xpwidgets/GfxInfoWebGL.h
widget/src/xpwidgets/Makefile.in
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -690,16 +690,43 @@ WebGLContext::GetContextAttributes(jsval
     {
         *aResult = JSVAL_VOID;
         return NS_ERROR_FAILURE;
     }
 
     return NS_OK;
 }
 
+/* [noscript] DOMString mozGetUnderlyingParamString(in WebGLenum pname); */
+NS_IMETHODIMP
+WebGLContext::MozGetUnderlyingParamString(PRUint32 pname, nsAString& retval)
+{
+    retval.SetIsVoid(PR_TRUE);
+
+    MakeContextCurrent();
+
+    switch (pname) {
+    case LOCAL_GL_VENDOR:
+    case LOCAL_GL_RENDERER:
+    case LOCAL_GL_VERSION:
+    case LOCAL_GL_SHADING_LANGUAGE_VERSION:
+    case LOCAL_GL_EXTENSIONS: {
+        const char *s = (const char *) gl->fGetString(pname);
+        retval.Assign(NS_ConvertASCIItoUTF16(nsDependentCString(s)));
+    }
+        break;
+
+    default:
+        return NS_ERROR_INVALID_ARG;
+    }
+
+    return NS_OK;
+}
+
+
 //
 // XPCOM goop
 //
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(WebGLContext, nsIDOMWebGLRenderingContext)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(WebGLContext, nsIDOMWebGLRenderingContext)
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(WebGLContext)
@@ -825,37 +852,43 @@ NS_IMETHODIMP base::SetName(WebGLuint aN
 NAME_NOT_SUPPORTED(WebGLTexture)
 NAME_NOT_SUPPORTED(WebGLBuffer)
 NAME_NOT_SUPPORTED(WebGLProgram)
 NAME_NOT_SUPPORTED(WebGLShader)
 NAME_NOT_SUPPORTED(WebGLFramebuffer)
 NAME_NOT_SUPPORTED(WebGLRenderbuffer)
 
 /* [noscript] attribute WebGLint location; */
-NS_IMETHODIMP WebGLUniformLocation::GetLocation(WebGLint *aLocation)
+NS_IMETHODIMP
+WebGLUniformLocation::GetLocation(WebGLint *aLocation)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
-NS_IMETHODIMP WebGLUniformLocation::SetLocation(WebGLint aLocation)
+
+NS_IMETHODIMP
+WebGLUniformLocation::SetLocation(WebGLint aLocation)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* readonly attribute WebGLint size; */
-NS_IMETHODIMP WebGLActiveInfo::GetSize(WebGLint *aSize)
+NS_IMETHODIMP
+WebGLActiveInfo::GetSize(WebGLint *aSize)
 {
     *aSize = mSize;
     return NS_OK;
 }
 
 /* readonly attribute WebGLenum type; */
-NS_IMETHODIMP WebGLActiveInfo::GetType(WebGLenum *aType)
+NS_IMETHODIMP
+WebGLActiveInfo::GetType(WebGLenum *aType)
 {
     *aType = mType;
     return NS_OK;
 }
 
 /* readonly attribute DOMString name; */
-NS_IMETHODIMP WebGLActiveInfo::GetName(nsAString & aName)
+NS_IMETHODIMP
+WebGLActiveInfo::GetName(nsAString & aName)
 {
     aName = mName;
     return NS_OK;
 }
--- a/dom/interfaces/canvas/nsIDOMWebGLRenderingContext.idl
+++ b/dom/interfaces/canvas/nsIDOMWebGLRenderingContext.idl
@@ -817,9 +817,14 @@ interface nsIDOMWebGLRenderingContext : 
   [noscript] void vertexAttrib2fv_array(in WebGLuint indx, in WebGLArrayPtr values);
   [noscript] void vertexAttrib3fv_array(in WebGLuint indx, in WebGLArrayPtr values);
   [noscript] void vertexAttrib4fv_array(in WebGLuint indx, in WebGLArrayPtr values);
 
   // size is number of elements per attrib; offset, stride are in bytes
   void vertexAttribPointer(in WebGLuint idx, in WebGLint size, in WebGLenum type, in WebGLboolean normalized, in WebGLsizei stride, in WebGLsizeiptr offset);
 
   void viewport(in WebGLint x, in WebGLint y, in WebGLsizei width, in WebGLsizei height);
+
+  // get an underlying GL parameter, without any WebGL intervention.
+  // Most useful for querying GL_VENDOR/GL_RENDERER for identifying
+  // the underlying renderer to the user.
+  [noscript] DOMString mozGetUnderlyingParamString(in WebGLenum pname);
 };
--- a/toolkit/content/aboutSupport.js
+++ b/toolkit/content/aboutSupport.js
@@ -1,8 +1,9 @@
+# -*- Mode: js2; indent-tabs-mode: nil; js2-basic-offset: 2; -*-
 # ***** BEGIN LICENSE BLOCK *****
 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
 #
 # The contents of this file are subject to the Mozilla Public License Version
 # 1.1 (the "License"); you may not use this file except in compliance with
 # the License. You may obtain a copy of the License at
 # http://www.mozilla.org/MPL/
 #
@@ -235,18 +236,28 @@ function populateGraphicsSection() {
     try {
       dwEnabled = gfxInfo.DWriteEnabled;
     } catch(e) {}
     trGraphics.push(createParentElement("tr", [
       createHeader(bundle.GetStringFromName("directWriteEnabled")),
       createElement("td", dwEnabled),
     ]));
 
+    var webglrenderer;
+    try {
+      webglrenderer = gfxInfo.getWebGLParameter("full-renderer");
+    } catch (e) {
+      webglrenderer = "(WebGL unavailable)";
+    }
+    trGraphics.push(createParentElement("tr", [
+      createHeader(bundle.GetStringFromName("webglRenderer")),
+      createElement("td", webglrenderer)
+    ]));
+
     appendChildren(graphics_tbody, trGraphics);
-
   } // end if (gfxInfo)
 
   let windows = Services.ww.getWindowEnumerator();
   let acceleratedWindows = 0;
   let totalWindows = 0;
   let mgrType;
   while (windows.hasMoreElements()) {
     totalWindows++;
--- a/toolkit/locales/en-US/chrome/global/aboutSupport.properties
+++ b/toolkit/locales/en-US/chrome/global/aboutSupport.properties
@@ -18,8 +18,9 @@ direct2DEnabled = Direct2D Enabled
 directWriteEnabled = DirectWrite Enabled
 adapterDescription = Adapter Description
 adapterVendorID = Vendor ID
 adapterDeviceID = Device ID
 adapterDrivers = Adapter Drivers
 adapterRAM = Adapter RAM
 driverVersion = Driver Version
 driverDate = Driver Date
+webglRenderer = WebGL Renderer
--- a/widget/public/nsIGfxInfo.idl
+++ b/widget/public/nsIGfxInfo.idl
@@ -112,10 +112,17 @@ interface nsIGfxInfo : nsISupports
    */
   long getFeatureStatus(in long aFeature);
 
   /*
    * Ask about a feature, return the minimum driver version required for it if its status is
    * FEATURE_BLOCKED_DRIVER_VERSION, otherwise return an empty string. 
    */
   DOMString getFeatureSuggestedDriverVersion(in long aFeature);
+
+  /**
+   * WebGL info; valid params are "full-renderer", "vendor", "renderer", "version",
+   * "shading_language_version", "extensions".  These return info from
+   * underlying GL impl that's used to implement WebGL.
+   */
+  DOMString getWebGLParameter(in DOMString aParam);
 };
 
--- a/widget/src/cocoa/GfxInfo.mm
+++ b/widget/src/cocoa/GfxInfo.mm
@@ -35,16 +35,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include <OpenGL/OpenGL.h>
 #include <OpenGL/CGLRenderers.h>
 
 #include "GfxInfo.h"
+#include "GfxInfoWebGL.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/FunctionTimer.h"
 
 #if defined(MOZ_CRASHREPORTER) && defined(MOZ_ENABLE_LIBXUL)
 #include "nsExceptionHandler.h"
 #include "nsICrashReporter.h"
 #define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
 #include "nsIPrefService.h"
@@ -229,8 +230,14 @@ GfxInfo::GetFeatureStatus(PRInt32 aFeatu
   return NS_OK;
 }
 
 NS_IMETHODIMP
 GfxInfo::GetFeatureSuggestedDriverVersion(PRInt32 aFeature, nsAString& aSuggestedDriverVersion)
 {
   return NS_OK;
 }
+
+NS_IMETHODIMP
+GfxInfo::GetWebGLParameter(const nsAString& aParam, nsAString& aResult)
+{
+  return GfxInfoWebGL::GetWebGLParameter(aParam, aResult);
+}
--- a/widget/src/windows/GfxInfo.cpp
+++ b/widget/src/windows/GfxInfo.cpp
@@ -34,16 +34,17 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include <windows.h>
 #include "gfxWindowsPlatform.h"
 #include "GfxInfo.h"
+#include "GfxInfoWebGL.h"
 #include "nsUnicharUtils.h"
 #include "nsPrintfCString.h"
 #include "mozilla/FunctionTimer.h"
 #include "prenv.h"
 #include "prprf.h"
 
 #if defined(MOZ_CRASHREPORTER) && defined(MOZ_ENABLE_LIBXUL)
 #include "nsExceptionHandler.h"
@@ -746,8 +747,14 @@ GfxInfo::GetFeatureStatus(PRInt32 aFeatu
 }
 
 NS_IMETHODIMP
 GfxInfo::GetFeatureSuggestedDriverVersion(PRInt32 aFeature, nsAString& aSuggestedDriverVersion)
 {
   PRInt32 i;
   return GetFeatureStatusImpl(aFeature, &i, aSuggestedDriverVersion);
 }
+
+NS_IMETHODIMP
+GfxInfo::GetWebGLParameter(const nsAString& aParam, nsAString& aResult)
+{
+  return GfxInfoWebGL::GetWebGLParameter(aParam, aResult);
+}
new file mode 100644
--- /dev/null
+++ b/widget/src/xpwidgets/GfxInfoWebGL.cpp
@@ -0,0 +1,101 @@
+/* vim: se cin sw=2 ts=2 et : */
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "GfxInfoWebGL.h"
+
+#include "nsServiceManagerUtils.h"
+
+#include "GLDefs.h"
+#include "nsIDOMWebGLRenderingContext.h"
+#include "nsICanvasRenderingContextInternal.h"
+
+using namespace mozilla::widget;
+
+nsresult
+GfxInfoWebGL::GetWebGLParameter(const nsAString& aParam, nsAString& aResult)
+{
+  GLenum param;
+
+  if (aParam.EqualsLiteral("vendor")) param = LOCAL_GL_VENDOR;
+  else if (aParam.EqualsLiteral("renderer")) param = LOCAL_GL_RENDERER;
+  else if (aParam.EqualsLiteral("version")) param = LOCAL_GL_VERSION;
+  else if (aParam.EqualsLiteral("shading_language_version")) param = LOCAL_GL_SHADING_LANGUAGE_VERSION;
+  else if (aParam.EqualsLiteral("extensions")) param = LOCAL_GL_EXTENSIONS;
+  else if (aParam.EqualsLiteral("full-renderer")) param = 0;
+  else return NS_ERROR_INVALID_ARG;
+
+  nsCOMPtr<nsIDOMWebGLRenderingContext> webgl =
+    do_CreateInstance("@mozilla.org/content/canvas-rendering-context;1?id=experimental-webgl");
+  if (!webgl)
+    return NS_ERROR_NOT_AVAILABLE;
+
+  nsCOMPtr<nsICanvasRenderingContextInternal> webglInternal =
+    do_QueryInterface(webgl);
+  if (!webglInternal)
+    return NS_ERROR_NOT_AVAILABLE;
+
+  nsresult rv = webglInternal->SetDimensions(16, 16);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (param)
+    return webgl->MozGetUnderlyingParamString(param, aResult);
+
+  // this is the "full renderer" string, which is vendor + renderer + version
+
+  nsAutoString str;
+
+  rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_VENDOR, str);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  aResult.Append(str);
+  aResult.AppendLiteral(" -- ");
+
+  rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_RENDERER, str);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  aResult.Append(str);
+  aResult.AppendLiteral(" -- ");
+
+  rv = webgl->MozGetUnderlyingParamString(LOCAL_GL_VERSION, str);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  aResult.Append(str);
+
+  return NS_OK;
+}
new file mode 100644
--- /dev/null
+++ b/widget/src/xpwidgets/GfxInfoWebGL.h
@@ -0,0 +1,59 @@
+/* vim: se cin sw=2 ts=2 et : */
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef __mozilla_widget_GfxInfoWebGL_h__
+#define __mozilla_widget_GfxInfoWebGL_h__
+
+#include "nsString.h"
+
+namespace mozilla {
+namespace widget {
+
+class GfxInfoWebGL {
+public:
+    static nsresult GetWebGLParameter(const nsAString& aParam, nsAString& aResult);
+
+protected:
+    GfxInfoWebGL() { }
+};
+
+}
+}
+
+#endif
--- a/widget/src/xpwidgets/Makefile.in
+++ b/widget/src/xpwidgets/Makefile.in
@@ -63,16 +63,17 @@ CPPSRCS		= \
 		nsXPLookAndFeel.cpp \
 		nsClipboardHelper.cpp \
 		nsPrintOptionsImpl.cpp \
 		nsPrintSettingsImpl.cpp \
 		nsPrintSession.cpp \
 		nsWidgetAtoms.cpp \
 		nsIdleService.cpp \
 		nsClipboardPrivacyHandler.cpp \
+		GfxInfoWebGL.cpp \
 		$(NULL)
 
 ifdef MOZ_IPC
 CPPSRCS		+= \
 		PuppetWidget.cpp \
 		nsFilePickerProxy.cpp \
 		$(NULL)
 endif