LibreOffice Module sd (master) 1
SlsPageCacheManager.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <sal/types.h>
23#include <com/sun/star/uno/XInterface.hpp>
24#include <memory>
25#include <vector>
26
27class Size;
28class SdrPage;
29
30namespace sd::slidesorter::cache {
31
32class BitmapCache;
33
40{
41public:
42 typedef std::vector< std::pair<Size, std::shared_ptr<BitmapCache> > > BestFittingPageCaches;
43 typedef css::uno::Reference<css::uno::XInterface> DocumentKey;
44
47 static std::shared_ptr<PageCacheManager> Instance();
48
58 std::shared_ptr<BitmapCache> GetCache (
59 const DocumentKey& pDocument,
60 const Size& rPreviewSize);
61
66 void ReleaseCache (const std::shared_ptr<BitmapCache>& rpCache);
67
72 std::shared_ptr<BitmapCache> ChangeSize (
73 const std::shared_ptr<BitmapCache>& rpCache,
74 const Size& rOldPreviewSize,
75 const Size& rNewPreviewSize);
76
83 const DocumentKey& pDocument,
84 const SdrPage* pPage);
85
90 void InvalidateAllPreviewBitmaps (const DocumentKey& pDocument);
91
97
101 void ReleasePreviewBitmap (const SdrPage* pPage);
102
103private:
109 static std::weak_ptr<PageCacheManager> mpInstance;
110
112 class PageCacheContainer;
113 std::unique_ptr<PageCacheContainer> mpPageCaches;
114
117 std::unique_ptr<RecentlyUsedPageCaches> mpRecentlyUsedPageCaches;
118
123 static const sal_uInt32 mnMaximalRecentlyCacheCount = 2;
124
127
128 class Deleter;
129 friend class Deleter;
130
131 std::shared_ptr<BitmapCache> GetRecentlyUsedCache(
132 const DocumentKey& pDocument,
133 const Size& rSize);
134
140 DocumentKey const & pDocument,
141 const Size& rPreviewSize,
142 const std::shared_ptr<BitmapCache>& rpCache);
143
147 void Recycle (
148 const std::shared_ptr<BitmapCache>& rpCache,
149 const DocumentKey& pDocument,
150 const Size& rPreviewSize);
151};
152
153} // end of namespace ::sd::slidesorter::cache
154
155/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
The recently used caches are stored in one queue for each document.
Provide and manage the preview bitmap caches for all slide sorter instances.
static std::shared_ptr< PageCacheManager > Instance()
Return the one instance of the PageCacheManager class.
std::shared_ptr< BitmapCache > GetRecentlyUsedCache(const DocumentKey &pDocument, const Size &rSize)
std::shared_ptr< BitmapCache > GetCache(const DocumentKey &pDocument, const Size &rPreviewSize)
Look up the cache for the given model in which the previews have the specified size.
css::uno::Reference< css::uno::XInterface > DocumentKey
static const sal_uInt32 mnMaximalRecentlyCacheCount
The maximal number of recently used caches that are kept alive after they have become inactive,...
std::unique_ptr< RecentlyUsedPageCaches > mpRecentlyUsedPageCaches
void ReleaseCache(const std::shared_ptr< BitmapCache > &rpCache)
Tell the cache manager to release its own reference to the specified cache.
std::vector< std::pair< Size, std::shared_ptr< BitmapCache > > > BestFittingPageCaches
void InvalidateAllCaches()
Invalidate all the caches that are currently in use and destroy those that are not.
void Recycle(const std::shared_ptr< BitmapCache > &rpCache, const DocumentKey &pDocument, const Size &rPreviewSize)
This method is used internally to initialize a newly created BitmapCache with already existing previe...
void ReleasePreviewBitmap(const SdrPage *pPage)
Call this method when a page has been deleted and its preview is not needed anymore.
void InvalidateAllPreviewBitmaps(const DocumentKey &pDocument)
Invalidate the preview bitmaps for all slides that belong to the specified document.
bool InvalidatePreviewBitmap(const DocumentKey &pDocument, const SdrPage *pPage)
Invalidate the preview bitmap for one slide that belongs to the specified document.
std::shared_ptr< BitmapCache > ChangeSize(const std::shared_ptr< BitmapCache > &rpCache, const Size &rOldPreviewSize, const Size &rNewPreviewSize)
This is an information to the cache manager that the size of preview bitmaps in the specified cache h...
std::unique_ptr< PageCacheContainer > mpPageCaches
void PutRecentlyUsedCache(DocumentKey const &pDocument, const Size &rPreviewSize, const std::shared_ptr< BitmapCache > &rpCache)
Add the given cache to the list of recently used caches for the document.
static std::weak_ptr< PageCacheManager > mpInstance
Singleton instance of the cache manager.