Bug 651017, part 6: prune unused and unimplemented nsDeviceContext methods. Push some code down into nsFontCache.
authorZack Weinberg <zackw@panix.com>
Sat, 16 Apr 2011 18:22:44 -0700
changeset 68311 2afcb1f14fad1acc2d90c3dd5d44c32bb8eea696
parent 68310 3237cf9bc6f8e9573ca383e60fac07ad16fdba4c
child 68312 1764e405eb02190b3c9377dc26177c728cebe641
push id19580
push userzackw@panix.com
push dateTue, 19 Apr 2011 15:10:15 +0000
treeherdermozilla-central@1764e405eb02 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs651017
milestone6.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 651017, part 6: prune unused and unimplemented nsDeviceContext methods. Push some code down into nsFontCache.
gfx/src/nsDeviceContext.cpp
gfx/src/nsDeviceContext.h
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsPageFrame.cpp
layout/printing/nsPrintEngine.cpp
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -103,16 +103,17 @@ public:
                            nsFontMetrics*& aMetrics);
 
     void FontMetricsDeleted(const nsFontMetrics* aFontMetrics);
     void Compact();
     void Flush();
 
 protected:
     nsDeviceContext*          mContext; // owner
+    nsCOMPtr<nsIAtom>         mLocaleLanguage;
     nsTArray<nsFontMetrics*>  mFontMetrics;
 };
 
 NS_IMPL_ISUPPORTS1(nsFontCache, nsIObserver)
 
 // The Init and Destroy methods are necessary because it's not
 // safe to call AddObserver from a constructor or RemoveObserver
 // from a destructor.  That should be fixed.
@@ -120,16 +121,25 @@ void
 nsFontCache::Init(nsDeviceContext* aContext)
 {
     mContext = aContext;
     // register as a memory-pressure observer to free font resources
     // in low-memory situations.
     nsCOMPtr<nsIObserverService> obs = GetObserverService();
     if (obs)
         obs->AddObserver(this, "memory-pressure", PR_FALSE);
+
+    nsCOMPtr<nsILanguageAtomService> langService;
+    langService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
+    if (langService) {
+        mLocaleLanguage = langService->GetLocaleLanguage();
+    }
+    if (!mLocaleLanguage) {
+        mLocaleLanguage = do_GetAtom("x-western");
+    }
 }
 
 void
 nsFontCache::Destroy()
 {
     nsCOMPtr<nsIObserverService> obs = GetObserverService();
     if (obs)
         obs->RemoveObserver(this, "memory-pressure");
@@ -144,16 +154,19 @@ nsFontCache::Observe(nsISupports*, const
     return NS_OK;
 }
 
 nsresult
 nsFontCache::GetMetricsFor(const nsFont& aFont, nsIAtom* aLanguage,
                            gfxUserFontSet* aUserFontSet,
                            nsFontMetrics*& aMetrics)
 {
+    if (!aLanguage)
+        aLanguage = mLocaleLanguage;
+
     // First check our cache
     // start from the end, which is where we put the most-recent-used element
 
     nsFontMetrics* fm;
     PRInt32 n = mFontMetrics.Length() - 1;
     for (PRInt32 i = n; i >= 0; --i) {
         fm = mFontMetrics[i];
         if (fm->Font().Equals(aFont) && fm->GetUserFontSet() == aUserFontSet &&
@@ -271,121 +284,48 @@ nsDeviceContext::nsDeviceContext()
 nsDeviceContext::~nsDeviceContext()
 {
     if (mFontCache) {
         mFontCache->Destroy();
         NS_RELEASE(mFontCache);
     }
 }
 
-void
-nsDeviceContext::CreateFontCache()
+nsresult
+nsDeviceContext::GetMetricsFor(const nsFont& aFont,
+                               nsIAtom* aLanguage,
+                               gfxUserFontSet* aUserFontSet,
+                               nsFontMetrics*& aMetrics)
 {
-    mFontCache = new nsFontCache();
-    NS_ADDREF(mFontCache);
-    mFontCache->Init(this);
-    GetLocaleLanguage();
+    if (!mFontCache) {
+        mFontCache = new nsFontCache();
+        NS_ADDREF(mFontCache);
+        mFontCache->Init(this);
+    }
+
+    return mFontCache->GetMetricsFor(aFont, aLanguage, aUserFontSet, aMetrics);
+}
+
+nsresult
+nsDeviceContext::FlushFontCache(void)
+{
+    if (mFontCache)
+        mFontCache->Flush();
+    return NS_OK;
 }
 
 nsresult
 nsDeviceContext::FontMetricsDeleted(const nsFontMetrics* aFontMetrics)
 {
     if (mFontCache) {
         mFontCache->FontMetricsDeleted(aFontMetrics);
     }
     return NS_OK;
 }
 
-void
-nsDeviceContext::GetLocaleLanguage(void)
-{
-    if (!mLocaleLanguage) {
-        nsCOMPtr<nsILanguageAtomService> langService;
-        langService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
-        if (langService) {
-            mLocaleLanguage = langService->GetLocaleLanguage();
-        }
-        if (!mLocaleLanguage) {
-            mLocaleLanguage = do_GetAtom("x-western");
-        }
-    }
-}
-
-nsresult
-nsDeviceContext::GetMetricsFor(const nsFont& aFont,
-                               nsIAtom* aLanguage,
-                               gfxUserFontSet* aUserFontSet,
-                               nsFontMetrics*& aMetrics)
-{
-    if (!mFontCache)
-        CreateFontCache();
-
-    // XXX figure out why aLanguage is NULL sometimes
-    //      -> see nsPageFrame.cpp:511
-    if (!aLanguage) {
-        aLanguage = mLocaleLanguage;
-    }
-
-    return mFontCache->GetMetricsFor(aFont, aLanguage, aUserFontSet, aMetrics);
-}
-
-nsresult
-nsDeviceContext::GetMetricsFor(const nsFont& aFont,
-                               gfxUserFontSet* aUserFontSet,
-                               nsFontMetrics*& aMetrics)
-{
-    if (!mFontCache)
-        CreateFontCache();
-
-    return mFontCache->GetMetricsFor(aFont, mLocaleLanguage, aUserFontSet,
-                                     aMetrics);
-}
-
-struct FontEnumData {
-    FontEnumData(nsString& aFaceName) : mFaceName(aFaceName) {}
-    nsString& mFaceName;
-};
-
-static PRBool
-FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData)
-{
-    FontEnumData* data = (FontEnumData*)aData;
-    data->mFaceName = aFamily;
-    return PR_FALSE; // stop
-}
-
-nsresult
-nsDeviceContext::FirstExistingFont(const nsFont& aFont,
-                                   nsString& aFaceName)
-{
-    FontEnumData data(aFaceName);
-    if (aFont.EnumerateFamilies(FontEnumCallback, &data)) {
-        return NS_ERROR_FAILURE; // can only happen for an empty font
-    }
-    return NS_OK;
-}
-
-nsresult
-nsDeviceContext::GetLocalFontName(const nsString& aFaceName,
-                                  nsString& aLocalName,
-                                  PRBool& aAliased)
-{
-    aLocalName = aFaceName;
-    aAliased = PR_FALSE;
-    return NS_OK;
-}
-
-nsresult
-nsDeviceContext::FlushFontCache(void)
-{
-    if (mFontCache)
-        mFontCache->Flush();
-    return NS_OK;
-}
-
 PRBool
 nsDeviceContext::IsPrinterSurface()
 {
     return(mPrintingSurface != NULL);
 }
 
 void
 nsDeviceContext::SetDPI()
@@ -498,30 +438,16 @@ nsDeviceContext::Init(nsIWidget *aWidget
         return NS_OK;
 
     mScreenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
 
     return NS_OK;
 }
 
 nsresult
-nsDeviceContext::CreateRenderingContext(nsIView *aView,
-                                        nsRenderingContext *&aContext)
-{
-    // This is currently only called by the caret code
-    NS_ENSURE_ARG_POINTER(aView);
-    NS_PRECONDITION(aView->HasWidget(), "View has no widget!");
-
-    nsCOMPtr<nsIWidget> widget;
-    widget = aView->GetWidget();
-
-    return CreateRenderingContext(widget, aContext);
-}
-
-nsresult
 nsDeviceContext::CreateRenderingContext(nsIWidget *aWidget,
                                         nsRenderingContext *&aContext)
 {
     nsresult rv;
 
     aContext = nsnull;
     nsRefPtr<nsRenderingContext> pContext;
     rv = CreateRenderingContextInstance(*getter_AddRefs(pContext));
@@ -619,22 +545,16 @@ nsDeviceContext::GetSystemFont(nsSystemF
     aFont->size = NSFloatPixelsToAppUnits(fontStyle.size, UnscaledAppUnitsPerDevPixel());
     //aFont->langGroup = fontStyle.langGroup;
     aFont->sizeAdjust = fontStyle.sizeAdjust;
 
     return rv;
 }
 
 nsresult
-nsDeviceContext::CheckFontExistence(const nsString& aFaceName)
-{
-    return NS_OK;
-}
-
-nsresult
 nsDeviceContext::GetDepth(PRUint32& aDepth)
 {
     if (mDepth == 0) {
         nsCOMPtr<nsIScreen> primaryScreen;
         mScreenManager->GetPrimaryScreen(getter_AddRefs(primaryScreen));
         primaryScreen->GetColorDepth(reinterpret_cast<PRInt32 *>(&mDepth));
     }
 
@@ -686,27 +606,16 @@ nsDeviceContext::GetClientRect(nsRect &a
     }
     else
         ComputeClientRectUsingScreen(&aRect);
 
     return NS_OK;
 }
 
 nsresult
-nsDeviceContext::PrepareNativeWidget(nsIWidget* aWidget, void** aOut)
-{
-    *aOut = nsnull;
-    return NS_OK;
-}
-
-
-/*
- * below methods are for printing
- */
-nsresult
 nsDeviceContext::InitForPrinting(nsIDeviceContextSpec *aDevice)
 {
     NS_ENSURE_ARG_POINTER(aDevice);
 
     mDeviceContextSpec = aDevice;
 
     nsresult rv = aDevice->GetSurfaceForPrinter(getter_AddRefs(mPrintingSurface));
     if (NS_FAILED(rv))
@@ -714,25 +623,16 @@ nsDeviceContext::InitForPrinting(nsIDevi
 
     Init(nsnull);
 
     CalcPrintingSize();
 
     return NS_OK;
 }
 
-
-nsresult
-nsDeviceContext::PrepareDocument(PRUnichar * aTitle,
-                                 PRUnichar*  aPrintToFileName)
-{
-    return NS_OK;
-}
-
-
 nsresult
 nsDeviceContext::BeginDocument(PRUnichar*  aTitle,
                                PRUnichar*  aPrintToFileName,
                                PRInt32     aStartPage,
                                PRInt32     aEndPage)
 {
     static const PRUnichar kEmpty[] = { '\0' };
     nsresult rv;
@@ -809,18 +709,16 @@ nsDeviceContext::EndPage(void)
 #endif
 
     if (mDeviceContextSpec)
         mDeviceContextSpec->EndPage();
 
     return rv;
 }
 
-/** End printing methods **/
-
 void
 nsDeviceContext::ComputeClientRectUsingScreen(nsRect* outRect)
 {
     // we always need to recompute the clientRect
     // because the window may have moved onto a different screen. In the single
     // monitor case, we only need to do the computation if we haven't done it
     // once already, and remember that we have because we're assured it won't change.
     nsCOMPtr<nsIScreen> screen;
--- a/gfx/src/nsDeviceContext.h
+++ b/gfx/src/nsDeviceContext.h
@@ -36,24 +36,23 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _NS_DEVICECONTEXT_H_
 #define _NS_DEVICECONTEXT_H_
 
 #include "nsCOMPtr.h"
-#include "nsIAtom.h"
 #include "nsIDeviceContextSpec.h"
 #include "nsIScreenManager.h"
 #include "nsIWidget.h"
 #include "nsCoord.h"
 #include "gfxContext.h"
 
-class nsIView;
+class nsIAtom;
 class nsFontCache;
 class gfxUserFontSet;
 
 typedef enum {
     eSystemFont_Caption,         // css2
     eSystemFont_Icon,
     eSystemFont_Menu,
     eSystemFont_MessageBox,
@@ -93,25 +92,16 @@ public:
     /**
      * Initialize the device context from a device context spec
      * @param aDevSpec the specification of the printing device
      * @return error status
      */
     nsresult InitForPrinting(nsIDeviceContextSpec *aDevSpec);
 
     /**
-     * Create a rendering context and initialize it from an nsIView
-     * @param aView view to initialize context from
-     * @param aContext out parameter for new rendering context
-     * @return error status
-     */
-    nsresult CreateRenderingContext(nsIView *aView,
-                                    nsRenderingContext *&aContext);
-
-    /**
      * Create a rendering context and initialize it from an nsIWidget
      * @param aWidget widget to initialize context from
      * @param aContext out parameter for new rendering context
      * @return error status
      */
     nsresult CreateRenderingContext(nsIWidget *aWidget,
                                     nsRenderingContext *&aContext);
 
@@ -125,36 +115,22 @@ public:
     /**
      * Create an uninitalised rendering context.
      * @param aContext out parameter for new rendering context
      * @return error status
      */
     nsresult CreateRenderingContextInstance(nsRenderingContext *&aContext);
 
     /**
-     * We are in the process of creating the native widget for
-     * aWidget.  Do any device-specific processing required to
-     * initialize the native widget for this device. A pointer to some
-     * platform-specific data is returned in aOut.
-     */
-    nsresult PrepareNativeWidget(nsIWidget *aWidget, void **aOut);
-
-    /**
      * Gets the number of app units in one CSS pixel; this number is global,
      * not unique to each device context.
      */
     static PRInt32 AppUnitsPerCSSPixel() { return 60; }
 
     /**
-     * Convert app units to CSS pixels.  This is a global scale factor.
-     */
-    static gfxFloat AppUnitsToGfxCSSPixels(nscoord aAppUnits)
-    { return gfxFloat(aAppUnits) / AppUnitsPerCSSPixel(); }
-
-    /**
      * Gets the number of app units in one device pixel; this number
      * is usually a factor of AppUnitsPerCSSPixel(), although that is
      * not guaranteed.
      */
     PRInt32 AppUnitsPerDevPixel() const { return mAppUnitsPerDevPixel; }
 
     /**
      * Convert device pixels which is used for gfx/thebes to nearest
@@ -214,52 +190,29 @@ public:
      * @param aUserFontSet user font set
      * @return error status
      */
     nsresult GetMetricsFor(const nsFont& aFont, nsIAtom* aLanguage,
                            gfxUserFontSet* aUserFontSet,
                            nsFontMetrics*& aMetrics);
 
     /**
-     * Get the nsFontMetrics that describe the properties of
-     * an nsFont.
-     * @param aFont font description to obtain metrics for
-     * @param aMetrics out parameter for font metrics
-     * @param aUserFontSet user font set
-     * @return error status
-     */
-    nsresult GetMetricsFor(const nsFont& aFont,
-                           gfxUserFontSet* aUserFontSet,
-                           nsFontMetrics*& aMetrics);
-
-    /**
      * Notification when a font metrics instance created for this device is
      * about to be deleted
      */
     nsresult FontMetricsDeleted(const nsFontMetrics* aFontMetrics);
 
     /**
      * Attempt to free up resources by flushing out any fonts no longer
      * referenced by anything other than the font cache itself.
      * @return error status
      */
     nsresult FlushFontCache();
 
     /**
-     * Check to see if a particular named font exists.
-     * @param aFontName character string of font face name
-     * @return NS_OK if font is available, else font is unavailable
-     */
-    nsresult CheckFontExistence(const nsString& aFaceName);
-    nsresult FirstExistingFont(const nsFont& aFont, nsString& aFaceName);
-    nsresult GetLocalFontName(const nsString& aFaceName, nsString& aLocalName,
-                              PRBool& aAliased);
-
-
-    /**
      * Return the bit depth of the device.
      */
     nsresult GetDepth(PRUint32& aDepth);
 
     /**
      * Get the size of the displayable area of the output device
      * in app units.
      * @param aWidth out parameter for width
@@ -288,27 +241,16 @@ public:
      *              be (0,0) adjusted for any upper/left non-client
      *              space if present or relative to the primary
      *              monitor if this is not the primary.
      * @return error status
      */
     nsresult GetClientRect(nsRect& aRect);
 
     /**
-     * Do anything that needs to be done to prepare for printing.
-     * @param aTitle - title of Document
-     * @param aPrintToFileName - name of file to print to, if NULL
-     * then don't print to file
-     *
-     * @return error status
-     */
-    nsresult PrepareDocument(PRUnichar *aTitle,
-                             PRUnichar *aPrintToFileName);
-
-    /**
      * Inform the output device that output of a document is beginning
      * Used for print related device contexts. Must be matched 1:1 with
      * EndDocument() or AbortDocument().
      *
      * @param aTitle - title of Document
      * @param aPrintToFileName - name of file to print to, if NULL
      * then don't print to file
      * @param aStartPage - starting page number (must be greater than zero)
@@ -364,29 +306,21 @@ public:
     /**
      * Set the pixel scaling factor: all lengths are multiplied by this factor
      * when we convert them to device pixels. Returns whether the ratio of
      * app units to dev pixels changed because of the scale factor.
      */
     PRBool SetPixelScale(float aScale);
 
     /**
-     * Get the pixel scaling factor; defaults to 1.0, but can be changed with
-     * SetPixelScale.
-     */
-    float GetPixelScale() const { return mPixelScale; }
-
-    /**
      * True if this device context was created for printing.
      */
     PRBool IsPrinterSurface();
 
 protected:
-    void CreateFontCache();
-    void GetLocaleLanguage();
     void SetDPI();
     void ComputeClientRectUsingScreen(nsRect *outRect);
     void ComputeFullAreaUsingScreen(nsRect *outRect);
     void FindScreen(nsIScreen **outScreen);
     void CalcPrintingSize();
     void UpdateScaledAppUnits();
 
     nscoord  mWidth;
@@ -394,16 +328,15 @@ protected:
     PRUint32 mDepth;
     PRInt32  mAppUnitsPerDevPixel;
     PRInt32  mAppUnitsPerDevNotScaledPixel;
     PRInt32  mAppUnitsPerPhysicalInch;
     float    mPixelScale;
     float    mPrintingScale;
 
     nsFontCache*                   mFontCache;
-    nsCOMPtr<nsIAtom>              mLocaleLanguage;
     nsCOMPtr<nsIWidget>            mWidget;
     nsCOMPtr<nsIScreenManager>     mScreenManager;
     nsCOMPtr<nsIDeviceContextSpec> mDeviceContextSpec;
     nsRefPtr<gfxASurface>          mPrintingSurface;
 };
 
 #endif /* _NS_DEVICECONTEXT_H_ */
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -1961,18 +1961,16 @@ nsGfxScrollFrameInner::BuildDisplayList(
   dirtyRect.IntersectRect(aDirtyRect, mScrollPort);
 
   // Override the dirty rectangle if the displayport has been set.
   PRBool usingDisplayport =
     nsLayoutUtils::GetDisplayPort(mOuter->GetContent(), &dirtyRect);
 
   nsDisplayListCollection set;
 
-  nsPresContext* presContext = mOuter->PresContext();
-
   // Since making new layers is expensive, only use nsDisplayScrollLayer
   // if the area is scrollable.
   //
   // Scroll frames can be generated with a scroll range that is 0, 0.
   // Furthermore, it is not worth the memory tradeoff to allow asynchronous
   // scrolling of small scroll frames. We use an arbitrary minimum scroll
   // range of 20 pixels to eliminate many gfx scroll frames from becoming a
   // layer.
--- a/layout/generic/nsPageFrame.cpp
+++ b/layout/generic/nsPageFrame.cpp
@@ -505,17 +505,17 @@ nsPageFrame::PaintHeaderFooter(nsRenderi
 
   nsRect rect(aPt.x, aPt.y, mRect.width - mPD->mShadowSize.width,
               mRect.height - mPD->mShadowSize.height);
 
   aRenderingContext.SetColor(NS_RGB(0,0,0));
 
   // Get the FontMetrics to determine width.height of strings
   nsRefPtr<nsFontMetrics> fontMet;
-  pc->DeviceContext()->GetMetricsFor(*mPD->mHeadFootFont,
+  pc->DeviceContext()->GetMetricsFor(*mPD->mHeadFootFont, nsnull,
                                      pc->GetUserFontSet(),
                                      *getter_AddRefs(fontMet));
 
   aRenderingContext.SetFont(fontMet);
 
   nscoord ascent = 0;
   nscoord visibleHeight = 0;
   if (fontMet) {
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -724,34 +724,21 @@ nsPrintEngine::DoCommonPrint(PRBool     
 
     if (!notifyOnInit) {
       rv = FinishPrintPreview();
     } else {
       rv = NS_OK;
     }
     NS_ENSURE_SUCCESS(rv, rv);
   } else {
-    PRUnichar * docTitleStr;
-    PRUnichar * docURLStr;
-
-    GetDisplayTitleAndURL(mPrt->mPrintObject, &docTitleStr, &docURLStr, eDocTitleDefURLDoc); 
-
-    // Nobody ever cared about the file name passed in, as far as I can tell
-    rv = mPrt->mPrintDC->PrepareDocument(docTitleStr, nsnull);
-
-    if (docTitleStr) nsMemory::Free(docTitleStr);
-    if (docURLStr) nsMemory::Free(docURLStr);
-
-    NS_ENSURE_SUCCESS(rv, rv);
-
     PRBool doNotify;
     ShowPrintProgress(PR_TRUE, doNotify);
     if (!doNotify) {
       // Print listener setup...
-      mPrt->OnStartPrinting();    
+      mPrt->OnStartPrinting();
       rv = DocumentReadyForPrinting();
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   // We will enable scripting later after printing has finished.
   scriptSuppressor.Disconnect();