changed AquaSalGraphics implementation

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

changed AquaSalGraphics implementation

Philipp Lohmann
Hi,

attached you'll find a changed implementation for AquaSalGraphics. This
implements the new way of only painting to a back buffer and only
updating to the window if a system event requests it (or the frame is
flushed).

I found no more problems in comparison to the aquavcl01 checked in
version and an outdevgrind test (vcl's performance measuring tool to be
found in vcl/workben) shows that performance almost over the board is
considerably better. However since it's a quite invasive patch I'd like
people to play with it and find severe problems before I commit it.

Unless someone objects until tomorrow evening (german time) I'll commit
this patch.

Kind regards, pl

--
If you give someone a program, you will frustrate them for a day;
if you teach them how to program, you will frustrate them for a lifetime.
      -- Author unknown


Index: inc/salbmp.h
===================================================================
RCS file: /cvs/gsl/vcl/aqua/inc/Attic/salbmp.h,v
retrieving revision 1.1.2.7
diff -r1.1.2.7 salbmp.h
140,141c140,144
< bool Create( CGContextRef xContext, int nX, int nY, int nWidth, int nHeight );
< bool Create( sal_uInt32 nWidth, sal_uInt32 nHeight, sal_uInt16 nBits, sal_uInt32 nBytesPerRow, sal_uInt8* pBuffer, sal_uInt32 nX, sal_uInt32 nY, sal_uInt32 nDX, sal_uInt32 nDY );
---
> bool Create( CGContextRef xContext, int nX, int nY, int nWidth, int nHeight, bool bMirrorVert = true );
> bool Create( sal_uInt32 nWidth, sal_uInt32 nHeight, sal_uInt16 nBits, sal_uInt32 nBytesPerRow, sal_uInt8* pBuffer,
>                             sal_uInt32 nX, sal_uInt32 nY, sal_uInt32 nDX, sal_uInt32 nDY,
>                             bool bMirrorVert = true
>                             );
Index: inc/salframe.h
===================================================================
RCS file: /cvs/gsl/vcl/aqua/inc/salframe.h,v
retrieving revision 1.15.112.21
diff -r1.15.112.21 salframe.h
161a162,164
>    
>     // trigger painting of the window
>     void SendPaintEvent();
Index: inc/salgdi.h
===================================================================
RCS file: /cvs/gsl/vcl/aqua/inc/salgdi.h,v
retrieving revision 1.28.112.28
diff -r1.28.112.28 salgdi.h
94d93
< CGContextRef mrBitmapContext; // bitmap graphics context (either from a virtual device(mrBitmapContext==mrContext) or an offscreen copy of mrContext
96,97d94
< CGLayerRef mrCGLayer; // CGLayer to store what we draw to mrContext and be able to repaint (replace mrBitmapContext)
< CGContextRef mrCGLayerContext; // Context of CGLayer, used for drawing
124,125d120
< sal_Int32 mnGraphics; // guards BeginGraphics and EndGraphics from multiple calls
<
131,134d125
< #if DEBUGLEVEL>1
<         bool               mbQDCG;                   //true if in QDCG
< #endif
<
156d146
< bool isOffscreenCopy() const;
157a148,149
>     bool                CheckContext();
>     void                UpdateWindow();
159,164d150
<     // set up and release graphics context, required for any drawing operation
<     //  the view will be be flipped like the HIView coordinate system
<     //  i.e. (0,0) is top left and the y-axis points to the bottom
<     bool                BeginGraphics();
<     bool                EndGraphics();
< void InitContextForPainting( CGContextRef xContext );
167a154,155
>    
>     void                SetState();
343,347d330
< inline bool AquaSalGraphics::isOffscreenCopy() const
< {
< return mrBitmapContext && (mrBitmapContext != mrContext);
< }
<
Index: source/gdi/salatslayout.cxx
===================================================================
RCS file: /cvs/gsl/vcl/aqua/source/gdi/Attic/salatslayout.cxx,v
retrieving revision 1.1.2.15
diff -r1.1.2.15 salatslayout.cxx
335,339c335
< ATSUAttributeTag theTagsOff[10];
< ByteCount theSizesOff[10];
< ATSUAttributeValuePtr theValuesOff[10];
< ItemCount numcontrolsOff = 0;
< long height;
---
> long height = 0;
347c343
< if ( mpGraphics->BeginGraphics() )
---
> if ( mpGraphics->CheckContext() )
349,383c345,359
< // Get windows dimensions
< GetWindowPortBounds( mpGraphics->mrWindow, &windowBounds );
< height = windowBounds.bottom - windowBounds.top;
< // Modify Y for flipped view
< aPos.Y() = height - aPos.Y();
<
< if(mpGraphics->mrContext != NULL){
< // the flipped view leads to flipped glyphs as well
< // so apply another transformation that flips back and adjust y-pos accordingly
<
< CGContextTranslateCTM ( mpGraphics->mrContext, 0, height );
< CGContextScaleCTM ( mpGraphics->mrContext, 1.0, -1.0 );
<
< if (mpGraphics->isOffscreenCopy())
< {
< CGContextTranslateCTM ( mpGraphics->mrBitmapContext, 0, height );
< CGContextScaleCTM ( mpGraphics->mrBitmapContext, 1.0, -1.0 );
< }
<
<
< theTags[numcontrols] = kATSUCGContextTag;
< theSizes[numcontrols] = sizeof( CGContextRef );
< theValues[numcontrols++] =  &(mpGraphics->mrContext);
<
< }
< else
< {
< AquaLog("-->%s : mpGraphics->mrContext is NULL\n",__func__);
< }
<
< if (mpGraphics->isOffscreenCopy()){
< theTagsOff[numcontrolsOff] = kATSUCGContextTag;
< theSizesOff[numcontrolsOff] = sizeof( CGContextRef );
< theValuesOff[numcontrolsOff++] = &(mpGraphics->mrBitmapContext);
< }
---

> CGContextSaveGState( mpGraphics->mrContext );
>         // Get windows dimensions
>         height = CGBitmapContextGetHeight( mpGraphics->mrContext ); // returns 0 in not a bitmap context case
>         // Modify Y for flipped view
>         aPos.Y() = height - aPos.Y();
>        
>         // the flipped view leads to flipped glyphs as well
>         // so apply another transformation that flips back and adjust y-pos accordingly
>        
>         CGContextTranslateCTM ( mpGraphics->mrContext, 0, height );
>         CGContextScaleCTM ( mpGraphics->mrContext, 1.0, -1.0 );
>        
>         theTags[numcontrols] = kATSUCGContextTag;
>         theSizes[numcontrols] = sizeof( CGContextRef );
>         theValues[numcontrols++] =  &(mpGraphics->mrContext);
392,399d367
<
<
< if (mpGraphics->isOffscreenCopy())
< {
< theTagsOff[numcontrolsOff] = kATSULineRotationTag;
< theSizesOff[numcontrolsOff] = sizeof( Fixed );
< theValuesOff[numcontrolsOff++] = &theAngle;
< }
427,435d394
<
< if (mpGraphics->isOffscreenCopy())
< {
< ATSUSetLayoutControls( maATSULayout, numcontrolsOff, theTagsOff, theSizesOff, theValuesOff );
<
< theErr = ATSUDrawText( maATSULayout, mnTextOfs, mnTextLen, Long2Fix(aPos.X()), Long2Fix(aPos.Y()));
< if( theErr != noErr )
< AquaLog( "ATSLayout::DrawText(0x%p) : ATSUDrawText failed for offscreen copy!\n", this );
< }
437,438c396
<
<         mpGraphics->EndGraphics();
---
> CGContextRestoreGState( mpGraphics->mrContext );
Index: source/gdi/salbmp.cxx
===================================================================
RCS file: /cvs/gsl/vcl/aqua/source/gdi/salbmp.cxx,v
retrieving revision 1.23.112.19
diff -r1.23.112.19 salbmp.cxx
84c84
< bool AquaSalBitmap::Create( CGContextRef xContext, int nX, int nY, int nWidth, int nHeight )
---
> bool AquaSalBitmap::Create( CGContextRef xContext, int nX, int nY, int nWidth, int nHeight, bool bMirrorVert )
89c89
< nX, nY, nWidth, nHeight );
---
> nX, nY, nWidth, nHeight, bMirrorVert );
95c95
< bool AquaSalBitmap::Create( sal_uInt32 nWidth, sal_uInt32 nHeight, sal_uInt16 nBits, sal_uInt32 nBytesPerRow, sal_uInt8* pBuffer, sal_uInt32 nX, sal_uInt32 nY, sal_uInt32 nDX, sal_uInt32 nDY )
---
> bool AquaSalBitmap::Create( sal_uInt32 nWidth, sal_uInt32 nHeight, sal_uInt16 nBits, sal_uInt32 nBytesPerRow, sal_uInt8* pBuffer, sal_uInt32 nX, sal_uInt32 nY, sal_uInt32 nDX, sal_uInt32 nDY, bool bMirrorVert )
112,121c112,137
< nY = nHeight - nY - nDY;
< pSource += nBytesPerRow * nY;
<
< sal_uInt32 y = nDY;
< while( y-- )
< {
< memcpy( pDest, pSource, mnBytesPerRow );
< pDest += mnBytesPerRow;
< pSource += nBytesPerRow;
< }
---

>         if( bMirrorVert )
>         {
>             nY = nHeight - nY - nDY;
>             pSource += nBytesPerRow * nY;
>            
>             sal_uInt32 y = nDY;
>             while( y-- )
>             {
>                 memcpy( pDest, pSource, mnBytesPerRow );
>                 pDest += mnBytesPerRow;
>                 pSource += nBytesPerRow;
>             }
>         }
>         else
>         {
>             pSource += nBytesPerRow * nY;
>             pDest += mnBytesPerRow * (nDY-1);
>            
>             sal_uInt32 y = nDY;
>             while( y-- )
>             {
>                 memcpy( pDest, pSource, mnBytesPerRow );
>                 pDest -= mnBytesPerRow;
>                 pSource += nBytesPerRow;
>             }
>         }
Index: source/gdi/salgdi.cxx
===================================================================
RCS file: /cvs/gsl/vcl/aqua/source/gdi/salgdi.cxx,v
retrieving revision 1.59.112.44
diff -r1.59.112.44 salgdi.cxx
99,103d98
<     mrBitmapContext =  NULL;
<
< #if DEBUGLEVEL>1
<     mbQDCG=false;
< #endif
134d128
< mnGraphics = 0;
141,142d134
< DBG_ASSERT( mnGraphics == 0, "vcl::AquaSalGraphics::~AquaSalGraphics(), BeginGraphics and EndGraphics calls do not match!" );
<
154c146
< if( mrBitmapContext && (mrBitmapContext != mrContext) )
---
> if( mrContext && mrWindow != 0 )
157,159c149,151
< void * pBuffer = CGBitmapContextGetData(mrBitmapContext);
< CFRelease( mrBitmapContext );
< mrBitmapContext = 0;
---
> void * pBuffer = CGBitmapContextGetData(mrContext);
> CFRelease( mrContext );
> mrContext = 0;
161c153
< free( pBuffer );
---
> rtl_freeMemory( pBuffer );
210,221c202
< if ( mrWindow )
< {
< return static_cast<USHORT>( CGDisplayBitsPerPixel( GetWindowDisplayID() ) );
< }
< else if( mrBitmapContext )
< {
< return static_cast<USHORT>( CGBitmapContextGetBitsPerPixel(mrBitmapContext) );
< }
< else
< {
< return 32;
< }
---
>     return static_cast<USHORT>( CheckContext() ? CGBitmapContextGetBitsPerPixel(mrContext) : 0 );
230a212,213
>     if( CheckContext() )
>         SetState();
293a277,278
>     if( CheckContext() )
>         SetState();
300a286,287
>
> CGContextSetStrokeColor( mrContext, mpLineColor );
310a298,299
>
> CGContextSetStrokeColor( mrContext, mpLineColor );
317a307,308
>
> CGContextSetFillColor( mrContext, mpFillColor );
327a319,320
>
> CGContextSetFillColor( mrContext, mpFillColor );
337a331,340

> static SalColor ImplGetROPSalColor( SalROPColor nROPColor )
> {
> SalColor nSalColor;
> if ( nROPColor == SAL_ROP_0 )
> nSalColor = MAKE_SALCOLOR( 0, 0, 0 );
> else
> nSalColor = MAKE_SALCOLOR( 255, 255, 255 );
> return nSalColor;
> }
>
339a343
>     SetLineColor( ImplGetROPSalColor( nROPColor ) );
345a350
>     SetFillColor( ImplGetROPSalColor( nROPColor ) );
352,358c357,359
<     // save fill color and replace it with the desired color
<     float oldFillColor[4];
<     memcpy( (void*) oldFillColor, (void*) mpFillColor, sizeof( oldFillColor ) );
<     memcpy( (void*) mpFillColor, (void*) pColor, sizeof( oldFillColor ) );
<    
< if ( BeginGraphics() )
< {
---
> if ( CheckContext() )
>     {
>         CGContextSetFillColor( mrContext, pColor );
360,369c361,363
< CGContextFillRect (mrContext, CGRectMake (nX, nY, 1, 1));
<
< if( isOffscreenCopy() )
< CGContextFillRect (mrBitmapContext, CGRectMake (nX, nY, 1, 1));
< EndGraphics();
< }
<    
<     // restore fill color
<     memcpy( (void*) mpFillColor, (void*) oldFillColor, sizeof( oldFillColor ) );
<    
---
> CGContextFillRect( mrContext, CGRectMake (nX, nY, 1, 1) );
>         CGContextSetFillColor( mrContext, mpFillColor );
>     }
375c369,370
<     ImplDrawPixel( nX, nY, mpLineColor );
---
>     ImplDrawPixel( nX, nY, mpLineColor );
>     RefreshRect( nX, nY, 1, 1 );
389a385
>     RefreshRect( nX, nY, 1, 1 );
404,405c400
< if ( BeginGraphics() )
< {
---
> if ( CheckContext() )
407,410c402,405
< if( isOffscreenCopy() )
< implDrawLine( mrBitmapContext, nX1, nY1, nX2, nY2 );
< EndGraphics();
< }
---
>    
>     Rectangle aRefreshRect( nX1, nY1, nX2, nY2 );
>     aRefreshRect.Justify();
>     RefreshRect( aRefreshRect.Left(), aRefreshRect.Top(), aRefreshRect.GetWidth(), aRefreshRect.GetHeight() );
415,422d409
< static void implDrawRect( CGContextRef& xContext, long nX, long nY, long nWidth, long nHeight, bool bFilled )
< {
< if( bFilled )
< CGContextStrokeRect(xContext, CGRectMake (nX, nY, nWidth, nHeight));
< else
< CGContextFillRect(xContext, CGRectMake (nX, nY, nWidth, nHeight));
< }
<
425c412
< if ( BeginGraphics() )
---
> if ( CheckContext() )
427c414,417
< const bool bFilled = IsBrushTransparent();
---
>         CGRect aRect( CGRectMake(nX, nY, nWidth, nHeight) );
>        
>         if( ! IsBrushTransparent() )
>             CGContextFillRect( mrContext, aRect );
429,432c419,422
< implDrawRect( mrContext, nX, nY, nWidth, nHeight, bFilled );
< if( isOffscreenCopy() )
< implDrawRect( mrBitmapContext, nX, nY, nWidth, nHeight, bFilled );
< EndGraphics();
---
>         if( ! IsPenTransparent() )
>             CGContextStrokeRect( mrContext, aRect );
>        
>         RefreshRect( nX, nY, nWidth, nHeight );
450c440
< if( (nPoints > 1) && BeginGraphics() )
---
> if( (nPoints > 1) && CheckContext() )
453,455c443
< if( isOffscreenCopy() )
< implDrawPolyLine( mrBitmapContext, nPoints, pPtAry );
< EndGraphics();
---
>         RefreshWindow();
461c449
< static void ImplDrawPolygone( CGContextRef& xContext, ULONG nPoints, const SalPoint *pPtAry, float* pFillColor, float* pLineColor )
---
> static void ImplDrawPolygon( CGContextRef& xContext, ULONG nPoints, const SalPoint *pPtAry, float* pFillColor, float* pLineColor )
481,487c469,471
< if( (nPoints > 1) && BeginGraphics() )
< {
< ImplDrawPolygone( mrContext, nPoints, pPtAry, mpFillColor, mpLineColor );
< if( isOffscreenCopy() )
< ImplDrawPolygone( mrBitmapContext, nPoints, pPtAry, mpFillColor, mpLineColor );
< EndGraphics();
< }
---
> if( (nPoints > 1) && CheckContext() )
> ImplDrawPolygon( mrContext, nPoints, pPtAry, mpFillColor, mpLineColor );
>     RefreshWindow();
492c476
< static void ImplDrawPolyPolygone( CGContextRef& xContext, ULONG nPolyCount, const ULONG *pPoints, PCONSTSALPOINT  *ppPtAry )
---
> static void ImplDrawPolyPolygon( CGContextRef& xContext, ULONG nPolyCount, const ULONG *pPoints, PCONSTSALPOINT  *ppPtAry )
514,520c498,499
< if( nPolyCount && ( mpFillColor[3] > 0.0 ) && BeginGraphics() )
< {
< ImplDrawPolyPolygone( mrContext, nPolyCount, pPoints, ppPtAry );
< if( isOffscreenCopy() )
< ImplDrawPolyPolygone( mrBitmapContext, nPolyCount, pPoints, ppPtAry );
< EndGraphics();
< }
---
> if( nPolyCount && ( mpFillColor[3] > 0.0 ) && CheckContext() )
> ImplDrawPolyPolygon( mrContext, nPolyCount, pPoints, ppPtAry );
526a506
>     RefreshWindow();
607c587
< if ( BeginGraphics() )
---
> if( CheckContext() )
612,613d591
< if( isOffscreenCopy() )
< CGContextDrawImage(mrBitmapContext, CGRectMake ((int)pPosAry->mnDestX, (int)pPosAry->mnDestY, (int)pPosAry->mnDestWidth, (int)pPosAry->mnDestHeight), xImage);
618d595
< EndGraphics();
636c613
< if ( BeginGraphics() )
---
> if( CheckContext() )
645,646d621
< if( isOffscreenCopy() )
< CGContextDrawImage(mrBitmapContext, CGRectMake (pPosAry->mnDestX, pPosAry->mnDestY, pPosAry->mnDestWidth, pPosAry->mnDestHeight), xMaskedImage);
649c624
< EndGraphics();
---
>         RefreshWindow();
659c634
< if ( BeginGraphics() )
---
> if ( CheckContext() )
668,669d642
< if( isOffscreenCopy() )
< CGContextDrawImage(mrBitmapContext, CGRectMake (pPosAry->mnDestX, pPosAry->mnDestY, pPosAry->mnDestWidth, pPosAry->mnDestHeight), xImage);
672d644
< EndGraphics();
687c659
< if( mrBitmapContext )
---
> if( mrContext )
690c662
< if( !pBitmap->Create( mrBitmapContext, nX, nY, nDX, nDY ) )
---
> if( !pBitmap->Create( mrContext, nX, nY, nDX, nDY, mrWindow == 0 ) )
715c687
<     if ( BeginGraphics() )
---
>     if ( CheckContext() )
745d716
<         EndGraphics();
748,751d718
<     else
<     {
<         AquaLog( ">>>>> AquaSalGraphics::invert - failed BeginGraphics\n" );
<     }
759c726
<     if ( BeginGraphics() )
---
>     if ( CheckContext() )
789,790d755
<         EndGraphics();
<         RefreshRect(pRect.origin.x, pRect.origin.y, pRect.size.width, pRect.size.height);
791a757
>         RefreshRect(pRect.origin.x, pRect.origin.y, pRect.size.width, pRect.size.height);
839c805
<     if ( BeginGraphics() )
---
>     if ( CheckContext() )
841d806
<
843,847c808
<
< if( isOffscreenCopy() )
<             CGContextDrawImage(mrBitmapContext, CGRectMake( rTR.mnDestX, rTR.mnDestY, rTR.mnDestWidth, rTR.mnDestHeight), xMaskedImage );
<
<         EndGraphics();
---
>         RefreshRect(rTR.mnDestX, rTR.mnDestY, rTR.mnDestWidth, rTR.mnDestHeight);
859c820
<     if ( BeginGraphics() )
---
>     if ( CheckContext() )
866a828
>         mpFillColor[3] = oldAlpha; // reset the old value
869d830
<         EndGraphics();
871d831
<         mpFillColor[3] = oldAlpha; // reset the old value
1055c1015
< else if( mrBitmapContext )
---
> else if( mrContext )
Index: source/gdi/salgdiutils.cxx
===================================================================
RCS file: /cvs/gsl/vcl/aqua/source/gdi/salgdiutils.cxx,v
retrieving revision 1.7.112.23
diff -r1.7.112.23 salgdiutils.cxx
80c80,86
< mrBitmapContext = xContext;
---
>     if( mrContext )
>     {
>         CGContextSetFillColorSpace( mrContext, mrRGBColorSpace );
>         CGContextSetStrokeColorSpace( mrContext, mrRGBColorSpace );
>         CGContextSaveGState( mrContext );
>         SetState();
>     }
85c91
< void AquaSalGraphics::InitContextForPainting( CGContextRef xContext )
---
> void AquaSalGraphics::SetState()
86a93,94
>     CGContextRestoreGState( mrContext );
>     CGContextSaveGState( mrContext );
90,92c98,100
< CGContextBeginPath( xContext );                // discard any existing path
< CGContextAddPath( xContext, mrClippingPath );  // set the current path to the clipping path
< CGContextClip( xContext );                     // use it for clipping
---
> CGContextBeginPath( mrContext );                // discard any existing path
> CGContextAddPath( mrContext, mrClippingPath );  // set the current path to the clipping path
> CGContextClip( mrContext );                     // use it for clipping
96,99c104,105
< CGContextSetFillColorSpace( xContext, mrRGBColorSpace );
< CGContextSetFillColor( xContext, mpFillColor );
< CGContextSetStrokeColorSpace( xContext, mrRGBColorSpace );
< CGContextSetStrokeColor( xContext, mpLineColor );
---
> CGContextSetFillColor( mrContext, mpFillColor );
> CGContextSetStrokeColor( mrContext, mpLineColor );
104c110
< bool AquaSalGraphics::BeginGraphics ()
---
> bool AquaSalGraphics::CheckContext()
106,166c112,117
< if( mnGraphics++ == 0 )
< {
< if( mrWindow != NULL && mrContext == 0)
< {
< Rect windowBounds;
< GetWindowPortBounds ( mrWindow, &windowBounds);
< const unsigned int nWidth = windowBounds.right - windowBounds.left;
< const unsigned int nHeight = windowBounds.bottom - windowBounds.top;
<
< if( mrBitmapContext )
< {
< // check if window size changed and we need to create a new bitmap context
< if( (CGBitmapContextGetWidth(mrBitmapContext) != nWidth)  || (CGBitmapContextGetHeight(mrBitmapContext) != nHeight) )
< {
< void* pBuffer = CGBitmapContextGetData(mrBitmapContext);
< CFRelease( mrBitmapContext );
< mrBitmapContext = 0;
< free( pBuffer );
< }
< }
<
< if( !mrBitmapContext )
< {
< void* pData = malloc( nWidth * 4 * nHeight );
< if (pData )
< {
< mrBitmapContext = CGBitmapContextCreate( pData, nWidth, nHeight, 8, nWidth * 4, mrRGBColorSpace, kCGImageAlphaNoneSkipFirst );
<
< if( !mrBitmapContext )
< {
< free( pData );
< }
< }
< }
<
< SetPortWindowPort (mrWindow);
< if( noErr == QDBeginCGContext (GetWindowPort (mrWindow), &mrContext))
< {
< #if DEBUGLEVEL>1
<                 mbQDCG = true;
< #endif
< if( mrBitmapContext )
< {
< CGContextSaveGState( mrBitmapContext );
< InitContextForPainting( mrBitmapContext );
< }
<
< CGContextTranslateCTM (mrContext, 0, nHeight);
< CGContextScaleCTM (mrContext, 1.0, -1.0);
<
< InitContextForPainting( mrContext );
<
< //RefreshWindow();
< }
< }
< else if( mbVirDev )
< {
< CGContextSaveGState( mrBitmapContext );
< InitContextForPainting( mrBitmapContext );
< }
< }
---
>     if( mrWindow != NULL )
>     {
>         Rect windowBounds;
>         GetWindowPortBounds( mrWindow, &windowBounds );
>         const unsigned int nWidth = windowBounds.right - windowBounds.left;
>         const unsigned int nHeight = windowBounds.bottom - windowBounds.top;
167a119,153

>         if( mrContext )
>         {
>             // check if window size changed and we need to create a new bitmap context
>             if( (CGBitmapContextGetWidth(mrContext) != nWidth)  || (CGBitmapContextGetHeight(mrContext) != nHeight) )
>             {
>                 void* pBuffer = CGBitmapContextGetData(mrContext);
>                 CFRelease( mrContext );
>                 mrContext = 0;
>                 rtl_freeMemory( pBuffer );
>             }
>         }
>
>         if( !mrContext )
>         {
>             void* pData = rtl_allocateMemory( nWidth * 4 * nHeight );
>             if (pData )
>             {
>                 mrContext = CGBitmapContextCreate( pData, nWidth, nHeight, 8, nWidth * 4, mrRGBColorSpace, kCGImageAlphaNoneSkipFirst );
>
>                 if( !mrContext )
>                 {
>                     rtl_freeMemory( pData );
>                 }
>                 else
>                 {
>                     CGContextTranslateCTM( mrContext, 0, nHeight );
>                     CGContextScaleCTM( mrContext, 1.0, -1.0 );
>                     CGContextSetFillColorSpace( mrContext, mrRGBColorSpace );
>                     CGContextSetStrokeColorSpace( mrContext, mrRGBColorSpace );
>                     CGContextSaveGState( mrContext );
>                     SetState();
>                 }
>             }
>         }
>     }
174c160
< AquaLog("<<<WARNING>>> AquaSalGraphics::BeginGraphics() FAILED!!!!\n" );
---
> AquaLog("<<<WARNING>>> AquaSalGraphics::CheckContext() FAILED!!!!\n" );
184a171,173
>     myRect.right -= myRect.left;
>     myRect.bottom -= myRect.top;
>     myRect.left = myRect.top = 0;
203a193,199
>    
>     Rect aRect;
>     aRect.left   = (short)lX;
>     aRect.top    = (short)lY;
>     aRect.right  = (short)(lX + lWidth );
>     aRect.bottom = (short)(lY + lHeight );
>     InvalWindowRect(mrWindow, &aRect);
214a211
>     RefreshWindow();
221,227c218
<         bool bAcquireContext = (mrContext == NULL);
<         if( bAcquireContext )
<             bAcquireContext = BeginGraphics();
<         if( mrContext )
<             CGContextFlush(mrContext);
<         if( bAcquireContext )
<             EndGraphics();
---
>         UpdateWindow();
249,289c240
< bool AquaSalGraphics::EndGraphics ()
< {
< if( (mnGraphics > 0) && (--mnGraphics == 0) )
< {
< if( mrContext != NULL && mrWindow != NULL )
< {
< /* TODO: Optimize this so we synchronize only on user event?
< if( !mnUpdateGraphicsEvent )
< mnUpdateGraphicsEvent = Application::PostUserEvent( LINK( this, AquaSalGraphics, UpdateGraphics), 0 );
< */
< //RefreshWindow();
< //CGContextSynchronize(mrContext);
<
< QDEndCGContext (GetWindowPort(mrWindow), &mrContext);
< #if DEBUGLEVEL>1
<                          mbQDCG = false;
< #endif
< mrContext = 0;
<
< if( mrBitmapContext )
< CGContextRestoreGState( mrBitmapContext );
< }
< else if( mbVirDev )
< {
< if( mrBitmapContext )
< CGContextRestoreGState( mrBitmapContext );
< }
< }
< #if DEBUGLEVEL>1
<     if(mbQDCG)
<         AquaLog("-->%s unmatched QDEndCGContext\n",__func__);
<     else
<         AquaLog("-->%s OK\n",__func__);
< #endif
< return true;
< }
<
< // -----------------------------------------------------------------------
<
< /*
< IMPL_LINK( AquaSalGraphics, UpdateGraphics, void*, EMPTYARG )
---
> void AquaSalGraphics::UpdateWindow()
291,292d241
< mnUpdateGraphicsEvent = 0;
<
295,296c244,246
< SetPortWindowPort (mrWindow);
< if( noErr == QDBeginCGContext (GetWindowPort (mrWindow), &mrWindowContext))
---
>         SetPortWindowPort(mrWindow);
>         CGContextRef xWindowContext = 0;
> if( noErr == QDBeginCGContext (GetWindowPort (mrWindow), &xWindowContext))
299c249
<             GetWindowPortBounds ( mrWindow, &windowBounds);
---
>             GetWindowPortBounds( mrWindow, &windowBounds);
301c251
< CGContextDrawImage(mrWindowContext, CGRectMake (windowBounds.left, windowBounds.top, windowBounds.right - windowBounds.left, windowBounds.bottom - windowBounds.top ), xImage);
---
> CGContextDrawImage(xWindowContext, CGRectMake(windowBounds.left, windowBounds.top, windowBounds.right - windowBounds.left, windowBounds.bottom - windowBounds.top ), xImage);
303,305c253,254
< CGContextSynchronize(mrWindowContext);
< QDEndCGContext (GetWindowPort(mrWindow), &mrWindowContext);
< mrWindowContext = 0;
---
>             CGContextFlush( xWindowContext );
> QDEndCGContext (GetWindowPort(mrWindow), &xWindowContext);
308d256
< return 0;
310d257
< */
Index: source/gdi/salnativewidgets.cxx
===================================================================
RCS file: /cvs/gsl/vcl/aqua/source/gdi/Attic/salnativewidgets.cxx,v
retrieving revision 1.1.2.33
diff -r1.1.2.33 salnativewidgets.cxx
279c279,280
<             if( nPart == PART_ENTIRE_CONTROL )
---
>             #if 0
>             if( nPart == PART_ENTIRE_CONTROL ) // we don't currently support the tooltip
280a282
>             #endif
476,477c478,482
<     BOOL bOk = FALSE;
<
---
>     BOOL bOK = FALSE;
>    
>     if( ! CheckContext() )
>         return false;
>    
478a484
>     RefreshRect( buttonRect.Left(), buttonRect.Top(), buttonRect.GetWidth(), buttonRect.GetHeight() );
485c491
<
---
>    
487,488c493,494
<         PART_BUTTON_UP 101
<         PART_BUTTON_DOWN 102
---
>     PART_BUTTON_UP 101
>     PART_BUTTON_DOWN 102
492c498
<
---
>    
495,496c501,502
<      **/
<
---
>     **/
>    
500,503c506,509
<         //case CTRL_FIXEDBORDER:
<         //case CTRL_TAB_PANE:
<         //case CTRL_TAB_BODY:
<         case CTRL_TOOLBAR:
---
>     //case CTRL_FIXEDBORDER:
>     //case CTRL_TAB_PANE:
>     //case CTRL_TAB_BODY:
>     case CTRL_TOOLBAR:
505c511,532
<             if( BeginGraphics() )
---

>             HIThemeMenuItemDrawInfo aMenuItemDrawInfo;
>             aMenuItemDrawInfo.version = 0;
>             aMenuItemDrawInfo.state = kThemeMenuActive;
>             aMenuItemDrawInfo.itemType = kThemeMenuItemHierBackground;
>             HIThemeDrawMenuItem(&rc,&rc,&aMenuItemDrawInfo,mrContext,kHIThemeOrientationNormal,NULL);
>             bOK = true;
>         }
>         break;
>        
>     case CTRL_MENU_POPUP:
>         {
>             if ((nPart == PART_ENTIRE_CONTROL) || (nPart == PART_MENU_ITEM )|| (nPart == HAS_BACKGROUND_TEXTURE ))
>             {
>                 HIThemeMenuDrawInfo aMenuInfo;
>                 aMenuInfo.version = 0;
>                 aMenuInfo.menuType = kThemeMenuTypePullDown;
>                
>                 HIThemeMenuItemDrawInfo aMenuItemDrawInfo;
>                 // the Aqua grey theme when the item is selected is drawn here.
>                 aMenuItemDrawInfo.itemType = kThemeMenuItemPlain;
>                
>                 if ((nPart == PART_MENU_ITEM ))
507,508c534,539
<                     HIThemeMenuItemDrawInfo aMenuItemDrawInfo;
<                     aMenuItemDrawInfo.version = 0;
---
>                     // the blue theme when the item is selected is drawn here.
>                     aMenuItemDrawInfo.state = kThemeMenuSelected;
>                 }
>                 else
>                 {
>                     // normal color for non selected item
510,515d540
<                     aMenuItemDrawInfo.itemType = kThemeMenuItemHierBackground;
<                     HIThemeDrawMenuItem(&rc,&rc,&aMenuItemDrawInfo,mrContext,kHIThemeOrientationNormal,NULL);
<                     if ( isOffscreenCopy() )
<                         HIThemeDrawMenuItem(&rc,&rc,&aMenuItemDrawInfo,mrBitmapContext,kHIThemeOrientationNormal,NULL);
<                     EndGraphics();
<                     return true;
517,518c542,550
<             else
<                 return false;
---
>                
>                 // repaints the background of the pull down menu
>                 HIThemeDrawMenuBackground(&rc,&aMenuInfo,mrContext,kHIThemeOrientationNormal);
>                
>                 // repaints the item either blue (selected) and/or Aqua grey (active only)
>                 HIThemeDrawMenuItem(&rc,&rc,&aMenuItemDrawInfo,mrContext,kHIThemeOrientationNormal,&rc);
>                
>                 bOK = true;
>             }
520,569c552,553
<             break;
<
<         case CTRL_MENU_POPUP:
<         {
<             if ((nPart == PART_ENTIRE_CONTROL) || (nPart == PART_MENU_ITEM )|| (nPart == HAS_BACKGROUND_TEXTURE ))
< {
< HIThemeMenuDrawInfo aMenuInfo;
< aMenuInfo.version = 0;
< aMenuInfo.menuType = kThemeMenuTypePullDown;
<
< HIThemeMenuItemDrawInfo aMenuItemDrawInfo;
< // the Aqua grey theme when the item is selected is drawn here.
< aMenuItemDrawInfo.itemType = kThemeMenuItemPlain;
<
< if ((nPart == PART_MENU_ITEM ))
< {
< // the blue theme when the item is selected is drawn here.
< aMenuItemDrawInfo.state = kThemeMenuSelected;
< }
< else
< {
< // normal color for non selected item
< aMenuItemDrawInfo.state = kThemeMenuActive;
< }
<
< if( BeginGraphics() )
< {
<
<                             // repaints the background of the pull down menu
< HIThemeDrawMenuBackground(&rc,&aMenuInfo,mrContext,kHIThemeOrientationNormal);
<
<                             // repaints the item either blue (selected) and/or Aqua grey (active only)
< HIThemeDrawMenuItem(&rc,&rc,&aMenuItemDrawInfo,mrContext,kHIThemeOrientationNormal,&rc);
<
<                             // Draw POPUP menu item to the offscreen bitmap
<                             if ( isOffscreenCopy() )
<                             {
<                                 HIThemeDrawMenuBackground(&rc,&aMenuInfo,mrBitmapContext,kHIThemeOrientationNormal);
<                                 HIThemeDrawMenuItem(&rc,&rc,&aMenuItemDrawInfo,mrBitmapContext,kHIThemeOrientationNormal,&rc);
<                             }
<
< EndGraphics();
< return true;
< }
< else
< return false;
< }
< }
< break;
<
---
>         break;
>        
571,572c555
<    {
<
---
>         {
575c558
<
---
>            
578c561
<
---
>            
586c569
<
---
>                
589c572
<
---
>                
591,592c574,575
<                                 kThemeAdornmentDefault :
<                             kThemeAdornmentNone;
---
>                 kThemeAdornmentDefault :
>                 kThemeAdornmentNone;
594,606c577,580
<                 aBevelInfo.adornment |= kThemeAdornmentFocus;
<
<                 if( BeginGraphics() )
<                 {
<                     HIThemeDrawButton( &rc, &aBevelInfo, mrContext, kHIThemeOrientationNormal, NULL );
<                     if ( isOffscreenCopy() )
<                         HIThemeDrawButton( &rc, &aBevelInfo, mrBitmapContext, kHIThemeOrientationNormal, NULL );
<                     EndGraphics();
<                     return true;
<                 }
<                 else
<                     return false;
<                 break;
---
>                     aBevelInfo.adornment |= kThemeAdornmentFocus;
>                
>                 HIThemeDrawButton( &rc, &aBevelInfo, mrContext, kHIThemeOrientationNormal, NULL );
>                 bOK = true;
622c596
<
---
>                        
626c600
<
---
>                    
628c602
<
---
>                    
630c604
<
---
>                    
632,633c606,607
<                             kThemeAdornmentDefault :
<                             kThemeAdornmentNone;
---
>                     kThemeAdornmentDefault :
>                     kThemeAdornmentNone;
635,636c609,610
<                     aPushInfo.adornment |= kThemeAdornmentFocus;
<
---
>                         aPushInfo.adornment |= kThemeAdornmentFocus;
>                    
639,649c613,615
<
<                     if( BeginGraphics() )
<                     {
<                         HIThemeDrawButton( &rc, &aPushInfo, mrContext, kHIThemeOrientationNormal, NULL );
<                         if ( isOffscreenCopy() )
<                             HIThemeDrawButton( &rc, &aPushInfo, mrBitmapContext, kHIThemeOrientationNormal, NULL );
<                         EndGraphics();
<                         return true;
<                     }
<                     else
<                         return false;
---
>                    
>                     HIThemeDrawButton( &rc, &aPushInfo, mrContext, kHIThemeOrientationNormal, NULL );
>                     bOK = true;
651d616
<                     break;
653,655c618,621
<    }
<
< case CTRL_RADIOBUTTON:
---
>         }
>         break;
>        
>     case CTRL_RADIOBUTTON:
661,664c627,630
<                 case CTRL_RADIOBUTTON: aInfo.kind = kThemeRadioButton;
<                                         break;
<                 case CTRL_CHECKBOX:    aInfo.kind = kThemeCheckBox;
<                                         break;
---
>             case CTRL_RADIOBUTTON: aInfo.kind = kThemeRadioButton;
>                 break;
>             case CTRL_CHECKBOX:    aInfo.kind = kThemeCheckBox;
>                 break;
666c632
<
---
>            
668c634
<
---
>            
671c637
<
---
>            
673,674c639,640
<                                 kThemeAdornmentDefault :
<                                 kThemeAdornmentNone;
---
>             kThemeAdornmentDefault :
>             kThemeAdornmentNone;
677c643,653
<             if( BeginGraphics() )
---

>             HIThemeDrawButton( &rc, &aInfo, mrContext, kHIThemeOrientationNormal, NULL );
>             bOK = true;
>         }
>         break;
>        
>     case CTRL_SCROLLBAR:
>         {
>             ScrollbarValue* pScrollbarVal = (ScrollbarValue *)(aValue.getOptionalVal());
>            
>             if( nPart == PART_DRAW_BACKGROUND_VERT ||
>                 nPart == PART_DRAW_BACKGROUND_HORZ )
679,683c655,693
<                 HIThemeDrawButton( &rc, &aInfo, mrContext, kHIThemeOrientationNormal, NULL );
<                 if ( isOffscreenCopy() )
<                     HIThemeDrawButton( &rc, &aInfo, mrBitmapContext, kHIThemeOrientationNormal, NULL );
<                 EndGraphics();
<                 return true;
---

>                 HIThemeTrackDrawInfo aTrackDraw;
>                 aTrackDraw.version = 0;
>                 aTrackDraw.kind = kThemeMediumScrollBar;
>                 aTrackDraw.bounds = rc;
>                 aTrackDraw.min = pScrollbarVal->mnMin;
>                 aTrackDraw.max = pScrollbarVal->mnMax - pScrollbarVal->mnVisibleSize;
>                 aTrackDraw.value = pScrollbarVal->mnCur;
>                 aTrackDraw.reserved = 0;
>                 aTrackDraw.attributes = kThemeTrackShowThumb;
>                 if( nPart == PART_DRAW_BACKGROUND_HORZ )
>                     aTrackDraw.attributes |= kThemeTrackHorizontal;
>                 aTrackDraw.enableState = kThemeTrackActive;
>                
>                 ScrollBarTrackInfo aScrollInfo;
>                 aScrollInfo.viewsize = pScrollbarVal->mnVisibleSize;
>                 aScrollInfo.pressState = 0;
>                
>                 if ( pScrollbarVal->mnButton1State & CTRL_STATE_ENABLED )
>                 {
>                     if ( pScrollbarVal->mnButton1State & CTRL_STATE_PRESSED )
>                         aScrollInfo.pressState = kThemeTopOutsideArrowPressed;
>                 }
>                
>                 if ( pScrollbarVal->mnButton2State & CTRL_STATE_ENABLED )
>                 {
>                     if ( pScrollbarVal->mnButton2State & CTRL_STATE_PRESSED )
>                         aScrollInfo.pressState = kThemeBottomOutsideArrowPressed;
>                 }
>                
>                 if ( pScrollbarVal->mnThumbState & CTRL_STATE_ENABLED )
>                 {
>                     if ( pScrollbarVal->mnThumbState & CTRL_STATE_PRESSED )
>                         aScrollInfo.pressState = kThemeThumbPressed;
>                 }
>                
>                 aTrackDraw.trackInfo.scrollbar = aScrollInfo;
>                
>                 HIThemeDrawTrack( &aTrackDraw, NULL, mrContext, kHIThemeOrientationNormal );
>                 bOK = true;
685,686d694
<             else
<                 return false;
688,745d695
<             break;
<
<     case CTRL_SCROLLBAR:
< {
< ScrollbarValue* pScrollbarVal = (ScrollbarValue *)(aValue.getOptionalVal());
<
< if( nPart == PART_DRAW_BACKGROUND_VERT ||
< nPart == PART_DRAW_BACKGROUND_HORZ )
< {
< HIThemeTrackDrawInfo aTrackDraw;
< aTrackDraw.version = 0;
< aTrackDraw.kind = kThemeMediumScrollBar;
< aTrackDraw.bounds = rc;
< aTrackDraw.min = pScrollbarVal->mnMin;
< aTrackDraw.max = pScrollbarVal->mnMax - pScrollbarVal->mnVisibleSize;
< aTrackDraw.value = pScrollbarVal->mnCur;
< aTrackDraw.reserved = 0;
< aTrackDraw.attributes = kThemeTrackShowThumb;
< if( nPart == PART_DRAW_BACKGROUND_HORZ )
< aTrackDraw.attributes |= kThemeTrackHorizontal;
< aTrackDraw.enableState = kThemeTrackActive;
<
< ScrollBarTrackInfo aScrollInfo;
< aScrollInfo.viewsize = pScrollbarVal->mnVisibleSize;
< aScrollInfo.pressState = 0;
<
< if ( pScrollbarVal->mnButton1State & CTRL_STATE_ENABLED )
< {
< if ( pScrollbarVal->mnButton1State & CTRL_STATE_PRESSED )
< aScrollInfo.pressState = kThemeTopOutsideArrowPressed;
< }
<
< if ( pScrollbarVal->mnButton2State & CTRL_STATE_ENABLED )
< {
< if ( pScrollbarVal->mnButton2State & CTRL_STATE_PRESSED )
< aScrollInfo.pressState = kThemeBottomOutsideArrowPressed;
< }
<
< if ( pScrollbarVal->mnThumbState & CTRL_STATE_ENABLED )
< {
< if ( pScrollbarVal->mnThumbState & CTRL_STATE_PRESSED )
< aScrollInfo.pressState = kThemeThumbPressed;
< }
<
< aTrackDraw.trackInfo.scrollbar = aScrollInfo;
<
< if ( BeginGraphics() )
< {
< HIThemeDrawTrack( &aTrackDraw, NULL, mrContext, kHIThemeOrientationNormal );
<                     if ( isOffscreenCopy() )
<                         HIThemeDrawTrack( &aTrackDraw, NULL, mrBitmapContext, kHIThemeOrientationNormal );
< EndGraphics();
< return true;
< }
< else
< return false;
< }
< }
747c697,698
< return bOk;
---
>    
>     return bOK;
Index: source/window/salframe.cxx
===================================================================
RCS file: /cvs/gsl/vcl/aqua/source/window/salframe.cxx,v
retrieving revision 1.46.112.88
diff -r1.46.112.88 salframe.cxx
305a306,316

> void AquaSalFrame::SendPaintEvent()
> {
>     SalPaintEvent aPaintEvt;
>     aPaintEvt.mnBoundX = 0;
>     aPaintEvt.mnBoundY = 0;
>     aPaintEvt.mnBoundWidth = maGeometry.nWidth;
>     aPaintEvt.mnBoundHeight = maGeometry.nHeight;
>    
>     CallCallback(SALEVENT_PAINT, &aPaintEvt);
> }
>
336,340c347,349
<         if( ! mbShown )
<         {
<             Rect aRect = { 0, 0, mnWidth, mnHeight };
<             InvalWindowRect( mrWindow, &aRect );
<         }
---
>
>         // trigger filling out backbuffer
>         SendPaintEvent();
1432,1446d1440
<
< Rect contentBounds;
< GetWindowBounds( pSalFrame->mrWindow, kWindowContentRgn, &contentBounds );
<
< SalPaintEvent aPaintEvt;
< aPaintEvt.mnBoundX = 0;
< aPaintEvt.mnBoundY = 0;
< aPaintEvt.mnBoundWidth = pSalFrame->mnWidth;
< aPaintEvt.mnBoundHeight = pSalFrame->mnHeight;
<    
<     AquaLog( "Full paint event: (%ld, %ld, %ld, %ld)\n",
<             aPaintEvt.mnBoundX, aPaintEvt.mnBoundY,
<             aPaintEvt.mnBoundWidth, aPaintEvt.mnBoundHeight);
<
< pSalFrame->CallCallback(SALEVENT_PAINT, &aPaintEvt);
1447a1442,1444
>     if( pSalFrame->mpGraphics )
>         pSalFrame->mpGraphics->UpdateWindow();
>
1460,1474c1457,1459
<     Rect portBounds;
<     GetWindowBounds (pSalFrame->mrWindow,  kWindowContentRgn, &portBounds );
<
< SalPaintEvent aPaintEvt;
< aPaintEvt.mnBoundX = 0;
< aPaintEvt.mnBoundY = 0;
< aPaintEvt.mnBoundWidth = pSalFrame->mnWidth;
< aPaintEvt.mnBoundHeight = pSalFrame->mnHeight;
<
<     AquaLog( "Paint event: (%ld, %ld, %ld, %ld)\n",
<             aPaintEvt.mnBoundX, aPaintEvt.mnBoundY,
<             aPaintEvt.mnBoundWidth, aPaintEvt.mnBoundHeight);
<
< pSalFrame->CallCallback(SALEVENT_PAINT, &aPaintEvt);
<
---
>     if( pSalFrame->mpGraphics )
>         pSalFrame->mpGraphics->UpdateWindow();
>    
1498a1484,1487
>
>     pSalFrame->UpdateFrameGeometry();
>     pSalFrame->SendPaintEvent();
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: changed AquaSalGraphics implementation

Philipp Lohmann
sorry for the bother, that one was of course supposed to go to the
poring mac group.


--
If you give someone a program, you will frustrate them for a day;
if you teach them how to program, you will frustrate them for a lifetime.
      -- Author unknown

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]