1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_SLIDESORTER_CACHE_COMPACTOR_HXX
25 #define SD_SLIDESORTER_CACHE_COMPACTOR_HXX
26 
27 #include <sal/types.h>
28 #include <vcl/timer.hxx>
29 #include <memory>
30 
31 namespace sd { namespace slidesorter { namespace cache {
32 
33 class BitmapCache;
34 class BitmapCompressor;
35 
36 /** This is an interface class whose implementations are created via the
37     Create() factory method.
38 */
39 class CacheCompactor
40 {
41 public:
~CacheCompactor(void)42     virtual ~CacheCompactor (void) {};
43 
44     /** Create a new instance of the CacheCompactor interface class.  The
45         type of compaction algorithm used depends on values from the
46         configuration: the SlideSorter/PreviewCache/CompactionPolicy
47         property of the Impress.xcs file currently supports the values
48         "None" and "Compress".  With the later the CompressionPolicy
49         property is evaluated which implementation of the BitmapCompress
50         interface class to use as bitmap compressor.
51         @param rCache
52             The bitmap cache on which to operate.
53         @param nMaximalCacheSize
54             The total number of bytes the off-screen bitmaps in the cache
55             may have.  When the Run() method is (indirectly) called the
56             compactor tries to reduce that summed size of off-screen bitmaps
57             under this number.  However, it is not guaranteed that this
58             works in all cases.
59     */
60     static ::std::auto_ptr<CacheCompactor> Create (
61         BitmapCache& rCache,
62         sal_Int32 nMaximalCacheSize);
63 
64     /** Request a compaction of the off-screen previews in the bitmap
65         cache.  This calls via a timer the Run() method.
66     */
67     virtual void RequestCompaction (void);
68 
69 protected:
70     BitmapCache& mrCache;
71     sal_Int32 mnMaximalCacheSize;
72 
73     CacheCompactor(
74         BitmapCache& rCache,
75         sal_Int32 nMaximalCacheSize);
76 
77     /** This method actually tries to reduce the total number of bytes used
78         by the off-screen preview bitmaps.
79     */
80     virtual void Run (void) = 0;
81 
82 private:
83     /** This timer is used to collect calles to RequestCompaction() and
84         eventually call Run().
85     */
86     Timer maCompactionTimer;
87     bool mbIsCompactionRunning;
88     DECL_LINK(CompactionCallback, Timer*);
89 };
90 
91 
92 
93 
94 } } } // end of namespace ::sd::slidesorter::cache
95 
96 #endif
97