From bd454f49fa5e66d6bea89c9d8c10f9c2c89a981b Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Sat, 16 Apr 2011 18:22:41 -0700 Subject: [PATCH] Bug 651017, part 2: wrap gfxPlatform::Init/Shutdown in a service and register it for app-startup. Also prune some dead CIDs from nsGfxCIID.h. --HG-- extra : rebase_source : d296ac53c4c60d79f7e2d6904dd54ce930099bbd --- gfx/src/nsGfxCIID.h | 14 +++---------- gfx/src/nsThebesGfxFactory.cpp | 26 ++++++++++++++++++++++++- gfx/thebes/gfxPlatform.cpp | 4 ++-- modules/libpr0n/build/nsImageModule.cpp | 11 +++-------- widget/src/windows/nsImageClipboard.cpp | 1 + 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/gfx/src/nsGfxCIID.h b/gfx/src/nsGfxCIID.h index 303d3ead2b9..5cc4a4b333b 100644 --- a/gfx/src/nsGfxCIID.h +++ b/gfx/src/nsGfxCIID.h @@ -38,14 +38,6 @@ #ifndef nsGfxCIID_h__ #define nsGfxCIID_h__ -#include "nsISupports.h" -#include "nsIFactory.h" -#include "nsIComponentManager.h" - -#define NS_IMAGE_CID \ -{ 0x6049b260, 0xc1e6, 0x11d1, \ -{ 0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } } - #define NS_DEVICE_CONTEXT_CID \ { 0x6049b262, 0xc1e6, 0x11d1, \ { 0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } } @@ -62,8 +54,8 @@ { 0xda5b130a, 0x1dd1, 0x11b2, \ { 0xad, 0x47, 0xf4, 0x55, 0xb1, 0x81, 0x4a, 0x78 } } -#define NS_DRAWING_SURFACE_CID \ -{ 0x199c7040, 0xcab0, 0x11d2, \ -{ 0xa8, 0x49, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } } +#define NS_GFX_INITIALIZATION_CID \ +{ 0x67c41576, 0x9664, 0x4ed5, \ +{ 0x90, 0xc1, 0xf6, 0x68, 0x3f, 0xd5, 0x2c, 0x8f } } #endif diff --git a/gfx/src/nsThebesGfxFactory.cpp b/gfx/src/nsThebesGfxFactory.cpp index 0f514e6e8ac..8547b3e90be 100644 --- a/gfx/src/nsThebesGfxFactory.cpp +++ b/gfx/src/nsThebesGfxFactory.cpp @@ -47,9 +47,25 @@ #include "nsThebesFontEnumerator.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. + +namespace { +class GfxInitialization : public nsISupports { + NS_DECL_ISUPPORTS +}; + +NS_IMPL_ISUPPORTS0(GfxInitialization) +} + NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesDeviceContext) NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesRegion) NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesFontEnumerator) +NS_GENERIC_FACTORY_CONSTRUCTOR(GfxInitialization) static nsresult nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) @@ -96,12 +112,14 @@ NS_DEFINE_NAMED_CID(NS_FONT_ENUMERATOR_CID); NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_CID); NS_DEFINE_NAMED_CID(NS_REGION_CID); NS_DEFINE_NAMED_CID(NS_SCRIPTABLE_REGION_CID); +NS_DEFINE_NAMED_CID(NS_GFX_INITIALIZATION_CID); static const mozilla::Module::CIDEntry kThebesCIDs[] = { { &kNS_FONT_ENUMERATOR_CID, false, NULL, nsThebesFontEnumeratorConstructor }, { &kNS_DEVICE_CONTEXT_CID, false, NULL, nsThebesDeviceContextConstructor }, { &kNS_REGION_CID, false, NULL, nsThebesRegionConstructor }, { &kNS_SCRIPTABLE_REGION_CID, false, NULL, nsScriptableRegionConstructor }, + { &kNS_GFX_INITIALIZATION_CID, false, NULL, GfxInitializationConstructor }, { NULL } }; @@ -110,6 +128,12 @@ static const mozilla::Module::ContractIDEntry kThebesContracts[] = { { "@mozilla.org/gfx/devicecontext;1", &kNS_DEVICE_CONTEXT_CID }, { "@mozilla.org/gfx/region/nsThebes;1", &kNS_REGION_CID }, { "@mozilla.org/gfx/region;1", &kNS_SCRIPTABLE_REGION_CID }, + { "@mozilla.org/gfx/init;1", &kNS_GFX_INITIALIZATION_CID }, + { NULL } +}; + +static const mozilla::Module::CategoryEntry kThebesCategories[] = { + { "app-startup", "Gfx Initialization", "service,@mozilla.org/gfx/init;1" }, { NULL } }; @@ -130,7 +154,7 @@ static const mozilla::Module kThebesModule = { mozilla::Module::kVersion, kThebesCIDs, kThebesContracts, - NULL, + kThebesCategories, NULL, nsThebesGfxModuleCtor, nsThebesGfxModuleDtor diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index f939dd22b54..a43b3205db8 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -272,9 +272,9 @@ gfxPlatform::Init() gPlatform = new gfxOS2Platform; #elif defined(ANDROID) gPlatform = new gfxAndroidPlatform; +#else + #error "No gfxPlatform implementation available" #endif - if (!gPlatform) - return NS_ERROR_OUT_OF_MEMORY; nsresult rv; diff --git a/modules/libpr0n/build/nsImageModule.cpp b/modules/libpr0n/build/nsImageModule.cpp index aa35fd3e748..9e44f1d7b86 100644 --- a/modules/libpr0n/build/nsImageModule.cpp +++ b/modules/libpr0n/build/nsImageModule.cpp @@ -37,10 +37,7 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsIDeviceContext.h" #include "mozilla/ModuleUtils.h" -#include "nsXPCOMCID.h" -#include "nsServiceManagerUtils.h" #include "RasterImage.h" @@ -121,11 +118,9 @@ static const mozilla::Module::CategoryEntry kImageCategories[] = { static nsresult imglib_Initialize() { - // Hack: We need the gfx module to be initialized because we use gfxPlatform - // in imgFrame. Request something from the gfx module to ensure that - // everything's set up for us. - nsCOMPtr devctx = - do_CreateInstance("@mozilla.org/gfx/devicecontext;1"); + // We need the gfx module to be initialized because we use gfxPlatform + // in imgFrame. It should have happened by now, but make sure. + nsCOMPtr dummy = do_GetService("@mozilla.org/gfx/init;1"); imgLoader::InitCache(); return NS_OK; diff --git a/widget/src/windows/nsImageClipboard.cpp b/widget/src/windows/nsImageClipboard.cpp index 9c0b5f63f9c..51881401f5a 100644 --- a/widget/src/windows/nsImageClipboard.cpp +++ b/widget/src/windows/nsImageClipboard.cpp @@ -47,6 +47,7 @@ #include "prmem.h" #include "imgIEncoder.h" #include "nsLiteralString.h" +#include "nsComponentManagerUtils.h" /* Things To Do 11/8/00