tdf#120342 OSX always lock SolarMutex in drawRect

Since we're now a good OSX citizen and do all our drawing in the
main thread, I believe the workaround from i#93512 and merged in
commit 81ec69125209 ("CWS-TOOLING: integrate CWS i93512_DEV300")
isn't needed anymore. Therefore we can just claim the SolarMutex
and draw. And I couldn't reproduce the deadlock of i#93512 with
this patch applied.

But I already was wrong a few times and many drawing semantics
have changed for OSX 10.14, so I might be wrong again ;-)

Change-Id: Ibbf1c1f394038ee5051bc16d2f3c677f4231b2ba
Reviewed-on: https://gerrit.libreoffice.org/65009
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
diff --git a/vcl/osx/salframeview.mm b/vcl/osx/salframeview.mm
index 241cb38..3d89e17 100644
--- a/vcl/osx/salframeview.mm
+++ b/vcl/osx/salframeview.mm
@@ -506,57 +506,31 @@
    return NO;
}

// helper class similar to a osl::Guard< comphelper::SolarMutex > for the
// SalYieldMutex; the difference is that it only does tryToAcquire instead of
// acquire so dreaded deadlocks like #i93512# are prevented
class TryGuard
{
public:
            TryGuard()  { mbGuarded = ImplSalYieldMutexTryToAcquire(); }
            ~TryGuard() { if( mbGuarded ) ImplSalYieldMutexRelease(); }
    bool    IsGuarded() { return mbGuarded; }
private:
    bool    mbGuarded;
};

-(void)drawRect: (NSRect)aRect
{
    if( GetSalData()->mpInstance )
    {
        const bool bIsLiveResize = [self inLiveResize];
        const bool bWasLiveResize = GetSalData()->mpInstance->mbIsLiveResize;
        if ( bWasLiveResize != bIsLiveResize )
        {
            GetSalData()->mpInstance->mbIsLiveResize = bIsLiveResize;
            Scheduler::ProcessTaskScheduling();
        }
    }

    // HOTFIX: #i93512# prevent deadlocks if any other thread already has the SalYieldMutex
    TryGuard aTryGuard;
    if( !aTryGuard.IsGuarded() )
    {
        // NOTE: the mpFrame access below is not guarded yet!
        // TODO: mpFrame et al need to be guarded by an independent mutex
        AquaSalGraphics* pGraphics = (mpFrame && AquaSalFrame::isAlive(mpFrame)) ? mpFrame->mpGraphics : nullptr;
        if( pGraphics )
        {
            // we did not get the mutex so we cannot draw now => request to redraw later
            // convert the NSRect to a CGRect for Refreshrect()
            const CGRect aCGRect = {{aRect.origin.x,aRect.origin.y},{aRect.size.width,aRect.size.height}};
            pGraphics->RefreshRect( aCGRect );
        }
    AquaSalInstance *pInstance = GetSalData()->mpInstance;
    assert(pInstance);
    if (!pInstance)
        return;

    SolarMutexGuard aGuard;
    if (!mpFrame || !AquaSalFrame::isAlive(mpFrame))
        return;

    const bool bIsLiveResize = [self inLiveResize];
    const bool bWasLiveResize = pInstance->mbIsLiveResize;
    if (bWasLiveResize != bIsLiveResize)
    {
        pInstance->mbIsLiveResize = bIsLiveResize;
        Scheduler::ProcessTaskScheduling();
    }

    if( mpFrame && AquaSalFrame::isAlive( mpFrame ) )
    AquaSalGraphics* pGraphics = mpFrame->mpGraphics;
    if (pGraphics)
    {
        if( mpFrame->mpGraphics )
        {
            mpFrame->mpGraphics->UpdateWindow( aRect );
            if( mpFrame->getClipPath() )
                [mpFrame->getNSWindow() invalidateShadow];
        }
        pGraphics->UpdateWindow(aRect);
        if (mpFrame->getClipPath())
            [mpFrame->getNSWindow() invalidateShadow];
    }
}