Source/WebCore/ChangeLog

 12013-09-09 Brent Fulgham <bfulgham@apple.com>
 2
 3 [Windows] Change from using OwnPtr<GDI Stuff> to new GDIObject template.
 4 https://bugs.webkit.org/show_bug.cgi?id=120778
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Change code to use a GDI-specific smart pointer, rather than OwnPtr. This
 9 is a first step to simplifying OwnPtr. It also gets rid of some Windows-
 10 specific code in WTF.
 11
 12 * WebCore.vcxproj/WebCore.vcxproj: Add the new header file.
 13 * WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
 14 * platform/graphics/ca/win/CACFLayerTreeHost.cpp:
 15 (WebCore::getDirtyRects): Switch from OwnPtr to GDIObject.
 16 * platform/win/GDIObject.h: Added.
 17 (WebCore::GDIObject::GDIObject):
 18 (WebCore::GDIObject::~GDIObject):
 19 (WebCore::GDIObject::get):
 20 (WebCore::GDIObject::operator HGDIOBJ ):
 21 (WebCore::GDIObject::operator ValueType ):
 22 (WebCore::GDIObject::operator!):
 23 (WebCore::GDIObject::operator UnspecifiedBoolType):
 24 (WebCore::GDIObject::operator=):
 25 (WebCore::GDIObject::swap):
 26 (WebCore::GDIObject::operator==):
 27 (WebCore::GDIObject::operator!=):
 28 (WebCore::::clear):
 29 (WebCore::::release):
 30 (WebCore::::GDIObject):
 31 (WebCore::=):
 32 (WebCore::swap):
 33 (WebCore::operator==):
 34 (WebCore::operator!=):
 35 (WebCore::getPtr):
 36 (WebCore::T):
 37 (WebCore::HDC):
 38 * platform/win/ScrollbarThemeWin.cpp:
 39 (WebCore::ScrollbarThemeWin::paintTrackPiece): Switch to GDIObject.
 40 * rendering/RenderThemeWin.cpp:
 41 (WebCore::drawControl): Switch to GDIObject.
 42
1432013-09-09 Bem Jones-Bey <bjonesbe@adobe.com>
244
345 Move logical(Left|Right)FloatOffsetForLine methods into FloatingObjects
155368

Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

1934719347 <ClInclude Include="..\platform\win\COMPtr.h" />
1934819348 <ClInclude Include="..\platform\win\DefWndProcWindowClass.h" />
1934919349 <ClInclude Include="..\platform\win\DelayLoadedModulesEnumerator.h" />
 19350 <ClInclude Include="..\platform\win\GDIObject.h" />
1935019351 <ClInclude Include="..\platform\win\GDIObjectCounter.h" />
1935119352 <ClInclude Include="..\platform\win\HWndDC.h" />
1935219353 <ClInclude Include="..\platform\win\ImportedFunctionsEnumerator.h" />

2144821449 <ImportGroup Label="ExtensionTargets">
2144921450 <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
2145021451 </ImportGroup>
21451 </Project>
 21452</Project>
155355

Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters

31773177 <ClCompile Include="..\dom\Comment.cpp">
31783178 <Filter>dom</Filter>
31793179 </ClCompile>
3180  <ClCompile Include="..\dom\ComposedShadowTreeWalker.cpp">
3181  <Filter>dom</Filter>
3182  </ClCompile>
31833180 <ClCompile Include="..\dom\CompositionEvent.cpp">
31843181 <Filter>dom</Filter>
31853182 </ClCompile>

1024310240 <ClInclude Include="..\dom\Comment.h">
1024410241 <Filter>dom</Filter>
1024510242 </ClInclude>
10246  <ClInclude Include="..\dom\ComposedShadowTreeWalker.h">
10247  <Filter>dom</Filter>
10248  </ClInclude>
1024910243 <ClInclude Include="..\dom\CompositionEvent.h">
1025010244 <Filter>dom</Filter>
1025110245 </ClInclude>

1490314897 </ClInclude>
1490414898 <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\HTMLElementTypeHelpers.h" />
1490514899 <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\SVGElementTypeHelpers.h" />
 14900 <ClInclude Include="..\platform\win\GDIObject.h">
 14901 <Filter>platform\win</Filter>
 14902 </ClInclude>
1490614903 </ItemGroup>
1490714904 <ItemGroup>
1490814905 <None Include="..\css\CSSGrammar.y.in">

1587515872 <Filter>platform\win</Filter>
1587615873 </MASM>
1587715874 </ItemGroup>
15878 </Project>
 15875</Project>
155355

Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.cpp

3030
3131#include "CACFLayerTreeHostClient.h"
3232#include "DefWndProcWindowClass.h"
 33#include "GDIObject.h"
3334#include "LayerChangesFlusher.h"
3435#include "LegacyCACFLayerTreeHost.h"
3536#include "PlatformCALayer.h"

@@static void getDirtyRects(HWND window, V
239240 if (!GetClientRect(window, &clientRect))
240241 return;
241242
242  OwnPtr<HRGN> region = adoptPtr(CreateRectRgn(0, 0, 0, 0));
243  int regionType = GetUpdateRgn(window, region.get(), false);
 243 GDIObject<HRGN> region(::CreateRectRgn(0, 0, 0, 0));
 244 int regionType = GetUpdateRgn(window, region, false);
244245 if (regionType != COMPLEXREGION) {
245246 RECT dirtyRect;
246247 if (GetUpdateRect(window, &dirtyRect, false))

@@static void getDirtyRects(HWND window, V
248249 return;
249250 }
250251
251  DWORD dataSize = GetRegionData(region.get(), 0, 0);
 252 DWORD dataSize = ::GetRegionData(region, 0, 0);
252253 OwnArrayPtr<unsigned char> regionDataBuffer = adoptArrayPtr(new unsigned char[dataSize]);
253254 RGNDATA* regionData = reinterpret_cast<RGNDATA*>(regionDataBuffer.get());
254  if (!GetRegionData(region.get(), dataSize, regionData))
 255 if (!::GetRegionData(region, dataSize, regionData))
255256 return;
256257
257258 outRects.resize(regionData->rdh.nCount);
155355

Source/WebCore/platform/win/GDIObject.h

 1/*
 2 * Copyright (C) 2013 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef GDIObject_h
 27#define GDIObject_h
 28
 29#include <algorithm>
 30#include <memory>
 31#include <wtf/Assertions.h>
 32#include <wtf/Noncopyable.h>
 33#include <wtf/NullPtr.h>
 34
 35typedef struct HBITMAP__* HBITMAP;
 36typedef struct HBRUSH__* HBRUSH;
 37typedef struct HDC__* HDC;
 38typedef struct HFONT__* HFONT;
 39typedef struct HPALETTE__* HPALETTE;
 40typedef struct HPEN__* HPEN;
 41typedef struct HRGN__* HRGN;
 42
 43namespace WebCore {
 44
 45template<typename T> void deleteObject(T);
 46
 47template<typename T> class GDIObject {
 48#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
 49 // If rvalue references are not supported, the copy constructor is
 50 // public so GDIObject cannot be marked noncopyable. See note below.
 51 WTF_MAKE_NONCOPYABLE(GDIObject);
 52#endif
 53public:
 54 typedef T ValueType;
 55 typedef ValueType* PtrType;
 56
 57 GDIObject() : m_obj(0) { }
 58 GDIObject(const T& obj) : m_obj(obj) { }
 59
 60 ~GDIObject() { deleteObject<T>(m_obj); }
 61
 62 PtrType get() const { return &m_obj; }
 63 operator HGDIOBJ () { return static_cast<HGDIOBJ>(m_obj); }
 64 operator ValueType () { return m_obj; }
 65
 66 void clear();
 67 ValueType release() WARN_UNUSED_RETURN;
 68
 69 bool operator!() const { return !m_obj; }
 70
 71 // This conversion operator allows implicit conversion to bool but not to other integer types.
 72 typedef PtrType GDIObject::*UnspecifiedBoolType;
 73 operator UnspecifiedBoolType() const { return m_obj ? &GDIObject::m_obj : 0; }
 74
 75 GDIObject<T>& operator=(T);
 76 GDIObject<T>& operator=(std::nullptr_t) { clear(); return *this; }
 77
 78#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
 79 GDIObject(GDIObject&&);
 80 template<typename U> GDIObject(GDIObject<U>&&);
 81
 82 GDIObject& operator=(GDIObject&&);
 83 template<typename U> GDIObject& operator=(GDIObject<U>&&);
 84#endif
 85
 86 void swap(GDIObject& o) { std::swap(m_obj, o.m_obj); }
 87
 88private:
 89#if !COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
 90 // If rvalue references are supported, noncopyable takes care of this.
 91 GDIObject& operator=(const GDIObject&);
 92#endif
 93
 94 // We should never have two GDIObjects for the same underlying object (otherwise we'll get
 95 // double-destruction), so these equality operators should never be needed.
 96 template<typename U> bool operator==(const GDIObject<U>&) { COMPILE_ASSERT(!sizeof(U*), GDIObjects_should_never_be_equal); return false; }
 97 template<typename U> bool operator!=(const GDIObject<U>&) { COMPILE_ASSERT(!sizeof(U*), GDIObjects_should_never_be_equal); return false; }
 98
 99 T m_obj;
 100};
 101
 102template<typename T> inline void GDIObject<T>::clear()
 103{
 104 ValueType ptr = m_obj;
 105 m_obj = 0;
 106 deleteObject(ptr);
 107}
 108
 109template<typename T> inline T GDIObject<T>::release()
 110{
 111 ValueType obj = m_obj;
 112 m_obj = 0;
 113 return obj;
 114}
 115
 116#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
 117template<typename T> inline GDIObject<T>::GDIObject(GDIObject<T>&& o)
 118 : m_obj(o.leakObject())
 119{
 120}
 121
 122template<typename T> inline GDIObject<T>& GDIObject<T>::operator=(GDIObject<T>&& o)
 123{
 124 ValueType obj = m_obj;
 125 m_obj = o.leakObject();
 126 ASSERT(!obj || m_obj != obj);
 127 deleteObject(obj);
 128
 129 return *this;
 130}
 131#endif
 132
 133template<typename T> inline GDIObject<T>& GDIObject<T>::operator=(T o)
 134{
 135 ValueType obj = m_obj;
 136 m_obj = o;
 137 ASSERT(!obj || m_obj != obj);
 138 deleteObject(obj);
 139
 140 return *this;
 141}
 142
 143template<typename T> inline void swap(GDIObject<T>& a, GDIObject<T>& b)
 144{
 145 a.swap(b);
 146}
 147
 148template<typename T, typename U> inline bool operator==(const GDIObject<T>& a, U* b)
 149{
 150 return a.get() == b;
 151}
 152
 153template<typename T, typename U> inline bool operator==(T* a, const GDIObject<U>& b)
 154{
 155 return a == b.get();
 156}
 157
 158template<typename T, typename U> inline bool operator!=(const GDIObject<T>& a, U* b)
 159{
 160 return a.get() != b;
 161}
 162
 163template<typename T, typename U> inline bool operator!=(T* a, const GDIObject<U>& b)
 164{
 165 return a != b.get();
 166}
 167
 168template<typename T> inline typename GDIObject<T>::PtrType getPtr(const GDIObject<T>& p)
 169{
 170 return p.get();
 171}
 172
 173// Nearly all GDI types use the same DeleteObject call.
 174template<typename T> inline void deleteObject<T>(T obj)
 175{
 176 if (obj)
 177 ::DeleteObject(obj);
 178}
 179
 180template<> inline void deleteObject<HDC>(HDC obj)
 181{
 182 if (obj)
 183 ::DeleteDC(obj);
 184}
 185
 186} // namespace WebCore
 187
 188using WebCore::GDIObject;
 189
 190#endif // GDIObject_h
0

Source/WebCore/platform/win/ScrollbarThemeWin.cpp

2626#include "config.h"
2727#include "ScrollbarThemeWin.h"
2828
 29#include "GDIObject.h"
2930#include "GraphicsContext.h"
3031#include "LocalWindowsContext.h"
3132#include "PlatformMouseEvent.h"

@@void ScrollbarThemeWin::paintTrackPiece(
257258 else {
258259 static WORD patternBits[8] = { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 };
259260 OwnPtr<HBITMAP> patternBitmap = adoptPtr(::CreateBitmap(8, 8, 1, 1, patternBits));
260  OwnPtr<HBRUSH> brush = adoptPtr(::CreatePatternBrush(patternBitmap.get()));
 261 GDIObject<HBRUSH> brush(::CreatePatternBrush(patternBitmap.get()));
261262 SaveDC(hdc);
262263 ::SetTextColor(hdc, ::GetSysColor(COLOR_3DHILIGHT));
263264 ::SetBkColor(hdc, ::GetSysColor(COLOR_3DFACE));
264265 ::SetBrushOrgEx(hdc, rect.x(), rect.y(), NULL);
265  ::SelectObject(hdc, brush.get());
266  ::FillRect(hdc, &themeRect, brush.get());
 266 ::SelectObject(hdc, brush);
 267 ::FillRect(hdc, &themeRect, brush);
267268 ::RestoreDC(hdc, -1);
268269 }
269270 }
155355

Source/WebCore/rendering/RenderThemeWin.cpp

2727#include "FontMetrics.h"
2828#include "Frame.h"
2929#include "FrameSelection.h"
 30#include "GDIObject.h"
3031#include "GraphicsContext.h"
3132#include "HTMLMeterElement.h"
3233#include "LocalWindowsContext.h"

@@static void drawControl(GraphicsContext*
692693 static WORD patternBits[8] = {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55};
693694 OwnPtr<HBITMAP> patternBmp = adoptPtr(::CreateBitmap(8, 8, 1, 1, patternBits));
694695 if (patternBmp) {
695  OwnPtr<HBRUSH> brush = adoptPtr(::CreatePatternBrush(patternBmp.get()));
 696 GDIObject<HBRUSH> brush(::CreatePatternBrush(patternBmp.get()));
696697 COLORREF oldForeColor = ::SetTextColor(hdc, ::GetSysColor(COLOR_3DFACE));
697698 COLORREF oldBackColor = ::SetBkColor(hdc, ::GetSysColor(COLOR_3DHILIGHT));
698699 POINT p;
699700 ::GetViewportOrgEx(hdc, &p);
700701 ::SetBrushOrgEx(hdc, p.x + widgetRect.left, p.y + widgetRect.top, NULL);
701  HGDIOBJ oldBrush = ::SelectObject(hdc, brush.get());
702  ::FillRect(hdc, &widgetRect, brush.get());
 702 HGDIOBJ oldBrush = ::SelectObject(hdc, brush);
 703 ::FillRect(hdc, &widgetRect, brush);
703704 ::SetTextColor(hdc, oldForeColor);
704705 ::SetBkColor(hdc, oldBackColor);
705706 ::SelectObject(hdc, oldBrush);
155355