From c7e8ee4e622ad90c6860994a0bb8eaa9c8c80566 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 9 Apr 2020 11:26:43 +0200 Subject: Fix image scaling on WASM platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apparently it has trouble with multi-threading from the main thread. Change-Id: Ib544d69270c2780d4a42bde6fd7f491e32f29cd2 Reviewed-by: Morten Johan Sørvig --- src/gui/painting/qimagescale_neon.cpp | 86 ++++++++++++----------------------- 1 file changed, 28 insertions(+), 58 deletions(-) (limited to 'src/gui/painting/qimagescale_neon.cpp') diff --git a/src/gui/painting/qimagescale_neon.cpp b/src/gui/painting/qimagescale_neon.cpp index 416155e139..65fe3fac3c 100644 --- a/src/gui/painting/qimagescale_neon.cpp +++ b/src/gui/painting/qimagescale_neon.cpp @@ -41,7 +41,7 @@ #include "qimage.h" #include -#if QT_CONFIG(thread) +#if QT_CONFIG(thread) && !defined(Q_OS_WASM) #include "qsemaphore.h" #include "qthreadpool.h" #endif @@ -52,6 +52,30 @@ QT_BEGIN_NAMESPACE using namespace QImageScale; +template +static inline void multithread_pixels_function(QImageScaleInfo *isi, int dh, const T &scaleSection) +{ +#if QT_CONFIG(thread) && !defined(Q_OS_WASM) + int segments = (qsizetype(isi->sh) * isi->sw) / (1<<16); + segments = std::min(segments, dh); + if (segments > 1) { + QSemaphore semaphore; + int y = 0; + for (int i = 0; i < segments; ++i) { + int yn = (dh - y) / (segments - i); + QThreadPool::globalInstance()->start([&, y, yn]() { + scaleSection(y, y + yn); + semaphore.release(1); + }); + y += yn; + } + semaphore.acquire(segments); + return; + } +#endif + scaleSection(0, dh); +} + inline static uint32x4_t qt_qimageScaleAARGBA_helper(const unsigned int *pix, int xyap, int Cxy, int step) { uint32x2_t vpix32 = vmov_n_u32(*pix); @@ -110,25 +134,7 @@ void qt_qimageScaleAARGBA_up_x_down_y_neon(QImageScaleInfo *isi, unsigned int *d } } }; -#if QT_CONFIG(thread) - int segments = (qsizetype(isi->sh) * isi->sw) / (1<<16); - segments = std::min(segments, dh); - if (segments > 1) { - QSemaphore semaphore; - int y = 0; - for (int i = 0; i < segments; ++i) { - int yn = (dh - y) / (segments - i); - QThreadPool::globalInstance()->start([&, y, yn]() { - scaleSection(y, y + yn); - semaphore.release(1); - }); - y += yn; - } - semaphore.acquire(segments); - return; - } -#endif - scaleSection(0, dh); + multithread_pixels_function(isi, dh, scaleSection); } template @@ -170,25 +176,7 @@ void qt_qimageScaleAARGBA_down_x_up_y_neon(QImageScaleInfo *isi, unsigned int *d } } }; -#if QT_CONFIG(thread) - int segments = (qsizetype(isi->sh) * isi->sw) / (1<<16); - segments = std::min(segments, dh); - if (segments > 1) { - QSemaphore semaphore; - int y = 0; - for (int i = 0; i < segments; ++i) { - int yn = (dh - y) / (segments - i); - QThreadPool::globalInstance()->start([&, y, yn]() { - scaleSection(y, y + yn); - semaphore.release(1); - }); - y += yn; - } - semaphore.acquire(segments); - return; - } -#endif - scaleSection(0, dh); + multithread_pixels_function(isi, dh, scaleSection); } template @@ -239,25 +227,7 @@ void qt_qimageScaleAARGBA_down_xy_neon(QImageScaleInfo *isi, unsigned int *dest, } } }; -#if QT_CONFIG(thread) - int segments = (qsizetype(isi->sh) * isi->sw) / (1<<16); - segments = std::min(segments, dh); - if (segments > 1) { - QSemaphore semaphore; - int y = 0; - for (int i = 0; i < segments; ++i) { - int yn = (dh - y) / (segments - i); - QThreadPool::globalInstance()->start([&, y, yn]() { - scaleSection(y, y + yn); - semaphore.release(1); - }); - y += yn; - } - semaphore.acquire(segments); - return; - } -#endif - scaleSection(0, dh); + multithread_pixels_function(isi, dh, scaleSection); } template void qt_qimageScaleAARGBA_up_x_down_y_neon(QImageScaleInfo *isi, unsigned int *dest, -- cgit v1.2.3