aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/coreapi
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-10-22 12:36:18 +0200
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-10-26 10:26:02 +0000
commitf9fae251ca07401ee1b0039edc6ea6b7a522b5a7 (patch)
tree2dff3c7006f5a00ab6791a0e932109807a217ab4 /src/quick/scenegraph/coreapi
parent901b88c6ae6c476a8ad9825d9020325a9a58ab61 (diff)
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>
Diffstat (limited to 'src/quick/scenegraph/coreapi')
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp35
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterial.cpp2
-rw-r--r--src/quick/scenegraph/coreapi/qsgnode.cpp2
-rw-r--r--src/quick/scenegraph/coreapi/qsgrenderer.cpp11
4 files changed, 24 insertions, 26 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
index 60ada14c32..66a8f6fbd3 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
@@ -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;
- }
-
- 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_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(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 = qt_sg_envInt("QSG_RENDERER_BATCH_NODE_THRESHOLD", 64);
+ m_batchVertexThreshold = qt_sg_envInt("QSG_RENDERER_BATCH_VERTEX_THRESHOLD", 1024);
+
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"));
diff --git a/src/quick/scenegraph/coreapi/qsgmaterial.cpp b/src/quick/scenegraph/coreapi/qsgmaterial.cpp
index c68c0b93d2..633cab8078 100644
--- a/src/quick/scenegraph/coreapi/qsgmaterial.cpp
+++ b/src/quick/scenegraph/coreapi/qsgmaterial.cpp
@@ -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
/*!
diff --git a/src/quick/scenegraph/coreapi/qsgnode.cpp b/src/quick/scenegraph/coreapi/qsgnode.cpp
index 51f3976ed9..c09af7c0a3 100644
--- a/src/quick/scenegraph/coreapi/qsgnode.cpp
+++ b/src/quick/scenegraph/coreapi/qsgnode.cpp
@@ -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()
diff --git a/src/quick/scenegraph/coreapi/qsgrenderer.cpp b/src/quick/scenegraph/coreapi/qsgrenderer.cpp
index a9752cb9a9..775277e588 100644
--- a/src/quick/scenegraph/coreapi/qsgrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgrenderer.cpp
@@ -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;