vcl/inc/image.h                 |    6 ++++--
 vcl/inc/salgdi.hxx              |    8 ++++++++
 vcl/source/gdi/salgdilayout.cxx |    7 +++++++
 vcl/source/image/Image.cxx      |    2 +-
 vcl/source/image/ImplImage.cxx  |   18 ++++++++++--------
 5 files changed, 30 insertions(+), 11 deletions(-)

New commits:
commit cc2a6787446f1ae6492a41c405f45a9cc8cc7d4e
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Wed Sep 14 16:05:38 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Wed Sep 14 20:34:23 2022 +0200

    Related: tdf#144583 move current lok hidpi icon thing into SalGraphics
    
    Change-Id: If34a2b15aebc5316783d72564ede23e02db04302
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139944
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/vcl/inc/image.h b/vcl/inc/image.h
index c049e27072e7..5d0cc9fcb671 100644
--- a/vcl/inc/image.h
+++ b/vcl/inc/image.h
@@ -22,6 +22,8 @@
 
 #include <vcl/bitmapex.hxx>
 
+class SalGraphics;
+
 class ImplImage
 {
 private:
@@ -36,7 +38,7 @@ private:
     BitmapEx maBitmapEx;
     BitmapEx maDisabledBitmapEx;
 
-    bool loadStockAtScale(double fScale, BitmapEx &rBitmapEx);
+    bool loadStockAtScale(SalGraphics* pGraphics, BitmapEx &rBitmapEx);
 
 public:
     ImplImage(const BitmapEx& rBitmapEx);
@@ -57,7 +59,7 @@ public:
     /// Legacy - the original bitmap
     BitmapEx const & getBitmapEx(bool bDisabled = false);
     /// Taking account of HiDPI scaling
-    BitmapEx const & getBitmapExForHiDPI(bool bDisabled = false);
+    BitmapEx const & getBitmapExForHiDPI(bool bDisabled, SalGraphics* 
pGraphics);
 
     bool isEqual(const ImplImage &ref) const;
     bool isSizeEmpty() const
diff --git a/vcl/inc/salgdi.hxx b/vcl/inc/salgdi.hxx
index a0f8a22df7b3..acbfd1fa73e5 100644
--- a/vcl/inc/salgdi.hxx
+++ b/vcl/inc/salgdi.hxx
@@ -409,6 +409,14 @@ public:
 
     virtual SystemGraphicsData  GetGraphicsData() const = 0;
 
+    // Backends like the svp/gtk ones use cairo and hidpi scale at the surface
+    // but bitmaps aren't hidpi, so if this returns true for the case that the
+    // surface is hidpi then pScaleOut contains the scaling factor. So we can
+    // create larger hires bitmaps which we know will be logically scaled down
+    // by this factor but physically just copied
+    virtual bool ShouldDownscaleIconsAtSurface(double* pScaleOut) const;
+
+
 #if ENABLE_CAIRO_CANVAS
 
     /// Check whether cairo will work
diff --git a/vcl/source/gdi/salgdilayout.cxx b/vcl/source/gdi/salgdilayout.cxx
index 07757614b087..91419779d871 100644
--- a/vcl/source/gdi/salgdilayout.cxx
+++ b/vcl/source/gdi/salgdilayout.cxx
@@ -926,4 +926,11 @@ OUString SalGraphics::getRenderBackendName() const
     return OUString();
 }
 
+bool SalGraphics::ShouldDownscaleIconsAtSurface(double* pScaleOut) const
+{
+    if (pScaleOut)
+        *pScaleOut = comphelper::LibreOfficeKit::getDPIScale();
+    return comphelper::LibreOfficeKit::isActive();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/image/Image.cxx b/vcl/source/image/Image.cxx
index e32f7e54df22..2b0a9521c8c1 100644
--- a/vcl/source/image/Image.cxx
+++ b/vcl/source/image/Image.cxx
@@ -120,7 +120,7 @@ void Image::Draw(OutputDevice* pOutDev, const Point& rPos, 
DrawImageFlags nStyle
 
     Size aOutSize = pSize ? *pSize : 
pOutDev->PixelToLogic(mpImplData->getSizePixel());
 
-    BitmapEx aRenderBmp = mpImplData->getBitmapExForHiDPI(bool(nStyle & 
DrawImageFlags::Disable));
+    BitmapEx aRenderBmp = mpImplData->getBitmapExForHiDPI(bool(nStyle & 
DrawImageFlags::Disable), pOutDev->GetGraphics());
 
     if (!(nStyle & DrawImageFlags::Disable) &&
         (nStyle & (DrawImageFlags::ColorTransform | DrawImageFlags::Highlight |
diff --git a/vcl/source/image/ImplImage.cxx b/vcl/source/image/ImplImage.cxx
index 65ce3ca0c441..7883c3b1e6f6 100644
--- a/vcl/source/image/ImplImage.cxx
+++ b/vcl/source/image/ImplImage.cxx
@@ -28,6 +28,7 @@
 #include <comphelper/lok.hxx>
 
 #include <image.h>
+#include <salgdi.hxx>
 
 ImplImage::ImplImage(const BitmapEx &rBitmapEx)
     : maBitmapChecksum(0)
@@ -42,14 +43,15 @@ ImplImage::ImplImage(OUString aStockName)
 {
 }
 
-bool ImplImage::loadStockAtScale(double fScale, BitmapEx &rBitmapEx)
+bool ImplImage::loadStockAtScale(SalGraphics* pGraphics, BitmapEx &rBitmapEx)
 {
     BitmapEx aBitmapEx;
 
     ImageLoadFlags eScalingFlags = ImageLoadFlags::NONE;
     sal_Int32 nScalePercentage = -1;
 
-    if (comphelper::LibreOfficeKit::isActive()) // scale at the surface
+    double fScale(1.0);
+    if (pGraphics && pGraphics->ShouldDownscaleIconsAtSurface(&fScale)) // 
scale at the surface
     {
         nScalePercentage = fScale * 100.0;
         eScalingFlags = ImageLoadFlags::IgnoreScalingFactor;
@@ -94,7 +96,7 @@ Size ImplImage::getSizePixel()
         aRet = maSizePixel;
     else if (isStock())
     {
-        if (loadStockAtScale(1.0, maBitmapEx))
+        if (loadStockAtScale(nullptr, maBitmapEx))
         {
             assert(maDisabledBitmapEx.IsEmpty());
             assert(maBitmapChecksum == 0);
@@ -138,16 +140,16 @@ bool ImplImage::isEqual(const ImplImage &ref) const
         return maBitmapEx == ref.maBitmapEx;
 }
 
-BitmapEx const & ImplImage::getBitmapExForHiDPI(bool bDisabled)
+BitmapEx const & ImplImage::getBitmapExForHiDPI(bool bDisabled, SalGraphics* 
pGraphics)
 {
-    if (isStock())
+    if (isStock() && pGraphics)
     {   // check we have the right bitmap cached.
-        // FIXME: DPI scaling should be tied to the outdev really ...
-        double fScale = comphelper::LibreOfficeKit::getDPIScale();
+        double fScale = 1.0;
+        pGraphics->ShouldDownscaleIconsAtSurface(&fScale);
         Size aTarget(maSizePixel.Width()*fScale,
                      maSizePixel.Height()*fScale);
         if (maBitmapEx.GetSizePixel() != aTarget)
-            loadStockAtScale(fScale, maBitmapEx);
+            loadStockAtScale(pGraphics, maBitmapEx);
     }
     return getBitmapEx(bDisabled);
 }

Reply via email to