include/vcl/BinaryDataContainerTools.hxx | 23 +++++++ vcl/Library_vcl.mk | 1 vcl/inc/graphic/Manager.hxx | 5 + vcl/inc/graphic/UnoBinaryDataContainer.hxx | 53 +++++++++++++++++ vcl/source/gdi/impgraph.cxx | 18 +++--- vcl/source/graphic/BinaryDataContainerTools.cxx | 28 +++++++++ vcl/source/graphic/Manager.cxx | 57 ++++++++++++++----- vcl/source/graphic/UnoBinaryDataContainer.cxx | 72 +++--------------------- vcl/vcl.common.component | 4 - 9 files changed, 173 insertions(+), 88 deletions(-)
New commits: commit f59194150398272343713aa5adbde00d65eb203f Author: Tomaž Vajngerl <[email protected]> AuthorDate: Thu Dec 31 19:38:25 2020 +0900 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Thu Dec 31 19:38:25 2020 +0900 BinaryDataContainer UNO improvement Change-Id: I44afd52d39bcb3d11bbd6676f54118b4161786cb diff --git a/include/vcl/BinaryDataContainerTools.hxx b/include/vcl/BinaryDataContainerTools.hxx new file mode 100644 index 000000000000..d3d2cbe1f73e --- /dev/null +++ b/include/vcl/BinaryDataContainerTools.hxx @@ -0,0 +1,23 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#pragma once + +#include <vcl/dllapi.h> +#include <vcl/BinaryDataContainer.hxx> +#include <com/sun/star/util/XBinaryDataContainer.hpp> + +namespace vcl +{ +VCL_DLLPUBLIC BinaryDataContainer convertUnoBinaryDataContainer( + const css::uno::Reference<css::util::XBinaryDataContainer>& rxBinaryDataContainer); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index b7b47ac463ec..478638da2220 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -322,6 +322,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/pdf/PDFiumLibrary \ vcl/source/pdf/ExternalPDFStreams \ vcl/source/graphic/BinaryDataContainer \ + vcl/source/graphic/BinaryDataContainerTools \ vcl/source/graphic/GraphicID \ vcl/source/graphic/GraphicLoader \ vcl/source/graphic/GraphicObject \ diff --git a/vcl/inc/graphic/UnoBinaryDataContainer.hxx b/vcl/inc/graphic/UnoBinaryDataContainer.hxx new file mode 100644 index 000000000000..f722d8966b62 --- /dev/null +++ b/vcl/inc/graphic/UnoBinaryDataContainer.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + */ + +#pragma once + +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <comphelper/servicehelper.hxx> + +#include <com/sun/star/util/XBinaryDataContainer.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <vcl/BinaryDataContainer.hxx> + +class UnoBinaryDataContainer final + : public cppu::WeakImplHelper<css::util::XBinaryDataContainer, css::lang::XUnoTunnel> +{ +private: + BinaryDataContainer maBinaryDataContainer; + +public: + UnoBinaryDataContainer() {} + + UnoBinaryDataContainer(BinaryDataContainer const& rBinaryDataContainer) + : maBinaryDataContainer(rBinaryDataContainer) + { + } + + BinaryDataContainer const& getBinaryDataContainer() const { return maBinaryDataContainer; } + + void setBinaryDataContainer(BinaryDataContainer const& rBinaryDataContainer) + { + maBinaryDataContainer = rBinaryDataContainer; + } + + // XBinaryDataContainer + css::uno::Sequence<sal_Int8> SAL_CALL getCopyAsByteSequence() override; + + UNO3_GETIMPLEMENTATION_DECL(UnoBinaryDataContainer) +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/graphic/BinaryDataContainerTools.cxx b/vcl/source/graphic/BinaryDataContainerTools.cxx new file mode 100644 index 000000000000..3921e075cea2 --- /dev/null +++ b/vcl/source/graphic/BinaryDataContainerTools.cxx @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <vcl/BinaryDataContainerTools.hxx> +#include <graphic/UnoBinaryDataContainer.hxx> + +namespace vcl +{ +BinaryDataContainer convertUnoBinaryDataContainer( + const css::uno::Reference<css::util::XBinaryDataContainer>& rxBinaryDataContainer) +{ + BinaryDataContainer aBinaryDataContainer; + UnoBinaryDataContainer* pUnoBinaryDataContainer + = comphelper::getUnoTunnelImplementation<UnoBinaryDataContainer>(rxBinaryDataContainer); + if (pUnoBinaryDataContainer) + aBinaryDataContainer = pUnoBinaryDataContainer->getBinaryDataContainer(); + return aBinaryDataContainer; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/graphic/UnoBinaryDataContainer.cxx b/vcl/source/graphic/UnoBinaryDataContainer.cxx index cd6ce99d4a39..8ee3660be416 100644 --- a/vcl/source/graphic/UnoBinaryDataContainer.cxx +++ b/vcl/source/graphic/UnoBinaryDataContainer.cxx @@ -8,77 +8,27 @@ * */ -#include <cppuhelper/implbase.hxx> -#include <cppuhelper/supportsservice.hxx> +#include <graphic/UnoBinaryDataContainer.hxx> -#include <com/sun/star/util/XBinaryDataContainer.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/uno/XComponentContext.hpp> - -#include <vcl/BinaryDataContainer.hxx> +#include <cppuhelper/queryinterface.hxx> using namespace css; -namespace -{ -typedef ::cppu::WeakImplHelper<util::XBinaryDataContainer, css::lang::XServiceInfo> - BinaryDataContainer_BASE; +// css::lang::XUnoTunnel +UNO3_GETIMPLEMENTATION_IMPL(UnoBinaryDataContainer); -class UnoBinaryDataContainer : public BinaryDataContainer_BASE +css::uno::Sequence<sal_Int8> SAL_CALL UnoBinaryDataContainer::getCopyAsByteSequence() { -private: - BinaryDataContainer maBinaryDataContainer; - -public: - explicit UnoBinaryDataContainer() {} - - BinaryDataContainer const& getBinaryDataContainer() { return maBinaryDataContainer; } - - void setBinaryDataContainer(BinaryDataContainer const& rBinaryDataContainer) - { - maBinaryDataContainer = rBinaryDataContainer; - } - - // XBinaryDataContainer - css::uno::Sequence<sal_Int8> SAL_CALL getCopyAsByteSequence() override - { - if (maBinaryDataContainer.isEmpty()) - return css::uno::Sequence<sal_Int8>(); + if (maBinaryDataContainer.isEmpty()) + return css::uno::Sequence<sal_Int8>(); - size_t nSize = maBinaryDataContainer.getSize(); + size_t nSize = maBinaryDataContainer.getSize(); - css::uno::Sequence<sal_Int8> aData(nSize); + css::uno::Sequence<sal_Int8> aData(nSize); - std::copy(maBinaryDataContainer.cbegin(), maBinaryDataContainer.cend(), aData.getArray()); + std::copy(maBinaryDataContainer.cbegin(), maBinaryDataContainer.cend(), aData.getArray()); - return aData; - } - - // XServiceInfo - virtual OUString SAL_CALL getImplementationName() override - { - return "com.sun.star.util.BinaryDataContainer"; - } - - virtual sal_Bool SAL_CALL supportsService(OUString const& rServiceName) override - { - return cppu::supportsService(this, rServiceName); - } - - virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override - { - return uno::Sequence<OUString>{ "com.sun.star.util.BinaryDataContainer" }; - } -}; - -} // end anonymous namespace - -extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* -com_sun_star_comp_util_BinaryDataContainer_get_implementation( - SAL_UNUSED_PARAMETER uno::XComponentContext*, - SAL_UNUSED_PARAMETER uno::Sequence<uno::Any> const&) -{ - return cppu::acquire(new UnoBinaryDataContainer()); + return aData; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/vcl.common.component b/vcl/vcl.common.component index abf5da9c10dd..2665a136afcc 100644 --- a/vcl/vcl.common.component +++ b/vcl/vcl.common.component @@ -35,8 +35,4 @@ constructor="dtrans_CMimeContentTypeFactory_get_implementation"> <service name="com.sun.star.datatransfer.MimeContentTypeFactory"/> </implementation> - <implementation name="com.sun.star.util.BinaryDataContainer" - constructor="com_sun_star_comp_util_BinaryDataContainer_get_implementation"> - <service name="com.sun.star.util.BinaryDataContainer"/> - </implementation> </component> commit 56254577d762adec3059eb50fbd71bbeecc3be1b Author: Tomaž Vajngerl <[email protected]> AuthorDate: Wed Dec 30 17:13:35 2020 +0900 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Wed Dec 30 17:13:35 2020 +0900 vcl: Improve graphic manager swapping allocation This improves the counting of the used space by graphics and makes the manager loop faster. Change-Id: Ifebe5fe52722d0f22dae0d1bdef02f65afb036ae diff --git a/vcl/inc/graphic/Manager.hxx b/vcl/inc/graphic/Manager.hxx index bff72780cbd7..098c8644ac61 100644 --- a/vcl/inc/graphic/Manager.hxx +++ b/vcl/inc/graphic/Manager.hxx @@ -41,6 +41,7 @@ private: Manager(); void registerGraphic(const std::shared_ptr<ImpGraphic>& rImpGraphic); + void loopGraphicsAndSwapOut(); DECL_LINK(SwapOutTimerHandler, Timer*, void); @@ -49,8 +50,8 @@ private: public: static Manager& get(); - void swappedIn(const ImpGraphic* pImpGraphic); - void swappedOut(const ImpGraphic* pImpGraphic); + void swappedIn(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes); + void swappedOut(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes); void reduceGraphicMemory(); void changeExisting(const ImpGraphic* pImpGraphic, sal_Int64 nOldSize); diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 778d05c951b0..d98875dc7c98 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -1269,6 +1269,8 @@ bool ImpGraphic::swapOut() bool bResult = false; + sal_Int64 nByteSize = getSizeBytes(); + // We have GfxLink so we have the source available if (mpGfxLink && mpGfxLink->IsNative()) { @@ -1282,9 +1284,6 @@ bool ImpGraphic::swapOut() // mark as swapped out mbSwapOut = true; - // Signal to manager that we have swapped out - vcl::graphic::Manager::get().swappedOut(this); - bResult = true; } else @@ -1324,12 +1323,15 @@ bool ImpGraphic::swapOut() mpSwapFile = std::move(pSwapFile); mbSwapOut = true; - - // Signal to manager that we have swapped out - vcl::graphic::Manager::get().swappedOut(this); } } + if (bResult) + { + // Signal to manager that we have swapped out + vcl::graphic::Manager::get().swappedOut(this, nByteSize); + } + return bResult; } @@ -1465,7 +1467,9 @@ bool ImpGraphic::swapIn() } if (bReturn) - vcl::graphic::Manager::get().swappedIn(this); + { + vcl::graphic::Manager::get().swappedIn(this, getSizeBytes()); + } return bReturn; } diff --git a/vcl/source/graphic/Manager.cxx b/vcl/source/graphic/Manager.cxx index 5d535e446955..b6bf8bef610b 100644 --- a/vcl/source/graphic/Manager.cxx +++ b/vcl/source/graphic/Manager.cxx @@ -75,25 +75,23 @@ Manager::Manager() } } -void Manager::reduceGraphicMemory() +void Manager::loopGraphicsAndSwapOut() { - if (!mbSwapEnabled) - return; - - std::scoped_lock<std::recursive_mutex> aGuard(maMutex); - // make a copy of m_pImpGraphicList because if we swap out a svg, the svg // filter may create more temp Graphics which are auto-added to // m_pImpGraphicList invalidating a loop over m_pImpGraphicList, e.g. // reexport of tdf118346-1.odg o3tl::sorted_vector<ImpGraphic*> aImpGraphicList = m_pImpGraphicList; + for (ImpGraphic* pEachImpGraphic : aImpGraphicList) { - if (mnUsedSize < mnMemoryLimit * 0.7) + if (double(mnUsedSize) < sal_Int64(mnMemoryLimit * 0.7)) return; + if (pEachImpGraphic->isSwappedOut()) + continue; sal_Int64 nCurrentGraphicSize = getGraphicSizeBytes(pEachImpGraphic); - if (!pEachImpGraphic->isSwappedOut() && nCurrentGraphicSize > 1000000) + if (nCurrentGraphicSize > 100000) { if (!pEachImpGraphic->mpContext) { @@ -108,6 +106,33 @@ void Manager::reduceGraphicMemory() } } +void Manager::reduceGraphicMemory() +{ + if (!mbSwapEnabled) + return; + + if (mnUsedSize < mnMemoryLimit) + return; + + std::scoped_lock<std::recursive_mutex> aGuard(maMutex); + + loopGraphicsAndSwapOut(); + + sal_Int64 calculatedSize = 0; + for (ImpGraphic* pEachImpGraphic : m_pImpGraphicList) + { + if (!pEachImpGraphic->isSwappedOut()) + { + calculatedSize += getGraphicSizeBytes(pEachImpGraphic); + } + } + + if (calculatedSize != mnUsedSize) + { + mnUsedSize = calculatedSize; + } +} + sal_Int64 Manager::getGraphicSizeBytes(const ImpGraphic* pImpGraphic) { if (!pImpGraphic->isAvailable()) @@ -213,18 +238,22 @@ std::shared_ptr<ImpGraphic> Manager::newInstance(const GraphicExternalLink& rGra return pReturn; } -void Manager::swappedIn(const ImpGraphic* pImpGraphic) +void Manager::swappedIn(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes) { std::scoped_lock<std::recursive_mutex> aGuard(maMutex); - - mnUsedSize += getGraphicSizeBytes(pImpGraphic); + if (pImpGraphic) + { + mnUsedSize += nSizeBytes; + } } -void Manager::swappedOut(const ImpGraphic* pImpGraphic) +void Manager::swappedOut(const ImpGraphic* pImpGraphic, sal_Int64 nSizeBytes) { std::scoped_lock<std::recursive_mutex> aGuard(maMutex); - - mnUsedSize -= getGraphicSizeBytes(pImpGraphic); + if (pImpGraphic) + { + mnUsedSize -= nSizeBytes; + } } void Manager::changeExisting(const ImpGraphic* pImpGraphic, sal_Int64 nOldSizeBytes) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
