make OutputDevice::Flush() also flush Skia

Skia uses an idle timer to flush buffered Skia drawing. This has
the problem that if there's a lot to do, the actual drawing to
the screen may become starved and not update. Fortunately there's
OutputDevice::Flush() that is called e.g. during Impress animations,
so make that also work for Skia, which should make things
somewhat smoother.

Change-Id: Ia8629e63dc7d7a2d7200c033bc2dc2c51f6caf0b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103675
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
diff --git a/vcl/inc/skia/win/gdiimpl.hxx b/vcl/inc/skia/win/gdiimpl.hxx
index 564fcd7..bcdf687 100644
--- a/vcl/inc/skia/win/gdiimpl.hxx
+++ b/vcl/inc/skia/win/gdiimpl.hxx
@@ -68,6 +68,8 @@ public:
    virtual bool DrawTextLayout(const GenericSalLayout& layout) override;
    virtual void ClearDevFontCache() override;

    virtual void Flush() override;

    static void prepareSkia();

protected:
diff --git a/vcl/inc/skia/x11/gdiimpl.hxx b/vcl/inc/skia/x11/gdiimpl.hxx
index d131d54..10c6c5f 100644
--- a/vcl/inc/skia/x11/gdiimpl.hxx
+++ b/vcl/inc/skia/x11/gdiimpl.hxx
@@ -30,6 +30,7 @@ public:
    virtual void Init() override;
    virtual void DeInit() override;
    virtual void freeResources() override;
    virtual void Flush() override;

    static void prepareSkia();

diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h
index eac9dad..6e5e260 100644
--- a/vcl/inc/unx/salgdi.h
+++ b/vcl/inc/unx/salgdi.h
@@ -98,6 +98,8 @@ public:

    const SalX11Screen&             GetScreenNumber() const { return m_nXScreen; }

    void                            Flush();

    // override all pure virtual methods
    virtual void                    GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) override;
    virtual sal_uInt16              GetBitCount() const override;
diff --git a/vcl/inc/unx/x11/x11gdiimpl.h b/vcl/inc/unx/x11/x11gdiimpl.h
index 2e41e87..342da09 100644
--- a/vcl/inc/unx/x11/x11gdiimpl.h
+++ b/vcl/inc/unx/x11/x11gdiimpl.h
@@ -18,6 +18,7 @@ class X11GraphicsImpl
{
public:
    virtual ~X11GraphicsImpl() {};
    virtual void Flush() {};
};

#endif // INCLUDED_VCL_INC_UNX_X11_X11GDIIMPL_HXX
diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index f2560f3..a717286 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -222,6 +222,7 @@ public:
    bool isScreen() const;

    void setHWND(HWND hWnd);
    void Flush();

protected:
    virtual bool        setClipRegion( const vcl::Region& ) override;
diff --git a/vcl/inc/win/wingdiimpl.hxx b/vcl/inc/win/wingdiimpl.hxx
index 679be2c..2b1355c 100644
--- a/vcl/inc/win/wingdiimpl.hxx
+++ b/vcl/inc/win/wingdiimpl.hxx
@@ -37,6 +37,8 @@ public:

    virtual void ClearDevFontCache(){};

    virtual void Flush(){};

    // Implementation for WinSalGraphics::DrawTextLayout().
    // Returns true if handled, if false, then WinSalGraphics will handle it itself.
    virtual bool DrawTextLayout(const GenericSalLayout&) { return false; }
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
index ce67db4..819f024 100644
--- a/vcl/skia/win/gdiimpl.cxx
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -61,6 +61,8 @@ void WinSkiaSalGraphicsImpl::DeInit()

void WinSkiaSalGraphicsImpl::freeResources() {}

void WinSkiaSalGraphicsImpl::Flush() { performFlush(); }

void WinSkiaSalGraphicsImpl::performFlush()
{
    SkiaZone zone;
diff --git a/vcl/skia/x11/gdiimpl.cxx b/vcl/skia/x11/gdiimpl.cxx
index 68571cc..635beb1 100644
--- a/vcl/skia/x11/gdiimpl.cxx
+++ b/vcl/skia/x11/gdiimpl.cxx
@@ -129,6 +129,8 @@ void X11SkiaSalGraphicsImpl::DeInit()

void X11SkiaSalGraphicsImpl::freeResources() {}

void X11SkiaSalGraphicsImpl::Flush() { performFlush(); }

void X11SkiaSalGraphicsImpl::performFlush()
{
    SkiaZone zone;
diff --git a/vcl/unx/generic/gdi/salgdi.cxx b/vcl/unx/generic/gdi/salgdi.cxx
index eeae831..6da291c 100644
--- a/vcl/unx/generic/gdi/salgdi.cxx
+++ b/vcl/unx/generic/gdi/salgdi.cxx
@@ -500,6 +500,12 @@ SystemGraphicsData X11SalGraphics::GetGraphicsData() const
    return aRes;
}

void X11SalGraphics::Flush()
{
    if( X11GraphicsImpl* x11Impl = dynamic_cast< X11GraphicsImpl* >( mxImpl.get()))
        x11Impl->Flush();
}

#if ENABLE_CAIRO_CANVAS

bool X11SalGraphics::SupportsCairo() const
diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx
index 3baf293..03dfe8b 100644
--- a/vcl/unx/generic/window/salframe.cxx
+++ b/vcl/unx/generic/window/salframe.cxx
@@ -2303,6 +2303,8 @@ void X11SalFrame::SetTitle( const OUString& rTitle )

void X11SalFrame::Flush()
{
    if( pGraphics_ )
        pGraphics_->Flush();
    XFlush( GetDisplay()->GetDisplay() );
}

diff --git a/vcl/win/gdi/salgdi.cxx b/vcl/win/gdi/salgdi.cxx
index db4ea11..813ce8c 100644
--- a/vcl/win/gdi/salgdi.cxx
+++ b/vcl/win/gdi/salgdi.cxx
@@ -719,6 +719,12 @@ long WinSalGraphics::GetGraphicsWidth() const
    return mpImpl->GetGraphicsWidth();
}

void WinSalGraphics::Flush()
{
    if(WinSalGraphicsImplBase* impl = dynamic_cast<WinSalGraphicsImplBase*>(GetImpl()))
        impl->Flush();
}

void WinSalGraphics::ResetClipRegion()
{
    mpImpl->ResetClipRegion();
diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx
index 7ee4aa7..13ae25a 100644
--- a/vcl/win/window/salframe.cxx
+++ b/vcl/win/window/salframe.cxx
@@ -2187,6 +2187,10 @@ void WinSalFrame::SetPointerPos( long nX, long nY )

void WinSalFrame::Flush()
{
    if(mpLocalGraphics)
        mpLocalGraphics->Flush();
    if(mpThreadGraphics)
        mpThreadGraphics->Flush();
    GdiFlush();
}