From 1f0fd06bc0cfe5036661ce2c23911f34eccf678a Mon Sep 17 00:00:00 2001 From: Marco Cecchetti Date: Mon, 24 Jun 2024 15:26:18 +0900 Subject: sd: slideshow render interface and implementation Interface and implementation to expose the ability to render the slide's layers to a bitmap. Change-Id: I3da48585e498354592e163d84bd29659b233c255 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170214 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- sd/source/ui/inc/DrawViewShell.hxx | 7 +++++ sd/source/ui/inc/unomodel.hxx | 9 +++++- sd/source/ui/unoidl/unomodel.cxx | 60 ++++++++++++++++++++++++++++++++++++++ sd/source/ui/view/drviewsa.cxx | 2 ++ sd/source/ui/view/drviewsk.cxx | 42 ++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 1 deletion(-) (limited to 'sd/source/ui') diff --git a/sd/source/ui/inc/DrawViewShell.hxx b/sd/source/ui/inc/DrawViewShell.hxx index f6da30194224..ce1e7c74cea3 100644 --- a/sd/source/ui/inc/DrawViewShell.hxx +++ b/sd/source/ui/inc/DrawViewShell.hxx @@ -33,6 +33,7 @@ namespace svx::sidebar { class SelectionChangeHandler; } namespace com::sun::star::lang { class XEventListener; } namespace com::sun::star::scanner { class XScannerManager2; } +namespace com::sun::star::presentation { class XSlideShow; } class Outliner; class SdPage; @@ -383,6 +384,10 @@ public: const SdViewOptions& GetViewOptions() const { return maViewOptions; } //move this method to ViewShell. //void NotifyAccUpdate(); + + css::uno::Reference getXSlideShowInstance(); + void destroyXSlideShowInstance(); + protected: DECL_DLLPRIVATE_LINK( ClipboardChanged, TransferableDataHelper*, void ); DECL_DLLPRIVATE_LINK( TabSplitHdl, TabBar *, void ); @@ -502,6 +507,8 @@ private: std::unique_ptr mpViewOverlayManager; std::vector> m_ExternalEdits; SdViewOptions maViewOptions; + + css::uno::Reference mxSlideShow; }; /// Merge the background properties together and deposit the result in rMergeAttr diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx index 28bd323dd8d4..3b5532759cc4 100644 --- a/sd/source/ui/inc/unomodel.hxx +++ b/sd/source/ui/inc/unomodel.hxx @@ -283,12 +283,19 @@ public: } /// @see vcl::ITiledRenderable::setPaintTextEdit(). virtual void setPaintTextEdit(bool bPaint) override { mbPaintTextEdit = bPaint; } - /// @see vcl::ITiledRenderable::getViewRenderState(). SD_DLLPUBLIC OString getViewRenderState(SfxViewShell* pViewShell = nullptr) override; /// @see vcl::ITiledRenderable::getPresentationInfo(). OString getPresentationInfo() const override; + /// @see vcl::ITiledRenderable::createSlideRenderer(). + bool createSlideRenderer( + sal_Int32 nSlideNumber, sal_Int32& nViewWidth, sal_Int32& nViewHeight, + bool bRenderBackground, bool bRenderMasterPage) override; + /// @see vcl::ITiledRenderable::postSlideshowCleanup(). + void postSlideshowCleanup() override; + /// @see vcl::ITiledRenderable::renderNextSlideLayer(). + bool renderNextSlideLayer(unsigned char* pBuffer, bool& bIsBitmapLayer, OUString& rJsonMsg) override; // XComponent diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 4241a7537a25..e46884e1c88a 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -80,6 +80,7 @@ #include #include #include +#include #include #include @@ -3090,6 +3091,65 @@ OString SdXImpressDocument::getPresentationInfo() const return aJsonWriter.finishAndGetAsOString(); } +bool SdXImpressDocument::createSlideRenderer( + sal_Int32 nSlideNumber, sal_Int32& nViewWidth, sal_Int32& nViewHeight, + bool bRenderBackground, bool bRenderMasterPage) +{ + DrawViewShell* pViewSh = GetViewShell(); + if (!pViewSh) + return false; + + uno::Reference xSlideShow = pViewSh->getXSlideShowInstance(); + if (!xSlideShow.is()) + return false; + + bool bSuccess = false; + try + { + uno::Reference xDrawPages(mpDoc->getUnoModel(), uno::UNO_QUERY_THROW); + uno::Reference xSlides(xDrawPages->getDrawPages(), uno::UNO_QUERY_THROW); + uno::Reference xSlide(xSlides->getByIndex(nSlideNumber), uno::UNO_QUERY_THROW); + uno::Reference xAnimNodeSupplier(xSlide, uno::UNO_QUERY_THROW); + uno::Reference xAnimNode = xAnimNodeSupplier->getAnimationNode(); + + bSuccess = xSlideShow->createLOKSlideRenderer(nViewWidth, nViewHeight, + bRenderMasterPage, bRenderBackground, + xSlide, xDrawPages, xAnimNode); + } + catch (uno::Exception&) + { + TOOLS_WARN_EXCEPTION( "sd", "SdXImpressDocument::createLOKSlideRenderer: failed" ); + } + return bSuccess; +} + +void SdXImpressDocument::postSlideshowCleanup() +{ + DrawViewShell* pViewSh = GetViewShell(); + if (!pViewSh) + return; + + pViewSh->destroyXSlideShowInstance(); +} + +bool SdXImpressDocument::renderNextSlideLayer(unsigned char* pBuffer, bool& bIsBitmapLayer, OUString& rJsonMsg) +{ + DrawViewShell* pViewSh = GetViewShell(); + if (!pViewSh) + return true; + + uno::Reference xSlideShow = pViewSh->getXSlideShowInstance(); + if (!xSlideShow.is()) + return true; + + auto nBufferPointer = sal::static_int_cast(reinterpret_cast(pBuffer)); + sal_Bool bBitmapLayer = false; + bool bDone = xSlideShow->renderNextLOKSlideLayer(nBufferPointer, bBitmapLayer, rJsonMsg); + bIsBitmapLayer = bBitmapLayer; + + return bDone; +} + SdrModel& SdXImpressDocument::getSdrModelFromUnoModel() const { OSL_ENSURE(GetDoc(), "No SdrModel in draw/Impress, should not happen"); diff --git a/sd/source/ui/view/drviewsa.cxx b/sd/source/ui/view/drviewsa.cxx index a3587ab7490b..f057488e591d 100644 --- a/sd/source/ui/view/drviewsa.cxx +++ b/sd/source/ui/view/drviewsa.cxx @@ -160,6 +160,8 @@ DrawViewShell::~DrawViewShell() void DrawViewShell::ImplDestroy() { + destroyXSlideShowInstance(); + SD_MOD()->GetColorConfig().RemoveListener(this); mpSelectionChangeHandler->Disconnect(); diff --git a/sd/source/ui/view/drviewsk.cxx b/sd/source/ui/view/drviewsk.cxx index bdbb821e96b3..cb40d8398f04 100644 --- a/sd/source/ui/view/drviewsk.cxx +++ b/sd/source/ui/view/drviewsk.cxx @@ -11,12 +11,18 @@ #include #include +#include + #include +#include +#include #include #include #include #include +using namespace css; + namespace sd { void DrawViewShell::ConfigurationChanged( utl::ConfigurationBroadcaster* pCb, ConfigurationHints ) @@ -57,6 +63,42 @@ void DrawViewShell::ConfigureAppBackgroundColor( svtools::ColorConfig *pColorCon maViewOptions.mnAppBackgroundColor = aFillColor; } +void DrawViewShell::destroyXSlideShowInstance() +{ + if (!mxSlideShow.is()) + return; + + try + { + uno::Reference xComponent(mxSlideShow, uno::UNO_QUERY); + if (xComponent.is()) + xComponent->dispose(); + } + catch (uno::Exception&) + { + TOOLS_WARN_EXCEPTION( "sd", "DrawViewShell::destroyXSlideShowInstance dispose"); + } + + mxSlideShow.clear(); +} + +uno::Reference DrawViewShell::getXSlideShowInstance() +{ + if (!mxSlideShow.is()) + { + try + { + auto xContext = ::comphelper::getProcessComponentContext(); + mxSlideShow.set(presentation::SlideShow::create(xContext), uno::UNO_SET_THROW); + } + catch (uno::Exception&) + { + TOOLS_WARN_EXCEPTION("sd", "DrawViewShell::createXSlideShowInstance()"); + } + } + return mxSlideShow; +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit