Bug 766251 - 2/5 - reimplement GfxInfo on Android to use the data provided by the Java thread - r=jrmuizel

This commit is contained in:
Benoit Jacob 2012-07-05 10:12:33 -04:00
parent 9e50f7cb4b
commit cc27dbb9a7
2 changed files with 110 additions and 82 deletions

View File

@ -24,6 +24,11 @@ using namespace mozilla::widget;
NS_IMPL_ISUPPORTS_INHERITED1(GfxInfo, GfxInfoBase, nsIGfxInfoDebug)
#endif
GfxInfo::GfxInfo()
: mInitializedFromJavaData(false)
{
}
/* GetD2DEnabled and GetDwriteEnabled shouldn't be called until after gfxPlatform initialization
* has occurred because they depend on it for information. (See bug 591561) */
nsresult
@ -58,53 +63,104 @@ GfxInfo::GetCleartypeParameters(nsAString & aCleartypeParams)
return NS_ERROR_FAILURE;
}
nsresult
GfxInfo::Init()
void
GfxInfo::EnsureInitializedFromGfxInfoData()
{
mAdapterDescription.AssignLiteral(""); // we may append to it below
if (mInitializedFromJavaData)
return;
mInitializedFromJavaData = true;
{
nsCString gfxInfoData;
mozilla::AndroidBridge::Bridge()->GetGfxInfoData(gfxInfoData);
// the code here is a mini-parser for the text that GfxInfoThread.java produces.
// Here, |stringToFill| is the parser state. If it's null, we are expecting
// the next line to tell us what is the next string we'll read, e.g. "VENDOR"
// means that the next string we'll read is |mVendor|. We record that knowledge
// in the |stringToFill| pointer. So when it's not null, we just copy the next
// input line into the string pointed to by |stringToFill|.
nsCString *stringToFill = nsnull;
char *bufptr = gfxInfoData.BeginWriting();
while(true) {
char *line = NS_strtok("\n", &bufptr);
if (!line)
break;
if (stringToFill) {
stringToFill->Assign(line);
stringToFill = nsnull;
} else if(!strcmp(line, "VENDOR")) {
stringToFill = &mVendor;
} else if(!strcmp(line, "RENDERER")) {
stringToFill = &mRenderer;
} else if(!strcmp(line, "VERSION")) {
stringToFill = &mVersion;
} else if(!strcmp(line, "ERROR")) {
stringToFill = &mError;
}
}
}
if (!mError.IsEmpty()) {
mAdapterDescription.AppendPrintf("An error occurred earlier while querying gfx info: %s. ",
mError.get());
printf_stderr("%s\n", mAdapterDescription.get());
}
const char *spoofedVendor = PR_GetEnv("MOZ_GFX_SPOOF_GL_VENDOR");
if (spoofedVendor)
mVendor.Assign(spoofedVendor);
const char *spoofedRenderer = PR_GetEnv("MOZ_GFX_SPOOF_GL_RENDERER");
if (spoofedRenderer)
mRenderer.Assign(spoofedRenderer);
const char *spoofedVersion = PR_GetEnv("MOZ_GFX_SPOOF_GL_VERSION");
if (spoofedVersion)
mVersion.Assign(spoofedVersion);
mAdapterDescription.AppendPrintf("%s -- %s -- %s",
mVendor.get(),
mRenderer.get(),
mVersion.get());
// Now we append general (non-gfx) device information. The only reason why this code is still here
// is that this used to be all we had in GfxInfo on Android, and we can't trivially remove it
// as it's useful information that isn't given anywhere else in about:support of in crash reports.
// But we should really move this out of GfxInfo.
if (mozilla::AndroidBridge::Bridge()) {
nsAutoString str;
mAdapterDescription.Append(NS_LITERAL_STRING("Model: '"));
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MODEL", str)) {
mAdapterDeviceID = str;
mAdapterDescription.Append(str);
mAdapterDescription.AppendPrintf(" -- Model: %s", NS_LossyConvertUTF16toASCII(str).get());
}
mAdapterDescription.Append(NS_LITERAL_STRING("', Product: '"));
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "PRODUCT", str))
mAdapterDescription.Append(str);
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "PRODUCT", str)) {
mAdapterDescription.AppendPrintf(", Product: %s", NS_LossyConvertUTF16toASCII(str).get());
}
mAdapterDescription.Append(NS_LITERAL_STRING("', Manufacturer: '"));
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MANUFACTURER", str))
mAdapterDescription.Append(str);
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MANUFACTURER", str)) {
mAdapterDescription.AppendPrintf(", Manufacturer: %s", NS_LossyConvertUTF16toASCII(str).get());
}
mAdapterDescription.Append(NS_LITERAL_STRING("', Hardware: '"));
PRInt32 version; // the HARDWARE field isn't available on Android SDK < 8
int32_t version; // the HARDWARE field isn't available on Android SDK < 8
if (!mozilla::AndroidBridge::Bridge()->GetStaticIntField("android/os/Build$VERSION", "SDK_INT", &version))
version = 0;
if (version >= 8 && mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "HARDWARE", str)) {
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "HARDWARE", str)) {
mAdapterVendorID = str;
mAdapterDescription.Append(str);
mAdapterDescription.AppendPrintf(", Hardware: %s", NS_LossyConvertUTF16toASCII(str).get());
}
}
mAdapterDescription.Append(NS_LITERAL_STRING("'"));
mAndroidSDKVersion = version;
}
AddOpenGLCrashReportAnnotations();
return GfxInfoBase::Init();
AddCrashReportAnnotations();
}
/* readonly attribute DOMString adapterDescription; */
NS_IMETHODIMP
GfxInfo::GetAdapterDescription(nsAString & aAdapterDescription)
{
aAdapterDescription = mAdapterDescription;
aAdapterDescription = NS_ConvertASCIItoUTF16(mAdapterDescription);
return NS_OK;
}
@ -149,8 +205,7 @@ GfxInfo::GetAdapterDriver2(nsAString & aAdapterDriver)
NS_IMETHODIMP
GfxInfo::GetAdapterDriverVersion(nsAString & aAdapterDriverVersion)
{
aAdapterDriverVersion.Truncate(0);
aAdapterDriverVersion.AppendInt(mAndroidSDKVersion);
aAdapterDriverVersion = NS_ConvertASCIItoUTF16(mVersion);
return NS_OK;
}
@ -180,7 +235,7 @@ GfxInfo::GetAdapterDriverDate2(nsAString & aAdapterDriverDate)
NS_IMETHODIMP
GfxInfo::GetAdapterVendorID(nsAString & aAdapterVendorID)
{
aAdapterVendorID = mAdapterVendorID;
aAdapterVendorID = NS_ConvertASCIItoUTF16(mVendor);
return NS_OK;
}
@ -195,7 +250,7 @@ GfxInfo::GetAdapterVendorID2(nsAString & aAdapterVendorID)
NS_IMETHODIMP
GfxInfo::GetAdapterDeviceID(nsAString & aAdapterDeviceID)
{
aAdapterDeviceID = mAdapterDeviceID;
aAdapterDeviceID = NS_ConvertASCIItoUTF16(mRenderer);
return NS_OK;
}
@ -214,35 +269,18 @@ GfxInfo::GetIsGPU2Active(bool* aIsGPU2Active)
}
void
GfxInfo::AddOpenGLCrashReportAnnotations()
GfxInfo::AddCrashReportAnnotations()
{
#if defined(MOZ_CRASHREPORTER)
nsAutoString adapterDescriptionString, deviceID, vendorID;
nsCAutoString narrowDeviceID, narrowVendorID;
GetAdapterDeviceID(deviceID);
GetAdapterVendorID(vendorID);
GetAdapterDescription(adapterDescriptionString);
narrowDeviceID = NS_ConvertUTF16toUTF8(deviceID);
narrowVendorID = NS_ConvertUTF16toUTF8(vendorID);
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AdapterVendorID"),
narrowVendorID);
mVendor);
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AdapterDeviceID"),
narrowDeviceID);
mRenderer);
/* 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.Append("AdapterVendorID: ");
note.Append(narrowVendorID);
note.Append(", AdapterDeviceID: ");
note.Append(narrowDeviceID);
note.Append(".\n");
note.AppendPrintf("AdapterDescription: '%s'.", NS_ConvertUTF16toUTF8(adapterDescriptionString).get());
note.Append("\n");
note.AppendPrintf("AdapterDescription: '%s'\n", mAdapterDescription.get());
CrashReporter::AppendAppNotesToCrashReport(note);
#endif
@ -284,23 +322,11 @@ GfxInfo::GetFeatureStatusImpl(PRInt32 aFeature,
if (aOS)
*aOS = os;
// Don't evaluate special cases when evaluating the downloaded blocklist.
if (!aDriverInfo.Length()) {
if (aFeature == FEATURE_OPENGL_LAYERS) {
/* The following code is an old way to whitelist devices when we're ready.
* It is staying here for reference. The best way to do this now is to add
* an entry in the list above. There is a dummy entry which will whitelist a
* device when uncommented and device/vendor IDs are inserted. It is
* preferred that we stop whitelisting and instead go to blocklisting, where
* everything is assumed to be okay as long as it's not in the blocklist. */
// nsAutoString str;
// /* Whitelist Galaxy S phones */
// if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "HARDWARE", str)) {
// if (str != NS_LITERAL_STRING("smdkc110")) {
// status = FEATURE_BLOCKED_DEVICE;
// }
// }
}
EnsureInitializedFromGfxInfoData();
if (!mError.IsEmpty()) {
*aStatus = nsIGfxInfo::FEATURE_BLOCKED_DEVICE;
return NS_OK;
}
return GfxInfoBase::GetFeatureStatusImpl(aFeature, aStatus, aSuggestedDriverVersion, aDriverInfo, &os);
@ -313,21 +339,24 @@ GfxInfo::GetFeatureStatusImpl(PRInt32 aFeature,
/* void spoofVendorID (in DOMString aVendorID); */
NS_IMETHODIMP GfxInfo::SpoofVendorID(const nsAString & aVendorID)
{
mAdapterVendorID = aVendorID;
EnsureInitializedFromGfxInfoData(); // initialization from GfxInfo data overwrites mVendor
mVendor = NS_LossyConvertUTF16toASCII(aVendorID);
return NS_OK;
}
/* void spoofDeviceID (in unsigned long aDeviceID); */
NS_IMETHODIMP GfxInfo::SpoofDeviceID(const nsAString & aDeviceID)
{
mAdapterDeviceID = aDeviceID;
EnsureInitializedFromGfxInfoData(); // initialization from GfxInfo data overwrites mRenderer
mRenderer = NS_LossyConvertUTF16toASCII(aDeviceID);
return NS_OK;
}
/* void spoofDriverVersion (in DOMString aDriverVersion); */
NS_IMETHODIMP GfxInfo::SpoofDriverVersion(const nsAString & aDriverVersion)
{
mDriverVersion = aDriverVersion;
EnsureInitializedFromGfxInfoData(); // initialization from GfxInfo data overwrites mVersion
mVersion = NS_LossyConvertUTF16toASCII(aDriverVersion);
return NS_OK;
}

View File

@ -19,6 +19,8 @@ namespace widget {
class GfxInfo : public GfxInfoBase
{
public:
GfxInfo();
// We only declare the subset of nsIGfxInfo that we actually implement. The
// rest is brought forward from GfxInfoBase.
NS_SCRIPTABLE NS_IMETHOD GetD2DEnabled(bool *aD2DEnabled);
@ -45,7 +47,7 @@ public:
using GfxInfoBase::GetFeatureSuggestedDriverVersion;
using GfxInfoBase::GetWebGLParameter;
virtual nsresult Init();
void EnsureInitializedFromGfxInfoData();
#ifdef DEBUG
NS_DECL_ISUPPORTS_INHERITED
@ -63,21 +65,18 @@ protected:
private:
void AddOpenGLCrashReportAnnotations();
nsString mRendererIDsString;
nsString mAdapterRAMString;
void AddCrashReportAnnotations();
nsString mDeviceID;
nsString mDriverVersion;
nsString mDriverDate;
nsString mDeviceKey;
bool mInitializedFromJavaData;
nsString mAdapterDeviceID;
nsString mAdapterVendorID;
nsString mAdapterDescription;
PRInt32 mAndroidSDKVersion;
// the GL strings
nsCString mVendor;
nsCString mRenderer;
nsCString mVersion;
// a possible error message produced by the data source (e.g. if EGL initialization failed)
nsCString mError;
PRUint32 mRendererIDs[16];
nsCString mAdapterDescription;
};
} // namespace widget