[Windows] Create SharedGDIObject Class Template
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Sep 2013 21:40:21 +0000 (21:40 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Sep 2013 21:40:21 +0000 (21:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=121037

Reviewed by Anders Carlsson.

Source/WebCore:

* WebCore.vcxproj/WebCore.vcxproj: Remove RefCountedGDIHandle.h, and
add new SharedGDIObject.h file.
* WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
* platform/graphics/FontPlatformData.h:
(WebCore::FontPlatformData::hfont): Switch to new SharedGDIObject.
* platform/graphics/win/FontPlatformDataCGWin.cpp:
(WebCore::FontPlatformData::FontPlatformData): Ditto.
* platform/graphics/win/FontPlatformDataCairoWin.cpp:
(WebCore::FontPlatformData::FontPlatformData): Ditto.
* platform/graphics/win/FontPlatformDataWin.cpp:
(WebCore::FontPlatformData::FontPlatformData): Ditto.
* platform/graphics/win/RefCountedGDIHandle.h: Removed.
* platform/graphics/win/SharedGDIObject.h: Added.
(WebCore::SharedGDIObject::create):
(WebCore::SharedGDIObject::get):
(WebCore::SharedGDIObject::hash):
(WebCore::SharedGDIObject::SharedGDIObject):

Source/WebKit/win:

* WebView.cpp: Change implementations to use the new SharedGDIObject
class.
(WebView::addToDirtyRegion):
(WebView::scrollBackingStore):
(WebView::updateBackingStore):
(WebView::performLayeredWindowUpdate):
(WebView::paint):
(WebView::backingStore):
* WebView.h: Ditto.

Source/WTF:

Now that the SharedGDIObject class exists we can get rid of
the Windows-specific code in OwnPtr.

* WTF.vcxproj/WTF.vcxproj: Remove OwnPtrWin.cpp.
* WTF.vcxproj/WTF.vcxproj.filters: Ditto.
* wtf/OwnPtrCommon.h:
(WTF::deleteOwnedPtr): Remove Windows declarations that
are no longer needed.
* wtf/win/GDIObject.h:
(WTF::GDIObject::get): Change to 'const' to match
signature (and use cases) elsewhere in the code base for
our smart pointer classes.
* wtf/win/OwnPtrWin.cpp: Removed.

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

17 files changed:
Source/WTF/ChangeLog
Source/WTF/WTF.vcxproj/WTF.vcxproj
Source/WTF/WTF.vcxproj/WTF.vcxproj.filters
Source/WTF/wtf/OwnPtrCommon.h
Source/WTF/wtf/win/GDIObject.h
Source/WebCore/ChangeLog
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/platform/graphics/FontPlatformData.h
Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp
Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp
Source/WebCore/platform/graphics/win/FontPlatformDataWin.cpp
Source/WebCore/platform/graphics/win/RefCountedGDIHandle.h [deleted file]
Source/WebCore/platform/graphics/win/SharedGDIObject.h [moved from Source/WTF/wtf/win/OwnPtrWin.cpp with 55% similarity]
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebView.cpp
Source/WebKit/win/WebView.h

index 339636a..15fa5a8 100644 (file)
@@ -1,3 +1,24 @@
+2013-09-10  Brent Fulgham  <bfulgham@apple.com>
+
+        [Windows] Create SharedGDIObject Class Template
+        https://bugs.webkit.org/show_bug.cgi?id=121037
+
+        Reviewed by Anders Carlsson.
+
+        Now that the SharedGDIObject class exists we can get rid of
+        the Windows-specific code in OwnPtr.
+
+        * WTF.vcxproj/WTF.vcxproj: Remove OwnPtrWin.cpp.
+        * WTF.vcxproj/WTF.vcxproj.filters: Ditto.
+        * wtf/OwnPtrCommon.h: 
+        (WTF::deleteOwnedPtr): Remove Windows declarations that
+        are no longer needed.
+        * wtf/win/GDIObject.h:
+        (WTF::GDIObject::get): Change to 'const' to match
+        signature (and use cases) elsewhere in the code base for
+        our smart pointer classes.
+        * wtf/win/OwnPtrWin.cpp: Removed.
+
 2013-09-10  Anders Carlsson  <andersca@apple.com>
 
         Remove more uses of WTF::AlignedBuffer
index 9708b50..313ada8 100644 (file)
     <ClCompile Include="..\wtf\unicode\icu\CollatorICU.cpp" />\r
     <ClCompile Include="..\wtf\unicode\UTF8.cpp" />\r
     <ClCompile Include="..\wtf\win\MainThreadWin.cpp" />\r
-    <ClCompile Include="..\wtf\win\OwnPtrWin.cpp" />\r
     <ClCompile Include="..\wtf\WTFThreadData.cpp" />\r
     <ClCompile Include="..\wtf\SchedulePairCF.cpp" />\r
   </ItemGroup>\r
index ef283a0..43cc389 100644 (file)
@@ -78,9 +78,6 @@
     <ClCompile Include="..\wtf\win\MainThreadWin.cpp">\r
       <Filter>win</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="..\wtf\win\OwnPtrWin.cpp">\r
-      <Filter>win</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="..\wtf\threads\win\BinarySemaphoreWin.cpp">\r
       <Filter>threads\win</Filter>\r
     </ClCompile>\r
index 260241f..3f53315 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
  * Copyright (C) 2009 Torch Mobile, Inc.
  * Copyright (C) 2010 Company 100 Inc.
  *
 #ifndef WTF_OwnPtrCommon_h
 #define WTF_OwnPtrCommon_h
 
-#if OS(WINDOWS)
-typedef struct HBITMAP__* HBITMAP;
-typedef struct HDC__* HDC;
-typedef struct HRGN__* HRGN;
-#endif
-
 #if PLATFORM(EFL)
 typedef struct _Ecore_Evas Ecore_Evas;
 typedef struct _Ecore_IMF_Context Ecore_IMF_Context;
@@ -59,12 +53,6 @@ namespace WTF {
             delete ptr;
     }
 
-#if OS(WINDOWS)
-    WTF_EXPORT_PRIVATE void deleteOwnedPtr(HBITMAP);
-    WTF_EXPORT_PRIVATE void deleteOwnedPtr(HDC);
-    WTF_EXPORT_PRIVATE void deleteOwnedPtr(HRGN);
-#endif
-
 #if PLATFORM(EFL)
     WTF_EXPORT_PRIVATE void deleteOwnedPtr(Ecore_Evas*);
     WTF_EXPORT_PRIVATE void deleteOwnedPtr(Ecore_IMF_Context*);
index fa631e4..2025eef 100644 (file)
@@ -42,7 +42,7 @@ public:
     GDIObject() : m_object(0) { }
     ~GDIObject() { deleteObject<T>(m_object); }
 
-    T get() { return m_object; }
+    T get() const { return m_object; }
 
     void clear();
     T leak() WARN_UNUSED_RETURN;
index bc28d4a..cb95ee6 100644 (file)
@@ -1,3 +1,28 @@
+2013-09-10  Brent Fulgham  <bfulgham@apple.com>
+
+        [Windows] Create SharedGDIObject Class Template
+        https://bugs.webkit.org/show_bug.cgi?id=121037
+
+        Reviewed by Anders Carlsson.
+
+        * WebCore.vcxproj/WebCore.vcxproj: Remove RefCountedGDIHandle.h, and
+        add new SharedGDIObject.h file.
+        * WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
+        * platform/graphics/FontPlatformData.h:
+        (WebCore::FontPlatformData::hfont): Switch to new SharedGDIObject.
+        * platform/graphics/win/FontPlatformDataCGWin.cpp:
+        (WebCore::FontPlatformData::FontPlatformData): Ditto.
+        * platform/graphics/win/FontPlatformDataCairoWin.cpp:
+        (WebCore::FontPlatformData::FontPlatformData): Ditto.
+        * platform/graphics/win/FontPlatformDataWin.cpp:
+        (WebCore::FontPlatformData::FontPlatformData): Ditto.
+        * platform/graphics/win/RefCountedGDIHandle.h: Removed.
+        * platform/graphics/win/SharedGDIObject.h: Added.
+        (WebCore::SharedGDIObject::create):
+        (WebCore::SharedGDIObject::get):
+        (WebCore::SharedGDIObject::hash):
+        (WebCore::SharedGDIObject::SharedGDIObject):
+
 2013-09-10  Tim Horton  <timothy_horton@apple.com>
 
         [mac] PDFDocumentImage should use PDFKit to draw
index 14daa91..e8f48eb 100644 (file)
     <ClInclude Include="..\platform\graphics\opengl\GLPlatformContext.h" />
     <ClInclude Include="..\platform\graphics\opengl\GLPlatformSurface.h" />
     <ClInclude Include="..\platform\graphics\VideoTrackPrivate.h" />
+    <ClInclude Include="..\platform\graphics\win\SharedGDIObject.h" />
     <ClInclude Include="..\platform\HistogramSupport.h" />
     <ClInclude Include="..\platform\HostWindow.h" />
     <ClInclude Include="..\platform\KillRing.h" />
     <ClInclude Include="..\platform\graphics\opentype\OpenTypeTypes.h" />
     <ClInclude Include="..\platform\graphics\opentype\OpenTypeUtilities.h" />
     <ClInclude Include="..\platform\graphics\opentype\OpenTypeVerticalData.h" />
-    <ClInclude Include="..\platform\graphics\win\RefCountedGDIHandle.h" />
     <ClInclude Include="..\platform\graphics\win\UniscribeController.h" />
     <CustomBuildStep Include="..\platform\graphics\win\WKCAImageQueue.h">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
index dca91e1..ce5d545 100644 (file)
     <ClCompile Include="..\platform\win\StructuredExceptionHandlerSuppressor.cpp">
       <Filter>platform\win</Filter>
     </ClCompile>
+    <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSBeforeUnloadEvent.cpp" />
+    <ClCompile Include="..\rendering\FloatingObjects.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\Modules\filesystem\AsyncFileWriter.h">
     <ClInclude Include="..\platform\graphics\opentype\OpenTypeVerticalData.h">
       <Filter>platform\graphics\win</Filter>
     </ClInclude>
-    <ClInclude Include="..\platform\graphics\win\RefCountedGDIHandle.h">
-      <Filter>platform\graphics\win</Filter>
-    </ClInclude>
     <ClInclude Include="..\platform\graphics\win\UniscribeController.h">
       <Filter>platform\graphics\win</Filter>
     </ClInclude>
     </ClInclude>
     <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\HTMLElementTypeHelpers.h" />
     <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\SVGElementTypeHelpers.h" />
+    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSBeforeUnloadEvent.h" />
+    <ClInclude Include="..\rendering\FloatingObjects.h" />
+    <ClInclude Include="..\platform\graphics\win\SharedGDIObject.h">
+      <Filter>platform\graphics\win</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\css\CSSGrammar.y.in">
index 4eb2e11..435131d 100644 (file)
@@ -40,7 +40,7 @@
 #include "FontWidthVariant.h"
 
 #if PLATFORM(WIN)
-#include "RefCountedGDIHandle.h"
+#include "SharedGDIObject.h"
 #endif
 
 #if USE(CAIRO)
@@ -112,7 +112,7 @@ public:
     ~FontPlatformData();
 
 #if PLATFORM(WIN)
-    HFONT hfont() const { return m_font ? m_font->handle() : 0; }
+    HFONT hfont() const { return m_font ? m_font->get() : 0; }
     bool useGDI() const { return m_useGDI; }
 #elif OS(DARWIN)
     NSFont* font() const { return m_font; }
@@ -228,7 +228,7 @@ private:
 #if OS(DARWIN)
     NSFont* m_font;
 #elif PLATFORM(WIN)
-    RefPtr<RefCountedGDIHandle<HFONT> > m_font;
+    RefPtr<SharedGDIObject<HFONT>> m_font;
 #endif
 
 #if USE(CG)
index 4d71f37..833ffae 100644 (file)
@@ -24,6 +24,7 @@
 #include "config.h"
 #include "FontPlatformData.h"
 
+#include "SharedGDIObject.h"
 #include <ApplicationServices/ApplicationServices.h>
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
 #include <wtf/HashMap.h>
@@ -120,7 +121,7 @@ FontPlatformData::FontPlatformData(HFONT hfont, CGFontRef font, float size, bool
     , m_orientation(Horizontal)
     , m_size(size)
     , m_widthVariant(RegularWidth)
-    , m_font(RefCountedGDIHandle<HFONT>::create(hfont))
+    , m_font(SharedGDIObject<HFONT>::create(adoptGDIObject<HFONT>(hfont)))
     , m_cgFont(font)
     , m_isColorBitmapFont(false)
     , m_useGDI(useGDI)
index 9cddb38..4adece7 100644 (file)
@@ -57,7 +57,7 @@ void FontPlatformData::platformDataInit(HFONT font, float size, HDC hdc, WCHAR*
 }
 
 FontPlatformData::FontPlatformData(HFONT font, cairo_font_face_t* fontFace, float size, bool bold, bool oblique)
-    : m_font(RefCountedGDIHandle<HFONT>::create(font))
+    : m_font(SharedGDIObject<HFONT>::create(adoptGDIObject<HFONT>(font)))
     , m_size(size)
     , m_orientation(Horizontal)
     , m_widthVariant(RegularWidth)
index 56c1688..7b6d665 100644 (file)
@@ -38,7 +38,7 @@ using std::min;
 namespace WebCore {
 
 FontPlatformData::FontPlatformData(HFONT font, float size, bool bold, bool oblique, bool useGDI)
-    : m_font(RefCountedGDIHandle<HFONT>::create(font))
+    : m_font(SharedGDIObject<HFONT>::create(adoptGDIObject<HFONT>(font)))
     , m_size(size)
     , m_orientation(Horizontal)
     , m_widthVariant(RegularWidth)
diff --git a/Source/WebCore/platform/graphics/win/RefCountedGDIHandle.h b/Source/WebCore/platform/graphics/win/RefCountedGDIHandle.h
deleted file mode 100644 (file)
index 65f66f1..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef RefCountedGDIHandle_h
-#define RefCountedGDIHandle_h
-
-#include <windows.h>
-#include <wtf/HashFunctions.h>
-#include <wtf/OwnPtr.h>
-#include <wtf/RefCounted.h>
-
-namespace WebCore {
-
-template <typename T> class RefCountedGDIHandle : public RefCounted<RefCountedGDIHandle<T> > {
-public:
-    static PassRefPtr<RefCountedGDIHandle> create(T handle)
-    {
-        return adoptRef(new RefCountedGDIHandle<T>(handle));
-    }
-
-    static PassRefPtr<RefCountedGDIHandle<T> > createDeleted()
-    {
-        return adoptRef(new RefCountedGDIHandle<T>(reinterpret_cast<T>(-1)));
-    }
-
-    ~RefCountedGDIHandle()
-    {
-        if (m_handle != reinterpret_cast<T>(-1))
-            WTF::deleteOwnedPtr(m_handle);
-    }
-
-    T handle() const
-    {
-        return m_handle;
-    }
-
-    unsigned hash() const
-    {
-        return WTF::PtrHash<T>::hash(m_handle);
-    }
-
-private:
-    RefCountedGDIHandle(T handle)
-        : m_handle(handle)
-    {
-    }
-
-    T m_handle;
-};
-
-} // namespace WebCore
-
-#endif // RefCountedGDIHandle_h
similarity index 55%
rename from Source/WTF/wtf/win/OwnPtrWin.cpp
rename to Source/WebCore/platform/graphics/win/SharedGDIObject.h
index 61dd34b..dd2683a 100644 (file)
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2007 Apple Inc. All rights reserved.
- * Copyright (C) 2008, 2009 Torch Mobile, Inc.
+ * Copyright (C) 2013 Apple, Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "config.h"
-#include "OwnPtr.h"
+#ifndef SharedGDIObject_h
+#define SharedGDIObject_h
 
-#if OS(WINDOWS)
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/win/GDIObject.h>
 
-#include <windows.h>
+namespace WebCore {
 
-namespace WTF {
+template <typename T> class SharedGDIObject : public RefCounted<SharedGDIObject<T>> {
+public:
+    static PassRefPtr<SharedGDIObject> create(GDIObject<T> object)
+    {
+        return adoptRef(new SharedGDIObject<T>(std::move(object)));
+    }
 
-void deleteOwnedPtr(HBITMAP ptr)
-{
-    if (ptr)
-        DeleteObject(ptr);
-}
+    T get() const
+    {
+        return m_object.get();
+    }
 
-void deleteOwnedPtr(HDC ptr)
-{
-    if (ptr)
-        DeleteDC(ptr);
-}
+    unsigned hash() const
+    {
+        return WTF::PtrHash<T>::hash(m_object.get());
+    }
 
-void deleteOwnedPtr(HRGN ptr)
-{
-    if (ptr)
-        DeleteObject(ptr);
-}
+private:
+    explicit SharedGDIObject(GDIObject<T> object)
+        : m_object(std::move(object))
+    {
+    }
 
-} // namespace WTF
+    GDIObject<T> m_object;
+};
 
-#endif // OS(WINDOWS)
+} // namespace WebCore
+
+#endif // SharedGDIObject_h
index ff6779d..91186bf 100644 (file)
@@ -1,3 +1,20 @@
+2013-09-10  Brent Fulgham  <bfulgham@apple.com>
+
+        [Windows] Create SharedGDIObject Class Template
+        https://bugs.webkit.org/show_bug.cgi?id=121037
+
+        Reviewed by Anders Carlsson.
+
+        * WebView.cpp: Change implementations to use the new SharedGDIObject
+        class.
+        (WebView::addToDirtyRegion):
+        (WebView::scrollBackingStore):
+        (WebView::updateBackingStore):
+        (WebView::performLayeredWindowUpdate):
+        (WebView::paint):
+        (WebView::backingStore):
+        * WebView.h: Ditto.
+
 2013-09-09  Brent Fulgham  <bfulgham@apple.com>
 
         [Windows] Change from using OwnPtr<GDI Stuff> to new GDIObject template.
index dcd0f1b..5d7afa2 100644 (file)
@@ -823,7 +823,7 @@ bool WebView::ensureBackingStore()
         BitmapInfo bitmapInfo = BitmapInfo::createBottomUp(IntSize(m_backingStoreSize));
 
         void* pixels = NULL;
-        m_backingStoreBitmap = RefCountedHBITMAP::create(::CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0));
+        m_backingStoreBitmap = SharedGDIObject<HBITMAP>::create(adoptGDIObject(::CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0)));
         return true;
     }
 
@@ -843,12 +843,12 @@ void WebView::addToDirtyRegion(const IntRect& dirtyRect)
     }
 #endif
 
-    HRGN newRegion = ::CreateRectRgn(dirtyRect.x(), dirtyRect.y(),
-                                     dirtyRect.maxX(), dirtyRect.maxY());
-    addToDirtyRegion(newRegion);
+    auto newRegion = adoptGDIObject(::CreateRectRgn(dirtyRect.x(), dirtyRect.y(),
+        dirtyRect.maxX(), dirtyRect.maxY()));
+    addToDirtyRegion(std::move(newRegion));
 }
 
-void WebView::addToDirtyRegion(HRGN newRegion)
+void WebView::addToDirtyRegion(GDIObject<HRGN> newRegion)
 {
 #if USE(ACCELERATED_COMPOSITING)
     ASSERT(!isAcceleratedCompositing());
@@ -857,12 +857,11 @@ void WebView::addToDirtyRegion(HRGN newRegion)
     LOCAL_GDI_COUNTER(0, __FUNCTION__);
 
     if (m_backingStoreDirtyRegion) {
-        HRGN combinedRegion = ::CreateRectRgn(0,0,0,0);
-        ::CombineRgn(combinedRegion, m_backingStoreDirtyRegion->handle(), newRegion, RGN_OR);
-        ::DeleteObject(newRegion);
-        m_backingStoreDirtyRegion = RefCountedHRGN::create(combinedRegion);
+        auto combinedRegion = adoptGDIObject(::CreateRectRgn(0, 0, 0, 0));
+        ::CombineRgn(combinedRegion.get(), m_backingStoreDirtyRegion->get(), newRegion.get(), RGN_OR);
+        m_backingStoreDirtyRegion = SharedGDIObject<HRGN>::create(std::move(combinedRegion));
     } else
-        m_backingStoreDirtyRegion = RefCountedHRGN::create(newRegion);
+        m_backingStoreDirtyRegion = SharedGDIObject<HRGN>::create(std::move(newRegion));
 
     if (m_uiDelegatePrivate)
         m_uiDelegatePrivate->webViewDidInvalidate(this);
@@ -890,25 +889,25 @@ void WebView::scrollBackingStore(FrameView* frameView, int dx, int dy, const Int
     }
 
     // Make a region to hold the invalidated scroll area.
-    HRGN updateRegion = ::CreateRectRgn(0, 0, 0, 0);
+    auto updateRegion = adoptGDIObject(::CreateRectRgn(0, 0, 0, 0));
 
     // Collect our device context info and select the bitmap to scroll.
     HWndDC windowDC(m_viewWindow);
     auto bitmapDC = adoptGDIObject(::CreateCompatibleDC(windowDC));
-    HGDIOBJ oldBitmap = ::SelectObject(bitmapDC.get(), m_backingStoreBitmap->handle());
+    HGDIOBJ oldBitmap = ::SelectObject(bitmapDC.get(), m_backingStoreBitmap->get());
     
     // Scroll the bitmap.
     RECT scrollRectWin(scrollViewRect);
     RECT clipRectWin(clipRect);
-    ::ScrollDC(bitmapDC.get(), dx, dy, &scrollRectWin, &clipRectWin, updateRegion, 0);
+    ::ScrollDC(bitmapDC.get(), dx, dy, &scrollRectWin, &clipRectWin, updateRegion.get(), 0);
     RECT regionBox;
-    ::GetRgnBox(updateRegion, &regionBox);
+    ::GetRgnBox(updateRegion.get(), &regionBox);
 
     // Flush.
     GdiFlush();
 
     // Add the dirty region to the backing store's dirty region.
-    addToDirtyRegion(updateRegion);
+    addToDirtyRegion(std::move(updateRegion));
 
     if (m_uiDelegatePrivate)
         m_uiDelegatePrivate->webViewScrolled(this);
@@ -995,7 +994,7 @@ void WebView::updateBackingStore(FrameView* frameView, HDC dc, bool backingStore
         HWndDC windowDC(m_viewWindow);
         bitmapDCObject = adoptGDIObject(::CreateCompatibleDC(windowDC));
         bitmapDC = bitmapDCObject.get();
-        oldBitmap = ::SelectObject(bitmapDC, m_backingStoreBitmap->handle());
+        oldBitmap = ::SelectObject(bitmapDC, m_backingStoreBitmap->get());
     }
 
     if (m_backingStoreBitmap && (m_backingStoreDirtyRegion || backingStoreCompletelyDirty)) {
@@ -1007,8 +1006,8 @@ void WebView::updateBackingStore(FrameView* frameView, HDC dc, bool backingStore
         Vector<IntRect> paintRects;
         if (!backingStoreCompletelyDirty && m_backingStoreDirtyRegion) {
             RECT regionBox;
-            ::GetRgnBox(m_backingStoreDirtyRegion->handle(), &regionBox);
-            getUpdateRects(m_backingStoreDirtyRegion->handle(), regionBox, paintRects);
+            ::GetRgnBox(m_backingStoreDirtyRegion->get(), &regionBox);
+            getUpdateRects(m_backingStoreDirtyRegion->get(), regionBox, paintRects);
         } else {
             RECT clientRect;
             ::GetClientRect(m_viewWindow, &clientRect);
@@ -1038,10 +1037,10 @@ void WebView::performLayeredWindowUpdate()
 
     HWndDC hdcScreen(m_viewWindow);
     auto hdcMem = adoptGDIObject(::CreateCompatibleDC(hdcScreen));
-    HBITMAP hbmOld = static_cast<HBITMAP>(::SelectObject(hdcMem.get(), m_backingStoreBitmap->handle()));
+    HBITMAP hbmOld = static_cast<HBITMAP>(::SelectObject(hdcMem.get(), m_backingStoreBitmap->get()));
 
     BITMAP bmpInfo;
-    ::GetObject(m_backingStoreBitmap->handle(), sizeof(bmpInfo), &bmpInfo);
+    ::GetObject(m_backingStoreBitmap->get(), sizeof(bmpInfo), &bmpInfo);
     SIZE windowSize = { bmpInfo.bmWidth, bmpInfo.bmHeight };
 
     BLENDFUNCTION blendFunction;
@@ -1080,12 +1079,12 @@ void WebView::paint(HDC dc, LPARAM options)
 
     RECT rcPaint;
     HDC hdc;
-    OwnPtr<HRGN> region;
+    GDIObject<HRGN> region;
     int regionType = NULLREGION;
     PAINTSTRUCT ps;
     WindowsToPaint windowsToPaint;
     if (!dc) {
-        region = adoptPtr(CreateRectRgn(0,0,0,0));
+        region = adoptGDIObject(::CreateRectRgn(0, 0, 0, 0));
         regionType = GetUpdateRgn(m_viewWindow, region.get(), false);
         hdc = BeginPaint(m_viewWindow, &ps);
         rcPaint = ps.rcPaint;
@@ -1112,7 +1111,7 @@ void WebView::paint(HDC dc, LPARAM options)
     m_paintCount++;
 
     auto bitmapDC = adoptGDIObject(::CreateCompatibleDC(hdc));
-    HGDIOBJ oldBitmap = ::SelectObject(bitmapDC.get(), m_backingStoreBitmap->handle());
+    HGDIOBJ oldBitmap = ::SelectObject(bitmapDC.get(), m_backingStoreBitmap->get());
 
     // Update our backing store if needed.
     updateBackingStore(frameView, bitmapDC.get(), backingStoreCompletelyDirty, windowsToPaint);
@@ -5980,7 +5979,7 @@ HRESULT STDMETHODCALLTYPE WebView::backingStore(
         return E_POINTER;
     if (!m_backingStoreBitmap)
         return E_FAIL;
-    *hBitmap = reinterpret_cast<OLE_HANDLE>(m_backingStoreBitmap->handle());
+    *hBitmap = reinterpret_cast<OLE_HANDLE>(m_backingStoreBitmap->get());
     return S_OK;
 }
 
index 200cdb0..0dcb4bd 100644 (file)
@@ -34,7 +34,7 @@
 #include <WebCore/COMPtr.h>
 #include <WebCore/DragActions.h>
 #include <WebCore/IntRect.h>
-#include <WebCore/RefCountedGDIHandle.h>
+#include <WebCore/SharedGDIObject.h>
 #include <WebCore/SuspendableTimer.h>
 #include <WebCore/WindowMessageListener.h>
 #include <wtf/HashSet.h>
@@ -70,9 +70,6 @@ class WebFrame;
 class WebInspector;
 class WebInspectorClient;
 
-typedef WebCore::RefCountedGDIHandle<HBITMAP> RefCountedHBITMAP;
-typedef WebCore::RefCountedGDIHandle<HRGN> RefCountedHRGN;
-
 WebView* kit(WebCore::Page*);
 WebCore::Page* core(IWebView*);
 
@@ -880,7 +877,7 @@ public:
     void paintIntoWindow(HDC bitmapDC, HDC windowDC, const WebCore::IntRect& dirtyRect);
     bool ensureBackingStore();
     void addToDirtyRegion(const WebCore::IntRect&);
-    void addToDirtyRegion(HRGN);
+    void addToDirtyRegion(GDIObject<HRGN>);
     void scrollBackingStore(WebCore::FrameView*, int dx, int dy, const WebCore::IntRect& scrollViewRect, const WebCore::IntRect& clipRect);
     void deleteBackingStore();
     void repaint(const WebCore::IntRect&, bool contentChanged, bool immediate = false, bool repaintContentOnly = false);
@@ -1086,9 +1083,9 @@ protected:
     WebInspectorClient* m_inspectorClient;
 #endif // ENABLE(INSPECTOR)
     
-    RefPtr<RefCountedHBITMAP> m_backingStoreBitmap;
+    RefPtr<WebCore::SharedGDIObject<HBITMAP>> m_backingStoreBitmap;
     SIZE m_backingStoreSize;
-    RefPtr<RefCountedHRGN> m_backingStoreDirtyRegion;
+    RefPtr<WebCore::SharedGDIObject<HRGN>> m_backingStoreDirtyRegion;
 
     COMPtr<IAccessibilityDelegate> m_accessibilityDelegate;
     COMPtr<IWebEditingDelegate> m_editingDelegate;