Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 4d345627 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Make HDR code build on systems where patched Qt is not available

You need to add -DHAVE_HDR to enable HDR-related code. But
you will need a patched Qt for that.

The patch also makes the code behave correctly on Linux
systems.

PS:
The patch also makes it possible to select OpenGL ES renderer
on Linux. The renderer is selected fine, but doesn't work for
some reason. I guess some texture format is set incorrectly.
parent ea1bfc81
......@@ -188,6 +188,10 @@ add_feature_info("Foundation Build" FOUNDATION_BUILD "A Foundation build is a bi
option(KRITA_ENABLE_BROKEN_TESTS "Enable tests that are marked as broken" OFF)
add_feature_info("Enable Broken Tests" KRITA_ENABLE_BROKEN_TESTS "Runs broken test when \"make test\" is invoked (use -DKRITA_ENABLE_BROKEN_TESTS=ON to enable).")
option(HAVE_HDR "Enable HDR surface format selection. Available only on certain patched versions of Qt" OFF)
configure_file(config-hdr.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-hdr.h)
add_feature_info("Enable HDR" HAVE_HDR "Enable selection of HDR surface fort Krita window. Needs a particular patched version of Qt")
option(LIMIT_LONG_TESTS "Run long running unittests in a limited quick mode" ON)
configure_file(config-limit-long-tests.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-limit-long-tests.h)
add_feature_info("Limit long tests" LIMIT_LONG_TESTS "Run long running unittests in a limited quick mode")
......
/* config-hdr.h. Generated by cmake from config-hdr.h.cmake */
/* Define if you want to have HDR surface selection capabilities */
#cmakedefine ENABLE_HDR 1
......@@ -179,10 +179,10 @@ extern "C" int main(int argc, char **argv)
KisConfig::RootSurfaceFormat rootSurfaceFormat = KisConfig::rootSurfaceFormat(&kritarc);
KisOpenGL::OpenGLRenderer preferredRenderer = KisOpenGL::RendererAuto;
#ifdef Q_OS_WIN
const QString preferredRendererString = kritarc.value("OpenGLRenderer", "auto").toString();
preferredRenderer = KisOpenGL::convertConfigToOpenGLRenderer(preferredRendererString);
#ifdef Q_OS_WIN
// Force ANGLE to use Direct3D11. D3D9 doesn't support OpenGL ES 3 and WARP
// might get weird crashes atm.
qputenv("QT_ANGLE_PLATFORM", "d3d11");
......
......@@ -21,6 +21,7 @@
#include "kis_dlg_preferences.h"
#include <config-hdr.h>
#include <opengl/kis_opengl.h>
#include <QBitmap>
......@@ -934,8 +935,10 @@ void PerformanceTab::slotFrameClonesLimitChanged(int value)
QString colorSpaceString(QSurfaceFormat::ColorSpace cs, int depth)
{
const QString csString =
#ifdef HAVE_HDR
cs == QSurfaceFormat::bt2020PQColorSpace ? "Rec. 2020 PQ" :
cs == QSurfaceFormat::scRGBColorSpace ? "Rec. 709 Linear" :
#endif
cs == QSurfaceFormat::sRGBColorSpace ? "sRGB" :
cs == QSurfaceFormat::DefaultColorSpace ? "sRGB" :
"Unknown Color Space";
......@@ -964,14 +967,16 @@ DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name)
const QString rendererOpenGLText = i18nc("canvas renderer", "OpenGL");
#ifdef Q_OS_WIN
const QString rendererAngleText = i18nc("canvas renderer", "Direct3D 11 via ANGLE");
lblCurrentRenderer->setText(KisOpenGL::hasOpenGLES() ? rendererAngleText : rendererOpenGLText);
const QString rendererOpenGLESText = i18nc("canvas renderer", "Direct3D 11 via ANGLE");
#else
const QString rendererOpenGLESText = i18nc("canvas renderer", "OpenGL ES");
#endif
lblCurrentRenderer->setText(KisOpenGL::hasOpenGLES() ? rendererOpenGLESText : rendererOpenGLText);
cmbPreferredRenderer->clear();
QString qtPreferredRendererText;
if (KisOpenGL::getQtPreferredOpenGLRenderer() == KisOpenGL::RendererOpenGLES) {
qtPreferredRendererText = rendererAngleText;
qtPreferredRendererText = rendererOpenGLESText;
} else {
qtPreferredRendererText = rendererOpenGLText;
}
......@@ -983,29 +988,18 @@ DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name)
cmbPreferredRenderer->setCurrentIndex(cmbPreferredRenderer->count() - 1);
}
}
#ifdef Q_OS_WIN
if (KisOpenGL::getSupportedOpenGLRenderers() & KisOpenGL::RendererOpenGLES) {
cmbPreferredRenderer->addItem(rendererAngleText, KisOpenGL::RendererOpenGLES);
cmbPreferredRenderer->addItem(rendererOpenGLESText, KisOpenGL::RendererOpenGLES);
if (KisOpenGL::getUserPreferredOpenGLRendererConfig() == KisOpenGL::RendererOpenGLES) {
cmbPreferredRenderer->setCurrentIndex(cmbPreferredRenderer->count() - 1);
}
}
#else
lblPreferredRenderer->setEnabled(false);
cmbPreferredRenderer->setEnabled(false);
cmbPreferredRenderer->clear();
cmbPreferredRenderer->addItem(rendererOpenGLText);
cmbPreferredRenderer->setCurrentIndex(0);
const QString rendererOpenGLESText = i18nc("canvas renderer", "OpenGL ES");
lblCurrentRenderer->setText(KisOpenGL::hasOpenGLES() ? rendererOpenGLESText : rendererOpenGLText);
#endif
#ifdef Q_OS_WIN
if (!(KisOpenGL::getSupportedOpenGLRenderers() &
(KisOpenGL::RendererDesktopGL | KisOpenGL::RendererOpenGLES))) {
#else
if (!KisOpenGL::hasOpenGL()) {
#endif
(KisOpenGL::RendererDesktopGL | KisOpenGL::RendererOpenGLES))) {
grpOpenGL->setEnabled(false);
grpOpenGL->setChecked(false);
chkUseTextureBuffer->setEnabled(false);
......@@ -1031,8 +1025,10 @@ DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name)
lblCurrentRootSurfaceFormat->setText("");
lblHDRWarning->setText("");
cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(QSurfaceFormat::sRGBColorSpace, 8));
#ifdef HAVE_HDR
cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(QSurfaceFormat::bt2020PQColorSpace, 10));
cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(QSurfaceFormat::scRGBColorSpace, 16));
#endif
cmbPreferedRootSurfaceFormat->setCurrentIndex(formatToIndex(KisConfig::BT709_G22));
slotPreferredSurfaceFormatChanged(cmbPreferedRootSurfaceFormat->currentIndex());
......@@ -1080,6 +1076,10 @@ DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name)
slotPreferredSurfaceFormatChanged(cmbPreferedRootSurfaceFormat->currentIndex());
}
#ifndef HAVE_HDR
grpHDRSettings->setVisible(false);
#endif
const QStringList openglWarnings = KisOpenGL::getOpenGLWarnings();
if (openglWarnings.isEmpty()) {
lblOpenGLWarnings->setVisible(false);
......@@ -1141,12 +1141,8 @@ void DisplaySettingsTab::setDefault()
{
KisConfig cfg(true);
cmbPreferredRenderer->setCurrentIndex(0);
#ifdef Q_OS_WIN
if (!(KisOpenGL::getSupportedOpenGLRenderers() &
(KisOpenGL::RendererDesktopGL | KisOpenGL::RendererOpenGLES))) {
#else
if (!KisOpenGL::hasOpenGL()) {
#endif
grpOpenGL->setEnabled(false);
grpOpenGL->setChecked(false);
chkUseTextureBuffer->setEnabled(false);
......@@ -1509,14 +1505,13 @@ bool KisDlgPreferences::editPreferences()
dialog->m_performanceSettings->save();
#ifdef Q_OS_WIN
{
KisOpenGL::OpenGLRenderer renderer = static_cast<KisOpenGL::OpenGLRenderer>(
dialog->m_displaySettings->cmbPreferredRenderer->itemData(
dialog->m_displaySettings->cmbPreferredRenderer->currentIndex()).toInt());
KisOpenGL::setUserPreferredOpenGLRendererConfig(renderer);
}
#endif
if (!cfg.useOpenGL() && dialog->m_displaySettings->grpOpenGL->isChecked())
cfg.setCanvasState("TRY_OPENGL");
cfg.setUseOpenGL(dialog->m_displaySettings->grpOpenGL->isChecked());
......
#include "KisOpenGLModeProber.h"
#include <config-hdr.h>
#include <QApplication>
#include <QOpenGLContext>
#include <QOpenGLFunctions>
......@@ -43,10 +44,12 @@ const KoColorProfile *KisOpenGLModeProber::rootSurfaceColorProfile() const
if (surfaceColorSpace == QSurfaceFormat::sRGBColorSpace) {
// use the default one!
#ifdef HAVE_HDR
} else if (surfaceColorSpace == QSurfaceFormat::scRGBColorSpace) {
profile = KoColorSpaceRegistry::instance()->p709G10Profile();
} else if (surfaceColorSpace == QSurfaceFormat::bt2020PQColorSpace) {
profile = KoColorSpaceRegistry::instance()->p2020PQProfile();
#endif
}
return profile;
......@@ -155,7 +158,9 @@ bool KisOpenGLModeProber::fuzzyCompareColorSpaces(const QSurfaceFormat::ColorSpa
void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceFormat config,
QSurfaceFormat *format)
{
#ifdef HAVE_HDR
if (config == KisConfig::BT2020_PQ) {
format->setRedBufferSize(10);
format->setGreenBufferSize(10);
format->setBlueBufferSize(10);
......@@ -167,7 +172,16 @@ void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceForm
format->setBlueBufferSize(16);
format->setAlphaBufferSize(16);
format->setColorSpace(QSurfaceFormat::scRGBColorSpace);
} else {
} else
#else
if (config == KisConfig::BT2020_PQ) {
qWarning() << "WARNING: Bt.2020 PQ surface type is not supoprted by this build of Krita";
} else if (config == KisConfig::BT709_G10) {
qWarning() << "WARNING: scRGB surface type is not supoprted by this build of Krita";
}
#endif
{
format->setRedBufferSize(8);
format->setGreenBufferSize(8);
format->setBlueBufferSize(8);
......@@ -179,6 +193,8 @@ void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceForm
bool KisOpenGLModeProber::isFormatHDR(const QSurfaceFormat &format)
{
#ifdef HAVE_HDR
bool isBt2020PQ =
format.colorSpace() == QSurfaceFormat::bt2020PQColorSpace &&
format.redBufferSize() == 10 &&
......@@ -194,6 +210,9 @@ bool KisOpenGLModeProber::isFormatHDR(const QSurfaceFormat &format)
format.alphaBufferSize() == 16;
return isBt2020PQ || isBt709G10;
#else
return false;
#endif
}
KisOpenGLModeProber::Result::Result(QOpenGLContext &context) {
......
......@@ -3,16 +3,24 @@
#include "kis_debug.h"
#include <QOpenGLContext>
//#include <QtGui/5.11.2/QtGui/qpa/qplatformnativeinterface.h>
#include <QtGui/5.12.0/QtGui/qpa/qplatformnativeinterface.h>
#include <QGuiApplication>
#include <QWindow>
#include <config-hdr.h>
#ifdef Q_OS_WIN
#if (QT_VERSION == QT_VERSION_CHECK(5, 11, 2))
#include <QtGui/5.11.2/QtGui/qpa/qplatformnativeinterface.h>
#elif (QT_VERSION == QT_VERSION_CHECK(5, 12, 0))
#include <QtGui/5.12.0/QtGui/qpa/qplatformnativeinterface.h>
#endif
#include <d3d11.h>
#include <wrl/client.h>
#include <dxgi1_6.h>
#include "EGL/egl.h"
#include "EGL/eglext.h"
#endif
namespace {
struct EGLException {
......@@ -36,7 +44,9 @@ void getProcAddressSafe(QOpenGLContext *context, const char *funcName, FuncType
}
}
#ifdef Q_OS_WIN
typedef const char *(EGLAPIENTRYP PFNEGLQUERYSTRINGPROC) (EGLDisplay dpy, EGLint name);
#endif
}
......@@ -47,7 +57,9 @@ struct KisScreenInformationAdapter::Private
QOpenGLContext *context;
QString errorString;
#ifdef Q_OS_WIN
Microsoft::WRL::ComPtr<IDXGIAdapter1> dxgiAdapter;
#endif
};
KisScreenInformationAdapter::KisScreenInformationAdapter(QOpenGLContext *context)
......@@ -67,6 +79,8 @@ void KisScreenInformationAdapter::Private::initialize(QOpenGLContext *newContext
try {
#ifdef Q_OS_WIN
if (!context->isOpenGLES()) {
throw EGLException("the context is not OpenGL ES");
}
......@@ -140,16 +154,27 @@ void KisScreenInformationAdapter::Private::initialize(QOpenGLContext *newContext
this->dxgiAdapter = dxgiAdapter;
}
#else
throw EGLException("current platform doesn't support fetching display information");
#endif
} catch (EGLException &e) {
this->context = 0;
this->errorString = e.what();
#ifdef Q_OS_WIN
this->dxgiAdapter.Reset();
#endif
}
}
bool KisScreenInformationAdapter::isValid() const
{
#ifdef Q_OS_WIN
return m_d->context && m_d->dxgiAdapter;
#else
return false;
#endif
}
QString KisScreenInformationAdapter::errorString() const
......@@ -161,6 +186,8 @@ KisScreenInformationAdapter::ScreenInfo KisScreenInformationAdapter::infoForScre
{
ScreenInfo info;
#ifdef Q_OS_WIN
QPlatformNativeInterface *nativeInterface = qGuiApp->platformNativeInterface();
HMONITOR monitor = reinterpret_cast<HMONITOR>(nativeInterface->nativeResourceForScreen("handle", screen));
......@@ -203,9 +230,17 @@ KisScreenInformationAdapter::ScreenInfo KisScreenInformationAdapter::infoForScre
if (desc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709) {
info.colorSpace = QSurfaceFormat::sRGBColorSpace;
} else if (desc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709) {
#ifdef HAVE_HDR
info.colorSpace = QSurfaceFormat::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;
#else
qWarning("WARNING: bt2020-pq display color space is not supported by Qt's build");
#endif
} else {
qWarning("WARNING: unknown display color space! 0x%X", desc.ColorSpace);
}
......@@ -217,6 +252,8 @@ KisScreenInformationAdapter::ScreenInfo KisScreenInformationAdapter::infoForScre
i++;
}
#endif
Q_UNUSED(screen);
return info;
}
......
......@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <config-hdr.h>
#include "opengl/kis_opengl.h"
#include "opengl/kis_opengl_p.h"
......@@ -129,17 +130,20 @@ void KisOpenGL::initialize()
debugOut << "\n Supports deprecated functions" << openGLCheckResult->supportsDeprecatedFunctions();
debugOut << "\n is OpenGL ES:" << openGLCheckResult->isOpenGLES();
#ifdef Q_OS_WIN
debugOut << "\n\nQPA OpenGL Detection Info";
debugOut << "\n supportsDesktopGL:" << bool(g_supportedRenderers & RendererDesktopGL);
#ifdef Q_OS_WIN
debugOut << "\n supportsAngleD3D11:" << bool(g_supportedRenderers & RendererOpenGLES);
debugOut << "\n isQtPreferAngle:" << bool(g_rendererPreferredByQt == RendererOpenGLES);
#else
debugOut << "\n supportsOpenGLES:" << bool(g_supportedRenderers & RendererOpenGLES);
debugOut << "\n isQtPreferOpenGLES:" << bool(g_rendererPreferredByQt == RendererOpenGLES);
#endif
debugOut << "\n== log ==\n";
debugOut.noquote();
debugOut << g_surfaceFormatDetectionLog;
debugOut.resetFormat();
debugOut << "\n== end log ==";
#endif
dbgOpenGL.noquote().nospace() << g_debugText;
......@@ -510,8 +514,13 @@ public:
private:
bool isHDRFormat(const QSurfaceFormat &f) const {
#ifdef HAVE_HDR
return f.colorSpace() == QSurfaceFormat::bt2020PQColorSpace ||
f.colorSpace() == QSurfaceFormat::scRGBColorSpace;
#else
Q_UNUSED(f);
return false;
#endif
}
bool isBlacklisted(const QSurfaceFormat &f) const {
......@@ -523,8 +532,12 @@ private:
}
bool doPreferHDR() const {
#ifdef HAVE_HDR
return m_preferredColorSpace == QSurfaceFormat::bt2020PQColorSpace ||
m_preferredColorSpace == QSurfaceFormat::scRGBColorSpace;
#else
return false;
#endif
}
bool isPreferredColorSpace(const QSurfaceFormat::ColorSpace cs) const {
......@@ -566,7 +579,12 @@ QSurfaceFormat KisOpenGL::selectSurfaceFormat(KisOpenGL::OpenGLRenderer preferre
using Info = boost::optional<KisOpenGLModeProber::Result>;
QVector<QSurfaceFormat::RenderableType> renderers({QSurfaceFormat::OpenGLES, QSurfaceFormat::OpenGL});
#ifdef HAVE_HDR
QVector<KisConfig::RootSurfaceFormat> formatSymbols({KisConfig::BT709_G22, KisConfig::BT709_G10, KisConfig::BT2020_PQ});
#else
QVector<KisConfig::RootSurfaceFormat> formatSymbols({KisConfig::BT709_G22});
#endif
QVector<QSurfaceFormat> preferredFormats;
Q_FOREACH (const QSurfaceFormat::RenderableType renderer, renderers) {
......@@ -583,9 +601,17 @@ QSurfaceFormat KisOpenGL::selectSurfaceFormat(KisOpenGL::OpenGLRenderer preferre
FormatPositionLess compareOp;
compareOp.setPreferredRendererByQt(info->isOpenGLES() ? QSurfaceFormat::OpenGLES : QSurfaceFormat::OpenGL);
compareOp.setPreferredColorSpace(preferredRootSurfaceFormat == KisConfig::BT709_G22 ? QSurfaceFormat::sRGBColorSpace :
preferredRootSurfaceFormat == KisConfig::BT709_G10 ? QSurfaceFormat::scRGBColorSpace :
QSurfaceFormat::bt2020PQColorSpace);
#ifdef HAVE_HDR
compareOp.setPreferredColorSpace(
preferredRootSurfaceFormat == KisConfig::BT709_G22 ? QSurfaceFormat::sRGBColorSpace :
preferredRootSurfaceFormat == KisConfig::BT709_G10 ? QSurfaceFormat::scRGBColorSpace :
QSurfaceFormat::bt2020PQColorSpace);
#else
Q_UNUSED(preferredRootSurfaceFormat);
compareOp.setPreferredColorSpace(QSurfaceFormat::sRGBColorSpace);
#endif
#ifdef Q_OS_WIN
compareOp.setPreferredRendererByHDR(QSurfaceFormat::OpenGLES);
#endif
......@@ -646,6 +672,8 @@ QSurfaceFormat KisOpenGL::selectSurfaceFormat(KisOpenGL::OpenGLRenderer preferre
Info info = KisOpenGLModeProber::instance()->probeFormat(format);
if (info && info->isSupportedVersion()) {
#ifdef Q_OS_WIN
// HACK: Block ANGLE with Direct3D9
// Direct3D9 does not give OpenGL ES 3.0
// Some versions of ANGLE returns OpenGL version 3.0 incorrectly
......@@ -657,6 +685,7 @@ QSurfaceFormat KisOpenGL::selectSurfaceFormat(KisOpenGL::OpenGLRenderer preferre
continue;
}
#endif
dbgDetection() << "Found format:" << format;
dbgDetection() << " " << format.renderableType();
......
......@@ -48,7 +48,6 @@ public:
};
public:
#ifdef Q_OS_WIN
enum OpenGLRenderer {
RendererNone = 0x00,
RendererAuto = 0x01,
......@@ -70,7 +69,6 @@ public:
static void setUserPreferredOpenGLRendererConfig(OpenGLRenderer renderer);
static QString convertOpenGLRendererToConfig(OpenGLRenderer renderer);
static OpenGLRenderer convertConfigToOpenGLRenderer(QString renderer);
#endif
/// Request OpenGL version 3.2
static void initialize();
......
add_subdirectory(defaultdockers)
add_subdirectory(smallcolorselector)
if(HAVE_OPENEXR)
add_subdirectory(smallcolorselector)
endif()
add_subdirectory(specificcolorselector)
add_subdirectory(digitalmixer)
add_subdirectory(advancedcolorselector)
......
......@@ -17,6 +17,7 @@
*/
#include "lutdocker_dock.h"
#include <config-hdr.h>
#include <sstream>
......@@ -243,8 +244,11 @@ bool LutDockerDock::canChangeExposureAndGamma() const
m_colorManagement->currentIndex() != (int)KisOcioConfiguration::INTERNAL;
const bool exposureManagementEnabled =
externalColorManagementEnabled ||
KisOpenGLModeProber::instance()->surfaceformatInUse().colorSpace() == QSurfaceFormat::scRGBColorSpace;
externalColorManagementEnabled
#ifdef HAVE_HDR
|| KisOpenGLModeProber::instance()->surfaceformatInUse().colorSpace() == QSurfaceFormat::scRGBColorSpace
#endif
;
return exposureManagementEnabled;
}
......
......@@ -2,7 +2,7 @@
#define KISGLIMAGEF16_H
#include <QSharedDataPointer>
#include <openexr/half.h>
#include <half.h>
#include <boost/operators.hpp>
class QSize;
......
......@@ -4,6 +4,7 @@
#include <QFile>
#include <QResizeEvent>
#include "kis_debug.h"
#include <config-hdr.h>
#include "KisGLImageF16.h"
......@@ -40,7 +41,10 @@ KisGLImageWidget::KisGLImageWidget(QSurfaceFormat::ColorSpace colorSpace,
m_texture(QOpenGLTexture::Target2D)
{
setTextureFormat(GL_RGBA16F);
#ifdef HAVE_HDR
setTextureColorSpace(colorSpace);
#endif
setUpdateBehavior(QOpenGLWidget::NoPartialUpdate);
}
......
......@@ -34,7 +34,7 @@ extern "C" int main(int argc, char **argv)
qsrand(time(0));
KLocalizedString::setApplicationDomain("kritarunner");
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
KisOpenGL::setDefaultFormat();
KisOpenGL::testingInitializeDefaultSurfaceFormat();
// first create the application so we can create a pixmap
......
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