blob: 471d47f01f691038fbd1623001f2967fae435a3a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/* -*- 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/.
*/
#include <vcl/skia/SkiaHelper.hxx>
#include <vcl/svapp.hxx>
#include <desktop/crashreport.hxx>
#include <officecfg/Office/Common.hxx>
#if !HAVE_FEATURE_SKIA
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");
bool bBlacklisted = false; // TODO isDeviceBlacklisted();
return !bDisableSkia && !bBlacklisted;
}
bool isVCLSkiaEnabled()
{
/**
* The !bSet part should only be called once! Changing the results in the same
* run will mix Skia and normal rendering.
*/
static bool bSet = false;
static bool bEnable = false;
static bool bForceSkia = false;
// No hardware rendering, so no Skia
// TODO SKIA
if (Application::IsBitmapRendering())
return false;
if (bSet)
{
return bForceSkia || bEnable;
}
/*
* There are a number of cases that these environment variables cover:
* * SAL_FORCESKIA forces Skia independent of any other option
* * SAL_DISABLESKIA avoids the use of Skia if SAL_FORCESKIA is not set
*/
bSet = true;
bForceSkia = !!getenv("SAL_FORCESKIA") || officecfg::Office::Common::VCL::ForceSkia::get();
bool bRet = false;
bool bSupportsVCLSkia = supportsVCLSkia();
// TODO SKIA always call supportsVCLOpenGL to de-zombie the glxtest child process on X11
if (bForceSkia)
{
bRet = true;
}
else if (bSupportsVCLSkia)
{
static bool bEnableSkiaEnv = !!getenv("SAL_ENABLESKIA");
bEnable = bEnableSkiaEnv;
if (officecfg::Office::Common::VCL::UseSkia::get())
bEnable = false;
// Force disable in safe mode
if (Application::IsSafeModeEnabled())
bEnable = false;
bRet = bEnable;
}
CrashReporter::addKeyValue("UseSkia", OUString::boolean(bRet), CrashReporter::Write);
return bRet;
}
static RenderMethod methodToUse = RenderRaster;
static bool initRenderMethodToUse()
{
if (const char* env = getenv("SAL_SKIA"))
{
if (strcmp(env, "raster") == 0)
{
methodToUse = RenderRaster;
return true;
}
}
methodToUse = RenderVulkan;
return true;
}
RenderMethod renderMethodToUse()
{
static bool methodToUseInited = initRenderMethodToUse();
if (methodToUseInited) // Used just to ensure thread-safe one-time init.
return methodToUse;
abort();
}
void disableRenderMethod(RenderMethod method)
{
if (renderMethodToUse() != method)
return;
// Choose a fallback, right now always raster.
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: */
|