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"
23 #include "SlsBitmapCache.hxx"
26 #include <comphelper/profilezone.hxx>
28 namespace sd
{ namespace slidesorter
{ namespace cache
{
30 //===== QueueProcessor ======================================================
32 QueueProcessor::QueueProcessor (
34 const std::shared_ptr
<BitmapCache
>& rpCache
,
35 const Size
& rPreviewSize
,
36 const bool bDoSuperSampling
,
37 const SharedCacheContext
& rpCacheContext
)
40 maPreviewSize(rPreviewSize
),
41 mbDoSuperSampling(bDoSuperSampling
),
42 mpCacheContext(rpCacheContext
),
48 maTimer
.SetInvokeHandler (LINK(this,QueueProcessor
,ProcessRequestHdl
));
49 maTimer
.SetTimeout (10);
50 maTimer
.SetDebugName ("sd::QueueProcessor maTimer");
53 QueueProcessor::~QueueProcessor()
57 void QueueProcessor::Start (int nPriorityClass
)
61 if ( ! maTimer
.IsActive())
63 if (nPriorityClass
== 0)
64 maTimer
.SetTimeout (10);
66 maTimer
.SetTimeout (100);
71 void QueueProcessor::Stop()
73 if (maTimer
.IsActive())
77 void QueueProcessor::Pause()
82 void QueueProcessor::Resume()
85 if ( ! mrQueue
.IsEmpty())
86 Start(mrQueue
.GetFrontPriorityClass());
89 void QueueProcessor::SetPreviewSize (
90 const Size
& rPreviewSize
,
91 const bool bDoSuperSampling
)
93 maPreviewSize
= rPreviewSize
;
94 mbDoSuperSampling
= bDoSuperSampling
;
97 IMPL_LINK_NOARG(QueueProcessor
, ProcessRequestHdl
, Timer
*, void)
102 void QueueProcessor::ProcessRequests()
104 assert(mpCacheContext
.get()!=nullptr);
106 // Never process more than one request at a time in order to prevent the
107 // lock up of the edit view.
108 if ( ! mrQueue
.IsEmpty()
110 && mpCacheContext
->IsIdle())
112 CacheKey aKey
= nullptr;
113 RequestPriorityClass
ePriorityClass (NOT_VISIBLE
);
115 ::osl::MutexGuard
aGuard (mrQueue
.GetMutex());
117 if ( ! mrQueue
.IsEmpty())
119 // Get the request with the highest priority from the queue.
120 ePriorityClass
= mrQueue
.GetFrontPriorityClass();
121 aKey
= mrQueue
.GetFront();
127 ProcessOneRequest(aKey
, ePriorityClass
);
130 // Schedule the processing of the next element(s).
132 ::osl::MutexGuard
aGuard (mrQueue
.GetMutex());
133 if ( ! mrQueue
.IsEmpty())
134 Start(mrQueue
.GetFrontPriorityClass());
137 comphelper::ProfileZone
aZone("QueueProcessor finished processing all elements");
142 void QueueProcessor::ProcessOneRequest (
144 const RequestPriorityClass ePriorityClass
)
148 ::osl::MutexGuard
aGuard (maMutex
);
150 // Create a new preview bitmap and store it in the cache.
151 if (mpCache
!= nullptr && mpCacheContext
.get() != nullptr)
153 const SdPage
* pSdPage
= dynamic_cast<const SdPage
*>(mpCacheContext
->GetPage(aKey
));
154 if (pSdPage
!= nullptr)
156 const BitmapEx
aPreview (
157 maBitmapFactory
.CreateBitmap(*pSdPage
, maPreviewSize
, mbDoSuperSampling
));
158 mpCache
->SetBitmap (pSdPage
, aPreview
, ePriorityClass
!=NOT_VISIBLE
);
160 // Initiate a repaint of the new preview.
161 mpCacheContext
->NotifyPreviewCreation(aKey
);
165 catch (css::uno::RuntimeException
&)
167 OSL_FAIL("RuntimeException caught in QueueProcessor");
169 catch (css::uno::Exception
&)
171 OSL_FAIL("Exception caught in QueueProcessor");
175 void QueueProcessor::SetBitmapCache (
176 const std::shared_ptr
<BitmapCache
>& rpCache
)
181 } } } // end of namespace ::sd::slidesorter::cache
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */