summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/vcl/skia/SkiaHelper.hxx34
-rw-r--r--vcl/inc/skia/gdiimpl.hxx3
-rw-r--r--vcl/inc/skia/salbmp.hxx2
-rw-r--r--vcl/inc/skia/utils.hxx38
-rw-r--r--vcl/skia/SkiaHelper.cxx57
-rw-r--r--vcl/skia/gdiimpl.cxx14
-rw-r--r--vcl/unx/generic/app/salinst.cxx4
-rw-r--r--vcl/win/app/salinst.cxx3
8 files changed, 119 insertions, 36 deletions
diff --git a/include/vcl/skia/SkiaHelper.hxx b/include/vcl/skia/SkiaHelper.hxx
index d27cffd650f3..8cb76c653600 100644
--- a/include/vcl/skia/SkiaHelper.hxx
+++ b/include/vcl/skia/SkiaHelper.hxx
@@ -14,26 +14,28 @@
#include <config_features.h>
-// All member functions static and VCL_DLLPUBLIC. Basically a glorified namespace.
-struct VCL_DLLPUBLIC SkiaHelper
+namespace SkiaHelper
{
- SkiaHelper() = delete; // Should not be instantiated
-
-public:
- static bool isVCLSkiaEnabled();
+VCL_DLLPUBLIC bool isVCLSkiaEnabled();
#if HAVE_FEATURE_SKIA
- // Which Skia backend to use.
- enum RenderMethod
- {
- RenderRaster,
- RenderVulkan
- };
- static RenderMethod renderMethodToUse();
- static void disableRenderMethod(RenderMethod method);
-#endif
+
+// Which Skia backend to use.
+enum RenderMethod
+{
+ RenderRaster,
+ RenderVulkan
};
-#endif
+VCL_DLLPUBLIC RenderMethod renderMethodToUse();
+
+// Clean up before exit.
+VCL_DLLPUBLIC void cleanup();
+
+#endif // HAVE_FEATURE_SKIA
+
+} // namespace
+
+#endif // INCLUDED_VCL_SKIA_SKIAHELPER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/skia/gdiimpl.hxx b/vcl/inc/skia/gdiimpl.hxx
index e61ee6cfb787..7365d58f9173 100644
--- a/vcl/inc/skia/gdiimpl.hxx
+++ b/vcl/inc/skia/gdiimpl.hxx
@@ -28,7 +28,7 @@
#include <SkSurface.h>
#include <prewin.h>
-#include <tools/sk_app/VulkanWindowContext.h>
+#include <tools/sk_app/WindowContext.h>
#include <postwin.h>
class SkiaFlushIdle;
@@ -263,7 +263,6 @@ protected:
/// Pointer to the SalFrame or SalVirtualDevice
SalGeometryProvider* mProvider;
std::unique_ptr<sk_app::WindowContext> mWindowContext;
- sk_app::VulkanWindowContext::SharedGrContext mOffscreenGrContext;
// The Skia surface that is target of all the rendering.
sk_sp<SkSurface> mSurface;
bool mIsGPU; // whether the surface is GPU-backed
diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx
index ed0f374162d6..0b0e1aa5439c 100644
--- a/vcl/inc/skia/salbmp.hxx
+++ b/vcl/inc/skia/salbmp.hxx
@@ -101,6 +101,6 @@ private:
int mScanlineSize; // size of one row in mBuffer
};
-#endif // INCLUDED_VCL_INC_OPENGL_SALBMP_H
+#endif // INCLUDED_VCL_INC_SKIA_SALBMP_H
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/skia/utils.hxx b/vcl/inc/skia/utils.hxx
new file mode 100644
index 000000000000..5d824400030a
--- /dev/null
+++ b/vcl/inc/skia/utils.hxx
@@ -0,0 +1,38 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_VCL_INC_SKIA_UTILS_H
+#define INCLUDED_VCL_INC_SKIA_UTILS_H
+
+#include <vcl/skia/SkiaHelper.hxx>
+
+#include <tools/sk_app/VulkanWindowContext.h>
+
+namespace SkiaHelper
+{
+// Get the one shared GrContext instance.
+GrContext* getSharedGrContext();
+
+void disableRenderMethod(RenderMethod method);
+
+} // namespace
+
+#endif // INCLUDED_VCL_INC_SKIA_UTILS_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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: */
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index 9c8d7c497ba2..6a977ab6b598 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -25,6 +25,7 @@
#include <vcl/svapp.hxx>
#include <vcl/lazydelete.hxx>
#include <vcl/skia/SkiaHelper.hxx>
+#include <skia/utils.hxx>
#include <SkCanvas.h>
#include <SkPath.h>
@@ -182,7 +183,6 @@ SkiaSalGraphicsImpl::~SkiaSalGraphicsImpl()
{
assert(!mSurface);
assert(!mWindowContext);
- assert(!mOffscreenGrContext);
}
void SkiaSalGraphicsImpl::Init() {}
@@ -243,8 +243,7 @@ void SkiaSalGraphicsImpl::createOffscreenSurface()
{
case SkiaHelper::RenderVulkan:
{
- mOffscreenGrContext = sk_app::VulkanWindowContext::getSharedGrContext();
- GrContext* grContext = mOffscreenGrContext.getGrContext();
+ GrContext* grContext = SkiaHelper::getSharedGrContext();
// We may not get a GrContext if called before any onscreen window is created.
if (!grContext)
{
@@ -253,14 +252,10 @@ void SkiaSalGraphicsImpl::createOffscreenSurface()
// Create temporary WindowContext with no window. That will fail,
// but it will initialize the shared GrContext.
createWindowContext();
- // Keep a reference.
- sk_app::VulkanWindowContext::SharedGrContext context
- = sk_app::VulkanWindowContext::getSharedGrContext();
+ // This will use the temporarily created context.
+ grContext = SkiaHelper::getSharedGrContext();
// Destroy the temporary WindowContext.
destroySurface();
- // Keep a reference until the surface is destroyed.
- mOffscreenGrContext = context;
- grContext = mOffscreenGrContext.getGrContext();
}
if (grContext)
{
@@ -309,7 +304,6 @@ void SkiaSalGraphicsImpl::destroySurface()
mSurface.reset();
mWindowContext.reset();
mIsGPU = false;
- mOffscreenGrContext.reset();
}
void SkiaSalGraphicsImpl::DeInit() { destroySurface(); }
diff --git a/vcl/unx/generic/app/salinst.cxx b/vcl/unx/generic/app/salinst.cxx
index 3c39a1addbd9..f253f70d7d93 100644
--- a/vcl/unx/generic/app/salinst.cxx
+++ b/vcl/unx/generic/app/salinst.cxx
@@ -79,6 +79,10 @@ X11SalInstance::~X11SalInstance()
// would be done in a static destructor else which is
// a little late
GetGenericUnixSalData()->Dispose();
+
+#if HAVE_FEATURE_SKIA
+ SkiaHelper::cleanup();
+#endif
}
SalX11Display* X11SalInstance::CreateDisplay() const
diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx
index 43cc8e8e6a85..cd9332e0c728 100644
--- a/vcl/win/app/salinst.cxx
+++ b/vcl/win/app/salinst.cxx
@@ -407,6 +407,9 @@ WinSalInstance::~WinSalInstance()
{
ImplFreeSalGDI();
DestroyWindow( mhComWnd );
+#if HAVE_FEATURE_SKIA
+ SkiaHelper::cleanup();
+#endif
}
static LRESULT ImplSalDispatchMessage( const MSG* pMsg )