[Libreoffice-commits] core.git: vcl/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Mon May 4 17:04:53 UTC 2020
vcl/source/bitmap/BitmapFilterStackBlur.cxx | 61 ++++++++--------------------
1 file changed, 19 insertions(+), 42 deletions(-)
New commits:
commit 72795f68df49cfb58aee70daa848a1889a117c28
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Mon May 4 16:20:21 2020 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Mon May 4 19:04:20 2020 +0200
StackBlur filter: Don't create threads for small bitmap
This makes the last (or the only) strip to run im main thread, thus
removing threading overhead for small (width/height <= 16) objects.
Change-Id: I6da050a62b00a013838f16eb94a32e2639d93aec
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93423
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/vcl/source/bitmap/BitmapFilterStackBlur.cxx b/vcl/source/bitmap/BitmapFilterStackBlur.cxx
index fde6ab089a3b..9b3c37127fcf 100644
--- a/vcl/source/bitmap/BitmapFilterStackBlur.cxx
+++ b/vcl/source/bitmap/BitmapFilterStackBlur.cxx
@@ -48,9 +48,8 @@ static const sal_Int16 constShiftTable[255]
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24 };
-class BlurSharedData
+struct BlurSharedData
{
-public:
BitmapReadAccess* mpReadAccess;
BitmapWriteAccess* mpWriteAccess;
long mnRadius;
@@ -70,9 +69,8 @@ public:
}
};
-class BlurArrays
+struct BlurArrays
{
-public:
BlurSharedData maShared;
std::vector<sal_uInt8> maStackBuffer;
@@ -110,8 +108,6 @@ public:
typedef void (*BlurRangeFn)(BlurSharedData const& rShared, long nStartY, long nEndY);
-constexpr long constBlurThreadStrip = 16;
-
class BlurTask : public comphelper::ThreadTask
{
BlurRangeFn mpBlurFunction;
@@ -454,6 +450,8 @@ void stackBlurVertical(BlurSharedData const& rShared, long nStart, long nEnd)
}
}
+constexpr long nThreadStrip = 16;
+
void runStackBlur(Bitmap& rBitmap, const long nRadius, const long nComponentWidth,
const long nColorChannels, BlurRangeFn pBlurHorizontalFn,
BlurRangeFn pBlurVerticalFn, const bool bParallel)
@@ -463,65 +461,44 @@ void runStackBlur(Bitmap& rBitmap, const long nRadius, const long nComponentWidt
try
{
comphelper::ThreadPool& rShared = comphelper::ThreadPool::getSharedOptimalPool();
- std::shared_ptr<comphelper::ThreadTaskTag> pTag
- = comphelper::ThreadPool::createThreadTaskTag();
+ auto pTag = comphelper::ThreadPool::createThreadTaskTag();
{
Bitmap::ScopedReadAccess pReadAccess(rBitmap);
BitmapScopedWriteAccess pWriteAccess(rBitmap);
-
BlurSharedData aSharedData(pReadAccess.get(), pWriteAccess.get(), nRadius,
nComponentWidth, nColorChannels);
- const Size aSize = rBitmap.GetSizePixel();
- long nEnd = aSize.Height() - 1;
-
+ const long nLastIndex = pReadAccess->Height() - 1;
long nStripStart = 0;
- long nStripEnd = nStripStart + constBlurThreadStrip - 1;
-
- while (nStripEnd < nEnd)
- {
- std::unique_ptr<BlurTask> pTask(
- new BlurTask(pTag, pBlurHorizontalFn, aSharedData, nStripStart, nStripEnd));
- rShared.pushTask(std::move(pTask));
- nStripStart += constBlurThreadStrip;
- nStripEnd += constBlurThreadStrip;
- }
- if (nStripStart <= nEnd)
+ for (; nStripStart < nLastIndex - nThreadStrip; nStripStart += nThreadStrip)
{
- std::unique_ptr<BlurTask> pTask(
- new BlurTask(pTag, pBlurHorizontalFn, aSharedData, nStripStart, nEnd));
+ long nStripEnd = nStripStart + nThreadStrip - 1;
+ auto pTask(std::make_unique<BlurTask>(pTag, pBlurHorizontalFn, aSharedData,
+ nStripStart, nStripEnd));
rShared.pushTask(std::move(pTask));
}
+ // Do the last (or the only) strip in main thread without threading overhead
+ pBlurHorizontalFn(aSharedData, nStripStart, nLastIndex);
rShared.waitUntilDone(pTag);
}
{
Bitmap::ScopedReadAccess pReadAccess(rBitmap);
BitmapScopedWriteAccess pWriteAccess(rBitmap);
-
BlurSharedData aSharedData(pReadAccess.get(), pWriteAccess.get(), nRadius,
nComponentWidth, nColorChannels);
- const Size aSize = rBitmap.GetSizePixel();
- long nEnd = aSize.Width() - 1;
-
+ const long nLastIndex = pReadAccess->Width() - 1;
long nStripStart = 0;
- long nStripEnd = nStripStart + constBlurThreadStrip - 1;
-
- while (nStripEnd < nEnd)
- {
- std::unique_ptr<BlurTask> pTask(
- new BlurTask(pTag, pBlurVerticalFn, aSharedData, nStripStart, nStripEnd));
- rShared.pushTask(std::move(pTask));
- nStripStart += constBlurThreadStrip;
- nStripEnd += constBlurThreadStrip;
- }
- if (nStripStart <= nEnd)
+ for (; nStripStart < nLastIndex - nThreadStrip; nStripStart += nThreadStrip)
{
- std::unique_ptr<BlurTask> pTask(
- new BlurTask(pTag, pBlurVerticalFn, aSharedData, nStripStart, nEnd));
+ long nStripEnd = nStripStart + nThreadStrip - 1;
+ auto pTask(std::make_unique<BlurTask>(pTag, pBlurVerticalFn, aSharedData,
+ nStripStart, nStripEnd));
rShared.pushTask(std::move(pTask));
}
+ // Do the last (or the only) strip in main thread without threading overhead
+ pBlurVerticalFn(aSharedData, nStripStart, nLastIndex);
rShared.waitUntilDone(pTag);
}
}
More information about the Libreoffice-commits
mailing list