[windows] Convert usage of GetDC to HWndDC Part 3.
authorlevin@chromium.org <levin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2012 18:51:50 +0000 (18:51 +0000)
committerlevin@chromium.org <levin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2012 18:51:50 +0000 (18:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76889

Reviewed by Adam Roben.

Source/WebCore:

No new functionality so no new tests.

* platform/graphics/win/UniscribeController.cpp:
(WebCore::UniscribeController::shapeAndPlaceItem): Simple replacement.
(WebCore::UniscribeController::shape): Use the delayed allocation.
* platform/win/PopupMenuWin.cpp:
(WebCore::PopupMenuWin::paint): Fix a dc leak and use the dellayed allocation.

Source/WebKit2:

* UIProcess/win/WebPopupMenuProxyWin.cpp:
(WebKit::WebPopupMenuProxyWin::paint): Fix a dc leak and use the dellayed allocation.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/win/UniscribeController.cpp
Source/WebCore/platform/win/PopupMenuWin.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/win/WebPopupMenuProxyWin.cpp

index 94a640e..966c7d8 100644 (file)
@@ -1,3 +1,18 @@
+2012-01-24  David Levin  <levin@chromium.org>
+
+        [windows] Convert usage of GetDC to HWndDC Part 3.
+        https://bugs.webkit.org/show_bug.cgi?id=76889
+
+        Reviewed by Adam Roben.
+
+        No new functionality so no new tests.
+
+        * platform/graphics/win/UniscribeController.cpp:
+        (WebCore::UniscribeController::shapeAndPlaceItem): Simple replacement.
+        (WebCore::UniscribeController::shape): Use the delayed allocation.
+        * platform/win/PopupMenuWin.cpp:
+        (WebCore::PopupMenuWin::paint): Fix a dc leak and use the dellayed allocation.
+
 2012-01-24  Mario Sanchez Prada  <msanchez@igalia.com>
 
         [GTK] Refactor GTK's accessibilitity code to be more modular
index 67e34a7..336b4e6 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "UniscribeController.h"
 #include "Font.h"
+#include "HWndDC.h"
 #include "SimpleFontData.h"
 #include "TextRun.h"
 #include <wtf/MathExtras.h>
@@ -248,13 +249,12 @@ bool UniscribeController::shapeAndPlaceItem(const UChar* cp, unsigned i, const S
     if (placeResult == E_PENDING) {
         // The script cache isn't primed with enough info yet.  We need to select our HFONT into
         // a DC and pass the DC in to ScriptPlace.
-        HDC hdc = GetDC(0);
+        HWndDC hdc(0);
         HFONT hfont = fontData->platformData().hfont();
         HFONT oldFont = (HFONT)SelectObject(hdc, hfont);
         placeResult = ScriptPlace(hdc, fontData->scriptCache(), glyphs.data(), glyphs.size(), visualAttributes.data(),
                                   &item.a, advances.data(), offsets.data(), 0);
         SelectObject(hdc, oldFont);
-        ReleaseDC(0, hdc);
     }
     
     if (FAILED(placeResult) || glyphs.isEmpty())
@@ -380,7 +380,7 @@ bool UniscribeController::shape(const UChar* str, int len, SCRIPT_ITEM item, con
                                 Vector<WORD>& glyphs, Vector<WORD>& clusters,
                                 Vector<SCRIPT_VISATTR>& visualAttributes)
 {
-    HDC hdc = 0;
+    HWndDC hdc;
     HFONT oldFont = 0;
     HRESULT shapeResult = E_PENDING;
     int glyphCount = 0;
@@ -391,7 +391,7 @@ bool UniscribeController::shape(const UChar* str, int len, SCRIPT_ITEM item, con
             // The script cache isn't primed with enough info yet.  We need to select our HFONT into
             // a DC and pass the DC in to ScriptShape.
             ASSERT(!hdc);
-            hdc = GetDC(0);
+            hdc.setHWnd(0);
             HFONT hfont = fontData->platformData().hfont();
             oldFont = (HFONT)SelectObject(hdc, hfont);
         } else if (shapeResult == E_OUTOFMEMORY) {
@@ -401,10 +401,8 @@ bool UniscribeController::shape(const UChar* str, int len, SCRIPT_ITEM item, con
         }
     } while (shapeResult == E_PENDING || shapeResult == E_OUTOFMEMORY);
 
-    if (hdc) {
+    if (hdc)
         SelectObject(hdc, oldFont);
-        ReleaseDC(0, hdc);
-    }
 
     if (FAILED(shapeResult))
         return false;
index 097fc82..d0b3ec9 100644 (file)
@@ -31,6 +31,7 @@
 #include "FrameView.h"
 #include "GraphicsContext.h"
 #include "HTMLNames.h"
+#include "HWndDC.h"
 #include "HostWindow.h"
 #include "Page.h"
 #include "PlatformMouseEvent.h"
@@ -42,6 +43,7 @@
 #include "SimpleFontData.h"
 #include "TextRun.h"
 #include "WebCoreInstanceHandle.h"
+
 #include <windows.h>
 #include <windowsx.h>
 #if OS(WINCE)
@@ -566,7 +568,7 @@ void PopupMenuWin::paint(const IntRect& damageRect, HDC hdc)
         return;
 
     if (!m_DC) {
-        m_DC = ::CreateCompatibleDC(::GetDC(m_popup));
+        m_DC = ::CreateCompatibleDC(HWndDC(m_popup));
         if (!m_DC)
             return;
     }
@@ -660,12 +662,10 @@ void PopupMenuWin::paint(const IntRect& damageRect, HDC hdc)
     if (m_scrollbar)
         m_scrollbar->paint(&context, damageRect);
 
-    HDC localDC = hdc ? hdc : ::GetDC(m_popup);
+    HWndDC hWndDC;
+    HDC localDC = hdc ? hdc : hWndDC.setHWnd(m_popup);
 
     ::BitBlt(localDC, damageRect.x(), damageRect.y(), damageRect.width(), damageRect.height(), m_DC, damageRect.x(), damageRect.y(), SRCCOPY);
-
-    if (!hdc)
-        ::ReleaseDC(m_popup, localDC);
 }
 
 int PopupMenuWin::scrollSize(ScrollbarOrientation orientation) const
index 8ebfa6e..aa8f07c 100644 (file)
@@ -1,3 +1,13 @@
+2012-01-24  David Levin  <levin@chromium.org>
+
+        [windows] Convert usage of GetDC to HWndDC Part 3.
+        https://bugs.webkit.org/show_bug.cgi?id=76889
+
+        Reviewed by Adam Roben.
+
+        * UIProcess/win/WebPopupMenuProxyWin.cpp:
+        (WebKit::WebPopupMenuProxyWin::paint): Fix a dc leak and use the dellayed allocation.
+
 2012-01-24  Sergio Villar Senin  <svillar@igalia.com>
 
         [WK2] [GTK] TestDownloads hitting an assertion in Debug builds
index d32e0f8..a040ad4 100644 (file)
@@ -34,6 +34,7 @@
 #include <WebCore/WebCoreInstanceHandle.h>
 #include <WebCore/ScrollbarTheme.h>
 #include <WebCore/BitmapInfo.h>
+#include <WebCore/HWndDC.h>
 #include <WebCore/PlatformMouseEvent.h>
 #include <windowsx.h>
 
@@ -808,7 +809,7 @@ void WebPopupMenuProxyWin::paint(const IntRect& damageRect, HDC hdc)
         return;
 
     if (!m_DC) {
-        m_DC = ::CreateCompatibleDC(::GetDC(m_popup));
+        m_DC = ::CreateCompatibleDC(HWndDC(m_popup));
         if (!m_DC)
             return;
     }
@@ -848,12 +849,11 @@ void WebPopupMenuProxyWin::paint(const IntRect& damageRect, HDC hdc)
     if (m_scrollbar)
         m_scrollbar->paint(&context, damageRect);
 
-    HDC localDC = hdc ? hdc : ::GetDC(m_popup);
 
-    ::BitBlt(localDC, damageRect.x(), damageRect.y(), damageRect.width(), damageRect.height(), m_DC, damageRect.x(), damageRect.y(), SRCCOPY);
+    HWndDC hWndDC;
+    HDC localDC = hdc ? hdc : hWndDC.setHWnd(m_popup);
 
-    if (!hdc)
-        ::ReleaseDC(m_popup, localDC);
+    ::BitBlt(localDC, damageRect.x(), damageRect.y(), damageRect.width(), damageRect.height(), m_DC, damageRect.x(), damageRect.y(), SRCCOPY);
 }
 
 bool WebPopupMenuProxyWin::setFocusedIndex(int i, bool hotTracking)