tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / vcl / win / gdi / salgdi2.cxx
blobba4afc157bc355e7e299addec069475a25cc6016
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <memory>
21 #include <string.h>
22 #include <stdlib.h>
24 #include <svsys.h>
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>
33 #include <vcl/BitmapAccessMode.hxx>
34 #include <vcl/BitmapBuffer.hxx>
35 #include <vcl/BitmapPalette.hxx>
36 #include <vcl/BitmapReadAccess.hxx>
37 #include <vcl/Scanline.hxx>
38 #include <salgdiimpl.hxx>
40 #include <config_features.h>
41 #if HAVE_FEATURE_SKIA
42 #include <skia/win/gdiimpl.hxx>
43 #include <skia/salbmp.hxx>
44 #endif
47 bool WinSalGraphics::supportsOperation( OutDevSupportType eType ) const
49 return mpImpl->supportsOperation(eType);
52 void WinSalGraphics::copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics )
54 mpImpl->copyBits( rPosAry, pSrcGraphics );
57 void WinSalGraphics::copyArea( tools::Long nDestX, tools::Long nDestY,
58 tools::Long nSrcX, tools::Long nSrcY,
59 tools::Long nSrcWidth, tools::Long nSrcHeight,
60 bool bWindowInvalidate )
62 mpImpl->copyArea( nDestX, nDestY, nSrcX, nSrcY,
63 nSrcWidth, nSrcHeight, bWindowInvalidate );
66 namespace
69 class ColorScanlineConverter
71 public:
72 ScanlineFormat meSourceFormat;
74 int mnComponentSize;
75 int mnComponentExchangeIndex;
77 tools::Long mnScanlineSize;
79 ColorScanlineConverter(ScanlineFormat eSourceFormat, int nComponentSize, tools::Long nScanlineSize)
80 : meSourceFormat(eSourceFormat)
81 , mnComponentSize(nComponentSize)
82 , mnComponentExchangeIndex(0)
83 , mnScanlineSize(nScanlineSize)
85 if (meSourceFormat == ScanlineFormat::N32BitTcAbgr ||
86 meSourceFormat == ScanlineFormat::N32BitTcArgb)
88 mnComponentExchangeIndex = 1;
92 void convertScanline(sal_uInt8* pSource, sal_uInt8* pDestination)
94 for (tools::Long x = 0; x < mnScanlineSize; x += mnComponentSize)
96 for (int i = 0; i < mnComponentSize; ++i)
98 pDestination[x + i] = pSource[x + i];
100 pDestination[x + mnComponentExchangeIndex + 0] = pSource[x + mnComponentExchangeIndex + 2];
101 pDestination[x + mnComponentExchangeIndex + 2] = pSource[x + mnComponentExchangeIndex + 0];
106 void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap)
108 BitmapPalette aBitmapPalette;
109 #if HAVE_FEATURE_SKIA
110 if(SkiaSalBitmap* pSkiaSalBitmap = dynamic_cast<SkiaSalBitmap*>(&rSalBitmap))
111 aBitmapPalette = pSkiaSalBitmap->Palette();
112 #endif
114 BitmapBuffer* pRead = rSalBitmap.AcquireBuffer(BitmapAccessMode::Read);
116 rWinSalBitmap.Create(rSalBitmap.GetSize(), vcl::bitDepthToPixelFormat(rSalBitmap.GetBitCount()), aBitmapPalette);
117 BitmapBuffer* pWrite = rWinSalBitmap.AcquireBuffer(BitmapAccessMode::Write);
119 sal_uInt8* pSource(pRead->mpBits);
120 sal_uInt8* pDestination(pWrite->mpBits);
121 tools::Long readRowChange = pRead->mnScanlineSize;
122 if (pRead->meDirection == ScanlineDirection::TopDown)
124 pSource += pRead->mnScanlineSize * (pRead->mnHeight - 1);
125 readRowChange = -readRowChange;
128 std::unique_ptr<ColorScanlineConverter> pConverter;
130 if (pRead->meFormat == ScanlineFormat::N24BitTcRgb)
132 pConverter.reset(new ColorScanlineConverter(ScanlineFormat::N24BitTcRgb, 3, pRead->mnScanlineSize));
134 else if (pRead->meFormat == ScanlineFormat::N32BitTcRgba)
136 pConverter.reset(new ColorScanlineConverter(ScanlineFormat::N32BitTcRgba, 4, pRead->mnScanlineSize));
138 if (pConverter)
140 for (tools::Long y = 0; y < pRead->mnHeight; y++)
142 pConverter->convertScanline(pSource, pDestination);
143 pSource += readRowChange;
144 pDestination += pWrite->mnScanlineSize;
147 else
149 for (tools::Long y = 0; y < pRead->mnHeight; y++)
151 memcpy(pDestination, pSource, pRead->mnScanlineSize);
152 pSource += readRowChange;
153 pDestination += pWrite->mnScanlineSize;
156 rWinSalBitmap.ReleaseBuffer(pWrite, BitmapAccessMode::Write);
158 rSalBitmap.ReleaseBuffer(pRead, BitmapAccessMode::Read);
161 } // end anonymous namespace
163 void WinSalGraphics::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap)
165 assert(&rSalBitmap && "msvc -analyze gets confused here");
166 if (dynamic_cast<const WinSalBitmap*>(&rSalBitmap) == nullptr
167 #if HAVE_FEATURE_SKIA
168 && dynamic_cast<WinSkiaSalGraphicsImpl*>(mpImpl.get()) == nullptr
169 #endif
172 WinSalBitmap aWinSalBitmap;
173 SalBitmap& rConstBitmap = const_cast<SalBitmap&>(rSalBitmap);
174 convertToWinSalBitmap(rConstBitmap, aWinSalBitmap);
175 mpImpl->drawBitmap(rPosAry, aWinSalBitmap);
177 else
179 mpImpl->drawBitmap(rPosAry, rSalBitmap);
183 void WinSalGraphics::drawBitmap( const SalTwoRect& rPosAry,
184 const SalBitmap& rSSalBitmap,
185 const SalBitmap& rSTransparentBitmap )
187 assert(&rSSalBitmap && "msvc -analyze gets confused here");
188 if (dynamic_cast<const WinSalBitmap*>(&rSSalBitmap) == nullptr
189 #if HAVE_FEATURE_SKIA
190 && dynamic_cast<WinSkiaSalGraphicsImpl*>(mpImpl.get()) == nullptr
191 #endif
194 WinSalBitmap aWinSalBitmap;
195 SalBitmap& rConstBitmap = const_cast<SalBitmap&>(rSSalBitmap);
196 convertToWinSalBitmap(rConstBitmap, aWinSalBitmap);
198 WinSalBitmap aWinTransparentSalBitmap;
199 SalBitmap& rConstTransparentBitmap = const_cast<SalBitmap&>(rSTransparentBitmap);
200 convertToWinSalBitmap(rConstTransparentBitmap, aWinTransparentSalBitmap);
202 mpImpl->drawBitmap(rPosAry, aWinSalBitmap, aWinTransparentSalBitmap);
204 else
206 mpImpl->drawBitmap(rPosAry, rSSalBitmap, rSTransparentBitmap);
210 bool WinSalGraphics::drawAlphaRect( tools::Long nX, tools::Long nY, tools::Long nWidth,
211 tools::Long nHeight, sal_uInt8 nTransparency )
213 return mpImpl->drawAlphaRect( nX, nY, nWidth, nHeight, nTransparency );
216 void WinSalGraphics::drawMask( const SalTwoRect& rPosAry,
217 const SalBitmap& rSSalBitmap,
218 Color nMaskColor )
220 mpImpl->drawMask( rPosAry, rSSalBitmap, nMaskColor );
223 std::shared_ptr<SalBitmap> WinSalGraphics::getBitmap( tools::Long nX, tools::Long nY, tools::Long nDX, tools::Long nDY )
225 return mpImpl->getBitmap( nX, nY, nDX, nDY );
228 Color WinSalGraphics::getPixel( tools::Long nX, tools::Long nY )
230 return mpImpl->getPixel( nX, nY );
233 void WinSalGraphics::invert( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, SalInvert nFlags )
235 mpImpl->invert( nX, nY, nWidth, nHeight, nFlags );
238 void WinSalGraphics::invert( sal_uInt32 nPoints, const Point* pPtAry, SalInvert nSalFlags )
240 mpImpl->invert( nPoints, pPtAry, nSalFlags );
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */