include/vcl/graph.hxx | 1 vcl/Library_vcl.mk | 1 vcl/inc/graphic/Manager.hxx | 3 + vcl/inc/graphic/VectorGraphicLoader.hxx | 24 ++++++++++ vcl/inc/impgraph.hxx | 1 vcl/source/filter/ipdf/pdfread.cxx | 6 -- vcl/source/gdi/graph.cxx | 5 ++ vcl/source/gdi/impgraph.cxx | 67 ++++++++++++++++++++--------- vcl/source/gdi/vectorgraphicdata.cxx | 10 ++-- vcl/source/graphic/Manager.cxx | 8 +++ vcl/source/graphic/VectorGraphicLoader.cxx | 26 +++++++++++ 11 files changed, 123 insertions(+), 29 deletions(-)
New commits: commit 356bfad6e271707de8166fee7d2daa50e3a20d59 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Jan 2 00:18:25 2021 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Jan 2 00:18:25 2021 +0900 vcl: rename ambiguious aSequence variable to aPropertySequence There is maSequence already, which is totally different to this variable, so rename it to aPropertySequence, which should hint at what it is actually used for. Change-Id: Ia202c5bd69ed17ebe80ffb522538e03de2a83f3c diff --git a/vcl/source/gdi/vectorgraphicdata.cxx b/vcl/source/gdi/vectorgraphicdata.cxx index 193fa5c7022a..8c6ac4a5074e 100644 --- a/vcl/source/gdi/vectorgraphicdata.cxx +++ b/vcl/source/gdi/vectorgraphicdata.cxx @@ -219,11 +219,11 @@ void VectorGraphicData::ensureSequenceAndRange() std::copy(maDataContainer.cbegin(), maDataContainer.cend(), aDataSequence.begin()); const uno::Reference<io::XInputStream> xInputStream(new comphelper::SequenceInputStream(aDataSequence)); - uno::Sequence< ::beans::PropertyValue > aSequence; + uno::Sequence< ::beans::PropertyValue > aPropertySequence; if (mpExternalHeader) { - aSequence = mpExternalHeader->getSequence(); + aPropertySequence = mpExternalHeader->getSequence(); } if (xInputStream.is()) @@ -236,12 +236,12 @@ void VectorGraphicData::ensureSequenceAndRange() if (!mbEnableEMFPlus) { - auto aVector = comphelper::sequenceToContainer<std::vector<beans::PropertyValue>>(aSequence); + auto aVector = comphelper::sequenceToContainer<std::vector<beans::PropertyValue>>(aPropertySequence); aVector.push_back(comphelper::makePropertyValue("EMFPlusEnable", uno::makeAny(false))); - aSequence = comphelper::containerToSequence(aVector); + aPropertySequence = comphelper::containerToSequence(aVector); } - maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xEmfParser->getDecomposition(xInputStream, OUString(), aSequence)); + maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xEmfParser->getDecomposition(xInputStream, OUString(), aPropertySequence)); } break; commit 52aa3b79c9d51250b73db49b982e281125eee825 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Jan 2 00:12:25 2021 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Jan 2 00:12:25 2021 +0900 vcl: support creating a Graphic with only GfxLink as swapped-out This adds support to create a Graphic with only a GfxLink and the Graphic is in a swapped-out state. This is similar to the prepared state, but the prepared state is a special state of the Graphic. In the future, all loading will probably be done in this way and prepared state will go away, but for now this is only supported for PDF and is used in PDFium import only. The main reason is to avoid that a multi-page PDF is immediately swapped out after loading, which just does unneeded work and freezes the application for a while. Change-Id: I409741d27a4ad309264cdf27b2ba03f2cf37ead9 diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx index 86d885a326ac..79083bb5a224 100644 --- a/include/vcl/graph.hxx +++ b/include/vcl/graph.hxx @@ -89,6 +89,7 @@ public: SAL_DLLPRIVATE ImpGraphic* ImplGetImpGraphic() const { return mxImpGraphic.get(); } Graphic(); + Graphic(std::shared_ptr<GfxLink> const & rGfxLink, sal_Int32 nPageIndex = 0); Graphic( const GraphicExternalLink& rGraphicLink ); Graphic( const Graphic& rGraphic ); Graphic( Graphic&& rGraphic ) noexcept; diff --git a/vcl/inc/graphic/Manager.hxx b/vcl/inc/graphic/Manager.hxx index 098c8644ac61..4319620e21c4 100644 --- a/vcl/inc/graphic/Manager.hxx +++ b/vcl/inc/graphic/Manager.hxx @@ -17,6 +17,7 @@ #include <vcl/vectorgraphicdata.hxx> #include <vcl/timer.hxx> #include <vcl/GraphicExternalLink.hxx> +#include <vcl/gfxlink.hxx> #include <memory> #include <mutex> @@ -60,6 +61,8 @@ public: std::shared_ptr<ImpGraphic> copy(std::shared_ptr<ImpGraphic> const& pImpGraphic); std::shared_ptr<ImpGraphic> newInstance(); std::shared_ptr<ImpGraphic> newInstance(const BitmapEx& rBitmapEx); + std::shared_ptr<ImpGraphic> newInstance(std::shared_ptr<GfxLink> const& rLink, + sal_Int32 nPageIndex = 0); std::shared_ptr<ImpGraphic> newInstance(const std::shared_ptr<VectorGraphicData>& rVectorGraphicDataPtr); std::shared_ptr<ImpGraphic> newInstance(const Animation& rAnimation); diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx index 2ee0e9ef61ec..6287be0df1b1 100644 --- a/vcl/inc/impgraph.hxx +++ b/vcl/inc/impgraph.hxx @@ -90,6 +90,7 @@ public: ImpGraphic( const ImpGraphic& rImpGraphic ); ImpGraphic( ImpGraphic&& rImpGraphic ) noexcept; ImpGraphic( const GraphicExternalLink& rExternalLink); + ImpGraphic(std::shared_ptr<GfxLink> const& rGfxLink, sal_Int32 nPageIndex = 0); ImpGraphic( const BitmapEx& rBmpEx ); ImpGraphic(const std::shared_ptr<VectorGraphicData>& rVectorGraphicDataPtr); ImpGraphic( const Animation& rAnimation ); diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 69376a621d79..3c99937edf48 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -474,14 +474,10 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rG tools::Long nPageWidth = convertTwipToMm100(aPageSize.getX() * pointToTwipconversionRatio); tools::Long nPageHeight = convertTwipToMm100(aPageSize.getY() * pointToTwipconversionRatio); - auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>( - aDataContainer, VectorGraphicDataType::Pdf, nPageIndex); - // Create the Graphic with the VectorGraphicDataPtr and link the original PDF stream. // We swap out this Graphic as soon as possible, and a later swap in // actually renders the correct Bitmap on demand. - Graphic aGraphic(aVectorGraphicDataPtr); - aGraphic.SetGfxLink(pGfxLink); + Graphic aGraphic(pGfxLink, nPageIndex); auto pPage = pPdfDocument->openPage(nPageIndex); diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx index 033e5576ce20..74a61e871e78 100644 --- a/vcl/source/gdi/graph.cxx +++ b/vcl/source/gdi/graph.cxx @@ -177,6 +177,11 @@ Graphic::Graphic(Graphic&& rGraphic) noexcept { } +Graphic::Graphic(std::shared_ptr<GfxLink> const & rGfxLink, sal_Int32 nPageIndex) + : mxImpGraphic(vcl::graphic::Manager::get().newInstance(rGfxLink, nPageIndex)) +{ +} + Graphic::Graphic(GraphicExternalLink const & rGraphicExternalLink) : mxImpGraphic(vcl::graphic::Manager::get().newInstance(rGraphicExternalLink)) { diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index cf1aef68cd94..83dc59127876 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -131,6 +131,23 @@ ImpGraphic::ImpGraphic(ImpGraphic&& rImpGraphic) noexcept rImpGraphic.mbDummyContext = false; } +ImpGraphic::ImpGraphic(std::shared_ptr<GfxLink> const & rGfxLink, sal_Int32 nPageIndex) + : mpGfxLink(rGfxLink) + , meType(GraphicType::Bitmap) + , mnSizeBytes(0) + , mbSwapOut(true) + , mbDummyContext(false) + , maLastUsed (std::chrono::high_resolution_clock::now()) + , mbPrepared (false) +{ + maSwapInfo.mbIsTransparent = true; + maSwapInfo.mbIsAlpha = true; + maSwapInfo.mbIsEPS = false; + maSwapInfo.mbIsAnimated = false; + maSwapInfo.mnAnimationLoopCount = 0; + maSwapInfo.mnPageIndex = nPageIndex; +} + ImpGraphic::ImpGraphic(GraphicExternalLink const & rGraphicExternalLink) : meType ( GraphicType::Default ), mnSizeBytes ( 0 ), diff --git a/vcl/source/graphic/Manager.cxx b/vcl/source/graphic/Manager.cxx index b6bf8bef610b..721607c17a52 100644 --- a/vcl/source/graphic/Manager.cxx +++ b/vcl/source/graphic/Manager.cxx @@ -202,6 +202,14 @@ std::shared_ptr<ImpGraphic> Manager::newInstance() return pReturn; } +std::shared_ptr<ImpGraphic> Manager::newInstance(std::shared_ptr<GfxLink> const& rGfxLink, + sal_Int32 nPageIndex) +{ + auto pReturn = std::make_shared<ImpGraphic>(rGfxLink, nPageIndex); + registerGraphic(pReturn); + return pReturn; +} + std::shared_ptr<ImpGraphic> Manager::newInstance(const BitmapEx& rBitmapEx) { auto pReturn = std::make_shared<ImpGraphic>(rBitmapEx); commit 2baf88c15ed73bc784fb16b1a8c57c0745539c27 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Jan 2 00:03:33 2021 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Sat Jan 2 00:03:33 2021 +0900 vcl: optimize copying size in px to ImpSwapInfo when swapping out Calling getSizePixel can force to create a bitmap for vector graphic, only for the purpuse to get the size of the graphic in pixels. We use this when swapping out, which is not ideal as we would force create a replacement bitmap just before we would get rid of it. This optimization will just copy the size in pixels to the ImpSwapInfo structure if a bitmap exists and otherwise leave it empty. Change-Id: I9ccb1af4ddc63e77e2a6ca536cb4f762d0b5f182 diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 6e89d73b55c9..cf1aef68cd94 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -334,7 +334,11 @@ void ImpGraphic::createSwapInfo() if (isSwappedOut()) return; - maSwapInfo.maSizePixel = getSizePixel(); + if (!maBitmapEx.IsEmpty()) + maSwapInfo.maSizePixel = maBitmapEx.GetSizePixel(); + else + maSwapInfo.maSizePixel = Size(); + maSwapInfo.maPrefMapMode = getPrefMapMode(); maSwapInfo.maPrefSize = getPrefSize(); maSwapInfo.mbIsAnimated = isAnimated(); commit 4c605717a7c3a9134803111ff77b499b9321d2b4 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Jan 1 23:44:57 2021 +0900 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Fri Jan 1 23:44:57 2021 +0900 vcl: create PDF from DataContainer, use that when swapping in VectorGraphicLoader is a set of functions that "load" a vector graphic (starting with PDF) from a BinaryDataContainer. Usually this only needs to create VectorGraphicData and set the correct type, as loading will be done on-demand. Use the VectorGraphicLoader function when swapping-in so this is an alternative to calling LoadNative on GfxLink, which loads into a new Graphic via. GraphicFilter, which is something we really want to avoid. Change-Id: If529c8ddca2b31660da4ea28d8e75bb20bf3c778 diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 478638da2220..c9b60f254727 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -337,6 +337,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/graphic/UnoGraphicProvider \ vcl/source/graphic/UnoGraphicTransformer \ vcl/source/graphic/VectorGraphicSearch \ + vcl/source/graphic/VectorGraphicLoader \ vcl/source/bitmap/impvect \ vcl/source/bitmap/bitmap \ vcl/source/bitmap/BitmapEx \ diff --git a/vcl/inc/graphic/VectorGraphicLoader.hxx b/vcl/inc/graphic/VectorGraphicLoader.hxx new file mode 100644 index 000000000000..b6f38120885c --- /dev/null +++ b/vcl/inc/graphic/VectorGraphicLoader.hxx @@ -0,0 +1,24 @@ +/* -*- 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 <tools/stream.hxx> +#include <vcl/vectorgraphicdata.hxx> +#include <vcl/BinaryDataContainer.hxx> +#include <memory> + +namespace vcl +{ +std::shared_ptr<VectorGraphicData> +loadPdfFromDataContainer(BinaryDataContainer const& rDataContainer); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index d98875dc7c98..6e89d73b55c9 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -46,6 +46,7 @@ #include <vcl/gdimetafiletools.hxx> #include <vcl/TypeSerializer.hxx> #include <vcl/pdfread.hxx> +#include <graphic/VectorGraphicLoader.hxx> #define GRAPHIC_MTFTOBMP_MAXEXT 2048 #define GRAPHIC_STREAMBUFSIZE 8192UL @@ -1394,29 +1395,36 @@ bool ImpGraphic::swapIn() } else if (mpGfxLink && mpGfxLink->IsNative()) { - Graphic aGraphic; - if (!mpGfxLink->LoadNative(aGraphic)) - return false; - - auto & rImpGraphic = *aGraphic.ImplGetImpGraphic(); - - if (meType != rImpGraphic.meType) - return false; - - // Move over only graphic content - mpAnimation.reset(); - if (rImpGraphic.mpAnimation) + if (mpGfxLink->GetType() == GfxLinkType::NativePdf) { - mpAnimation = std::make_unique<Animation>(*rImpGraphic.mpAnimation); - maBitmapEx = mpAnimation->GetBitmapEx(); + maVectorGraphicData = vcl::loadPdfFromDataContainer(mpGfxLink->getDataContainer()); } else { - maBitmapEx = rImpGraphic.maBitmapEx; - } + Graphic aGraphic; + if (!mpGfxLink->LoadNative(aGraphic)) + return false; - maMetaFile = rImpGraphic.maMetaFile; - maVectorGraphicData = rImpGraphic.maVectorGraphicData; + auto & rImpGraphic = *aGraphic.ImplGetImpGraphic(); + + if (meType != rImpGraphic.meType) + return false; + + // Move over only graphic content + mpAnimation.reset(); + if (rImpGraphic.mpAnimation) + { + mpAnimation = std::make_unique<Animation>(*rImpGraphic.mpAnimation); + maBitmapEx = mpAnimation->GetBitmapEx(); + } + else + { + maBitmapEx = rImpGraphic.maBitmapEx; + } + + maMetaFile = rImpGraphic.maMetaFile; + maVectorGraphicData = rImpGraphic.maVectorGraphicData; + } // Set to 0, to force recalculation mnSizeBytes = 0; diff --git a/vcl/source/graphic/VectorGraphicLoader.cxx b/vcl/source/graphic/VectorGraphicLoader.cxx new file mode 100644 index 000000000000..988c3db803be --- /dev/null +++ b/vcl/source/graphic/VectorGraphicLoader.cxx @@ -0,0 +1,26 @@ +/* -*- 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 <tools/stream.hxx> +#include <graphic/VectorGraphicLoader.hxx> + +namespace vcl +{ +std::shared_ptr<VectorGraphicData> +loadPdfFromDataContainer(BinaryDataContainer const& rDataContainer) +{ + if (rDataContainer.isEmpty()) + return std::shared_ptr<VectorGraphicData>(); + + return std::make_shared<VectorGraphicData>(rDataContainer, VectorGraphicDataType::Pdf); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits