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

Generated by: LCOV version 1.10