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

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Tue Oct 29 12:08:07 UTC 2019


 vcl/inc/skia/gdiimpl.hxx |    3 ++-
 vcl/skia/README          |   24 ++++++++++++++++++++++++
 vcl/skia/gdiimpl.cxx     |   29 ++++++++++++++++++++++-------
 vcl/skia/win/gdiimpl.cxx |    1 +
 vcl/skia/x11/gdiimpl.cxx |    1 +
 5 files changed, 50 insertions(+), 8 deletions(-)

New commits:
commit d4cc59e9c0ae5de4e60c0ecdee7d36286980fc84
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Tue Oct 29 13:06:40 2019 +0100
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Tue Oct 29 13:06:40 2019 +0100

    add Skia VCL README with some basic information
    
    Change-Id: Ifff230ce76b4b33cd91322e564be1685afea763f

diff --git a/vcl/skia/README b/vcl/skia/README
new file mode 100644
index 000000000000..6c3da7254b8b
--- /dev/null
+++ b/vcl/skia/README
@@ -0,0 +1,24 @@
+This is code for using the Skia library as a drawing library in VCL backends.
+See external/skia for info on the library itself.
+
+Environment variables:
+======================
+
+SAL_DISABLESKIA=1 - force disabled Skia
+SAL_ENABLESKIA=1 - enable Skia, unless blacklisted (and if the VCL backend supports Skia)
+SAL_FORCESKIA=1 - force using Skia, even if blacklisted
+SAL_SKIA=raster|vulkan - select Skia's drawing method, by default Vulkan is used
+
+There also also GUI options for controlling whether Skia is enabled.
+
+Note that many backends do not use Skia. E.g. on Linux it is necessary to also use
+SAL_USE_VCLPLUGIN=gen .
+
+Skia drawing methods:
+=====================
+
+Skia supports several methods to draw:
+- Raster - CPU-based drawing (here primarily used for debugging)
+- Vulkan - Vulkan-based GPU drawing, this is the default
+
+There are more (OpenGL, Metal on Mac, etc.), but (as of now) they are not supported by VCL.
commit 5dec2fbd0e18a04521ddd788d087112a4bf03362
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Tue Oct 29 13:06:03 2019 +0100
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Tue Oct 29 13:06:03 2019 +0100

    default to Skia using Vulkan, use SAL_SKIA=raster to use raster
    
    Change-Id: I5969b0672cdbb54e60b861bac102191dad6a4caf

diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index bd9519c7243b..8712893f9554 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -157,11 +157,11 @@ SkiaSalGraphicsImpl::RenderMethod SkiaSalGraphicsImpl::renderMethodToUse()
 {
     static RenderMethod method = [] {
         if (const char* env = getenv("SAL_SKIA"))
-        { // TODO switch the default later
-            if (strcmp(env, "vk") == 0 || strcmp(env, "vulkan") == 0)
-                return RenderVulkan;
+        {
+            if (strcmp(env, "raster") == 0)
+                return RenderRaster;
         }
-        return RenderRaster;
+        return RenderVulkan;
     }();
 
     return method;
commit 21cd87ab20621a13cb27212c2d59a3c77709d7c9
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Tue Oct 29 13:05:06 2019 +0100
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Tue Oct 29 13:05:06 2019 +0100

    more safe handling of destroying Skia surfaces/contexts
    
    As the comment in SkiaSalGraphicsImpl::destroySurface() says,
    they may both refer to each other's data when being destroyed,
    so try to handle that.
    
    Change-Id: I44353ed9d1888f8e8d15d93cd2c66414adfd372b

diff --git a/vcl/inc/skia/gdiimpl.hxx b/vcl/inc/skia/gdiimpl.hxx
index a5036fbb3075..8190115a0714 100644
--- a/vcl/inc/skia/gdiimpl.hxx
+++ b/vcl/inc/skia/gdiimpl.hxx
@@ -204,7 +204,8 @@ protected:
     // Call to ensure that mSurface is valid. If mSurface is going to be modified,
     // use preDraw() instead of this.
     void checkSurface();
-    void resetSurface();
+    void recreateSurface();
+    void destroySurface();
 
     void privateDrawAlphaRect(long nX, long nY, long nWidth, long nHeight, double nTransparency);
 
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index d6a956e4e76f..bd9519c7243b 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -180,8 +180,9 @@ SkiaSalGraphicsImpl::~SkiaSalGraphicsImpl() {}
 
 void SkiaSalGraphicsImpl::Init() {}
 
-void SkiaSalGraphicsImpl::resetSurface()
+void SkiaSalGraphicsImpl::recreateSurface()
 {
+    destroySurface();
     createSurface();
     mSurface->getCanvas()->save(); // see SetClipRegion()
     mClipRegion = vcl::Region(tools::Rectangle(0, 0, GetWidth(), GetHeight()));
@@ -198,7 +199,21 @@ void SkiaSalGraphicsImpl::createSurface()
     mSurface = SkSurface::MakeRasterN32Premul(GetWidth(), GetHeight());
 }
 
-void SkiaSalGraphicsImpl::DeInit() { mSurface.reset(); }
+void SkiaSalGraphicsImpl::destroySurface()
+{
+    // If we use e.g. Vulkan, we must destroy the surface before the context,
+    // otherwise destroying the surface will reference the context. This is
+    // handled by calling destroySurface() before destroying the context.
+    // However we also need to flush the surface before destroying it,
+    // otherwise when destroing the context later there still could be queued
+    // commands referring to the surface data. This is probably a Skia bug,
+    // but work around it here.
+    if (mSurface)
+        mSurface->flush();
+    mSurface.reset();
+}
+
+void SkiaSalGraphicsImpl::DeInit() { destroySurface(); }
 
 void SkiaSalGraphicsImpl::preDraw() { checkSurface(); }
 
@@ -219,7 +234,7 @@ void SkiaSalGraphicsImpl::postDraw()
 void SkiaSalGraphicsImpl::checkSurface()
 {
     if (!mSurface || GetWidth() != mSurface->width() || GetHeight() != mSurface->height())
-        resetSurface();
+        recreateSurface();
 }
 
 static SkIRect toSkIRect(const tools::Rectangle& rectangle)
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
index e583cea86f3c..c1a6d45353cb 100644
--- a/vcl/skia/win/gdiimpl.cxx
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -50,6 +50,7 @@ void WinSkiaSalGraphicsImpl::createSurface()
     // valid here, but better check.
     assert(GetWidth() != 0 && GetHeight() != 0);
     sk_app::DisplayParams displayParams;
+    destroySurface();
     switch (renderMethodToUse())
     {
         case RenderRaster:
diff --git a/vcl/skia/x11/gdiimpl.cxx b/vcl/skia/x11/gdiimpl.cxx
index 72f3e65b5859..29119f092ac9 100644
--- a/vcl/skia/x11/gdiimpl.cxx
+++ b/vcl/skia/x11/gdiimpl.cxx
@@ -55,6 +55,7 @@ void X11SkiaSalGraphicsImpl::createSurface()
     winInfo.fVisualInfo = const_cast<SalVisual*>(&mX11Parent.GetVisual());
     winInfo.fWidth = GetWidth();
     winInfo.fHeight = GetHeight();
+    destroySurface();
     switch (renderMethodToUse())
     {
         case RenderRaster:


More information about the Libreoffice-commits mailing list