From 86fdd581a832c7476d7556f3f4fb7d83f5de4d8b Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Wed, 29 Dec 2021 15:47:42 +0900 Subject: vcl: move tryToUse{Source,Mask}Buffer to BitmapHelper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I9352aec388db56596fef3f5f323244b1df26cdcb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127979 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- vcl/headless/BitmapHelper.cxx | 82 +++++++++++++++++++++++++++++++++++++++ vcl/headless/svpgdi.cxx | 78 ------------------------------------- vcl/inc/headless/BitmapHelper.hxx | 5 +++ 3 files changed, 87 insertions(+), 78 deletions(-) (limited to 'vcl') diff --git a/vcl/headless/BitmapHelper.cxx b/vcl/headless/BitmapHelper.cxx index 8d56631a4fee..2b9c670dfb3f 100644 --- a/vcl/headless/BitmapHelper.cxx +++ b/vcl/headless/BitmapHelper.cxx @@ -18,6 +18,7 @@ */ #include +#include BitmapHelper::BitmapHelper(const SalBitmap& rSourceBitmap, const bool bForceARGB32) #ifdef HAVE_CAIRO_FORMAT_RGB24_888 @@ -183,4 +184,85 @@ sal_Int64 SystemDependentData_MaskHelper::estimateUsageInBytes() const { return estimateUsageInBytesForSurfaceHelper(maMaskHelper.get()); } + +namespace +{ +// MM02 decide to use buffers or not +const char* pDisableMM02Goodies(getenv("SAL_DISABLE_MM02_GOODIES")); +bool bUseBuffer(nullptr == pDisableMM02Goodies); +const tools::Long nMinimalSquareSizeToBuffer(64 * 64); +} + +void tryToUseSourceBuffer(const SalBitmap& rSourceBitmap, std::shared_ptr& rSurface) +{ + // MM02 try to access buffered BitmapHelper + std::shared_ptr pSystemDependentData_BitmapHelper; + const bool bBufferSource(bUseBuffer + && rSourceBitmap.GetSize().Width() * rSourceBitmap.GetSize().Height() + > nMinimalSquareSizeToBuffer); + + if (bBufferSource) + { + const SvpSalBitmap& rSrcBmp(static_cast(rSourceBitmap)); + pSystemDependentData_BitmapHelper + = rSrcBmp.getSystemDependentData(); + + if (pSystemDependentData_BitmapHelper) + { + // reuse buffered data + rSurface = pSystemDependentData_BitmapHelper->getBitmapHelper(); + } + } + + if (rSurface) + return; + + // create data on-demand + rSurface = std::make_shared(rSourceBitmap); + + if (bBufferSource) + { + // add to buffering mechanism to potentially reuse next time + const SvpSalBitmap& rSrcBmp(static_cast(rSourceBitmap)); + rSrcBmp.addOrReplaceSystemDependentData( + ImplGetSystemDependentDataManager(), rSurface); + } +} + +void tryToUseMaskBuffer(const SalBitmap& rMaskBitmap, std::shared_ptr& rMask) +{ + // MM02 try to access buffered MaskHelper + std::shared_ptr pSystemDependentData_MaskHelper; + const bool bBufferMask(bUseBuffer + && rMaskBitmap.GetSize().Width() * rMaskBitmap.GetSize().Height() + > nMinimalSquareSizeToBuffer); + + if (bBufferMask) + { + const SvpSalBitmap& rSrcBmp(static_cast(rMaskBitmap)); + pSystemDependentData_MaskHelper + = rSrcBmp.getSystemDependentData(); + + if (pSystemDependentData_MaskHelper) + { + // reuse buffered data + rMask = pSystemDependentData_MaskHelper->getMaskHelper(); + } + } + + if (rMask) + return; + + // create data on-demand + rMask = std::make_shared(rMaskBitmap); + + if (bBufferMask) + { + // add to buffering mechanism to potentially reuse next time + const SvpSalBitmap& rSrcBmp(static_cast(rMaskBitmap)); + rSrcBmp.addOrReplaceSystemDependentData( + ImplGetSystemDependentDataManager(), rMask); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index 3a321af10293..04849793efd9 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -57,84 +57,6 @@ # endif #endif -namespace -{ - // MM02 decide to use buffers or not - const char* pDisableMM02Goodies(getenv("SAL_DISABLE_MM02_GOODIES")); - bool bUseBuffer(nullptr == pDisableMM02Goodies); - const tools::Long nMinimalSquareSizeToBuffer(64*64); - - void tryToUseSourceBuffer(const SalBitmap& rSourceBitmap, std::shared_ptr& rSurface) - { - // MM02 try to access buffered BitmapHelper - std::shared_ptr pSystemDependentData_BitmapHelper; - const bool bBufferSource(bUseBuffer - && rSourceBitmap.GetSize().Width() * rSourceBitmap.GetSize().Height() > nMinimalSquareSizeToBuffer); - - if(bBufferSource) - { - const SvpSalBitmap& rSrcBmp(static_cast(rSourceBitmap)); - pSystemDependentData_BitmapHelper = rSrcBmp.getSystemDependentData(); - - if(pSystemDependentData_BitmapHelper) - { - // reuse buffered data - rSurface = pSystemDependentData_BitmapHelper->getBitmapHelper(); - } - } - - if(rSurface) - return; - - // create data on-demand - rSurface = std::make_shared(rSourceBitmap); - - if(bBufferSource) - { - // add to buffering mechanism to potentially reuse next time - const SvpSalBitmap& rSrcBmp(static_cast(rSourceBitmap)); - rSrcBmp.addOrReplaceSystemDependentData( - ImplGetSystemDependentDataManager(), - rSurface); - } - } - - void tryToUseMaskBuffer(const SalBitmap& rMaskBitmap, std::shared_ptr& rMask) - { - // MM02 try to access buffered MaskHelper - std::shared_ptr pSystemDependentData_MaskHelper; - const bool bBufferMask(bUseBuffer - && rMaskBitmap.GetSize().Width() * rMaskBitmap.GetSize().Height() > nMinimalSquareSizeToBuffer); - - if(bBufferMask) - { - const SvpSalBitmap& rSrcBmp(static_cast(rMaskBitmap)); - pSystemDependentData_MaskHelper = rSrcBmp.getSystemDependentData(); - - if(pSystemDependentData_MaskHelper) - { - // reuse buffered data - rMask = pSystemDependentData_MaskHelper->getMaskHelper(); - } - } - - if(rMask) - return; - - // create data on-demand - rMask = std::make_shared(rMaskBitmap); - - if(bBufferMask) - { - // add to buffering mechanism to potentially reuse next time - const SvpSalBitmap& rSrcBmp(static_cast(rMaskBitmap)); - rSrcBmp.addOrReplaceSystemDependentData( - ImplGetSystemDependentDataManager(), - rMask); - } - } -} - bool SvpSalGraphics::drawAlphaBitmap( const SalTwoRect& rTR, const SalBitmap& rSourceBitmap, const SalBitmap& rAlphaBitmap ) { if (rAlphaBitmap.GetBitCount() != 8 && rAlphaBitmap.GetBitCount() != 1) diff --git a/vcl/inc/headless/BitmapHelper.hxx b/vcl/inc/headless/BitmapHelper.hxx index da5e417a4e9f..cffa0b21d50b 100644 --- a/vcl/inc/headless/BitmapHelper.hxx +++ b/vcl/inc/headless/BitmapHelper.hxx @@ -73,4 +73,9 @@ public: virtual sal_Int64 estimateUsageInBytes() const override; }; +VCL_DLLPUBLIC void tryToUseSourceBuffer(const SalBitmap& rSourceBitmap, + std::shared_ptr& rSurface); +VCL_DLLPUBLIC void tryToUseMaskBuffer(const SalBitmap& rMaskBitmap, + std::shared_ptr& rMask); + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit