QmlDesigner: Improve usage of QML items as quick3d textures

Quick3D Texture elements require some window signals to show QML item
as texture, so we fake them to make textures appear in form editor
and state preview. To prevent texture mirroring, flipV value
is force set at proxy creation. To keep state preview up to date,
we trigger multiple render passes if there are any QML items used
as texture sources in quick3D textures.

Task-number: QDS-2290
Change-Id: I16c34aad943213c0b737fdb073333be3bbd40f2d
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2020-06-17 15:54:41 +03:00
parent c6b9a03b39
commit 60ff6b6577
12 changed files with 203 additions and 1 deletions

View File

@@ -29,6 +29,7 @@ HEADERS += $$PWD/positionernodeinstance.h
HEADERS += $$PWD/layoutnodeinstance.h
HEADERS += $$PWD/qt3dpresentationnodeinstance.h
HEADERS += $$PWD/quick3dnodeinstance.h
HEADERS += $$PWD/quick3dtexturenodeinstance.h
SOURCES += $$PWD/qt5nodeinstanceserver.cpp
SOURCES += $$PWD/qt5testnodeinstanceserver.cpp
@@ -54,3 +55,4 @@ SOURCES += $$PWD/positionernodeinstance.cpp
SOURCES += $$PWD/layoutnodeinstance.cpp
SOURCES += $$PWD/qt3dpresentationnodeinstance.cpp
SOURCES += $$PWD/quick3dnodeinstance.cpp
SOURCES += $$PWD/quick3dtexturenodeinstance.cpp

View File

@@ -1416,4 +1416,28 @@ void NodeInstanceServer::changeLanguage(const ChangeLanguageCommand &command)
}
void NodeInstanceServer::changePreviewImageSize(const ChangePreviewImageSizeCommand &) {}
void NodeInstanceServer::incrementNeedsExtraRender()
{
++m_needsExtraRenderCount;
}
void NodeInstanceServer::decrementNeedsExtraRender()
{
--m_needsExtraRenderCount;
}
void NodeInstanceServer::handleExtraRender()
{
// If multipass is needed, render two additional times to ensure correct result
if (m_extraRenderCurrentPass == 0 && m_needsExtraRenderCount > 0)
m_extraRenderCurrentPass = 3;
if (m_extraRenderCurrentPass > 0) {
--m_extraRenderCurrentPass;
if (m_extraRenderCurrentPass > 0)
startRenderTimer();
}
}
} // namespace QmlDesigner

View File

@@ -191,6 +191,11 @@ public:
void sendDebugOutput(DebugOutputCommand::Type type, const QString &message, const QVector<qint32> &instanceIds);
void removeInstanceRelationsipForDeletedObject(QObject *object);
void incrementNeedsExtraRender();
void decrementNeedsExtraRender();
void handleExtraRender();
public slots:
void refreshLocalFileProperty(const QString &path);
void refreshDummyData(const QString &path);
@@ -290,6 +295,8 @@ private:
QPointer<QQmlComponent> m_importComponent;
QPointer<QObject> m_importComponentObject;
std::unique_ptr<MultiLanguage::Link> multilanguageLink;
int m_needsExtraRenderCount = 0;
int m_extraRenderCurrentPass = 0;
};
}

View File

@@ -467,11 +467,17 @@ void Qt5InformationNodeInstanceServer::doRender3DEditView()
};
updateNodesRecursive(m_editView3DContentItem);
// Fake render loop signaling to update things like QML items as 3D textures
m_editView3D->beforeSynchronizing();
m_editView3D->beforeRendering();
QSizeF size = qobject_cast<QQuickItem *>(m_editView3DContentItem)->size();
QRectF renderRect(QPointF(0., 0.), size);
QImage renderImage = designerSupport()->renderImageForItem(m_editView3DContentItem,
renderRect, size.toSize());
m_editView3D->afterRendering();
// There's no instance related to image, so instance id is -1.
// Key number is selected so that it is unlikely to conflict other ImageContainer use.
const qint32 edit3DKey = 2100000000;

View File

@@ -86,6 +86,7 @@ void Qt5PreviewNodeInstanceServer::collectItemChangesAndSendChangeCommands()
nodeInstanceClient()->statePreviewImagesChanged(StatePreviewImageChangedCommand(imageContainerVector));
slowDownRenderTimer();
handleExtraRender();
inFunction = false;
}
}

View File

@@ -0,0 +1,86 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "quick3dtexturenodeinstance.h"
#include <QQuickItem>
#include <QTimer>
namespace QmlDesigner {
namespace Internal {
Quick3DTextureNodeInstance::Quick3DTextureNodeInstance(QObject *object)
: ObjectNodeInstance(object)
{
}
Quick3DTextureNodeInstance::Pointer Quick3DTextureNodeInstance::create(QObject *object)
{
Pointer instance(new Quick3DTextureNodeInstance(object));
QTimer::singleShot(0, [object](){
// Texture will be upside down for unknown reason unless we force flip update at start
QVariant prop = object->property("flipV");
QVariant prop2(!prop.toBool());
object->setProperty("flipV", prop2);
object->setProperty("flipV", prop);
});
instance->populateResetHashes();
return instance;
}
void Quick3DTextureNodeInstance::setPropertyBinding(const PropertyName &name,
const QString &expression)
{
ObjectNodeInstance::setPropertyBinding(name, expression);
if (name == "sourceItem") {
bool targetNeed = true;
if (expression.isEmpty())
targetNeed = false;
if (targetNeed != m_multiPassNeeded) {
m_multiPassNeeded = targetNeed;
if (targetNeed)
nodeInstanceServer()->incrementNeedsExtraRender();
else
nodeInstanceServer()->decrementNeedsExtraRender();
}
}
}
void Quick3DTextureNodeInstance::resetProperty(const PropertyName &name)
{
ObjectNodeInstance::resetProperty(name);
if (name == "sourceItem") {
if (m_multiPassNeeded) {
m_multiPassNeeded = false;
nodeInstanceServer()->decrementNeedsExtraRender();
}
}
}
} // namespace Internal
} // namespace QmlDesigner

View File

@@ -0,0 +1,54 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "objectnodeinstance.h"
namespace QmlDesigner {
namespace Internal {
class Quick3DTextureNodeInstance : public ObjectNodeInstance
{
public:
using Pointer = QSharedPointer<Quick3DTextureNodeInstance>;
using WeakPointer = QWeakPointer<Quick3DTextureNodeInstance>;
static Pointer create(QObject *objectToBeWrapped);
void setPropertyBinding(const PropertyName &name, const QString &expression) override;
void resetProperty(const PropertyName &name) override;
protected:
Quick3DTextureNodeInstance(QObject *item);
private:
void handleRedrawTimeout();
bool m_multiPassNeeded = false;
};
} // namespace Internal
} // namespace QmlDesigner

View File

@@ -386,8 +386,14 @@ QImage QuickItemNodeInstance::renderImage() const
static double devicePixelRatio = qgetenv("FORMEDITOR_DEVICE_PIXEL_RATIO").toDouble();
size *= devicePixelRatio;
// Fake render loop signaling to update things like QML items as 3D textures
nodeInstanceServer()->quickView()->beforeSynchronizing();
nodeInstanceServer()->quickView()->beforeRendering();
QImage renderImage = designerSupport()->renderImageForItem(quickItem(), renderBoundingRect, size);
nodeInstanceServer()->quickView()->afterRendering();
renderImage.setDevicePixelRatio(devicePixelRatio);
return renderImage;
@@ -401,7 +407,15 @@ QImage QuickItemNodeInstance::renderPreviewImage(const QSize &previewImageSize)
static double devicePixelRatio = qgetenv("FORMEDITOR_DEVICE_PIXEL_RATIO").toDouble();
const QSize size = previewImageSize * devicePixelRatio;
if (quickItem()->isVisible()) {
return designerSupport()->renderImageForItem(quickItem(), previewItemBoundingRect, size);
// Fake render loop signaling to update things like QML items as 3D textures
nodeInstanceServer()->quickView()->beforeSynchronizing();
nodeInstanceServer()->quickView()->beforeRendering();
QImage image = designerSupport()->renderImageForItem(quickItem(), previewItemBoundingRect, size);
nodeInstanceServer()->quickView()->afterRendering();
return image;
} else {
QImage transparentImage(size, QImage::Format_ARGB32_Premultiplied);
transparentImage.fill(Qt::transparent);

View File

@@ -40,6 +40,7 @@
#include "quickitemnodeinstance.h"
#include "quick3dnodeinstance.h"
#include "quick3dtexturenodeinstance.h"
#include "nodeinstanceserver.h"
#include "instancecontainer.h"
@@ -176,6 +177,8 @@ Internal::ObjectNodeInstance::Pointer ServerNodeInstance::createInstance(QObject
instance = Internal::LayoutNodeInstance::create(objectToBeWrapped);
else if (isSubclassOf(objectToBeWrapped, "QQuickItem"))
instance = Internal::QuickItemNodeInstance::create(objectToBeWrapped);
else if (isSubclassOf(objectToBeWrapped, "QQuick3DTexture"))
instance = Internal::Quick3DTextureNodeInstance::create(objectToBeWrapped);
else if (isSubclassOf(objectToBeWrapped, "QQuick3DNode"))
instance = Internal::Quick3DNodeInstance::create(objectToBeWrapped);
else if (isSubclassOf(objectToBeWrapped, "QQmlComponent"))

View File

@@ -61,6 +61,7 @@ namespace Internal {
class QmlStateNodeInstance;
class QuickItemNodeInstance;
class Quick3DNodeInstance;
class Quick3DTextureNodeInstance;
}
class ServerNodeInstance
@@ -84,6 +85,7 @@ class ServerNodeInstance
friend class QmlDesigner::Internal::QmlPropertyChangesNodeInstance;
friend class QmlDesigner::Internal::QmlStateNodeInstance;
friend class QmlDesigner::Internal::Quick3DNodeInstance;
friend class QmlDesigner::Internal::Quick3DTextureNodeInstance;
public:
enum ComponentWrap {

View File

@@ -152,6 +152,7 @@ extend_qtc_executable(qml2puppet
qt5rendernodeinstanceserver.cpp qt5rendernodeinstanceserver.h
qt5testnodeinstanceserver.cpp qt5testnodeinstanceserver.h
quick3dnodeinstance.cpp quick3dnodeinstance.h
quick3dtexturenodeinstance.cpp quick3dtexturenodeinstance.h
quickitemnodeinstance.cpp quickitemnodeinstance.h
servernodeinstance.cpp servernodeinstance.h
)

View File

@@ -198,6 +198,8 @@ QtcTool {
"instances/qmlstatenodeinstance.h",
"instances/quick3dnodeinstance.cpp",
"instances/quick3dnodeinstance.h",
"instances/quick3dtexturenodeinstance.cpp",
"instances/quick3dtexturenodeinstance.h",
"instances/qmltransitionnodeinstance.cpp",
"instances/qmltransitionnodeinstance.h",
"instances/qt3dpresentationnodeinstance.cpp",