LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/cache - SlsQueueProcessor.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 66 79 83.5 %
Date: 2015-06-13 12:38:46 Functions: 13 15 86.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "SlsQueueProcessor.hxx"
      21             : #include "SlsCacheConfiguration.hxx"
      22             : #include "SlsRequestQueue.hxx"
      23             : 
      24             : namespace sd { namespace slidesorter { namespace cache {
      25             : 
      26             : //=====  QueueProcessor  ======================================================
      27             : 
      28          64 : QueueProcessor::QueueProcessor (
      29             :     RequestQueue& rQueue,
      30             :     const ::boost::shared_ptr<BitmapCache>& rpCache,
      31             :     const Size& rPreviewSize,
      32             :     const bool bDoSuperSampling,
      33             :     const SharedCacheContext& rpCacheContext)
      34             :     : maMutex(),
      35             :       maTimer(),
      36             :       mnTimeBetweenHighPriorityRequests (10/*ms*/),
      37             :       mnTimeBetweenLowPriorityRequests (100/*ms*/),
      38             :       mnTimeBetweenRequestsWhenNotIdle (1000/*ms*/),
      39             :       maPreviewSize(rPreviewSize),
      40             :       mbDoSuperSampling(bDoSuperSampling),
      41             :       mpCacheContext(rpCacheContext),
      42             :       mrQueue(rQueue),
      43             :       mpCache(rpCache),
      44             :       maBitmapFactory(),
      45          64 :       mbIsPaused(false)
      46             : {
      47             :     // Look into the configuration if there for overriding values.
      48          64 :     ::com::sun::star::uno::Any aTimeBetweenReqeusts;
      49          64 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenHighPriorityRequests");
      50          64 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      51           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenHighPriorityRequests;
      52             : 
      53          64 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenLowPriorityRequests");
      54          64 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      55           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenLowPriorityRequests;
      56             : 
      57          64 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenRequestsDuringShow");
      58          64 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      59           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenRequestsWhenNotIdle;
      60             : 
      61          64 :     maTimer.SetTimeoutHdl (LINK(this,QueueProcessor,ProcessRequestHdl));
      62          64 :     maTimer.SetTimeout (10);
      63          64 : }
      64             : 
      65         128 : QueueProcessor::~QueueProcessor()
      66             : {
      67         128 : }
      68             : 
      69         600 : void QueueProcessor::Start (int nPriorityClass)
      70             : {
      71         600 :     if (mbIsPaused)
      72         600 :         return;
      73         600 :     if ( ! maTimer.IsActive())
      74             :     {
      75         155 :         if (nPriorityClass == 0)
      76          65 :             maTimer.SetTimeout (10);
      77             :         else
      78          90 :             maTimer.SetTimeout (100);
      79         155 :         maTimer.Start();
      80             :     }
      81             : }
      82             : 
      83          64 : void QueueProcessor::Stop()
      84             : {
      85          64 :     if (maTimer.IsActive())
      86          10 :         maTimer.Stop();
      87          64 : }
      88             : 
      89           0 : void QueueProcessor::Pause()
      90             : {
      91           0 :     mbIsPaused = true;
      92           0 : }
      93             : 
      94           0 : void QueueProcessor::Resume()
      95             : {
      96           0 :     mbIsPaused = false;
      97           0 :     if ( ! mrQueue.IsEmpty())
      98           0 :         Start(mrQueue.GetFrontPriorityClass());
      99           0 : }
     100             : 
     101           2 : void QueueProcessor::SetPreviewSize (
     102             :     const Size& rPreviewSize,
     103             :     const bool bDoSuperSampling)
     104             : {
     105           2 :     maPreviewSize = rPreviewSize;
     106           2 :     mbDoSuperSampling = bDoSuperSampling;
     107           2 : }
     108             : 
     109         290 : IMPL_LINK_NOARG_TYPED(QueueProcessor, ProcessRequestHdl, Timer *, void)
     110             : {
     111         145 :     ProcessRequests();
     112         145 : }
     113             : 
     114         145 : void QueueProcessor::ProcessRequests()
     115             : {
     116             :     OSL_ASSERT(mpCacheContext.get()!=NULL);
     117             : 
     118             :     // Never process more than one request at a time in order to prevent the
     119             :     // lock up of the edit view.
     120         290 :     if ( ! mrQueue.IsEmpty()
     121         145 :         && ! mbIsPaused
     122         290 :         &&  mpCacheContext->IsIdle())
     123             :     {
     124         145 :         CacheKey aKey = NULL;
     125         145 :         RequestPriorityClass ePriorityClass (NOT_VISIBLE);
     126             :         {
     127         145 :             ::osl::MutexGuard aGuard (mrQueue.GetMutex());
     128             : 
     129         145 :             if ( ! mrQueue.IsEmpty())
     130             :             {
     131             :                 // Get the request with the highest priority from the queue.
     132         145 :                 ePriorityClass = mrQueue.GetFrontPriorityClass();
     133         145 :                 aKey = mrQueue.GetFront();
     134         145 :                 mrQueue.PopFront();
     135         145 :             }
     136             :         }
     137             : 
     138         145 :         if (aKey != NULL)
     139         145 :             ProcessOneRequest(aKey, ePriorityClass);
     140             :     }
     141             : 
     142             :     // Schedule the processing of the next element(s).
     143             :     {
     144         145 :         ::osl::MutexGuard aGuard (mrQueue.GetMutex());
     145         145 :         if ( ! mrQueue.IsEmpty())
     146          30 :             Start(mrQueue.GetFrontPriorityClass());
     147             :     }
     148         145 : }
     149             : 
     150         145 : void QueueProcessor::ProcessOneRequest (
     151             :     CacheKey aKey,
     152             :     const RequestPriorityClass ePriorityClass)
     153             : {
     154             :     try
     155             :     {
     156         145 :         ::osl::MutexGuard aGuard (maMutex);
     157             : 
     158             :         // Create a new preview bitmap and store it in the cache.
     159         290 :         if (mpCache.get() != NULL
     160         145 :             && mpCacheContext.get() != NULL)
     161             :         {
     162         145 :             const SdPage* pSdPage = dynamic_cast<const SdPage*>(mpCacheContext->GetPage(aKey));
     163         145 :             if (pSdPage != NULL)
     164             :             {
     165             :                 const Bitmap aPreview (
     166         145 :                     maBitmapFactory.CreateBitmap(*pSdPage, maPreviewSize, mbDoSuperSampling));
     167         145 :                 mpCache->SetBitmap (pSdPage, aPreview, ePriorityClass!=NOT_VISIBLE);
     168             : 
     169             :                 // Initiate a repaint of the new preview.
     170         145 :                 mpCacheContext->NotifyPreviewCreation(aKey, aPreview);
     171             :             }
     172         145 :         }
     173             :     }
     174           0 :     catch (::com::sun::star::uno::RuntimeException &)
     175             :     {
     176             :         OSL_FAIL("RuntimeException caught in QueueProcessor");
     177             :     }
     178           0 :     catch (::com::sun::star::uno::Exception &)
     179             :     {
     180             :         OSL_FAIL("Exception caught in QueueProcessor");
     181             :     }
     182         145 : }
     183             : 
     184           2 : void QueueProcessor::SetBitmapCache (
     185             :     const ::boost::shared_ptr<BitmapCache>& rpCache)
     186             : {
     187           2 :     mpCache = rpCache;
     188           2 : }
     189             : 
     190          66 : } } } // end of namespace ::sd::slidesorter::cache
     191             : 
     192             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11