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 #ifndef INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CACHE_SLSPAGECACHEMANAGER_HXX
21 #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_CACHE_SLSPAGECACHEMANAGER_HXX
23 #include <sal/types.h>
24 #include <com/sun/star/uno/XInterface.hpp>
31 namespace sd
{ namespace slidesorter
{ namespace cache
{
35 /** Provide and manage the preview bitmap caches for all slide sorter
36 instances. There is one cache per active slide sorter plus a small
37 number of caches that are no longer in use. The later are kept to speed
38 up the switching between views.
40 class PageCacheManager
43 typedef std::vector
< std::pair
<Size
, std::shared_ptr
<BitmapCache
> > > BestFittingPageCaches
;
44 typedef css::uno::Reference
<css::uno::XInterface
> DocumentKey
;
46 /** Return the one instance of the PageCacheManager class.
48 static std::shared_ptr
<PageCacheManager
> Instance();
50 /** Look up the cache for the given model in which the previews have the
51 specified size. If no such cache exists, then one is created. When
52 a new BitmapCache is created its Recycle() method is called with a
53 sorted list of existing caches from which the new one initialize its
56 The returned cache lives as long as somebody keeps a shared
57 pointer and the ReleaseCache() method has not been called.
59 std::shared_ptr
<BitmapCache
> GetCache (
60 const DocumentKey
& pDocument
,
61 const Size
& rPreviewSize
);
63 /** Tell the cache manager to release its own reference to the specified
64 cache. After that the cache will live as long as the caller (and
65 maybe others) holds its reference.
67 void ReleaseCache (const std::shared_ptr
<BitmapCache
>& rpCache
);
69 /** This is an information to the cache manager that the size of preview
70 bitmaps in the specified cache has changed.
73 std::shared_ptr
<BitmapCache
> ChangeSize (
74 const std::shared_ptr
<BitmapCache
>& rpCache
,
75 const Size
& rOldPreviewSize
,
76 const Size
& rNewPreviewSize
);
78 /** Invalidate the preview bitmap for one slide that belongs to the
79 specified document. The bitmaps for this slide in all caches are
80 marked as out-of-date and will be re-created when they are requested
83 bool InvalidatePreviewBitmap (
84 const DocumentKey
& pDocument
,
85 const SdrPage
* pPage
);
87 /** Invalidate the preview bitmaps for all slides that belong to the
88 specified document. This is necessary after model changes that
89 affect e.g. page number fields.
91 void InvalidateAllPreviewBitmaps (const DocumentKey
& pDocument
);
93 /** Invalidate all the caches that are currently in use and destroy
94 those that are not. This is used for example when the high contrast
95 mode is turned on or off.
97 void InvalidateAllCaches();
99 /** Call this method when a page has been deleted and its preview
100 is not needed anymore.
102 void ReleasePreviewBitmap (const SdrPage
* pPage
);
105 /** Singleton instance of the cache manager. Note that this is a weak
106 pointer. The (implementation class of) ViewShellBase holds a
107 shared_ptr so that the cache manager has the same life time as the
110 static std::weak_ptr
<PageCacheManager
> mpInstance
;
112 /// List of active caches.
113 class PageCacheContainer
;
114 std::unique_ptr
<PageCacheContainer
> mpPageCaches
;
116 /// List of inactive, recently used caches.
117 class RecentlyUsedPageCaches
;
118 std::unique_ptr
<RecentlyUsedPageCaches
> mpRecentlyUsedPageCaches
;
120 /** The maximal number of recently used caches that are kept alive after
121 they have become inactive, i.e. after they are not used anymore by a
124 static const sal_uInt32 mnMaximalRecentlyCacheCount
= 2;
130 friend class Deleter
;
132 std::shared_ptr
<BitmapCache
> GetRecentlyUsedCache(
133 const DocumentKey
& pDocument
,
136 /** Add the given cache to the list of recently used caches for the
137 document. There is one such list per document. Each least has at
138 most mnMaximalRecentlyCacheCount members.
140 void PutRecentlyUsedCache(
141 DocumentKey
const & pDocument
,
142 const Size
& rPreviewSize
,
143 const std::shared_ptr
<BitmapCache
>& rpCache
);
145 /** This method is used internally to initialize a newly created
146 BitmapCache with already existing previews.
149 const std::shared_ptr
<BitmapCache
>& rpCache
,
150 const DocumentKey
& pDocument
,
151 const Size
& rPreviewSize
);
154 } } } // end of namespace ::sd::slidesorter::cache
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */