LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/cache - SlsQueueProcessor.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 67 80 83.8 %
Date: 2014-04-11 Functions: 12 14 85.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             : 
      21             : #include "SlsQueueProcessor.hxx"
      22             : #include "SlsCacheConfiguration.hxx"
      23             : #include "SlsRequestQueue.hxx"
      24             : 
      25             : namespace sd { namespace slidesorter { namespace cache {
      26             : 
      27             : 
      28             : //=====  QueueProcessor  ======================================================
      29             : 
      30          63 : QueueProcessor::QueueProcessor (
      31             :     RequestQueue& rQueue,
      32             :     const ::boost::shared_ptr<BitmapCache>& rpCache,
      33             :     const Size& rPreviewSize,
      34             :     const bool bDoSuperSampling,
      35             :     const SharedCacheContext& rpCacheContext)
      36             :     : maMutex(),
      37             :       maTimer(),
      38             :       mnTimeBetweenHighPriorityRequests (10/*ms*/),
      39             :       mnTimeBetweenLowPriorityRequests (100/*ms*/),
      40             :       mnTimeBetweenRequestsWhenNotIdle (1000/*ms*/),
      41             :       maPreviewSize(rPreviewSize),
      42             :       mbDoSuperSampling(bDoSuperSampling),
      43             :       mpCacheContext(rpCacheContext),
      44             :       mrQueue(rQueue),
      45             :       mpCache(rpCache),
      46             :       maBitmapFactory(),
      47          63 :       mbIsPaused(false)
      48             : {
      49             :     // Look into the configuration if there for overriding values.
      50          63 :     ::com::sun::star::uno::Any aTimeBetweenReqeusts;
      51          63 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenHighPriorityRequests");
      52          63 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      53           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenHighPriorityRequests;
      54             : 
      55          63 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenLowPriorityRequests");
      56          63 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      57           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenLowPriorityRequests;
      58             : 
      59          63 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenRequestsDuringShow");
      60          63 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      61           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenRequestsWhenNotIdle;
      62             : 
      63          63 :     maTimer.SetTimeoutHdl (LINK(this,QueueProcessor,ProcessRequestHdl));
      64          63 :     maTimer.SetTimeout (mnTimeBetweenHighPriorityRequests);
      65          63 : }
      66             : 
      67             : 
      68             : 
      69             : 
      70             : 
      71         126 : QueueProcessor::~QueueProcessor (void)
      72             : {
      73         126 : }
      74             : 
      75             : 
      76             : 
      77             : 
      78         637 : void QueueProcessor::Start (int nPriorityClass)
      79             : {
      80         637 :     if (mbIsPaused)
      81         637 :         return;
      82         637 :     if ( ! maTimer.IsActive())
      83             :     {
      84         142 :         if (nPriorityClass == 0)
      85          67 :             maTimer.SetTimeout (mnTimeBetweenHighPriorityRequests);
      86             :         else
      87          75 :             maTimer.SetTimeout (mnTimeBetweenLowPriorityRequests);
      88         142 :         maTimer.Start();
      89             :     }
      90             : }
      91             : 
      92             : 
      93             : 
      94             : 
      95          63 : void QueueProcessor::Stop (void)
      96             : {
      97          63 :     if (maTimer.IsActive())
      98           8 :         maTimer.Stop();
      99          63 : }
     100             : 
     101             : 
     102             : 
     103             : 
     104           0 : void QueueProcessor::Pause (void)
     105             : {
     106           0 :     mbIsPaused = true;
     107           0 : }
     108             : 
     109             : 
     110             : 
     111             : 
     112           0 : void QueueProcessor::Resume (void)
     113             : {
     114           0 :     mbIsPaused = false;
     115           0 :     if ( ! mrQueue.IsEmpty())
     116           0 :         Start(mrQueue.GetFrontPriorityClass());
     117           0 : }
     118             : 
     119             : 
     120             : 
     121             : 
     122          63 : void QueueProcessor::Terminate (void)
     123             : {
     124          63 : }
     125             : 
     126             : 
     127             : 
     128             : 
     129           4 : void QueueProcessor::SetPreviewSize (
     130             :     const Size& rPreviewSize,
     131             :     const bool bDoSuperSampling)
     132             : {
     133           4 :     maPreviewSize = rPreviewSize;
     134           4 :     mbDoSuperSampling = bDoSuperSampling;
     135           4 : }
     136             : 
     137             : 
     138             : 
     139             : 
     140         268 : IMPL_LINK_NOARG(QueueProcessor, ProcessRequestHdl)
     141             : {
     142         134 :     ProcessRequests();
     143         134 :     return 1;
     144             : }
     145             : 
     146             : 
     147             : 
     148             : 
     149         134 : void QueueProcessor::ProcessRequests (void)
     150             : {
     151             :     OSL_ASSERT(mpCacheContext.get()!=NULL);
     152             : 
     153             :     // Never process more than one request at a time in order to prevent the
     154             :     // lock up of the edit view.
     155         268 :     if ( ! mrQueue.IsEmpty()
     156         134 :         && ! mbIsPaused
     157         268 :         &&  mpCacheContext->IsIdle())
     158             :     {
     159         134 :         CacheKey aKey = NULL;
     160         134 :         RequestPriorityClass ePriorityClass (NOT_VISIBLE);
     161             :         {
     162         134 :             ::osl::MutexGuard aGuard (mrQueue.GetMutex());
     163             : 
     164         134 :             if ( ! mrQueue.IsEmpty())
     165             :             {
     166             :                 // Get the request with the highest priority from the queue.
     167         134 :                 ePriorityClass = mrQueue.GetFrontPriorityClass();
     168         134 :                 aKey = mrQueue.GetFront();
     169         134 :                 mrQueue.PopFront();
     170         134 :             }
     171             :         }
     172             : 
     173         134 :         if (aKey != NULL)
     174         134 :             ProcessOneRequest(aKey, ePriorityClass);
     175             :     }
     176             : 
     177             :     // Schedule the processing of the next element(s).
     178             :     {
     179         134 :         ::osl::MutexGuard aGuard (mrQueue.GetMutex());
     180         134 :         if ( ! mrQueue.IsEmpty())
     181          19 :             Start(mrQueue.GetFrontPriorityClass());
     182             :     }
     183         134 : }
     184             : 
     185             : 
     186             : 
     187             : 
     188         134 : void QueueProcessor::ProcessOneRequest (
     189             :     CacheKey aKey,
     190             :     const RequestPriorityClass ePriorityClass)
     191             : {
     192             :     try
     193             :     {
     194         134 :         ::osl::MutexGuard aGuard (maMutex);
     195             : 
     196             :         // Create a new preview bitmap and store it in the cache.
     197         268 :         if (mpCache.get() != NULL
     198         134 :             && mpCacheContext.get() != NULL)
     199             :         {
     200         134 :             const SdPage* pSdPage = dynamic_cast<const SdPage*>(mpCacheContext->GetPage(aKey));
     201         134 :             if (pSdPage != NULL)
     202             :             {
     203             :                 const Bitmap aPreview (
     204         134 :                     maBitmapFactory.CreateBitmap(*pSdPage, maPreviewSize, mbDoSuperSampling));
     205         134 :                 mpCache->SetBitmap (pSdPage, aPreview, ePriorityClass!=NOT_VISIBLE);
     206             : 
     207             :                 // Initiate a repaint of the new preview.
     208         134 :                 mpCacheContext->NotifyPreviewCreation(aKey, aPreview);
     209             :             }
     210         134 :         }
     211             :     }
     212           0 :     catch (::com::sun::star::uno::RuntimeException &)
     213             :     {
     214             :         OSL_FAIL("RuntimeException caught in QueueProcessor");
     215             :     }
     216           0 :     catch (::com::sun::star::uno::Exception &)
     217             :     {
     218             :         OSL_FAIL("Exception caught in QueueProcessor");
     219             :     }
     220         134 : }
     221             : 
     222           4 : void QueueProcessor::SetBitmapCache (
     223             :     const ::boost::shared_ptr<BitmapCache>& rpCache)
     224             : {
     225           4 :     mpCache = rpCache;
     226           4 : }
     227             : 
     228             : 
     229             : } } } // end of namespace ::sd::slidesorter::cache
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10