1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 (
30 const ::boost::shared_ptr
<BitmapCache
>& rpCache
,
31 const Size
& rPreviewSize
,
32 const bool bDoSuperSampling
,
33 const SharedCacheContext
& rpCacheContext
)
36 mnTimeBetweenHighPriorityRequests (10/*ms*/),
37 mnTimeBetweenLowPriorityRequests (100/*ms*/),
38 mnTimeBetweenRequestsWhenNotIdle (1000/*ms*/),
39 maPreviewSize(rPreviewSize
),
40 mbDoSuperSampling(bDoSuperSampling
),
41 mpCacheContext(rpCacheContext
),
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
)
73 if ( ! maTimer
.IsActive())
75 if (nPriorityClass
== 0)
76 maTimer
.SetTimeout (10);
78 maTimer
.SetTimeout (100);
83 void QueueProcessor::Stop()
85 if (maTimer
.IsActive())
89 void QueueProcessor::Pause()
94 void QueueProcessor::Resume()
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)
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()
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();
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 (
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
));
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
)
190 } } } // end of namespace ::sd::slidesorter::cache
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */