From c2ab12e2d054d7d21575efe6947c971dec1650f8 Mon Sep 17 00:00:00 2001 From: wang-bin Date: Thu, 11 Jun 2015 18:02:56 +0800 Subject: [PATCH] examples: add angle d3d option to swith d3d9/11. angle is enabled --- examples/common/Config.cpp | 20 +++++++++++++++- examples/common/Config.h | 5 ++++ examples/common/common.cpp | 37 +++++++++++++++++++++-------- examples/player/config/MiscPage.cpp | 11 +++++++-- examples/player/config/MiscPage.h | 2 ++ 5 files changed, 62 insertions(+), 13 deletions(-) diff --git a/examples/common/Config.cpp b/examples/common/Config.cpp index 219bbde2d..dc72d2414 100644 --- a/examples/common/Config.cpp +++ b/examples/common/Config.cpp @@ -109,7 +109,9 @@ class Config::Data avfilterAudio = settings.value("options", "").toString(); settings.endGroup(); settings.beginGroup("opengl"); - angle = settings.value("angle", false).toBool(); + angle = settings.value("angle", true).toBool(); + // d3d11 bad performance (gltexsubimage2d) + angle_dx = settings.value("angle_platform", "d3d9").toString(); settings.endGroup(); settings.beginGroup("buffer"); @@ -167,6 +169,7 @@ class Config::Data settings.endGroup(); settings.beginGroup("opengl"); settings.setValue("angle", angle); + settings.setValue("angle_platform", angle_dx); settings.endGroup(); settings.beginGroup("buffer"); settings.setValue("value", buffer_value); @@ -207,6 +210,7 @@ class Config::Data int preview_w, preview_h; bool angle; + QString angle_dx; bool abort_timeout; qreal timeout; int buffer_value; @@ -650,6 +654,20 @@ Config& Config::setANGLE(bool value) return *this; } +QString Config::getANGLEPlatform() const +{ + return mpData->angle_dx; +} + +Config& Config::setANGLEPlatform(const QString& value) +{ + if (mpData->angle_dx == value) + return *this; + mpData->angle_dx = value; + emit ANGLEPlatformChanged(); + return *this; +} + int Config::bufferValue() const { return mpData->buffer_value; diff --git a/examples/common/Config.h b/examples/common/Config.h index 7da756db3..cfbef9d93 100644 --- a/examples/common/Config.h +++ b/examples/common/Config.h @@ -57,6 +57,7 @@ class COMMON_EXPORT Config : public QObject Q_PROPERTY(int previewWidth READ previewWidth WRITE setPreviewWidth NOTIFY previewWidthChanged) Q_PROPERTY(int previewHeight READ previewHeight WRITE setPreviewHeight NOTIFY previewHeightChanged) Q_PROPERTY(bool ANGLE READ isANGLE WRITE setANGLE NOTIFY ANGLEChanged) + Q_PROPERTY(QString ANGLEPlatform READ getANGLEPlatform WRITE setANGLEPlatform NOTIFY ANGLEPlatformChanged) Q_PROPERTY(bool avformatOptionsEnabled READ avformatOptionsEnabled WRITE setAvformatOptionsEnabled NOTIFY avformatOptionsEnabledChanged) Q_PROPERTY(qreal timeout READ timeout WRITE setTimeout NOTIFY timeoutChanged) Q_PROPERTY(int bufferValue READ bufferValue WRITE setBufferValue NOTIFY bufferValueChanged) @@ -146,6 +147,9 @@ class COMMON_EXPORT Config : public QObject bool isANGLE() const; // false: auto Config& setANGLE(bool value); + QString getANGLEPlatform() const; + Config& setANGLEPlatform(const QString &value); + // ms >0. default 30000ms qreal timeout() const; Config& setTimeout(qreal value); @@ -183,6 +187,7 @@ class COMMON_EXPORT Config : public QObject Q_SIGNAL void previewWidthChanged(); Q_SIGNAL void previewHeightChanged(); Q_SIGNAL void ANGLEChanged(); + Q_SIGNAL void ANGLEPlatformChanged(); Q_SIGNAL void avformatOptionsEnabledChanged(); Q_SIGNAL void bufferValueChanged(); Q_SIGNAL void timeoutChanged(); diff --git a/examples/common/common.cpp b/examples/common/common.cpp index 8bdda6806..fbed7f8b2 100644 --- a/examples/common/common.cpp +++ b/examples/common/common.cpp @@ -77,23 +77,40 @@ void load_qm(const QStringList &names, const QString& lang) void set_opengl_backend(const QString& glopt, const QString &appname) { QString gl = appname.toLower(); + const int ext = appname.lastIndexOf("."); + if (ext > 0) + gl = gl.left(ext); if (gl.indexOf("-desktop") > 0) gl = "desktop"; - else if (gl.indexOf("-es") > 0 || gl.indexOf("-angle") > 0) //-es.exe - gl = "es"; + else if (gl.indexOf("-es") > 0 || gl.indexOf("-angle") > 0) + gl = gl.mid(gl.indexOf("-es") + 1); else if (gl.indexOf("-sw") > 0 || gl.indexOf("-software") > 0) gl = "software"; else gl = glopt.toLower(); - if (gl == "auto" && Config::instance().isANGLE()) - gl = "es"; + if ((gl.isEmpty() || gl == "auto") && Config::instance().isANGLE()) { + gl = "es_"; + gl.append(Config::instance().getANGLEPlatform().toLower()); + } #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - if (gl == "es") - QCoreApplication::setAttribute(Qt::AA_UseOpenGLES); - else if (gl == "desktop") - QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); - else if (gl == "software") - QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL); + if (gl.startsWith("es")) { + qApp->setAttribute(Qt::AA_UseOpenGLES); //5.5.0rc seems broken +#ifdef QT_OPENGL_DYNAMIC + qputenv("QT_OPENGL", "angle"); +#endif +#ifdef Q_OS_WIN + if (gl.endsWith("d3d11")) + qputenv("QT_ANGLE_PLATFORM", "d3d11"); + else if (gl.endsWith("d3d9")) + qputenv("QT_ANGLE_PLATFORM", "d3d9"); + else if (gl.endsWith("warp")) + qputenv("QT_ANGLE_PLATFORM", "warp"); +#endif + } else if (gl == "desktop") { + qApp->setAttribute(Qt::AA_UseDesktopOpenGL); + } else if (gl == "software") { + qApp->setAttribute(Qt::AA_UseSoftwareOpenGL); + } #endif } diff --git a/examples/player/config/MiscPage.cpp b/examples/player/config/MiscPage.cpp index 7984f2d1f..c70587c9f 100644 --- a/examples/player/config/MiscPage.cpp +++ b/examples/player/config/MiscPage.cpp @@ -71,8 +71,13 @@ MiscPage::MiscPage() hb->addWidget(m_timeout_abort); gl->addLayout(hb, r++, 1); - m_angle = new QCheckBox("Force OpenGL ANGLE (Windows)"); - gl->addWidget(m_angle, r++, 0); + m_angle = new QCheckBox(tr("OpenGLES2 ANGLE on Windows") + "-" + tr("RESTART REQUIRED")); + m_angle->setToolTip(tr("Used by DXVA Zero Copy")); + gl->addWidget(m_angle, r, 0); + m_angle_platform = new QComboBox(); + m_angle_platform->setToolTip(tr("Use D3D9 with DXVA2 to get best performance") + "\n" + tr("RESTART REQUIRED")); + m_angle_platform->addItems(QStringList() << "D3D9" << "D3D11" << "AUTO" << "WARP"); + gl->addWidget(m_angle_platform, r++, 1); applyToUi(); } @@ -89,6 +94,7 @@ void MiscPage::applyFromUi() .setPreviewWidth(m_preview_w->value()) .setPreviewHeight(m_preview_h->value()) .setANGLE(m_angle->isChecked()) + .setANGLEPlatform(m_angle_platform->currentText().toLower()) .setForceFrameRate(m_fps->value()) .setBufferValue(m_buffer_value->value()) .setTimeout(m_timeout->value()) @@ -102,6 +108,7 @@ void MiscPage::applyToUi() m_preview_w->setValue(Config::instance().previewWidth()); m_preview_h->setValue(Config::instance().previewHeight()); m_angle->setChecked(Config::instance().isANGLE()); + m_angle_platform->setCurrentIndex(m_angle_platform->findText(Config::instance().getANGLEPlatform().toUpper())); m_fps->setValue(Config::instance().forceFrameRate()); //m_notify_interval->setValue(Config::instance().avfilterOptions()); m_buffer_value->setValue(Config::instance().bufferValue()); diff --git a/examples/player/config/MiscPage.h b/examples/player/config/MiscPage.h index 8163b4292..51cd98e97 100644 --- a/examples/player/config/MiscPage.h +++ b/examples/player/config/MiscPage.h @@ -24,6 +24,7 @@ #include "ConfigPageBase.h" #include #include +#include class MiscPage : public ConfigPageBase { @@ -44,6 +45,7 @@ class MiscPage : public ConfigPageBase QDoubleSpinBox *m_timeout; QCheckBox *m_timeout_abort; QCheckBox *m_angle; + QComboBox *m_angle_platform; }; #endif // MISCPAGE_H