LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/slidesorter/cache - SlsQueueProcessor.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 68 81 84.0 %
Date: 2013-07-09 Functions: 14 16 87.5 %
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          65 : 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          65 :       mbIsPaused(false)
      48             : {
      49             :     // Look into the configuration if there for overriding values.
      50          65 :     ::com::sun::star::uno::Any aTimeBetweenReqeusts;
      51          65 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenHighPriorityRequests");
      52          65 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      53           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenHighPriorityRequests;
      54             : 
      55          65 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenLowPriorityRequests");
      56          65 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      57           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenLowPriorityRequests;
      58             : 
      59          65 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenRequestsDuringShow");
      60          65 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      61           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenRequestsWhenNotIdle;
      62             : 
      63          65 :     maTimer.SetTimeoutHdl (LINK(this,QueueProcessor,ProcessRequestHdl));
      64          65 :     maTimer.SetTimeout (mnTimeBetweenHighPriorityRequests);
      65          65 : }
      66             : 
      67             : 
      68             : 
      69             : 
      70             : 
      71         130 : QueueProcessor::~QueueProcessor (void)
      72             : {
      73         130 : }
      74             : 
      75             : 
      76             : 
      77             : 
      78         649 : void QueueProcessor::Start (int nPriorityClass)
      79             : {
      80         649 :     if (mbIsPaused)
      81         649 :         return;
      82         649 :     if ( ! maTimer.IsActive())
      83             :     {
      84         143 :         if (nPriorityClass == 0)
      85          67 :             maTimer.SetTimeout (mnTimeBetweenHighPriorityRequests);
      86             :         else
      87          76 :             maTimer.SetTimeout (mnTimeBetweenLowPriorityRequests);
      88         143 :         maTimer.Start();
      89             :     }
      90             : }
      91             : 
      92             : 
      93             : 
      94             : 
      95          65 : void QueueProcessor::Stop (void)
      96             : {
      97          65 :     if (maTimer.IsActive())
      98           6 :         maTimer.Stop();
      99          65 : }
     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          65 : void QueueProcessor::Terminate (void)
     123             : {
     124          65 : }
     125             : 
     126             : 
     127             : 
     128             : 
     129           9 : void QueueProcessor::SetPreviewSize (
     130             :     const Size& rPreviewSize,
     131             :     const bool bDoSuperSampling)
     132             : {
     133           9 :     maPreviewSize = rPreviewSize;
     134           9 :     mbDoSuperSampling = bDoSuperSampling;
     135           9 : }
     136             : 
     137             : 
     138             : 
     139             : 
     140         274 : IMPL_LINK_NOARG(QueueProcessor, ProcessRequestHdl)
     141             : {
     142         137 :     ProcessRequests();
     143         137 :     return 1;
     144             : }
     145             : 
     146             : 
     147             : 
     148             : 
     149         137 : 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         274 :     if ( ! mrQueue.IsEmpty()
     156         137 :         && ! mbIsPaused
     157         274 :         &&  mpCacheContext->IsIdle())
     158             :     {
     159         137 :         CacheKey aKey = NULL;
     160         137 :         RequestPriorityClass ePriorityClass (NOT_VISIBLE);
     161             :         {
     162         137 :             ::osl::MutexGuard aGuard (mrQueue.GetMutex());
     163             : 
     164         137 :             if ( ! mrQueue.IsEmpty())
     165             :             {
     166             :                 // Get the request with the highest priority from the queue.
     167         137 :                 ePriorityClass = mrQueue.GetFrontPriorityClass();
     168         137 :                 aKey = mrQueue.GetFront();
     169         137 :                 mrQueue.PopFront();
     170         137 :             }
     171             :         }
     172             : 
     173         137 :         if (aKey != NULL)
     174         137 :             ProcessOneRequest(aKey, ePriorityClass);
     175             :     }
     176             : 
     177             :     // Schedule the processing of the next element(s).
     178             :     {
     179         137 :         ::osl::MutexGuard aGuard (mrQueue.GetMutex());
     180         137 :         if ( ! mrQueue.IsEmpty())
     181          21 :             Start(mrQueue.GetFrontPriorityClass());
     182             :     }
     183         137 : }
     184             : 
     185             : 
     186             : 
     187             : 
     188         137 : void QueueProcessor::ProcessOneRequest (
     189             :     CacheKey aKey,
     190             :     const RequestPriorityClass ePriorityClass)
     191             : {
     192             :     try
     193             :     {
     194         137 :         ::osl::MutexGuard aGuard (maMutex);
     195             : 
     196             :         // Create a new preview bitmap and store it in the cache.
     197         274 :         if (mpCache.get() != NULL
     198         137 :             && mpCacheContext.get() != NULL)
     199             :         {
     200         137 :             const SdPage* pSdPage = dynamic_cast<const SdPage*>(mpCacheContext->GetPage(aKey));
     201         137 :             if (pSdPage != NULL)
     202             :             {
     203             :                 const Bitmap aPreview (
     204         137 :                     maBitmapFactory.CreateBitmap(*pSdPage, maPreviewSize, mbDoSuperSampling));
     205         137 :                 mpCache->SetBitmap (pSdPage, aPreview, ePriorityClass!=NOT_VISIBLE);
     206             : 
     207             :                 // Initiate a repaint of the new preview.
     208         137 :                 mpCacheContext->NotifyPreviewCreation(aKey, aPreview);
     209             :             }
     210         137 :         }
     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         137 : }
     221             : 
     222           9 : void QueueProcessor::SetBitmapCache (
     223             :     const ::boost::shared_ptr<BitmapCache>& rpCache)
     224             : {
     225           9 :     mpCache = rpCache;
     226           9 : }
     227             : 
     228             : 
     229          33 : } } } // end of namespace ::sd::slidesorter::cache
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10