Skip to content

Commit

Permalink
examples: add angle d3d option to swith d3d9/11. angle is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jun 11, 2015
1 parent 428b8fd commit c2ab12e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
20 changes: 19 additions & 1 deletion examples/common/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions examples/common/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
37 changes: 27 additions & 10 deletions examples/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 9 additions & 2 deletions examples/player/config/MiscPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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())
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions examples/player/config/MiscPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ConfigPageBase.h"
#include <QCheckBox>
#include <QDoubleSpinBox>
#include <QComboBox>

class MiscPage : public ConfigPageBase
{
Expand All @@ -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

0 comments on commit c2ab12e

Please sign in to comment.