[Libreoffice-commits] core.git: Branch 'private/Ashod/cd-5.3-3.2_import_unloaded' - 12 commits - basctl/inc basic/source canvas/source chart2/CppunitTest_chart2_export.mk chart2/CppunitTest_chart2_import.mk chart2/CppunitTest_chart2_trendcalculators.mk chart2/CppunitTest_chart2_xshape.mk chart2/inc chart2/source compilerplugins/clang cppcanvas/CppunitTest_cppcanvas_emfplus.mk cui/inc cui/Library_cui.mk cui/qa cui/source cui/uiconfig cui/UIConfig_cui.mk dbaccess/source desktop/CppunitTest_desktop_lib.mk drawinglayer/source editeng/source filter/source include/drawinglayer include/editeng include/filter include/svtools include/svx include/vcl l10ntools/source oox/source postprocess/Rdb_services.mk reportdesign/inc sc/CppunitTest_sc_anchor_test.mk sc/CppunitTest_sc_annotationobj.mk sc/CppunitTest_sc_annotationshapeobj.mk sc/CppunitTest_sc_annotationsobj.mk sc/CppunitTest_sc_bugfix_test.mk sc/CppunitTest_sc_cellrangeobj.mk sc/CppunitTest_sc_chart_regression_test.mk sc/CppunitTest_sc_check_data_pilot_ field.mk sc/CppunitTest_sc_check_data_pilot_table.mk sc/CppunitTest_sc_check_xcell_ranges_query.mk sc/CppunitTest_sc_copypaste.mk sc/CppunitTest_sc_databaserangeobj.mk sc/CppunitTest_sc_datapilotfieldobj.mk sc/CppunitTest_sc_datapilottableobj.mk sc/CppunitTest_sc_editfieldobj_cell.mk sc/CppunitTest_sc_editfieldobj_header.mk sc/CppunitTest_sc_filters_test.mk sc/CppunitTest_sc_html_export_test.mk sc/CppunitTest_sc_macros_test.mk sc/CppunitTest_sc_mark_test.mk sc/CppunitTest_sc_modelobj.mk sc/CppunitTest_sc_namedrangeobj.mk sc/CppunitTest_sc_namedrangesobj.mk sc/CppunitTest_sc_new_cond_format_api.mk sc/CppunitTest_sc_opencl_test.mk sc/CppunitTest_sc_outlineobj.mk sc/CppunitTest_sc_rangelst_test.mk sc/CppunitTest_sc_recordchanges.mk sc/CppunitTest_sc_styleloaderobj.mk sc/CppunitTest_sc_subsequent_export_test.mk sc/CppunitTest_sc_subsequent_filters_test.mk sc/CppunitTest_sc_tablesheetobj.mk sc/CppunitTest_sc_tablesheetsobj.mk sc/CppunitTest_sc_ucalc.mk sc/CppunitTest_sc_viewpaneobj.mk sc /inc sc/qa sd/CppunitTest_sd_filters_test.mk sd/CppunitTest_sd_html_export_tests.mk sd/CppunitTest_sd_import_tests.mk sd/CppunitTest_sd_misc_tests.mk sd/inc sd/qa sd/source slideshow/source solenv/bin svtools/inc svtools/Library_svt.mk svtools/qa svtools/source svtools/util svx/inc svx/source sw/CppunitTest_sw_filters_test.mk sw/CppunitTest_sw_htmlexport.mk sw/CppunitTest_sw_macros_test.mk sw/CppunitTest_sw_mailmerge.mk sw/CppunitTest_sw_odfimport.mk sw/CppunitTest_sw_ooxmlexport8.mk sw/CppunitTest_sw_ooxmlimport.mk sw/CppunitTest_sw_rtfimport.mk sw/CppunitTest_sw_ww8export2.mk sw/CppunitTest_sw_ww8export.mk sw/CppunitTest_sw_ww8import.mk sw/inc sw/ooxmlexport_setup.mk sw/qa sw/source vcl/inc vcl/Library_vcl.mk vcl/source vcl/vcl.common.component vcl/workben writerfilter/CppunitTest_writerfilter_rtftok.mk writerfilter/source
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Wed Jun 20 19:57:47 UTC 2018
Rebased ref, commits from common ancestor:
commit 1fb42f8e8ecb0696c41c5d80e2d6a4ca521fd24d
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Wed Jun 20 15:55:07 2018 -0400
vcl: remove swapping logic from GraphicObject to support lazy-loading
Change-Id: I286a9b6ee75f07744232771263c26579ad9653e7
diff --git a/include/vcl/GraphicObject.hxx b/include/vcl/GraphicObject.hxx
index 822f37abb72b..00df8ee00042 100644
--- a/include/vcl/GraphicObject.hxx
+++ b/include/vcl/GraphicObject.hxx
@@ -173,30 +173,8 @@ class VCL_DLLPUBLIC GraphicObject
private:
Graphic maGraphic;
GraphicAttr maAttr;
- Size maPrefSize;
- MapMode maPrefMapMode;
- sal_uLong mnSizeBytes;
- GraphicType meType;
- OUString maLink;
- Link<const GraphicObject*, SvStream*> maSwapStreamHdl;
OUString maUserData;
- std::unique_ptr<Timer> mxSwapOutTimer;
std::unique_ptr<GrfSimpleCacheObj> mxSimpleCache;
- sal_uInt32 mnAnimationLoopCount;
-
- // a unique increasing ID to be able to say which data change is older
- sal_uLong mnDataChangeTimeStamp;
-
- bool mbAutoSwapped : 1;
- bool mbTransparent : 1;
- bool mbAnimated : 1;
- bool mbEPS : 1;
- bool mbIsInSwapIn : 1;
- bool mbIsInSwapOut : 1;
-
- void VCL_DLLPRIVATE ImplAssignGraphicData();
- static void VCL_DLLPRIVATE ImplEnsureGraphicManager();
- void VCL_DLLPRIVATE ImplAutoSwapIn();
bool VCL_DLLPRIVATE ImplGetCropParams(
OutputDevice* pOut,
@@ -299,12 +277,6 @@ private:
bool bEnlarge
) const;
- DECL_LINK( ImplAutoSwapOutHdl, Timer*, void );
-protected:
-
- SvStream* GetSwapStream() const;
- void SetSwapState();
-
public:
GraphicObject();
GraphicObject( const Graphic& rGraphic );
@@ -316,12 +288,6 @@ public:
bool operator==( const GraphicObject& rCacheObj ) const;
bool operator!=( const GraphicObject& rCacheObj ) const { return !( *this == rCacheObj ); }
- bool HasSwapStreamHdl() const { return maSwapStreamHdl.IsSet(); }
- void SetSwapStreamHdl(const Link<const GraphicObject*, SvStream*>& rHdl);
-
- void FireSwapInRequest();
- void FireSwapOutRequest();
-
const Graphic& GetGraphic() const;
void SetGraphic( const Graphic& rGraphic, const GraphicObject* pCopyObj = nullptr);
void SetGraphic( const Graphic& rGraphic, const OUString& rLink );
@@ -361,11 +327,6 @@ public:
void SetAttr( const GraphicAttr& rAttr );
const GraphicAttr& GetAttr() const { return maAttr; }
- bool HasLink() const { return !maLink.isEmpty(); }
- void SetLink();
- void SetLink( const OUString& rLink );
- const OUString& GetLink() const { return maLink; }
-
bool HasUserData() const { return !maUserData.isEmpty(); }
void SetUserData();
void SetUserData( const OUString& rUserData );
@@ -373,14 +334,6 @@ public:
OString GetUniqueID() const;
- bool SwapOut();
- bool SwapOut( SvStream* pOStm );
- bool SwapIn();
-
- bool IsInSwapIn() const { return mbIsInSwapIn; }
- bool IsInSwapOut() const { return mbIsInSwapOut; }
- bool IsSwappedOut() const { return( mbAutoSwapped || maGraphic.IsSwapOut() ); }
-
GraphicType GetType() const;
Size GetPrefSize() const;
MapMode GetPrefMapMode() const;
@@ -462,9 +415,6 @@ public:
double fTopCrop,
double fRightCrop,
double fBottomCrop) const;
-
- // read access
- sal_uLong GetDataChangeTimeStamp() const { return mnDataChangeTimeStamp; }
};
namespace vcl
diff --git a/svx/source/sdr/contact/viewcontactofgraphic.cxx b/svx/source/sdr/contact/viewcontactofgraphic.cxx
index 89b763deb3ef..9e49fae47d7f 100644
--- a/svx/source/sdr/contact/viewcontactofgraphic.cxx
+++ b/svx/source/sdr/contact/viewcontactofgraphic.cxx
@@ -418,10 +418,6 @@ namespace sdr
// draft when swapped out
const GraphicObject& rGraphicObject = GetGrafObject().GetGraphicObject();
- static bool bAllowReplacements(true);
-
- if(rGraphicObject.IsSwappedOut() && bAllowReplacements)
- return true;
// draft when no graphic
if(GraphicType::NONE == rGraphicObject.GetType() || GraphicType::Default == rGraphicObject.GetType())
diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx
index 0415cfbe3eb2..9563815e199f 100644
--- a/svx/source/svdraw/svdograf.cxx
+++ b/svx/source/svdraw/svdograf.cxx
@@ -339,7 +339,6 @@ SdrGrafObj::SdrGrafObj()
{
pGraphic = new GraphicObject;
mpReplacementGraphic = nullptr;
- pGraphic->SetSwapStreamHdl( LINK(this, SdrGrafObj, ImpSwapHdl) );
onGraphicChanged();
// #i118485# Shear allowed and possible now
@@ -363,7 +362,6 @@ SdrGrafObj::SdrGrafObj(const Graphic& rGrf, const Rectangle& rRect)
{
pGraphic = new GraphicObject( rGrf );
mpReplacementGraphic = nullptr;
- pGraphic->SetSwapStreamHdl( LINK(this, SdrGrafObj, ImpSwapHdl) );
onGraphicChanged();
// #i118485# Shear allowed and possible now
@@ -387,7 +385,6 @@ SdrGrafObj::SdrGrafObj( const Graphic& rGrf )
{
pGraphic = new GraphicObject( rGrf );
mpReplacementGraphic = nullptr;
- pGraphic->SetSwapStreamHdl( LINK(this, SdrGrafObj, ImpSwapHdl) );
onGraphicChanged();
// #i118485# Shear allowed and possible now
@@ -416,7 +413,6 @@ void SdrGrafObj::SetGraphicObject( const GraphicObject& rGrfObj )
*pGraphic = rGrfObj;
delete mpReplacementGraphic;
mpReplacementGraphic = nullptr;
- pGraphic->SetSwapStreamHdl( LINK(this, SdrGrafObj, ImpSwapHdl) );
pGraphic->SetUserData();
mbIsPreview = false;
SetChanged();
@@ -426,10 +422,8 @@ void SdrGrafObj::SetGraphicObject( const GraphicObject& rGrfObj )
const GraphicObject& SdrGrafObj::GetGraphicObject(bool bForceSwapIn) const
{
- if(bForceSwapIn)
- {
+ if (bForceSwapIn)
ForceSwapIn();
- }
return *pGraphic;
}
@@ -450,11 +444,6 @@ const GraphicObject* SdrGrafObj::GetReplacementGraphicObject() const
// Replacement graphic for bitmap + PDF is just the bitmap.
const_cast<SdrGrafObj*>(this)->mpReplacementGraphic = new GraphicObject(pGraphic->GetGraphic().GetBitmapEx());
}
- if (mpReplacementGraphic)
- {
- mpReplacementGraphic->SetSwapStreamHdl(
- LINK(const_cast<SdrGrafObj*>(this), SdrGrafObj, ReplacementSwapHdl));
- }
}
return mpReplacementGraphic;
@@ -549,7 +538,7 @@ bool SdrGrafObj::IsEPS() const
bool SdrGrafObj::IsSwappedOut() const
{
- return mbIsPreview || pGraphic->IsSwappedOut();
+ return false;
}
MapMode SdrGrafObj::GetGrafPrefMapMode() const
@@ -607,29 +596,10 @@ Size SdrGrafObj::getOriginalSize() const
void SdrGrafObj::ForceSwapIn() const
{
- if( mbIsPreview && pGraphic->HasUserData() )
+ if (pGraphicLink && (pGraphic->GetType() == GraphicType::NONE ||
+ pGraphic->GetType() == GraphicType::Default) )
{
- // removing preview graphic
- const OUString aUserData( pGraphic->GetUserData() );
-
- Graphic aEmpty;
- pGraphic->SetGraphic( aEmpty );
- pGraphic->SetUserData( aUserData );
-
- const_cast< SdrGrafObj* >( this )->mbIsPreview = false;
- }
- if ( pGraphicLink && pGraphic->IsSwappedOut() )
- ImpUpdateGraphicLink( false );
- else
- pGraphic->FireSwapInRequest();
-
- if( pGraphic->IsSwappedOut() ||
- ( pGraphic->GetType() == GraphicType::NONE ) ||
- ( pGraphic->GetType() == GraphicType::Default ) )
- {
- Graphic aDefaultGraphic;
- aDefaultGraphic.SetDefaultType();
- pGraphic->SetGraphic( aDefaultGraphic );
+ pGraphicLink->Update();
}
}
@@ -669,7 +639,6 @@ void SdrGrafObj::SetGraphicLink(const OUString& rFileName, const OUString& rRefe
aFilterName = rFilterName;
ImpLinkAnmeldung();
pGraphic->SetUserData();
- pGraphic->SetSwapState();
}
void SdrGrafObj::ReleaseGraphicLink()
@@ -1309,144 +1278,6 @@ void SdrGrafObj::AdjustToMaxRect( const Rectangle& rMaxRect, bool bShrinkOnly )
}
}
-IMPL_LINK(SdrGrafObj, ReplacementSwapHdl, const GraphicObject*, pO, SvStream*)
-{
- // replacement image is always swapped
- if (pO->IsInSwapOut())
- {
- SdrSwapGraphicsMode const nSwapMode(pModel->GetSwapGraphicsMode());
- if (nSwapMode & SdrSwapGraphicsMode::TEMP)
- {
- return GRFMGR_AUTOSWAPSTREAM_TEMP;
- }
- }
- else if (pO->IsInSwapIn())
- {
- return GRFMGR_AUTOSWAPSTREAM_TEMP;
- }
- else
- {
- assert(!"why is swap handler being called?");
- }
-
- return GRFMGR_AUTOSWAPSTREAM_NONE;
-}
-
-IMPL_LINK( SdrGrafObj, ImpSwapHdl, const GraphicObject*, pO, SvStream* )
-{
- SvStream* pRet = GRFMGR_AUTOSWAPSTREAM_NONE;
-
- if( pO->IsInSwapOut() )
- {
- if( pModel && !mbIsPreview && pModel->IsSwapGraphics() && pGraphic->GetGraphic().GetSizeBytes() > 20480 )
- {
- // test if this object is visualized from someone
- // ## test only if there are VOCs other than the preview renderer
- if(!GetViewContact().HasViewObjectContacts())
- {
- const SdrSwapGraphicsMode nSwapMode = pModel->GetSwapGraphicsMode();
-
- if( ( pGraphicLink ) &&
- ( nSwapMode & SdrSwapGraphicsMode::PURGE ) )
- {
- pRet = GRFMGR_AUTOSWAPSTREAM_LINK;
- }
- else if( nSwapMode & SdrSwapGraphicsMode::TEMP )
- {
- pRet = GRFMGR_AUTOSWAPSTREAM_TEMP;
- pGraphic->SetUserData();
- }
-
- // #i102380#
- sdr::contact::ViewContactOfGraphic* pVC = dynamic_cast< sdr::contact::ViewContactOfGraphic* >(&GetViewContact());
-
- if(pVC)
- {
- pVC->flushGraphicObjects();
- }
- }
- }
- }
- else if( pO->IsInSwapIn() )
- {
- // can be loaded from the original document stream later
- if( pModel != nullptr )
- {
- if( pGraphic->HasUserData() )
- {
- ::comphelper::LifecycleProxy proxy;
- OUString aUserData = pGraphic->GetUserData();
- uno::Reference<io::XInputStream> const xStream(
- pModel->GetDocumentStream(aUserData, proxy));
-
- std::unique_ptr<SvStream> const pStream( (xStream.is())
- ? ::utl::UcbStreamHelper::CreateStream(xStream)
- : nullptr );
-
- if( pStream != nullptr )
- {
- Graphic aGraphic;
-
- std::unique_ptr<css::uno::Sequence< css::beans::PropertyValue > > pFilterData;
-
- if(mbInsidePaint && !GetViewContact().HasViewObjectContacts())
- {
- pFilterData.reset(new css::uno::Sequence< css::beans::PropertyValue >( 3 ));
-
- const css::awt::Size aPreviewSizeHint( 64, 64 );
- const bool bAllowPartialStreamRead = true;
- // create <GfxLink> instance also for previews in order to avoid that its corresponding
- // data is cleared in the graphic cache entry in case that the preview data equals the complete graphic data
- const bool bCreateNativeLink = true;
- (*pFilterData)[ 0 ].Name = "PreviewSizeHint";
- (*pFilterData)[ 0 ].Value <<= aPreviewSizeHint;
- (*pFilterData)[ 1 ].Name = "AllowPartialStreamRead";
- (*pFilterData)[ 1 ].Value <<= bAllowPartialStreamRead;
- (*pFilterData)[ 2 ].Name = "CreateNativeLink";
- (*pFilterData)[ 2 ].Value <<= bCreateNativeLink;
-
- mbIsPreview = true;
- }
-
- if(!GraphicFilter::GetGraphicFilter().ImportGraphic(
- aGraphic, aUserData, *pStream,
- GRFILTER_FORMAT_DONTKNOW, nullptr, GraphicFilterImportFlags::NONE, pFilterData.get()))
- {
- const OUString aNewUserData( pGraphic->GetUserData() );
- pGraphic->SetGraphic( aGraphic );
- if( mbIsPreview )
- {
- pGraphic->SetUserData(aNewUserData);
- }
- else
- {
- pGraphic->SetUserData();
- }
-
- // Graphic successfully swapped in.
- pRet = GRFMGR_AUTOSWAPSTREAM_LOADED;
- }
- pFilterData.reset();
-
- pStream->ResetError();
- }
- }
- else if( !ImpUpdateGraphicLink( false ) )
- {
- pRet = GRFMGR_AUTOSWAPSTREAM_TEMP;
- }
- else
- {
- pRet = GRFMGR_AUTOSWAPSTREAM_LOADED;
- }
- }
- else
- pRet = GRFMGR_AUTOSWAPSTREAM_TEMP;
- }
-
- return pRet;
-}
-
void SdrGrafObj::SetGrafAnimationAllowed(bool bNew)
{
if(mbGrafAnimationAllowed != bNew)
diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx
index 556727e5d504..00c01953ab35 100644
--- a/sw/source/core/doc/notxtfrm.cxx
+++ b/sw/source/core/doc/notxtfrm.cxx
@@ -770,26 +770,26 @@ void paintGraphicUsingPrimitivesHelper(vcl::RenderContext & rOutputDevice,
// - it's indeed a jpeg graphic (could be checked by the url ending, but is more reliable to check later)
// In all other cases (normal repaint, print, etc...) use the available Graphic with the
// already loaded pixel graphic as before this change.
- if (rOutputDevice.GetExtOutDevData() && rGrfObj.HasLink() && !rGrfObj.GetGraphic().IsGfxLink())
+ if (rOutputDevice.GetExtOutDevData() /*&& rGrfObj.HasLink()*/ && !rGrfObj.GetGraphic().IsGfxLink())
{
const vcl::PDFExtOutDevData* pPDFExt = dynamic_cast< const vcl::PDFExtOutDevData* >(rOutputDevice.GetExtOutDevData());
if (pPDFExt && pPDFExt->GetIsLosslessCompression())
{
- Graphic aTempGraphic;
- INetURLObject aURL(rGrfObj.GetLink());
-
- if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aTempGraphic, aURL))
- {
- if(aTempGraphic.IsGfxLink() && GfxLinkType::NativeJpg == aTempGraphic.GetGfxLink().GetType())
- {
- aContent[0] = new drawinglayer::primitive2d::GraphicPrimitive2D(
- aTargetTransform,
- aTempGraphic,
- rGraphicAttr);
- bDone = true;
- }
- }
+ // Graphic aTempGraphic;
+ // INetURLObject aURL(rGrfObj.GetLink());
+
+ // if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aTempGraphic, aURL))
+ // {
+ // if(aTempGraphic.IsGfxLink() && GfxLinkType::NativeJpg == aTempGraphic.GetGfxLink().GetType())
+ // {
+ // aContent[0] = new drawinglayer::primitive2d::GraphicPrimitive2D(
+ // aTargetTransform,
+ // aTempGraphic,
+ // rGraphicAttr);
+ // bDone = true;
+ // }
+ // }
}
}
diff --git a/sw/source/core/docnode/swbaslnk.cxx b/sw/source/core/docnode/swbaslnk.cxx
index 80f4ca21d25c..a7d626eb0176 100644
--- a/sw/source/core/docnode/swbaslnk.cxx
+++ b/sw/source/core/docnode/swbaslnk.cxx
@@ -163,7 +163,7 @@ static void lcl_CallModify( SwGrfNode& rGrfNd, SfxPoolItem& rItem )
bGraphicPieceArrived = false;
}
- pSwGrfNode->SetGraphic(aGrf, rGrfObj.GetLink());
+ pSwGrfNode->SetGraphic(aGrf, "");
bUpdate = true;
// In order for the Node to have the right transparency status
diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx
index 0ece2156ee4f..c76a51820034 100644
--- a/sw/source/core/edit/editsh.cxx
+++ b/sw/source/core/edit/editsh.cxx
@@ -248,8 +248,7 @@ bool SwEditShell::IsLinkedGrfSwapOut() const
SwGrfNode *pGrfNode = GetGrfNode_();
return pGrfNode &&
( pGrfNode->IsLinkedFile() &&
- ( GraphicType::Default == pGrfNode->GetGrfObj().GetType() ||
- pGrfNode->GetGrfObj().IsSwappedOut()));
+ ( GraphicType::Default == pGrfNode->GetGrfObj().GetType()));
}
const GraphicObject* SwEditShell::GetGraphicObj() const
diff --git a/sw/source/core/graphic/ndgrf.cxx b/sw/source/core/graphic/ndgrf.cxx
index 82f0678a1843..0c0e90ee3159 100644
--- a/sw/source/core/graphic/ndgrf.cxx
+++ b/sw/source/core/graphic/ndgrf.cxx
@@ -71,7 +71,6 @@ SwGrfNode::SwGrfNode(
mbLinkedInputStreamReady( false ),
mbIsStreamReadOnly( false )
{
- maGrfObj.SetSwapStreamHdl( LINK(this, SwGrfNode, SwapGraphic) );
bInSwapIn = bChgTwipSize =
bFrameInPaint = bScaleImageMap = false;
@@ -89,7 +88,6 @@ SwGrfNode::SwGrfNode( const SwNodeIndex & rWhere,
mbLinkedInputStreamReady( false ),
mbIsStreamReadOnly( false )
{
- maGrfObj.SetSwapStreamHdl( LINK(this, SwGrfNode, SwapGraphic) );
bInSwapIn = bChgTwipSize =
bFrameInPaint = bScaleImageMap = false;
bGraphicArrived = true;
@@ -112,8 +110,6 @@ SwGrfNode::SwGrfNode( const SwNodeIndex & rWhere,
mbLinkedInputStreamReady( false ),
mbIsStreamReadOnly( false )
{
- maGrfObj.SetSwapStreamHdl( LINK(this, SwGrfNode, SwapGraphic) );
-
Graphic aGrf; aGrf.SetDefaultType();
maGrfObj.SetGraphic( aGrf, rGrfName );
@@ -188,13 +184,6 @@ bool SwGrfNode::ReRead(
onGraphicChanged();
bReadGrf = true;
}
- else if( pGrfObj )
- {
- maGrfObj = *pGrfObj;
- maGrfObj.SetLink( rGrfName );
- onGraphicChanged();
- bReadGrf = true;
- }
else
{
// reset data of the old graphic so that the correct placeholder is
@@ -249,15 +238,6 @@ bool SwGrfNode::ReRead(
// create connection without update, as we have the graphic
static_cast<SwBaseLink*>( refLink.get() )->Connect();
}
- else if( pGrfObj )
- {
- maGrfObj = *pGrfObj;
- maGrfObj.SetLink( rGrfName );
- onGraphicChanged();
- bReadGrf = true;
- // create connection without update, as we have the graphic
- static_cast<SwBaseLink*>( refLink.get() )->Connect();
- }
else
{
Graphic aGrf;
@@ -406,11 +386,6 @@ const GraphicObject* SwGrfNode::GetReplacementGrfObj() const
// This returns the bitmap, without the pdf data.
const_cast<SwGrfNode*>(this)->mpReplacementGraphic = new GraphicObject(GetGrfObj().GetGraphic().GetBitmapEx());
}
- if (mpReplacementGraphic)
- {
- mpReplacementGraphic->SetSwapStreamHdl(
- LINK(const_cast<SwGrfNode*>(this), SwGrfNode, SwapReplacement));
- }
}
return mpReplacementGraphic;
@@ -524,7 +499,7 @@ StreamAndStorageNames lcl_GetStreamStorageNames( const OUString& sUserData )
bool SwGrfNode::SwapIn( bool bWaitForData )
{
if( bInSwapIn ) // not recursively!
- return !maGrfObj.IsSwappedOut();
+ return true;
bool bRet = false;
bInSwapIn = true;
@@ -552,56 +527,15 @@ bool SwGrfNode::SwapIn( bool bWaitForData )
ModifyNotification( &aMsgHint, &aMsgHint );
}
}
- else if( maGrfObj.IsSwappedOut() )
- {
- // link to download
- bRet = pLink->SwapIn( bWaitForData );
- }
else
- bRet = true;
- }
- else if( maGrfObj.IsSwappedOut() )
- {
- // graphic is in storage or in a temp file
- if( !HasEmbeddedStreamName() )
{
- bRet = maGrfObj.SwapIn();
- }
- else
- {
- try
- {
- const StreamAndStorageNames aNames = lcl_GetStreamStorageNames( maGrfObj.GetUserData() );
- uno::Reference < embed::XStorage > refPics = GetDocSubstorageOrRoot( aNames.sStorage );
- SvStream* pStrm = GetStreamForEmbedGrf( refPics, aNames.sStream );
- if ( pStrm )
- {
- bRet = ImportGraphic( *pStrm );
- delete pStrm;
- if( bRet )
- {
- maGrfObj.SetUserData();
- }
- }
- }
- catch (const uno::Exception&)
- {
- // #i48434#
- OSL_FAIL( "<SwGrfNode::SwapIn(..)> - unhandled exception!" );
- }
- }
-
- if( bRet )
- {
- SwMsgPoolItem aMsg( RES_GRAPHIC_SWAPIN );
- ModifyNotification( &aMsg, &aMsg );
+ bRet = true;
}
}
else
bRet = true;
- OSL_ENSURE( bRet, "Cannot swap in graphic" );
- if( bRet )
+ if (bRet)
{
if( !nGrfSize.Width() && !nGrfSize.Height() )
SetTwipSize( ::GetGraphicSizeTwip( maGrfObj.GetGraphic(), nullptr ) );
@@ -612,21 +546,6 @@ bool SwGrfNode::SwapIn( bool bWaitForData )
bool SwGrfNode::SwapOut()
{
- if( maGrfObj.GetType() != GraphicType::Default &&
- maGrfObj.GetType() != GraphicType::NONE &&
- !maGrfObj.IsSwappedOut() && !bInSwapIn )
- {
- if( refLink.Is() )
- {
- // written graphics and links are removed here
- return maGrfObj.SwapOut( GRFMGR_AUTOSWAPSTREAM_LINK );
- }
- else
- {
- return maGrfObj.SwapOut();
- }
-
- }
return true;
}
@@ -732,14 +651,12 @@ void SwGrfNode::InsertLink( const OUString& rGrfName, const OUString& rFltName )
(!bSync && !rFltName.isEmpty() ? &rFltName : nullptr) );
}
}
- maGrfObj.SetLink( rGrfName );
}
void SwGrfNode::ReleaseLink()
{
if( refLink.Is() )
{
- const OUString aFileName(maGrfObj.GetLink());
const Graphic aLocalGraphic(maGrfObj.GetGraphic());
const bool bHasOriginalData(aLocalGraphic.IsGfxLink());
@@ -752,7 +669,6 @@ void SwGrfNode::ReleaseLink()
getIDocumentLinksAdministration().GetLinkManager().Remove( refLink.get() );
refLink.Clear();
- maGrfObj.SetLink();
// #i15508# added extra processing after getting rid of the link. Use whatever is
// known from the formerly linked graphic to get to a state as close to a directly
@@ -769,21 +685,6 @@ void SwGrfNode::ReleaseLink()
// This happens e.g. when inserting a linked graphic and breaking the link
maGrfObj.SetGraphic(aLocalGraphic);
}
- else if(!aFileName.isEmpty())
- {
- // #i15508# we have no original data, but a file name. This happens e.g.
- // when inserting a linked graphic and save, reload document. Try to access
- // that data from the original file; if this works, use it. Else use the
- // data we have (but without knowing the original format)
- GraphicFilter& rFlt = GraphicFilter::GetGraphicFilter();
- Graphic aNew;
- int nRes = GraphicFilter::LoadGraphic( aFileName, OUString(), aNew, &rFlt);
-
- if(GRFILTER_OK == nRes)
- {
- maGrfObj.SetGraphic(aNew);
- }
- }
}
}
@@ -961,60 +862,6 @@ SwContentNode* SwGrfNode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const
return pGrfNd;
}
-IMPL_STATIC_LINK(SwGrfNode, SwapReplacement, const GraphicObject*, pGrfObj, SvStream*)
-{
- // replacement image is always swapped
- if (pGrfObj->IsInSwapOut())
- {
- return GRFMGR_AUTOSWAPSTREAM_TEMP;
- }
- else if (pGrfObj->IsInSwapIn())
- {
- return GRFMGR_AUTOSWAPSTREAM_TEMP;
- }
- else
- {
- assert(!"why is swap handler being called?");
- }
-
- return GRFMGR_AUTOSWAPSTREAM_NONE;
-}
-
-IMPL_LINK( SwGrfNode, SwapGraphic, const GraphicObject*, pGrfObj, SvStream* )
-{
- SvStream* pRet;
-
- // Keep graphic while in swap in. That's at least important
- // when breaking links, because in this situation a reschedule call and
- // a DataChanged call lead to a paint of the graphic.
- if( pGrfObj->IsInSwapOut() && (IsSelected() || bInSwapIn) )
- pRet = GRFMGR_AUTOSWAPSTREAM_NONE;
- else if( refLink.Is() )
- {
- if( pGrfObj->IsInSwapIn() )
- {
- // then make it by your self
- if( !bInSwapIn )
- {
- const bool bIsModifyLocked = IsModifyLocked();
- LockModify();
- SwapIn();
- if( !bIsModifyLocked )
- UnlockModify();
- }
- pRet = GRFMGR_AUTOSWAPSTREAM_NONE;
- }
- else
- pRet = GRFMGR_AUTOSWAPSTREAM_LINK;
- }
- else
- {
- pRet = GRFMGR_AUTOSWAPSTREAM_TEMP;
- }
-
- return pRet;
-}
-
/// returns the Graphic-Attr-Structure filled with our graphic attributes
GraphicAttr& SwGrfNode::GetGraphicAttr( GraphicAttr& rGA,
const SwFrame* pFrame ) const
diff --git a/vcl/source/graphic/GraphicObject.cxx b/vcl/source/graphic/GraphicObject.cxx
index 8e2df2a7f440..624a4f8d6e53 100644
--- a/vcl/source/graphic/GraphicObject.cxx
+++ b/vcl/source/graphic/GraphicObject.cxx
@@ -303,129 +303,29 @@ struct GrfSimpleCacheObj
};
GraphicObject::GraphicObject()
- : mbAutoSwapped(false)
- , mbIsInSwapIn(false)
- , mbIsInSwapOut(false)
{
- ImplEnsureGraphicManager();
- ImplAssignGraphicData();
}
GraphicObject::GraphicObject(const Graphic& rGraphic)
: maGraphic(rGraphic)
- , mbAutoSwapped(false)
- , mbIsInSwapIn(false)
- , mbIsInSwapOut(false)
{
- ImplEnsureGraphicManager();
- ImplAssignGraphicData();
}
GraphicObject::GraphicObject(const GraphicObject& rGraphicObj)
: maGraphic(rGraphicObj.GetGraphic())
, maAttr(rGraphicObj.maAttr)
- , maLink(rGraphicObj.maLink)
, maUserData(rGraphicObj.maUserData)
- , mbAutoSwapped(false)
- , mbIsInSwapIn(false)
- , mbIsInSwapOut(false)
{
- ImplAssignGraphicData();
- if( rGraphicObj.HasUserData() && rGraphicObj.IsSwappedOut() )
- SetSwapState();
}
GraphicObject::GraphicObject(const OString& rUniqueID)
- : mbAutoSwapped(false)
- , mbIsInSwapIn(false)
- , mbIsInSwapOut(false)
{
- ImplEnsureGraphicManager();
-
- // assign default properties
- ImplAssignGraphicData();
-
- // update properties
- ImplAssignGraphicData();
}
GraphicObject::~GraphicObject()
{
}
-void GraphicObject::ImplAssignGraphicData()
-{
- maPrefSize = maGraphic.GetPrefSize();
- maPrefMapMode = maGraphic.GetPrefMapMode();
- mnSizeBytes = maGraphic.GetSizeBytes();
- meType = maGraphic.GetType();
- mbTransparent = maGraphic.IsTransparent();
- // mbAlpha = maGraphic.IsAlpha();
- mbAnimated = maGraphic.IsAnimated();
- mbEPS = maGraphic.IsEPS();
- mnAnimationLoopCount = ( mbAnimated ? maGraphic.GetAnimationLoopCount() : 0 );
-}
-
-void GraphicObject::ImplEnsureGraphicManager()
-{
-}
-
-void GraphicObject::ImplAutoSwapIn()
-{
- if( !IsSwappedOut() )
- return;
-
- {
- mbIsInSwapIn = true;
-
- if( maGraphic.SwapIn() )
- mbAutoSwapped = false;
- else
- {
- SvStream* pStream = GetSwapStream();
-
- if( GRFMGR_AUTOSWAPSTREAM_NONE != pStream )
- {
- if( GRFMGR_AUTOSWAPSTREAM_LINK == pStream )
- {
- if( HasLink() )
- {
- OUString aURLStr;
-
- if( osl::FileBase::getFileURLFromSystemPath( GetLink(), aURLStr ) == osl::FileBase::E_None )
- {
- std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aURLStr, StreamMode::READ ));
-
- if( pIStm )
- {
- ReadGraphic( *pIStm, maGraphic );
- mbAutoSwapped = ( maGraphic.GetType() != GraphicType::NONE );
- }
- }
- }
- }
- else if( GRFMGR_AUTOSWAPSTREAM_TEMP == pStream )
- mbAutoSwapped = !maGraphic.SwapIn();
- else if( GRFMGR_AUTOSWAPSTREAM_LOADED == pStream )
- mbAutoSwapped = maGraphic.IsSwapOut();
- else
- {
- mbAutoSwapped = !maGraphic.SwapIn( pStream );
- delete pStream;
- }
- }
- else
- {
- DBG_ASSERT( ( GraphicType::NONE == meType ) || ( GraphicType::Default == meType ),
- "GraphicObject::ImplAutoSwapIn: could not get stream to swap in graphic! (=>KA)" );
- }
- }
-
- mbIsInSwapIn = false;
- }
- ImplAssignGraphicData();
-}
-
GraphicType GraphicObject::GetType() const
{
return maGraphic.GetType();
@@ -529,16 +429,11 @@ GraphicObject& GraphicObject::operator=( const GraphicObject& rGraphicObj )
{
if( &rGraphicObj != this )
{
- maSwapStreamHdl = Link<const GraphicObject*, SvStream*>();
mxSimpleCache.reset();
maGraphic = rGraphicObj.GetGraphic();
maAttr = rGraphicObj.maAttr;
- maLink = rGraphicObj.maLink;
maUserData = rGraphicObj.maUserData;
- mbAutoSwapped = false;
- if( rGraphicObj.HasUserData() && rGraphicObj.IsSwappedOut() )
- SetSwapState();
}
return *this;
@@ -547,26 +442,14 @@ GraphicObject& GraphicObject::operator=( const GraphicObject& rGraphicObj )
bool GraphicObject::operator==( const GraphicObject& rGraphicObj ) const
{
return( ( rGraphicObj.maGraphic == maGraphic ) &&
- ( rGraphicObj.maAttr == maAttr ) &&
- ( rGraphicObj.GetLink() == GetLink() ) );
+ ( rGraphicObj.maAttr == maAttr ) );
}
OString GraphicObject::GetUniqueID() const
{
- if ( !IsInSwapIn() && IsEPS() )
- const_cast<GraphicObject*>(this)->FireSwapInRequest();
-
return GetGraphic().getUniqueID();
}
-SvStream* GraphicObject::GetSwapStream() const
-{
- if( HasSwapStreamHdl() )
- return maSwapStreamHdl.Call( this );
- else
- return GRFMGR_AUTOSWAPSTREAM_NONE;
-}
-
void GraphicObject::SetAttr( const GraphicAttr& rAttr )
{
maAttr = rAttr;
@@ -575,16 +458,6 @@ void GraphicObject::SetAttr( const GraphicAttr& rAttr )
mxSimpleCache.reset();
}
-void GraphicObject::SetLink()
-{
- maLink.clear();
-}
-
-void GraphicObject::SetLink( const OUString& rLink )
-{
- maLink = rLink;
-}
-
void GraphicObject::SetUserData()
{
maUserData.clear();
@@ -593,8 +466,6 @@ void GraphicObject::SetUserData()
void GraphicObject::SetUserData( const OUString& rUserData )
{
maUserData = rUserData;
- if( !rUserData.isEmpty() )
- SetSwapState();
}
static sal_uInt32 GetCacheTimeInMs()
@@ -609,38 +480,6 @@ static sal_uInt32 GetCacheTimeInMs()
return nSeconds * 1000;
}
-void GraphicObject::SetSwapStreamHdl(const Link<const GraphicObject*, SvStream*>& rHdl)
-{
- maSwapStreamHdl = rHdl;
-
- sal_uInt32 const nSwapOutTimeout(GetCacheTimeInMs());
- if (nSwapOutTimeout)
- {
- if (!mxSwapOutTimer)
- {
- mxSwapOutTimer.reset(new Timer("svtools::GraphicObject mpSwapOutTimer"));
- mxSwapOutTimer->SetTimeoutHdl( LINK( this, GraphicObject, ImplAutoSwapOutHdl ) );
- }
-
- mxSwapOutTimer->SetTimeout( nSwapOutTimeout );
- mxSwapOutTimer->Start();
- }
- else
- {
- mxSwapOutTimer.reset();
- }
-}
-
-void GraphicObject::FireSwapInRequest()
-{
- ImplAutoSwapIn();
-}
-
-void GraphicObject::FireSwapOutRequest()
-{
- ImplAutoSwapOutHdl( nullptr );
-}
-
bool GraphicObject::Draw( OutputDevice* pOut, const Point& rPt, const Size& rSz,
const GraphicAttr* pAttr, GraphicManagerDrawFlags nFlags )
{
@@ -737,49 +576,46 @@ bool GraphicObject::StartAnimation( OutputDevice* pOut, const Point& rPt, const
GetGraphic();
- if( !IsSwappedOut() )
+ const GraphicAttr aAttr( GetAttr() );
+
+ if (IsAnimated())
{
- const GraphicAttr aAttr( GetAttr() );
+ Point aPt( rPt );
+ Size aSz( rSz );
+ bool bCropped = aAttr.IsCropped();
- if( mbAnimated )
+ if( bCropped )
{
- Point aPt( rPt );
- Size aSz( rSz );
- bool bCropped = aAttr.IsCropped();
-
- if( bCropped )
- {
- tools::PolyPolygon aClipPolyPoly;
- bool bRectClip;
- const bool bCrop = ImplGetCropParams( pOut, aPt, aSz, &aAttr, aClipPolyPoly, bRectClip );
+ tools::PolyPolygon aClipPolyPoly;
+ bool bRectClip;
+ const bool bCrop = ImplGetCropParams( pOut, aPt, aSz, &aAttr, aClipPolyPoly, bRectClip );
- pOut->Push( PushFlags::CLIPREGION );
+ pOut->Push( PushFlags::CLIPREGION );
- if( bCrop )
- {
- if( bRectClip )
- pOut->IntersectClipRegion( aClipPolyPoly.GetBoundRect() );
- else
- pOut->IntersectClipRegion(vcl::Region(aClipPolyPoly));
- }
- }
-
- if (!mxSimpleCache || (mxSimpleCache->maAttr != aAttr) || pFirstFrameOutDev)
+ if( bCrop )
{
- mxSimpleCache.reset(new GrfSimpleCacheObj(GetTransformedGraphic(&aAttr), aAttr));
- mxSimpleCache->maGraphic.SetAnimationNotifyHdl(GetGraphic().GetAnimationNotifyHdl());
+ if( bRectClip )
+ pOut->IntersectClipRegion( aClipPolyPoly.GetBoundRect() );
+ else
+ pOut->IntersectClipRegion(vcl::Region(aClipPolyPoly));
}
+ }
+
+ if (!mxSimpleCache || (mxSimpleCache->maAttr != aAttr) || pFirstFrameOutDev)
+ {
+ mxSimpleCache.reset(new GrfSimpleCacheObj(GetTransformedGraphic(&aAttr), aAttr));
+ mxSimpleCache->maGraphic.SetAnimationNotifyHdl(GetGraphic().GetAnimationNotifyHdl());
+ }
- mxSimpleCache->maGraphic.StartAnimation(pOut, aPt, aSz, nExtraData, pFirstFrameOutDev);
+ mxSimpleCache->maGraphic.StartAnimation(pOut, aPt, aSz, nExtraData, pFirstFrameOutDev);
- if( bCropped )
- pOut->Pop();
+ if( bCropped )
+ pOut->Pop();
- bRet = true;
- }
- else
- bRet = Draw( pOut, rPt, rSz, &aAttr );
+ bRet = true;
}
+ else
+ bRet = Draw( pOut, rPt, rSz, &aAttr );
return bRet;
}
@@ -792,43 +628,17 @@ void GraphicObject::StopAnimation( OutputDevice* pOut, long nExtraData )
const Graphic& GraphicObject::GetGraphic() const
{
- GraphicObject *pThis = const_cast<GraphicObject*>(this);
- (void)pThis->SwapIn();
-
- //fdo#50697 If we've been asked to provide the graphic, then reset
- //the cache timeout to start from now and not remain at the
- //time of creation
- // restart SwapOut timer; this is like touching in a cache to reset to the full timeout value
- if (pThis->mxSwapOutTimer && pThis->mxSwapOutTimer->IsActive())
- {
- pThis->mxSwapOutTimer->Stop();
- pThis->mxSwapOutTimer->Start();
- }
-
return maGraphic;
}
void GraphicObject::SetGraphic( const Graphic& rGraphic, const GraphicObject* /*pCopyObj*/ )
{
- if (mxSwapOutTimer)
- mxSwapOutTimer->Stop();
-
maGraphic = rGraphic;
- mbAutoSwapped = false;
- maLink.clear();
- mxSimpleCache.reset();
-
- if (mxSwapOutTimer)
- mxSwapOutTimer->Start();
}
void GraphicObject::SetGraphic( const Graphic& rGraphic, const OUString& rLink )
{
- // in case we are called from a situation where rLink and maLink are the same thing,
- // we need a copy because SetGraphic clears maLink
- OUString sLinkCopy = rLink;
SetGraphic( rGraphic );
- maLink = sLinkCopy;
}
Graphic GraphicObject::GetTransformedGraphic( const Size& rDestSize, const MapMode& rDestMap, const GraphicAttr& rAttr ) const
@@ -1065,7 +875,7 @@ Graphic GraphicObject::GetTransformedGraphic( const GraphicAttr* pAttr ) const
Graphic aGraphic;
GraphicAttr aAttr( pAttr ? *pAttr : GetAttr() );
- if( maGraphic.IsSupportedGraphic() && !maGraphic.IsSwapOut() )
+ if (maGraphic.IsSupportedGraphic())
{
if( aAttr.IsSpecialDrawMode() || aAttr.IsAdjusted() || aAttr.IsMirrored() || aAttr.IsRotated() || aAttr.IsTransparent() )
{
@@ -1075,7 +885,7 @@ Graphic GraphicObject::GetTransformedGraphic( const GraphicAttr* pAttr ) const
{
Animation aAnimation( maGraphic.GetAnimation() );
lclImplAdjust( aAnimation, aAttr, GraphicAdjustmentFlags::ALL );
- aAnimation.SetLoopCount( mnAnimationLoopCount );
+ aAnimation.SetLoopCount(maGraphic.GetAnimationLoopCount());
aGraphic = aAnimation;
}
else
@@ -1108,103 +918,6 @@ Graphic GraphicObject::GetTransformedGraphic( const GraphicAttr* pAttr ) const
return aGraphic;
}
-bool GraphicObject::SwapOut()
-{
- const bool bRet = !mbAutoSwapped && maGraphic.SwapOut();
-
- return bRet;
-}
-
-bool GraphicObject::SwapOut( SvStream* pOStm )
-{
- bool bRet = false;
- try
- {
- bRet = !mbAutoSwapped;
- // swap out as a link
- if( pOStm == GRFMGR_AUTOSWAPSTREAM_LINK )
- {
- maGraphic.SwapOutAsLink();
- }
- else
- {
- bRet = bRet && maGraphic.SwapOut( pOStm );
- }
- }
- catch(...)
- {
- SAL_WARN( "svtools", "GraphicObject::SwapIn exception");
- }
- return bRet;
-}
-
-bool GraphicObject::SwapIn()
-{
- bool bRet = false;
- try
- {
- if( mbAutoSwapped )
- {
- ImplAutoSwapIn();
- bRet = true;
- }
- else
- {
- bRet = maGraphic.SwapIn();
- }
-
- if( bRet )
- {
- ImplAssignGraphicData();
- }
- }
- catch (...)
- {
- SAL_WARN( "svtools", "GraphicObject::SwapIn exception");
- }
-
- return bRet;
-}
-
-void GraphicObject::SetSwapState()
-{
- if( !IsSwappedOut() )
- {
- mbAutoSwapped = true;
- }
-}
-
-IMPL_LINK_NOARG(GraphicObject, ImplAutoSwapOutHdl, Timer *, void)
-{
- if( !IsSwappedOut() )
- {
- mbIsInSwapOut = true;
-
- SvStream* pStream = GetSwapStream();
-
- if( GRFMGR_AUTOSWAPSTREAM_NONE != pStream )
- {
- if( GRFMGR_AUTOSWAPSTREAM_LINK == pStream )
- mbAutoSwapped = SwapOut( GRFMGR_AUTOSWAPSTREAM_LINK );
- else
- {
- if( GRFMGR_AUTOSWAPSTREAM_TEMP == pStream )
- mbAutoSwapped = SwapOut();
- else
- {
- mbAutoSwapped = SwapOut( pStream );
- delete pStream;
- }
- }
- }
-
- mbIsInSwapOut = false;
- }
-
- if (mxSwapOutTimer)
- mxSwapOutTimer->Start();
-}
-
#define UNO_NAME_GRAPHOBJ_URLPREFIX "vnd.sun.star.GraphicObject:"
bool GraphicObject::isGraphicObjectUniqueIdURL(OUString const & rURL)
commit 7be2fd11d068bdea630caad2607e6166b12b9288
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Sat Mar 31 17:27:01 2018 +0900
vcl: detach usage and remove GraphicManager and GraphicCache
Also remove some GraphicObjectTest because they call into
GraphicManager which now doesn't exist anymore.
Reviewed-on: https://gerrit.libreoffice.org/52243
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit ea3d755ac949c1b6dada5c341e018f8c23f5d395)
Change-Id: Ia434736d8611df629af3e897c878a7fb8bbe4706
diff --git a/include/vcl/GraphicObject.hxx b/include/vcl/GraphicObject.hxx
index 1ad14e01216f..822f37abb72b 100644
--- a/include/vcl/GraphicObject.hxx
+++ b/include/vcl/GraphicObject.hxx
@@ -168,13 +168,9 @@ public:
class VCL_DLLPUBLIC GraphicObject
{
- friend class GraphicManager;
friend class SdrGrafObj;
private:
-
- static GraphicManager* mpGlobalMgr;
-
Graphic maGraphic;
GraphicAttr maAttr;
Size maPrefSize;
@@ -197,7 +193,6 @@ private:
bool mbEPS : 1;
bool mbIsInSwapIn : 1;
bool mbIsInSwapOut : 1;
- bool mbAlpha : 1;
void VCL_DLLPRIVATE ImplAssignGraphicData();
static void VCL_DLLPRIVATE ImplEnsureGraphicManager();
@@ -305,10 +300,6 @@ private:
) const;
DECL_LINK( ImplAutoSwapOutHdl, Timer*, void );
-
- // Handle evtl. needed AfterDataChanges, needs to be called when new
- // graphic data is swapped in/added to the GraphicManager
- void VCL_DLLPRIVATE ImplAfterDataChange();
protected:
SvStream* GetSwapStream() const;
@@ -317,8 +308,8 @@ protected:
public:
GraphicObject();
GraphicObject( const Graphic& rGraphic );
+ GraphicObject(const OString& rUniqueID);
GraphicObject( const GraphicObject& rCacheObj );
- explicit GraphicObject( const OString& rUniqueID );
~GraphicObject();
GraphicObject& operator=( const GraphicObject& rCacheObj );
@@ -331,21 +322,6 @@ public:
void FireSwapInRequest();
void FireSwapOutRequest();
- GraphicManager& GetGraphicManager() const
- {
- (void)this; // avoid loplugin:staticmethods because first GraphicManager ctor creates
- // mpGlobalMgr and the last GraphicManager dtor destroys it
- return *mpGlobalMgr;
- }
-
- bool IsCached(
- OutputDevice* pOut,
- const Point& rPt,
- const Size& rSz,
- const GraphicAttr* pAttr,
- GraphicManagerDrawFlags nFlags = GraphicManagerDrawFlags::STANDARD
- ) const;
-
const Graphic& GetGraphic() const;
void SetGraphic( const Graphic& rGraphic, const GraphicObject* pCopyObj = nullptr);
void SetGraphic( const Graphic& rGraphic, const OUString& rLink );
@@ -467,6 +443,8 @@ public:
void StopAnimation( OutputDevice* pOut = nullptr, long nExtraData = 0 );
+ static bool isGraphicObjectUniqueIdURL(OUString const & rURL);
+
static GraphicObject CreateGraphicObjectFromURL( const OUString &rURL );
// will inspect an object ( e.g. a control ) for any 'ImageURL'
// properties and return these in a vector. Note: this implementation
@@ -489,128 +467,23 @@ public:
sal_uLong GetDataChangeTimeStamp() const { return mnDataChangeTimeStamp; }
};
-class VCL_DLLPUBLIC GraphicManager
+namespace vcl
+{
+namespace graphic
{
- friend class GraphicObject;
- friend class GraphicDisplayCacheEntry;
-private:
+// Will search an object ( e.g. a control ) for any 'ImageURL' or 'Graphic'
+// properties and return graphics from the properties in a vector. ImageURL
+// will be loaded from the URL.
+//
+// Note: this implementation will cater for XNameContainer objects and deep inspect any containers
+// if they exist
- std::unordered_set< GraphicObject* > maObjList;
- sal_uLong mnUsedSize; // currently used memory footprint of all swapped in graphics
- GraphicCache* mpCache;
-
- GraphicManager( const GraphicManager& ) {}
- GraphicManager& operator=( const GraphicManager& ) { return *this; }
-
- bool VCL_DLLPRIVATE ImplDraw(
- OutputDevice* pOut,
- const Point& rPt,
- const Size& rSz,
- GraphicObject& rObj,
- const GraphicAttr& rAttr,
- const GraphicManagerDrawFlags nFlags,
- bool& rCached
- );
-
- static bool VCL_DLLPRIVATE ImplCreateOutput(
- OutputDevice* pOut,
- const Point& rPt,
- const Size& rSz,
- const BitmapEx& rBmpEx,
- const GraphicAttr& rAttr,
- const GraphicManagerDrawFlags nFlags,
- BitmapEx* pBmpEx = nullptr
- );
- static bool VCL_DLLPRIVATE ImplCreateOutput(
- OutputDevice* pOut,
- const Point& rPt,
- const Size& rSz,
- const GDIMetaFile& rMtf,
- const GraphicAttr& rAttr,
- const GraphicManagerDrawFlags nFlags,
- GDIMetaFile& rOutMtf,
- BitmapEx& rOutBmpEx
- );
-
- static void VCL_DLLPRIVATE ImplAdjust(
- BitmapEx& rBmpEx,
- const GraphicAttr& rAttr,
- GraphicAdjustmentFlags nAdjustmentFlags
- );
- static void VCL_DLLPRIVATE ImplAdjust(
- GDIMetaFile& rMtf,
- const GraphicAttr& rAttr,
- GraphicAdjustmentFlags nAdjustmentFlags
- );
- static void VCL_DLLPRIVATE ImplAdjust(
- Animation& rAnimation,
- const GraphicAttr& rAttr,
- GraphicAdjustmentFlags nAdjustmentFlags
- );
-
- static void VCL_DLLPRIVATE ImplDraw(
- OutputDevice* pOut,
- const Point& rPt,
- const Size& rSz,
- const GDIMetaFile& rMtf,
- const GraphicAttr& rAttr
- );
-
- // Only used by GraphicObject's Ctor's and Dtor's
- void VCL_DLLPRIVATE ImplRegisterObj(
- const GraphicObject& rObj,
- Graphic& rSubstitute,
- const OString* pID,
- const GraphicObject* pCopyObj
- );
- void VCL_DLLPRIVATE ImplUnregisterObj( const GraphicObject& rObj );
- bool VCL_DLLPRIVATE ImplHasObjects() const { return !maObjList.empty(); }
-
- // Only used in swap case by GraphicObject
- void VCL_DLLPRIVATE ImplGraphicObjectWasSwappedOut( const GraphicObject& rObj );
- void VCL_DLLPRIVATE ImplGraphicObjectWasSwappedIn( const GraphicObject& rObj );
-
- OString VCL_DLLPRIVATE ImplGetUniqueID( const GraphicObject& rObj ) const;
-
- // This method allows to check memory footprint for all currently swapped in GraphicObjects on this GraphicManager
- // which are based on Bitmaps. This is needed on 32Bit systems and only does something on those systems. The problem
- // to solve is that normally the SwapOut is timer-driven, but even with short timer settings there are situations
- // where this does not trigger - or in other words: A maximum limitation for GraphicManagers was not in place before.
- // For 32Bit systems this leads to situations where graphics will be missing. This method will actively swap out
- // the longest swapped in graphics until a maximum memory boundary (derived from user settings in tools/options/memory)
- // is no longer exceeded
- void VCL_DLLPRIVATE ImplCheckSizeOfSwappedInGraphics(const GraphicObject* pGraphicToIgnore);
-public:
+VCL_DLLPUBLIC void SearchForGraphics(css::uno::Reference<css::uno::XInterface> const & rxInterface,
+ std::vector<css::uno::Reference<css::graphic::XGraphic>> & raGraphicList);
- GraphicManager( sal_uLong nCacheSize, sal_uLong nMaxObjCacheSize );
- ~GraphicManager();
-
- void SetMaxCacheSize( sal_uLong nNewCacheSize );
- sal_uLong GetMaxCacheSize() const;
-
- void SetMaxObjCacheSize( sal_uLong nNewMaxObjSize );
-
- void SetCacheTimeout( sal_uLong nTimeoutSeconds );
-
- bool IsInCache(
- OutputDevice* pOut,
- const Point& rPt,
- const Size& rSz,
- const GraphicObject& rObj,
- const GraphicAttr& rAttr
- ) const;
-
- bool DrawObj(
- OutputDevice* pOut,
- const Point& rPt,
- const Size& rSz,
- GraphicObject& rObj,
- const GraphicAttr& rAttr,
- const GraphicManagerDrawFlags nFlags,
- bool& rCached
- );
-};
+}
+} // end namespace vcl::graphic
#endif // INCLUDED_VCL_GRAPHICOBJECT_HXX
diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx
index 5e6a47b09559..8bc96ddfab73 100644
--- a/include/vcl/graph.hxx
+++ b/include/vcl/graph.hxx
@@ -198,6 +198,8 @@ public:
OUString getOriginURL() const;
void setOriginURL(OUString const & rOriginURL);
+ OString getUniqueID() const;
+
public:
std::shared_ptr<GraphicReader>& GetContext();
diff --git a/svtools/qa/unit/GraphicObjectTest.cxx b/svtools/qa/unit/GraphicObjectTest.cxx
index e4709e23db3a..7d646dacd085 100644
--- a/svtools/qa/unit/GraphicObjectTest.cxx
+++ b/svtools/qa/unit/GraphicObjectTest.cxx
@@ -38,9 +38,7 @@ class GraphicObjectTest: public test::BootstrapFixture, public unotest::MacrosTe
public:
void testSwap();
- void testSizeBasedAutoSwap();
void testTdf88836();
- void testTdf88935();
void testPdf();
@@ -57,9 +55,7 @@ private:
private:
CPPUNIT_TEST_SUITE(GraphicObjectTest);
CPPUNIT_TEST(testSwap);
- CPPUNIT_TEST(testSizeBasedAutoSwap);
CPPUNIT_TEST(testTdf88836);
- CPPUNIT_TEST(testTdf88935);
CPPUNIT_TEST(testPdf);
CPPUNIT_TEST_SUITE_END();
};
@@ -147,92 +143,6 @@ void GraphicObjectTest::testSwap()
}
}
-void GraphicObjectTest::testSizeBasedAutoSwap()
-{
- // Set cache size to a very small value to check what happens
- {
- std::shared_ptr< comphelper::ConfigurationChanges > aBatch(comphelper::ConfigurationChanges::create());
- officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(sal_Int32(1), aBatch);
- aBatch->commit();
- }
-
- uno::Reference< lang::XComponent > xComponent =
- loadFromDesktop(m_directories.getURLFromSrc("svtools/qa/unit/data/document_with_two_images.odt"), "com.sun.star.text.TextDocument");
-
- SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(xComponent.get());
- CPPUNIT_ASSERT(pTxtDoc);
- SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
- CPPUNIT_ASSERT(pDoc);
- SwNodes& aNodes = pDoc->GetNodes();
-
- // Find images
- const GraphicObject* pGrafObj1 = nullptr;
- const GraphicObject* pGrafObj2 = nullptr;
- for( sal_uLong nIndex = 0; nIndex < aNodes.Count(); ++nIndex)
- {
- if( aNodes[nIndex]->IsGrfNode() )
- {
- SwGrfNode* pGrfNode = aNodes[nIndex]->GetGrfNode();
- CPPUNIT_ASSERT(pGrfNode);
- if( !pGrafObj1 )
- {
- pGrafObj1 = &pGrfNode->GetGrfObj();
- }
- else
- {
- pGrafObj2 = &pGrfNode->GetGrfObj();
- }
- }
- }
- CPPUNIT_ASSERT_MESSAGE("Missing image", pGrafObj1 != nullptr && pGrafObj2 != nullptr);
-
- {
- // First image should be swapped out
- CPPUNIT_ASSERT(pGrafObj1->IsSwappedOut());
- CPPUNIT_ASSERT_EQUAL(sal_uLong(697230), pGrafObj1->GetGraphic().GetSizeBytes());
-
- // Still swapped out: size is cached
- CPPUNIT_ASSERT(pGrafObj1->IsSwappedOut());
- }
-
- {
- // Second image should be in the memory
- // Size based swap out is triggered by swap in, so the last swapped in image should be
- // in the memory despite of size limit is reached.
- CPPUNIT_ASSERT(!pGrafObj2->IsSwappedOut());
- CPPUNIT_ASSERT_EQUAL(sal_uLong(1620000), pGrafObj2->GetGraphic().GetSizeBytes());
- }
-
- // Swap in first image -> second image will be swapped out
- {
- pGrafObj1->GetGraphic(); // GetGraphic calls swap in on a const object
- CPPUNIT_ASSERT(!pGrafObj1->IsSwappedOut());
- CPPUNIT_ASSERT(pGrafObj2->IsSwappedOut());
- }
-
- // Swap in second image -> first image will be swapped out
- {
- pGrafObj2->GetGraphic(); // GetGraphic calls swap in on a const object
- CPPUNIT_ASSERT(!pGrafObj2->IsSwappedOut());
- CPPUNIT_ASSERT(pGrafObj1->IsSwappedOut());
- }
-
- // Use bigger cache
- {
- GraphicManager& rGrfMgr = pGrafObj1->GetGraphicManager();
- rGrfMgr.SetMaxCacheSize((pGrafObj1->GetGraphic().GetSizeBytes()+pGrafObj2->GetGraphic().GetSizeBytes())*10);
- }
- // Swap in both images -> both should be swapped in
- {
- pGrafObj1->GetGraphic();
- pGrafObj2->GetGraphic();
- CPPUNIT_ASSERT(!pGrafObj1->IsSwappedOut());
- CPPUNIT_ASSERT(!pGrafObj2->IsSwappedOut());
- }
-
- xComponent->dispose();
-}
-
void GraphicObjectTest::testTdf88836()
{
// Construction with empty bitmap -> type should be GraphicType::NONE
@@ -242,73 +152,6 @@ void GraphicObjectTest::testTdf88836()
CPPUNIT_ASSERT_EQUAL(int(GraphicType::NONE), int(aGraphic.GetType()));
}
-void GraphicObjectTest::testTdf88935()
-{
- // Cache size was not updated by deletion of graphic objects
-
- // Load a file with two images
- uno::Reference< lang::XComponent > xComponent =
- loadFromDesktop(m_directories.getURLFromSrc("svtools/qa/unit/data/document_with_two_images.odt"), "com.sun.star.text.TextDocument");
- SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(xComponent.get());
- CPPUNIT_ASSERT(pTxtDoc);
- SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
- CPPUNIT_ASSERT(pDoc);
- SwNodes& aNodes = pDoc->GetNodes();
-
- // Find images
- const GraphicObject* pGraphObj1 = nullptr;
- const GraphicObject* pGraphObj2 = nullptr;
- for( sal_uLong nIndex = 0; nIndex < aNodes.Count(); ++nIndex)
- {
- if( aNodes[nIndex]->IsGrfNode() )
- {
- SwGrfNode* pGrfNode = aNodes[nIndex]->GetGrfNode();
- CPPUNIT_ASSERT(pGrfNode);
- if( !pGraphObj1 )
- {
- pGraphObj1 = &pGrfNode->GetGrfObj();
- }
- else
- {
- pGraphObj2 = &pGrfNode->GetGrfObj();
- }
- }
- }
- CPPUNIT_ASSERT_MESSAGE("Missing image", pGraphObj1 != nullptr && pGraphObj2 != nullptr);
-
- // Set cache size
- {
- GraphicManager& rGrfMgr = pGraphObj1->GetGraphicManager();
- rGrfMgr.SetMaxCacheSize((pGraphObj1->GetGraphic().GetSizeBytes()+pGraphObj2->GetGraphic().GetSizeBytes())*10);
- }
-
- // Both images fit into the cache
- {
- pGraphObj1->GetGraphic();
- pGraphObj2->GetGraphic();
- CPPUNIT_ASSERT(!pGraphObj1->IsSwappedOut());
- CPPUNIT_ASSERT(!pGraphObj2->IsSwappedOut());
- }
-
- // Create and remove some copy of the first image
- for( int i = 0; i < 50; ++i )
- {
- GraphicObject aGraphObj3(*pGraphObj1);
- CPPUNIT_ASSERT(aGraphObj3.SwapOut());
- CPPUNIT_ASSERT(aGraphObj3.SwapIn());
- }
-
- // Both images fit into the cache
- {
- pGraphObj1->GetGraphic();
- pGraphObj2->GetGraphic();
- CPPUNIT_ASSERT(!pGraphObj1->IsSwappedOut());
- CPPUNIT_ASSERT(!pGraphObj2->IsSwappedOut());
- }
-
- xComponent->dispose();
-}
-
void GraphicObjectTest::testPdf()
{
#if HAVE_FEATURE_PDFIUM
diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx
index 1159fbdf3663..556727e5d504 100644
--- a/sw/source/core/doc/notxtfrm.cxx
+++ b/sw/source/core/doc/notxtfrm.cxx
@@ -583,29 +583,8 @@ void SwNoTextFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
case RES_GRF_REREAD_AND_INCACHE:
if( SwNodeType::Grf == GetNode()->GetNodeType() )
{
+ // TODO: Remove - due to GraphicObject refactoring
bComplete = false;
- SwGrfNode* pNd = static_cast<SwGrfNode*>( GetNode());
-
- SwViewShell* pVSh = pNd->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
- if( pVSh )
- {
- GraphicAttr aAttr;
- if( pNd->GetGrfObj().IsCached( pVSh->GetOut(), Point(),
- Prt().SSize(), &pNd->GetGraphicAttr( aAttr, this ) ))
- {
- for(SwViewShell& rShell : pVSh->GetRingContainer())
- {
- SET_CURR_SHELL( &rShell );
- if( rShell.GetWin() )
- {
- if( rShell.IsPreview() )
- ::RepaintPagePreview( &rShell, Frame().SVRect() );
- else
- rShell.GetWin()->Invalidate( Frame().SVRect() );
- }
- }
- }
- }
}
break;
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 6dfa6445a4ad..11e7fe32a1be 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -306,7 +306,6 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/graphic/GraphicLoader \
vcl/source/graphic/GraphicObject \
vcl/source/graphic/GraphicObject2 \
- vcl/source/graphic/grfcache \
vcl/source/graphic/grfattr \
vcl/source/graphic/Manager \
vcl/source/graphic/UnoGraphic \
diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx
index 2383c1a5f53d..e36181321341 100644
--- a/vcl/inc/impgraph.hxx
+++ b/vcl/inc/impgraph.hxx
@@ -42,9 +42,35 @@ struct ImpSwapFile;
class GraphicConversionParameters;
class ImpGraphic;
+class GraphicID
+{
+private:
+ sal_uInt32 mnID1;
+ sal_uInt32 mnID2;
+ sal_uInt32 mnID3;
+ BitmapChecksum mnID4;
+
+public:
+ GraphicID(ImpGraphic& rGraphic);
+
+ bool operator==(const GraphicID& rID) const
+ {
+ return rID.mnID1 == mnID1 && rID.mnID2 == mnID2 &&
+ rID.mnID3 == mnID3 && rID.mnID4 == mnID4;
+ }
+
+ bool IsEmpty() const
+ {
+ return 0 == mnID4;
+ }
+
+ OString getIDString() const;
+};
+
class ImpGraphic final
{
friend class Graphic;
+ friend class GraphicID;
friend class vcl::graphic::Manager;
private:
@@ -61,6 +87,8 @@ private:
bool mbSwapOut;
bool mbDummyContext;
SvgDataPtr maSvgData;
+ std::unique_ptr<GraphicID> mpGraphicID;
+
/// The PDF stream from which this Graphic is rendered,
/// as converted (version downgraded) from the original,
@@ -112,6 +140,13 @@ private:
return mpPdfData && mpPdfData->hasElements();
}
+ OString getUniqueID()
+ {
+ if (!mpGraphicID)
+ mpGraphicID.reset(new GraphicID(*this));
+ return mpGraphicID->getIDString();
+ }
+
void ImplCreateSwapInfo();
void ImplClearGraphics();
void ImplClear();
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx
index dfb091362ec9..ef10b004cf39 100644
--- a/vcl/source/gdi/graph.cxx
+++ b/vcl/source/gdi/graph.cxx
@@ -643,6 +643,14 @@ void Graphic::setOriginURL(OUString const & rOriginURL)
}
}
+OString Graphic::getUniqueID() const
+{
+ OString aUniqueString;
+ if (mxImpGraphic)
+ aUniqueString = mxImpGraphic->getUniqueID();
+ return aUniqueString;
+}
+
namespace {
struct Id: public rtl::Static<cppu::OImplementationId, Id> {};
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 004c315a8ea7..be5f442269a2 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -41,6 +41,7 @@
#include <vcl/dibtools.hxx>
#include <memory>
#include <o3tl/make_unique.hxx>
+#include <rtl/strbuf.hxx>
#include <vcl/pdfread.hxx>
@@ -101,6 +102,76 @@ Size GraphicReader::GetPreviewSize() const
return aSize;
}
+GraphicID::GraphicID(ImpGraphic & rGraphic)
+{
+ mnID1 = static_cast<sal_uLong>(rGraphic.ImplGetType()) << 28;
+ mnID2 = mnID3 = mnID4 = 0;
+
+ if (rGraphic.ImplGetType() == GraphicType::Bitmap)
+ {
+ if (rGraphic.getSvgData().get())
+ {
+ const SvgDataPtr& rSvgDataPtr = rGraphic.getSvgData();
+ const basegfx::B2DRange& rRange = rSvgDataPtr->getRange();
+
+ mnID1 |= rSvgDataPtr->getSvgDataArrayLength();
+ mnID2 = basegfx::fround(rRange.getWidth());
+ mnID3 = basegfx::fround(rRange.getHeight());
+ mnID4 = vcl_get_checksum(0, rSvgDataPtr->getSvgDataArray().getConstArray(), rSvgDataPtr->getSvgDataArrayLength());
+ }
+ else if (rGraphic.ImplIsAnimated())
+ {
+ const Animation aAnimation(rGraphic.ImplGetAnimation());
+
+ mnID1 |= ( aAnimation.Count() & 0x0fffffff );
+ mnID2 = aAnimation.GetDisplaySizePixel().Width();
+ mnID3 = aAnimation.GetDisplaySizePixel().Height();
+ mnID4 = rGraphic.ImplGetChecksum();
+ }
+ else
+ {
+ const BitmapEx aBmpEx(rGraphic.ImplGetBitmapEx(GraphicConversionParameters()));
+
+ mnID1 |= ( ( ( static_cast<sal_uLong>(aBmpEx.GetTransparentType()) << 8 ) | ( aBmpEx.IsAlpha() ? 1 : 0 ) ) & 0x0fffffff );
+ mnID2 = aBmpEx.GetSizePixel().Width();
+ mnID3 = aBmpEx.GetSizePixel().Height();
+ mnID4 = rGraphic.ImplGetChecksum();
+ }
+ }
+ else if (rGraphic.ImplGetType() == GraphicType::GdiMetafile)
+ {
+ const GDIMetaFile& rMtf = rGraphic.ImplGetGDIMetaFile();
+
+ mnID1 |= ( rMtf.GetActionSize() & 0x0fffffff );
+ mnID2 = rMtf.GetPrefSize().Width();
+ mnID3 = rMtf.GetPrefSize().Height();
+ mnID4 = rGraphic.ImplGetChecksum();
+ }
+}
+
+OString GraphicID::getIDString() const
+{
+ static const char aHexData[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+
+ OStringBuffer aHexStr;
+ sal_Int32 nShift, nIndex = 0;
+ aHexStr.setLength(24 + (2 * BITMAP_CHECKSUM_SIZE));
+
+ for( nShift = 28; nShift >= 0; nShift -= 4 )
+ aHexStr[nIndex++] = aHexData[ ( mnID1 >> static_cast<sal_uInt32>(nShift) ) & 0xf ];
+
+ for( nShift = 28; nShift >= 0; nShift -= 4 )
+ aHexStr[nIndex++] = aHexData[ ( mnID2 >> static_cast<sal_uInt32>(nShift) ) & 0xf ];
+
+ for( nShift = 28; nShift >= 0; nShift -= 4 )
+ aHexStr[nIndex++] = aHexData[ ( mnID3 >> static_cast<sal_uInt32>(nShift) ) & 0xf ];
+
+ for( nShift = ( 8 * BITMAP_CHECKSUM_SIZE ) - 4; nShift >= 0; nShift -= 4 )
+ aHexStr[nIndex++] = aHexData[ ( mnID4 >> static_cast<sal_uInt32>(nShift) ) & 0xf ];
+
+ return aHexStr.makeStringAndClear();
+}
+
ImpGraphic::ImpGraphic() :
meType ( GraphicType::NONE ),
mnSizeBytes ( 0UL ),
diff --git a/vcl/source/graphic/GraphicObject.cxx b/vcl/source/graphic/GraphicObject.cxx
index 444a5a26cf24..8e2df2a7f440 100644
--- a/vcl/source/graphic/GraphicObject.cxx
+++ b/vcl/source/graphic/GraphicObject.cxx
@@ -34,11 +34,15 @@
#include <vcl/metaact.hxx>
#include <vcl/virdev.hxx>
#include <vcl/GraphicObject.hxx>
+#include <vcl/GraphicLoader.hxx>
+#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <memory>
+
+using namespace css;
using com::sun::star::uno::Reference;
using com::sun::star::uno::XInterface;
using com::sun::star::uno::UNO_QUERY;
@@ -46,7 +50,248 @@ using com::sun::star::uno::Sequence;
using com::sun::star::container::XNameContainer;
using com::sun::star::beans::XPropertySet;
-GraphicManager* GraphicObject::mpGlobalMgr = nullptr;
+#define WATERMARK_LUM_OFFSET 50
+#define WATERMARK_CON_OFFSET -70
+
+namespace vcl
+{
+namespace graphic
+{
+
+void SearchForGraphics(uno::Reference<uno::XInterface> const & xInterface,
+ std::vector<uno::Reference<css::graphic::XGraphic>> & raGraphicList)
+{
+ uno::Reference<beans::XPropertySet> xPropertySet(xInterface, UNO_QUERY);
+ if (xPropertySet.is())
+ {
+ if (xPropertySet->getPropertySetInfo()->hasPropertyByName("ImageURL"))
+ {
+ OUString sURL;
+ xPropertySet->getPropertyValue("ImageURL") >>= sURL;
+ if (!sURL.isEmpty() && !GraphicObject::isGraphicObjectUniqueIdURL(sURL))
+ {
+ Graphic aGraphic = vcl::graphic::loadFromURL(sURL);
+ if (aGraphic)
+ {
+ raGraphicList.push_back(aGraphic.GetXGraphic());
+ }
+ }
+ } else if (xPropertySet->getPropertySetInfo()->hasPropertyByName("Graphic"))
+ {
+ uno::Reference<css::graphic::XGraphic> xGraphic;
+ xPropertySet->getPropertyValue("Graphic") >>= xGraphic;
+ if (xGraphic.is())
+ {
+ raGraphicList.push_back(xGraphic);
+ }
+ }
+ }
+ Reference<XNameContainer> xContainer(xInterface, UNO_QUERY);
+ if (xContainer.is())
+ {
+ for (OUString const & rName : xContainer->getElementNames())
+ {
+ uno::Reference<XInterface> xInnerInterface;
+ xContainer->getByName(rName) >>= xInnerInterface;
+ SearchForGraphics(xInnerInterface, raGraphicList);
+ }
+ }
+}
+
+}} // end namespace vcl::graphic
+
+namespace
+{
+
+bool lclDrawObj( OutputDevice* pOut, const Point& rPt, const Size& rSz,
+ GraphicObject const & rObj, const GraphicAttr& rAttr)
+{
+ Point aPt( rPt );
+ Size aSz( rSz );
+ bool bRet = false;
+
+ if( ( rObj.GetType() == GraphicType::Bitmap ) || ( rObj.GetType() == GraphicType::GdiMetafile ) )
+ {
+ // simple output of transformed graphic
+ const Graphic aGraphic( rObj.GetTransformedGraphic( &rAttr ) );
+
+ if( aGraphic.IsSupportedGraphic() )
+ {
+ const sal_uInt16 nRot10 = rAttr.GetRotation() % 3600;
+
+ if( nRot10 )
+ {
+ tools::Polygon aPoly( Rectangle( aPt, aSz ) );
+
+ aPoly.Rotate( aPt, nRot10 );
+ const Rectangle aRotBoundRect( aPoly.GetBoundRect() );
+ aPt = aRotBoundRect.TopLeft();
+ aSz = aRotBoundRect.GetSize();
+ }
+
+ aGraphic.Draw( pOut, aPt, aSz );
+ }
+
+ bRet = true;
+ }
+
+ return bRet;
+}
+
+void lclImplAdjust( BitmapEx& rBmpEx, const GraphicAttr& rAttr, GraphicAdjustmentFlags nAdjustmentFlags )
+{
+ GraphicAttr aAttr( rAttr );
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::DRAWMODE ) && aAttr.IsSpecialDrawMode() )
+ {
+ switch( aAttr.GetDrawMode() )
+ {
+ case GRAPHICDRAWMODE_MONO:
+ rBmpEx.Convert( BmpConversion::N1BitThreshold );
+ break;
+
+ case GRAPHICDRAWMODE_GREYS:
+ rBmpEx.Convert( BmpConversion::N8BitGreys );
+ break;
+
+ case GRAPHICDRAWMODE_WATERMARK:
+ {
+ aAttr.SetLuminance( aAttr.GetLuminance() + WATERMARK_LUM_OFFSET );
+ aAttr.SetContrast( aAttr.GetContrast() + WATERMARK_CON_OFFSET );
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::COLORS ) && aAttr.IsAdjusted() )
+ {
+ rBmpEx.Adjust( aAttr.GetLuminance(), aAttr.GetContrast(),
+ aAttr.GetChannelR(), aAttr.GetChannelG(), aAttr.GetChannelB(),
+ aAttr.GetGamma(), aAttr.IsInvert() );
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::MIRROR ) && aAttr.IsMirrored() )
+ {
+ rBmpEx.Mirror( aAttr.GetMirrorFlags() );
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::ROTATE ) && aAttr.IsRotated() )
+ {
+ rBmpEx.Rotate( aAttr.GetRotation(), COL_TRANSPARENT );
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::TRANSPARENCY ) && aAttr.IsTransparent() )
+ {
+ rBmpEx.AdjustTransparency(aAttr.GetTransparency());
+ }
+}
+
+void lclImplAdjust( GDIMetaFile& rMtf, const GraphicAttr& rAttr, GraphicAdjustmentFlags nAdjustmentFlags )
+{
+ GraphicAttr aAttr( rAttr );
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::DRAWMODE ) && aAttr.IsSpecialDrawMode() )
+ {
+ switch( aAttr.GetDrawMode() )
+ {
+ case GRAPHICDRAWMODE_MONO:
+ rMtf.Convert( MtfConversion::N1BitThreshold );
+ break;
+
+ case GRAPHICDRAWMODE_GREYS:
+ rMtf.Convert( MtfConversion::N8BitGreys );
+ break;
+
+ case GRAPHICDRAWMODE_WATERMARK:
+ {
+ aAttr.SetLuminance( aAttr.GetLuminance() + WATERMARK_LUM_OFFSET );
+ aAttr.SetContrast( aAttr.GetContrast() + WATERMARK_CON_OFFSET );
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::COLORS ) && aAttr.IsAdjusted() )
+ {
+ rMtf.Adjust( aAttr.GetLuminance(), aAttr.GetContrast(),
+ aAttr.GetChannelR(), aAttr.GetChannelG(), aAttr.GetChannelB(),
+ aAttr.GetGamma(), aAttr.IsInvert() );
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::MIRROR ) && aAttr.IsMirrored() )
+ {
+ rMtf.Mirror( aAttr.GetMirrorFlags() );
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::ROTATE ) && aAttr.IsRotated() )
+ {
+ rMtf.Rotate( aAttr.GetRotation() );
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::TRANSPARENCY ) && aAttr.IsTransparent() )
+ {
+ OSL_FAIL( "Missing implementation: Mtf-Transparency" );
+ }
+}
+
+void lclImplAdjust( Animation& rAnimation, const GraphicAttr& rAttr, GraphicAdjustmentFlags nAdjustmentFlags )
+{
+ GraphicAttr aAttr( rAttr );
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::DRAWMODE ) && aAttr.IsSpecialDrawMode() )
+ {
+ switch( aAttr.GetDrawMode() )
+ {
+ case GRAPHICDRAWMODE_MONO:
+ rAnimation.Convert( BmpConversion::N1BitThreshold );
+ break;
+
+ case GRAPHICDRAWMODE_GREYS:
+ rAnimation.Convert( BmpConversion::N8BitGreys );
+ break;
+
+ case GRAPHICDRAWMODE_WATERMARK:
+ {
+ aAttr.SetLuminance( aAttr.GetLuminance() + WATERMARK_LUM_OFFSET );
+ aAttr.SetContrast( aAttr.GetContrast() + WATERMARK_CON_OFFSET );
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::COLORS ) && aAttr.IsAdjusted() )
+ {
+ rAnimation.Adjust( aAttr.GetLuminance(), aAttr.GetContrast(),
+ aAttr.GetChannelR(), aAttr.GetChannelG(), aAttr.GetChannelB(),
+ aAttr.GetGamma(), aAttr.IsInvert() );
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::MIRROR ) && aAttr.IsMirrored() )
+ {
+ rAnimation.Mirror( aAttr.GetMirrorFlags() );
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::ROTATE ) && aAttr.IsRotated() )
+ {
+ OSL_FAIL( "Missing implementation: Animation-Rotation" );
+ }
+
+ if( ( nAdjustmentFlags & GraphicAdjustmentFlags::TRANSPARENCY ) && aAttr.IsTransparent() )
+ {
+ OSL_FAIL( "Missing implementation: Animation-Transparency" );
+ }
+}
+
+} // end anonymous namespace
struct GrfSimpleCacheObj
{
@@ -57,19 +302,6 @@ struct GrfSimpleCacheObj
maGraphic( rGraphic ), maAttr( rAttr ) {}
};
-// unique increasing ID for being able to detect the GraphicObject with the
-// oldest last data changes
-static sal_uLong aIncrementingTimeOfLastDataChange = 1;
-
-void GraphicObject::ImplAfterDataChange()
-{
- // set unique timestamp ID of last data change
- mnDataChangeTimeStamp = aIncrementingTimeOfLastDataChange++;
-
- // check memory footprint of all GraphicObjects managed and evtl. take action
- mpGlobalMgr->ImplCheckSizeOfSwappedInGraphics(this);
-}
-
GraphicObject::GraphicObject()
: mbAutoSwapped(false)
, mbIsInSwapIn(false)
@@ -77,7 +309,6 @@ GraphicObject::GraphicObject()
{
ImplEnsureGraphicManager();
ImplAssignGraphicData();
- mpGlobalMgr->ImplRegisterObj(*this, maGraphic, nullptr, nullptr);
}
GraphicObject::GraphicObject(const Graphic& rGraphic)
@@ -88,7 +319,6 @@ GraphicObject::GraphicObject(const Graphic& rGraphic)
{
ImplEnsureGraphicManager();
ImplAssignGraphicData();
- mpGlobalMgr->ImplRegisterObj(*this, maGraphic, nullptr, nullptr);
}
GraphicObject::GraphicObject(const GraphicObject& rGraphicObj)
@@ -101,7 +331,6 @@ GraphicObject::GraphicObject(const GraphicObject& rGraphicObj)
, mbIsInSwapOut(false)
{
ImplAssignGraphicData();
- mpGlobalMgr->ImplRegisterObj(*this, maGraphic, nullptr, &rGraphicObj);
if( rGraphicObj.HasUserData() && rGraphicObj.IsSwappedOut() )
SetSwapState();
}
@@ -116,21 +345,12 @@ GraphicObject::GraphicObject(const OString& rUniqueID)
// assign default properties
ImplAssignGraphicData();
- mpGlobalMgr->ImplRegisterObj(*this, maGraphic, &rUniqueID, nullptr);
-
// update properties
ImplAssignGraphicData();
}
GraphicObject::~GraphicObject()
{
- mpGlobalMgr->ImplUnregisterObj( *this );
-
- if (!mpGlobalMgr->ImplHasObjects())
- {
- delete mpGlobalMgr;
- mpGlobalMgr = nullptr;
- }
}
void GraphicObject::ImplAssignGraphicData()
@@ -144,94 +364,66 @@ void GraphicObject::ImplAssignGraphicData()
mbAnimated = maGraphic.IsAnimated();
mbEPS = maGraphic.IsEPS();
mnAnimationLoopCount = ( mbAnimated ? maGraphic.GetAnimationLoopCount() : 0 );
-
- // Handle evtl. needed AfterDataChanges
- ImplAfterDataChange();
}
void GraphicObject::ImplEnsureGraphicManager()
{
- if (!mpGlobalMgr)
- {
- if (!utl::ConfigManager::IsAvoidConfig())
- {
- mpGlobalMgr = new GraphicManager(
- (officecfg::Office::Common::Cache::GraphicManager::
- TotalCacheSize::get()),
- (officecfg::Office::Common::Cache::GraphicManager::
- ObjectCacheSize::get()));
- mpGlobalMgr->SetCacheTimeout(
- officecfg::Office::Common::Cache::GraphicManager::
- ObjectReleaseTime::get());
- }
- else
- {
- mpGlobalMgr = new GraphicManager(
- 20000,
- 20000);
- mpGlobalMgr->SetCacheTimeout(
- 20000);
- }
- }
}
void GraphicObject::ImplAutoSwapIn()
{
- if( IsSwappedOut() )
+ if( !IsSwappedOut() )
+ return;
+
{
+ mbIsInSwapIn = true;
+
+ if( maGraphic.SwapIn() )
+ mbAutoSwapped = false;
+ else
{
- mbIsInSwapIn = true;
+ SvStream* pStream = GetSwapStream();
- if( maGraphic.SwapIn() )
- mbAutoSwapped = false;
- else
+ if( GRFMGR_AUTOSWAPSTREAM_NONE != pStream )
{
- SvStream* pStream = GetSwapStream();
-
- if( GRFMGR_AUTOSWAPSTREAM_NONE != pStream )
+ if( GRFMGR_AUTOSWAPSTREAM_LINK == pStream )
{
- if( GRFMGR_AUTOSWAPSTREAM_LINK == pStream )
+ if( HasLink() )
{
- if( HasLink() )
+ OUString aURLStr;
+
+ if( osl::FileBase::getFileURLFromSystemPath( GetLink(), aURLStr ) == osl::FileBase::E_None )
{
- OUString aURLStr;
+ std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aURLStr, StreamMode::READ ));
- if( osl::FileBase::getFileURLFromSystemPath( GetLink(), aURLStr ) == osl::FileBase::E_None )
+ if( pIStm )
{
- std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aURLStr, StreamMode::READ ));
-
- if( pIStm )
- {
- ReadGraphic( *pIStm, maGraphic );
- mbAutoSwapped = ( maGraphic.GetType() != GraphicType::NONE );
- }
+ ReadGraphic( *pIStm, maGraphic );
+ mbAutoSwapped = ( maGraphic.GetType() != GraphicType::NONE );
}
}
}
- else if( GRFMGR_AUTOSWAPSTREAM_TEMP == pStream )
- mbAutoSwapped = !maGraphic.SwapIn();
- else if( GRFMGR_AUTOSWAPSTREAM_LOADED == pStream )
- mbAutoSwapped = maGraphic.IsSwapOut();
- else
- {
- mbAutoSwapped = !maGraphic.SwapIn( pStream );
- delete pStream;
- }
}
+ else if( GRFMGR_AUTOSWAPSTREAM_TEMP == pStream )
+ mbAutoSwapped = !maGraphic.SwapIn();
+ else if( GRFMGR_AUTOSWAPSTREAM_LOADED == pStream )
+ mbAutoSwapped = maGraphic.IsSwapOut();
else
{
- DBG_ASSERT( ( GraphicType::NONE == meType ) || ( GraphicType::Default == meType ),
- "GraphicObject::ImplAutoSwapIn: could not get stream to swap in graphic! (=>KA)" );
+ mbAutoSwapped = !maGraphic.SwapIn( pStream );
+ delete pStream;
}
}
-
- mbIsInSwapIn = false;
-
- if (!mbAutoSwapped)
- mpGlobalMgr->ImplGraphicObjectWasSwappedIn( *this );
+ else
+ {
+ DBG_ASSERT( ( GraphicType::NONE == meType ) || ( GraphicType::Default == meType ),
+ "GraphicObject::ImplAutoSwapIn: could not get stream to swap in graphic! (=>KA)" );
+ }
}
- ImplAssignGraphicData();
+
+ mbIsInSwapIn = false;
}
+ ImplAssignGraphicData();
}
GraphicType GraphicObject::GetType() const
@@ -337,8 +529,6 @@ GraphicObject& GraphicObject::operator=( const GraphicObject& rGraphicObj )
{
if( &rGraphicObj != this )
{
- mpGlobalMgr->ImplUnregisterObj( *this );
-
maSwapStreamHdl = Link<const GraphicObject*, SvStream*>();
mxSimpleCache.reset();
@@ -347,7 +537,6 @@ GraphicObject& GraphicObject::operator=( const GraphicObject& rGraphicObj )
maLink = rGraphicObj.maLink;
maUserData = rGraphicObj.maUserData;
mbAutoSwapped = false;
- mpGlobalMgr->ImplRegisterObj( *this, maGraphic, nullptr, &rGraphicObj );
if( rGraphicObj.HasUserData() && rGraphicObj.IsSwappedOut() )
SetSwapState();
}
@@ -367,7 +556,7 @@ OString GraphicObject::GetUniqueID() const
if ( !IsInSwapIn() && IsEPS() )
const_cast<GraphicObject*>(this)->FireSwapInRequest();
- return mpGlobalMgr->ImplGetUniqueID(*this);
+ return GetGraphic().getUniqueID();
}
SvStream* GraphicObject::GetSwapStream() const
@@ -452,29 +641,6 @@ void GraphicObject::FireSwapOutRequest()
ImplAutoSwapOutHdl( nullptr );
}
-bool GraphicObject::IsCached( OutputDevice* pOut, const Point& rPt, const Size& rSz,
- const GraphicAttr* pAttr, GraphicManagerDrawFlags nFlags ) const
-{
- bool bRet;
-
- if( nFlags & GraphicManagerDrawFlags::CACHED )
- {
- Point aPt( rPt );
- Size aSz( rSz );
- if ( pAttr && pAttr->IsCropped() )
- {
- tools::PolyPolygon aClipPolyPoly;
- bool bRectClip;
- ImplGetCropParams( pOut, aPt, aSz, pAttr, aClipPolyPoly, bRectClip );
- }
- bRet = mpGlobalMgr->IsInCache( pOut, aPt, aSz, *this, ( pAttr ? *pAttr : GetAttr() ) );
- }
- else
- bRet = false;
-
- return bRet;
-}
-
bool GraphicObject::Draw( OutputDevice* pOut, const Point& rPt, const Size& rSz,
const GraphicAttr* pAttr, GraphicManagerDrawFlags nFlags )
{
@@ -483,7 +649,6 @@ bool GraphicObject::Draw( OutputDevice* pOut, const Point& rPt, const Size& rSz,
Size aSz( rSz );
const DrawModeFlags nOldDrawMode = pOut->GetDrawMode();
bool bCropped = aAttr.IsCropped();
- bool bCached = false;
bool bRet;
// #i29534# Provide output rects for PDF writer
@@ -532,23 +697,13 @@ bool GraphicObject::Draw( OutputDevice* pOut, const Point& rPt, const Size& rSz,
}
}
- bRet = mpGlobalMgr->DrawObj( pOut, aPt, aSz, *this, aAttr, nFlags, bCached );
+ bRet = lclDrawObj(pOut, aPt, aSz, *this, aAttr);
if( bCropped )
pOut->Pop();
pOut->SetDrawMode( nOldDrawMode );
- // #i29534# Moved below OutDev restoration, to avoid multiple swap-ins
- // (code above needs to call GetGraphic twice)
- if( bCached )
- {
- if (mxSwapOutTimer)
- mxSwapOutTimer->Start();
- else
- FireSwapOutRequest();
- }
-
return bRet;
}
@@ -653,10 +808,8 @@ const Graphic& GraphicObject::GetGraphic() const
return maGraphic;
}
-void GraphicObject::SetGraphic( const Graphic& rGraphic, const GraphicObject* pCopyObj )
+void GraphicObject::SetGraphic( const Graphic& rGraphic, const GraphicObject* /*pCopyObj*/ )
{
- mpGlobalMgr->ImplUnregisterObj( *this );
-
if (mxSwapOutTimer)
mxSwapOutTimer->Stop();
@@ -665,12 +818,8 @@ void GraphicObject::SetGraphic( const Graphic& rGraphic, const GraphicObject* pC
maLink.clear();
mxSimpleCache.reset();
- mpGlobalMgr->ImplRegisterObj( *this, maGraphic, nullptr, pCopyObj);
-
if (mxSwapOutTimer)
mxSwapOutTimer->Start();
-
-
}
void GraphicObject::SetGraphic( const Graphic& rGraphic, const OUString& rLink )
@@ -909,7 +1058,7 @@ Graphic GraphicObject::GetTransformedGraphic( const Size& rDestSize, const MapMo
return aTransGraphic;
}
-Graphic GraphicObject::GetTransformedGraphic( const GraphicAttr* pAttr ) const // TODO: Change to Impl
+Graphic GraphicObject::GetTransformedGraphic( const GraphicAttr* pAttr ) const
{
GetGraphic();
@@ -925,21 +1074,21 @@ Graphic GraphicObject::GetTransformedGraphic( const GraphicAttr* pAttr ) const /
if( IsAnimated() )
{
Animation aAnimation( maGraphic.GetAnimation() );
- GraphicManager::ImplAdjust( aAnimation, aAttr, GraphicAdjustmentFlags::ALL );
+ lclImplAdjust( aAnimation, aAttr, GraphicAdjustmentFlags::ALL );
aAnimation.SetLoopCount( mnAnimationLoopCount );
aGraphic = aAnimation;
}
else
{
BitmapEx aBmpEx( maGraphic.GetBitmapEx() );
- GraphicManager::ImplAdjust( aBmpEx, aAttr, GraphicAdjustmentFlags::ALL );
+ lclImplAdjust( aBmpEx, aAttr, GraphicAdjustmentFlags::ALL );
aGraphic = aBmpEx;
}
}
else
{
GDIMetaFile aMtf( maGraphic.GetGDIMetaFile() );
- GraphicManager::ImplAdjust( aMtf, aAttr, GraphicAdjustmentFlags::ALL );
+ lclImplAdjust( aMtf, aAttr, GraphicAdjustmentFlags::ALL );
aGraphic = aMtf;
}
}
@@ -963,9 +1112,6 @@ bool GraphicObject::SwapOut()
{
const bool bRet = !mbAutoSwapped && maGraphic.SwapOut();
- if (bRet)
- mpGlobalMgr->ImplGraphicObjectWasSwappedOut( *this );
-
return bRet;
}
@@ -984,9 +1130,6 @@ bool GraphicObject::SwapOut( SvStream* pOStm )
{
bRet = bRet && maGraphic.SwapOut( pOStm );
}
-
- if (bRet)
- mpGlobalMgr->ImplGraphicObjectWasSwappedOut(*this);
}
catch(...)
{
@@ -1008,9 +1151,6 @@ bool GraphicObject::SwapIn()
else
{
bRet = maGraphic.SwapIn();
-
- if (bRet)
- mpGlobalMgr->ImplGraphicObjectWasSwappedIn(*this);
}
if( bRet )
@@ -1031,8 +1171,6 @@ void GraphicObject::SetSwapState()
if( !IsSwappedOut() )
{
mbAutoSwapped = true;
-
- mpGlobalMgr->ImplGraphicObjectWasSwappedOut(*this);
}
}
@@ -1069,6 +1207,12 @@ IMPL_LINK_NOARG(GraphicObject, ImplAutoSwapOutHdl, Timer *, void)
#define UNO_NAME_GRAPHOBJ_URLPREFIX "vnd.sun.star.GraphicObject:"
+bool GraphicObject::isGraphicObjectUniqueIdURL(OUString const & rURL)
+ {
+ const OUString aPrefix("vnd.sun.star.GraphicObject:");
+ return rURL.startsWith(aPrefix);
+ }
+
GraphicObject GraphicObject::CreateGraphicObjectFromURL( const OUString &rURL )
{
const OUString aPrefix( UNO_NAME_GRAPHOBJ_URLPREFIX );
diff --git a/vcl/source/graphic/GraphicObject2.cxx b/vcl/source/graphic/GraphicObject2.cxx
index 87122f5af02d..b96cd679c731 100644
--- a/vcl/source/graphic/GraphicObject2.cxx
+++ b/vcl/source/graphic/GraphicObject2.cxx
@@ -31,1605 +31,9 @@
#include <vcl/animate.hxx>
#include <vcl/alpha.hxx>
#include <vcl/virdev.hxx>
-#include "grfcache.hxx"
#include <vcl/GraphicObject.hxx>
#include <memory>
-
-#define WATERMARK_LUM_OFFSET 50
-#define WATERMARK_CON_OFFSET -70
-#define MAP( cVal0, cVal1, nFrac ) ((sal_uInt8)((((long)(cVal0)<<20)+nFrac*((long)(cVal1)-(cVal0)))>>20))
-
-
-GraphicManager::GraphicManager( sal_uLong nCacheSize, sal_uLong nMaxObjCacheSize ) :
- mnUsedSize(0),
- mpCache( new GraphicCache( nCacheSize, nMaxObjCacheSize ) )
-{
-}
-
-GraphicManager::~GraphicManager()
-{
- assert(maObjList.empty());
- delete mpCache;
-}
-
-void GraphicManager::SetMaxCacheSize( sal_uLong nNewCacheSize )
-{
- mpCache->SetMaxDisplayCacheSize( nNewCacheSize );
-}
-
-sal_uLong GraphicManager::GetMaxCacheSize() const
-{
- return mpCache->GetMaxDisplayCacheSize();
-}
-
-void GraphicManager::SetMaxObjCacheSize( sal_uLong nNewMaxObjSize )
-{
- mpCache->SetMaxObjDisplayCacheSize( nNewMaxObjSize );
-}
-
-void GraphicManager::SetCacheTimeout( sal_uLong nTimeoutSeconds )
-{
- mpCache->SetCacheTimeout( nTimeoutSeconds );
-}
-
-bool GraphicManager::IsInCache( OutputDevice* pOut, const Point& rPt,
- const Size& rSz, const GraphicObject& rObj,
- const GraphicAttr& rAttr ) const
-{
- return mpCache->IsInDisplayCache( pOut, rPt, rSz, rObj, rAttr );
-}
-
-bool GraphicManager::DrawObj( OutputDevice* pOut, const Point& rPt, const Size& rSz,
- GraphicObject& rObj, const GraphicAttr& rAttr,
- const GraphicManagerDrawFlags nFlags, bool& rCached )
-{
- Point aPt( rPt );
- Size aSz( rSz );
- bool bRet = false;
-
- rCached = false;
-
- if( ( rObj.GetType() == GraphicType::Bitmap ) || ( rObj.GetType() == GraphicType::GdiMetafile ) )
- {
- // create output and fill cache
-
- if( rObj.IsAnimated() || ( pOut->GetOutDevType() == OUTDEV_PRINTER ) ||
- ( !( nFlags & GraphicManagerDrawFlags::NO_SUBSTITUTE ) &&
- ( ( nFlags & GraphicManagerDrawFlags::SUBSTITUTE ) ||
- !( nFlags & GraphicManagerDrawFlags::CACHED ) ||
- ( pOut->GetConnectMetaFile() && !pOut->IsOutputEnabled() ) ) ) )
- {
- // simple output of transformed graphic
- const Graphic aGraphic( rObj.GetTransformedGraphic( &rAttr ) );
-
- if( aGraphic.IsSupportedGraphic() )
- {
- const sal_uInt16 nRot10 = rAttr.GetRotation() % 3600;
-
- if( nRot10 )
- {
- tools::Polygon aPoly( Rectangle( aPt, aSz ) );
-
- aPoly.Rotate( aPt, nRot10 );
- const Rectangle aRotBoundRect( aPoly.GetBoundRect() );
- aPt = aRotBoundRect.TopLeft();
- aSz = aRotBoundRect.GetSize();
- }
-
- aGraphic.Draw( pOut, aPt, aSz );
- }
-
- bRet = true;
- }
-
- if( !bRet )
- {
- // cached/direct drawing
- if( !mpCache->DrawDisplayCacheObj( pOut, aPt, aSz, rObj, rAttr ) )
- bRet = ImplDraw( pOut, aPt, aSz, rObj, rAttr, nFlags, rCached );
- else
- bRet = rCached = true;
- }
- }
-
- return bRet;
-}
-
-void GraphicManager::ImplRegisterObj( const GraphicObject& rObj, Graphic& rSubstitute,
- const OString* pID, const GraphicObject* pCopyObj )
-{
- assert(maObjList.find(const_cast<GraphicObject*>(&rObj)) == maObjList.end());
-
- maObjList.emplace( const_cast<GraphicObject*>(&rObj) );
-
- mpCache->AddGraphicObject( rObj, rSubstitute, pID, pCopyObj );
- if( !rObj.IsSwappedOut() )
- mnUsedSize += rObj.maGraphic.GetSizeBytes();
-}
-
-void GraphicManager::ImplUnregisterObj( const GraphicObject& rObj )
-{
- mpCache->ReleaseGraphicObject( rObj );
- if( !rObj.IsSwappedOut() )
- {
- assert(mnUsedSize >= rObj.maGraphic.GetSizeBytes());
- mnUsedSize -= rObj.maGraphic.GetSizeBytes();
- }
- if ( 0 < maObjList.erase( const_cast<GraphicObject*>(&rObj) ) )
- return;
-
- assert(false); // surely it should have been registered?
-}
-
-void GraphicManager::ImplGraphicObjectWasSwappedOut( const GraphicObject& rObj )
-{
- mpCache->GraphicObjectWasSwappedOut( rObj );
- assert(mnUsedSize >= rObj.GetGraphic().GetSizeBytes());
- mnUsedSize -= rObj.GetGraphic().GetSizeBytes();
-}
-
-OString GraphicManager::ImplGetUniqueID( const GraphicObject& rObj ) const
-{
- return mpCache->GetUniqueID( rObj );
-}
-
-namespace
-{
- struct simpleSortByDataChangeTimeStamp
- {
- bool operator() (GraphicObject* p1, GraphicObject* p2) const
- {
- return p1->GetDataChangeTimeStamp() < p2->GetDataChangeTimeStamp();
- }
- };
-} // end of anonymous namespace
-
-void GraphicManager::ImplCheckSizeOfSwappedInGraphics(const GraphicObject* pGraphicToIgnore)
-{
- // detect maximum allowed memory footprint. Use the user-settings of MaxCacheSize (defaulted
- // to 200MB).
- const sal_uLong nMaxCacheSize(GetMaxCacheSize());
-
- 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(decltype(aCandidates)::size_type 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
- GraphicObject* pObj = aCandidates[a];
- if( pObj == pGraphicToIgnore )
- {
- continue;
- }
- if (maObjList.find(pObj) == maObjList.end())
- {
- // object has been deleted when swapping out another one
- continue;
- }
-
- // do not swap out when we have less than 16KB data objects
- if(pObj->GetGraphic().GetSizeBytes() >= (16 * 1024))
- {
- pObj->FireSwapOutRequest();
- }
- }
- }
-}
-
-void GraphicManager::ImplGraphicObjectWasSwappedIn( const GraphicObject& rObj )
-{
- mpCache->GraphicObjectWasSwappedIn( rObj );
- mnUsedSize += rObj.maGraphic.GetSizeBytes();
-}
-
-bool GraphicManager::ImplDraw( OutputDevice* pOut, const Point& rPt,
- const Size& rSz, GraphicObject& rObj,
- const GraphicAttr& rAttr,
- const GraphicManagerDrawFlags nFlags, bool& rCached )
-{
- const Graphic& rGraphic = rObj.GetGraphic();
- bool bRet = false;
-
- if( rGraphic.IsSupportedGraphic() && !rObj.IsSwappedOut() )
- {
- if( GraphicType::Bitmap == rGraphic.GetType() )
- {
- const BitmapEx aSrcBmpEx( rGraphic.GetBitmapEx() );
-
- // #i46805# No point in caching a bitmap that is rendered
- // via RectFill on the OutDev
- if( !(pOut->GetDrawMode() & ( DrawModeFlags::BlackBitmap | DrawModeFlags::WhiteBitmap )) &&
- mpCache->IsDisplayCacheable( pOut, rPt, rSz, rObj, rAttr ) )
- {
- BitmapEx aDstBmpEx;
-
- if( ImplCreateOutput( pOut, rPt, rSz, aSrcBmpEx, rAttr, nFlags, &aDstBmpEx ) )
- {
- rCached = mpCache->CreateDisplayCacheObj( pOut, rPt, rSz, rObj, rAttr, aDstBmpEx );
- bRet = true;
- }
- }
-
- if( !bRet )
- bRet = ImplCreateOutput( pOut, rPt, rSz, aSrcBmpEx, rAttr, nFlags );
- }
- else
- {
- const GDIMetaFile& rSrcMtf = rGraphic.GetGDIMetaFile();
-
- if( mpCache->IsDisplayCacheable( pOut, rPt, rSz, rObj, rAttr ) )
- {
- GDIMetaFile aDstMtf;
- BitmapEx aContainedBmpEx;
-
- if( ImplCreateOutput( pOut, rPt, rSz, rSrcMtf, rAttr, nFlags, aDstMtf, aContainedBmpEx ) )
- {
- if( !!aContainedBmpEx )
- {
- // Use bitmap output method, if metafile basically contains only a single
- // bitmap (allows caching the resulting pixmap).
- BitmapEx aDstBmpEx;
-
- if( ImplCreateOutput( pOut, rPt, rSz, aContainedBmpEx, rAttr, nFlags, &aDstBmpEx ) )
- {
- rCached = mpCache->CreateDisplayCacheObj( pOut, rPt, rSz, rObj, rAttr, aDstBmpEx );
- bRet = true;
- }
- }
- else
- {
- rCached = mpCache->CreateDisplayCacheObj( pOut, rPt, rSz, rObj, rAttr, aDstMtf );
- bRet = true;
- }
- }
- }
-
- if( !bRet )
- {
- const Graphic aGraphic( rObj.GetTransformedGraphic( &rAttr ) );
-
- if( aGraphic.IsSupportedGraphic() )
- {
- aGraphic.Draw( pOut, rPt, rSz );
- bRet = true;
- }
- }
- }
- }
-
- return bRet;
-}
-
-bool ImplCreateRotatedScaled( const BitmapEx& rBmpEx, const GraphicAttr& rAttributes,
- sal_uInt16 nRot10, const Size& rUnrotatedSzPix,
- long nStartX, long nEndX, long nStartY, long nEndY,
- BitmapEx& rOutBmpEx )
-{
- const long aUnrotatedWidth = rUnrotatedSzPix.Width();
- const long aUnrotatedHeight = rUnrotatedSzPix.Height();
- const long aBitmapWidth = rBmpEx.GetSizePixel().Width();
- const long aBitmapHeight = rBmpEx.GetSizePixel().Height();
-
- long nTmpX, nTmpY, nTmpFX, nTmpFY, nTmp;
- double fTmp;
-
- bool bHMirr( rAttributes.GetMirrorFlags() & BmpMirrorFlags::Horizontal );
- bool bVMirr( rAttributes.GetMirrorFlags() & BmpMirrorFlags::Vertical );
-
- std::unique_ptr<long[]> pMapIX(new long[ aUnrotatedWidth ]);
- std::unique_ptr<long[]> pMapFX(new long[ aUnrotatedWidth ]);
- std::unique_ptr<long[]> pMapIY(new long[ aUnrotatedHeight ]);
- std::unique_ptr<long[]> pMapFY(new long[ aUnrotatedHeight ]);
-
- double fRevScaleX;
- double fRevScaleY;
-
- bool scaleByAveraging = false;
-
- if(aBitmapWidth > 1 && aUnrotatedWidth > 1)
- {
- fRevScaleX = (double) ( aBitmapWidth - 1 ) / (double)( aUnrotatedWidth - 1 );
- // create horizontal mapping table
- long x;
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list