[Libreoffice-commits] core.git: Branch 'feature/skia' - 2 commits - external/skia vcl/inc vcl/skia

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Mon Oct 21 14:17:00 UTC 2019


 external/skia/UnpackedTarball_skia.mk   |    2 
 external/skia/fix-shader-locale.patch.1 |   57 +++++++++++++++++++++++++
 vcl/inc/skia/gdiimpl.hxx                |   17 ++++---
 vcl/skia/gdiimpl.cxx                    |   72 +++++++++++++++++++++-----------
 4 files changed, 116 insertions(+), 32 deletions(-)

New commits:
commit c48c14947f089e9fdbc1c1eabe25ae2b33f25f50
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Mon Oct 21 16:12:19 2019 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Mon Oct 21 16:16:00 2019 +0200

    resize surface in SkiaSalGraphicsImpl if needed
    
    This is similar to what the OpenGL backend does. Apparently the VCL
    code can just silently resize the graphics without telling.
    
    Change-Id: Ie7c2a7798e76ad598e9cdd1435d68ed03793c408

diff --git a/vcl/inc/skia/gdiimpl.hxx b/vcl/inc/skia/gdiimpl.hxx
index c7c59ac9b2d6..463e927c3572 100644
--- a/vcl/inc/skia/gdiimpl.hxx
+++ b/vcl/inc/skia/gdiimpl.hxx
@@ -185,19 +185,19 @@ public:
 
     void drawBitmap(const SalTwoRect& rPosAry, const SkBitmap& bitmap);
 
-    // To be called after any drawing.
-    void scheduleFlush();
-
-    // Internal, called by SkiaFlushIdle.
-    virtual void performFlush() = 0;
-
 #ifdef DBG_UTIL
     void dump(const char* file) const;
     static void dump(const SkBitmap& bitmap, const char* file);
 #endif
 
 protected:
+    // To be called before any drawing.
+    void preDraw();
+    // To be called after any drawing.
+    void postDraw();
+
     virtual void createSurface();
+    void resetSurface();
 
     void setProvider(SalGeometryProvider* provider) { mProvider = provider; }
 
@@ -205,7 +205,10 @@ protected:
 
     void invert(basegfx::B2DPolygon const& rPoly, SalInvert eFlags);
 
-protected:
+    // Called by SkiaFlushIdle.
+    virtual void performFlush() = 0;
+    friend class SkiaFlushIdle;
+
     // get the width of the device
     int GetWidth() const { return mProvider ? mProvider->GetWidth() : 1; }
     // get the height of the device
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index deb35255ddfa..ccf4ea7cef34 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -114,13 +114,16 @@ SkiaSalGraphicsImpl::SkiaSalGraphicsImpl(SalGraphics& rParent, SalGeometryProvid
 
 SkiaSalGraphicsImpl::~SkiaSalGraphicsImpl() {}
 
-void SkiaSalGraphicsImpl::Init()
+void SkiaSalGraphicsImpl::Init() { resetSurface(); }
+
+void SkiaSalGraphicsImpl::resetSurface()
 {
     createSurface();
     mSurface->getCanvas()->save(); // see SetClipRegion()
     mClipRegion = vcl::Region(tools::Rectangle(0, 0, GetWidth(), GetHeight()));
 
     // We don't want to be swapping before we've painted.
+    mFlush->Stop();
     mFlush->SetPriority(TaskPriority::POST_PAINT);
 }
 
@@ -132,6 +135,24 @@ void SkiaSalGraphicsImpl::createSurface()
 
 void SkiaSalGraphicsImpl::DeInit() { mSurface.reset(); }
 
+void SkiaSalGraphicsImpl::preDraw()
+{
+    // VCL can sometimes resize us without telling us, update the surface if needed.
+    if (GetWidth() != mSurface->width() || GetHeight() != mSurface->height())
+        resetSurface();
+}
+
+void SkiaSalGraphicsImpl::postDraw()
+{
+    if (!isOffscreen())
+    {
+        if (!Application::IsInExecute())
+            performFlush(); // otherwise nothing would trigger idle rendering
+        else if (!mFlush->IsActive())
+            mFlush->Start();
+    }
+}
+
 static SkIRect toSkIRect(const tools::Rectangle& rectangle)
 {
     return SkIRect::MakeXYWH(rectangle.Left(), rectangle.Top(), rectangle.GetWidth(),
@@ -207,37 +228,41 @@ void SkiaSalGraphicsImpl::drawPixel(long nX, long nY)
 {
     if (mLineColor == SALCOLOR_NONE)
         return;
+    preDraw();
     SkCanvas* canvas = mSurface->getCanvas();
     canvas->drawPoint(nX, nY, SkPaint());
-    scheduleFlush();
+    postDraw();
 }
 
 void SkiaSalGraphicsImpl::drawPixel(long nX, long nY, Color nColor)
 {
     if (nColor == SALCOLOR_NONE)
         return;
+    preDraw();
     SkCanvas* canvas = mSurface->getCanvas();
     SkPaint paint;
     paint.setColor(toSkColor(nColor));
     // Apparently drawPixel() is actually expected to set the pixel and not draw it.
     paint.setBlendMode(SkBlendMode::kSrc); // set as is, including alpha
     canvas->drawPoint(nX, nY, paint);
-    scheduleFlush();
+    postDraw();
 }
 
 void SkiaSalGraphicsImpl::drawLine(long nX1, long nY1, long nX2, long nY2)
 {
     if (mLineColor == SALCOLOR_NONE)
         return;
+    preDraw();
     SkCanvas* canvas = mSurface->getCanvas();
     SkPaint paint;
     paint.setColor(toSkColor(mLineColor));
     canvas->drawLine(nX1, nY1, nX2, nY2, paint);
-    scheduleFlush();
+    postDraw();
 }
 
 void SkiaSalGraphicsImpl::drawRect(long nX, long nY, long nWidth, long nHeight)
 {
+    preDraw();
     SkCanvas* canvas = mSurface->getCanvas();
     SkPaint paint;
     if (mFillColor != SALCOLOR_NONE)
@@ -252,13 +277,14 @@ void SkiaSalGraphicsImpl::drawRect(long nX, long nY, long nWidth, long nHeight)
         paint.setStyle(SkPaint::kStroke_Style);
         canvas->drawIRect(SkIRect::MakeXYWH(nX, nY, nWidth - 1, nHeight - 1), paint);
     }
-    scheduleFlush();
+    postDraw();
 }
 
 void SkiaSalGraphicsImpl::drawPolyLine(sal_uInt32 nPoints, const SalPoint* pPtAry)
 {
     if (mLineColor == SALCOLOR_NONE)
         return;
+    preDraw();
     std::vector<SkPoint> pointVector;
     pointVector.reserve(nPoints);
     for (sal_uInt32 i = 0; i < nPoints; ++i)
@@ -267,13 +293,14 @@ void SkiaSalGraphicsImpl::drawPolyLine(sal_uInt32 nPoints, const SalPoint* pPtAr
     paint.setColor(toSkColor(mLineColor));
     mSurface->getCanvas()->drawPoints(SkCanvas::kLines_PointMode, nPoints, pointVector.data(),
                                       paint);
-    scheduleFlush();
+    postDraw();
 }
 
 void SkiaSalGraphicsImpl::drawPolygon(sal_uInt32 nPoints, const SalPoint* pPtAry)
 {
     if (mLineColor == SALCOLOR_NONE && mFillColor == SALCOLOR_NONE)
         return;
+    preDraw();
     std::vector<SkPoint> pointVector;
     pointVector.reserve(nPoints);
     for (sal_uInt32 i = 0; i < nPoints; ++i)
@@ -293,7 +320,7 @@ void SkiaSalGraphicsImpl::drawPolygon(sal_uInt32 nPoints, const SalPoint* pPtAry
         paint.setStyle(SkPaint::kStroke_Style);
         mSurface->getCanvas()->drawPath(path, paint);
     }
-    scheduleFlush();
+    postDraw();
 }
 
 void SkiaSalGraphicsImpl::drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints,
@@ -301,6 +328,7 @@ void SkiaSalGraphicsImpl::drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pP
 {
     if (mLineColor == SALCOLOR_NONE && mFillColor == SALCOLOR_NONE)
         return;
+    preDraw();
     std::vector<SkPoint> pointVector;
     SkPath path;
     for (sal_uInt32 poly = 0; poly < nPoly; ++poly)
@@ -328,7 +356,7 @@ void SkiaSalGraphicsImpl::drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pP
         paint.setStyle(SkPaint::kStroke_Style);
         mSurface->getCanvas()->drawPath(path, paint);
     }
-    scheduleFlush();
+    postDraw();
 }
 
 bool SkiaSalGraphicsImpl::drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice,
@@ -389,15 +417,17 @@ void SkiaSalGraphicsImpl::copyArea(long nDestX, long nDestY, long nSrcX, long nS
 {
     if (nDestX == nSrcX && nDestY == nSrcY)
         return;
+    preDraw();
     sk_sp<SkImage> image
         = mSurface->makeImageSnapshot(SkIRect::MakeXYWH(nSrcX, nSrcY, nSrcWidth, nSrcHeight));
     // TODO makeNonTextureImage() ?
     mSurface->getCanvas()->drawImage(image, nDestX, nDestY);
-    scheduleFlush();
+    postDraw();
 }
 
 void SkiaSalGraphicsImpl::copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics)
 {
+    preDraw();
     SkiaSalGraphicsImpl* src;
     if (pSrcGraphics)
     {
@@ -414,7 +444,7 @@ void SkiaSalGraphicsImpl::copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcG
                                                           rPosAry.mnDestWidth,
                                                           rPosAry.mnDestHeight),
                                          nullptr);
-    scheduleFlush();
+    postDraw();
 }
 
 bool SkiaSalGraphicsImpl::blendBitmap(const SalTwoRect&, const SalBitmap& rBitmap)
@@ -438,6 +468,7 @@ void SkiaSalGraphicsImpl::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap&
     if (rPosAry.mnSrcWidth <= 0 || rPosAry.mnSrcHeight <= 0 || rPosAry.mnDestWidth <= 0
         || rPosAry.mnDestHeight <= 0)
         return;
+    preDraw();
     assert(dynamic_cast<const SkiaSalBitmap*>(&rSalBitmap));
     mSurface->getCanvas()->drawBitmapRect(
         static_cast<const SkiaSalBitmap&>(rSalBitmap).GetSkBitmap(),
@@ -445,7 +476,7 @@ void SkiaSalGraphicsImpl::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap&
         SkRect::MakeXYWH(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth,
                          rPosAry.mnDestHeight),
         nullptr);
-    scheduleFlush();
+    postDraw();
 }
 
 void SkiaSalGraphicsImpl::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap,
@@ -467,6 +498,7 @@ void SkiaSalGraphicsImpl::drawMask(const SalTwoRect& rPosAry, const SalBitmap& r
 void SkiaSalGraphicsImpl::drawMask(const SalTwoRect& rPosAry, const SkBitmap& rBitmap,
                                    Color nMaskColor)
 {
+    preDraw();
     SkBitmap tmpBitmap;
     if (!tmpBitmap.tryAllocN32Pixels(rBitmap.width(), rBitmap.height()))
         abort();
@@ -484,7 +516,7 @@ void SkiaSalGraphicsImpl::drawMask(const SalTwoRect& rPosAry, const SkBitmap& rB
         SkRect::MakeXYWH(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth,
                          rPosAry.mnDestHeight),
         nullptr);
-    scheduleFlush();
+    postDraw();
 }
 
 std::shared_ptr<SalBitmap> SkiaSalGraphicsImpl::getBitmap(long nX, long nY, long nWidth,
@@ -509,6 +541,7 @@ Color SkiaSalGraphicsImpl::getPixel(long nX, long nY)
 
 void SkiaSalGraphicsImpl::invert(basegfx::B2DPolygon const& rPoly, SalInvert eFlags)
 {
+    preDraw();
     // TrackFrame just inverts a dashed path around the polygon
     if (eFlags == SalInvert::TrackFrame)
     {
@@ -568,7 +601,7 @@ void SkiaSalGraphicsImpl::invert(basegfx::B2DPolygon const& rPoly, SalInvert eFl
 
         mSurface->getCanvas()->drawPath(aPath, aPaint);
     }
-    scheduleFlush();
+    postDraw();
 }
 
 void SkiaSalGraphicsImpl::invert(long nX, long nY, long nWidth, long nHeight, SalInvert eFlags)
@@ -625,13 +658,14 @@ bool SkiaSalGraphicsImpl::drawAlphaBitmap(const SalTwoRect& rPosAry, const SalBi
 
 void SkiaSalGraphicsImpl::drawBitmap(const SalTwoRect& rPosAry, const SkBitmap& bitmap)
 {
+    preDraw();
     mSurface->getCanvas()->drawBitmapRect(
         bitmap,
         SkRect::MakeXYWH(rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight),
         SkRect::MakeXYWH(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth,
                          rPosAry.mnDestHeight),
         nullptr);
-    scheduleFlush();
+    postDraw();
 }
 
 bool SkiaSalGraphicsImpl::drawTransformedBitmap(const basegfx::B2DPoint& rNull,
@@ -667,16 +701,6 @@ bool SkiaSalGraphicsImpl::drawGradient(const tools::PolyPolygon& rPolygon,
     return false;
 }
 
-void SkiaSalGraphicsImpl::scheduleFlush()
-{
-    if (isOffscreen())
-        return;
-    if (!Application::IsInExecute())
-        performFlush(); // otherwise nothing would trigger idle rendering
-    else if (!mFlush->IsActive())
-        mFlush->Start();
-}
-
 #ifdef DBG_UTIL
 void SkiaSalGraphicsImpl::dump(const char* file) const
 {
commit 92cf4eb8ac19a7854f9a5afdd6cf26575d85d650
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Mon Oct 21 15:35:29 2019 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Mon Oct 21 16:15:55 2019 +0200

    fix Skia/vulkan with some locales
    
    Change-Id: Ie2dcd526efba5631a6956023d864be828c6eb634

diff --git a/external/skia/UnpackedTarball_skia.mk b/external/skia/UnpackedTarball_skia.mk
index 25543084a8ca..e9905f5abfa7 100644
--- a/external/skia/UnpackedTarball_skia.mk
+++ b/external/skia/UnpackedTarball_skia.mk
@@ -12,7 +12,7 @@ $(eval $(call gb_UnpackedTarball_UnpackedTarball,skia))
 $(eval $(call gb_UnpackedTarball_set_tarball,skia,$(SKIA_TARBALL)))
 
 # TODO
-skia_patches := lerp.patch fix-pch.patch fix-ddi.patch make-api-visible.patch.1
+skia_patches := lerp.patch fix-pch.patch fix-ddi.patch make-api-visible.patch.1 fix-shader-locale.patch.1
 
 $(eval $(call gb_UnpackedTarball_set_patchlevel,skia,1))
 
diff --git a/external/skia/fix-shader-locale.patch.1 b/external/skia/fix-shader-locale.patch.1
new file mode 100644
index 000000000000..71a5b0e00c82
--- /dev/null
+++ b/external/skia/fix-shader-locale.patch.1
@@ -0,0 +1,57 @@
+https://bugs.chromium.org/p/skia/issues/detail?id=9550
+
+diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
+index d42ee6f07e..1e3ebddf95 100644
+--- a/src/core/SkString.cpp
++++ b/src/core/SkString.cpp
+@@ -502,11 +502,15 @@ void SkString::appendf(const char format[], ...) {
+ }
+ 
+ void SkString::appendVAList(const char format[], va_list args) {
++    char* oldlocale = strdup( setlocale( LC_NUMERIC, nullptr ));
++    setlocale( LC_NUMERIC, "C" );
+     char buffer[kBufferSize];
+     int length = vsnprintf(buffer, kBufferSize, format, args);
+     SkASSERT(length >= 0 && length < SkToInt(kBufferSize));
+ 
+     this->append(buffer, length);
++    setlocale( LC_NUMERIC, oldlocale );
++    free( oldlocale );
+ }
+ 
+ void SkString::prependf(const char format[], ...) {
+@@ -519,11 +523,15 @@ void SkString::prependf(const char format[], ...) {
+ }
+ 
+ void SkString::prependVAList(const char format[], va_list args) {
++    char* oldlocale = strdup( setlocale( LC_NUMERIC, nullptr ));
++    setlocale( LC_NUMERIC, "C" );
+     char buffer[kBufferSize];
+     int length = vsnprintf(buffer, kBufferSize, format, args);
+     SkASSERT(length >= 0 && length < SkToInt(kBufferSize));
+ 
+     this->prepend(buffer, length);
++    setlocale( LC_NUMERIC, oldlocale );
++    free( oldlocale );
+ }
+ 
+ 
+diff --git a/src/sksl/SkSLOutputStream.cpp b/src/sksl/SkSLOutputStream.cpp
+index f72637d4cb..6e31e8f302 100644
+--- a/src/sksl/SkSLOutputStream.cpp
++++ b/src/sksl/SkSLOutputStream.cpp
+@@ -21,10 +21,14 @@ void OutputStream::printf(const char format[], ...) {
+ }
+ 
+ void OutputStream::appendVAList(const char format[], va_list args) {
++    char* oldlocale = strdup( setlocale( LC_NUMERIC, nullptr ));
++    setlocale( LC_NUMERIC, "C" );
+     char buffer[kBufferSize];
+     int length = vsnprintf(buffer, kBufferSize, format, args);
+     SkASSERT(length >= 0 && length < (int) kBufferSize);
+     this->write(buffer, length);
++    setlocale( LC_NUMERIC, oldlocale );
++    free( oldlocale );
+ }
+ 
+ }


More information about the Libreoffice-commits mailing list