[Libreoffice-commits] core.git: vcl/inc vcl/skia
LuboÅ¡ LuÅák (via logerrit)
logerrit at kemper.freedesktop.org
Wed Oct 7 14:19:02 UTC 2020
vcl/inc/skia/salbmp.hxx | 2 ++
vcl/inc/skia/utils.hxx | 18 +++++++++++++++---
vcl/skia/SkiaHelper.cxx | 10 +++++-----
vcl/skia/gdiimpl.cxx | 3 ++-
vcl/skia/salbmp.cxx | 31 ++++++++++++++++++++-----------
5 files changed, 44 insertions(+), 20 deletions(-)
New commits:
commit 3f359a03308493e59e0c29572fff7b0194c4aea1
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Tue Oct 6 22:56:40 2020 +0200
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Wed Oct 7 16:18:16 2020 +0200
try more to match Skia's alpha type for source and destination
This is an extension of the other recent commit, matching alpha type
is faster, and knowing the content is opaque should also allow
more optimizations.
Change-Id: I632d3f50e3f4729a64403c3c3ed1b79d63f0c5dd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104046
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx
index 0cd48c8c46c2..49aabcf69a7f 100644
--- a/vcl/inc/skia/salbmp.hxx
+++ b/vcl/inc/skia/salbmp.hxx
@@ -82,6 +82,8 @@ public:
// Returns true if it is known that this bitmap can be ignored if it's to be used
// as an alpha bitmap. An optimization, not guaranteed to return true for all such cases.
bool IsFullyOpaqueAsAlpha() const;
+ // Alpha type best suitable for the content.
+ SkAlphaType alphaType() const;
#ifdef DBG_UTIL
void dump(const char* file) const;
diff --git a/vcl/inc/skia/utils.hxx b/vcl/inc/skia/utils.hxx
index b3a2045eea96..00feccedfdae 100644
--- a/vcl/inc/skia/utils.hxx
+++ b/vcl/inc/skia/utils.hxx
@@ -37,11 +37,23 @@ void disableRenderMethod(RenderMethod method);
// Create SkSurface, GPU-backed if possible.
VCL_DLLPUBLIC sk_sp<SkSurface> createSkSurface(int width, int height,
- SkColorType type = kN32_SkColorType);
+ SkColorType type = kN32_SkColorType,
+ SkAlphaType alpha = kPremul_SkAlphaType);
-inline sk_sp<SkSurface> createSkSurface(const Size& size, SkColorType type = kN32_SkColorType)
+inline sk_sp<SkSurface> createSkSurface(const Size& size, SkColorType type = kN32_SkColorType,
+ SkAlphaType alpha = kPremul_SkAlphaType)
{
- return createSkSurface(size.Width(), size.Height(), type);
+ return createSkSurface(size.Width(), size.Height(), type, alpha);
+}
+
+inline sk_sp<SkSurface> createSkSurface(int width, int height, SkAlphaType alpha)
+{
+ return createSkSurface(width, height, kN32_SkColorType, alpha);
+}
+
+inline sk_sp<SkSurface> createSkSurface(const Size& size, SkAlphaType alpha)
+{
+ return createSkSurface(size.Width(), size.Height(), kN32_SkColorType, alpha);
}
// Create SkImage, GPU-backed if possible.
diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx
index 2d185bab149b..3adef6a9afd2 100644
--- a/vcl/skia/SkiaHelper.cxx
+++ b/vcl/skia/SkiaHelper.cxx
@@ -381,7 +381,7 @@ static sk_app::VulkanWindowContext::SharedGrDirectContext getTemporaryGrDirectCo
return sk_app::VulkanWindowContext::getSharedGrDirectContext();
}
-sk_sp<SkSurface> createSkSurface(int width, int height, SkColorType type)
+sk_sp<SkSurface> createSkSurface(int width, int height, SkColorType type, SkAlphaType alpha)
{
SkiaZone zone;
assert(type == kN32_SkColorType || type == kAlpha_8_SkColorType);
@@ -392,9 +392,9 @@ sk_sp<SkSurface> createSkSurface(int width, int height, SkColorType type)
{
if (GrDirectContext* grDirectContext = getSharedGrDirectContext())
{
- surface = SkSurface::MakeRenderTarget(
- grDirectContext, SkBudgeted::kNo,
- SkImageInfo::Make(width, height, type, kPremul_SkAlphaType));
+ surface
+ = SkSurface::MakeRenderTarget(grDirectContext, SkBudgeted::kNo,
+ SkImageInfo::Make(width, height, type, alpha));
if (surface)
{
#ifdef DBG_UTIL
@@ -411,7 +411,7 @@ sk_sp<SkSurface> createSkSurface(int width, int height, SkColorType type)
break;
}
// Create raster surface as a fallback.
- surface = SkSurface::MakeRaster(SkImageInfo::Make(width, height, type, kPremul_SkAlphaType));
+ surface = SkSurface::MakeRaster(SkImageInfo::Make(width, height, type, alpha));
assert(surface);
if (surface)
{
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index f0076d9a90f9..fa29ab32d0ac 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -1540,7 +1540,8 @@ sk_sp<SkImage> SkiaSalGraphicsImpl::mergeCacheBitmaps(const SkiaSalBitmap& bitma
assert(image->width() == targetSize.Width() && image->height() == targetSize.Height());
return image;
}
- sk_sp<SkSurface> tmpSurface = SkiaHelper::createSkSurface(targetSize);
+ sk_sp<SkSurface> tmpSurface = SkiaHelper::createSkSurface(
+ targetSize, alphaBitmap ? kPremul_SkAlphaType : bitmap.alphaType());
if (!tmpSurface)
return nullptr;
SkCanvas* canvas = tmpSurface->getCanvas();
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index bbf1e6f0670e..531c9661be64 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -391,7 +391,8 @@ bool SkiaSalBitmap::ConvertToGreyscale()
{
if (mBitCount == 8 && mPalette.IsGreyPalette8Bit())
return true;
- sk_sp<SkSurface> surface = SkiaHelper::createSkSurface(mPixelsSize);
+ sk_sp<SkSurface> surface
+ = SkiaHelper::createSkSurface(mPixelsSize, mImage->imageInfo().alphaType());
SkPaint paint;
paint.setBlendMode(SkBlendMode::kSrc); // set as is, including alpha
// VCL uses different coefficients for conversion to gray than Skia, so use the VCL
@@ -533,15 +534,8 @@ SkBitmap SkiaSalBitmap::GetAsSkBitmap() const
const size_t bytes = mPixelsSize.Height() * mScanlineSize;
std::unique_ptr<sal_uInt8[]> data(new sal_uInt8[bytes]);
memcpy(data.get(), mBuffer.get(), bytes);
- // The bitmap's alpha matters only if SKIA_USE_BITMAP32 is set, otherwise
- // the alpha is in a separate bitmap.
-#if SKIA_USE_BITMAP32
- SkAlphaType alphaType = kPremul_SkAlphaType;
-#else
- SkAlphaType alphaType = kOpaque_SkAlphaType;
-#endif
if (!bitmap.installPixels(
- SkImageInfo::MakeS32(mPixelsSize.Width(), mPixelsSize.Height(), alphaType),
+ SkImageInfo::MakeS32(mPixelsSize.Width(), mPixelsSize.Height(), alphaType()),
data.release(), mScanlineSize,
[](void* addr, void*) { delete[] static_cast<sal_uInt8*>(addr); }, nullptr))
abort();
@@ -668,7 +662,8 @@ const sk_sp<SkImage>& SkiaSalBitmap::GetSkImage() const
if (mEraseColorSet)
{
SkiaZone zone;
- sk_sp<SkSurface> surface = SkiaHelper::createSkSurface(mSize);
+ sk_sp<SkSurface> surface = SkiaHelper::createSkSurface(
+ mSize, mEraseColor.GetTransparency() != 0 ? kPremul_SkAlphaType : kOpaque_SkAlphaType);
assert(surface);
surface->getCanvas()->clear(toSkColor(mEraseColor));
SkiaSalBitmap* thisPtr = const_cast<SkiaSalBitmap*>(this);
@@ -699,7 +694,8 @@ const sk_sp<SkImage>& SkiaSalBitmap::GetSkImage() const
{
assert(!mBuffer); // This code should be only called if only mImage holds data.
SkiaZone zone;
- sk_sp<SkSurface> surface = SkiaHelper::createSkSurface(mSize);
+ sk_sp<SkSurface> surface
+ = SkiaHelper::createSkSurface(mSize, mImage->imageInfo().alphaType());
assert(surface);
SkPaint paint;
paint.setBlendMode(SkBlendMode::kSrc); // set as is, including alpha
@@ -872,6 +868,19 @@ bool SkiaSalBitmap::IsFullyOpaqueAsAlpha() const
return SkColorGetA(fromEraseColorToAlphaImageColor(mEraseColor)) == 0;
}
+SkAlphaType SkiaSalBitmap::alphaType() const
+{
+ if (mEraseColorSet)
+ return mEraseColor.GetTransparency() != 0 ? kPremul_SkAlphaType : kOpaque_SkAlphaType;
+#if SKIA_USE_BITMAP32
+ // The bitmap's alpha matters only if SKIA_USE_BITMAP32 is set, otherwise
+ // the alpha is in a separate bitmap.
+ if (mBitCount == 32)
+ return kPremul_SkAlphaType;
+#endif
+ return kOpaque_SkAlphaType;
+}
+
void SkiaSalBitmap::PerformErase()
{
if (mPixelsSize.IsEmpty())
More information about the Libreoffice-commits
mailing list