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

28{
29}

◆ ~KisOpenGLModeProber()

KisOpenGLModeProber::~KisOpenGLModeProber ( )

Definition at line 31 of file KisOpenGLModeProber.cpp.

32{
33
34}

Member Function Documentation

◆ angleRendererToString()

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

Definition at line 337 of file KisOpenGLModeProber.cpp.

338{
339 QString value;
340
341 switch (renderer) {
343 break;
345 value = "d3d9";
346 break;
348 value = "d3d11";
349 break;
351 value = "warp";
352 break;
353 };
354
355 return value;
356}
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 248 of file KisOpenGLModeProber.cpp.

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

37{
38 return s_instance;
39}

◆ isFormatHDR()

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

Definition at line 312 of file KisOpenGLModeProber.cpp.

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

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

55{
57
58 const auto surfaceColorSpace =
60
61 if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::sRGBColorSpace) {
62 // use the default one!
63#ifdef HAVE_HDR
64 } else if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {
66 } else if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {
68#endif
69 }
70
71 return profile;
72}
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 46 of file KisOpenGLModeProber.cpp.

47{
48 // TODO: use information provided by KisOpenGL instead
49 QOpenGLContext *sharedContext = QOpenGLContext::globalShareContext();
50 QSurfaceFormat format = sharedContext ? sharedContext->format() : QSurfaceFormat::defaultFormat();
51 return format;
52}

◆ useHDRMode()

bool KisOpenGLModeProber::useHDRMode ( ) const

Definition at line 41 of file KisOpenGLModeProber.cpp.

42{
43 return isFormatHDR(QSurfaceFormat::defaultFormat());
44}
static bool isFormatHDR(const QSurfaceFormat &format)

References isFormatHDR().


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