Bug 962440 - move gfxFontInfoLoader into separate file. r=bas
authorJohn Daggett <jdaggett@mozilla.com>
Wed, 29 Jan 2014 16:39:01 +0900
changeset 165720 3ee447cb0b7531f908b4db0738820261d16489a0
parent 165719 579ca52244a1bf3a22164bac7ee9a25026e0864e
child 165721 71c900e16cf9465298b05da2cb9a7812b3145120
push id26102
push userryanvm@gmail.com
push dateWed, 29 Jan 2014 20:09:21 +0000
treeherdermozilla-central@27c8e496895a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs962440
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 962440 - move gfxFontInfoLoader into separate file. r=bas
gfx/thebes/gfxFontInfoLoader.cpp
gfx/thebes/gfxFontInfoLoader.h
gfx/thebes/gfxFontUtils.cpp
gfx/thebes/gfxFontUtils.h
gfx/thebes/gfxPlatformFontList.h
gfx/thebes/moz.build
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/gfxFontInfoLoader.cpp
@@ -0,0 +1,115 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "gfxFontInfoLoader.h"
+#include "nsCRT.h"
+#include "nsIObserverService.h"
+
+using namespace mozilla;
+using mozilla::services::GetObserverService;
+
+NS_IMPL_ISUPPORTS1(gfxFontInfoLoader::ShutdownObserver, nsIObserver)
+
+NS_IMETHODIMP
+gfxFontInfoLoader::ShutdownObserver::Observe(nsISupports *aSubject,
+                                             const char *aTopic,
+                                             const char16_t *someData)
+{
+    if (!nsCRT::strcmp(aTopic, "quit-application")) {
+        mLoader->CancelLoader();
+    } else {
+        NS_NOTREACHED("unexpected notification topic");
+    }
+    return NS_OK;
+}
+
+void
+gfxFontInfoLoader::StartLoader(uint32_t aDelay, uint32_t aInterval)
+{
+    mInterval = aInterval;
+
+    // sanity check
+    if (mState != stateInitial && mState != stateTimerOff) {
+        CancelLoader();
+    }
+
+    // set up timer
+    if (!mTimer) {
+        mTimer = do_CreateInstance("@mozilla.org/timer;1");
+        if (!mTimer) {
+            NS_WARNING("Failure to create font info loader timer");
+            return;
+        }
+    }
+
+    // need an initial delay?
+    uint32_t timerInterval;
+
+    if (aDelay) {
+        mState = stateTimerOnDelay;
+        timerInterval = aDelay;
+    } else {
+        mState = stateTimerOnInterval;
+        timerInterval = mInterval;
+    }
+
+    InitLoader();
+
+    // start timer
+    mTimer->InitWithFuncCallback(LoaderTimerCallback, this, timerInterval,
+                                 nsITimer::TYPE_REPEATING_SLACK);
+
+    nsCOMPtr<nsIObserverService> obs = GetObserverService();
+    if (obs) {
+        mObserver = new ShutdownObserver(this);
+        obs->AddObserver(mObserver, "quit-application", false);
+    }
+}
+
+void
+gfxFontInfoLoader::CancelLoader()
+{
+    if (mState == stateInitial) {
+        return;
+    }
+    mState = stateTimerOff;
+    if (mTimer) {
+        mTimer->Cancel();
+        mTimer = nullptr;
+    }
+    RemoveShutdownObserver();
+    FinishLoader();
+}
+
+void
+gfxFontInfoLoader::LoaderTimerFire()
+{
+    if (mState == stateTimerOnDelay) {
+        mState = stateTimerOnInterval;
+        mTimer->SetDelay(mInterval);
+    }
+
+    bool done = RunLoader();
+    if (done) {
+        CancelLoader();
+    }
+}
+
+gfxFontInfoLoader::~gfxFontInfoLoader()
+{
+    RemoveShutdownObserver();
+}
+
+void
+gfxFontInfoLoader::RemoveShutdownObserver()
+{
+    if (mObserver) {
+        nsCOMPtr<nsIObserverService> obs = GetObserverService();
+        if (obs) {
+            obs->RemoveObserver(mObserver, "quit-application");
+            mObserver = nullptr;
+        }
+    }
+}
new file mode 100644
--- /dev/null
+++ b/gfx/thebes/gfxFontInfoLoader.h
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef GFX_FONT_INFO_LOADER_H
+#define GFX_FONT_INFO_LOADER_H
+
+#include "nsCOMPtr.h"
+#include "nsIObserver.h"
+#include "nsITimer.h"
+
+// helper class for loading in font info spaced out at regular intervals
+
+class gfxFontInfoLoader {
+public:
+
+    // state transitions:
+    //   initial ---StartLoader with delay---> timer on delay
+    //   initial ---StartLoader without delay---> timer on interval
+    //   timer on delay ---LoaderTimerFire---> timer on interval
+    //   timer on delay ---CancelLoader---> timer off
+    //   timer on interval ---CancelLoader---> timer off
+    //   timer off ---StartLoader with delay---> timer on delay
+    //   timer off ---StartLoader without delay---> timer on interval
+    typedef enum {
+        stateInitial,
+        stateTimerOnDelay,
+        stateTimerOnInterval,
+        stateTimerOff
+    } TimerState;
+
+    gfxFontInfoLoader() :
+        mInterval(0), mState(stateInitial)
+    {
+    }
+
+    virtual ~gfxFontInfoLoader();
+
+    // start timer with an initial delay, then call Run method at regular intervals
+    void StartLoader(uint32_t aDelay, uint32_t aInterval);
+
+    // cancel the timer and cleanup
+    void CancelLoader();
+
+protected:
+    class ShutdownObserver : public nsIObserver
+    {
+    public:
+        NS_DECL_ISUPPORTS
+        NS_DECL_NSIOBSERVER
+
+        ShutdownObserver(gfxFontInfoLoader *aLoader)
+            : mLoader(aLoader)
+        { }
+
+        virtual ~ShutdownObserver()
+        { }
+
+    protected:
+        gfxFontInfoLoader *mLoader;
+    };
+
+    // Init - initialization at start time after initial delay
+    virtual void InitLoader() = 0;
+
+    // Run - called at intervals, return true to indicate done
+    virtual bool RunLoader() = 0;
+
+    // Finish - cleanup after done
+    virtual void FinishLoader() = 0;
+
+    // Timer interval callbacks
+    static void LoaderTimerCallback(nsITimer *aTimer, void *aThis) {
+        gfxFontInfoLoader *loader = static_cast<gfxFontInfoLoader*>(aThis);
+        loader->LoaderTimerFire();
+    }
+
+    void LoaderTimerFire();
+
+    void RemoveShutdownObserver();
+
+    nsCOMPtr<nsITimer> mTimer;
+    nsCOMPtr<nsIObserver> mObserver;
+    uint32_t mInterval;
+    TimerState mState;
+};
+
+#endif /* GFX_FONT_INFO_LOADER_H */
--- a/gfx/thebes/gfxFontUtils.cpp
+++ b/gfx/thebes/gfxFontUtils.cpp
@@ -13,37 +13,35 @@
 #include "gfxFontUtils.h"
 
 #include "nsServiceManagerUtils.h"
 
 #include "mozilla/dom/EncodingUtils.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 
+#include "nsCOMPtr.h"
 #include "nsIUUIDGenerator.h"
-#include "nsIObserverService.h"
 #include "nsIUnicodeDecoder.h"
-#include "nsCRT.h"
 
 #include "harfbuzz/hb.h"
 
 #include "plbase64.h"
 #include "prlog.h"
 
 #ifdef PR_LOGGING
 
 #define LOG(log, args) PR_LOG(gfxPlatform::GetLog(log), \
                                PR_LOG_DEBUG, args)
 
 #endif // PR_LOGGING
 
 #define UNICODE_BMP_LIMIT 0x10000
 
 using namespace mozilla;
-using mozilla::services::GetObserverService;
 
 #pragma pack(1)
 
 typedef struct {
     AutoSwap_PRUint16 format;
     AutoSwap_PRUint16 reserved;
     AutoSwap_PRUint32 length;
     AutoSwap_PRUint32 language;
@@ -1428,111 +1426,8 @@ gfxFontUtils::IsCffFont(const uint8_t* a
     // this is only called after aFontData has passed basic validation,
     // so we know there is enough data present to allow us to read the version!
     const SFNTHeader *sfntHeader = reinterpret_cast<const SFNTHeader*>(aFontData);
     return (sfntHeader->sfntVersion == TRUETYPE_TAG('O','T','T','O'));
 }
 
 #endif
 
-NS_IMPL_ISUPPORTS1(gfxFontInfoLoader::ShutdownObserver, nsIObserver)
-
-NS_IMETHODIMP
-gfxFontInfoLoader::ShutdownObserver::Observe(nsISupports *aSubject,
-                                             const char *aTopic,
-                                             const char16_t *someData)
-{
-    if (!nsCRT::strcmp(aTopic, "quit-application")) {
-        mLoader->CancelLoader();
-    } else {
-        NS_NOTREACHED("unexpected notification topic");
-    }
-    return NS_OK;
-}
-
-void
-gfxFontInfoLoader::StartLoader(uint32_t aDelay, uint32_t aInterval)
-{
-    mInterval = aInterval;
-
-    // sanity check
-    if (mState != stateInitial && mState != stateTimerOff) {
-        CancelLoader();
-    }
-
-    // set up timer
-    if (!mTimer) {
-        mTimer = do_CreateInstance("@mozilla.org/timer;1");
-        if (!mTimer) {
-            NS_WARNING("Failure to create font info loader timer");
-            return;
-        }
-    }
-
-    // need an initial delay?
-    uint32_t timerInterval;
-
-    if (aDelay) {
-        mState = stateTimerOnDelay;
-        timerInterval = aDelay;
-    } else {
-        mState = stateTimerOnInterval;
-        timerInterval = mInterval;
-    }
-
-    InitLoader();
-
-    // start timer
-    mTimer->InitWithFuncCallback(LoaderTimerCallback, this, timerInterval,
-                                 nsITimer::TYPE_REPEATING_SLACK);
-
-    nsCOMPtr<nsIObserverService> obs = GetObserverService();
-    if (obs) {
-        mObserver = new ShutdownObserver(this);
-        obs->AddObserver(mObserver, "quit-application", false);
-    }
-}
-
-void
-gfxFontInfoLoader::CancelLoader()
-{
-    if (mState == stateInitial) {
-        return;
-    }
-    mState = stateTimerOff;
-    if (mTimer) {
-        mTimer->Cancel();
-        mTimer = nullptr;
-    }
-    RemoveShutdownObserver();
-    FinishLoader();
-}
-
-void
-gfxFontInfoLoader::LoaderTimerFire()
-{
-    if (mState == stateTimerOnDelay) {
-        mState = stateTimerOnInterval;
-        mTimer->SetDelay(mInterval);
-    }
-
-    bool done = RunLoader();
-    if (done) {
-        CancelLoader();
-    }
-}
-
-gfxFontInfoLoader::~gfxFontInfoLoader()
-{
-    RemoveShutdownObserver();
-}
-
-void
-gfxFontInfoLoader::RemoveShutdownObserver()
-{
-    if (mObserver) {
-        nsCOMPtr<nsIObserverService> obs = GetObserverService();
-        if (obs) {
-            obs->RemoveObserver(mObserver, "quit-application");
-            mObserver = nullptr;
-        }
-    }
-}
--- a/gfx/thebes/gfxFontUtils.h
+++ b/gfx/thebes/gfxFontUtils.h
@@ -2,22 +2,19 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_FONT_UTILS_H
 #define GFX_FONT_UTILS_H
 
 #include "gfxPlatform.h"
-#include "nsITimer.h"
-#include "nsCOMPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsTArray.h"
 #include "nsAutoPtr.h"
-#include "nsIObserver.h"
 #include "mozilla/Likely.h"
 #include "mozilla/Endian.h"
 #include "mozilla/MemoryReporting.h"
 
 #include "zlib.h"
 #include <algorithm>
 
 /* Bug 341128 - w32api defines min/max which causes problems with <bitset> */
@@ -938,85 +935,10 @@ protected:
                    ((mEncoding == rhs.mEncoding) && (mLanguage < rhs.mLanguage));
         }
     };
     static const MacFontNameCharsetMapping gMacFontNameCharsets[];
     static const char* gISOFontNameCharsets[];
     static const char* gMSFontNameCharsets[];
 };
 
-// helper class for loading in font info spaced out at regular intervals
-
-class gfxFontInfoLoader {
-public:
-
-    // state transitions:
-    //   initial ---StartLoader with delay---> timer on delay
-    //   initial ---StartLoader without delay---> timer on interval
-    //   timer on delay ---LoaderTimerFire---> timer on interval
-    //   timer on delay ---CancelLoader---> timer off
-    //   timer on interval ---CancelLoader---> timer off
-    //   timer off ---StartLoader with delay---> timer on delay
-    //   timer off ---StartLoader without delay---> timer on interval
-    typedef enum {
-        stateInitial,
-        stateTimerOnDelay,
-        stateTimerOnInterval,
-        stateTimerOff
-    } TimerState;
-
-    gfxFontInfoLoader() :
-        mInterval(0), mState(stateInitial)
-    {
-    }
-
-    virtual ~gfxFontInfoLoader();
-
-    // start timer with an initial delay, then call Run method at regular intervals
-    void StartLoader(uint32_t aDelay, uint32_t aInterval);
-
-    // cancel the timer and cleanup
-    void CancelLoader();
-
-protected:
-    class ShutdownObserver : public nsIObserver
-    {
-    public:
-        NS_DECL_ISUPPORTS
-        NS_DECL_NSIOBSERVER
-
-        ShutdownObserver(gfxFontInfoLoader *aLoader)
-            : mLoader(aLoader)
-        { }
-
-        virtual ~ShutdownObserver()
-        { }
-
-    protected:
-        gfxFontInfoLoader *mLoader;
-    };
-
-    // Init - initialization at start time after initial delay
-    virtual void InitLoader() = 0;
-
-    // Run - called at intervals, return true to indicate done
-    virtual bool RunLoader() = 0;
-
-    // Finish - cleanup after done
-    virtual void FinishLoader() = 0;
-
-    // Timer interval callbacks
-    static void LoaderTimerCallback(nsITimer *aTimer, void *aThis) {
-        gfxFontInfoLoader *loader = static_cast<gfxFontInfoLoader*>(aThis);
-        loader->LoaderTimerFire();
-    }
-
-    void LoaderTimerFire();
-
-    void RemoveShutdownObserver();
-
-    nsCOMPtr<nsITimer> mTimer;
-    nsCOMPtr<nsIObserver> mObserver;
-    uint32_t mInterval;
-    TimerState mState;
-};
 
 #endif /* GFX_FONT_UTILS_H */
--- a/gfx/thebes/gfxPlatformFontList.h
+++ b/gfx/thebes/gfxPlatformFontList.h
@@ -6,16 +6,17 @@
 #ifndef GFXPLATFORMFONTLIST_H_
 #define GFXPLATFORMFONTLIST_H_
 
 #include "nsDataHashtable.h"
 #include "nsRefPtrHashtable.h"
 #include "nsTHashtable.h"
 
 #include "gfxFontUtils.h"
+#include "gfxFontInfoLoader.h"
 #include "gfxFont.h"
 #include "gfxPlatform.h"
 
 #include "nsIMemoryReporter.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
 
 class CharMapHashKey : public PLDHashEntryHdr
--- a/gfx/thebes/moz.build
+++ b/gfx/thebes/moz.build
@@ -15,16 +15,17 @@ EXPORTS += [
     'gfxCachedTempSurface.h',
     'gfxColor.h',
     'gfxContext.h',
     'gfxDrawable.h',
     'gfxFailure.h',
     'gfxFont.h',
     'gfxFontConstants.h',
     'gfxFontFeatures.h',
+    'gfxFontInfoLoader.h',
     'gfxFontTest.h',
     'gfxFontUtils.h',
     'gfxGradientCache.h',
     'gfxImageSurface.h',
     'gfxLineSegment.h',
     'gfxMatrix.h',
     'gfxPath.h',
     'gfxPattern.h',
@@ -239,16 +240,17 @@ SOURCES += [
 UNIFIED_SOURCES += [
     'gfx3DMatrix.cpp',
     'gfxAlphaRecovery.cpp',
     'gfxBaseSharedMemorySurface.cpp',
     'gfxBlur.cpp',
     'gfxCachedTempSurface.cpp',
     'gfxContext.cpp',
     'gfxFontFeatures.cpp',
+    'gfxFontInfoLoader.cpp',
     'gfxFontMissingGlyphs.cpp',
     'gfxFontTest.cpp',
     'gfxGradientCache.cpp',
     'gfxGraphiteShaper.cpp',
     'gfxHarfBuzzShaper.cpp',
     'gfxImageSurface.cpp',
     'gfxMatrix.cpp',
     'gfxPath.cpp',