bitmapcache.h

Go to the documentation of this file.
00001 // $Id: bitmapcache.h 751 2006-03-31 15:43:49Z alex $
00002 // BitmapCache.h: interface for the CBitmapCache class.
00003 //
00005 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00006 ================================XARAHEADERSTART===========================
00007  
00008                Xara LX, a vector drawing and manipulation program.
00009                     Copyright (C) 1993-2006 Xara Group Ltd.
00010        Copyright on certain contributions may be held in joint with their
00011               respective authors. See AUTHORS file for details.
00012 
00013 LICENSE TO USE AND MODIFY SOFTWARE
00014 ----------------------------------
00015 
00016 This file is part of Xara LX.
00017 
00018 Xara LX is free software; you can redistribute it and/or modify it
00019 under the terms of the GNU General Public License version 2 as published
00020 by the Free Software Foundation.
00021 
00022 Xara LX and its component source files are distributed in the hope
00023 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00024 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00025 See the GNU General Public License for more details.
00026 
00027 You should have received a copy of the GNU General Public License along
00028 with Xara LX (see the file GPL in the root directory of the
00029 distribution); if not, write to the Free Software Foundation, Inc., 51
00030 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00031 
00032 
00033 ADDITIONAL RIGHTS
00034 -----------------
00035 
00036 Conditional upon your continuing compliance with the GNU General Public
00037 License described above, Xara Group Ltd grants to you certain additional
00038 rights. 
00039 
00040 The additional rights are to use, modify, and distribute the software
00041 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00042 library and any other such library that any version of Xara LX relased
00043 by Xara Group Ltd requires in order to compile and execute, including
00044 the static linking of that library to XaraLX. In the case of the
00045 "CDraw" library, you may satisfy obligation under the GNU General Public
00046 License to provide source code by providing a binary copy of the library
00047 concerned and a copy of the license accompanying it.
00048 
00049 Nothing in this section restricts any of the rights you have under
00050 the GNU General Public License.
00051 
00052 
00053 SCOPE OF LICENSE
00054 ----------------
00055 
00056 This license applies to this program (XaraLX) and its constituent source
00057 files only, and does not necessarily apply to other Xara products which may
00058 in part share the same code base, and are subject to their own licensing
00059 terms.
00060 
00061 This license does not apply to files in the wxXtra directory, which
00062 are built into a separate library, and are subject to the wxWindows
00063 license contained within that directory in the file "WXXTRA-LICENSE".
00064 
00065 This license does not apply to the binary libraries (if any) within
00066 the "libs" directory, which are subject to a separate license contained
00067 within that directory in the file "LIBS-LICENSE".
00068 
00069 
00070 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00071 ----------------------------------------------
00072 
00073 Subject to the terms of the GNU Public License (see above), you are
00074 free to do whatever you like with your modifications. However, you may
00075 (at your option) wish contribute them to Xara's source tree. You can
00076 find details of how to do this at:
00077   http://www.xaraxtreme.org/developers/
00078 
00079 Prior to contributing your modifications, you will need to complete our
00080 contributor agreement. This can be found at:
00081   http://www.xaraxtreme.org/developers/contribute/
00082 
00083 Please note that Xara will not accept modifications which modify any of
00084 the text between the start and end of this header (marked
00085 XARAHEADERSTART and XARAHEADEREND).
00086 
00087 
00088 MARKS
00089 -----
00090 
00091 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00092 designs are registered or unregistered trademarks, design-marks, and/or
00093 service marks of Xara Group Ltd. All rights in these marks are reserved.
00094 
00095 
00096       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00097                         http://www.xara.com/
00098 
00099 =================================XARAHEADEREND============================
00100  */
00101 
00102 #if !defined(AFX_BITMAPCACHE_H__41BFBD9B_A02E_4205_AE0A_4F6A5E0DC7D0__INCLUDED_)
00103 #define AFX_BITMAPCACHE_H__41BFBD9B_A02E_4205_AE0A_4F6A5E0DC7D0__INCLUDED_
00104 
00105 //#include <afxtempl.h>
00106 #include "bitmapcachekey.h"
00107 #include "bitmap.h"
00108 
00109 #define CACHEPRIORITY_NORMAL 0
00110 #define CACHEPRIORITY_TEMPBITMAP_LOW 0
00111 #define CACHEPRIORITY_TEMPBITMAP_HIGH 1000
00112 #define CACHEPRIORITY_PERMANENT 8000
00113 
00114 
00115 class CCachedBitmap: public CCObject
00116 {
00117 public:
00118     CCachedBitmap();
00119     CCachedBitmap(LPBITMAPINFO pNewInfo, LPBYTE pNewBits, INT32 nNewPriority = CACHEPRIORITY_NORMAL);
00120     CCachedBitmap(const CCachedBitmap& cbmp);
00121     CCachedBitmap(UINT32 Width, UINT32 Height, UINT32 Depth, DocRect rect, INT32 nNewPriority = CACHEPRIORITY_NORMAL);
00122     ~CCachedBitmap();
00123 
00124     bool operator==(const CCachedBitmap& cbmp) const;
00125     const CCachedBitmap& operator=( const CCachedBitmap& cbmp );
00126 
00127     void            Release();
00128     CCachedBitmap   Copy();
00129     void            Transform(TransformBase& Trans);
00130     DocRect         GetCachedRect();
00131     void            SetCachedRect(DocRect r);
00132     void            SetCachedParallelogram(DocCoord* pCoords, UINT32 numCoords);
00133 
00134     BOOL            IsValid() const;
00135     UINT32          GetBitmapSize() const;
00136     BOOL            IsTransparent() const;
00137     UINT32          GetBPP() const;
00138 
00139 public:
00140     LPBITMAPINFO    pbmpInfo;
00141     LPBYTE          pbmpBits;
00142 //  DocRect         rectCachedRect;
00143     DocCoord        coord0;             // Three coords representing a parallelogram alow the bitmap to be transformed
00144     DocCoord        coord1;             // (mainly for use with destructive liveffects but also good for quick blits
00145     DocCoord        coord2;             //  of cached info during dragging)
00146     INT32           nPriority;
00147     BOOL            bFullCoverage;      // TRUE when this bitmap fully covers the relevant object
00148 };
00149 
00150 
00151 // Declare global template-specific override for HashKey function...
00152 struct LessBitmapCacheKey
00153 {
00154   bool operator()(const CBitmapCacheKey &s1, const CBitmapCacheKey &s2) const
00155   {
00156       return s1.Hash() < s2.Hash();
00157   }
00158 };
00159 
00160 typedef std::map<CBitmapCacheKey, CCachedBitmap, LessBitmapCacheKey> CCacheKeyMap;
00161 
00162 class CBitmapCache
00163 {
00164 public:
00165     CBitmapCache();
00166 //  virtual ~CBitmapCache();
00167 
00168 // Methods
00169 public:
00170     void            Initialise();
00171     void            DeInitialise();
00172 
00173     void            StoreBitmap(const CBitmapCacheKey& key, const CCachedBitmap& bitmap);
00174 //  CCachedBitmap   FindBitmap(const CBitmapCacheKey& key);
00175     CCachedBitmap   RemoveBitmap(const CBitmapCacheKey& key);
00176     BOOL            RemoveAllOwnedBitmaps(  const CBitmapCacheKey& key,
00177                                             const BOOL bOpaqueOnly = FALSE,
00178                                             const INT32 maxpriority = CACHEPRIORITY_TEMPBITMAP_HIGH);
00179     void            RemoveLowPriorityBitmaps(const INT32 maxpriority = CACHEPRIORITY_TEMPBITMAP_HIGH);
00180     CCachedBitmap   FindNextOwnedBitmap(CCacheKeyMap::iterator &pos,
00181                                         CBitmapCacheKey &key,
00182                                         const BOOL bOpaqueOnly = FALSE,
00183                                         const INT32 maxpriority = CACHEPRIORITY_TEMPBITMAP_HIGH);
00184     void            SetMaximumDataSize(UINT64 maxsize);
00185     UINT64          GetMaximumDataSize();
00186     UINT32          GetCurrentDataSize();
00187 
00188 #ifdef _DEBUG
00189     void            DebugDump();
00190 #endif
00191 
00192     // Some CMap emulation functions
00193     BOOL Lookup( const CBitmapCacheKey &Key, CCachedBitmap &CachedBitmap )
00194     {
00195         CCacheKeyMap::iterator iter = m_map.find( Key );
00196         if( m_map.end() == iter )
00197             return false;
00198         
00199         CachedBitmap = iter->second;
00200         return true;
00201     }
00202 
00203     CCacheKeyMap::iterator GetStartPosition() {return m_map.begin();}
00204 
00205 // Public helper functions
00206 public:
00207     static UINT64 CalcRecommendedMaximumDataSize();
00208 
00209 // Private helper functions
00210 private:
00211 //  UINT32          PrimeAbove(UINT32 number);
00212     CCachedBitmap   RemoveRandomBitmap(const INT32 maxpriority = CACHEPRIORITY_TEMPBITMAP_HIGH);            // Cache removal policy helper
00213 
00214 // Internal members
00215 private:
00216     CCacheKeyMap    m_map;
00217 
00218     UINT64      m_lMaxDataSize;
00219     UINT32          m_lCurrentDataSize;
00220     UINT32          m_lMaxHashTableLoad;
00221 
00222 // Preferences
00223     static INT32 CacheRAMPercent;           // Amount of free RAM to grab for cacheing
00224 
00225 };
00226 
00227 #endif // !defined(AFX_BITMAPCACHE_H__41BFBD9B_A02E_4205_AE0A_4F6A5E0DC7D0__INCLUDED_)

Generated on Sat Nov 10 03:44:24 2007 for Camelot by  doxygen 1.4.4