bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / slidesorter / cache / SlsQueueProcessor.cxx
blob212734e3df0bd2d219b1e0df1e945f6dae5e3698
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "SlsQueueProcessor.hxx"
21 #include "SlsCacheConfiguration.hxx"
22 #include "SlsRequestQueue.hxx"
24 namespace sd { namespace slidesorter { namespace cache {
26 //===== QueueProcessor ======================================================
28 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 mbIsPaused(false)
47 // Look into the configuration if there for overriding values.
48 ::com::sun::star::uno::Any aTimeBetweenReqeusts;
49 aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenHighPriorityRequests");
50 if (aTimeBetweenReqeusts.has<sal_Int32>())
51 aTimeBetweenReqeusts >>= mnTimeBetweenHighPriorityRequests;
53 aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenLowPriorityRequests");
54 if (aTimeBetweenReqeusts.has<sal_Int32>())
55 aTimeBetweenReqeusts >>= mnTimeBetweenLowPriorityRequests;
57 aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenRequestsDuringShow");
58 if (aTimeBetweenReqeusts.has<sal_Int32>())
59 aTimeBetweenReqeusts >>= mnTimeBetweenRequestsWhenNotIdle;
61 maTimer.SetTimeoutHdl (LINK(this,QueueProcessor,ProcessRequestHdl));
62 maTimer.SetTimeout (10);
65 QueueProcessor::~QueueProcessor()
69 void QueueProcessor::Start (int nPriorityClass)
71 if (mbIsPaused)
72 return;
73 if ( ! maTimer.IsActive())
75 if (nPriorityClass == 0)
76 maTimer.SetTimeout (10);
77 else
78 maTimer.SetTimeout (100);
79 maTimer.Start();
83 void QueueProcessor::Stop()
85 if (maTimer.IsActive())
86 maTimer.Stop();
89 void QueueProcessor::Pause()
91 mbIsPaused = true;
94 void QueueProcessor::Resume()
96 mbIsPaused = false;
97 if ( ! mrQueue.IsEmpty())
98 Start(mrQueue.GetFrontPriorityClass());
101 void QueueProcessor::SetPreviewSize (
102 const Size& rPreviewSize,
103 const bool bDoSuperSampling)
105 maPreviewSize = rPreviewSize;
106 mbDoSuperSampling = bDoSuperSampling;
109 IMPL_LINK_NOARG_TYPED(QueueProcessor, ProcessRequestHdl, Timer *, void)
111 ProcessRequests();
114 void QueueProcessor::ProcessRequests()
116 OSL_ASSERT(mpCacheContext.get()!=NULL);
118 // Never process more than one request at a time in order to prevent the
119 // lock up of the edit view.
120 if ( ! mrQueue.IsEmpty()
121 && ! mbIsPaused
122 && mpCacheContext->IsIdle())
124 CacheKey aKey = NULL;
125 RequestPriorityClass ePriorityClass (NOT_VISIBLE);
127 ::osl::MutexGuard aGuard (mrQueue.GetMutex());
129 if ( ! mrQueue.IsEmpty())
131 // Get the request with the highest priority from the queue.
132 ePriorityClass = mrQueue.GetFrontPriorityClass();
133 aKey = mrQueue.GetFront();
134 mrQueue.PopFront();
138 if (aKey != NULL)
139 ProcessOneRequest(aKey, ePriorityClass);
142 // Schedule the processing of the next element(s).
144 ::osl::MutexGuard aGuard (mrQueue.GetMutex());
145 if ( ! mrQueue.IsEmpty())
146 Start(mrQueue.GetFrontPriorityClass());
150 void QueueProcessor::ProcessOneRequest (
151 CacheKey aKey,
152 const RequestPriorityClass ePriorityClass)
156 ::osl::MutexGuard aGuard (maMutex);
158 // Create a new preview bitmap and store it in the cache.
159 if (mpCache.get() != NULL
160 && mpCacheContext.get() != NULL)
162 const SdPage* pSdPage = dynamic_cast<const SdPage*>(mpCacheContext->GetPage(aKey));
163 if (pSdPage != NULL)
165 const Bitmap aPreview (
166 maBitmapFactory.CreateBitmap(*pSdPage, maPreviewSize, mbDoSuperSampling));
167 mpCache->SetBitmap (pSdPage, aPreview, ePriorityClass!=NOT_VISIBLE);
169 // Initiate a repaint of the new preview.
170 mpCacheContext->NotifyPreviewCreation(aKey, aPreview);
174 catch (::com::sun::star::uno::RuntimeException &)
176 OSL_FAIL("RuntimeException caught in QueueProcessor");
178 catch (::com::sun::star::uno::Exception &)
180 OSL_FAIL("Exception caught in QueueProcessor");
184 void QueueProcessor::SetBitmapCache (
185 const ::boost::shared_ptr<BitmapCache>& rpCache)
187 mpCache = rpCache;
190 } } } // end of namespace ::sd::slidesorter::cache
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */