diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-06-06 14:03:47 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-06-08 10:22:37 +0000 |
commit | de89bc619d034a23a0c6398eaa001fef929f5f4b (patch) | |
tree | bc5d7245542f3ded26a4bac9e8c0bd1461a655c3 | |
parent | 4bba1a38897f381412c92d0780b3756ec76cc32b (diff) |
Avoid text scaling on high dpi screens
Only active for Qt 5.11.1 and newer.
Task-number: QT3DS-1839
Change-Id: I7a10a14b58e2931ca75e5aee21aef88ed1d63fee
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
-rw-r--r-- | src/runtime/q3dsscenemanager.cpp | 57 | ||||
-rw-r--r-- | src/runtime/q3dsuippresentation.cpp | 11 | ||||
-rw-r--r-- | src/runtime/q3dsuippresentation_p.h | 2 |
3 files changed, 60 insertions, 10 deletions
diff --git a/src/runtime/q3dsscenemanager.cpp b/src/runtime/q3dsscenemanager.cpp index e970d39..e50f652 100644 --- a/src/runtime/q3dsscenemanager.cpp +++ b/src/runtime/q3dsscenemanager.cpp @@ -94,6 +94,8 @@ #include <Qt3DRender/QScissorTest> #include <Qt3DRender/QRayCaster> +#include <Qt3DRender/private/qpaintedtextureimage_p.h> + #include <Qt3DAnimation/QClipAnimator> #include <Qt3DAnimation/qclock.h> @@ -511,17 +513,30 @@ void Q3DSSceneManager::updateSizes(const QSize &size, qreal dpr, const QRect &vi for (auto callback : m_compositorOutputSizeChangeCallbacks) callback(); - Q3DSUipPresentation::forAllLayers(m_scene, [=](Q3DSLayerNode *layer3DS) { - Q3DSLayerAttached *data = static_cast<Q3DSLayerAttached *>(layer3DS->attached()); - if (data) { - data->parentSize = m_outputPixelSize; - data->frameDirty |= Q3DSGraphObjectAttached::LayerDirty; - // do it right away if there was no size set yet - if (data->parentSize.isEmpty() || forceSynchronous) - updateSubTree(m_scene); - // Defer otherwise, like it is done for other property changes. + bool forceTreeVisit = forceSynchronous; + Q3DSUipPresentation::forAllObjects(m_scene, [this, &forceTreeVisit](Q3DSGraphObject *obj) { + if (obj->type() == Q3DSGraphObject::Layer) { + Q3DSLayerAttached *data = obj->attached<Q3DSLayerAttached>(); + if (data) { + data->parentSize = m_outputPixelSize; + data->frameDirty |= Q3DSGraphObjectAttached::LayerDirty; + // do it right away if there was no size set yet + if (data->parentSize.isEmpty()) + forceTreeVisit = true; + // Defer otherwise, like it is done for other property changes. + } + } else if (obj->type() == Q3DSGraphObject::Text) { + // Text nodes depend on the device pixel ratio and so + // may need to be updated. + Q3DSTextAttached *data = obj->attached<Q3DSTextAttached>(); + if (data) { + data->frameDirty = Q3DSGraphObjectAttached::TextDirty; + data->frameChangeFlags |= Q3DSTextNode::TextureImageDepChanges; + } } }); + if (forceTreeVisit) + updateSubTree(m_scene); } void Q3DSSceneManager::setCurrentSlide(Q3DSSlide *newSlide, bool flush) @@ -3979,7 +3994,14 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN data->texture->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear); data->textureImage = new Q3DSTextImage(text3DS, m_textRenderer); +#if QT_VERSION >= QT_VERSION_CHECK(5,11,1) + auto texImageD = static_cast<Qt3DRender::QPaintedTextureImagePrivate *>( + Qt3DRender::QPaintedTextureImagePrivate::get(data->textureImage)); + texImageD->m_devicePixelRatio = m_viewportData.viewportDpr; + data->textureImage->setSize(sz * m_viewportData.viewportDpr); +#else data->textureImage->setSize(sz); +#endif data->texture->addTextureImage(data->textureImage); data->textureParam = new Qt3DRender::QParameter; @@ -4003,15 +4025,30 @@ void Q3DSSceneManager::updateText(Q3DSTextNode *text3DS, bool needsNewImage) data->colorParam->setValue(text3DS->color()); if (needsNewImage) { - // textstring, leading, tracking + // textstring, leading, tracking, ... const QSize sz = m_textRenderer->textImageSize(text3DS); if (!sz.isEmpty()) { data->mesh->setWidth(sz.width()); data->mesh->setHeight(sz.height()); +#if QT_VERSION >= QT_VERSION_CHECK(5,11,1) + const QSize pixelSize = sz * m_viewportData.viewportDpr; + auto texImageD = static_cast<Qt3DRender::QPaintedTextureImagePrivate *>( + Qt3DRender::QPaintedTextureImagePrivate::get(data->textureImage)); + if (data->textureImage->size() != pixelSize + || texImageD->m_devicePixelRatio != m_viewportData.viewportDpr) + { + texImageD->m_devicePixelRatio = m_viewportData.viewportDpr; + // this repaints, no need for update() afterwards + data->textureImage->setSize(pixelSize); + } else { + data->textureImage->update(); + } +#else if (data->textureImage->size() != sz) data->textureImage->setSize(sz); // this repaints, no need for update() afterwards else data->textureImage->update(); +#endif } } } diff --git a/src/runtime/q3dsuippresentation.cpp b/src/runtime/q3dsuippresentation.cpp index b4a7aab..d67562f 100644 --- a/src/runtime/q3dsuippresentation.cpp +++ b/src/runtime/q3dsuippresentation.cpp @@ -4208,6 +4208,17 @@ void Q3DSUipPresentation::applySlidePropertyChanges(Q3DSSlide *slide) const notifyPropertyChanges(changeList); } +void Q3DSUipPresentation::forAllObjects(Q3DSGraphObject *root, + std::function<void(Q3DSGraphObject *)> f) +{ + Q3DSGraphObject *obj = root; + while (obj) { + f(obj); + forAllObjects(obj->firstChild(), f); + obj = obj->nextSibling(); + } +} + static void forAllObjectsInSubTree_helper(Q3DSGraphObject *obj, std::function<void(Q3DSGraphObject *)> f, bool isSubTreeRoot) diff --git a/src/runtime/q3dsuippresentation_p.h b/src/runtime/q3dsuippresentation_p.h index abffb8a..af41cc8 100644 --- a/src/runtime/q3dsuippresentation_p.h +++ b/src/runtime/q3dsuippresentation_p.h @@ -2004,6 +2004,8 @@ public: typedef QHash<QString, bool> ImageBufferMap; const ImageBufferMap &imageBuffer() const; + static void forAllObjects(Q3DSGraphObject *root, + std::function<void(Q3DSGraphObject *)> f); static void forAllObjectsInSubTree(Q3DSGraphObject *root, std::function<void(Q3DSGraphObject *)> f); static void forAllObjectsOfType(Q3DSGraphObject *root, |