Bug 422774 - reduce narrow Windows API calls in gfx, original patch by Brad Lassey <blassey@mozilla.com>, r=pavlov
authorBrian Crowder <crowder@fiverocks.com>
Wed, 27 Aug 2008 14:44:55 -0700
changeset 18480 4dd270901e745533c34ba54108d6d3b2c3574b40
parent 18479 73d8df3129ac6a0ddd0d0b99aaa6704441f67a70
child 18481 e17e0d80a9625a9657667b8772b0ee8251619f02
push id1575
push userbcrowder@mozilla.com
push dateWed, 27 Aug 2008 21:46:09 +0000
treeherdermozilla-central@f97dbb2beaab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspavlov
bugs422774
milestone1.9.1a2pre
Bug 422774 - reduce narrow Windows API calls in gfx, original patch by Brad Lassey <blassey@mozilla.com>, r=pavlov
gfx/src/thebes/nsSystemFontsWin.cpp
gfx/src/thebes/nsSystemFontsWin.h
gfx/thebes/src/gfxWindowsFonts.cpp
gfx/thebes/src/gfxWindowsSurface.cpp
--- a/gfx/src/thebes/nsSystemFontsWin.cpp
+++ b/gfx/src/thebes/nsSystemFontsWin.cpp
@@ -38,29 +38,23 @@
 
 #include "nsIRenderingContext.h"
 
 #include "gfxWindowsSurface.h"
 
 #include "nsSystemFontsWin.h"
 
 
-nsresult nsSystemFontsWin::CopyLogFontToNSFont(HDC* aHDC, const LOGFONT* ptrLogFont,
-					       nsString *aFontName,
-                                               gfxFontStyle *aFontStyle,
-                                               PRBool aIsWide) const
+nsresult nsSystemFontsWin::CopyLogFontToNSFont(HDC* aHDC, const LOGFONTW* ptrLogFont,
+                                               nsString *aFontName,
+                                               gfxFontStyle *aFontStyle) const
 {
   PRUnichar name[LF_FACESIZE];
   name[0] = 0;
-  if (aIsWide)
-    memcpy(name, ptrLogFont->lfFaceName, LF_FACESIZE*2);
-  else {
-    MultiByteToWideChar(CP_ACP, 0, ptrLogFont->lfFaceName,
-      strlen(ptrLogFont->lfFaceName) + 1, name, sizeof(name)/sizeof(name[0]));
-  }
+  memcpy(name, ptrLogFont->lfFaceName, LF_FACESIZE*sizeof(PRUnichar));
   *aFontName = name;
 
   // Do Style
   aFontStyle->style = FONT_STYLE_NORMAL;
   if (ptrLogFont->lfItalic)
   {
     aFontStyle->style = FONT_STYLE_ITALIC;
   }
@@ -80,17 +74,17 @@ nsresult nsSystemFontsWin::CopyLogFontTo
   //
   // So this accounts for the difference in the DeviceContexts
   // The mPixelScale will be a "1" for the screen and could be
   // any value when going to a printer, for example mPixleScale is
   // 6.25 when going to a 600dpi printer.
   // round, but take into account whether it is negative
   float pixelHeight = -ptrLogFont->lfHeight;
   if (pixelHeight < 0) {
-    HFONT hFont = ::CreateFontIndirect(ptrLogFont);
+    HFONT hFont = ::CreateFontIndirectW(ptrLogFont);
     if (!hFont)
       return NS_ERROR_OUT_OF_MEMORY;
     HGDIOBJ hObject = ::SelectObject(*aHDC, hFont);
     TEXTMETRIC tm;
     ::GetTextMetrics(*aHDC, &tm);
     ::SelectObject(*aHDC, hObject);
     ::DeleteObject(hFont);
     pixelHeight = tm.tmAscent;
@@ -111,42 +105,42 @@ nsresult nsSystemFontsWin::CopyLogFontTo
 }
 
 nsresult nsSystemFontsWin::GetSysFontInfo(HDC aHDC, nsSystemFontID anID,
                                           nsString *aFontName,
                                           gfxFontStyle *aFontStyle) const
 {
   HGDIOBJ hGDI;
 
-  LOGFONT logFont;
-  LOGFONT* ptrLogFont = NULL;
+  LOGFONTW logFont;
+  LOGFONTW* ptrLogFont = NULL;
 
 #ifdef WINCE
   hGDI = ::GetStockObject(SYSTEM_FONT);
   if (hGDI == NULL)
     return NS_ERROR_UNEXPECTED;
   
-  if (::GetObject(hGDI, sizeof(logFont), &logFont) > 0)
+  if (::GetObjectW(hGDI, sizeof(logFont), &logFont) > 0)
     ptrLogFont = &logFont;
 #else
 
-  NONCLIENTMETRICS ncm;
+  NONCLIENTMETRICSW ncm;
 
   BOOL status;
   if (anID == eSystemFont_Icon) 
   {
-    status = ::SystemParametersInfo(SPI_GETICONTITLELOGFONT,
-                                  sizeof(logFont),
-                                  (PVOID)&logFont,
-                                  0);
+    status = ::SystemParametersInfoW(SPI_GETICONTITLELOGFONT,
+                                     sizeof(logFont),
+                                     (PVOID)&logFont,
+                                     0);
   }
   else
   {
-    ncm.cbSize = sizeof(NONCLIENTMETRICS);
-    status = ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 
+    ncm.cbSize = sizeof(NONCLIENTMETRICSW);
+    status = ::SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, 
                                      sizeof(ncm),  
                                      (PVOID)&ncm, 
                                      0);
   }
 
   if (!status)
   {
     return NS_ERROR_FAILURE;
@@ -191,17 +185,17 @@ nsresult nsSystemFontsWin::GetSysFontInf
     case eSystemFont_Button:
     case eSystemFont_PullDownMenu:
     case eSystemFont_List:
     case eSystemFont_Field:
     case eSystemFont_Caption: 
       hGDI = ::GetStockObject(DEFAULT_GUI_FONT);
       if (hGDI != NULL)
       {
-        if (::GetObject(hGDI, sizeof(logFont), &logFont) > 0)
+        if (::GetObjectW(hGDI, sizeof(logFont), &logFont) > 0)
         { 
           ptrLogFont = &logFont;
         }
       }
       break;
   } // switch 
 
 #endif // WINCE
--- a/gfx/src/thebes/nsSystemFontsWin.h
+++ b/gfx/src/thebes/nsSystemFontsWin.h
@@ -45,18 +45,17 @@
 class nsSystemFontsWin
 {
 public:
     nsSystemFontsWin();
 
     nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
                            gfxFontStyle *aFontStyle) const;
 private:
-    nsresult CopyLogFontToNSFont(HDC* aHDC, const LOGFONT* ptrLogFont,
-                                 nsString *aFontName, gfxFontStyle *aFontStyle,
-				 PRBool aIsWide = PR_FALSE) const;
+    nsresult CopyLogFontToNSFont(HDC* aHDC, const LOGFONTW* ptrLogFont,
+                                 nsString *aFontName, gfxFontStyle *aFontStyle) const;
     nsresult GetSysFontInfo(HDC aHDC, nsSystemFontID anID,
                             nsString *aFontName,
                             gfxFontStyle *aFontStyle) const;
 };
 
 #endif /* _NS_SYSTEMFONTSWIN_H_ */
 
--- a/gfx/thebes/src/gfxWindowsFonts.cpp
+++ b/gfx/thebes/src/gfxWindowsFonts.cpp
@@ -637,32 +637,32 @@ gfxWindowsFont::ComputeMetrics()
     // The font is monospace when TMPF_FIXED_PITCH is *not* set!
     // See http://msdn2.microsoft.com/en-us/library/ms534202(VS.85).aspx
     if (!(metrics.tmPitchAndFamily & TMPF_FIXED_PITCH)) {
       mMetrics->maxAdvance = mMetrics->aveCharWidth;
     }
 
     // Cache the width of a single space.
     SIZE size;
-    GetTextExtentPoint32(dc, " ", 1, &size);
+    GetTextExtentPoint32W(dc, L" ", 1, &size);
     mMetrics->spaceWidth = ROUND(size.cx);
 
     // Cache the width of digit zero.
     // XXX MSDN (http://msdn.microsoft.com/en-us/library/ms534223.aspx)
     // does not say what the failure modes for GetTextExtentPoint32 are -
     // is it safe to assume it will fail iff the font has no '0'?
     if (GetTextExtentPoint32(dc, "0", 1, &size))
         mMetrics->zeroOrAveCharWidth = ROUND(size.cx);
     else
         mMetrics->zeroOrAveCharWidth = mMetrics->aveCharWidth;
 
     mSpaceGlyph = 0;
     if (metrics.tmPitchAndFamily & TMPF_TRUETYPE) {
         WORD glyph;
-        DWORD ret = GetGlyphIndicesA(dc, " ", 1, &glyph,
+        DWORD ret = GetGlyphIndicesW(dc, L" ", 1, &glyph,
                                      GGI_MARK_NONEXISTING_GLYPHS);
         if (ret != GDI_ERROR && glyph != 0xFFFF) {
             mSpaceGlyph = glyph;
         }
     }
 
     SelectObject(dc, oldFont);
 
--- a/gfx/thebes/src/gfxWindowsSurface.cpp
+++ b/gfx/thebes/src/gfxWindowsSurface.cpp
@@ -163,64 +163,36 @@ gfxWindowsSurface::OptimizeToDDB(HDC dc,
     tmpCtx.SetSource(this);
     tmpCtx.Paint();
 
     gfxWindowsSurface *raw = (gfxWindowsSurface*) (wsurf.get());
     NS_ADDREF(raw);
     return raw;
 }
 
-static char*
-GetACPString(const nsAString& aStr)
-{
-    int acplen = aStr.Length() * 2 + 1;
-    char * acp = new char[acplen];
-    if(acp) {
-        int outlen = ::WideCharToMultiByte(CP_ACP, 0, 
-                                           PromiseFlatString(aStr).get(),
-                                           aStr.Length(),
-                                           acp, acplen, NULL, NULL);
-        if (outlen > 0)
-            acp[outlen] = '\0';  // null terminate
-    }
-    return acp;
-}
-
 nsresult gfxWindowsSurface::BeginPrinting(const nsAString& aTitle,
                                           const nsAString& aPrintToFileName)
 {
 #define DOC_TITLE_LENGTH 30
-    DOCINFO docinfo;
+    DOCINFOW docinfo;
 
-    nsString titleStr;
-    titleStr = aTitle;
+    nsString titleStr(aTitle);
     if (titleStr.Length() > DOC_TITLE_LENGTH) {
         titleStr.SetLength(DOC_TITLE_LENGTH-3);
         titleStr.AppendLiteral("...");
     }
-    char *title = GetACPString(titleStr);
 
-    char *docName = nsnull;
-    if (!aPrintToFileName.IsEmpty()) {
-        docName = ToNewCString(aPrintToFileName);
-    }
-
+    nsString docName(aPrintToFileName);
     docinfo.cbSize = sizeof(docinfo);
-    docinfo.lpszDocName = title ? title : "Mozilla Document";
-    docinfo.lpszOutput = docName;
+    docinfo.lpszDocName = titleStr.Length() > 0 ? titleStr.get() : L"Mozilla Document";
+    docinfo.lpszOutput = docName.Length() > 0 ? docName.get() : nsnull;
     docinfo.lpszDatatype = NULL;
     docinfo.fwType = 0;
 
-    int result = ::StartDoc(mDC, &docinfo);
-        
-    delete [] title;
-    if (docName != nsnull) nsMemory::Free(docName);
-
-    if (result <= 0)
-        return NS_ERROR_FAILURE;
+    ::StartDocW(mDC, &docinfo);
 
     return NS_OK;
 }
 
 nsresult gfxWindowsSurface::EndPrinting()
 {
     int result = ::EndDoc(mDC);
     if (result <= 0)