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 _GRFCACHE_HXX 25 #define _GRFCACHE_HXX 26 27 #include <tools/list.hxx> 28 #include <vcl/graph.hxx> 29 #include <vcl/timer.hxx> 30 #include <svtools/grfmgr.hxx> 31 32 // ----------------------- 33 // - GraphicManagerCache - 34 // ----------------------- 35 36 class GraphicCacheEntry; 37 38 class GraphicCache 39 { 40 private: 41 42 GraphicManager& mrMgr; 43 Timer maReleaseTimer; 44 List maGraphicCache; 45 List maDisplayCache; 46 sal_uLong mnReleaseTimeoutSeconds; 47 sal_uLong mnMaxDisplaySize; 48 sal_uLong mnMaxObjDisplaySize; 49 sal_uLong mnUsedDisplaySize; 50 51 sal_Bool ImplFreeDisplayCacheSpace( sal_uLong nSizeToFree ); 52 GraphicCacheEntry* ImplGetCacheEntry( const GraphicObject& rObj ); 53 54 55 DECL_LINK( ReleaseTimeoutHdl, Timer* pTimer ); 56 57 public: 58 59 GraphicCache( GraphicManager& rMgr, 60 sal_uLong nDisplayCacheSize = 10000000UL, 61 sal_uLong nMaxObjDisplayCacheSize = 2400000UL ); 62 ~GraphicCache(); 63 64 public: 65 66 void AddGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute, 67 const ByteString* pID, const GraphicObject* pCopyObj ); 68 void ReleaseGraphicObject( const GraphicObject& rObj ); 69 70 void GraphicObjectWasSwappedOut( const GraphicObject& rObj ); 71 sal_Bool FillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute ); 72 void GraphicObjectWasSwappedIn( const GraphicObject& rObj ); 73 74 ByteString GetUniqueID( const GraphicObject& rObj ) const; 75 76 public: 77 78 void SetMaxDisplayCacheSize( sal_uLong nNewCacheSize ); GetMaxDisplayCacheSize() const79 sal_uLong GetMaxDisplayCacheSize() const { return mnMaxDisplaySize; }; 80 81 void SetMaxObjDisplayCacheSize( sal_uLong nNewMaxObjSize, sal_Bool bDestroyGreaterCached = sal_False ); GetMaxObjDisplayCacheSize() const82 sal_uLong GetMaxObjDisplayCacheSize() const { return mnMaxObjDisplaySize; } 83 GetUsedDisplayCacheSize() const84 sal_uLong GetUsedDisplayCacheSize() const { return mnUsedDisplaySize; } GetFreeDisplayCacheSize() const85 sal_uLong GetFreeDisplayCacheSize() const { return( mnMaxDisplaySize - mnUsedDisplaySize ); } 86 87 void SetCacheTimeout( sal_uLong nTimeoutSeconds ); GetCacheTimeout() const88 sal_uLong GetCacheTimeout() const { return mnReleaseTimeoutSeconds; } 89 90 void ClearDisplayCache(); 91 sal_Bool IsDisplayCacheable( OutputDevice* pOut, const Point& rPt, const Size& rSz, 92 const GraphicObject& rObj, const GraphicAttr& rAttr ) const; 93 sal_Bool IsInDisplayCache( OutputDevice* pOut, const Point& rPt, const Size& rSz, 94 const GraphicObject& rObj, const GraphicAttr& rAttr ) const; 95 sal_Bool CreateDisplayCacheObj( OutputDevice* pOut, const Point& rPt, const Size& rSz, 96 const GraphicObject& rObj, const GraphicAttr& rAttr, 97 const BitmapEx& rBmpEx ); 98 sal_Bool CreateDisplayCacheObj( OutputDevice* pOut, const Point& rPt, const Size& rSz, 99 const GraphicObject& rObj, const GraphicAttr& rAttr, 100 const GDIMetaFile& rMtf ); 101 sal_Bool DrawDisplayCacheObj( OutputDevice* pOut, const Point& rPt, const Size& rSz, 102 const GraphicObject& rObj, const GraphicAttr& rAttr ); 103 }; 104 105 #endif // _GRFCACHE_HXX 106