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

View File

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

View File

@ -92,6 +92,7 @@
#include "nsIGfxInfo.h"
gfxPlatform *gPlatform = nsnull;
static bool gEverInitialized = false;
// These two may point to the same profile
static qcms_profile *gCMSOutputProfile = nsnull;
@ -228,13 +229,19 @@ gfxPlatform::gfxPlatform()
gfxPlatform*
gfxPlatform::GetPlatform()
{
if (!gPlatform) {
Init();
}
return gPlatform;
}
void
gfxPlatform::Init()
{
NS_ASSERTION(!gPlatform, "Already started???");
if (gEverInitialized) {
NS_RUNTIMEABORT("Already started???");
}
gEverInitialized = true;
gfxAtoms::RegisterAtoms();
@ -317,6 +324,11 @@ gfxPlatform::Init()
prefs->AddObserver("gfx.downloadable_fonts.", 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

View File

@ -118,10 +118,6 @@ static const mozilla::Module::CategoryEntry kImageCategories[] = {
static nsresult
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();
return NS_OK;
}

View File

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