aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2016-08-26 20:39:48 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2016-08-26 20:40:28 +0200
commit830a55ef58a21bf342eef1c2544bcbc899014e7b (patch)
treee15d5fbe038eb1c39e16b069453785c09705f328 /src
parent86f81f48c6ceed124dabddf68994dcf3c0488509 (diff)
parent48dce24717ca537a6f5d817b2f5cd689df86ad68 (diff)
Merge remote-tracking branch 'origin/5.7' into 5.8
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsruntime/qv4numberobject.cpp22
-rw-r--r--src/quick/scenegraph/qsgdefaultglyphnode_p.cpp23
2 files changed, 40 insertions, 5 deletions
diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp
index d27eef1d79..f8e0d8763b 100644
--- a/src/qml/jsruntime/qv4numberobject.cpp
+++ b/src/qml/jsruntime/qv4numberobject.cpp
@@ -285,12 +285,30 @@ ReturnedValue NumberPrototype::method_toPrecision(CallContext *ctx)
if (!ctx->argc() || ctx->args()[0].isUndefined())
return RuntimeHelpers::toString(scope.engine, v);
- double precision = ctx->args()[0].toInt32();
+ int precision = ctx->args()[0].toInt32();
if (precision < 1 || precision > 21) {
ScopedString error(scope, scope.engine->newString(QStringLiteral("Number.prototype.toPrecision: precision out of range")));
return ctx->engine()->throwRangeError(error);
}
- QString result = NumberLocale::instance()->toString(v->asDouble(), 'g', precision);
+ // TODO: Once we get a NumberOption to retain trailing zeroes, replace the code below with:
+ // QString result = NumberLocale::instance()->toString(v->asDouble(), 'g', precision);
+ QByteArray format = "%#." + QByteArray::number(precision) + "g";
+ QString result = QString::asprintf(format.constData(), v->asDouble());
+ if (result.endsWith(QLatin1Char('.'))) {
+ // This is 'f' notation, not 'e'.
+ result.chop(1);
+ } else {
+ int ePos = result.indexOf(QLatin1Char('e'));
+ if (ePos != -1) {
+ Q_ASSERT(ePos + 2 < result.length()); // always '+' or '-', and number, after 'e'
+ Q_ASSERT(ePos > 0); // 'e' is not the first character
+
+ if (result.at(ePos + 2) == QLatin1Char('0')) // Drop leading zeroes in exponent
+ result = result.remove(ePos + 2, 1);
+ if (result.at(ePos - 1) == QLatin1Char('.')) // Drop trailing dots before 'e'
+ result = result.remove(ePos - 1, 1);
+ }
+ }
return scope.engine->newString(result)->asReturnedValue();
}
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
index 7c2663d5a3..3501f30487 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
@@ -41,6 +41,7 @@
#include <private/qsgmaterialshader_p.h>
#include <qopenglshaderprogram.h>
+#include <qopenglframebufferobject.h>
#include <QtGui/private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
@@ -210,6 +211,7 @@ public:
void activate();
void deactivate();
+ bool useSRGB() const;
uint m_useSRGB : 1;
};
@@ -229,11 +231,26 @@ void QSG24BitTextMaskShader::initialize()
}
}
+bool QSG24BitTextMaskShader::useSRGB() const
+{
+#ifdef Q_OS_MACOS
+ if (!m_useSRGB)
+ return false;
+
+ // m_useSRGB is true, but if some QOGLFBO was bound check it's texture format:
+ QOpenGLContext *ctx = QOpenGLContext::currentContext();
+ QOpenGLFramebufferObject *qfbo = QOpenGLContextPrivate::get(ctx)->qgl_current_fbo;
+ return !qfbo || qfbo->format().internalTextureFormat() == GL_SRGB8_ALPHA8_EXT;
+#else
+ return m_useSRGB;
+#endif
+}
+
void QSG24BitTextMaskShader::activate()
{
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
funcs->glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR);
- if (m_useSRGB)
+ if (useSRGB())
funcs->glEnable(GL_FRAMEBUFFER_SRGB);
}
@@ -241,7 +258,7 @@ void QSG24BitTextMaskShader::deactivate()
{
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- if (m_useSRGB)
+ if (useSRGB())
funcs->glDisable(GL_FRAMEBUFFER_SRGB);
}
@@ -266,7 +283,7 @@ void QSG24BitTextMaskShader::updateState(const RenderState &state, QSGMaterial *
if (oldMaterial == 0 || material->color() != oldMaterial->color() || state.isOpacityDirty()) {
QVector4D color = material->color();
- if (m_useSRGB)
+ if (useSRGB())
color = qt_sRGB_to_linear_RGB(color);
QOpenGLContext::currentContext()->functions()->glBlendColor(color.x(), color.y(), color.z(), color.w());
color = qsg_premultiply(color, state.opacity());