This is an automated email from the ASF dual-hosted git repository.

jimjag pushed a commit to branch AOO50X
in repository https://gitbox.apache.org/repos/asf/openoffice.git


The following commit(s) were added to refs/heads/AOO50X by this push:
     new 5da5b66131 vcl: back macOS windows and virtual devices with pixel 
layers at the screen's scale
5da5b66131 is described below

commit 5da5b6613156a8985ee55c8b2dfa172a7e9b566c
Author: Jim Jagielski <[email protected]>
AuthorDate: Mon Nov 16 08:53:41 2026 -0500

    vcl: back macOS windows and virtual devices with pixel layers at the 
screen's scale
    
    A CGLayer made from the window's graphics context is a display list on
    current macOS, so drawing and scroll copies piled up until Calc stalled.
    
    (cherry picked from commit a0fb2c02612e0d9f32fadf3ba13d43762dbddae3)
---
 main/vcl/aqua/source/gdi/salbmp.cxx      |  7 ++++---
 main/vcl/aqua/source/gdi/salgdi.cxx      | 24 ++++++++++++++----------
 main/vcl/aqua/source/gdi/salgdiutils.cxx | 29 ++++++++++++++++++-----------
 main/vcl/aqua/source/gdi/salvd.cxx       | 22 ++++++++++++++--------
 main/vcl/inc/aqua/salbmp.h               |  2 +-
 main/vcl/inc/aqua/salgdi.h               |  5 +++--
 main/vcl/inc/aqua/salvd.h                |  1 +
 7 files changed, 55 insertions(+), 35 deletions(-)

diff --git a/main/vcl/aqua/source/gdi/salbmp.cxx 
b/main/vcl/aqua/source/gdi/salbmp.cxx
index 3f52c4355d..647095c3e3 100644
--- a/main/vcl/aqua/source/gdi/salbmp.cxx
+++ b/main/vcl/aqua/source/gdi/salbmp.cxx
@@ -70,7 +70,7 @@ AquaSalBitmap::~AquaSalBitmap()
 // ------------------------------------------------------------------
 
 bool AquaSalBitmap::Create( CGLayerRef xLayer, int nBitmapBits,
-       int nX, int nY, int nWidth, int nHeight, bool /*bMirrorVert*/ )
+       int nX, int nY, int nWidth, int nHeight, bool /*bMirrorVert*/, float 
fScale )
 {
        DBG_ASSERT( xLayer, "AquaSalBitmap::Create() from non-layered context" 
);
 
@@ -79,7 +79,8 @@ bool AquaSalBitmap::Create( CGLayerRef xLayer, int 
nBitmapBits,
                nWidth += nX, nX = 0;
        if( nY < 0 )
                nHeight += nY, nY = 0;
-       const CGSize aLayerSize = CGLayerGetSize( xLayer );
+       const CGSize aLayerPixels = CGLayerGetSize( xLayer );
+       const CGSize aLayerSize = CGSizeMake( aLayerPixels.width / fScale, 
aLayerPixels.height / fScale );
        if( nWidth >= (int)aLayerSize.width - nX )
                nWidth = (int)aLayerSize.width - nX;
        if( nHeight >= (int)aLayerSize.height - nY )
@@ -97,7 +98,7 @@ bool AquaSalBitmap::Create( CGLayerRef xLayer, int 
nBitmapBits,
 
        // copy layer content into the bitmap buffer
        const CGPoint aSrcPoint = CGPointMake( -nX, -nY);
-       ::CGContextDrawLayerAtPoint( mxGraphicContext, aSrcPoint, xLayer );
+       ::CGContextDrawLayerInRect( mxGraphicContext, CGRectMake( aSrcPoint.x, 
aSrcPoint.y, aLayerSize.width, aLayerSize.height ), xLayer );
        return true;
 }
 
diff --git a/main/vcl/aqua/source/gdi/salgdi.cxx 
b/main/vcl/aqua/source/gdi/salgdi.cxx
index 56893c2c20..3a807fe765 100644
--- a/main/vcl/aqua/source/gdi/salgdi.cxx
+++ b/main/vcl/aqua/source/gdi/salgdi.cxx
@@ -269,6 +269,7 @@ AquaSalGraphics::AquaSalGraphics()
     , mnWidth( 0 )
     , mnHeight( 0 )
     , mnBitmapDepth( 0 )
+    , mfScale( 1.0f )
     , mnRealDPIX( 0 )
     , mnRealDPIY( 0 )
     , mfFakeDPIScale( 1.0 )
@@ -1143,7 +1144,7 @@ void AquaSalGraphics::copyBits( const SalTwoRect& 
rPosAry, SalGraphics *pSrcGrap
            if( pSrc->IsFlipped() )
                    { CGContextTranslateCTM( xCopyContext, 0, +mnHeight ); 
CGContextScaleCTM( xCopyContext, +1, -1 ); }
            // TODO: pSrc->size() != this->size()
-                   ::CGContextDrawLayerAtPoint( xCopyContext, aDstPoint, 
pSrc->mxLayer );
+                   ::CGContextDrawLayerInRect( xCopyContext, CGRectMake( 
aDstPoint.x, aDstPoint.y, pSrc->mnWidth, pSrc->mnHeight ), pSrc->mxLayer );
            CGContextRestoreGState( xCopyContext );
            // mark the destination rectangle as updated
            RefreshRect( aDstRect );
@@ -1201,9 +1202,10 @@ void AquaSalGraphics::copyArea( long nDstX, long 
nDstY,long nSrcX, long nSrcY, l
        CGLayerRef xSrcLayer = mxLayer;
        // TODO: if( mnBitmapDepth > 0 )
        {
-               const CGSize aSrcSize = CGSizeMake( nSrcWidth, nSrcHeight);
+               const CGSize aSrcSize = CGSizeMake( nSrcWidth * mfScale, 
nSrcHeight * mfScale);
                xSrcLayer = ::CGLayerCreateWithContext( xCopyContext, aSrcSize, 
NULL );
                const CGContextRef xSrcContext = CGLayerGetContext( xSrcLayer );
+               ::CGContextScaleCTM( xSrcContext, mfScale, mfScale );
                CGPoint aSrcPoint = CGPointMake( -nSrcX, -nSrcY);
                if( IsFlipped() )
                {
@@ -1211,12 +1213,12 @@ void AquaSalGraphics::copyArea( long nDstX, long 
nDstY,long nSrcX, long nSrcY, l
                        ::CGContextScaleCTM( xSrcContext, +1, -1 );
                        aSrcPoint.y = (nSrcY + nSrcHeight) - mnHeight;
                }
-               ::CGContextDrawLayerAtPoint( xSrcContext, aSrcPoint, mxLayer );
+               ::CGContextDrawLayerInRect( xSrcContext, CGRectMake( 
aSrcPoint.x, aSrcPoint.y, mnWidth, mnHeight ), mxLayer );
        }
 
        // draw at new destination
        const CGPoint aDstPoint = CGPointMake( +nDstX, +nDstY);
-       ::CGContextDrawLayerAtPoint( xCopyContext, aDstPoint, xSrcLayer );
+       ::CGContextDrawLayerInRect( xCopyContext, CGRectMake( aDstPoint.x, 
aDstPoint.y, nSrcWidth, nSrcHeight ), xSrcLayer );
 
        // cleanup
        if( xSrcLayer != mxLayer )
@@ -1299,7 +1301,7 @@ SalBitmap* AquaSalGraphics::getBitmap( long  nX, long  
nY, long  nDX, long  nDY
        ApplyXorContext();
 
        AquaSalBitmap* pBitmap = new AquaSalBitmap;
-       if( !pBitmap->Create( mxLayer, mnBitmapDepth, nX, nY, nDX, nDY, 
!mbWindow ) )
+       if( !pBitmap->Create( mxLayer, mnBitmapDepth, nX, nY, nDX, nDY, 
!mbWindow, mfScale ) )
        {
                delete pBitmap;
                pBitmap = NULL;
@@ -1339,7 +1341,7 @@ SalColor AquaSalGraphics::getPixel( long nX, long nY )
        if( IsFlipped() )
                nY = mnHeight - nY;
        const CGPoint aCGPoint = CGPointMake( -nX, -nY);
-       CGContextDrawLayerAtPoint( xOnePixelContext, aCGPoint, mxLayer );
+       CGContextDrawLayerInRect( xOnePixelContext, CGRectMake( aCGPoint.x, 
aCGPoint.y, mnWidth, mnHeight ), mxLayer );
        CGContextRelease( xOnePixelContext );
 
        SalColor nSalColor = MAKE_SALCOLOR( aPixel.r, aPixel.g, aPixel.b );
@@ -2368,7 +2370,7 @@ void AquaSalGraphics::SetXORMode( bool bSet, bool 
bInvertOnly )
        if( !mpXorEmulation )
        {
                mpXorEmulation = new XorEmulation();
-               mpXorEmulation->SetTarget( mnWidth, mnHeight, mnBitmapDepth, 
mrContext, mxLayer );
+               mpXorEmulation->SetTarget( mnWidth, mnHeight, mnBitmapDepth, 
mrContext, mxLayer, mfScale );
        }
 
        // change the XOR mode
@@ -2422,7 +2424,7 @@ XorEmulation::~XorEmulation()
 // -----------------------------------------------------------------------
 
 void XorEmulation::SetTarget( int nWidth, int nHeight, int nTargetDepth,
-       CGContextRef xTargetContext, CGLayerRef xTargetLayer )
+       CGContextRef xTargetContext, CGLayerRef xTargetLayer, float fScale )
 {
        // prepare to replace old mask+temp context
        if( mxMaskContext )
@@ -2500,7 +2502,8 @@ void XorEmulation::SetTarget( int nWidth, int nHeight, 
int nTargetDepth,
                CGContextSetBlendMode( mxMaskContext, kCGBlendModeDifference );
 
        // initialize the transformation matrix to the drawing target
-       const CGAffineTransform aCTM = CGContextGetCTM( xTargetContext );
+       const CGAffineTransform aCTM = CGAffineTransformConcat( 
CGContextGetCTM( xTargetContext ),
+               CGAffineTransformMakeScale( 1.0 / fScale, 1.0 / fScale ) );
        CGContextConcatCTM( mxMaskContext, aCTM );
        if( mxTempContext )
                CGContextConcatCTM( mxTempContext, aCTM );
@@ -2518,7 +2521,8 @@ bool XorEmulation::UpdateTarget()
 
        // update the temp bitmap buffer if needed
        if( mxTempContext )
-               CGContextDrawLayerAtPoint( mxTempContext, CGPointZero, 
mxTargetLayer );
+               CGContextDrawLayerInRect( mxTempContext, CGRectMake( 0, 0, 
CGBitmapContextGetWidth( mxTempContext ),
+                       CGBitmapContextGetHeight( mxTempContext ) ), 
mxTargetLayer );
 
        // do a manual XOR with the XorMask
        // this approach suffices for simple color manipulations
diff --git a/main/vcl/aqua/source/gdi/salgdiutils.cxx 
b/main/vcl/aqua/source/gdi/salgdiutils.cxx
index b44a09af5a..f1f83e7cf3 100644
--- a/main/vcl/aqua/source/gdi/salgdiutils.cxx
+++ b/main/vcl/aqua/source/gdi/salgdiutils.cxx
@@ -80,7 +80,7 @@ void AquaSalGraphics::SetPrinterGraphics( CGContextRef 
xContext, long nDPIX, lon
 }
 
 void AquaSalGraphics::SetVirDevGraphics( CGLayerRef xLayer, CGContextRef 
xContext,
-       int nBitmapDepth )
+       int nBitmapDepth, float fScale )
 {
     mbWindow    = false;
     mbPrinter   = false;
@@ -90,6 +90,7 @@ void AquaSalGraphics::SetVirDevGraphics( CGLayerRef xLayer, 
CGContextRef xContex
        mxLayer = xLayer;
        mrContext = xContext;
        mnBitmapDepth = nBitmapDepth;
+       mfScale = xLayer ? fScale : 1.0f;
 
        // return early if the virdev is being destroyed
     if( !xContext )
@@ -104,8 +105,9 @@ void AquaSalGraphics::SetVirDevGraphics( CGLayerRef xLayer, 
CGContextRef xContex
     else
     {
                const CGSize aSize = CGLayerGetSize( mxLayer );
-               mnWidth = static_cast<int>(aSize.width);
-               mnHeight = static_cast<int>(aSize.height);
+               mnWidth = static_cast<int>(aSize.width / mfScale);
+               mnHeight = static_cast<int>(aSize.height / mfScale);
+               CGContextScaleCTM( mrContext, mfScale, mfScale );
     }
 
        // prepare graphics for drawing
@@ -116,7 +118,7 @@ void AquaSalGraphics::SetVirDevGraphics( CGLayerRef xLayer, 
CGContextRef xContex
        // re-enable XorEmulation for the new context
        if( mpXorEmulation )
        {
-               mpXorEmulation->SetTarget( mnWidth, mnHeight, mnBitmapDepth, 
mrContext, mxLayer );
+               mpXorEmulation->SetTarget( mnWidth, mnHeight, mnBitmapDepth, 
mrContext, mxLayer, mfScale );
                if( mpXorEmulation->IsEnabled() )
                        mrContext = mpXorEmulation->GetMaskContext();
        }
@@ -179,15 +181,18 @@ bool AquaSalGraphics::CheckContext()
     {
         const unsigned int nWidth = mpFrame->maGeometry.nWidth;
         const unsigned int nHeight = mpFrame->maGeometry.nHeight;
+        const float fScale = [mpFrame->getNSWindow() backingScaleFactor];
+        const int nOldWidth = mnWidth, nOldHeight = mnHeight;
 
         CGContextRef rReleaseContext = 0;
         CGLayerRef   rReleaseLayer = NULL;
 
                // check if a new drawing context is needed (e.g. after a 
resize)
-               if( (unsigned(mnWidth) != nWidth) || (unsigned(mnHeight) != 
nHeight) )
+               if( (unsigned(mnWidth) != nWidth) || (unsigned(mnHeight) != 
nHeight) || (mfScale != fScale) )
                {
                        mnWidth = nWidth;
                        mnHeight = nHeight;
+                       mfScale = fScale;
                        // prepare to release the corresponding resources
                        rReleaseContext = mrContext;
                        rReleaseLayer   = mxLayer;
@@ -197,18 +202,20 @@ bool AquaSalGraphics::CheckContext()
 
         if( !mrContext )
         {
-               const CGSize aLayerSize = CGSizeMake( nWidth, nHeight);
-               NSGraphicsContext* pNSGContext = [NSGraphicsContext 
graphicsContextWithWindow: mpFrame->getNSWindow()];
-               CGContextRef xCGContext = 
reinterpret_cast<CGContextRef>([pNSGContext graphicsPort]);
+               const CGSize aLayerSize = CGSizeMake( nWidth * mfScale, nHeight 
* mfScale);
+               // a layer made from the window's context records a display 
list instead of pixels
+               CGContextRef xCGContext = CGBitmapContextCreate( NULL, 1, 1, 8, 
4, GetSalData()->mxRGBSpace, kCGImageAlphaNoneSkipFirst );
            mxLayer = CGLayerCreateWithContext( xCGContext, aLayerSize, NULL );
+               CGContextRelease( xCGContext );
                        if( mxLayer )
                                mrContext = CGLayerGetContext( mxLayer );
 
             if( mrContext )
             {
+                CGContextScaleCTM( mrContext, mfScale, mfScale );
                 // copy original layer to resized layer
                 if( rReleaseLayer )
-                       CGContextDrawLayerAtPoint( mrContext, CGPointZero, 
rReleaseLayer );
+                       CGContextDrawLayerInRect( mrContext, CGRectMake( 0, 0, 
nOldWidth, nOldHeight ), rReleaseLayer );
 
                 CGContextTranslateCTM( mrContext, 0, nHeight );
                 CGContextScaleCTM( mrContext, 1.0, -1.0 );
@@ -219,7 +226,7 @@ bool AquaSalGraphics::CheckContext()
 
                                // re-enable XOR emulation for the new context
                                if( mpXorEmulation )
-                                       mpXorEmulation->SetTarget( mnWidth, 
mnHeight, mnBitmapDepth, mrContext, mxLayer );
+                                       mpXorEmulation->SetTarget( mnWidth, 
mnHeight, mnBitmapDepth, mrContext, mxLayer, mfScale );
             }
         }
 
@@ -289,7 +296,7 @@ void AquaSalGraphics::UpdateWindow( NSRect& )
         }
 
                ApplyXorContext();
-               CGContextDrawLayerAtPoint( rCGContext, CGPointZero, mxLayer );
+               CGContextDrawLayerInRect( rCGContext, CGRectMake( 0, 0, 
mnWidth, mnHeight ), mxLayer );
         if( rClip ) // cleanup clipping
             CGContextRestoreGState( rCGContext );
        }
diff --git a/main/vcl/aqua/source/gdi/salvd.cxx 
b/main/vcl/aqua/source/gdi/salvd.cxx
index 8f1d3566cd..c06427ebf2 100644
--- a/main/vcl/aqua/source/gdi/salvd.cxx
+++ b/main/vcl/aqua/source/gdi/salvd.cxx
@@ -58,6 +58,7 @@ AquaSalVirtualDevice::AquaSalVirtualDevice( AquaSalGraphics* 
pGraphic, long nDX,
 ,      mxBitmapContext( NULL )
 ,      mnBitmapDepth( 0 )
 ,      mxLayer( NULL )
+,      mfScale( 1.0f )
 {
     if( pGraphic && pData && pData->rCGContext )
        {
@@ -163,7 +164,7 @@ sal_Bool AquaSalVirtualDevice::SetSize( long nDX, long nDY )
     if( mxLayer )
     {
        const CGSize aSize = CGLayerGetSize( mxLayer );
-        if( (nDX == aSize.width) && (nDY == aSize.height) )
+        if( (nDX * mfScale == aSize.width) && (nDY * mfScale == aSize.height) )
            {
                // Yay, we do not have to do anything :)
                        return true;
@@ -171,9 +172,11 @@ sal_Bool AquaSalVirtualDevice::SetSize( long nDX, long nDY 
)
     }
 
     Destroy();
+    mfScale = 1.0f;
 
        // create a Quartz layer matching to the intended virdev usage
        CGContextRef xCGContext = NULL;
+       CGContextRef xRefContext = NULL;
        if( mnBitmapDepth && (mnBitmapDepth < 16) )
        {
                mnBitmapDepth = 8;  // TODO: are 1bit vdevs worth it?
@@ -206,9 +209,10 @@ sal_Bool AquaSalVirtualDevice::SetSize( long nDX, long nDY 
)
             NSWindow* pNSWindow = pSalFrame->getNSWindow();
             if ( pNSWindow )
             {
-                NSGraphicsContext* pNSContext = [NSGraphicsContext 
graphicsContextWithWindow: pNSWindow];
-                if( pNSContext )
-                    xCGContext = reinterpret_cast<CGContextRef>([pNSContext 
graphicsPort]);
+                // a layer made from the window's context records a display 
list instead of pixels
+                xRefContext = CGBitmapContextCreate( NULL, 1, 1, 8, 4, 
GetSalData()->mxRGBSpace, kCGImageAlphaNoneSkipFirst );
+                xCGContext = xRefContext;
+                mfScale = [pNSWindow backingScaleFactor];
             }
             else
             {
@@ -228,14 +232,16 @@ sal_Bool AquaSalVirtualDevice::SetSize( long nDX, long 
nDY )
 
        DBG_ASSERT( xCGContext, "no context" );
 
-       const CGSize aNewSize = CGSizeMake( nDX, nDY);
+       const CGSize aNewSize = CGSizeMake( nDX * mfScale, nDY * mfScale);
        mxLayer = CGLayerCreateWithContext( xCGContext, aNewSize, NULL );
+       if( xRefContext )
+               CGContextRelease( xRefContext );
 
        if( mxLayer && mpGraphics )
        {
                // get the matching Quartz context
                CGContextRef xDrawContext = CGLayerGetContext( mxLayer );
-               mpGraphics->SetVirDevGraphics( mxLayer, xDrawContext, 
mnBitmapDepth );
+               mpGraphics->SetVirDevGraphics( mxLayer, xDrawContext, 
mnBitmapDepth, mfScale );
        }
 
        return (mxLayer != NULL);
@@ -248,8 +254,8 @@ void AquaSalVirtualDevice::GetSize( long& rWidth, long& 
rHeight )
        if( mxLayer )
        {
        const CGSize aSize = CGLayerGetSize( mxLayer );
-               rWidth = static_cast<long>(aSize.width);
-               rHeight = static_cast<long>(aSize.height);
+               rWidth = static_cast<long>(aSize.width / mfScale);
+               rHeight = static_cast<long>(aSize.height / mfScale);
        }
        else
        {
diff --git a/main/vcl/inc/aqua/salbmp.h b/main/vcl/inc/aqua/salbmp.h
index f757aef131..7b6b8c80ec 100644
--- a/main/vcl/inc/aqua/salbmp.h
+++ b/main/vcl/inc/aqua/salbmp.h
@@ -97,7 +97,7 @@ private:
                                                                           
sal_uInt16 nSrcBits, sal_uInt32 nSrcBytesPerRow, const BitmapPalette& 
rSrcPalette, sal_uInt8* pSrcData );
 
 public:
-       bool                    Create( CGLayerRef xLayer, int nBitCount, int 
nX, int nY, int nWidth, int nHeight, bool bMirrorVert = true );
+       bool                    Create( CGLayerRef xLayer, int nBitCount, int 
nX, int nY, int nWidth, int nHeight, bool bMirrorVert = true, float fScale = 
1.0f );
 
 public:
        CGImageRef              CreateWithMask( const AquaSalBitmap& rMask, int 
nX, int nY, int nWidth, int nHeight ) const;
diff --git a/main/vcl/inc/aqua/salgdi.h b/main/vcl/inc/aqua/salgdi.h
index 42b62c0cd3..cb45c43da5 100644
--- a/main/vcl/inc/aqua/salgdi.h
+++ b/main/vcl/inc/aqua/salgdi.h
@@ -156,6 +156,7 @@ protected:
        int                                                                     
        mnWidth;
        int                                                                     
        mnHeight;
        int                                                                     
        mnBitmapDepth;  // zero unless bitmap
+       float                                                                   
        mfScale;                // layer pixels per point
     /// device resolution of this graphics
     long                                    mnRealDPIX;
        long                                    mnRealDPIY;
@@ -198,7 +199,7 @@ public:
 
     void                SetWindowGraphics( AquaSalFrame* pFrame );
     void                SetPrinterGraphics( CGContextRef, long nRealDPIX, long 
nRealDPIY, double fFakeScale );
-    void                SetVirDevGraphics( CGLayerRef, CGContextRef, int 
nBitDepth = 0 );
+    void                SetVirDevGraphics( CGLayerRef, CGContextRef, int 
nBitDepth = 0, float fScale = 1.0f );
 
     void                initResolution( NSWindow* );
     void                copyResolution( AquaSalGraphics& );
@@ -422,7 +423,7 @@ public:
                                        XorEmulation();
        /*final*/               ~XorEmulation();
 
-       void                    SetTarget( int nWidth, int nHeight, int 
nBitmapDepth, CGContextRef, CGLayerRef );
+       void                    SetTarget( int nWidth, int nHeight, int 
nBitmapDepth, CGContextRef, CGLayerRef, float fScale = 1.0f );
        bool                    UpdateTarget();
        void                    Enable()                        { mbIsEnabled = 
true; }
        void                    Disable()                       { mbIsEnabled = 
false; }
diff --git a/main/vcl/inc/aqua/salvd.h b/main/vcl/inc/aqua/salvd.h
index 883dbd1532..d76c8779cd 100644
--- a/main/vcl/inc/aqua/salvd.h
+++ b/main/vcl/inc/aqua/salvd.h
@@ -70,6 +70,7 @@ private:
     CGContextRef mxBitmapContext;
     int mnBitmapDepth;
        CGLayerRef mxLayer;              // Quartz layer
+       float mfScale;                   // layer pixels per point
        AquaSalGraphics* mpGraphics;     // current VirDev graphics
 
        void Destroy();

Reply via email to