tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / slidesorter / cache / SlsQueueProcessor.cxx
blob2325e232aba71b483d61fb77867802c14a62391f
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 "SlsRequestQueue.hxx"
22 #include "SlsBitmapCache.hxx"
24 #include <sdpage.hxx>
25 #include <comphelper/profilezone.hxx>
26 #include <utility>
27 #include <comphelper/diagnose_ex.hxx>
29 namespace sd::slidesorter::cache {
31 //===== QueueProcessor ======================================================
33 QueueProcessor::QueueProcessor (
34 RequestQueue& rQueue,
35 std::shared_ptr<BitmapCache> pCache,
36 const Size& rPreviewSize,
37 const bool bDoSuperSampling,
38 SharedCacheContext pCacheContext)
39 : maTimer("sd::QueueProcessor maTimer"),
40 maPreviewSize(rPreviewSize),
41 mbDoSuperSampling(bDoSuperSampling),
42 mpCacheContext(std::move(pCacheContext)),
43 mrQueue(rQueue),
44 mpCache(std::move(pCache)),
45 mbIsPaused(false)
47 maTimer.SetInvokeHandler (LINK(this,QueueProcessor,ProcessRequestHdl));
48 maTimer.SetTimeout (10);
51 QueueProcessor::~QueueProcessor()
55 void QueueProcessor::Start (int nPriorityClass)
57 if (mbIsPaused)
58 return;
59 if ( ! maTimer.IsActive())
61 if (nPriorityClass == 0)
62 maTimer.SetTimeout (10);
63 else
64 maTimer.SetTimeout (100);
65 maTimer.Start();
69 void QueueProcessor::Stop()
71 if (maTimer.IsActive())
72 maTimer.Stop();
75 void QueueProcessor::Pause()
77 mbIsPaused = true;
80 void QueueProcessor::Resume()
82 mbIsPaused = false;
83 if ( ! mrQueue.IsEmpty())
84 Start(mrQueue.GetFrontPriorityClass());
87 void QueueProcessor::SetPreviewSize (
88 const Size& rPreviewSize,
89 const bool bDoSuperSampling)
91 maPreviewSize = rPreviewSize;
92 mbDoSuperSampling = bDoSuperSampling;
95 IMPL_LINK_NOARG(QueueProcessor, ProcessRequestHdl, Timer *, void)
97 ProcessRequests();
100 void QueueProcessor::ProcessRequests()
102 assert(mpCacheContext);
104 // Never process more than one request at a time in order to prevent the
105 // lock up of the edit view.
106 if ( ! mrQueue.IsEmpty()
107 && ! mbIsPaused
108 && mpCacheContext->IsIdle())
110 CacheKey aKey = nullptr;
111 RequestPriorityClass ePriorityClass (NOT_VISIBLE);
113 ::osl::MutexGuard aGuard (mrQueue.GetMutex());
115 if ( ! mrQueue.IsEmpty())
117 // Get the request with the highest priority from the queue.
118 ePriorityClass = mrQueue.GetFrontPriorityClass();
119 aKey = mrQueue.GetFront();
120 mrQueue.PopFront();
124 if (aKey != nullptr)
125 ProcessOneRequest(aKey, ePriorityClass);
128 // Schedule the processing of the next element(s).
130 ::osl::MutexGuard aGuard (mrQueue.GetMutex());
131 if ( ! mrQueue.IsEmpty())
132 Start(mrQueue.GetFrontPriorityClass());
133 else
135 comphelper::ProfileZone aZone("QueueProcessor finished processing all elements");
140 void QueueProcessor::ProcessOneRequest (
141 CacheKey aKey,
142 const RequestPriorityClass ePriorityClass)
146 std::scoped_lock aGuard (maMutex);
148 // Create a new preview bitmap and store it in the cache.
149 if (mpCache != nullptr && mpCacheContext)
151 const SdPage* pSdPage = dynamic_cast<const SdPage*>(mpCacheContext->GetPage(aKey));
152 if (pSdPage != nullptr)
154 const BitmapEx aPreview (
155 maBitmapFactory.CreateBitmap(*pSdPage, maPreviewSize, mbDoSuperSampling));
156 mpCache->SetBitmap (pSdPage, aPreview, ePriorityClass!=NOT_VISIBLE);
158 // Initiate a repaint of the new preview.
159 mpCacheContext->NotifyPreviewCreation(aKey);
163 catch (css::uno::Exception &)
165 TOOLS_WARN_EXCEPTION( "sd", "QueueProcessor");
169 void QueueProcessor::SetBitmapCache (
170 const std::shared_ptr<BitmapCache>& rpCache)
172 mpCache = rpCache;
175 } // end of namespace ::sd::slidesorter::cache
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */