Commit 2924b7b9 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Make Krita compile on Qt 5.9

The patch basically adds a fake enum KisSurfaceColorSpace, when old
Qt is found.
parent 9c521e39
......@@ -4,7 +4,7 @@ message(STATUS "Using CMake version: ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
set(MIN_QT_VERSION 5.10.0)
set(MIN_QT_VERSION 5.6.0)
set(MIN_FRAMEWORKS_VERSION 5.18.0)
......
......@@ -991,15 +991,15 @@ void PerformanceTab::slotFrameClonesLimitChanged(int value)
#include <QOpenGLContext>
#include <QScreen>
QString colorSpaceString(QSurfaceFormat::ColorSpace cs, int depth)
QString colorSpaceString(KisSurfaceColorSpace cs, int depth)
{
const QString csString =
#ifdef HAVE_HDR
cs == QSurfaceFormat::bt2020PQColorSpace ? "Rec. 2020 PQ" :
cs == QSurfaceFormat::scRGBColorSpace ? "Rec. 709 Linear" :
cs == KisSurfaceColorSpace::bt2020PQColorSpace ? "Rec. 2020 PQ" :
cs == KisSurfaceColorSpace::scRGBColorSpace ? "Rec. 709 Linear" :
#endif
cs == QSurfaceFormat::sRGBColorSpace ? "sRGB" :
cs == QSurfaceFormat::DefaultColorSpace ? "sRGB" :
cs == KisSurfaceColorSpace::sRGBColorSpace ? "sRGB" :
cs == KisSurfaceColorSpace::DefaultColorSpace ? "sRGB" :
"Unknown Color Space";
return QString("%1 (%2 bit)").arg(csString).arg(depth);
......@@ -1083,10 +1083,10 @@ DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name)
lblCurrentDisplayFormat->setText("");
lblCurrentRootSurfaceFormat->setText("");
lblHDRWarning->setText("");
cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(QSurfaceFormat::sRGBColorSpace, 8));
cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(KisSurfaceColorSpace::sRGBColorSpace, 8));
#ifdef HAVE_HDR
cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(QSurfaceFormat::bt2020PQColorSpace, 10));
cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(QSurfaceFormat::scRGBColorSpace, 16));
cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(KisSurfaceColorSpace::bt2020PQColorSpace, 10));
cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(KisSurfaceColorSpace::scRGBColorSpace, 16));
#endif
cmbPreferedRootSurfaceFormat->setCurrentIndex(formatToIndex(KisConfig::BT709_G22));
slotPreferredSurfaceFormatChanged(cmbPreferedRootSurfaceFormat->currentIndex());
......@@ -1128,9 +1128,13 @@ DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name)
}
const QSurfaceFormat currentFormat = KisOpenGLModeProber::instance()->surfaceformatInUse();
lblCurrentRootSurfaceFormat->setText(colorSpaceString(currentFormat.colorSpace(), currentFormat.redBufferSize()));
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
KisSurfaceColorSpace colorSpace = currentFormat.colorSpace();
#else
KisSurfaceColorSpace colorSpace = KisSurfaceColorSpace::DefaultColorSpace;
#endif
lblCurrentRootSurfaceFormat->setText(colorSpaceString(colorSpace, currentFormat.redBufferSize()));
cmbPreferedRootSurfaceFormat->setCurrentIndex(formatToIndex(cfg.rootSurfaceFormat()));
connect(cmbPreferedRootSurfaceFormat, SIGNAL(currentIndexChanged(int)), SLOT(slotPreferredSurfaceFormatChanged(int)));
slotPreferredSurfaceFormatChanged(cmbPreferedRootSurfaceFormat->currentIndex());
}
......@@ -1264,7 +1268,7 @@ void DisplaySettingsTab::slotPreferredSurfaceFormatChanged(int index)
KisScreenInformationAdapter::ScreenInfo info = adapter.infoForScreen(screen);
if (info.isValid()) {
if (cmbPreferedRootSurfaceFormat->currentIndex() != formatToIndex(KisConfig::BT709_G22) &&
info.colorSpace == QSurfaceFormat::sRGBColorSpace) {
info.colorSpace == KisSurfaceColorSpace::sRGBColorSpace) {
lblHDRWarning->setText(i18n("WARNING: current display doesn't support HDR rendering"));
} else {
lblHDRWarning->setText("");
......
......@@ -58,19 +58,23 @@ QSurfaceFormat KisOpenGLModeProber::surfaceformatInUse() const
const KoColorProfile *KisOpenGLModeProber::rootSurfaceColorProfile() const
{
const QSurfaceFormat::ColorSpace surfaceColorSpace = surfaceformatInUse().colorSpace();
const KoColorProfile *profile = KoColorSpaceRegistry::instance()->p709SRGBProfile();
if (surfaceColorSpace == QSurfaceFormat::sRGBColorSpace) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
const KisSurfaceColorSpace surfaceColorSpace = surfaceformatInUse().colorSpace();
if (surfaceColorSpace == KisSurfaceColorSpace::sRGBColorSpace) {
// use the default one!
#ifdef HAVE_HDR
} else if (surfaceColorSpace == QSurfaceFormat::scRGBColorSpace) {
} else if (surfaceColorSpace == KisSurfaceColorSpace::scRGBColorSpace) {
profile = KoColorSpaceRegistry::instance()->p709G10Profile();
} else if (surfaceColorSpace == QSurfaceFormat::bt2020PQColorSpace) {
} else if (surfaceColorSpace == KisSurfaceColorSpace::bt2020PQColorSpace) {
profile = KoColorSpaceRegistry::instance()->p2020PQProfile();
#endif
}
#endif
return profile;
}
......@@ -157,21 +161,23 @@ KisOpenGLModeProber::probeFormat(const QSurfaceFormat &format, bool adjustGlobal
return boost::none;
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
if (!fuzzyCompareColorSpaces(context.format().colorSpace(), format.colorSpace())) {
dbgOpenGL << "Failed to create an OpenGL context with requested color space. Requested:" << format.colorSpace() << "Actual:" << context.format().colorSpace();
return boost::none;
}
#endif
return Result(context);
}
bool KisOpenGLModeProber::fuzzyCompareColorSpaces(const QSurfaceFormat::ColorSpace &lhs, const QSurfaceFormat::ColorSpace &rhs)
bool KisOpenGLModeProber::fuzzyCompareColorSpaces(const KisSurfaceColorSpace &lhs, const KisSurfaceColorSpace &rhs)
{
return lhs == rhs ||
((lhs == QSurfaceFormat::DefaultColorSpace ||
lhs == QSurfaceFormat::sRGBColorSpace) &&
(rhs == QSurfaceFormat::DefaultColorSpace ||
rhs == QSurfaceFormat::sRGBColorSpace));
((lhs == KisSurfaceColorSpace::DefaultColorSpace ||
lhs == KisSurfaceColorSpace::sRGBColorSpace) &&
(rhs == KisSurfaceColorSpace::DefaultColorSpace ||
rhs == KisSurfaceColorSpace::sRGBColorSpace));
}
void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceFormat config,
......@@ -184,13 +190,13 @@ void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceForm
format->setGreenBufferSize(10);
format->setBlueBufferSize(10);
format->setAlphaBufferSize(2);
format->setColorSpace(QSurfaceFormat::bt2020PQColorSpace);
format->setColorSpace(KisSurfaceColorSpace::bt2020PQColorSpace);
} else if (config == KisConfig::BT709_G10) {
format->setRedBufferSize(16);
format->setGreenBufferSize(16);
format->setBlueBufferSize(16);
format->setAlphaBufferSize(16);
format->setColorSpace(QSurfaceFormat::scRGBColorSpace);
format->setColorSpace(KisSurfaceColorSpace::scRGBColorSpace);
} else
#else
if (config == KisConfig::BT2020_PQ) {
......@@ -205,8 +211,11 @@ void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceForm
format->setGreenBufferSize(8);
format->setBlueBufferSize(8);
format->setAlphaBufferSize(8);
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// TODO: check if we can use real sRGB space here
format->setColorSpace(QSurfaceFormat::DefaultColorSpace);
format->setColorSpace(KisSurfaceColorSpace::DefaultColorSpace);
#endif
}
}
......@@ -215,14 +224,14 @@ bool KisOpenGLModeProber::isFormatHDR(const QSurfaceFormat &format)
#ifdef HAVE_HDR
bool isBt2020PQ =
format.colorSpace() == QSurfaceFormat::bt2020PQColorSpace &&
format.colorSpace() == KisSurfaceColorSpace::bt2020PQColorSpace &&
format.redBufferSize() == 10 &&
format.greenBufferSize() == 10 &&
format.blueBufferSize() == 10 &&
format.alphaBufferSize() == 2;
bool isBt709G10 =
format.colorSpace() == QSurfaceFormat::scRGBColorSpace &&
format.colorSpace() == KisSurfaceColorSpace::scRGBColorSpace &&
format.redBufferSize() == 16 &&
format.greenBufferSize() == 16 &&
format.blueBufferSize() == 16 &&
......
......@@ -24,6 +24,7 @@
#include "kritaui_export.h"
#include "kis_config.h"
#include <QSurfaceFormat>
#include "KisSurfaceColorSpace.h"
#include <boost/optional.hpp>
class KoColorProfile;
......@@ -47,8 +48,8 @@ public:
boost::optional<Result> probeFormat(const QSurfaceFormat &format,
bool adjustGlobalState = true);
static bool fuzzyCompareColorSpaces(const QSurfaceFormat::ColorSpace &lhs,
const QSurfaceFormat::ColorSpace &rhs);
static bool fuzzyCompareColorSpaces(const KisSurfaceColorSpace &lhs,
const KisSurfaceColorSpace &rhs);
public:
static void initSurfaceFormatFromConfig(KisConfig::RootSurfaceFormat config,
......
......@@ -249,19 +249,19 @@ KisScreenInformationAdapter::ScreenInfo KisScreenInformationAdapter::infoForScre
info.maxLuminance = desc.MaxLuminance;
info.maxFullFrameLuminance = desc.MaxFullFrameLuminance;
info.colorSpace = QSurfaceFormat::DefaultColorSpace;
info.colorSpace = KisSurfaceColorSpace::DefaultColorSpace;
if (desc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709) {
info.colorSpace = QSurfaceFormat::sRGBColorSpace;
info.colorSpace = KisSurfaceColorSpace::sRGBColorSpace;
} else if (desc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709) {
#ifdef HAVE_HDR
info.colorSpace = QSurfaceFormat::scRGBColorSpace;
info.colorSpace = KisSurfaceColorSpace::scRGBColorSpace;
#else
qWarning("WARNING: scRGB display color space is not supported by Qt's build");
#endif
} else if (desc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020) {
#ifdef HAVE_HDR
info.colorSpace = QSurfaceFormat::bt2020PQColorSpace;
info.colorSpace = KisSurfaceColorSpace::bt2020PQColorSpace;
#else
qWarning("WARNING: bt2020-pq display color space is not supported by Qt's build");
#endif
......
......@@ -22,6 +22,7 @@
#include "kritaui_export.h"
#include <QScopedPointer>
#include <QSurfaceFormat>
#include "KisSurfaceColorSpace.h"
class QScreen;
class QOpenGLContext;
......@@ -32,7 +33,7 @@ public:
struct ScreenInfo {
QScreen *screen = 0;
int bitsPerColor = 0;
QSurfaceFormat::ColorSpace colorSpace = QSurfaceFormat::DefaultColorSpace;
KisSurfaceColorSpace colorSpace = KisSurfaceColorSpace::DefaultColorSpace;
qreal redPrimary[2] = {0, 0};
qreal greenPrimary[2] = {0, 0};
qreal bluePrimary[2] = {0, 0};
......
/*
* Copyright (c) 2019 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KISSURFACECOLORSPACE_H
#define KISSURFACECOLORSPACE_H
#include <QSurfaceFormat>
/**
* This file is a simple workaround for building our surface format
* selection code on Qt older than 5.10, which doesn't have this feature
*
* TODO: remove this file when we drop support for Qt 5.9 LTS
*/
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
using KisSurfaceColorSpace = QSurfaceFormat::ColorSpace;
#else
enum KisSurfaceColorSpace {
DefaultColorSpace,
sRGBColorSpace
};
#endif
#endif // KISSURFACECOLORSPACE_H
......@@ -445,7 +445,7 @@ public:
}
bool operator()(const QSurfaceFormat &lhs, const QSurfaceFormat &rhs) const {
KIS_SAFE_ASSERT_RECOVER_NOOP(m_preferredColorSpace != QSurfaceFormat::DefaultColorSpace);
KIS_SAFE_ASSERT_RECOVER_NOOP(m_preferredColorSpace != KisSurfaceColorSpace::DefaultColorSpace);
ORDER_BY(isPreferredColorSpace(lhs.colorSpace()),
isPreferredColorSpace(rhs.colorSpace()));
......@@ -482,7 +482,7 @@ public:
public:
void setPreferredColorSpace(const QSurfaceFormat::ColorSpace &preferredColorSpace) {
void setPreferredColorSpace(const KisSurfaceColorSpace &preferredColorSpace) {
m_preferredColorSpace = preferredColorSpace;
}
......@@ -506,7 +506,7 @@ public:
m_openGLESBlacklisted = openGLESBlacklisted;
}
QSurfaceFormat::ColorSpace preferredColorSpace() const {
KisSurfaceColorSpace preferredColorSpace() const {
return m_preferredColorSpace;
}
......@@ -517,8 +517,8 @@ public:
private:
bool isHDRFormat(const QSurfaceFormat &f) const {
#ifdef HAVE_HDR
return f.colorSpace() == QSurfaceFormat::bt2020PQColorSpace ||
f.colorSpace() == QSurfaceFormat::scRGBColorSpace;
return f.colorSpace() == KisSurfaceColorSpace::bt2020PQColorSpace ||
f.colorSpace() == KisSurfaceColorSpace::scRGBColorSpace;
#else
Q_UNUSED(f);
return false;
......@@ -535,20 +535,20 @@ private:
bool doPreferHDR() const {
#ifdef HAVE_HDR
return m_preferredColorSpace == QSurfaceFormat::bt2020PQColorSpace ||
m_preferredColorSpace == QSurfaceFormat::scRGBColorSpace;
return m_preferredColorSpace == KisSurfaceColorSpace::bt2020PQColorSpace ||
m_preferredColorSpace == KisSurfaceColorSpace::scRGBColorSpace;
#else
return false;
#endif
}
bool isPreferredColorSpace(const QSurfaceFormat::ColorSpace cs) const {
bool isPreferredColorSpace(const KisSurfaceColorSpace cs) const {
return KisOpenGLModeProber::fuzzyCompareColorSpaces(m_preferredColorSpace, cs);
return false;
}
private:
QSurfaceFormat::ColorSpace m_preferredColorSpace = QSurfaceFormat::DefaultColorSpace;
KisSurfaceColorSpace m_preferredColorSpace = KisSurfaceColorSpace::DefaultColorSpace;
QSurfaceFormat::RenderableType m_preferredRendererByQt = QSurfaceFormat::OpenGL;
QSurfaceFormat::RenderableType m_preferredRendererByUser = QSurfaceFormat::DefaultRenderableType;
QSurfaceFormat::RenderableType m_preferredRendererByHDR = QSurfaceFormat::DefaultRenderableType;
......@@ -606,12 +606,12 @@ QSurfaceFormat KisOpenGL::selectSurfaceFormat(KisOpenGL::OpenGLRenderer preferre
#ifdef HAVE_HDR
compareOp.setPreferredColorSpace(
preferredRootSurfaceFormat == KisConfig::BT709_G22 ? QSurfaceFormat::sRGBColorSpace :
preferredRootSurfaceFormat == KisConfig::BT709_G10 ? QSurfaceFormat::scRGBColorSpace :
QSurfaceFormat::bt2020PQColorSpace);
preferredRootSurfaceFormat == KisConfig::BT709_G22 ? KisSurfaceColorSpace::sRGBColorSpace :
preferredRootSurfaceFormat == KisConfig::BT709_G10 ? KisSurfaceColorSpace::scRGBColorSpace :
KisSurfaceColorSpace::bt2020PQColorSpace);
#else
Q_UNUSED(preferredRootSurfaceFormat);
compareOp.setPreferredColorSpace(QSurfaceFormat::sRGBColorSpace);
compareOp.setPreferredColorSpace(KisSurfaceColorSpace::sRGBColorSpace);
#endif
#ifdef Q_OS_WIN
......@@ -669,8 +669,11 @@ QSurfaceFormat KisOpenGL::selectSurfaceFormat(KisOpenGL::OpenGLRenderer preferre
QSurfaceFormat resultFormat = defaultFormat;
Q_FOREACH (const QSurfaceFormat &format, preferredFormats) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
dbgDetection() <<"Probing format..." << format.colorSpace() << format.renderableType();
#else
dbgDetection() <<"Probing format..." << format.renderableType();
#endif
Info info = KisOpenGLModeProber::instance()->probeFormat(format);
if (info && info->isSupportedVersion()) {
......@@ -699,8 +702,12 @@ QSurfaceFormat KisOpenGL::selectSurfaceFormat(KisOpenGL::OpenGLRenderer preferre
{
const bool colorSpaceIsCorrect =
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
KisOpenGLModeProber::fuzzyCompareColorSpaces(compareOp.preferredColorSpace(),
resultFormat.colorSpace());
#else
true;
#endif
const bool rendererIsCorrect =
compareOp.preferredRendererByUser() == QSurfaceFormat::DefaultRenderableType ||
......
......@@ -243,10 +243,19 @@ bool LutDockerDock::canChangeExposureAndGamma() const
const bool externalColorManagementEnabled =
m_colorManagement->currentIndex() != (int)KisOcioConfiguration::INTERNAL;
#ifdef HAVE_HDR
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
KisSurfaceColorSpace currentColorSpace = KisOpenGLModeProber::instance()->surfaceformatInUse().colorSpace();
#else
KisSurfaceColorSpace currentColorSpace = KisSurfaceColorSpace::DefaultColorSpace;
#endif
#endif
const bool exposureManagementEnabled =
externalColorManagementEnabled
#ifdef HAVE_HDR
|| KisOpenGLModeProber::instance()->surfaceformatInUse().colorSpace() == QSurfaceFormat::scRGBColorSpace
|| currentColorSpace == KisSurfaceColorSpace::scRGBColorSpace
#endif
;
......
......@@ -28,7 +28,7 @@ KisClickableGLImageWidget::KisClickableGLImageWidget(QWidget *parent)
{
}
KisClickableGLImageWidget::KisClickableGLImageWidget(QSurfaceFormat::ColorSpace colorSpace, QWidget *parent)
KisClickableGLImageWidget::KisClickableGLImageWidget(KisSurfaceColorSpace colorSpace, QWidget *parent)
: KisGLImageWidget(colorSpace, parent)
{
}
......
......@@ -42,7 +42,7 @@ public:
public:
KisClickableGLImageWidget(QWidget *parent = nullptr);
KisClickableGLImageWidget(QSurfaceFormat::ColorSpace colorSpace,
KisClickableGLImageWidget(KisSurfaceColorSpace colorSpace,
QWidget *parent = nullptr);
~KisClickableGLImageWidget();
......
......@@ -50,11 +50,11 @@ inline void rectToTexCoords(QVector2D* texCoords, const QRectF &rc)
}
KisGLImageWidget::KisGLImageWidget(QWidget *parent)
: KisGLImageWidget(QSurfaceFormat::sRGBColorSpace, parent)
: KisGLImageWidget(KisSurfaceColorSpace::sRGBColorSpace, parent)
{
}
KisGLImageWidget::KisGLImageWidget(QSurfaceFormat::ColorSpace colorSpace,
KisGLImageWidget::KisGLImageWidget(KisSurfaceColorSpace colorSpace,
QWidget *parent)
: QOpenGLWidget(parent),
m_texture(QOpenGLTexture::Target2D)
......
......@@ -27,6 +27,7 @@
#include <QOpenGLBuffer>
#include <QTransform>
#include <KisGLImageF16.h>
#include <opengl/KisSurfaceColorSpace.h>
class KisGLImageWidget : public QOpenGLWidget, protected QOpenGLFunctions
......@@ -34,7 +35,7 @@ class KisGLImageWidget : public QOpenGLWidget, protected QOpenGLFunctions
Q_OBJECT
public:
KisGLImageWidget(QWidget *parent = nullptr);
KisGLImageWidget(QSurfaceFormat::ColorSpace colorSpace,
KisGLImageWidget(KisSurfaceColorSpace colorSpace,
QWidget *parent = nullptr);
~KisGLImageWidget();
......
......@@ -125,7 +125,7 @@ KisSmallColorWidget::KisSmallColorWidget(QWidget* parent)
}
const QSurfaceFormat::ColorSpace colorSpace = QSurfaceFormat::DefaultColorSpace;
const KisSurfaceColorSpace colorSpace = KisSurfaceColorSpace::DefaultColorSpace;
d->hueWidget = new KisClickableGLImageWidget(colorSpace, this);
d->hueWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment