1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _GRFCACHE_HXX
29 #define _GRFCACHE_HXX
30 
31 #include <tools/list.hxx>
32 #include <vcl/graph.hxx>
33 #include <vcl/timer.hxx>
34 #include <svtools/grfmgr.hxx>
35 
36 // -----------------------
37 // - GraphicManagerCache -
38 // -----------------------
39 
40 class GraphicCacheEntry;
41 
42 class GraphicCache
43 {
44 private:
45 
46 	GraphicManager&				mrMgr;
47     Timer                       maReleaseTimer;
48 	List						maGraphicCache;
49 	List						maDisplayCache;
50     sal_uLong                       mnReleaseTimeoutSeconds;
51 	sal_uLong						mnMaxDisplaySize;
52 	sal_uLong						mnMaxObjDisplaySize;
53 	sal_uLong						mnUsedDisplaySize;
54 
55 	sal_Bool						ImplFreeDisplayCacheSpace( sal_uLong nSizeToFree );
56 	GraphicCacheEntry*			ImplGetCacheEntry( const GraphicObject& rObj );
57 
58 
59                                 DECL_LINK( ReleaseTimeoutHdl, Timer* pTimer );
60 
61 public:
62 
63 								GraphicCache( GraphicManager& rMgr,
64 											  sal_uLong nDisplayCacheSize = 10000000UL,
65 											  sal_uLong nMaxObjDisplayCacheSize = 2400000UL );
66 								~GraphicCache();
67 
68 public:
69 
70 	void						AddGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute,
71                                                   const ByteString* pID, const GraphicObject* pCopyObj );
72 	void						ReleaseGraphicObject( const GraphicObject& rObj );
73 
74 	void						GraphicObjectWasSwappedOut( const GraphicObject& rObj );
75 	sal_Bool						FillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute );
76 	void						GraphicObjectWasSwappedIn( const GraphicObject& rObj );
77 
78 	ByteString					GetUniqueID( const GraphicObject& rObj ) const;
79 
80 public:
81 
82 	void						SetMaxDisplayCacheSize( sal_uLong nNewCacheSize );
83 	sal_uLong						GetMaxDisplayCacheSize() const { return mnMaxDisplaySize; };
84 
85 	void						SetMaxObjDisplayCacheSize( sal_uLong nNewMaxObjSize, sal_Bool bDestroyGreaterCached = sal_False );
86 	sal_uLong						GetMaxObjDisplayCacheSize() const { return mnMaxObjDisplaySize; }
87 
88 	sal_uLong						GetUsedDisplayCacheSize() const { return mnUsedDisplaySize; }
89 	sal_uLong						GetFreeDisplayCacheSize() const { return( mnMaxDisplaySize - mnUsedDisplaySize ); }
90 
91     void                        SetCacheTimeout( sal_uLong nTimeoutSeconds );
92     sal_uLong                       GetCacheTimeout() const { return mnReleaseTimeoutSeconds; }
93 
94 	void						ClearDisplayCache();
95 	sal_Bool						IsDisplayCacheable( OutputDevice* pOut, const Point& rPt, const Size& rSz,
96 													const GraphicObject& rObj, const GraphicAttr& rAttr ) const;
97 	sal_Bool						IsInDisplayCache( OutputDevice* pOut, const Point& rPt, const Size& rSz,
98 												  const GraphicObject& rObj, const GraphicAttr& rAttr ) const;
99 	sal_Bool						CreateDisplayCacheObj( OutputDevice* pOut, const Point& rPt, const Size& rSz,
100 													   const GraphicObject& rObj, const GraphicAttr& rAttr,
101 													   const BitmapEx& rBmpEx );
102 	sal_Bool						CreateDisplayCacheObj( OutputDevice* pOut, const Point& rPt, const Size& rSz,
103 													   const GraphicObject& rObj, const GraphicAttr& rAttr,
104 													   const GDIMetaFile& rMtf );
105 	sal_Bool						DrawDisplayCacheObj( OutputDevice* pOut, const Point& rPt, const Size& rSz,
106 													 const GraphicObject& rObj, const GraphicAttr& rAttr );
107 };
108 
109 #endif // _GRFCACHE_HXX
110