summaryrefslogtreecommitdiff
path: root/vcl/skia/SkiaHelper.cxx
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-12-03 19:16:00 +0100
committerLuboš Luňák <l.lunak@collabora.com>2019-12-06 14:25:52 +0100
commitea5eb4639ac3cca4301e23655d0e7aeaed6f8bcc (patch)
tree5d993eaf9ac1ac816cdcec6a10d0ecd8ba46c218 /vcl/skia/SkiaHelper.cxx
parent5b667d771de65167e269bb145b888eabbc7fdedd (diff)
keep just one shared reference to Skia shared GrContext
This should make it easier to keep the reference without having to keep references all over the place, especially when the shared GrContext starts to be used also for GPU-backed surfaces elsewhere. Change-Id: Icf3f6eb849ebc5eb63b1836f9caeb6f5e5e58ca6 Reviewed-on: https://gerrit.libreoffice.org/84560 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl/skia/SkiaHelper.cxx')
-rw-r--r--vcl/skia/SkiaHelper.cxx57
1 files changed, 50 insertions, 7 deletions
diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx
index 040f189be74f..471d47f01f69 100644
--- a/vcl/skia/SkiaHelper.cxx
+++ b/vcl/skia/SkiaHelper.cxx
@@ -14,10 +14,21 @@
#include <officecfg/Office/Common.hxx>
#if !HAVE_FEATURE_SKIA
-bool SkiaHelper::isVCLSkiaEnabled() { return false; }
+
+namespace SkiaHelper
+{
+bool isVCLSkiaEnabled() { return false; }
+
+} // namespace
#else
+#include <skia/utils.hxx>
+
+#include <tools/sk_app/VulkanWindowContext.h>
+
+namespace SkiaHelper
+{
static bool supportsVCLSkia()
{
static bool bDisableSkia = !!getenv("SAL_DISABLESKIA");
@@ -26,7 +37,7 @@ static bool supportsVCLSkia()
return !bDisableSkia && !bBlacklisted;
}
-bool SkiaHelper::isVCLSkiaEnabled()
+bool isVCLSkiaEnabled()
{
/**
* The !bSet part should only be called once! Changing the results in the same
@@ -84,7 +95,7 @@ bool SkiaHelper::isVCLSkiaEnabled()
return bRet;
}
-static SkiaHelper::RenderMethod methodToUse = SkiaHelper::RenderRaster;
+static RenderMethod methodToUse = RenderRaster;
static bool initRenderMethodToUse()
{
@@ -92,15 +103,15 @@ static bool initRenderMethodToUse()
{
if (strcmp(env, "raster") == 0)
{
- methodToUse = SkiaHelper::RenderRaster;
+ methodToUse = RenderRaster;
return true;
}
}
- methodToUse = SkiaHelper::RenderVulkan;
+ methodToUse = RenderVulkan;
return true;
}
-SkiaHelper::RenderMethod SkiaHelper::renderMethodToUse()
+RenderMethod renderMethodToUse()
{
static bool methodToUseInited = initRenderMethodToUse();
if (methodToUseInited) // Used just to ensure thread-safe one-time init.
@@ -108,7 +119,7 @@ SkiaHelper::RenderMethod SkiaHelper::renderMethodToUse()
abort();
}
-void SkiaHelper::disableRenderMethod(RenderMethod method)
+void disableRenderMethod(RenderMethod method)
{
if (renderMethodToUse() != method)
return;
@@ -116,6 +127,38 @@ void SkiaHelper::disableRenderMethod(RenderMethod method)
methodToUse = RenderRaster;
}
+static sk_app::VulkanWindowContext::SharedGrContext* sharedGrContext;
+
+GrContext* getSharedGrContext()
+{
+ assert(renderMethodToUse() == RenderVulkan);
+ if (sharedGrContext)
+ return sharedGrContext->getGrContext();
+ // TODO mutex?
+ // Setup the shared GrContext from Skia's (patched) VulkanWindowContext, if it's been
+ // already set up.
+ sk_app::VulkanWindowContext::SharedGrContext context
+ = sk_app::VulkanWindowContext::getSharedGrContext();
+ GrContext* grContext = context.getGrContext();
+ if (grContext)
+ {
+ sharedGrContext = new sk_app::VulkanWindowContext::SharedGrContext(context);
+ return grContext;
+ }
+ // TODO
+ // SkiaSalGraphicsImpl::createOffscreenSurface() creates the shared context using a dummy window,
+ // but we do not have a window here. Is it worth it to try to do it here?
+ return nullptr;
+}
+
+void cleanup()
+{
+ delete sharedGrContext;
+ sharedGrContext = nullptr;
+}
+
+} // namespace
+
#endif // HAVE_FEATURE_SKIA
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */