[Libreoffice-commits] core.git: vcl/source

Caolán McNamara caolanm at redhat.com
Mon Feb 27 09:06:08 UTC 2017


 vcl/source/bitmap/bitmapscalesuper.cxx |   59 ++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 23 deletions(-)

New commits:
commit 29108b656576d66e336b4bbe623556b4a82fef81
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Sun Feb 26 21:10:38 2017 +0000

    fall back to unthreaded scaling if threaded scaling fails
    
    Change-Id: I916bdca4976bcc39d4342dacc9d0aea9a711e1f1
    Reviewed-on: https://gerrit.libreoffice.org/34660
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/source/bitmap/bitmapscalesuper.cxx b/vcl/source/bitmap/bitmapscalesuper.cxx
index ae540e5..15aa67e 100644
--- a/vcl/source/bitmap/bitmapscalesuper.cxx
+++ b/vcl/source/bitmap/bitmapscalesuper.cxx
@@ -989,43 +989,56 @@ bool BitmapScaleSuper::filter(Bitmap& rBitmap)
         // We work hard when there is a large destination image, or
         // A large source image.
         bool bHorizontalWork = pReadAccess->Width() > 512 || pWriteAccess->Width() > 512;
+        bool bUseThreads = true;
 
         static bool bDisableThreadedScaling = getenv ("VCL_NO_THREAD_SCALE");
         if ( bDisableThreadedScaling || !bHorizontalWork ||
              nEndY - nStartY < SCALE_THREAD_STRIP )
         {
             SAL_INFO("vcl.gdi", "Scale in main thread");
-            pScaleRangeFn( aContext, nStartY, nEndY );
+            bUseThreads = false;
         }
-        else
+
+        if (bUseThreads)
         {
-            // partition and queue work
-            comphelper::ThreadPool &rShared = comphelper::ThreadPool::getSharedOptimalPool();
-            std::shared_ptr<comphelper::ThreadTaskTag> pTag = comphelper::ThreadPool::createThreadTaskTag();
-            sal_uInt32 nThreads = rShared.getWorkerCount();
-            assert( nThreads > 0 );
-            sal_uInt32 nStrips = ((nEndY - nStartY) + SCALE_THREAD_STRIP - 1) / SCALE_THREAD_STRIP;
-            sal_uInt32 nStripsPerThread = nStrips / nThreads;
-            SAL_INFO("vcl.gdi", "Scale in " << nStrips << " strips " << nStripsPerThread << " per thread we have " << nThreads << " CPU threads ");
-            long nStripY = nStartY;
-            for ( sal_uInt32 t = 0; t < nThreads - 1; t++ )
+            try
             {
-                ScaleTask *pTask = new ScaleTask( pTag, pScaleRangeFn );
-                for ( sal_uInt32 j = 0; j < nStripsPerThread; j++ )
+                // partition and queue work
+                comphelper::ThreadPool &rShared = comphelper::ThreadPool::getSharedOptimalPool();
+                std::shared_ptr<comphelper::ThreadTaskTag> pTag = comphelper::ThreadPool::createThreadTaskTag();
+                sal_uInt32 nThreads = rShared.getWorkerCount();
+                assert( nThreads > 0 );
+                sal_uInt32 nStrips = ((nEndY - nStartY) + SCALE_THREAD_STRIP - 1) / SCALE_THREAD_STRIP;
+                sal_uInt32 nStripsPerThread = nStrips / nThreads;
+                SAL_INFO("vcl.gdi", "Scale in " << nStrips << " strips " << nStripsPerThread << " per thread we have " << nThreads << " CPU threads ");
+                long nStripY = nStartY;
+                for ( sal_uInt32 t = 0; t < nThreads - 1; t++ )
                 {
-                    ScaleRangeContext aRC( &aContext, nStripY );
-                    pTask->push( aRC );
-                    nStripY += SCALE_THREAD_STRIP;
+                    ScaleTask *pTask = new ScaleTask( pTag, pScaleRangeFn );
+                    for ( sal_uInt32 j = 0; j < nStripsPerThread; j++ )
+                    {
+                        ScaleRangeContext aRC( &aContext, nStripY );
+                        pTask->push( aRC );
+                        nStripY += SCALE_THREAD_STRIP;
+                    }
+                    rShared.pushTask( pTask );
                 }
-                rShared.pushTask( pTask );
-            }
-            // finish any remaining bits here
-            pScaleRangeFn( aContext, nStripY, nEndY );
+                // finish any remaining bits here
+                pScaleRangeFn( aContext, nStripY, nEndY );
 
-            rShared.waitUntilDone(pTag);
-            SAL_INFO("vcl.gdi", "All threaded scaling tasks complete");
+                rShared.waitUntilDone(pTag);
+                SAL_INFO("vcl.gdi", "All threaded scaling tasks complete");
+            }
+            catch (...)
+            {
+                SAL_WARN("vcl.gdi", "threaded bitmap scaling failed");
+                bUseThreads = false;
+            }
         }
 
+        if (!bUseThreads)
+            pScaleRangeFn( aContext, nStartY, nEndY );
+
         bRet = true;
     }
 


More information about the Libreoffice-commits mailing list