[Libreoffice-commits] core.git: Branch 'feature/image_rework' - 3 commits - include/svtools svtools/README svtools/source sw/qa
Zolnai Tamás
tamas.zolnai at collabora.com
Wed Nov 5 23:18:48 PST 2014
include/svtools/grfmgr.hxx | 1
svtools/README | 15 ++++----
svtools/source/graphic/grfmgr2.cxx | 50 ++++++++++-------------------
sw/qa/extras/globalfilter/globalfilter.cxx | 14 +-------
4 files changed, 29 insertions(+), 51 deletions(-)
New commits:
commit e914c3f85ef49d90620efdc9747cd3a761cb18dc
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date: Tue Nov 4 19:10:35 2014 +0100
Update notes about swapping
Change-Id: I6b9f5f9c4a0bc87376a469835a50dc2cf598479e
diff --git a/svtools/README b/svtools/README
index b4f399c..23ff07c 100644
--- a/svtools/README
+++ b/svtools/README
@@ -3,13 +3,14 @@ Tools on top of VCL. Common dialogs, file and print dialogs, wizards, vcl filter
== Image swapping ==
-LO has three kind of swapout mechanisms:
+LO has two kind of swapout mechanisms:
-1) Manual swap out calls: Maybe it comes from old days, when memory was more expensive to use so LO tried to store
-images in the memory only when it is really used and swap out them directly after use. These manual calls seems
-useless nowadays and even ineffective.
-
-2) Size based auto swapping: when the size of all graphic objects reaches a configurable limit (20 MB by default)
+1) Size based auto swapping: when the size of all graphic objects reaches a configurable limit (20 MB by default)
then some of the graphics are saved to the local file system and freed in the memory.
+Configure: Tools -> Options -> Memory -> GraphcisCache -> Use for LibreOffice
+
+2) Time based auto swapping: after an image is swapped in / loaded a timer starts and when the timer (1 min by default)
+has a time out this image is swapped out ( sometimes this time out is ignored when the image is in use ).
+Configure: Tools -> Options -> Memory -> GraphcisCache -> Remove from memory after
-3) Time based auto swapping: more info needed.
+Both swapping are done by GraphicObject and GraphicManager.
commit ebbfd970468e93d1450948fdf03b9cd13f8d5da1
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date: Tue Nov 4 08:34:41 2014 +0100
Optimize ImplCheckSizeOfSwappedInGraphics() a bit
Store used size as a member so we don't need to recalculate it
all the time and no need to use a size map.
Change-Id: I1f929c5d3a56f545cef123bda087ecaf8ca0be4a
diff --git a/include/svtools/grfmgr.hxx b/include/svtools/grfmgr.hxx
index d515773..2bdbc9a 100644
--- a/include/svtools/grfmgr.hxx
+++ b/include/svtools/grfmgr.hxx
@@ -520,6 +520,7 @@ class SVT_DLLPUBLIC GraphicManager
private:
GraphicObjectList_impl maObjList;
+ sal_uLong mnUsedSize; // currently used memory footprint of all swapped in graphics
GraphicCache* mpCache;
GraphicManager( const GraphicManager& ) {}
diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx
index d054ab3..2ff6192 100644
--- a/svtools/source/graphic/grfmgr2.cxx
+++ b/svtools/source/graphic/grfmgr2.cxx
@@ -34,7 +34,6 @@
#include "grfcache.hxx"
#include <svtools/grfmgr.hxx>
#include <boost/scoped_array.hpp>
-#include <boost/unordered_map.hpp>
// - defines -
@@ -48,7 +47,8 @@
GraphicManager::GraphicManager( sal_uLong nCacheSize, sal_uLong nMaxObjCacheSize ) :
- mpCache( new GraphicCache( nCacheSize, nMaxObjCacheSize ) )
+ mnUsedSize(0),
+ mpCache( new GraphicCache( nCacheSize, nMaxObjCacheSize ) )
{
}
@@ -156,6 +156,8 @@ void GraphicManager::ImplRegisterObj( const GraphicObject& rObj, Graphic& rSubst
maObjList.push_back( (GraphicObject*)&rObj );
mpCache->AddGraphicObject( rObj, rSubstitute, pID, pCopyObj );
+ if( !rObj.IsSwappedOut() )
+ mnUsedSize += rObj.GetSizeBytes();
}
void GraphicManager::ImplUnregisterObj( const GraphicObject& rObj )
@@ -169,11 +171,14 @@ void GraphicManager::ImplUnregisterObj( const GraphicObject& rObj )
}
}
assert(false); // surely it should have been registered?
+ if( !rObj.IsSwappedOut() )
+ mnUsedSize -= rObj.GetSizeBytes();
}
void GraphicManager::ImplGraphicObjectWasSwappedOut( const GraphicObject& rObj )
{
mpCache->GraphicObjectWasSwappedOut( rObj );
+ mnUsedSize -= rObj.GetSizeBytes();
}
OString GraphicManager::ImplGetUniqueID( const GraphicObject& rObj ) const
@@ -194,29 +199,6 @@ namespace
void GraphicManager::ImplCheckSizeOfSwappedInGraphics(const GraphicObject* pGraphicToIgnore)
{
- // get the currently used memory footprint of all swapped in bitmap graphics
- // of this graphic manager. Remember candidates in a vector. The size in bytes is
- // already available, thus this loop is not expensive to execute
- sal_uLong nUsedSize(0);
- GraphicObject* pObj = 0;
- std::vector< GraphicObject* > aCandidates;
- boost::unordered_map<GraphicObject *, size_t> sizes;
-
- for (size_t i = 0, n = maObjList.size(); i < n; ++i)
- {
- pObj = maObjList[i];
- if (pObj->meType == GRAPHIC_BITMAP && !pObj->IsSwappedOut() && pObj->GetSizeBytes())
- {
- size_t const nSize = pObj->GetSizeBytes();
- nUsedSize += nSize;
- if( pObj != pGraphicToIgnore )
- {
- aCandidates.push_back(pObj);
- sizes.insert(std::make_pair(pObj, nSize));
- }
- }
- }
-
// detect maximum allowed memory footprint. Use the user-settings of MaxCacheSize (defaulted
// to 20MB) and add a decent multiplicator (experimented to find one). Limit to
// a useful maximum for 32Bit address space
@@ -232,30 +214,33 @@ void GraphicManager::ImplCheckSizeOfSwappedInGraphics(const GraphicObject* pGrap
// calc max allowed cache size
const sal_uLong nMaxCacheSize(::std::min(GetMaxCacheSize() * aMultiplicator, aMaxSize32Bit));
- if(nUsedSize >= nMaxCacheSize && !aCandidates.empty())
+ if(mnUsedSize >= nMaxCacheSize)
{
+ // Copy the object list for now, because maObjList can change in the meantime unexpectedly.
+ std::vector< GraphicObject* > aCandidates(maObjList.begin(), maObjList.end());
// if we use more currently, sort by last DataChangeTimeStamp
// sort by DataChangeTimeStamp so that the oldest get removed first
::std::sort(aCandidates.begin(), aCandidates.end(), simpleSortByDataChangeTimeStamp());
- for(sal_uInt32 a(0); nUsedSize >= nMaxCacheSize && a < aCandidates.size(); a++)
+ for(sal_uInt32 a(0); mnUsedSize >= nMaxCacheSize && a < aCandidates.size(); a++)
{
// swap out until we have no more or the goal to use less than nMaxCacheSize
// is reached
- pObj = aCandidates[a];
+ GraphicObject* pObj = aCandidates[a];
+ if( pObj == pGraphicToIgnore )
+ {
+ continue;
+ }
if (std::find(maObjList.begin(), maObjList.end(), pObj) == maObjList.end())
{
// object has been deleted when swapping out another one
- nUsedSize = (sizes[pObj] < nUsedSize) ? nUsedSize - sizes[pObj] : 0;
continue;
}
- const sal_uLong nSizeBytes(pObj->GetSizeBytes());
// do not swap out when we have less than 16KB data objects
- if(nSizeBytes >= (16 * 1024))
+ if(pObj->GetSizeBytes() >= (16 * 1024))
{
pObj->FireSwapOutRequest();
- nUsedSize = (nSizeBytes < nUsedSize) ? nUsedSize - nSizeBytes : 0;
}
}
}
@@ -269,6 +254,7 @@ bool GraphicManager::ImplFillSwappedGraphicObject( const GraphicObject& rObj, Gr
void GraphicManager::ImplGraphicObjectWasSwappedIn( const GraphicObject& rObj )
{
mpCache->GraphicObjectWasSwappedIn( rObj );
+ mnUsedSize += rObj.GetSizeBytes();
}
bool GraphicManager::ImplDraw( OutputDevice* pOut, const Point& rPt,
commit 25565683be3c8edc8851968784ad8111f897bc43
Author: Zolnai Tamás <tamas.zolnai at collabora.com>
Date: Wed Nov 5 23:30:20 2014 +0100
Remove HTML swapped out image export tests
It crashes on master for some reason. Since it's not
in our main focus it's simpler to remove it.
Change-Id: I2d595bf18abc4f22fac2c16b37247a23fd271c3d
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx
index 19bdb5f..1fd4331 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -38,7 +38,6 @@ void Test::testSwappedOutImageExport()
"Rich Text Format",
"MS Word 97",
"Office Open XML Text",
- "HTML (StarWriter)",
};
for( size_t nFilter = 0; nFilter < aFilterNames.size(); ++nFilter )
@@ -82,17 +81,8 @@ void Test::testSwappedOutImageExport()
{
OUString sURL;
XPropSet->getPropertyValue("GraphicURL") >>= sURL;
- // HTML filter changes the name, but the real indicater here is the "null" URL.
- if( aFilterNames[nFilter] == "HTML (StarWriter)" )
- {
- CPPUNIT_ASSERT_MESSAGE(
- sFailedMessage.getStr(), sURL != OUString("vnd.sun.star.GraphicObject:00000000000000000000000000000000"));
- }
- else
- {
- CPPUNIT_ASSERT_EQUAL_MESSAGE(
- sFailedMessage.getStr(), OUString("vnd.sun.star.GraphicObject:10000000000002620000017D9F4CD7A2"), sURL);
- }
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(
+ sFailedMessage.getStr(), OUString("vnd.sun.star.GraphicObject:10000000000002620000017D9F4CD7A2"), sURL);
}
// Check size
{
More information about the Libreoffice-commits
mailing list