Kaydet (Commit) c2c60eb9 authored tarafından Dmitriy Shilin's avatar Dmitriy Shilin Kaydeden (comit) Mike Kaganski

tdf#107792 vcl/win: introduce ScopedCachedHDC

Change-Id: Ia6c5ca98005642bbcce9d9d66bf16a4d4cbed04e
Reviewed-on: https://gerrit.libreoffice.org/66648
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 44df356a
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <win/svsys.h> #include <win/svsys.h>
#include <win/wincomp.hxx> #include <win/wincomp.hxx>
#include <win/saldata.hxx>
#include <memory> #include <memory>
...@@ -53,6 +54,22 @@ using ScopedSelectedHPEN = ScopedSelectedGDI<ScopedHPEN, SelectPen>; ...@@ -53,6 +54,22 @@ using ScopedSelectedHPEN = ScopedSelectedGDI<ScopedHPEN, SelectPen>;
using ScopedSelectedHFONT = ScopedSelectedGDI<ScopedHFONT, SelectFont>; using ScopedSelectedHFONT = ScopedSelectedGDI<ScopedHFONT, SelectFont>;
using ScopedSelectedHBRUSH = ScopedSelectedGDI<ScopedHBRUSH, SelectBrush>; using ScopedSelectedHBRUSH = ScopedSelectedGDI<ScopedHBRUSH, SelectBrush>;
template <sal_uLong ID> class ScopedCachedHDC
{
public:
explicit ScopedCachedHDC(HBITMAP hBitmap)
: m_hDC(ImplGetCachedDC(ID, hBitmap))
{
}
~ScopedCachedHDC() { ImplReleaseCachedDC(ID); }
HDC get() const { return m_hDC; }
private:
HDC m_hDC;
};
#endif // INCLUDED_VCL_INC_WIN_SCOPED_GDI_HXX #endif // INCLUDED_VCL_INC_WIN_SCOPED_GDI_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -559,7 +559,8 @@ void ImplDrawBitmap( HDC hDC, const SalTwoRect& rPosAry, const WinSalBitmap& rSa ...@@ -559,7 +559,8 @@ void ImplDrawBitmap( HDC hDC, const SalTwoRect& rPosAry, const WinSalBitmap& rSa
} }
else if( hDrawDDB && !bPrintDDB ) else if( hDrawDDB && !bPrintDDB )
{ {
HDC hBmpDC = ImplGetCachedDC( CACHED_HDC_DRAW, hDrawDDB ); ScopedCachedHDC<CACHED_HDC_DRAW> hBmpDC(hDrawDDB);
COLORREF nOldBkColor = RGB(0xFF,0xFF,0xFF); COLORREF nOldBkColor = RGB(0xFF,0xFF,0xFF);
COLORREF nOldTextColor = RGB(0,0,0); COLORREF nOldTextColor = RGB(0,0,0);
bool bMono = ( rSalBitmap.GetBitCount() == 1 ); bool bMono = ( rSalBitmap.GetBitCount() == 1 );
...@@ -592,7 +593,7 @@ void ImplDrawBitmap( HDC hDC, const SalTwoRect& rPosAry, const WinSalBitmap& rSa ...@@ -592,7 +593,7 @@ void ImplDrawBitmap( HDC hDC, const SalTwoRect& rPosAry, const WinSalBitmap& rSa
BitBlt( hDC, BitBlt( hDC,
static_cast<int>(rPosAry.mnDestX), static_cast<int>(rPosAry.mnDestY), static_cast<int>(rPosAry.mnDestX), static_cast<int>(rPosAry.mnDestY),
static_cast<int>(rPosAry.mnDestWidth), static_cast<int>(rPosAry.mnDestHeight), static_cast<int>(rPosAry.mnDestWidth), static_cast<int>(rPosAry.mnDestHeight),
hBmpDC, hBmpDC.get(),
static_cast<int>(rPosAry.mnSrcX), static_cast<int>(rPosAry.mnSrcY), static_cast<int>(rPosAry.mnSrcX), static_cast<int>(rPosAry.mnSrcY),
nDrawMode ); nDrawMode );
} }
...@@ -603,7 +604,7 @@ void ImplDrawBitmap( HDC hDC, const SalTwoRect& rPosAry, const WinSalBitmap& rSa ...@@ -603,7 +604,7 @@ void ImplDrawBitmap( HDC hDC, const SalTwoRect& rPosAry, const WinSalBitmap& rSa
StretchBlt( hDC, StretchBlt( hDC,
static_cast<int>(rPosAry.mnDestX), static_cast<int>(rPosAry.mnDestY), static_cast<int>(rPosAry.mnDestX), static_cast<int>(rPosAry.mnDestY),
static_cast<int>(rPosAry.mnDestWidth), static_cast<int>(rPosAry.mnDestHeight), static_cast<int>(rPosAry.mnDestWidth), static_cast<int>(rPosAry.mnDestHeight),
hBmpDC, hBmpDC.get(),
static_cast<int>(rPosAry.mnSrcX), static_cast<int>(rPosAry.mnSrcY), static_cast<int>(rPosAry.mnSrcX), static_cast<int>(rPosAry.mnSrcY),
static_cast<int>(rPosAry.mnSrcWidth), static_cast<int>(rPosAry.mnSrcHeight), static_cast<int>(rPosAry.mnSrcWidth), static_cast<int>(rPosAry.mnSrcHeight),
nDrawMode ); nDrawMode );
...@@ -616,8 +617,6 @@ void ImplDrawBitmap( HDC hDC, const SalTwoRect& rPosAry, const WinSalBitmap& rSa ...@@ -616,8 +617,6 @@ void ImplDrawBitmap( HDC hDC, const SalTwoRect& rPosAry, const WinSalBitmap& rSa
SetBkColor( hDC, nOldBkColor ); SetBkColor( hDC, nOldBkColor );
::SetTextColor( hDC, nOldTextColor ); ::SetTextColor( hDC, nOldTextColor );
} }
ImplReleaseCachedDC( CACHED_HDC_DRAW );
} }
} }
} }
...@@ -688,11 +687,11 @@ void WinSalGraphicsImpl::drawBitmap( const SalTwoRect& rPosAry, ...@@ -688,11 +687,11 @@ void WinSalGraphicsImpl::drawBitmap( const SalTwoRect& rPosAry,
hMaskBitmap.reset(CreateCompatibleBitmap(hDC, nDstWidth, nDstHeight)); hMaskBitmap.reset(CreateCompatibleBitmap(hDC, nDstWidth, nDstHeight));
} }
HDC hMemDC = ImplGetCachedDC( CACHED_HDC_1, hMemBitmap.get() ); ScopedCachedHDC<CACHED_HDC_1> hMemDC(hMemBitmap.get());
HDC hMaskDC = ImplGetCachedDC( CACHED_HDC_2, hMaskBitmap.get() ); ScopedCachedHDC<CACHED_HDC_2> hMaskDC(hMaskBitmap.get());
aPosAry.mnDestX = aPosAry.mnDestY = 0; aPosAry.mnDestX = aPosAry.mnDestY = 0;
BitBlt( hMemDC, 0, 0, nDstWidth, nDstHeight, hDC, nDstX, nDstY, SRCCOPY ); BitBlt( hMemDC.get(), 0, 0, nDstWidth, nDstHeight, hDC, nDstX, nDstY, SRCCOPY );
// WIN/WNT seems to have a minor problem mapping the correct color of the // WIN/WNT seems to have a minor problem mapping the correct color of the
// mask to the palette if we draw the DIB directly ==> draw DDB // mask to the palette if we draw the DIB directly ==> draw DDB
...@@ -701,35 +700,32 @@ void WinSalGraphicsImpl::drawBitmap( const SalTwoRect& rPosAry, ...@@ -701,35 +700,32 @@ void WinSalGraphicsImpl::drawBitmap( const SalTwoRect& rPosAry,
WinSalBitmap aTmp; WinSalBitmap aTmp;
if( aTmp.Create( rTransparentBitmap, &mrParent ) ) if( aTmp.Create( rTransparentBitmap, &mrParent ) )
ImplDrawBitmap( hMaskDC, aPosAry, aTmp, false, SRCCOPY ); ImplDrawBitmap( hMaskDC.get(), aPosAry, aTmp, false, SRCCOPY );
} }
else else
ImplDrawBitmap( hMaskDC, aPosAry, rTransparentBitmap, false, SRCCOPY ); ImplDrawBitmap( hMaskDC.get(), aPosAry, rTransparentBitmap, false, SRCCOPY );
// now MemDC contains background, MaskDC the transparency mask // now MemDC contains background, MaskDC the transparency mask
// #105055# Respect XOR mode // #105055# Respect XOR mode
if( mbXORMode ) if( mbXORMode )
{ {
ImplDrawBitmap( hMaskDC, aPosAry, rSalBitmap, false, SRCERASE ); ImplDrawBitmap( hMaskDC.get(), aPosAry, rSalBitmap, false, SRCERASE );
// now MaskDC contains the bitmap area with black background // now MaskDC contains the bitmap area with black background
BitBlt( hMemDC, 0, 0, nDstWidth, nDstHeight, hMaskDC, 0, 0, SRCINVERT ); BitBlt( hMemDC.get(), 0, 0, nDstWidth, nDstHeight, hMaskDC.get(), 0, 0, SRCINVERT );
// now MemDC contains background XORed bitmap area ontop // now MemDC contains background XORed bitmap area ontop
} }
else else
{ {
BitBlt( hMemDC, 0, 0, nDstWidth, nDstHeight, hMaskDC, 0, 0, SRCAND ); BitBlt( hMemDC.get(), 0, 0, nDstWidth, nDstHeight, hMaskDC.get(), 0, 0, SRCAND );
// now MemDC contains background with masked-out bitmap area // now MemDC contains background with masked-out bitmap area
ImplDrawBitmap( hMaskDC, aPosAry, rSalBitmap, false, SRCERASE ); ImplDrawBitmap( hMaskDC.get(), aPosAry, rSalBitmap, false, SRCERASE );
// now MaskDC contains the bitmap area with black background // now MaskDC contains the bitmap area with black background
BitBlt( hMemDC, 0, 0, nDstWidth, nDstHeight, hMaskDC, 0, 0, SRCPAINT ); BitBlt( hMemDC.get(), 0, 0, nDstWidth, nDstHeight, hMaskDC.get(), 0, 0, SRCPAINT );
// now MemDC contains background and bitmap merged together // now MemDC contains background and bitmap merged together
} }
// copy to output DC // copy to output DC
BitBlt( hDC, nDstX, nDstY, nDstWidth, nDstHeight, hMemDC, 0, 0, SRCCOPY ); BitBlt( hDC, nDstX, nDstY, nDstWidth, nDstHeight, hMemDC.get(), 0, 0, SRCCOPY );
ImplReleaseCachedDC( CACHED_HDC_1 );
ImplReleaseCachedDC( CACHED_HDC_2 );
} }
bool WinSalGraphicsImpl::drawAlphaRect( long nX, long nY, long nWidth, bool WinSalGraphicsImpl::drawAlphaRect( long nX, long nY, long nWidth,
...@@ -738,8 +734,8 @@ bool WinSalGraphicsImpl::drawAlphaRect( long nX, long nY, long nWidth, ...@@ -738,8 +734,8 @@ bool WinSalGraphicsImpl::drawAlphaRect( long nX, long nY, long nWidth,
if( mbPen || !mbBrush || mbXORMode ) if( mbPen || !mbBrush || mbXORMode )
return false; // can only perform solid fills without XOR. return false; // can only perform solid fills without XOR.
HDC hMemDC = ImplGetCachedDC( CACHED_HDC_1 ); ScopedCachedHDC<CACHED_HDC_1> hMemDC(nullptr);
SetPixel( hMemDC, int(0), int(0), mnBrushColor ); SetPixel( hMemDC.get(), int(0), int(0), mnBrushColor );
BLENDFUNCTION aFunc = { BLENDFUNCTION aFunc = {
AC_SRC_OVER, AC_SRC_OVER,
...@@ -751,11 +747,9 @@ bool WinSalGraphicsImpl::drawAlphaRect( long nX, long nY, long nWidth, ...@@ -751,11 +747,9 @@ bool WinSalGraphicsImpl::drawAlphaRect( long nX, long nY, long nWidth,
// hMemDC contains a 1x1 bitmap of the right color - stretch-blit // hMemDC contains a 1x1 bitmap of the right color - stretch-blit
// that to dest hdc // that to dest hdc
bool bRet = GdiAlphaBlend(mrParent.getHDC(), nX, nY, nWidth, nHeight, bool bRet = GdiAlphaBlend(mrParent.getHDC(), nX, nY, nWidth, nHeight,
hMemDC, 0,0,1,1, hMemDC.get(), 0,0,1,1,
aFunc ) == TRUE; aFunc ) == TRUE;
ImplReleaseCachedDC( CACHED_HDC_1 );
return bRet; return bRet;
} }
...@@ -800,11 +794,15 @@ std::shared_ptr<SalBitmap> WinSalGraphicsImpl::getBitmap( long nX, long nY, long ...@@ -800,11 +794,15 @@ std::shared_ptr<SalBitmap> WinSalGraphicsImpl::getBitmap( long nX, long nY, long
HDC hDC = mrParent.getHDC(); HDC hDC = mrParent.getHDC();
HBITMAP hBmpBitmap = CreateCompatibleBitmap( hDC, nDX, nDY ); HBITMAP hBmpBitmap = CreateCompatibleBitmap( hDC, nDX, nDY );
HDC hBmpDC = ImplGetCachedDC( CACHED_HDC_1, hBmpBitmap );
bool bRet; bool bRet;
bRet = BitBlt( hBmpDC, 0, 0, static_cast<int>(nDX), static_cast<int>(nDY), hDC, static_cast<int>(nX), static_cast<int>(nY), SRCCOPY ) ? TRUE : FALSE; {
ImplReleaseCachedDC( CACHED_HDC_1 ); ScopedCachedHDC<CACHED_HDC_1> hBmpDC(hBmpBitmap);
bRet = BitBlt(hBmpDC.get(), 0, 0,
static_cast<int>(nDX), static_cast<int>(nDY), hDC,
static_cast<int>(nX), static_cast<int>(nY), SRCCOPY) ? TRUE : FALSE;
}
if( bRet ) if( bRet )
{ {
......
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