LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/cache - SlsBitmapCache.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 2 0.0 %
Date: 2014-11-03 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          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_SLSBITMAPCACHE_HXX
      21             : #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_CACHE_SLSBITMAPCACHE_HXX
      22             : 
      23             : class SdrPage;
      24             : 
      25             : #include <vcl/bitmapex.hxx>
      26             : #include <osl/mutex.hxx>
      27             : #include <boost/shared_ptr.hpp>
      28             : #include <boost/unordered_map.hpp>
      29             : #include <boost/scoped_ptr.hpp>
      30             : 
      31             : namespace sd { namespace slidesorter { namespace cache {
      32             : 
      33             : class CacheCompactor;
      34             : class BitmapCompressor;
      35             : 
      36             : /** This low level cache is the actual bitmap container.  It supports a
      37             :     precious flag for every preview bitmap and keeps track of total sizes
      38             :     for all previews with/without this flag.  The precious flag is used by
      39             :     compaction algorithms to determine which previews may be compressed or
      40             :     even discarded and which have to remain in their original form.  The
      41             :     precious flag is usually set for the visible previews.
      42             : 
      43             :     Additionally to the actual preview there is an optional marked preview.
      44             :     This is used for slides excluded from the slide show which have a preview
      45             :     that shows a mark (some sort of bitmap overlay) to that effect.
      46             : */
      47             : class BitmapCache
      48             : {
      49             : public:
      50             :     /** The key for looking up preview bitmaps is a pointer to an SdrPage
      51             :         object.  The prior use of PageObjectViewObjectContact objects (which
      52             :         ultimatly use them) turned out to be less suitable because their
      53             :         life time is shorter then that of the page objects.  Frequent
      54             :         destruction and re-creation of the preview bitmaps was the result.
      55             :     */
      56             :     typedef const SdrPage* CacheKey;
      57             :     class CacheEntry;
      58             :     class CacheBitmapContainer;
      59             :     typedef ::std::vector<CacheKey> CacheIndex;
      60             : 
      61             :     /** Create a new cache for bitmap objects.
      62             :         @param nMaximalNormalCacheSize
      63             :             When a size larger then zero is given then that size is used.
      64             :             Otherwise the default value from the configuration is used.
      65             :             When that does not exist either then a internal default value is
      66             :             used.
      67             :     */
      68             :     BitmapCache (const sal_Int32 nMaximalNormalCacheSize = 0);
      69             : 
      70             :     /** The destructor clears the cache and relases all bitmaps still in it.
      71             :     */
      72             :     ~BitmapCache (void);
      73             : 
      74             :     /** Remove all preview bitmaps from the cache.  After this call the
      75             :         cache is empty.
      76             :     */
      77             :     void Clear (void);
      78             : 
      79             :     /** Return <TRUE/> when the cache is full, i.e. the cache compactor had
      80             :         to be run.
      81             :     */
      82           0 :     bool IsFull (void) const { return mbIsFull;}
      83             : 
      84             :     /** Return the memory size that is occupied by all non-precious bitmaps
      85             :         in the cache.
      86             :     */
      87           0 :     sal_Int32 GetSize (void) { return mnNormalCacheSize;}
      88             : 
      89             :     /** Return <TRUE/> when a preview bitmap exists for the given key.
      90             :     */
      91             :     bool HasBitmap (const CacheKey& rKey);
      92             : 
      93             :     /** Return <TRUE/> when a preview bitmap exists for the given key and
      94             :         when it is up-to-date.
      95             :     */
      96             :     bool BitmapIsUpToDate (const CacheKey& rKey);
      97             : 
      98             :     /** Return the preview bitmap for the given contact object.
      99             :     */
     100             :     Bitmap GetBitmap (const CacheKey& rKey);
     101             : 
     102             :     /** Return the marked preview bitmap for the given contact object.
     103             :     */
     104             :     Bitmap GetMarkedBitmap (const CacheKey& rKey);
     105             : 
     106             :     /** Release the reference to the preview bitmap that is associated with
     107             :         the given key.
     108             :     */
     109             :     void ReleaseBitmap (const CacheKey& rKey);
     110             : 
     111             :     /** Mark the specified preview bitmap as not being up-to-date
     112             :         anymore.
     113             :         @return
     114             :             When the key references a page in the cache then
     115             :             return <TRUE/>.  When the key is not known then <FALSE/>
     116             :             is returned.
     117             :     */
     118             :     bool InvalidateBitmap (const CacheKey& rKey);
     119             : 
     120             :     /** Mark all preview bitmaps as not being up-to-date anymore.
     121             :     */
     122             :     void InvalidateCache (void);
     123             : 
     124             :     /** Add or replace a bitmap for the given key.
     125             :     */
     126             :     void SetBitmap (
     127             :         const CacheKey& rKey,
     128             :         const Bitmap& rPreview,
     129             :         bool bIsPrecious);
     130             : 
     131             :     /** Add or replace a marked bitmap for the given key.
     132             :     */
     133             :     void SetMarkedBitmap (
     134             :         const CacheKey& rKey,
     135             :         const Bitmap& rPreview);
     136             : 
     137             :     /** Mark the specified preview bitmap as precious, i.e. that it must not
     138             :         be compressed or otherwise removed from the cache.
     139             :     */
     140             :     void SetPrecious (const CacheKey& rKey, bool bIsPrecious);
     141             : 
     142             :     /** Calculate the cache size.  This should rarely be necessary because
     143             :         the cache size is tracked with each modification of preview
     144             :         bitmaps.
     145             :     */
     146             :     void ReCalculateTotalCacheSize (void);
     147             : 
     148             :     /** Use the previews in the given cache to initialize missing previews.
     149             :     */
     150             :     void Recycle (const BitmapCache& rCache);
     151             : 
     152             :     /** Return a list of sorted cache keys that represent an index into (a
     153             :         part of) the cache.  The entries of the index are sorted according
     154             :         to last access times with the least recently access time first.
     155             :         @param bIncludePrecious
     156             :             When this flag is <TRUE/> entries with the precious flag set are
     157             :             included in the index.  When the flag is <FALSE/> these entries
     158             :             are omitted.
     159             :         @param bIncludeNoPreview
     160             :             When this flag is <TRUE/> entries with that have no preview
     161             :             bitmaps are included in the index.  When the flag is <FALSE/> these entries
     162             :             are omitted.
     163             :     */
     164             :     ::std::unique_ptr<CacheIndex> GetCacheIndex (
     165             :         bool bIncludePrecious,
     166             :         bool bIncludeNoPreview) const;
     167             : 
     168             :     /** Compress the specified preview bitmap with the given bitmap
     169             :         compressor.  A reference to the compressor is stored for later
     170             :         decompression.
     171             :     */
     172             :     void Compress (
     173             :         const CacheKey& rKey,
     174             :         const ::boost::shared_ptr<BitmapCompressor>& rpCompressor);
     175             : 
     176             : private:
     177             :     mutable ::osl::Mutex maMutex;
     178             : 
     179             :     ::boost::scoped_ptr<CacheBitmapContainer> mpBitmapContainer;
     180             : 
     181             :     /** Total size of bytes that are occupied by bitmaps in the cache for
     182             :         whom the slides are currently not inside the visible area.
     183             :     */
     184             :     sal_Int32 mnNormalCacheSize;
     185             : 
     186             :     /** Total size of bytes that are occupied by bitmaps in the cache for
     187             :         whom the slides are currently visible.
     188             :     */
     189             :     sal_Int32 mnPreciousCacheSize;
     190             : 
     191             :     /** At the moment the access time is not an actual time or date value
     192             :         but a counter that is increased with every access.  It thus defines
     193             :         the same ordering as a true time.
     194             :     */
     195             :     sal_Int32 mnCurrentAccessTime;
     196             : 
     197             :     /** The maximal cache size for the off-screen preview bitmaps.  When
     198             :         mnNormalCacheSize grows larger than this value then the
     199             :         mpCacheCompactor member is used to reduce the cache size.
     200             :     */
     201             :     sal_Int32 mnMaximalNormalCacheSize;
     202             : 
     203             :     /** The cache compactor is used to reduce the number of bytes used by
     204             :         off-screen preview bitmaps.
     205             :     */
     206             :     ::std::unique_ptr<CacheCompactor> mpCacheCompactor;
     207             : 
     208             :     /** This flag stores if the cache is or recently was full, i.e. the
     209             :         cache compactor has or had to be run in order to reduce the cache
     210             :         size to the allowed value.
     211             :     */
     212             :     bool mbIsFull;
     213             : 
     214             :     /** Update mnNormalCacheSize or mnPreciousCacheSize according to the
     215             :         precious flag of the specified preview bitmap and the specified
     216             :         operation.
     217             :     */
     218             :     enum CacheOperation { ADD, REMOVE };
     219             :     void UpdateCacheSize (const CacheEntry& rKey, CacheOperation eOperation);
     220             : };
     221             : 
     222             : } } } // end of namespace ::sd::slidesorter::cache
     223             : 
     224             : #endif
     225             : 
     226             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10