diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-08-30 11:51:25 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-08-31 10:04:23 +0200 |
commit | bbf7dc39abf64c314e9c43c4d0554d1d7bdef3e7 (patch) | |
tree | 3ebc56bfcea749ebdbe721ac61fddd4df4bccbcb | |
parent | 874bcdbd8948ca98a559d8604795ea3ee238bf15 (diff) |
test at least creating Metal context when initializing Skia
Change-Id: Ic00236e7876039c3f5c0c1e719e829b844d1d2e4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121271
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r-- | vcl/skia/SkiaHelper.cxx | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx index 6881ad1cbf83..458f415befa4 100644 --- a/vcl/skia/SkiaHelper.cxx +++ b/vcl/skia/SkiaHelper.cxx @@ -158,7 +158,7 @@ static void writeSkiaRasterInfo() writeToLog(logFile, "Compiler", skia_compiler_name()); } -#ifdef SK_VULKAN +#if defined(SK_VULKAN) || defined(SK_METAL) static std::unique_ptr<sk_app::WindowContext> getTemporaryWindowContext(); #endif @@ -170,6 +170,7 @@ static void checkDeviceDenylisted(bool blockDisable = false) SkiaZone zone; + bool useRaster = false; switch (renderMethodToUse()) { case RenderVulkan: @@ -204,32 +205,57 @@ static void checkDeviceDenylisted(bool blockDisable = false) if (denylisted && !blockDisable) { disableRenderMethod(RenderVulkan); - writeSkiaRasterInfo(); + useRaster = true; } - break; #else SAL_WARN("vcl.skia", "Vulkan support not built in"); (void)blockDisable; - [[fallthrough]]; + useRaster = true; #endif + break; } case RenderMetal: + { #ifdef SK_METAL - // Try to assume Metal always works, given that Mac doesn't have such as wide range of HW vendors as PC. - // If there turns out to be problems, handle it similarly to Vulkan. - SAL_INFO("vcl.skia", "Using Skia Metal mode"); - writeSkiaMetalInfo(); - break; + // First try if a GrDirectContext already exists. + std::unique_ptr<sk_app::WindowContext> temporaryWindowContext; + GrDirectContext* grDirectContext = sk_app::getMetalSharedGrDirectContext(); + if (!grDirectContext) + { + // Create a temporary window context just to get the GrDirectContext, + // as an initial test of Metal functionality. + temporaryWindowContext = getTemporaryWindowContext(); + grDirectContext = sk_app::getMetalSharedGrDirectContext(); + } + if (grDirectContext) // Metal was initialized properly + { + // Try to assume Metal always works, given that Mac doesn't have such as wide range of HW vendors as PC. + // If there turns out to be problems, handle it similarly to Vulkan. + SAL_INFO("vcl.skia", "Using Skia Metal mode"); + writeSkiaMetalInfo(); + } + else + { + SAL_INFO("vcl.skia", "Metal could not be initialized"); + disableRenderMethod(RenderMetal); + useRaster = true; + } #else SAL_WARN("vcl.skia", "Metal support not built in"); - [[fallthrough]]; + useRaster = true; #endif + break; + } case RenderRaster: - SAL_INFO("vcl.skia", "Using Skia raster mode"); - // software, never denylisted - writeSkiaRasterInfo(); + useRaster = true; break; } + if (useRaster) + { + SAL_INFO("vcl.skia", "Using Skia raster mode"); + // software, never denylisted + writeSkiaRasterInfo(); + } done = true; } @@ -431,7 +457,7 @@ GrDirectContext* getSharedGrDirectContext() return nullptr; } -#ifdef SK_VULKAN +#if defined(SK_VULKAN) || defined(SK_METAL) static std::unique_ptr<sk_app::WindowContext> getTemporaryWindowContext() { if (createGpuWindowContextFunction == nullptr) |