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

#include <KisOpenGLModeProber.h>

Classes

class  Result
 

Public Member Functions

 KisOpenGLModeProber ()
 
boost::optional< ResultprobeFormat (const KisOpenGL::RendererConfig &rendererConfig, bool adjustGlobalState=true)
 
const KoColorProfilerootSurfaceColorProfile () 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 KisOpenGLModeProberinstance ()
 
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 23 of file KisOpenGLModeProber.cpp.

24{
25}

◆ ~KisOpenGLModeProber()

KisOpenGLModeProber::~KisOpenGLModeProber ( )

Definition at line 27 of file KisOpenGLModeProber.cpp.

28{
29
30}

Member Function Documentation

◆ angleRendererToString()

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

Definition at line 333 of file KisOpenGLModeProber.cpp.

334{
335 QString value;
336
337 switch (renderer) {
339 break;
341 value = "d3d9";
342 break;
344 value = "d3d11";
345 break;
347 value = "warp";
348 break;
349 };
350
351 return value;
352}
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 244 of file KisOpenGLModeProber.cpp.

246{
247#ifdef HAVE_HDR
251 if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {
252 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 10);
253 format->setRedBufferSize(10);
254 format->setGreenBufferSize(10);
255 format->setBlueBufferSize(10);
256 format->setAlphaBufferSize(2);
258 } else if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {
259 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 16);
260 format->setRedBufferSize(16);
261 format->setGreenBufferSize(16);
262 format->setBlueBufferSize(16);
263 format->setAlphaBufferSize(16);
265 } else {
266 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 8);
267 format->setRedBufferSize(8);
268 format->setGreenBufferSize(8);
269 format->setBlueBufferSize(8);
270 format->setAlphaBufferSize(8);
271 // TODO: check if we can use real sRGB space here
272 format->setColorSpace(KisSurfaceColorSpaceWrapper());
273 }
274#else
279 if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {
280 qWarning() << "WARNING: Bt.2020 PQ surface type is not supported by this build of Krita";
281 rootSurfaceFormat.first = KisSurfaceColorSpaceWrapper::DefaultColorSpace;
282 } else if (rootSurfaceFormat.first == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {
283 qWarning() << "WARNING: scRGB surface type is not supported by this build of Krita";
284 rootSurfaceFormat.first = KisSurfaceColorSpaceWrapper::DefaultColorSpace;
285 } else {
287 KIS_SAFE_ASSERT_RECOVER_NOOP(rootSurfaceFormat.second == 8 || rootSurfaceFormat.second == 10);
288
289 if (rootSurfaceFormat.second == 10) {
290 format->setRedBufferSize(10);
291 format->setGreenBufferSize(10);
292 format->setBlueBufferSize(10);
293 format->setAlphaBufferSize(2);
294 // TODO: check if we can use real sRGB space here
295 format->setColorSpace(KisSurfaceColorSpaceWrapper());
296 } else {
297 format->setRedBufferSize(8);
298 format->setGreenBufferSize(8);
299 format->setBlueBufferSize(8);
300 format->setAlphaBufferSize(8);
301 // TODO: check if we can use real sRGB space here
302 format->setColorSpace(KisSurfaceColorSpaceWrapper());
303 }
304 }
305#endif
306}
#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 32 of file KisOpenGLModeProber.cpp.

33{
34 return s_instance;
35}

◆ isFormatHDR()

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

Definition at line 308 of file KisOpenGLModeProber.cpp.

309{
310#ifdef HAVE_HDR
311
312 bool isBt2020PQ =
314 format.redBufferSize() == 10 &&
315 format.greenBufferSize() == 10 &&
316 format.blueBufferSize() == 10 &&
317 format.alphaBufferSize() == 2;
318
319 bool isBt709G10 =
320 format.colorSpace() == KisSurfaceColorSpaceWrapper::makeSCRGBColorSpace() &&
321 format.redBufferSize() == 16 &&
322 format.greenBufferSize() == 16 &&
323 format.blueBufferSize() == 16 &&
324 format.alphaBufferSize() == 16;
325
326 return isBt2020PQ || isBt709G10;
327#else
328 Q_UNUSED(format);
329 return false;
330#endif
331}
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 137 of file KisOpenGLModeProber.cpp.

139{
140 const QSurfaceFormat &format = rendererConfig.format;
141
142 dbgOpenGL << "Probing format" << rendererConfig.rendererId() << rendererConfig.angleRenderer
143 << rendererConfig.format;
144
145 QScopedPointer<AppAttributeSetter> sharedContextSetter;
146 QScopedPointer<AppAttributeSetter> glSetter;
147 QScopedPointer<AppAttributeSetter> glesSetter;
148 QScopedPointer<SurfaceFormatSetter> formatSetter;
149 QScopedPointer<EnvironmentSetter> rendererSetter;
150 QScopedPointer<EnvironmentSetter> portalSetter;
151 QScopedPointer<QGuiApplication> application;
152
153 int argc = 1;
154 QByteArray probeAppName("krita");
155 char *argv = probeAppName.data();
156
157
158 if (adjustGlobalState) {
159 sharedContextSetter.reset(new AppAttributeSetter(Qt::AA_ShareOpenGLContexts, false));
160
161 if (format.renderableType() != QSurfaceFormat::DefaultRenderableType) {
162 glSetter.reset(new AppAttributeSetter(Qt::AA_UseDesktopOpenGL, format.renderableType() != QSurfaceFormat::OpenGLES));
163 glesSetter.reset(new AppAttributeSetter(Qt::AA_UseOpenGLES, format.renderableType() == QSurfaceFormat::OpenGLES));
164 }
165
166 if (!qEnvironmentVariableIsSet("QT_ANGLE_PLATFORM")) {
167 rendererSetter.reset(new EnvironmentSetter(QLatin1String("QT_ANGLE_PLATFORM"), angleRendererToString(rendererConfig.angleRenderer)));
168 }
169 portalSetter.reset(new EnvironmentSetter(QLatin1String("QT_NO_XDG_DESKTOP_PORTAL"), QLatin1String("1")));
170 formatSetter.reset(new SurfaceFormatSetter(format));
171
172 // Disable this workaround for plasma (BUG:408015), because it causes
173 // a crash on Windows with Qt 5.15.7
174 const bool runningInKDE = qEnvironmentVariableIsSet("KDE_FULL_SESSION");
175 const bool isInAppimage = qEnvironmentVariableIsSet("APPIMAGE");
176
177 if (runningInKDE && !isInAppimage) {
178 QGuiApplication::setDesktopSettingsAware(false);
179 }
180
181 application.reset(new QGuiApplication(argc, &argv));
182
183 if (runningInKDE && !isInAppimage) {
184 QGuiApplication::setDesktopSettingsAware(true);
185 }
186
187 }
188
189 QWindow surface;
190 surface.setFormat(format);
191 surface.setSurfaceType(QSurface::OpenGLSurface);
192 surface.create();
193 QOpenGLContext context;
194 context.setFormat(format);
195
196
197 if (!context.create()) {
198 dbgOpenGL << "OpenGL context cannot be created";
199 return boost::none;
200 }
201 if (!context.isValid()) {
202 dbgOpenGL << "OpenGL context is not valid while checking Qt's OpenGL status";
203 return boost::none;
204 }
205 if (!context.makeCurrent(&surface)) {
206 dbgOpenGL << "OpenGL context cannot be made current";
207 return boost::none;
208 }
209
211 KisSurfaceColorSpaceWrapper::fromQtColorSpace(context.format().colorSpace()),
212 KisSurfaceColorSpaceWrapper::fromQtColorSpace(format.colorSpace()))) {
213
214 dbgOpenGL << "Failed to create an OpenGL context with requested color space. Requested:" << format.colorSpace() << "Actual:" << context.format().colorSpace();
215 return boost::none;
216 }
217
218 if (format.redBufferSize() > 0 && format.greenBufferSize() > 0 && format.blueBufferSize() > 0
219 && (context.format().redBufferSize() != format.redBufferSize()
220 || context.format().greenBufferSize() != format.greenBufferSize()
221 || context.format().blueBufferSize() != format.blueBufferSize())) {
222
223 dbgOpenGL << "Failed to create an OpenGL context with requested bit depth. Requested:" << format.redBufferSize()
224 << "Actual:" << context.format().redBufferSize();
225 return boost::none;
226 }
227
228 Result result(context);
229
230 dbgOpenGL << "Probe returned" << result.rendererString() << result.driverVersionString() << result.isOpenGLES();
231
232 return result;
233}
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:60
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 50 of file KisOpenGLModeProber.cpp.

51{
53
54 const auto surfaceColorSpace =
56
57 if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::sRGBColorSpace) {
58 // use the default one!
59#ifdef HAVE_HDR
60 } else if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {
62 } else if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {
64#endif
65 }
66
67 return profile;
68}
QSurfaceFormat surfaceformatInUse() const
static KoColorSpaceRegistry * instance()
const KoColorProfile * p709G10Profile() const
const KoColorProfile * p709SRGBProfile() const
const KoColorProfile * p2020PQProfile() const

References KisSurfaceColorSpaceWrapper::bt2020PQColorSpace, KisSurfaceColorSpaceWrapper::fromQtColorSpace(), KoColorSpaceRegistry::instance(), KoColorSpaceRegistry::p2020PQProfile(), KoColorSpaceRegistry::p709G10Profile(), KoColorSpaceRegistry::p709SRGBProfile(), KisSurfaceColorSpaceWrapper::scRGBColorSpace, KisSurfaceColorSpaceWrapper::sRGBColorSpace, and surfaceformatInUse().

◆ surfaceformatInUse()

QSurfaceFormat KisOpenGLModeProber::surfaceformatInUse ( ) const

Definition at line 42 of file KisOpenGLModeProber.cpp.

43{
44 // TODO: use information provided by KisOpenGL instead
45 QOpenGLContext *sharedContext = QOpenGLContext::globalShareContext();
46 QSurfaceFormat format = sharedContext ? sharedContext->format() : QSurfaceFormat::defaultFormat();
47 return format;
48}

◆ useHDRMode()

bool KisOpenGLModeProber::useHDRMode ( ) const

Definition at line 37 of file KisOpenGLModeProber.cpp.

38{
39 return isFormatHDR(QSurfaceFormat::defaultFormat());
40}
static bool isFormatHDR(const QSurfaceFormat &format)

References isFormatHDR().


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