[chromium] Convert uses of GetDC to HWndDC.
authorlevin@chromium.org <levin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2012 00:22:38 +0000 (00:22 +0000)
committerlevin@chromium.org <levin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2012 00:22:38 +0000 (00:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76290

Reviewed by Dmitry Titov.

* platform/graphics/chromium/FontCacheChromiumWin.cpp:
(WebCore::createFontIndirectAndGetWinName):
(WebCore::fontContainsCharacter):
(WebCore::FontCache::getLastResortFallbackFont):
(WebCore::FontCache::getTraitsInFamily):
* platform/graphics/chromium/FontPlatformDataChromiumWin.cpp:
(WebCore::FontPlatformData::scriptFontProperties):
* platform/graphics/chromium/FontUtilsChromiumWin.cpp:
(WebCore::FontMap::getAscent):
(WebCore::FontMap::getSpaceGlyph):
* platform/graphics/chromium/GlyphPageTreeNodeChromiumWin.cpp:
(WebCore::fillBMPGlyphs):
* platform/graphics/chromium/SimpleFontDataChromiumWin.cpp:
(WebCore::SimpleFontData::platformInit):
(WebCore::SimpleFontData::determinePitch):
(WebCore::SimpleFontData::platformWidthForGlyph):
* platform/graphics/chromium/UniscribeHelper.cpp:
(WebCore::UniscribeHelper::EnsureCachedDCCreated):
* rendering/RenderThemeChromiumWin.cpp:
(WebCore::systemFontSize):
(WebCore::pointsToPixels):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105654 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/FontCacheChromiumWin.cpp
Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp
Source/WebCore/platform/graphics/chromium/FontUtilsChromiumWin.cpp
Source/WebCore/platform/graphics/chromium/GlyphPageTreeNodeChromiumWin.cpp
Source/WebCore/platform/graphics/chromium/SimpleFontDataChromiumWin.cpp
Source/WebCore/platform/graphics/chromium/UniscribeHelper.cpp
Source/WebCore/rendering/RenderThemeChromiumWin.cpp

index fb93fc3..6c706ba 100644 (file)
@@ -1,3 +1,32 @@
+2012-01-13  David Levin  <levin@chromium.org>
+
+        [chromium] Convert uses of GetDC to HWndDC.
+        https://bugs.webkit.org/show_bug.cgi?id=76290
+
+        Reviewed by Dmitry Titov.
+
+        * platform/graphics/chromium/FontCacheChromiumWin.cpp:
+        (WebCore::createFontIndirectAndGetWinName):
+        (WebCore::fontContainsCharacter):
+        (WebCore::FontCache::getLastResortFallbackFont):
+        (WebCore::FontCache::getTraitsInFamily):
+        * platform/graphics/chromium/FontPlatformDataChromiumWin.cpp:
+        (WebCore::FontPlatformData::scriptFontProperties):
+        * platform/graphics/chromium/FontUtilsChromiumWin.cpp:
+        (WebCore::FontMap::getAscent):
+        (WebCore::FontMap::getSpaceGlyph):
+        * platform/graphics/chromium/GlyphPageTreeNodeChromiumWin.cpp:
+        (WebCore::fillBMPGlyphs):
+        * platform/graphics/chromium/SimpleFontDataChromiumWin.cpp:
+        (WebCore::SimpleFontData::platformInit):
+        (WebCore::SimpleFontData::determinePitch):
+        (WebCore::SimpleFontData::platformWidthForGlyph):
+        * platform/graphics/chromium/UniscribeHelper.cpp:
+        (WebCore::UniscribeHelper::EnsureCachedDCCreated):
+        * rendering/RenderThemeChromiumWin.cpp:
+        (WebCore::systemFontSize):
+        (WebCore::pointsToPixels):
+
 2012-01-23  Joe Thomas  <joethomas@motorola.com>
 
         https://bugs.webkit.org/show_bug.cgi?id=75799
index 9f5bd49..a50e6ab 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2006, 2007 Apple Computer, Inc.
- * Copyright (c) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
+ * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -36,6 +36,7 @@
 #include "FontUtilsChromiumWin.h"
 #include "HashMap.h"
 #include "HashSet.h"
+#include "HWndDC.h"
 #include "PlatformSupport.h"
 #include "SimpleFontData.h"
 #include <unicode/uniset.h>
@@ -241,7 +242,7 @@ static HFONT createFontIndirectAndGetWinName(const String& family, LOGFONT* winf
     if (!hfont)
         return 0;
 
-    HDC dc = GetDC(0);
+    HWndDC dc(0);
     HGDIOBJ oldFont = static_cast<HFONT>(SelectObject(dc, hfont));
     WCHAR name[LF_FACESIZE];
     unsigned resultLength = GetTextFace(dc, LF_FACESIZE, name);
@@ -249,7 +250,6 @@ static HFONT createFontIndirectAndGetWinName(const String& family, LOGFONT* winf
         resultLength--; // ignore the null terminator
 
     SelectObject(dc, oldFont);
-    ReleaseDC(0, dc);
     *winName = String(name, resultLength);
     return hfont;
 }
@@ -279,7 +279,7 @@ static bool fontContainsCharacter(const FontPlatformData* fontData,
         return it->second->contains(character);
     
     HFONT hfont = fontData->hfont(); 
-    HDC hdc = GetDC(0);
+    HWndDC hdc(0);
     HGDIOBJ oldFont = static_cast<HFONT>(SelectObject(hdc, hfont));
     int count = GetFontUnicodeRanges(hdc, 0);
     if (!count && PlatformSupport::ensureFontLoaded(hfont))
@@ -287,7 +287,6 @@ static bool fontContainsCharacter(const FontPlatformData* fontData,
     if (!count) {
         LOG_ERROR("Unable to get the font unicode range after second attempt");
         SelectObject(hdc, oldFont);
-        ReleaseDC(0, hdc);
         return true;
     }
 
@@ -299,7 +298,6 @@ static bool fontContainsCharacter(const FontPlatformData* fontData,
     count = GetFontUnicodeRanges(hdc, glyphset);
     ASSERT(count > 0);
     SelectObject(hdc, oldFont);
-    ReleaseDC(0, hdc);
 
     // FIXME: consider doing either of the following two:
     // 1) port back ICU 4.0's faster look-up code for UnicodeSet
@@ -571,11 +569,10 @@ SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& desc
     // both GetTextFace() and EnumFontFamilies() return the localized name. So,
     // FontCache::createFontPlatformData() does not filter out the fonts
     // returned by this EnumFontFamilies() call.
-    HDC dc = GetDC(0);
+    HWndDC dc(0);
     if (dc) {
         GetLastResortFallbackFontProcData procData(this, &description, shouldRetain, fallbackFontName);
         EnumFontFamilies(dc, 0, getLastResortFallbackFontProc, reinterpret_cast<LPARAM>(&procData));
-        ReleaseDC(0, dc);
 
         if (procData.m_fontData)
             return procData.m_fontData;
@@ -587,7 +584,7 @@ SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& desc
 
 void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigned>& traitsMasks)
 {
-    HDC hdc = GetDC(0);
+    HWndDC hdc(0);
 
     LOGFONT logFont;
     logFont.lfCharSet = DEFAULT_CHARSET;
@@ -599,8 +596,6 @@ void FontCache::getTraitsInFamily(const AtomicString& familyName, Vector<unsigne
     TraitsInFamilyProcData procData(familyName);
     EnumFontFamiliesEx(hdc, &logFont, traitsInFamilyEnumProc, reinterpret_cast<LPARAM>(&procData), 0);
     copyToVector(procData.m_traitsMasks, traitsMasks);
-
-    ReleaseDC(0, hdc);
 }
 
 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
index 46f9ecd..a89a182 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2006, 2007 Apple Computer, Inc.
- * Copyright (c) 2006, 2007, 2008, 2009, Google Inc. All rights reserved.
+ * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -36,6 +36,7 @@
 #include <objidl.h>
 #include <mlang.h>
 
+#include "HWndDC.h"
 #include "PlatformSupport.h"
 #include "SkTypeface_win.h"
 #include "SkiaFontWin.h"
@@ -161,7 +162,7 @@ SCRIPT_FONTPROPERTIES* FontPlatformData::scriptFontProperties() const
         HRESULT result = ScriptGetFontProperties(0, scriptCache(),
                                                  m_scriptFontProperties);
         if (result == E_PENDING) {
-            HDC dc = GetDC(0);
+            HWndDC dc(0);
             HGDIOBJ oldFont = SelectObject(dc, hfont());
             HRESULT hr = ScriptGetFontProperties(dc, scriptCache(),
                                                  m_scriptFontProperties);
@@ -177,7 +178,6 @@ SCRIPT_FONTPROPERTIES* FontPlatformData::scriptFontProperties() const
             }
 
             SelectObject(dc, oldFont);
-            ReleaseDC(0, dc);
         }
     }
     return m_scriptFontProperties;
index a4798dd..711b896 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2007, 2008, 2009, 2010, Google Inc. All rights reserved.
+ * Copyright (c) 2006, 2007, 2008, 2009, 2010, 2012 Google Inc. All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -33,6 +33,7 @@
 
 #include <limits>
 
+#include "HWndDC.h"
 #include "PlatformString.h"
 #include "UniscribeHelper.h"
 #include <unicode/locid.h>
@@ -50,14 +51,13 @@ bool isFontPresent(const UChar* fontName)
                              fontName);
     if (!hfont)
         return false;
-    HDC dc = GetDC(0);
+    HWndDC dc(0);
     HGDIOBJ oldFont = static_cast<HFONT>(SelectObject(dc, hfont));
     WCHAR actualFontName[LF_FACESIZE];
     GetTextFace(dc, LF_FACESIZE, actualFontName);
     actualFontName[LF_FACESIZE - 1] = 0;
     SelectObject(dc, oldFont);
     DeleteObject(hfont);
-    ReleaseDC(0, dc);
     // We don't have to worry about East Asian fonts with locale-dependent
     // names here for now.
     return !wcscmp(fontName, actualFontName);
@@ -241,24 +241,22 @@ const int kUndefinedAscent = std::numeric_limits<int>::min();
 // kUndefinedAscent is returned, instead.
 int getAscent(HFONT hfont)
 {
-    HDC dc = GetDC(0);
+    HWndDC dc(0);
     HGDIOBJ oldFont = SelectObject(dc, hfont);
     TEXTMETRIC tm;
     BOOL gotMetrics = GetTextMetrics(dc, &tm);
     SelectObject(dc, oldFont);
-    ReleaseDC(0, dc);
     return gotMetrics ? tm.tmAscent : kUndefinedAscent;
 }
 
 WORD getSpaceGlyph(HFONT hfont) 
 {
-    HDC dc = GetDC(0);
+    HWndDC dc(0);
     HGDIOBJ oldFont = SelectObject(dc, hfont);
     WCHAR space = L' ';
     WORD spaceGlyph = 0;
     GetGlyphIndices(dc, &space, 1, &spaceGlyph, 0);
     SelectObject(dc, oldFont);
-    ReleaseDC(0, dc);
     return spaceGlyph;
 }
 
index 42f45ab..f5425b9 100644 (file)
@@ -83,7 +83,7 @@ static bool fillBMPGlyphs(unsigned offset,
                           GlyphPage* page,
                           const SimpleFontData* fontData)
 {
-    HWndDC dc((HWND)0);
+    HWndDC dc(0);
     HGDIOBJ oldFont = SelectObject(dc, fontData->platformData().hfont());
 
     TEXTMETRIC tm = {0};
index 78ad56a..a3dbd77 100644 (file)
@@ -36,6 +36,7 @@
 #include "Font.h"
 #include "FontCache.h"
 #include "FontDescription.h"
+#include "HWndDC.h"
 #include "PlatformSupport.h"
 #include <wtf/MathExtras.h>
 
@@ -55,7 +56,7 @@ void SimpleFontData::platformInit()
         return;
     }
 
-    HDC dc = GetDC(0);
+    HWndDC dc(0);
     HGDIOBJ oldFont = SelectObject(dc, m_platformData.hfont());
 
     TEXTMETRIC textMetric = {0};
@@ -95,7 +96,6 @@ void SimpleFontData::platformInit()
     m_fontMetrics.setLineSpacing(ascent + descent + lineGap);
 
     SelectObject(dc, oldFont);
-    ReleaseDC(0, dc);
 }
 
 void SimpleFontData::platformCharWidthInit()
@@ -147,7 +147,7 @@ bool SimpleFontData::containsCharacters(const UChar* characters, int length) con
 void SimpleFontData::determinePitch()
 {
     // TEXTMETRICS have this.  Set m_treatAsFixedPitch based off that.
-    HDC dc = GetDC(0);
+    HWndDC dc(0);
     HGDIOBJ oldFont = SelectObject(dc, m_platformData.hfont());
 
     // Yes, this looks backwards, but the fixed pitch bit is actually set if the font
@@ -166,7 +166,6 @@ void SimpleFontData::determinePitch()
     m_treatAsFixedPitch = ((textMetric.tmPitchAndFamily & TMPF_FIXED_PITCH) == 0);
 
     SelectObject(dc, oldFont);
-    ReleaseDC(0, dc);
 }
 
 FloatRect SimpleFontData::platformBoundsForGlyph(Glyph) const
@@ -179,7 +178,7 @@ float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
     if (!m_platformData.size())
         return 0;
 
-    HDC dc = GetDC(0);
+    HWndDC dc(0);
     HGDIOBJ oldFont = SelectObject(dc, m_platformData.hfont());
 
     int width = 0;
@@ -194,7 +193,6 @@ float SimpleFontData::platformWidthForGlyph(Glyph glyph) const
     }
 
     SelectObject(dc, oldFont);
-    ReleaseDC(0, dc);
 
     return static_cast<float>(width);
 }
index efca3d9..51b0c69 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2007, 2008, 2009, Google Inc. All rights reserved.
+ * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -33,6 +33,7 @@
 
 #include "Font.h"
 #include "FontUtilsChromiumWin.h"
+#include "HWndDC.h"
 #include "PlatformContextSkia.h"
 #include "SkiaFontWin.h"
 #include "SkPoint.h"
@@ -786,13 +787,11 @@ void UniscribeHelper::EnsureCachedDCCreated()
     // Allocate a memory DC that is compatible with the Desktop DC since we don't have any window,
     // and we don't want to use the Desktop DC directly since it can have nasty side effects
     // as identified in Chrome Issue http://crbug.com/59315.
-    HDC screenDC = ::GetDC(0);
+    HWndDC screenDC(0);
     m_cachedDC = ::CreateCompatibleDC(screenDC);
     ASSERT(m_cachedDC);
-
-    int result = ::ReleaseDC(0, screenDC);
-    ASSERT(result == 1);
 }
+
 void UniscribeHelper::fillShapes()
 {
     m_shapes.resize(m_runs.size());
index d4328df..4224554 100644 (file)
@@ -36,6 +36,7 @@
 #include "GraphicsContext.h"
 #include "HTMLMediaElement.h"
 #include "HTMLNames.h"
+#include "HWndDC.h"
 #include "MediaControlElements.h"
 #include "PaintInfo.h"
 #include "PlatformSupport.h"
@@ -178,13 +179,12 @@ static float systemFontSize(const LOGFONT& font)
     if (size < 0) {
         HFONT hFont = CreateFontIndirect(&font);
         if (hFont) {
-            HDC hdc = GetDC(0); // What about printing?  Is this the right DC?
+            HWndDC hdc(0); // What about printing? Is this the right DC?
             if (hdc) {
                 HGDIOBJ hObject = SelectObject(hdc, hFont);
                 TEXTMETRIC tm;
                 GetTextMetrics(hdc, &tm);
                 SelectObject(hdc, hObject);
-                ReleaseDC(0, hdc);
                 size = tm.tmAscent;
             }
             DeleteObject(hFont);
@@ -209,13 +209,11 @@ static float pointsToPixels(float points)
 {
     static float pixelsPerInch = 0.0f;
     if (!pixelsPerInch) {
-        HDC hdc = GetDC(0); // What about printing?  Is this the right DC?
-        if (hdc) // Can this ever actually be NULL?
+        HWndDC hdc(0); // What about printing? Is this the right DC?
+        if (hdc) // Can this ever actually be NULL?
             pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
-            ReleaseDC(0, hdc);
-        } else {
+        else
             pixelsPerInch = 96.0f;
-        }
     }
 
     static const float pointsPerInch = 72.0f;