diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-11-03 23:05:25 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2016-11-04 15:53:48 +0000 |
commit | 6b571ae4608ac15256eb7582f442ce69975370f3 (patch) | |
tree | c76fdd06a8ba38678297ab48889e62a41604a24c /vcl | |
parent | c52d1403c3b9874bd1454093e0379e8766679609 (diff) |
opengl: change from BGRA to RGBA color arrangement on Windows
BGRA is native color arrangement on Windows however some intel
drivers have problems with large textures if they read from a
BGRA buffer. So with this commit we switch to RGBA color
arrangement. This shouldn't cause much performance differences,
but we need to convert from RGBA to BGRA when printing.
Change-Id: Ic112dc6a6c5d8b70e96041d0de15a03bbbdc406f
Reviewed-on: https://gerrit.libreoffice.org/30544
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/opengl/salbmp.cxx | 40 | ||||
-rw-r--r-- | vcl/win/gdi/salgdi2.cxx | 67 |
2 files changed, 64 insertions, 43 deletions
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx index fde9f199157d..bce9fb7850c0 100644 --- a/vcl/opengl/salbmp.cxx +++ b/vcl/opengl/salbmp.cxx @@ -55,28 +55,16 @@ inline bool determineTextureFormat(sal_uInt16 nBits, GLenum& nFormat, GLenum& nT nType = GL_UNSIGNED_BYTE; return true; case 16: -#ifdef _WIN32 - nFormat = GL_BGR; -#else nFormat = GL_RGB; -#endif nType = GL_UNSIGNED_SHORT_5_6_5; return true; case 24: -#ifdef _WIN32 - nFormat = GL_BGR; -#else nFormat = GL_RGB; -#endif nType = GL_UNSIGNED_BYTE; return true; case 32: -#ifdef _WIN32 - nFormat = GL_BGRA; -#else nFormat = GL_RGBA; -#endif - nType = GL_UNSIGNED_BYTE; + nType = GL_UNSIGNED_INT_8_8_8_8; return true; default: break; @@ -783,16 +771,6 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode ) break; case 16: { -#ifdef _WIN32 - pBuffer->mnFormat = ScanlineFormat::N16BitTcLsbMask; - ColorMaskElement aRedMask(0x00007c00); - aRedMask.CalcMaskShift(); - ColorMaskElement aGreenMask(0x000003e0); - aGreenMask.CalcMaskShift(); - ColorMaskElement aBlueMask(0x0000001f); - aBlueMask.CalcMaskShift(); - pBuffer->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); -#else pBuffer->mnFormat = ScanlineFormat::N16BitTcMsbMask; ColorMaskElement aRedMask(0x0000f800); aRedMask.CalcMaskShift(); @@ -801,30 +779,15 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode ) ColorMaskElement aBlueMask(0x0000001f); aBlueMask.CalcMaskShift(); pBuffer->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); -#endif break; } case 24: { -#ifdef _WIN32 - pBuffer->mnFormat = ScanlineFormat::N24BitTcBgr; -#else pBuffer->mnFormat = ScanlineFormat::N24BitTcRgb; -#endif break; } case 32: { -#ifdef _WIN32 - pBuffer->mnFormat = ScanlineFormat::N32BitTcBgra; - ColorMaskElement aRedMask(0x00ff0000); - aRedMask.CalcMaskShift(); - ColorMaskElement aGreenMask(0x0000ff00); - aGreenMask.CalcMaskShift(); - ColorMaskElement aBlueMask(0x000000ff); - aBlueMask.CalcMaskShift(); - pBuffer->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); -#else pBuffer->mnFormat = ScanlineFormat::N32BitTcRgba; ColorMaskElement aRedMask(0xff000000); aRedMask.CalcMaskShift(); @@ -833,7 +796,6 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode ) ColorMaskElement aBlueMask(0x0000ff00); aBlueMask.CalcMaskShift(); pBuffer->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); -#endif break; } } diff --git a/vcl/win/gdi/salgdi2.cxx b/vcl/win/gdi/salgdi2.cxx index 3a49ac592dde..000746bbf042 100644 --- a/vcl/win/gdi/salgdi2.cxx +++ b/vcl/win/gdi/salgdi2.cxx @@ -73,6 +73,45 @@ void WinSalGraphics::copyArea( long nDestX, long nDestY, namespace { +class ColorScanlineConverter +{ +public: + ScanlineFormat meSourceFormat; + ScanlineFormat meDestinationFormat; + + int mnComponentSize; + int mnComponentExchangeIndex; + + long mnScanlineSize; + + ColorScanlineConverter(ScanlineFormat eSourceFormat, ScanlineFormat eDestinationFormat, int nComponentSize, long nScanlineSize) + : meSourceFormat(eSourceFormat) + , meDestinationFormat(eDestinationFormat) + , mnComponentSize(nComponentSize) + , mnComponentExchangeIndex(0) + , mnScanlineSize(nScanlineSize) + { + if (meSourceFormat == ScanlineFormat::N32BitTcAbgr || + meSourceFormat == ScanlineFormat::N32BitTcArgb) + { + mnComponentExchangeIndex = 1; + } + } + + void convertScanline(sal_uInt8* pSource, sal_uInt8* pDestination) + { + for (int x = 0; x < mnScanlineSize; x += mnComponentSize) + { + for (int i = 0; i < mnComponentSize; ++i) + { + pDestination[x + i] = pSource[x + i]; + } + pDestination[x + mnComponentExchangeIndex + 0] = pSource[x + mnComponentExchangeIndex + 2]; + pDestination[x + mnComponentExchangeIndex + 2] = pSource[x + mnComponentExchangeIndex + 0]; + } + } +}; + void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap) { BitmapPalette aBitmapPalette; @@ -90,11 +129,31 @@ void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap) sal_uInt8* pSource(pRead->mpBits); sal_uInt8* pDestination(pWrite->mpBits); - for (long y = 0; y < pRead->mnHeight; y++) + std::unique_ptr<ColorScanlineConverter> pConverter; + + if (pRead->mnFormat == ScanlineFormat::N24BitTcRgb) + pConverter.reset(new ColorScanlineConverter(ScanlineFormat::N24BitTcRgb, ScanlineFormat::N24BitTcBgr, + 3, pRead->mnScanlineSize)); + else if (pRead->mnFormat == ScanlineFormat::N32BitTcRgba) + pConverter.reset(new ColorScanlineConverter(ScanlineFormat::N32BitTcRgba, ScanlineFormat::N32BitTcBgra, + 4, pRead->mnScanlineSize)); + if (pConverter) + { + for (long y = 0; y < pRead->mnHeight; y++) + { + pConverter->convertScanline(pSource, pDestination); + pSource += pRead->mnScanlineSize; + pDestination += pWrite->mnScanlineSize; + } + } + else { - memcpy(pDestination, pSource, pRead->mnScanlineSize); - pSource += pRead->mnScanlineSize; - pDestination += pWrite->mnScanlineSize; + for (long y = 0; y < pRead->mnHeight; y++) + { + memcpy(pDestination, pSource, pRead->mnScanlineSize); + pSource += pRead->mnScanlineSize; + pDestination += pWrite->mnScanlineSize; + } } rWinSalBitmap.ReleaseBuffer(pWrite, BitmapAccessMode::Write); |