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 34 of file KisOpenGLModeProber.cpp.

35{
36}

◆ ~KisOpenGLModeProber()

KisOpenGLModeProber::~KisOpenGLModeProber ( )

Definition at line 38 of file KisOpenGLModeProber.cpp.

39{
40
41}

Member Function Documentation

◆ angleRendererToString()

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

Definition at line 389 of file KisOpenGLModeProber.cpp.

390{
391 QString value;
392
393 switch (renderer) {
395 break;
397 value = "d3d9";
398 break;
400 value = "d3d11";
401 break;
403 value = "warp";
404 break;
405 };
406
407 return value;
408}
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 300 of file KisOpenGLModeProber.cpp.

302{
303#ifdef HAVE_HDR
307 if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {
308 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 10);
309 format->setRedBufferSize(10);
310 format->setGreenBufferSize(10);
311 format->setBlueBufferSize(10);
312 format->setAlphaBufferSize(2);
314 } else if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {
315 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 16);
316 format->setRedBufferSize(16);
317 format->setGreenBufferSize(16);
318 format->setBlueBufferSize(16);
319 format->setAlphaBufferSize(16);
321 } else {
322 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 8);
323 format->setRedBufferSize(8);
324 format->setGreenBufferSize(8);
325 format->setBlueBufferSize(8);
326 format->setAlphaBufferSize(8);
327 // TODO: check if we can use real sRGB space here
328 format->setColorSpace(KisSurfaceColorSpaceWrapper());
329 }
330#else
335 if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {
336 qWarning() << "WARNING: Bt.2020 PQ surface type is not supported by this build of Krita";
337 rootSurfaceFormat.first = KisSurfaceColorSpaceWrapper::DefaultColorSpace;
338 } else if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {
339 qWarning() << "WARNING: scRGB surface type is not supported by this build of Krita";
340 rootSurfaceFormat.first = KisSurfaceColorSpaceWrapper::DefaultColorSpace;
341 } else {
343 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 8 || rootSurfaceFormat.second == 10);
344
345 if (rootSurfaceFormat.second == 10) {
346 format->setRedBufferSize(10);
347 format->setGreenBufferSize(10);
348 format->setBlueBufferSize(10);
349 format->setAlphaBufferSize(2);
350 // TODO: check if we can use real sRGB space here
351 format->setColorSpace(KisSurfaceColorSpaceWrapper());
352 } else {
353 format->setRedBufferSize(8);
354 format->setGreenBufferSize(8);
355 format->setBlueBufferSize(8);
356 format->setAlphaBufferSize(8);
357 // TODO: check if we can use real sRGB space here
358 format->setColorSpace(KisSurfaceColorSpaceWrapper());
359 }
360 }
361#endif
362}
#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 43 of file KisOpenGLModeProber.cpp.

44{
45 return s_instance;
46}

◆ isFormatHDR()

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

Definition at line 364 of file KisOpenGLModeProber.cpp.

365{
366#ifdef HAVE_HDR
367
368 bool isBt2020PQ =
370 format.redBufferSize() == 10 &&
371 format.greenBufferSize() == 10 &&
372 format.blueBufferSize() == 10 &&
373 format.alphaBufferSize() == 2;
374
375 bool isBt709G10 =
376 format.colorSpace() == KisSurfaceColorSpaceWrapper::makeSCRGBColorSpace() &&
377 format.redBufferSize() == 16 &&
378 format.greenBufferSize() == 16 &&
379 format.blueBufferSize() == 16 &&
380 format.alphaBufferSize() == 16;
381
382 return isBt2020PQ || isBt709G10;
383#else
384 Q_UNUSED(format);
385 return false;
386#endif
387}
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 170 of file KisOpenGLModeProber.cpp.

172{
173 const QSurfaceFormat &format = rendererConfig.format;
174
175 dbgOpenGL << "Probing format" << rendererConfig.rendererId() << rendererConfig.angleRenderer
176 << rendererConfig.format;
177
178 QScopedPointer<AppAttributeSetter> sharedContextSetter;
179 QScopedPointer<AppAttributeSetter> glSetter;
180 QScopedPointer<AppAttributeSetter> glesSetter;
181 QScopedPointer<SurfaceFormatSetter> formatSetter;
182 QScopedPointer<EnvironmentSetter> rendererSetter;
183 QScopedPointer<EnvironmentSetter> portalSetter;
184#ifdef HAVE_DBUS
185 QScopedPointer<DisableDesktopAwareSetter> desktopAwareSetter;
186#endif
187 QScopedPointer<QGuiApplication> application;
188
189 int argc = 1;
190 QByteArray probeAppName("krita");
191 char *argv = probeAppName.data();
192
193
194 if (adjustGlobalState) {
195 sharedContextSetter.reset(new AppAttributeSetter(Qt::AA_ShareOpenGLContexts, false));
196
197 if (format.renderableType() != QSurfaceFormat::DefaultRenderableType) {
198 glSetter.reset(new AppAttributeSetter(Qt::AA_UseDesktopOpenGL, format.renderableType() != QSurfaceFormat::OpenGLES));
199 glesSetter.reset(new AppAttributeSetter(Qt::AA_UseOpenGLES, format.renderableType() == QSurfaceFormat::OpenGLES));
200 }
201
202 if (!qEnvironmentVariableIsSet("QT_ANGLE_PLATFORM")) {
203 rendererSetter.reset(new EnvironmentSetter(QLatin1String("QT_ANGLE_PLATFORM"), angleRendererToString(rendererConfig.angleRenderer)));
204 }
205 portalSetter.reset(new EnvironmentSetter(QLatin1String("QT_NO_XDG_DESKTOP_PORTAL"), QLatin1String("1")));
206 formatSetter.reset(new SurfaceFormatSetter(format));
207
208#ifdef HAVE_DBUS
209 if (!qEnvironmentVariableIsSet("KRITA_DISABLE_DESKTOP_UNAWARE_PROBING_WORKAROUND")) {
210 // When QGuiApplication is created, it also creates platform-specific GUI
211 // elements, like QPlatformMenu and QPlatformSystemTrayIcon. These classes
212 // can utilize DBus for communicating the platform. If we create a DBus
213 // connection, but do not start an event loop, then the connection will
214 // stuck in a "suspended delivery" state and will not be able to process
215 // anything. See bug 408015 and bug 515889
216 desktopAwareSetter.reset(new DisableDesktopAwareSetter());
217 }
218#endif /* HAVE_DBUS */
219
220 application.reset(new QGuiApplication(argc, &argv));
221 }
222
223#ifdef HAVE_DBUS
224 if (!qEnvironmentVariableIsSet("KRITA_DISABLE_TEMPORARY_APP_EVENTS_PROCESSING_WORKAROUND")) {
225 // If an application has been created, force it to process
226 // all the queued events and exit. Some internal
227 // Qt systems' initialization process rely on the queued
228 // events to be processed. See bug 515889.
229 QScopeGuard forceEventProcessingGuard([&]() {
230 if (!application)
231 return;
232
233 QMetaObject::invokeMethod(
234 application.data(),
235 [app = application.data()]() {
236 app->quit();
237 },
238 Qt::QueuedConnection);
239
240 application->exec();
241 });
242 }
243#endif /* HAVE_DBUS */
244
245 QWindow surface;
246 surface.setFormat(format);
247 surface.setSurfaceType(QSurface::OpenGLSurface);
248 surface.create();
249 QOpenGLContext context;
250 context.setFormat(format);
251
252
253 if (!context.create()) {
254 dbgOpenGL << "OpenGL context cannot be created";
255 return boost::none;
256 }
257 if (!context.isValid()) {
258 dbgOpenGL << "OpenGL context is not valid while checking Qt's OpenGL status";
259 return boost::none;
260 }
261 if (!context.makeCurrent(&surface)) {
262 dbgOpenGL << "OpenGL context cannot be made current";
263 return boost::none;
264 }
265
267 KisSurfaceColorSpaceWrapper::fromQtColorSpace(context.format().colorSpace()),
268 KisSurfaceColorSpaceWrapper::fromQtColorSpace(format.colorSpace()))) {
269
270 dbgOpenGL << "Failed to create an OpenGL context with requested color space. Requested:" << format.colorSpace() << "Actual:" << context.format().colorSpace();
271 return boost::none;
272 }
273
274 if (format.redBufferSize() > 0 && format.greenBufferSize() > 0 && format.blueBufferSize() > 0
275 && (context.format().redBufferSize() != format.redBufferSize()
276 || context.format().greenBufferSize() != format.greenBufferSize()
277 || context.format().blueBufferSize() != format.blueBufferSize())) {
278
279 dbgOpenGL << "Failed to create an OpenGL context with requested bit depth. Requested:" << format.redBufferSize()
280 << "Actual:" << context.format().redBufferSize();
281 return boost::none;
282 }
283
284 Result result(context);
285
286 dbgOpenGL << "Probe returned" << result.rendererString() << result.driverVersionString() << result.isOpenGLES();
287
288 return result;
289}
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 61 of file KisOpenGLModeProber.cpp.

62{
64
65 const auto surfaceColorSpace =
67
68 if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::sRGBColorSpace) {
69 // use the default one!
70#ifdef HAVE_HDR
71 } else if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {
73 } else if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {
74 // On Windows we use the legacy PQ profile, explicitly pinned to
75 // 80 nits. It is baked in the Qt's source code
77 query.hdrReferenceWhite = 80.0;
79#endif
80 }
81
82 return profile;
83}
@ 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 53 of file KisOpenGLModeProber.cpp.

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

◆ useHDRMode()

bool KisOpenGLModeProber::useHDRMode ( ) const

Definition at line 48 of file KisOpenGLModeProber.cpp.

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

References isFormatHDR().


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