Bug 651498: call gfxPlatform::Init when necessary and not earlier. r=joedrew,bsmedberg

--HG--
extra : rebase_source : fa6eae9a0656197d2c245f7c15120f36face2347
This commit is contained in:
Zack Weinberg 2011-04-21 12:36:49 -07:00
parent 41f3c1a6c7
commit d100392a5b
5 changed files with 28 additions and 35 deletions

View File

@ -47,12 +47,11 @@
#include "nsDeviceContext.h" #include "nsDeviceContext.h"
#include "gfxPlatform.h" #include "gfxPlatform.h"
// This service doesn't do anything; its only purpose is to force the // This class doesn't do anything; its only purpose is to give
// gfx module constructor to be called (and hence gfxPlatform::Init). // gfxPlatform::Init a way to force this component to be registered,
// It's invoked at app-startup time and may also be invoked directly // so that gfxPlatform::Shutdown will be called at an appropriate
// (as do_GetService("@mozilla.org/gfx/init;1")) from code (like the // time. (Component teardown is the only shutdown hook that runs
// libpr0n module constructor) that wants to make sure gfx is // late enough; see bug 651498.)
// initialized.
namespace { namespace {
class GfxInitialization : public nsISupports { class GfxInitialization : public nsISupports {
@ -129,18 +128,6 @@ static const mozilla::Module::ContractIDEntry kThebesContracts[] = {
{ NULL } { NULL }
}; };
static const mozilla::Module::CategoryEntry kThebesCategories[] = {
{ "app-startup", "Gfx Initialization", "service,@mozilla.org/gfx/init;1" },
{ NULL }
};
static nsresult
nsThebesGfxModuleCtor()
{
gfxPlatform::Init();
return NS_OK;
}
static void static void
nsThebesGfxModuleDtor() nsThebesGfxModuleDtor()
{ {
@ -152,9 +139,9 @@ static const mozilla::Module kThebesModule = {
mozilla::Module::kVersion, mozilla::Module::kVersion,
kThebesCIDs, kThebesCIDs,
kThebesContracts, kThebesContracts,
kThebesCategories,
NULL, NULL,
nsThebesGfxModuleCtor, NULL,
NULL,
nsThebesGfxModuleDtor nsThebesGfxModuleDtor
}; };

View File

@ -728,8 +728,7 @@ gfxDWriteFontList::InitFontList()
// determine dwrite version // determine dwrite version
nsAutoString dwriteVers; nsAutoString dwriteVers;
gfxWindowsPlatform::GetPlatform()->GetDLLVersion(L"dwrite.dll", gfxWindowsPlatform::GetDLLVersion(L"dwrite.dll", dwriteVers);
dwriteVers);
LOG_FONTINIT(("InitFontList\n")); LOG_FONTINIT(("InitFontList\n"));
LOG_FONTINIT(("Start: %s %s\n", nowDate, nowTime)); LOG_FONTINIT(("Start: %s %s\n", nowDate, nowTime));
LOG_FONTINIT(("Uptime: %9.3f s\n", upTime/1000)); LOG_FONTINIT(("Uptime: %9.3f s\n", upTime/1000));
@ -961,8 +960,7 @@ gfxDWriteFontList::DelayedInitFontList()
// determine dwrite version // determine dwrite version
nsAutoString dwriteVers; nsAutoString dwriteVers;
gfxWindowsPlatform::GetPlatform()->GetDLLVersion(L"dwrite.dll", gfxWindowsPlatform::GetDLLVersion(L"dwrite.dll", dwriteVers);
dwriteVers);
LOG_FONTINIT(("DelayedInitFontList\n")); LOG_FONTINIT(("DelayedInitFontList\n"));
LOG_FONTINIT(("Start: %s %s\n", nowDate, nowTime)); LOG_FONTINIT(("Start: %s %s\n", nowDate, nowTime));
LOG_FONTINIT(("Uptime: %9.3f s\n", upTime/1000)); LOG_FONTINIT(("Uptime: %9.3f s\n", upTime/1000));

View File

@ -92,6 +92,7 @@
#include "nsIGfxInfo.h" #include "nsIGfxInfo.h"
gfxPlatform *gPlatform = nsnull; gfxPlatform *gPlatform = nsnull;
static bool gEverInitialized = false;
// These two may point to the same profile // These two may point to the same profile
static qcms_profile *gCMSOutputProfile = nsnull; static qcms_profile *gCMSOutputProfile = nsnull;
@ -228,13 +229,19 @@ gfxPlatform::gfxPlatform()
gfxPlatform* gfxPlatform*
gfxPlatform::GetPlatform() gfxPlatform::GetPlatform()
{ {
if (!gPlatform) {
Init();
}
return gPlatform; return gPlatform;
} }
void void
gfxPlatform::Init() gfxPlatform::Init()
{ {
NS_ASSERTION(!gPlatform, "Already started???"); if (gEverInitialized) {
NS_RUNTIMEABORT("Already started???");
}
gEverInitialized = true;
gfxAtoms::RegisterAtoms(); gfxAtoms::RegisterAtoms();
@ -317,6 +324,11 @@ gfxPlatform::Init()
prefs->AddObserver("gfx.downloadable_fonts.", fontPrefObserver, PR_FALSE); prefs->AddObserver("gfx.downloadable_fonts.", fontPrefObserver, PR_FALSE);
prefs->AddObserver("gfx.font_rendering.", fontPrefObserver, PR_FALSE); prefs->AddObserver("gfx.font_rendering.", fontPrefObserver, PR_FALSE);
} }
// Force registration of the gfx component, thus arranging for
// ::Shutdown to be called.
nsCOMPtr<nsISupports> forceReg
= do_CreateInstance("@mozilla.org/gfx/init;1");
} }
void void

View File

@ -118,10 +118,6 @@ static const mozilla::Module::CategoryEntry kImageCategories[] = {
static nsresult static nsresult
imglib_Initialize() imglib_Initialize()
{ {
// We need the gfx module to be initialized because we use gfxPlatform
// in imgFrame. It should have happened by now, but make sure.
nsCOMPtr<nsISupports> dummy = do_GetService("@mozilla.org/gfx/init;1");
imgLoader::InitCache(); imgLoader::InitCache();
return NS_OK; return NS_OK;
} }

View File

@ -102,7 +102,7 @@ GfxInfo::GetDWriteEnabled(PRBool *aEnabled)
NS_IMETHODIMP NS_IMETHODIMP
GfxInfo::GetDWriteVersion(nsAString & aDwriteVersion) GfxInfo::GetDWriteVersion(nsAString & aDwriteVersion)
{ {
gfxWindowsPlatform::GetPlatform()->GetDLLVersion(L"dwrite.dll", aDwriteVersion); gfxWindowsPlatform::GetDLLVersion(L"dwrite.dll", aDwriteVersion);
return NS_OK; return NS_OK;
} }
@ -354,21 +354,21 @@ GfxInfo::Init()
mHasDriverVersionMismatch = PR_FALSE; mHasDriverVersionMismatch = PR_FALSE;
if (mAdapterVendorID == vendorIntel) { if (mAdapterVendorID == vendorIntel) {
// we've had big crashers (bugs 590373 and 595364) apparently correlated // we've had big crashers (bugs 590373 and 595364) apparently correlated
// with bad Intel driver installations where the DriverVersion reported by the registry was // with bad Intel driver installations where the DriverVersion reported
// not the version of the DLL. // by the registry was not the version of the DLL.
PRBool is64bitApp = sizeof(void*) == 8; PRBool is64bitApp = sizeof(void*) == 8;
const PRUnichar *dllFileName = is64bitApp const PRUnichar *dllFileName = is64bitApp
? L"igd10umd64.dll" ? L"igd10umd64.dll"
: L"igd10umd32.dll"; : L"igd10umd32.dll";
nsString dllVersion; nsString dllVersion;
// if GetDLLVersion fails, it gives "0.0.0.0" gfxWindowsPlatform::GetDLLVersion((PRUnichar*)dllFileName, dllVersion);
gfxWindowsPlatform::GetPlatform()->GetDLLVersion((PRUnichar*)dllFileName, dllVersion);
PRUint64 dllNumericVersion = 0, driverNumericVersion = 0; PRUint64 dllNumericVersion = 0, driverNumericVersion = 0;
// so if GetDLLVersion failed, we get dllNumericVersion = 0
ParseDriverVersion(dllVersion, &dllNumericVersion); ParseDriverVersion(dllVersion, &dllNumericVersion);
ParseDriverVersion(mDriverVersion, &driverNumericVersion); ParseDriverVersion(mDriverVersion, &driverNumericVersion);
// if GetDLLVersion fails, it gives "0.0.0.0"
// so if GetDLLVersion failed, we get dllNumericVersion = 0
// so this test implicitly handles the case where GetDLLVersion failed // so this test implicitly handles the case where GetDLLVersion failed
if (dllNumericVersion != driverNumericVersion) if (dllNumericVersion != driverNumericVersion)
mHasDriverVersionMismatch = PR_TRUE; mHasDriverVersionMismatch = PR_TRUE;