Quick: Sanitize reading environment variables.
Where possible, use qEnvironmentVariableIsSet()/ qEnvironmentVariableIsEmpty() instead of checking on the return value of qgetenv(). Where the value is required, add a check using one of qEnvironmentVariableIsSet()/Empty(). Move QSGAtlasTexture::qsg_envInt() to qsgrenderer.cpp for reuse as qt_sg_envInt() and add qt_sg_envFloat(). Change-Id: I4c93f16c228d4f537154f389a0fa1427654485f7 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
This commit is contained in:
parent
901b88c6ae
commit
f9fae251ca
|
@ -358,7 +358,7 @@ void QQuickImageBase::resolve2xLocalFile(const QUrl &url, qreal targetDevicePixe
|
|||
Q_ASSERT(sourceDevicePixelRatio);
|
||||
|
||||
// Bail out if "@2x" image loading is disabled, don't change the source url or devicePixelRatio.
|
||||
static bool disable2xImageLoading = !qgetenv("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING").isEmpty();
|
||||
static const bool disable2xImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING");
|
||||
if (disable2xImageLoading)
|
||||
return;
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
static bool qsg_leak_check = !qgetenv("QML_LEAK_CHECK").isEmpty();
|
||||
static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK");
|
||||
#endif
|
||||
|
||||
void debugFocusTree(QQuickItem *item, QQuickItem *scope = 0, int depth = 1)
|
||||
|
|
|
@ -61,6 +61,8 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
extern QByteArray qsgShaderRewriter_insertZAttributes(const char *input, QSurfaceFormat::OpenGLContextProfile profile);
|
||||
|
||||
int qt_sg_envInt(const char *name, int defaultValue);
|
||||
|
||||
namespace QSGBatchRenderer
|
||||
{
|
||||
|
||||
|
@ -785,30 +787,17 @@ Renderer::Renderer(QSGRenderContext *ctx)
|
|||
}
|
||||
|
||||
m_bufferStrategy = GL_STATIC_DRAW;
|
||||
QByteArray strategy = qgetenv("QSG_RENDERER_BUFFER_STRATEGY");
|
||||
if (strategy == "dynamic") {
|
||||
m_bufferStrategy = GL_DYNAMIC_DRAW;
|
||||
} else if (strategy == "stream") {
|
||||
m_bufferStrategy = GL_STREAM_DRAW;
|
||||
if (Q_UNLIKELY(qEnvironmentVariableIsSet("QSG_RENDERER_BUFFER_STRATEGY"))) {
|
||||
const QByteArray strategy = qgetenv("QSG_RENDERER_BUFFER_STRATEGY");
|
||||
if (strategy == "dynamic")
|
||||
m_bufferStrategy = GL_DYNAMIC_DRAW;
|
||||
else if (strategy == "stream")
|
||||
m_bufferStrategy = GL_STREAM_DRAW;
|
||||
}
|
||||
|
||||
m_batchNodeThreshold = 64;
|
||||
QByteArray alternateThreshold = qgetenv("QSG_RENDERER_BATCH_NODE_THRESHOLD");
|
||||
if (alternateThreshold.length() > 0) {
|
||||
bool ok = false;
|
||||
int threshold = alternateThreshold.toInt(&ok);
|
||||
if (ok)
|
||||
m_batchNodeThreshold = threshold;
|
||||
}
|
||||
m_batchNodeThreshold = qt_sg_envInt("QSG_RENDERER_BATCH_NODE_THRESHOLD", 64);
|
||||
m_batchVertexThreshold = qt_sg_envInt("QSG_RENDERER_BATCH_VERTEX_THRESHOLD", 1024);
|
||||
|
||||
m_batchVertexThreshold = 1024;
|
||||
alternateThreshold = qgetenv("QSG_RENDERER_BATCH_VERTEX_THRESHOLD");
|
||||
if (alternateThreshold.length() > 0) {
|
||||
bool ok = false;
|
||||
int threshold = alternateThreshold.toInt(&ok);
|
||||
if (ok)
|
||||
m_batchVertexThreshold = threshold;
|
||||
}
|
||||
if (Q_UNLIKELY(debug_build() || debug_render())) {
|
||||
qDebug() << "Batch thresholds: nodes:" << m_batchNodeThreshold << " vertices:" << m_batchVertexThreshold;
|
||||
qDebug() << "Using buffer strategy:" << (m_bufferStrategy == GL_STATIC_DRAW ? "static" : (m_bufferStrategy == GL_DYNAMIC_DRAW ? "dynamic" : "stream"));
|
||||
|
|
|
@ -64,7 +64,7 @@ const char *QSGMaterialShaderPrivate::loadShaderSource(QOpenGLShader::ShaderType
|
|||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
static bool qsg_leak_check = !qgetenv("QML_LEAK_CHECK").isEmpty();
|
||||
static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK");
|
||||
#endif
|
||||
|
||||
/*!
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
static bool qsg_leak_check = !qgetenv("QML_LEAK_CHECK").isEmpty();
|
||||
static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK");
|
||||
static int qt_node_count = 0;
|
||||
|
||||
static void qt_print_node_count()
|
||||
|
|
|
@ -40,12 +40,21 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
static bool qsg_sanity_check = qgetenv("QSG_SANITY_CHECK").toInt();
|
||||
static const bool qsg_sanity_check = qEnvironmentVariableIntValue("QSG_SANITY_CHECK");
|
||||
|
||||
static QElapsedTimer frameTimer;
|
||||
static qint64 preprocessTime;
|
||||
static qint64 updatePassTime;
|
||||
|
||||
int qt_sg_envInt(const char *name, int defaultValue)
|
||||
{
|
||||
if (Q_LIKELY(!qEnvironmentVariableIsSet(name)))
|
||||
return defaultValue;
|
||||
bool ok = false;
|
||||
int value = qgetenv(name).toInt(&ok);
|
||||
return ok ? value : defaultValue;
|
||||
}
|
||||
|
||||
void QSGBindable::clear(QSGAbstractRenderer::ClearMode mode) const
|
||||
{
|
||||
GLuint bits = 0;
|
||||
|
|
|
@ -134,8 +134,8 @@ static bool qsg_useConsistentTiming()
|
|||
{
|
||||
static int use = -1;
|
||||
if (use < 0) {
|
||||
QByteArray fixed = qgetenv("QSG_FIXED_ANIMATION_STEP");
|
||||
use = !(fixed.isEmpty() || fixed == "no");
|
||||
use = !qEnvironmentVariableIsEmpty("QSG_FIXED_ANIMATION_STEP") && qgetenv("QSG_FIXED_ANIMATION_STEP") != "no"
|
||||
? 1 : 0;
|
||||
qCDebug(QSG_LOG_INFO, "Using %s", bool(use) ? "fixed animation steps" : "sg animation driver");
|
||||
}
|
||||
return bool(use);
|
||||
|
@ -297,15 +297,16 @@ QSGContext::QSGContext(QObject *parent) :
|
|||
QObject(*(new QSGContextPrivate), parent)
|
||||
{
|
||||
Q_D(QSGContext);
|
||||
QByteArray mode = qgetenv("QSG_DISTANCEFIELD_ANTIALIASING");
|
||||
if (!mode.isEmpty())
|
||||
if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("QSG_DISTANCEFIELD_ANTIALIASING"))) {
|
||||
const QByteArray mode = qgetenv("QSG_DISTANCEFIELD_ANTIALIASING");
|
||||
d->distanceFieldAntialiasingDecided = true;
|
||||
if (mode == "subpixel")
|
||||
d->distanceFieldAntialiasing = QSGGlyphNode::HighQualitySubPixelAntialiasing;
|
||||
else if (mode == "subpixel-lowq")
|
||||
d->distanceFieldAntialiasing = QSGGlyphNode::LowQualitySubPixelAntialiasing;
|
||||
else if (mode == "gray")
|
||||
d->distanceFieldAntialiasing = QSGGlyphNode::GrayAntialiasing;
|
||||
if (mode == "subpixel")
|
||||
d->distanceFieldAntialiasing = QSGGlyphNode::HighQualitySubPixelAntialiasing;
|
||||
else if (mode == "subpixel-lowq")
|
||||
d->distanceFieldAntialiasing = QSGGlyphNode::LowQualitySubPixelAntialiasing;
|
||||
else if (mode == "gray")
|
||||
d->distanceFieldAntialiasing = QSGGlyphNode::GrayAntialiasing;
|
||||
}
|
||||
|
||||
// Adds compatibility with Qt 5.3 and earlier's QSG_RENDER_TIMING
|
||||
if (qEnvironmentVariableIsSet("QSG_RENDER_TIMING")) {
|
||||
|
@ -333,12 +334,14 @@ void QSGContext::renderContextInitialized(QSGRenderContext *renderContext)
|
|||
|
||||
d->mutex.lock();
|
||||
if (d->antialiasingMethod == UndecidedAntialiasing) {
|
||||
QByteArray aaType = qgetenv("QSG_ANTIALIASING_METHOD");
|
||||
if (aaType == "msaa") {
|
||||
d->antialiasingMethod = MsaaAntialiasing;
|
||||
} else if (aaType == "vertex") {
|
||||
d->antialiasingMethod = VertexAntialiasing;
|
||||
} else {
|
||||
if (Q_UNLIKELY(qEnvironmentVariableIsSet("QSG_ANTIALIASING_METHOD"))) {
|
||||
const QByteArray aaType = qgetenv("QSG_ANTIALIASING_METHOD");
|
||||
if (aaType == "msaa")
|
||||
d->antialiasingMethod = MsaaAntialiasing;
|
||||
else if (aaType == "vertex")
|
||||
d->antialiasingMethod = VertexAntialiasing;
|
||||
}
|
||||
if (d->antialiasingMethod == UndecidedAntialiasing) {
|
||||
if (renderContext->openglContext()->format().samples() > 0)
|
||||
d->antialiasingMethod = MsaaAntialiasing;
|
||||
else
|
||||
|
|
|
@ -199,13 +199,15 @@ QSGRenderLoop *QSGRenderLoop::instance()
|
|||
else if (qmlForceThreadedRenderer())
|
||||
loopType = ThreadedRenderLoop;
|
||||
|
||||
const QByteArray loopName = qgetenv("QSG_RENDER_LOOP");
|
||||
if (loopName == QByteArrayLiteral("windows"))
|
||||
loopType = WindowsRenderLoop;
|
||||
else if (loopName == QByteArrayLiteral("basic"))
|
||||
loopType = BasicRenderLoop;
|
||||
else if (loopName == QByteArrayLiteral("threaded"))
|
||||
loopType = ThreadedRenderLoop;
|
||||
if (Q_UNLIKELY(qEnvironmentVariableIsSet("QSG_RENDER_LOOP"))) {
|
||||
const QByteArray loopName = qgetenv("QSG_RENDER_LOOP");
|
||||
if (loopName == QByteArrayLiteral("windows"))
|
||||
loopType = WindowsRenderLoop;
|
||||
else if (loopName == QByteArrayLiteral("basic"))
|
||||
loopType = BasicRenderLoop;
|
||||
else if (loopName == QByteArrayLiteral("threaded"))
|
||||
loopType = ThreadedRenderLoop;
|
||||
}
|
||||
|
||||
switch (loopType) {
|
||||
case ThreadedRenderLoop:
|
||||
|
|
|
@ -54,21 +54,13 @@ QT_BEGIN_NAMESPACE
|
|||
#define GL_BGRA 0x80E1
|
||||
#endif
|
||||
|
||||
int qt_sg_envInt(const char *name, int defaultValue);
|
||||
|
||||
static QElapsedTimer qsg_renderer_timer;
|
||||
|
||||
namespace QSGAtlasTexture
|
||||
{
|
||||
|
||||
static int qsg_envInt(const char *name, int defaultValue)
|
||||
{
|
||||
QByteArray content = qgetenv(name);
|
||||
|
||||
bool ok = false;
|
||||
int value = content.toInt(&ok);
|
||||
return ok ? value : defaultValue;
|
||||
}
|
||||
|
||||
Manager::Manager()
|
||||
: m_atlas(0)
|
||||
{
|
||||
|
@ -79,8 +71,8 @@ Manager::Manager()
|
|||
int max;
|
||||
gl->functions()->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
|
||||
|
||||
int w = qMin(max, qsg_envInt("QSG_ATLAS_WIDTH", qMax(512U, qNextPowerOfTwo(surfaceSize.width() - 1))));
|
||||
int h = qMin(max, qsg_envInt("QSG_ATLAS_HEIGHT", qMax(512U, qNextPowerOfTwo(surfaceSize.height() - 1))));
|
||||
int w = qMin(max, qt_sg_envInt("QSG_ATLAS_WIDTH", qMax(512U, qNextPowerOfTwo(surfaceSize.width() - 1))));
|
||||
int h = qMin(max, qt_sg_envInt("QSG_ATLAS_HEIGHT", qMax(512U, qNextPowerOfTwo(surfaceSize.height() - 1))));
|
||||
|
||||
if (surface->surfaceClass() == QSurface::Window) {
|
||||
QWindow *window = static_cast<QWindow *>(surface);
|
||||
|
@ -91,7 +83,7 @@ Manager::Manager()
|
|||
}
|
||||
}
|
||||
|
||||
m_atlas_size_limit = qsg_envInt("QSG_ATLAS_SIZE_LIMIT", qMax(w, h) / 2);
|
||||
m_atlas_size_limit = qt_sg_envInt("QSG_ATLAS_SIZE_LIMIT", qMax(w, h) / 2);
|
||||
m_atlas_size = QSize(w, h);
|
||||
|
||||
qCDebug(QSG_LOG_INFO, "texture atlas dimensions: %dx%d", w, h);
|
||||
|
|
|
@ -39,18 +39,27 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
static float qt_sg_envFloat(const char *name, float defaultValue)
|
||||
{
|
||||
if (Q_LIKELY(!qEnvironmentVariableIsSet(name)))
|
||||
return defaultValue;
|
||||
bool ok = false;
|
||||
const float value = qgetenv(name).toFloat(&ok);
|
||||
return ok ? value : defaultValue;
|
||||
}
|
||||
|
||||
static float defaultThresholdFunc(float glyphScale)
|
||||
{
|
||||
static float base = qgetenv("QT_DF_BASE").isEmpty() ? 0.5f : qgetenv("QT_DF_BASE").toFloat();
|
||||
static float baseDev = qgetenv("QT_DF_BASEDEVIATION").isEmpty() ? 0.065f : qgetenv("QT_DF_BASEDEVIATION").toFloat();
|
||||
static float devScaleMin = qgetenv("QT_DF_SCALEFORMAXDEV").isEmpty() ? 0.15f : qgetenv("QT_DF_SCALEFORMAXDEV").toFloat();
|
||||
static float devScaleMax = qgetenv("QT_DF_SCALEFORNODEV").isEmpty() ? 0.3f : qgetenv("QT_DF_SCALEFORNODEV").toFloat();
|
||||
static const float base = qt_sg_envFloat("QT_DF_BASE", 0.5f);
|
||||
static const float baseDev = qt_sg_envFloat("QT_DF_BASEDEVIATION", 0.065f);
|
||||
static const float devScaleMin = qt_sg_envFloat("QT_DF_SCALEFORMAXDEV", 0.15f);
|
||||
static const float devScaleMax = qt_sg_envFloat("QT_DF_SCALEFORNODEV", 0.3f);
|
||||
return base - ((qBound(devScaleMin, glyphScale, devScaleMax) - devScaleMin) / (devScaleMax - devScaleMin) * -baseDev + baseDev);
|
||||
}
|
||||
|
||||
static float defaultAntialiasingSpreadFunc(float glyphScale)
|
||||
{
|
||||
static float range = qgetenv("QT_DF_RANGE").isEmpty() ? 0.06f : qgetenv("QT_DF_RANGE").toFloat();
|
||||
static const float range = qt_sg_envFloat("QT_DF_RANGE", 0.06f);
|
||||
return range / glyphScale;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
static QElapsedTimer qsg_renderer_timer;
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
static bool qsg_leak_check = !qgetenv("QML_LEAK_CHECK").isEmpty();
|
||||
static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK");
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
static bool qsg_leak_check = !qgetenv("QML_LEAK_CHECK").isEmpty();
|
||||
static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK");
|
||||
#endif
|
||||
|
||||
// The cache limit describes the maximum "junk" in the cache.
|
||||
|
|
Loading…
Reference in New Issue