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

commit d73478a9fa783b9d6f242a44d4a5f9422f5f387f
Author: Jim Jagielski <[email protected]>
AuthorDate: Mon Nov 16 12:52:51 2026 -0500

    vcl: keep a macOS layer and its scale in one value
---
 main/vcl/aqua/source/gdi/salbmp.cxx      |  8 ++--
 main/vcl/aqua/source/gdi/salgdi.cxx      | 32 ++++++++--------
 main/vcl/aqua/source/gdi/salgdiutils.cxx | 42 ++++++++++-----------
 main/vcl/aqua/source/gdi/salvd.cxx       | 46 +++++++++++------------
 main/vcl/inc/aqua/salbmp.h               |  2 +-
 main/vcl/inc/aqua/salgdi.h               |  6 +--
 main/vcl/inc/aqua/salvd.h                |  3 +-
 main/vcl/inc/aqua/scaledlayer.h          | 63 ++++++++++++++++++++++++++++++++
 8 files changed, 129 insertions(+), 73 deletions(-)

diff --git a/main/vcl/aqua/source/gdi/salbmp.cxx 
b/main/vcl/aqua/source/gdi/salbmp.cxx
index 647095c3e3..e04463d235 100644
--- a/main/vcl/aqua/source/gdi/salbmp.cxx
+++ b/main/vcl/aqua/source/gdi/salbmp.cxx
@@ -69,9 +69,10 @@ AquaSalBitmap::~AquaSalBitmap()
 
 // ------------------------------------------------------------------
 
-bool AquaSalBitmap::Create( CGLayerRef xLayer, int nBitmapBits,
-       int nX, int nY, int nWidth, int nHeight, bool /*bMirrorVert*/, float 
fScale )
+bool AquaSalBitmap::Create( const ScaledLayer& rLayer, int nBitmapBits,
+       int nX, int nY, int nWidth, int nHeight, bool /*bMirrorVert*/ )
 {
+       CGLayerRef xLayer = rLayer.get();
        DBG_ASSERT( xLayer, "AquaSalBitmap::Create() from non-layered context" 
);
 
        // sanitize input parameters
@@ -79,8 +80,7 @@ bool AquaSalBitmap::Create( CGLayerRef xLayer, int 
nBitmapBits,
                nWidth += nX, nX = 0;
        if( nY < 0 )
                nHeight += nY, nY = 0;
-       const CGSize aLayerPixels = CGLayerGetSize( xLayer );
-       const CGSize aLayerSize = CGSizeMake( aLayerPixels.width / fScale, 
aLayerPixels.height / fScale );
+       const CGSize aLayerSize = rLayer.getPointSize();
        if( nWidth >= (int)aLayerSize.width - nX )
                nWidth = (int)aLayerSize.width - nX;
        if( nHeight >= (int)aLayerSize.height - nY )
diff --git a/main/vcl/aqua/source/gdi/salgdi.cxx 
b/main/vcl/aqua/source/gdi/salgdi.cxx
index 68ea3900cf..738f1ded02 100644
--- a/main/vcl/aqua/source/gdi/salgdi.cxx
+++ b/main/vcl/aqua/source/gdi/salgdi.cxx
@@ -262,14 +262,12 @@ bool ImplMacFontData::HasCJKSupport( void ) const
 
 AquaSalGraphics::AquaSalGraphics()
     : mpFrame( NULL )
-    , mxLayer( NULL )
     , mrContext( NULL )
     , mpXorEmulation( NULL )
     , mnXorMode( 0 )
     , mnWidth( 0 )
     , mnHeight( 0 )
     , mnBitmapDepth( 0 )
-    , mfScale( 1.0f )
     , mnRealDPIX( 0 )
     , mnRealDPIY( 0 )
     , mfFakeDPIScale( 1.0 )
@@ -296,8 +294,8 @@ AquaSalGraphics::~AquaSalGraphics()
        if( mpXorEmulation )
                delete mpXorEmulation;
 
-       if( mxLayer )
-               CGLayerRelease( mxLayer );
+       if( maLayer.get() )
+               CGLayerRelease( maLayer.get() );
        else if( mrContext && mbWindow )
        {
                // destroy backbuffer bitmap context that we created ourself
@@ -1122,7 +1120,7 @@ void AquaSalGraphics::copyBits( const SalTwoRect& 
rPosAry, SalGraphics *pSrcGrap
        ApplyXorContext();
        pSrc->ApplyXorContext();
 
-       DBG_ASSERT( pSrc->mxLayer!=NULL, "AquaSalGraphics::copyBits() from 
non-layered graphics" );
+       DBG_ASSERT( pSrc->maLayer.get()!=NULL, "AquaSalGraphics::copyBits() 
from non-layered graphics" );
 
        const CGPoint aDstPoint = CGPointMake( +rPosAry.mnDestX - 
rPosAry.mnSrcX, rPosAry.mnDestY - rPosAry.mnSrcY);
        if( (rPosAry.mnSrcWidth == rPosAry.mnDestWidth && rPosAry.mnSrcHeight 
== rPosAry.mnDestHeight) &&
@@ -1144,7 +1142,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()
-                   ::CGContextDrawLayerInRect( xCopyContext, CGRectMake( 
aDstPoint.x, aDstPoint.y, pSrc->mnWidth, pSrc->mnHeight ), pSrc->mxLayer );
+                   ::CGContextDrawLayerInRect( xCopyContext, CGRectMake( 
aDstPoint.x, aDstPoint.y, pSrc->mnWidth, pSrc->mnHeight ), pSrc->maLayer.get() 
);
            CGContextRestoreGState( xCopyContext );
            // mark the destination rectangle as updated
            RefreshRect( aDstRect );
@@ -1187,7 +1185,7 @@ void AquaSalGraphics::copyArea( long nDstX, long 
nDstY,long nSrcX, long nSrcY, l
                delete pBitmap;
        }
 #else
-       DBG_ASSERT( mxLayer!=NULL, "AquaSalGraphics::copyArea() for non-layered 
graphics" );
+       DBG_ASSERT( maLayer.get()!=NULL, "AquaSalGraphics::copyArea() for 
non-layered graphics" );
 
        // in XOR mode the drawing context is redirected to the XOR mask
        // copyArea() always works on the target context though
@@ -1199,13 +1197,13 @@ void AquaSalGraphics::copyArea( long nDstX, long 
nDstY,long nSrcX, long nSrcY, l
        // TODO: is it possible to get rid of this unneeded copy more often?
        //       e.g. on OSX>=10.5 only this situation causes problems:
        //                      mnBitmapDepth && (aDstPoint.x + pSrc->mnWidth) 
> mnWidth
-       CGLayerRef xSrcLayer = mxLayer;
+       CGLayerRef xSrcLayer = maLayer.get();
        // TODO: if( mnBitmapDepth > 0 )
        {
-               const CGSize aSrcSize = CGSizeMake( nSrcWidth * mfScale, 
nSrcHeight * mfScale);
+               const CGSize aSrcSize = maLayer.toPixels( nSrcWidth, nSrcHeight 
);
                xSrcLayer = ::CGLayerCreateWithContext( xCopyContext, aSrcSize, 
NULL );
                const CGContextRef xSrcContext = CGLayerGetContext( xSrcLayer );
-               ::CGContextScaleCTM( xSrcContext, mfScale, mfScale );
+               maLayer.scaleContext( xSrcContext );
                CGPoint aSrcPoint = CGPointMake( -nSrcX, -nSrcY);
                if( IsFlipped() )
                {
@@ -1213,7 +1211,7 @@ void AquaSalGraphics::copyArea( long nDstX, long 
nDstY,long nSrcX, long nSrcY, l
                        ::CGContextScaleCTM( xSrcContext, +1, -1 );
                        aSrcPoint.y = (nSrcY + nSrcHeight) - mnHeight;
                }
-               ::CGContextDrawLayerInRect( xSrcContext, CGRectMake( 
aSrcPoint.x, aSrcPoint.y, mnWidth, mnHeight ), mxLayer );
+               ::CGContextDrawLayerInRect( xSrcContext, CGRectMake( 
aSrcPoint.x, aSrcPoint.y, mnWidth, mnHeight ), maLayer.get() );
        }
 
        // draw at new destination
@@ -1221,7 +1219,7 @@ void AquaSalGraphics::copyArea( long nDstX, long 
nDstY,long nSrcX, long nSrcY, l
        ::CGContextDrawLayerInRect( xCopyContext, CGRectMake( aDstPoint.x, 
aDstPoint.y, nSrcWidth, nSrcHeight ), xSrcLayer );
 
        // cleanup
-       if( xSrcLayer != mxLayer )
+       if( xSrcLayer != maLayer.get() )
                CGLayerRelease( xSrcLayer );
 
        // mark the destination rectangle as updated
@@ -1296,12 +1294,12 @@ void AquaSalGraphics::drawMask( const SalTwoRect& 
rPosAry, const SalBitmap& rSal
 
 SalBitmap* AquaSalGraphics::getBitmap( long  nX, long  nY, long  nDX, long  
nDY )
 {
-       DBG_ASSERT( mxLayer, "AquaSalGraphics::getBitmap() with no layer" );
+       DBG_ASSERT( maLayer.get(), "AquaSalGraphics::getBitmap() with no layer" 
);
 
        ApplyXorContext();
 
        AquaSalBitmap* pBitmap = new AquaSalBitmap;
-       if( !pBitmap->Create( mxLayer, mnBitmapDepth, nX, nY, nDX, nDY, 
!mbWindow, mfScale ) )
+       if( !pBitmap->Create( maLayer, mnBitmapDepth, nX, nY, nDX, nDY, 
!mbWindow ) )
        {
                delete pBitmap;
                pBitmap = NULL;
@@ -1315,7 +1313,7 @@ SalBitmap* AquaSalGraphics::getBitmap( long  nX, long  
nY, long  nDX, long  nDY
 SalColor AquaSalGraphics::getPixel( long nX, long nY )
 {
        // return default value on printers or when out of bounds
-       if( !mxLayer
+       if( !maLayer.get()
        || (nX < 0) || (nX >= mnWidth)
        || (nY < 0) || (nY >= mnHeight))
                return COL_BLACK;
@@ -1341,7 +1339,7 @@ SalColor AquaSalGraphics::getPixel( long nX, long nY )
        if( IsFlipped() )
                nY = mnHeight - nY;
        const CGPoint aCGPoint = CGPointMake( -nX, -nY);
-       CGContextDrawLayerInRect( xOnePixelContext, CGRectMake( aCGPoint.x, 
aCGPoint.y, mnWidth, mnHeight ), mxLayer );
+       CGContextDrawLayerInRect( xOnePixelContext, CGRectMake( aCGPoint.x, 
aCGPoint.y, mnWidth, mnHeight ), maLayer.get() );
        CGContextRelease( xOnePixelContext );
 
        SalColor nSalColor = MAKE_SALCOLOR( aPixel.r, aPixel.g, aPixel.b );
@@ -2370,7 +2368,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, maLayer.get() );
        }
 
        // change the XOR mode
diff --git a/main/vcl/aqua/source/gdi/salgdiutils.cxx 
b/main/vcl/aqua/source/gdi/salgdiutils.cxx
index dd6952ff92..eb281d719d 100644
--- a/main/vcl/aqua/source/gdi/salgdiutils.cxx
+++ b/main/vcl/aqua/source/gdi/salgdiutils.cxx
@@ -79,35 +79,34 @@ void AquaSalGraphics::SetPrinterGraphics( CGContextRef 
xContext, long nDPIX, lon
     }
 }
 
-void AquaSalGraphics::SetVirDevGraphics( CGLayerRef xLayer, CGContextRef 
xContext,
-       int nBitmapDepth, float fScale )
+void AquaSalGraphics::SetVirDevGraphics( const ScaledLayer& rLayer, 
CGContextRef xContext,
+       int nBitmapDepth )
 {
     mbWindow    = false;
     mbPrinter   = false;
     mbVirDev    = true;
 
        // set graphics properties
-       mxLayer = xLayer;
+       maLayer = rLayer.get() ? rLayer : ScaledLayer();
        mrContext = xContext;
        mnBitmapDepth = nBitmapDepth;
-       mfScale = xLayer ? fScale : 1.0f;
 
        // return early if the virdev is being destroyed
     if( !xContext )
        return;
 
        // get new graphics properties
-    if( !mxLayer )
+    if( !maLayer.get() )
     {
                mnWidth = CGBitmapContextGetWidth( mrContext );
                mnHeight = CGBitmapContextGetHeight( mrContext );
     }
     else
     {
-               const CGSize aSize = CGLayerGetSize( mxLayer );
-               mnWidth = static_cast<int>(aSize.width / mfScale);
-               mnHeight = static_cast<int>(aSize.height / mfScale);
-               CGContextScaleCTM( mrContext, mfScale, mfScale );
+               const CGSize aSize = maLayer.getPointSize();
+               mnWidth = static_cast<int>(aSize.width);
+               mnHeight = static_cast<int>(aSize.height);
+               maLayer.scaleContext( mrContext );
     }
 
        // prepare graphics for drawing
@@ -118,7 +117,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, maLayer.get() );
                if( mpXorEmulation->IsEnabled() )
                        mrContext = mpXorEmulation->GetMaskContext();
        }
@@ -188,31 +187,30 @@ bool AquaSalGraphics::CheckContext()
         CGLayerRef   rReleaseLayer = NULL;
 
                // check if a new drawing context is needed (e.g. after a 
resize)
-               if( (unsigned(mnWidth) != nWidth) || (unsigned(mnHeight) != 
nHeight) || (mfScale != fScale) )
+               if( (unsigned(mnWidth) != nWidth) || (unsigned(mnHeight) != 
nHeight) || (maLayer.getScale() != fScale) )
                {
                        mnWidth = nWidth;
                        mnHeight = nHeight;
-                       mfScale = fScale;
                        // prepare to release the corresponding resources
                        rReleaseContext = mrContext;
-                       rReleaseLayer   = mxLayer;
+                       rReleaseLayer   = maLayer.get();
                        mrContext = NULL;
-                       mxLayer = NULL;
+                       maLayer = ScaledLayer( NULL, fScale );
                }
 
         if( !mrContext )
         {
-               const CGSize aLayerSize = CGSizeMake( nWidth * mfScale, nHeight 
* mfScale);
+               const CGSize aLayerSize = maLayer.toPixels( nWidth, nHeight );
                // 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 );
+           maLayer = ScaledLayer( CGLayerCreateWithContext( xCGContext, 
aLayerSize, NULL ), maLayer.getScale() );
                CGContextRelease( xCGContext );
-                       if( mxLayer )
-                               mrContext = CGLayerGetContext( mxLayer );
+                       if( maLayer.get() )
+                               mrContext = CGLayerGetContext( maLayer.get() );
 
             if( mrContext )
             {
-                CGContextScaleCTM( mrContext, mfScale, mfScale );
+                maLayer.scaleContext( mrContext );
                 // copy original layer to resized layer
                 if( rReleaseLayer )
                        CGContextDrawLayerInRect( mrContext, CGRectMake( 0, 0, 
nOldWidth, nOldHeight ), rReleaseLayer );
@@ -226,7 +224,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, maLayer.get() );
             }
         }
 
@@ -282,7 +280,7 @@ void AquaSalGraphics::UpdateWindow( NSRect& )
        if( !mpFrame )
                return;
     NSGraphicsContext* pContext = [NSGraphicsContext currentContext];
-       if( (mxLayer != NULL) && (pContext != NULL) )
+       if( (maLayer.get() != NULL) && (pContext != NULL) )
        {
         CGContextRef rCGContext = reinterpret_cast<CGContextRef>([pContext 
graphicsPort]);
 
@@ -296,7 +294,7 @@ void AquaSalGraphics::UpdateWindow( NSRect& )
         }
 
                ApplyXorContext();
-               CGContextDrawLayerInRect( rCGContext, CGRectMake( 0, 0, 
mnWidth, mnHeight ), mxLayer );
+               CGContextDrawLayerInRect( rCGContext, CGRectMake( 0, 0, 
mnWidth, mnHeight ), maLayer.get() );
         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 8df74224e6..b7b17a1886 100644
--- a/main/vcl/aqua/source/gdi/salvd.cxx
+++ b/main/vcl/aqua/source/gdi/salvd.cxx
@@ -57,8 +57,6 @@ AquaSalVirtualDevice::AquaSalVirtualDevice( AquaSalGraphics* 
pGraphic, long nDX,
 :      mbGraphicsUsed( false )
 ,      mxBitmapContext( NULL )
 ,      mnBitmapDepth( 0 )
-,      mxLayer( NULL )
-,      mfScale( 1.0f )
 {
     if( pGraphic && pData && pData->rCGContext )
        {
@@ -66,7 +64,7 @@ AquaSalVirtualDevice::AquaSalVirtualDevice( AquaSalGraphics* 
pGraphic, long nDX,
         // We ignore nDx and nDY, as the desired size comes from the 
SystemGraphicsData
         mbForeignContext = true;        // the mxContext is from pData
            mpGraphics = new AquaSalGraphics( /*pGraphic*/ );
-           mpGraphics->SetVirDevGraphics( mxLayer, pData->rCGContext );
+           mpGraphics->SetVirDevGraphics( ScaledLayer(), pData->rCGContext );
        }
        else
        {
@@ -99,7 +97,7 @@ AquaSalVirtualDevice::~AquaSalVirtualDevice()
 {
        if( mpGraphics )
        {
-               mpGraphics->SetVirDevGraphics( NULL, NULL );
+               mpGraphics->SetVirDevGraphics( ScaledLayer(), NULL );
                delete mpGraphics;
                mpGraphics = 0;
        }
@@ -112,16 +110,16 @@ void AquaSalVirtualDevice::Destroy()
 {
     if( mbForeignContext ) {
         // Do not delete mxContext that we have received from outside VCL
-               mxLayer = NULL;
+               maLayer = ScaledLayer();
         return;
     }
 
-       if( mxLayer )
+       if( maLayer.get() )
        {
                if( mpGraphics )
-                       mpGraphics->SetVirDevGraphics( NULL, NULL );
-               CGLayerRelease( mxLayer );
-               mxLayer = NULL;
+                       mpGraphics->SetVirDevGraphics( ScaledLayer(), NULL );
+               CGLayerRelease( maLayer.get() );
+               maLayer = ScaledLayer();
        }
 
        if( mxBitmapContext )
@@ -161,10 +159,10 @@ sal_Bool AquaSalVirtualDevice::SetSize( long nDX, long 
nDY )
         return true;
     }
 
-    if( mxLayer )
+    if( maLayer.get() )
     {
-       const CGSize aSize = CGLayerGetSize( mxLayer );
-        if( (nDX * mfScale == aSize.width) && (nDY * mfScale == aSize.height) )
+       const CGSize aSize = maLayer.getPixelSize();
+        if( CGSizeEqualToSize( maLayer.toPixels( nDX, nDY ), aSize ) )
            {
                // Yay, we do not have to do anything :)
                        return true;
@@ -172,7 +170,7 @@ sal_Bool AquaSalVirtualDevice::SetSize( long nDX, long nDY )
     }
 
     Destroy();
-    mfScale = 1.0f;
+    float fScale = 1.0f;
 
        // create a Quartz layer matching to the intended virdev usage
        CGContextRef xCGContext = NULL;
@@ -212,7 +210,7 @@ sal_Bool AquaSalVirtualDevice::SetSize( long nDX, long nDY )
                 // 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 = pSalFrame->getBackingScale();
+                fScale = pSalFrame->getBackingScale();
             }
             else
             {
@@ -232,30 +230,30 @@ sal_Bool AquaSalVirtualDevice::SetSize( long nDX, long 
nDY )
 
        DBG_ASSERT( xCGContext, "no context" );
 
-       const CGSize aNewSize = CGSizeMake( nDX * mfScale, nDY * mfScale);
-       mxLayer = CGLayerCreateWithContext( xCGContext, aNewSize, NULL );
+       const CGSize aNewSize = ScaledLayer::toPixels( nDX, nDY, fScale );
+       maLayer = ScaledLayer( CGLayerCreateWithContext( xCGContext, aNewSize, 
NULL ), fScale );
        if( xRefContext )
                CGContextRelease( xRefContext );
 
-       if( mxLayer && mpGraphics )
+       if( maLayer.get() && mpGraphics )
        {
                // get the matching Quartz context
-               CGContextRef xDrawContext = CGLayerGetContext( mxLayer );
-               mpGraphics->SetVirDevGraphics( mxLayer, xDrawContext, 
mnBitmapDepth, mfScale );
+               CGContextRef xDrawContext = CGLayerGetContext( maLayer.get() );
+               mpGraphics->SetVirDevGraphics( maLayer, xDrawContext, 
mnBitmapDepth );
        }
 
-       return (mxLayer != NULL);
+       return (maLayer.get() != NULL);
 }
 
 // -----------------------------------------------------------------------
 
 void AquaSalVirtualDevice::GetSize( long& rWidth, long& rHeight )
 {
-       if( mxLayer )
+       if( maLayer.get() )
        {
-       const CGSize aSize = CGLayerGetSize( mxLayer );
-               rWidth = static_cast<long>(aSize.width / mfScale);
-               rHeight = static_cast<long>(aSize.height / mfScale);
+       const CGSize aSize = maLayer.getPointSize();
+               rWidth = static_cast<long>(aSize.width);
+               rHeight = static_cast<long>(aSize.height);
        }
        else
        {
diff --git a/main/vcl/inc/aqua/salbmp.h b/main/vcl/inc/aqua/salbmp.h
index 7b6b8c80ec..231b8e40d1 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, float fScale = 
1.0f );
+       bool                    Create( const ScaledLayer& rLayer, int 
nBitCount, int nX, int nY, int nWidth, int nHeight, bool bMirrorVert = true );
 
 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 6d880d8d31..ed3532d5f1 100644
--- a/main/vcl/inc/aqua/salgdi.h
+++ b/main/vcl/inc/aqua/salgdi.h
@@ -31,6 +31,7 @@
 #include "postmac.h"
 
 #include "aqua/aquavcltypes.h"
+#include "aqua/scaledlayer.h"
 
 #include "outfont.hxx"
 #include "salgdi.hxx"
@@ -149,14 +150,13 @@ class AquaSalGraphics : public SalGraphics
     friend class CTLayout;
 protected:
     AquaSalFrame*                           mpFrame;
-       CGLayerRef                                                              
mxLayer;        // Quartz graphics layer
+       ScaledLayer                                                             
maLayer;        // Quartz graphics layer
        CGContextRef                                mrContext;  // Quartz 
drawing context
        class XorEmulation*                                             
mpXorEmulation;
     int                                     mnXorMode; // 0: off 1: on 2: 
invert only
        int                                                                     
        mnWidth;
        int                                                                     
        mnHeight;
        int                                                                     
        mnBitmapDepth;  // zero unless bitmap
-       float                                                                   
        mfScale;                // layer pixels per point
     /// device resolution of this graphics
     long                                    mnRealDPIX;
        long                                    mnRealDPIY;
@@ -199,7 +199,7 @@ public:
 
     void                SetWindowGraphics( AquaSalFrame* pFrame );
     void                SetPrinterGraphics( CGContextRef, long nRealDPIX, long 
nRealDPIY, double fFakeScale );
-    void                SetVirDevGraphics( CGLayerRef, CGContextRef, int 
nBitDepth = 0, float fScale = 1.0f );
+    void                SetVirDevGraphics( const ScaledLayer&, CGContextRef, 
int nBitDepth = 0 );
 
     void                initResolution( NSWindow* );
     void                copyResolution( AquaSalGraphics& );
diff --git a/main/vcl/inc/aqua/salvd.h b/main/vcl/inc/aqua/salvd.h
index d76c8779cd..80c979dc47 100644
--- a/main/vcl/inc/aqua/salvd.h
+++ b/main/vcl/inc/aqua/salvd.h
@@ -69,8 +69,7 @@ private:
     bool mbForeignContext;           // is mxContext from outside VCL
     CGContextRef mxBitmapContext;
     int mnBitmapDepth;
-       CGLayerRef mxLayer;              // Quartz layer
-       float mfScale;                   // layer pixels per point
+       ScaledLayer maLayer;             // Quartz layer
        AquaSalGraphics* mpGraphics;     // current VirDev graphics
 
        void Destroy();
diff --git a/main/vcl/inc/aqua/scaledlayer.h b/main/vcl/inc/aqua/scaledlayer.h
new file mode 100644
index 0000000000..ef0aab396d
--- /dev/null
+++ b/main/vcl/inc/aqua/scaledlayer.h
@@ -0,0 +1,63 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+
+
+#ifndef _SV_SCALEDLAYER_H
+#define _SV_SCALEDLAYER_H
+
+#include "premac.h"
+#include <ApplicationServices/ApplicationServices.h>
+#include "postmac.h"
+
+// A CGLayer sized in pixels and the number of its pixels per point.
+// It does not retain or release the layer.
+class ScaledLayer
+{
+public:
+       ScaledLayer() : mxLayer( NULL ), mfScale( 1.0f ) {}
+       ScaledLayer( CGLayerRef xLayer, float fScale ) : mxLayer( xLayer ), 
mfScale( fScale ) {}
+
+       CGLayerRef      get() const { return mxLayer; }
+       float           getScale() const { return mfScale; }
+
+       CGSize          getPixelSize() const { return mxLayer ? CGLayerGetSize( 
mxLayer ) : CGSizeZero; }
+       CGSize          getPointSize() const
+       {
+               const CGSize aPixels = getPixelSize();
+               return CGSizeMake( aPixels.width / mfScale, aPixels.height / 
mfScale );
+       }
+
+       static CGSize toPixels( CGFloat fWidth, CGFloat fHeight, float fScale )
+       {
+               return CGSizeMake( fWidth * fScale, fHeight * fScale );
+       }
+       CGSize          toPixels( CGFloat fWidth, CGFloat fHeight ) const { 
return toPixels( fWidth, fHeight, mfScale ); }
+
+       // lets a layer context take VCL coordinates in points
+       void            scaleContext( CGContextRef xContext ) const { 
CGContextScaleCTM( xContext, mfScale, mfScale ); }
+
+private:
+       CGLayerRef      mxLayer;
+       float           mfScale;
+};
+
+#endif // _SV_SCALEDLAYER_H

Reply via email to