From fbaf7d1423fc95da3e17b19498f25e3463496821 Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Wed, 5 Jan 2011 23:54:31 -0500 Subject: [PATCH] Bug 619578. Add Android GfxInfo. r=vlad A very basic implementation. --HG-- extra : rebase_source : 7eac8fb407d7df6b7c82d5fc176ad14048653428 --- gfx/thebes/EGLUtils.h | 42 ++++++ gfx/thebes/GLContextProviderEGL.cpp | 11 ++ gfx/thebes/Makefile.in | 1 + widget/src/android/GfxInfo.cpp | 193 +++++++++++++++++++++++++ widget/src/android/GfxInfo.h | 76 ++++++++++ widget/src/android/Makefile.in | 1 + widget/src/android/nsWidgetFactory.cpp | 10 ++ 7 files changed, 334 insertions(+) create mode 100644 gfx/thebes/EGLUtils.h create mode 100644 widget/src/android/GfxInfo.cpp create mode 100644 widget/src/android/GfxInfo.h diff --git a/gfx/thebes/EGLUtils.h b/gfx/thebes/EGLUtils.h new file mode 100644 index 000000000000..e8d93be6ab87 --- /dev/null +++ b/gfx/thebes/EGLUtils.h @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * ***** 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 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 ***** */ + +namespace mozilla { +namespace gl { + +const char* +GetVendor(); + +} +} diff --git a/gfx/thebes/GLContextProviderEGL.cpp b/gfx/thebes/GLContextProviderEGL.cpp index 32c32fe9f2b9..fe90a00e4f74 100644 --- a/gfx/thebes/GLContextProviderEGL.cpp +++ b/gfx/thebes/GLContextProviderEGL.cpp @@ -144,6 +144,7 @@ public: #include "GLContextProvider.h" #include "nsDebug.h" #include "nsThreadUtils.h" +#include "EGLUtils.h" #include "nsIWidget.h" @@ -1562,6 +1563,16 @@ CreateSurfaceForWindow(nsIWidget *aWidget, EGLConfig config) return surface; } +const char* +GetVendor() +{ + if (!sEGLLibrary.EnsureInitialized()) { + return nsnull; + } + + return reinterpret_cast(sEGLLibrary.fQueryString(EGL_DISPLAY(), LOCAL_EGL_VENDOR)); +} + already_AddRefed GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget) { diff --git a/gfx/thebes/Makefile.in b/gfx/thebes/Makefile.in index 73ef37c66035..20bec726d178 100644 --- a/gfx/thebes/Makefile.in +++ b/gfx/thebes/Makefile.in @@ -45,6 +45,7 @@ EXPORTS = \ GLContextProvider.h \ GLContextProviderImpl.h \ nsCoreAnimationSupport.h \ + EGLUtils.h \ $(NULL) ifdef MOZ_IPC diff --git a/widget/src/android/GfxInfo.cpp b/widget/src/android/GfxInfo.cpp new file mode 100644 index 000000000000..ef1a38c38b2d --- /dev/null +++ b/widget/src/android/GfxInfo.cpp @@ -0,0 +1,193 @@ +/* -*- 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. + * + * 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 "GfxInfo.h" +#include "GfxInfoWebGL.h" +#include "nsUnicharUtils.h" +#include "nsPrintfCString.h" +#include "mozilla/FunctionTimer.h" +#include "prenv.h" +#include "prprf.h" +#include "EGLUtils.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" +#endif + + +using namespace mozilla::widget; + + +NS_IMPL_ISUPPORTS1(GfxInfo, nsIGfxInfo) + +/* GetD2DEnabled and GetDwriteEnabled shouldn't be called until after gfxPlatform initialization + * has occurred because they depend on it for information. (See bug 591561) */ +nsresult +GfxInfo::GetD2DEnabled(PRBool *aEnabled) +{ + return NS_ERROR_FAILURE; +} + +nsresult +GfxInfo::GetDWriteEnabled(PRBool *aEnabled) +{ + return NS_ERROR_FAILURE; +} + +void +GfxInfo::Init() +{ +} + + +/* readonly attribute DOMString adapterDescription; */ +NS_IMETHODIMP +GfxInfo::GetAdapterDescription(nsAString & aAdapterDescription) +{ + aAdapterDescription.AssignASCII(mozilla::gl::GetVendor()); + return NS_OK; +} + +/* readonly attribute DOMString adapterRAM; */ +NS_IMETHODIMP +GfxInfo::GetAdapterRAM(nsAString & aAdapterRAM) +{ + aAdapterRAM.AssignLiteral(""); + return NS_OK; +} + +/* readonly attribute DOMString adapterDriver; */ +NS_IMETHODIMP +GfxInfo::GetAdapterDriver(nsAString & aAdapterDriver) +{ + aAdapterDriver.AssignLiteral(""); + return NS_OK; +} + +/* readonly attribute DOMString adapterDriverVersion; */ +NS_IMETHODIMP +GfxInfo::GetAdapterDriverVersion(nsAString & aAdapterDriverVersion) +{ + aAdapterDriverVersion.AssignLiteral(""); + return NS_OK; +} + +/* readonly attribute DOMString adapterDriverDate; */ +NS_IMETHODIMP +GfxInfo::GetAdapterDriverDate(nsAString & aAdapterDriverDate) +{ + aAdapterDriverDate.AssignLiteral(""); + return NS_OK; +} + +/* readonly attribute unsigned long adapterVendorID; */ +NS_IMETHODIMP +GfxInfo::GetAdapterVendorID(PRUint32 *aAdapterVendorID) +{ + *aAdapterVendorID = 0; + return NS_OK; +} + +/* readonly attribute unsigned long adapterDeviceID; */ +NS_IMETHODIMP +GfxInfo::GetAdapterDeviceID(PRUint32 *aAdapterDeviceID) +{ + *aAdapterDeviceID = 0; + return NS_OK; +} + +void +GfxInfo::AddCrashReportAnnotations() +{ +#if 0 +#if defined(MOZ_CRASHREPORTER) && defined(MOZ_ENABLE_LIBXUL) + nsCAutoString deviceIDString, vendorIDString; + PRUint32 deviceID, vendorID; + + GetAdapterDeviceID(&deviceID); + GetAdapterVendorID(&vendorID); + + deviceIDString.AppendPrintf("%04x", deviceID); + vendorIDString.AppendPrintf("%04x", vendorID); + + CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AdapterVendorID"), + vendorIDString); + CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AdapterDeviceID"), + deviceIDString); + + /* Add an App Note for now so that we get the data immediately. These + * can go away after we store the above in the socorro db */ + nsCAutoString note; + /* AppendPrintf only supports 32 character strings, mrghh. */ + note.AppendPrintf("AdapterVendorID: %04x, ", vendorID); + note.AppendPrintf("AdapterDeviceID: %04x", deviceID); + + if (vendorID == 0) { + /* if we didn't find a valid vendorID lets append the mDeviceID string to try to find out why */ + note.Append(", "); + note.AppendWithConversion(mDeviceID); + note.Append(", "); + note.AppendWithConversion(mDeviceKeyDebug); + } + note.Append("\n"); + + CrashReporter::AppendAppNotesToCrashReport(note); + +#endif +#endif +} + +NS_IMETHODIMP +GfxInfo::GetFeatureStatus(PRInt32 aFeature, PRInt32 *aStatus) +{ + PRInt32 status = nsIGfxInfo::FEATURE_NO_INFO; + *aStatus = status; + 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); +} diff --git a/widget/src/android/GfxInfo.h b/widget/src/android/GfxInfo.h new file mode 100644 index 000000000000..366d388d4ca9 --- /dev/null +++ b/widget/src/android/GfxInfo.h @@ -0,0 +1,76 @@ +/* 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_GfxInfo_h__ +#define __mozilla_widget_GfxInfo_h__ + +#include + +#include "nsString.h" + +namespace mozilla { +namespace widget { + +class GfxInfo : public nsIGfxInfo +{ +public: + GfxInfo() {Init();} + virtual ~GfxInfo() {} + + NS_DECL_ISUPPORTS + NS_DECL_NSIGFXINFO +private: + + void Init(); + void AddCrashReportAnnotations(); + nsString mRendererIDsString; + nsString mAdapterRAMString; + + nsString mDeviceID; + nsString mDriverVersion; + nsString mDriverDate; + nsString mDeviceKey; + + PRUint32 mRendererIDs[16]; +}; + +} // namespace widget +} // namespace mozilla + +#endif /* __mozilla_widget_GfxInfo_h__ */ diff --git a/widget/src/android/Makefile.in b/widget/src/android/Makefile.in index 107056ce7d5c..40b7e7d93972 100644 --- a/widget/src/android/Makefile.in +++ b/widget/src/android/Makefile.in @@ -52,6 +52,7 @@ LIBXUL_LIBRARY = 1 CPPSRCS = \ + GfxInfo.cpp \ nsWidgetFactory.cpp \ nsAppShell.cpp \ nsToolkit.cpp \ diff --git a/widget/src/android/nsWidgetFactory.cpp b/widget/src/android/nsWidgetFactory.cpp index 996c647fd595..0191e092d3f7 100644 --- a/widget/src/android/nsWidgetFactory.cpp +++ b/widget/src/android/nsWidgetFactory.cpp @@ -77,6 +77,13 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecAndroid) NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter) NS_GENERIC_FACTORY_CONSTRUCTOR(nsIMEPicker) +#include "GfxInfo.h" +namespace mozilla { +namespace widget { +NS_GENERIC_FACTORY_CONSTRUCTOR(GfxInfo) +} +} + static nsresult nsFilePickerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) @@ -113,6 +120,7 @@ NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SPEC_CID); NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID); NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID); NS_DEFINE_NAMED_CID(NS_IMEPICKER_CID); +NS_DEFINE_NAMED_CID(NS_GFXINFO_CID); static const mozilla::Module::CIDEntry kWidgetCIDs[] = { { &kNS_WINDOW_CID, false, NULL, nsWindowConstructor }, @@ -131,6 +139,7 @@ static const mozilla::Module::CIDEntry kWidgetCIDs[] = { { &kNS_FILEPICKER_CID, false, NULL, nsFilePickerConstructor }, { &kNS_HTMLFORMATCONVERTER_CID, false, NULL, nsHTMLFormatConverterConstructor }, { &kNS_IMEPICKER_CID, false, NULL, nsIMEPickerConstructor }, + { &kNS_GFXINFO_CID, false, NULL, mozilla::widget::GfxInfoConstructor }, { NULL } }; @@ -151,6 +160,7 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = { { "@mozilla.org/filepicker;1", &kNS_FILEPICKER_CID }, { "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID }, { "@mozilla.org/imepicker;1", &kNS_IMEPICKER_CID }, + { "@mozilla.org/gfx/info;1", &kNS_GFXINFO_CID }, { NULL } };