Krita Source Code Documentation
Loading...
Searching...
No Matches
KisOpenGLModeProber Class Reference

#include <KisOpenGLModeProber.h>

Classes

class  Result
 

Public Member Functions

 KisOpenGLModeProber ()
 
boost::optional< Result > probeFormat (const KisOpenGL::RendererConfig &rendererConfig, bool adjustGlobalState=true)
 
const KoColorProfile * rootSurfaceColorProfile () const
 
QSurfaceFormat surfaceformatInUse () const
 
bool useHDRMode () const
 
 ~KisOpenGLModeProber ()
 

Static Public Member Functions

static QString angleRendererToString (KisOpenGL::AngleRenderer renderer)
 
static bool fuzzyCompareColorSpaces (const KisSurfaceColorSpaceWrapper &lhs, const KisSurfaceColorSpaceWrapper &rhs)
 
static void initSurfaceFormatFromConfig (std::pair< KisSurfaceColorSpaceWrapper, int > rootSurfaceFormat, QSurfaceFormat *format)
 
static KisOpenGLModeProber * instance ()
 
static bool isFormatHDR (const QSurfaceFormat &format)
 

Detailed Description

Definition at line 21 of file KisOpenGLModeProber.h.

Constructor & Destructor Documentation

◆ KisOpenGLModeProber()

KisOpenGLModeProber::KisOpenGLModeProber ( )

Definition at line 33 of file KisOpenGLModeProber.cpp.

34{
35}

◆ ~KisOpenGLModeProber()

KisOpenGLModeProber::~KisOpenGLModeProber ( )

Definition at line 37 of file KisOpenGLModeProber.cpp.

38{
39
40}

Member Function Documentation

◆ angleRendererToString()

QString KisOpenGLModeProber::angleRendererToString ( KisOpenGL::AngleRenderer renderer)
static

Definition at line 347 of file KisOpenGLModeProber.cpp.

348{
349 QString value;
350
351 switch (renderer) {
353 break;
355 value = "d3d9";
356 break;
358 value = "d3d11";
359 break;
361 value = "warp";
362 break;
363 };
364
365 return value;
366}
float value(const T *src, size_t ch)
@ AngleRendererD3d11Warp
Definition kis_opengl.h:53
@ AngleRendererD3d11
Definition kis_opengl.h:51
@ AngleRendererD3d9
Definition kis_opengl.h:52
@ AngleRendererDefault
Definition kis_opengl.h:50

References KisOpenGL::AngleRendererD3d11, KisOpenGL::AngleRendererD3d11Warp, KisOpenGL::AngleRendererD3d9, KisOpenGL::AngleRendererDefault, and value().

◆ fuzzyCompareColorSpaces()

◆ initSurfaceFormatFromConfig()

void KisOpenGLModeProber::initSurfaceFormatFromConfig ( std::pair< KisSurfaceColorSpaceWrapper, int > rootSurfaceFormat,
QSurfaceFormat * format )
static

In Wayland's HDR we don't set the mode on the root surface, we should only select bit-width.

Definition at line 258 of file KisOpenGLModeProber.cpp.

260{
261#ifdef HAVE_HDR
265 if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {
266 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 10);
267 format->setRedBufferSize(10);
268 format->setGreenBufferSize(10);
269 format->setBlueBufferSize(10);
270 format->setAlphaBufferSize(2);
272 } else if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {
273 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 16);
274 format->setRedBufferSize(16);
275 format->setGreenBufferSize(16);
276 format->setBlueBufferSize(16);
277 format->setAlphaBufferSize(16);
279 } else {
280 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 8);
281 format->setRedBufferSize(8);
282 format->setGreenBufferSize(8);
283 format->setBlueBufferSize(8);
284 format->setAlphaBufferSize(8);
285 // TODO: check if we can use real sRGB space here
286 format->setColorSpace(KisSurfaceColorSpaceWrapper());
287 }
288#else
293 if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {
294 qWarning() << "WARNING: Bt.2020 PQ surface type is not supported by this build of Krita";
295 rootSurfaceFormat.first = KisSurfaceColorSpaceWrapper::DefaultColorSpace;
296 } else if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {
297 qWarning() << "WARNING: scRGB surface type is not supported by this build of Krita";
298 rootSurfaceFormat.first = KisSurfaceColorSpaceWrapper::DefaultColorSpace;
299 } else {
301 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 8 || rootSurfaceFormat.second == 10);
302
303 if (rootSurfaceFormat.second == 10) {
304 format->setRedBufferSize(10);
305 format->setGreenBufferSize(10);
306 format->setBlueBufferSize(10);
307 format->setAlphaBufferSize(2);
308 // TODO: check if we can use real sRGB space here
309 format->setColorSpace(KisSurfaceColorSpaceWrapper());
310 } else {
311 format->setRedBufferSize(8);
312 format->setGreenBufferSize(8);
313 format->setBlueBufferSize(8);
314 format->setAlphaBufferSize(8);
315 // TODO: check if we can use real sRGB space here
316 format->setColorSpace(KisSurfaceColorSpaceWrapper());
317 }
318 }
319#endif
320}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KisSurfaceColorSpaceWrapper::bt2020PQColorSpace, KisSurfaceColorSpaceWrapper::DefaultColorSpace, KIS_SAFE_ASSERT_RECOVER_NOOP, and KisSurfaceColorSpaceWrapper::scRGBColorSpace.

◆ instance()

KisOpenGLModeProber * KisOpenGLModeProber::instance ( )
static

Definition at line 42 of file KisOpenGLModeProber.cpp.

43{
44 return s_instance;
45}

◆ isFormatHDR()

bool KisOpenGLModeProber::isFormatHDR ( const QSurfaceFormat & format)
static

Definition at line 322 of file KisOpenGLModeProber.cpp.

323{
324#ifdef HAVE_HDR
325
326 bool isBt2020PQ =
328 format.redBufferSize() == 10 &&
329 format.greenBufferSize() == 10 &&
330 format.blueBufferSize() == 10 &&
331 format.alphaBufferSize() == 2;
332
333 bool isBt709G10 =
334 format.colorSpace() == KisSurfaceColorSpaceWrapper::makeSCRGBColorSpace() &&
335 format.redBufferSize() == 16 &&
336 format.greenBufferSize() == 16 &&
337 format.blueBufferSize() == 16 &&
338 format.alphaBufferSize() == 16;
339
340 return isBt2020PQ || isBt709G10;
341#else
342 Q_UNUSED(format);
343 return false;
344#endif
345}
static constexpr KisSurfaceColorSpaceWrapper makeSCRGBColorSpace()
static constexpr KisSurfaceColorSpaceWrapper makeBt2020PQColorSpace()

References KisSurfaceColorSpaceWrapper::makeBt2020PQColorSpace(), and KisSurfaceColorSpaceWrapper::makeSCRGBColorSpace().

◆ probeFormat()

boost::optional< KisOpenGLModeProber::Result > KisOpenGLModeProber::probeFormat ( const KisOpenGL::RendererConfig & rendererConfig,
bool adjustGlobalState = true )

Definition at line 151 of file KisOpenGLModeProber.cpp.

153{
154 const QSurfaceFormat &format = rendererConfig.format;
155
156 dbgOpenGL << "Probing format" << rendererConfig.rendererId() << rendererConfig.angleRenderer
157 << rendererConfig.format;
158
159 QScopedPointer<AppAttributeSetter> sharedContextSetter;
160 QScopedPointer<AppAttributeSetter> glSetter;
161 QScopedPointer<AppAttributeSetter> glesSetter;
162 QScopedPointer<SurfaceFormatSetter> formatSetter;
163 QScopedPointer<EnvironmentSetter> rendererSetter;
164 QScopedPointer<EnvironmentSetter> portalSetter;
165 QScopedPointer<QGuiApplication> application;
166
167 int argc = 1;
168 QByteArray probeAppName("krita");
169 char *argv = probeAppName.data();
170
171
172 if (adjustGlobalState) {
173 sharedContextSetter.reset(new AppAttributeSetter(Qt::AA_ShareOpenGLContexts, false));
174
175 if (format.renderableType() != QSurfaceFormat::DefaultRenderableType) {
176 glSetter.reset(new AppAttributeSetter(Qt::AA_UseDesktopOpenGL, format.renderableType() != QSurfaceFormat::OpenGLES));
177 glesSetter.reset(new AppAttributeSetter(Qt::AA_UseOpenGLES, format.renderableType() == QSurfaceFormat::OpenGLES));
178 }
179
180 if (!qEnvironmentVariableIsSet("QT_ANGLE_PLATFORM")) {
181 rendererSetter.reset(new EnvironmentSetter(QLatin1String("QT_ANGLE_PLATFORM"), angleRendererToString(rendererConfig.angleRenderer)));
182 }
183 portalSetter.reset(new EnvironmentSetter(QLatin1String("QT_NO_XDG_DESKTOP_PORTAL"), QLatin1String("1")));
184 formatSetter.reset(new SurfaceFormatSetter(format));
185
186 // Disable this workaround for plasma (BUG:408015), because it causes
187 // a crash on Windows with Qt 5.15.7
188 const bool runningInKDE = qEnvironmentVariableIsSet("KDE_FULL_SESSION");
189 const bool isInAppimage = qEnvironmentVariableIsSet("APPIMAGE");
190
191 if (runningInKDE && !isInAppimage) {
192 QGuiApplication::setDesktopSettingsAware(false);
193 }
194
195 application.reset(new QGuiApplication(argc, &argv));
196
197 if (runningInKDE && !isInAppimage) {
198 QGuiApplication::setDesktopSettingsAware(true);
199 }
200
201 }
202
203 QWindow surface;
204 surface.setFormat(format);
205 surface.setSurfaceType(QSurface::OpenGLSurface);
206 surface.create();
207 QOpenGLContext context;
208 context.setFormat(format);
209
210
211 if (!context.create()) {
212 dbgOpenGL << "OpenGL context cannot be created";
213 return boost::none;
214 }
215 if (!context.isValid()) {
216 dbgOpenGL << "OpenGL context is not valid while checking Qt's OpenGL status";
217 return boost::none;
218 }
219 if (!context.makeCurrent(&surface)) {
220 dbgOpenGL << "OpenGL context cannot be made current";
221 return boost::none;
222 }
223
225 KisSurfaceColorSpaceWrapper::fromQtColorSpace(context.format().colorSpace()),
226 KisSurfaceColorSpaceWrapper::fromQtColorSpace(format.colorSpace()))) {
227
228 dbgOpenGL << "Failed to create an OpenGL context with requested color space. Requested:" << format.colorSpace() << "Actual:" << context.format().colorSpace();
229 return boost::none;
230 }
231
232 if (format.redBufferSize() > 0 && format.greenBufferSize() > 0 && format.blueBufferSize() > 0
233 && (context.format().redBufferSize() != format.redBufferSize()
234 || context.format().greenBufferSize() != format.greenBufferSize()
235 || context.format().blueBufferSize() != format.blueBufferSize())) {
236
237 dbgOpenGL << "Failed to create an OpenGL context with requested bit depth. Requested:" << format.redBufferSize()
238 << "Actual:" << context.format().redBufferSize();
239 return boost::none;
240 }
241
242 Result result(context);
243
244 dbgOpenGL << "Probe returned" << result.rendererString() << result.driverVersionString() << result.isOpenGLES();
245
246 return result;
247}
static QString angleRendererToString(KisOpenGL::AngleRenderer renderer)
static bool fuzzyCompareColorSpaces(const KisSurfaceColorSpaceWrapper &lhs, const KisSurfaceColorSpaceWrapper &rhs)
static KisSurfaceColorSpaceWrapper fromQtColorSpace(const QColorSpace &colorSpace)
#define dbgOpenGL
Definition kis_debug.h:63
AngleRenderer angleRenderer
Definition kis_opengl.h:58
QSurfaceFormat format
Definition kis_opengl.h:57
OpenGLRenderer rendererId() const

References KisOpenGL::RendererConfig::angleRenderer, angleRendererToString(), dbgOpenGL, KisOpenGLModeProber::Result::driverVersionString(), KisOpenGL::RendererConfig::format, KisSurfaceColorSpaceWrapper::fromQtColorSpace(), fuzzyCompareColorSpaces(), KisOpenGLModeProber::Result::isOpenGLES(), KisOpenGL::RendererConfig::rendererId(), and KisOpenGLModeProber::Result::rendererString().

◆ rootSurfaceColorProfile()

const KoColorProfile * KisOpenGLModeProber::rootSurfaceColorProfile ( ) const

Definition at line 60 of file KisOpenGLModeProber.cpp.

61{
63
64 const auto surfaceColorSpace =
66
67 if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::sRGBColorSpace) {
68 // use the default one!
69#ifdef HAVE_HDR
70 } else if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {
72 } else if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {
73 // On Windows we use the legacy PQ profile, explicitly pinned to
74 // 80 nits. It is baked in the Qt's source code
76 query.hdrReferenceWhite = 80.0;
78#endif
79 }
80
81 return profile;
82}
@ PRIMARIES_ITU_R_BT_2020_2_AND_2100_0
@ TRC_ITU_R_BT_2100_0_PQ
QSurfaceFormat surfaceformatInUse() const
The KoColorProfileQuery struct.
static KoColorSpaceRegistry * instance()
const KoColorProfile * profileFor(const KoColorProfileQuery &query, const bool generate=true) const
profileFor tries to find the profile that matches these characteristics, if no such profile is found,...
const KoColorProfile * p709G10Profile() const
const KoColorProfile * p709SRGBProfile() const

References KisSurfaceColorSpaceWrapper::bt2020PQColorSpace, KisSurfaceColorSpaceWrapper::fromQtColorSpace(), KoColorProfileQuery::hdrReferenceWhite, KoColorSpaceRegistry::instance(), KoColorSpaceRegistry::p709G10Profile(), KoColorSpaceRegistry::p709SRGBProfile(), PRIMARIES_ITU_R_BT_2020_2_AND_2100_0, KoColorSpaceRegistry::profileFor(), KisSurfaceColorSpaceWrapper::scRGBColorSpace, KisSurfaceColorSpaceWrapper::sRGBColorSpace, surfaceformatInUse(), and TRC_ITU_R_BT_2100_0_PQ.

◆ surfaceformatInUse()

QSurfaceFormat KisOpenGLModeProber::surfaceformatInUse ( ) const

Definition at line 52 of file KisOpenGLModeProber.cpp.

53{
54 // TODO: use information provided by KisOpenGL instead
55 QOpenGLContext *sharedContext = QOpenGLContext::globalShareContext();
56 QSurfaceFormat format = sharedContext ? sharedContext->format() : QSurfaceFormat::defaultFormat();
57 return format;
58}

◆ useHDRMode()

bool KisOpenGLModeProber::useHDRMode ( ) const

Definition at line 47 of file KisOpenGLModeProber.cpp.

48{
49 return isFormatHDR(QSurfaceFormat::defaultFormat());
50}
static bool isFormatHDR(const QSurfaceFormat &format)

References isFormatHDR().


The documentation for this class was generated from the following files: