15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file
55900e8ecSAndrew Rist * distributed with this work for additional information
65900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file
75900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at
105900e8ecSAndrew Rist *
115900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
125900e8ecSAndrew Rist *
135900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist * software distributed under the License is distributed on an
155900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist * KIND, either express or implied. See the License for the
175900e8ecSAndrew Rist * specific language governing permissions and limitations
185900e8ecSAndrew Rist * under the License.
195900e8ecSAndrew Rist *
205900e8ecSAndrew Rist *************************************************************/
215900e8ecSAndrew Rist
225900e8ecSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <vos/timer.hxx>
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir #include <vcl/outdev.hxx>
30cdf0e10cSrcweir #include <tools/poly.hxx>
31cdf0e10cSrcweir #include "grfcache.hxx"
32ddde725dSArmin Le Grand #include <rtl/crc.h>
33cdf0e10cSrcweir #include <memory>
34cdf0e10cSrcweir
35cdf0e10cSrcweir // -----------
36cdf0e10cSrcweir // - Defines -
37cdf0e10cSrcweir // -----------
38cdf0e10cSrcweir
39cdf0e10cSrcweir #define RELEASE_TIMEOUT 10000
40cdf0e10cSrcweir #define MAX_BMP_EXTENT 4096
41cdf0e10cSrcweir
42cdf0e10cSrcweir // -----------
43cdf0e10cSrcweir // - statics -
44cdf0e10cSrcweir // -----------
45cdf0e10cSrcweir
46cdf0e10cSrcweir static const char aHexData[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
47cdf0e10cSrcweir
48cdf0e10cSrcweir // -------------
49cdf0e10cSrcweir // - GraphicID -
50cdf0e10cSrcweir // -------------
51cdf0e10cSrcweir
52cdf0e10cSrcweir class GraphicID
53cdf0e10cSrcweir {
54cdf0e10cSrcweir private:
55cdf0e10cSrcweir
56cdf0e10cSrcweir sal_uInt32 mnID1;
57cdf0e10cSrcweir sal_uInt32 mnID2;
58cdf0e10cSrcweir sal_uInt32 mnID3;
59cdf0e10cSrcweir sal_uInt32 mnID4;
60cdf0e10cSrcweir
61cdf0e10cSrcweir GraphicID();
62cdf0e10cSrcweir
63cdf0e10cSrcweir public:
64cdf0e10cSrcweir
65cdf0e10cSrcweir
66cdf0e10cSrcweir GraphicID( const GraphicObject& rObj );
~GraphicID()67cdf0e10cSrcweir ~GraphicID() {}
68cdf0e10cSrcweir
operator ==(const GraphicID & rID) const69cdf0e10cSrcweir sal_Bool operator==( const GraphicID& rID ) const
70cdf0e10cSrcweir {
71cdf0e10cSrcweir return( rID.mnID1 == mnID1 && rID.mnID2 == mnID2 &&
72cdf0e10cSrcweir rID.mnID3 == mnID3 && rID.mnID4 == mnID4 );
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
75cdf0e10cSrcweir ByteString GetIDString() const;
IsEmpty() const76cdf0e10cSrcweir sal_Bool IsEmpty() const { return( 0 == mnID4 ); }
77cdf0e10cSrcweir };
78cdf0e10cSrcweir
79cdf0e10cSrcweir // -----------------------------------------------------------------------------
80cdf0e10cSrcweir
GraphicID(const GraphicObject & rObj)81cdf0e10cSrcweir GraphicID::GraphicID( const GraphicObject& rObj )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir const Graphic& rGraphic = rObj.GetGraphic();
84cdf0e10cSrcweir
85cdf0e10cSrcweir mnID1 = ( (sal_uLong) rGraphic.GetType() ) << 28;
86cdf0e10cSrcweir
87cdf0e10cSrcweir switch( rGraphic.GetType() )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir case( GRAPHIC_BITMAP ):
90cdf0e10cSrcweir {
91ddde725dSArmin Le Grand if(rGraphic.getSvgData().get())
92ddde725dSArmin Le Grand {
93ddde725dSArmin Le Grand const SvgDataPtr& rSvgDataPtr = rGraphic.getSvgData();
94ddde725dSArmin Le Grand const basegfx::B2DRange& rRange = rSvgDataPtr->getRange();
95ddde725dSArmin Le Grand
96ddde725dSArmin Le Grand mnID1 |= rSvgDataPtr->getSvgDataArrayLength();
97ddde725dSArmin Le Grand mnID2 = basegfx::fround(rRange.getWidth());
98ddde725dSArmin Le Grand mnID3 = basegfx::fround(rRange.getHeight());
99ddde725dSArmin Le Grand mnID4 = rtl_crc32(0, rSvgDataPtr->getSvgDataArray().get(), rSvgDataPtr->getSvgDataArrayLength());
100ddde725dSArmin Le Grand }
101ddde725dSArmin Le Grand else if( rGraphic.IsAnimated() )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir const Animation aAnimation( rGraphic.GetAnimation() );
104cdf0e10cSrcweir
105cdf0e10cSrcweir mnID1 |= ( aAnimation.Count() & 0x0fffffff );
106cdf0e10cSrcweir mnID2 = aAnimation.GetDisplaySizePixel().Width();
107cdf0e10cSrcweir mnID3 = aAnimation.GetDisplaySizePixel().Height();
108cdf0e10cSrcweir mnID4 = rGraphic.GetChecksum();
109cdf0e10cSrcweir }
110cdf0e10cSrcweir else
111cdf0e10cSrcweir {
112cdf0e10cSrcweir const BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
113cdf0e10cSrcweir
114cdf0e10cSrcweir mnID1 |= ( ( ( (sal_uLong) aBmpEx.GetTransparentType() << 8 ) | ( aBmpEx.IsAlpha() ? 1 : 0 ) ) & 0x0fffffff );
115cdf0e10cSrcweir mnID2 = aBmpEx.GetSizePixel().Width();
116cdf0e10cSrcweir mnID3 = aBmpEx.GetSizePixel().Height();
117cdf0e10cSrcweir mnID4 = rGraphic.GetChecksum();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir }
120cdf0e10cSrcweir break;
121cdf0e10cSrcweir
122cdf0e10cSrcweir case( GRAPHIC_GDIMETAFILE ):
123cdf0e10cSrcweir {
124cdf0e10cSrcweir const GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
125cdf0e10cSrcweir
126cdf0e10cSrcweir mnID1 |= ( aMtf.GetActionCount() & 0x0fffffff );
127cdf0e10cSrcweir mnID2 = aMtf.GetPrefSize().Width();
128cdf0e10cSrcweir mnID3 = aMtf.GetPrefSize().Height();
129cdf0e10cSrcweir mnID4 = rGraphic.GetChecksum();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir break;
132cdf0e10cSrcweir
133cdf0e10cSrcweir default:
134cdf0e10cSrcweir mnID2 = mnID3 = mnID4 = 0;
135cdf0e10cSrcweir break;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir // -----------------------------------------------------------------------------
140cdf0e10cSrcweir
GetIDString() const141cdf0e10cSrcweir ByteString GraphicID::GetIDString() const
142cdf0e10cSrcweir {
143cdf0e10cSrcweir ByteString aHexStr;
144cdf0e10cSrcweir sal_Char* pStr = aHexStr.AllocBuffer( 32 );
145cdf0e10cSrcweir sal_Int32 nShift;
146cdf0e10cSrcweir
147cdf0e10cSrcweir for( nShift = 28; nShift >= 0; nShift -= 4 )
148cdf0e10cSrcweir *pStr++ = aHexData[ ( mnID1 >> (sal_uInt32) nShift ) & 0xf ];
149cdf0e10cSrcweir
150cdf0e10cSrcweir for( nShift = 28; nShift >= 0; nShift -= 4 )
151cdf0e10cSrcweir *pStr++ = aHexData[ ( mnID2 >> (sal_uInt32) nShift ) & 0xf ];
152cdf0e10cSrcweir
153cdf0e10cSrcweir for( nShift = 28; nShift >= 0; nShift -= 4 )
154cdf0e10cSrcweir *pStr++ = aHexData[ ( mnID3 >> (sal_uInt32) nShift ) & 0xf ];
155cdf0e10cSrcweir
156cdf0e10cSrcweir for( nShift = 28; nShift >= 0; nShift -= 4 )
157cdf0e10cSrcweir *pStr++ = aHexData[ ( mnID4 >> (sal_uInt32) nShift ) & 0xf ];
158cdf0e10cSrcweir
159cdf0e10cSrcweir return aHexStr;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
162cdf0e10cSrcweir // ---------------------
163cdf0e10cSrcweir // - GraphicCacheEntry -
164cdf0e10cSrcweir // ---------------------
165cdf0e10cSrcweir
166cdf0e10cSrcweir class GraphicCacheEntry
167cdf0e10cSrcweir {
168cdf0e10cSrcweir private:
169cdf0e10cSrcweir
170cdf0e10cSrcweir List maGraphicObjectList;
171cdf0e10cSrcweir GraphicID maID;
172cdf0e10cSrcweir GfxLink maGfxLink;
173cdf0e10cSrcweir BitmapEx* mpBmpEx;
174cdf0e10cSrcweir GDIMetaFile* mpMtf;
175cdf0e10cSrcweir Animation* mpAnimation;
176ddde725dSArmin Le Grand sal_Bool mbSwappedAll;
177ddde725dSArmin Le Grand
178ddde725dSArmin Le Grand // SvgData support
179ddde725dSArmin Le Grand SvgDataPtr maSvgData;
180ddde725dSArmin Le Grand
181ddde725dSArmin Le Grand sal_Bool ImplInit( const GraphicObject& rObj );
ImplMatches(const GraphicObject & rObj) const182ddde725dSArmin Le Grand sal_Bool ImplMatches( const GraphicObject& rObj ) const { return( GraphicID( rObj ) == maID ); }
183cdf0e10cSrcweir void ImplFillSubstitute( Graphic& rSubstitute );
184cdf0e10cSrcweir
185cdf0e10cSrcweir public:
186cdf0e10cSrcweir
187cdf0e10cSrcweir GraphicCacheEntry( const GraphicObject& rObj );
188cdf0e10cSrcweir ~GraphicCacheEntry();
189cdf0e10cSrcweir
GetID() const190cdf0e10cSrcweir const GraphicID& GetID() const { return maID; }
191cdf0e10cSrcweir
192cdf0e10cSrcweir void AddGraphicObjectReference( const GraphicObject& rObj, Graphic& rSubstitute );
193cdf0e10cSrcweir sal_Bool ReleaseGraphicObjectReference( const GraphicObject& rObj );
GetGraphicObjectReferenceCount()194cdf0e10cSrcweir sal_uLong GetGraphicObjectReferenceCount() { return maGraphicObjectList.Count(); }
195cdf0e10cSrcweir sal_Bool HasGraphicObjectReference( const GraphicObject& rObj );
196cdf0e10cSrcweir
197cdf0e10cSrcweir void TryToSwapIn();
198cdf0e10cSrcweir void GraphicObjectWasSwappedOut( const GraphicObject& rObj );
199cdf0e10cSrcweir sal_Bool FillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute );
200cdf0e10cSrcweir void GraphicObjectWasSwappedIn( const GraphicObject& rObj );
201cdf0e10cSrcweir };
202cdf0e10cSrcweir
203cdf0e10cSrcweir // -----------------------------------------------------------------------------
204cdf0e10cSrcweir
GraphicCacheEntry(const GraphicObject & rObj)205cdf0e10cSrcweir GraphicCacheEntry::GraphicCacheEntry( const GraphicObject& rObj ) :
206cdf0e10cSrcweir maID ( rObj ),
207cdf0e10cSrcweir mpBmpEx ( NULL ),
208cdf0e10cSrcweir mpMtf ( NULL ),
209cdf0e10cSrcweir mpAnimation ( NULL ),
210ddde725dSArmin Le Grand mbSwappedAll ( true )
211cdf0e10cSrcweir {
212ddde725dSArmin Le Grand mbSwappedAll = !ImplInit(rObj);
213cdf0e10cSrcweir maGraphicObjectList.Insert( (void*) &rObj, LIST_APPEND );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir
216cdf0e10cSrcweir // -----------------------------------------------------------------------------
217cdf0e10cSrcweir
~GraphicCacheEntry()218cdf0e10cSrcweir GraphicCacheEntry::~GraphicCacheEntry()
219cdf0e10cSrcweir {
220cdf0e10cSrcweir DBG_ASSERT( !maGraphicObjectList.Count(), "GraphicCacheEntry::~GraphicCacheEntry(): Not all GraphicObjects are removed from this entry" );
221cdf0e10cSrcweir
222cdf0e10cSrcweir delete mpBmpEx;
223cdf0e10cSrcweir delete mpMtf;
224cdf0e10cSrcweir delete mpAnimation;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
227cdf0e10cSrcweir // -----------------------------------------------------------------------------
228cdf0e10cSrcweir
ImplInit(const GraphicObject & rObj)229cdf0e10cSrcweir sal_Bool GraphicCacheEntry::ImplInit( const GraphicObject& rObj )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir sal_Bool bRet;
232cdf0e10cSrcweir
233cdf0e10cSrcweir if( !rObj.IsSwappedOut() )
234cdf0e10cSrcweir {
235cdf0e10cSrcweir const Graphic& rGraphic = rObj.GetGraphic();
236cdf0e10cSrcweir
237cdf0e10cSrcweir if( mpBmpEx )
238cdf0e10cSrcweir delete mpBmpEx, mpBmpEx = NULL;
239cdf0e10cSrcweir
240cdf0e10cSrcweir if( mpMtf )
241cdf0e10cSrcweir delete mpMtf, mpMtf = NULL;
242cdf0e10cSrcweir
243cdf0e10cSrcweir if( mpAnimation )
244cdf0e10cSrcweir delete mpAnimation, mpAnimation = NULL;
245cdf0e10cSrcweir
246cdf0e10cSrcweir switch( rGraphic.GetType() )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir case( GRAPHIC_BITMAP ):
249cdf0e10cSrcweir {
250ddde725dSArmin Le Grand if(rGraphic.getSvgData().get())
251ddde725dSArmin Le Grand {
252ddde725dSArmin Le Grand maSvgData = rGraphic.getSvgData();
253ddde725dSArmin Le Grand }
254ddde725dSArmin Le Grand else if( rGraphic.IsAnimated() )
255ddde725dSArmin Le Grand {
256cdf0e10cSrcweir mpAnimation = new Animation( rGraphic.GetAnimation() );
257ddde725dSArmin Le Grand }
258cdf0e10cSrcweir else
259ddde725dSArmin Le Grand {
260cdf0e10cSrcweir mpBmpEx = new BitmapEx( rGraphic.GetBitmapEx() );
261ddde725dSArmin Le Grand }
262cdf0e10cSrcweir }
263cdf0e10cSrcweir break;
264cdf0e10cSrcweir
265cdf0e10cSrcweir case( GRAPHIC_GDIMETAFILE ):
266cdf0e10cSrcweir {
267cdf0e10cSrcweir mpMtf = new GDIMetaFile( rGraphic.GetGDIMetaFile() );
268cdf0e10cSrcweir }
269cdf0e10cSrcweir break;
270cdf0e10cSrcweir
271cdf0e10cSrcweir default:
272cdf0e10cSrcweir DBG_ASSERT( GetID().IsEmpty(), "GraphicCacheEntry::ImplInit: Could not initialize graphic! (=>KA)" );
273cdf0e10cSrcweir break;
274cdf0e10cSrcweir }
275cdf0e10cSrcweir
276cdf0e10cSrcweir if( rGraphic.IsLink() )
277cdf0e10cSrcweir maGfxLink = ( (Graphic&) rGraphic ).GetLink();
278cdf0e10cSrcweir else
279cdf0e10cSrcweir maGfxLink = GfxLink();
280cdf0e10cSrcweir
281cdf0e10cSrcweir bRet = sal_True;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir else
284cdf0e10cSrcweir bRet = sal_False;
285cdf0e10cSrcweir
286cdf0e10cSrcweir return bRet;
287cdf0e10cSrcweir }
288cdf0e10cSrcweir
289cdf0e10cSrcweir // -----------------------------------------------------------------------------
290cdf0e10cSrcweir
ImplFillSubstitute(Graphic & rSubstitute)291cdf0e10cSrcweir void GraphicCacheEntry::ImplFillSubstitute( Graphic& rSubstitute )
292cdf0e10cSrcweir {
293cdf0e10cSrcweir // create substitute for graphic;
294cdf0e10cSrcweir const Size aPrefSize( rSubstitute.GetPrefSize() );
295cdf0e10cSrcweir const MapMode aPrefMapMode( rSubstitute.GetPrefMapMode() );
296cdf0e10cSrcweir const Link aAnimationNotifyHdl( rSubstitute.GetAnimationNotifyHdl() );
297cdf0e10cSrcweir const String aDocFileName( rSubstitute.GetDocFileName() );
298cdf0e10cSrcweir const sal_uLong nDocFilePos = rSubstitute.GetDocFilePos();
299cdf0e10cSrcweir const GraphicType eOldType = rSubstitute.GetType();
300cdf0e10cSrcweir const sal_Bool bDefaultType = ( rSubstitute.GetType() == GRAPHIC_DEFAULT );
301cdf0e10cSrcweir
302cdf0e10cSrcweir if( rSubstitute.IsLink() && ( GFX_LINK_TYPE_NONE == maGfxLink.GetType() ) )
303cdf0e10cSrcweir maGfxLink = rSubstitute.GetLink();
304cdf0e10cSrcweir
305ddde725dSArmin Le Grand if(maSvgData.get())
306ddde725dSArmin Le Grand {
307ddde725dSArmin Le Grand rSubstitute = maSvgData;
308ddde725dSArmin Le Grand }
309ddde725dSArmin Le Grand else if( mpBmpEx )
310ddde725dSArmin Le Grand {
311cdf0e10cSrcweir rSubstitute = *mpBmpEx;
312ddde725dSArmin Le Grand }
313cdf0e10cSrcweir else if( mpAnimation )
314ddde725dSArmin Le Grand {
315cdf0e10cSrcweir rSubstitute = *mpAnimation;
316ddde725dSArmin Le Grand }
317cdf0e10cSrcweir else if( mpMtf )
318ddde725dSArmin Le Grand {
319cdf0e10cSrcweir rSubstitute = *mpMtf;
320ddde725dSArmin Le Grand }
321cdf0e10cSrcweir else
322ddde725dSArmin Le Grand {
323cdf0e10cSrcweir rSubstitute.Clear();
324ddde725dSArmin Le Grand }
325cdf0e10cSrcweir
326cdf0e10cSrcweir if( eOldType != GRAPHIC_NONE )
327cdf0e10cSrcweir {
328ddde725dSArmin Le Grand rSubstitute.SetPrefSize( aPrefSize );
329ddde725dSArmin Le Grand rSubstitute.SetPrefMapMode( aPrefMapMode );
330cdf0e10cSrcweir rSubstitute.SetAnimationNotifyHdl( aAnimationNotifyHdl );
331cdf0e10cSrcweir rSubstitute.SetDocFileName( aDocFileName, nDocFilePos );
332cdf0e10cSrcweir }
333cdf0e10cSrcweir
334cdf0e10cSrcweir if( GFX_LINK_TYPE_NONE != maGfxLink.GetType() )
335ddde725dSArmin Le Grand {
336cdf0e10cSrcweir rSubstitute.SetLink( maGfxLink );
337ddde725dSArmin Le Grand }
338cdf0e10cSrcweir
339cdf0e10cSrcweir if( bDefaultType )
340ddde725dSArmin Le Grand {
341cdf0e10cSrcweir rSubstitute.SetDefaultType();
342ddde725dSArmin Le Grand }
343cdf0e10cSrcweir }
344cdf0e10cSrcweir
345cdf0e10cSrcweir // -----------------------------------------------------------------------------
346cdf0e10cSrcweir
AddGraphicObjectReference(const GraphicObject & rObj,Graphic & rSubstitute)347cdf0e10cSrcweir void GraphicCacheEntry::AddGraphicObjectReference( const GraphicObject& rObj, Graphic& rSubstitute )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir if( mbSwappedAll )
350cdf0e10cSrcweir mbSwappedAll = !ImplInit( rObj );
351cdf0e10cSrcweir
352cdf0e10cSrcweir ImplFillSubstitute( rSubstitute );
353cdf0e10cSrcweir maGraphicObjectList.Insert( (void*) &rObj, LIST_APPEND );
354cdf0e10cSrcweir }
355cdf0e10cSrcweir
356cdf0e10cSrcweir // -----------------------------------------------------------------------------
357cdf0e10cSrcweir
ReleaseGraphicObjectReference(const GraphicObject & rObj)358cdf0e10cSrcweir sal_Bool GraphicCacheEntry::ReleaseGraphicObjectReference( const GraphicObject& rObj )
359cdf0e10cSrcweir {
360cdf0e10cSrcweir sal_Bool bRet = sal_False;
361cdf0e10cSrcweir
362cdf0e10cSrcweir for( void* pObj = maGraphicObjectList.First(); !bRet && pObj; pObj = maGraphicObjectList.Next() )
363cdf0e10cSrcweir {
364cdf0e10cSrcweir if( &rObj == (GraphicObject*) pObj )
365cdf0e10cSrcweir {
366cdf0e10cSrcweir maGraphicObjectList.Remove( pObj );
367cdf0e10cSrcweir bRet = sal_True;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir }
370cdf0e10cSrcweir
371cdf0e10cSrcweir return bRet;
372cdf0e10cSrcweir }
373cdf0e10cSrcweir
374cdf0e10cSrcweir // -----------------------------------------------------------------------------
375cdf0e10cSrcweir
HasGraphicObjectReference(const GraphicObject & rObj)376cdf0e10cSrcweir sal_Bool GraphicCacheEntry::HasGraphicObjectReference( const GraphicObject& rObj )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir sal_Bool bRet = sal_False;
379cdf0e10cSrcweir
380cdf0e10cSrcweir for( void* pObj = maGraphicObjectList.First(); !bRet && pObj; pObj = maGraphicObjectList.Next() )
381cdf0e10cSrcweir if( &rObj == (GraphicObject*) pObj )
382cdf0e10cSrcweir bRet = sal_True;
383cdf0e10cSrcweir
384cdf0e10cSrcweir return bRet;
385cdf0e10cSrcweir }
386cdf0e10cSrcweir
387cdf0e10cSrcweir // -----------------------------------------------------------------------------
388cdf0e10cSrcweir
TryToSwapIn()389cdf0e10cSrcweir void GraphicCacheEntry::TryToSwapIn()
390cdf0e10cSrcweir {
391cdf0e10cSrcweir if( mbSwappedAll && maGraphicObjectList.Count() )
392cdf0e10cSrcweir ( (GraphicObject*) maGraphicObjectList.First() )->FireSwapInRequest();
393cdf0e10cSrcweir }
394cdf0e10cSrcweir
395cdf0e10cSrcweir // -----------------------------------------------------------------------------
396cdf0e10cSrcweir
GraphicObjectWasSwappedOut(const GraphicObject &)397cdf0e10cSrcweir void GraphicCacheEntry::GraphicObjectWasSwappedOut( const GraphicObject& /*rObj*/ )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir mbSwappedAll = sal_True;
400cdf0e10cSrcweir
401cdf0e10cSrcweir for( void* pObj = maGraphicObjectList.First(); mbSwappedAll && pObj; pObj = maGraphicObjectList.Next() )
402cdf0e10cSrcweir if( !( (GraphicObject*) pObj )->IsSwappedOut() )
403cdf0e10cSrcweir mbSwappedAll = sal_False;
404cdf0e10cSrcweir
405cdf0e10cSrcweir if( mbSwappedAll )
406cdf0e10cSrcweir {
407cdf0e10cSrcweir delete mpBmpEx, mpBmpEx = NULL;
408cdf0e10cSrcweir delete mpMtf, mpMtf = NULL;
409cdf0e10cSrcweir delete mpAnimation, mpAnimation = NULL;
410*9333066cSArmin Le Grand
411*9333066cSArmin Le Grand // #119176# also reset SvgData
412*9333066cSArmin Le Grand maSvgData.reset();
413cdf0e10cSrcweir }
414cdf0e10cSrcweir }
415cdf0e10cSrcweir
416cdf0e10cSrcweir // -----------------------------------------------------------------------------
417cdf0e10cSrcweir
FillSwappedGraphicObject(const GraphicObject & rObj,Graphic & rSubstitute)418cdf0e10cSrcweir sal_Bool GraphicCacheEntry::FillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute )
419cdf0e10cSrcweir {
420cdf0e10cSrcweir sal_Bool bRet;
421cdf0e10cSrcweir
422cdf0e10cSrcweir if( !mbSwappedAll && rObj.IsSwappedOut() )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir ImplFillSubstitute( rSubstitute );
425cdf0e10cSrcweir bRet = sal_True;
426cdf0e10cSrcweir }
427cdf0e10cSrcweir else
428cdf0e10cSrcweir bRet = sal_False;
429cdf0e10cSrcweir
430cdf0e10cSrcweir return bRet;
431cdf0e10cSrcweir }
432cdf0e10cSrcweir
433cdf0e10cSrcweir // -----------------------------------------------------------------------------
434cdf0e10cSrcweir
GraphicObjectWasSwappedIn(const GraphicObject & rObj)435cdf0e10cSrcweir void GraphicCacheEntry::GraphicObjectWasSwappedIn( const GraphicObject& rObj )
436cdf0e10cSrcweir {
437cdf0e10cSrcweir if( mbSwappedAll )
438cdf0e10cSrcweir mbSwappedAll = !ImplInit( rObj );
439cdf0e10cSrcweir }
440cdf0e10cSrcweir
441cdf0e10cSrcweir // ----------------------------
442cdf0e10cSrcweir // - GraphicDisplayCacheEntry -
443cdf0e10cSrcweir // ----------------------------
444cdf0e10cSrcweir
445cdf0e10cSrcweir class GraphicDisplayCacheEntry
446cdf0e10cSrcweir {
447cdf0e10cSrcweir private:
448cdf0e10cSrcweir
449cdf0e10cSrcweir ::vos::TTimeValue maReleaseTime;
450cdf0e10cSrcweir const GraphicCacheEntry* mpRefCacheEntry;
451cdf0e10cSrcweir GDIMetaFile* mpMtf;
452cdf0e10cSrcweir BitmapEx* mpBmpEx;
453cdf0e10cSrcweir GraphicAttr maAttr;
454cdf0e10cSrcweir Size maOutSizePix;
455cdf0e10cSrcweir sal_uLong mnCacheSize;
456cdf0e10cSrcweir sal_uLong mnOutDevDrawMode;
457cdf0e10cSrcweir sal_uInt16 mnOutDevBitCount;
458cdf0e10cSrcweir
459cdf0e10cSrcweir public:
460cdf0e10cSrcweir
461cdf0e10cSrcweir static sal_uLong GetNeededSize( OutputDevice* pOut, const Point& rPt, const Size& rSz,
462cdf0e10cSrcweir const GraphicObject& rObj, const GraphicAttr& rAttr );
463cdf0e10cSrcweir
464cdf0e10cSrcweir public:
465cdf0e10cSrcweir
GraphicDisplayCacheEntry(const GraphicCacheEntry * pRefCacheEntry,OutputDevice * pOut,const Point & rPt,const Size & rSz,const GraphicObject & rObj,const GraphicAttr & rAttr,const BitmapEx & rBmpEx)466cdf0e10cSrcweir GraphicDisplayCacheEntry( const GraphicCacheEntry* pRefCacheEntry,
467cdf0e10cSrcweir OutputDevice* pOut, const Point& rPt, const Size& rSz,
468cdf0e10cSrcweir const GraphicObject& rObj, const GraphicAttr& rAttr,
469cdf0e10cSrcweir const BitmapEx& rBmpEx ) :
470cdf0e10cSrcweir mpRefCacheEntry( pRefCacheEntry ),
471cdf0e10cSrcweir mpMtf( NULL ), mpBmpEx( new BitmapEx( rBmpEx ) ),
472cdf0e10cSrcweir maAttr( rAttr ), maOutSizePix( pOut->LogicToPixel( rSz ) ),
473cdf0e10cSrcweir mnCacheSize( GetNeededSize( pOut, rPt, rSz, rObj, rAttr ) ),
474cdf0e10cSrcweir mnOutDevDrawMode( pOut->GetDrawMode() ),
475cdf0e10cSrcweir mnOutDevBitCount( pOut->GetBitCount() )
476cdf0e10cSrcweir {
477cdf0e10cSrcweir }
478cdf0e10cSrcweir
GraphicDisplayCacheEntry(const GraphicCacheEntry * pRefCacheEntry,OutputDevice * pOut,const Point & rPt,const Size & rSz,const GraphicObject & rObj,const GraphicAttr & rAttr,const GDIMetaFile & rMtf)479cdf0e10cSrcweir GraphicDisplayCacheEntry( const GraphicCacheEntry* pRefCacheEntry,
480cdf0e10cSrcweir OutputDevice* pOut, const Point& rPt, const Size& rSz,
481cdf0e10cSrcweir const GraphicObject& rObj, const GraphicAttr& rAttr,
482cdf0e10cSrcweir const GDIMetaFile& rMtf ) :
483cdf0e10cSrcweir mpRefCacheEntry( pRefCacheEntry ),
484cdf0e10cSrcweir mpMtf( new GDIMetaFile( rMtf ) ), mpBmpEx( NULL ),
485cdf0e10cSrcweir maAttr( rAttr ), maOutSizePix( pOut->LogicToPixel( rSz ) ),
486cdf0e10cSrcweir mnCacheSize( GetNeededSize( pOut, rPt, rSz, rObj, rAttr ) ),
487cdf0e10cSrcweir mnOutDevDrawMode( pOut->GetDrawMode() ),
488cdf0e10cSrcweir mnOutDevBitCount( pOut->GetBitCount() )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir }
491cdf0e10cSrcweir
492cdf0e10cSrcweir
493cdf0e10cSrcweir ~GraphicDisplayCacheEntry();
494cdf0e10cSrcweir
GetAttr() const495cdf0e10cSrcweir const GraphicAttr& GetAttr() const { return maAttr; }
GetOutputSizePixel() const496cdf0e10cSrcweir const Size& GetOutputSizePixel() const { return maOutSizePix; }
GetCacheSize() const497cdf0e10cSrcweir sal_uLong GetCacheSize() const { return mnCacheSize; }
GetReferencedCacheEntry() const498cdf0e10cSrcweir const GraphicCacheEntry* GetReferencedCacheEntry() const { return mpRefCacheEntry; }
GetOutDevDrawMode() const499cdf0e10cSrcweir sal_uLong GetOutDevDrawMode() const { return mnOutDevDrawMode; }
GetOutDevBitCount() const500cdf0e10cSrcweir sal_uInt16 GetOutDevBitCount() const { return mnOutDevBitCount; }
501cdf0e10cSrcweir
SetReleaseTime(const::vos::TTimeValue & rReleaseTime)502cdf0e10cSrcweir void SetReleaseTime( const ::vos::TTimeValue& rReleaseTime ) { maReleaseTime = rReleaseTime; }
GetReleaseTime() const503cdf0e10cSrcweir const ::vos::TTimeValue& GetReleaseTime() const { return maReleaseTime; }
504cdf0e10cSrcweir
Matches(OutputDevice * pOut,const Point &,const Size & rSzPixel,const GraphicCacheEntry * pCacheEntry,const GraphicAttr & rAttr) const505cdf0e10cSrcweir sal_Bool Matches( OutputDevice* pOut, const Point& /*rPtPixel*/, const Size& rSzPixel,
506cdf0e10cSrcweir const GraphicCacheEntry* pCacheEntry, const GraphicAttr& rAttr ) const
507cdf0e10cSrcweir {
508cdf0e10cSrcweir // #i46805# Additional match
509cdf0e10cSrcweir // criteria: outdev draw mode and
510cdf0e10cSrcweir // bit count. One cannot reuse
511cdf0e10cSrcweir // this cache object, if it's
512cdf0e10cSrcweir // e.g. generated for
513cdf0e10cSrcweir // DRAWMODE_GRAYBITMAP.
514cdf0e10cSrcweir return( ( pCacheEntry == mpRefCacheEntry ) &&
515cdf0e10cSrcweir ( maAttr == rAttr ) &&
516cdf0e10cSrcweir ( ( maOutSizePix == rSzPixel ) || ( !maOutSizePix.Width() && !maOutSizePix.Height() ) ) &&
517cdf0e10cSrcweir ( pOut->GetBitCount() == mnOutDevBitCount ) &&
518cdf0e10cSrcweir ( pOut->GetDrawMode() == mnOutDevDrawMode ) );
519cdf0e10cSrcweir }
520cdf0e10cSrcweir
521cdf0e10cSrcweir void Draw( OutputDevice* pOut, const Point& rPt, const Size& rSz ) const;
522cdf0e10cSrcweir };
523cdf0e10cSrcweir
524cdf0e10cSrcweir // -----------------------------------------------------------------------------
525cdf0e10cSrcweir
GetNeededSize(OutputDevice * pOut,const Point &,const Size & rSz,const GraphicObject & rObj,const GraphicAttr & rAttr)526cdf0e10cSrcweir sal_uLong GraphicDisplayCacheEntry::GetNeededSize( OutputDevice* pOut, const Point& /*rPt*/, const Size& rSz,
527cdf0e10cSrcweir const GraphicObject& rObj, const GraphicAttr& rAttr )
528cdf0e10cSrcweir {
529cdf0e10cSrcweir const Graphic& rGraphic = rObj.GetGraphic();
530cdf0e10cSrcweir const GraphicType eType = rGraphic.GetType();
531cdf0e10cSrcweir sal_uLong nNeededSize;
532cdf0e10cSrcweir
533cdf0e10cSrcweir if( GRAPHIC_BITMAP == eType )
534cdf0e10cSrcweir {
535cdf0e10cSrcweir const Size aOutSizePix( pOut->LogicToPixel( rSz ) );
536cdf0e10cSrcweir const long nBitCount = pOut->GetBitCount();
537cdf0e10cSrcweir
538cdf0e10cSrcweir if( ( aOutSizePix.Width() > MAX_BMP_EXTENT ) ||
539cdf0e10cSrcweir ( aOutSizePix.Height() > MAX_BMP_EXTENT ) )
540cdf0e10cSrcweir {
541cdf0e10cSrcweir nNeededSize = ULONG_MAX;
542cdf0e10cSrcweir }
543cdf0e10cSrcweir else if( nBitCount )
544cdf0e10cSrcweir {
545cdf0e10cSrcweir nNeededSize = aOutSizePix.Width() * aOutSizePix.Height() * nBitCount / 8;
546cdf0e10cSrcweir
547cdf0e10cSrcweir if( rObj.IsTransparent() || ( rAttr.GetRotation() % 3600 ) )
548cdf0e10cSrcweir nNeededSize += nNeededSize / nBitCount;
549cdf0e10cSrcweir }
550cdf0e10cSrcweir else
551cdf0e10cSrcweir {
552cdf0e10cSrcweir DBG_ERROR( "GraphicDisplayCacheEntry::GetNeededSize(): pOut->GetBitCount() == 0" );
553cdf0e10cSrcweir nNeededSize = 256000;
554cdf0e10cSrcweir }
555cdf0e10cSrcweir }
556cdf0e10cSrcweir else if( GRAPHIC_GDIMETAFILE == eType )
557cdf0e10cSrcweir nNeededSize = rGraphic.GetSizeBytes();
558cdf0e10cSrcweir else
559cdf0e10cSrcweir nNeededSize = 0;
560cdf0e10cSrcweir
561cdf0e10cSrcweir return nNeededSize;
562cdf0e10cSrcweir }
563cdf0e10cSrcweir
564cdf0e10cSrcweir // -----------------------------------------------------------------------------
565cdf0e10cSrcweir
~GraphicDisplayCacheEntry()566cdf0e10cSrcweir GraphicDisplayCacheEntry::~GraphicDisplayCacheEntry()
567cdf0e10cSrcweir {
568cdf0e10cSrcweir if( mpMtf )
569cdf0e10cSrcweir delete mpMtf;
570cdf0e10cSrcweir
571cdf0e10cSrcweir if( mpBmpEx )
572cdf0e10cSrcweir delete mpBmpEx;
573cdf0e10cSrcweir }
574cdf0e10cSrcweir
575cdf0e10cSrcweir // -----------------------------------------------------------------------------
576cdf0e10cSrcweir
Draw(OutputDevice * pOut,const Point & rPt,const Size & rSz) const577cdf0e10cSrcweir void GraphicDisplayCacheEntry::Draw( OutputDevice* pOut, const Point& rPt, const Size& rSz ) const
578cdf0e10cSrcweir {
579cdf0e10cSrcweir if( mpMtf )
580cdf0e10cSrcweir GraphicManager::ImplDraw( pOut, rPt, rSz, *mpMtf, maAttr );
581cdf0e10cSrcweir else if( mpBmpEx )
582cdf0e10cSrcweir {
583cdf0e10cSrcweir if( maAttr.IsRotated() )
584cdf0e10cSrcweir {
585cdf0e10cSrcweir Polygon aPoly( Rectangle( rPt, rSz ) );
586cdf0e10cSrcweir
587cdf0e10cSrcweir aPoly.Rotate( rPt, maAttr.GetRotation() % 3600 );
588cdf0e10cSrcweir const Rectangle aRotBoundRect( aPoly.GetBoundRect() );
589cdf0e10cSrcweir pOut->DrawBitmapEx( aRotBoundRect.TopLeft(), aRotBoundRect.GetSize(), *mpBmpEx );
590cdf0e10cSrcweir }
591cdf0e10cSrcweir else
592cdf0e10cSrcweir pOut->DrawBitmapEx( rPt, rSz, *mpBmpEx );
593cdf0e10cSrcweir }
594cdf0e10cSrcweir }
595cdf0e10cSrcweir
596cdf0e10cSrcweir // -----------------------
597cdf0e10cSrcweir // - GraphicCache -
598cdf0e10cSrcweir // -----------------------
599cdf0e10cSrcweir
GraphicCache(GraphicManager & rMgr,sal_uLong nDisplayCacheSize,sal_uLong nMaxObjDisplayCacheSize)600cdf0e10cSrcweir GraphicCache::GraphicCache( GraphicManager& rMgr, sal_uLong nDisplayCacheSize, sal_uLong nMaxObjDisplayCacheSize ) :
601cdf0e10cSrcweir mrMgr ( rMgr ),
602cdf0e10cSrcweir mnReleaseTimeoutSeconds ( 0UL ),
603cdf0e10cSrcweir mnMaxDisplaySize ( nDisplayCacheSize ),
604cdf0e10cSrcweir mnMaxObjDisplaySize ( nMaxObjDisplayCacheSize ),
605cdf0e10cSrcweir mnUsedDisplaySize ( 0UL )
606cdf0e10cSrcweir {
607cdf0e10cSrcweir maReleaseTimer.SetTimeoutHdl( LINK( this, GraphicCache, ReleaseTimeoutHdl ) );
608cdf0e10cSrcweir maReleaseTimer.SetTimeout( RELEASE_TIMEOUT );
609cdf0e10cSrcweir maReleaseTimer.Start();
610cdf0e10cSrcweir }
611cdf0e10cSrcweir
612cdf0e10cSrcweir // -----------------------------------------------------------------------------
613cdf0e10cSrcweir
~GraphicCache()614cdf0e10cSrcweir GraphicCache::~GraphicCache()
615cdf0e10cSrcweir {
616cdf0e10cSrcweir DBG_ASSERT( !maGraphicCache.Count(), "GraphicCache::~GraphicCache(): there are some GraphicObjects in cache" );
617cdf0e10cSrcweir DBG_ASSERT( !maDisplayCache.Count(), "GraphicCache::~GraphicCache(): there are some GraphicObjects in display cache" );
618cdf0e10cSrcweir }
619cdf0e10cSrcweir
620cdf0e10cSrcweir // -----------------------------------------------------------------------------
621cdf0e10cSrcweir
AddGraphicObject(const GraphicObject & rObj,Graphic & rSubstitute,const ByteString * pID,const GraphicObject * pCopyObj)622cdf0e10cSrcweir void GraphicCache::AddGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute,
623cdf0e10cSrcweir const ByteString* pID, const GraphicObject* pCopyObj )
624cdf0e10cSrcweir {
625cdf0e10cSrcweir sal_Bool bInserted = sal_False;
626cdf0e10cSrcweir
627cdf0e10cSrcweir if( !rObj.IsSwappedOut() &&
628cdf0e10cSrcweir ( pID || ( pCopyObj && ( pCopyObj->GetType() != GRAPHIC_NONE ) ) || ( rObj.GetType() != GRAPHIC_NONE ) ) )
629cdf0e10cSrcweir {
630cdf0e10cSrcweir if( pCopyObj )
631cdf0e10cSrcweir {
632cdf0e10cSrcweir GraphicCacheEntry* pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.First() );
633cdf0e10cSrcweir
634cdf0e10cSrcweir while( !bInserted && pEntry )
635cdf0e10cSrcweir {
636cdf0e10cSrcweir if( pEntry->HasGraphicObjectReference( *pCopyObj ) )
637cdf0e10cSrcweir {
638cdf0e10cSrcweir pEntry->AddGraphicObjectReference( rObj, rSubstitute );
639cdf0e10cSrcweir bInserted = sal_True;
640cdf0e10cSrcweir }
641cdf0e10cSrcweir else
642cdf0e10cSrcweir {
643cdf0e10cSrcweir pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.Next() );
644cdf0e10cSrcweir }
645cdf0e10cSrcweir }
646cdf0e10cSrcweir }
647cdf0e10cSrcweir
648cdf0e10cSrcweir if( !bInserted )
649cdf0e10cSrcweir {
650cdf0e10cSrcweir GraphicCacheEntry* pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.First() );
651cdf0e10cSrcweir ::std::auto_ptr< GraphicID > apID;
652cdf0e10cSrcweir
653cdf0e10cSrcweir if( !pID )
654cdf0e10cSrcweir {
655cdf0e10cSrcweir apID.reset( new GraphicID( rObj ) );
656cdf0e10cSrcweir }
657cdf0e10cSrcweir
658cdf0e10cSrcweir while( !bInserted && pEntry )
659cdf0e10cSrcweir {
660cdf0e10cSrcweir const GraphicID& rEntryID = pEntry->GetID();
661cdf0e10cSrcweir
662cdf0e10cSrcweir if( pID )
663cdf0e10cSrcweir {
664cdf0e10cSrcweir if( rEntryID.GetIDString() == *pID )
665cdf0e10cSrcweir {
666cdf0e10cSrcweir pEntry->TryToSwapIn();
667cdf0e10cSrcweir
668cdf0e10cSrcweir // since pEntry->TryToSwapIn can modify our current list, we have to
669cdf0e10cSrcweir // iterate from beginning to add a reference to the appropriate
670cdf0e10cSrcweir // CacheEntry object; after this, quickly jump out of the outer iteration
671cdf0e10cSrcweir for( pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.First() );
672cdf0e10cSrcweir !bInserted && pEntry;
673cdf0e10cSrcweir pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.Next() ) )
674cdf0e10cSrcweir {
675cdf0e10cSrcweir const GraphicID& rID = pEntry->GetID();
676cdf0e10cSrcweir
677cdf0e10cSrcweir if( rID.GetIDString() == *pID )
678cdf0e10cSrcweir {
679cdf0e10cSrcweir pEntry->AddGraphicObjectReference( rObj, rSubstitute );
680cdf0e10cSrcweir bInserted = sal_True;
681cdf0e10cSrcweir }
682cdf0e10cSrcweir }
683cdf0e10cSrcweir
684cdf0e10cSrcweir if( !bInserted )
685cdf0e10cSrcweir {
686cdf0e10cSrcweir maGraphicCache.Insert( new GraphicCacheEntry( rObj ), LIST_APPEND );
687cdf0e10cSrcweir bInserted = sal_True;
688cdf0e10cSrcweir }
689cdf0e10cSrcweir }
690cdf0e10cSrcweir }
691cdf0e10cSrcweir else
692cdf0e10cSrcweir {
693cdf0e10cSrcweir if( rEntryID == *apID )
694cdf0e10cSrcweir {
695cdf0e10cSrcweir pEntry->AddGraphicObjectReference( rObj, rSubstitute );
696cdf0e10cSrcweir bInserted = sal_True;
697cdf0e10cSrcweir }
698cdf0e10cSrcweir }
699cdf0e10cSrcweir
700cdf0e10cSrcweir if( !bInserted )
701cdf0e10cSrcweir pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.Next() );
702cdf0e10cSrcweir }
703cdf0e10cSrcweir }
704cdf0e10cSrcweir }
705cdf0e10cSrcweir
706cdf0e10cSrcweir if( !bInserted )
707cdf0e10cSrcweir maGraphicCache.Insert( new GraphicCacheEntry( rObj ), LIST_APPEND );
708cdf0e10cSrcweir }
709cdf0e10cSrcweir
710cdf0e10cSrcweir // -----------------------------------------------------------------------------
711cdf0e10cSrcweir
ReleaseGraphicObject(const GraphicObject & rObj)712cdf0e10cSrcweir void GraphicCache::ReleaseGraphicObject( const GraphicObject& rObj )
713cdf0e10cSrcweir {
714cdf0e10cSrcweir // Release cached object
715cdf0e10cSrcweir GraphicCacheEntry* pEntry = (GraphicCacheEntry*) maGraphicCache.First();
716cdf0e10cSrcweir sal_Bool bRemoved = sal_False;
717cdf0e10cSrcweir
718cdf0e10cSrcweir while( !bRemoved && pEntry )
719cdf0e10cSrcweir {
720cdf0e10cSrcweir bRemoved = pEntry->ReleaseGraphicObjectReference( rObj );
721cdf0e10cSrcweir
722cdf0e10cSrcweir if( bRemoved )
723cdf0e10cSrcweir {
724cdf0e10cSrcweir if( 0 == pEntry->GetGraphicObjectReferenceCount() )
725cdf0e10cSrcweir {
726cdf0e10cSrcweir // if graphic cache entry has no more references,
727cdf0e10cSrcweir // the corresponding display cache object can be removed
728cdf0e10cSrcweir GraphicDisplayCacheEntry* pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.First();
729cdf0e10cSrcweir
730cdf0e10cSrcweir while( pDisplayEntry )
731cdf0e10cSrcweir {
732cdf0e10cSrcweir if( pDisplayEntry->GetReferencedCacheEntry() == pEntry )
733cdf0e10cSrcweir {
734cdf0e10cSrcweir mnUsedDisplaySize -= pDisplayEntry->GetCacheSize();
735cdf0e10cSrcweir maDisplayCache.Remove( pDisplayEntry );
736cdf0e10cSrcweir delete pDisplayEntry;
737cdf0e10cSrcweir pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.GetCurObject();
738cdf0e10cSrcweir }
739cdf0e10cSrcweir else
740cdf0e10cSrcweir pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.Next();
741cdf0e10cSrcweir }
742cdf0e10cSrcweir
743cdf0e10cSrcweir // delete graphic cache entry
744cdf0e10cSrcweir maGraphicCache.Remove( (void*) pEntry );
745cdf0e10cSrcweir delete pEntry;
746cdf0e10cSrcweir }
747cdf0e10cSrcweir }
748cdf0e10cSrcweir else
749cdf0e10cSrcweir pEntry = (GraphicCacheEntry*) maGraphicCache.Next();
750cdf0e10cSrcweir }
751cdf0e10cSrcweir
752cdf0e10cSrcweir DBG_ASSERT( bRemoved, "GraphicCache::ReleaseGraphicObject(...): GraphicObject not found in cache" );
753cdf0e10cSrcweir }
754cdf0e10cSrcweir
755cdf0e10cSrcweir // -----------------------------------------------------------------------------
756cdf0e10cSrcweir
GraphicObjectWasSwappedOut(const GraphicObject & rObj)757cdf0e10cSrcweir void GraphicCache::GraphicObjectWasSwappedOut( const GraphicObject& rObj )
758cdf0e10cSrcweir {
759cdf0e10cSrcweir // notify cache that rObj is swapped out (and can thus be pruned
760cdf0e10cSrcweir // from the cache)
761cdf0e10cSrcweir GraphicCacheEntry* pEntry = ImplGetCacheEntry( rObj );
762cdf0e10cSrcweir
763cdf0e10cSrcweir if( pEntry )
764cdf0e10cSrcweir pEntry->GraphicObjectWasSwappedOut( rObj );
765cdf0e10cSrcweir }
766cdf0e10cSrcweir
767cdf0e10cSrcweir // -----------------------------------------------------------------------------
768cdf0e10cSrcweir
FillSwappedGraphicObject(const GraphicObject & rObj,Graphic & rSubstitute)769cdf0e10cSrcweir sal_Bool GraphicCache::FillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute )
770cdf0e10cSrcweir {
771cdf0e10cSrcweir GraphicCacheEntry* pEntry = ImplGetCacheEntry( rObj );
772cdf0e10cSrcweir
773cdf0e10cSrcweir if( !pEntry )
774cdf0e10cSrcweir return sal_False;
775cdf0e10cSrcweir
776cdf0e10cSrcweir return pEntry->FillSwappedGraphicObject( rObj, rSubstitute );
777cdf0e10cSrcweir }
778cdf0e10cSrcweir
779cdf0e10cSrcweir // -----------------------------------------------------------------------------
780cdf0e10cSrcweir
GraphicObjectWasSwappedIn(const GraphicObject & rObj)781cdf0e10cSrcweir void GraphicCache::GraphicObjectWasSwappedIn( const GraphicObject& rObj )
782cdf0e10cSrcweir {
783cdf0e10cSrcweir GraphicCacheEntry* pEntry = ImplGetCacheEntry( rObj );
784cdf0e10cSrcweir
785cdf0e10cSrcweir if( pEntry )
786cdf0e10cSrcweir {
787cdf0e10cSrcweir if( pEntry->GetID().IsEmpty() )
788cdf0e10cSrcweir {
789cdf0e10cSrcweir ReleaseGraphicObject( rObj );
790cdf0e10cSrcweir AddGraphicObject( rObj, (Graphic&) rObj.GetGraphic(), NULL, NULL );
791cdf0e10cSrcweir }
792cdf0e10cSrcweir else
793cdf0e10cSrcweir pEntry->GraphicObjectWasSwappedIn( rObj );
794cdf0e10cSrcweir }
795cdf0e10cSrcweir }
796cdf0e10cSrcweir
797cdf0e10cSrcweir // -----------------------------------------------------------------------------
798cdf0e10cSrcweir
SetMaxDisplayCacheSize(sal_uLong nNewCacheSize)799cdf0e10cSrcweir void GraphicCache::SetMaxDisplayCacheSize( sal_uLong nNewCacheSize )
800cdf0e10cSrcweir {
801cdf0e10cSrcweir mnMaxDisplaySize = nNewCacheSize;
802cdf0e10cSrcweir
803cdf0e10cSrcweir if( GetMaxDisplayCacheSize() < GetUsedDisplayCacheSize() )
804cdf0e10cSrcweir ImplFreeDisplayCacheSpace( GetUsedDisplayCacheSize() - GetMaxDisplayCacheSize() );
805cdf0e10cSrcweir }
806cdf0e10cSrcweir
807cdf0e10cSrcweir // -----------------------------------------------------------------------------
808cdf0e10cSrcweir
SetMaxObjDisplayCacheSize(sal_uLong nNewMaxObjSize,sal_Bool bDestroyGreaterCached)809cdf0e10cSrcweir void GraphicCache::SetMaxObjDisplayCacheSize( sal_uLong nNewMaxObjSize, sal_Bool bDestroyGreaterCached )
810cdf0e10cSrcweir {
811cdf0e10cSrcweir const sal_Bool bDestroy = ( bDestroyGreaterCached && ( nNewMaxObjSize < mnMaxObjDisplaySize ) );
812cdf0e10cSrcweir
813cdf0e10cSrcweir mnMaxObjDisplaySize = Min( nNewMaxObjSize, mnMaxDisplaySize );
814cdf0e10cSrcweir
815cdf0e10cSrcweir if( bDestroy )
816cdf0e10cSrcweir {
817cdf0e10cSrcweir GraphicDisplayCacheEntry* pCacheObj = (GraphicDisplayCacheEntry*) maDisplayCache.First();
818cdf0e10cSrcweir
819cdf0e10cSrcweir while( pCacheObj )
820cdf0e10cSrcweir {
821cdf0e10cSrcweir if( pCacheObj->GetCacheSize() > mnMaxObjDisplaySize )
822cdf0e10cSrcweir {
823cdf0e10cSrcweir mnUsedDisplaySize -= pCacheObj->GetCacheSize();
824cdf0e10cSrcweir maDisplayCache.Remove( pCacheObj );
825cdf0e10cSrcweir delete pCacheObj;
826cdf0e10cSrcweir pCacheObj = (GraphicDisplayCacheEntry*) maDisplayCache.GetCurObject();
827cdf0e10cSrcweir }
828cdf0e10cSrcweir else
829cdf0e10cSrcweir pCacheObj = (GraphicDisplayCacheEntry*) maDisplayCache.Next();
830cdf0e10cSrcweir }
831cdf0e10cSrcweir }
832cdf0e10cSrcweir }
833cdf0e10cSrcweir
834cdf0e10cSrcweir // -----------------------------------------------------------------------------
835cdf0e10cSrcweir
SetCacheTimeout(sal_uLong nTimeoutSeconds)836cdf0e10cSrcweir void GraphicCache::SetCacheTimeout( sal_uLong nTimeoutSeconds )
837cdf0e10cSrcweir {
838cdf0e10cSrcweir if( mnReleaseTimeoutSeconds != nTimeoutSeconds )
839cdf0e10cSrcweir {
840cdf0e10cSrcweir GraphicDisplayCacheEntry* pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.First();
841cdf0e10cSrcweir ::vos::TTimeValue aReleaseTime;
842cdf0e10cSrcweir
843cdf0e10cSrcweir if( ( mnReleaseTimeoutSeconds = nTimeoutSeconds ) != 0 )
844cdf0e10cSrcweir {
845cdf0e10cSrcweir osl_getSystemTime( &aReleaseTime );
846cdf0e10cSrcweir aReleaseTime.addTime( ::vos::TTimeValue( nTimeoutSeconds, 0 ) );
847cdf0e10cSrcweir }
848cdf0e10cSrcweir
849cdf0e10cSrcweir while( pDisplayEntry )
850cdf0e10cSrcweir {
851cdf0e10cSrcweir pDisplayEntry->SetReleaseTime( aReleaseTime );
852cdf0e10cSrcweir pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.Next();
853cdf0e10cSrcweir }
854cdf0e10cSrcweir }
855cdf0e10cSrcweir }
856cdf0e10cSrcweir
857cdf0e10cSrcweir // -----------------------------------------------------------------------------
858cdf0e10cSrcweir
ClearDisplayCache()859cdf0e10cSrcweir void GraphicCache::ClearDisplayCache()
860cdf0e10cSrcweir {
861cdf0e10cSrcweir for( void* pObj = maDisplayCache.First(); pObj; pObj = maDisplayCache.Next() )
862cdf0e10cSrcweir delete (GraphicDisplayCacheEntry*) pObj;
863cdf0e10cSrcweir
864cdf0e10cSrcweir maDisplayCache.Clear();
865cdf0e10cSrcweir mnUsedDisplaySize = 0UL;
866cdf0e10cSrcweir }
867cdf0e10cSrcweir
868cdf0e10cSrcweir // -----------------------------------------------------------------------------
869cdf0e10cSrcweir
IsDisplayCacheable(OutputDevice * pOut,const Point & rPt,const Size & rSz,const GraphicObject & rObj,const GraphicAttr & rAttr) const870cdf0e10cSrcweir sal_Bool GraphicCache::IsDisplayCacheable( OutputDevice* pOut, const Point& rPt, const Size& rSz,
871cdf0e10cSrcweir const GraphicObject& rObj, const GraphicAttr& rAttr ) const
872cdf0e10cSrcweir {
873cdf0e10cSrcweir return( GraphicDisplayCacheEntry::GetNeededSize( pOut, rPt, rSz, rObj, rAttr ) <=
874cdf0e10cSrcweir GetMaxObjDisplayCacheSize() );
875cdf0e10cSrcweir }
876cdf0e10cSrcweir
877cdf0e10cSrcweir // -----------------------------------------------------------------------------
878cdf0e10cSrcweir
IsInDisplayCache(OutputDevice * pOut,const Point & rPt,const Size & rSz,const GraphicObject & rObj,const GraphicAttr & rAttr) const879cdf0e10cSrcweir sal_Bool GraphicCache::IsInDisplayCache( OutputDevice* pOut, const Point& rPt, const Size& rSz,
880cdf0e10cSrcweir const GraphicObject& rObj, const GraphicAttr& rAttr ) const
881cdf0e10cSrcweir {
882cdf0e10cSrcweir const Point aPtPixel( pOut->LogicToPixel( rPt ) );
883cdf0e10cSrcweir const Size aSzPixel( pOut->LogicToPixel( rSz ) );
884cdf0e10cSrcweir const GraphicCacheEntry* pCacheEntry = ( (GraphicCache*) this )->ImplGetCacheEntry( rObj );
885cdf0e10cSrcweir //GraphicDisplayCacheEntry* pDisplayEntry = (GraphicDisplayCacheEntry*) ( (GraphicCache*) this )->maDisplayCache.First(); // -Wall removed ....
886cdf0e10cSrcweir sal_Bool bFound = sal_False;
887cdf0e10cSrcweir
888cdf0e10cSrcweir if( pCacheEntry )
889cdf0e10cSrcweir {
890cdf0e10cSrcweir for( long i = 0, nCount = maDisplayCache.Count(); !bFound && ( i < nCount ); i++ )
891cdf0e10cSrcweir if( ( (GraphicDisplayCacheEntry*) maDisplayCache.GetObject( i ) )->Matches( pOut, aPtPixel, aSzPixel, pCacheEntry, rAttr ) )
892cdf0e10cSrcweir bFound = sal_True;
893cdf0e10cSrcweir }
894cdf0e10cSrcweir
895cdf0e10cSrcweir return bFound;
896cdf0e10cSrcweir }
897cdf0e10cSrcweir
898cdf0e10cSrcweir // -----------------------------------------------------------------------------
899cdf0e10cSrcweir
GetUniqueID(const GraphicObject & rObj) const900cdf0e10cSrcweir ByteString GraphicCache::GetUniqueID( const GraphicObject& rObj ) const
901cdf0e10cSrcweir {
902cdf0e10cSrcweir ByteString aRet;
903cdf0e10cSrcweir GraphicCacheEntry* pEntry = ( (GraphicCache*) this )->ImplGetCacheEntry( rObj );
904cdf0e10cSrcweir
905cdf0e10cSrcweir // ensure that the entry is correctly initialized (it has to be read at least once)
906cdf0e10cSrcweir if( pEntry && pEntry->GetID().IsEmpty() )
907cdf0e10cSrcweir pEntry->TryToSwapIn();
908cdf0e10cSrcweir
909cdf0e10cSrcweir // do another call to ImplGetCacheEntry in case of modified entry list
910cdf0e10cSrcweir pEntry = ( (GraphicCache*) this )->ImplGetCacheEntry( rObj );
911cdf0e10cSrcweir
912cdf0e10cSrcweir if( pEntry )
913cdf0e10cSrcweir aRet = pEntry->GetID().GetIDString();
914cdf0e10cSrcweir
915cdf0e10cSrcweir return aRet;
916cdf0e10cSrcweir }
917cdf0e10cSrcweir
918cdf0e10cSrcweir // -----------------------------------------------------------------------------
919cdf0e10cSrcweir
CreateDisplayCacheObj(OutputDevice * pOut,const Point & rPt,const Size & rSz,const GraphicObject & rObj,const GraphicAttr & rAttr,const BitmapEx & rBmpEx)920cdf0e10cSrcweir sal_Bool GraphicCache::CreateDisplayCacheObj( OutputDevice* pOut, const Point& rPt, const Size& rSz,
921cdf0e10cSrcweir const GraphicObject& rObj, const GraphicAttr& rAttr,
922cdf0e10cSrcweir const BitmapEx& rBmpEx )
923cdf0e10cSrcweir {
924cdf0e10cSrcweir const sal_uLong nNeededSize = GraphicDisplayCacheEntry::GetNeededSize( pOut, rPt, rSz, rObj, rAttr );
925cdf0e10cSrcweir sal_Bool bRet = sal_False;
926cdf0e10cSrcweir
927cdf0e10cSrcweir if( nNeededSize <= GetMaxObjDisplayCacheSize() )
928cdf0e10cSrcweir {
929cdf0e10cSrcweir if( nNeededSize > GetFreeDisplayCacheSize() )
930cdf0e10cSrcweir ImplFreeDisplayCacheSpace( nNeededSize - GetFreeDisplayCacheSize() );
931cdf0e10cSrcweir
932cdf0e10cSrcweir GraphicDisplayCacheEntry* pNewEntry = new GraphicDisplayCacheEntry( ImplGetCacheEntry( rObj ),
933cdf0e10cSrcweir pOut, rPt, rSz, rObj, rAttr, rBmpEx );
934cdf0e10cSrcweir
935cdf0e10cSrcweir if( GetCacheTimeout() )
936cdf0e10cSrcweir {
937cdf0e10cSrcweir ::vos::TTimeValue aReleaseTime;
938cdf0e10cSrcweir
939cdf0e10cSrcweir osl_getSystemTime( &aReleaseTime );
940cdf0e10cSrcweir aReleaseTime.addTime( ::vos::TTimeValue( GetCacheTimeout(), 0 ) );
941cdf0e10cSrcweir pNewEntry->SetReleaseTime( aReleaseTime );
942cdf0e10cSrcweir }
943cdf0e10cSrcweir
944cdf0e10cSrcweir maDisplayCache.Insert( pNewEntry, LIST_APPEND );
945cdf0e10cSrcweir mnUsedDisplaySize += pNewEntry->GetCacheSize();
946cdf0e10cSrcweir bRet = sal_True;
947cdf0e10cSrcweir }
948cdf0e10cSrcweir
949cdf0e10cSrcweir return bRet;
950cdf0e10cSrcweir }
951cdf0e10cSrcweir
952cdf0e10cSrcweir // -----------------------------------------------------------------------------
953cdf0e10cSrcweir
CreateDisplayCacheObj(OutputDevice * pOut,const Point & rPt,const Size & rSz,const GraphicObject & rObj,const GraphicAttr & rAttr,const GDIMetaFile & rMtf)954cdf0e10cSrcweir sal_Bool GraphicCache::CreateDisplayCacheObj( OutputDevice* pOut, const Point& rPt, const Size& rSz,
955cdf0e10cSrcweir const GraphicObject& rObj, const GraphicAttr& rAttr,
956cdf0e10cSrcweir const GDIMetaFile& rMtf )
957cdf0e10cSrcweir {
958cdf0e10cSrcweir const sal_uLong nNeededSize = GraphicDisplayCacheEntry::GetNeededSize( pOut, rPt, rSz, rObj, rAttr );
959cdf0e10cSrcweir sal_Bool bRet = sal_False;
960cdf0e10cSrcweir
961cdf0e10cSrcweir if( nNeededSize <= GetMaxObjDisplayCacheSize() )
962cdf0e10cSrcweir {
963cdf0e10cSrcweir if( nNeededSize > GetFreeDisplayCacheSize() )
964cdf0e10cSrcweir ImplFreeDisplayCacheSpace( nNeededSize - GetFreeDisplayCacheSize() );
965cdf0e10cSrcweir
966cdf0e10cSrcweir GraphicDisplayCacheEntry* pNewEntry = new GraphicDisplayCacheEntry( ImplGetCacheEntry( rObj ),
967cdf0e10cSrcweir pOut, rPt, rSz, rObj, rAttr, rMtf );
968cdf0e10cSrcweir
969cdf0e10cSrcweir if( GetCacheTimeout() )
970cdf0e10cSrcweir {
971cdf0e10cSrcweir ::vos::TTimeValue aReleaseTime;
972cdf0e10cSrcweir
973cdf0e10cSrcweir osl_getSystemTime( &aReleaseTime );
974cdf0e10cSrcweir aReleaseTime.addTime( ::vos::TTimeValue( GetCacheTimeout(), 0 ) );
975cdf0e10cSrcweir pNewEntry->SetReleaseTime( aReleaseTime );
976cdf0e10cSrcweir }
977cdf0e10cSrcweir
978cdf0e10cSrcweir maDisplayCache.Insert( pNewEntry, LIST_APPEND );
979cdf0e10cSrcweir mnUsedDisplaySize += pNewEntry->GetCacheSize();
980cdf0e10cSrcweir bRet = sal_True;
981cdf0e10cSrcweir }
982cdf0e10cSrcweir
983cdf0e10cSrcweir return bRet;
984cdf0e10cSrcweir }
985cdf0e10cSrcweir
986cdf0e10cSrcweir // -----------------------------------------------------------------------------
987cdf0e10cSrcweir
DrawDisplayCacheObj(OutputDevice * pOut,const Point & rPt,const Size & rSz,const GraphicObject & rObj,const GraphicAttr & rAttr)988cdf0e10cSrcweir sal_Bool GraphicCache::DrawDisplayCacheObj( OutputDevice* pOut, const Point& rPt, const Size& rSz,
989cdf0e10cSrcweir const GraphicObject& rObj, const GraphicAttr& rAttr )
990cdf0e10cSrcweir {
991cdf0e10cSrcweir const Point aPtPixel( pOut->LogicToPixel( rPt ) );
992cdf0e10cSrcweir const Size aSzPixel( pOut->LogicToPixel( rSz ) );
993cdf0e10cSrcweir const GraphicCacheEntry* pCacheEntry = ImplGetCacheEntry( rObj );
994cdf0e10cSrcweir GraphicDisplayCacheEntry* pDisplayCacheEntry = (GraphicDisplayCacheEntry*) maDisplayCache.First();
995cdf0e10cSrcweir sal_Bool bRet = sal_False;
996cdf0e10cSrcweir
997cdf0e10cSrcweir while( !bRet && pDisplayCacheEntry )
998cdf0e10cSrcweir {
999cdf0e10cSrcweir if( pDisplayCacheEntry->Matches( pOut, aPtPixel, aSzPixel, pCacheEntry, rAttr ) )
1000cdf0e10cSrcweir {
1001cdf0e10cSrcweir ::vos::TTimeValue aReleaseTime;
1002cdf0e10cSrcweir
1003cdf0e10cSrcweir // put found object at last used position
1004cdf0e10cSrcweir maDisplayCache.Insert( maDisplayCache.Remove( pDisplayCacheEntry ), LIST_APPEND );
1005cdf0e10cSrcweir
1006cdf0e10cSrcweir if( GetCacheTimeout() )
1007cdf0e10cSrcweir {
1008cdf0e10cSrcweir osl_getSystemTime( &aReleaseTime );
1009cdf0e10cSrcweir aReleaseTime.addTime( ::vos::TTimeValue( GetCacheTimeout(), 0 ) );
1010cdf0e10cSrcweir }
1011cdf0e10cSrcweir
1012cdf0e10cSrcweir pDisplayCacheEntry->SetReleaseTime( aReleaseTime );
1013cdf0e10cSrcweir bRet = sal_True;
1014cdf0e10cSrcweir }
1015cdf0e10cSrcweir else
1016cdf0e10cSrcweir pDisplayCacheEntry = (GraphicDisplayCacheEntry*) maDisplayCache.Next();
1017cdf0e10cSrcweir }
1018cdf0e10cSrcweir
1019cdf0e10cSrcweir if( bRet )
1020cdf0e10cSrcweir pDisplayCacheEntry->Draw( pOut, rPt, rSz );
1021cdf0e10cSrcweir
1022cdf0e10cSrcweir return bRet;
1023cdf0e10cSrcweir }
1024cdf0e10cSrcweir
1025cdf0e10cSrcweir // -----------------------------------------------------------------------------
1026cdf0e10cSrcweir
ImplFreeDisplayCacheSpace(sal_uLong nSizeToFree)1027cdf0e10cSrcweir sal_Bool GraphicCache::ImplFreeDisplayCacheSpace( sal_uLong nSizeToFree )
1028cdf0e10cSrcweir {
1029cdf0e10cSrcweir sal_uLong nFreedSize = 0UL;
1030cdf0e10cSrcweir
1031cdf0e10cSrcweir if( nSizeToFree )
1032cdf0e10cSrcweir {
1033cdf0e10cSrcweir void* pObj = maDisplayCache.First();
1034cdf0e10cSrcweir
1035cdf0e10cSrcweir if( nSizeToFree > mnUsedDisplaySize )
1036cdf0e10cSrcweir nSizeToFree = mnUsedDisplaySize;
1037cdf0e10cSrcweir
1038cdf0e10cSrcweir while( pObj )
1039cdf0e10cSrcweir {
1040cdf0e10cSrcweir GraphicDisplayCacheEntry* pCacheObj = (GraphicDisplayCacheEntry*) pObj;
1041cdf0e10cSrcweir
1042cdf0e10cSrcweir nFreedSize += pCacheObj->GetCacheSize();
1043cdf0e10cSrcweir mnUsedDisplaySize -= pCacheObj->GetCacheSize();
1044cdf0e10cSrcweir maDisplayCache.Remove( pObj );
1045cdf0e10cSrcweir delete pCacheObj;
1046cdf0e10cSrcweir
1047cdf0e10cSrcweir if( nFreedSize >= nSizeToFree )
1048cdf0e10cSrcweir break;
1049cdf0e10cSrcweir else
1050cdf0e10cSrcweir pObj = maDisplayCache.GetCurObject();
1051cdf0e10cSrcweir }
1052cdf0e10cSrcweir }
1053cdf0e10cSrcweir
1054cdf0e10cSrcweir return( nFreedSize >= nSizeToFree );
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir
1057cdf0e10cSrcweir // -----------------------------------------------------------------------------
1058cdf0e10cSrcweir
ImplGetCacheEntry(const GraphicObject & rObj)1059cdf0e10cSrcweir GraphicCacheEntry* GraphicCache::ImplGetCacheEntry( const GraphicObject& rObj )
1060cdf0e10cSrcweir {
1061cdf0e10cSrcweir GraphicCacheEntry* pRet = NULL;
1062cdf0e10cSrcweir
1063cdf0e10cSrcweir for( void* pObj = maGraphicCache.First(); !pRet && pObj; pObj = maGraphicCache.Next() )
1064cdf0e10cSrcweir if( ( (GraphicCacheEntry*) pObj )->HasGraphicObjectReference( rObj ) )
1065cdf0e10cSrcweir pRet = (GraphicCacheEntry*) pObj;
1066cdf0e10cSrcweir
1067cdf0e10cSrcweir return pRet;
1068cdf0e10cSrcweir }
1069cdf0e10cSrcweir
1070cdf0e10cSrcweir // -----------------------------------------------------------------------------
1071cdf0e10cSrcweir
IMPL_LINK(GraphicCache,ReleaseTimeoutHdl,Timer *,pTimer)1072cdf0e10cSrcweir IMPL_LINK( GraphicCache, ReleaseTimeoutHdl, Timer*, pTimer )
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir pTimer->Stop();
1075cdf0e10cSrcweir
1076cdf0e10cSrcweir ::vos::TTimeValue aCurTime;
1077cdf0e10cSrcweir GraphicDisplayCacheEntry* pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.First();
1078cdf0e10cSrcweir
1079cdf0e10cSrcweir osl_getSystemTime( &aCurTime );
1080cdf0e10cSrcweir
1081cdf0e10cSrcweir while( pDisplayEntry )
1082cdf0e10cSrcweir {
1083cdf0e10cSrcweir const ::vos::TTimeValue& rReleaseTime = pDisplayEntry->GetReleaseTime();
1084cdf0e10cSrcweir
1085cdf0e10cSrcweir if( !rReleaseTime.isEmpty() && ( rReleaseTime < aCurTime ) )
1086cdf0e10cSrcweir {
1087cdf0e10cSrcweir mnUsedDisplaySize -= pDisplayEntry->GetCacheSize();
1088cdf0e10cSrcweir maDisplayCache.Remove( pDisplayEntry );
1089cdf0e10cSrcweir delete pDisplayEntry;
1090cdf0e10cSrcweir pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.GetCurObject();
1091cdf0e10cSrcweir }
1092cdf0e10cSrcweir else
1093cdf0e10cSrcweir pDisplayEntry = (GraphicDisplayCacheEntry*) maDisplayCache.Next();
1094cdf0e10cSrcweir }
1095cdf0e10cSrcweir
1096cdf0e10cSrcweir pTimer->Start();
1097cdf0e10cSrcweir
1098cdf0e10cSrcweir return 0;
1099cdf0e10cSrcweir }
1100