1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
26 #include <win/wincomp.hxx>
27 #include <win/salbmp.h>
28 #include <win/saldata.hxx>
29 #include <win/salids.hrc>
30 #include <win/salgdi.h>
31 #include <win/salframe.h>
32 #include <opengl/salbmp.hxx>
34 #include <vcl/BitmapAccessMode.hxx>
35 #include <vcl/BitmapBuffer.hxx>
36 #include <vcl/BitmapPalette.hxx>
37 #include <vcl/Scanline.hxx>
38 #include <vcl/bitmapaccess.hxx>
39 #include <outdata.hxx>
40 #include <salgdiimpl.hxx>
41 #include <opengl/win/gdiimpl.hxx>
44 bool WinSalGraphics::supportsOperation( OutDevSupportType eType
) const
46 static bool bAllowForTest(true);
51 case OutDevSupportType::TransparentRect
:
52 bRet
= mbVirDev
|| mbWindow
;
54 case OutDevSupportType::B2DDraw
:
62 void WinSalGraphics::copyBits( const SalTwoRect
& rPosAry
, SalGraphics
* pSrcGraphics
)
64 mpImpl
->copyBits( rPosAry
, pSrcGraphics
);
67 void WinSalGraphics::copyArea( long nDestX
, long nDestY
,
68 long nSrcX
, long nSrcY
,
69 long nSrcWidth
, long nSrcHeight
,
70 bool bWindowInvalidate
)
72 mpImpl
->copyArea( nDestX
, nDestY
, nSrcX
, nSrcY
,
73 nSrcWidth
, nSrcHeight
, bWindowInvalidate
);
79 class ColorScanlineConverter
82 ScanlineFormat meSourceFormat
;
83 ScanlineFormat meDestinationFormat
;
86 int mnComponentExchangeIndex
;
90 ColorScanlineConverter(ScanlineFormat eSourceFormat
, ScanlineFormat eDestinationFormat
, int nComponentSize
, long nScanlineSize
)
91 : meSourceFormat(eSourceFormat
)
92 , meDestinationFormat(eDestinationFormat
)
93 , mnComponentSize(nComponentSize
)
94 , mnComponentExchangeIndex(0)
95 , mnScanlineSize(nScanlineSize
)
97 if (meSourceFormat
== ScanlineFormat::N32BitTcAbgr
||
98 meSourceFormat
== ScanlineFormat::N32BitTcArgb
)
100 mnComponentExchangeIndex
= 1;
104 void convertScanline(sal_uInt8
* pSource
, sal_uInt8
* pDestination
)
106 for (long x
= 0; x
< mnScanlineSize
; x
+= mnComponentSize
)
108 for (int i
= 0; i
< mnComponentSize
; ++i
)
110 pDestination
[x
+ i
] = pSource
[x
+ i
];
112 pDestination
[x
+ mnComponentExchangeIndex
+ 0] = pSource
[x
+ mnComponentExchangeIndex
+ 2];
113 pDestination
[x
+ mnComponentExchangeIndex
+ 2] = pSource
[x
+ mnComponentExchangeIndex
+ 0];
118 void convertToWinSalBitmap(SalBitmap
& rSalBitmap
, WinSalBitmap
& rWinSalBitmap
)
120 BitmapPalette aBitmapPalette
;
121 OpenGLSalBitmap
* pGLSalBitmap
= dynamic_cast<OpenGLSalBitmap
*>(&rSalBitmap
);
122 if (pGLSalBitmap
!= nullptr)
124 aBitmapPalette
= pGLSalBitmap
->GetBitmapPalette();
127 BitmapBuffer
* pRead
= rSalBitmap
.AcquireBuffer(BitmapAccessMode::Read
);
129 rWinSalBitmap
.Create(rSalBitmap
.GetSize(), rSalBitmap
.GetBitCount(), aBitmapPalette
);
130 BitmapBuffer
* pWrite
= rWinSalBitmap
.AcquireBuffer(BitmapAccessMode::Write
);
132 sal_uInt8
* pSource(pRead
->mpBits
);
133 sal_uInt8
* pDestination(pWrite
->mpBits
);
135 std::unique_ptr
<ColorScanlineConverter
> pConverter
;
137 if (pRead
->mnFormat
== ScanlineFormat::N24BitTcRgb
)
138 pConverter
.reset(new ColorScanlineConverter(ScanlineFormat::N24BitTcRgb
, ScanlineFormat::N24BitTcBgr
,
139 3, pRead
->mnScanlineSize
));
140 else if (pRead
->mnFormat
== ScanlineFormat::N32BitTcRgba
)
141 pConverter
.reset(new ColorScanlineConverter(ScanlineFormat::N32BitTcRgba
, ScanlineFormat::N32BitTcBgra
,
142 4, pRead
->mnScanlineSize
));
145 for (long y
= 0; y
< pRead
->mnHeight
; y
++)
147 pConverter
->convertScanline(pSource
, pDestination
);
148 pSource
+= pRead
->mnScanlineSize
;
149 pDestination
+= pWrite
->mnScanlineSize
;
154 for (long y
= 0; y
< pRead
->mnHeight
; y
++)
156 memcpy(pDestination
, pSource
, pRead
->mnScanlineSize
);
157 pSource
+= pRead
->mnScanlineSize
;
158 pDestination
+= pWrite
->mnScanlineSize
;
161 rWinSalBitmap
.ReleaseBuffer(pWrite
, BitmapAccessMode::Write
);
163 rSalBitmap
.ReleaseBuffer(pRead
, BitmapAccessMode::Read
);
166 } // end anonymous namespace
168 void WinSalGraphics::drawBitmap(const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
)
170 if (dynamic_cast<WinOpenGLSalGraphicsImpl
*>(mpImpl
.get()) == nullptr &&
171 dynamic_cast<const WinSalBitmap
*>(&rSalBitmap
) == nullptr)
173 std::unique_ptr
<WinSalBitmap
> pWinSalBitmap(new WinSalBitmap());
174 SalBitmap
& rConstBitmap
= const_cast<SalBitmap
&>(rSalBitmap
);
175 convertToWinSalBitmap(rConstBitmap
, *pWinSalBitmap
);
176 mpImpl
->drawBitmap(rPosAry
, *pWinSalBitmap
);
180 mpImpl
->drawBitmap(rPosAry
, rSalBitmap
);
184 void WinSalGraphics::drawBitmap( const SalTwoRect
& rPosAry
,
185 const SalBitmap
& rSSalBitmap
,
186 const SalBitmap
& rSTransparentBitmap
)
188 if (dynamic_cast<WinOpenGLSalGraphicsImpl
*>(mpImpl
.get()) == nullptr &&
189 dynamic_cast<const WinSalBitmap
*>(&rSSalBitmap
) == nullptr)
191 std::unique_ptr
<WinSalBitmap
> pWinSalBitmap(new WinSalBitmap());
192 SalBitmap
& rConstBitmap
= const_cast<SalBitmap
&>(rSSalBitmap
);
193 convertToWinSalBitmap(rConstBitmap
, *pWinSalBitmap
);
196 std::unique_ptr
<WinSalBitmap
> pWinTransparentSalBitmap(new WinSalBitmap());
197 SalBitmap
& rConstTransparentBitmap
= const_cast<SalBitmap
&>(rSTransparentBitmap
);
198 convertToWinSalBitmap(rConstTransparentBitmap
, *pWinTransparentSalBitmap
);
200 mpImpl
->drawBitmap(rPosAry
, *pWinSalBitmap
, *pWinTransparentSalBitmap
);
204 mpImpl
->drawBitmap(rPosAry
, rSSalBitmap
, rSTransparentBitmap
);
208 bool WinSalGraphics::drawAlphaRect( long nX
, long nY
, long nWidth
,
209 long nHeight
, sal_uInt8 nTransparency
)
211 return mpImpl
->drawAlphaRect( nX
, nY
, nWidth
, nHeight
, nTransparency
);
214 void WinSalGraphics::drawMask( const SalTwoRect
& rPosAry
,
215 const SalBitmap
& rSSalBitmap
,
218 mpImpl
->drawMask( rPosAry
, rSSalBitmap
, nMaskColor
);
221 std::shared_ptr
<SalBitmap
> WinSalGraphics::getBitmap( long nX
, long nY
, long nDX
, long nDY
)
223 return mpImpl
->getBitmap( nX
, nY
, nDX
, nDY
);
226 Color
WinSalGraphics::getPixel( long nX
, long nY
)
228 return mpImpl
->getPixel( nX
, nY
);
231 void WinSalGraphics::invert( long nX
, long nY
, long nWidth
, long nHeight
, SalInvert nFlags
)
233 mpImpl
->invert( nX
, nY
, nWidth
, nHeight
, nFlags
);
236 void WinSalGraphics::invert( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, SalInvert nSalFlags
)
238 mpImpl
->invert( nPoints
, pPtAry
, nSalFlags
);
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */