diff options
-rw-r--r-- | external/skia/share-grcontext.patch.1 | 2 | ||||
-rw-r--r-- | include/vcl/skia/SkiaHelper.hxx | 13 | ||||
-rw-r--r-- | vcl/inc/skia/gdiimpl.hxx | 8 | ||||
-rw-r--r-- | vcl/skia/SkiaHelper.cxx | 33 | ||||
-rw-r--r-- | vcl/skia/gdiimpl.cxx | 22 | ||||
-rw-r--r-- | vcl/skia/win/gdiimpl.cxx | 25 | ||||
-rw-r--r-- | vcl/skia/x11/gdiimpl.cxx | 22 |
7 files changed, 83 insertions, 42 deletions
diff --git a/external/skia/share-grcontext.patch.1 b/external/skia/share-grcontext.patch.1 index 0492bd948240..357c3a885880 100644 --- a/external/skia/share-grcontext.patch.1 +++ b/external/skia/share-grcontext.patch.1 @@ -426,7 +426,7 @@ index 2db9e79ae6..7950dc159b 100644 void swapBuffers() override; - bool isValid() override { return fDevice != VK_NULL_HANDLE; } -+ bool isValid() override { return fShared->fDevice != VK_NULL_HANDLE; } ++ bool isValid() override { return fShared && fShared->fDevice != VK_NULL_HANDLE; } void resize(int w, int h) override { this->createSwapchain(w, h, fDisplayParams); diff --git a/include/vcl/skia/SkiaHelper.hxx b/include/vcl/skia/SkiaHelper.hxx index 77e9fab5797a..d27cffd650f3 100644 --- a/include/vcl/skia/SkiaHelper.hxx +++ b/include/vcl/skia/SkiaHelper.hxx @@ -12,6 +12,8 @@ #include <vcl/dllapi.h> +#include <config_features.h> + // All member functions static and VCL_DLLPUBLIC. Basically a glorified namespace. struct VCL_DLLPUBLIC SkiaHelper { @@ -19,6 +21,17 @@ struct VCL_DLLPUBLIC SkiaHelper public: static bool isVCLSkiaEnabled(); + +#if HAVE_FEATURE_SKIA + // Which Skia backend to use. + enum RenderMethod + { + RenderRaster, + RenderVulkan + }; + static RenderMethod renderMethodToUse(); + static void disableRenderMethod(RenderMethod method); +#endif }; #endif diff --git a/vcl/inc/skia/gdiimpl.hxx b/vcl/inc/skia/gdiimpl.hxx index 195b5d877eed..7c41e98a91b5 100644 --- a/vcl/inc/skia/gdiimpl.hxx +++ b/vcl/inc/skia/gdiimpl.hxx @@ -241,14 +241,6 @@ protected: SkScalar toSkX(long x) const { return mIsGPU ? x + 0.5 : x; } SkScalar toSkY(long y) const { return mIsGPU ? y + 0.5 : y; } - // Which Skia backend to use. - enum RenderMethod - { - RenderRaster, - RenderVulkan - }; - static RenderMethod renderMethodToUse(); - #ifdef DBG_UTIL void prefillSurface(); #endif diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx index bc643bd546b1..810e8f9b0b11 100644 --- a/vcl/skia/SkiaHelper.cxx +++ b/vcl/skia/SkiaHelper.cxx @@ -13,8 +13,6 @@ #include <desktop/crashreport.hxx> #include <officecfg/Office/Common.hxx> -#include <config_features.h> - #if !HAVE_FEATURE_SKIA bool SkiaHelper::isVCLSkiaEnabled() { return false; } @@ -86,6 +84,37 @@ bool SkiaHelper::isVCLSkiaEnabled() return bRet; } +static SkiaHelper::RenderMethod methodToUse = SkiaHelper::RenderRaster; + +static bool initRenderMethodToUse() +{ + if (const char* env = getenv("SAL_SKIA")) + { + if (strcmp(env, "raster") == 0) + { + methodToUse = SkiaHelper::RenderRaster; + return true; + } + } + methodToUse = SkiaHelper::RenderVulkan; + return true; +} + +SkiaHelper::RenderMethod SkiaHelper::renderMethodToUse() +{ + static bool methodToUseInited = initRenderMethodToUse(); + (void)methodToUseInited; // Used just to ensure thread-safe one-time init. + return methodToUse; +} + +void SkiaHelper::disableRenderMethod(RenderMethod method) +{ + if (renderMethodToUse() != method) + return; + // Choose a fallback, right now always raster. + methodToUse = RenderRaster; +} + #endif // HAVE_FEATURE_SKIA /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx index ac47d254cc03..cb2beb2667a0 100644 --- a/vcl/skia/gdiimpl.cxx +++ b/vcl/skia/gdiimpl.cxx @@ -24,6 +24,7 @@ #include <vcl/idle.hxx> #include <vcl/svapp.hxx> #include <vcl/lazydelete.hxx> +#include <vcl/skia/SkiaHelper.hxx> #include <SkCanvas.h> #include <SkPath.h> @@ -168,20 +169,6 @@ public: } }; -SkiaSalGraphicsImpl::RenderMethod SkiaSalGraphicsImpl::renderMethodToUse() -{ - static RenderMethod method = [] { - if (const char* env = getenv("SAL_SKIA")) - { - if (strcmp(env, "raster") == 0) - return RenderRaster; - } - return RenderVulkan; - }(); - - return method; -} - SkiaSalGraphicsImpl::SkiaSalGraphicsImpl(SalGraphics& rParent, SalGeometryProvider* pProvider) : mParent(rParent) , mProvider(pProvider) @@ -226,9 +213,9 @@ void SkiaSalGraphicsImpl::createOffscreenSurface() { assert(isOffscreen()); destroySurface(); - switch (renderMethodToUse()) + switch (SkiaHelper::renderMethodToUse()) { - case RenderVulkan: + case SkiaHelper::RenderVulkan: { mOffscreenGrContext = sk_app::VulkanWindowContext::getSharedGrContext(); GrContext* grContext = mOffscreenGrContext.getGrContext(); @@ -260,7 +247,8 @@ void SkiaSalGraphicsImpl::createOffscreenSurface() #endif return; } - SAL_WARN("vcl.skia", "cannot create Vulkan GPU offscreen surface"); + SAL_WARN("vcl.skia", "cannot create Vulkan offscreen GPU surface, disabling Vulkan"); + SkiaHelper::disableRenderMethod(SkiaHelper::RenderVulkan); break; } default: diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx index 8f30c3486dac..cba8bed29355 100644 --- a/vcl/skia/win/gdiimpl.cxx +++ b/vcl/skia/win/gdiimpl.cxx @@ -9,12 +9,13 @@ #include <skia/win/gdiimpl.hxx> -#include <tools/sk_app/win/WindowContextFactory_win.h> -#include <tools/sk_app/WindowContext.h> #include <win/saldata.hxx> +#include <vcl/skia/SkiaHelper.hxx> #include <SkColorFilter.h> #include <SkPixelRef.h> +#include <tools/sk_app/win/WindowContextFactory_win.h> +#include <tools/sk_app/WindowContext.h> WinSkiaSalGraphicsImpl::WinSkiaSalGraphicsImpl(WinSalGraphics& rGraphics, SalGeometryProvider* mpProvider) @@ -52,22 +53,30 @@ void WinSkiaSalGraphicsImpl::createSurface() // valid here, but better check. assert(GetWidth() != 0 && GetHeight() != 0); sk_app::DisplayParams displayParams; - switch (renderMethodToUse()) + switch (SkiaHelper::renderMethodToUse()) { - case RenderRaster: + case SkiaHelper::RenderRaster: mWindowContext = sk_app::window_context_factory::MakeRasterForWin(mWinParent.gethWnd(), displayParams); + assert(SkToBool(mWindowContext)); + mSurface = mWindowContext->getBackbufferSurface(); + assert(mSurface.get()); mIsGPU = false; break; - case RenderVulkan: + case SkiaHelper::RenderVulkan: mWindowContext = sk_app::window_context_factory::MakeVulkanForWin(mWinParent.gethWnd(), displayParams); + if (mWindowContext) + mSurface = mWindowContext->getBackbufferSurface(); + if (!mSurface) + { + SAL_WARN("vcl.skia", "cannot create Vulkan GPU surface, disabling Vulkan"); + SkiaHelper::disableRenderMethod(SkiaHelper::RenderVulkan); + return createSurface(); // try again + } mIsGPU = true; break; } - assert(SkToBool(mWindowContext)); // TODO - mSurface = mWindowContext->getBackbufferSurface(); - assert(mSurface.get()); #ifdef DBG_UTIL prefillSurface(); #endif diff --git a/vcl/skia/x11/gdiimpl.cxx b/vcl/skia/x11/gdiimpl.cxx index ef381c5e56d3..7eb02a51169e 100644 --- a/vcl/skia/x11/gdiimpl.cxx +++ b/vcl/skia/x11/gdiimpl.cxx @@ -21,6 +21,8 @@ #include <tools/sk_app/unix/WindowContextFactory_unix.h> #include <tools/sk_app/WindowContext.h> +#include <vcl/skia/SkiaHelper.hxx> + X11SkiaSalGraphicsImpl::X11SkiaSalGraphicsImpl(X11SalGraphics& rParent) : SkiaSalGraphicsImpl(rParent, rParent.GetGeometryProvider()) , mX11Parent(rParent) @@ -63,22 +65,30 @@ void X11SkiaSalGraphicsImpl::createSurface() #endif winInfo.fWidth = GetWidth(); winInfo.fHeight = GetHeight(); - switch (renderMethodToUse()) + switch (SkiaHelper::renderMethodToUse()) { - case RenderRaster: + case SkiaHelper::RenderRaster: mWindowContext = sk_app::window_context_factory::MakeRasterForXlib(winInfo, displayParams); + assert(SkToBool(mWindowContext)); + mSurface = mWindowContext->getBackbufferSurface(); + assert(mSurface.get()); mIsGPU = false; break; - case RenderVulkan: + case SkiaHelper::RenderVulkan: mWindowContext = sk_app::window_context_factory::MakeVulkanForXlib(winInfo, displayParams); + if (mWindowContext) + mSurface = mWindowContext->getBackbufferSurface(); + if (!mSurface) + { + SAL_WARN("vcl.skia", "cannot create Vulkan GPU surface, disabling Vulkan"); + SkiaHelper::disableRenderMethod(SkiaHelper::RenderVulkan); + return createSurface(); // try again + } mIsGPU = true; break; } - assert(SkToBool(mWindowContext)); // TODO - mSurface = mWindowContext->getBackbufferSurface(); - assert(mSurface.get()); #ifdef DBG_UTIL prefillSurface(); #endif |