[Libreoffice-commits] core.git: vcl/skia
LuboÅ¡ LuÅák (via logerrit)
logerrit at kemper.freedesktop.org
Wed Mar 10 18:46:31 UTC 2021
vcl/skia/salbmp.cxx | 70 ++++++++++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 29 deletions(-)
New commits:
commit bf2ba0f39be62978b512d6ed101219b9dd0dc6e4
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Tue Mar 9 22:08:04 2021 +0100
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Wed Mar 10 19:45:43 2021 +0100
access pixels directly if SkImage is a raster one (tdf#140925)
This avoids copying the data to a temporary storage that's not needed.
Moreover Skia does not memcpy() the data if the format is
kAlpha_8_SkColorType.
Change-Id: I66974acd7656df8b82d1babacf7a0cb60711fc76
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112253
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index b94debcb7d3a..e8266f86990e 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -1054,13 +1054,19 @@ void SkiaSalBitmap::EnsureBitmapData()
assert(mAlphaImage->colorType() == kAlpha_8_SkColorType);
SkiaZone zone;
SkBitmap bitmap;
- if (!bitmap.tryAllocPixels(SkImageInfo::MakeA8(mSize.Width(), mSize.Height())))
- abort();
- SkCanvas canvas(bitmap);
- SkPaint paint;
- paint.setBlendMode(SkBlendMode::kSrc); // set as is, including alpha
- canvas.drawImage(mAlphaImage, 0, 0, SkSamplingOptions(), &paint);
- canvas.flush();
+ SkPixmap pixmap;
+ if (mAlphaImage->peekPixels(&pixmap))
+ bitmap.installPixels(pixmap);
+ else
+ {
+ if (!bitmap.tryAllocPixels(SkImageInfo::MakeA8(mSize.Width(), mSize.Height())))
+ abort();
+ SkCanvas canvas(bitmap);
+ SkPaint paint;
+ paint.setBlendMode(SkBlendMode::kSrc); // set as is, including alpha
+ canvas.drawImage(mAlphaImage, 0, 0, SkSamplingOptions(), &paint);
+ canvas.flush();
+ }
bitmap.setImmutable();
CreateBitmapData();
assert(mBuffer != nullptr);
@@ -1111,30 +1117,36 @@ void SkiaSalBitmap::EnsureBitmapData()
alphaType = kPremul_SkAlphaType;
#endif
SkBitmap bitmap;
- if (!bitmap.tryAllocPixels(SkImageInfo::MakeS32(mSize.Width(), mSize.Height(), alphaType)))
- abort();
- SkCanvas canvas(bitmap);
- SkPaint paint;
- paint.setBlendMode(SkBlendMode::kSrc); // set as is, including alpha
- if (mSize != mPixelsSize) // pending scaling?
+ SkPixmap pixmap;
+ if (mSize == mPixelsSize && mImage->peekPixels(&pixmap))
+ bitmap.installPixels(pixmap);
+ else
{
- assert(mImage->width() == mPixelsSize.getWidth()
- && mImage->height() == mPixelsSize.getHeight());
- canvas.drawImageRect(mImage, SkRect::MakeWH(mSize.getWidth(), mSize.getHeight()),
- makeSamplingOptions(mScaleQuality), &paint);
- SAL_INFO("vcl.skia.trace", "ensurebitmapdata(" << this << "): image scaled " << mPixelsSize
- << "->" << mSize << ":"
- << static_cast<int>(mScaleQuality));
- mPixelsSize = mSize;
- ComputeScanlineSize();
- mScaleQuality = BmpScaleFlag::BestQuality;
- // Information about the pending scaling has been discarded, so make sure we do not
- // keep around any cached images that would still need scaling.
- ResetCachedDataBySize();
+ if (!bitmap.tryAllocPixels(SkImageInfo::MakeS32(mSize.Width(), mSize.Height(), alphaType)))
+ abort();
+ SkCanvas canvas(bitmap);
+ SkPaint paint;
+ paint.setBlendMode(SkBlendMode::kSrc); // set as is, including alpha
+ if (mSize != mPixelsSize) // pending scaling?
+ {
+ assert(mImage->width() == mPixelsSize.getWidth()
+ && mImage->height() == mPixelsSize.getHeight());
+ canvas.drawImageRect(mImage, SkRect::MakeWH(mSize.getWidth(), mSize.getHeight()),
+ makeSamplingOptions(mScaleQuality), &paint);
+ SAL_INFO("vcl.skia.trace", "ensurebitmapdata(" << this << "): image scaled "
+ << mPixelsSize << "->" << mSize << ":"
+ << static_cast<int>(mScaleQuality));
+ mPixelsSize = mSize;
+ ComputeScanlineSize();
+ mScaleQuality = BmpScaleFlag::BestQuality;
+ // Information about the pending scaling has been discarded, so make sure we do not
+ // keep around any cached images that would still need scaling.
+ ResetCachedDataBySize();
+ }
+ else
+ canvas.drawImage(mImage, 0, 0, SkSamplingOptions(), &paint);
+ canvas.flush();
}
- else
- canvas.drawImage(mImage, 0, 0, SkSamplingOptions(), &paint);
- canvas.flush();
bitmap.setImmutable();
CreateBitmapData();
assert(mBuffer != nullptr);
More information about the Libreoffice-commits
mailing list