[Libreoffice-commits] core.git: include/vcl vcl/inc vcl/opengl vcl/skia vcl/source
LuboÅ¡ LuÅák (via logerrit)
logerrit at kemper.freedesktop.org
Tue Apr 7 09:54:36 UTC 2020
include/vcl/bitmap.hxx | 3 ++-
vcl/inc/opengl/salbmp.hxx | 1 +
vcl/inc/salbmp.hxx | 4 ++++
vcl/inc/skia/salbmp.hxx | 1 +
vcl/opengl/salbmp.cxx | 7 +++++++
vcl/skia/salbmp.cxx | 30 +++++++++++++++++++++++++++---
vcl/source/gdi/alpha.cxx | 6 +++---
vcl/source/gdi/bitmap3.cxx | 13 ++++++++++++-
8 files changed, 57 insertions(+), 8 deletions(-)
New commits:
commit 2fcfbd73768b69ba58607a054e7f851be2942992
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Fri Apr 3 22:50:12 2020 +0200
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Tue Apr 7 11:53:54 2020 +0200
no gray conversion needed for VCL alpha hacks
AlphaMask doesn't need any conversion to gray, it's just enough
to make sure the alpha channel bitmap is 8bpp. And the conversion
is needed for the separate-OutputDevice-alpha hacks, where
GetBitmap() gives non-8bpp bitmap for the alpha contents, but there
all the R,G,B channels are the same, so just take red and avoid
pointless conversion.
Change-Id: Ib30fc8fa6d05067d582402ab2c0fcfb49a3742f2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91772
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index 77fef84ccaa3..1df24105e8bd 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -74,7 +74,8 @@ enum class BmpConversion
N24Bit,
N32Bit,
N8BitTrans,
- Ghosted
+ Ghosted,
+ N8BitNoConversion // make 8bit without color conversion (e.g. take the red channel)
};
enum class BmpCombine
diff --git a/vcl/inc/opengl/salbmp.hxx b/vcl/inc/opengl/salbmp.hxx
index c1ae867e6e6e..a01eca89f0fe 100644
--- a/vcl/inc/opengl/salbmp.hxx
+++ b/vcl/inc/opengl/salbmp.hxx
@@ -80,6 +80,7 @@ public:
bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) override;
bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol ) override;
bool ConvertToGreyscale() override;
+ bool InterpretAs8Bit() override;
public:
diff --git a/vcl/inc/salbmp.hxx b/vcl/inc/salbmp.hxx
index a526e2b6ee65..4244ae1a376f 100644
--- a/vcl/inc/salbmp.hxx
+++ b/vcl/inc/salbmp.hxx
@@ -81,6 +81,10 @@ public:
{
return false;
}
+ virtual bool InterpretAs8Bit()
+ {
+ return false;
+ }
void GetChecksum(BitmapChecksum& rChecksum) const
{
diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx
index a5f264ae2ba1..cfdb9d3d2347 100644
--- a/vcl/inc/skia/salbmp.hxx
+++ b/vcl/inc/skia/salbmp.hxx
@@ -57,6 +57,7 @@ public:
BmpScaleFlag nScaleFlag) override;
virtual bool Replace(const Color& rSearchColor, const Color& rReplaceColor,
sal_uInt8 nTol) override;
+ virtual bool InterpretAs8Bit() override;
virtual bool ConvertToGreyscale() override;
// Returns the contents as SkImage (possibly GPU-backed).
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 3b500b0945dc..4c8261858023 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -768,4 +768,11 @@ bool OpenGLSalBitmap::ConvertToGreyscale()
return true;
}
+// This is needed to just make the bitmap usable as an alpha channel.
+// Converting to 8bit grey will do.
+bool OpenGLSalBitmap::InterpretAs8Bit()
+{
+ return ConvertToGreyscale();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index dd723b9ee55e..89c43bb31e93 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -351,9 +351,6 @@ bool SkiaSalBitmap::ConvertToGreyscale()
#endif
// Normally this would need to convert contents of mBuffer for all possible formats,
// so just let the VCL algorithm do it.
- // The exception is when this bitmap contains only SkImage, which most probably
- // comes from SkiaSalGraphicsImpl::GetBitmap(). That is often used by the horrible
- // separate-alpha-outdev hack, and followed by a later call to GetAlphaSkBitmap().
// Avoid the costly SkImage->buffer->SkImage conversion.
if (!mBuffer && mImage)
{
@@ -381,6 +378,33 @@ bool SkiaSalBitmap::ConvertToGreyscale()
return false;
}
+bool SkiaSalBitmap::InterpretAs8Bit()
+{
+#ifdef DBG_UTIL
+ assert(mWriteAccessCount == 0);
+#endif
+ if (mBitCount == 8 && mPalette == Bitmap::GetGreyPalette(256))
+ return true;
+ // This is usually used by AlphaMask, the point is just to treat
+ // the content as an alpha channel. This is often used
+ // by the horrible separate-alpha-outdev hack, where the bitmap comes
+ // from SkiaSalGraphicsImpl::GetBitmap(), so only mImage is set,
+ // and that is followed by a later call to GetAlphaSkBitmap().
+ // Avoid the costly SkImage->buffer->SkImage conversion and simply
+ // just treat the SkImage as being for 8bit bitmap. EnsureBitmapData()
+ // will do the conversion if needed, but the normal case will be
+ // GetAlphaSkImage() creating kAlpha_8_SkColorType SkImage from it.
+ if (!mBuffer && mImage)
+ {
+ mBitCount = 8;
+ mPalette = Bitmap::GetGreyPalette(256);
+ ResetToSkImage(mImage); // keep mImage, it will be interpreted as 8bit if needed
+ SAL_INFO("vcl.skia.trace", "interpretas8bit(" << this << ")");
+ return true;
+ }
+ return false;
+}
+
SkBitmap SkiaSalBitmap::GetAsSkBitmap() const
{
#ifdef DBG_UTIL
diff --git a/vcl/source/gdi/alpha.cxx b/vcl/source/gdi/alpha.cxx
index 16e9c9965556..fde0e94583a9 100644
--- a/vcl/source/gdi/alpha.cxx
+++ b/vcl/source/gdi/alpha.cxx
@@ -29,7 +29,7 @@ AlphaMask::AlphaMask( const Bitmap& rBitmap ) :
Bitmap( rBitmap )
{
if( !!rBitmap )
- Convert( BmpConversion::N8BitGreys );
+ Convert( BmpConversion::N8BitNoConversion );
}
AlphaMask::AlphaMask( const AlphaMask& ) = default;
@@ -50,7 +50,7 @@ AlphaMask& AlphaMask::operator=( const Bitmap& rBitmap )
*static_cast<Bitmap*>(this) = rBitmap;
if( !!rBitmap )
- Convert( BmpConversion::N8BitGreys );
+ Convert( BmpConversion::N8BitNoConversion );
return *this;
}
@@ -143,7 +143,7 @@ void AlphaMask::ReleaseAccess( BitmapReadAccess* pAccess )
if( pAccess )
{
Bitmap::ReleaseAccess( pAccess );
- Convert( BmpConversion::N8BitGreys );
+ Convert( BmpConversion::N8BitNoConversion );
}
}
diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx
index 508d1af46f57..c400008e60b4 100644
--- a/vcl/source/gdi/bitmap3.cxx
+++ b/vcl/source/gdi/bitmap3.cxx
@@ -230,10 +230,20 @@ bool Bitmap::Convert( BmpConversion eConversion )
if (mxSalBmp)
{
// avoid large chunk of obsolete and hopefully rarely used conversions.
- if (eConversion == BmpConversion::N8BitGreys)
+ if (eConversion == BmpConversion::N8BitNoConversion)
{
std::shared_ptr<SalBitmap> xImpBmp(ImplGetSVData()->mpDefInst->CreateSalBitmap());
// frequently used conversion for creating alpha masks
+ if (xImpBmp->Create(*mxSalBmp) && xImpBmp->InterpretAs8Bit())
+ {
+ ImplSetSalBitmap(xImpBmp);
+ SAL_INFO( "vcl.opengl", "Ref count: " << mxSalBmp.use_count() );
+ return true;
+ }
+ }
+ if (eConversion == BmpConversion::N8BitGreys)
+ {
+ std::shared_ptr<SalBitmap> xImpBmp(ImplGetSVData()->mpDefInst->CreateSalBitmap());
if (xImpBmp->Create(*mxSalBmp) && xImpBmp->ConvertToGreyscale())
{
ImplSetSalBitmap(xImpBmp);
@@ -280,6 +290,7 @@ bool Bitmap::Convert( BmpConversion eConversion )
break;
case BmpConversion::N8BitGreys:
+ case BmpConversion::N8BitNoConversion:
bRet = ImplMakeGreyscales( 256 );
break;
More information about the Libreoffice-commits
mailing list