Commit f44603e1 authored by bfulgham@apple.com's avatar bfulgham@apple.com

[Windows] Revise GDI Create Functions to use GDIObject Smart Pointer.

https://bugs.webkit.org/show_bug.cgi?id=121100

Reviewed by Anders Carlsson.

* platform/graphics/FontPlatformData.h: Use GDIObject instead of bare pointer.
* platform/graphics/win/FontCacheWin.cpp:
(WebCore::createGDIFont): No longer need to leak the pointer; use move semantic
to pass ownership to FontPlatformData.
(WebCore::FontCache::createFontPlatformData):
* platform/graphics/win/FontCustomPlatformData.cpp:
(WebCore::FontCustomPlatformData::fontPlatformData): Use move operation.
* platform/graphics/win/FontCustomPlatformDataCairo.cpp:
(WebCore::FontCustomPlatformData::fontPlatformData): Ditto.
* 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/GlyphPageTreeNodeCairoWin.cpp:
(WebCore::GlyphPage::fill): Use HWndDC smart pointer instead of bare HDC.
* platform/graphics/win/SimpleFontDataWin.cpp:
(WebCore::SimpleFontData::platformCreateScaledFontData): Use move operation.
* platform/win/DragImageCGWin.cpp:
(WebCore::allocImage): Change to use GDIObject.
(WebCore::scaleDragImage): Use smart pointers to avoid manual deallocs.
(WebCore::createDragImageFromImage): Ditto.
* platform/win/DragImageCairoWin.cpp:
(WebCore::allocImage): Change to use GDIObject.
(WebCore::scaleDragImage): Use smart pointers to avoid manual deallocs.
(WebCore::createDragImageFromImage): Ditto.
* platform/win/DragImageWin.cpp:
(WebCore::createDragImageForLink): Update for GDIObject.
* platform/win/PopupMenuWin.cpp:
(WebCore::PopupMenuWin::PopupMenuWin): Switch to GDIObject.
(WebCore::PopupMenuWin::~PopupMenuWin): Remove uneeded deallocs.
(WebCore::PopupMenuWin::paint): Update for GDIObject.
* platform/win/PopupMenuWin.h: Use smart pointers instead of bare GDI objects.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@155557 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d856e104
2013-09-11 Brent Fulgham <bfulgham@apple.com>
[Windows] Revise GDI Create Functions to use GDIObject Smart Pointer.
https://bugs.webkit.org/show_bug.cgi?id=121100
Reviewed by Anders Carlsson.
* platform/graphics/FontPlatformData.h: Use GDIObject instead of bare pointer.
* platform/graphics/win/FontCacheWin.cpp:
(WebCore::createGDIFont): No longer need to leak the pointer; use move semantic
to pass ownership to FontPlatformData.
(WebCore::FontCache::createFontPlatformData):
* platform/graphics/win/FontCustomPlatformData.cpp:
(WebCore::FontCustomPlatformData::fontPlatformData): Use move operation.
* platform/graphics/win/FontCustomPlatformDataCairo.cpp:
(WebCore::FontCustomPlatformData::fontPlatformData): Ditto.
* 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/GlyphPageTreeNodeCairoWin.cpp:
(WebCore::GlyphPage::fill): Use HWndDC smart pointer instead of bare HDC.
* platform/graphics/win/SimpleFontDataWin.cpp:
(WebCore::SimpleFontData::platformCreateScaledFontData): Use move operation.
* platform/win/DragImageCGWin.cpp:
(WebCore::allocImage): Change to use GDIObject.
(WebCore::scaleDragImage): Use smart pointers to avoid manual deallocs.
(WebCore::createDragImageFromImage): Ditto.
* platform/win/DragImageCairoWin.cpp:
(WebCore::allocImage): Change to use GDIObject.
(WebCore::scaleDragImage): Use smart pointers to avoid manual deallocs.
(WebCore::createDragImageFromImage): Ditto.
* platform/win/DragImageWin.cpp:
(WebCore::createDragImageForLink): Update for GDIObject.
* platform/win/PopupMenuWin.cpp:
(WebCore::PopupMenuWin::PopupMenuWin): Switch to GDIObject.
(WebCore::PopupMenuWin::~PopupMenuWin): Remove uneeded deallocs.
(WebCore::PopupMenuWin::paint): Update for GDIObject.
* platform/win/PopupMenuWin.h: Use smart pointers instead of bare GDI objects.
2013-09-11 Patrick Gansterer <paroga@webkit.org>
Fix animations with !USE(ACCELERATED_COMPOSITING) after r147792.
......@@ -101,11 +101,11 @@ public:
#endif
#endif
#if PLATFORM(WIN)
FontPlatformData(HFONT, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
FontPlatformData(GDIObject<HFONT>, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
#if USE(CG)
FontPlatformData(HFONT, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
FontPlatformData(GDIObject<HFONT>, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
#elif USE(CAIRO)
FontPlatformData(HFONT, cairo_font_face_t*, float size, bool bold, bool italic);
FontPlatformData(GDIObject<HFONT>, cairo_font_face_t*, float size, bool bold, bool italic);
#endif
#endif
......
......@@ -441,7 +441,7 @@ static int CALLBACK matchImprovingEnumProc(CONST LOGFONT* candidate, CONST TEXTM
return 1;
}
static HFONT createGDIFont(const AtomicString& family, LONG desiredWeight, bool desiredItalic, int size, bool synthesizeItalic)
static GDIObject<HFONT> createGDIFont(const AtomicString& family, LONG desiredWeight, bool desiredItalic, int size, bool synthesizeItalic)
{
HWndDC hdc(0);
......@@ -456,7 +456,7 @@ static HFONT createGDIFont(const AtomicString& family, LONG desiredWeight, bool
EnumFontFamiliesEx(hdc, &logFont, matchImprovingEnumProc, reinterpret_cast<LPARAM>(&matchData), 0);
if (!matchData.m_hasMatched)
return 0;
return nullptr;
matchData.m_chosen.lfHeight = -size;
matchData.m_chosen.lfWidth = 0;
......@@ -478,7 +478,7 @@ static HFONT createGDIFont(const AtomicString& family, LONG desiredWeight, bool
auto chosenFont = adoptGDIObject(::CreateFontIndirect(&matchData.m_chosen));
if (!chosenFont)
return 0;
return nullptr;
HWndDC dc(0);
SaveDC(dc);
......@@ -488,9 +488,9 @@ static HFONT createGDIFont(const AtomicString& family, LONG desiredWeight, bool
RestoreDC(dc, -1);
if (wcsicmp(matchData.m_chosen.lfFaceName, actualName))
return 0;
return nullptr;
return chosenFont.leak();
return chosenFont;
}
struct TraitsInFamilyProcData {
......@@ -553,8 +553,8 @@ PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip
// FIXME: We will eventually want subpixel precision for GDI mode, but the scaled rendering doesn't
// look as nice. That may be solvable though.
LONG weight = adjustedGDIFontWeight(toGDIFontWeight(fontDescription.weight()), family);
auto hfont = adoptGDIObject(createGDIFont(family, weight, fontDescription.italic(),
fontDescription.computedPixelSize() * (useGDI ? 1 : 32), useGDI));
auto hfont = createGDIFont(family, weight, fontDescription.italic(),
fontDescription.computedPixelSize() * (useGDI ? 1 : 32), useGDI);
if (!hfont)
return nullptr;
......@@ -568,7 +568,7 @@ PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip
bool synthesizeBold = isGDIFontWeightBold(weight) && !isGDIFontWeightBold(logFont.lfWeight);
bool synthesizeItalic = fontDescription.italic() && !logFont.lfItalic;
FontPlatformData* result = new FontPlatformData(hfont.get(), fontDescription.computedPixelSize(), synthesizeBold, synthesizeItalic, useGDI);
FontPlatformData* result = new FontPlatformData(std::move(hfont), fontDescription.computedPixelSize(), synthesizeBold, synthesizeItalic, useGDI);
#if USE(CG)
bool fontCreationFailed = !result->cgFont();
......@@ -584,8 +584,6 @@ PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip
return nullptr;
}
hfont.leak(); // result now owns the HFONT.
return adoptPtr(result);
}
......
......@@ -66,7 +66,7 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, b
auto hfont = adoptGDIObject(::CreateFontIndirect(&logFont));
RetainPtr<CGFontRef> cgFont = adoptCF(CGFontCreateWithPlatformFont(&logFont));
return FontPlatformData(hfont.leak(), cgFont.get(), size, bold, italic, renderingMode == AlternateRenderingMode);
return FontPlatformData(std::move(hfont), cgFont.get(), size, bold, italic, renderingMode == AlternateRenderingMode);
}
// Creates a unique and unpredictable font name, in order to avoid collisions and to
......
......@@ -63,7 +63,7 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, b
cairo_font_face_t* fontFace = cairo_win32_font_face_create_for_hfont(hfont.get());
FontPlatformData fontPlatformData(hfont.leak(), fontFace, size, bold, italic);
FontPlatformData fontPlatformData(std::move(hfont), fontFace, size, bold, italic);
cairo_font_face_destroy(fontFace);
......
......@@ -115,13 +115,13 @@ void FontPlatformData::platformDataInit(HFONT font, float size, HDC hdc, WCHAR*
m_cgFont = adoptCF(CGFontCreateWithPlatformFont(&logfont));
}
FontPlatformData::FontPlatformData(HFONT hfont, CGFontRef font, float size, bool bold, bool oblique, bool useGDI)
FontPlatformData::FontPlatformData(GDIObject<HFONT> hfont, CGFontRef font, float size, bool bold, bool oblique, bool useGDI)
: m_syntheticBold(bold)
, m_syntheticOblique(oblique)
, m_orientation(Horizontal)
, m_size(size)
, m_widthVariant(RegularWidth)
, m_font(SharedGDIObject<HFONT>::create(adoptGDIObject<HFONT>(hfont)))
, m_font(SharedGDIObject<HFONT>::create(std::move(hfont)))
, m_cgFont(font)
, m_isColorBitmapFont(false)
, m_useGDI(useGDI)
......
......@@ -56,8 +56,8 @@ void FontPlatformData::platformDataInit(HFONT font, float size, HDC hdc, WCHAR*
cairo_font_face_destroy(fontFace);
}
FontPlatformData::FontPlatformData(HFONT font, cairo_font_face_t* fontFace, float size, bool bold, bool oblique)
: m_font(SharedGDIObject<HFONT>::create(adoptGDIObject<HFONT>(font)))
FontPlatformData::FontPlatformData(GDIObject<HFONT> font, cairo_font_face_t* fontFace, float size, bool bold, bool oblique)
: m_font(SharedGDIObject<HFONT>::create(std::move(font)))
, m_size(size)
, m_orientation(Horizontal)
, m_widthVariant(RegularWidth)
......
......@@ -37,8 +37,8 @@ using std::min;
namespace WebCore {
FontPlatformData::FontPlatformData(HFONT font, float size, bool bold, bool oblique, bool useGDI)
: m_font(SharedGDIObject<HFONT>::create(adoptGDIObject<HFONT>(font)))
FontPlatformData::FontPlatformData(GDIObject<HFONT> font, float size, bool bold, bool oblique, bool useGDI)
: m_font(SharedGDIObject<HFONT>::create(std::move(font)))
, m_size(size)
, m_orientation(Horizontal)
, m_widthVariant(RegularWidth)
......@@ -55,7 +55,7 @@ FontPlatformData::FontPlatformData(HFONT font, float size, bool bold, bool obliq
HWndDC hdc(0);
SaveDC(hdc);
SelectObject(hdc, font);
::SelectObject(hdc, m_font->get());
UINT bufferSize = GetOutlineTextMetrics(hdc, 0, NULL);
ASSERT_WITH_MESSAGE(bufferSize, "Bitmap fonts not supported with CoreGraphics.");
......@@ -66,7 +66,7 @@ FontPlatformData::FontPlatformData(HFONT font, float size, bool bold, bool obliq
GetOutlineTextMetricsW(hdc, bufferSize, metrics);
WCHAR* faceName = (WCHAR*)((uintptr_t)metrics + (uintptr_t)metrics->otmpFaceName);
platformDataInit(font, size, hdc, faceName);
platformDataInit(m_font->get(), size, hdc, faceName);
free(metrics);
}
......
......@@ -42,7 +42,7 @@ bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned b
bool haveGlyphs = false;
HDC dc = GetDC((HWND)0);
HWndDC dc(0);
SaveDC(dc);
SelectObject(dc, fontData->platformData().hfont());
......@@ -61,7 +61,6 @@ bool GlyphPage::fill(unsigned offset, unsigned length, UChar* buffer, unsigned b
}
}
RestoreDC(dc, -1);
ReleaseDC(0, dc);
return haveGlyphs;
}
......
......@@ -140,7 +140,7 @@ PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const Fo
GetObject(m_platformData.hfont(), sizeof(LOGFONT), &winfont);
winfont.lfHeight = -lroundf(scaledSize * (m_platformData.useGDI() ? 1 : 32));
auto hfont = adoptGDIObject(::CreateFontIndirect(&winfont));
return SimpleFontData::create(FontPlatformData(hfont.leak(), scaledSize, m_platformData.syntheticBold(), m_platformData.syntheticOblique(), m_platformData.useGDI()), isCustomFont(), false);
return SimpleFontData::create(FontPlatformData(std::move(hfont), scaledSize, m_platformData.syntheticBold(), m_platformData.syntheticOblique(), m_platformData.useGDI()), isCustomFont(), false);
}
bool SimpleFontData::containsCharacters(const UChar* characters, int length) const
......
......@@ -45,12 +45,12 @@ void deallocContext(CGContextRef target)
CGContextRelease(target);
}
HBITMAP allocImage(HDC dc, IntSize size, CGContextRef *targetRef)
GDIObject<HBITMAP> allocImage(HDC dc, IntSize size, CGContextRef *targetRef)
{
BitmapInfo bmpInfo = BitmapInfo::create(size);
LPVOID bits;
HBITMAP hbmp = CreateDIBSection(dc, &bmpInfo, DIB_RGB_COLORS, &bits, 0, 0);
auto hbmp = adoptGDIObject(::CreateDIBSection(dc, &bmpInfo, DIB_RGB_COLORS, &bits, 0, 0));
if (!targetRef)
return hbmp;
......@@ -58,10 +58,8 @@ HBITMAP allocImage(HDC dc, IntSize size, CGContextRef *targetRef)
CGContextRef bitmapContext = CGBitmapContextCreate(bits, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight, 8,
bmpInfo.bmiHeader.biWidth * 4, deviceRGBColorSpaceRef(),
kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst);
if (!bitmapContext) {
DeleteObject(hbmp);
return 0;
}
if (!bitmapContext)
return GDIObject<HBITMAP>();
*targetRef = bitmapContext;
return hbmp;
......@@ -78,30 +76,31 @@ static CGContextRef createCgContextFromBitmap(HBITMAP bitmap)
return bitmapContext;
}
DragImageRef scaleDragImage(DragImageRef image, FloatSize scale)
DragImageRef scaleDragImage(DragImageRef imageRef, FloatSize scale)
{
// FIXME: due to the way drag images are done on windows we need
// to preprocess the alpha channel <rdar://problem/5015946>
if (!image)
if (!imageRef)
return 0;
CGContextRef targetContext;
CGContextRef srcContext;
CGImageRef srcImage;
IntSize srcSize = dragImageSize(image);
GDIObject<HBITMAP> hbmp;
auto image = adoptGDIObject(imageRef);
IntSize srcSize = dragImageSize(image.get());
IntSize dstSize(static_cast<int>(srcSize.width() * scale.width()), static_cast<int>(srcSize.height() * scale.height()));
HBITMAP hbmp = 0;
HWndDC dc(0);
auto dstDC = adoptGDIObject(::CreateCompatibleDC(dc));
if (!dstDC)
goto exit;
CGContextRef targetContext;
hbmp = allocImage(dstDC.get(), dstSize, &targetContext);
if (!hbmp)
goto exit;
srcContext = createCgContextFromBitmap(image);
srcImage = CGBitmapContextCreateImage(srcContext);
CGContextRef srcContext = createCgContextFromBitmap(image.get());
CGImageRef srcImage = CGBitmapContextCreateImage(srcContext);
CGRect rect;
rect.origin.x = 0;
rect.origin.y = 0;
......@@ -110,34 +109,25 @@ DragImageRef scaleDragImage(DragImageRef image, FloatSize scale)
CGImageRelease(srcImage);
CGContextRelease(srcContext);
CGContextRelease(targetContext);
::DeleteObject(image);
image = 0;
exit:
if (!hbmp)
hbmp = image;
return hbmp;
hbmp.swap(image);
return hbmp.leak();
}
DragImageRef createDragImageFromImage(Image* img, ImageOrientationDescription)
{
HBITMAP hbmp = 0;
HWndDC dc(0);
auto workingDC = adoptGDIObject(::CreateCompatibleDC(dc));
CGContextRef drawContext = 0;
if (!workingDC)
return 0;
hbmp = allocImage(workingDC.get(), img->size(), &drawContext);
if (!hbmp)
CGContextRef drawContext = 0;
auto hbmp = allocImage(workingDC.get(), img->size(), &drawContext);
if (!hbmp || !drawContext)
return 0;
if (!drawContext) {
::DeleteObject(hbmp);
hbmp = 0;
}
CGImageRef srcImage = img->getCGImageRef();
CGRect rect;
rect.size = img->size();
......@@ -153,7 +143,7 @@ DragImageRef createDragImageFromImage(Image* img, ImageOrientationDescription)
}
CGContextRelease(drawContext);
return hbmp;
return hbmp.leak();
}
}
......@@ -43,12 +43,12 @@ void deallocContext(PlatformContextCairo* target)
delete target;
}
HBITMAP allocImage(HDC dc, IntSize size, PlatformContextCairo** targetRef)
GDIObject<HBITMAP> allocImage(HDC dc, IntSize size, PlatformContextCairo** targetRef)
{
BitmapInfo bmpInfo = BitmapInfo::create(size);
LPVOID bits;
HBITMAP hbmp = CreateDIBSection(dc, &bmpInfo, DIB_RGB_COLORS, &bits, 0, 0);
auto hbmp = adoptGDIObject(::CreateDIBSection(dc, &bmpInfo, DIB_RGB_COLORS, &bits, 0, 0));
// At this point, we have a Cairo surface that points to a Windows DIB. The DIB interprets
// with the opposite meaning of positive Y axis, so everything we draw into this cairo
......@@ -62,10 +62,8 @@ HBITMAP allocImage(HDC dc, IntSize size, PlatformContextCairo** targetRef)
bmpInfo.bmiHeader.biHeight,
bmpInfo.bmiHeader.biWidth * 4);
if (!bitmapContext) {
DeleteObject(hbmp);
return 0;
}
if (!bitmapContext)
return GDIObject<HBITMAP>();
cairo_t* cr = cairo_create(bitmapContext);
cairo_surface_destroy(bitmapContext);
......@@ -102,20 +100,21 @@ static cairo_surface_t* createCairoContextFromBitmap(HBITMAP bitmap)
info.bmWidthBytes);
}
DragImageRef scaleDragImage(DragImageRef image, FloatSize scale)
DragImageRef scaleDragImage(DragImageRef imageRef, FloatSize scale)
{
// FIXME: due to the way drag images are done on windows we need
// to preprocess the alpha channel <rdar://problem/5015946>
if (!image)
if (!imageRef)
return 0;
IntSize srcSize = dragImageSize(image);
GDIObject<HBITMAP> hbmp;
auto image = adoptGDIObject(imageRef);
IntSize srcSize = dragImageSize(image.get());
IntSize dstSize(static_cast<int>(srcSize.width() * scale.width()), static_cast<int>(srcSize.height() * scale.height()));
HBITMAP hbmp = 0;
HDC dc = GetDC(0);
HWndDC dc(0);
auto dstDC = adoptGDIObject(::CreateCompatibleDC(dc));
if (!dstDC)
goto exit;
......@@ -124,7 +123,7 @@ DragImageRef scaleDragImage(DragImageRef image, FloatSize scale)
if (!hbmp)
goto exit;
cairo_surface_t* srcImage = createCairoContextFromBitmap(image);
cairo_surface_t* srcImage = createCairoContextFromBitmap(image.get());
// Scale the target surface to the new image size, and flip it
// so that when we set the srcImage as the surface it will draw
......@@ -139,52 +138,39 @@ DragImageRef scaleDragImage(DragImageRef image, FloatSize scale)
cairo_surface_destroy(srcImage);
deallocContext(targetContext);
::DeleteObject(image);
image = 0;
exit:
if (!hbmp)
hbmp = image;
ReleaseDC(0, dc);
return hbmp;
hbmp.swap(image);
return hbmp.leak();
}
DragImageRef createDragImageFromImage(Image* img, ImageOrientationDescription)
{
HBITMAP hbmp = 0;
HDC dc = GetDC(0);
HWndDC dc(0);
auto workingDC = adoptGDIObject(::CreateCompatibleDC(dc));
if (!workingDC)
goto exit;
return 0;
PlatformContextCairo* drawContext = 0;
hbmp = allocImage(workingDC.get(), img->size(), &drawContext);
if (!hbmp)
goto exit;
auto hbmp = allocImage(workingDC.get(), img->size(), &drawContext);
if (!hbmp || !drawContext)
return 0;
if (!drawContext) {
::DeleteObject(hbmp);
hbmp = 0;
}
cairo_t* cr = drawContext->cr();
cairo_set_source_rgb(cr, 1.0, 0.0, 1.0);
cairo_fill_preserve(cr);
{ // This block is required due to the msvc compiler error C2362.
cairo_t* cr = drawContext->cr();
cairo_set_source_rgb(cr, 1.0, 0.0, 1.0);
cairo_fill_preserve(cr);
RefPtr<cairo_surface_t> surface = img->nativeImageForCurrentFrame();
if (surface) {
// Draw the image.
cairo_set_source_surface(cr, surface.get(), 0.0, 0.0);
cairo_paint(cr);
}
RefPtr<cairo_surface_t> surface = img->nativeImageForCurrentFrame();
if (surface) {
// Draw the image.
cairo_set_source_surface(cr, surface.get(), 0.0, 0.0);
cairo_paint(cr);
}
deallocContext(drawContext);
exit:
ReleaseDC(0, dc);
return hbmp;
return hbmp.leak();
}
}
......@@ -44,7 +44,7 @@
namespace WebCore {
HBITMAP allocImage(HDC, IntSize, PlatformGraphicsContext** targetRef);
GDIObject<HBITMAP> allocImage(HDC, IntSize, PlatformGraphicsContext** targetRef);
void deallocContext(PlatformGraphicsContext* target);
IntSize dragImageSize(DragImageRef image)
......@@ -178,18 +178,17 @@ DragImageRef createDragImageForLink(KURL& url, const String& inLabel, FontRender
// We now know how big the image needs to be, so we create and
// fill the background
HBITMAP image = 0;
HWndDC dc(0);
auto workingDC = adoptGDIObject(::CreateCompatibleDC(dc));
if (!workingDC)
return 0;
PlatformGraphicsContext* contextRef;
image = allocImage(workingDC.get(), imageSize, &contextRef);
auto image = allocImage(workingDC.get(), imageSize, &contextRef);
if (!image)
return 0;
::SelectObject(workingDC.get(), image);
::SelectObject(workingDC.get(), image.get());
GraphicsContext context(contextRef);
// On Mac alpha is {0.7, 0.7, 0.7, 0.8}, however we can't control alpha
// for drag images on win, so we use 1
......@@ -215,7 +214,7 @@ DragImageRef createDragImageForLink(KURL& url, const String& inLabel, FontRender
WebCoreDrawDoubledTextAtPoint(context, label, textPos, *labelFont, topColor, bottomColor);
deallocContext(contextRef);
return image;
return image.leak();
}
}
......@@ -107,8 +107,6 @@ PopupMenuWin::PopupMenuWin(PopupMenuClient* client)
: m_popupClient(client)
, m_scrollbar(0)
, m_popup(0)
, m_DC(0)
, m_bmp(0)
, m_wasClicked(false)
, m_itemHeight(0)
, m_scrollOffset(0)
......@@ -121,10 +119,6 @@ PopupMenuWin::PopupMenuWin(PopupMenuClient* client)
PopupMenuWin::~PopupMenuWin()
{
if (m_bmp)
::DeleteObject(m_bmp);
if (m_DC)
::DeleteDC(m_DC);
if (m_popup)
::DestroyWindow(m_popup);
if (m_scrollbar)
......@@ -589,7 +583,7 @@ void PopupMenuWin::paint(const IntRect& damageRect, HDC hdc)
return;
if (!m_DC) {
m_DC = ::CreateCompatibleDC(HWndDC(m_popup));
m_DC = adoptGDIObject(::CreateCompatibleDC(HWndDC(m_popup)));
if (!m_DC)
return;
}
......@@ -597,13 +591,11 @@ void PopupMenuWin::paint(const IntRect& damageRect, HDC hdc)
if (m_bmp) {
bool keepBitmap = false;
BITMAP bitmap;
if (GetObject(m_bmp, sizeof(bitmap), &bitmap))
if (::GetObject(m_bmp.get(), sizeof(bitmap), &bitmap))
keepBitmap = bitmap.bmWidth == clientRect().width()
&& bitmap.bmHeight == clientRect().height();
if (!keepBitmap) {
DeleteObject(m_bmp);
m_bmp = 0;
}
if (!keepBitmap)
m_bmp.clear();
}
if (!m_bmp) {
#if OS(WINCE)
......@@ -612,14 +604,14 @@ void PopupMenuWin::paint(const IntRect& damageRect, HDC hdc)
BitmapInfo bitmapInfo = BitmapInfo::createBottomUp(clientRect().size());
#endif
void* pixels = 0;
m_bmp = ::CreateDIBSection(m_DC, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0);
m_bmp = adoptGDIObject(::CreateDIBSection(m_DC.get(), &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0));
if (!m_bmp)
return;
::SelectObject(m_DC, m_bmp);
::SelectObject(m_DC.get(), m_bmp.get());
}
GraphicsContext context(m_DC);
GraphicsContext context(m_DC.get());
int itemCount = client()->listSize();
......@@ -684,7 +676,7 @@ void PopupMenuWin::paint(const IntRect& damageRect, HDC hdc)
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);
::BitBlt(localDC, damageRect.x(), damageRect.y(), damageRect.width(), damageRect.height(), m_DC.get(), damageRect.x(), damageRect.y(), SRCCOPY);
}
int PopupMenuWin::scrollSize(ScrollbarOrientation orientation) const
......
......@@ -120,8 +120,8 @@ private:
PopupMenuClient* m_popupClient;
RefPtr<Scrollbar> m_scrollbar;
HWND m_popup;
HDC m_DC;
HBITMAP m_bmp;
GDIObject<HDC> m_DC;
GDIObject<HBITMAP> m_bmp;
bool m_wasClicked;
IntRect m_windowRect;
int m_itemHeight;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment