[Libreoffice-commits] core.git: vcl/inc vcl/skia
LuboÅ¡ LuÅák (via logerrit)
logerrit at kemper.freedesktop.org
Tue Apr 7 09:53:36 UTC 2020
vcl/inc/skia/utils.hxx | 3 +++
vcl/skia/SkiaHelper.cxx | 29 +++++++++++++++++++++++++++++
vcl/skia/gdiimpl.cxx | 2 +-
vcl/skia/salbmp.cxx | 22 ++++++----------------
4 files changed, 39 insertions(+), 17 deletions(-)
New commits:
commit fafc059a17416502722622ff52f38a3e4acd7998
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Fri Apr 3 10:50:58 2020 +0200
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Tue Apr 7 11:52:58 2020 +0200
avoid Skia bitmap->image pixel copying in raster mode
SkImage::MakeFromBitmap() shares the pixels instead of copying,
so in raster mode this saves some work.
Change-Id: I89aa86c269c4b4f24e305dec390ae0f80e2537da
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91769
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/vcl/inc/skia/utils.hxx b/vcl/inc/skia/utils.hxx
index c1f35e812d00..16e5addd6909 100644
--- a/vcl/inc/skia/utils.hxx
+++ b/vcl/inc/skia/utils.hxx
@@ -43,6 +43,9 @@ inline sk_sp<SkSurface> createSkSurface(const Size& size, SkColorType type = kN3
return createSkSurface(size.Width(), size.Height(), type);
}
+// Create SkImage, GPU-backed if possible.
+VCL_DLLPUBLIC sk_sp<SkImage> createSkImage(const SkBitmap& bitmap);
+
// Must be called in any VCL backend before any Skia functionality is used.
// If not set, Skia will be disabled.
VCL_DLLPUBLIC void
diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx
index ed85cec00049..356570706f59 100644
--- a/vcl/skia/SkiaHelper.cxx
+++ b/vcl/skia/SkiaHelper.cxx
@@ -333,6 +333,35 @@ sk_sp<SkSurface> createSkSurface(int width, int height, SkColorType type)
return surface;
}
+sk_sp<SkImage> createSkImage(const SkBitmap& bitmap)
+{
+ SkiaZone zone;
+ assert(bitmap.colorType() == kN32_SkColorType || bitmap.colorType() == kAlpha_8_SkColorType);
+ switch (SkiaHelper::renderMethodToUse())
+ {
+ case SkiaHelper::RenderVulkan:
+ {
+ if (GrContext* grContext = getSharedGrContext())
+ {
+ sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(
+ grContext, SkBudgeted::kNo, bitmap.info().makeAlphaType(kPremul_SkAlphaType));
+ assert(surface);
+ SkPaint paint;
+ paint.setBlendMode(SkBlendMode::kSrc); // set as is, including alpha
+ surface->getCanvas()->drawBitmap(bitmap, 0, 0, &paint);
+ return surface->makeImageSnapshot();
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ // Create raster image as a fallback.
+ sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
+ assert(image);
+ return image;
+}
+
void cleanup()
{
delete sharedGrContext;
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index e68d620ac894..e4f064589b21 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -944,7 +944,7 @@ bool SkiaSalGraphicsImpl::blendAlphaBitmap(const SalTwoRect& rPosAry,
// This was originally implemented for the OpenGL drawing method and it is poorly documented.
// The source and mask bitmaps are the usual data and alpha bitmaps, and 'alpha'
// is the "alpha" layer of the VirtualDevice (the alpha in VirtualDevice is also stored
- // as a separate bitmap). Now I understand it correctly these two alpha masks first need
+ // as a separate bitmap). Now if I understand it correctly these two alpha masks first need
// to be combined into the actual alpha mask to be used. The formula for TYPE_BLEND
// in opengl's combinedTextureFragmentShader.glsl is
// "result_alpha = 1.0 - (1.0 - floor(alpha)) * mask".
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index c000b391eaa2..7c3d183a54d9 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -460,12 +460,9 @@ const sk_sp<SkImage>& SkiaSalBitmap::GetSkImage() const
return mImage;
}
SkiaZone zone;
- sk_sp<SkSurface> surface = SkiaHelper::createSkSurface(mSize);
- assert(surface);
- SkPaint paint;
- paint.setBlendMode(SkBlendMode::kSrc); // set as is, including alpha
- surface->getCanvas()->drawBitmap(GetAsSkBitmap(), 0, 0, &paint);
- const_cast<sk_sp<SkImage>&>(mImage) = surface->makeImageSnapshot();
+ sk_sp<SkImage> image = SkiaHelper::createSkImage(GetAsSkBitmap());
+ assert(image);
+ const_cast<sk_sp<SkImage>&>(mImage) = image;
SAL_INFO("vcl.skia.trace", "getskimage(" << this << ")");
return mImage;
}
@@ -528,16 +525,9 @@ const sk_sp<SkImage>& SkiaSalBitmap::GetAlphaSkImage() const
delete convertedBitmap;
alphaBitmap.setImmutable();
}
- sk_sp<SkSurface> surface = SkiaHelper::createSkSurface(mSize, kAlpha_8_SkColorType);
- assert(surface);
- // https://bugs.chromium.org/p/skia/issues/detail?id=9692
- // Raster kAlpha_8_SkColorType surfaces need empty contents for SkBlendMode::kSrc.
- if (!surface->getCanvas()->getGrContext())
- surface->getCanvas()->clear(SkColorSetARGB(0x00, 0x00, 0x00, 0x00));
- SkPaint paint;
- paint.setBlendMode(SkBlendMode::kSrc); // set as is, including alpha
- surface->getCanvas()->drawBitmap(alphaBitmap, 0, 0, &paint);
- const_cast<sk_sp<SkImage>&>(mAlphaImage) = surface->makeImageSnapshot();
+ sk_sp<SkImage> image = SkiaHelper::createSkImage(alphaBitmap);
+ assert(image);
+ const_cast<sk_sp<SkImage>&>(mAlphaImage) = image;
SAL_INFO("vcl.skia.trace", "getalphaskbitmap(" << this << ")");
return mAlphaImage;
}
More information about the Libreoffice-commits
mailing list