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 .
22 #include <sal/types.h>
23 #include <com/sun/star/uno/XInterface.hpp>
30 namespace sd::slidesorter::cache
{
34 /** Provide and manage the preview bitmap caches for all slide sorter
35 instances. There is one cache per active slide sorter plus a small
36 number of caches that are no longer in use. The later are kept to speed
37 up the switching between views.
39 class PageCacheManager
42 typedef std::vector
< std::pair
<Size
, std::shared_ptr
<BitmapCache
> > > BestFittingPageCaches
;
43 typedef css::uno::Reference
<css::uno::XInterface
> DocumentKey
;
45 /** Return the one instance of the PageCacheManager class.
47 static std::shared_ptr
<PageCacheManager
> Instance();
49 /** Look up the cache for the given model in which the previews have the
50 specified size. If no such cache exists, then one is created. When
51 a new BitmapCache is created its Recycle() method is called with a
52 sorted list of existing caches from which the new one initialize its
55 The returned cache lives as long as somebody keeps a shared
56 pointer and the ReleaseCache() method has not been called.
58 std::shared_ptr
<BitmapCache
> GetCache (
59 const DocumentKey
& pDocument
,
60 const Size
& rPreviewSize
);
62 /** Tell the cache manager to release its own reference to the specified
63 cache. After that the cache will live as long as the caller (and
64 maybe others) holds its reference.
66 void ReleaseCache (const std::shared_ptr
<BitmapCache
>& rpCache
);
68 /** This is an information to the cache manager that the size of preview
69 bitmaps in the specified cache has changed.
72 std::shared_ptr
<BitmapCache
> ChangeSize (
73 const std::shared_ptr
<BitmapCache
>& rpCache
,
74 const Size
& rOldPreviewSize
,
75 const Size
& rNewPreviewSize
);
77 /** Invalidate the preview bitmap for one slide that belongs to the
78 specified document. The bitmaps for this slide in all caches are
79 marked as out-of-date and will be re-created when they are requested
82 bool InvalidatePreviewBitmap (
83 const DocumentKey
& pDocument
,
84 const SdrPage
* pPage
);
86 /** Invalidate the preview bitmaps for all slides that belong to the
87 specified document. This is necessary after model changes that
88 affect e.g. page number fields.
90 void InvalidateAllPreviewBitmaps (const DocumentKey
& pDocument
);
92 /** Invalidate all the caches that are currently in use and destroy
93 those that are not. This is used for example when the high contrast
94 mode is turned on or off.
96 void InvalidateAllCaches();
98 /** Call this method when a page has been deleted and its preview
99 is not needed anymore.
101 void ReleasePreviewBitmap (const SdrPage
* pPage
);
104 /** Singleton instance of the cache manager. Note that this is a weak
105 pointer. The (implementation class of) ViewShellBase holds a
106 shared_ptr so that the cache manager has the same life time as the
109 static std::weak_ptr
<PageCacheManager
> mpInstance
;
111 /// List of active caches.
112 class PageCacheContainer
;
113 std::unique_ptr
<PageCacheContainer
> mpPageCaches
;
115 /// List of inactive, recently used caches.
116 class RecentlyUsedPageCaches
;
117 std::unique_ptr
<RecentlyUsedPageCaches
> mpRecentlyUsedPageCaches
;
119 /** The maximal number of recently used caches that are kept alive after
120 they have become inactive, i.e. after they are not used anymore by a
123 static const sal_uInt32 mnMaximalRecentlyCacheCount
= 2;
129 friend class Deleter
;
131 std::shared_ptr
<BitmapCache
> GetRecentlyUsedCache(
132 const DocumentKey
& pDocument
,
135 /** Add the given cache to the list of recently used caches for the
136 document. There is one such list per document. Each least has at
137 most mnMaximalRecentlyCacheCount members.
139 void PutRecentlyUsedCache(
140 DocumentKey
const & pDocument
,
141 const Size
& rPreviewSize
,
142 const std::shared_ptr
<BitmapCache
>& rpCache
);
144 /** This method is used internally to initialize a newly created
145 BitmapCache with already existing previews.
148 const std::shared_ptr
<BitmapCache
>& rpCache
,
149 const DocumentKey
& pDocument
,
150 const Size
& rPreviewSize
);
153 } // end of namespace ::sd::slidesorter::cache
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */