[windows] Convert usages of GetDC to HWndDC Part 2.
authorlevin@chromium.org <levin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2012 01:31:05 +0000 (01:31 +0000)
committerlevin@chromium.org <levin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2012 01:31:05 +0000 (01:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76750

Reviewed by Adam Roben.

Source/WebKit/win:

* FullscreenVideoController.cpp:
(createCompatibleDCForWindow): Moved out the code which creates a DC for a window
to keep the same scope for the DC lifetime.
(FullscreenVideoController::draw):  Switch to using OwnPtr<HDC>
since createCompatibleDCForWindow returns a PassOwnPtr.
* WebNodeHighlight.cpp:
(WebNodeHighlight::update):
  Cleaned up leaks from calling GetDC without release.
  Note that there is a potential leak of hdc that previously existed
  and still does in an early exit scenario. (This could be easily fixed
  by using OwnPtr<HDC> but I was trying to keep this patch focused.)
* WebView.cpp:
(WebView::scrollBackingStore): Typical conversion.
(WebView::updateBackingStore): Reduced the scope of windowDC to be
right where it is being used.
(WebView::performLayeredWindowUpdate): Typical conversion.
(WebView::paintIntoBackingStore): Ditto.

Source/WebKit2:

* Shared/win/ShareableBitmapWin.cpp:
(WebKit::ShareableBitmap::windowsContext): Fix incorrect usage of OwnPtr<HDC> which
would do a DeleteDC instead of a ReleaseDC.

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

Source/WebKit/win/ChangeLog
Source/WebKit/win/FullscreenVideoController.cpp
Source/WebKit/win/WebNodeHighlight.cpp
Source/WebKit/win/WebView.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/win/ShareableBitmapWin.cpp

index dc14cbe..ea2214d 100644 (file)
@@ -1,5 +1,30 @@
 2012-01-23  David Levin  <levin@chromium.org>
 
+        [windows] Convert usages of GetDC to HWndDC Part 2.
+        https://bugs.webkit.org/show_bug.cgi?id=76750
+
+        Reviewed by Adam Roben.
+
+        * FullscreenVideoController.cpp:
+        (createCompatibleDCForWindow): Moved out the code which creates a DC for a window
+        to keep the same scope for the DC lifetime.
+        (FullscreenVideoController::draw):  Switch to using OwnPtr<HDC>
+        since createCompatibleDCForWindow returns a PassOwnPtr.
+        * WebNodeHighlight.cpp:
+        (WebNodeHighlight::update): 
+          Cleaned up leaks from calling GetDC without release.
+          Note that there is a potential leak of hdc that previously existed
+          and still does in an early exit scenario. (This could be easily fixed
+          by using OwnPtr<HDC> but I was trying to keep this patch focused.)
+        * WebView.cpp:
+        (WebView::scrollBackingStore): Typical conversion.
+        (WebView::updateBackingStore): Reduced the scope of windowDC to be
+        right where it is being used.
+        (WebView::performLayeredWindowUpdate): Typical conversion.
+        (WebView::paintIntoBackingStore): Ditto.
+
+2012-01-23  David Levin  <levin@chromium.org>
+
         [windows] Convert usages of GetDC to HWndDC Part 1.
         https://bugs.webkit.org/show_bug.cgi?id=76744
 
index 30405c6..9488479 100644 (file)
 #include <WebCore/Font.h>
 #include <WebCore/FontSelector.h>
 #include <WebCore/GraphicsContext.h>
+#include <WebCore/HWndDC.h>
 #include <WebCore/Page.h>
 #include <WebCore/PlatformCALayer.h>
 #include <WebCore/TextRun.h>
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
 #include <windowsx.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
 #include <wtf/StdLibExtras.h>
 
 using namespace std;
@@ -482,12 +485,10 @@ static String timeToString(float time)
 
 void FullscreenVideoController::draw()
 {
-    HDC windowDC = GetDC(m_hudWindow);
-    HDC bitmapDC = CreateCompatibleDC(windowDC);
-    ::ReleaseDC(m_hudWindow, windowDC);
-    HGDIOBJ oldBitmap = SelectObject(bitmapDC, m_bitmap.get());
+    OwnPtr<HDC> bitmapDC = adoptPtr(CreateCompatibleDC(HWndDC(m_hudWindow)));
+    HGDIOBJ oldBitmap = SelectObject(bitmapDC.get(), m_bitmap.get());
 
-    GraphicsContext context(bitmapDC, true);
+    GraphicsContext context(bitmapDC.get(), true);
 
     context.save();
 
@@ -549,12 +550,11 @@ void FullscreenVideoController::draw()
     SIZE size = { windowWidth, windowHeight };
     POINT sourcePoint = {0, 0};
     POINT destPoint = { m_hudPosition.x(), m_hudPosition.y() };
-    BOOL result = UpdateLayeredWindow(m_hudWindow, 0, &destPoint, &size, bitmapDC, &sourcePoint, 0, &blendFunction, ULW_ALPHA);
+    BOOL result = UpdateLayeredWindow(m_hudWindow, 0, &destPoint, &size, bitmapDC.get(), &sourcePoint, 0, &blendFunction, ULW_ALPHA);
 
     context.restore();
 
-    ::SelectObject(bitmapDC, oldBitmap);
-    ::DeleteDC(bitmapDC);
+    ::SelectObject(bitmapDC.get(), oldBitmap);
 }
 
 LRESULT FullscreenVideoController::hudWndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam)
index 5952723..c35d0b6 100644 (file)
 #include <WebCore/BitmapInfo.h>
 #include <WebCore/Color.h>
 #include <WebCore/GraphicsContext.h>
+#include <WebCore/HWndDC.h>
 #include <WebCore/InspectorController.h>
 #include <WebCore/Page.h>
 #include <WebCore/WindowMessageBroadcaster.h>
-#include <wtf/OwnPtr.h>
 #include <wtf/HashSet.h>
+#include <wtf/OwnPtr.h>
 
 using namespace WebCore;
 
@@ -134,7 +135,7 @@ void WebNodeHighlight::update()
 {
     ASSERT(m_overlay);
 
-    HDC hdc = ::CreateCompatibleDC(::GetDC(m_overlay));
+    HDC hdc = ::CreateCompatibleDC(HWndDC(m_overlay));
     if (!hdc)
         return;
 
@@ -174,8 +175,7 @@ void WebNodeHighlight::update()
     dstPoint.x = webViewRect.left;
     dstPoint.y = webViewRect.top;
 
-    ::UpdateLayeredWindow(m_overlay, ::GetDC(0), &dstPoint, &size, hdc, &srcPoint, 0, &bf, ULW_ALPHA);
-
+    ::UpdateLayeredWindow(m_overlay, HWndDC(0), &dstPoint, &size, hdc, &srcPoint, 0, &bf, ULW_ALPHA);
     ::DeleteDC(hdc);
 }
 
index 57d3458..615fa11 100644 (file)
@@ -95,6 +95,7 @@
 #include <WebCore/GraphicsContext.h>
 #include <WebCore/HTMLMediaElement.h>
 #include <WebCore/HTMLNames.h>
+#include <WebCore/HWndDC.h>
 #include <WebCore/HistoryItem.h>
 #include <WebCore/HitTestRequest.h>
 #include <WebCore/HitTestResult.h>
@@ -862,7 +863,7 @@ void WebView::scrollBackingStore(FrameView* frameView, int dx, int dy, const Int
     HRGN updateRegion = ::CreateRectRgn(0, 0, 0, 0);
 
     // Collect our device context info and select the bitmap to scroll.
-    HDC windowDC = ::GetDC(m_viewWindow);
+    HWndDC windowDC(m_viewWindow);
     HDC bitmapDC = ::CreateCompatibleDC(windowDC);
     HGDIOBJ oldBitmap = ::SelectObject(bitmapDC, m_backingStoreBitmap->handle());
     
@@ -888,7 +889,6 @@ void WebView::scrollBackingStore(FrameView* frameView, int dx, int dy, const Int
     // Clean up.
     ::SelectObject(bitmapDC, oldBitmap);
     ::DeleteDC(bitmapDC);
-    ::ReleaseDC(m_viewWindow, windowDC);
 }
 
 void WebView::sizeChanged(const IntSize& newSize)
@@ -958,11 +958,10 @@ void WebView::updateBackingStore(FrameView* frameView, HDC dc, bool backingStore
 
     LOCAL_GDI_COUNTER(0, __FUNCTION__);
 
-    HDC windowDC = 0;
     HDC bitmapDC = dc;
     HGDIOBJ oldBitmap = 0;
     if (!dc) {
-        windowDC = ::GetDC(m_viewWindow);
+        HWndDC windowDC(m_viewWindow);
         bitmapDC = ::CreateCompatibleDC(windowDC);
         oldBitmap = ::SelectObject(bitmapDC, m_backingStoreBitmap->handle());
     }
@@ -996,7 +995,6 @@ void WebView::updateBackingStore(FrameView* frameView, HDC dc, bool backingStore
     if (!dc) {
         ::SelectObject(bitmapDC, oldBitmap);
         ::DeleteDC(bitmapDC);
-        ::ReleaseDC(m_viewWindow, windowDC);
     }
 
     GdiFlush();
@@ -1008,7 +1006,7 @@ void WebView::performLayeredWindowUpdate()
     if (!m_backingStoreBitmap)
         return;
 
-    HDC hdcScreen = ::GetDC(m_viewWindow);
+    HWndDC hdcScreen(m_viewWindow);
     OwnPtr<HDC> hdcMem = adoptPtr(::CreateCompatibleDC(hdcScreen));
     HBITMAP hbmOld = static_cast<HBITMAP>(::SelectObject(hdcMem.get(), m_backingStoreBitmap->handle()));
 
@@ -1026,7 +1024,6 @@ void WebView::performLayeredWindowUpdate()
     ::UpdateLayeredWindow(m_viewWindow, hdcScreen, 0, &windowSize, hdcMem.get(), &layerPos, 0, &blendFunction, ULW_ALPHA);
 
     ::SelectObject(hdcMem.get(), hbmOld);
-    ::ReleaseDC(0, hdcScreen);
 }
 
 void WebView::paint(HDC dc, LPARAM options)
@@ -1132,13 +1129,14 @@ void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, const In
     RECT rect = dirtyRect;
 
 #if FLASH_BACKING_STORE_REDRAW
-    HDC dc = ::GetDC(m_viewWindow);
-    OwnPtr<HBRUSH> yellowBrush(CreateSolidBrush(RGB(255, 255, 0)));
-    FillRect(dc, &rect, yellowBrush.get());
-    GdiFlush();
-    Sleep(50);
-    paintIntoWindow(bitmapDC, dc, dirtyRect);
-    ::ReleaseDC(m_viewWindow, dc);
+    {
+        HWndDC dc(m_viewWindow);
+        OwnPtr<HBRUSH> yellowBrush(CreateSolidBrush(RGB(255, 255, 0)));
+        FillRect(dc, &rect, yellowBrush.get());
+        GdiFlush();
+        Sleep(50);
+        paintIntoWindow(bitmapDC, dc, dirtyRect);
+    }
 #endif
 
     GraphicsContext gc(bitmapDC, m_transparent);
index a82fc10..c0d6e49 100644 (file)
@@ -1,5 +1,16 @@
 2012-01-23  David Levin  <levin@chromium.org>
 
+        [windows] Convert usages of GetDC to HWndDC Part 2.
+        https://bugs.webkit.org/show_bug.cgi?id=76750
+
+        Reviewed by Adam Roben.
+
+        * Shared/win/ShareableBitmapWin.cpp:
+        (WebKit::ShareableBitmap::windowsContext): Fix incorrect usage of OwnPtr<HDC> which
+        would do a DeleteDC instead of a ReleaseDC.
+
+2012-01-23  David Levin  <levin@chromium.org>
+
         [windows] Convert usages of GetDC to HWndDC Part 1.
         https://bugs.webkit.org/show_bug.cgi?id=76744
 
index bf23dcd..2ed8428 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <WebCore/BitmapInfo.h>
 #include <WebCore/GraphicsContext.h>
+#include <WebCore/HWndDC.h>
 
 using namespace WebCore;
 
@@ -39,10 +40,10 @@ HDC ShareableBitmap::windowsContext() const
     if (m_windowsContext)
         return m_windowsContext.get();
 
-    OwnPtr<HDC> screenDC = adoptPtr(::GetDC(0));
+    HWndDC screenDC(0);
     BitmapInfo bmInfo = BitmapInfo::createBottomUp(m_size);
 
-    m_windowsContext = adoptPtr(::CreateCompatibleDC(screenDC.get()));
+    m_windowsContext = adoptPtr(::CreateCompatibleDC(screenDC));
     m_windowsBitmap = adoptPtr(CreateDIBSection(m_windowsContext.get(), &bmInfo, DIB_RGB_COLORS, 0, m_sharedMemory->handle(), 0));
     ::SelectObject(m_windowsContext.get(), m_windowsBitmap.get());