Line data Source code
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 : #ifndef INCLUDED_SD_SOURCE_UI_SLIDESORTER_CACHE_SLSCACHECOMPACTOR_HXX
21 : #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_CACHE_SLSCACHECOMPACTOR_HXX
22 :
23 : #include <sal/types.h>
24 : #include <vcl/timer.hxx>
25 : #include <memory>
26 :
27 : namespace sd { namespace slidesorter { namespace cache {
28 :
29 : class BitmapCache;
30 :
31 : /** This is an interface class whose implementations are created via the
32 : Create() factory method.
33 : */
34 : class CacheCompactor
35 : {
36 : public:
37 112 : virtual ~CacheCompactor (void) {};
38 :
39 : /** Create a new instance of the CacheCompactor interface class. The
40 : type of compaction algorithm used depends on values from the
41 : configuration: the SlideSorter/PreviewCache/CompactionPolicy
42 : property of the Impress.xcs file currently supports the values
43 : "None" and "Compress". With the later the CompressionPolicy
44 : property is evaluated which implementation of the BitmapCompress
45 : interface class to use as bitmap compressor.
46 : @param rCache
47 : The bitmap cache on which to operate.
48 : @param nMaximalCacheSize
49 : The total number of bytes the off-screen bitmaps in the cache
50 : may have. When the Run() method is (indirectly) called the
51 : compactor tries to reduce that summed size of off-screen bitmaps
52 : under this number. However, it is not guaranteed that this
53 : works in all cases.
54 : */
55 : static ::std::unique_ptr<CacheCompactor> Create (
56 : BitmapCache& rCache,
57 : sal_Int32 nMaximalCacheSize);
58 :
59 : /** Request a compaction of the off-screen previews in the bitmap
60 : cache. This calls via a timer the Run() method.
61 : */
62 : virtual void RequestCompaction (void);
63 :
64 : protected:
65 : BitmapCache& mrCache;
66 : sal_Int32 mnMaximalCacheSize;
67 :
68 : CacheCompactor(
69 : BitmapCache& rCache,
70 : sal_Int32 nMaximalCacheSize);
71 :
72 : /** This method actually tries to reduce the total number of bytes used
73 : by the off-screen preview bitmaps.
74 : */
75 : virtual void Run (void) = 0;
76 :
77 : private:
78 : /** This timer is used to collect calles to RequestCompaction() and
79 : eventually call Run().
80 : */
81 : Timer maCompactionTimer;
82 : bool mbIsCompactionRunning;
83 : DECL_LINK(CompactionCallback, void *);
84 : };
85 :
86 : } } } // end of namespace ::sd::slidesorter::cache
87 :
88 : #endif
89 :
90 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|