aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/configure.json17
-rw-r--r--src/quick/designer/qqmldesignermetaobject.cpp5
-rw-r--r--src/quick/designer/qquickdesignercustomparserobject.cpp4
-rw-r--r--src/quick/designer/qquickdesignercustomparserobject_p.h4
-rw-r--r--src/quick/designer/qquickdesignerwindowmanager.cpp11
-rw-r--r--src/quick/designer/qquickdesignerwindowmanager_p.h5
-rw-r--r--src/quick/doc/qtquick.qdocconf2
-rw-r--r--src/quick/doc/snippets/cmake-macros/examples.cmake6
-rw-r--r--src/quick/doc/snippets/pointerHandlers/handlerFlick.qml88
-rw-r--r--src/quick/doc/snippets/pointerHandlers/wheelHandler.qml63
-rw-r--r--src/quick/doc/snippets/qml/boundaryRule.qml74
-rw-r--r--src/quick/doc/snippets/qml/qml-extending-types/signals/Button.qml2
-rw-r--r--src/quick/doc/snippets/qml/regularexpression.qml56
-rw-r--r--src/quick/doc/snippets/qml/tableview/cpp-tablemodel.cpp (renamed from src/quick/doc/snippets/qml/tableview/tablemodel.cpp)0
-rw-r--r--src/quick/doc/snippets/qml/tableview/cpp-tablemodel.qml (renamed from src/quick/doc/snippets/qml/tableview/tablemodel.qml)0
-rw-r--r--src/quick/doc/snippets/qml/tableview/qml-tablemodel.qml92
-rw-r--r--src/quick/doc/snippets/qml/texthandling.qml4
-rw-r--r--src/quick/doc/src/cmake-macros.qdoc56
-rw-r--r--src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc58
-rw-r--r--src/quick/doc/src/concepts/visualcanvas/scenegraph.qdoc338
-rw-r--r--src/quick/doc/src/concepts/visualcanvas/topic.qdoc17
-rw-r--r--src/quick/doc/src/examples.qdoc7
-rw-r--r--src/quick/handlers/handlers.pri7
-rw-r--r--src/quick/handlers/qquickdraghandler.cpp45
-rw-r--r--src/quick/handlers/qquickdraghandler_p.h13
-rw-r--r--src/quick/handlers/qquickhoverhandler.cpp11
-rw-r--r--src/quick/handlers/qquickmultipointhandler.cpp170
-rw-r--r--src/quick/handlers/qquickmultipointhandler_p.h18
-rw-r--r--src/quick/handlers/qquickmultipointhandler_p_p.h83
-rw-r--r--src/quick/handlers/qquickpinchhandler.cpp58
-rw-r--r--src/quick/handlers/qquickpinchhandler_p.h1
-rw-r--r--src/quick/handlers/qquickpointerdevicehandler.cpp3
-rw-r--r--src/quick/handlers/qquicktaphandler.cpp16
-rw-r--r--src/quick/handlers/qquickwheelhandler.cpp520
-rw-r--r--src/quick/handlers/qquickwheelhandler_p.h128
-rw-r--r--src/quick/handlers/qquickwheelhandler_p_p.h87
-rw-r--r--src/quick/items/context2d/qquickcanvascontext_p.h3
-rw-r--r--src/quick/items/context2d/qquickcanvasitem.cpp10
-rw-r--r--src/quick/items/context2d/qquickcanvasitem_p.h6
-rw-r--r--src/quick/items/context2d/qquickcontext2d.cpp11
-rw-r--r--src/quick/items/context2d/qquickcontext2d_p.h2
-rw-r--r--src/quick/items/context2d/qquickcontext2dtexture.cpp13
-rw-r--r--src/quick/items/items.pri14
-rw-r--r--src/quick/items/qquickanimatedimage.cpp7
-rw-r--r--src/quick/items/qquickanimatedimage_p.h7
-rw-r--r--src/quick/items/qquickanimatedsprite.cpp2
-rw-r--r--src/quick/items/qquickanimatedsprite_p.h4
-rw-r--r--src/quick/items/qquickborderimage.cpp22
-rw-r--r--src/quick/items/qquickborderimage_p_p.h2
-rw-r--r--src/quick/items/qquickdrag.cpp4
-rw-r--r--src/quick/items/qquickdrag_p.h6
-rw-r--r--src/quick/items/qquickdroparea.cpp21
-rw-r--r--src/quick/items/qquickdroparea_p.h4
-rw-r--r--src/quick/items/qquickevents.cpp9
-rw-r--r--src/quick/items/qquickevents_p_p.h1
-rw-r--r--src/quick/items/qquickflickable.cpp9
-rw-r--r--src/quick/items/qquickflickablebehavior_p.h5
-rw-r--r--src/quick/items/qquickframebufferobject.cpp4
-rw-r--r--src/quick/items/qquickframebufferobject.h3
-rw-r--r--src/quick/items/qquickgenericshadereffect.cpp53
-rw-r--r--src/quick/items/qquickgenericshadereffect_p.h4
-rw-r--r--src/quick/items/qquickgraphicsinfo.cpp7
-rw-r--r--src/quick/items/qquickgraphicsinfo_p.h11
-rw-r--r--src/quick/items/qquickimage.cpp19
-rw-r--r--src/quick/items/qquickimage_p.h8
-rw-r--r--src/quick/items/qquickimagebase.cpp47
-rw-r--r--src/quick/items/qquickimagebase_p.h9
-rw-r--r--src/quick/items/qquickimagebase_p_p.h6
-rw-r--r--src/quick/items/qquickitem.cpp55
-rw-r--r--src/quick/items/qquickitem.h4
-rw-r--r--src/quick/items/qquickitem_p.h5
-rw-r--r--src/quick/items/qquickitemsmodule.cpp93
-rw-r--r--src/quick/items/qquickitemview.cpp38
-rw-r--r--src/quick/items/qquickitemview_p.h4
-rw-r--r--src/quick/items/qquickitemview_p_p.h8
-rw-r--r--src/quick/items/qquicklistview_p.h8
-rw-r--r--src/quick/items/qquickmousearea.cpp30
-rw-r--r--src/quick/items/qquickmousearea_p.h12
-rw-r--r--src/quick/items/qquickmousearea_p_p.h2
-rw-r--r--src/quick/items/qquickmultipointtoucharea.cpp4
-rw-r--r--src/quick/items/qquickopenglshadereffect.cpp12
-rw-r--r--src/quick/items/qquickopenglshadereffectnode.cpp1
-rw-r--r--src/quick/items/qquickpathview.cpp179
-rw-r--r--src/quick/items/qquickpincharea_p.h4
-rw-r--r--src/quick/items/qquickrectangle.cpp26
-rw-r--r--src/quick/items/qquickrendercontrol.cpp16
-rw-r--r--src/quick/items/qquickrepeater.cpp1
-rw-r--r--src/quick/items/qquickscreen_p.h8
-rw-r--r--src/quick/items/qquickshadereffect.cpp18
-rw-r--r--src/quick/items/qquickshadereffect_p.h2
-rw-r--r--src/quick/items/qquickshadereffectsource.cpp2
-rw-r--r--src/quick/items/qquickshadereffectsource_p.h4
-rw-r--r--src/quick/items/qquickspriteengine.cpp12
-rw-r--r--src/quick/items/qquickspriteengine_p.h4
-rw-r--r--src/quick/items/qquickspritesequence_p.h1
-rw-r--r--src/quick/items/qquickspritesequence_p_p.h3
-rw-r--r--src/quick/items/qquickstateoperations.cpp12
-rw-r--r--src/quick/items/qquickstateoperations_p.h12
-rw-r--r--src/quick/items/qquicktableview.cpp1122
-rw-r--r--src/quick/items/qquicktableview_p.h19
-rw-r--r--src/quick/items/qquicktableview_p_p.h65
-rw-r--r--src/quick/items/qquicktext.cpp16
-rw-r--r--src/quick/items/qquicktext_p.h1
-rw-r--r--src/quick/items/qquicktext_p_p.h1
-rw-r--r--src/quick/items/qquicktextcontrol.cpp46
-rw-r--r--src/quick/items/qquicktextcontrol_p.h9
-rw-r--r--src/quick/items/qquicktextcontrol_p_p.h3
-rw-r--r--src/quick/items/qquicktextdocument.cpp8
-rw-r--r--src/quick/items/qquicktextdocument_p.h3
-rw-r--r--src/quick/items/qquicktextedit.cpp31
-rw-r--r--src/quick/items/qquicktextedit_p.h4
-rw-r--r--src/quick/items/qquicktextedit_p_p.h3
-rw-r--r--src/quick/items/qquicktextinput.cpp9
-rw-r--r--src/quick/items/qquicktextinput_p.h8
-rw-r--r--src/quick/items/qquicktextnode.cpp2
-rw-r--r--src/quick/items/qquicktextnodeengine.cpp13
-rw-r--r--src/quick/items/qquickview.cpp21
-rw-r--r--src/quick/items/qquickview.h1
-rw-r--r--src/quick/items/qquickview_p.h2
-rw-r--r--src/quick/items/qquickwindow.cpp627
-rw-r--r--src/quick/items/qquickwindow.h20
-rw-r--r--src/quick/items/qquickwindow_p.h26
-rw-r--r--src/quick/items/qquickwindowmodule.cpp9
-rw-r--r--src/quick/items/qquickwindowmodule_p.h4
-rw-r--r--src/quick/qtquick2.cpp1
-rw-r--r--src/quick/quick.pro2
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer.cpp5
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer_p.h4
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp3
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarecontext_p.h2
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarelayer.cpp8
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h10
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture.cpp11
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture_p.h11
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp1
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarerenderablenode.cpp2
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarerenderloop.cpp2
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp16
-rw-r--r--src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp16
-rw-r--r--src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture_p.h6
-rw-r--r--src/quick/scenegraph/compressedtexture/qsgcompressedtexture.cpp179
-rw-r--r--src/quick/scenegraph/compressedtexture/qsgcompressedtexture_p.h23
-rw-r--r--src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp73
-rw-r--r--src/quick/scenegraph/coreapi/qsgabstractrenderer.h10
-rw-r--r--src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h1
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp2749
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h306
-rw-r--r--src/quick/scenegraph/coreapi/qsggeometry.cpp5
-rw-r--r--src/quick/scenegraph/coreapi/qsggeometry.h6
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterial.cpp572
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterial.h98
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterialrhishader.cpp630
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterialrhishader.h182
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterialrhishader_p.h114
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterialshader.cpp556
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterialshader.h136
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterialshader_p.h8
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterialtype.h51
-rw-r--r--src/quick/scenegraph/coreapi/qsgopenglvisualizer.cpp365
-rw-r--r--src/quick/scenegraph/coreapi/qsgopenglvisualizer_p.h91
-rw-r--r--src/quick/scenegraph/coreapi/qsgrenderer.cpp31
-rw-r--r--src/quick/scenegraph/coreapi/qsgrenderer_p.h55
-rw-r--r--src/quick/scenegraph/coreapi/qsgrendererinterface.cpp106
-rw-r--r--src/quick/scenegraph/coreapi/qsgrendererinterface.h21
-rw-r--r--src/quick/scenegraph/coreapi/qsgrendernode.cpp103
-rw-r--r--src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp929
-rw-r--r--src/quick/scenegraph/coreapi/qsgrhivisualizer_p.h233
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture.cpp (renamed from src/quick/scenegraph/util/qsgtexture.cpp)336
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture.h (renamed from src/quick/scenegraph/util/qsgtexture.h)21
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture_p.h109
-rw-r--r--src/quick/scenegraph/qsgadaptationlayer.cpp29
-rw-r--r--src/quick/scenegraph/qsgadaptationlayer_p.h42
-rw-r--r--src/quick/scenegraph/qsgcontext.cpp55
-rw-r--r--src/quick/scenegraph/qsgcontext_p.h29
-rw-r--r--src/quick/scenegraph/qsgdefaultcontext.cpp114
-rw-r--r--src/quick/scenegraph/qsgdefaultcontext_p.h6
-rw-r--r--src/quick/scenegraph/qsgdefaultglyphnode.cpp13
-rw-r--r--src/quick/scenegraph/qsgdefaultglyphnode_p.cpp493
-rw-r--r--src/quick/scenegraph/qsgdefaultglyphnode_p.h6
-rw-r--r--src/quick/scenegraph/qsgdefaultglyphnode_p_p.h23
-rw-r--r--src/quick/scenegraph/qsgdefaultinternalimagenode.cpp61
-rw-r--r--src/quick/scenegraph/qsgdefaultinternalimagenode_p.h5
-rw-r--r--src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp52
-rw-r--r--src/quick/scenegraph/qsgdefaultrendercontext.cpp200
-rw-r--r--src/quick/scenegraph/qsgdefaultrendercontext_p.h82
-rw-r--r--src/quick/scenegraph/qsgdefaultspritenode.cpp77
-rw-r--r--src/quick/scenegraph/qsgdistancefieldglyphnode.cpp16
-rw-r--r--src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp415
-rw-r--r--src/quick/scenegraph/qsgdistancefieldglyphnode_p.h3
-rw-r--r--src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h6
-rw-r--r--src/quick/scenegraph/qsgopengldistancefieldglyphcache.cpp (renamed from src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp)43
-rw-r--r--src/quick/scenegraph/qsgopengldistancefieldglyphcache_p.h (renamed from src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h)13
-rw-r--r--src/quick/scenegraph/qsgopengllayer.cpp (renamed from src/quick/scenegraph/qsgdefaultlayer.cpp)56
-rw-r--r--src/quick/scenegraph/qsgopengllayer_p.h (renamed from src/quick/scenegraph/qsgdefaultlayer_p.h)22
-rw-r--r--src/quick/scenegraph/qsgrenderloop.cpp468
-rw-r--r--src/quick/scenegraph/qsgrenderloop_p.h13
-rw-r--r--src/quick/scenegraph/qsgrhidistancefieldglyphcache.cpp570
-rw-r--r--src/quick/scenegraph/qsgrhidistancefieldglyphcache_p.h125
-rw-r--r--src/quick/scenegraph/qsgrhilayer.cpp474
-rw-r--r--src/quick/scenegraph/qsgrhilayer_p.h143
-rw-r--r--src/quick/scenegraph/qsgrhishadereffectnode.cpp886
-rw-r--r--src/quick/scenegraph/qsgrhishadereffectnode_p.h163
-rw-r--r--src/quick/scenegraph/qsgrhisupport.cpp608
-rw-r--r--src/quick/scenegraph/qsgrhisupport_p.h171
-rw-r--r--src/quick/scenegraph/qsgrhitextureglyphcache.cpp272
-rw-r--r--src/quick/scenegraph/qsgrhitextureglyphcache_p.h101
-rw-r--r--src/quick/scenegraph/qsgthreadedrenderloop.cpp555
-rw-r--r--src/quick/scenegraph/qsgthreadedrenderloop_p.h2
-rw-r--r--src/quick/scenegraph/qsgwindowsrenderloop.cpp28
-rw-r--r--src/quick/scenegraph/scenegraph.pri58
-rw-r--r--src/quick/scenegraph/scenegraph.qrc52
-rw-r--r--src/quick/scenegraph/shaders_ng/24bittextmask.frag19
-rw-r--r--src/quick/scenegraph/shaders_ng/24bittextmask.frag.qsbbin0 -> 1873 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/32bitcolortext.frag18
-rw-r--r--src/quick/scenegraph/shaders_ng/32bitcolortext.frag.qsbbin0 -> 1754 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/8bittextmask.frag18
-rw-r--r--src/quick/scenegraph/shaders_ng/8bittextmask.frag.qsbbin0 -> 1753 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/8bittextmask_a.frag18
-rw-r--r--src/quick/scenegraph/shaders_ng/8bittextmask_a.frag.qsbbin0 -> 1280 bytes
-rwxr-xr-xsrc/quick/scenegraph/shaders_ng/compile.bat86
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag25
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag.qsbbin0 -> 2209 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.vert26
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.vert.qsbbin0 -> 2209 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag25
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag.qsbbin0 -> 2210 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.frag27
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.frag.qsbbin0 -> 2319 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.vert27
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.vert.qsbbin0 -> 2340 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldshiftedtext_a.frag27
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldshiftedtext_a.frag.qsbbin0 -> 2334 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldtext.frag20
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldtext.frag.qsbbin0 -> 1883 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldtext.vert22
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldtext.vert.qsbbin0 -> 2048 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldtext_a.frag20
-rw-r--r--src/quick/scenegraph/shaders_ng/distancefieldtext_a.frag.qsbbin0 -> 1883 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/flatcolor.frag13
-rw-r--r--src/quick/scenegraph/shaders_ng/flatcolor.frag.qsbbin0 -> 1149 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/flatcolor.vert15
-rw-r--r--src/quick/scenegraph/shaders_ng/flatcolor.vert.qsbbin0 -> 1597 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.frag40
-rw-r--r--src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.frag.qsbbin0 -> 3314 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.vert44
-rw-r--r--src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.vert.qsbbin0 -> 3675 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext_a.frag40
-rw-r--r--src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext_a.frag.qsbbin0 -> 3304 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.frag29
-rw-r--r--src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.frag.qsbbin0 -> 2411 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.vert37
-rw-r--r--src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.vert.qsbbin0 -> 3028 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext_a.frag29
-rw-r--r--src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext_a.frag.qsbbin0 -> 2412 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/opaquetexture.frag11
-rw-r--r--src/quick/scenegraph/shaders_ng/opaquetexture.frag.qsbbin0 -> 1173 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/opaquetexture.vert18
-rw-r--r--src/quick/scenegraph/shaders_ng/opaquetexture.vert.qsbbin0 -> 1791 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/outlinedtext.frag33
-rw-r--r--src/quick/scenegraph/shaders_ng/outlinedtext.frag.qsbbin0 -> 2549 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/outlinedtext.vert32
-rw-r--r--src/quick/scenegraph/shaders_ng/outlinedtext.vert.qsbbin0 -> 2728 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/outlinedtext_a.frag33
-rw-r--r--src/quick/scenegraph/shaders_ng/outlinedtext_a.frag.qsbbin0 -> 1859 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/shadereffect.frag16
-rw-r--r--src/quick/scenegraph/shaders_ng/shadereffect.frag.qsbbin0 -> 1622 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/shadereffect.vert19
-rw-r--r--src/quick/scenegraph/shaders_ng/shadereffect.vert.qsbbin0 -> 1860 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/smoothcolor.frag9
-rw-r--r--src/quick/scenegraph/shaders_ng/smoothcolor.frag.qsbbin0 -> 838 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/smoothcolor.vert51
-rw-r--r--src/quick/scenegraph/shaders_ng/smoothcolor.vert.qsbbin0 -> 3682 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/smoothtexture.frag13
-rw-r--r--src/quick/scenegraph/shaders_ng/smoothtexture.frag.qsbbin0 -> 1299 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/smoothtexture.vert61
-rw-r--r--src/quick/scenegraph/shaders_ng/smoothtexture.vert.qsbbin0 -> 4350 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/sprite.frag22
-rw-r--r--src/quick/scenegraph/shaders_ng/sprite.frag.qsbbin0 -> 1908 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/sprite.vert29
-rw-r--r--src/quick/scenegraph/shaders_ng/sprite.vert.qsbbin0 -> 2437 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/stencilclip.frag8
-rw-r--r--src/quick/scenegraph/shaders_ng/stencilclip.frag.qsbbin0 -> 853 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/stencilclip.vert14
-rw-r--r--src/quick/scenegraph/shaders_ng/stencilclip.vert.qsbbin0 -> 1510 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/styledtext.frag26
-rw-r--r--src/quick/scenegraph/shaders_ng/styledtext.frag.qsbbin0 -> 2210 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/styledtext.vert26
-rw-r--r--src/quick/scenegraph/shaders_ng/styledtext.vert.qsbbin0 -> 2460 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/styledtext_a.frag26
-rw-r--r--src/quick/scenegraph/shaders_ng/styledtext_a.frag.qsbbin0 -> 1631 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/textmask.frag19
-rw-r--r--src/quick/scenegraph/shaders_ng/textmask.frag.qsbbin0 -> 1873 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/textmask.vert21
-rw-r--r--src/quick/scenegraph/shaders_ng/textmask.vert.qsbbin0 -> 2142 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/texture.frag16
-rw-r--r--src/quick/scenegraph/shaders_ng/texture.frag.qsbbin0 -> 1618 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/texture.vert19
-rw-r--r--src/quick/scenegraph/shaders_ng/texture.vert.qsbbin0 -> 1865 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/vertexcolor.frag9
-rw-r--r--src/quick/scenegraph/shaders_ng/vertexcolor.frag.qsbbin0 -> 851 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/vertexcolor.vert19
-rw-r--r--src/quick/scenegraph/shaders_ng/vertexcolor.vert.qsbbin0 -> 1837 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/visualization.frag19
-rw-r--r--src/quick/scenegraph/shaders_ng/visualization.frag.qsbbin0 -> 1877 bytes
-rw-r--r--src/quick/scenegraph/shaders_ng/visualization.vert30
-rw-r--r--src/quick/scenegraph/shaders_ng/visualization.vert.qsbbin0 -> 2099 bytes
-rw-r--r--src/quick/scenegraph/util/qsgdefaultpainternode.cpp24
-rw-r--r--src/quick/scenegraph/util/qsgdefaultpainternode_p.h11
-rw-r--r--src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp4
-rw-r--r--src/quick/scenegraph/util/qsgengine.cpp25
-rw-r--r--src/quick/scenegraph/util/qsgengine.h2
-rw-r--r--src/quick/scenegraph/util/qsgflatcolormaterial.cpp55
-rw-r--r--src/quick/scenegraph/util/qsgopenglatlastexture.cpp (renamed from src/quick/scenegraph/util/qsgatlastexture.cpp)33
-rw-r--r--src/quick/scenegraph/util/qsgopenglatlastexture_p.h (renamed from src/quick/scenegraph/util/qsgatlastexture_p.h)10
-rw-r--r--src/quick/scenegraph/util/qsgplaintexture.cpp457
-rw-r--r--src/quick/scenegraph/util/qsgplaintexture_p.h (renamed from src/quick/scenegraph/util/qsgtexture_p.h)60
-rw-r--r--src/quick/scenegraph/util/qsgrhiatlastexture.cpp491
-rw-r--r--src/quick/scenegraph/util/qsgrhiatlastexture_p.h217
-rw-r--r--src/quick/scenegraph/util/qsgrhinativetextureimporter.cpp104
-rw-r--r--src/quick/scenegraph/util/qsgrhinativetextureimporter_p.h70
-rw-r--r--src/quick/scenegraph/util/qsgsimplematerial.cpp5
-rw-r--r--src/quick/scenegraph/util/qsgsimplerectnode.cpp8
-rw-r--r--src/quick/scenegraph/util/qsgsimpletexturenode.cpp8
-rw-r--r--src/quick/scenegraph/util/qsgtexturematerial.cpp120
-rw-r--r--src/quick/scenegraph/util/qsgtexturematerial_p.h23
-rw-r--r--src/quick/scenegraph/util/qsgvertexcolormaterial.cpp54
-rw-r--r--src/quick/util/qquickanimation.cpp2
-rw-r--r--src/quick/util/qquickanimatorjob.cpp2
-rw-r--r--src/quick/util/qquickbehavior.cpp2
-rw-r--r--src/quick/util/qquickboundaryrule.cpp574
-rw-r--r--src/quick/util/qquickboundaryrule_p.h145
-rw-r--r--src/quick/util/qquickglobal.cpp7
-rw-r--r--src/quick/util/qquickimageprovider_p.h2
-rw-r--r--src/quick/util/qquickpath.cpp353
-rw-r--r--src/quick/util/qquickpath_p.h58
-rw-r--r--src/quick/util/qquickpath_p_p.h1
-rw-r--r--src/quick/util/qquickpixmapcache.cpp119
-rw-r--r--src/quick/util/qquickpixmapcache_p.h5
-rw-r--r--src/quick/util/qquickpropertychanges.cpp99
-rw-r--r--src/quick/util/qquickpropertychanges_p.h6
-rw-r--r--src/quick/util/qquickshortcut.cpp2
-rw-r--r--src/quick/util/qquickshortcut_p.h4
-rw-r--r--src/quick/util/qquickstate.cpp60
-rw-r--r--src/quick/util/qquickstate_p.h8
-rw-r--r--src/quick/util/qquickstate_p_p.h10
-rw-r--r--src/quick/util/qquickstategroup.cpp7
-rw-r--r--src/quick/util/qquickutilmodule.cpp9
-rw-r--r--src/quick/util/qquickvalidator.cpp46
-rw-r--r--src/quick/util/qquickvalidator_p.h3
-rw-r--r--src/quick/util/qquickvaluetypes.cpp5
-rw-r--r--src/quick/util/qquickvaluetypes_p.h2
-rw-r--r--src/quick/util/util.pri2
352 files changed, 20958 insertions, 3384 deletions
diff --git a/src/quick/configure.json b/src/quick/configure.json
index 9ec3531ef4..0cb1e7470b 100644
--- a/src/quick/configure.json
+++ b/src/quick/configure.json
@@ -1,8 +1,10 @@
{
"module": "quick",
"depends": [
+ "core-private",
"qml-private",
- "gui-private"
+ "gui-private",
+ "qmlmodels-private"
],
"testDir": "../../config.tests",
@@ -112,6 +114,7 @@
"label": "TableView item",
"purpose": "Provides the TableView item.",
"section": "Qt Quick",
+ "condition": "features.qml-table-model",
"output": [
"privateFeature"
]
@@ -178,6 +181,18 @@
"output": [
"privateFeature"
]
+ },
+ "quick-draganddrop": {
+ "label": "Drag & Drop",
+ "purpose": "Drag and drop support for Qt Quick",
+ "section": "Qt Quick",
+ "condition": [
+ "features.draganddrop",
+ "features.regularexpression"
+ ],
+ "output": [
+ "publicFeature"
+ ]
}
},
diff --git a/src/quick/designer/qqmldesignermetaobject.cpp b/src/quick/designer/qqmldesignermetaobject.cpp
index 2efcdada8b..de7da7f9be 100644
--- a/src/quick/designer/qqmldesignermetaobject.cpp
+++ b/src/quick/designer/qqmldesignermetaobject.cpp
@@ -45,7 +45,6 @@
#include <QDebug>
#include <private/qqmlengine_p.h>
-#include <private/qqmlpropertycache_p.h>
QT_BEGIN_NAMESPACE
@@ -137,7 +136,7 @@ QQmlDesignerMetaObject::QQmlDesignerMetaObject(QObject *object, QQmlEngine *engi
//Assign cache to object
if (ddata && ddata->propertyCache) {
cache->setParent(ddata->propertyCache);
- cache->invalidate(engine, this);
+ cache->invalidate(this);
ddata->propertyCache->release();
ddata->propertyCache = cache.data();
ddata->propertyCache->addref();
@@ -162,7 +161,7 @@ void QQmlDesignerMetaObject::createNewDynamicProperty(const QString &name)
//Updating cache
QQmlPropertyCache *oldParent = cache->parent();
- QQmlEnginePrivate::get(m_context->engine())->cache(this)->invalidate(m_context->engine(), this);
+ QQmlEnginePrivate::get(m_context->engine())->cache(this)->invalidate(this);
cache->setParent(oldParent);
QQmlProperty property(myObject(), name, m_context);
diff --git a/src/quick/designer/qquickdesignercustomparserobject.cpp b/src/quick/designer/qquickdesignercustomparserobject.cpp
index 50a8b6a25b..841aae5bc3 100644
--- a/src/quick/designer/qquickdesignercustomparserobject.cpp
+++ b/src/quick/designer/qquickdesignercustomparserobject.cpp
@@ -46,12 +46,12 @@ QQuickDesignerCustomParserObject::QQuickDesignerCustomParserObject()
}
-void QQuickDesignerCustomParser::verifyBindings(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &)
+void QQuickDesignerCustomParser::verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &)
{
/* Nothing to do we accept anything */
}
-void QQuickDesignerCustomParser::applyBindings(QObject *, const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &)
+void QQuickDesignerCustomParser::applyBindings(QObject *, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &, const QList<const QV4::CompiledData::Binding *> &)
{
/* Nothing to do we accept anything */
}
diff --git a/src/quick/designer/qquickdesignercustomparserobject_p.h b/src/quick/designer/qquickdesignercustomparserobject_p.h
index b38417d102..4da00ea841 100644
--- a/src/quick/designer/qquickdesignercustomparserobject_p.h
+++ b/src/quick/designer/qquickdesignercustomparserobject_p.h
@@ -70,8 +70,8 @@ public:
QQuickDesignerCustomParser()
: QQmlCustomParser(AcceptsAttachedProperties | AcceptsSignalHandlers) {}
- void verifyBindings(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &props) override;
- void applyBindings(QObject *obj, const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) override;
+ void verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &props) override;
+ void applyBindings(QObject *obj, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) override;
};
QT_END_NAMESPACE
diff --git a/src/quick/designer/qquickdesignerwindowmanager.cpp b/src/quick/designer/qquickdesignerwindowmanager.cpp
index 093559a572..9648a40a23 100644
--- a/src/quick/designer/qquickdesignerwindowmanager.cpp
+++ b/src/quick/designer/qquickdesignerwindowmanager.cpp
@@ -39,10 +39,10 @@
#include "qquickdesignerwindowmanager_p.h"
#include "private/qquickwindow_p.h"
+#include <QtQuick/QQuickWindow>
#if QT_CONFIG(opengl)
-# include <QtQuick/private/qsgdefaultrendercontext_p.h>
+#include <private/qsgdefaultrendercontext_p.h>
#endif
-#include <QtQuick/QQuickWindow>
QT_BEGIN_NAMESPACE
@@ -74,7 +74,12 @@ void QQuickDesignerWindowManager::makeOpenGLContext(QQuickWindow *window)
m_openGlContext->create();
if (!m_openGlContext->makeCurrent(window))
qWarning("QQuickWindow: makeCurrent() failed...");
- m_renderContext->initialize(m_openGlContext.data());
+ QSGDefaultRenderContext::InitParams params;
+ params.sampleCount = qMax(1, m_openGlContext->format().samples());
+ params.openGLContext = m_openGlContext.data();
+ params.initialSurfacePixelSize = window->size() * window->effectiveDevicePixelRatio();
+ params.maybeSurface = window;
+ m_renderContext->initialize(&params);
} else {
m_openGlContext->makeCurrent(window);
}
diff --git a/src/quick/designer/qquickdesignerwindowmanager_p.h b/src/quick/designer/qquickdesignerwindowmanager_p.h
index 5322b6c421..5e387ff5b9 100644
--- a/src/quick/designer/qquickdesignerwindowmanager_p.h
+++ b/src/quick/designer/qquickdesignerwindowmanager_p.h
@@ -55,18 +55,17 @@
#include <private/qsgrenderloop_p.h>
#include <private/qtquickglobal_p.h>
-#include <QtQuick/private/qsgcontext_p.h>
+#include <private/qsgcontext_p.h>
#if QT_CONFIG(opengl)
# include <QtGui/QOpenGLContext>
#endif
-
QT_BEGIN_NAMESPACE
class QQuickWindow;
class QSGContext;
-class QSGRenderContext;
+class QSGDefaultRenderContext;
class QAnimationDriver;
class QQuickDesignerWindowManager : public QSGRenderLoop
diff --git a/src/quick/doc/qtquick.qdocconf b/src/quick/doc/qtquick.qdocconf
index 56f1f20b3e..91458527dd 100644
--- a/src/quick/doc/qtquick.qdocconf
+++ b/src/quick/doc/qtquick.qdocconf
@@ -41,9 +41,11 @@ tagfile = ../../../doc/qtquick/qtquick.tags
depends += qtcore qtqml qtqmltest qtgui qtlinguist qtquickcontrols qtquickcontrols1 qtdoc qtquickdialogs qtsensors qtwidgets qmake qtmultimedia qtgraphicaleffects qtsql qtxmlpatterns
headerdirs += ..\
+ ../../quick \
../../quickwidgets
sourcedirs += .. \
+ ../../quick \
../../quickwidgets
exampledirs += ../../../examples/quick \
diff --git a/src/quick/doc/snippets/cmake-macros/examples.cmake b/src/quick/doc/snippets/cmake-macros/examples.cmake
new file mode 100644
index 0000000000..8ca6180f9b
--- /dev/null
+++ b/src/quick/doc/snippets/cmake-macros/examples.cmake
@@ -0,0 +1,6 @@
+#! [qt5_import_qml_plugins]
+find_package(Qt5 COMPONENTS Quick QmlImportScanner)
+add_executable(myapp main.cpp)
+target_link_libraries(myapp Qt5::Quick)
+qt5_import_qml_plugins(myapp)
+#! [qt5_import_plugins]
diff --git a/src/quick/doc/snippets/pointerHandlers/handlerFlick.qml b/src/quick/doc/snippets/pointerHandlers/handlerFlick.qml
new file mode 100644
index 0000000000..f74b075357
--- /dev/null
+++ b/src/quick/doc/snippets/pointerHandlers/handlerFlick.qml
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+//![0]
+import QtQuick 2.14
+import Qt.labs.animation 1.0
+
+Item {
+ width: 320; height: 480
+ Flow {
+ id: content
+ width: parent.width
+ spacing: 2; padding: 2
+
+ WheelHandler {
+ orientation: Qt.Vertical
+ property: "y"
+ rotationScale: 15
+ acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
+ onActiveChanged: if (!active) ybr.returnToBounds()
+ }
+
+ DragHandler {
+ xAxis.enabled: false
+ onActiveChanged: if (!active) ybr.returnToBounds()
+ }
+
+ BoundaryRule on y {
+ id: ybr
+ minimum: content.parent.height - content.height
+ maximum: 0
+ minimumOvershoot: 400; maximumOvershoot: 400
+ overshootFilter: BoundaryRule.Peak
+ }
+
+ Repeater {
+ model: 1000
+ Rectangle { color: "gray"; width: 10 + Math.random() * 100; height: 15 }
+ }
+ }
+}
+//![0]
diff --git a/src/quick/doc/snippets/pointerHandlers/wheelHandler.qml b/src/quick/doc/snippets/pointerHandlers/wheelHandler.qml
new file mode 100644
index 0000000000..2c9913ac97
--- /dev/null
+++ b/src/quick/doc/snippets/pointerHandlers/wheelHandler.qml
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+//![0]
+import QtQuick 2.14
+
+Rectangle {
+ width: 170; height: 120
+ color: "green"; antialiasing: true
+
+ WheelHandler {
+ property: "rotation"
+ onWheel: console.log("rotation", event.angleDelta.y,
+ "scaled", rotation, "@", point.position, "=>", parent.rotation)
+ }
+}
+//![0]
diff --git a/src/quick/doc/snippets/qml/boundaryRule.qml b/src/quick/doc/snippets/qml/boundaryRule.qml
new file mode 100644
index 0000000000..c010f5de5e
--- /dev/null
+++ b/src/quick/doc/snippets/qml/boundaryRule.qml
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+//![0]
+import QtQuick 2.14
+import Qt.labs.animation 1.0
+
+Rectangle {
+ id: root
+ width: 170; height: 120
+ color: "green"
+
+ DragHandler {
+ id: dragHandler
+ yAxis.minimum: -1000
+ xAxis.minimum: -1000
+ onActiveChanged: if (!active) xbr.returnToBounds();
+ }
+
+ BoundaryRule on x {
+ id: xbr
+ minimum: -50
+ maximum: 100
+ minimumOvershoot: 40
+ maximumOvershoot: 40
+ }
+}
+//![0]
diff --git a/src/quick/doc/snippets/qml/qml-extending-types/signals/Button.qml b/src/quick/doc/snippets/qml/qml-extending-types/signals/Button.qml
index b40f517234..96f7fc1c7c 100644
--- a/src/quick/doc/snippets/qml/qml-extending-types/signals/Button.qml
+++ b/src/quick/doc/snippets/qml/qml-extending-types/signals/Button.qml
@@ -55,7 +55,7 @@ Rectangle {
id: rect
width: 100; height: 100
- signal buttonClicked(int xPos, int yPos)
+ signal buttonClicked(xPos: int, yPos: int)
MouseArea {
anchors.fill: parent
diff --git a/src/quick/doc/snippets/qml/regularexpression.qml b/src/quick/doc/snippets/qml/regularexpression.qml
new file mode 100644
index 0000000000..f6f4a4171a
--- /dev/null
+++ b/src/quick/doc/snippets/qml/regularexpression.qml
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.14
+//![0]
+TextInput {
+ id: hexNumber
+ validator: RegularExpressionValidator { regularExpression: /[0-9A-F]+/ }
+}
+//![0]
diff --git a/src/quick/doc/snippets/qml/tableview/tablemodel.cpp b/src/quick/doc/snippets/qml/tableview/cpp-tablemodel.cpp
index ea9f76f131..ea9f76f131 100644
--- a/src/quick/doc/snippets/qml/tableview/tablemodel.cpp
+++ b/src/quick/doc/snippets/qml/tableview/cpp-tablemodel.cpp
diff --git a/src/quick/doc/snippets/qml/tableview/tablemodel.qml b/src/quick/doc/snippets/qml/tableview/cpp-tablemodel.qml
index 8a8ec94958..8a8ec94958 100644
--- a/src/quick/doc/snippets/qml/tableview/tablemodel.qml
+++ b/src/quick/doc/snippets/qml/tableview/cpp-tablemodel.qml
diff --git a/src/quick/doc/snippets/qml/tableview/qml-tablemodel.qml b/src/quick/doc/snippets/qml/tableview/qml-tablemodel.qml
new file mode 100644
index 0000000000..a01a2a628a
--- /dev/null
+++ b/src/quick/doc/snippets/qml/tableview/qml-tablemodel.qml
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//![0]
+import QtQuick 2.14
+import Qt.labs.qmlmodels 1.0
+
+TableView {
+ anchors.fill: parent
+ columnSpacing: 1
+ rowSpacing: 1
+ clip: true
+
+ model: TableModel {
+ TableModelColumn { display: "name" }
+ TableModelColumn { display: "color" }
+
+ rows: [
+ {
+ "name": "cat",
+ "color": "black"
+ },
+ {
+ "name": "dog",
+ "color": "brown"
+ },
+ {
+ "name": "bird",
+ "color": "white"
+ }
+ ]
+ }
+
+ delegate: Rectangle {
+ implicitWidth: 100
+ implicitHeight: 50
+ border.width: 1
+
+ Text {
+ text: display
+ anchors.centerIn: parent
+ }
+ }
+}
+//![0]
diff --git a/src/quick/doc/snippets/qml/texthandling.qml b/src/quick/doc/snippets/qml/texthandling.qml
index 0fb5fc130f..6c086f8501 100644
--- a/src/quick/doc/snippets/qml/texthandling.qml
+++ b/src/quick/doc/snippets/qml/texthandling.qml
@@ -48,7 +48,7 @@
**
****************************************************************************/
//! [document]
-import QtQuick 2.0
+import QtQuick 2.14
//! [parent begin]
@@ -83,7 +83,7 @@ Column {
}
TextInput {
focus: true
- validator: RegExpValidator { regExp: /fruit basket/ }
+ validator: RegularExpressionValidator { regularExpression: /fruit basket/ }
}
}
//! [regexp validator]
diff --git a/src/quick/doc/src/cmake-macros.qdoc b/src/quick/doc/src/cmake-macros.qdoc
new file mode 100644
index 0000000000..b643a9e4e4
--- /dev/null
+++ b/src/quick/doc/src/cmake-macros.qdoc
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+\page qtqml-cmake-qt5-import-qml-plugins.html
+\ingroup cmake-macros-qtqml
+
+\title qt5_import_qml_plugins
+
+\brief Scans \c{.qml} files and imports required QML static plugins
+
+\section1 Overview
+
+\badcode
+find_package(Qt5QmlImportScanner REQUIRED)
+qt5_import_qml_plugins(<TARGET>)
+\endcode
+
+\section1 Description
+
+Runs \c{qmlimportscanner} at configure time to find the static QML plugins
+used and links them to the given target.
+
+\note When used with a non-static Qt build, this function does nothing.
+
+This CMake command was introduced in Qt 5.14.
+
+\section1 Example
+
+\snippet cmake-macros/examples.cmake qt5_import_qml_plugins
+
+*/
diff --git a/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc b/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc
index 8edc5cb0b6..e83aa39734 100644
--- a/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc
+++ b/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc
@@ -31,15 +31,35 @@
\section1 Scene Graph Adaptations in Qt Quick
-Originally, Qt Quick always relied on OpenGL (OpenGL ES 2.0 or OpenGL 2.0) to parse the scene graph
-and render the results to a render target. From Qt 5.8 onwards, Qt Quick also supports rendering in
-software and with Direct3D 12.
+Originally, Qt Quick always relied on OpenGL (OpenGL ES 2.0 or OpenGL 2.0) to
+parse the scene graph and render the results to a render target
+
+From Qt 5.8 onwards, Qt Quick also supports rendering in software, with OpenVG,
+and with Direct3D 12. This is realized by having additional scene graph
+adaptations, either in form of plugins (d3d12, openvg) or built-in to the Qt
+Quick library (software). The default adaptation continues to rely directly on
+OpenGL.
+
+From Qt 5.14 onwards, the default adaptation gains the option of rendering via
+a graphics abstraction layer, the Qt Rendering Hardware Interface (RHI),
+provided by the \l QtGui module. When enabled, no direct OpenGL calls are made.
+Rather, the scene graph renders by using the APIs provided by the abstraction
+layer, which is then translated into OpenGL, Vulkan, Metal, or Direct 3D calls.
+Shader handling is also unified by writing shader code once, compiling to
+\l{https://www.khronos.org/spir/}{SPIR-V}, and then translating to the language
+appropriate for the various graphics APIs.
\target Switching Between the Adaptation Used by the Application
\section1 Switch Between Adaptations in Your Application
-The default rendering backend is still OpenGL, but in Qt builds with OpenGL support disabled, the
-default is the software renderer. You can override this in one of two ways:
+Unlike \c software or \c d3d12, the RHI-based renderer is not an additional
+adaptation, and is always built-in. As of Qt 5.14 it can be enabled by setting
+the environment variable \c{QSG_RHI} to a non-zero value before starting the
+application, or via \l QQuickWindow::setScenegraphBackend() in combination with
+\l QSGRendererInterface::GraphicsApi. When none of this is done, OpenGL is used
+directly like in previous versions.
+
+Switching to a different adaptation can be achieved in two ways:
\list
\li Use an environment variable - Set the \c{QT_QUICK_BACKEND} or the legacy
@@ -51,7 +71,8 @@ default is the software renderer. You can override this in one of two ways:
The following backends are supported:
\list
- \li OpenGL - Request with the \c{""} string or the QSGRendererInterface::OpenGL enum value.
+ \li Default - Request with the \c{""} string or a QSGRendererInterface::GraphicsApi enum value
+ different than the ones listed below.
\li Software - Request with the \c{"software"} string or the QSGRendererInterface::Software
enum value.
\li Direct3D 12 - Request with the \c{"d3d12"} string or the QSGRendererInterface::Direct3D12
@@ -64,16 +85,25 @@ To find out which backend is in use, you can enable basic scene graph informatio
\c{QSG_INFO} environment variable or the \c{qt.scenegraph.general} logging category. This results
in some information being printed onto the debug output, during application startup.
-\note Typically, adaptations other than OpenGL come with a set of limitations as they are unlikely
- to provide a feature set that's 100% compatible with OpenGL. However, these adaptations may
- provide their own specific advantages in certain areas. For more information on the various
- adaptations, refer to the sections below.
+\note In Qt builds with OpenGL disabled, the default adaptation is \c software.
+This may change in future releases.
+
+\note Typically, adaptations other than the default one come with a set of
+limitations as they are unlikely to provide a feature set that's 100%
+compatible with OpenGL. However, these adaptations may provide their own
+specific advantages in certain areas. For more information on the various
+adaptations, refer to the sections below.
+
+\section1 Default Adaptation
-\section1 OpenGL ES 2.0 and OpenGL 2.0 Adaptation
+When using OpenGL directly, the default adaptation is capable of providing the
+full Qt Quick 2 feature set. For more details, see
+\l{qtquick-visualcanvas-scenegraph-renderer.html}{Default Adaptation}.
-The OpenGL adaptation is the default adaptation, which is capable of providing the full Qt Quick 2
-feature set. For more details, see
-\l{qtquick-visualcanvas-scenegraph-renderer.html}{OpenGL Adaptation}.
+When using OpenGL, Vulkan, Metal, or Direct 3D via the RHI, the default
+adaptation is capable of providing most features, including the full batching
+renderer described in \l{qtquick-visualcanvas-scenegraph-renderer.html}{Default
+Adaptation}, but some additional features may not be available as of Qt 5.14.
\section1 Software Adaptation
diff --git a/src/quick/doc/src/concepts/visualcanvas/scenegraph.qdoc b/src/quick/doc/src/concepts/visualcanvas/scenegraph.qdoc
index ee6c501c71..e09c430e43 100644
--- a/src/quick/doc/src/concepts/visualcanvas/scenegraph.qdoc
+++ b/src/quick/doc/src/concepts/visualcanvas/scenegraph.qdoc
@@ -31,15 +31,13 @@
\section1 The Scene Graph in Qt Quick
-Qt Quick 2 makes use of a dedicated scene graph based and a series of
-adaptations of which the default uses OpenGL ES 2.0 or OpenGL 2.0 for
-its rendering. Using a scene graph for graphics rather than the
-traditional imperative painting systems (QPainter and
-similar), means the scene to be rendered can be retained between
-frames and the complete set of primitives to render is known before
-rendering starts. This opens up for a number of optimizations, such as
-batch rendering to minimize state changes and discarding obscured
-primitives.
+Qt Quick 2 makes use of a dedicated scene graph that is then traversed and
+rendered via a graphics API such as OpenGL ES, OpenGL, Vulkan, Metal, or Direct
+3D. Using a scene graph for graphics rather than the traditional imperative
+painting systems (QPainter and similar), means the scene to be rendered can be
+retained between frames and the complete set of primitives to render is known
+before rendering starts. This opens up for a number of optimizations, such as
+batch rendering to minimize state changes and discarding obscured primitives.
For example, say a user-interface contains a list of ten items
where each item has a background color, an icon and a text. Using the
@@ -63,9 +61,10 @@ independently of the state of the items. On many platforms, the scene
graph will even be rendered on a dedicated render thread while the GUI
thread is preparing the next frame's state.
-\note Much of the information listed on this page is specific to the
-default OpenGL adaptation of the Qt Quick Scene graph. For more information
-about the different scene graph adaptations see
+\note Much of the information listed on this page is specific to the built-in,
+default behavior of the Qt Quick Scene graph. When using an alternative scene
+graph adaptation, such as, the \c software adaptation, not all concepts may
+apply. For more information about the different scene graph adaptations see
\l{qtquick-visualcanvas-adaptations.html}{Scene Graph Adaptations}.
@@ -106,10 +105,10 @@ Custom nodes are added to the scene graph by subclassing
QQuickItem::updatePaintNode() and setting the
\l {QQuickItem::ItemHasContents} flag.
-\warning It is crucial that OpenGL operations and interaction with the
-scene graph happens exclusively on the render thread, primarily
-during the updatePaintNode() call. The rule of thumb is to only
-use classes with the "QSG" prefix inside the
+\warning It is crucial that native graphics (OpenGL, Vulkan, Metal, etc.)
+operations and interaction with the scene graph happens exclusively on the
+render thread, primarily during the updatePaintNode() call. The rule of thumb
+is to only use classes with the "QSG" prefix inside the
QQuickItem::updatePaintNode() function.
For more details, see the \l {Scene Graph - Custom Geometry}.
@@ -133,11 +132,11 @@ simplifies cleanup when the scene graph lives outside the GUI thread.
\section2 Materials
-The material describes how the interior of a geometry in a \l
-QSGGeometryNode is filled. It encapsulates an OpenGL shader program
-and provides ample flexibility in what can be achieved, though most of
-the Qt Quick items themselves only use very basic materials, such as
-solid color and texture fills.
+The material describes how the interior of a geometry in a \l QSGGeometryNode
+is filled. It encapsulates graphics shaders for the vertex and fragment stages
+of the graphics pipeline and provides ample flexibility in what can be
+achieved, though most of the Qt Quick items themselves only use very basic
+materials, such as solid color and texture fills.
For users who just want to apply custom shading to a QML Item type,
it is possible to do this directly in QML using the \l ShaderEffect
@@ -151,11 +150,11 @@ For more details, see the \l {Scene Graph - Simple Material}
\section2 Convenience Nodes
-The scene graph API is very low-level and focuses on performance
-rather than convenience. Writing custom geometries and materials from
-scratch, even the most basic ones, requires a non-trivial amount of
-code. For this reason, the API includes a few convenience classes to
-make the most common custom nodes readily available.
+The scene graph API is low-level and focuses on performance rather than
+convenience. Writing custom geometries and materials from scratch, even the
+most basic ones, requires a non-trivial amount of code. For this reason, the
+API includes a few convenience classes to make the most common custom nodes
+readily available.
\list
\li \l QSGSimpleRectNode - a QSGGeometryNode subclass which defines a
@@ -169,15 +168,16 @@ a rectangular geometry with a texture material.
\section1 Scene Graph and Rendering
-The rendering of the scene graph happens internally in the
-QQuickWindow class, and there is no public API to access it. There are,
-however, a few places in the rendering pipeline where the user can
-attach application code. This can be used to add custom scene graph
-content or render raw OpenGL content. The integration points are
-defined by the render loop.
+The rendering of the scene graph happens internally in the QQuickWindow class,
+and there is no public API to access it. There are, however, a few places in
+the rendering pipeline where the user can attach application code. This can be
+used to add custom scene graph content or to insert arbitrary rendering
+commands by directly calling the graphics API (OpenGL, Vulkan, Metal, etc.)
+that is in use by the scene graph. The integration points are defined by the
+render loop.
-For detailed description of how the scene graph renderer for OpenGL
-works, see \l {Qt Quick Scene Graph OpenGL Renderer}.
+For detailed description of how the scene graph renderer works, see \l {Qt
+Quick Scene Graph Default Renderer}.
There are three render loop variants available: \c basic, \c windows,
and \c threaded. Out of these, \c basic and \c windows are
@@ -189,14 +189,14 @@ satisfactory, or for testing purposes, the environment variable
verify which render loop is in use, enable the \c qt.scenegraph.general
\l {QLoggingCategory}{logging category}.
-\note The \c threaded and \c windows render loops rely on the OpenGL
-implementation for throttling by requesting a swap interval of 1. Some
-graphics drivers allow users to override this setting and turn it off,
-ignoring Qt's request. Without blocking in the swap buffers operation
-(or elsewhere), the render loop will run animations too fast and spin
-the CPU at 100%. If a system is known to be unable to provide
-vsync-based throttling, use the \c basic render loop instead by
-setting \c {QSG_RENDER_LOOP=basic} in the environment.
+\note The \c threaded and \c windows render loops rely on the graphics API
+implementation for throttling, for example, by requesting a swap interval of 1
+in case of OpenGL. Some graphics drivers allow users to override this setting
+and turn it off, ignoring Qt's request. Without blocking in the swap buffers
+operation (or elsewhere), the render loop will run animations too fast and spin
+the CPU at 100%. If a system is known to be unable to provide vsync-based
+throttling, use the \c basic render loop instead by setting \c
+{QSG_RENDER_LOOP=basic} in the environment.
\section2 Threaded Render Loop ("threaded")
@@ -207,8 +207,9 @@ waiting for a blocking swap buffer call. This offers significant
performance improvements, but imposes certain restrictions on where
and when interaction with the scene graph can happen.
-The following is a simple outline of how a frame gets
-composed with the threaded render loop.
+The following is a simple outline of how a frame gets rendered with the
+threaded render loop and OpenGL. The steps are the same with other graphics
+APIs as well, apart from the OpenGL context specifics.
\image sg-renderloop-threaded.png
@@ -219,8 +220,8 @@ to be called. This can be the result of for instance an animation or
user input. An event is posted to the render thread to initiate a new
frame.
-\li The render thread prepares to draw a new frame and makes the
-OpenGL context current and initiates a block on the GUI thread.
+\li The render thread prepares to draw a new frame and initiates a block on the
+GUI thread.
\li While the render thread is preparing the new frame, the GUI thread
calls QQuickItem::updatePolish() to do final touch-up of items before
@@ -243,23 +244,27 @@ time the QML items and the nodes in the scene graph interact.
\li The scene graph is rendered:
\list 1
- \li The QQuickWindow::beforeRendering() signal is
- emitted. Applications can make direct connections
- (using Qt::DirectConnection) to this signal to use custom OpenGL calls
- which will then stack visually beneath the QML scene.
+ \li The QQuickWindow::beforeRendering() signal is emitted. Applications can
+ make direct connections (using Qt::DirectConnection) to this signal to use
+ custom graphics API calls which will then stack visually beneath the QML
+ scene.
\li Items that have specified QSGNode::UsePreprocess, will have their
QSGNode::preprocess() function invoked.
- \li The renderer processes the nodes and calls OpenGL functions.
+ \li The renderer processes the nodes.
- \li The QQuickWindow::afterRendering() signal is
- emitted. Applications can make direct connections
- (using Qt::DirectConnection) to this signal to use custom OpenGL calls
- which will then stack visually over the QML scene.
+ \li The renderer generates states and records draw calls for the graphics
+ API in use.
- \li The rendered frame is swapped and QQuickWindow::frameSwapped()
- is emitted.
+ \li The QQuickWindow::afterRendering() signal is emitted. Applications can
+ make direct connections (using Qt::DirectConnection) to this signal to
+ issue custom graphics API calls which will then stack visually over the QML
+ scene.
+
+ \li The frame is now ready. The buffers are swapped (OpenGL), or a present
+ command is recorded and the command buffers are submitted to a graphics
+ queue (Vulkan, Metal). QQuickWindow::frameSwapped() is emitted.
\endlist
@@ -269,37 +274,38 @@ animations, process events, etc.
\endlist
The threaded renderer is currently used by default on Windows with
-opengl32.dll, Linux with non-Mesa based drivers, mobile
-platforms, and Embedded Linux with EGLFS but this is subject to
-change. It is possible to force use of the threaded renderer by
-setting \c {QSG_RENDER_LOOP=threaded} in the environment.
+opengl32.dll, Linux excluding Mesa llvmpipe, \macos with Metal, mobile
+platforms, and Embedded Linux with EGLFS, and with Vulkan regardless of the
+platform, but this is subject to change. It is always possible to force use of
+the threaded renderer by setting \c {QSG_RENDER_LOOP=threaded} in the
+environment.
\section2 Non-threaded Render Loops ("basic" and "windows")
-The non-threaded render loop is currently used by default on Windows
-with ANGLE or a non-default opengl32 implementation, \macos, and Linux with
-Mesa drivers. For the latter this is mostly a precautionary measure,
-as not all combinations of OpenGL drivers and windowing systems have
-been tested. At the same time implementations like ANGLE or Mesa
-llvmpipe are not able to function properly with threaded rendering at
-all so not using threaded rendering is essential for these.
+The non-threaded render loop is currently used by default on Windows with ANGLE
+or a non-default opengl32 implementation, \macos with OpenGL, and Linux with
+some drivers. For the latter this is mostly a precautionary measure, as not all
+combinations of OpenGL drivers and windowing systems have been tested. At the
+same time implementations like ANGLE or Mesa llvmpipe are not able to function
+properly with threaded rendering at all so not using threaded rendering is
+essential for these.
-On macOS, the threaded render loop is not supported when building
-with XCode 10 (10.14 SDK) or later, since this opts in to layer-backed
-views on macOS 10.14. You can build with Xcode 9 (10.13 SDK) to opt
-out of layer-backing, in which case the threaded render loop is
-available and used by default.
+On macOS and OpenGL, the threaded render loop is not supported when building
+with XCode 10 (10.14 SDK) or later, since this opts in to layer-backed views on
+macOS 10.14. You can build with Xcode 9 (10.13 SDK) to opt out of
+layer-backing, in which case the threaded render loop is available and used by
+default. There is no such restriction with Metal.
-By default \c windows is used for non-threaded rendering on Windows
-with ANGLE, while \c basic is used for all other platforms when
-non-threaded rendering is needed.
+By default \c windows is used for non-threaded rendering on Windows with ANGLE,
+while \c basic is used for all other platforms when non-threaded rendering is
+needed.
-Even when using the non-threaded render loop, you should write your
-code as if you are using the threaded renderer, as failing to do so
-will make the code non-portable.
+Even when using the non-threaded render loop, you should write your code as if
+you are using the threaded renderer, as failing to do so will make the code
+non-portable.
-The following is a simplified illustration of the frame rendering
-sequence in the non-threaded renderer.
+The following is a simplified illustration of the frame rendering sequence in
+the non-threaded renderer.
\image sg-renderloop-singlethreaded.png
@@ -314,32 +320,50 @@ time. It is possible to implement either a threaded or non-threaded
behavior similar to the ones shown above.
-\section2 Mixing Scene Graph and OpenGL
+\section2 Mixing Scene Graph and the native graphics API
-The scene graph offers two methods for integrating OpenGL content:
-by calling OpenGL commands directly and by creating a textured node
-in the scene graph.
+The scene graph offers two methods for integrating application-provided
+graphics commands: by issuing OpenGL, Vulkan, Metal, etc. commands directly,
+and by creating a textured node in the scene graph.
By connecting to the \l QQuickWindow::beforeRendering() and \l
-QQuickWindow::afterRendering() signals, applications can make OpenGL
-calls directly into the same context as the scene graph is rendering
-to. As the signal names indicate, the user can then render OpenGL
-content either under a Qt Quick scene or over it. The benefit of
-integrating in this manner is that no extra framebuffer nor memory is
-needed to perform the rendering. The downside is that Qt Quick decides
-when to call the signals and this is the only time the OpenGL
-application is allowed to draw.
+QQuickWindow::afterRendering() signals, applications can make OpenGL calls
+directly into the same context as the scene graph is rendering to. With APIs
+like Vulkan or Metal, applications can query native objects, such as, the scene
+graph's command buffer, via QSGRendererInterface, and record commands to it as
+they see fit. As the signal names indicate, the user can then render content
+either under a Qt Quick scene or over it. The benefit of integrating in this
+manner is that no extra framebuffer nor memory is needed to perform the
+rendering, and a possibly expensive texturing step is eliminated. The downside
+is that Qt Quick decides when to call the signals and this is the only time the
+OpenGL application is allowed to draw.
The \l {Scene Graph - OpenGL Under QML} example gives an example on
-how to use these signals.
+how to use these signals using OpenGL.
+
+The \l {Scene Graph - Direct3D 11 Under QML} example gives an example on
+how to use these signals using Direct3D.
+
+The \l {Scene Graph - Metal Under QML} example gives an example on
+how to use these signals using Metal.
+
+The \l {Scene Graph - Vulkan Under QML} example gives an example on
+how to use these signals using Vulkan.
-The other alternative is to create a QQuickFramebufferObject, render
-into it, and let it be displayed in the scene graph as a texture.
-The \l {Scene Graph - Rendering FBOs} example shows how this can be
-done. It is also possible to combine multiple rendering contexts and
-multiple threads to create content to be displayed in the scene graph.
-The \l {Scene Graph - Rendering FBOs in a thread} examples show how
-this can be done.
+The other alternative, only available for OpenGL currently, is to create a
+QQuickFramebufferObject, render into it, and let it be displayed in the scene
+graph as a texture. The \l {Scene Graph - Rendering FBOs} example shows how
+this can be done. It is also possible to combine multiple rendering contexts
+and multiple threads to create content to be displayed in the scene graph. The
+\l {Scene Graph - Rendering FBOs in a thread} examples show how this can be
+done.
+
+Graphics APIs other than OpenGL can also follow this approach, even though
+QQuickFramebufferObject does not currently support them. Creating and rendering
+to a texture directly with the underlying API, followed by wrapping and using
+this resource in a Qt Quick scene in a custom QQuickItem, is demonstrated in
+the \l {Scene Graph - Metal Texture Import} example. That example uses Metal,
+the concepts however apply to all other graphics APIs as well.
\warning When mixing OpenGL content with scene graph rendering, it is
important the application does not leave the OpenGL context in a state
@@ -347,8 +371,8 @@ with buffers bound, attributes enabled, special values in the z-buffer
or stencil-buffer or similar. Doing so can result in unpredictable
behavior.
-\warning The OpenGL rendering code must be thread aware, as the
-rendering might be happening outside the GUI thread.
+\warning The custom rendering code must be thread aware in the sense that it
+should not assume being executed on the GUI (main) thread of the application.
\section2 Custom Items using QPainter
@@ -386,6 +410,15 @@ addition to being helpful to Qt contributors.
\endlist
+The legacy \c{QSG_INFO} environment variable is also available. Setting it to a
+non-zero value enables the \c{qt.scenegraph.general} category.
+
+\note When encountering graphics problems, or when in doubt which render loop
+or graphics API is in use, always start the application with at least
+\c{qt.scenegraph.general} and \c{qt.rhi.*} enabled, or \c{QSG_INFO=1} set. This
+will then print some essential information onto the debug output during
+initialization.
+
\section1 Scene Graph Backend
In addition to the public API, the scene graph has an adaptation layer
@@ -419,13 +452,12 @@ with multiple windows.
*/
/*!
- \title Qt Quick Scene Graph OpenGL Renderer
+ \title Qt Quick Scene Graph Default Renderer
\page qtquick-visualcanvas-scenegraph-renderer.html
- This document explains how the scene graph renderer for OpenGL
- works internally
+ This document explains how the default scene graph renderer works internally,
so that one can write code that uses it in an optimal fashion, both
- performance-wise and feature-wise.
+ performance and feature-wise.
One does not need to understand the internals of the renderer to get
good performance. However, it might help when integrating with the
@@ -442,8 +474,8 @@ with multiple windows.
platforms be processed and rendered in a separate thread. The
renderer is a self contained part of the scene graph which traverses
the QSGNode tree and uses geometry defined in QSGGeometryNode and
- shader state defined in QSGMaterial to schedule OpenGL state change
- and draw calls.
+ shader state defined in QSGMaterial to update the graphics state and
+ generate draw calls.
If needed, the renderer can be completely replaced using the
internal scene graph back-end API. This is mostly interesting for
@@ -457,11 +489,15 @@ with multiple windows.
\section1 Batching
- Where a traditional 2D API, such as QPainter, Cairo or Context2D, is
- written to handle thousands of individual draw calls per frame,
- OpenGL is a pure hardware API and performs best when the number of
- draw calls is very low and state changes are kept to a
- minimum. Consider the following use case:
+ Whereas a traditional 2D API, such as QPainter, Cairo or Context2D, is
+ written to handle thousands of individual draw calls per frame, OpenGL and
+ other hardware accelerated APIs perform best when the number of draw calls is
+ very low and state changes are kept to a minimum.
+
+ \note While \c OpenGL is used as an example in the following sections, the
+ same concepts apply to other graphics APIs as well.
+
+ Consider the following use case:
\image visualcanvas_list.png
@@ -934,4 +970,78 @@ with multiple windows.
\image visualize-overdraw-1.png "overdraw-1"
\image visualize-overdraw-2.png "overdraw-2"
\c QSG_VISUALIZE=overdraw
+
+ \section1 Rendering via the Qt Rendering Hardware Interface
+
+ From Qt 5.14 onwards, the default adaptation gains the option of rendering
+ via a graphics abstraction layer, the Qt Rendering Hardware Interface (RHI),
+ provided by the \l QtGui module. When enabled, no direct OpenGL calls are
+ made. Rather, the scene graph renders by using the APIs provided by the
+ abstraction layer, which is then translated into OpenGL, Vulkan, Metal, or
+ Direct 3D calls. Shader handling is also unified by writing shader code once,
+ compiling to \l{https://www.khronos.org/spir/}{SPIR-V}, and then translating
+ to the language appropriate for the various graphics APIs.
+
+ To enable this instead of directly using OpenGL, the following environment
+ variables can be used:
+
+ \table 100%
+ \header
+ \li Environment Variable
+ \li Possible Values
+ \li Description
+
+ \row
+ \li \c QSG_RHI
+ \li \c 1
+ \li Enables rendering via the RHI. The targeted graphics API is chosen based on
+ the platform, unless overridden by \c QSG_RHI_BACKEND. The defaults are currently
+ Direct3D 11 for Windows, Metal for macOS, OpenGL elsehwere.
+
+ \row
+ \li \c QSG_RHI_BACKEND
+ \li \c vulkan, \c metal, \c opengl, \c d3d11
+ \li Requests the specific RHI backend.
+
+ \row
+ \li \c QSG_INFO
+ \li \c 1
+ \li Like with the OpenGL-based rendering path, setting this enables printing system
+ information when initializing the Qt Quick scene graph. This can be very useful for
+ troubleshooting.
+
+ \row
+ \li \c QSG_RHI_DEBUG_LAYER
+ \li \c 1
+ \li Where applicable (Vulkan, Direct3D), enables the graphics API implementation's debug
+ and/or validation layers, if available.
+
+ \row
+ \li \c QSG_RHI_PREFER_SOFTWARE_RENDERER
+ \li \c 1
+ \li Requests choosing an adapter or physical device that uses software-based
+ rasterization. Applicable only when the underlying API has support for
+ enumerating adapters (for example, Direct3D or Vulkan), and is ignored
+ otherwise.
+
+ \endtable
+
+ Applications wishing to always run with a single given graphics API, can
+ request this via C++ as well. For example, the following call made early in
+ main(), before constructing any QQuickWindow, forces the use of Vulkan (and
+ will fail otherwise);
+
+ \badcode
+ QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi);
+ \endcode
+
+ See QSGRendererInterface::GraphicsApi. The enum values ending in \c Rhi are
+ equivalent in effect to running with both \c QSG_RHI and \c QSG_RHI_BACKEND
+ set.
+
+ All QRhi backends will choose the system default GPU adapter or physical
+ device, unless overridden by \c{QSG_RHI_PREFER_SOFTWARE_RENDERER} or a
+ backend-specific variable, such as, \c{QT_D3D_ADAPTER_INDEX} or
+ \c{QT_VK_PHYSICAL_DEVICE_INDEX}. No further adapter configurability is
+ provided at this time.
*/
diff --git a/src/quick/doc/src/concepts/visualcanvas/topic.qdoc b/src/quick/doc/src/concepts/visualcanvas/topic.qdoc
index cb6b3564f2..677e5bd739 100644
--- a/src/quick/doc/src/concepts/visualcanvas/topic.qdoc
+++ b/src/quick/doc/src/concepts/visualcanvas/topic.qdoc
@@ -56,12 +56,15 @@ See the documentation about the \l{qtquick-visualcanvas-visualparent.html}
\section1 Scene Graph
Modern computer systems and devices use graphics processing units or GPUs to
-render graphics. Qt Quick can leverage this graphics hardware by using graphics
-APIs like OpenGL. The default graphics adaptation for Qt Quick requires OpenGL and
-it is used to display applications developed with Qt Quick in QML. In particular,
-Qt Quick defines a scene graph which is then rendered. See the documentation about the
-\l{qtquick-visualcanvas-scenegraph.html}{Scene Graph} for in-depth information about
-the concept of a scene graph and why it is beneficial, and about the scene graph
-adaptations provided by Qt Quick.
+render graphics. Qt Quick can leverage this graphics hardware by using graphics
+APIs like \l{https://www.khronos.org/opengl/}{OpenGL},
+\l{https://www.khronos.org/vulkan/}{Vulkan}, or
+\l{https://developer.apple.com/documentation/metal}{Metal}. The default
+graphics adaptation for Qt Quick requires OpenGL and it is used to display
+applications developed with Qt Quick in QML. In particular, Qt Quick defines a
+scene graph which is then rendered. See the documentation about the
+\l{qtquick-visualcanvas-scenegraph.html}{Scene Graph} for in-depth information
+about the concept of a scene graph and why it is beneficial, and about the
+scene graph adaptations provided by Qt Quick.
*/
diff --git a/src/quick/doc/src/examples.qdoc b/src/quick/doc/src/examples.qdoc
index 77475e9812..a913af47c1 100644
--- a/src/quick/doc/src/examples.qdoc
+++ b/src/quick/doc/src/examples.qdoc
@@ -171,9 +171,14 @@ Creator.
\div {class="doc-column"}
\b{Scene Graph}
\list
+ \li \l{Scene Graph - Custom Geometry}{Custom Geometry}
+ \li \l{Scene Graph - Metal Under QML}{Metal Under QML}
+ \li \l{Scene Graph - Metal Texture Import}{Metal Texture Import}
\li \l{Scene Graph - OpenGL Under QML}{OpenGL Under QML}
+ \li \l{Scene Graph - Direct3D 11 Under QML}{Direct3D 11 Under QML}
+ \li \l{Scene Graph - Vulkan Under QML}{Vulkan Under QML}
+ \li \l{Scene Graph - Custom Rendering with QSGRenderNode}{Render Node}
\li \l{Scene Graph - Painted Item}{Painted Item}
- \li \l{Scene Graph - Custom Geometry}{Custom Geometry}
\li \l{Scene Graph - Graph}{Graph}
\li \l{Scene Graph - Simple Material}{Simple Material}
\li \l{Scene Graph - Rendering FBOs}{Rendering FBOs}
diff --git a/src/quick/handlers/handlers.pri b/src/quick/handlers/handlers.pri
index 226cca22cb..49975bd1ca 100644
--- a/src/quick/handlers/handlers.pri
+++ b/src/quick/handlers/handlers.pri
@@ -3,6 +3,7 @@ HEADERS += \
$$PWD/qquickhandlerpoint_p.h \
$$PWD/qquickhoverhandler_p.h \
$$PWD/qquickmultipointhandler_p.h \
+ $$PWD/qquickmultipointhandler_p_p.h \
$$PWD/qquickpinchhandler_p.h \
$$PWD/qquickpointerdevicehandler_p.h \
$$PWD/qquickpointerdevicehandler_p_p.h \
@@ -26,3 +27,9 @@ SOURCES += \
$$PWD/qquicksinglepointhandler.cpp \
$$PWD/qquicktaphandler.cpp \
$$PWD/qquickdragaxis.cpp
+
+qtConfig(wheelevent) {
+ HEADERS += $$PWD/qquickwheelhandler_p.h $$PWD/qquickwheelhandler_p_p.h
+ SOURCES += $$PWD/qquickwheelhandler.cpp
+}
+
diff --git a/src/quick/handlers/qquickdraghandler.cpp b/src/quick/handlers/qquickdraghandler.cpp
index e5531369cf..61b66beff4 100644
--- a/src/quick/handlers/qquickdraghandler.cpp
+++ b/src/quick/handlers/qquickdraghandler.cpp
@@ -103,7 +103,7 @@ bool QQuickDragHandler::targetContainsCentroid()
QPointF QQuickDragHandler::targetCentroidPosition()
{
- QPointF pos = m_centroid.position();
+ QPointF pos = centroid().position();
if (target() != parentItem())
pos = parentItem()->mapToItem(target(), pos);
return pos;
@@ -114,8 +114,14 @@ void QQuickDragHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEvent
QQuickMultiPointHandler::onGrabChanged(grabber, transition, point);
if (grabber == this && transition == QQuickEventPoint::GrabExclusive && target()) {
// In case the grab got handed over from another grabber, we might not get the Press.
- if (!m_pressedInsideTarget) {
- if (target() != parentItem())
+
+ auto isDescendant = [](QQuickItem *parent, QQuickItem *target) {
+ return (target != parent) && !target->isAncestorOf(parent);
+ };
+ if (m_snapMode == SnapAlways
+ || (m_snapMode == SnapIfPressedOutsideTarget && !m_pressedInsideTarget)
+ || (m_snapMode == SnapAuto && !m_pressedInsideTarget && isDescendant(parentItem(), target()))
+ ) {
m_pressTargetPos = QPointF(target()->width(), target()->height()) / 2;
} else if (m_pressTargetPos.isNull()) {
m_pressTargetPos = targetCentroidPosition();
@@ -123,6 +129,33 @@ void QQuickDragHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEvent
}
}
+/*!
+ \qmlproperty enumeration QtQuick.DragHandler::snapMode
+
+ This property holds the snap mode.
+
+ The snap mode configures snapping of the \l target item's center to the event point.
+
+ Possible values:
+ \value DragHandler.SnapNever Never snap
+ \value DragHandler.SnapAuto The \l target snaps if the event point was pressed outside of the \l target
+ item \e and the \l target is a descendant of \l parentItem (default)
+ \value DragHandler.SnapWhenPressedOutsideTarget The \l target snaps if the event point was pressed outside of the \l target
+ \value DragHandler.SnapAlways Always snap
+*/
+QQuickDragHandler::SnapMode QQuickDragHandler::snapMode() const
+{
+ return m_snapMode;
+}
+
+void QQuickDragHandler::setSnapMode(QQuickDragHandler::SnapMode mode)
+{
+ if (mode == m_snapMode)
+ return;
+ m_snapMode = mode;
+ emit snapModeChanged();
+}
+
void QQuickDragHandler::onActiveChanged()
{
QQuickMultiPointHandler::onActiveChanged();
@@ -153,7 +186,7 @@ void QQuickDragHandler::handlePointerEventImpl(QQuickPointerEvent *event)
if (active()) {
// Calculate drag delta, taking into account the axis enabled constraint
// i.e. if xAxis is not enabled, then ignore the horizontal component of the actual movement
- QVector2D accumulatedDragDelta = QVector2D(m_centroid.scenePosition() - m_centroid.scenePressPosition());
+ QVector2D accumulatedDragDelta = QVector2D(centroid().scenePosition() - centroid().scenePressPosition());
if (!m_xAxis.enabled())
accumulatedDragDelta.setX(0);
if (!m_yAxis.enabled())
@@ -169,9 +202,9 @@ void QQuickDragHandler::handlePointerEventImpl(QQuickPointerEvent *event)
QVector <QQuickEventPoint *> chosenPoints;
if (event->isPressEvent())
- m_pressedInsideTarget = target() && m_currentPoints.count() > 0;
+ m_pressedInsideTarget = target() && currentPoints().count() > 0;
- for (const QQuickHandlerPoint &p : m_currentPoints) {
+ for (const QQuickHandlerPoint &p : currentPoints()) {
if (!allOverThreshold)
break;
QQuickEventPoint *point = event->pointById(p.id());
diff --git a/src/quick/handlers/qquickdraghandler_p.h b/src/quick/handlers/qquickdraghandler_p.h
index 748026488a..e8f47163ed 100644
--- a/src/quick/handlers/qquickdraghandler_p.h
+++ b/src/quick/handlers/qquickdraghandler_p.h
@@ -62,8 +62,17 @@ class Q_QUICK_PRIVATE_EXPORT QQuickDragHandler : public QQuickMultiPointHandler
Q_PROPERTY(QQuickDragAxis * xAxis READ xAxis CONSTANT)
Q_PROPERTY(QQuickDragAxis * yAxis READ yAxis CONSTANT)
Q_PROPERTY(QVector2D translation READ translation NOTIFY translationChanged)
+ Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged REVISION 14)
public:
+ enum SnapMode {
+ NoSnap = 0,
+ SnapAuto,
+ SnapIfPressedOutsideTarget,
+ SnapAlways
+ };
+ Q_ENUM(SnapMode)
+
explicit QQuickDragHandler(QQuickItem *parent = nullptr);
void handlePointerEventImpl(QQuickPointerEvent *event) override;
@@ -73,11 +82,14 @@ public:
QVector2D translation() const { return m_translation; }
void setTranslation(const QVector2D &trans);
+ QQuickDragHandler::SnapMode snapMode() const;
+ void setSnapMode(QQuickDragHandler::SnapMode mode);
void enforceConstraints();
Q_SIGNALS:
void translationChanged();
+ Q_REVISION(14) void snapModeChanged();
protected:
void onActiveChanged() override;
@@ -97,6 +109,7 @@ private:
QQuickDragAxis m_xAxis;
QQuickDragAxis m_yAxis;
+ QQuickDragHandler::SnapMode m_snapMode = SnapAuto;
bool m_pressedInsideTarget = false;
friend class QQuickDragAxis;
diff --git a/src/quick/handlers/qquickhoverhandler.cpp b/src/quick/handlers/qquickhoverhandler.cpp
index a6325e084b..79cb288af8 100644
--- a/src/quick/handlers/qquickhoverhandler.cpp
+++ b/src/quick/handlers/qquickhoverhandler.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2018 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -72,9 +72,6 @@ QQuickHoverHandler::QQuickHoverHandler(QQuickItem *parent)
{
// Tell QQuickPointerDeviceHandler::wantsPointerEvent() to ignore button state
d_func()->acceptedButtons = Qt::NoButton;
- // Rule out the touchscreen for now (can be overridden in QML in case a hover-detecting touchscreen exists)
- setAcceptedDevices(static_cast<QQuickPointerDevice::DeviceType>(
- static_cast<int>(QQuickPointerDevice::AllDevices) ^ static_cast<int>(QQuickPointerDevice::TouchScreen)));
}
QQuickHoverHandler::~QQuickHoverHandler()
@@ -103,7 +100,11 @@ bool QQuickHoverHandler::wantsPointerEvent(QQuickPointerEvent *event)
void QQuickHoverHandler::handleEventPoint(QQuickEventPoint *point)
{
- setHovered(true);
+ bool hovered = true;
+ if (point->state() == QQuickEventPoint::Released &&
+ point->pointerEvent()->device()->pointerType() == QQuickPointerDevice::Finger)
+ hovered = false;
+ setHovered(hovered);
setPassiveGrab(point);
}
diff --git a/src/quick/handlers/qquickmultipointhandler.cpp b/src/quick/handlers/qquickmultipointhandler.cpp
index 6fbab29077..f404788de4 100644
--- a/src/quick/handlers/qquickmultipointhandler.cpp
+++ b/src/quick/handlers/qquickmultipointhandler.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "qquickmultipointhandler_p.h"
+#include "qquickmultipointhandler_p_p.h"
#include <private/qquickitem_p.h>
#include <QLineF>
#include <QMouseEvent>
@@ -59,14 +60,13 @@ QT_BEGIN_NAMESPACE
of multiple touchpoints.
*/
QQuickMultiPointHandler::QQuickMultiPointHandler(QQuickItem *parent, int minimumPointCount, int maximumPointCount)
- : QQuickPointerDeviceHandler(parent)
- , m_minimumPointCount(minimumPointCount)
- , m_maximumPointCount(maximumPointCount)
+ : QQuickPointerDeviceHandler(*(new QQuickMultiPointHandlerPrivate(minimumPointCount, maximumPointCount)), parent)
{
}
bool QQuickMultiPointHandler::wantsPointerEvent(QQuickPointerEvent *event)
{
+ Q_D(QQuickMultiPointHandler);
if (!QQuickPointerDeviceHandler::wantsPointerEvent(event))
return false;
@@ -84,14 +84,14 @@ bool QQuickMultiPointHandler::wantsPointerEvent(QQuickPointerEvent *event)
// handle a specific number of points, so a differing number of points will
// usually result in different behavior. But otherwise if the currentPoints
// are all still there in the event, we're good to go (do not reset
- // m_currentPoints, because we don't want to lose the pressPosition, and do
+ // currentPoints, because we don't want to lose the pressPosition, and do
// not want to reshuffle the order either).
const QVector<QQuickEventPoint *> candidatePoints = eligiblePoints(event);
- if (candidatePoints.count() != m_currentPoints.count()) {
- m_currentPoints.clear();
+ if (candidatePoints.count() != d->currentPoints.count()) {
+ d->currentPoints.clear();
if (active()) {
setActive(false);
- m_centroid.reset();
+ d->centroid.reset();
emit centroidChanged();
}
} else if (hasCurrentPoints(event)) {
@@ -101,57 +101,60 @@ bool QQuickMultiPointHandler::wantsPointerEvent(QQuickPointerEvent *event)
ret = ret || (candidatePoints.size() >= minimumPointCount() && candidatePoints.size() <= maximumPointCount());
if (ret) {
const int c = candidatePoints.count();
- m_currentPoints.resize(c);
+ d->currentPoints.resize(c);
for (int i = 0; i < c; ++i) {
- m_currentPoints[i].reset(candidatePoints[i]);
- m_currentPoints[i].localize(parentItem());
+ d->currentPoints[i].reset(candidatePoints[i]);
+ d->currentPoints[i].localize(parentItem());
}
} else {
- m_currentPoints.clear();
+ d->currentPoints.clear();
}
return ret;
}
void QQuickMultiPointHandler::handlePointerEventImpl(QQuickPointerEvent *event)
{
+ Q_D(QQuickMultiPointHandler);
QQuickPointerHandler::handlePointerEventImpl(event);
- // event's points can be reordered since the previous event, which is why m_currentPoints
+ // event's points can be reordered since the previous event, which is why currentPoints
// is _not_ a shallow copy of the QQuickPointerTouchEvent::m_touchPoints vector.
- // So we have to update our m_currentPoints instances based on the given event.
- for (QQuickHandlerPoint &p : m_currentPoints) {
+ // So we have to update our currentPoints instances based on the given event.
+ for (QQuickHandlerPoint &p : d->currentPoints) {
const QQuickEventPoint *ep = event->pointById(p.id());
if (ep)
p.reset(ep);
}
- QPointF sceneGrabPos = m_centroid.sceneGrabPosition();
- m_centroid.reset(m_currentPoints);
- m_centroid.m_sceneGrabPosition = sceneGrabPos; // preserve as it was
+ QPointF sceneGrabPos = d->centroid.sceneGrabPosition();
+ d->centroid.reset(d->currentPoints);
+ d->centroid.m_sceneGrabPosition = sceneGrabPos; // preserve as it was
emit centroidChanged();
}
void QQuickMultiPointHandler::onActiveChanged()
{
+ Q_D(QQuickMultiPointHandler);
if (active()) {
- m_centroid.m_sceneGrabPosition = m_centroid.m_scenePosition;
+ d->centroid.m_sceneGrabPosition = d->centroid.m_scenePosition;
} else {
- // Don't call m_centroid.reset() here, because in a QML onActiveChanged
+ // Don't call centroid.reset() here, because in a QML onActiveChanged
// callback, we'd like to see what the position _was_, what the velocity _was_, etc.
// (having them undefined is not useful)
// But pressedButtons and pressedModifiers are meant to be more real-time than those
// (which seems a bit inconsistent, from one side).
- m_centroid.m_pressedButtons = Qt::NoButton;
- m_centroid.m_pressedModifiers = Qt::NoModifier;
+ d->centroid.m_pressedButtons = Qt::NoButton;
+ d->centroid.m_pressedModifiers = Qt::NoModifier;
}
}
void QQuickMultiPointHandler::onGrabChanged(QQuickPointerHandler *, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *)
{
+ Q_D(QQuickMultiPointHandler);
// If another handler or item takes over this set of points, assume it has
// decided that it's the better fit for them. Don't immediately re-grab
// at the next opportunity. This should help to avoid grab cycles
// (e.g. between DragHandler and PinchHandler).
if (transition == QQuickEventPoint::UngrabExclusive || transition == QQuickEventPoint::CancelGrabExclusive)
- m_currentPoints.clear();
+ d->currentPoints.clear();
}
QVector<QQuickEventPoint *> QQuickMultiPointHandler::eligiblePoints(QQuickPointerEvent *event)
@@ -191,14 +194,21 @@ QVector<QQuickEventPoint *> QQuickMultiPointHandler::eligiblePoints(QQuickPointe
The default value is 2.
*/
+int QQuickMultiPointHandler::minimumPointCount() const
+{
+ Q_D(const QQuickMultiPointHandler);
+ return d->minimumPointCount;
+}
+
void QQuickMultiPointHandler::setMinimumPointCount(int c)
{
- if (m_minimumPointCount == c)
+ Q_D(QQuickMultiPointHandler);
+ if (d->minimumPointCount == c)
return;
- m_minimumPointCount = c;
+ d->minimumPointCount = c;
emit minimumPointCountChanged();
- if (m_maximumPointCount < 0)
+ if (d->maximumPointCount < 0)
emit maximumPointCountChanged();
}
@@ -217,22 +227,61 @@ void QQuickMultiPointHandler::setMinimumPointCount(int c)
The default value is the same as \l minimumPointCount.
*/
+int QQuickMultiPointHandler::maximumPointCount() const
+{
+ Q_D(const QQuickMultiPointHandler);
+ return d->maximumPointCount >= 0 ? d->maximumPointCount : d->minimumPointCount;
+}
+
void QQuickMultiPointHandler::setMaximumPointCount(int maximumPointCount)
{
- if (m_maximumPointCount == maximumPointCount)
+ Q_D(QQuickMultiPointHandler);
+ if (d->maximumPointCount == maximumPointCount)
return;
- m_maximumPointCount = maximumPointCount;
+ d->maximumPointCount = maximumPointCount;
emit maximumPointCountChanged();
}
+/*!
+ \readonly
+ \qmlproperty QtQuick::HandlerPoint QtQuick::MultiPointHandler::centroid
+
+ A point exactly in the middle of the currently-pressed touch points.
+ If only one point is pressed, it's the same as that point.
+ A handler that has a \l target will normally transform it relative to this point.
+*/
+const QQuickHandlerPoint &QQuickMultiPointHandler::centroid() const
+{
+ Q_D(const QQuickMultiPointHandler);
+ return d->centroid;
+}
+
+/*!
+ Returns a modifiable reference to the point that will be returned by the
+ \l centroid property. If you modify it, you are responsible to emit
+ \l centroidChanged.
+*/
+QQuickHandlerPoint &QQuickMultiPointHandler::mutableCentroid()
+{
+ Q_D(QQuickMultiPointHandler);
+ return d->centroid;
+}
+
+QVector<QQuickHandlerPoint> &QQuickMultiPointHandler::currentPoints()
+{
+ Q_D(QQuickMultiPointHandler);
+ return d->currentPoints;
+}
+
bool QQuickMultiPointHandler::hasCurrentPoints(QQuickPointerEvent *event)
{
- if (event->pointCount() < m_currentPoints.size() || m_currentPoints.size() == 0)
+ Q_D(const QQuickMultiPointHandler);
+ if (event->pointCount() < d->currentPoints.size() || d->currentPoints.size() == 0)
return false;
// TODO optimize: either ensure the points are sorted,
// or use std::equal with a predicate
- for (const QQuickHandlerPoint &p : qAsConst(m_currentPoints)) {
+ for (const QQuickHandlerPoint &p : qAsConst(d->currentPoints)) {
const QQuickEventPoint *ep = event->pointById(p.id());
if (!ep)
return false;
@@ -244,30 +293,33 @@ bool QQuickMultiPointHandler::hasCurrentPoints(QQuickPointerEvent *event)
qreal QQuickMultiPointHandler::averageTouchPointDistance(const QPointF &ref)
{
+ Q_D(const QQuickMultiPointHandler);
qreal ret = 0;
- if (Q_UNLIKELY(m_currentPoints.size() == 0))
+ if (Q_UNLIKELY(d->currentPoints.size() == 0))
return ret;
- for (const QQuickHandlerPoint &p : m_currentPoints)
+ for (const QQuickHandlerPoint &p : d->currentPoints)
ret += QVector2D(p.scenePosition() - ref).length();
- return ret / m_currentPoints.size();
+ return ret / d->currentPoints.size();
}
qreal QQuickMultiPointHandler::averageStartingDistance(const QPointF &ref)
{
+ Q_D(const QQuickMultiPointHandler);
// TODO cache it in setActive()?
qreal ret = 0;
- if (Q_UNLIKELY(m_currentPoints.size() == 0))
+ if (Q_UNLIKELY(d->currentPoints.size() == 0))
return ret;
- for (const QQuickHandlerPoint &p : m_currentPoints)
+ for (const QQuickHandlerPoint &p : d->currentPoints)
ret += QVector2D(p.sceneGrabPosition() - ref).length();
- return ret / m_currentPoints.size();
+ return ret / d->currentPoints.size();
}
QVector<QQuickMultiPointHandler::PointData> QQuickMultiPointHandler::angles(const QPointF &ref) const
{
+ Q_D(const QQuickMultiPointHandler);
QVector<PointData> angles;
- angles.reserve(m_currentPoints.count());
- for (const QQuickHandlerPoint &p : m_currentPoints) {
+ angles.reserve(d->currentPoints.count());
+ for (const QQuickHandlerPoint &p : d->currentPoints) {
qreal angle = QLineF(ref, p.scenePosition()).angle();
angles.append(PointData(p.id(), -angle)); // convert to clockwise, to be consistent with QQuickItem::rotation
}
@@ -312,7 +364,7 @@ void QQuickMultiPointHandler::acceptPoints(const QVector<QQuickEventPoint *> &po
point->setAccepted();
}
-bool QQuickMultiPointHandler::grabPoints(QVector<QQuickEventPoint *> points)
+bool QQuickMultiPointHandler::grabPoints(const QVector<QQuickEventPoint *> &points)
{
if (points.isEmpty())
return false;
@@ -332,17 +384,41 @@ bool QQuickMultiPointHandler::grabPoints(QVector<QQuickEventPoint *> points)
void QQuickMultiPointHandler::moveTarget(QPointF pos)
{
- target()->setPosition(pos);
- m_centroid.m_position = target()->mapFromScene(m_centroid.m_scenePosition);
+ Q_D(QQuickMultiPointHandler);
+ if (QQuickItem *t = target()) {
+ d->xMetaProperty().write(t, pos.x());
+ d->yMetaProperty().write(t, pos.y());
+ d->centroid.m_position = t->mapFromScene(d->centroid.m_scenePosition);
+ } else {
+ qWarning() << "moveTarget: target is null";
+ }
}
-/*!
- \readonly
- \qmlproperty QtQuick::HandlerPoint QtQuick::MultiPointHandler::centroid
+QQuickMultiPointHandlerPrivate::QQuickMultiPointHandlerPrivate(int minPointCount, int maxPointCount)
+ : QQuickPointerDeviceHandlerPrivate()
+ , minimumPointCount(minPointCount)
+ , maximumPointCount(maxPointCount)
+{
+}
- A point exactly in the middle of the currently-pressed touch points.
- If only one point is pressed, it's the same as that point.
- A handler that has a \l target will normally transform it relative to this point.
-*/
+QMetaProperty &QQuickMultiPointHandlerPrivate::xMetaProperty() const
+{
+ Q_Q(const QQuickMultiPointHandler);
+ if (!xProperty.isValid() && q->target()) {
+ const QMetaObject *targetMeta = q->target()->metaObject();
+ xProperty = targetMeta->property(targetMeta->indexOfProperty("x"));
+ }
+ return xProperty;
+}
+
+QMetaProperty &QQuickMultiPointHandlerPrivate::yMetaProperty() const
+{
+ Q_Q(const QQuickMultiPointHandler);
+ if (!yProperty.isValid() && q->target()) {
+ const QMetaObject *targetMeta = q->target()->metaObject();
+ yProperty = targetMeta->property(targetMeta->indexOfProperty("y"));
+ }
+ return yProperty;
+}
QT_END_NAMESPACE
diff --git a/src/quick/handlers/qquickmultipointhandler_p.h b/src/quick/handlers/qquickmultipointhandler_p.h
index 06f170154b..480f69035b 100644
--- a/src/quick/handlers/qquickmultipointhandler_p.h
+++ b/src/quick/handlers/qquickmultipointhandler_p.h
@@ -58,6 +58,8 @@
QT_BEGIN_NAMESPACE
+class QQuickMultiPointHandlerPrivate;
+
class Q_QUICK_PRIVATE_EXPORT QQuickMultiPointHandler : public QQuickPointerDeviceHandler
{
Q_OBJECT
@@ -68,13 +70,13 @@ class Q_QUICK_PRIVATE_EXPORT QQuickMultiPointHandler : public QQuickPointerDevic
public:
explicit QQuickMultiPointHandler(QQuickItem *parent = nullptr, int minimumPointCount = 2, int maximumPointCount = -1);
- int minimumPointCount() const { return m_minimumPointCount; }
+ int minimumPointCount() const;
void setMinimumPointCount(int c);
- int maximumPointCount() const { return m_maximumPointCount >= 0 ? m_maximumPointCount : m_minimumPointCount; }
+ int maximumPointCount() const;
void setMaximumPointCount(int maximumPointCount);
- QQuickHandlerPoint centroid() const { return m_centroid; }
+ const QQuickHandlerPoint &centroid() const;
signals:
void minimumPointCountChanged();
@@ -94,6 +96,8 @@ protected:
void handlePointerEventImpl(QQuickPointerEvent *event) override;
void onActiveChanged() override;
void onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) override;
+ QVector<QQuickHandlerPoint> &currentPoints();
+ QQuickHandlerPoint &mutableCentroid();
bool hasCurrentPoints(QQuickPointerEvent *event);
QVector<QQuickEventPoint *> eligiblePoints(QQuickPointerEvent *event);
qreal averageTouchPointDistance(const QPointF &ref);
@@ -103,14 +107,10 @@ protected:
QVector<PointData> angles(const QPointF &ref) const;
static qreal averageAngleDelta(const QVector<PointData> &old, const QVector<PointData> &newAngles);
void acceptPoints(const QVector<QQuickEventPoint *> &points);
- bool grabPoints(QVector<QQuickEventPoint *> points);
+ bool grabPoints(const QVector<QQuickEventPoint *> &points);
void moveTarget(QPointF pos);
-protected:
- QVector<QQuickHandlerPoint> m_currentPoints;
- QQuickHandlerPoint m_centroid;
- int m_minimumPointCount;
- int m_maximumPointCount;
+ Q_DECLARE_PRIVATE(QQuickMultiPointHandler)
};
QT_END_NAMESPACE
diff --git a/src/quick/handlers/qquickmultipointhandler_p_p.h b/src/quick/handlers/qquickmultipointhandler_p_p.h
new file mode 100644
index 0000000000..406e4a1fdf
--- /dev/null
+++ b/src/quick/handlers/qquickmultipointhandler_p_p.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKPOINTERMULTIHANDLER_P_H
+#define QQUICKPOINTERMULTIHANDLER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qquickhandlerpoint_p.h"
+#include "qquickpointerdevicehandler_p_p.h"
+#include "qquickmultipointhandler_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class Q_QUICK_PRIVATE_EXPORT QQuickMultiPointHandlerPrivate : public QQuickPointerDeviceHandlerPrivate
+{
+ Q_DECLARE_PUBLIC(QQuickMultiPointHandler)
+
+public:
+ static QQuickMultiPointHandlerPrivate* get(QQuickMultiPointHandler *q) { return q->d_func(); }
+ static const QQuickMultiPointHandlerPrivate* get(const QQuickMultiPointHandler *q) { return q->d_func(); }
+
+ QQuickMultiPointHandlerPrivate(int minPointCount, int maxPointCount);
+
+ QMetaProperty &xMetaProperty() const;
+ QMetaProperty &yMetaProperty() const;
+
+ QVector<QQuickHandlerPoint> currentPoints;
+ QQuickHandlerPoint centroid;
+ int minimumPointCount;
+ int maximumPointCount;
+ mutable QMetaProperty xProperty;
+ mutable QMetaProperty yProperty;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKPOINTERMULTIHANDLER_P_H
diff --git a/src/quick/handlers/qquickpinchhandler.cpp b/src/quick/handlers/qquickpinchhandler.cpp
index dc1a9a92f9..a5a867015c 100644
--- a/src/quick/handlers/qquickpinchhandler.cpp
+++ b/src/quick/handlers/qquickpinchhandler.cpp
@@ -267,20 +267,14 @@ void QQuickPinchHandler::onActiveChanged()
{
QQuickMultiPointHandler::onActiveChanged();
if (active()) {
- m_startMatrix = QMatrix4x4();
- m_startAngles = angles(m_centroid.sceneGrabPosition());
- m_startDistance = averageTouchPointDistance(m_centroid.sceneGrabPosition());
+ m_startAngles = angles(centroid().sceneGrabPosition());
+ m_startDistance = averageTouchPointDistance(centroid().sceneGrabPosition());
m_activeRotation = 0;
m_activeTranslation = QVector2D();
if (const QQuickItem *t = target()) {
m_startScale = t->scale(); // TODO incompatible with independent x/y scaling
m_startRotation = t->rotation();
- QVector3D xformOrigin(t->transformOriginPoint());
- m_startMatrix.translate(float(t->x()), float(t->y()));
- m_startMatrix.translate(xformOrigin);
- m_startMatrix.scale(float(m_startScale));
- m_startMatrix.rotate(float(m_startRotation), 0, 0, -1);
- m_startMatrix.translate(-xformOrigin);
+ m_startPos = t->position();
} else {
m_startScale = m_accumulatedScale;
m_startRotation = 0;
@@ -294,7 +288,7 @@ void QQuickPinchHandler::onActiveChanged()
void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event)
{
if (Q_UNLIKELY(lcPinchHandler().isDebugEnabled())) {
- for (const QQuickHandlerPoint &p : m_currentPoints)
+ for (const QQuickHandlerPoint &p : currentPoints())
qCDebug(lcPinchHandler) << hex << p.id() << p.sceneGrabPosition() << "->" << p.scenePosition();
}
QQuickMultiPointHandler::handlePointerEventImpl(event);
@@ -302,13 +296,13 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event)
qreal dist = 0;
#if QT_CONFIG(gestures)
if (const auto gesture = event->asPointerNativeGestureEvent()) {
- m_centroid.reset(event->point(0));
+ mutableCentroid().reset(event->point(0));
switch (gesture->type()) {
case Qt::EndNativeGesture:
m_activeScale = 1;
m_activeRotation = 0;
m_activeTranslation = QVector2D();
- m_centroid.reset();
+ mutableCentroid().reset();
setActive(false);
emit updated();
return;
@@ -333,7 +327,7 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event)
{
const bool containsReleasedPoints = event->isReleaseEvent();
QVector<QQuickEventPoint *> chosenPoints;
- for (const QQuickHandlerPoint &p : m_currentPoints) {
+ for (const QQuickHandlerPoint &p : currentPoints()) {
QQuickEventPoint *ep = event->pointById(p.id());
chosenPoints << ep;
}
@@ -341,8 +335,8 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event)
// Verify that at least one of the points has moved beyond threshold needed to activate the handler
int numberOfPointsDraggedOverThreshold = 0;
QVector2D accumulatedDrag;
- const QVector2D currentCentroid(m_centroid.scenePosition());
- const QVector2D pressCentroid(m_centroid.scenePressPosition());
+ const QVector2D currentCentroid(centroid().scenePosition());
+ const QVector2D pressCentroid(centroid().scenePressPosition());
QStyleHints *styleHints = QGuiApplication::styleHints();
const int dragThreshold = styleHints->startDragDistance();
@@ -410,9 +404,9 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event)
}
const bool requiredNumberOfPointsDraggedOverThreshold = numberOfPointsDraggedOverThreshold >= minimumPointCount() && numberOfPointsDraggedOverThreshold <= maximumPointCount();
- accumulatedMovementMagnitude /= m_currentPoints.count();
+ accumulatedMovementMagnitude /= currentPoints().count();
- QVector2D avgDrag = accumulatedDrag / m_currentPoints.count();
+ QVector2D avgDrag = accumulatedDrag / currentPoints().count();
if (!xAxis()->enabled())
avgDrag.setX(0);
if (!yAxis()->enabled())
@@ -445,12 +439,12 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event)
// avoid mapping the minima and maxima, as they might have unmappable values
// such as -inf/+inf. Because of this we perform the bounding to min/max in local coords.
// 1. scale
- dist = averageTouchPointDistance(m_centroid.scenePosition());
+ dist = averageTouchPointDistance(centroid().scenePosition());
m_activeScale = dist / m_startDistance;
m_activeScale = qBound(m_minimumScale/m_startScale, m_activeScale, m_maximumScale/m_startScale);
// 2. rotate
- QVector<PointData> newAngles = angles(m_centroid.scenePosition());
+ QVector<PointData> newAngles = angles(centroid().scenePosition());
const qreal angleDelta = averageAngleDelta(m_startAngles, newAngles);
m_activeRotation += angleDelta;
m_startAngles = std::move(newAngles);
@@ -465,25 +459,15 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event)
m_accumulatedScale = m_startScale * m_activeScale;
if (target() && target()->parentItem()) {
- const QPointF centroidParentPos = target()->parentItem()->mapFromScene(m_centroid.scenePosition());
+ const QPointF centroidParentPos = target()->parentItem()->mapFromScene(centroid().scenePosition());
// 3. Drag/translate
- const QPointF centroidStartParentPos = target()->parentItem()->mapFromScene(m_centroid.sceneGrabPosition());
+ const QPointF centroidStartParentPos = target()->parentItem()->mapFromScene(centroid().sceneGrabPosition());
m_activeTranslation = QVector2D(centroidParentPos - centroidStartParentPos);
// apply rotation + scaling around the centroid - then apply translation.
- QMatrix4x4 mat;
-
- const QVector3D centroidParentVector(centroidParentPos);
- mat.translate(centroidParentVector);
- mat.rotate(float(m_activeRotation), 0, 0, 1);
- mat.scale(float(m_activeScale));
- mat.translate(-centroidParentVector);
- mat.translate(QVector3D(m_activeTranslation));
-
- mat = mat * m_startMatrix;
-
- QPointF xformOriginPoint = target()->transformOriginPoint();
- QPointF pos = mat * xformOriginPoint;
- pos -= xformOriginPoint;
+ QPointF pos = QQuickItemPrivate::get(target())->adjustedPosForTransform(centroidParentPos,
+ m_startPos, m_activeTranslation,
+ m_startScale, m_activeScale,
+ m_startRotation, m_activeRotation);
if (xAxis()->enabled())
pos.setX(qBound(xAxis()->minimum(), pos.x(), xAxis()->maximum()));
@@ -498,10 +482,10 @@ void QQuickPinchHandler::handlePointerEventImpl(QQuickPointerEvent *event)
target()->setRotation(rotation);
target()->setScale(m_accumulatedScale);
} else {
- m_activeTranslation = QVector2D(m_centroid.scenePosition() - m_centroid.scenePressPosition());
+ m_activeTranslation = QVector2D(centroid().scenePosition() - centroid().scenePressPosition());
}
- qCDebug(lcPinchHandler) << "centroid" << m_centroid.scenePressPosition() << "->" << m_centroid.scenePosition()
+ qCDebug(lcPinchHandler) << "centroid" << centroid().scenePressPosition() << "->" << centroid().scenePosition()
<< ", distance" << m_startDistance << "->" << dist
<< ", startScale" << m_startScale << "->" << m_accumulatedScale
<< ", activeRotation" << m_activeRotation
diff --git a/src/quick/handlers/qquickpinchhandler_p.h b/src/quick/handlers/qquickpinchhandler_p.h
index 766d57f892..cea794f0c8 100644
--- a/src/quick/handlers/qquickpinchhandler_p.h
+++ b/src/quick/handlers/qquickpinchhandler_p.h
@@ -158,7 +158,6 @@ private:
qreal m_accumulatedStartCentroidDistance = 0;
QVector<PointData> m_startAngles;
QQuickMatrix4x4 m_transform;
- QMatrix4x4 m_startMatrix;
};
QT_END_NAMESPACE
diff --git a/src/quick/handlers/qquickpointerdevicehandler.cpp b/src/quick/handlers/qquickpointerdevicehandler.cpp
index 2964042f39..90f31bf9fd 100644
--- a/src/quick/handlers/qquickpointerdevicehandler.cpp
+++ b/src/quick/handlers/qquickpointerdevicehandler.cpp
@@ -307,7 +307,8 @@ bool QQuickPointerDeviceHandler::wantsPointerEvent(QQuickPointerEvent *event)
return false;
// HoverHandler sets acceptedButtons to Qt::NoButton to indicate that button state is irrelevant.
if (event->device()->pointerType() != QQuickPointerDevice::Finger && acceptedButtons() != Qt::NoButton &&
- (event->buttons() & acceptedButtons()) == 0 && (event->button() & acceptedButtons()) == 0)
+ (event->buttons() & acceptedButtons()) == 0 && (event->button() & acceptedButtons()) == 0
+ && !event->asPointerScrollEvent())
return false;
return true;
}
diff --git a/src/quick/handlers/qquicktaphandler.cpp b/src/quick/handlers/qquicktaphandler.cpp
index 3b42c5e536..7b26adbe6f 100644
--- a/src/quick/handlers/qquicktaphandler.cpp
+++ b/src/quick/handlers/qquicktaphandler.cpp
@@ -78,8 +78,8 @@ int QQuickTapHandler::m_touchMultiTapDistanceSquared(-1);
\l gesturePolicy to \c TapHandler.ReleaseWithinBounds.
For multi-tap gestures (double-tap, triple-tap etc.), the distance moved
- must not exceed QPlatformTheme::MouseDoubleClickDistance with mouse and
- QPlatformTheme::TouchDoubleTapDistance with touch, and the time between
+ must not exceed QStyleHints::mouseDoubleClickDistance() with mouse and
+ QStyleHints::touchDoubleTapDistance() with touch, and the time between
taps must not exceed QStyleHints::mouseDoubleClickInterval().
\sa MouseArea
@@ -90,11 +90,9 @@ QQuickTapHandler::QQuickTapHandler(QQuickItem *parent)
{
if (m_mouseMultiClickDistanceSquared < 0) {
m_multiTapInterval = qApp->styleHints()->mouseDoubleClickInterval() / 1000.0;
- m_mouseMultiClickDistanceSquared = QGuiApplicationPrivate::platformTheme()->
- themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt();
+ m_mouseMultiClickDistanceSquared = qApp->styleHints()->mouseDoubleClickDistance();
m_mouseMultiClickDistanceSquared *= m_mouseMultiClickDistanceSquared;
- m_touchMultiTapDistanceSquared = QGuiApplicationPrivate::platformTheme()->
- themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
+ m_touchMultiTapDistanceSquared = qApp->styleHints()->touchDoubleTapDistance();
m_touchMultiTapDistanceSquared *= m_touchMultiTapDistanceSquared;
}
}
@@ -410,9 +408,9 @@ void QQuickTapHandler::updateTimeHeld()
\since 5.11
This signal is emitted when the \c parent Item is tapped twice within a
- short span of time (QStyleHints::mouseDoubleClickInterval) and distance
- (QPlatformTheme::MouseDoubleClickDistance or
- QPlatformTheme::TouchDoubleTapDistance). This signal always occurs after
+ short span of time (QStyleHints::mouseDoubleClickInterval()) and distance
+ (QStyleHints::mouseDoubleClickDistance() or
+ QStyleHints::touchDoubleTapDistance()). This signal always occurs after
\l singleTapped, \l tapped, and \l tapCountChanged. The \a eventPoint
signal parameter contains information from the release event about the
point that was tapped.
diff --git a/src/quick/handlers/qquickwheelhandler.cpp b/src/quick/handlers/qquickwheelhandler.cpp
new file mode 100644
index 0000000000..90e4fef97e
--- /dev/null
+++ b/src/quick/handlers/qquickwheelhandler.cpp
@@ -0,0 +1,520 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickwheelhandler_p.h"
+#include "qquickwheelhandler_p_p.h"
+#include <QLoggingCategory>
+#include <QtMath>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(lcWheelHandler, "qt.quick.handler.wheel")
+
+/*!
+ \qmltype WheelHandler
+ \instantiates QQuickWheelHandler
+ \inqmlmodule QtQuick
+ \ingroup qtquick-input-handlers
+ \brief Handler for the mouse wheel.
+
+ WheelHandler is a handler that is used to interactively manipulate some
+ numeric property of an Item as the user rotates the mouse wheel. Like other
+ Input Handlers, by default it manipulates its \l {PointerHandler::target}
+ {target}. Declare \l property to control which target property will be
+ manipulated:
+
+ \snippet pointerHandlers/wheelHandler.qml 0
+
+ \l BoundaryRule is quite useful in combination with WheelHandler (as well
+ as with other Input Handlers) to declare the allowed range of values that
+ the target property can have. For example it is possible to implement
+ scrolling using a combination of WheelHandler and \l DragHandler to
+ manipulate the scrollable Item's \l{QQuickItem::y}{y} property when the
+ user rotates the wheel or drags the item on a touchscreen, and
+ \l BoundaryRule to limit the range of motion from the top to the bottom:
+
+ \snippet pointerHandlers/handlerFlick.qml 0
+
+ Alternatively if \l targetProperty is not set or \l target is null,
+ WheelHandler will not automatically manipulate anything; but the
+ \l rotation property can be used in a binding to manipulate another
+ property, or you can implement \c onWheel and handle the wheel event
+ directly.
+
+ WheelHandler handles only a rotating mouse wheel by default.
+ Optionally it can handle smooth-scrolling events from touchpad gestures,
+ by setting \l acceptedDevices to \c{PointerDevice.Mouse | PointerDevice.TouchPad}.
+
+ \note Some non-mouse hardware (such as a touch-sensitive Wacom tablet, or
+ a Linux laptop touchpad) generates real wheel events from gestures.
+ WheelHandler will respond to those events as wheel events regardless of the
+ setting of the \l acceptedDevices property.
+
+ \sa MouseArea
+ \sa Flickable
+*/
+
+QQuickWheelHandler::QQuickWheelHandler(QQuickItem *parent)
+ : QQuickSinglePointHandler(*(new QQuickWheelHandlerPrivate), parent)
+{
+ setAcceptedDevices(QQuickPointerDevice::Mouse);
+}
+
+/*!
+ \qmlproperty enum QtQuick::WheelHandler::orientation
+
+ Which wheel to react to. The default is \c Qt.Vertical.
+
+ Not every mouse has a \c Horizontal wheel; sometimes it is emulated by
+ tilting the wheel sideways. A touchpad can usually generate both vertical
+ and horizontal wheel events.
+*/
+Qt::Orientation QQuickWheelHandler::orientation() const
+{
+ Q_D(const QQuickWheelHandler);
+ return d->orientation;
+}
+
+void QQuickWheelHandler::setOrientation(Qt::Orientation orientation)
+{
+ Q_D(QQuickWheelHandler);
+ if (d->orientation == orientation)
+ return;
+
+ d->orientation = orientation;
+ emit orientationChanged();
+}
+
+/*!
+ \qmlproperty bool QtQuick::WheelHandler::invertible
+
+ Whether or not to reverse the direction of property change if
+ \l QQuickPointerScrollEvent::inverted is true. The default is \c true.
+
+ If the operating system has a "natural scrolling" setting that causes
+ scrolling to be in the same direction as the finger movement, then if this
+ property is set to \c true, and WheelHandler is directly setting a property
+ on \l target, the direction of movement will correspond to the system setting.
+ If this property is set to \l false, it will invert the \l rotation so that
+ the direction of motion is always the same as the direction of finger movement.
+*/
+bool QQuickWheelHandler::isInvertible() const
+{
+ Q_D(const QQuickWheelHandler);
+ return d->invertible;
+}
+
+void QQuickWheelHandler::setInvertible(bool invertible)
+{
+ Q_D(QQuickWheelHandler);
+ if (d->invertible == invertible)
+ return;
+
+ d->invertible = invertible;
+ emit invertibleChanged();
+}
+
+/*!
+ \qmlproperty real QtQuick::WheelHandler::activeTimeout
+
+ The amount of time in seconds after which the \l active property will
+ revert to \c false if no more wheel events are received. The default is
+ \c 0.1 (100 ms).
+
+ When WheelHandler handles events that contain
+ \l {Qt::ScrollPhase}{scroll phase} information, such as events from some
+ touchpads, the \l active property will become \c false as soon as an event
+ with phase \l Qt::ScrollEnd is received; in that case the timeout is not
+ necessary. But a conventional mouse with a wheel does not provide the
+ \l {QQuickPointerScrollEvent::phase}{scroll phase}: the mouse cannot detect
+ when the user has decided to stop scrolling, so the \l active property
+ transitions to \c false after this much time has elapsed.
+*/
+qreal QQuickWheelHandler::activeTimeout() const
+{
+ Q_D(const QQuickWheelHandler);
+ return d->activeTimeout;
+}
+
+void QQuickWheelHandler::setActiveTimeout(qreal timeout)
+{
+ Q_D(QQuickWheelHandler);
+ if (qFuzzyCompare(d->activeTimeout, timeout))
+ return;
+
+ if (timeout < 0) {
+ qWarning("activeTimeout must be positive");
+ return;
+ }
+
+ d->activeTimeout = timeout;
+ emit activeTimeoutChanged();
+}
+
+/*!
+ \qmlproperty real QtQuick::WheelHandler::rotation
+
+ The angle through which the mouse wheel has been rotated since the last
+ time this property was set, in wheel degrees.
+
+ A positive value indicates that the wheel was rotated up/right;
+ a negative value indicates that the wheel was rotated down/left.
+
+ A basic mouse click-wheel works in steps of 15 degrees.
+
+ The default is \c 0 at startup. It can be programmatically set to any value
+ at any time. The value will be adjusted from there as the user rotates the
+ mouse wheel.
+
+ \sa orientation
+*/
+qreal QQuickWheelHandler::rotation() const
+{
+ Q_D(const QQuickWheelHandler);
+ return d->rotation * d->rotationScale;
+}
+
+void QQuickWheelHandler::setRotation(qreal rotation)
+{
+ Q_D(QQuickWheelHandler);
+ if (qFuzzyCompare(d->rotation, rotation / d->rotationScale))
+ return;
+
+ d->rotation = rotation / d->rotationScale;
+ emit rotationChanged();
+}
+
+/*!
+ \qmlproperty real QtQuick::WheelHandler::rotationScale
+
+ The scaling to be applied to the \l rotation property, and to the
+ \l property on the \l target item, if any. The default is 1, such that
+ \l rotation will be in units of degrees of rotation. It can be set to a
+ negative number to invert the effect of the direction of mouse wheel
+ rotation.
+*/
+qreal QQuickWheelHandler::rotationScale() const
+{
+ Q_D(const QQuickWheelHandler);
+ return d->rotationScale;
+}
+
+void QQuickWheelHandler::setRotationScale(qreal rotationScale)
+{
+ Q_D(QQuickWheelHandler);
+ if (qFuzzyCompare(d->rotationScale, rotationScale))
+ return;
+ if (qFuzzyIsNull(rotationScale)) {
+ qWarning("rotationScale cannot be set to zero");
+ return;
+ }
+
+ d->rotationScale = rotationScale;
+ emit rotationScaleChanged();
+}
+
+/*!
+ \qmlproperty string QtQuick::WheelHandler::property
+
+ The property to be modified on the \l target when the mouse wheel is rotated.
+
+ The default is no property (empty string). When no target property is being
+ automatically modified, you can use bindings to react to mouse wheel
+ rotation in arbitrary ways.
+
+ You can use the mouse wheel to adjust any numeric property. For example if
+ \c property is set to \c x, the \l target will move horizontally as the
+ wheel is rotated. The following properties have special behavior:
+
+ \value scale
+ \l{QQuickItem::scale}{scale} will be modified in a non-linear fashion
+ as described under \l targetScaleMultiplier. If
+ \l targetTransformAroundCursor is \c true, the \l{QQuickItem::x}{x} and
+ \l{QQuickItem::y}{y} properties will be simultaneously adjusted so that
+ the user will effectively zoom into or out of the point under the mouse
+ cursor.
+ \value rotation
+ \l{QQuickItem::rotation}{rotation} will be set to \l rotation. If
+ \l targetTransformAroundCursor is \c true, the l{QQuickItem::x}{x} and
+ \l{QQuickItem::y}{y} properties will be simultaneously adjusted so
+ that the user will effectively rotate the item around the point under
+ the mouse cursor.
+
+ The adjustment of the given target property is always scaled by \l rotationScale.
+*/
+QString QQuickWheelHandler::property() const
+{
+ Q_D(const QQuickWheelHandler);
+ return d->propertyName;
+}
+
+void QQuickWheelHandler::setProperty(const QString &propertyName)
+{
+ Q_D(QQuickWheelHandler);
+ if (d->propertyName == propertyName)
+ return;
+
+ d->propertyName = propertyName;
+ d->metaPropertyDirty = true;
+ emit propertyChanged();
+}
+
+/*!
+ \qmlproperty real QtQuick::WheelHandler::targetScaleMultiplier
+
+ The amount by which the \l target \l{QQuickItem::scale}{scale} is to be
+ multiplied whenever the \l rotation changes by 15 degrees. This
+ is relevant only when \l property is \c "scale".
+
+ The \c scale will be multiplied by
+ \c targetScaleMultiplier \sup {angleDelta * rotationScale / 15}.
+ The default is \c 2 \sup {1/3}, which means that if \l rotationScale is left
+ at its default value, and the mouse wheel is rotated by one "click"
+ (15 degrees), the \l target will be scaled by approximately 1.25; after
+ three "clicks" its size will be doubled or halved, depending on the
+ direction that the wheel is rotated. If you want to make it double or halve
+ with every 2 clicks of the wheel, set this to \c 2 \sup {1/2} (1.4142).
+ If you want to make it scale the opposite way as the wheel is rotated,
+ set \c rotationScale to a negative value.
+*/
+qreal QQuickWheelHandler::targetScaleMultiplier() const
+{
+ Q_D(const QQuickWheelHandler);
+ return d->targetScaleMultiplier;
+}
+
+void QQuickWheelHandler::setTargetScaleMultiplier(qreal targetScaleMultiplier)
+{
+ Q_D(QQuickWheelHandler);
+ if (qFuzzyCompare(d->targetScaleMultiplier, targetScaleMultiplier))
+ return;
+
+ d->targetScaleMultiplier = targetScaleMultiplier;
+ emit targetScaleMultiplierChanged();
+}
+
+/*!
+ \qmlproperty bool QtQuick::WheelHandler::targetTransformAroundCursor
+
+ Whether the \l target should automatically be repositioned in such a way
+ that it is transformed around the mouse cursor position while the
+ \l property is adjusted. The default is \c true.
+
+ If \l property is set to \c "rotation" and \l targetTransformAroundCursor
+ is \c true, then as the wheel is rotated, the \l target item will rotate in
+ place around the mouse cursor position. If \c targetTransformAroundCursor
+ is \c false, it will rotate around its
+ \l{QQuickItem::transformOrigin}{transformOrigin} instead.
+*/
+bool QQuickWheelHandler::isTargetTransformAroundCursor() const
+{
+ Q_D(const QQuickWheelHandler);
+ return d->targetTransformAroundCursor;
+}
+
+void QQuickWheelHandler::setTargetTransformAroundCursor(bool ttac)
+{
+ Q_D(QQuickWheelHandler);
+ if (d->targetTransformAroundCursor == ttac)
+ return;
+
+ d->targetTransformAroundCursor = ttac;
+ emit targetTransformAroundCursorChanged();
+}
+
+bool QQuickWheelHandler::wantsPointerEvent(QQuickPointerEvent *event)
+{
+ if (!event)
+ return false;
+ QQuickPointerScrollEvent *scroll = event->asPointerScrollEvent();
+ if (!scroll)
+ return false;
+ if (!acceptedDevices().testFlag(QQuickPointerDevice::DeviceType::TouchPad)
+ && scroll->synthSource() != Qt::MouseEventNotSynthesized)
+ return false;
+ if (!active()) {
+ switch (orientation()) {
+ case Qt::Horizontal:
+ if (qFuzzyIsNull(scroll->angleDelta().x()) && qFuzzyIsNull(scroll->pixelDelta().x()))
+ return false;
+ break;
+ case Qt::Vertical:
+ if (qFuzzyIsNull(scroll->angleDelta().y()) && qFuzzyIsNull(scroll->pixelDelta().y()))
+ return false;
+ break;
+ }
+ }
+ QQuickEventPoint *point = event->point(0);
+ if (QQuickPointerDeviceHandler::wantsPointerEvent(event) && wantsEventPoint(point) && parentContains(point)) {
+ setPointId(point->pointId());
+ return true;
+ }
+ return false;
+}
+
+void QQuickWheelHandler::handleEventPoint(QQuickEventPoint *point)
+{
+ Q_D(QQuickWheelHandler);
+ QQuickPointerScrollEvent *event = point->pointerEvent()->asPointerScrollEvent();
+ setActive(true); // ScrollEnd will not happen unless it was already active (see setActive(false) below)
+ point->setAccepted();
+ qreal inversion = !d->invertible && event->isInverted() ? -1 : 1;
+ qreal angleDelta = inversion * qreal(orientation() == Qt::Horizontal ? event->angleDelta().x() :
+ event->angleDelta().y()) / 8;
+ d->rotation += angleDelta;
+ emit rotationChanged();
+ emit wheel(event);
+ if (!d->propertyName.isEmpty() && target()) {
+ QQuickItem *t = target();
+ // writing target()'s property is done via QMetaProperty::write() so that any registered interceptors can react.
+ if (d->propertyName == QLatin1String("scale")) {
+ qreal multiplier = qPow(d->targetScaleMultiplier, angleDelta * d->rotationScale / 15); // wheel "clicks"
+ const QPointF centroidParentPos = t->parentItem()->mapFromScene(point->scenePosition());
+ const QPointF positionWas = t->position();
+ const qreal scaleWas = t->scale();
+ const qreal activePropertyValue = scaleWas * multiplier;
+ qCDebug(lcWheelHandler) << objectName() << "angle delta" << event->angleDelta() << "pixel delta" << event->pixelDelta()
+ << "@" << point->position() << "in parent" << centroidParentPos
+ << "in scene" << point->scenePosition()
+ << "multiplier" << multiplier << "scale" << scaleWas
+ << "->" << activePropertyValue;
+ d->targetMetaProperty().write(t, activePropertyValue);
+ if (d->targetTransformAroundCursor) {
+ // If an interceptor intervened, scale may now be different than we asked for. Adjust accordingly.
+ multiplier = t->scale() / scaleWas;
+ const QPointF adjPos = QQuickItemPrivate::get(t)->adjustedPosForTransform(
+ centroidParentPos, positionWas, QVector2D(), scaleWas, multiplier, t->rotation(), 0);
+ qCDebug(lcWheelHandler) << "adjusting item pos" << adjPos << "in scene" << t->parentItem()->mapToScene(adjPos);
+ t->setPosition(adjPos);
+ }
+ } else if (d->propertyName == QLatin1String("rotation")) {
+ const QPointF positionWas = t->position();
+ const qreal rotationWas = t->rotation();
+ const qreal activePropertyValue = rotationWas + angleDelta * d->rotationScale;
+ const QPointF centroidParentPos = t->parentItem()->mapFromScene(point->scenePosition());
+ qCDebug(lcWheelHandler) << objectName() << "angle delta" << event->angleDelta() << "pixel delta" << event->pixelDelta()
+ << "@" << point->position() << "in parent" << centroidParentPos
+ << "in scene" << point->scenePosition() << "rotation" << t->rotation()
+ << "->" << activePropertyValue;
+ d->targetMetaProperty().write(t, activePropertyValue);
+ if (d->targetTransformAroundCursor) {
+ // If an interceptor intervened, rotation may now be different than we asked for. Adjust accordingly.
+ const QPointF adjPos = QQuickItemPrivate::get(t)->adjustedPosForTransform(
+ centroidParentPos, positionWas, QVector2D(),
+ t->scale(), 1, rotationWas, t->rotation() - rotationWas);
+ qCDebug(lcWheelHandler) << "adjusting item pos" << adjPos << "in scene" << t->parentItem()->mapToScene(adjPos);
+ t->setPosition(adjPos);
+ }
+ } else {
+ qCDebug(lcWheelHandler) << objectName() << "angle delta" << event->angleDelta() << "scaled" << angleDelta << "total" << d->rotation << "pixel delta" << event->pixelDelta()
+ << "@" << point->position() << "in scene" << point->scenePosition() << "rotation" << t->rotation();
+ qreal delta = 0;
+ if (event->hasPixelDelta()) {
+ delta = inversion * d->rotationScale * qreal(orientation() == Qt::Horizontal ? event->pixelDelta().x() : event->pixelDelta().y());
+ qCDebug(lcWheelHandler) << "changing target" << d->propertyName << "by pixel delta" << delta << "from" << event;
+ } else {
+ delta = angleDelta * d->rotationScale;
+ qCDebug(lcWheelHandler) << "changing target" << d->propertyName << "by scaled angle delta" << delta << "from" << event;
+ }
+ bool ok = false;
+ qreal value = d->targetMetaProperty().read(t).toReal(&ok);
+ if (ok)
+ d->targetMetaProperty().write(t, value + qreal(delta));
+ else
+ qWarning() << "failed to read property" << d->propertyName << "of" << t;
+ }
+ }
+ switch (event->phase()) {
+ case Qt::ScrollEnd:
+ qCDebug(lcWheelHandler) << objectName() << "deactivating due to ScrollEnd phase";
+ setActive(false);
+ break;
+ case Qt::NoScrollPhase:
+ d->deactivationTimer.start(qRound(d->activeTimeout * 1000), this);
+ break;
+ case Qt::ScrollBegin:
+ case Qt::ScrollUpdate:
+ case Qt::ScrollMomentum:
+ break;
+ }
+}
+
+void QQuickWheelHandler::onTargetChanged(QQuickItem *oldTarget)
+{
+ Q_UNUSED(oldTarget)
+ Q_D(QQuickWheelHandler);
+ d->metaPropertyDirty = true;
+}
+
+void QQuickWheelHandler::onActiveChanged()
+{
+ Q_D(QQuickWheelHandler);
+ if (!active())
+ d->deactivationTimer.stop();
+}
+
+void QQuickWheelHandler::timerEvent(QTimerEvent *event)
+{
+ Q_D(const QQuickWheelHandler);
+ if (event->timerId() == d->deactivationTimer.timerId()) {
+ qCDebug(lcWheelHandler) << objectName() << "deactivating due to timeout";
+ setActive(false);
+ }
+}
+
+QQuickWheelHandlerPrivate::QQuickWheelHandlerPrivate()
+ : QQuickSinglePointHandlerPrivate()
+{
+}
+
+QMetaProperty &QQuickWheelHandlerPrivate::targetMetaProperty() const
+{
+ Q_Q(const QQuickWheelHandler);
+ if (metaPropertyDirty && q->target()) {
+ if (!propertyName.isEmpty()) {
+ const QMetaObject *targetMeta = q->target()->metaObject();
+ metaProperty = targetMeta->property(
+ targetMeta->indexOfProperty(propertyName.toLocal8Bit().constData()));
+ }
+ metaPropertyDirty = false;
+ }
+ return metaProperty;
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/handlers/qquickwheelhandler_p.h b/src/quick/handlers/qquickwheelhandler_p.h
new file mode 100644
index 0000000000..f8d1c00726
--- /dev/null
+++ b/src/quick/handlers/qquickwheelhandler_p.h
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKWHEELHANDLER_H
+#define QQUICKWHEELHANDLER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qquickitem.h"
+#include "qevent.h"
+#include "qquicksinglepointhandler_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QQuickWheelEvent;
+class QQuickWheelHandlerPrivate;
+
+class Q_QUICK_PRIVATE_EXPORT QQuickWheelHandler : public QQuickSinglePointHandler
+{
+ Q_OBJECT
+ Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
+ Q_PROPERTY(bool invertible READ isInvertible WRITE setInvertible NOTIFY invertibleChanged)
+ Q_PROPERTY(qreal activeTimeout READ activeTimeout WRITE setActiveTimeout NOTIFY activeTimeoutChanged)
+ Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
+ Q_PROPERTY(qreal rotationScale READ rotationScale WRITE setRotationScale NOTIFY rotationScaleChanged)
+ Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
+ Q_PROPERTY(qreal targetScaleMultiplier READ targetScaleMultiplier WRITE setTargetScaleMultiplier NOTIFY targetScaleMultiplierChanged)
+ Q_PROPERTY(bool targetTransformAroundCursor READ isTargetTransformAroundCursor WRITE setTargetTransformAroundCursor NOTIFY targetTransformAroundCursorChanged)
+
+public:
+ explicit QQuickWheelHandler(QQuickItem *parent = nullptr);
+
+ Qt::Orientation orientation() const;
+ void setOrientation(Qt::Orientation orientation);
+
+ bool isInvertible() const;
+ void setInvertible(bool invertible);
+
+ qreal activeTimeout() const;
+ void setActiveTimeout(qreal timeout);
+
+ qreal rotation() const;
+ void setRotation(qreal rotation);
+
+ qreal rotationScale() const;
+ void setRotationScale(qreal rotationScale);
+
+ QString property() const;
+ void setProperty(const QString &name);
+
+ qreal targetScaleMultiplier() const;
+ void setTargetScaleMultiplier(qreal targetScaleMultiplier);
+
+ bool isTargetTransformAroundCursor() const;
+ void setTargetTransformAroundCursor(bool ttac);
+
+Q_SIGNALS:
+ void wheel(QQuickPointerScrollEvent *event);
+
+ void orientationChanged();
+ void invertibleChanged();
+ void activeTimeoutChanged();
+ void rotationChanged();
+ void rotationScaleChanged();
+ void propertyChanged();
+ void targetScaleMultiplierChanged();
+ void targetTransformAroundCursorChanged();
+
+protected:
+ bool wantsPointerEvent(QQuickPointerEvent *event) override;
+ void handleEventPoint(QQuickEventPoint *point) override;
+ void onTargetChanged(QQuickItem *oldTarget) override;
+ void onActiveChanged() override;
+ void timerEvent(QTimerEvent *event) override;
+
+ Q_DECLARE_PRIVATE(QQuickWheelHandler)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickWheelHandler)
+
+#endif // QQUICKWHEELHANDLER_H
diff --git a/src/quick/handlers/qquickwheelhandler_p_p.h b/src/quick/handlers/qquickwheelhandler_p_p.h
new file mode 100644
index 0000000000..d35e04c51b
--- /dev/null
+++ b/src/quick/handlers/qquickwheelhandler_p_p.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKWHEELHANDLER_P_P_H
+#define QQUICKWHEELHANDLER_P_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qquicksinglepointhandler_p_p.h"
+#include "qquickwheelhandler_p.h"
+#include <QtCore/qbasictimer.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_QUICK_PRIVATE_EXPORT QQuickWheelHandlerPrivate : public QQuickSinglePointHandlerPrivate
+{
+ Q_DECLARE_PUBLIC(QQuickWheelHandler)
+
+public:
+ static QQuickWheelHandlerPrivate* get(QQuickWheelHandler *q) { return q->d_func(); }
+ static const QQuickWheelHandlerPrivate* get(const QQuickWheelHandler *q) { return q->d_func(); }
+
+ QQuickWheelHandlerPrivate();
+
+ QMetaProperty &targetMetaProperty() const;
+
+ QBasicTimer deactivationTimer;
+ qreal activeTimeout = 0.1;
+ qreal rotationScale = 1;
+ qreal rotation = 0; // in units of degrees
+ qreal targetScaleMultiplier = 1.25992104989487; // qPow(2, 1/3)
+ QString propertyName;
+ mutable QMetaProperty metaProperty;
+ Qt::Orientation orientation = Qt::Vertical;
+ mutable bool metaPropertyDirty = true;
+ bool invertible = true;
+ bool targetTransformAroundCursor = true;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKWHEELHANDLER_P_P_H
diff --git a/src/quick/items/context2d/qquickcanvascontext_p.h b/src/quick/items/context2d/qquickcanvascontext_p.h
index 95100d2912..3872a2ac74 100644
--- a/src/quick/items/context2d/qquickcanvascontext_p.h
+++ b/src/quick/items/context2d/qquickcanvascontext_p.h
@@ -56,7 +56,7 @@
QT_REQUIRE_CONFIG(quick_canvas);
#include <QtQuick/qquickitem.h>
-#include <private/qv8engine_p.h>
+#include <QtQml/private/qv4value_p.h>
QT_BEGIN_NAMESPACE
@@ -80,6 +80,7 @@ public:
virtual void prepare(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth, bool antialiasing);
virtual void flush();
+ virtual QV4::ExecutionEngine *v4Engine() const = 0;
virtual void setV4Engine(QV4::ExecutionEngine *engine) = 0;
virtual QV4::ReturnedValue v4value() const = 0;
diff --git a/src/quick/items/context2d/qquickcanvasitem.cpp b/src/quick/items/context2d/qquickcanvasitem.cpp
index 3462b0dbac..b8e6d58af4 100644
--- a/src/quick/items/context2d/qquickcanvasitem.cpp
+++ b/src/quick/items/context2d/qquickcanvasitem.cpp
@@ -378,13 +378,10 @@ void QQuickCanvasItem::setContextType(const QString &contextType)
this property will contain the current drawing context, otherwise null.
*/
-QQmlV4Handle QQuickCanvasItem::context() const
+QJSValue QQuickCanvasItem::context() const
{
Q_D(const QQuickCanvasItem);
- if (d->context)
- return QQmlV4Handle(d->context->v4value());
-
- return QQmlV4Handle(QV4::Encode::null());
+ return d->context ? QJSValue(d->context->v4Engine(), d->context->v4value()) : QJSValue();
}
/*!
@@ -772,7 +769,8 @@ QSGNode *QQuickCanvasItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
QSGInternalImageNode *node = static_cast<QSGInternalImageNode *>(oldNode);
if (!node) {
- node = QQuickWindowPrivate::get(window())->context->sceneGraphContext()->createInternalImageNode();
+ QSGRenderContext *rc = QQuickWindowPrivate::get(window())->context;
+ node = rc->sceneGraphContext()->createInternalImageNode(rc);
d->node = node;
}
diff --git a/src/quick/items/context2d/qquickcanvasitem_p.h b/src/quick/items/context2d/qquickcanvasitem_p.h
index 7dc981a6eb..cd2977429b 100644
--- a/src/quick/items/context2d/qquickcanvasitem_p.h
+++ b/src/quick/items/context2d/qquickcanvasitem_p.h
@@ -56,9 +56,9 @@
QT_REQUIRE_CONFIG(quick_canvas);
#include <QtQuick/qquickitem.h>
-#include <private/qv8engine_p.h>
#include <private/qqmlrefcount_p.h>
#include <QtCore/QThread>
+#include <QtCore/qmutex.h>
#include <QtGui/QImage>
QT_BEGIN_NAMESPACE
@@ -93,7 +93,7 @@ class QQuickCanvasItem : public QQuickItem
Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged)
Q_PROPERTY(QString contextType READ contextType WRITE setContextType NOTIFY contextTypeChanged)
- Q_PROPERTY(QQmlV4Handle context READ context NOTIFY contextChanged)
+ Q_PROPERTY(QJSValue context READ context NOTIFY contextChanged)
Q_PROPERTY(QSizeF canvasSize READ canvasSize WRITE setCanvasSize NOTIFY canvasSizeChanged)
Q_PROPERTY(QSize tileSize READ tileSize WRITE setTileSize NOTIFY tileSizeChanged)
Q_PROPERTY(QRectF canvasWindow READ canvasWindow WRITE setCanvasWindow NOTIFY canvasWindowChanged)
@@ -122,7 +122,7 @@ public:
QString contextType() const;
void setContextType(const QString &contextType);
- QQmlV4Handle context() const;
+ QJSValue context() const;
QSizeF canvasSize() const;
void setCanvasSize(const QSizeF &);
diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp
index 7cd222d3c1..54cda72a36 100644
--- a/src/quick/items/context2d/qquickcontext2d.cpp
+++ b/src/quick/items/context2d/qquickcontext2d.cpp
@@ -56,7 +56,6 @@
#include <private/qquickimage_p_p.h>
#include <qqmlinfo.h>
-#include <private/qv8engine_p.h>
#include <qqmlengine.h>
#include <private/qv4domerrors_p.h>
@@ -474,7 +473,7 @@ static QFont qt_font_from_string(const QString& fontString, const QFont &current
return newFont;
}
-class QQuickContext2DEngineData : public QV8Engine::Deletable
+class QQuickContext2DEngineData : public QV4::ExecutionEngine::Deletable
{
public:
QQuickContext2DEngineData(QV4::ExecutionEngine *engine);
@@ -4324,7 +4323,8 @@ void QQuickContext2D::init(QQuickCanvasItem *canvasItem, const QVariantMap &args
m_renderTarget = QQuickCanvasItem::Image;
}
- // Disable Framebuffer Object based rendering when not running with OpenGL
+ // Disable Framebuffer Object based rendering when not running with OpenGL.
+ // Same goes for the RHI based code path (regardless of the backend in use).
if (m_renderTarget == QQuickCanvasItem::FramebufferObject) {
QSGRendererInterface *rif = canvasItem->window()->rendererInterface();
if (rif && rif->graphicsApi() != QSGRendererInterface::OpenGL)
@@ -4587,6 +4587,11 @@ void QQuickContext2D::reset()
m_buffer->clearRect(QRectF(0, 0, m_canvas->width(), m_canvas->height()));
}
+QV4::ExecutionEngine *QQuickContext2D::v4Engine() const
+{
+ return m_v4engine;
+}
+
void QQuickContext2D::setV4Engine(QV4::ExecutionEngine *engine)
{
if (m_v4engine != engine) {
diff --git a/src/quick/items/context2d/qquickcontext2d_p.h b/src/quick/items/context2d/qquickcontext2d_p.h
index 1ece6796f3..b5626dec0c 100644
--- a/src/quick/items/context2d/qquickcontext2d_p.h
+++ b/src/quick/items/context2d/qquickcontext2d_p.h
@@ -65,7 +65,6 @@ QT_REQUIRE_CONFIG(quick_canvas);
#include <QtCore/qstring.h>
#include <QtCore/qstack.h>
#include <QtCore/qqueue.h>
-#include <private/qv8engine_p.h>
#include <QtCore/QWaitCondition>
#include <private/qv4value_p.h>
@@ -199,6 +198,7 @@ public:
QImage toImage(const QRectF& bounds) override;
QV4::ReturnedValue v4value() const override;
+ QV4::ExecutionEngine *v4Engine() const override;
void setV4Engine(QV4::ExecutionEngine *eng) override;
QQuickCanvasItem* canvas() const { return m_canvas; }
diff --git a/src/quick/items/context2d/qquickcontext2dtexture.cpp b/src/quick/items/context2d/qquickcontext2dtexture.cpp
index 69ff3b3852..0ebd1a66c9 100644
--- a/src/quick/items/context2d/qquickcontext2dtexture.cpp
+++ b/src/quick/items/context2d/qquickcontext2dtexture.cpp
@@ -41,7 +41,7 @@
#include "qquickcontext2dtile_p.h"
#include "qquickcanvasitem_p.h"
#include <private/qquickitem_p.h>
-#include <QtQuick/private/qsgtexture_p.h>
+#include <QtQuick/private/qsgplaintexture_p.h>
#include "qquickcontext2dcommandbuffer_p.h"
#include <QOpenGLPaintDevice>
#if QT_CONFIG(opengl)
@@ -238,15 +238,8 @@ void QQuickContext2DTexture::paintWithoutTiles(QQuickContext2DCommandBuffer *ccb
QPainter p;
p.begin(device);
- if (m_antialiasing)
- p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing, true);
- else
- p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing, false);
-
- if (m_smooth)
- p.setRenderHint(QPainter::SmoothPixmapTransform, true);
- else
- p.setRenderHint(QPainter::SmoothPixmapTransform, false);
+ p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing, m_antialiasing);
+ p.setRenderHint(QPainter::SmoothPixmapTransform, m_smooth);
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
diff --git a/src/quick/items/items.pri b/src/quick/items/items.pri
index e649b5429d..6f2f9fbd8e 100644
--- a/src/quick/items/items.pri
+++ b/src/quick/items/items.pri
@@ -52,8 +52,6 @@ HEADERS += \
$$PWD/qquickstateoperations_p.h \
$$PWD/qquickimplicitsizeitem_p.h \
$$PWD/qquickimplicitsizeitem_p_p.h \
- $$PWD/qquickdrag_p.h \
- $$PWD/qquickdroparea_p.h \
$$PWD/qquickmultipointtoucharea_p.h \
$$PWD/qquickscreen_p.h \
$$PWD/qquickwindowattached_p.h \
@@ -95,8 +93,6 @@ SOURCES += \
$$PWD/qquickstateoperations.cpp \
$$PWD/qquickimplicitsizeitem.cpp \
$$PWD/qquickaccessibleattached.cpp \
- $$PWD/qquickdrag.cpp \
- $$PWD/qquickdroparea.cpp \
$$PWD/qquickmultipointtoucharea.cpp \
$$PWD/qquickwindowmodule.cpp \
$$PWD/qquickscreen.cpp \
@@ -105,6 +101,16 @@ SOURCES += \
$$PWD/qquickgraphicsinfo.cpp \
$$PWD/qquickitemgrabresult.cpp
+qtConfig(quick-draganddrop) {
+ HEADERS += \
+ $$PWD/qquickdrag_p.h \
+ $$PWD/qquickdroparea_p.h \
+
+ SOURCES += \
+ $$PWD/qquickdrag.cpp \
+ $$PWD/qquickdroparea.cpp \
+}
+
qtConfig(quick-animatedimage) {
HEADERS += \
$$PWD/qquickanimatedimage_p.h \
diff --git a/src/quick/items/qquickanimatedimage.cpp b/src/quick/items/qquickanimatedimage.cpp
index fe445425e7..18d492cd68 100644
--- a/src/quick/items/qquickanimatedimage.cpp
+++ b/src/quick/items/qquickanimatedimage.cpp
@@ -67,7 +67,7 @@ QQuickPixmap* QQuickAnimatedImagePrivate::infoForCurrentFrame(QQmlEngine *engine
.arg(current));
}
if (!requestedUrl.isEmpty()) {
- if (QQuickPixmap::isCached(requestedUrl, QSize(), QQuickImageProviderOptions()))
+ if (QQuickPixmap::isCached(requestedUrl, QSize(), 0, QQuickImageProviderOptions()))
pixmap = new QQuickPixmap(engine, requestedUrl);
else
pixmap = new QQuickPixmap(requestedUrl, movie->currentImage());
@@ -139,6 +139,9 @@ QQuickAnimatedImage::QQuickAnimatedImage(QQuickItem *parent)
: QQuickImage(*(new QQuickAnimatedImagePrivate), parent)
{
connect(this, &QQuickImageBase::cacheChanged, this, &QQuickAnimatedImage::onCacheChanged);
+ connect(this, &QQuickImageBase::currentFrameChanged, this, &QQuickAnimatedImage::frameChanged);
+ connect(this, &QQuickImageBase::currentFrameChanged, this, &QQuickAnimatedImage::currentFrameChanged);
+ connect(this, &QQuickImageBase::frameCountChanged, this, &QQuickAnimatedImage::frameCountChanged);
}
QQuickAnimatedImage::~QQuickAnimatedImage()
@@ -464,7 +467,7 @@ void QQuickAnimatedImage::movieUpdate()
if (d->movie) {
d->setPixmap(*d->infoForCurrentFrame(qmlEngine(this)));
- emit frameChanged();
+ emit QQuickImageBase::currentFrameChanged();
}
}
diff --git a/src/quick/items/qquickanimatedimage_p.h b/src/quick/items/qquickanimatedimage_p.h
index 6b5db215bd..13eae83350 100644
--- a/src/quick/items/qquickanimatedimage_p.h
+++ b/src/quick/items/qquickanimatedimage_p.h
@@ -85,10 +85,10 @@ public:
bool isPaused() const;
void setPaused(bool pause);
- int currentFrame() const;
- void setCurrentFrame(int frame);
+ int currentFrame() const override;
+ void setCurrentFrame(int frame) override;
- int frameCount() const;
+ int frameCount() const override;
qreal speed() const;
void setSpeed(qreal speed);
@@ -101,6 +101,7 @@ Q_SIGNALS:
void playingChanged();
void pausedChanged();
void frameChanged();
+ void currentFrameChanged();
void frameCountChanged();
Q_REVISION(11) void speedChanged();
diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp
index 18adb4e992..d22e77c8ad 100644
--- a/src/quick/items/qquickanimatedsprite.cpp
+++ b/src/quick/items/qquickanimatedsprite.cpp
@@ -532,7 +532,7 @@ void QQuickAnimatedSprite::setInterpolate(bool arg)
}
}
-void QQuickAnimatedSprite::setSource(QUrl arg)
+void QQuickAnimatedSprite::setSource(const QUrl &arg)
{
Q_D(QQuickAnimatedSprite);
diff --git a/src/quick/items/qquickanimatedsprite_p.h b/src/quick/items/qquickanimatedsprite_p.h
index ff59591c9f..d36f908c78 100644
--- a/src/quick/items/qquickanimatedsprite_p.h
+++ b/src/quick/items/qquickanimatedsprite_p.h
@@ -122,7 +122,7 @@ Q_SIGNALS:
void runningChanged(bool arg);
void interpolateChanged(bool arg);
- void sourceChanged(QUrl arg);
+ void sourceChanged(const QUrl &arg);
void reverseChanged(bool arg);
void frameSyncChanged(bool arg);
void frameCountChanged(int arg);
@@ -148,7 +148,7 @@ public Q_SLOTS:
void setRunning(bool arg);
void setPaused(bool arg);
void setInterpolate(bool arg);
- void setSource(QUrl arg);
+ void setSource(const QUrl &arg);
void setReverse(bool arg);
void setFrameSync(bool arg);
void setFrameCount(int arg);
diff --git a/src/quick/items/qquickborderimage.cpp b/src/quick/items/qquickborderimage.cpp
index b840328184..462a44634e 100644
--- a/src/quick/items/qquickborderimage.cpp
+++ b/src/quick/items/qquickborderimage.cpp
@@ -327,7 +327,7 @@ void QQuickBorderImage::load()
QNetworkRequest req(d->url);
d->sciReply = qmlEngine(this)->networkAccessManager()->get(req);
qmlobject_connect(d->sciReply, QNetworkReply, SIGNAL(finished()),
- this, QQuickBorderImage, SLOT(sciRequestFinished()))
+ this, QQuickBorderImage, SLOT(sciRequestFinished()));
#endif
}
} else {
@@ -343,7 +343,7 @@ void QQuickBorderImage::load()
QUrl loadUrl = d->url;
resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio);
- d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options);
+ d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, QQuickImageProviderOptions(), d->currentFrame, d->frameCount);
if (d->pix.isLoading()) {
if (d->progress != 0.0) {
@@ -534,6 +534,10 @@ void QQuickBorderImage::requestFinished()
d->oldSourceSize = sourceSize();
emit sourceSizeChanged();
}
+ if (d->frameCount != d->pix.frameCount()) {
+ d->frameCount = d->pix.frameCount();
+ emit frameCountChanged();
+ }
pixmapChange();
}
@@ -647,7 +651,7 @@ QSGNode *QQuickBorderImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat
bool updatePixmap = d->pixmapChanged;
d->pixmapChanged = false;
if (!node) {
- node = d->sceneGraphContext()->createInternalImageNode();
+ node = d->sceneGraphContext()->createInternalImageNode(d->sceneGraphRenderContext());
updatePixmap = true;
}
@@ -693,6 +697,18 @@ void QQuickBorderImage::pixmapChange()
update();
}
+/*!
+ \qmlproperty int QtQuick::BorderImage::currentFrame
+ \qmlproperty int QtQuick::BorderImage::frameCount
+ \since 5.14
+
+ currentFrame is the frame that is currently visible. The default is \c 0.
+ You can set it to a number between \c 0 and \c {frameCount - 1} to display a
+ different frame, if the image contains multiple frames.
+
+ frameCount is the number of frames in the image. Most images have only one frame.
+*/
+
QT_END_NAMESPACE
#include "moc_qquickborderimage_p.cpp"
diff --git a/src/quick/items/qquickborderimage_p_p.h b/src/quick/items/qquickborderimage_p_p.h
index 0f4e7acc05..17dab7d121 100644
--- a/src/quick/items/qquickborderimage_p_p.h
+++ b/src/quick/items/qquickborderimage_p_p.h
@@ -86,7 +86,7 @@ public:
if (!border) {
border = new QQuickScaleGrid(q);
qmlobject_connect(border, QQuickScaleGrid, SIGNAL(borderChanged()),
- q, QQuickBorderImage, SLOT(doUpdate()))
+ q, QQuickBorderImage, SLOT(doUpdate()));
}
return border;
}
diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp
index a2cb739ff2..7c6f1caa54 100644
--- a/src/quick/items/qquickdrag.cpp
+++ b/src/quick/items/qquickdrag.cpp
@@ -45,7 +45,6 @@
#include <QtQuick/private/qquickevents_p_p.h>
#include <private/qquickitemchangelistener_p.h>
#include <private/qquickpixmapcache_p.h>
-#include <private/qv8engine_p.h>
#include <private/qv4scopedvalue_p.h>
#include <QtCore/qmimedata.h>
#include <QtQml/qqmlinfo.h>
@@ -53,7 +52,6 @@
#include <QtGui/qstylehints.h>
#include <QtGui/qguiapplication.h>
-#if QT_CONFIG(draganddrop)
#include <qpa/qplatformdrag.h>
#include <QtGui/qdrag.h>
@@ -1001,5 +999,3 @@ QQuickDragAttached *QQuickDrag::qmlAttachedProperties(QObject *obj)
QT_END_NAMESPACE
#include "moc_qquickdrag_p.cpp"
-
-#endif // draganddrop
diff --git a/src/quick/items/qquickdrag_p.h b/src/quick/items/qquickdrag_p.h
index 6bfbae74c9..094070aa2c 100644
--- a/src/quick/items/qquickdrag_p.h
+++ b/src/quick/items/qquickdrag_p.h
@@ -53,14 +53,14 @@
#include <QtQuick/qquickitem.h>
-#include <private/qv8engine_p.h>
+#include <private/qintrusivelist_p.h>
#include <private/qqmlguard_p.h>
#include <QtCore/qmimedata.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qurl.h>
-#if QT_CONFIG(draganddrop)
+QT_REQUIRE_CONFIG(quick_draganddrop);
QT_BEGIN_NAMESPACE
@@ -318,6 +318,4 @@ QT_END_NAMESPACE
QML_DECLARE_TYPE(QQuickDrag)
QML_DECLARE_TYPEINFO(QQuickDrag, QML_HAS_ATTACHED_PROPERTIES)
-#endif // draganddrop
-
#endif
diff --git a/src/quick/items/qquickdroparea.cpp b/src/quick/items/qquickdroparea.cpp
index fbbee31653..76be8cc261 100644
--- a/src/quick/items/qquickdroparea.cpp
+++ b/src/quick/items/qquickdroparea.cpp
@@ -43,7 +43,7 @@
#include <private/qv4arraybuffer_p.h>
-#if QT_CONFIG(draganddrop)
+#include <QtCore/qregularexpression.h>
QT_BEGIN_NAMESPACE
@@ -70,7 +70,7 @@ public:
QStringList getKeys(const QMimeData *mimeData) const;
QStringList keys;
- QRegExp keyRegExp;
+ QRegularExpression keyRegExp;
QPointF dragPosition;
QQuickDropAreaDrag *drag;
QPointer<QObject> source;
@@ -157,13 +157,15 @@ void QQuickDropArea::setKeys(const QStringList &keys)
d->keys = keys;
if (keys.isEmpty()) {
- d->keyRegExp = QRegExp();
+ d->keyRegExp = QRegularExpression();
} else {
- QString pattern = QLatin1Char('(') + QRegExp::escape(keys.first());
+ QString pattern = QLatin1Char('(') + QRegularExpression::escape(keys.first());
for (int i = 1; i < keys.count(); ++i)
- pattern += QLatin1Char('|') + QRegExp::escape(keys.at(i));
+ pattern += QLatin1Char('|') + QRegularExpression::escape(keys.at(i));
pattern += QLatin1Char(')');
- d->keyRegExp = QRegExp(pattern.replace(QLatin1String("\\*"), QLatin1String(".+")));
+ d->keyRegExp = QRegularExpression(
+ QRegularExpression::anchoredPattern(pattern.replace(QLatin1String("\\*"),
+ QLatin1String(".+"))));
}
emit keysChanged();
}
@@ -231,12 +233,11 @@ void QQuickDropArea::dragMoveEvent(QDragMoveEvent *event)
bool QQuickDropAreaPrivate::hasMatchingKey(const QStringList &keys) const
{
- if (keyRegExp.isEmpty())
+ if (keyRegExp.pattern().isEmpty())
return true;
- QRegExp copy = keyRegExp;
for (const QString &key : keys) {
- if (copy.exactMatch(key))
+ if (key.contains(keyRegExp))
return true;
}
return false;
@@ -619,5 +620,3 @@ void QQuickDropEvent::accept(QQmlV4Function *args)
QT_END_NAMESPACE
#include "moc_qquickdroparea_p.cpp"
-
-#endif // draganddrop
diff --git a/src/quick/items/qquickdroparea_p.h b/src/quick/items/qquickdroparea_p.h
index d25cd4decc..2b2ace2eae 100644
--- a/src/quick/items/qquickdroparea_p.h
+++ b/src/quick/items/qquickdroparea_p.h
@@ -55,7 +55,7 @@
#include <QtGui/qevent.h>
-#if QT_CONFIG(draganddrop)
+QT_REQUIRE_CONFIG(quick_draganddrop);
QT_BEGIN_NAMESPACE
@@ -190,6 +190,4 @@ QT_END_NAMESPACE
QML_DECLARE_TYPE(QQuickDropEvent)
QML_DECLARE_TYPE(QQuickDropArea)
-#endif // draganddrop
-
#endif // QQUICKDROPAREA_P_H
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp
index 7d128b4a16..0c697739fa 100644
--- a/src/quick/items/qquickevents.cpp
+++ b/src/quick/items/qquickevents.cpp
@@ -41,6 +41,7 @@
#include <QtCore/qmap.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qtouchdevice_p.h>
+#include <QtGui/private/qevent_p.h>
#include <QtQuick/private/qquickitem_p.h>
#include <QtQuick/private/qquickpointerhandler_p.h>
#include <QtQuick/private/qquickwindow_p.h>
@@ -1448,7 +1449,7 @@ QQuickPointerEvent *QQuickPointerScrollEvent::reset(QEvent *event)
m_synthSource = ev->source();
m_inverted = ev->inverted();
- m_point->reset(Qt::TouchPointMoved, ev->posF(), quint64(1) << 24, ev->timestamp()); // mouse has device ID 1
+ m_point->reset(Qt::TouchPointMoved, ev->position(), quint64(1) << 24, ev->timestamp()); // mouse has device ID 1
}
#endif
// TODO else if (event->type() == QEvent::Scroll) ...
@@ -1828,6 +1829,7 @@ QTouchEvent *QQuickPointerTouchEvent::touchEventForItem(QQuickItem *item, bool i
// but that would require changing tst_qquickwindow::touchEvent_velocity(): it expects transformed velocity
bool anyPressOrReleaseInside = false;
+ bool anyStationaryWithModifiedPropertyInside = false;
bool anyGrabber = false;
QMatrix4x4 transformMatrix(QQuickItemPrivate::get(item)->windowToItemTransform());
for (int i = 0; i < m_pointCount; ++i) {
@@ -1860,6 +1862,8 @@ QTouchEvent *QQuickPointerTouchEvent::touchEventForItem(QQuickItem *item, bool i
anyPressOrReleaseInside = true;
const QTouchEvent::TouchPoint *tp = touchPointById(p->pointId());
if (tp) {
+ if (isInside && tp->d->stationaryWithModifiedProperty)
+ anyStationaryWithModifiedPropertyInside = true;
eventStates |= tp->state();
QTouchEvent::TouchPoint tpCopy = *tp;
tpCopy.setPos(item->mapFromScene(tpCopy.scenePos()));
@@ -1873,7 +1877,8 @@ QTouchEvent *QQuickPointerTouchEvent::touchEventForItem(QQuickItem *item, bool i
// Now touchPoints will have only points which are inside the item.
// But if none of them were just pressed inside, and the item has no other reason to care, ignore them anyway.
- if (eventStates == Qt::TouchPointStationary || touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering))
+ if ((eventStates == Qt::TouchPointStationary && !anyStationaryWithModifiedPropertyInside) ||
+ touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering))
return nullptr;
// if all points have the same state, set the event type accordingly
diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h
index e614b1bd6d..1a3737091f 100644
--- a/src/quick/items/qquickevents_p_p.h
+++ b/src/quick/items/qquickevents_p_p.h
@@ -605,6 +605,7 @@ private:
bool m_inverted = false;
friend class QQuickWindowPrivate;
+ friend class QQuickWheelHandler;
Q_DISABLE_COPY(QQuickPointerScrollEvent)
};
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp
index 7e1f54f07e..d9ec7de611 100644
--- a/src/quick/items/qquickflickable.cpp
+++ b/src/quick/items/qquickflickable.cpp
@@ -266,9 +266,9 @@ void QQuickFlickablePrivate::init()
QQml_setParent_noEvent(contentItem, q);
contentItem->setParentItem(q);
qmlobject_connect(&timeline, QQuickTimeLine, SIGNAL(completed()),
- q, QQuickFlickable, SLOT(timelineCompleted()))
+ q, QQuickFlickable, SLOT(timelineCompleted()));
qmlobject_connect(&velocityTimeline, QQuickTimeLine, SIGNAL(completed()),
- q, QQuickFlickable, SLOT(velocityTimelineCompleted()))
+ q, QQuickFlickable, SLOT(velocityTimelineCompleted()));
q->setAcceptedMouseButtons(Qt::LeftButton);
q->setAcceptTouchEvents(false); // rely on mouse events synthesized from touch
q->setFiltersChildMouseEvents(true);
@@ -1489,7 +1489,7 @@ void QQuickFlickable::wheelEvent(QWheelEvent *event)
d->vData.velocity = 0;
d->hData.velocity = 0;
d->timer.start();
- d->maybeBeginDrag(currentTimestamp, event->posF());
+ d->maybeBeginDrag(currentTimestamp, event->position());
break;
case Qt::NoScrollPhase: // default phase with an ordinary wheel mouse
case Qt::ScrollUpdate:
@@ -1571,7 +1571,8 @@ void QQuickFlickable::wheelEvent(QWheelEvent *event)
QVector2D velocity(xDelta / elapsed, yDelta / elapsed);
d->lastPosTime = currentTimestamp;
d->accumulatedWheelPixelDelta += QVector2D(event->pixelDelta());
- d->drag(currentTimestamp, event->type(), event->posF(), d->accumulatedWheelPixelDelta, true, !d->scrollingPhase, true, velocity);
+ d->drag(currentTimestamp, event->type(), event->position(), d->accumulatedWheelPixelDelta,
+ true, !d->scrollingPhase, true, velocity);
event->accept();
}
diff --git a/src/quick/items/qquickflickablebehavior_p.h b/src/quick/items/qquickflickablebehavior_p.h
index ae7fe71359..fbce62f075 100644
--- a/src/quick/items/qquickflickablebehavior_p.h
+++ b/src/quick/items/qquickflickablebehavior_p.h
@@ -93,6 +93,11 @@
#define QML_FLICK_MULTIFLICK_THRESHOLD 1250
#endif
+// If the time (ms) between the last move and the release exceeds this, then velocity will be zero.
+#ifndef QML_FLICK_VELOCITY_DECAY_TIME
+#define QML_FLICK_VELOCITY_DECAY_TIME 50
+#endif
+
// Multiflick acceleration minimum contentSize/viewSize ratio
#ifndef QML_FLICK_MULTIFLICK_RATIO
#define QML_FLICK_MULTIFLICK_RATIO 10
diff --git a/src/quick/items/qquickframebufferobject.cpp b/src/quick/items/qquickframebufferobject.cpp
index 48f8b8db5c..190bc6853c 100644
--- a/src/quick/items/qquickframebufferobject.cpp
+++ b/src/quick/items/qquickframebufferobject.cpp
@@ -109,6 +109,10 @@ public:
* and can be used directly in \l {ShaderEffect}{ShaderEffects} and other
* classes that consume texture providers.
*
+ * \warning This class is only suitable when working directly with OpenGL. It
+ * is not compatible with the \l{Scene Graph Adaptations}{RHI-based rendering
+ * path}.
+ *
* \sa {Scene Graph - Rendering FBOs}, {Scene Graph and Rendering}
*/
diff --git a/src/quick/items/qquickframebufferobject.h b/src/quick/items/qquickframebufferobject.h
index d66ca40b3a..db143e48cf 100644
--- a/src/quick/items/qquickframebufferobject.h
+++ b/src/quick/items/qquickframebufferobject.h
@@ -44,11 +44,12 @@
QT_BEGIN_NAMESPACE
-
class QOpenGLFramebufferObject;
class QQuickFramebufferObjectPrivate;
class QSGFramebufferObjectNode;
+// ### Qt 6: To be removed. To be seen if an alternative will need to be introduced.
+
class Q_QUICK_EXPORT QQuickFramebufferObject : public QQuickItem
{
Q_OBJECT
diff --git a/src/quick/items/qquickgenericshadereffect.cpp b/src/quick/items/qquickgenericshadereffect.cpp
index 248c2b6ec3..df61ee853d 100644
--- a/src/quick/items/qquickgenericshadereffect.cpp
+++ b/src/quick/items/qquickgenericshadereffect.cpp
@@ -40,15 +40,32 @@
#include <private/qquickgenericshadereffect_p.h>
#include <private/qquickwindow_p.h>
#include <private/qquickitem_p.h>
-#include <QSignalMapper>
QT_BEGIN_NAMESPACE
-// The generic shader effect is used when the scenegraph backend indicates
-// SupportsShaderEffectNode. This, unlike the monolithic and interconnected (e.g.
-// with particles) OpenGL variant, passes most of the work to a scenegraph node
-// created via the adaptation layer, thus allowing different implementation in
-// the backends.
+namespace {
+class IntSignalMapper : public QObject
+{
+ Q_OBJECT
+
+ int value;
+public:
+ explicit IntSignalMapper(int v)
+ : QObject(nullptr), value(v) {}
+
+public Q_SLOTS:
+ void map() { emit mapped(value); }
+
+Q_SIGNALS:
+ void mapped(int);
+};
+} // unnamed namespace
+
+// The generic shader effect is used whenever on the RHI code path, or when the
+// scenegraph backend indicates SupportsShaderEffectNode. This, unlike the
+// monolithic and interconnected (e.g. with particles) OpenGL variant, passes
+// most of the work to a scenegraph node created via the adaptation layer, thus
+// allowing different implementation in the backends.
QQuickGenericShaderEffect::QQuickGenericShaderEffect(QQuickShaderEffect *item, QObject *parent)
: QObject(parent)
@@ -123,8 +140,8 @@ void QQuickGenericShaderEffect::setBlending(bool enable)
QVariant QQuickGenericShaderEffect::mesh() const
{
- return m_mesh ? qVariantFromValue(static_cast<QObject *>(m_mesh))
- : qVariantFromValue(m_meshResolution);
+ return m_mesh ? QVariant::fromValue(static_cast<QObject *>(m_mesh))
+ : QVariant::fromValue(m_meshResolution);
}
void QQuickGenericShaderEffect::setMesh(const QVariant &mesh)
@@ -254,6 +271,10 @@ QSGNode *QQuickGenericShaderEffect::handleUpdatePaintNode(QSGNode *oldNode, QQui
if (!node) {
QSGRenderContext *rc = QQuickWindowPrivate::get(m_item->window())->context;
node = rc->sceneGraphContext()->createShaderEffectNode(rc, mgr);
+ if (!node) {
+ qWarning("No shader effect node");
+ return nullptr;
+ }
m_dirty = QSGShaderEffectNode::DirtyShaderAll;
}
@@ -445,7 +466,7 @@ bool QQuickGenericShaderEffect::updateShader(Shader shaderType, const QByteArray
// provided and monitored like with an application-provided shader.
QSGGuiThreadShaderEffectManager::ShaderInfo::Variable v;
v.name = QByteArrayLiteral("source");
- v.bindPoint = 0;
+ v.bindPoint = 0; // fake
v.type = texturesSeparate ? QSGGuiThreadShaderEffectManager::ShaderInfo::Texture
: QSGGuiThreadShaderEffectManager::ShaderInfo::Sampler;
m_shaders[shaderType].shaderInfo.variables.append(v);
@@ -543,15 +564,10 @@ void QQuickGenericShaderEffect::updateShaderVars(Shader shaderType)
if (!mp.hasNotifySignal())
qWarning("ShaderEffect: property '%s' does not have notification method", v.name.constData());
- // Have a QSignalMapper that emits mapped() with an index+type on each property change notify signal.
+ // Have a IntSignalMapper that emits mapped() with an index+type on each property change notify signal.
auto &sm(m_signalMappers[shaderType][i]);
- if (!sm.mapper) {
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
- sm.mapper = new QSignalMapper;
-QT_WARNING_POP
- sm.mapper->setMapping(m_item, i | (shaderType << 16));
- }
+ if (!sm.mapper)
+ sm.mapper = new IntSignalMapper(i | (shaderType << 16));
sm.active = true;
const QByteArray signalName = '2' + mp.notifySignal().methodSignature();
QObject::connect(m_item, signalName, sm.mapper, SLOT(map()));
@@ -559,7 +575,7 @@ QT_WARNING_POP
} else {
// Do not warn for dynamic properties.
if (!m_item->property(v.name.constData()).isValid())
- qWarning("ShaderEffect: '%s' does not have a matching property!", v.name.constData());
+ qWarning("ShaderEffect: '%s' does not have a matching property", v.name.constData());
}
vd.value = m_item->property(v.name.constData());
@@ -661,3 +677,4 @@ void QQuickGenericShaderEffect::markGeometryDirtyAndUpdateIfSupportsAtlas()
QT_END_NAMESPACE
#include "moc_qquickgenericshadereffect_p.cpp"
+#include "qquickgenericshadereffect.moc"
diff --git a/src/quick/items/qquickgenericshadereffect_p.h b/src/quick/items/qquickgenericshadereffect_p.h
index 3f6f92921b..368c32d2f8 100644
--- a/src/quick/items/qquickgenericshadereffect_p.h
+++ b/src/quick/items/qquickgenericshadereffect_p.h
@@ -59,8 +59,6 @@
QT_BEGIN_NAMESPACE
-class QSignalMapper;
-
class Q_QUICK_PRIVATE_EXPORT QQuickGenericShaderEffect : public QObject
{
Q_OBJECT
@@ -142,7 +140,7 @@ private:
struct SignalMapper {
SignalMapper() : mapper(nullptr), active(false) { }
- QSignalMapper *mapper;
+ QObject *mapper;
bool active;
};
QVector<SignalMapper> m_signalMappers[NShader];
diff --git a/src/quick/items/qquickgraphicsinfo.cpp b/src/quick/items/qquickgraphicsinfo.cpp
index cd1012c690..8f6f4386fb 100644
--- a/src/quick/items/qquickgraphicsinfo.cpp
+++ b/src/quick/items/qquickgraphicsinfo.cpp
@@ -96,6 +96,12 @@ QQuickGraphicsInfo *QQuickGraphicsInfo::qmlAttachedProperties(QObject *object)
\li GraphicsInfo.Software - Qt Quick's software renderer based on QPainter with the raster paint engine
\li GraphicsInfo.OpenGL - OpenGL or OpenGL ES
\li GraphicsInfo.Direct3D12 - Direct3D 12
+ \li GraphicsInfo.OpenVG - OpenVG
+ \li GraphicsInfo.OpenGLRhi - OpenGL on top of QRhi, a graphics abstraction layer
+ \li GraphicsInfo.Direct3D11Rhi - Direct3D 11 on top of QRhi, a graphics abstraction layer
+ \li GraphicsInfo.VulkanRhi - Vulkan on top of QRhi, a graphics abstraction layer
+ \li GraphicsInfo.MetalRhi - Metal on top of QRhi, a graphics abstraction layer
+ \li GraphicsInfo.NullRhi - Null (no output) on top of QRhi, a graphics abstraction layer
\endlist
*/
@@ -109,6 +115,7 @@ QQuickGraphicsInfo *QQuickGraphicsInfo::qmlAttachedProperties(QObject *object)
\li GraphicsInfo.UnknownShadingLanguage - Not yet known due to no window and scenegraph associated
\li GraphicsInfo.GLSL - GLSL or GLSL ES
\li GraphicsInfo.HLSL - HLSL
+ \li GraphicsInfo.RhiShader - QShader
\endlist
\note The value is only up-to-date once the item is associated with a
diff --git a/src/quick/items/qquickgraphicsinfo_p.h b/src/quick/items/qquickgraphicsinfo_p.h
index 9ef7bacb3e..f0a18c29cc 100644
--- a/src/quick/items/qquickgraphicsinfo_p.h
+++ b/src/quick/items/qquickgraphicsinfo_p.h
@@ -80,14 +80,21 @@ public:
Unknown = QSGRendererInterface::Unknown,
Software = QSGRendererInterface::Software,
OpenGL = QSGRendererInterface::OpenGL,
- Direct3D12 = QSGRendererInterface::Direct3D12
+ Direct3D12 = QSGRendererInterface::Direct3D12,
+ OpenVG = QSGRendererInterface::OpenVG,
+ OpenGLRhi = QSGRendererInterface::OpenGLRhi,
+ Direct3D11Rhi = QSGRendererInterface::Direct3D11Rhi,
+ VulkanRhi = QSGRendererInterface::VulkanRhi,
+ MetalRhi = QSGRendererInterface::MetalRhi,
+ NullRhi = QSGRendererInterface::NullRhi
};
Q_ENUM(GraphicsApi)
enum ShaderType {
UnknownShadingLanguage = QSGRendererInterface::UnknownShadingLanguage,
GLSL = QSGRendererInterface::GLSL,
- HLSL = QSGRendererInterface::HLSL
+ HLSL = QSGRendererInterface::HLSL,
+ RhiShader = QSGRendererInterface::RhiShader
};
Q_ENUM(ShaderType)
diff --git a/src/quick/items/qquickimage.cpp b/src/quick/items/qquickimage.cpp
index 16343774e2..840cfe15da 100644
--- a/src/quick/items/qquickimage.cpp
+++ b/src/quick/items/qquickimage.cpp
@@ -663,7 +663,7 @@ QSGNode *QQuickImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
QSGInternalImageNode *node = static_cast<QSGInternalImageNode *>(oldNode);
if (!node) {
d->pixmapChanged = true;
- node = d->sceneGraphContext()->createInternalImageNode();
+ node = d->sceneGraphContext()->createInternalImageNode(d->sceneGraphRenderContext());
}
QRectF targetRect;
@@ -687,7 +687,6 @@ QSGNode *QQuickImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
yOffset = qCeil(height() - pixHeight);
switch (d->fillMode) {
- default:
case Stretch:
targetRect = QRectF(0, 0, width(), height());
sourceRect = d->pix.rect();
@@ -699,7 +698,7 @@ QSGNode *QQuickImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
break;
case PreserveAspectCrop: {
- targetRect = QRect(0, 0, width(), height());
+ targetRect = QRectF(0, 0, width(), height());
qreal wscale = width() / qreal(d->pix.width());
qreal hscale = height() / qreal(d->pix.height());
@@ -751,7 +750,7 @@ QSGNode *QQuickImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
targetRect = QRectF(x + xOffset, y + yOffset, w, h);
sourceRect = QRectF(x, y, w, h);
break;
- };
+ }
qreal nsWidth = (hWrap == QSGTexture::Repeat || d->fillMode == Pad) ? d->pix.width() / d->devicePixelRatio : d->pix.width();
qreal nsHeight = (vWrap == QSGTexture::Repeat || d->fillMode == Pad) ? d->pix.height() / d->devicePixelRatio : d->pix.height();
@@ -889,4 +888,16 @@ void QQuickImage::setMipmap(bool use)
By default, this property is set to false.
*/
+/*!
+ \qmlproperty int QtQuick::Image::currentFrame
+ \qmlproperty int QtQuick::Image::frameCount
+ \since 5.14
+
+ currentFrame is the frame that is currently visible. The default is \c 0.
+ You can set it to a number between \c 0 and \c {frameCount - 1} to display a
+ different frame, if the image contains multiple frames.
+
+ frameCount is the number of frames in the image. Most images have only one frame.
+*/
+
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickimage_p.h b/src/quick/items/qquickimage_p.h
index 7fb4413900..257cde5313 100644
--- a/src/quick/items/qquickimage_p.h
+++ b/src/quick/items/qquickimage_p.h
@@ -66,8 +66,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickImage : public QQuickImageBase
Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedGeometryChanged)
Q_PROPERTY(HAlignment horizontalAlignment READ horizontalAlignment WRITE setHorizontalAlignment NOTIFY horizontalAlignmentChanged)
Q_PROPERTY(VAlignment verticalAlignment READ verticalAlignment WRITE setVerticalAlignment NOTIFY verticalAlignmentChanged)
- Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged REVISION 1)
- Q_PROPERTY(bool autoTransform READ autoTransform WRITE setAutoTransform NOTIFY autoTransformChanged REVISION 2)
+ Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged REVISION 3)
+ Q_PROPERTY(bool autoTransform READ autoTransform WRITE setAutoTransform NOTIFY autoTransformChanged REVISION 5)
public:
QQuickImage(QQuickItem *parent=nullptr);
@@ -112,8 +112,8 @@ Q_SIGNALS:
void paintedGeometryChanged();
void horizontalAlignmentChanged(HAlignment alignment);
void verticalAlignmentChanged(VAlignment alignment);
- Q_REVISION(1) void mipmapChanged(bool);
- Q_REVISION(2) void autoTransformChanged();
+ Q_REVISION(3) void mipmapChanged(bool);
+ Q_REVISION(5) void autoTransformChanged();
private Q_SLOTS:
void invalidateSceneGraph();
diff --git a/src/quick/items/qquickimagebase.cpp b/src/quick/items/qquickimagebase.cpp
index 74ee859f77..8bab14bfd1 100644
--- a/src/quick/items/qquickimagebase.cpp
+++ b/src/quick/items/qquickimagebase.cpp
@@ -46,6 +46,8 @@
#include <QtQml/qqmlinfo.h>
#include <QtQml/qqmlfile.h>
+#include <QtQml/qqmlabstracturlinterceptor.h>
+
QT_BEGIN_NAMESPACE
@@ -53,7 +55,7 @@ QT_BEGIN_NAMESPACE
// if they're not happy with our implementation of it.
bool QQuickImageBasePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio)
{
- // QQuickImageProvider and SVG can generate a high resolution image when
+ // QQuickImageProvider and SVG and PDF can generate a high resolution image when
// sourceSize is set (this function is only called if it's set).
// If sourceSize is not set then the provider default size will be used, as usual.
bool setDevicePixelRatio = false;
@@ -62,7 +64,8 @@ bool QQuickImageBasePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio
} else {
QString stringUrl = url.path(QUrl::PrettyDecoded);
if (stringUrl.endsWith(QLatin1String("svg")) ||
- stringUrl.endsWith(QLatin1String("svgz"))) {
+ stringUrl.endsWith(QLatin1String("svgz")) ||
+ stringUrl.endsWith(QLatin1String("pdf"))) {
setDevicePixelRatio = true;
}
}
@@ -208,6 +211,36 @@ bool QQuickImageBase::mirror() const
return d->mirror;
}
+void QQuickImageBase::setCurrentFrame(int frame)
+{
+ Q_D(QQuickImageBase);
+ if (frame == d->currentFrame || frame < 0 || (isComponentComplete() && frame >= d->pix.frameCount()))
+ return;
+
+ d->currentFrame = frame;
+
+ if (isComponentComplete()) {
+ if (frame > 0)
+ d->cache = false;
+ load();
+ update();
+ }
+
+ emit currentFrameChanged();
+}
+
+int QQuickImageBase::currentFrame() const
+{
+ Q_D(const QQuickImageBase);
+ return d->currentFrame;
+}
+
+int QQuickImageBase::frameCount() const
+{
+ Q_D(const QQuickImageBase);
+ return d->frameCount;
+}
+
void QQuickImageBase::load()
{
Q_D(QQuickImageBase);
@@ -244,6 +277,9 @@ void QQuickImageBase::load()
d->devicePixelRatio = 1.0;
QUrl loadUrl = d->url;
+ QQmlEngine* engine = qmlEngine(this);
+ if (engine && engine->urlInterceptor())
+ loadUrl = engine->urlInterceptor()->intercept(loadUrl, QQmlAbstractUrlInterceptor::UrlString);
bool updatedDevicePixelRatio = false;
if (d->sourcesize.isValid())
@@ -255,7 +291,7 @@ void QQuickImageBase::load()
resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio);
}
- d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, d->providerOptions);
+ d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, d->providerOptions, d->currentFrame, d->frameCount);
if (d->pix.isLoading()) {
if (d->progress != 0.0) {
@@ -314,6 +350,11 @@ void QQuickImageBase::requestFinished()
d->oldAutoTransform = autoTransform();
emitAutoTransformBaseChanged();
}
+ if (d->frameCount != d->pix.frameCount()) {
+ d->frameCount = d->pix.frameCount();
+ emit frameCountChanged();
+ }
+
update();
}
diff --git a/src/quick/items/qquickimagebase_p.h b/src/quick/items/qquickimagebase_p.h
index d8d0be9b8c..8cd59c8cea 100644
--- a/src/quick/items/qquickimagebase_p.h
+++ b/src/quick/items/qquickimagebase_p.h
@@ -68,6 +68,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickImageBase : public QQuickImplicitSizeItem
Q_PROPERTY(bool cache READ cache WRITE setCache NOTIFY cacheChanged)
Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize RESET resetSourceSize NOTIFY sourceSizeChanged)
Q_PROPERTY(bool mirror READ mirror WRITE setMirror NOTIFY mirrorChanged)
+ Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY currentFrameChanged REVISION 14)
+ Q_PROPERTY(int frameCount READ frameCount NOTIFY frameCountChanged REVISION 14)
public:
QQuickImageBase(QQuickItem *parent=nullptr);
@@ -95,6 +97,11 @@ public:
virtual void setMirror(bool mirror);
bool mirror() const;
+ virtual void setCurrentFrame(int frame);
+ virtual int currentFrame() const;
+
+ virtual int frameCount() const;
+
virtual void setAutoTransform(bool transform);
bool autoTransform() const;
@@ -112,6 +119,8 @@ Q_SIGNALS:
void asynchronousChanged();
void cacheChanged();
void mirrorChanged();
+ Q_REVISION(14) void currentFrameChanged();
+ Q_REVISION(14) void frameCountChanged();
protected:
virtual void load();
diff --git a/src/quick/items/qquickimagebase_p_p.h b/src/quick/items/qquickimagebase_p_p.h
index 1b771166a2..88e18ba32e 100644
--- a/src/quick/items/qquickimagebase_p_p.h
+++ b/src/quick/items/qquickimagebase_p_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -68,6 +68,8 @@ public:
: status(QQuickImageBase::Null),
progress(0.0),
devicePixelRatio(1.0),
+ currentFrame(0),
+ frameCount(0),
async(false),
cache(true),
mirror(false),
@@ -85,6 +87,8 @@ public:
QSize oldSourceSize;
qreal devicePixelRatio;
QQuickImageProviderOptions providerOptions;
+ int currentFrame;
+ int frameCount;
bool async : 1;
bool cache : 1;
bool mirror: 1;
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index d90cc71997..4c20b7e2e1 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -4177,7 +4177,7 @@ void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
Q_UNUSED(event);
}
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
/*!
This event handler can be reimplemented in a subclass to receive drag-enter
events for an item. The event information is provided by the
@@ -4245,7 +4245,7 @@ void QQuickItem::dropEvent(QDropEvent *event)
{
Q_UNUSED(event);
}
-#endif // draganddrop
+#endif // quick_draganddrop
/*!
Reimplement this method to filter the mouse events that are received by
@@ -5097,7 +5097,7 @@ QQuickStateGroup *QQuickItemPrivate::_states()
if (!componentComplete)
_stateGroup->classBegin();
qmlobject_connect(_stateGroup, QQuickStateGroup, SIGNAL(stateChanged(QString)),
- q, QQuickItem, SIGNAL(stateChanged(QString)))
+ q, QQuickItem, SIGNAL(stateChanged(QString)));
}
return _stateGroup;
@@ -5136,6 +5136,40 @@ void QQuickItemPrivate::transformChanged()
#endif
}
+QPointF QQuickItemPrivate::adjustedPosForTransform(const QPointF &centroidParentPos,
+ const QPointF &startPos,
+ const QVector2D &activeTranslation, //[0,0] means no additional translation from startPos
+ qreal startScale,
+ qreal activeScale, // 1.0 means no additional scale from startScale
+ qreal startRotation,
+ qreal activeRotation) // 0.0 means no additional rotation from startRotation
+{
+ Q_Q(QQuickItem);
+ QVector3D xformOrigin(q->transformOriginPoint());
+ QMatrix4x4 startMatrix;
+ startMatrix.translate(float(startPos.x()), float(startPos.y()));
+ startMatrix.translate(xformOrigin);
+ startMatrix.scale(float(startScale));
+ startMatrix.rotate(float(startRotation), 0, 0, -1);
+ startMatrix.translate(-xformOrigin);
+
+ const QVector3D centroidParentVector(centroidParentPos);
+ QMatrix4x4 mat;
+ mat.translate(centroidParentVector);
+ mat.rotate(float(activeRotation), 0, 0, 1);
+ mat.scale(float(activeScale));
+ mat.translate(-centroidParentVector);
+ mat.translate(QVector3D(activeTranslation));
+
+ mat = mat * startMatrix;
+
+ QPointF xformOriginPoint = q->transformOriginPoint();
+ QPointF pos = mat * xformOriginPoint;
+ pos -= xformOriginPoint;
+
+ return pos;
+}
+
bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e, bool post)
{
if (!extra.isAllocated() || !extra->keyHandler)
@@ -5666,6 +5700,7 @@ void QQuickItem::setRotation(qreal r)
color: "red"
x: 25; y: 25; width: 50; height: 50
scale: 1.4
+ transformOrigin: Item.TopLeft
}
}
\endqml
@@ -8098,7 +8133,7 @@ bool QQuickItem::event(QEvent *ev)
wheelEvent(static_cast<QWheelEvent*>(ev));
break;
#endif
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
case QEvent::DragEnter:
dragEnterEvent(static_cast<QDragEnterEvent*>(ev));
break;
@@ -8111,7 +8146,7 @@ bool QQuickItem::event(QEvent *ev)
case QEvent::Drop:
dropEvent(static_cast<QDropEvent*>(ev));
break;
-#endif // draganddrop
+#endif // quick_draganddrop
#if QT_CONFIG(gestures)
case QEvent::NativeGesture:
ev->ignore();
@@ -8373,7 +8408,7 @@ void QQuickItemLayer::activateEffect()
m_effect->stackAfter(m_effectSource);
}
m_effect->setVisible(m_item->isVisible());
- m_effect->setProperty(m_name, qVariantFromValue<QObject *>(m_effectSource));
+ m_effect->setProperty(m_name, QVariant::fromValue<QObject *>(m_effectSource));
QQuickItemPrivate::get(m_effect)->setTransparentForPositioner(true);
m_effectComponent->completeCreate();
}
@@ -8513,7 +8548,11 @@ void QQuickItemLayer::setSourceRect(const QRectF &sourceRect)
/*!
\qmlproperty bool QtQuick::Item::layer.smooth
- Holds whether the layer is smoothly transformed.
+ Holds whether the layer is smoothly transformed. When enabled, sampling the
+ layer's texture is performed using \c linear interpolation, while
+ non-smooth results in using the \c nearest filtering mode.
+
+ By default, this property is set to \c false.
\sa {Item Layers}
*/
@@ -8670,7 +8709,7 @@ void QQuickItemLayer::setName(const QByteArray &name) {
return;
if (m_effect) {
m_effect->setProperty(m_name, QVariant());
- m_effect->setProperty(name, qVariantFromValue<QObject *>(m_effectSource));
+ m_effect->setProperty(name, QVariant::fromValue<QObject *>(m_effectSource));
}
m_name = name;
emit nameChanged(name);
diff --git a/src/quick/items/qquickitem.h b/src/quick/items/qquickitem.h
index 6f601e0872..394a5adb8c 100644
--- a/src/quick/items/qquickitem.h
+++ b/src/quick/items/qquickitem.h
@@ -318,7 +318,7 @@ public:
void setKeepTouchGrab(bool);
// implemented in qquickitemgrabresult.cpp
- Q_REVISION(2) Q_INVOKABLE bool grabToImage(const QJSValue &callback, const QSize &targetSize = QSize());
+ Q_REVISION(4) Q_INVOKABLE bool grabToImage(const QJSValue &callback, const QSize &targetSize = QSize());
QSharedPointer<QQuickItemGrabResult> grabToImage(const QSize &targetSize = QSize());
Q_INVOKABLE virtual bool contains(const QPointF &point) const;
@@ -433,7 +433,7 @@ protected:
virtual void hoverEnterEvent(QHoverEvent *event);
virtual void hoverMoveEvent(QHoverEvent *event);
virtual void hoverLeaveEvent(QHoverEvent *event);
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
virtual void dragEnterEvent(QDragEnterEvent *);
virtual void dragMoveEvent(QDragMoveEvent *);
virtual void dragLeaveEvent(QDragLeaveEvent *);
diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h
index f618bcf1c3..3e8feec4bf 100644
--- a/src/quick/items/qquickitem_p.h
+++ b/src/quick/items/qquickitem_p.h
@@ -592,6 +592,11 @@ public:
QPointF computeTransformOrigin() const;
virtual void transformChanged();
+ QPointF adjustedPosForTransform(const QPointF &centroid,
+ const QPointF &startPos, const QVector2D &activeTranslatation,
+ qreal startScale, qreal activeScale,
+ qreal startRotation, qreal activeRotation);
+
void deliverKeyEvent(QKeyEvent *);
bool filterKeyEvent(QKeyEvent *, bool post);
#if QT_CONFIG(im)
diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp
index 77bcf2583c..7bc6eefe0a 100644
--- a/src/quick/items/qquickitemsmodule.cpp
+++ b/src/quick/items/qquickitemsmodule.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -110,10 +110,11 @@
#include "qquickshadereffect_p.h"
#include "qquickshadereffectmesh_p.h"
#endif
+#if QT_CONFIG(quick_draganddrop)
#include "qquickdrag_p.h"
#include "qquickdroparea_p.h"
+#endif
#include "qquickmultipointtoucharea_p.h"
-#include <private/qqmlmetatype_p.h>
#include <QtQuick/private/qquickaccessibleattached_p.h>
#include "handlers/qquickdraghandler_p.h"
@@ -121,6 +122,7 @@
#include "handlers/qquickpinchhandler_p.h"
#include "handlers/qquickpointhandler_p.h"
#include "handlers/qquicktaphandler_p.h"
+#include "handlers/qquickwheelhandler_p.h"
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(lcTransient)
@@ -224,6 +226,9 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickPathCatmullRomCurve>("QtQuick",2,0,"PathCurve");
qmlRegisterType<QQuickPathArc>("QtQuick",2,0,"PathArc");
qmlRegisterType<QQuickPathSvg>("QtQuick",2,0,"PathSvg");
+ qmlRegisterType<QQuickPath, 14>(uri, 2, 14, "Path");
+ qmlRegisterType<QQuickPathPolyline>("QtQuick", 2, 14, "PathPolyline");
+ qmlRegisterType<QQuickPathMultiline>("QtQuick", 2, 14, "PathMultiline");
#endif
#if QT_CONFIG(quick_pathview)
qmlRegisterType<QQuickPathView>(uri,major,minor,"PathView");
@@ -241,28 +246,28 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickTextEdit,1>(uri,2,1,"TextEdit");
qmlRegisterType<QQuickTextInput>(uri,major,minor,"TextInput");
qmlRegisterType<QQuickTextInput,2>(uri,2,2,"TextInput");
- qmlRegisterType<QQuickTextInput,3>(uri,2,4,"TextInput");
- qmlRegisterType<QQuickItemGrabResult>();
+ qmlRegisterType<QQuickTextInput,4>(uri,2,4,"TextInput");
+ qmlRegisterAnonymousType<QQuickItemGrabResult>(uri, major);
#if QT_CONFIG(quick_shadereffect)
- qmlRegisterType<QQuickItemLayer>();
-#endif
- qmlRegisterType<QQuickAnchors>();
- qmlRegisterType<QQuickKeyEvent>();
- qmlRegisterType<QQuickMouseEvent>();
- qmlRegisterType<QQuickWheelEvent>();
- qmlRegisterType<QQuickCloseEvent>();
- qmlRegisterType<QQuickTransform>();
+ qmlRegisterAnonymousType<QQuickItemLayer>(uri, major);
+#endif
+ qmlRegisterAnonymousType<QQuickAnchors>(uri, major);
+ qmlRegisterAnonymousType<QQuickKeyEvent>(uri, major);
+ qmlRegisterAnonymousType<QQuickMouseEvent>(uri, major);
+ qmlRegisterAnonymousType<QQuickWheelEvent>(uri, major);
+ qmlRegisterAnonymousType<QQuickCloseEvent>(uri, major);
+ qmlRegisterAnonymousType<QQuickTransform>(uri, major);
#if QT_CONFIG(quick_path)
- qmlRegisterType<QQuickPathElement>();
- qmlRegisterType<QQuickCurve>();
+ qmlRegisterAnonymousType<QQuickPathElement>(uri, major);
+ qmlRegisterAnonymousType<QQuickCurve>(uri, major);
#endif
- qmlRegisterType<QQuickScaleGrid>();
- qmlRegisterType<QQuickTextLine>();
- qmlRegisterType<QQuickPen>();
- qmlRegisterType<QQuickFlickableVisibleArea>();
+ qmlRegisterAnonymousType<QQuickScaleGrid>(uri, major);
+ qmlRegisterAnonymousType<QQuickTextLine>(uri, major);
+ qmlRegisterAnonymousType<QQuickPen>(uri, major);
+ qmlRegisterAnonymousType<QQuickFlickableVisibleArea>(uri, major);
qRegisterMetaType<QQuickAnchorLine>("QQuickAnchorLine");
- qmlRegisterType<QQuickTextDocument>();
+ qmlRegisterAnonymousType<QQuickTextDocument>(uri, major);
qmlRegisterUncreatableType<QQuickKeyNavigationAttached>(uri,major,minor,"KeyNavigation",QQuickKeyNavigationAttached::tr("KeyNavigation is only available via attached properties"));
@@ -274,7 +279,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickPinchArea>(uri,major,minor,"PinchArea");
qmlRegisterType<QQuickPinch>(uri,major,minor,"Pinch");
- qmlRegisterType<QQuickPinchEvent>();
+ qmlRegisterAnonymousType<QQuickPinchEvent>(uri, major);
#if QT_CONFIG(quick_shadereffect)
qmlRegisterType<QQuickShaderEffectSource>("QtQuick", 2, 0, "ShaderEffectSource");
@@ -297,7 +302,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickParentChange>(uri, major, minor,"ParentChange");
qmlRegisterType<QQuickAnchorChanges>(uri, major, minor,"AnchorChanges");
- qmlRegisterType<QQuickAnchorSet>();
+ qmlRegisterAnonymousType<QQuickAnchorSet>(uri, major);
qmlRegisterType<QQuickAnchorAnimation>(uri, major, minor,"AnchorAnimation");
qmlRegisterType<QQuickParentAnimation>(uri, major, minor,"ParentAnimation");
#if QT_CONFIG(quick_path)
@@ -305,10 +310,10 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickPathInterpolator>("QtQuick",2,0,"PathInterpolator");
#endif
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
qmlRegisterType<QQuickDropArea>("QtQuick", 2, 0, "DropArea");
- qmlRegisterType<QQuickDropEvent>();
- qmlRegisterType<QQuickDropAreaDrag>();
+ qmlRegisterAnonymousType<QQuickDropEvent>(uri, 2);
+ qmlRegisterAnonymousType<QQuickDropAreaDrag>(uri, 2);
qmlRegisterUncreatableType<QQuickDrag>("QtQuick", 2, 0, "Drag", QQuickDragAttached::tr("Drag is only available via attached properties"));
#endif
@@ -329,7 +334,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
const char *itemViewName = "ItemView";
const QString itemViewMessage = QQuickItemView::tr("ItemView is an abstract base class");
qmlRegisterUncreatableType<QQuickItemView, 1>(uri, 2, 1, itemViewName, itemViewMessage);
- qmlRegisterUncreatableType<QQuickItemView, 2>(uri, 2, 3, itemViewName, itemViewMessage);
+ qmlRegisterUncreatableType<QQuickItemView, 3>(uri, 2, 3, itemViewName, itemViewMessage);
#endif
#if QT_CONFIG(quick_listview)
qmlRegisterType<QQuickListView, 1>(uri, 2, 1, "ListView");
@@ -344,23 +349,23 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickText, 3>(uri, 2, 3, "Text");
qmlRegisterType<QQuickTextEdit, 3>(uri, 2, 3, "TextEdit");
- qmlRegisterType<QQuickImage, 1>(uri, 2, 3,"Image");
+ qmlRegisterType<QQuickImage, 3>(uri, 2, 3,"Image");
- qmlRegisterType<QQuickItem, 2>(uri, 2, 4, "Item");
+ qmlRegisterType<QQuickItem, 4>(uri, 2, 4, "Item");
#if QT_CONFIG(quick_listview)
- qmlRegisterType<QQuickListView, 2>(uri, 2, 4, "ListView");
+ qmlRegisterType<QQuickListView, 4>(uri, 2, 4, "ListView");
#endif
- qmlRegisterType<QQuickMouseArea, 1>(uri, 2, 4, "MouseArea");
+ qmlRegisterType<QQuickMouseArea, 4>(uri, 2, 4, "MouseArea");
#if QT_CONFIG(quick_shadereffect)
- qmlRegisterType<QQuickShaderEffect, 1>(uri, 2, 4, "ShaderEffect");
+ qmlRegisterType<QQuickShaderEffect, 4>(uri, 2, 4, "ShaderEffect");
#endif
#if QT_CONFIG(opengl)
qmlRegisterUncreatableType<QQuickOpenGLInfo>(uri, 2, 4,"OpenGLInfo", QQuickOpenGLInfo::tr("OpenGLInfo is only available via attached properties"));
#endif
- qmlRegisterType<QQuickPinchArea, 1>(uri, 2, 5,"PinchArea");
- qmlRegisterType<QQuickImage, 2>(uri, 2, 5,"Image");
- qmlRegisterType<QQuickMouseArea, 2>(uri, 2, 5, "MouseArea");
+ qmlRegisterType<QQuickPinchArea, 5>(uri, 2, 5,"PinchArea");
+ qmlRegisterType<QQuickImage, 5>(uri, 2, 5,"Image");
+ qmlRegisterType<QQuickMouseArea, 5>(uri, 2, 5, "MouseArea");
qmlRegisterType<QQuickText, 6>(uri, 2, 6, "Text");
qmlRegisterType<QQuickTextEdit, 6>(uri, 2, 6, "TextEdit");
@@ -376,7 +381,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterUncreatableType<QQuickEnterKeyAttached, 6>(uri, 2, 6, "EnterKey",
QQuickEnterKeyAttached::tr("EnterKey is only available via attached properties"));
#if QT_CONFIG(quick_shadereffect)
- qmlRegisterType<QQuickShaderEffectSource, 1>(uri, 2, 6, "ShaderEffectSource");
+ qmlRegisterType<QQuickShaderEffectSource, 6>(uri, 2, 6, "ShaderEffectSource");
#endif
qmlRegisterType<QQuickItem, 7>(uri, 2, 7, "Item");
@@ -406,7 +411,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickMouseArea, 9>(uri, 2, 9, "MouseArea");
#if QT_CONFIG(quick_path)
- qmlRegisterType<QQuickPathArc, 2>(uri, 2, 9, "PathArc");
+ qmlRegisterType<QQuickPathArc, 9>(uri, 2, 9, "PathArc");
qmlRegisterType<QQuickPathMove>(uri, 2, 9, "PathMove");
#endif
@@ -421,7 +426,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
#endif
#if QT_CONFIG(quick_shadereffect)
- qmlRegisterType<QQuickShaderEffectSource, 2>(uri, 2, 9, "ShaderEffectSource");
+ qmlRegisterType<QQuickShaderEffectSource, 9>(uri, 2, 9, "ShaderEffectSource");
#endif
qmlRegisterType<QQuickFlickable, 10>(uri, 2, 10, "Flickable");
@@ -475,9 +480,25 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickTableView>(uri, 2, 12, "TableView");
#endif
+#if QT_CONFIG(quick_itemview)
qmlRegisterUncreatableType<QQuickItemView, 13>(uri, 2, 13, itemViewName, itemViewMessage);
+#endif
+#if QT_CONFIG(quick_pathview)
qmlRegisterType<QQuickPathView, 13>(uri, 2, 13, "PathView");
+#endif
+#if QT_CONFIG(quick_gridview)
qmlRegisterType<QQuickGridView, 13>(uri, 2, 13, "GridView");
+#endif
+#if QT_CONFIG(quick_tableview)
+ qmlRegisterType<QQuickTableView, 14>(uri, 2, 14, "TableView");
+#endif
+#if QT_CONFIG(wheelevent)
+ qmlRegisterType<QQuickWheelHandler>(uri, 2, 14, "WheelHandler");
+#endif
+ qmlRegisterUncreatableType<QQuickImageBase, 14>(uri, 2, 14, "ImageBase",
+ QQuickPointerHandler::tr("ImageBase is an abstract base class"));
+ qmlRegisterType<QQuickImage, 14>(uri, 2, 14, "Image");
+ qmlRegisterType<QQuickDragHandler, 14>(uri, 2, 14, "DragHandler");
}
static void initResources()
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp
index 120eeb13d5..661f19509a 100644
--- a/src/quick/items/qquickitemview.cpp
+++ b/src/quick/items/qquickitemview.cpp
@@ -247,6 +247,8 @@ void QQuickItemView::setModel(const QVariant &m)
connect(d->model, SIGNAL(modelUpdated(QQmlChangeSet,bool)),
this, SLOT(modelUpdated(QQmlChangeSet,bool)));
+ if (QQmlDelegateModel *dataModel = qobject_cast<QQmlDelegateModel*>(d->model))
+ QObjectPrivate::connect(dataModel, &QQmlDelegateModel::delegateChanged, d, &QQuickItemViewPrivate::applyDelegateChange);
emit countChanged();
}
emit modelChanged();
@@ -277,22 +279,8 @@ void QQuickItemView::setDelegate(QQmlComponent *delegate)
if (QQmlDelegateModel *dataModel = qobject_cast<QQmlDelegateModel*>(d->model)) {
int oldCount = dataModel->count();
dataModel->setDelegate(delegate);
- if (isComponentComplete()) {
- d->releaseVisibleItems();
- d->releaseItem(d->currentItem);
- d->currentItem = nullptr;
- d->updateSectionCriteria();
- d->refill();
- d->moveReason = QQuickItemViewPrivate::SetIndex;
- d->updateCurrent(d->currentIndex);
- if (d->highlight && d->currentItem) {
- if (d->autoHighlight)
- d->resetHighlightPosition();
- d->updateTrackedItem();
- }
- d->moveReason = QQuickItemViewPrivate::Other;
- d->updateViewport();
- }
+ if (isComponentComplete())
+ d->applyDelegateChange();
if (oldCount != dataModel->count())
emit countChanged();
}
@@ -1098,6 +1086,24 @@ qreal QQuickItemViewPrivate::calculatedMaxExtent() const
return maxExtent;
}
+void QQuickItemViewPrivate::applyDelegateChange()
+{
+ releaseVisibleItems();
+ releaseItem(currentItem);
+ currentItem = nullptr;
+ updateSectionCriteria();
+ refill();
+ moveReason = QQuickItemViewPrivate::SetIndex;
+ updateCurrent(currentIndex);
+ if (highlight && currentItem) {
+ if (autoHighlight)
+ resetHighlightPosition();
+ updateTrackedItem();
+ }
+ moveReason = QQuickItemViewPrivate::Other;
+ updateViewport();
+}
+
// for debugging only
void QQuickItemViewPrivate::checkVisible() const
{
diff --git a/src/quick/items/qquickitemview_p.h b/src/quick/items/qquickitemview_p.h
index 0a0da587b4..66e09f9ed1 100644
--- a/src/quick/items/qquickitemview_p.h
+++ b/src/quick/items/qquickitemview_p.h
@@ -81,8 +81,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickItemView : public QQuickFlickable
Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged)
Q_PROPERTY(bool keyNavigationEnabled READ isKeyNavigationEnabled WRITE setKeyNavigationEnabled NOTIFY keyNavigationEnabledChanged REVISION 7)
Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
- Q_PROPERTY(int displayMarginBeginning READ displayMarginBeginning WRITE setDisplayMarginBeginning NOTIFY displayMarginBeginningChanged REVISION 2)
- Q_PROPERTY(int displayMarginEnd READ displayMarginEnd WRITE setDisplayMarginEnd NOTIFY displayMarginEndChanged REVISION 2)
+ Q_PROPERTY(int displayMarginBeginning READ displayMarginBeginning WRITE setDisplayMarginBeginning NOTIFY displayMarginBeginningChanged REVISION 3)
+ Q_PROPERTY(int displayMarginEnd READ displayMarginEnd WRITE setDisplayMarginEnd NOTIFY displayMarginEndChanged REVISION 3)
Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged)
Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged)
diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h
index 1f42c847b3..6442fee27d 100644
--- a/src/quick/items/qquickitemview_p_p.h
+++ b/src/quick/items/qquickitemview_p_p.h
@@ -59,9 +59,9 @@ QT_REQUIRE_CONFIG(quick_itemview);
#include "qquickitemviewfxitem_p_p.h"
#include "qquickitemviewtransition_p.h"
#include "qquickflickable_p_p.h"
-#include <QtQml/private/qqmlobjectmodel_p.h>
-#include <QtQml/private/qqmldelegatemodel_p.h>
-#include <QtQml/private/qqmlchangeset_p.h>
+#include <QtQmlModels/private/qqmlobjectmodel_p.h>
+#include <QtQmlModels/private/qqmldelegatemodel_p.h>
+#include <QtQmlModels/private/qqmlchangeset_p.h>
QT_BEGIN_NAMESPACE
@@ -191,6 +191,8 @@ public:
qreal calculatedMinExtent() const;
qreal calculatedMaxExtent() const;
+ void applyDelegateChange();
+
void applyPendingChanges();
bool applyModelChanges(ChangeResult *insertionResult, ChangeResult *removalResult);
bool applyRemovalChange(const QQmlChangeSet::Change &removal, ChangeResult *changeResult, int *removedCount);
diff --git a/src/quick/items/qquicklistview_p.h b/src/quick/items/qquicklistview_p.h
index 9a9b325b1e..f2bab9e018 100644
--- a/src/quick/items/qquicklistview_p.h
+++ b/src/quick/items/qquicklistview_p.h
@@ -126,8 +126,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickListView : public QQuickItemView
Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
- Q_PROPERTY(HeaderPositioning headerPositioning READ headerPositioning WRITE setHeaderPositioning NOTIFY headerPositioningChanged REVISION 2)
- Q_PROPERTY(FooterPositioning footerPositioning READ footerPositioning WRITE setFooterPositioning NOTIFY footerPositioningChanged REVISION 2)
+ Q_PROPERTY(HeaderPositioning headerPositioning READ headerPositioning WRITE setHeaderPositioning NOTIFY headerPositioningChanged REVISION 4)
+ Q_PROPERTY(FooterPositioning footerPositioning READ footerPositioning WRITE setFooterPositioning NOTIFY footerPositioningChanged REVISION 4)
Q_CLASSINFO("DefaultProperty", "data")
@@ -188,8 +188,8 @@ Q_SIGNALS:
void highlightResizeVelocityChanged();
void highlightResizeDurationChanged();
void snapModeChanged();
- Q_REVISION(2) void headerPositioningChanged();
- Q_REVISION(2) void footerPositioningChanged();
+ Q_REVISION(4) void headerPositioningChanged();
+ Q_REVISION(4) void footerPositioningChanged();
protected:
void viewportMoved(Qt::Orientations orient) override;
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp
index 4bee4864d5..ddf34798d7 100644
--- a/src/quick/items/qquickmousearea.cpp
+++ b/src/quick/items/qquickmousearea.cpp
@@ -40,7 +40,9 @@
#include "qquickmousearea_p.h"
#include "qquickmousearea_p_p.h"
#include "qquickwindow.h"
+#if QT_CONFIG(quick_draganddrop)
#include "qquickdrag_p.h"
+#endif
#include <private/qqmldata_p.h>
#include <private/qsgadaptationlayer_p.h>
@@ -62,7 +64,7 @@ QQuickMouseAreaPrivate::QQuickMouseAreaPrivate()
moved(false), stealMouse(false), doubleClick(false), preventStealing(false),
propagateComposedEvents(false), overThreshold(false), pressed(nullptr),
pressAndHoldInterval(-1)
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
, drag(nullptr)
#endif
#if QT_CONFIG(cursor)
@@ -73,7 +75,7 @@ QQuickMouseAreaPrivate::QQuickMouseAreaPrivate()
QQuickMouseAreaPrivate::~QQuickMouseAreaPrivate()
{
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
delete drag;
#endif
#if QT_CONFIG(cursor)
@@ -685,7 +687,7 @@ void QQuickMouseArea::mousePressEvent(QMouseEvent *event)
} else {
d->longPress = false;
d->saveEvent(event);
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
if (d->drag)
d->drag->setActive(false);
#endif
@@ -712,7 +714,7 @@ void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event)
// ### can GV handle this for us?
setHovered(contains(d->lastPos));
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
if (d->drag && d->drag->target()) {
if (!d->moved) {
d->targetStartPos = d->drag->target()->parentItem()
@@ -759,8 +761,10 @@ void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event)
QPointF targetPos = d->drag->target()->position();
- if (d->drag->active())
+ if (d->drag->active()) {
d->drag->target()->setPosition(boundedDragPos);
+ d->lastPos = d->lastScenePos - mapToScene(position());
+ }
bool dragOverThresholdX = QQuickWindowPrivate::dragOverThreshold(dragPos.x() - startPos.x(),
Qt::XAxis, event, d->drag->threshold());
@@ -806,7 +810,7 @@ void QQuickMouseArea::mouseReleaseEvent(QMouseEvent *event)
setPressed(event->button(), false, event->source());
if (!d->pressed) {
// no other buttons are pressed
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
if (d->drag)
d->drag->setActive(false);
#endif
@@ -895,7 +899,7 @@ void QQuickMouseArea::wheelEvent(QWheelEvent *event)
}
QQuickWheelEvent &we = d->quickWheelEvent;
- we.reset(event->posF().x(), event->posF().y(), event->angleDelta(), event->pixelDelta(),
+ we.reset(event->position().x(), event->position().y(), event->angleDelta(), event->pixelDelta(),
event->buttons(), event->modifiers(), event->inverted());
we.setAccepted(d->isWheelConnected());
emit wheel(&we);
@@ -916,7 +920,7 @@ void QQuickMouseArea::ungrabMouse()
d->overThreshold = false;
setKeepMouseGrab(false);
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
if (d->drag)
d->drag->setActive(false);
#endif
@@ -999,7 +1003,7 @@ bool QQuickMouseArea::childMouseEventFilter(QQuickItem *i, QEvent *e)
Q_D(QQuickMouseArea);
if (!d->pressed &&
(!d->enabled || !isVisible()
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
|| !d->drag || !d->drag->filterChildren()
#endif
)
@@ -1022,7 +1026,7 @@ void QQuickMouseArea::timerEvent(QTimerEvent *event)
Q_D(QQuickMouseArea);
if (event->timerId() == d->pressAndHoldTimer.timerId()) {
d->pressAndHoldTimer.stop();
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
bool dragged = d->drag && d->drag->active();
#else
bool dragged = false;
@@ -1065,7 +1069,7 @@ void QQuickMouseArea::itemChange(ItemChange change, const ItemChangeData &value)
Q_D(QQuickMouseArea);
switch (change) {
case ItemVisibleHasChanged:
- if (acceptHoverEvents() && d->hovered != (isVisible() && isUnderMouse())) {
+ if (d->effectiveEnable && d->enabled && acceptHoverEvents() && d->hovered != (isVisible() && isUnderMouse())) {
if (!d->hovered) {
QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
d->lastScenePos = d->window->mapFromGlobal(cursorPos.toPoint());
@@ -1198,7 +1202,7 @@ bool QQuickMouseArea::setPressed(Qt::MouseButton button, bool p, Qt::MouseEventS
{
Q_D(QQuickMouseArea);
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
bool dragged = d->drag && d->drag->active();
#else
bool dragged = false;
@@ -1404,7 +1408,7 @@ void QQuickMouseArea::resetPressAndHoldInterval()
*/
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
QQuickDrag *QQuickMouseArea::drag()
{
Q_D(QQuickMouseArea);
diff --git a/src/quick/items/qquickmousearea_p.h b/src/quick/items/qquickmousearea_p.h
index 0a8449957f..0e01fa7915 100644
--- a/src/quick/items/qquickmousearea_p.h
+++ b/src/quick/items/qquickmousearea_p.h
@@ -71,11 +71,11 @@ class Q_QUICK_PRIVATE_EXPORT QQuickMouseArea : public QQuickItem
Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged)
Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
- Q_PROPERTY(bool scrollGestureEnabled READ isScrollGestureEnabled WRITE setScrollGestureEnabled NOTIFY scrollGestureEnabledChanged REVISION 2)
+ Q_PROPERTY(bool scrollGestureEnabled READ isScrollGestureEnabled WRITE setScrollGestureEnabled NOTIFY scrollGestureEnabledChanged REVISION 5)
Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedButtonsChanged)
Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged)
Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
Q_PROPERTY(QQuickDrag *drag READ drag CONSTANT) //### add flicking to QQuickDrag or add a QQuickFlick ???
#endif
Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged)
@@ -83,7 +83,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickMouseArea : public QQuickItem
#if QT_CONFIG(cursor)
Q_PROPERTY(Qt::CursorShape cursorShape READ cursorShape WRITE setCursorShape RESET unsetCursor NOTIFY cursorShapeChanged)
#endif
- Q_PROPERTY(bool containsPress READ containsPress NOTIFY containsPressChanged REVISION 1)
+ Q_PROPERTY(bool containsPress READ containsPress NOTIFY containsPressChanged REVISION 4)
Q_PROPERTY(int pressAndHoldInterval READ pressAndHoldInterval WRITE setPressAndHoldInterval NOTIFY pressAndHoldIntervalChanged RESET resetPressAndHoldInterval REVISION 9)
public:
@@ -111,7 +111,7 @@ public:
bool hoverEnabled() const;
void setHoverEnabled(bool h);
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
QQuickDrag *drag();
#endif
@@ -134,7 +134,7 @@ Q_SIGNALS:
void hoveredChanged();
void pressedChanged();
void enabledChanged();
- Q_REVISION(2) void scrollGestureEnabledChanged();
+ Q_REVISION(5) void scrollGestureEnabledChanged();
void pressedButtonsChanged();
void acceptedButtonsChanged();
void hoverEnabledChanged();
@@ -156,7 +156,7 @@ Q_SIGNALS:
void entered();
void exited();
void canceled();
- Q_REVISION(1) void containsPressChanged();
+ Q_REVISION(4) void containsPressChanged();
Q_REVISION(9) void pressAndHoldIntervalChanged();
protected:
diff --git a/src/quick/items/qquickmousearea_p_p.h b/src/quick/items/qquickmousearea_p_p.h
index 0dd2690d43..fba383e268 100644
--- a/src/quick/items/qquickmousearea_p_p.h
+++ b/src/quick/items/qquickmousearea_p_p.h
@@ -97,7 +97,7 @@ public:
bool overThreshold : 1;
Qt::MouseButtons pressed;
int pressAndHoldInterval;
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
QQuickDrag *drag;
#endif
QPointer<QQuickPointerMask> mask;
diff --git a/src/quick/items/qquickmultipointtoucharea.cpp b/src/quick/items/qquickmultipointtoucharea.cpp
index 70426a6a8c..b02e58fae4 100644
--- a/src/quick/items/qquickmultipointtoucharea.cpp
+++ b/src/quick/items/qquickmultipointtoucharea.cpp
@@ -40,6 +40,7 @@
#include "qquickmultipointtoucharea_p.h"
#include <QtQuick/qquickwindow.h>
#include <private/qsgadaptationlayer_p.h>
+#include <private/qevent_p.h>
#include <private/qquickitem_p.h>
#include <private/qguiapplication_p.h>
#include <QEvent>
@@ -655,7 +656,8 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event)
// (we may have just obtained enough points to start tracking them -- in that case moved or stationary count as newly pressed)
addTouchPoint(&p);
started = true;
- } else if (touchPointState & Qt::TouchPointMoved) {
+ } else if ((touchPointState & Qt::TouchPointMoved) || p.d->stationaryWithModifiedProperty) {
+ // React to a stationary point with a property change (velocity, pressure) as if the point moved. (QTBUG-77142)
QQuickTouchPoint* dtp = static_cast<QQuickTouchPoint*>(_touchPoints.value(id));
Q_ASSERT(dtp);
_movedTouchPoints.append(dtp);
diff --git a/src/quick/items/qquickopenglshadereffect.cpp b/src/quick/items/qquickopenglshadereffect.cpp
index 3aa00340b2..e217fdb5d0 100644
--- a/src/quick/items/qquickopenglshadereffect.cpp
+++ b/src/quick/items/qquickopenglshadereffect.cpp
@@ -57,6 +57,10 @@
QT_BEGIN_NAMESPACE
+// Note: this legacy ShaderEffect implementation is used only when running
+// directly with OpenGL. This is going to go away in the future (Qt 6?), since
+// the RHI path uses QQuickGenericShaderEffect always.
+
namespace {
enum VariableQualifier {
@@ -185,8 +189,8 @@ class MappedSlotObject: public QtPrivate::QSlotObjectBase
public:
typedef std::function<void()> PropChangedFunc;
- explicit MappedSlotObject(PropChangedFunc func)
- : QSlotObjectBase(&impl), _signalIndex(-1), func(func)
+ explicit MappedSlotObject(PropChangedFunc f)
+ : QSlotObjectBase(&impl), _signalIndex(-1), func(std::move(f))
{ ref(); }
void setSignalIndex(int idx) { _signalIndex = idx; }
@@ -710,8 +714,8 @@ void QQuickOpenGLShaderEffect::setBlending(bool enable)
QVariant QQuickOpenGLShaderEffect::mesh() const
{
- return m_mesh ? qVariantFromValue(static_cast<QObject *>(m_mesh))
- : qVariantFromValue(m_meshResolution);
+ return m_mesh ? QVariant::fromValue(static_cast<QObject *>(m_mesh))
+ : QVariant::fromValue(m_meshResolution);
}
void QQuickOpenGLShaderEffect::setMesh(const QVariant &mesh)
diff --git a/src/quick/items/qquickopenglshadereffectnode.cpp b/src/quick/items/qquickopenglshadereffectnode.cpp
index 3ccd2a76f7..26ef59c20e 100644
--- a/src/quick/items/qquickopenglshadereffectnode.cpp
+++ b/src/quick/items/qquickopenglshadereffectnode.cpp
@@ -366,7 +366,6 @@ class QQuickOpenGLShaderEffectMaterialCache : public QObject
public:
static QQuickOpenGLShaderEffectMaterialCache *get(bool create = true) {
QOpenGLContext *ctx = QOpenGLContext::currentContext();
- Q_ASSERT(ctx);
QQuickOpenGLShaderEffectMaterialCache *me = ctx->findChild<QQuickOpenGLShaderEffectMaterialCache *>(QStringLiteral("__qt_ShaderEffectCache"), Qt::FindDirectChildrenOnly);
if (!me && create) {
me = new QQuickOpenGLShaderEffectMaterialCache();
diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp
index 8abb3f29cd..6976665134 100644
--- a/src/quick/items/qquickpathview.cpp
+++ b/src/quick/items/qquickpathview.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -60,8 +60,9 @@
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(lcItemViewDelegateLifecycle)
+Q_LOGGING_CATEGORY(lcPathView, "qt.quick.pathview")
-const qreal MinimumFlickVelocity = 75.0;
+static const qreal MinimumFlickVelocity = 75;
static QQmlOpenMetaObjectType *qPathViewAttachedType = nullptr;
@@ -90,8 +91,8 @@ void QQuickPathViewAttached::setValue(const QByteArray &name, const QVariant &va
}
QQuickPathViewPrivate::QQuickPathViewPrivate()
- : path(nullptr), currentIndex(0), currentItemOffset(0.0), startPc(0)
- , offset(0.0), offsetAdj(0.0), mappedRange(1.0), mappedCache(0.0)
+ : path(nullptr), currentIndex(0), currentItemOffset(0), startPc(0)
+ , offset(0), offsetAdj(0), mappedRange(1), mappedCache(0)
, stealMouse(false), ownModel(false), interactive(true), haveHighlightRange(true)
, autoHighlight(true), highlightUp(false), layoutScheduled(false)
, moving(false), flicking(false), dragging(false), inRequest(false), delegateValidated(false)
@@ -117,10 +118,10 @@ void QQuickPathViewPrivate::init()
q->setFlag(QQuickItem::ItemIsFocusScope);
q->setFiltersChildMouseEvents(true);
qmlobject_connect(&tl, QQuickTimeLine, SIGNAL(updated()),
- q, QQuickPathView, SLOT(ticked()))
+ q, QQuickPathView, SLOT(ticked()));
timer.invalidate();
qmlobject_connect(&tl, QQuickTimeLine, SIGNAL(completed()),
- q, QQuickPathView, SLOT(movementEnding()))
+ q, QQuickPathView, SLOT(movementEnding()));
}
QQuickItem *QQuickPathViewPrivate::getItem(int modelIndex, qreal z, bool async)
@@ -163,7 +164,7 @@ void QQuickPathView::createdItem(int index, QObject *object)
att->setOnPath(false);
}
item->setParentItem(this);
- d->updateItem(item, 1.0);
+ d->updateItem(item, 1);
} else {
d->requestedIndex = -1;
if (!d->inRequest)
@@ -184,13 +185,13 @@ void QQuickPathView::initItem(int index, QObject *object)
if (att) {
att->m_view = this;
qreal percent = d->positionOfIndex(index);
- if (percent < 1.0 && d->path) {
+ if (percent < 1 && d->path) {
const auto attributes = d->path->attributes();
for (const QString &attr : attributes)
att->setValue(attr.toUtf8(), d->path->attributeAt(attr, percent));
item->setZ(d->requestedZ);
}
- att->setOnPath(percent < 1.0);
+ att->setOnPath(percent < 1);
}
}
}
@@ -264,17 +265,17 @@ void QQuickPathViewPrivate::updateMappedRange()
mappedRange = qreal(modelCount)/pathItems;
mappedCache = qreal(cacheSize)/pathItems/2; // Half of cache at each end
} else {
- mappedRange = 1.0;
- mappedCache = 0.0;
+ mappedRange = 1;
+ mappedCache = 0;
}
}
qreal QQuickPathViewPrivate::positionOfIndex(qreal index) const
{
- qreal pos = -1.0;
+ qreal pos = -1;
if (model && index >= 0 && index < modelCount) {
- qreal start = 0.0;
+ qreal start = 0;
if (haveHighlightRange && (highlightRangeMode != QQuickPathView::NoHighlightRange
|| snapMode != QQuickPathView::NoSnap))
start = highlightRangeStart;
@@ -282,10 +283,10 @@ qreal QQuickPathViewPrivate::positionOfIndex(qreal index) const
globalPos = std::fmod(globalPos, qreal(modelCount)) / modelCount;
if (pathItems != -1 && pathItems < modelCount) {
globalPos += start / mappedRange;
- globalPos = std::fmod(globalPos, qreal(1.0));
+ globalPos = std::fmod(globalPos, qreal(1));
pos = globalPos * mappedRange;
} else {
- pos = std::fmod(globalPos + start, qreal(1.0));
+ pos = std::fmod(globalPos + start, qreal(1));
}
}
@@ -296,7 +297,7 @@ qreal QQuickPathViewPrivate::positionOfIndex(qreal index) const
// account the circular space.
bool QQuickPathViewPrivate::isInBound(qreal position, qreal lower, qreal upper) const
{
- if (lower == upper)
+ if (qFuzzyCompare(lower, upper))
return true;
if (lower > upper) {
if (position > upper && position > lower)
@@ -358,7 +359,7 @@ void QQuickPathViewPrivate::updateHighlight()
} else {
qreal target = currentIndex;
- offsetAdj = 0.0;
+ offsetAdj = 0;
tl.reset(moveHighlight);
moveHighlight.setValue(highlightPosition);
@@ -367,14 +368,14 @@ void QQuickPathViewPrivate::updateHighlight()
if (target - highlightPosition > modelCount/2) {
highlightUp = false;
qreal distance = modelCount - target + highlightPosition;
- tl.move(moveHighlight, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * highlightPosition / distance));
+ tl.move(moveHighlight, 0, QEasingCurve(QEasingCurve::InQuad), int(duration * highlightPosition / distance));
tl.set(moveHighlight, modelCount-0.01);
tl.move(moveHighlight, target, QEasingCurve(QEasingCurve::OutQuad), int(duration * (modelCount-target) / distance));
} else if (target - highlightPosition <= -modelCount/2) {
highlightUp = true;
qreal distance = modelCount - highlightPosition + target;
tl.move(moveHighlight, modelCount-0.01, QEasingCurve(QEasingCurve::InQuad), int(duration * (modelCount-highlightPosition) / distance));
- tl.set(moveHighlight, 0.0);
+ tl.set(moveHighlight, 0);
tl.move(moveHighlight, target, QEasingCurve(QEasingCurve::OutQuad), int(duration * target / distance));
} else {
highlightUp = highlightPosition - target < 0;
@@ -386,9 +387,9 @@ void QQuickPathViewPrivate::updateHighlight()
void QQuickPathViewPrivate::setHighlightPosition(qreal pos)
{
- if (pos != highlightPosition) {
- qreal start = 0.0;
- qreal end = 1.0;
+ if (!(qFuzzyCompare(pos, highlightPosition))) {
+ qreal start = 0;
+ qreal end = 1;
if (haveHighlightRange && highlightRangeMode != QQuickPathView::NoHighlightRange) {
start = highlightRangeStart;
end = highlightRangeEnd;
@@ -399,7 +400,7 @@ void QQuickPathViewPrivate::setHighlightPosition(qreal pos)
qreal relativeHighlight = std::fmod(pos + offset, range) / range;
if (!highlightUp && relativeHighlight > end / mappedRange) {
- qreal diff = 1.0 - relativeHighlight;
+ qreal diff = 1 - relativeHighlight;
setOffset(offset + diff * range);
} else if (highlightUp && relativeHighlight >= (end - start) / mappedRange) {
qreal diff = relativeHighlight - (end - start) / mappedRange;
@@ -410,7 +411,7 @@ void QQuickPathViewPrivate::setHighlightPosition(qreal pos)
qreal pathPos = positionOfIndex(pos);
updateItem(highlightItem, pathPos);
if (QQuickPathViewAttached *att = attached(highlightItem))
- att->setOnPath(pathPos < 1.0);
+ att->setOnPath(pathPos < 1);
}
}
@@ -435,10 +436,10 @@ void QQuickPathViewPrivate::updateItem(QQuickItem *item, qreal percent)
const auto attributes = path->attributes();
for (const QString &attr : attributes)
att->setValue(attr.toUtf8(), path->attributeAt(attr, percent));
- att->setOnPath(percent < 1.0);
+ att->setOnPath(percent < 1);
}
- QQuickItemPrivate::get(item)->setCulled(percent >= 1.0);
- QPointF pf = path->pointAt(qMin(percent, qreal(1.0)));
+ QQuickItemPrivate::get(item)->setCulled(percent >= 1);
+ QPointF pf = path->pointAtPercent(qMin(percent, qreal(1)));
item->setX(pf.x() - item->width()/2);
item->setY(pf.y() - item->height()/2);
}
@@ -668,7 +669,7 @@ void QQuickPathView::setModel(const QVariant &m)
d->currentIndex = 0;
emit currentIndexChanged();
}
- if (d->offset != 0.0) {
+ if (!(qFuzzyIsNull(d->offset))) {
d->offset = 0;
emit offsetChanged();
}
@@ -820,7 +821,7 @@ void QQuickPathView::decrementCurrentIndex()
\qmlproperty real QtQuick::PathView::offset
The offset specifies how far along the path the items are from their initial positions.
- This is a real number that ranges from 0.0 to the count of items in the model.
+ This is a real number that ranges from \c 0 to the count of items in the model.
*/
qreal QQuickPathView::offset() const
{
@@ -839,7 +840,7 @@ void QQuickPathView::setOffset(qreal offset)
void QQuickPathViewPrivate::setOffset(qreal o)
{
Q_Q(QQuickPathView);
- if (offset != o) {
+ if (!qFuzzyCompare(offset, o)) {
if (isValid() && q->isComponentComplete()) {
qreal oldOffset = offset;
offset = std::fmod(o, qreal(modelCount));
@@ -882,7 +883,6 @@ void QQuickPathViewPrivate::setAdjustedOffset(qreal o)
\sa highlightItem, highlightRangeMode
*/
-
QQmlComponent *QQuickPathView::highlight() const
{
Q_D(const QQuickPathView);
@@ -901,25 +901,26 @@ void QQuickPathView::setHighlight(QQmlComponent *highlight)
}
/*!
- \qmlproperty Item QtQuick::PathView::highlightItem
+ \qmlproperty Item QtQuick::PathView::highlightItem
- \c highlightItem holds the highlight item, which was created
- from the \l highlight component.
+ \c highlightItem holds the highlight item, which was created
+ from the \l highlight component.
- \sa highlight
+ \sa highlight
*/
QQuickItem *QQuickPathView::highlightItem() const
{
Q_D(const QQuickPathView);
return d->highlightItem;
}
+
/*!
\qmlproperty real QtQuick::PathView::preferredHighlightBegin
\qmlproperty real QtQuick::PathView::preferredHighlightEnd
\qmlproperty enumeration QtQuick::PathView::highlightRangeMode
These properties set the preferred range of the highlight (current item)
- within the view. The preferred values must be in the range 0.0-1.0.
+ within the view. The preferred values must be in the range from \c 0 to \c 1.
Valid values for \c highlightRangeMode are:
@@ -960,7 +961,7 @@ qreal QQuickPathView::preferredHighlightBegin() const
void QQuickPathView::setPreferredHighlightBegin(qreal start)
{
Q_D(QQuickPathView);
- if (d->highlightRangeStart == start || start < 0 || start > 1.0)
+ if (qFuzzyCompare(d->highlightRangeStart, start) || start < 0 || start > 1)
return;
d->highlightRangeStart = start;
d->haveHighlightRange = d->highlightRangeStart <= d->highlightRangeEnd;
@@ -977,7 +978,7 @@ qreal QQuickPathView::preferredHighlightEnd() const
void QQuickPathView::setPreferredHighlightEnd(qreal end)
{
Q_D(QQuickPathView);
- if (d->highlightRangeEnd == end || end < 0 || end > 1.0)
+ if (qFuzzyCompare(d->highlightRangeEnd, end) || end < 0 || end > 1)
return;
d->highlightRangeEnd = end;
d->haveHighlightRange = d->highlightRangeStart <= d->highlightRangeEnd;
@@ -1048,7 +1049,7 @@ qreal QQuickPathView::dragMargin() const
void QQuickPathView::setDragMargin(qreal dragMargin)
{
Q_D(QQuickPathView);
- if (d->dragMargin == dragMargin)
+ if (qFuzzyCompare(d->dragMargin, dragMargin))
return;
d->dragMargin = dragMargin;
emit dragMarginChanged();
@@ -1069,7 +1070,7 @@ qreal QQuickPathView::flickDeceleration() const
void QQuickPathView::setFlickDeceleration(qreal dec)
{
Q_D(QQuickPathView);
- if (d->deceleration == dec)
+ if (qFuzzyCompare(d->deceleration, dec))
return;
d->deceleration = dec;
emit flickDecelerationChanged();
@@ -1090,7 +1091,7 @@ qreal QQuickPathView::maximumFlickVelocity() const
void QQuickPathView::setMaximumFlickVelocity(qreal vel)
{
Q_D(QQuickPathView);
- if (vel == d->maximumFlickVelocity)
+ if (qFuzzyCompare(vel, d->maximumFlickVelocity))
return;
d->maximumFlickVelocity = vel;
emit maximumFlickVelocityChanged();
@@ -1580,16 +1581,16 @@ QQuickItem *QQuickPathView::itemAtIndex(int index) const
QPointF QQuickPathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const
{
const auto pathLength = path->path().length();
- qreal samples = qMin(pathLength / 5, qreal(500.0));
+ qreal samples = qMin(pathLength / 5, qreal(500));
qreal res = pathLength / samples;
qreal mindist = 1e10; // big number
- QPointF nearPoint = path->pointAt(0);
+ QPointF nearPoint = path->pointAtPercent(0);
qreal nearPc = 0;
// get rough pos
for (qreal i=1; i < samples; i++) {
- QPointF pt = path->pointAt(i/samples);
+ QPointF pt = path->pointAtPercent(i/samples);
QPointF diff = pt - point;
qreal dist = diff.x()*diff.x() + diff.y()*diff.y();
if (dist < mindist) {
@@ -1601,8 +1602,8 @@ QPointF QQuickPathViewPrivate::pointNear(const QPointF &point, qreal *nearPercen
// now refine
qreal approxPc = nearPc;
- for (qreal i = approxPc-1.0; i < approxPc+1.0; i += 1/(2*res)) {
- QPointF pt = path->pointAt(i/samples);
+ for (qreal i = approxPc-1; i < approxPc+1; i += 1/(2*res)) {
+ QPointF pt = path->pointAtPercent(i/samples);
QPointF diff = pt - point;
qreal dist = diff.x()*diff.x() + diff.y()*diff.y();
if (dist < mindist) {
@@ -1623,6 +1624,7 @@ void QQuickPathViewPrivate::addVelocitySample(qreal v)
velocityBuffer.append(v);
if (velocityBuffer.count() > QML_FLICK_SAMPLEBUFFER)
velocityBuffer.remove(0);
+ qCDebug(lcPathView) << "instantaneous velocity" << v;
}
qreal QQuickPathViewPrivate::calcVelocity() const
@@ -1635,6 +1637,7 @@ qreal QQuickPathViewPrivate::calcVelocity() const
velocity += v;
}
velocity /= count;
+ qCDebug(lcPathView) << "average velocity" << velocity << "based on" << count << "samples";
}
return velocity;
}
@@ -1642,7 +1645,7 @@ qreal QQuickPathViewPrivate::calcVelocity() const
qint64 QQuickPathViewPrivate::computeCurrentTime(QInputEvent *event) const
{
if (0 != event->timestamp())
- return event->timestamp();
+ return qint64(event->timestamp());
return timer.elapsed();
}
@@ -1669,7 +1672,7 @@ void QQuickPathViewPrivate::handleMousePressEvent(QMouseEvent *event)
if (item->contains(item->mapFromScene(event->windowPos())))
break;
}
- if (idx == items.count() && dragMargin == 0.) // didn't click on an item
+ if (idx == items.count() && qFuzzyIsNull(dragMargin)) // didn't click on an item
return;
startPoint = pointNear(event->localPos(), &startPc);
@@ -1731,7 +1734,7 @@ void QQuickPathViewPrivate::handleMouseMoveEvent(QMouseEvent *event)
moveReason = QQuickPathViewPrivate::Mouse;
int count = pathItems == -1 ? modelCount : qMin(pathItems, modelCount);
qreal diff = (newPc - startPc)*count;
- if (diff) {
+ if (!qFuzzyIsNull(diff)) {
q->setOffset(offset + diff);
if (diff > modelCount/2)
@@ -1741,7 +1744,7 @@ void QQuickPathViewPrivate::handleMouseMoveEvent(QMouseEvent *event)
qint64 elapsed = currentTimestamp - lastPosTime;
if (elapsed > 0)
- addVelocitySample(diff / (qreal(elapsed) / 1000.));
+ addVelocitySample(diff / (qreal(elapsed) / 1000));
}
if (!moving) {
moving = true;
@@ -1766,7 +1769,7 @@ void QQuickPathView::mouseReleaseEvent(QMouseEvent *event)
}
}
-void QQuickPathViewPrivate::handleMouseReleaseEvent(QMouseEvent *)
+void QQuickPathViewPrivate::handleMouseReleaseEvent(QMouseEvent *event)
{
Q_Q(QQuickPathView);
stealMouse = false;
@@ -1780,6 +1783,12 @@ void QQuickPathViewPrivate::handleMouseReleaseEvent(QMouseEvent *)
}
qreal velocity = calcVelocity();
+ qint64 elapsed = computeCurrentTime(event) - lastPosTime;
+ // Let the velocity linearly decay such that it becomes 0 if elapsed time > QML_FLICK_VELOCITY_DECAY_TIME
+ // The intention is that if you are flicking at some speed, then stop in one place for some time before releasing,
+ // the previous velocity is lost. (QTBUG-77173, QTBUG-59052)
+ velocity *= qreal(qMax(0LL, QML_FLICK_VELOCITY_DECAY_TIME - elapsed)) / QML_FLICK_VELOCITY_DECAY_TIME;
+ qCDebug(lcPathView) << "after elapsed time" << elapsed << "velocity decayed to" << velocity;
qreal count = pathItems == -1 ? modelCount : qMin(pathItems, modelCount);
const auto averageItemLength = path->path().length() / count;
qreal pixelVelocity = averageItemLength * velocity;
@@ -1797,32 +1806,32 @@ void QQuickPathViewPrivate::handleMouseReleaseEvent(QMouseEvent *)
|| snapMode != QQuickPathView::NoSnap)) {
if (snapMode == QQuickPathView::SnapOneItem) {
// encourage snapping one item in direction of motion
- if (velocity > 0.)
+ if (velocity > 0)
dist = qRound(0.5 + offset) - offset;
else
dist = qRound(0.5 - offset) + offset;
} else {
// + 0.25 to encourage moving at least one item in the flick direction
- dist = qMin(qreal(modelCount-1), qreal(v2 / (accel * 2.0) + 0.25));
+ dist = qMin(qreal(modelCount-1), qreal(v2 / (accel * 2) + 0.25));
// round to nearest item.
- if (velocity > 0.)
+ if (velocity > 0)
dist = qRound(dist + offset) - offset;
else
dist = qRound(dist - offset) + offset;
}
// Calculate accel required to stop on item boundary
- if (dist <= 0.) {
- dist = 0.;
- accel = 0.;
+ if (dist <= 0) {
+ dist = 0;
+ accel = 0;
} else {
- accel = v2 / (2.0f * qAbs(dist));
+ accel = v2 / (2 * qAbs(dist));
}
} else {
- dist = qMin(qreal(modelCount-1), qreal(v2 / (accel * 2.0)));
+ dist = qMin(qreal(modelCount-1), qreal(v2 / (accel * 2)));
}
- flickDuration = static_cast<int>(1000 * qAbs(velocity) / accel);
- offsetAdj = 0.0;
+ flickDuration = int(1000 * qAbs(velocity) / accel);
+ offsetAdj = 0;
moveOffset.setValue(offset);
tl.accel(moveOffset, velocity, accel, dist);
tl.callback(QQuickTimeLineCallback(&moveOffset, fixOffsetCallback, this));
@@ -1996,7 +2005,7 @@ void QQuickPathView::refill()
else
qCDebug(lcItemViewDelegateLifecycle) << "idx" << idx << "@" << pos << ":" << item;
}
- if (pos < 1.0) {
+ if (pos < 1) {
d->updateItem(item, pos);
if (idx == d->currentIndex) {
currentVisible = true;
@@ -2006,9 +2015,9 @@ void QQuickPathView::refill()
} else {
d->updateItem(item, pos);
if (QQuickPathViewAttached *att = d->attached(item))
- att->setOnPath(pos < 1.0);
- if (!d->isInBound(pos, d->mappedRange - d->mappedCache, 1.0 + d->mappedCache)) {
- qCDebug(lcItemViewDelegateLifecycle) << "release" << idx << "@" << pos << ", !isInBound: lower" << (d->mappedRange - d->mappedCache) << "upper" << (1.0 + d->mappedCache);
+ att->setOnPath(pos < 1);
+ if (!d->isInBound(pos, d->mappedRange - d->mappedCache, 1 + d->mappedCache)) {
+ qCDebug(lcItemViewDelegateLifecycle) << "release" << idx << "@" << pos << ", !isInBound: lower" << (d->mappedRange - d->mappedCache) << "upper" << (1 + d->mappedCache);
d->releaseItem(item);
it = d->items.erase(it);
} else {
@@ -2024,12 +2033,12 @@ void QQuickPathView::refill()
int endIdx = 0;
qreal endPos;
int startIdx = 0;
- qreal startPos = 0.0;
+ qreal startPos = 0;
const bool wasEmpty = d->items.isEmpty();
if (!wasEmpty) {
//Find the beginning and end, items may not be in sorted order
- endPos = -1.0;
- startPos = 2.0;
+ endPos = -1;
+ startPos = 2;
for (QQuickItem * item : qAsConst(d->items)) {
int idx = d->model->indexOf(item, nullptr);
@@ -2058,10 +2067,10 @@ void QQuickPathView::refill()
if (idx >= d->modelCount)
idx = 0;
qreal nextPos = d->positionOfIndex(idx);
- while ((d->isInBound(nextPos, endPos, 1.0 + d->mappedCache) || !d->items.count())
+ while ((d->isInBound(nextPos, endPos, 1 + d->mappedCache) || !d->items.count())
&& d->items.count() < count+d->cacheSize) {
qCDebug(lcItemViewDelegateLifecycle) << "append" << idx << "@" << nextPos << (d->currentIndex == idx ? "current" : "") << "items count was" << d->items.count();
- QQuickItem *item = d->getItem(idx, idx+1, nextPos >= 1.0);
+ QQuickItem *item = d->getItem(idx, idx+1, nextPos >= 1);
if (!item) {
waiting = true;
break;
@@ -2093,7 +2102,7 @@ void QQuickPathView::refill()
while (!waiting && d->isInBound(nextPos, d->mappedRange - d->mappedCache, startPos)
&& d->items.count() < count+d->cacheSize) {
qCDebug(lcItemViewDelegateLifecycle) << "prepend" << idx << "@" << nextPos << (d->currentIndex == idx ? "current" : "") << "items count was" << d->items.count();
- QQuickItem *item = d->getItem(idx, idx+1, nextPos >= 1.0);
+ QQuickItem *item = d->getItem(idx, idx+1, nextPos >= 1);
if (!item) {
waiting = true;
break;
@@ -2126,9 +2135,9 @@ void QQuickPathView::refill()
QQuickItem *lastItem = d->items.at(0);
while (idx != endIdx) {
nextPos = d->positionOfIndex(idx);
- if (d->isInBound(nextPos, d->mappedRange - d->mappedCache, 1.0 + d->mappedCache)) {
+ if (d->isInBound(nextPos, d->mappedRange - d->mappedCache, 1 + d->mappedCache)) {
//This gets the reference from the delegate model, and will not re-create
- QQuickItem *item = d->getItem(idx, idx+1, nextPos >= 1.0);
+ QQuickItem *item = d->getItem(idx, idx+1, nextPos >= 1);
if (!item) {
waiting = true;
break;
@@ -2162,13 +2171,13 @@ void QQuickPathView::refill()
bool currentChanged = false;
if (!currentVisible) {
- d->currentItemOffset = 1.0;
+ d->currentItemOffset = 1;
if (d->currentItem) {
- d->updateItem(d->currentItem, 1.0);
+ d->updateItem(d->currentItem, 1);
} else if (!waiting && d->currentIndex >= 0 && d->currentIndex < d->modelCount) {
if ((d->currentItem = d->getItem(d->currentIndex, d->currentIndex))) {
currentChanged = true;
- d->updateItem(d->currentItem, 1.0);
+ d->updateItem(d->currentItem, 1);
if (QQuickPathViewAttached *att = d->attached(d->currentItem))
att->setIsCurrentItem(true);
}
@@ -2362,7 +2371,7 @@ void QQuickPathViewPrivate::createCurrentItem()
}
} else if (currentIndex >= 0 && currentIndex < modelCount) {
if ((currentItem = getItem(currentIndex, currentIndex))) {
- updateItem(currentItem, 1.0);
+ updateItem(currentItem, 1);
if (QQuickPathViewAttached *att = attached(currentItem))
att->setIsCurrentItem(true);
}
@@ -2396,7 +2405,7 @@ void QQuickPathViewPrivate::updateCurrent()
void QQuickPathViewPrivate::fixOffsetCallback(void *d)
{
- ((QQuickPathViewPrivate *)d)->fixOffset();
+ static_cast<QQuickPathViewPrivate *>(d)->fixOffset();
}
void QQuickPathViewPrivate::fixOffset()
@@ -2421,7 +2430,7 @@ void QQuickPathViewPrivate::snapToIndex(int index, MovementReason reason)
qreal targetOffset = std::fmod(qreal(modelCount - index), qreal(modelCount));
moveReason = reason;
- offsetAdj = 0.0;
+ offsetAdj = 0;
tl.reset(moveOffset);
moveOffset.setValue(offset);
@@ -2433,20 +2442,20 @@ void QQuickPathViewPrivate::snapToIndex(int index, MovementReason reason)
if (!duration || qAbs(offset - targetOffset) < threshold || (qFuzzyIsNull(targetOffset) && qAbs(modelCount - offset) < threshold)) {
tl.set(moveOffset, targetOffset);
- } else if (moveDirection == QQuickPathView::Positive || (moveDirection == QQuickPathView::Shortest && targetOffset - offset > modelCount/2.0)) {
+ } else if (moveDirection == QQuickPathView::Positive || (moveDirection == QQuickPathView::Shortest && targetOffset - offset > modelCount/2)) {
qreal distance = modelCount - targetOffset + offset;
if (targetOffset > moveOffset) {
- tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * offset / distance));
+ tl.move(moveOffset, 0, QEasingCurve(QEasingCurve::InQuad), int(duration * offset / distance));
tl.set(moveOffset, modelCount);
- tl.move(moveOffset, targetOffset, QEasingCurve(offset == 0.0 ? QEasingCurve::InOutQuad : QEasingCurve::OutQuad), int(duration * (modelCount-targetOffset) / distance));
+ tl.move(moveOffset, targetOffset, QEasingCurve(qFuzzyIsNull(offset) ? QEasingCurve::InOutQuad : QEasingCurve::OutQuad), int(duration * (modelCount-targetOffset) / distance));
} else {
tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration);
}
- } else if (moveDirection == QQuickPathView::Negative || targetOffset - offset <= -modelCount/2.0) {
+ } else if (moveDirection == QQuickPathView::Negative || targetOffset - offset <= -modelCount/2) {
qreal distance = modelCount - offset + targetOffset;
if (targetOffset < moveOffset) {
- tl.move(moveOffset, modelCount, QEasingCurve(targetOffset == 0 ? QEasingCurve::InOutQuad : QEasingCurve::InQuad), int(duration * (modelCount-offset) / distance));
- tl.set(moveOffset, 0.0);
+ tl.move(moveOffset, modelCount, QEasingCurve(qFuzzyIsNull(targetOffset) ? QEasingCurve::InOutQuad : QEasingCurve::InQuad), int(duration * (modelCount-offset) / distance));
+ tl.set(moveOffset, 0);
tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * targetOffset / distance));
} else {
tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration);
diff --git a/src/quick/items/qquickpincharea_p.h b/src/quick/items/qquickpincharea_p.h
index 8eff53e6dc..cf21555823 100644
--- a/src/quick/items/qquickpincharea_p.h
+++ b/src/quick/items/qquickpincharea_p.h
@@ -59,7 +59,7 @@ class Q_AUTOTEST_EXPORT QQuickPinch : public QObject
{
Q_OBJECT
- Q_PROPERTY(QQuickItem *target READ target WRITE setTarget RESET resetTarget)
+ Q_PROPERTY(QQuickItem *target READ target WRITE setTarget RESET resetTarget NOTIFY targetChanged)
Q_PROPERTY(qreal minimumScale READ minimumScale WRITE setMinimumScale NOTIFY minimumScaleChanged)
Q_PROPERTY(qreal maximumScale READ maximumScale WRITE setMaximumScale NOTIFY maximumScaleChanged)
Q_PROPERTY(qreal minimumRotation READ minimumRotation WRITE setMinimumRotation NOTIFY minimumRotationChanged)
@@ -283,7 +283,7 @@ Q_SIGNALS:
void pinchStarted(QQuickPinchEvent *pinch);
void pinchUpdated(QQuickPinchEvent *pinch);
void pinchFinished(QQuickPinchEvent *pinch);
- Q_REVISION(1) void smartZoom(QQuickPinchEvent *pinch);
+ Q_REVISION(5) void smartZoom(QQuickPinchEvent *pinch);
protected:
bool childMouseEventFilter(QQuickItem *i, QEvent *e) override;
diff --git a/src/quick/items/qquickrectangle.cpp b/src/quick/items/qquickrectangle.cpp
index 5e217dcd0c..f3cefc7463 100644
--- a/src/quick/items/qquickrectangle.cpp
+++ b/src/quick/items/qquickrectangle.cpp
@@ -451,8 +451,30 @@ void QQuickRectangle::setGradient(const QJSValue &gradient)
d->gradient = QJSValue();
}
} else if (gradient.isNumber() || gradient.isString()) {
- QGradient preset(gradient.toVariant().value<QGradient::Preset>());
- if (preset.type() != QGradient::NoGradient) {
+ static const QMetaEnum gradientPresetMetaEnum = QMetaEnum::fromType<QGradient::Preset>();
+ Q_ASSERT(gradientPresetMetaEnum.isValid());
+
+ QGradient result;
+
+ // This code could simply use gradient.toVariant().convert<QGradient::Preset>(),
+ // but QTBUG-76377 prevents us from doing error checks. So we need to
+ // do them manually. Also, NumPresets cannot be used.
+
+ if (gradient.isNumber()) {
+ const auto preset = QGradient::Preset(gradient.toInt());
+ if (preset != QGradient::NumPresets && gradientPresetMetaEnum.valueToKey(preset))
+ result = QGradient(preset);
+ } else if (gradient.isString()) {
+ const auto presetName = gradient.toString();
+ if (presetName != QLatin1String("NumPresets")) {
+ bool ok;
+ const auto presetInt = gradientPresetMetaEnum.keyToValue(qPrintable(presetName), &ok);
+ if (ok)
+ result = QGradient(QGradient::Preset(presetInt));
+ }
+ }
+
+ if (result.type() != QGradient::NoGradient) {
d->gradient = gradient;
} else {
qmlWarning(this) << "No such gradient preset '" << gradient.toString() << "'";
diff --git a/src/quick/items/qquickrendercontrol.cpp b/src/quick/items/qquickrendercontrol.cpp
index 76bcae1003..9f9777f199 100644
--- a/src/quick/items/qquickrendercontrol.cpp
+++ b/src/quick/items/qquickrendercontrol.cpp
@@ -188,8 +188,7 @@ void QQuickRenderControlPrivate::windowDestroyed()
if (window) {
rc->invalidate();
- delete QQuickWindowPrivate::get(window)->animationController;
- QQuickWindowPrivate::get(window)->animationController = nullptr;
+ QQuickWindowPrivate::get(window)->animationController.reset();
#if QT_CONFIG(quick_shadereffect) && QT_CONFIG(opengl)
if (QOpenGLContext::currentContext())
@@ -242,7 +241,18 @@ void QQuickRenderControl::initialize(QOpenGLContext *gl)
// It cannot be done here since the surface to use may not be the
// surface belonging to window. In fact window may not have a native
// window/surface at all.
- d->rc->initialize(gl);
+ QSGDefaultRenderContext *rc = qobject_cast<QSGDefaultRenderContext *>(d->rc);
+ if (rc) {
+ QSGDefaultRenderContext::InitParams params;
+ params.sampleCount = qMax(1, gl->format().samples());
+ params.openGLContext = gl;
+ params.initialSurfacePixelSize = d->window->size() * d->window->effectiveDevicePixelRatio();
+ params.maybeSurface = d->window;
+ rc->initialize(&params);
+ } else {
+ // can this happen?
+ d->rc->initialize(nullptr);
+ }
#else
Q_UNUSED(gl)
#endif
diff --git a/src/quick/items/qquickrepeater.cpp b/src/quick/items/qquickrepeater.cpp
index 0c00fecead..c8c5281089 100644
--- a/src/quick/items/qquickrepeater.cpp
+++ b/src/quick/items/qquickrepeater.cpp
@@ -41,7 +41,6 @@
#include "qquickrepeater_p_p.h"
#include <private/qqmlglobal_p.h>
-#include <private/qqmllistaccessor_p.h>
#include <private/qqmlchangeset_p.h>
#include <private/qqmldelegatemodel_p.h>
diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h
index e9db07d14c..10e524e4a0 100644
--- a/src/quick/items/qquickscreen_p.h
+++ b/src/quick/items/qquickscreen_p.h
@@ -83,8 +83,8 @@ class Q_AUTOTEST_EXPORT QQuickScreenInfo : public QObject
// TODO Qt 6 Remove this orientation -> incomplete device orientation -> better use OrientationSensor
Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged)
- Q_PROPERTY(int virtualX READ virtualX NOTIFY virtualXChanged REVISION 1)
- Q_PROPERTY(int virtualY READ virtualY NOTIFY virtualYChanged REVISION 1)
+ Q_PROPERTY(int virtualX READ virtualX NOTIFY virtualXChanged REVISION 3)
+ Q_PROPERTY(int virtualY READ virtualY NOTIFY virtualYChanged REVISION 3)
public:
QQuickScreenInfo(QObject *parent = nullptr, QScreen *wrappedScreen = nullptr);
@@ -121,8 +121,8 @@ Q_SIGNALS:
void devicePixelRatioChanged();
void primaryOrientationChanged();
void orientationChanged();
- Q_REVISION(1) void virtualXChanged();
- Q_REVISION(1) void virtualYChanged();
+ Q_REVISION(3) void virtualXChanged();
+ Q_REVISION(3) void virtualYChanged();
protected:
QPointer<QScreen> m_screen;
diff --git a/src/quick/items/qquickshadereffect.cpp b/src/quick/items/qquickshadereffect.cpp
index eb5256fa4e..b3c8386fd9 100644
--- a/src/quick/items/qquickshadereffect.cpp
+++ b/src/quick/items/qquickshadereffect.cpp
@@ -44,6 +44,9 @@
#include <private/qquickopenglshadereffect_p.h>
#endif
#include <private/qquickgenericshadereffect_p.h>
+#if QT_CONFIG(opengl) /* || QT_CONFIG(vulkan) || defined(Q_OS_WIN) || defined(Q_OS_DARWIN) */
+#include <private/qsgrhisupport_p.h>
+#endif
QT_BEGIN_NAMESPACE
@@ -506,13 +509,20 @@ QQuickShaderEffect::QQuickShaderEffect(QQuickItem *parent)
{
setFlag(QQuickItem::ItemHasContents);
+#if QT_CONFIG(opengl) /* || QT_CONFIG(vulkan) || defined(Q_OS_WIN) || defined(Q_OS_DARWIN) */
+ if (QSGRhiSupport::instance()->isRhiEnabled()) {
+ m_impl = new QQuickGenericShaderEffect(this, this);
+ } else
+#endif
+ {
#if QT_CONFIG(opengl)
- if (!qsg_backend_flags().testFlag(QSGContextFactoryInterface::SupportsShaderEffectNode))
- m_glImpl = new QQuickOpenGLShaderEffect(this, this);
+ if (!qsg_backend_flags().testFlag(QSGContextFactoryInterface::SupportsShaderEffectNode))
+ m_glImpl = new QQuickOpenGLShaderEffect(this, this);
- if (!m_glImpl)
+ if (!m_glImpl)
#endif
- m_impl = new QQuickGenericShaderEffect(this, this);
+ m_impl = new QQuickGenericShaderEffect(this, this);
+ }
}
QQuickShaderEffect::~QQuickShaderEffect()
diff --git a/src/quick/items/qquickshadereffect_p.h b/src/quick/items/qquickshadereffect_p.h
index c5bddc40d2..6e2f35882b 100644
--- a/src/quick/items/qquickshadereffect_p.h
+++ b/src/quick/items/qquickshadereffect_p.h
@@ -74,7 +74,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffect : public QQuickItem
Q_PROPERTY(CullMode cullMode READ cullMode WRITE setCullMode NOTIFY cullModeChanged)
Q_PROPERTY(QString log READ log NOTIFY logChanged)
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
- Q_PROPERTY(bool supportsAtlasTextures READ supportsAtlasTextures WRITE setSupportsAtlasTextures NOTIFY supportsAtlasTexturesChanged REVISION 1)
+ Q_PROPERTY(bool supportsAtlasTextures READ supportsAtlasTextures WRITE setSupportsAtlasTextures NOTIFY supportsAtlasTexturesChanged REVISION 4)
public:
enum CullMode {
diff --git a/src/quick/items/qquickshadereffectsource.cpp b/src/quick/items/qquickshadereffectsource.cpp
index 505940e673..f9f3e5cfa3 100644
--- a/src/quick/items/qquickshadereffectsource.cpp
+++ b/src/quick/items/qquickshadereffectsource.cpp
@@ -750,7 +750,7 @@ QSGNode *QQuickShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaint
QSGInternalImageNode *node = static_cast<QSGInternalImageNode *>(oldNode);
if (!node) {
- node = d->sceneGraphContext()->createInternalImageNode();
+ node = d->sceneGraphContext()->createInternalImageNode(d->sceneGraphRenderContext());
node->setFlag(QSGNode::UsePreprocess);
node->setTexture(m_texture);
QQuickShaderSourceAttachedNode *attached = new QQuickShaderSourceAttachedNode;
diff --git a/src/quick/items/qquickshadereffectsource_p.h b/src/quick/items/qquickshadereffectsource_p.h
index d5bb33902a..d612d1179f 100644
--- a/src/quick/items/qquickshadereffectsource_p.h
+++ b/src/quick/items/qquickshadereffectsource_p.h
@@ -87,8 +87,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffectSource : public QQuickItem, publi
Q_PROPERTY(bool hideSource READ hideSource WRITE setHideSource NOTIFY hideSourceChanged)
Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged)
Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged)
- Q_PROPERTY(TextureMirroring textureMirroring READ textureMirroring WRITE setTextureMirroring NOTIFY textureMirroringChanged REVISION 1)
- Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged REVISION 2)
+ Q_PROPERTY(TextureMirroring textureMirroring READ textureMirroring WRITE setTextureMirroring NOTIFY textureMirroringChanged REVISION 6)
+ Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged REVISION 9)
public:
enum WrapMode {
diff --git a/src/quick/items/qquickspriteengine.cpp b/src/quick/items/qquickspriteengine.cpp
index be297bbe76..8c52703938 100644
--- a/src/quick/items/qquickspriteengine.cpp
+++ b/src/quick/items/qquickspriteengine.cpp
@@ -554,7 +554,7 @@ void QQuickStochasticEngine::restart(int index)
bool randomStart = (m_startTimes.at(index) == NINF);
m_startTimes[index] = m_timeOffset;
if (m_addAdvance)
- m_startTimes[index] += m_advanceTime.elapsed();
+ m_startTimes[index] += m_advanceTimer.elapsed();
if (randomStart)
m_startTimes[index] -= QRandomGenerator::global()->bounded(m_duration.at(index));
int time = m_duration.at(index) + m_startTimes.at(index);
@@ -574,12 +574,12 @@ void QQuickSpriteEngine::restart(int index) //Reimplemented to recognize and han
} else {
m_startTimes[index] = m_timeOffset;
if (m_addAdvance)
- m_startTimes[index] += m_advanceTime.elapsed();
+ m_startTimes[index] += m_advanceTimer.elapsed();
if (randomStart)
m_startTimes[index] -= QRandomGenerator::global()->bounded(m_duration.at(index));
int time = spriteDuration(index) + m_startTimes.at(index);
if (randomStart) {
- int curTime = m_timeOffset + (m_addAdvance ? m_advanceTime.elapsed() : 0);
+ int curTime = m_timeOffset + (m_addAdvance ? m_advanceTimer.elapsed() : 0);
while (time < curTime) //Fast forward through psuedostates as needed
time += spriteDuration(index);
}
@@ -623,10 +623,10 @@ void QQuickSpriteEngine::advance(int idx) //Reimplemented to recognize and handl
}
//just go past the pseudostate logic
} else if (m_startTimes.at(idx) + m_duration.at(idx)
- > int(m_timeOffset + (m_addAdvance ? m_advanceTime.elapsed() : 0))) {
+ > int(m_timeOffset + (m_addAdvance ? m_advanceTimer.elapsed() : 0))) {
//only a pseduostate ended
emit stateChanged(idx);
- addToUpdateList(spriteStart(idx) + spriteDuration(idx) + (m_addAdvance ? m_advanceTime.elapsed() : 0), idx);
+ addToUpdateList(spriteStart(idx) + spriteDuration(idx) + (m_addAdvance ? m_advanceTimer.elapsed() : 0), idx);
return;
}
int nextIdx = nextState(m_things.at(idx), idx);
@@ -685,7 +685,7 @@ uint QQuickStochasticEngine::updateSprites(uint time)//### would returning a lis
}
m_stateUpdates.remove(0, i);
- m_advanceTime.start();
+ m_advanceTimer.start();
m_addAdvance = true;
if (m_stateUpdates.isEmpty())
return uint(-1);
diff --git a/src/quick/items/qquickspriteengine_p.h b/src/quick/items/qquickspriteengine_p.h
index d3944b4620..da505be911 100644
--- a/src/quick/items/qquickspriteengine_p.h
+++ b/src/quick/items/qquickspriteengine_p.h
@@ -58,7 +58,7 @@ QT_REQUIRE_CONFIG(quick_sprite);
#include <QObject>
#include <QVector>
#include <QTimer>
-#include <QTime>
+#include <QElapsedTimer>
#include <QList>
#include <QQmlListProperty>
#include <QImage>
@@ -254,7 +254,7 @@ protected:
QVector<int> m_startTimes;
QVector<QPair<uint, QVector<int> > > m_stateUpdates;//### This could be done faster - priority queue?
- QTime m_advanceTime;
+ QElapsedTimer m_advanceTimer;
uint m_timeOffset;
QString m_globalGoal;
int m_maxFrames;
diff --git a/src/quick/items/qquickspritesequence_p.h b/src/quick/items/qquickspritesequence_p.h
index 899ce79e0e..12c80d6a27 100644
--- a/src/quick/items/qquickspritesequence_p.h
+++ b/src/quick/items/qquickspritesequence_p.h
@@ -56,7 +56,6 @@
QT_REQUIRE_CONFIG(quick_sprite);
#include <QtQuick/QQuickItem>
-#include <QTime>
QT_BEGIN_NAMESPACE
diff --git a/src/quick/items/qquickspritesequence_p_p.h b/src/quick/items/qquickspritesequence_p_p.h
index 3579833116..4788cd15aa 100644
--- a/src/quick/items/qquickspritesequence_p_p.h
+++ b/src/quick/items/qquickspritesequence_p_p.h
@@ -57,6 +57,7 @@ QT_REQUIRE_CONFIG(quick_sprite);
#include "qquickitem_p.h"
#include "qquicksprite_p.h"
+#include <QElapsedTimer>
QT_BEGIN_NAMESPACE
@@ -78,7 +79,7 @@ public:
}
QList<QQuickSprite*> m_sprites;
QQuickSpriteEngine* m_spriteEngine;
- QTime m_timestamp;
+ QElapsedTimer m_timestamp;
int m_curFrame;
bool m_pleaseReset;
bool m_running;
diff --git a/src/quick/items/qquickstateoperations.cpp b/src/quick/items/qquickstateoperations.cpp
index fe1dfd349e..31d1c91649 100644
--- a/src/quick/items/qquickstateoperations.cpp
+++ b/src/quick/items/qquickstateoperations.cpp
@@ -200,7 +200,7 @@ QQmlScriptString QQuickParentChange::x() const
return d->xString.value;
}
-void QQuickParentChange::setX(QQmlScriptString x)
+void QQuickParentChange::setX(const QQmlScriptString &x)
{
Q_D(QQuickParentChange);
d->xString = x;
@@ -218,7 +218,7 @@ QQmlScriptString QQuickParentChange::y() const
return d->yString.value;
}
-void QQuickParentChange::setY(QQmlScriptString y)
+void QQuickParentChange::setY(const QQmlScriptString &y)
{
Q_D(QQuickParentChange);
d->yString = y;
@@ -236,7 +236,7 @@ QQmlScriptString QQuickParentChange::width() const
return d->widthString.value;
}
-void QQuickParentChange::setWidth(QQmlScriptString width)
+void QQuickParentChange::setWidth(const QQmlScriptString &width)
{
Q_D(QQuickParentChange);
d->widthString = width;
@@ -254,7 +254,7 @@ QQmlScriptString QQuickParentChange::height() const
return d->heightString.value;
}
-void QQuickParentChange::setHeight(QQmlScriptString height)
+void QQuickParentChange::setHeight(const QQmlScriptString &height)
{
Q_D(QQuickParentChange);
d->heightString = height;
@@ -272,7 +272,7 @@ QQmlScriptString QQuickParentChange::scale() const
return d->scaleString.value;
}
-void QQuickParentChange::setScale(QQmlScriptString scale)
+void QQuickParentChange::setScale(const QQmlScriptString &scale)
{
Q_D(QQuickParentChange);
d->scaleString = scale;
@@ -290,7 +290,7 @@ QQmlScriptString QQuickParentChange::rotation() const
return d->rotationString.value;
}
-void QQuickParentChange::setRotation(QQmlScriptString rotation)
+void QQuickParentChange::setRotation(const QQmlScriptString &rotation)
{
Q_D(QQuickParentChange);
d->rotationString = rotation;
diff --git a/src/quick/items/qquickstateoperations_p.h b/src/quick/items/qquickstateoperations_p.h
index e947b2213f..357366bc60 100644
--- a/src/quick/items/qquickstateoperations_p.h
+++ b/src/quick/items/qquickstateoperations_p.h
@@ -87,27 +87,27 @@ public:
QQuickItem *originalParent() const;
QQmlScriptString x() const;
- void setX(QQmlScriptString x);
+ void setX(const QQmlScriptString &x);
bool xIsSet() const;
QQmlScriptString y() const;
- void setY(QQmlScriptString y);
+ void setY(const QQmlScriptString &y);
bool yIsSet() const;
QQmlScriptString width() const;
- void setWidth(QQmlScriptString width);
+ void setWidth(const QQmlScriptString &width);
bool widthIsSet() const;
QQmlScriptString height() const;
- void setHeight(QQmlScriptString height);
+ void setHeight(const QQmlScriptString &height);
bool heightIsSet() const;
QQmlScriptString scale() const;
- void setScale(QQmlScriptString scale);
+ void setScale(const QQmlScriptString &scale);
bool scaleIsSet() const;
QQmlScriptString rotation() const;
- void setRotation(QQmlScriptString rotation);
+ void setRotation(const QQmlScriptString &rotation);
bool rotationIsSet() const;
ActionList actions() override;
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index 58cd80500c..295c6898bc 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -42,10 +42,10 @@
#include <QtCore/qtimer.h>
#include <QtCore/qdir.h>
-#include <QtQml/private/qqmldelegatemodel_p.h>
-#include <QtQml/private/qqmldelegatemodel_p_p.h>
+#include <QtQmlModels/private/qqmldelegatemodel_p.h>
+#include <QtQmlModels/private/qqmldelegatemodel_p_p.h>
#include <QtQml/private/qqmlincubator_p.h>
-#include <QtQml/private/qqmlchangeset_p.h>
+#include <QtQmlModels/private/qqmlchangeset_p.h>
#include <QtQml/qqmlinfo.h>
#include <QtQuick/private/qquickflickable_p_p.h>
@@ -53,12 +53,11 @@
/*!
\qmltype TableView
- \instantiates QQuickTableView
\inqmlmodule QtQuick
\since 5.12
\ingroup qtquick-views
\inherits Flickable
- \brief Provides a table view of items provided by the model.
+ \brief Provides a table view of items to display data from a model.
A TableView has a \l model that defines the data to be displayed, and a
\l delegate that defines how the data should be displayed.
@@ -73,25 +72,34 @@
A TableView displays data from models created from built-in QML types
such as ListModel and XmlListModel, which populates the first column only
- in a TableView. To create models with multiple columns, create a model in
- C++ that inherits QAbstractItemModel, and expose it to QML.
+ in a TableView. To create models with multiple columns, either use
+ \l TableModel or a C++ model that inherits QAbstractItemModel.
\section1 Example Usage
+ \section2 C++ Models
+
The following example shows how to create a model from C++ with multiple
columns:
- \snippet qml/tableview/tablemodel.cpp 0
+ \snippet qml/tableview/cpp-tablemodel.cpp 0
And then how to use it from QML:
- \snippet qml/tableview/tablemodel.qml 0
+ \snippet qml/tableview/cpp-tablemodel.qml 0
+
+ \section2 QML Models
+
+ For prototyping and displaying very simple data (from a web API, for
+ example), \l TableModel can be used:
+
+ \snippet qml/tableview/qml-tablemodel.qml 0
\section1 Reusing items
TableView recycles delegate items by default, instead of instantiating from
the \l delegate whenever new rows and columns are flicked into view. This
- can give a huge performance boost, depending on the complexity of the
+ approach gives a huge performance boost, depending on the complexity of the
delegate.
When an item is flicked out, it moves to the \e{reuse pool}, which is an
@@ -125,8 +133,8 @@
\section1 Row heights and column widths
When a new column is flicked into view, TableView will determine its width
- by calling the \l columnWidthProvider function. TableView itself will never
- store row height or column width, as it's designed to support large models
+ by calling the \l columnWidthProvider function. TableView does not store
+ row height or column width, as it's designed to support large models
containing any number of rows and columns. Instead, it will ask the
application whenever it needs to know.
@@ -140,9 +148,9 @@
\note The calculated width of a column is discarded when it is flicked out
of the viewport, and is recalculated if the column is flicked back in. The
calculation is always based on the items that are visible when the column
- is flicked in. This means that it can end up different each time, depending
- on which row you're at when the column enters. You should therefore have the
- same \c implicitWidth for all items in a column, or set
+ is flicked in. This means that column width can be different each time,
+ depending on which row you're at when the column enters. You should
+ therefore have the same \c implicitWidth for all items in a column, or set
\l columnWidthProvider. The same logic applies for the row height
calculation.
@@ -151,10 +159,11 @@
must call \l forceLayout. This informs TableView that it needs to use the
provider functions again to recalculate and update the layout.
- Since Qt 5.13, if you want to hide a specific column, you can return \c 0 from the
- \l columnWidthProvider for that column. Likewise, you can return 0 from the
- \l rowHeightProvider to hide a row. If you return a negative number, TableView
- will fall back to calculate the size based on the delegate items.
+ Since Qt 5.13, if you want to hide a specific column, you can return \c 0
+ from the \l columnWidthProvider for that column. Likewise, you can return 0
+ from the \l rowHeightProvider to hide a row. If you return a negative
+ number, TableView will fall back to calculate the size based on the delegate
+ items.
\note The size of a row or column should be a whole number to avoid
sub-pixel alignment of items.
@@ -168,11 +177,11 @@
\section1 Overlays and underlays
- Tableview inherits \l Flickable. And when new items are instantiated from the
- delegate, it will parent them to the \l{Flickable::}{contentItem}
- with a \c z value equal to \c 1. You can add your own items inside the
- Tableview, as child items of the Flickable. By controlling their \c z
- value, you can make them be on top of or underneath the table items.
+ All new items that are instantiated from the delegate are parented to the
+ \l{Flickable::}{contentItem} with the \c z value, \c 1. You can add your
+ own items inside the Tableview, as child items of the Flickable. By
+ controlling their \c z value, you can make them be on top of or
+ underneath the table items.
Here is an example that shows how to add some text on top of the table, that
moves together with the table as you flick:
@@ -182,6 +191,7 @@
/*!
\qmlproperty int QtQuick::TableView::rows
+ \readonly
This property holds the number of rows in the table. This is
equal to the number of rows in the model.
@@ -191,10 +201,11 @@
/*!
\qmlproperty int QtQuick::TableView::columns
+ \readonly
This property holds the number of columns in the table. This is
equal to the number of columns in the model. If the model is
- a list, columns will be 1.
+ a list, columns will be \c 1.
This property is read only.
*/
@@ -204,7 +215,7 @@
This property holds the spacing between the rows.
- The default value is 0.
+ The default value is \c 0.
*/
/*!
@@ -212,20 +223,20 @@
This property holds the spacing between the columns.
- The default value is 0.
+ The default value is \c 0.
*/
/*!
\qmlproperty var QtQuick::TableView::rowHeightProvider
This property can hold a function that returns the row height for each row
- in the model. When assigned, it will be called whenever TableView needs to
- know the height of a specific row. The function takes one argument, \c row,
- for which the TableView needs to know the height.
+ in the model. It is called whenever TableView needs to know the height of
+ a specific row. The function takes one argument, \c row, for which the
+ TableView needs to know the height.
- Since Qt 5.13, if you want to hide a specific row, you can return \c 0 height for
- that row. If you return a negative number, TableView will fall back to
- calculate the height based on the delegate items.
+ Since Qt 5.13, if you want to hide a specific row, you can return \c 0
+ height for that row. If you return a negative number, TableView calculates
+ the height based on the delegate items.
\sa columnWidthProvider, {Row heights and column widths}
*/
@@ -234,13 +245,13 @@
\qmlproperty var QtQuick::TableView::columnWidthProvider
This property can hold a function that returns the column width for each
- column in the model. When assigned, it is called whenever TableView needs
- to know the width of a specific column. The function takes one argument,
- \c column, for which the TableView needs to know the width.
+ column in the model. It is called whenever TableView needs to know the
+ width of a specific column. The function takes one argument, \c column,
+ for which the TableView needs to know the width.
- Since Qt 5.13, if you want to hide a specific column, you can return \c 0 width for
- that column. If you return a negative number, TableView will fall back to
- calculate the width based on the delegate items.
+ Since Qt 5.13, if you want to hide a specific column, you can return \c 0
+ width for that column. If you return a negative number, TableView
+ calculates the width based on the delegate items.
\sa rowHeightProvider, {Row heights and column widths}
*/
@@ -250,9 +261,9 @@
This property holds the model that provides data for the table.
The model provides the set of data that is used to create the items
- in the view. Models can be created directly in QML using \l ListModel,
- \l XmlListModel or \l ObjectModel, or provided by a custom C++ model
- class. If it is a C++ model, it must be a subclass of \l QAbstractItemModel
+ in the view. Models can be created directly in QML using \l TableModel,
+ \l ListModel, \l XmlListModel, or \l ObjectModel, or provided by a custom
+ C++ model class. The C++ model must be a subclass of \l QAbstractItemModel
or a simple list.
\sa {qml-data-models}{Data Models}
@@ -266,10 +277,9 @@
applies to \c row and \c column. Properties of the model are also available
depending upon the type of \l {qml-data-models}{Data Model}.
- A delegate should specify its size using \l [QML]{Item::implicitWidth}{implicitWidth} and
- \l [QML]{Item::implicitHeight}{implicitHeight}.
- The TableView lays out the items based on that information. Explicit width or
- height settings are ignored and overwritten.
+ A delegate should specify its size using \l{Item::}{implicitWidth} and
+ \l {Item::}{implicitHeight}. The TableView lays out the items based on that
+ information. Explicit width or height settings are ignored and overwritten.
\note Delegates are instantiated as needed and may be destroyed at any time.
They are also reused if the \l reuseItems property is set to \c true. You
@@ -291,37 +301,35 @@
/*!
\qmlproperty real QtQuick::TableView::contentWidth
- This property holds the width of the \l view, which is also
- the width of the table (including margins). As a TableView cannot
- always know the exact width of the table without loading all columns
- in the model, the \c contentWidth is usually an estimated width based on
- the columns it has seen so far. This estimate is recalculated whenever
- new columns are flicked into view, which means that the content width
- can change dynamically.
+ This property holds the table width required to accommodate the number of
+ columns in the model. This is usually not the same as the \c width of the
+ \l view, which means that the table's width could be larger or smaller than
+ the viewport width. As a TableView cannot always know the exact width of
+ the table without loading all columns in the model, the \c contentWidth is
+ usually an estimate based on the initially loaded table.
- If you know up front what the width of the table will be, assign a value
- to \c contentWidth explicitly, to avoid unnecessary calculations and
- updates to the TableView.
+ If you know what the width of the table will be, assign a value to
+ \c contentWidth, to avoid unnecessary calculations and updates to the
+ TableView.
- \sa contentHeight
+ \sa contentHeight, columnWidthProvider
*/
/*!
\qmlproperty real QtQuick::TableView::contentHeight
- This property holds the height of the \l view, which is also
- the height of the table (including margins). As a TableView cannot
- always know the exact height of the table without loading all rows
- in the model, the \c contentHeight is usually an estimated height
- based on the rows it has seen so far. This estimate is recalculated
- whenever new rows are flicked into view, which means that the content height
- can change dynamically.
+ This property holds the table height required to accommodate the number of
+ rows in the data model. This is usually not the same as the \c height of the
+ \c view, which means that the table's height could be larger or smaller than the
+ viewport height. As a TableView cannot always know the exact height of the
+ table without loading all rows in the model, the \c contentHeight is
+ usually an estimate based on the initially loaded table.
- If you know up front what the height of the table will be, assign a
- value to \c contentHeight explicitly, to avoid unnecessary calculations and
- updates to the TableView.
+ If you know what the height of the table will be, assign a
+ value to \c contentHeight, to avoid unnecessary calculations and updates to
+ the TableView.
- \sa contentWidth
+ \sa contentWidth, rowHeightProvider
*/
/*!
@@ -330,7 +338,7 @@
Responding to changes in the model are batched so that they are handled
only once per frame. This means the TableView delays showing any changes
while a script is being run. The same is also true when changing
- properties such as \l rowSpacing or \l {Item::anchors.leftMargin}{leftMargin}.
+ properties, such as \l rowSpacing or \l{Item::anchors.leftMargin}{leftMargin}.
This method forces the TableView to immediately update the layout so
that any recent changes take effect.
@@ -367,9 +375,9 @@
item has been taken out of the pool and placed inside the content view,
and the model properties such as index, row, and column have been updated.
- Other properties that are not provided by the model does not change when an item
- is reused. You should avoid storing any state inside a delegate, but if you do,
- manually reset that state on receiving this signal.
+ Other properties that are not provided by the model does not change when an
+ item is reused. You should avoid storing any state inside a delegate, but if
+ you do, manually reset that state on receiving this signal.
This signal is emitted when the item is reused, and not the first time the
item is created.
@@ -425,6 +433,10 @@ bool QQuickTableViewPrivate::EdgeRange::containsIndex(Qt::Edge edge, int index)
QQuickTableViewPrivate::QQuickTableViewPrivate()
: QQuickFlickablePrivate()
{
+ QObject::connect(&columnWidths, &QQuickTableSectionSizeProvider::sizeChanged,
+ [this] { this->forceLayout();});
+ QObject::connect(&rowHeights, &QQuickTableSectionSizeProvider::sizeChanged,
+ [this] { this->forceLayout();});
}
QQuickTableViewPrivate::~QQuickTableViewPrivate()
@@ -604,6 +616,12 @@ void QQuickTableViewPrivate::updateContentWidth()
{
Q_Q(QQuickTableView);
+ if (syncHorizontally) {
+ QBoolBlocker fixupGuard(inUpdateContentSize, true);
+ q->QQuickFlickable::setContentWidth(syncView->contentWidth());
+ return;
+ }
+
if (explicitContentWidth.isValid()) {
// Don't calculate contentWidth when it
// was set explicitly by the application.
@@ -616,6 +634,8 @@ void QQuickTableViewPrivate::updateContentWidth()
const qreal remainingSpacing = columnsRemaining * cellSpacing.width();
const qreal estimatedRemainingWidth = remainingColumnWidths + remainingSpacing;
const qreal estimatedWidth = loadedTableOuterRect.right() + estimatedRemainingWidth;
+
+ QBoolBlocker fixupGuard(inUpdateContentSize, true);
q->QQuickFlickable::setContentWidth(estimatedWidth);
}
@@ -623,6 +643,12 @@ void QQuickTableViewPrivate::updateContentHeight()
{
Q_Q(QQuickTableView);
+ if (syncVertically) {
+ QBoolBlocker fixupGuard(inUpdateContentSize, true);
+ q->QQuickFlickable::setContentHeight(syncView->contentHeight());
+ return;
+ }
+
if (explicitContentHeight.isValid()) {
// Don't calculate contentHeight when it
// was set explicitly by the application.
@@ -635,64 +661,204 @@ void QQuickTableViewPrivate::updateContentHeight()
const qreal remainingSpacing = rowsRemaining * cellSpacing.height();
const qreal estimatedRemainingHeight = remainingRowHeights + remainingSpacing;
const qreal estimatedHeight = loadedTableOuterRect.bottom() + estimatedRemainingHeight;
+
+ QBoolBlocker fixupGuard(inUpdateContentSize, true);
q->QQuickFlickable::setContentHeight(estimatedHeight);
}
-void QQuickTableViewPrivate::enforceTableAtOrigin()
+void QQuickTableViewPrivate::updateExtents()
{
- // Gaps before the first row/column can happen if rows/columns
- // changes size while flicking e.g because of spacing changes or
- // changes to a column maxWidth/row maxHeight. Check for this, and
- // move the whole table rect accordingly.
- bool layoutNeeded = false;
- const qreal flickMargin = 50;
-
- const bool noMoreColumns = nextVisibleEdgeIndexAroundLoadedTable(Qt::LeftEdge) == kEdgeIndexAtEnd;
- const bool noMoreRows = nextVisibleEdgeIndexAroundLoadedTable(Qt::TopEdge) == kEdgeIndexAtEnd;
+ // When rows or columns outside the viewport are removed or added, or a rebuild
+ // forces us to guesstimate a new top-left, the edges of the table might end up
+ // out of sync with the edges of the content view. We detect this situation here, and
+ // move the origin to ensure that there will never be gaps at the end of the table.
+ // Normally we detect that the size of the whole table is not going to be equal to the
+ // size of the content view already when we load the last row/column, and especially
+ // before it's flicked completely inside the viewport. For those cases we simply adjust
+ // the origin/endExtent, to give a smooth flicking experience.
+ // But if flicking fast (e.g with a scrollbar), it can happen that the viewport ends up
+ // outside the end of the table in just one viewport update. To avoid a "blink" in the
+ // viewport when that happens, we "move" the loaded table into the viewport to cover it.
+ Q_Q(QQuickTableView);
- if (noMoreColumns) {
- if (!qFuzzyIsNull(loadedTableOuterRect.left())) {
- // There are no more columns, but the table rect
- // is not at origin. So we move it there.
- loadedTableOuterRect.moveLeft(0);
- layoutNeeded = true;
+ bool tableMovedHorizontally = false;
+ bool tableMovedVertically = false;
+
+ const int nextLeftColumn = nextVisibleEdgeIndexAroundLoadedTable(Qt::LeftEdge);
+ const int nextRightColumn = nextVisibleEdgeIndexAroundLoadedTable(Qt::RightEdge);
+ const int nextTopRow = nextVisibleEdgeIndexAroundLoadedTable(Qt::TopEdge);
+ const int nextBottomRow = nextVisibleEdgeIndexAroundLoadedTable(Qt::BottomEdge);
+
+ if (syncHorizontally) {
+ const auto syncView_d = syncView->d_func();
+ origin.rx() = syncView_d->origin.x();
+ endExtent.rwidth() = syncView_d->endExtent.width();
+ hData.markExtentsDirty();
+ } else if (nextLeftColumn == kEdgeIndexAtEnd) {
+ // There are no more columns to load on the left side of the table.
+ // In that case, we ensure that the origin match the beginning of the table.
+ if (loadedTableOuterRect.left() > viewportRect.left()) {
+ // We have a blank area at the left end of the viewport. In that case we don't have time to
+ // wait for the viewport to move (after changing origin), since that will take an extra
+ // update cycle, which will be visible as a blink. Instead, unless the blank spot is just
+ // us overshooting, we brute force the loaded table inside the already existing viewport.
+ if (loadedTableOuterRect.left() > origin.x()) {
+ const qreal diff = loadedTableOuterRect.left() - origin.x();
+ loadedTableOuterRect.moveLeft(loadedTableOuterRect.left() - diff);
+ loadedTableInnerRect.moveLeft(loadedTableInnerRect.left() - diff);
+ tableMovedHorizontally = true;
+ }
}
- } else {
- if (loadedTableOuterRect.left() <= 0) {
- // The table rect is at origin, or outside. But we still have
- // more visible columns to the left. So we need to make some
- // space so that they can be flicked in.
- loadedTableOuterRect.moveLeft(flickMargin);
- layoutNeeded = true;
+ origin.rx() = loadedTableOuterRect.left();
+ hData.markExtentsDirty();
+ } else if (loadedTableOuterRect.left() <= origin.x() + cellSpacing.width()) {
+ // The table rect is at the origin, or outside, but we still have more
+ // visible columns to the left. So we try to guesstimate how much space
+ // the rest of the columns will occupy, and move the origin accordingly.
+ const int columnsRemaining = nextLeftColumn + 1;
+ const qreal remainingColumnWidths = columnsRemaining * averageEdgeSize.width();
+ const qreal remainingSpacing = columnsRemaining * cellSpacing.width();
+ const qreal estimatedRemainingWidth = remainingColumnWidths + remainingSpacing;
+ origin.rx() = loadedTableOuterRect.left() - estimatedRemainingWidth;
+ hData.markExtentsDirty();
+ } else if (nextRightColumn == kEdgeIndexAtEnd) {
+ // There are no more columns to load on the right side of the table.
+ // In that case, we ensure that the end of the content view match the end of the table.
+ if (loadedTableOuterRect.right() < viewportRect.right()) {
+ // We have a blank area at the right end of the viewport. In that case we don't have time to
+ // wait for the viewport to move (after changing endExtent), since that will take an extra
+ // update cycle, which will be visible as a blink. Instead, unless the blank spot is just
+ // us overshooting, we brute force the loaded table inside the already existing viewport.
+ const qreal w = qMin(viewportRect.right(), q->contentWidth() + endExtent.width());
+ if (loadedTableOuterRect.right() < w) {
+ const qreal diff = loadedTableOuterRect.right() - w;
+ loadedTableOuterRect.moveRight(loadedTableOuterRect.right() - diff);
+ loadedTableInnerRect.moveRight(loadedTableInnerRect.right() - diff);
+ tableMovedHorizontally = true;
+ }
}
- }
-
- if (noMoreRows) {
- if (!qFuzzyIsNull(loadedTableOuterRect.top())) {
- loadedTableOuterRect.moveTop(0);
- layoutNeeded = true;
+ endExtent.rwidth() = loadedTableOuterRect.right() - q->contentWidth();
+ hData.markExtentsDirty();
+ } else if (loadedTableOuterRect.right() >= q->contentWidth() + endExtent.width() - cellSpacing.width()) {
+ // The right-most column is outside the end of the content view, and we
+ // still have more visible columns in the model. This can happen if the application
+ // has set a fixed content width.
+ const int columnsRemaining = tableSize.width() - nextRightColumn;
+ const qreal remainingColumnWidths = columnsRemaining * averageEdgeSize.width();
+ const qreal remainingSpacing = columnsRemaining * cellSpacing.width();
+ const qreal estimatedRemainingWidth = remainingColumnWidths + remainingSpacing;
+ const qreal pixelsOutsideContentWidth = loadedTableOuterRect.right() - q->contentWidth();
+ endExtent.rwidth() = pixelsOutsideContentWidth + estimatedRemainingWidth;
+ hData.markExtentsDirty();
+ }
+
+ if (syncVertically) {
+ const auto syncView_d = syncView->d_func();
+ origin.ry() = syncView_d->origin.y();
+ endExtent.rheight() = syncView_d->endExtent.height();
+ vData.markExtentsDirty();
+ } else if (nextTopRow == kEdgeIndexAtEnd) {
+ // There are no more rows to load on the top side of the table.
+ // In that case, we ensure that the origin match the beginning of the table.
+ if (loadedTableOuterRect.top() > viewportRect.top()) {
+ // We have a blank area at the top of the viewport. In that case we don't have time to
+ // wait for the viewport to move (after changing origin), since that will take an extra
+ // update cycle, which will be visible as a blink. Instead, unless the blank spot is just
+ // us overshooting, we brute force the loaded table inside the already existing viewport.
+ if (loadedTableOuterRect.top() > origin.y()) {
+ const qreal diff = loadedTableOuterRect.top() - origin.y();
+ loadedTableOuterRect.moveTop(loadedTableOuterRect.top() - diff);
+ loadedTableInnerRect.moveTop(loadedTableInnerRect.top() - diff);
+ tableMovedVertically = true;
+ }
}
- } else {
- if (loadedTableOuterRect.top() <= 0) {
- loadedTableOuterRect.moveTop(flickMargin);
- layoutNeeded = true;
+ origin.ry() = loadedTableOuterRect.top();
+ vData.markExtentsDirty();
+ } else if (loadedTableOuterRect.top() <= origin.y() + cellSpacing.height()) {
+ // The table rect is at the origin, or outside, but we still have more
+ // visible rows at the top. So we try to guesstimate how much space
+ // the rest of the rows will occupy, and move the origin accordingly.
+ const int rowsRemaining = nextTopRow + 1;
+ const qreal remainingRowHeights = rowsRemaining * averageEdgeSize.height();
+ const qreal remainingSpacing = rowsRemaining * cellSpacing.height();
+ const qreal estimatedRemainingHeight = remainingRowHeights + remainingSpacing;
+ origin.ry() = loadedTableOuterRect.top() - estimatedRemainingHeight;
+ vData.markExtentsDirty();
+ } else if (nextBottomRow == kEdgeIndexAtEnd) {
+ // There are no more rows to load on the bottom side of the table.
+ // In that case, we ensure that the end of the content view match the end of the table.
+ if (loadedTableOuterRect.bottom() < viewportRect.bottom()) {
+ // We have a blank area at the bottom of the viewport. In that case we don't have time to
+ // wait for the viewport to move (after changing endExtent), since that will take an extra
+ // update cycle, which will be visible as a blink. Instead, unless the blank spot is just
+ // us overshooting, we brute force the loaded table inside the already existing viewport.
+ const qreal h = qMin(viewportRect.bottom(), q->contentHeight() + endExtent.height());
+ if (loadedTableOuterRect.bottom() < h) {
+ const qreal diff = loadedTableOuterRect.bottom() - h;
+ loadedTableOuterRect.moveBottom(loadedTableOuterRect.bottom() - diff);
+ loadedTableInnerRect.moveBottom(loadedTableInnerRect.bottom() - diff);
+ tableMovedVertically = true;
+ }
+ }
+ endExtent.rheight() = loadedTableOuterRect.bottom() - q->contentHeight();
+ vData.markExtentsDirty();
+ } else if (loadedTableOuterRect.bottom() >= q->contentHeight() + endExtent.height() - cellSpacing.height()) {
+ // The bottom-most row is outside the end of the content view, and we
+ // still have more visible rows in the model. This can happen if the application
+ // has set a fixed content height.
+ const int rowsRemaining = tableSize.height() - nextBottomRow;
+ const qreal remainingRowHeigts = rowsRemaining * averageEdgeSize.height();
+ const qreal remainingSpacing = rowsRemaining * cellSpacing.height();
+ const qreal estimatedRemainingHeight = remainingRowHeigts + remainingSpacing;
+ const qreal pixelsOutsideContentHeight = loadedTableOuterRect.bottom() - q->contentHeight();
+ endExtent.rheight() = pixelsOutsideContentHeight + estimatedRemainingHeight;
+ vData.markExtentsDirty();
+ }
+
+ if (tableMovedHorizontally || tableMovedVertically) {
+ qCDebug(lcTableViewDelegateLifecycle) << "move table to" << loadedTableOuterRect;
+
+ // relayoutTableItems() will take care of moving the existing
+ // delegate items into the new loadedTableOuterRect.
+ relayoutTableItems();
+
+ // Inform the sync children that they need to rebuild to stay in sync
+ for (auto syncChild : qAsConst(syncChildren)) {
+ auto syncChild_d = syncChild->d_func();
+ syncChild_d->scheduledRebuildOptions |= RebuildOption::ViewportOnly;
+ if (tableMovedHorizontally)
+ syncChild_d->scheduledRebuildOptions |= RebuildOption::CalculateNewTopLeftColumn;
+ if (tableMovedVertically)
+ syncChild_d->scheduledRebuildOptions |= RebuildOption::CalculateNewTopLeftRow;
}
}
- if (layoutNeeded) {
- qCDebug(lcTableViewDelegateLifecycle);
- relayoutTableItems();
+ if (hData.minExtentDirty || vData.minExtentDirty) {
+ qCDebug(lcTableViewDelegateLifecycle) << "move origin and endExtent to:" << origin << endExtent;
+ // updateBeginningEnd() will let the new extents take effect. This will also change the
+ // visualArea of the flickable, which again will cause any attached scrollbars to adjust
+ // the position of the handle. Note the latter will cause the viewport to move once more.
+ updateBeginningEnd();
}
}
void QQuickTableViewPrivate::updateAverageEdgeSize()
{
- const int loadedRowCount = loadedRows.count();
- const int loadedColumnCount = loadedColumns.count();
- const qreal accRowSpacing = (loadedRowCount - 1) * cellSpacing.height();
- const qreal accColumnSpacing = (loadedColumnCount - 1) * cellSpacing.width();
- averageEdgeSize.setHeight((loadedTableOuterRect.height() - accRowSpacing) / loadedRowCount);
- averageEdgeSize.setWidth((loadedTableOuterRect.width() - accColumnSpacing) / loadedColumnCount);
+ if (explicitContentWidth.isValid()) {
+ const qreal accColumnSpacing = (tableSize.width() - 1) * cellSpacing.width();
+ averageEdgeSize.setWidth((explicitContentWidth - accColumnSpacing) / tableSize.width());
+ } else {
+ const qreal accColumnSpacing = (loadedColumns.count() - 1) * cellSpacing.width();
+ averageEdgeSize.setWidth((loadedTableOuterRect.width() - accColumnSpacing) / loadedColumns.count());
+ }
+
+ if (explicitContentHeight.isValid()) {
+ const qreal accRowSpacing = (tableSize.height() - 1) * cellSpacing.height();
+ averageEdgeSize.setHeight((explicitContentHeight - accRowSpacing) / tableSize.height());
+ } else {
+ const qreal accRowSpacing = (loadedRows.count() - 1) * cellSpacing.height();
+ averageEdgeSize.setHeight((loadedTableOuterRect.height() - accRowSpacing) / loadedRows.count());
+ }
}
void QQuickTableViewPrivate::syncLoadedTableRectFromLoadedTable()
@@ -710,9 +876,8 @@ void QQuickTableViewPrivate::forceLayout()
if (loadedItems.isEmpty())
return;
- columnRowPositionsInvalid = true;
clearEdgeSizeCache();
- RebuildOptions rebuildOptions = RebuildOption::None;
+ RebuildOptions rebuildOptions = RebuildOption::LayoutOnly;
// Go through all columns from first to last, find the columns that used
// to be hidden and not loaded, and check if they should become visible
@@ -751,16 +916,14 @@ void QQuickTableViewPrivate::forceLayout()
break;
}
- if (rebuildOptions)
- scheduleRebuildTable(rebuildOptions);
+ scheduleRebuildTable(rebuildOptions);
- if (polishing) {
+ auto rootView = rootSyncView();
+ const bool updated = rootView->d_func()->updateTableRecursive();
+ if (!updated) {
qWarning() << "TableView::forceLayout(): Cannot do an immediate re-layout during an ongoing layout!";
- q_func()->polish();
- return;
+ rootView->polish();
}
-
- updatePolish();
}
void QQuickTableViewPrivate::syncLoadedTableFromLoadRequest()
@@ -1051,6 +1214,11 @@ qreal QQuickTableViewPrivate::getColumnLayoutWidth(int column)
if (explicitColumnWidth >= 0)
return explicitColumnWidth;
+ if (syncHorizontally) {
+ if (syncView->d_func()->loadedColumns.contains(column))
+ return syncView->d_func()->getColumnLayoutWidth(column);
+ }
+
// Iterate over the currently visible items in the column. The downside
// of doing that, is that the column width will then only be based on the implicit
// width of the currently loaded items (which can be different depending on which
@@ -1080,6 +1248,11 @@ qreal QQuickTableViewPrivate::getRowLayoutHeight(int row)
if (explicitRowHeight >= 0)
return explicitRowHeight;
+ if (syncVertically) {
+ if (syncView->d_func()->loadedRows.contains(row))
+ return syncView->d_func()->getRowLayoutHeight(row);
+ }
+
// Iterate over the currently visible items in the row. The downside
// of doing that, is that the row height will then only be based on the implicit
// height of the currently loaded items (which can be different depending on which
@@ -1109,6 +1282,13 @@ qreal QQuickTableViewPrivate::getColumnWidth(int column)
if (cachedColumnWidth.startIndex == column)
return cachedColumnWidth.size;
+ if (syncHorizontally)
+ return syncView->d_func()->getColumnWidth(column);
+
+ auto cw = columnWidths.size(column);
+ if (cw >= 0)
+ return cw;
+
if (columnWidthProvider.isUndefined())
return noExplicitColumnWidth;
@@ -1143,6 +1323,13 @@ qreal QQuickTableViewPrivate::getRowHeight(int row)
if (cachedRowHeight.startIndex == row)
return cachedRowHeight.size;
+ if (syncVertically)
+ return syncView->d_func()->getRowHeight(row);
+
+ auto rh = rowHeights.size(row);
+ if (rh >= 0)
+ return rh;
+
if (rowHeightProvider.isUndefined())
return noExplicitRowHeight;
@@ -1180,23 +1367,9 @@ bool QQuickTableViewPrivate::isRowHidden(int row)
return qFuzzyIsNull(getRowHeight(row));
}
-void QQuickTableViewPrivate::relayoutTable()
-{
- clearEdgeSizeCache();
- relayoutTableItems();
- syncLoadedTableRectFromLoadedTable();
- enforceTableAtOrigin();
- updateContentWidth();
- updateContentHeight();
- // Return back to updatePolish to loadAndUnloadVisibleEdges()
- // since the re-layout might have caused some edges to be pushed
- // out, while others might have been pushed in.
-}
-
void QQuickTableViewPrivate::relayoutTableItems()
{
qCDebug(lcTableViewDelegateLifecycle);
- columnRowPositionsInvalid = false;
qreal nextColumnX = loadedTableOuterRect.x();
qreal nextRowY = loadedTableOuterRect.y();
@@ -1378,20 +1551,7 @@ void QQuickTableViewPrivate::processLoadRequest()
if (rebuildState == RebuildState::Done) {
// Loading of this edge was not done as a part of a rebuild, but
// instead as an incremental build after e.g a flick.
- switch (loadRequest.edge()) {
- case Qt::LeftEdge:
- case Qt::TopEdge:
- enforceTableAtOrigin();
- break;
- case Qt::RightEdge:
- updateAverageEdgeSize();
- updateContentWidth();
- break;
- case Qt::BottomEdge:
- updateAverageEdgeSize();
- updateContentHeight();
- break;
- }
+ updateExtents();
drainReusePoolAfterLoadRequest();
}
@@ -1402,6 +1562,22 @@ void QQuickTableViewPrivate::processLoadRequest()
void QQuickTableViewPrivate::processRebuildTable()
{
+ Q_Q(QQuickTableView);
+
+ if (rebuildState == RebuildState::Begin) {
+ if (Q_UNLIKELY(lcTableViewDelegateLifecycle().isDebugEnabled())) {
+ qCDebug(lcTableViewDelegateLifecycle()) << "begin rebuild:" << q;
+ if (rebuildOptions & RebuildOption::All)
+ qCDebug(lcTableViewDelegateLifecycle()) << "RebuildOption::All, options:" << rebuildOptions;
+ else if (rebuildOptions & RebuildOption::ViewportOnly)
+ qCDebug(lcTableViewDelegateLifecycle()) << "RebuildOption::ViewportOnly, options:" << rebuildOptions;
+ else if (rebuildOptions & RebuildOption::LayoutOnly)
+ qCDebug(lcTableViewDelegateLifecycle()) << "RebuildOption::LayoutOnly, options:" << rebuildOptions;
+ else
+ Q_TABLEVIEW_UNREACHABLE(rebuildOptions);
+ }
+ }
+
moveToNextRebuildState();
if (rebuildState == RebuildState::LoadInitalTable) {
@@ -1412,12 +1588,11 @@ void QQuickTableViewPrivate::processRebuildTable()
if (rebuildState == RebuildState::VerifyTable) {
if (loadedItems.isEmpty()) {
- qCDebug(lcTableViewDelegateLifecycle()) << "no items loaded, meaning empty model, all rows or columns hidden, or no delegate";
+ qCDebug(lcTableViewDelegateLifecycle()) << "no items loaded!";
rebuildState = RebuildState::Done;
+ } else if (!moveToNextRebuildState()) {
return;
}
- if (!moveToNextRebuildState())
- return;
}
if (rebuildState == RebuildState::LayoutTable) {
@@ -1457,6 +1632,7 @@ void QQuickTableViewPrivate::processRebuildTable()
}
Q_TABLEVIEW_ASSERT(rebuildState == RebuildState::Done, int(rebuildState));
+ qCDebug(lcTableViewDelegateLifecycle()) << "rebuild complete:" << q;
}
bool QQuickTableViewPrivate::moveToNextRebuildState()
@@ -1466,53 +1642,114 @@ bool QQuickTableViewPrivate::moveToNextRebuildState()
// that the current state is not yet done.
return false;
}
- rebuildState = RebuildState(int(rebuildState) + 1);
- qCDebug(lcTableViewDelegateLifecycle()) << int(rebuildState);
- return true;
-}
-QPoint QQuickTableViewPrivate::calculateNewTopLeft()
-{
- const int firstVisibleLeft = nextVisibleEdgeIndex(Qt::RightEdge, 0);
- const int firstVisibleTop = nextVisibleEdgeIndex(Qt::BottomEdge, 0);
+ if (rebuildState == RebuildState::Begin
+ && rebuildOptions.testFlag(RebuildOption::LayoutOnly))
+ rebuildState = RebuildState::LayoutTable;
+ else
+ rebuildState = RebuildState(int(rebuildState) + 1);
- return QPoint(firstVisibleLeft, firstVisibleTop);
+ qCDebug(lcTableViewDelegateLifecycle()) << int(rebuildState);
+ return true;
}
-void QQuickTableViewPrivate::calculateTopLeft(QPoint &topLeft, QPointF &topLeftPos)
+void QQuickTableViewPrivate::calculateTopLeft(QPoint &topLeftCell, QPointF &topLeftPos)
{
if (tableSize.isEmpty()) {
- releaseLoadedItems(QQmlTableInstanceModel::NotReusable);
- topLeft = QPoint(kEdgeIndexAtEnd, kEdgeIndexAtEnd);
+ // There is no cell that can be top left
+ topLeftCell.rx() = kEdgeIndexAtEnd;
+ topLeftCell.ry() = kEdgeIndexAtEnd;
return;
}
- if (rebuildOptions & RebuildOption::All) {
- qCDebug(lcTableViewDelegateLifecycle()) << "RebuildOption::All";
- releaseLoadedItems(QQmlTableInstanceModel::NotReusable);
- topLeft = calculateNewTopLeft();
- } else if (rebuildOptions & RebuildOption::ViewportOnly) {
- qCDebug(lcTableViewDelegateLifecycle()) << "RebuildOption::ViewportOnly";
- releaseLoadedItems(reusableFlag);
+ if (syncHorizontally || syncVertically) {
+ const auto syncView_d = syncView->d_func();
- if (rebuildOptions & RebuildOption::CalculateNewTopLeftRow) {
- const int newRow = int(viewportRect.y() / (averageEdgeSize.height() + cellSpacing.height()));
- topLeft.ry() = qBound(0, newRow, tableSize.height() - 1);
- topLeftPos.ry() = topLeft.y() * (averageEdgeSize.height() + cellSpacing.height());
- } else {
- topLeft.ry() = qBound(0, topRow(), tableSize.height() - 1);
- topLeftPos.ry() = loadedTableOuterRect.topLeft().y();
+ if (syncView_d->loadedItems.isEmpty()) {
+ // The sync view contains no loaded items. This probably means
+ // that it has not been rebuilt yet. Which also means that
+ // we cannot rebuild anything before this happens.
+ topLeftCell.rx() = kEdgeIndexNotSet;
+ topLeftCell.ry() = kEdgeIndexNotSet;
+ return;
+ }
+
+ // Get sync view top left, and use that as our own top left (if possible)
+ const QPoint syncViewTopLeftCell(syncView_d->leftColumn(), syncView_d->topRow());
+ const auto syncViewTopLeftFxItem = syncView_d->loadedTableItem(syncViewTopLeftCell);
+ const QPointF syncViewTopLeftPos = syncViewTopLeftFxItem->geometry().topLeft();
+
+ if (syncHorizontally) {
+ topLeftCell.rx() = syncViewTopLeftCell.x();
+ topLeftPos.rx() = syncViewTopLeftPos.x();
+
+ if (topLeftCell.x() >= tableSize.width()) {
+ // Top left is outside our own model.
+ topLeftCell.rx() = kEdgeIndexAtEnd;
+ topLeftPos.rx() = kEdgeIndexAtEnd;
+ }
+ }
+
+ if (syncVertically) {
+ topLeftCell.ry() = syncViewTopLeftCell.y();
+ topLeftPos.ry() = syncViewTopLeftPos.y();
+
+ if (topLeftCell.y() >= tableSize.height()) {
+ // Top left is outside our own model.
+ topLeftCell.ry() = kEdgeIndexAtEnd;
+ topLeftPos.ry() = kEdgeIndexAtEnd;
+ }
}
- if (rebuildOptions & RebuildOption::CalculateNewTopLeftColumn) {
+
+ if (syncHorizontally && syncVertically) {
+ // We have a valid top left, so we're done
+ return;
+ }
+ }
+
+ // Since we're not sync-ing both horizontal and vertical, calculate the missing
+ // dimention(s) ourself. If we rebuild all, we find the first visible top-left
+ // item starting from cell(0, 0). Otherwise, guesstimate which row or column that
+ // should be the new top-left given the geometry of the viewport.
+
+ if (!syncHorizontally) {
+ if (rebuildOptions & RebuildOption::All) {
+ // Find the first visible column from the beginning
+ topLeftCell.rx() = nextVisibleEdgeIndex(Qt::RightEdge, 0);
+ if (topLeftCell.x() == kEdgeIndexAtEnd) {
+ // No visible column found
+ return;
+ }
+ } else if (rebuildOptions & RebuildOption::CalculateNewTopLeftColumn) {
+ // Guesstimate new top left
const int newColumn = int(viewportRect.x() / (averageEdgeSize.width() + cellSpacing.width()));
- topLeft.rx() = qBound(0, newColumn, tableSize.width() - 1);
- topLeftPos.rx() = topLeft.x() * (averageEdgeSize.width() + cellSpacing.width());
+ topLeftCell.rx() = qBound(0, newColumn, tableSize.width() - 1);
+ topLeftPos.rx() = topLeftCell.x() * (averageEdgeSize.width() + cellSpacing.width());
} else {
- topLeft.rx() = qBound(0, leftColumn(), tableSize.width() - 1);
+ // Keep the current top left, unless it's outside model
+ topLeftCell.rx() = qBound(0, leftColumn(), tableSize.width() - 1);
topLeftPos.rx() = loadedTableOuterRect.topLeft().x();
}
- } else {
- Q_TABLEVIEW_UNREACHABLE(rebuildOptions);
+ }
+
+ if (!syncVertically) {
+ if (rebuildOptions & RebuildOption::All) {
+ // Find the first visible row from the beginning
+ topLeftCell.ry() = nextVisibleEdgeIndex(Qt::BottomEdge, 0);
+ if (topLeftCell.y() == kEdgeIndexAtEnd) {
+ // No visible row found
+ return;
+ }
+ } else if (rebuildOptions & RebuildOption::CalculateNewTopLeftRow) {
+ // Guesstimate new top left
+ const int newRow = int(viewportRect.y() / (averageEdgeSize.height() + cellSpacing.height()));
+ topLeftCell.ry() = qBound(0, newRow, tableSize.height() - 1);
+ topLeftPos.ry() = topLeftCell.y() * (averageEdgeSize.height() + cellSpacing.height());
+ } else {
+ // Keep the current top left, unless it's outside model
+ topLeftCell.ry() = qBound(0, topRow(), tableSize.height() - 1);
+ topLeftPos.ry() = loadedTableOuterRect.topLeft().y();
+ }
}
}
@@ -1524,41 +1761,91 @@ void QQuickTableViewPrivate::beginRebuildTable()
QPointF topLeftPos;
calculateTopLeft(topLeft, topLeftPos);
+ if (rebuildOptions & RebuildOption::All)
+ releaseLoadedItems(QQmlTableInstanceModel::NotReusable);
+ else if (rebuildOptions & RebuildOption::ViewportOnly)
+ releaseLoadedItems(reusableFlag);
+
+ if (rebuildOptions & RebuildOption::All) {
+ origin = QPointF(0, 0);
+ endExtent = QSizeF(0, 0);
+ hData.markExtentsDirty();
+ vData.markExtentsDirty();
+ updateBeginningEnd();
+ }
+
loadedColumns.clear();
loadedRows.clear();
loadedTableOuterRect = QRect();
loadedTableInnerRect = QRect();
- columnRowPositionsInvalid = false;
clearEdgeSizeCache();
- if (topLeft.x() == kEdgeIndexAtEnd || topLeft.y() == kEdgeIndexAtEnd) {
- // No visible columns or rows, so nothing to load
+ if (syncHorizontally) {
+ setLocalViewportX(syncView->contentX());
+ viewportRect.moveLeft(syncView->d_func()->viewportRect.left());
+ }
+
+ if (syncVertically) {
+ setLocalViewportY(syncView->contentY());
+ viewportRect.moveTop(syncView->d_func()->viewportRect.top());
+ }
+
+ if (!model) {
+ qCDebug(lcTableViewDelegateLifecycle()) << "no model found, leaving table empty";
return;
}
- loadInitialTopLeftItem(topLeft, topLeftPos);
- loadAndUnloadVisibleEdges();
-}
+ if (model->count() == 0) {
+ qCDebug(lcTableViewDelegateLifecycle()) << "empty model found, leaving table empty";
+ return;
+ }
-void QQuickTableViewPrivate::layoutAfterLoadingInitialTable()
-{
- relayoutTable();
- updateAverageEdgeSize();
- updateContentWidth();
- updateContentHeight();
-}
+ if (tableModel && !tableModel->delegate()) {
+ qCDebug(lcTableViewDelegateLifecycle()) << "no delegate found, leaving table empty";
+ return;
+ }
-void QQuickTableViewPrivate::loadInitialTopLeftItem(const QPoint &cell, const QPointF &pos)
-{
- Q_TABLEVIEW_ASSERT(loadedItems.isEmpty(), "");
+ if (topLeft.x() == kEdgeIndexAtEnd || topLeft.y() == kEdgeIndexAtEnd) {
+ qCDebug(lcTableViewDelegateLifecycle()) << "no visible row or column found, leaving table empty";
+ return;
+ }
- if (tableModel && !tableModel->delegate())
+ if (topLeft.x() == kEdgeIndexNotSet || topLeft.y() == kEdgeIndexNotSet) {
+ qCDebug(lcTableViewDelegateLifecycle()) << "could not resolve top-left item, leaving table empty";
return;
+ }
// Load top-left item. After loaded, loadItemsInsideRect() will take
// care of filling out the rest of the table.
- loadRequest.begin(cell, pos, QQmlIncubator::AsynchronousIfNested);
+ loadRequest.begin(topLeft, topLeftPos, QQmlIncubator::AsynchronousIfNested);
processLoadRequest();
+ loadAndUnloadVisibleEdges();
+}
+
+void QQuickTableViewPrivate::layoutAfterLoadingInitialTable()
+{
+ clearEdgeSizeCache();
+ relayoutTableItems();
+ syncLoadedTableRectFromLoadedTable();
+
+ if (syncView || rebuildOptions.testFlag(RebuildOption::All)) {
+ // We try to limit how often we update the content size. The main reason is that is has a
+ // tendency to cause flicker in the viewport if it happens while flicking. But another just
+ // as valid reason is that we actually never really know what the size of the full table will
+ // ever be. Even if e.g spacing changes, and we normally would assume that the size of the table
+ // would increase accordingly, the model might also at some point have removed/hidden/resized
+ // rows/columns outside the viewport. This would also affect the size, but since we don't load
+ // rows or columns outside the viewport, this information is ignored. And even if we did, we
+ // might also have been fast-flicked to a new location at some point, and started a new rebuild
+ // there based on a new guesstimated top-left cell. Either way, changing the content size
+ // based on the currently visible row/columns/spacing can be really off. So instead of pretending
+ // that we know what the actual size of the table is, we just keep the first guesstimate.
+ updateAverageEdgeSize();
+ updateContentWidth();
+ updateContentHeight();
+ }
+
+ updateExtents();
}
void QQuickTableViewPrivate::unloadEdge(Qt::Edge edge)
@@ -1573,8 +1860,6 @@ void QQuickTableViewPrivate::unloadEdge(Qt::Edge edge)
unloadItem(QPoint(column, r.key()));
loadedColumns.remove(column);
syncLoadedTableRectFromLoadedTable();
- updateAverageEdgeSize();
- updateContentWidth();
break; }
case Qt::TopEdge:
case Qt::BottomEdge: {
@@ -1583,8 +1868,6 @@ void QQuickTableViewPrivate::unloadEdge(Qt::Edge edge)
unloadItem(QPoint(c.key(), row));
loadedRows.remove(row);
syncLoadedTableRectFromLoadedTable();
- updateAverageEdgeSize();
- updateContentHeight();
break; }
}
@@ -1697,21 +1980,63 @@ void QQuickTableViewPrivate::scheduleRebuildTable(RebuildOptions options) {
return;
}
- rebuildScheduled = true;
scheduledRebuildOptions |= options;
q_func()->polish();
}
-void QQuickTableViewPrivate::invalidateColumnRowPositions() {
- columnRowPositionsInvalid = true;
- q_func()->polish();
+QQuickTableView *QQuickTableViewPrivate::rootSyncView() const
+{
+ QQuickTableView *root = const_cast<QQuickTableView *>(q_func());
+ while (QQuickTableView *view = root->d_func()->syncView)
+ root = view;
+ return root;
}
void QQuickTableViewPrivate::updatePolish()
{
+ // We always start updating from the top of the syncView tree, since
+ // the layout of a syncView child will depend on the layout of the syncView.
+ // E.g when a new column is flicked in, the syncView should load and layout
+ // the column first, before any syncChildren gets a chance to do the same.
+ Q_TABLEVIEW_ASSERT(!polishing, "recursive updatePolish() calls are not allowed!");
+ rootSyncView()->d_func()->updateTableRecursive();
+}
+
+bool QQuickTableViewPrivate::updateTableRecursive()
+{
+ if (polishing) {
+ // We're already updating the Table in this view, so
+ // we cannot continue. Signal this back by returning false.
+ // The caller can then choose to call "polish()" instead, to
+ // do the update later.
+ return false;
+ }
+
+ const bool updateComplete = updateTable();
+ if (!updateComplete)
+ return false;
+
+ for (auto syncChild : qAsConst(syncChildren)) {
+ auto syncChild_d = syncChild->d_func();
+ syncChild_d->scheduledRebuildOptions |= rebuildOptions;
+
+ const bool descendantUpdateComplete = syncChild_d->updateTableRecursive();
+ if (!descendantUpdateComplete)
+ return false;
+ }
+
+ rebuildOptions = RebuildOption::None;
+
+ return true;
+}
+
+bool QQuickTableViewPrivate::updateTable()
+{
// Whenever something changes, e.g viewport moves, spacing is set to a
// new value, model changes etc, this function will end up being called. Here
// we check what needs to be done, and load/unload cells accordingly.
+ // If we cannot complete the update (because we need to wait for an item
+ // to load async), we return false.
Q_TABLEVIEW_ASSERT(!polishing, "recursive updatePolish() calls are not allowed!");
QBoolBlocker polishGuard(polishing, true);
@@ -1721,38 +2046,42 @@ void QQuickTableViewPrivate::updatePolish()
// as an atomic operation, which means that we don't continue doing anything else until all
// items have been received and laid out. Note that updatePolish is then called once more
// after the loadRequest has completed to handle anything that might have occurred in-between.
- return;
+ return false;
}
if (rebuildState != RebuildState::Done) {
processRebuildTable();
- return;
+ return rebuildState == RebuildState::Done;
}
syncWithPendingChanges();
if (rebuildState == RebuildState::Begin) {
processRebuildTable();
- return;
+ return rebuildState == RebuildState::Done;
}
if (loadedItems.isEmpty())
- return;
-
- if (columnRowPositionsInvalid) {
- relayoutTable();
- updateAverageEdgeSize();
- updateContentWidth();
- updateContentHeight();
- }
+ return !loadRequest.isActive();
loadAndUnloadVisibleEdges();
+
+ return !loadRequest.isActive();
}
void QQuickTableViewPrivate::fixup(QQuickFlickablePrivate::AxisData &data, qreal minExtent, qreal maxExtent)
{
- if (rebuildScheduled || rebuildState != RebuildState::Done)
+ if (inUpdateContentSize) {
+ // We update the content size dynamically as we load and unload edges.
+ // Unfortunately, this also triggers a call to this function. The base
+ // implementation will do things like start a momentum animation or move
+ // the content view somewhere else, which causes glitches. This can
+ // especially happen if flicking on one of the syncView children, which triggers
+ // an update to our content size. In that case, the base implementation don't know
+ // that the view is being indirectly dragged, and will therefore do strange things as
+ // it tries to 'fixup' the geometry. So we use a guard to prevent this from happening.
return;
+ }
QQuickFlickablePrivate::fixup(data, minExtent, maxExtent);
}
@@ -1836,25 +2165,32 @@ void QQuickTableViewPrivate::syncWithPendingChanges()
// such assignments into effect until we're in a state that allows it.
Q_Q(QQuickTableView);
viewportRect = QRectF(q->contentX(), q->contentY(), q->width(), q->height());
- syncRebuildOptions();
+
syncModel();
syncDelegate();
+ syncSyncView();
+
+ syncRebuildOptions();
}
void QQuickTableViewPrivate::syncRebuildOptions()
{
- if (!rebuildScheduled)
+ if (!scheduledRebuildOptions)
return;
rebuildState = RebuildState::Begin;
rebuildOptions = scheduledRebuildOptions;
scheduledRebuildOptions = RebuildOption::None;
- rebuildScheduled = false;
- if (loadedItems.isEmpty()) {
- // If we have no items from before, we cannot just rebuild the viewport, but need
- // to rebuild everything, since we have no top-left loaded item to start from.
+ if (loadedItems.isEmpty())
rebuildOptions.setFlag(RebuildOption::All);
+
+ // Some options are exclusive:
+ if (rebuildOptions.testFlag(RebuildOption::All)) {
+ rebuildOptions.setFlag(RebuildOption::ViewportOnly, false);
+ rebuildOptions.setFlag(RebuildOption::LayoutOnly, false);
+ } else if (rebuildOptions.testFlag(RebuildOption::ViewportOnly)) {
+ rebuildOptions.setFlag(RebuildOption::LayoutOnly, false);
}
}
@@ -1899,6 +2235,60 @@ void QQuickTableViewPrivate::syncModel()
connectToModel();
}
+void QQuickTableViewPrivate::syncSyncView()
+{
+ Q_Q(QQuickTableView);
+
+ if (assignedSyncView != syncView) {
+ if (syncView)
+ syncView->d_func()->syncChildren.removeOne(q);
+
+ if (assignedSyncView) {
+ QQuickTableView *view = assignedSyncView;
+
+ while (view) {
+ if (view == q) {
+ if (!layoutWarningIssued) {
+ layoutWarningIssued = true;
+ qmlWarning(q) << "TableView: recursive syncView connection detected!";
+ }
+ syncView = nullptr;
+ return;
+ }
+ view = view->d_func()->syncView;
+ }
+
+ assignedSyncView->d_func()->syncChildren.append(q);
+ scheduledRebuildOptions |= RebuildOption::ViewportOnly;
+ }
+
+ syncView = assignedSyncView;
+ }
+
+ syncHorizontally = syncView && assignedSyncDirection & Qt::Horizontal;
+ syncVertically = syncView && assignedSyncDirection & Qt::Vertical;
+
+ if (syncHorizontally)
+ q->setColumnSpacing(syncView->columnSpacing());
+ if (syncVertically)
+ q->setRowSpacing(syncView->rowSpacing());
+
+ if (syncView && loadedItems.isEmpty() && !tableSize.isEmpty()) {
+ // When we have a syncView, we can sometimes temporarily end up with no loaded items.
+ // This can happen if the syncView has a model with more rows or columns than us, in
+ // which case the viewport can end up in a place where we have no rows or columns to
+ // show. In that case, check now if the viewport has been flicked back again, and
+ // that we can rebuild the table with a visible top-left cell.
+ const auto syncView_d = syncView->d_func();
+ if (!syncView_d->loadedItems.isEmpty()) {
+ if (syncHorizontally && syncView_d->leftColumn() <= tableSize.width() - 1)
+ scheduledRebuildOptions |= QQuickTableViewPrivate::RebuildOption::ViewportOnly;
+ else if (syncVertically && syncView_d->topRow() <= tableSize.height() - 1)
+ scheduledRebuildOptions |= QQuickTableViewPrivate::RebuildOption::ViewportOnly;
+ }
+ }
+}
+
void QQuickTableViewPrivate::connectToModel()
{
Q_TABLEVIEW_ASSERT(model, "");
@@ -2028,6 +2418,83 @@ void QQuickTableViewPrivate::modelResetCallback()
scheduleRebuildTable(RebuildOption::All);
}
+void QQuickTableViewPrivate::scheduleRebuildIfFastFlick()
+{
+ Q_Q(QQuickTableView);
+ // If the viewport has moved more than one page vertically or horizontally, we switch
+ // strategy from refilling edges around the current table to instead rebuild the table
+ // from scratch inside the new viewport. This will greatly improve performance when flicking
+ // a long distance in one go, which can easily happen when dragging on scrollbars.
+
+ // Check the viewport moved more than one page vertically
+ if (!viewportRect.intersects(QRectF(viewportRect.x(), q->contentY(), 1, q->height()))) {
+ scheduledRebuildOptions |= RebuildOption::CalculateNewTopLeftRow;
+ scheduledRebuildOptions |= RebuildOption::ViewportOnly;
+ }
+
+ // Check the viewport moved more than one page horizontally
+ if (!viewportRect.intersects(QRectF(q->contentX(), viewportRect.y(), q->width(), 1))) {
+ scheduledRebuildOptions |= RebuildOption::CalculateNewTopLeftColumn;
+ scheduledRebuildOptions |= RebuildOption::ViewportOnly;
+ }
+}
+
+void QQuickTableViewPrivate::setLocalViewportX(qreal contentX)
+{
+ // Set the new viewport position if changed, but don't trigger any
+ // rebuilds or updates. We use this function internally to distinguish
+ // external flicking from internal sync-ing of the content view.
+ Q_Q(QQuickTableView);
+ QBoolBlocker blocker(inSetLocalViewportPos, true);
+
+ if (qFuzzyCompare(contentX, q->contentX()))
+ return;
+
+ q->setContentX(contentX);
+}
+
+void QQuickTableViewPrivate::setLocalViewportY(qreal contentY)
+{
+ // Set the new viewport position if changed, but don't trigger any
+ // rebuilds or updates. We use this function internally to distinguish
+ // external flicking from internal sync-ing of the content view.
+ Q_Q(QQuickTableView);
+ QBoolBlocker blocker(inSetLocalViewportPos, true);
+
+ if (qFuzzyCompare(contentY, q->contentY()))
+ return;
+
+ q->setContentY(contentY);
+}
+
+void QQuickTableViewPrivate::syncViewportPosRecursive()
+{
+ Q_Q(QQuickTableView);
+ QBoolBlocker recursionGuard(inSyncViewportPosRecursive, true);
+
+ if (syncView) {
+ auto syncView_d = syncView->d_func();
+ if (!syncView_d->inSyncViewportPosRecursive) {
+ if (syncHorizontally)
+ syncView_d->setLocalViewportX(q->contentX());
+ if (syncVertically)
+ syncView_d->setLocalViewportY(q->contentY());
+ syncView_d->syncViewportPosRecursive();
+ }
+ }
+
+ for (auto syncChild : qAsConst(syncChildren)) {
+ auto syncChild_d = syncChild->d_func();
+ if (!syncChild_d->inSyncViewportPosRecursive) {
+ if (syncChild_d->syncHorizontally)
+ syncChild_d->setLocalViewportX(q->contentX());
+ if (syncChild_d->syncVertically)
+ syncChild_d->setLocalViewportY(q->contentY());
+ syncChild_d->syncViewportPosRecursive();
+ }
+ }
+}
+
QQuickTableView::QQuickTableView(QQuickItem *parent)
: QQuickFlickable(*(new QQuickTableViewPrivate), parent)
{
@@ -2044,6 +2511,26 @@ QQuickTableView::QQuickTableView(QQuickTableViewPrivate &dd, QQuickItem *parent)
setFlag(QQuickItem::ItemIsFocusScope);
}
+qreal QQuickTableView::minXExtent() const
+{
+ return QQuickFlickable::minXExtent() - d_func()->origin.x();
+}
+
+qreal QQuickTableView::maxXExtent() const
+{
+ return QQuickFlickable::maxXExtent() - d_func()->endExtent.width();
+}
+
+qreal QQuickTableView::minYExtent() const
+{
+ return QQuickFlickable::minYExtent() - d_func()->origin.y();
+}
+
+qreal QQuickTableView::maxYExtent() const
+{
+ return QQuickFlickable::maxYExtent() - d_func()->endExtent.height();
+}
+
int QQuickTableView::rows() const
{
return d_func()->tableSize.height();
@@ -2068,7 +2555,7 @@ void QQuickTableView::setRowSpacing(qreal spacing)
return;
d->cellSpacing.setHeight(spacing);
- d->invalidateColumnRowPositions();
+ d->scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::LayoutOnly);
emit rowSpacingChanged();
}
@@ -2086,7 +2573,7 @@ void QQuickTableView::setColumnSpacing(qreal spacing)
return;
d->cellSpacing.setWidth(spacing);
- d->invalidateColumnRowPositions();
+ d->scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::LayoutOnly);
emit columnSpacingChanged();
}
@@ -2095,7 +2582,7 @@ QJSValue QQuickTableView::rowHeightProvider() const
return d_func()->rowHeightProvider;
}
-void QQuickTableView::setRowHeightProvider(QJSValue provider)
+void QQuickTableView::setRowHeightProvider(const QJSValue &provider)
{
Q_D(QQuickTableView);
if (provider.strictlyEquals(d->rowHeightProvider))
@@ -2111,7 +2598,7 @@ QJSValue QQuickTableView::columnWidthProvider() const
return d_func()->columnWidthProvider;
}
-void QQuickTableView::setColumnWidthProvider(QJSValue provider)
+void QQuickTableView::setColumnWidthProvider(const QJSValue &provider)
{
Q_D(QQuickTableView);
if (provider.strictlyEquals(d->columnWidthProvider))
@@ -2191,6 +2678,41 @@ void QQuickTableView::setContentHeight(qreal height)
QQuickFlickable::setContentHeight(height);
}
+QQuickTableView *QQuickTableView::syncView() const
+{
+ return d_func()->assignedSyncView;
+}
+
+void QQuickTableView::setSyncView(QQuickTableView *view)
+{
+ Q_D(QQuickTableView);
+ if (d->assignedSyncView == view)
+ return;
+
+ d->assignedSyncView = view;
+ d->scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::ViewportOnly);
+
+ emit syncViewChanged();
+}
+
+Qt::Orientations QQuickTableView::syncDirection() const
+{
+ return d_func()->assignedSyncDirection;
+}
+
+void QQuickTableView::setSyncDirection(Qt::Orientations direction)
+{
+ Q_D(QQuickTableView);
+ if (d->assignedSyncDirection == direction)
+ return;
+
+ d->assignedSyncDirection = direction;
+ if (d->assignedSyncView)
+ d->scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::ViewportOnly);
+
+ emit syncDirectionChanged();
+}
+
void QQuickTableView::forceLayout()
{
d_func()->forceLayout();
@@ -2218,45 +2740,42 @@ void QQuickTableView::geometryChanged(const QRectF &newGeometry, const QRectF &o
void QQuickTableView::viewportMoved(Qt::Orientations orientation)
{
Q_D(QQuickTableView);
+
+ // If the new viewport position was set from the setLocalViewportXY()
+ // functions, we just update the position silently and return. Otherwise, if
+ // the viewport was flicked by the user, or some other control, we
+ // recursively sync all the views in the hierarchy to the same position.
QQuickFlickable::viewportMoved(orientation);
+ if (d->inSetLocalViewportPos)
+ return;
- QQuickTableViewPrivate::RebuildOptions options = QQuickTableViewPrivate::RebuildOption::None;
+ // Move all views in the syncView hierarchy to the same contentX/Y.
+ // We need to start from this view (and not the root syncView) to
+ // ensure that we respect all the individual syncDirection flags
+ // between the individual views in the hierarchy.
+ d->syncViewportPosRecursive();
- // Check the viewport moved more than one page vertically
- if (!d->viewportRect.intersects(QRectF(d->viewportRect.x(), contentY(), 1, height())))
- options |= QQuickTableViewPrivate::RebuildOption::CalculateNewTopLeftRow;
- // Check the viewport moved more than one page horizontally
- if (!d->viewportRect.intersects(QRectF(contentX(), d->viewportRect.y(), width(), 1)))
- options |= QQuickTableViewPrivate::RebuildOption::CalculateNewTopLeftColumn;
-
- if (options) {
- // When the viewport has moved more than one page vertically or horizontally, we switch
- // strategy from refilling edges around the current table to instead rebuild the table
- // from scratch inside the new viewport. This will greatly improve performance when flicking
- // a long distance in one go, which can easily happen when dragging on scrollbars.
- options |= QQuickTableViewPrivate::RebuildOption::ViewportOnly;
- d->scheduleRebuildTable(options);
- }
-
- if (d->rebuildScheduled) {
- // No reason to do anything, since we're about to rebuild the whole table anyway.
- // Besides, calling updatePolish, which will start the rebuild, can easily cause
- // binding loops to happen since we usually end up modifying the geometry of the
- // viewport (contentItem) as well.
- return;
- }
+ auto rootView = d->rootSyncView();
+ auto rootView_d = rootView->d_func();
- // Calling polish() will schedule a polish event. But while the user is flicking, several
- // mouse events will be handled before we get an updatePolish() call. And the updatePolish()
- // call will only see the last mouse position. This results in a stuttering flick experience
- // (especially on windows). We improve on this by calling updatePolish() directly. But this
- // has the pitfall that we open up for recursive callbacks. E.g while inside updatePolish(), we
- // load/unload items, and emit signals. The application can listen to those signals and set a
- // new contentX/Y on the flickable. So we need to guard for this, to avoid unexpected behavior.
- if (d->polishing)
- polish();
- else
- d->updatePolish();
+ rootView_d->scheduleRebuildIfFastFlick();
+
+ if (!rootView_d->polishScheduled) {
+ if (rootView_d->scheduledRebuildOptions) {
+ // When we need to rebuild, collecting several viewport
+ // moves and do a single polish gives a quicker UI.
+ rootView->polish();
+ } else {
+ // Updating the table right away when flicking
+ // slowly gives a smoother experience.
+ const bool updated = rootView->d_func()->updateTableRecursive();
+ if (!updated) {
+ // One, or more, of the views are already in an
+ // update, so we need to wait a cycle.
+ rootView->polish();
+ }
+ }
+ }
}
void QQuickTableViewPrivate::_q_componentFinalized()
@@ -2292,6 +2811,71 @@ void QQuickTableView::componentComplete()
d_func()->registerCallbackWhenBindingsAreEvaluated();
}
+class QObjectPrivate;
+class QQuickTableSectionSizeProviderPrivate : public QObjectPrivate {
+public:
+ QQuickTableSectionSizeProviderPrivate();
+ ~QQuickTableSectionSizeProviderPrivate();
+ QHash<int, qreal> hash;
+};
+
+QQuickTableSectionSizeProvider::QQuickTableSectionSizeProvider(QObject *parent)
+ : QObject (*(new QQuickTableSectionSizeProviderPrivate), parent)
+{
+}
+
+void QQuickTableSectionSizeProvider::setSize(int section, qreal size)
+{
+ Q_D(QQuickTableSectionSizeProvider);
+ if (section < 0 || size < 0) {
+ qmlWarning(this) << "setSize: section or size less than zero";
+ return;
+ }
+ if (qFuzzyCompare(QQuickTableSectionSizeProvider::size(section), size))
+ return;
+ d->hash.insert(section, size);
+ emit sizeChanged();
+}
+
+// return -1.0 if no valid explicit size retrieved
+qreal QQuickTableSectionSizeProvider::size(int section)
+{
+ Q_D(QQuickTableSectionSizeProvider);
+ auto it = d->hash.find(section);
+ if (it != d->hash.end())
+ return *it;
+ return -1.0;
+}
+
+// return true if section is valid
+bool QQuickTableSectionSizeProvider::resetSize(int section)
+{
+ Q_D(QQuickTableSectionSizeProvider);
+ if (d->hash.empty())
+ return false;
+
+ auto ret = d->hash.remove(section);
+ if (ret)
+ emit sizeChanged();
+ return ret;
+}
+
+void QQuickTableSectionSizeProvider::resetAll()
+{
+ Q_D(QQuickTableSectionSizeProvider);
+ d->hash.clear();
+ emit sizeChanged();
+}
+
+QQuickTableSectionSizeProviderPrivate::QQuickTableSectionSizeProviderPrivate()
+ : QObjectPrivate()
+{
+}
+
+QQuickTableSectionSizeProviderPrivate::~QQuickTableSectionSizeProviderPrivate()
+{
+
+}
#include "moc_qquicktableview_p.cpp"
QT_END_NAMESPACE
diff --git a/src/quick/items/qquicktableview_p.h b/src/quick/items/qquicktableview_p.h
index f32c71b983..a5f727d7a4 100644
--- a/src/quick/items/qquicktableview_p.h
+++ b/src/quick/items/qquicktableview_p.h
@@ -79,6 +79,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickTableView : public QQuickFlickable
Q_PROPERTY(bool reuseItems READ reuseItems WRITE setReuseItems NOTIFY reuseItemsChanged)
Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged)
Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged)
+ Q_PROPERTY(QQuickTableView *syncView READ syncView WRITE setSyncView NOTIFY syncViewChanged REVISION 14)
+ Q_PROPERTY(Qt::Orientations syncDirection READ syncDirection WRITE setSyncDirection NOTIFY syncDirectionChanged REVISION 14)
public:
QQuickTableView(QQuickItem *parent = nullptr);
@@ -93,10 +95,10 @@ public:
void setColumnSpacing(qreal spacing);
QJSValue rowHeightProvider() const;
- void setRowHeightProvider(QJSValue provider);
+ void setRowHeightProvider(const QJSValue &provider);
QJSValue columnWidthProvider() const;
- void setColumnWidthProvider(QJSValue provider);
+ void setColumnWidthProvider(const QJSValue &provider);
virtual QVariant model() const;
virtual void setModel(const QVariant &newModel);
@@ -110,6 +112,12 @@ public:
void setContentWidth(qreal width);
void setContentHeight(qreal height);
+ QQuickTableView *syncView() const;
+ void setSyncView(QQuickTableView *view);
+
+ Qt::Orientations syncDirection() const;
+ void setSyncDirection(Qt::Orientations direction);
+
Q_INVOKABLE void forceLayout();
static QQuickTableViewAttached *qmlAttachedProperties(QObject *);
@@ -124,6 +132,8 @@ Q_SIGNALS:
void modelChanged();
void delegateChanged();
void reuseItemsChanged();
+ Q_REVISION(14) void syncViewChanged();
+ Q_REVISION(14) void syncDirectionChanged();
protected:
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
@@ -137,6 +147,11 @@ private:
Q_DISABLE_COPY(QQuickTableView)
Q_DECLARE_PRIVATE(QQuickTableView)
+ qreal minXExtent() const override;
+ qreal maxXExtent() const override;
+ qreal minYExtent() const override;
+ qreal maxYExtent() const override;
+
Q_PRIVATE_SLOT(d_func(), void _q_componentFinalized())
};
diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h
index f2fef0d774..b66ac66dec 100644
--- a/src/quick/items/qquicktableview_p_p.h
+++ b/src/quick/items/qquicktableview_p_p.h
@@ -54,9 +54,9 @@
#include "qquicktableview_p.h"
#include <QtCore/qtimer.h>
-#include <QtQml/private/qqmltableinstancemodel_p.h>
+#include <QtQmlModels/private/qqmltableinstancemodel_p.h>
#include <QtQml/private/qqmlincubator_p.h>
-#include <QtQml/private/qqmlchangeset_p.h>
+#include <QtQmlModels/private/qqmlchangeset_p.h>
#include <QtQml/qqmlinfo.h>
#include <QtQuick/private/qquickflickable_p_p.h>
@@ -70,6 +70,25 @@ static const qreal kDefaultRowHeight = 50;
static const qreal kDefaultColumnWidth = 50;
class FxTableItem;
+class QQuickTableSectionSizeProviderPrivate;
+
+class Q_QUICK_PRIVATE_EXPORT QQuickTableSectionSizeProvider : public QObject {
+ Q_OBJECT
+
+public:
+ QQuickTableSectionSizeProvider(QObject *parent=nullptr);
+ void setSize(int section, qreal size);
+ qreal size(int section);
+ bool resetSize(int section);
+ void resetAll();
+
+Q_SIGNALS:
+ void sizeChanged();
+
+private:
+ Q_DISABLE_COPY(QQuickTableSectionSizeProvider)
+ Q_DECLARE_PRIVATE(QQuickTableSectionSizeProvider)
+};
class Q_QML_AUTOTEST_EXPORT QQuickTableViewPrivate : public QQuickFlickablePrivate
{
@@ -188,10 +207,11 @@ public:
enum class RebuildOption {
None = 0,
- ViewportOnly = 0x1,
- CalculateNewTopLeftRow = 0x2,
- CalculateNewTopLeftColumn = 0x4,
- All = 0x8,
+ LayoutOnly = 0x1,
+ ViewportOnly = 0x2,
+ CalculateNewTopLeftRow = 0x4,
+ CalculateNewTopLeftColumn = 0x8,
+ All = 0x10,
};
Q_DECLARE_FLAGS(RebuildOptions, RebuildOption)
@@ -231,6 +251,9 @@ public:
QRectF loadedTableOuterRect;
QRectF loadedTableInnerRect;
+ QPointF origin = QPointF(0, 0);
+ QSizeF endExtent = QSizeF(0, 0);
+
QRectF viewportRect = QRectF(0, 0, -1, -1);
QSize tableSize;
@@ -246,13 +269,18 @@ public:
QQmlTableInstanceModel::ReusableFlag reusableFlag = QQmlTableInstanceModel::Reusable;
bool blockItemCreatedCallback = false;
- bool columnRowPositionsInvalid = false;
bool layoutWarningIssued = false;
bool polishing = false;
- bool rebuildScheduled = true;
+ bool syncVertically = false;
+ bool syncHorizontally = false;
+ bool inSetLocalViewportPos = false;
+ bool inSyncViewportPosRecursive = false;
+ bool inUpdateContentSize = false;
QJSValue rowHeightProvider;
QJSValue columnWidthProvider;
+ QQuickTableSectionSizeProvider rowHeights;
+ QQuickTableSectionSizeProvider columnWidths;
EdgeRange cachedNextVisibleEdgeIndex[4];
EdgeRange cachedColumnWidth;
@@ -272,6 +300,11 @@ public:
QSizeF averageEdgeSize;
+ QPointer<QQuickTableView> assignedSyncView;
+ QPointer<QQuickTableView> syncView;
+ QList<QPointer<QQuickTableView> > syncChildren;
+ Qt::Orientations assignedSyncDirection = Qt::Horizontal | Qt::Vertical;
+
const static QPoint kLeft;
const static QPoint kRight;
const static QPoint kUp;
@@ -304,7 +337,10 @@ public:
inline int leftColumn() const { return loadedColumns.firstKey(); }
inline int rightColumn() const { return loadedColumns.lastKey(); }
- void relayoutTable();
+ QQuickTableView *rootSyncView() const;
+
+ bool updateTableRecursive();
+ bool updateTable();
void relayoutTableItems();
void layoutVerticalEdge(Qt::Edge tableEdge);
@@ -317,7 +353,7 @@ public:
void updateAverageEdgeSize();
void forceLayout();
- void enforceTableAtOrigin();
+ void updateExtents();
void syncLoadedTableRectFromLoadedTable();
void syncLoadedTableFromLoadRequest();
@@ -342,7 +378,6 @@ public:
void releaseLoadedItems(QQmlTableInstanceModel::ReusableFlag reusableFlag);
void unloadItem(const QPoint &cell);
- void loadInitialTopLeftItem(const QPoint &cell, const QPointF &pos);
void loadEdge(Qt::Edge edge, QQmlIncubator::IncubationMode incubationMode);
void unloadEdge(Qt::Edge edge);
void loadAndUnloadVisibleEdges();
@@ -351,13 +386,11 @@ public:
void processRebuildTable();
bool moveToNextRebuildState();
- QPoint calculateNewTopLeft();
void calculateTopLeft(QPoint &topLeft, QPointF &topLeftPos);
void beginRebuildTable();
void layoutAfterLoadingInitialTable();
void scheduleRebuildTable(QQuickTableViewPrivate::RebuildOptions options);
- void invalidateColumnRowPositions();
int resolveImportVersion();
void createWrapperModel();
@@ -372,6 +405,7 @@ public:
inline void syncDelegate();
inline void syncModel();
inline void syncRebuildOptions();
+ inline void syncSyncView();
void connectToModel();
void disconnectFromModel();
@@ -385,6 +419,11 @@ public:
void layoutChangedCallback(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
void modelResetCallback();
+ void scheduleRebuildIfFastFlick();
+ void setLocalViewportX(qreal contentX);
+ void setLocalViewportY(qreal contentY);
+ void syncViewportPosRecursive();
+
void _q_componentFinalized();
void registerCallbackWhenBindingsAreEvaluated();
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp
index 6d343a91ce..ae849aeb4b 100644
--- a/src/quick/items/qquicktext.cpp
+++ b/src/quick/items/qquicktext.cpp
@@ -1653,13 +1653,17 @@ void QQuickText::setText(const QString &n)
if (d->text == n)
return;
- d->richText = d->format == RichText;
+ d->markdownText = d->format == MarkdownText;
+ d->richText = d->format == RichText || d->markdownText;
d->styledText = d->format == StyledText || (d->format == AutoText && Qt::mightBeRichText(n));
d->text = n;
if (isComponentComplete()) {
if (d->richText) {
d->ensureDoc();
- d->extra->doc->setText(n);
+ if (d->markdownText)
+ d->extra->doc->setMarkdownText(n);
+ else
+ d->extra->doc->setText(n);
d->rightToLeftText = d->extra->doc->toPlainText().isRightToLeft();
} else {
d->clearFormats();
@@ -2146,7 +2150,8 @@ void QQuickText::setTextFormat(TextFormat format)
return;
d->format = format;
bool wasRich = d->richText;
- d->richText = format == RichText;
+ d->markdownText = format == MarkdownText;
+ d->richText = format == RichText || d->markdownText;
d->styledText = format == StyledText || (format == AutoText && Qt::mightBeRichText(d->text));
if (isComponentComplete()) {
@@ -2687,7 +2692,10 @@ void QQuickText::componentComplete()
if (d->updateOnComponentComplete) {
if (d->richText) {
d->ensureDoc();
- d->extra->doc->setText(d->text);
+ if (d->markdownText)
+ d->extra->doc->setMarkdownText(d->text);
+ else
+ d->extra->doc->setText(d->text);
d->rightToLeftText = d->extra->doc->toPlainText().isRightToLeft();
} else {
d->rightToLeftText = d->text.isRightToLeft();
diff --git a/src/quick/items/qquicktext_p.h b/src/quick/items/qquicktext_p.h
index 1af60051fb..45f387cb12 100644
--- a/src/quick/items/qquicktext_p.h
+++ b/src/quick/items/qquicktext_p.h
@@ -121,6 +121,7 @@ public:
Q_ENUM(TextStyle)
enum TextFormat { PlainText = Qt::PlainText,
RichText = Qt::RichText,
+ MarkdownText = Qt::MarkdownText,
AutoText = Qt::AutoText,
StyledText = 4 };
Q_ENUM(TextFormat)
diff --git a/src/quick/items/qquicktext_p_p.h b/src/quick/items/qquicktext_p_p.h
index efa45e0958..c01998b100 100644
--- a/src/quick/items/qquicktext_p_p.h
+++ b/src/quick/items/qquicktext_p_p.h
@@ -161,6 +161,7 @@ public:
bool updateOnComponentComplete:1;
bool richText:1;
bool styledText:1;
+ bool markdownText:1;
bool widthExceeded:1;
bool heightExceeded:1;
bool internalWidthUpdate:1;
diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp
index 5c55f4f43f..3c392be751 100644
--- a/src/quick/items/qquicktextcontrol.cpp
+++ b/src/quick/items/qquicktextcontrol.cpp
@@ -113,6 +113,7 @@ QQuickTextControlPrivate::QQuickTextControlPrivate()
wordSelectionEnabled(false),
hasImState(false),
cursorRectangleChanged(false),
+ hoveredMarker(false),
lastSelectionStart(-1),
lastSelectionEnd(-1)
{}
@@ -321,6 +322,9 @@ void QQuickTextControlPrivate::setContent(Qt::TextFormat format, const QString &
formatCursor.select(QTextCursor::Document);
formatCursor.setCharFormat(charFormatForInsertion);
formatCursor.endEditBlock();
+ } else if (format == Qt::MarkdownText) {
+ doc->setBaseUrl(doc->baseUrl().adjusted(QUrl::RemoveFilename));
+ doc->setMarkdown(text);
} else {
#if QT_CONFIG(texthtmlparser)
doc->setHtml(text);
@@ -799,6 +803,12 @@ void QQuickTextControl::setPlainText(const QString &text)
d->setContent(Qt::PlainText, text);
}
+void QQuickTextControl::setMarkdownText(const QString &text)
+{
+ Q_D(QQuickTextControl);
+ d->setContent(Qt::MarkdownText, text);
+}
+
void QQuickTextControl::setHtml(const QString &text)
{
Q_D(QQuickTextControl);
@@ -1025,6 +1035,8 @@ void QQuickTextControlPrivate::mousePressEvent(QMouseEvent *e, const QPointF &po
cursor.clearSelection();
}
}
+ if (interactionFlags & Qt::TextEditable)
+ blockWithMarkerUnderMousePress = q->blockWithMarkerAt(pos);
if (e->button() & Qt::MiddleButton) {
return;
} else if (!(e->button() & Qt::LeftButton)) {
@@ -1196,6 +1208,16 @@ void QQuickTextControlPrivate::mouseReleaseEvent(QMouseEvent *e, const QPointF &
q->updateCursorRectangle(true);
}
+ if ((interactionFlags & Qt::TextEditable) && (e->button() & Qt::LeftButton) && blockWithMarkerUnderMousePress.isValid()) {
+ QTextBlock block = q->blockWithMarkerAt(pos);
+ if (block == blockWithMarkerUnderMousePress) {
+ auto fmt = block.blockFormat();
+ fmt.setMarker(fmt.marker() == QTextBlockFormat::MarkerType::Unchecked ?
+ QTextBlockFormat::MarkerType::Checked : QTextBlockFormat::MarkerType::Unchecked);
+ cursor.setBlockFormat(fmt);
+ }
+ }
+
if (interactionFlags & Qt::LinksAccessibleByMouse) {
if (!(e->button() & Qt::LeftButton))
return;
@@ -1375,7 +1397,7 @@ QVariant QQuickTextControl::inputMethodQuery(Qt::InputMethodQuery property) cons
return inputMethodQuery(property, QVariant());
}
-QVariant QQuickTextControl::inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const
+QVariant QQuickTextControl::inputMethodQuery(Qt::InputMethodQuery property, const QVariant &argument) const
{
Q_D(const QQuickTextControl);
QTextBlock block = d->cursor.block();
@@ -1478,8 +1500,15 @@ void QQuickTextControlPrivate::hoverEvent(QHoverEvent *e, const QPointF &pos)
if (hoveredLink != link) {
hoveredLink = link;
emit q->linkHovered(link);
+ qCDebug(DBG_HOVER_TRACE) << q << e->type() << pos << "hoveredLink" << hoveredLink;
+ } else {
+ QTextBlock block = q->blockWithMarkerAt(pos);
+ if (block.isValid() != hoveredMarker)
+ emit q->markerHovered(block.isValid());
+ hoveredMarker = block.isValid();
+ if (hoveredMarker)
+ qCDebug(DBG_HOVER_TRACE) << q << e->type() << pos << "hovered marker" << int(block.blockFormat().marker()) << block.text();
}
- qCDebug(DBG_HOVER_TRACE) << q << e->type() << pos << "hoveredLink" << hoveredLink;
}
bool QQuickTextControl::hasImState() const
@@ -1555,6 +1584,12 @@ QString QQuickTextControl::anchorAt(const QPointF &pos) const
return d->doc->documentLayout()->anchorAt(pos);
}
+QTextBlock QQuickTextControl::blockWithMarkerAt(const QPointF &pos) const
+{
+ Q_D(const QQuickTextControl);
+ return d->doc->documentLayout()->blockWithMarkerAt(pos);
+}
+
void QQuickTextControl::setAcceptRichText(bool accept)
{
Q_D(QQuickTextControl);
@@ -1784,6 +1819,13 @@ QString QQuickTextControl::toHtml() const
}
#endif
+#if QT_CONFIG(textmarkdownwriter)
+QString QQuickTextControl::toMarkdown() const
+{
+ return document()->toMarkdown();
+}
+#endif
+
bool QQuickTextControl::cursorOn() const
{
Q_D(const QQuickTextControl);
diff --git a/src/quick/items/qquicktextcontrol_p.h b/src/quick/items/qquicktextcontrol_p.h
index c99736a874..41b8ed7821 100644
--- a/src/quick/items/qquicktextcontrol_p.h
+++ b/src/quick/items/qquicktextcontrol_p.h
@@ -93,6 +93,9 @@ public:
#if QT_CONFIG(texthtmlparser)
QString toHtml() const;
#endif
+#if QT_CONFIG(textmarkdownwriter)
+ QString toMarkdown() const;
+#endif
bool hasImState() const;
bool overwriteMode() const;
@@ -107,6 +110,7 @@ public:
QString hoveredLink() const;
QString anchorAt(const QPointF &pos) const;
+ QTextBlock blockWithMarkerAt(const QPointF &pos) const;
void setCursorWidth(int width);
@@ -128,6 +132,7 @@ public:
public Q_SLOTS:
void setPlainText(const QString &text);
+ void setMarkdownText(const QString &text);
void setHtml(const QString &text);
#if QT_CONFIG(clipboard)
@@ -160,6 +165,8 @@ Q_SIGNALS:
void cursorRectangleChanged();
void linkActivated(const QString &link);
void linkHovered(const QString &link);
+ void markerClicked();
+ void markerHovered(bool marker);
public:
virtual void processEvent(QEvent *e, const QMatrix &matrix);
@@ -167,7 +174,7 @@ public:
#if QT_CONFIG(im)
virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
- Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const;
+ Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const;
#endif
virtual QMimeData *createMimeDataFromSelection() const;
diff --git a/src/quick/items/qquicktextcontrol_p_p.h b/src/quick/items/qquicktextcontrol_p_p.h
index 431bf1b6c4..d52200b49d 100644
--- a/src/quick/items/qquicktextcontrol_p_p.h
+++ b/src/quick/items/qquicktextcontrol_p_p.h
@@ -54,6 +54,7 @@
#include "QtGui/qtextdocumentfragment.h"
#include "QtGui/qtextcursor.h"
#include "QtGui/qtextformat.h"
+#include "QtGui/qtextobject.h"
#include "QtGui/qabstracttextdocumentlayout.h"
#include "QtCore/qbasictimer.h"
#include "QtCore/qpointer.h"
@@ -139,6 +140,7 @@ public:
QString anchorOnMousePress;
QString linkToCopy;
QString hoveredLink;
+ QTextBlock blockWithMarkerUnderMousePress;
QBasicTimer cursorBlinkTimer;
ulong timestampAtLastDoubleClick = 0; // will only be set at a double click
@@ -163,6 +165,7 @@ public:
bool wordSelectionEnabled : 1;
bool hasImState : 1;
bool cursorRectangleChanged : 1;
+ bool hoveredMarker: 1;
int lastSelectionStart;
int lastSelectionEnd;
diff --git a/src/quick/items/qquicktextdocument.cpp b/src/quick/items/qquicktextdocument.cpp
index 06ac5804c4..021bbca0f6 100644
--- a/src/quick/items/qquicktextdocument.cpp
+++ b/src/quick/items/qquicktextdocument.cpp
@@ -237,6 +237,14 @@ void QQuickTextDocumentWithImageResources::setText(const QString &text)
#endif
}
+#if QT_CONFIG(textmarkdownreader)
+void QQuickTextDocumentWithImageResources::setMarkdownText(const QString &text)
+{
+ clearResources();
+ QTextDocument::setMarkdown(text);
+}
+#endif
+
QSet<QUrl> QQuickTextDocumentWithImageResources::errors;
QT_END_NAMESPACE
diff --git a/src/quick/items/qquicktextdocument_p.h b/src/quick/items/qquicktextdocument_p.h
index 1218b12b89..9c5152d442 100644
--- a/src/quick/items/qquicktextdocument_p.h
+++ b/src/quick/items/qquicktextdocument_p.h
@@ -73,6 +73,9 @@ public:
virtual ~QQuickTextDocumentWithImageResources();
void setText(const QString &);
+#if QT_CONFIG(textmarkdownreader)
+ void setMarkdownText(const QString &);
+#endif
int resourcesLoading() const { return outstanding; }
QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) override;
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp
index bdfbb979dd..7d34cc3f56 100644
--- a/src/quick/items/qquicktextedit.cpp
+++ b/src/quick/items/qquicktextedit.cpp
@@ -194,6 +194,11 @@ QString QQuickTextEdit::text() const
d->text = d->control->toHtml();
else
#endif
+#if QT_CONFIG(textmarkdownwriter)
+ if (d->markdownText)
+ d->text = d->control->toMarkdown();
+ else
+#endif
d->text = d->control->toPlainText();
d->textCached = true;
}
@@ -407,6 +412,7 @@ void QQuickTextEdit::setText(const QString &text)
d->document->clearResources();
d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(text));
+ d->markdownText = d->format == MarkdownText;
if (!isComponentComplete()) {
d->text = text;
} else if (d->richText) {
@@ -415,6 +421,8 @@ void QQuickTextEdit::setText(const QString &text)
#else
d->control->setPlainText(text);
#endif
+ } else if (d->markdownText) {
+ d->control->setMarkdownText(text);
} else {
d->control->setPlainText(text);
}
@@ -486,6 +494,7 @@ void QQuickTextEdit::setTextFormat(TextFormat format)
bool wasRich = d->richText;
d->richText = format == RichText || (format == AutoText && (wasRich || Qt::mightBeRichText(text())));
+ d->markdownText = format == MarkdownText;
#if QT_CONFIG(texthtmlparser)
if (isComponentComplete()) {
@@ -1463,8 +1472,12 @@ void QQuickTextEdit::componentComplete()
d->control->setHtml(d->text);
else
#endif
- if (!d->text.isEmpty())
- d->control->setPlainText(d->text);
+ if (!d->text.isEmpty()) {
+ if (d->markdownText)
+ d->control->setMarkdownText(d->text);
+ else
+ d->control->setPlainText(d->text);
+ }
if (d->dirty) {
d->determineHorizontalAlignment();
@@ -2309,6 +2322,7 @@ void QQuickTextEditPrivate::init()
QObject::connect(document, &QQuickTextDocumentWithImageResources::contentsChange, q, &QQuickTextEdit::q_contentsChange);
QObject::connect(document->documentLayout(), &QAbstractTextDocumentLayout::updateBlock, q, &QQuickTextEdit::invalidateBlock);
QObject::connect(control, &QQuickTextControl::linkHovered, q, &QQuickTextEdit::q_linkHovered);
+ QObject::connect(control, &QQuickTextControl::markerHovered, q, &QQuickTextEdit::q_markerHovered);
document->setDefaultFont(font);
document->setDocumentMargin(textMargin);
@@ -2600,6 +2614,19 @@ void QQuickTextEdit::q_linkHovered(const QString &link)
#endif
}
+void QQuickTextEdit::q_markerHovered(bool hovered)
+{
+ Q_D(QQuickTextEdit);
+#if QT_CONFIG(cursor)
+ if (!hovered) {
+ setCursor(d->cursorToRestoreAfterHover);
+ } else if (cursor().shape() != Qt::PointingHandCursor) {
+ d->cursorToRestoreAfterHover = cursor().shape();
+ setCursor(Qt::PointingHandCursor);
+ }
+#endif
+}
+
void QQuickTextEdit::q_updateAlignment()
{
Q_D(QQuickTextEdit);
diff --git a/src/quick/items/qquicktextedit_p.h b/src/quick/items/qquicktextedit_p.h
index 259a614d6b..2d1b6c7f9c 100644
--- a/src/quick/items/qquicktextedit_p.h
+++ b/src/quick/items/qquicktextedit_p.h
@@ -134,7 +134,8 @@ public:
enum TextFormat {
PlainText = Qt::PlainText,
RichText = Qt::RichText,
- AutoText = Qt::AutoText
+ AutoText = Qt::AutoText,
+ MarkdownText = Qt::MarkdownText
};
Q_ENUM(TextFormat)
@@ -375,6 +376,7 @@ private Q_SLOTS:
void invalidateBlock(const QTextBlock &block);
void updateCursor();
void q_linkHovered(const QString &link);
+ void q_markerHovered(bool hovered);
void q_updateAlignment();
void updateSize();
void triggerPreprocess();
diff --git a/src/quick/items/qquicktextedit_p_p.h b/src/quick/items/qquicktextedit_p_p.h
index 389ce3175c..be555d44fd 100644
--- a/src/quick/items/qquicktextedit_p_p.h
+++ b/src/quick/items/qquicktextedit_p_p.h
@@ -127,7 +127,7 @@ public:
, focusOnPress(true), persistentSelection(false), requireImplicitWidth(false)
, selectByMouse(false), canPaste(false), canPasteValid(false), hAlignImplicit(true)
, textCached(true), inLayout(false), selectByKeyboard(false), selectByKeyboardSet(false)
- , hadSelection(false)
+ , hadSelection(false), markdownText(false)
{
}
@@ -225,6 +225,7 @@ public:
bool selectByKeyboard:1;
bool selectByKeyboardSet:1;
bool hadSelection : 1;
+ bool markdownText : 1;
};
QT_END_NAMESPACE
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index 182889b14e..a83b9beaa5 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -1009,9 +1009,10 @@ void QQuickTextInput::setAutoScroll(bool b)
an acceptable or intermediate state. The accepted signal will only be sent
if the text is in an acceptable state when enter is pressed.
- Currently supported validators are IntValidator, DoubleValidator and
- RegExpValidator. An example of using validators is shown below, which allows
- input of integers between 11 and 31 into the text input:
+ Currently supported validators are IntValidator, DoubleValidator,
+ RegExpValidator and RegularExpressionValidator. An example of using
+ validators is shown below, which allows input of integers between 11 and 31
+ into the text input:
\code
import QtQuick 2.0
@@ -1957,7 +1958,7 @@ QVariant QQuickTextInput::inputMethodQuery(Qt::InputMethodQuery property) const
return inputMethodQuery(property, QVariant());
}
-QVariant QQuickTextInput::inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const
+QVariant QQuickTextInput::inputMethodQuery(Qt::InputMethodQuery property, const QVariant &argument) const
{
Q_D(const QQuickTextInput);
switch (property) {
diff --git a/src/quick/items/qquicktextinput_p.h b/src/quick/items/qquicktextinput_p.h
index c46a2f8128..c10b06d02a 100644
--- a/src/quick/items/qquicktextinput_p.h
+++ b/src/quick/items/qquicktextinput_p.h
@@ -93,7 +93,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickTextInput : public QQuickImplicitSizeItem
Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
- Q_PROPERTY(int passwordMaskDelay READ passwordMaskDelay WRITE setPasswordMaskDelay RESET resetPasswordMaskDelay NOTIFY passwordMaskDelayChanged REVISION 3)
+ Q_PROPERTY(int passwordMaskDelay READ passwordMaskDelay WRITE setPasswordMaskDelay RESET resetPasswordMaskDelay NOTIFY passwordMaskDelayChanged REVISION 4)
Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
Q_PROPERTY(QString preeditText READ preeditText NOTIFY preeditTextChanged REVISION 7)
Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
@@ -268,7 +268,7 @@ public:
#if QT_CONFIG(im)
QVariant inputMethodQuery(Qt::InputMethodQuery property) const override;
- Q_REVISION(3) Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const;
+ Q_REVISION(4) Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const;
#endif
QRectF boundingRect() const override;
@@ -336,7 +336,7 @@ Q_SIGNALS:
void inputMaskChanged(const QString &inputMask);
void echoModeChanged(QQuickTextInput::EchoMode echoMode);
void passwordCharacterChanged();
- Q_REVISION(3) void passwordMaskDelayChanged(int delay);
+ Q_REVISION(4) void passwordMaskDelayChanged(int delay);
void displayTextChanged();
Q_REVISION(7) void preeditTextChanged();
void activeFocusOnPressChanged(bool activeFocusOnPress);
@@ -399,7 +399,7 @@ public Q_SLOTS:
void redo();
void insert(int position, const QString &text);
void remove(int start, int end);
- Q_REVISION(3) void ensureVisible(int position);
+ Q_REVISION(4) void ensureVisible(int position);
Q_REVISION(7) void clear();
private Q_SLOTS:
diff --git a/src/quick/items/qquicktextnode.cpp b/src/quick/items/qquicktextnode.cpp
index 0dd12207b7..9110a0664f 100644
--- a/src/quick/items/qquicktextnode.cpp
+++ b/src/quick/items/qquicktextnode.cpp
@@ -160,7 +160,7 @@ void QQuickTextNode::addRectangleNode(const QRectF &rect, const QColor &color)
void QQuickTextNode::addImage(const QRectF &rect, const QImage &image)
{
QSGRenderContext *sg = QQuickItemPrivate::get(m_ownerElement)->sceneGraphRenderContext();
- QSGInternalImageNode *node = sg->sceneGraphContext()->createInternalImageNode();
+ QSGInternalImageNode *node = sg->sceneGraphContext()->createInternalImageNode(sg);
QSGTexture *texture = sg->createTexture(image);
if (m_ownerElement->smooth())
texture->setFiltering(QSGTexture::Linear);
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp
index 1119a3d5b4..a0ae4e5f97 100644
--- a/src/quick/items/qquicktextnodeengine.cpp
+++ b/src/quick/items/qquicktextnodeengine.cpp
@@ -638,7 +638,7 @@ void QQuickTextNodeEngine::addBorder(const QRectF &rect, qreal border,
QTextFrameFormat::BorderStyle borderStyle,
const QBrush &borderBrush)
{
- QColor color = borderBrush.color();
+ const QColor &color = borderBrush.color();
// Currently we don't support other styles than solid
Q_UNUSED(borderStyle);
@@ -1011,6 +1011,17 @@ void QQuickTextNodeEngine::addTextBlock(QTextDocument *textDocument, const QText
break;
};
+ switch (block.blockFormat().marker()) {
+ case QTextBlockFormat::MarkerType::Checked:
+ listItemBullet = QChar(0x2612); // Checked checkbox
+ break;
+ case QTextBlockFormat::MarkerType::Unchecked:
+ listItemBullet = QChar(0x2610); // Unchecked checkbox
+ break;
+ case QTextBlockFormat::MarkerType::NoMarker:
+ break;
+ }
+
QSizeF size(fontMetrics.horizontalAdvance(listItemBullet), fontMetrics.height());
qreal xoff = fontMetrics.horizontalAdvance(QLatin1Char(' '));
if (block.textDirection() == Qt::LeftToRight)
diff --git a/src/quick/items/qquickview.cpp b/src/quick/items/qquickview.cpp
index c411da9519..17fc16d44b 100644
--- a/src/quick/items/qquickview.cpp
+++ b/src/quick/items/qquickview.cpp
@@ -44,8 +44,6 @@
#include "qquickitem_p.h"
#include "qquickitemchangelistener_p.h"
-#include <private/qqmlmemoryprofiler_p.h>
-
#include <QtQml/qqmlengine.h>
#include <private/qqmlengine_p.h>
#include <private/qv4qobjectwrapper_p.h>
@@ -101,7 +99,6 @@ void QQuickViewPrivate::execute()
component = nullptr;
}
if (!source.isEmpty()) {
- QML_MEMORY_SCOPE_URL(engine.data()->baseUrl().resolved(source));
component = new QQmlComponent(engine.data(), source, q);
if (!component->isLoading()) {
q->continueExecute();
@@ -243,6 +240,22 @@ void QQuickView::setSource(const QUrl& url)
}
/*!
+ Sets the initial properties with which the QML component gets initialized after
+ calling \l QQuickView::setSource.
+
+
+ Note that you can only use this function to initialize toplevel properties.
+
+ \sa QQmlComponent::createWithInitialProperties
+ \since 5.14
+*/
+void QQuickView::setInitialProperties(const QVariantMap &initialProperties)
+{
+ Q_D(QQuickView);
+ d->initialProperties = initialProperties;
+}
+
+/*!
\internal
Set the source \a url, \a component and content \a item (root of the QML object hierarchy) directly.
@@ -474,7 +487,7 @@ void QQuickView::continueExecute()
return;
}
- QObject *obj = d->component->create();
+ QObject *obj = d->initialProperties.empty() ? d->component->create() : d->component->createWithInitialProperties(d->initialProperties);
if (d->component->isError()) {
const QList<QQmlError> errorList = d->component->errors();
diff --git a/src/quick/items/qquickview.h b/src/quick/items/qquickview.h
index ecae25e90b..4122fcac79 100644
--- a/src/quick/items/qquickview.h
+++ b/src/quick/items/qquickview.h
@@ -88,6 +88,7 @@ public:
public Q_SLOTS:
void setSource(const QUrl&);
+ void setInitialProperties(const QVariantMap &initialProperties);
void setContent(const QUrl& url, QQmlComponent *component, QObject *item);
Q_SIGNALS:
diff --git a/src/quick/items/qquickview_p.h b/src/quick/items/qquickview_p.h
index 3f284c0519..b1ab8d8e8c 100644
--- a/src/quick/items/qquickview_p.h
+++ b/src/quick/items/qquickview_p.h
@@ -108,6 +108,8 @@ public:
QQuickView::ResizeMode resizeMode;
QSize initialSize;
QElapsedTimer frameTimer;
+
+ QVariantMap initialProperties;
};
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index 2316a6c6af..8fb023cf61 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -45,13 +45,16 @@
#include "qquickitem_p.h"
#include "qquickevents_p_p.h"
+#if QT_CONFIG(quick_draganddrop)
#include <private/qquickdrag_p.h>
+#endif
#include <private/qquickhoverhandler_p.h>
#include <private/qquickpointerhandler_p.h>
#include <QtQuick/private/qsgrenderer_p.h>
-#include <QtQuick/private/qsgtexture_p.h>
+#include <QtQuick/private/qsgplaintexture_p.h>
#include <private/qsgrenderloop_p.h>
+#include <private/qsgrhisupport_p.h>
#include <private/qquickrendercontrol_p.h>
#include <private/qquickanimatorcontroller_p.h>
#include <private/qquickprofiler_p.h>
@@ -73,7 +76,6 @@
#include <QtQuick/private/qquickpixmapcache_p.h>
-#include <private/qqmlmemoryprofiler_p.h>
#include <private/qqmldebugserviceinterfaces_p.h>
#include <private/qqmldebugconnector_p.h>
#if QT_CONFIG(opengl)
@@ -84,6 +86,8 @@
#include <private/qdebug_p.h>
#endif
+#include <QtGui/private/qrhi_p.h>
+
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(DBG_TOUCH, "qt.quick.touch")
@@ -98,6 +102,7 @@ Q_LOGGING_CATEGORY(DBG_DIRTY, "qt.quick.dirty")
Q_LOGGING_CATEGORY(lcTransient, "qt.quick.window.transient")
extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha);
+extern Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text = QString(), bool autorep = false, ushort count = 1);
bool QQuickWindowPrivate::defaultAlphaBuffer = false;
@@ -418,9 +423,15 @@ void forceUpdate(QQuickItem *item)
void QQuickWindowPrivate::syncSceneGraph()
{
- QML_MEMORY_SCOPE_STRING("SceneGraph");
Q_Q(QQuickWindow);
+ // Calculate the dpr the same way renderSceneGraph() will.
+ qreal devicePixelRatio = q->effectiveDevicePixelRatio();
+ if (renderTargetId && !QQuickRenderControl::renderWindowFor(q))
+ devicePixelRatio = 1;
+
+ context->prepareSync(devicePixelRatio);
+
animationController->beforeNodeSync();
emit q->beforeSynchronizing();
@@ -451,13 +462,40 @@ void QQuickWindowPrivate::syncSceneGraph()
runAndClearJobs(&afterSynchronizingJobs);
}
-void QQuickWindowPrivate::renderSceneGraph(const QSize &size)
+void QQuickWindowPrivate::emitBeforeRenderPassRecording(void *ud)
+{
+ QQuickWindow *w = reinterpret_cast<QQuickWindow *>(ud);
+ emit w->beforeRenderPassRecording();
+}
+
+void QQuickWindowPrivate::emitAfterRenderPassRecording(void *ud)
+{
+ QQuickWindow *w = reinterpret_cast<QQuickWindow *>(ud);
+ emit w->afterRenderPassRecording();
+}
+
+void QQuickWindowPrivate::renderSceneGraph(const QSize &size, const QSize &surfaceSize)
{
- QML_MEMORY_SCOPE_STRING("SceneGraph");
Q_Q(QQuickWindow);
if (!renderer)
return;
+ if (rhi) {
+ // ### no offscreen ("renderTargetId") support yet
+ context->beginNextRhiFrame(renderer,
+ swapchain->currentFrameRenderTarget(),
+ rpDescForSwapchain,
+ swapchain->currentFrameCommandBuffer(),
+ emitBeforeRenderPassRecording,
+ emitAfterRenderPassRecording,
+ q);
+ } else {
+ context->beginNextFrame(renderer,
+ emitBeforeRenderPassRecording,
+ emitAfterRenderPassRecording,
+ q);
+ }
+
animationController->advance();
emit q->beforeRendering();
runAndClearJobs(&beforeRenderingJobs);
@@ -477,17 +515,45 @@ void QQuickWindowPrivate::renderSceneGraph(const QSize &size)
renderer->setDevicePixelRatio(1);
}
} else {
- QRect rect(QPoint(0, 0), devicePixelRatio * size);
+ QSize pixelSize;
+ QSizeF logicalSize;
+ if (surfaceSize.isEmpty()) {
+ pixelSize = size * devicePixelRatio;
+ logicalSize = size;
+ } else {
+ pixelSize = surfaceSize;
+ logicalSize = QSizeF(surfaceSize) / devicePixelRatio;
+ }
+ QRect rect(QPoint(0, 0), pixelSize);
renderer->setDeviceRect(rect);
renderer->setViewportRect(rect);
- renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), size));
+ const bool flipY = rhi ? !rhi->isYUpInNDC() : false;
+ QSGAbstractRenderer::MatrixTransformFlags matrixFlags = 0;
+ if (flipY)
+ matrixFlags |= QSGAbstractRenderer::MatrixTransformFlipY;
+ renderer->setProjectionMatrixToRect(QRectF(QPoint(0, 0), logicalSize), matrixFlags);
renderer->setDevicePixelRatio(devicePixelRatio);
}
- context->renderNextFrame(renderer, fboId);
+ if (rhi)
+ context->renderNextRhiFrame(renderer);
+ else
+ context->renderNextFrame(renderer, fboId);
}
emit q->afterRendering();
runAndClearJobs(&afterRenderingJobs);
+
+ if (rhi)
+ context->endNextRhiFrame(renderer);
+ else
+ context->endNextFrame(renderer);
+
+ if (renderer->hasCustomRenderModeWithContinuousUpdate()) {
+ // For the overdraw visualizer. This update is not urgent so avoid a
+ // direct update() call, this is only here to keep the overdraw
+ // visualization box rotating even when the scene is static.
+ QCoreApplication::postEvent(q, new QEvent(QEvent::Type(FullUpdateRequest)));
+ }
}
QQuickWindowPrivate::QQuickWindowPrivate()
@@ -496,7 +562,7 @@ QQuickWindowPrivate::QQuickWindowPrivate()
#if QT_CONFIG(cursor)
, cursorItem(nullptr)
#endif
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
, dragGrabber(nullptr)
#endif
, touchMouseId(-1)
@@ -523,8 +589,11 @@ QQuickWindowPrivate::QQuickWindowPrivate()
, renderTargetId(0)
, vaoHelper(nullptr)
, incubationController(nullptr)
+ , hasActiveSwapchain(false)
+ , hasRenderableSwapchain(false)
+ , swapchainJustBecameRenderable(false)
{
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
dragGrabber = new QQuickDragGrabber;
#endif
}
@@ -540,6 +609,7 @@ void QQuickWindowPrivate::init(QQuickWindow *c, QQuickRenderControl *control)
{
q_ptr = c;
+
Q_Q(QQuickWindow);
contentItem = new QQuickRootItem;
@@ -577,8 +647,12 @@ void QQuickWindowPrivate::init(QQuickWindow *c, QQuickRenderControl *control)
q->setSurfaceType(windowManager ? windowManager->windowSurfaceType() : QSurface::OpenGLSurface);
q->setFormat(sg->defaultSurfaceFormat());
+#if QT_CONFIG(vulkan)
+ if (q->surfaceType() == QSurface::VulkanSurface)
+ q->setVulkanInstance(QSGRhiSupport::vulkanInstance());
+#endif
- animationController = new QQuickAnimatorController(q);
+ animationController.reset(new QQuickAnimatorController(q));
QObject::connect(context, SIGNAL(initialized()), q, SIGNAL(sceneGraphInitialized()), Qt::DirectConnection);
QObject::connect(context, SIGNAL(invalidated()), q, SIGNAL(sceneGraphInvalidated()), Qt::DirectConnection);
@@ -639,7 +713,7 @@ bool QQuickWindowPrivate::checkIfDoubleTapped(ulong newPressEventTimestamp, QPoi
if (touchMousePressTimestamp > 0) {
QPoint distanceBetweenPresses = newPressPos - touchMousePressPos;
- const int doubleTapDistance = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt();
+ const int doubleTapDistance = QGuiApplication::styleHints()->touchDoubleTapDistance();
doubleClicked = (qAbs(distanceBetweenPresses.x()) <= doubleTapDistance) && (qAbs(distanceBetweenPresses.y()) <= doubleTapDistance);
if (doubleClicked) {
@@ -1346,7 +1420,7 @@ QQuickWindow::~QQuickWindow()
}
delete d->incubationController; d->incubationController = nullptr;
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
delete d->dragGrabber; d->dragGrabber = nullptr;
#endif
QQuickRootItem *root = d->contentItem;
@@ -1578,6 +1652,7 @@ bool QQuickWindowPrivate::clearHover(ulong timestamp)
bool accepted = false;
for (QQuickItem* item : qAsConst(hoverItems)) {
accepted = sendHoverEvent(QEvent::HoverLeave, item, pos, pos, QGuiApplication::keyboardModifiers(), timestamp, true) || accepted;
+#if QT_CONFIG(cursor)
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
if (itemPrivate->hasPointerHandlers()) {
pos = q->mapFromGlobal(QCursor::pos());
@@ -1589,6 +1664,7 @@ bool QQuickWindowPrivate::clearHover(ulong timestamp)
if (QQuickHoverHandler *hh = qmlobject_cast<QQuickHoverHandler *>(h))
hh->handlePointerEvent(pointerEvent);
}
+#endif
}
hoverItems.clear();
return accepted;
@@ -1627,7 +1703,9 @@ bool QQuickWindow::event(QEvent *e)
QGuiApplication::keyboardModifiers(), 0L, accepted);
d->lastMousePosition = enter->windowPos();
enter->setAccepted(accepted);
+#if QT_CONFIG(cursor)
d->updateCursor(mapFromGlobal(QCursor::pos()));
+#endif
return delivered;
}
break;
@@ -1635,7 +1713,7 @@ bool QQuickWindow::event(QEvent *e)
d->clearHover();
d->lastMousePosition = QPointF();
break;
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
case QEvent::DragEnter:
case QEvent::DragLeave:
case QEvent::DragMove:
@@ -1717,6 +1795,13 @@ void QQuickWindowPrivate::deliverKeyEvent(QKeyEvent *e)
{
if (activeFocusItem) {
QQuickItem *item = activeFocusItem;
+
+ // In case of generated event, trigger ShortcutOverride event
+ if (e->type() == QEvent::KeyPress && e->spontaneous() == false)
+ qt_sendShortcutOverrideEvent(item, e->timestamp(),
+ e->key(), e->modifiers(), e->text(),
+ e->isAutoRepeat(), e->count());
+
e->accept();
QCoreApplication::sendEvent(item, e);
while (!e->isAccepted() && (item = item->parentItem())) {
@@ -2691,7 +2776,7 @@ void QQuickWindowPrivate::deliverMatchingPointsToItem(QQuickItem *item, QQuickPo
// If the touch was accepted (regardless by whom or in what form),
// update accepted new points.
bool isPressOrRelease = pointerEvent->isPressEvent() || pointerEvent->isReleaseEvent();
- for (auto point: qAsConst(touchEvent->touchPoints())) {
+ for (const auto &point: qAsConst(touchEvent->touchPoints())) {
if (auto pointerEventPoint = ptEvent->pointById(point.id())) {
pointerEventPoint->setAccepted();
if (isPressOrRelease)
@@ -2701,7 +2786,7 @@ void QQuickWindowPrivate::deliverMatchingPointsToItem(QQuickItem *item, QQuickPo
} else {
// But if the event was not accepted then we know this item
// will not be interested in further updates for those touchpoint IDs either.
- for (auto point: qAsConst(touchEvent->touchPoints())) {
+ for (const auto &point: qAsConst(touchEvent->touchPoints())) {
if (point.state() == Qt::TouchPointPressed) {
if (auto *tp = ptEvent->pointById(point.id())) {
if (tp->exclusiveGrabber() == item) {
@@ -2714,7 +2799,7 @@ void QQuickWindowPrivate::deliverMatchingPointsToItem(QQuickItem *item, QQuickPo
}
}
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
void QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QEvent *event)
{
grabber->resetTarget();
@@ -2743,32 +2828,49 @@ void QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QEvent *e
for (; grabItem != grabber->end(); grabItem = grabber->release(grabItem))
QCoreApplication::sendEvent(**grabItem, &leaveEvent);
return;
- } else for (; grabItem != grabber->end(); grabItem = grabber->release(grabItem)) {
+ } else {
QDragMoveEvent *moveEvent = static_cast<QDragMoveEvent *>(event);
- if (deliverDragEvent(grabber, **grabItem, moveEvent)) {
- for (++grabItem; grabItem != grabber->end();) {
- QPointF p = (**grabItem)->mapFromScene(moveEvent->pos());
- if ((**grabItem)->contains(p)) {
- QDragMoveEvent translatedEvent(
- p.toPoint(),
- moveEvent->possibleActions(),
- moveEvent->mimeData(),
- moveEvent->mouseButtons(),
- moveEvent->keyboardModifiers());
- QQuickDropEventEx::copyActions(&translatedEvent, *moveEvent);
- QCoreApplication::sendEvent(**grabItem, &translatedEvent);
- ++grabItem;
- } else {
- QDragLeaveEvent leaveEvent;
- QCoreApplication::sendEvent(**grabItem, &leaveEvent);
- grabItem = grabber->release(grabItem);
- }
+
+ // Used to ensure we don't send DragEnterEvents to current drop targets,
+ // and to detect which current drop targets we have left
+ QVarLengthArray<QQuickItem*, 64> currentGrabItems;
+ for (; grabItem != grabber->end(); grabItem = grabber->release(grabItem))
+ currentGrabItems.append(**grabItem);
+
+ // Look for any other potential drop targets that are higher than the current ones
+ QDragEnterEvent enterEvent(
+ moveEvent->pos(),
+ moveEvent->possibleActions(),
+ moveEvent->mimeData(),
+ moveEvent->mouseButtons(),
+ moveEvent->keyboardModifiers());
+ QQuickDropEventEx::copyActions(&enterEvent, *moveEvent);
+ event->setAccepted(deliverDragEvent(grabber, contentItem, &enterEvent, &currentGrabItems));
+
+ for (grabItem = grabber->begin(); grabItem != grabber->end(); ++grabItem) {
+ int i = currentGrabItems.indexOf(**grabItem);
+ if (i >= 0) {
+ currentGrabItems.remove(i);
+ // Still grabbed: send move event
+ QDragMoveEvent translatedEvent(
+ (**grabItem)->mapFromScene(moveEvent->pos()).toPoint(),
+ moveEvent->possibleActions(),
+ moveEvent->mimeData(),
+ moveEvent->mouseButtons(),
+ moveEvent->keyboardModifiers());
+ QQuickDropEventEx::copyActions(&translatedEvent, *moveEvent);
+ QCoreApplication::sendEvent(**grabItem, &translatedEvent);
+ event->setAccepted(translatedEvent.isAccepted());
+ QQuickDropEventEx::copyActions(moveEvent, translatedEvent);
}
- return;
- } else {
- QDragLeaveEvent leaveEvent;
- QCoreApplication::sendEvent(**grabItem, &leaveEvent);
}
+
+ // Anything left in currentGrabItems is no longer a drop target and should be sent a DragLeaveEvent
+ QDragLeaveEvent leaveEvent;
+ for (QQuickItem *i : currentGrabItems)
+ QCoreApplication::sendEvent(i, &leaveEvent);
+
+ return;
}
}
if (event->type() == QEvent::DragEnter || event->type() == QEvent::DragMove) {
@@ -2784,9 +2886,8 @@ void QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QEvent *e
}
}
-bool QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QQuickItem *item, QDragMoveEvent *event)
+bool QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QQuickItem *item, QDragMoveEvent *event, QVarLengthArray<QQuickItem*, 64> *currentGrabItems)
{
- bool accepted = false;
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
if (!item->isVisible() || !item->isEnabled() || QQuickItemPrivate::get(item)->culled)
return false;
@@ -2805,12 +2906,24 @@ bool QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QQuickIte
event->keyboardModifiers());
QQuickDropEventEx::copyActions(&enterEvent, *event);
QList<QQuickItem *> children = itemPrivate->paintOrderChildItems();
+
+ // Check children in front of this item first
for (int ii = children.count() - 1; ii >= 0; --ii) {
- if (deliverDragEvent(grabber, children.at(ii), &enterEvent))
+ if (children.at(ii)->z() < 0)
+ continue;
+ if (deliverDragEvent(grabber, children.at(ii), &enterEvent, currentGrabItems))
return true;
}
if (itemContained) {
+ // If this item is currently grabbed, don't send it another DragEnter,
+ // just grab it again if it's still contained.
+ if (currentGrabItems && currentGrabItems->contains(item)) {
+ grabber->grab(item);
+ grabber->setTarget(item);
+ return true;
+ }
+
if (event->type() == QEvent::DragMove || itemPrivate->flags & QQuickItem::ItemAcceptsDrops) {
QDragMoveEvent translatedEvent(
p.toPoint(),
@@ -2827,17 +2940,26 @@ bool QQuickWindowPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QQuickIte
if (event->type() == QEvent::DragEnter) {
if (translatedEvent.isAccepted()) {
grabber->grab(item);
- accepted = true;
+ grabber->setTarget(item);
+ return true;
}
} else {
- accepted = true;
+ return true;
}
}
}
- return accepted;
+ // Check children behind this item if this item or any higher children have not accepted
+ for (int ii = children.count() - 1; ii >= 0; --ii) {
+ if (children.at(ii)->z() >= 0)
+ continue;
+ if (deliverDragEvent(grabber, children.at(ii), &enterEvent, currentGrabItems))
+ return true;
+ }
+
+ return false;
}
-#endif // draganddrop
+#endif // quick_draganddrop
#if QT_CONFIG(cursor)
void QQuickWindowPrivate::updateCursor(const QPointF &scenePos)
@@ -2942,7 +3064,7 @@ bool QQuickWindowPrivate::sendFilteredPointerEventImpl(QQuickPointerEvent *event
if (filteringParent->childMouseEventFilter(receiver, filteringParentTouchEvent.data())) {
qCDebug(DBG_TOUCH) << "touch event intercepted by childMouseEventFilter of " << filteringParent;
skipDelivery.append(filteringParent);
- for (auto point: qAsConst(filteringParentTouchEvent->touchPoints())) {
+ for (const auto &point: qAsConst(filteringParentTouchEvent->touchPoints())) {
QQuickEventPoint *pt = event->pointById(point.id());
pt->setAccepted();
pt->setGrabberItem(filteringParent);
@@ -3625,24 +3747,20 @@ void QQuickWindow::setTransientParent_helper(QQuickWindow *window)
/*!
Returns the OpenGL context used for rendering.
- If the scene graph is not ready, or the scene graph is not using OpenGL,
- this function will return null.
-
- \note If using a scene graph adaptation other than OpenGL this
- function will return nullptr.
+ \note If the scene graph is not ready, or the scene graph is not using
+ OpenGL (or RHI over OpenGL), this function will return null.
\sa sceneGraphInitialized(), sceneGraphInvalidated()
*/
-
QOpenGLContext *QQuickWindow::openglContext() const
{
#if QT_CONFIG(opengl)
Q_D(const QQuickWindow);
if (d->context && d->context->isValid()) {
QSGRendererInterface *rif = d->context->sceneGraphContext()->rendererInterface(d->context);
- if (rif && rif->graphicsApi() == QSGRendererInterface::OpenGL) {
- auto openglRenderContext = static_cast<const QSGDefaultRenderContext *>(d->context);
- return openglRenderContext->openglContext();
+ if (rif) {
+ return reinterpret_cast<QOpenGLContext *>(rif->getResource(const_cast<QQuickWindow *>(this),
+ QSGRendererInterface::OpenGLContextResource));
}
}
#endif
@@ -3781,6 +3899,8 @@ bool QQuickWindow::isSceneGraphInitialized() const
This function only has an effect when using the default OpenGL scene
graph adaptation.
+ \note This function has no effect when running on the RHI graphics abstraction.
+
\warning
This function can only be called from the thread doing
the rendering.
@@ -3789,6 +3909,9 @@ bool QQuickWindow::isSceneGraphInitialized() const
void QQuickWindow::setRenderTarget(QOpenGLFramebufferObject *fbo)
{
Q_D(QQuickWindow);
+ if (d->rhi)
+ return;
+
if (d->context && QThread::currentThread() != d->context->thread()) {
qWarning("QQuickWindow::setRenderTarget: Cannot set render target from outside the rendering thread");
return;
@@ -3870,9 +3993,11 @@ QSize QQuickWindow::renderTargetSize() const
The default is to render to the surface of the window, in which
case the render target is 0.
- \note
- This function will return nullptr when not using the OpenGL scene
+ \note This function will return nullptr when not using the OpenGL scene
graph adaptation.
+
+ \note This function has no effect and returns nullptr when running on the
+ RHI graphics abstraction.
*/
QOpenGLFramebufferObject *QQuickWindow::renderTarget() const
{
@@ -3898,12 +4023,23 @@ QImage QQuickWindow::grabWindow()
Q_D(QQuickWindow);
if (!isVisible() && !d->renderControl) {
+ // backends like software and d3d12 can grab regardless of the window state
if (d->windowManager && (d->windowManager->flags() & QSGRenderLoop::SupportsGrabWithoutExpose))
return d->windowManager->grab(this);
}
-#if QT_CONFIG(opengl)
if (!isVisible() && !d->renderControl) {
+ if (d->rhi) {
+ // ### we may need a full offscreen round when non-exposed...
+
+ if (d->renderControl)
+ return d->renderControl->grab();
+ else if (d->windowManager)
+ return d->windowManager->grab(this);
+ return QImage();
+ }
+
+#if QT_CONFIG(opengl)
auto openglRenderContext = static_cast<QSGDefaultRenderContext *>(d->context);
if (!openglRenderContext->openglContext()) {
if (!handle() || !size().isValid()) {
@@ -3916,7 +4052,9 @@ QImage QQuickWindow::grabWindow()
context.setShareContext(qt_gl_global_share_context());
context.create();
context.makeCurrent(this);
- d->context->initialize(&context);
+ QSGDefaultRenderContext::InitParams rcParams;
+ rcParams.openGLContext = &context;
+ d->context->initialize(&rcParams);
d->polishItems();
d->syncSceneGraph();
@@ -3931,8 +4069,9 @@ QImage QQuickWindow::grabWindow()
return image;
}
- }
#endif
+ }
+
if (d->renderControl)
return d->renderControl->grab();
else if (d->windowManager)
@@ -4070,6 +4209,19 @@ QQmlIncubationController *QQuickWindow::incubationController() const
The OpenGL context used for rendering the scene graph will be bound
at this point.
+ When using the RHI, the signal is emitted after the preparations for the
+ frame have been done, meaning there is a command buffer in recording mode,
+ where applicable. If desired, the slot function connected to this signal
+ can query native resources like the command before via
+ QSGRendererInterface. Note however that the recording of the main render
+ pass is not yet started at this point and it is not possible to add
+ commands within that pass. Starting a pass means clearing the color, depth,
+ and stencil buffers so it is not possible to achieve an underlay type of
+ rendering by just connecting to this signal. Rather, connect to
+ beforeRenderPassRecording(). However, connecting to this signal is still
+ important if the recording of copy type of commands is desired since those
+ cannot be enqueued within a render pass.
+
\warning This signal is emitted from the scene graph rendering thread. If your
slot function needs to finish before execution continues, you must make sure that
the connection is direct (see Qt::ConnectionType).
@@ -4091,6 +4243,18 @@ QQmlIncubationController *QQuickWindow::incubationController() const
The OpenGL context used for rendering the scene graph will be bound at this point.
+ When using the RHI, the signal is emitted after scene graph has added its
+ commands to the command buffer, which is not yet submitted to the graphics
+ queue. If desired, the slot function connected to this signal can query
+ native resources, like the command buffer, before via QSGRendererInterface.
+ Note however that the render pass (or passes) are already recorded at this
+ point and it is not possible to add more commands within the scenegraph's
+ pass. Instead, use afterRenderPassRecording() for that. This signal has
+ therefore limited use and is rarely needed in an RHI-based setup. Rather,
+ it is the combination of beforeRendering() + beforeRenderPassRecording() or
+ beforeRendering() + afterRenderPassRecording() that is typically used to
+ achieve under- or overlaying of the custom rendering.
+
\warning This signal is emitted from the scene graph rendering thread. If your
slot function needs to finish before execution continues, you must make sure that
the connection is direct (see Qt::ConnectionType).
@@ -4103,14 +4267,78 @@ QQmlIncubationController *QQuickWindow::incubationController() const
*/
/*!
+ \fn void QQuickWindow::beforeRenderPassRecording()
+
+ This signal is emitted before the scenegraph starts recording commands for
+ the main render pass. (Layers have their own passes and are fully recorded
+ by the time this signal is emitted.) The render pass is already active on
+ the command buffer when the signal is emitted.
+
+ This signal is applicable when using the RHI graphics abstraction with the
+ scenegraph. It is emitted later than beforeRendering() and it guarantees
+ that not just the frame, but also the recording of the scenegraph's main
+ render pass is active. This allows inserting commands without having to
+ generate an entire, separate render pass (which would typically clear the
+ attached images). The native graphics objects can be queried via
+ QSGRendererInterface.
+
+ When not running with the RHI (and using OpenGL directly), the signal is
+ emitted after the renderer has cleared the render target. This makes it
+ possible to create applications that function identically both with and
+ without the RHI.
+
+ \note Resource updates (uploads, copies) typically cannot be enqueued from
+ within a render pass. Therefore, more complex user rendering will need to
+ connect to both beforeRendering() and this signal.
+
+ \warning This signal is emitted from the scene graph rendering thread. If your
+ slot function needs to finish before execution continues, you must make sure that
+ the connection is direct (see Qt::ConnectionType).
+
+ \since 5.14
+*/
+
+/*!
+ \fn void QQuickWindow::afterRenderPassRecording()
+
+ This signal is emitted after the scenegraph has recorded the commands for
+ its main render pass, but the pass is not yet finalized on the command
+ buffer.
+
+ This signal is applicable when using the RHI graphics abstraction with the
+ scenegraph. It is emitted earlier than afterRendering() and it guarantees
+ that not just the frame, but also the recording of the scenegraph's main
+ render pass is still active. This allows inserting commands without having
+ to generate an entire, separate render pass (which would typically clear
+ the attached images). The native graphics objects can be queried via
+ QSGRendererInterface.
+
+ When not running with the RHI (and using OpenGL directly), the signal is
+ emitted after the renderer has finished its rendering, but before
+ afterRendering(). This makes it possible to create applications that
+ function identically both with and without the RHI.
+
+ \note Resource updates (uploads, copies) typically cannot be enqueued from
+ within a render pass. Therefore, more complex user rendering will need to
+ connect to both beforeRendering() and this signal.
+
+ \warning This signal is emitted from the scene graph rendering thread. If your
+ slot function needs to finish before execution continues, you must make sure that
+ the connection is direct (see Qt::ConnectionType).
+
+ \since 5.14
+*/
+
+/*!
\fn void QQuickWindow::afterAnimating()
This signal is emitted on the gui thread before requesting the render thread to
perform the synchronization of the scene graph.
- Unlike the other similar signals, this one is emitted on the gui thread instead
- of the render thread. It can be used to synchronize external animation systems
- with the QML content.
+ Unlike the other similar signals, this one is emitted on the gui thread
+ instead of the render thread. It can be used to synchronize external
+ animation systems with the QML content. At the same time this means that
+ this signal is not suitable for triggering graphics operations.
\since 5.3
*/
@@ -4170,7 +4398,15 @@ QQmlIncubationController *QQuickWindow::incubationController() const
The color buffer is cleared by default.
- \sa beforeRendering()
+ \warning This flag is ignored completely when running with the RHI graphics
+ abstraction instead of using OpenGL directly. As explicit clear commands
+ simply do not exist in some modern APIs, the scene graph cannot offer this
+ flexibility anymore. The images associated with a render target will always
+ get cleared when a render pass starts. As a solution, an alternative to
+ disabling scene graph issued clears is provided in form of the
+ beforeRenderPassRecording() signal.
+
+ \sa beforeRendering(), beforeRenderPassRecording()
*/
void QQuickWindow::setClearBeforeRendering(bool enabled)
@@ -4274,24 +4510,129 @@ QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image, CreateText
\note This function only has an effect when using the default OpenGL scene graph
adaptation.
+ \note This function has no effect when running on the RHI graphics
+ abstraction. Use createTextureFromNativeObject() instead.
+
\sa sceneGraphInitialized(), QSGTexture
*/
QSGTexture *QQuickWindow::createTextureFromId(uint id, const QSize &size, CreateTextureOptions options) const
{
#if QT_CONFIG(opengl)
- if (openglContext()) {
- QSGPlainTexture *texture = new QSGPlainTexture();
- texture->setTextureId(id);
+ Q_D(const QQuickWindow);
+ if (!d->rhi) {
+ if (openglContext()) {
+ QSGPlainTexture *texture = new QSGPlainTexture();
+ texture->setTextureId(id);
+ texture->setHasAlphaChannel(options & TextureHasAlphaChannel);
+ texture->setOwnsTexture(options & TextureOwnsGLTexture);
+ texture->setTextureSize(size);
+ return texture;
+ }
+ } else {
+ qWarning("createTextureFromId() must not be called when running on the RHI. "
+ "Use createTextureFromNativeObject() instead.");
+ }
+#else
+ Q_UNUSED(id)
+ Q_UNUSED(size)
+ Q_UNUSED(options)
+#endif
+ return nullptr;
+}
+
+/*!
+ \enum QQuickWindow::NativeObjectType
+ \since 5.14
+
+ Specifies the type of the native object passed to functions such as
+ createTextureFromNativeObject().
+
+ \value NativeObjectTexture The native object is a 2D texture (OpenGL,
+ Direct3D 11, Metal) or image (Vulkan).
+ */
+
+/*!
+ Creates a new QSGTexture object from an existing native object.
+
+ The native object is wrapped, but not owned, by the resulting QSGTexture.
+ The caller of the function is responsible for deleting the returned
+ QSGTexture, but that will not destroy the underlying native object.
+
+ \a type specifies the type of the object. In practice the type is
+ NativeObjectTexture, indicating that the native object is a texture or
+ image of the underlying graphics API. Other types may be introduced in the
+ future.
+
+ This function is currently suitable for 2D RGBA textures only.
+
+ Unlike createTextureFromId(), this function supports both direct OpenGL
+ usage and the RHI abstracted rendering path.
+
+ \warning This function will return null if the scenegraph has not yet been
+ initialized.
+
+ Use \a options to customize the texture attributes. Only the
+ TextureHasAlphaChannel and TextureHasMipmaps are taken into account here.
+
+ \warning Unlike createTextureFromId(), this function never takes ownership
+ of the native object, and the TextureOwnsGLTexture flag is ignored.
+
+ \a size specifies the size in pixels.
+
+ \a nativeObjectPtr is a pointer to the native object handle. With OpenGL,
+ the native handle is a GLuint value, so \a nativeObjectPtr is then a
+ pointer to a GLuint. With Vulkan, the native handle is a VkImage, so \a
+ nativeObjectPtr is a pointer to a VkImage. With Direct3D 11 and Metal \a
+ nativeObjectPtr is a pointer to a ID3D11Texture2D or MTLTexture pointer.
+
+ \note Pay attention to the fact that \a nativeObjectPtr is always a pointer
+ to the native texture handle type, even if the native type itself is a
+ pointer.
+
+ \a nativeLayout is only used for APIs like Vulkan. When applicable, it must
+ specify the current image layout, such as, a VkImageLayout value.
+
+ \sa sceneGraphInitialized(), QSGTextures
+
+ \since 5.14
+ */
+QSGTexture *QQuickWindow::createTextureFromNativeObject(NativeObjectType type,
+ const void *nativeObjectPtr,
+ int nativeLayout,
+ const QSize &size,
+ CreateTextureOptions options) const
+{
+ if (type != NativeObjectTexture) {
+ qWarning("createTextureFromNativeObject: only textures are supported");
+ return nullptr;
+ }
+
+#if QT_CONFIG(opengl) /* || QT_CONFIG(vulkan) || defined(Q_OS_WIN) || defined(Q_OS_DARWIN) */
+ Q_D(const QQuickWindow);
+ if (d->rhi) {
+ QSGPlainTexture *texture = new QSGPlainTexture;
+ texture->setTextureFromNativeObject(d->rhi, type, nativeObjectPtr, nativeLayout,
+ size, options.testFlag(TextureHasMipmaps));
+ texture->setHasAlphaChannel(options & TextureHasAlphaChannel);
+ // note that the QRhiTexture does not (and cannot) own the native object
+ texture->setOwnsTexture(true); // texture meaning the QRhiTexture here, not the native object
+ texture->setTextureSize(size);
+ return texture;
+ } else if (openglContext()) {
+ QSGPlainTexture *texture = new QSGPlainTexture;
+ texture->setTextureId(*reinterpret_cast<const uint *>(nativeObjectPtr));
texture->setHasAlphaChannel(options & TextureHasAlphaChannel);
texture->setOwnsTexture(options & TextureOwnsGLTexture);
texture->setTextureSize(size);
return texture;
}
#else
- Q_UNUSED(id)
- Q_UNUSED(size)
- Q_UNUSED(options)
+ Q_UNUSED(nativeObjectPtr);
+ Q_UNUSED(nativeLayout);
+ Q_UNUSED(size);
+ Q_UNUSED(options);
#endif
+
return nullptr;
}
@@ -4382,15 +4723,19 @@ void QQuickWindow::setDefaultAlphaBuffer(bool useAlpha)
\note This function only has an effect when using the default OpenGL scene graph
adaptation.
- \sa QQuickWindow::beforeRendering()
+ \note This function has no effect when running on the RHI graphics
+ abstraction. With the RHI, the functions to call when enqueuing native
+ graphics commands are beginExternalCommands() and endExternalCommands().
+
+ \sa QQuickWindow::beforeRendering(), beginExternalCommands(), endExternalCommands()
*/
void QQuickWindow::resetOpenGLState()
{
- if (!openglContext())
- return;
-
Q_D(QQuickWindow);
+ if (d->rhi || !openglContext())
+ return;
+
QOpenGLContext *ctx = openglContext();
QOpenGLFunctions *gl = ctx->functions();
@@ -4437,6 +4782,132 @@ void QQuickWindow::resetOpenGLState()
QOpenGLFramebufferObject::bindDefault();
}
#endif
+
+/*!
+ \struct QQuickWindow::GraphicsStateInfo
+ \inmodule QtQuick
+ \since 5.14
+
+ \brief Describes some of the RHI's graphics state at the point of a
+ \l{QQuickWindow::beginExternalCommands()}{beginExternalCommands()} call.
+ */
+
+/*!
+ \return a reference to a GraphicsStateInfo struct describing some of the
+ RHI's internal state, in particular, the double or tripple buffering status
+ of the backend (such as, the Vulkan or Metal integrations). This is
+ relevant when the underlying graphics APIs is Vulkan or Metal, and the
+ external rendering code wishes to perform double or tripple buffering of
+ its own often-changing resources, such as, uniform buffers, in order to
+ avoid stalling the pipeline.
+ */
+const QQuickWindow::GraphicsStateInfo &QQuickWindow::graphicsStateInfo()
+{
+ Q_D(QQuickWindow);
+ if (d->rhi) {
+ d->rhiStateInfo.currentFrameSlot = d->rhi->currentFrameSlot();
+ d->rhiStateInfo.framesInFlight = d->rhi->resourceLimit(QRhi::FramesInFlight);
+ }
+ return d->rhiStateInfo;
+}
+
+/*!
+ When mixing raw graphics (OpenGL, Vulkan, Metal, etc.) commands with scene
+ graph rendering, it is necessary to call this function before recording
+ commands to the command buffer used by the scene graph to render its main
+ render pass. This is to avoid clobbering state.
+
+ In practice this function is often called from a slot connected to the
+ beforeRenderPassRecording() or afterRenderPassRecording() signals.
+
+ The function does not need to be called when recording commands to the
+ application's own command buffer (such as, a VkCommandBuffer or
+ MTLCommandBuffer + MTLRenderCommandEncoder created and managed by the
+ application, not retrieved from the scene graph). With graphics APIs where
+ no native command buffer concept is exposed (OpenGL, Direct 3D 11),
+ beginExternalCommands() and endExternalCommands() together provide a
+ replacement for resetOpenGLState().
+
+ Calling this function and endExternalCommands() is not necessary within the
+ \l{QSGRenderNode::render()}{render()} implementation of a QSGRenderNode
+ because the scene graph performs the necessary steps implicitly for render
+ nodes.
+
+ Native graphics objects (such as, graphics device, command buffer or
+ encoder) are accessible via QSGRendererInterface::getResource().
+
+ \warning Watch out for the fact that
+ QSGRendererInterface::CommandListResource may return a different object
+ between beginExternalCommands() - endExternalCommands(). This can happen
+ when the underlying implementation provides a dedicated secondary command
+ buffer for recording external graphics commands within a render pass.
+ Therefore, always query CommandListResource after calling this function. Do
+ not attempt to reuse an object from an earlier query.
+
+ \note This function has no effect when the scene graph is using OpenGL
+ directly and the RHI graphics abstraction layer is not in use. Refer to
+ resetOpenGLState() in that case.
+
+ \sa endExternalCommands()
+
+ \since 5.14
+ */
+void QQuickWindow::beginExternalCommands()
+{
+#if QT_CONFIG(opengl) /* || QT_CONFIG(vulkan) || defined(Q_OS_WIN) || defined(Q_OS_DARWIN) */
+ Q_D(QQuickWindow);
+ if (d->rhi && d->context && d->context->isValid()) {
+ QSGDefaultRenderContext *rc = static_cast<QSGDefaultRenderContext *>(d->context);
+ QRhiCommandBuffer *cb = rc->currentFrameCommandBuffer();
+ if (cb)
+ cb->beginExternal();
+ }
+#endif
+}
+
+/*!
+ When mixing raw graphics (OpenGL, Vulkan, Metal, etc.) commands with scene
+ graph rendering, it is necessary to call this function after recording
+ commands to the command buffer used by the scene graph to render its main
+ render pass. This is to avoid clobbering state.
+
+ In practice this function is often called from a slot connected to the
+ beforeRenderPassRecording() or afterRenderPassRecording() signals.
+
+ The function does not need to be called when recording commands to the
+ application's own command buffer (such as, a VkCommandBuffer or
+ MTLCommandBuffer + MTLRenderCommandEncoder created and managed by the
+ application, not retrieved from the scene graph). With graphics APIs where
+ no native command buffer concept is exposed (OpenGL, Direct 3D 11),
+ beginExternalCommands() and endExternalCommands() together provide a
+ replacement for resetOpenGLState().
+
+ Calling this function and beginExternalCommands() is not necessary within the
+ \l{QSGRenderNode::render()}{render()} implementation of a QSGRenderNode
+ because the scene graph performs the necessary steps implicitly for render
+ nodes.
+
+ \note This function has no effect when the scene graph is using OpenGL
+ directly and the RHI graphics abstraction layer is not in use. Refer to
+ resetOpenGLState() in that case.
+
+ \sa beginExternalCommands()
+
+ \since 5.14
+ */
+void QQuickWindow::endExternalCommands()
+{
+#if QT_CONFIG(opengl) /* || QT_CONFIG(vulkan) || defined(Q_OS_WIN) || defined(Q_OS_DARWIN) */
+ Q_D(QQuickWindow);
+ if (d->rhi && d->context && d->context->isValid()) {
+ QSGDefaultRenderContext *rc = static_cast<QSGDefaultRenderContext *>(d->context);
+ QRhiCommandBuffer *cb = rc->currentFrameCommandBuffer();
+ if (cb)
+ cb->endExternal();
+ }
+#endif
+}
+
/*!
\qmlproperty string Window::title
@@ -5022,6 +5493,10 @@ void QQuickWindow::setSceneGraphBackend(QSGRendererInterface::GraphicsApi api)
default:
break;
}
+#if QT_CONFIG(opengl) /* || QT_CONFIG(vulkan) || defined(Q_OS_WIN) || defined(Q_OS_DARWIN) */
+ if (QSGRendererInterface::isApiRhiBased(api))
+ QSGRhiSupport::configure(api);
+#endif
}
/*!
diff --git a/src/quick/items/qquickwindow.h b/src/quick/items/qquickwindow.h
index 53fe0a4c4b..56d50cec2a 100644
--- a/src/quick/items/qquickwindow.h
+++ b/src/quick/items/qquickwindow.h
@@ -66,6 +66,7 @@ class QQuickRenderControl;
class QSGRectangleNode;
class QSGImageNode;
class QSGNinePatchNode;
+class QRhi;
class Q_QUICK_EXPORT QQuickWindow : public QWindow
{
@@ -108,6 +109,11 @@ public:
};
Q_ENUM(TextRenderType)
+ enum NativeObjectType {
+ NativeObjectTexture
+ };
+ Q_ENUM(NativeObjectType)
+
explicit QQuickWindow(QWindow *parent = nullptr);
explicit QQuickWindow(QQuickRenderControl *renderControl);
@@ -135,6 +141,13 @@ public:
#if QT_CONFIG(opengl)
void resetOpenGLState();
#endif
+ struct GraphicsStateInfo {
+ int currentFrameSlot;
+ int framesInFlight;
+ };
+ const GraphicsStateInfo &graphicsStateInfo();
+ void beginExternalCommands();
+ void endExternalCommands();
QQmlIncubationController *incubationController() const;
#if QT_CONFIG(accessibility)
@@ -145,6 +158,11 @@ public:
QSGTexture *createTextureFromImage(const QImage &image) const;
QSGTexture *createTextureFromImage(const QImage &image, CreateTextureOptions options) const;
QSGTexture *createTextureFromId(uint id, const QSize &size, CreateTextureOptions options = CreateTextureOption()) const;
+ QSGTexture *createTextureFromNativeObject(NativeObjectType type,
+ const void *nativeObjectPtr,
+ int nativeLayout,
+ const QSize &size,
+ CreateTextureOptions options = CreateTextureOption()) const;
void setClearBeforeRendering(bool enabled);
bool clearBeforeRendering() const;
@@ -198,6 +216,8 @@ Q_SIGNALS:
Q_REVISION(1) void activeFocusItemChanged();
Q_REVISION(2) void sceneGraphError(QQuickWindow::SceneGraphError error, const QString &message);
+ Q_REVISION(14) void beforeRenderPassRecording();
+ Q_REVISION(14) void afterRenderPassRecording();
public Q_SLOTS:
void update();
diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h
index 63760a3b68..165859b5f3 100644
--- a/src/quick/items/qquickwindow_p.h
+++ b/src/quick/items/qquickwindow_p.h
@@ -82,6 +82,10 @@ class QQuickWindowPrivate;
class QQuickWindowRenderLoop;
class QSGRenderLoop;
class QTouchEvent;
+class QRhi;
+class QRhiSwapChain;
+class QRhiRenderBuffer;
+class QRhiRenderPassDescriptor;
//Make it easy to identify and customize the root item if needed
class QQuickRootItem : public QQuickItem
@@ -130,7 +134,7 @@ public:
#if QT_CONFIG(cursor)
QQuickItem *cursorItem;
#endif
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
QQuickDragGrabber *dragGrabber;
#endif
int touchMouseId;
@@ -186,9 +190,9 @@ public:
Qt::KeyboardModifiers modifiers, ulong timestamp, bool accepted);
bool clearHover(ulong timestamp = 0);
-#if QT_CONFIG(draganddrop)
+#if QT_CONFIG(quick_draganddrop)
void deliverDragEvent(QQuickDragGrabber *, QEvent *);
- bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *);
+ bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *, QVarLengthArray<QQuickItem*, 64> *currentGrabItems = nullptr);
#endif
#if QT_CONFIG(cursor)
void updateCursor(const QPointF &scenePos);
@@ -215,7 +219,7 @@ public:
void polishItems();
void forcePolish();
void syncSceneGraph();
- void renderSceneGraph(const QSize &size);
+ void renderSceneGraph(const QSize &size, const QSize &surfaceSize = QSize());
bool isRenderable() const;
@@ -250,7 +254,7 @@ public:
QSGRenderLoop *windowManager;
QQuickRenderControl *renderControl;
- QQuickAnimatorController *animationController;
+ QScopedPointer<QQuickAnimatorController> animationController;
QScopedPointer<QTouchEvent> delayedTouch;
int pointerEventRecursionGuard;
@@ -317,6 +321,9 @@ public:
QString *untranslatedMessage,
bool isEs);
+ static void emitBeforeRenderPassRecording(void *ud);
+ static void emitAfterRenderPassRecording(void *ud);
+
QMutex renderJobMutex;
QList<QRunnable *> beforeSynchronizingJobs;
QList<QRunnable *> afterSynchronizingJobs;
@@ -326,6 +333,15 @@ public:
void runAndClearJobs(QList<QRunnable *> *jobs);
+ QQuickWindow::GraphicsStateInfo rhiStateInfo;
+ QRhi *rhi = nullptr;
+ QRhiSwapChain *swapchain = nullptr;
+ QRhiRenderBuffer *depthStencilForSwapchain = nullptr;
+ QRhiRenderPassDescriptor *rpDescForSwapchain = nullptr;
+ uint hasActiveSwapchain : 1;
+ uint hasRenderableSwapchain : 1;
+ uint swapchainJustBecameRenderable : 1;
+
private:
static void cleanupNodesOnShutdown(QQuickItem *);
};
diff --git a/src/quick/items/qquickwindowmodule.cpp b/src/quick/items/qquickwindowmodule.cpp
index 2b109c0897..4b2b8f498d 100644
--- a/src/quick/items/qquickwindowmodule.cpp
+++ b/src/quick/items/qquickwindowmodule.cpp
@@ -205,15 +205,16 @@ void QQuickWindowModule::defineModule()
qmlRegisterRevision<QQuickWindow,1>(uri, 2, 1);//Type moved to a subclass, but also has new members
qmlRegisterRevision<QQuickWindow,2>(uri, 2, 2);
qmlRegisterType<QQuickWindowQmlImpl>(uri, 2, 1, "Window");
- qmlRegisterType<QQuickWindowQmlImpl,1>(uri, 2, 2, "Window");
- qmlRegisterType<QQuickWindowQmlImpl,2>(uri, 2, 3, "Window");
+ qmlRegisterType<QQuickWindowQmlImpl,2>(uri, 2, 2, "Window");
+ qmlRegisterType<QQuickWindowQmlImpl,3>(uri, 2, 3, "Window");
qmlRegisterUncreatableType<QQuickScreen>(uri, 2, 0, "Screen", QStringLiteral("Screen can only be used via the attached property."));
- qmlRegisterUncreatableType<QQuickScreen,1>(uri, 2, 3, "Screen", QStringLiteral("Screen can only be used via the attached property."));
- qmlRegisterUncreatableType<QQuickScreenInfo,2>(uri, 2, 3, "ScreenInfo", QStringLiteral("ScreenInfo can only be used via the attached property."));
+ qmlRegisterUncreatableType<QQuickScreen,3>(uri, 2, 3, "Screen", QStringLiteral("Screen can only be used via the attached property."));
+ qmlRegisterUncreatableType<QQuickScreenInfo,3>(uri, 2, 3, "ScreenInfo", QStringLiteral("ScreenInfo can only be used via the attached property."));
qmlRegisterUncreatableType<QQuickScreenInfo,10>(uri, 2, 10, "ScreenInfo", QStringLiteral("ScreenInfo can only be used via the attached property."));
qmlRegisterRevision<QWindow,13>(uri, 2, 13);
qmlRegisterRevision<QQuickWindow,13>(uri, 2, 13);
qmlRegisterType<QQuickWindowQmlImpl,13>(uri, 2, 13, "Window");
+ qmlRegisterRevision<QQuickWindow,14>(uri, 2, 14);
}
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickwindowmodule_p.h b/src/quick/items/qquickwindowmodule_p.h
index e7033e9b8d..1dcf1a1021 100644
--- a/src/quick/items/qquickwindowmodule_p.h
+++ b/src/quick/items/qquickwindowmodule_p.h
@@ -67,7 +67,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickWindowQmlImpl : public QQuickWindow, public Q
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged)
- Q_PROPERTY(QObject *screen READ screen WRITE setScreen NOTIFY screenChanged REVISION 2)
+ Q_PROPERTY(QObject *screen READ screen WRITE setScreen NOTIFY screenChanged REVISION 3)
public:
QQuickWindowQmlImpl(QWindow *parent = nullptr);
@@ -83,7 +83,7 @@ public:
Q_SIGNALS:
void visibleChanged(bool arg);
void visibilityChanged(QWindow::Visibility visibility);
- Q_REVISION(2) void screenChanged();
+ Q_REVISION(3) void screenChanged();
protected:
void classBegin() override;
diff --git a/src/quick/qtquick2.cpp b/src/quick/qtquick2.cpp
index 63f3b91b82..7a04c2146c 100644
--- a/src/quick/qtquick2.cpp
+++ b/src/quick/qtquick2.cpp
@@ -183,7 +183,6 @@ void QQmlQtQuick2Module::defineModule()
QQuick_initializeProviders();
QQuickUtilModule::defineModule();
- QQmlEnginePrivate::defineQtQuick2Module();
QQuickItemsModule::defineModule();
qmlRegisterUncreatableType<QQuickApplication>("QtQuick",2,0,"Application", QQuickApplication::tr("Application is an abstract class"));
diff --git a/src/quick/quick.pro b/src/quick/quick.pro
index 37d2ad1172..700f794af4 100644
--- a/src/quick/quick.pro
+++ b/src/quick/quick.pro
@@ -1,6 +1,6 @@
TARGET = QtQuick
-QT = core-private gui-private qml-private
+QT = core-private gui-private qml-private qmlmodels-private
qtConfig(qml-network): \
QT_PRIVATE += network
diff --git a/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer.cpp b/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer.cpp
index af3b901af4..ca620965a8 100644
--- a/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer.cpp
@@ -77,11 +77,6 @@ QSGSoftwareRenderableNode *QSGAbstractSoftwareRenderer::renderableNode(QSGNode *
return m_nodes.value(node, nullptr);
}
-const QLinkedList<QSGSoftwareRenderableNode*> &QSGAbstractSoftwareRenderer::renderableNodes() const
-{
- return m_renderableNodes;
-}
-
void QSGAbstractSoftwareRenderer::addNodeMapping(QSGNode *node, QSGSoftwareRenderableNode *renderableNode)
{
m_nodes.insert(node, renderableNode);
diff --git a/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer_p.h b/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer_p.h
index 875569454f..e1b477ab97 100644
--- a/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer_p.h
+++ b/src/quick/scenegraph/adaptations/software/qsgabstractsoftwarerenderer_p.h
@@ -54,7 +54,6 @@
#include <private/qsgrenderer_p.h>
#include <QtCore/QHash>
-#include <QtCore/QLinkedList>
QT_BEGIN_NAMESPACE
@@ -88,7 +87,6 @@ protected:
QRect backgroundRect();
// only known after calling optimizeRenderList()
bool isOpaque() const { return m_isOpaque; }
- const QLinkedList<QSGSoftwareRenderableNode*> &renderableNodes() const;
private:
void nodeAdded(QSGNode *node);
@@ -99,7 +97,7 @@ private:
void nodeOpacityUpdated(QSGNode *node);
QHash<QSGNode*, QSGSoftwareRenderableNode*> m_nodes;
- QLinkedList<QSGSoftwareRenderableNode*> m_renderableNodes;
+ QVector<QSGSoftwareRenderableNode*> m_renderableNodes;
QSGSimpleRectNode *m_background;
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp
index 5b5bf005d8..7b5ee66df6 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext.cpp
@@ -99,8 +99,9 @@ QSGInternalRectangleNode *QSGSoftwareContext::createInternalRectangleNode()
return new QSGSoftwareInternalRectangleNode();
}
-QSGInternalImageNode *QSGSoftwareContext::createInternalImageNode()
+QSGInternalImageNode *QSGSoftwareContext::createInternalImageNode(QSGRenderContext *renderContext)
{
+ Q_UNUSED(renderContext);
return new QSGSoftwareInternalImageNode();
}
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext_p.h b/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext_p.h
index 1f14717416..84f468ce33 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext_p.h
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarecontext_p.h
@@ -89,7 +89,7 @@ public:
QSGRenderContext *createRenderContext() override { return new QSGSoftwareRenderContext(this); }
QSGInternalRectangleNode *createInternalRectangleNode() override;
- QSGInternalImageNode *createInternalImageNode() override;
+ QSGInternalImageNode *createInternalImageNode(QSGRenderContext *renderContext) override;
QSGPainterNode *createPainterNode(QQuickPaintedItem *item) override;
QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode) override;
QSGLayer *createLayer(QSGRenderContext *renderContext) override;
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer.cpp
index 70378d2950..683ccb60c2 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer.cpp
@@ -45,7 +45,8 @@
QT_BEGIN_NAMESPACE
QSGSoftwareLayer::QSGSoftwareLayer(QSGRenderContext *renderContext)
- : m_item(nullptr)
+ : QSGLayer(*(new QSGSoftwareLayerPrivate))
+ , m_item(nullptr)
, m_context(renderContext)
, m_renderer(nullptr)
, m_device_pixel_ratio(1)
@@ -69,6 +70,11 @@ int QSGSoftwareLayer::textureId() const
return 0;
}
+int QSGSoftwareLayerPrivate::comparisonKey() const
+{
+ return 0;
+}
+
QSize QSGSoftwareLayer::textureSize() const
{
return m_pixmap.size();
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h b/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h
index 9f5a22e66f..1859e14514 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarelayer_p.h
@@ -53,13 +53,16 @@
#include <private/qsgadaptationlayer_p.h>
#include <private/qsgcontext_p.h>
+#include <private/qsgtexture_p.h>
QT_BEGIN_NAMESPACE
class QSGSoftwarePixmapRenderer;
+class QSGSoftwareLayerPrivate;
class QSGSoftwareLayer : public QSGLayer
{
+ Q_DECLARE_PRIVATE(QSGSoftwareLayer)
Q_OBJECT
public:
QSGSoftwareLayer(QSGRenderContext *renderContext);
@@ -117,6 +120,13 @@ private:
bool m_dirtyTexture;
};
+class QSGSoftwareLayerPrivate : public QSGTexturePrivate
+{
+ Q_DECLARE_PUBLIC(QSGSoftwareLayer)
+public:
+ int comparisonKey() const override;
+};
+
QT_END_NAMESPACE
#endif // QSGSOFTWARELAYER_H
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture.cpp
index 16e3a111ae..82a48d80ca 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture.cpp
@@ -38,10 +38,12 @@
****************************************************************************/
#include "qsgsoftwarepixmaptexture_p.h"
+#include <private/qsgcontext_p.h>
QT_BEGIN_NAMESPACE
QSGSoftwarePixmapTexture::QSGSoftwarePixmapTexture(const QImage &image, uint flags)
+ : QSGTexture(*(new QSGSoftwarePixmapTexturePrivate))
{
// Prevent pixmap format conversion to reduce memory consumption
// and surprises in calling code. (See QTBUG-47328)
@@ -55,11 +57,11 @@ QSGSoftwarePixmapTexture::QSGSoftwarePixmapTexture(const QImage &image, uint fla
}
QSGSoftwarePixmapTexture::QSGSoftwarePixmapTexture(const QPixmap &pixmap)
- : m_pixmap(pixmap)
+ : QSGTexture(*(new QSGSoftwarePixmapTexturePrivate)),
+ m_pixmap(pixmap)
{
}
-
int QSGSoftwarePixmapTexture::textureId() const
{
return 0;
@@ -85,6 +87,11 @@ void QSGSoftwarePixmapTexture::bind()
Q_UNREACHABLE();
}
+int QSGSoftwarePixmapTexturePrivate::comparisonKey() const
+{
+ return 0;
+}
+
QT_END_NAMESPACE
#include "moc_qsgsoftwarepixmaptexture_p.cpp"
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture_p.h b/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture_p.h
index 034fa25da9..baa62d93de 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture_p.h
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarepixmaptexture_p.h
@@ -52,12 +52,16 @@
//
#include <private/qsgtexture_p.h>
+#include <QtGui/QPixmap>
QT_BEGIN_NAMESPACE
+class QSGSoftwarePixmapTexturePrivate;
+
class QSGSoftwarePixmapTexture : public QSGTexture
{
Q_OBJECT
+ Q_DECLARE_PRIVATE(QSGSoftwarePixmapTexture)
public:
QSGSoftwarePixmapTexture(const QImage &image, uint flags);
QSGSoftwarePixmapTexture(const QPixmap &pixmap);
@@ -74,6 +78,13 @@ private:
QPixmap m_pixmap;
};
+class QSGSoftwarePixmapTexturePrivate : public QSGTexturePrivate
+{
+ Q_DECLARE_PUBLIC(QSGSoftwarePixmapTexture)
+public:
+ int comparisonKey() const override;
+};
+
QT_END_NAMESPACE
#endif // QSGSOFTWAREPIXMAPTEXTURE_H
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp
index 20286a03d5..141d8f3c6d 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarepublicnodes.cpp
@@ -41,6 +41,7 @@
#include "qsgsoftwarelayer_p.h"
#include "qsgsoftwarepixmaptexture_p.h"
#include "qsgsoftwareinternalimagenode_p.h"
+#include <private/qsgplaintexture_p.h>
QT_BEGIN_NAMESPACE
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderablenode.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderablenode.cpp
index 7fb531cca3..95c7efd4cb 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderablenode.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderablenode.cpp
@@ -52,7 +52,7 @@
#include <qsgsimplerectnode.h>
#include <qsgsimpletexturenode.h>
#include <private/qsgrendernode_p.h>
-#include <private/qsgtexture_p.h>
+#include <private/qsgplaintexture_p.h>
#include <qmath.h>
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderloop.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderloop.cpp
index f5a41410ee..c97dcb9326 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderloop.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarerenderloop.cpp
@@ -100,7 +100,7 @@ void QSGSoftwareRenderLoop::windowDestroyed(QQuickWindow *window)
rc->invalidate();
}
- delete d->animationController;
+ d->animationController.reset();
}
void QSGSoftwareRenderLoop::renderWindow(QQuickWindow *window, bool isNewExpose)
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp
index f8973af2fb..c6b463bb02 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp
@@ -69,10 +69,6 @@ const QEvent::Type WM_Obscure = QEvent::Type(QEvent::User + 1);
// Passed from the RL to RT when GUI has been locked, waiting for sync.
const QEvent::Type WM_RequestSync = QEvent::Type(QEvent::User + 2);
-// Passed by the RT to itself to trigger another render pass. This is typically
-// a result of QQuickWindow::update().
-const QEvent::Type WM_RequestRepaint = QEvent::Type(QEvent::User + 3);
-
// Passed by the RL to the RT to maybe release resource if no windows are
// rendering.
const QEvent::Type WM_TryRelease = QEvent::Type(QEvent::User + 4);
@@ -296,7 +292,7 @@ bool QSGSoftwareRenderThread::event(QEvent *e)
QCoreApplication::processEvents();
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
if (wme->destroying)
- delete wd->animationController;
+ wd->animationController.reset();
}
if (wme->destroying)
active = false;
@@ -353,13 +349,6 @@ bool QSGSoftwareRenderThread::event(QEvent *e)
return true;
}
- case WM_RequestRepaint:
- qCDebug(QSG_RASTER_LOG_RENDERLOOP, "RT - WM_RequestPaint");
- // When GUI posts this event, it is followed by a polishAndSync, so we
- // must not exit the event loop yet.
- pendingUpdate |= RepaintRequest;
- break;
-
default:
break;
}
@@ -855,7 +844,8 @@ void QSGSoftwareThreadedRenderLoop::handleExposure(QQuickWindow *window)
if (!w->thread->isRunning()) {
qCDebug(QSG_RASTER_LOG_RENDERLOOP, "starting render thread");
// Push a few things to the render thread.
- QQuickAnimatorController *controller = QQuickWindowPrivate::get(w->window)->animationController;
+ QQuickAnimatorController *controller
+ = QQuickWindowPrivate::get(w->window)->animationController.get();
if (controller->thread() != w->thread)
controller->moveToThread(w->thread);
if (w->thread->thread() == QThread::currentThread()) {
diff --git a/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp b/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp
index 796bc870de..46b2c6386c 100644
--- a/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp
+++ b/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp
@@ -65,7 +65,7 @@ namespace QSGCompressedAtlasTexture
{
Atlas::Atlas(const QSize &size, uint format)
- : QSGAtlasTexture::AtlasBase(size)
+ : QSGOpenGLAtlasTexture::AtlasBase(size)
, m_format(format)
{
}
@@ -88,10 +88,20 @@ Texture *Atlas::create(const QByteArray &data, int dataLength, int dataOffset, c
void Atlas::generateTexture()
{
+ int bytesPerBlock = 8;
+ switch (m_format) {
+ case QOpenGLTexture::RGBA8_ETC2_EAC:
+ case QOpenGLTexture::RGBA_DXT3:
+ case QOpenGLTexture::RGBA_DXT5:
+ bytesPerBlock = 16;
+ default:
+ break;
+ }
+
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
funcs->glCompressedTexImage2D(GL_TEXTURE_2D, 0, m_format,
m_size.width(), m_size.height(), 0,
- (m_size.width() * m_size.height()) / 2,
+ (m_size.width() / 4 * m_size.height() / 4) * bytesPerBlock,
nullptr);
}
@@ -117,7 +127,7 @@ void Atlas::uploadPendingTexture(int i)
}
Texture::Texture(Atlas *atlas, const QRect &textureRect, const QByteArray &data, int dataLength, int dataOffset, const QSize &size)
- : QSGAtlasTexture::TextureBase(atlas, textureRect)
+ : QSGOpenGLAtlasTexture::TextureBase(atlas, textureRect)
, m_nonatlas_texture(nullptr)
, m_data(data)
, m_size(size)
diff --git a/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture_p.h b/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture_p.h
index 59e935b623..78051778f5 100644
--- a/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture_p.h
+++ b/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture_p.h
@@ -57,7 +57,7 @@
#include <QtQuick/QSGTexture>
#include <QtQuick/private/qsgareaallocator_p.h>
-#include <QtQuick/private/qsgatlastexture_p.h>
+#include <QtQuick/private/qsgopenglatlastexture_p.h>
QT_BEGIN_NAMESPACE
@@ -67,7 +67,7 @@ namespace QSGCompressedAtlasTexture {
class Texture;
-class Atlas : public QSGAtlasTexture::AtlasBase
+class Atlas : public QSGOpenGLAtlasTexture::AtlasBase
{
public:
Atlas(const QSize &size, uint format);
@@ -84,7 +84,7 @@ private:
uint m_format;
};
-class Texture : public QSGAtlasTexture::TextureBase
+class Texture : public QSGOpenGLAtlasTexture::TextureBase
{
Q_OBJECT
public:
diff --git a/src/quick/scenegraph/compressedtexture/qsgcompressedtexture.cpp b/src/quick/scenegraph/compressedtexture/qsgcompressedtexture.cpp
index d3310bc11c..1a8bddaa6e 100644
--- a/src/quick/scenegraph/compressedtexture/qsgcompressedtexture.cpp
+++ b/src/quick/scenegraph/compressedtexture/qsgcompressedtexture.cpp
@@ -44,13 +44,15 @@
#include <QOpenGLFunctions>
#include <QDebug>
#include <QtQuick/private/qquickwindow_p.h>
+#include <QtGui/private/qrhi_p.h>
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(QSG_LOG_TEXTUREIO, "qt.scenegraph.textureio");
QSGCompressedTexture::QSGCompressedTexture(const QTextureFileData &texData)
- : m_textureData(texData)
+ : QSGTexture(*(new QSGCompressedTexturePrivate)),
+ m_textureData(texData)
{
m_size = m_textureData.size();
m_hasAlpha = !formatIsOpaque(m_textureData.glInternalFormat());
@@ -68,6 +70,8 @@ QSGCompressedTexture::~QSGCompressedTexture()
funcs->glDeleteTextures(1, &m_textureId);
}
#endif
+
+ delete m_texture;
}
int QSGCompressedTexture::textureId() const
@@ -85,6 +89,20 @@ int QSGCompressedTexture::textureId() const
return m_textureId;
}
+int QSGCompressedTexturePrivate::comparisonKey() const
+{
+ Q_Q(const QSGCompressedTexture);
+ // not textureId() as that would create an id when not yet done - that's not wanted here
+ if (q->m_textureId)
+ return q->m_textureId;
+
+ if (q->m_texture)
+ return int(qintptr(q->m_texture));
+
+ // two textures (and so materials) with not-yet-created texture underneath are never equal
+ return int(qintptr(q));
+}
+
QSize QSGCompressedTexture::textureSize() const
{
return m_size;
@@ -145,6 +163,165 @@ void QSGCompressedTexture::bind()
#endif // QT_CONFIG(opengl)
}
+static QPair<QRhiTexture::Format, bool> toRhiCompressedFormat(uint glinternalformat)
+{
+ switch (glinternalformat) {
+ case QOpenGLTexture::RGB_DXT1:
+ return { QRhiTexture::BC1, false };
+ case QOpenGLTexture::SRGB_DXT1:
+ return { QRhiTexture::BC1, true };
+
+ case QOpenGLTexture::RGBA_DXT3:
+ return { QRhiTexture::BC3, false };
+ case QOpenGLTexture::SRGB_Alpha_DXT3:
+ return { QRhiTexture::BC3, true };
+
+ case QOpenGLTexture::RGBA_DXT5:
+ return { QRhiTexture::BC5, false };
+ case QOpenGLTexture::SRGB_Alpha_DXT5:
+ return { QRhiTexture::BC5, true };
+
+ case QOpenGLTexture::RGB8_ETC2:
+ return { QRhiTexture::ETC2_RGB8, false };
+ case QOpenGLTexture::SRGB8_ETC2:
+ return { QRhiTexture::ETC2_RGB8, true };
+
+ case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2:
+ return { QRhiTexture::ETC2_RGB8A1, false };
+ case QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC2:
+ return { QRhiTexture::ETC2_RGB8A1, true };
+
+ case QOpenGLTexture::RGBA8_ETC2_EAC:
+ return { QRhiTexture::ETC2_RGBA8, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC:
+ return { QRhiTexture::ETC2_RGBA8, true };
+
+ case QOpenGLTexture::RGBA_ASTC_4x4:
+ return { QRhiTexture::ASTC_4x4, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_4x4:
+ return { QRhiTexture::ASTC_4x4, true };
+
+ case QOpenGLTexture::RGBA_ASTC_5x4:
+ return { QRhiTexture::ASTC_5x4, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x4:
+ return { QRhiTexture::ASTC_5x4, true };
+
+ case QOpenGLTexture::RGBA_ASTC_5x5:
+ return { QRhiTexture::ASTC_5x5, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x5:
+ return { QRhiTexture::ASTC_5x5, true };
+
+ case QOpenGLTexture::RGBA_ASTC_6x5:
+ return { QRhiTexture::ASTC_6x5, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x5:
+ return { QRhiTexture::ASTC_6x5, true };
+
+ case QOpenGLTexture::RGBA_ASTC_6x6:
+ return { QRhiTexture::ASTC_6x6, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x6:
+ return { QRhiTexture::ASTC_6x6, true };
+
+ case QOpenGLTexture::RGBA_ASTC_8x5:
+ return { QRhiTexture::ASTC_8x5, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x5:
+ return { QRhiTexture::ASTC_8x5, true };
+
+ case QOpenGLTexture::RGBA_ASTC_8x6:
+ return { QRhiTexture::ASTC_8x6, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x6:
+ return { QRhiTexture::ASTC_8x6, true };
+
+ case QOpenGLTexture::RGBA_ASTC_8x8:
+ return { QRhiTexture::ASTC_8x8, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x8:
+ return { QRhiTexture::ASTC_8x8, true };
+
+ case QOpenGLTexture::RGBA_ASTC_10x5:
+ return { QRhiTexture::ASTC_10x5, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x5:
+ return { QRhiTexture::ASTC_10x5, true };
+
+ case QOpenGLTexture::RGBA_ASTC_10x6:
+ return { QRhiTexture::ASTC_10x6, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x6:
+ return { QRhiTexture::ASTC_10x6, true };
+
+ case QOpenGLTexture::RGBA_ASTC_10x8:
+ return { QRhiTexture::ASTC_10x8, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x8:
+ return { QRhiTexture::ASTC_10x8, true };
+
+ case QOpenGLTexture::RGBA_ASTC_10x10:
+ return { QRhiTexture::ASTC_10x10, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x10:
+ return { QRhiTexture::ASTC_10x10, true };
+
+ case QOpenGLTexture::RGBA_ASTC_12x10:
+ return { QRhiTexture::ASTC_12x10, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x10:
+ return { QRhiTexture::ASTC_12x10, true };
+
+ case QOpenGLTexture::RGBA_ASTC_12x12:
+ return { QRhiTexture::ASTC_12x12, false };
+ case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x12:
+ return { QRhiTexture::ASTC_12x12, true };
+
+ default:
+ return { QRhiTexture::UnknownFormat, false };
+ }
+}
+
+QRhiTexture *QSGCompressedTexturePrivate::rhiTexture() const
+{
+ Q_Q(const QSGCompressedTexture);
+ return q->m_texture;
+}
+
+void QSGCompressedTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+{
+ Q_Q(QSGCompressedTexture);
+ if (q->m_uploaded)
+ return;
+
+ q->m_uploaded = true; // even if fails, no point in trying again
+
+ if (!q->m_textureData.isValid()) {
+ qCDebug(QSG_LOG_TEXTUREIO, "Invalid texture data for %s", q->m_textureData.logName().constData());
+ return;
+ }
+
+ const QPair<QRhiTexture::Format, bool> fmt = toRhiCompressedFormat(q->m_textureData.glInternalFormat());
+ if (fmt.first == QRhiTexture::UnknownFormat) {
+ qWarning("Unknown compressed format 0x%x", q->m_textureData.glInternalFormat());
+ return;
+ }
+
+ QRhiTexture::Flags texFlags = 0;
+ if (fmt.second)
+ texFlags |= QRhiTexture::sRGB;
+
+ if (!rhi->isTextureFormatSupported(fmt.first, texFlags)) {
+ qWarning("Unsupported compressed format 0x%x", q->m_textureData.glInternalFormat());
+ return;
+ }
+
+ if (!q->m_texture) {
+ q->m_texture = rhi->newTexture(fmt.first, q->m_size, 1, texFlags);
+ if (!q->m_texture->build()) {
+ qWarning("Failed to create QRhiTexture for compressed data");
+ delete q->m_texture;
+ q->m_texture = nullptr;
+ return;
+ }
+ }
+
+ // only upload mip level 0 since we never do mipmapping for compressed textures (for now?)
+ resourceUpdates->uploadTexture(q->m_texture, QRhiTextureUploadEntry(0, 0,
+ { q->m_textureData.data().constData() + q->m_textureData.dataOffset(), q->m_textureData.dataLength() }));
+
+ q->m_textureData = QTextureFileData(); // Release this memory, not needed anymore
+}
+
QTextureFileData QSGCompressedTexture::textureData() const
{
return m_textureData;
diff --git a/src/quick/scenegraph/compressedtexture/qsgcompressedtexture_p.h b/src/quick/scenegraph/compressedtexture/qsgcompressedtexture_p.h
index c3b58a2389..b858d8ddee 100644
--- a/src/quick/scenegraph/compressedtexture/qsgcompressedtexture_p.h
+++ b/src/quick/scenegraph/compressedtexture/qsgcompressedtexture_p.h
@@ -52,25 +52,28 @@
//
#include <private/qtexturefiledata_p.h>
-#include <QSGTexture>
-#include <QtQuick/private/qsgcontext_p.h>
+#include <private/qsgcontext_p.h>
+#include <private/qsgtexture_p.h>
#include <QQuickTextureFactory>
#include <QOpenGLFunctions>
QT_BEGIN_NAMESPACE
+class QSGCompressedTexturePrivate;
+
class Q_QUICK_PRIVATE_EXPORT QSGCompressedTexture : public QSGTexture
{
+ Q_DECLARE_PRIVATE(QSGCompressedTexture)
Q_OBJECT
public:
QSGCompressedTexture(const QTextureFileData& texData);
virtual ~QSGCompressedTexture();
- int textureId() const override;
QSize textureSize() const override;
bool hasAlphaChannel() const override;
bool hasMipmaps() const override;
+ int textureId() const override;
void bind() override;
QTextureFileData textureData() const;
@@ -81,14 +84,24 @@ protected:
QTextureFileData m_textureData;
QSize m_size;
mutable uint m_textureId = 0;
+ QRhiTexture *m_texture = nullptr;
bool m_hasAlpha = false;
bool m_uploaded = false;
};
-namespace QSGAtlasTexture {
+namespace QSGOpenGLAtlasTexture {
class Manager;
}
+class QSGCompressedTexturePrivate : public QSGTexturePrivate
+{
+ Q_DECLARE_PUBLIC(QSGCompressedTexture)
+public:
+ int comparisonKey() const override;
+ QRhiTexture *rhiTexture() const override;
+ void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
+};
+
class Q_QUICK_PRIVATE_EXPORT QSGCompressedTextureFactory : public QQuickTextureFactory
{
public:
@@ -101,7 +114,7 @@ protected:
QTextureFileData m_textureData;
private:
- friend class QSGAtlasTexture::Manager;
+ friend class QSGOpenGLAtlasTexture::Manager;
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp b/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp
index fddac7ed71..62ed342244 100644
--- a/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp
@@ -73,6 +73,22 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \enum QSGAbstractRenderer::MatrixTransformFlag
+
+ Used with setProjectionMatrixToRect() to indicate the expectations towards
+ the generated projection matrix.
+
+ \value MatrixTransformFlipY The traditional assumption in Qt Quick is that
+ Y points up in the normalized device coordinate system. There is at least
+ one modern graphics API where this is not the case (Vulkan). This flag can
+ then be used to get a projection that is appropriate for such an API.
+
+ \sa setProjectionMatrixToRect()
+
+ \since 5.14
+ */
+
+/*!
\fn void QSGAbstractRenderer::renderScene(GLuint fboId = 0)
Render the scene to the specified \a fboId
@@ -224,6 +240,9 @@ QRect QSGAbstractRenderer::viewportRect() const
Convenience method that calls setProjectionMatrix() with an
orthographic matrix generated from \a rect.
+ \note This function assumes that the graphics API uses Y up in its
+ normalized device coordinate system.
+
\sa setProjectionMatrix(), projectionMatrix()
*/
void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect)
@@ -236,6 +255,42 @@ void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect)
1,
-1);
setProjectionMatrix(matrix);
+ setProjectionMatrixWithNativeNDC(matrix);
+}
+
+/*!
+ Convenience method that calls setProjectionMatrix() with an
+ orthographic matrix generated from \a rect.
+
+ Set MatrixTransformFlipY in \a flags when the graphics API uses Y down in
+ its normalized device coordinate system (for example, Vulkan).
+
+ \sa setProjectionMatrix(), projectionMatrix()
+
+ \since 5.14
+ */
+void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags)
+{
+ const bool flipY = flags.testFlag(MatrixTransformFlipY);
+ QMatrix4x4 matrix;
+ matrix.ortho(rect.x(),
+ rect.x() + rect.width(),
+ flipY ? rect.y() : rect.y() + rect.height(),
+ flipY ? rect.y() + rect.height() : rect.y(),
+ 1,
+ -1);
+ setProjectionMatrix(matrix);
+
+ if (flipY) {
+ matrix.setToIdentity();
+ matrix.ortho(rect.x(),
+ rect.x() + rect.width(),
+ rect.y() + rect.height(),
+ rect.y(),
+ 1,
+ -1);
+ }
+ setProjectionMatrixWithNativeNDC(matrix);
}
/*!
@@ -250,6 +305,15 @@ void QSGAbstractRenderer::setProjectionMatrix(const QMatrix4x4 &matrix)
}
/*!
+ \internal
+ */
+void QSGAbstractRenderer::setProjectionMatrixWithNativeNDC(const QMatrix4x4 &matrix)
+{
+ Q_D(QSGAbstractRenderer);
+ d->m_projection_matrix_native_ndc = matrix;
+}
+
+/*!
Returns the projection matrix
\sa setProjectionMatrix(), setProjectionMatrixToRect()
@@ -261,6 +325,15 @@ QMatrix4x4 QSGAbstractRenderer::projectionMatrix() const
}
/*!
+ \internal
+ */
+QMatrix4x4 QSGAbstractRenderer::projectionMatrixWithNativeNDC() const
+{
+ Q_D(const QSGAbstractRenderer);
+ return d->m_projection_matrix_native_ndc;
+}
+
+/*!
Use \a color to clear the framebuffer when clearMode() is
set to QSGAbstractRenderer::ClearColorBuffer.
diff --git a/src/quick/scenegraph/coreapi/qsgabstractrenderer.h b/src/quick/scenegraph/coreapi/qsgabstractrenderer.h
index b9805f9db6..1594352dab 100644
--- a/src/quick/scenegraph/coreapi/qsgabstractrenderer.h
+++ b/src/quick/scenegraph/coreapi/qsgabstractrenderer.h
@@ -63,6 +63,13 @@ public:
Q_DECLARE_FLAGS(ClearMode, ClearModeBit)
Q_FLAG(ClearMode)
+ enum MatrixTransformFlag
+ {
+ MatrixTransformFlipY = 0x01
+ };
+ Q_DECLARE_FLAGS(MatrixTransformFlags, MatrixTransformFlag)
+ Q_FLAG(MatrixTransformFlags)
+
~QSGAbstractRenderer() override;
void setRootNode(QSGRootNode *node);
@@ -76,8 +83,11 @@ public:
QRect viewportRect() const;
void setProjectionMatrixToRect(const QRectF &rect);
+ void setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags);
void setProjectionMatrix(const QMatrix4x4 &matrix);
+ void setProjectionMatrixWithNativeNDC(const QMatrix4x4 &matrix);
QMatrix4x4 projectionMatrix() const;
+ QMatrix4x4 projectionMatrixWithNativeNDC() const;
void setClearColor(const QColor &color);
QColor clearColor() const;
diff --git a/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h b/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h
index e6b17f4448..bbc4289b2c 100644
--- a/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h
+++ b/src/quick/scenegraph/coreapi/qsgabstractrenderer_p.h
@@ -78,6 +78,7 @@ public:
QRect m_viewport_rect;
QMatrix4x4 m_projection_matrix;
+ QMatrix4x4 m_projection_matrix_native_ndc;
uint m_mirrored : 1;
};
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
index afe3380494..34027cbac7 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
** Copyright (C) 2016 Robin Burchell <robin.burchell@viroteck.net>
** Contact: https://www.qt.io/licensing/
@@ -57,7 +57,10 @@
#include <private/qnumeric_p.h>
#include <private/qquickprofiler_p.h>
-#include "qsgmaterialshader_p.h"
+#include "qsgmaterialrhishader_p.h"
+
+#include "qsgopenglvisualizer_p.h"
+#include "qsgrhivisualizer_p.h"
#include <algorithm>
@@ -67,6 +70,10 @@
QT_BEGIN_NAMESPACE
+#ifndef QT_NO_DEBUG
+Q_QUICK_PRIVATE_EXPORT bool qsg_test_and_clear_material_failure();
+#endif
+
extern QByteArray qsgShaderRewriter_insertZAttributes(const char *input, QSurfaceFormat::OpenGLContextProfile profile);
int qt_sg_envInt(const char *name, int defaultValue);
@@ -108,8 +115,8 @@ static inline int size_of_type(GLenum type)
4,
sizeof(double)
};
- Q_ASSERT(type >= GL_BYTE && type <= 0x140A); // the value of GL_DOUBLE
- return sizes[type - GL_BYTE];
+ Q_ASSERT(type >= QSGGeometry::ByteType && type <= QSGGeometry::DoubleType);
+ return sizes[type - QSGGeometry::ByteType];
}
bool qsg_sort_element_increasing_order(Element *a, Element *b) { return a->order < b->order; }
@@ -132,44 +139,179 @@ struct QMatrix4x4_Accessor
const float OPAQUE_LIMIT = 0.999f;
-ShaderManager::Shader *ShaderManager::prepareMaterial(QSGMaterial *material)
+const uint DYNAMIC_VERTEX_INDEX_BUFFER_THRESHOLD = 4;
+const int VERTEX_BUFFER_BINDING = 0;
+const int ZORDER_BUFFER_BINDING = VERTEX_BUFFER_BINDING + 1;
+
+static inline uint aligned(uint v, uint byteAlign)
+{
+ return (v + byteAlign - 1) & ~(byteAlign - 1);
+}
+
+QRhiVertexInputAttribute::Format qsg_vertexInputFormat(const QSGGeometry::Attribute &a)
+{
+ switch (a.type) {
+ case QSGGeometry::FloatType:
+ if (a.tupleSize == 4)
+ return QRhiVertexInputAttribute::Float4;
+ if (a.tupleSize == 3)
+ return QRhiVertexInputAttribute::Float3;
+ if (a.tupleSize == 2)
+ return QRhiVertexInputAttribute::Float2;
+ if (a.tupleSize == 1)
+ return QRhiVertexInputAttribute::Float;
+ break;
+ case QSGGeometry::UnsignedByteType:
+ if (a.tupleSize == 4)
+ return QRhiVertexInputAttribute::UNormByte4;
+ if (a.tupleSize == 2)
+ return QRhiVertexInputAttribute::UNormByte2;
+ if (a.tupleSize == 1)
+ return QRhiVertexInputAttribute::UNormByte;
+ break;
+ default:
+ break;
+ }
+ qWarning("Unsupported attribute type 0x%x with %d components", a.type, a.tupleSize);
+ Q_UNREACHABLE();
+ return QRhiVertexInputAttribute::Float;
+}
+
+static QRhiVertexInputLayout calculateVertexInputLayout(const QSGMaterialRhiShader *s, const QSGGeometry *geometry, bool batchable)
+{
+ Q_ASSERT(geometry);
+ const QSGMaterialRhiShaderPrivate *sd = QSGMaterialRhiShaderPrivate::get(s);
+ if (!sd->vertexShader) {
+ qWarning("No vertex shader in QSGMaterialRhiShader %p", s);
+ return QRhiVertexInputLayout();
+ }
+
+ const int attrCount = geometry->attributeCount();
+ QVarLengthArray<QRhiVertexInputAttribute, 8> inputAttributes;
+ inputAttributes.reserve(attrCount + 1);
+ int offset = 0;
+ for (int i = 0; i < attrCount; ++i) {
+ const QSGGeometry::Attribute &a = geometry->attributes()[i];
+ if (!sd->vertexShader->vertexInputLocations.contains(a.position)) {
+ qWarning("Vertex input %d is present in material but not in shader. This is wrong.",
+ a.position);
+ }
+ inputAttributes.append(QRhiVertexInputAttribute(VERTEX_BUFFER_BINDING, a.position, qsg_vertexInputFormat(a), offset));
+ offset += a.tupleSize * size_of_type(a.type);
+ }
+ if (batchable) {
+ inputAttributes.append(QRhiVertexInputAttribute(ZORDER_BUFFER_BINDING, sd->vertexShader->qt_order_attrib_location,
+ QRhiVertexInputAttribute::Float, 0));
+ }
+
+ Q_ASSERT(VERTEX_BUFFER_BINDING == 0 && ZORDER_BUFFER_BINDING == 1); // not very flexible
+ QVarLengthArray<QRhiVertexInputBinding, 2> inputBindings;
+ inputBindings.append(QRhiVertexInputBinding(geometry->sizeOfVertex()));
+ if (batchable)
+ inputBindings.append(QRhiVertexInputBinding(sizeof(float)));
+
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings(inputBindings.cbegin(), inputBindings.cend());
+ inputLayout.setAttributes(inputAttributes.cbegin(), inputAttributes.cend());
+
+ return inputLayout;
+}
+
+QRhiCommandBuffer::IndexFormat qsg_indexFormat(const QSGGeometry *geometry)
+{
+ switch (geometry->indexType()) {
+ case QSGGeometry::UnsignedShortType:
+ return QRhiCommandBuffer::IndexUInt16;
+ break;
+ case QSGGeometry::UnsignedIntType:
+ return QRhiCommandBuffer::IndexUInt32;
+ break;
+ default:
+ Q_UNREACHABLE();
+ return QRhiCommandBuffer::IndexUInt16;
+ }
+}
+
+QRhiGraphicsPipeline::Topology qsg_topology(int geomDrawMode)
+{
+ QRhiGraphicsPipeline::Topology topology = QRhiGraphicsPipeline::Triangles;
+ switch (geomDrawMode) {
+ case QSGGeometry::DrawPoints:
+ topology = QRhiGraphicsPipeline::Points;
+ break;
+ case QSGGeometry::DrawLines:
+ topology = QRhiGraphicsPipeline::Lines;
+ break;
+ case QSGGeometry::DrawLineStrip:
+ topology = QRhiGraphicsPipeline::LineStrip;
+ break;
+ case QSGGeometry::DrawTriangles:
+ topology = QRhiGraphicsPipeline::Triangles;
+ break;
+ case QSGGeometry::DrawTriangleStrip:
+ topology = QRhiGraphicsPipeline::TriangleStrip;
+ break;
+ default:
+ qWarning("Primitive topology 0x%x not supported", geomDrawMode);
+ break;
+ }
+ return topology;
+}
+
+ShaderManager::Shader *ShaderManager::prepareMaterial(QSGMaterial *material, bool enableRhiShaders, const QSGGeometry *geometry)
{
QSGMaterialType *type = material->type();
Shader *shader = rewrittenShaders.value(type, 0);
if (shader)
return shader;
+ if (enableRhiShaders && !material->flags().testFlag(QSGMaterial::SupportsRhiShader)) {
+ qWarning("The material failed to provide a working QShader pack");
+ return nullptr;
+ }
+
if (QSG_LOG_TIME_COMPILATION().isDebugEnabled())
qsg_renderer_timer.start();
Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphContextFrame);
- QSGMaterialShader *s = material->createShader();
- QOpenGLContext *ctx = context->openglContext();
- QSurfaceFormat::OpenGLContextProfile profile = ctx->format().profile();
-
- QOpenGLShaderProgram *p = s->program();
- char const *const *attr = s->attributeNames();
- int i;
- for (i = 0; attr[i]; ++i) {
- if (*attr[i])
- p->bindAttributeLocation(attr[i], i);
- }
- p->bindAttributeLocation("_qt_order", i);
- context->compileShader(s, material, qsgShaderRewriter_insertZAttributes(s->vertexShader(), profile), nullptr);
- context->initializeShader(s);
- if (!p->isLinked())
- return nullptr;
-
shader = new Shader;
- shader->program = s;
- shader->pos_order = i;
- shader->id_zRange = p->uniformLocation("_qt_zRange");
- shader->lastOpacity = 0;
+ if (enableRhiShaders) {
+ material->setFlag(QSGMaterial::RhiShaderWanted, true);
+ QSGMaterialRhiShader *s = static_cast<QSGMaterialRhiShader *>(material->createShader());
+ material->setFlag(QSGMaterial::RhiShaderWanted, false);
+ context->initializeRhiShader(s, QShader::BatchableVertexShader);
+ shader->programRhi.program = s;
+ shader->programRhi.inputLayout = calculateVertexInputLayout(s, geometry, true);
+ QSGMaterialRhiShaderPrivate *sD = QSGMaterialRhiShaderPrivate::get(s);
+ shader->programRhi.shaderStages = {
+ { QRhiGraphicsShaderStage::Vertex, sD->shader(QShader::VertexStage), QShader::BatchableVertexShader },
+ { QRhiGraphicsShaderStage::Fragment, sD->shader(QShader::FragmentStage) }
+ };
+ } else {
+ QSGMaterialShader *s = material->createShader();
+ QOpenGLContext *ctx = context->openglContext();
+ QSurfaceFormat::OpenGLContextProfile profile = ctx->format().profile();
+ QOpenGLShaderProgram *p = s->program();
+ char const *const *attr = s->attributeNames();
+ int i;
+ for (i = 0; attr[i]; ++i) {
+ if (*attr[i])
+ p->bindAttributeLocation(attr[i], i);
+ }
+ p->bindAttributeLocation("_qt_order", i);
+ context->compileShader(s, material, qsgShaderRewriter_insertZAttributes(s->vertexShader(), profile), nullptr);
+ context->initializeShader(s);
+ if (!p->isLinked()) {
+ delete shader;
+ return nullptr;
+ }
+ shader->programGL.program = s;
+ shader->programGL.pos_order = i;
+ }
- Q_ASSERT(shader->pos_order >= 0);
- Q_ASSERT(shader->id_zRange >= 0);
+ shader->lastOpacity = 0;
- qCDebug(QSG_LOG_TIME_COMPILATION, "shader compiled in %dms", (int) qsg_renderer_timer.elapsed());
+ qCDebug(QSG_LOG_TIME_COMPILATION, "material shaders prepared in %dms", (int) qsg_renderer_timer.elapsed());
Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphContextFrame,
QQuickProfiler::SceneGraphContextMaterialCompile);
@@ -178,25 +320,43 @@ ShaderManager::Shader *ShaderManager::prepareMaterial(QSGMaterial *material)
return shader;
}
-ShaderManager::Shader *ShaderManager::prepareMaterialNoRewrite(QSGMaterial *material)
+ShaderManager::Shader *ShaderManager::prepareMaterialNoRewrite(QSGMaterial *material, bool enableRhiShaders, const QSGGeometry *geometry)
{
QSGMaterialType *type = material->type();
Shader *shader = stockShaders.value(type, 0);
if (shader)
return shader;
+ if (enableRhiShaders && !material->flags().testFlag(QSGMaterial::SupportsRhiShader)) {
+ qWarning("The material failed to provide a working QShader pack");
+ return nullptr;
+ }
+
if (QSG_LOG_TIME_COMPILATION().isDebugEnabled())
qsg_renderer_timer.start();
Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphContextFrame);
- QSGMaterialShader *s = static_cast<QSGMaterialShader *>(material->createShader());
- context->compileShader(s, material);
- context->initializeShader(s);
+ shader = new Shader;
+ if (enableRhiShaders) {
+ material->setFlag(QSGMaterial::RhiShaderWanted, true);
+ QSGMaterialRhiShader *s = static_cast<QSGMaterialRhiShader *>(material->createShader());
+ material->setFlag(QSGMaterial::RhiShaderWanted, false);
+ context->initializeRhiShader(s, QShader::StandardShader);
+ shader->programRhi.program = s;
+ shader->programRhi.inputLayout = calculateVertexInputLayout(s, geometry, false);
+ QSGMaterialRhiShaderPrivate *sD = QSGMaterialRhiShaderPrivate::get(s);
+ shader->programRhi.shaderStages = {
+ { QRhiGraphicsShaderStage::Vertex, sD->shader(QShader::VertexStage) },
+ { QRhiGraphicsShaderStage::Fragment, sD->shader(QShader::FragmentStage) }
+ };
+ } else {
+ QSGMaterialShader *s = material->createShader();
+ context->compileShader(s, material);
+ context->initializeShader(s);
+ shader->programGL.program = s;
+ shader->programGL.pos_order = -1;
+ }
- shader = new Shader();
- shader->program = s;
- shader->id_zRange = -1;
- shader->pos_order = -1;
shader->lastOpacity = 0;
stockShaders[type] = shader;
@@ -216,6 +376,45 @@ void ShaderManager::invalidated()
rewrittenShaders.clear();
delete blitProgram;
blitProgram = nullptr;
+
+ qDeleteAll(srbCache);
+ srbCache.clear();
+}
+
+void ShaderManager::clearCachedRendererData()
+{
+ for (ShaderManager::Shader *sms : stockShaders) {
+ QSGMaterialRhiShader *s = sms->programRhi.program;
+ if (s) {
+ QSGMaterialRhiShaderPrivate *sd = QSGMaterialRhiShaderPrivate::get(s);
+ sd->clearCachedRendererData();
+ }
+ }
+ for (ShaderManager::Shader *sms : rewrittenShaders) {
+ QSGMaterialRhiShader *s = sms->programRhi.program;
+ if (s) {
+ QSGMaterialRhiShaderPrivate *sd = QSGMaterialRhiShaderPrivate::get(s);
+ sd->clearCachedRendererData();
+ }
+ }
+}
+
+QRhiShaderResourceBindings *ShaderManager::srb(const ShaderResourceBindingList &bindings)
+{
+ auto it = srbCache.constFind(bindings);
+ if (it != srbCache.constEnd())
+ return *it;
+
+ QRhiShaderResourceBindings *srb = context->rhi()->newShaderResourceBindings();
+ srb->setBindings(bindings.cbegin(), bindings.cend());
+ if (srb->build()) {
+ srbCache.insert(bindings, srb);
+ } else {
+ qWarning("Failed to build srb");
+ delete srb;
+ srb = nullptr;
+ }
+ return srb;
}
void qsg_dumpShadowRoots(BatchRootInfo *i, int indent)
@@ -304,8 +503,8 @@ void Updater::updateStates(QSGNode *n)
qDebug(" - forceupdate");
}
- if (Q_UNLIKELY(renderer->m_visualizeMode == Renderer::VisualizeChanges))
- renderer->visualizeChangesPrepare(sn);
+ if (Q_UNLIKELY(renderer->m_visualizer->mode() == Visualizer::VisualizeChanges))
+ renderer->m_visualizer->visualizeChangesPrepare(sn);
visitNode(sn);
}
@@ -531,11 +730,12 @@ void Updater::updateRootTransforms(Node *node, Node *root, const QMatrix4x4 &com
}
}
-int qsg_positionAttribute(QSGGeometry *g) {
+int qsg_positionAttribute(QSGGeometry *g)
+{
int vaOffset = 0;
for (int a=0; a<g->attributeCount(); ++a) {
const QSGGeometry::Attribute &attr = g->attributes()[a];
- if (attr.isVertexCoordinate && attr.tupleSize == 2 && attr.type == GL_FLOAT) {
+ if (attr.isVertexCoordinate && attr.tupleSize == 2 && attr.type == QSGGeometry::FloatType) {
return vaOffset;
}
vaOffset += attr.tupleSize * size_of_type(attr.type);
@@ -773,15 +973,29 @@ Renderer::Renderer(QSGDefaultRenderContext *ctx)
, m_currentStencilValue(0)
, m_clipMatrixId(0)
, m_currentClip(nullptr)
- , m_currentClipType(NoClip)
+ , m_currentClipType(ClipState::NoClip)
, m_vertexUploadPool(256)
, m_indexUploadPool(64)
, m_vao(nullptr)
- , m_visualizeMode(VisualizeNothing)
{
- initializeOpenGLFunctions();
+ m_rhi = m_context->rhi();
+ if (m_rhi) {
+ m_ubufAlignment = m_rhi->ubufAlignment();
+ m_uint32IndexForRhi = !m_rhi->isFeatureSupported(QRhi::NonFourAlignedEffectiveIndexBufferOffset);
+ if (qEnvironmentVariableIntValue("QSG_RHI_UINT32_INDEX"))
+ m_uint32IndexForRhi = true;
+ m_visualizer = new RhiVisualizer(this);
+ } else {
+ initializeOpenGLFunctions();
+ m_uint32IndexForRhi = false;
+ m_visualizer = new OpenGLVisualizer(this);
+ }
+
setNodeUpdater(new Updater(this));
+ // The shader manager is shared between renderers (think for example Item
+ // layers that create a new Renderer each) with the same rendercontext
+ // (i.e. QRhi or QOpenGLContext).
m_shaderManager = ctx->findChild<ShaderManager *>(QStringLiteral("__qt_ShaderManager"), Qt::FindDirectChildrenOnly);
if (!m_shaderManager) {
m_shaderManager = new ShaderManager(ctx);
@@ -810,20 +1024,29 @@ Renderer::Renderer(QSGDefaultRenderContext *ctx)
? "static" : (m_bufferStrategy == GL_DYNAMIC_DRAW ? "dynamic" : "stream")));
}
- // If rendering with an OpenGL Core profile context, we need to create a VAO
- // to hold our vertex specification state.
- if (m_context->openglContext()->format().profile() == QSurfaceFormat::CoreProfile) {
- m_vao = new QOpenGLVertexArrayObject(this);
- m_vao->create();
- }
+ if (!m_rhi) {
+ // If rendering with an OpenGL Core profile context, we need to create a VAO
+ // to hold our vertex specification state.
+ if (m_context->openglContext()->format().profile() == QSurfaceFormat::CoreProfile) {
+ m_vao = new QOpenGLVertexArrayObject(this);
+ m_vao->create();
+ }
- bool useDepth = qEnvironmentVariableIsEmpty("QSG_NO_DEPTH_BUFFER");
- m_useDepthBuffer = useDepth && ctx->openglContext()->format().depthBufferSize() > 0;
+ bool useDepth = qEnvironmentVariableIsEmpty("QSG_NO_DEPTH_BUFFER");
+ m_useDepthBuffer = useDepth && ctx->openglContext()->format().depthBufferSize() > 0;
+ }
}
static void qsg_wipeBuffer(Buffer *buffer, QOpenGLFunctions *funcs)
{
- funcs->glDeleteBuffers(1, &buffer->id);
+ if (buffer->buf) {
+ //qDebug("releasing rhibuf %p", buffer->buf);
+ delete buffer->buf;
+ }
+
+ if (buffer->id)
+ funcs->glDeleteBuffers(1, &buffer->id);
+
// The free here is ok because we're in one of two situations.
// 1. We're using the upload pool in which case unmap will have set the
// data pointer to 0 and calling free on 0 is ok.
@@ -837,12 +1060,14 @@ static void qsg_wipeBatch(Batch *batch, QOpenGLFunctions *funcs, bool separateIn
qsg_wipeBuffer(&batch->vbo, funcs);
if (separateIndexBuffer)
qsg_wipeBuffer(&batch->ibo, funcs);
+ delete batch->ubuf;
+ batch->stencilClipState.reset();
delete batch;
}
Renderer::~Renderer()
{
- if (QOpenGLContext::currentContext()) {
+ if (m_rhi || QOpenGLContext::currentContext()) {
// Clean up batches and buffers
const bool separateIndexBuffer = m_context->separateIndexBuffer();
for (int i = 0; i < m_opaqueBatches.size(); ++i)
@@ -864,6 +1089,42 @@ Renderer::~Renderer()
else
m_elementAllocator.release(e);
}
+
+ destroyGraphicsResources();
+
+ delete m_visualizer;
+}
+
+void Renderer::destroyGraphicsResources()
+{
+ // If this is from the dtor, then the shader manager and its already
+ // prepared shaders will stay around for other renderers -> the cached data
+ // in the rhi shaders have to be purged as it may refer to samplers we
+ // are going to destroy.
+ m_shaderManager->clearCachedRendererData();
+
+ qDeleteAll(m_pipelines);
+ qDeleteAll(m_samplers);
+
+ m_stencilClipCommon.reset();
+
+ delete m_dummyTexture;
+
+ m_visualizer->releaseResources();
+}
+
+void Renderer::releaseCachedResources()
+{
+ m_shaderManager->invalidated();
+
+ destroyGraphicsResources();
+
+ m_pipelines.clear();
+ m_samplers.clear();
+ m_dummyTexture = nullptr;
+
+ if (m_rhi)
+ m_rhi->releaseCachedResources();
}
void Renderer::invalidateAndRecycleBatch(Batch *b)
@@ -887,7 +1148,7 @@ void Renderer::invalidateAndRecycleBatch(Batch *b)
*/
void Renderer::map(Buffer *buffer, int byteSize, bool isIndexBuf)
{
- if (!m_context->hasBrokenIndexBufferObjects() && m_visualizeMode == VisualizeNothing) {
+ if (!m_context->hasBrokenIndexBufferObjects() && m_visualizer->mode() == Visualizer::VisualizeNothing) {
// Common case, use a shared memory pool for uploading vertex data to avoid
// excessive reevaluation
QDataBuffer<char> &pool = m_context->separateIndexBuffer() && isIndexBuf
@@ -905,14 +1166,54 @@ void Renderer::map(Buffer *buffer, int byteSize, bool isIndexBuf)
void Renderer::unmap(Buffer *buffer, bool isIndexBuf)
{
- if (buffer->id == 0)
- glGenBuffers(1, &buffer->id);
- GLenum target = isIndexBuf ? GL_ELEMENT_ARRAY_BUFFER : GL_ARRAY_BUFFER;
- glBindBuffer(target, buffer->id);
- glBufferData(target, buffer->size, buffer->data, m_bufferStrategy);
-
- if (!m_context->hasBrokenIndexBufferObjects() && m_visualizeMode == VisualizeNothing) {
- buffer->data = nullptr;
+ if (m_rhi) {
+ // Batches are pooled and reused which means the QRhiBuffer will be
+ // still valid in a recycled Batch. We only hit the newBuffer() path
+ // for brand new Batches.
+ if (!buffer->buf) {
+ buffer->buf = m_rhi->newBuffer(QRhiBuffer::Immutable,
+ isIndexBuf ? QRhiBuffer::IndexBuffer : QRhiBuffer::VertexBuffer,
+ buffer->size);
+ if (!buffer->buf->build())
+ qWarning("Failed to build vertex/index buffer of size %d", buffer->size);
+// else
+// qDebug("created rhibuf %p size %d", buffer->buf, buffer->size);
+ } else {
+ bool needsRebuild = false;
+ if (buffer->buf->size() < buffer->size) {
+ buffer->buf->setSize(buffer->size);
+ needsRebuild = true;
+ }
+ if (buffer->buf->type() != QRhiBuffer::Dynamic
+ && buffer->nonDynamicChangeCount > DYNAMIC_VERTEX_INDEX_BUFFER_THRESHOLD)
+ {
+ buffer->buf->setType(QRhiBuffer::Dynamic);
+ buffer->nonDynamicChangeCount = 0;
+ needsRebuild = true;
+ }
+ if (needsRebuild) {
+ //qDebug("rebuilding rhibuf %p size %d type Dynamic", buffer->buf, buffer->size);
+ buffer->buf->build();
+ }
+ }
+ if (buffer->buf->type() != QRhiBuffer::Dynamic) {
+ m_resourceUpdates->uploadStaticBuffer(buffer->buf,
+ QByteArray::fromRawData(buffer->data, buffer->size));
+ buffer->nonDynamicChangeCount += 1;
+ } else {
+ m_resourceUpdates->updateDynamicBuffer(buffer->buf, 0, buffer->size,
+ QByteArray::fromRawData(buffer->data, buffer->size));
+ }
+ if (m_visualizer->mode() == Visualizer::VisualizeNothing)
+ buffer->data = nullptr;
+ } else {
+ if (buffer->id == 0)
+ glGenBuffers(1, &buffer->id);
+ GLenum target = isIndexBuf ? GL_ELEMENT_ARRAY_BUFFER : GL_ARRAY_BUFFER;
+ glBindBuffer(target, buffer->id);
+ glBufferData(target, buffer->size, buffer->data, m_bufferStrategy);
+ if (!m_context->hasBrokenIndexBufferObjects() && m_visualizer->mode() == Visualizer::VisualizeNothing)
+ buffer->data = nullptr;
}
}
@@ -1098,8 +1399,12 @@ void Renderer::nodeWasRemoved(Node *node)
m_elementsToDelete.add(e);
if (m_renderNodeElements.isEmpty()) {
- static bool useDepth = qEnvironmentVariableIsEmpty("QSG_NO_DEPTH_BUFFER");
- m_useDepthBuffer = useDepth && m_context->openglContext()->format().depthBufferSize() > 0;
+ if (m_rhi) {
+ m_useDepthBuffer = true;
+ } else {
+ static bool useDepth = qEnvironmentVariableIsEmpty("QSG_NO_DEPTH_BUFFER");
+ m_useDepthBuffer = useDepth && m_context->openglContext()->format().depthBufferSize() > 0;
+ }
}
}
}
@@ -1539,7 +1844,7 @@ void Renderer::prepareOpaqueBatches()
if (gni->clipList() == gnj->clipList()
&& gni->geometry()->drawingMode() == gnj->geometry()->drawingMode()
- && (gni->geometry()->drawingMode() != GL_LINES || gni->geometry()->lineWidth() == gnj->geometry()->lineWidth())
+ && (gni->geometry()->drawingMode() != QSGGeometry::DrawLines || gni->geometry()->lineWidth() == gnj->geometry()->lineWidth())
&& gni->geometry()->attributes() == gnj->geometry()->attributes()
&& gni->inheritedOpacity() == gnj->inheritedOpacity()
&& gni->activeMaterial()->type() == gnj->activeMaterial()->type()
@@ -1638,7 +1943,7 @@ void Renderer::prepareAlphaBatches()
if (gni->clipList() == gnj->clipList()
&& gni->geometry()->drawingMode() == gnj->geometry()->drawingMode()
- && (gni->geometry()->drawingMode() != GL_LINES || gni->geometry()->lineWidth() == gnj->geometry()->lineWidth())
+ && (gni->geometry()->drawingMode() != QSGGeometry::DrawLines || gni->geometry()->lineWidth() == gnj->geometry()->lineWidth())
&& gni->geometry()->attributes() == gnj->geometry()->attributes()
&& gni->inheritedOpacity() == gnj->inheritedOpacity()
&& gni->activeMaterial()->type() == gnj->activeMaterial()->type()
@@ -1666,19 +1971,20 @@ void Renderer::prepareAlphaBatches()
}
-static inline int qsg_fixIndexCount(int iCount, GLenum drawMode) {
+static inline int qsg_fixIndexCount(int iCount, int drawMode)
+{
switch (drawMode) {
- case GL_TRIANGLE_STRIP:
+ case QSGGeometry::DrawTriangleStrip:
// Merged triangle strips need to contain degenerate triangles at the beginning and end.
// One could save 2 uploaded ushorts here by ditching the padding for the front of the
// first and the end of the last, but for simplicity, we simply don't care.
// Those extra triangles will be skipped while drawing to preserve the strip's parity
// anyhow.
return iCount + 2;
- case GL_LINES:
+ case QSGGeometry::DrawLines:
// For lines we drop the last vertex if the number of vertices is uneven.
return iCount - (iCount % 2);
- case GL_TRIANGLES:
+ case QSGGeometry::DrawTriangles:
// For triangles we drop trailing vertices until the result is divisible by 3.
return iCount - (iCount % 3);
default:
@@ -1700,7 +2006,7 @@ static inline int qsg_fixIndexCount(int iCount, GLenum drawMode) {
* iBase: The starting index for this element in the batch
*/
-void Renderer::uploadMergedElement(Element *e, int vaOffset, char **vertexData, char **zData, char **indexData, quint16 *iBase, int *indexCount)
+void Renderer::uploadMergedElement(Element *e, int vaOffset, char **vertexData, char **zData, char **indexData, void *iBasePtr, int *indexCount)
{
if (Q_UNLIKELY(debug_upload())) qDebug() << " - uploading element:" << e << e->node << (void *) *vertexData << (qintptr) (*zData - *vertexData) << (qintptr) (*indexData - *vertexData);
QSGGeometry *g = e->node->geometry();
@@ -1736,39 +2042,71 @@ void Renderer::uploadMergedElement(Element *e, int vaOffset, char **vertexData,
}
int iCount = g->indexCount();
- quint16 *indices = (quint16 *) *indexData;
+ if (m_uint32IndexForRhi) {
+ // can only happen when using the rhi
+ quint32 *iBase = (quint32 *) iBasePtr;
+ quint32 *indices = (quint32 *) *indexData;
+ if (iCount == 0) {
+ iCount = vCount;
+ if (g->drawingMode() == QSGGeometry::DrawTriangleStrip)
+ *indices++ = *iBase;
+ else
+ iCount = qsg_fixIndexCount(iCount, g->drawingMode());
- if (iCount == 0) {
- iCount = vCount;
- if (g->drawingMode() == GL_TRIANGLE_STRIP)
- *indices++ = *iBase;
- else
- iCount = qsg_fixIndexCount(iCount, g->drawingMode());
+ for (int i=0; i<iCount; ++i)
+ indices[i] = *iBase + i;
+ } else {
+ // source index data in QSGGeometry is always ushort (we would not merge otherwise)
+ const quint16 *srcIndices = g->indexDataAsUShort();
+ if (g->drawingMode() == QSGGeometry::DrawTriangleStrip)
+ *indices++ = *iBase + srcIndices[0];
+ else
+ iCount = qsg_fixIndexCount(iCount, g->drawingMode());
- for (int i=0; i<iCount; ++i)
- indices[i] = *iBase + i;
+ for (int i=0; i<iCount; ++i)
+ indices[i] = *iBase + srcIndices[i];
+ }
+ if (g->drawingMode() == QSGGeometry::DrawTriangleStrip) {
+ indices[iCount] = indices[iCount - 1];
+ iCount += 2;
+ }
+ *iBase += vCount;
} else {
- const quint16 *srcIndices = g->indexDataAsUShort();
- if (g->drawingMode() == GL_TRIANGLE_STRIP)
- *indices++ = *iBase + srcIndices[0];
- else
- iCount = qsg_fixIndexCount(iCount, g->drawingMode());
+ // normally batching is only done for ushort index data
+ quint16 *iBase = (quint16 *) iBasePtr;
+ quint16 *indices = (quint16 *) *indexData;
+ if (iCount == 0) {
+ iCount = vCount;
+ if (g->drawingMode() == QSGGeometry::DrawTriangleStrip)
+ *indices++ = *iBase;
+ else
+ iCount = qsg_fixIndexCount(iCount, g->drawingMode());
- for (int i=0; i<iCount; ++i)
- indices[i] = *iBase + srcIndices[i];
- }
- if (g->drawingMode() == GL_TRIANGLE_STRIP) {
- indices[iCount] = indices[iCount - 1];
- iCount += 2;
+ for (int i=0; i<iCount; ++i)
+ indices[i] = *iBase + i;
+ } else {
+ const quint16 *srcIndices = g->indexDataAsUShort();
+ if (g->drawingMode() == QSGGeometry::DrawTriangleStrip)
+ *indices++ = *iBase + srcIndices[0];
+ else
+ iCount = qsg_fixIndexCount(iCount, g->drawingMode());
+
+ for (int i=0; i<iCount; ++i)
+ indices[i] = *iBase + srcIndices[i];
+ }
+ if (g->drawingMode() == QSGGeometry::DrawTriangleStrip) {
+ indices[iCount] = indices[iCount - 1];
+ iCount += 2;
+ }
+ *iBase += vCount;
}
*vertexData += vCount * vSize;
- *indexData += iCount * sizeof(quint16);
- *iBase += vCount;
+ *indexData += iCount * mergedIndexElemSize();
*indexCount += iCount;
}
-static QMatrix4x4 qsg_matrixForRoot(Node *node)
+QMatrix4x4 qsg_matrixForRoot(Node *node)
{
if (node->type() == QSGNode::TransformNodeType)
return static_cast<QSGTransformNode *>(node->sgNode)->combinedMatrix();
@@ -1779,66 +2117,67 @@ static QMatrix4x4 qsg_matrixForRoot(Node *node)
void Renderer::uploadBatch(Batch *b)
{
- // Early out if nothing has changed in this batch..
- if (!b->needsUpload) {
- if (Q_UNLIKELY(debug_upload())) qDebug() << " Batch:" << b << "already uploaded...";
- return;
- }
-
- if (!b->first) {
- if (Q_UNLIKELY(debug_upload())) qDebug() << " Batch:" << b << "is invalid...";
- return;
- }
-
- if (b->isRenderNode) {
- if (Q_UNLIKELY(debug_upload())) qDebug() << " Batch: " << b << "is a render node...";
- return;
- }
+ // Early out if nothing has changed in this batch..
+ if (!b->needsUpload) {
+ if (Q_UNLIKELY(debug_upload())) qDebug() << " Batch:" << b << "already uploaded...";
+ return;
+ }
- // Figure out if we can merge or not, if not, then just render the batch as is..
- Q_ASSERT(b->first);
- Q_ASSERT(b->first->node);
+ if (!b->first) {
+ if (Q_UNLIKELY(debug_upload())) qDebug() << " Batch:" << b << "is invalid...";
+ return;
+ }
- QSGGeometryNode *gn = b->first->node;
- QSGGeometry *g = gn->geometry();
- QSGMaterial::Flags flags = gn->activeMaterial()->flags();
- bool canMerge = (g->drawingMode() == GL_TRIANGLES || g->drawingMode() == GL_TRIANGLE_STRIP ||
- g->drawingMode() == GL_LINES || g->drawingMode() == GL_POINTS)
- && b->positionAttribute >= 0
- && g->indexType() == GL_UNSIGNED_SHORT
- && (flags & (QSGMaterial::CustomCompileStep | QSGMaterial_FullMatrix)) == 0
- && ((flags & QSGMaterial::RequiresFullMatrixExceptTranslate) == 0 || b->isTranslateOnlyToRoot())
- && b->isSafeToBatch();
+ if (b->isRenderNode) {
+ if (Q_UNLIKELY(debug_upload())) qDebug() << " Batch: " << b << "is a render node...";
+ return;
+ }
- b->merged = canMerge;
+ // Figure out if we can merge or not, if not, then just render the batch as is..
+ Q_ASSERT(b->first);
+ Q_ASSERT(b->first->node);
- // Figure out how much memory we need...
- b->vertexCount = 0;
- b->indexCount = 0;
- int unmergedIndexSize = 0;
- Element *e = b->first;
+ QSGGeometryNode *gn = b->first->node;
+ QSGGeometry *g = gn->geometry();
+ QSGMaterial::Flags flags = gn->activeMaterial()->flags();
+ bool canMerge = (g->drawingMode() == QSGGeometry::DrawTriangles || g->drawingMode() == QSGGeometry::DrawTriangleStrip ||
+ g->drawingMode() == QSGGeometry::DrawLines || g->drawingMode() == QSGGeometry::DrawPoints)
+ && b->positionAttribute >= 0
+ && g->indexType() == QSGGeometry::UnsignedShortType
+ && (flags & (QSGMaterial::CustomCompileStep | QSGMaterial_FullMatrix)) == 0
+ && ((flags & QSGMaterial::RequiresFullMatrixExceptTranslate) == 0 || b->isTranslateOnlyToRoot())
+ && b->isSafeToBatch();
+
+ b->merged = canMerge;
+
+ // Figure out how much memory we need...
+ b->vertexCount = 0;
+ b->indexCount = 0;
+ int unmergedIndexSize = 0;
+ Element *e = b->first;
- while (e) {
- QSGGeometry *eg = e->node->geometry();
- b->vertexCount += eg->vertexCount();
- int iCount = eg->indexCount();
- if (b->merged) {
- if (iCount == 0)
- iCount = eg->vertexCount();
- iCount = qsg_fixIndexCount(iCount, g->drawingMode());
- } else {
- unmergedIndexSize += iCount * eg->sizeOfIndex();
- }
- b->indexCount += iCount;
- e = e->nextInBatch;
+ while (e) {
+ QSGGeometry *eg = e->node->geometry();
+ b->vertexCount += eg->vertexCount();
+ int iCount = eg->indexCount();
+ if (b->merged) {
+ if (iCount == 0)
+ iCount = eg->vertexCount();
+ iCount = qsg_fixIndexCount(iCount, g->drawingMode());
+ } else {
+ const int effectiveIndexSize = m_uint32IndexForRhi ? sizeof(quint32) : eg->sizeOfIndex();
+ unmergedIndexSize += iCount * effectiveIndexSize;
}
+ b->indexCount += iCount;
+ e = e->nextInBatch;
+ }
- // Abort if there are no vertices in this batch.. We abort this late as
- // this is a broken usecase which we do not care to optimize for...
- if (b->vertexCount == 0 || (b->merged && b->indexCount == 0))
- return;
+ // Abort if there are no vertices in this batch.. We abort this late as
+ // this is a broken usecase which we do not care to optimize for...
+ if (b->vertexCount == 0 || (b->merged && b->indexCount == 0))
+ return;
- /* Allocate memory for this batch. Merged batches are divided into three separate blocks
+ /* Allocate memory for this batch. Merged batches are divided into three separate blocks
1. Vertex data for all elements, as they were in the QSGGeometry object, but
with the tranform relative to this batch's root applied. The vertex data
is otherwise unmodified.
@@ -1850,119 +2189,161 @@ void Renderer::uploadBatch(Batch *b)
primitive. These are unsigned shorts for merged and arbitrary for
non-merged.
*/
- int bufferSize = b->vertexCount * g->sizeOfVertex();
- int ibufferSize = 0;
- if (b->merged) {
- ibufferSize = b->indexCount * sizeof(quint16);
- if (m_useDepthBuffer)
- bufferSize += b->vertexCount * sizeof(float);
- } else {
- ibufferSize = unmergedIndexSize;
- }
+ int bufferSize = b->vertexCount * g->sizeOfVertex();
+ int ibufferSize = 0;
+ if (b->merged) {
+ ibufferSize = b->indexCount * mergedIndexElemSize();
+ if (m_useDepthBuffer)
+ bufferSize += b->vertexCount * sizeof(float);
+ } else {
+ ibufferSize = unmergedIndexSize;
+ }
- const bool separateIndexBuffer = m_context->separateIndexBuffer();
- if (separateIndexBuffer)
- map(&b->ibo, ibufferSize, true);
- else
- bufferSize += ibufferSize;
- map(&b->vbo, bufferSize);
+ const bool separateIndexBuffer = m_context->separateIndexBuffer();
+ if (separateIndexBuffer)
+ map(&b->ibo, ibufferSize, true);
+ else
+ bufferSize += ibufferSize;
+ map(&b->vbo, bufferSize);
- if (Q_UNLIKELY(debug_upload())) qDebug() << " - batch" << b << " first:" << b->first << " root:"
- << b->root << " merged:" << b->merged << " positionAttribute" << b->positionAttribute
- << " vbo:" << b->vbo.id << ":" << b->vbo.size;
+ if (Q_UNLIKELY(debug_upload())) qDebug() << " - batch" << b << " first:" << b->first << " root:"
+ << b->root << " merged:" << b->merged << " positionAttribute" << b->positionAttribute
+ << " vbo:" << b->vbo.id << ":" << b->vbo.size;
- if (b->merged) {
- char *vertexData = b->vbo.data;
- char *zData = vertexData + b->vertexCount * g->sizeOfVertex();
- char *indexData = separateIndexBuffer
- ? b->ibo.data
- : zData + (int(m_useDepthBuffer) * b->vertexCount * sizeof(float));
-
- quint16 iOffset = 0;
- e = b->first;
- int verticesInSet = 0;
- int indicesInSet = 0;
- b->drawSets.reset();
- int drawSetIndices = separateIndexBuffer ? 0 : indexData - vertexData;
- const auto indexBase = separateIndexBuffer ? b->ibo.data : b->vbo.data;
- b->drawSets << DrawSet(0, zData - vertexData, drawSetIndices);
- while (e) {
- verticesInSet += e->node->geometry()->vertexCount();
- if (verticesInSet > 0xffff) {
- b->drawSets.last().indexCount = indicesInSet;
- if (g->drawingMode() == GL_TRIANGLE_STRIP) {
- b->drawSets.last().indices += 1 * sizeof(quint16);
- b->drawSets.last().indexCount -= 2;
- }
- drawSetIndices = indexData - indexBase;
- b->drawSets << DrawSet(vertexData - b->vbo.data,
- zData - b->vbo.data,
- drawSetIndices);
- iOffset = 0;
- verticesInSet = e->node->geometry()->vertexCount();
- indicesInSet = 0;
+ if (b->merged) {
+ char *vertexData = b->vbo.data;
+ char *zData = vertexData + b->vertexCount * g->sizeOfVertex();
+ char *indexData = separateIndexBuffer
+ ? b->ibo.data
+ : zData + (int(m_useDepthBuffer) * b->vertexCount * sizeof(float));
+
+ quint16 iOffset16 = 0;
+ quint32 iOffset32 = 0;
+ e = b->first;
+ uint verticesInSet = 0;
+ // Start a new set already after 65534 vertices because 0xFFFF may be
+ // used for an always-on primitive restart with some apis (adapt for
+ // uint32 indices as appropriate).
+ const uint verticesInSetLimit = m_uint32IndexForRhi ? 0xfffffffe : 0xfffe;
+ int indicesInSet = 0;
+ b->drawSets.reset();
+ int drawSetIndices = separateIndexBuffer ? 0 : indexData - vertexData;
+ const char *indexBase = separateIndexBuffer ? b->ibo.data : b->vbo.data;
+ b->drawSets << DrawSet(0, zData - vertexData, drawSetIndices);
+ while (e) {
+ verticesInSet += e->node->geometry()->vertexCount();
+ if (verticesInSet > verticesInSetLimit) {
+ b->drawSets.last().indexCount = indicesInSet;
+ if (g->drawingMode() == QSGGeometry::DrawTriangleStrip) {
+ b->drawSets.last().indices += 1 * mergedIndexElemSize();
+ b->drawSets.last().indexCount -= 2;
}
- uploadMergedElement(e, b->positionAttribute, &vertexData, &zData, &indexData, &iOffset, &indicesInSet);
- e = e->nextInBatch;
- }
- b->drawSets.last().indexCount = indicesInSet;
- // We skip the very first and very last degenerate triangles since they aren't needed
- // and the first one would reverse the vertex ordering of the merged strips.
- if (g->drawingMode() == GL_TRIANGLE_STRIP) {
- b->drawSets.last().indices += 1 * sizeof(quint16);
- b->drawSets.last().indexCount -= 2;
+ drawSetIndices = indexData - indexBase;
+ b->drawSets << DrawSet(vertexData - b->vbo.data,
+ zData - b->vbo.data,
+ drawSetIndices);
+ iOffset16 = 0;
+ iOffset32 = 0;
+ verticesInSet = e->node->geometry()->vertexCount();
+ indicesInSet = 0;
}
- } else {
- char *vboData = b->vbo.data;
- char *iboData = separateIndexBuffer ? b->ibo.data
- : vboData + b->vertexCount * g->sizeOfVertex();
- Element *e = b->first;
- while (e) {
- QSGGeometry *g = e->node->geometry();
- int vbs = g->vertexCount() * g->sizeOfVertex();
- memcpy(vboData, g->vertexData(), vbs);
- vboData = vboData + vbs;
- if (g->indexCount()) {
+ void *iBasePtr = &iOffset16;
+ if (m_uint32IndexForRhi)
+ iBasePtr = &iOffset32;
+ uploadMergedElement(e, b->positionAttribute, &vertexData, &zData, &indexData, iBasePtr, &indicesInSet);
+ e = e->nextInBatch;
+ }
+ b->drawSets.last().indexCount = indicesInSet;
+ // We skip the very first and very last degenerate triangles since they aren't needed
+ // and the first one would reverse the vertex ordering of the merged strips.
+ if (g->drawingMode() == QSGGeometry::DrawTriangleStrip) {
+ b->drawSets.last().indices += 1 * mergedIndexElemSize();
+ b->drawSets.last().indexCount -= 2;
+ }
+ } else {
+ char *vboData = b->vbo.data;
+ char *iboData = separateIndexBuffer ? b->ibo.data
+ : vboData + b->vertexCount * g->sizeOfVertex();
+ Element *e = b->first;
+ while (e) {
+ QSGGeometry *g = e->node->geometry();
+ int vbs = g->vertexCount() * g->sizeOfVertex();
+ memcpy(vboData, g->vertexData(), vbs);
+ vboData = vboData + vbs;
+ const int indexCount = g->indexCount();
+ if (indexCount) {
+ if (!m_rhi) {
int ibs = g->indexCount() * g->sizeOfIndex();
memcpy(iboData, g->indexData(), ibs);
iboData += ibs;
+ } else {
+ const int effectiveIndexSize = m_uint32IndexForRhi ? sizeof(quint32) : g->sizeOfIndex();
+ const int ibs = indexCount * effectiveIndexSize;
+ if (g->sizeOfIndex() == effectiveIndexSize) {
+ memcpy(iboData, g->indexData(), ibs);
+ } else {
+ if (g->sizeOfIndex() == sizeof(quint16) && effectiveIndexSize == sizeof(quint32)) {
+ quint16 *src = g->indexDataAsUShort();
+ quint32 *dst = (quint32 *) iboData;
+ for (int i = 0; i < indexCount; ++i)
+ dst[i] = src[i];
+ } else {
+ Q_ASSERT_X(false, "uploadBatch (unmerged)", "uint index with ushort effective index - cannot happen");
+ }
+ }
+ iboData += ibs;
}
- e = e->nextInBatch;
}
+ e = e->nextInBatch;
}
+ }
#ifndef QT_NO_DEBUG_OUTPUT
- if (Q_UNLIKELY(debug_upload())) {
- const char *vd = b->vbo.data;
- qDebug() << " -- Vertex Data, count:" << b->vertexCount << " - " << g->sizeOfVertex() << "bytes/vertex";
- for (int i=0; i<b->vertexCount; ++i) {
- QDebug dump = qDebug().nospace();
- dump << " --- " << i << ": ";
- int offset = 0;
- for (int a=0; a<g->attributeCount(); ++a) {
- const QSGGeometry::Attribute &attr = g->attributes()[a];
- dump << attr.position << ":(" << attr.tupleSize << ",";
- if (attr.type == GL_FLOAT) {
- dump << "float ";
- if (attr.isVertexCoordinate)
- dump << "* ";
- for (int t=0; t<attr.tupleSize; ++t)
- dump << *(const float *)(vd + offset + t * sizeof(float)) << " ";
- } else if (attr.type == GL_UNSIGNED_BYTE) {
- dump << "ubyte ";
- for (int t=0; t<attr.tupleSize; ++t)
- dump << *(const unsigned char *)(vd + offset + t * sizeof(unsigned char)) << " ";
- }
- dump << ") ";
- offset += attr.tupleSize * size_of_type(attr.type);
+ if (Q_UNLIKELY(debug_upload())) {
+ const char *vd = b->vbo.data;
+ qDebug() << " -- Vertex Data, count:" << b->vertexCount << " - " << g->sizeOfVertex() << "bytes/vertex";
+ for (int i=0; i<b->vertexCount; ++i) {
+ QDebug dump = qDebug().nospace();
+ dump << " --- " << i << ": ";
+ int offset = 0;
+ for (int a=0; a<g->attributeCount(); ++a) {
+ const QSGGeometry::Attribute &attr = g->attributes()[a];
+ dump << attr.position << ":(" << attr.tupleSize << ",";
+ if (attr.type == QSGGeometry::FloatType) {
+ dump << "float ";
+ if (attr.isVertexCoordinate)
+ dump << "* ";
+ for (int t=0; t<attr.tupleSize; ++t)
+ dump << *(const float *)(vd + offset + t * sizeof(float)) << " ";
+ } else if (attr.type == QSGGeometry::UnsignedByteType) {
+ dump << "ubyte ";
+ for (int t=0; t<attr.tupleSize; ++t)
+ dump << *(const unsigned char *)(vd + offset + t * sizeof(unsigned char)) << " ";
}
- if (b->merged && m_useDepthBuffer) {
- float zorder = ((float*)(b->vbo.data + b->vertexCount * g->sizeOfVertex()))[i];
- dump << " Z:(" << zorder << ")";
- }
- vd += g->sizeOfVertex();
+ dump << ") ";
+ offset += attr.tupleSize * size_of_type(attr.type);
+ }
+ if (b->merged && m_useDepthBuffer) {
+ float zorder = ((float*)(b->vbo.data + b->vertexCount * g->sizeOfVertex()))[i];
+ dump << " Z:(" << zorder << ")";
}
+ vd += g->sizeOfVertex();
+ }
- if (!b->drawSets.isEmpty()) {
+ if (!b->drawSets.isEmpty()) {
+ if (m_uint32IndexForRhi) {
+ const quint32 *id = (const quint32 *)(separateIndexBuffer
+ ? b->ibo.data
+ : b->vbo.data + b->drawSets.at(0).indices);
+ {
+ QDebug iDump = qDebug();
+ iDump << " -- Index Data, count:" << b->indexCount;
+ for (int i=0; i<b->indexCount; ++i) {
+ if ((i % 24) == 0)
+ iDump << endl << " --- ";
+ iDump << id[i];
+ }
+ }
+ } else {
const quint16 *id = (const quint16 *)(separateIndexBuffer
? b->ibo.data
: b->vbo.data + b->drawSets.at(0).indices);
@@ -1971,29 +2352,30 @@ void Renderer::uploadBatch(Batch *b)
iDump << " -- Index Data, count:" << b->indexCount;
for (int i=0; i<b->indexCount; ++i) {
if ((i % 24) == 0)
- iDump << endl << " --- ";
+ iDump << endl << " --- ";
iDump << id[i];
}
}
+ }
- for (int i=0; i<b->drawSets.size(); ++i) {
- const DrawSet &s = b->drawSets.at(i);
- qDebug() << " -- DrawSet: indexCount:" << s.indexCount << " vertices:" << s.vertices << " z:" << s.zorders << " indices:" << s.indices;
- }
+ for (int i=0; i<b->drawSets.size(); ++i) {
+ const DrawSet &s = b->drawSets.at(i);
+ qDebug() << " -- DrawSet: indexCount:" << s.indexCount << " vertices:" << s.vertices << " z:" << s.zorders << " indices:" << s.indices;
}
}
+ }
#endif // QT_NO_DEBUG_OUTPUT
- unmap(&b->vbo);
- if (separateIndexBuffer)
- unmap(&b->ibo, true);
+ unmap(&b->vbo);
+ if (separateIndexBuffer)
+ unmap(&b->ibo, true);
- if (Q_UNLIKELY(debug_upload())) qDebug() << " --- vertex/index buffers unmapped, batch upload completed...";
+ if (Q_UNLIKELY(debug_upload())) qDebug() << " --- vertex/index buffers unmapped, batch upload completed...";
- b->needsUpload = false;
+ b->needsUpload = false;
- if (Q_UNLIKELY(debug_render()))
- b->uploadedThisFrame = true;
+ if (Q_UNLIKELY(debug_render()))
+ b->uploadedThisFrame = true;
}
/*!
@@ -2002,15 +2384,15 @@ void Renderer::uploadBatch(Batch *b)
* If the clip is a pixel aligned rectangle, this function will use glScissor instead
* of stencil.
*/
-Renderer::ClipType Renderer::updateStencilClip(const QSGClipNode *clip)
+ClipState::ClipType Renderer::updateStencilClip(const QSGClipNode *clip)
{
if (!clip) {
glDisable(GL_STENCIL_TEST);
glDisable(GL_SCISSOR_TEST);
- return NoClip;
+ return ClipState::NoClip;
}
- ClipType clipType = NoClip;
+ ClipState::ClipType clipType = ClipState::NoClip;
GLuint vbo = 0;
int vboSize = 0;
@@ -2067,17 +2449,17 @@ Renderer::ClipType Renderer::updateStencilClip(const QSGClipNode *clip)
GLint ix2 = qRound((fx2 + 1) * deviceRect.width() * qreal(0.5));
GLint iy2 = qRound((fy2 + 1) * deviceRect.height() * qreal(0.5));
- if (!(clipType & ScissorClip)) {
+ if (!(clipType & ClipState::ScissorClip)) {
m_currentScissorRect = QRect(ix1, iy1, ix2 - ix1, iy2 - iy1);
glEnable(GL_SCISSOR_TEST);
- clipType |= ScissorClip;
+ clipType |= ClipState::ScissorClip;
} else {
m_currentScissorRect &= QRect(ix1, iy1, ix2 - ix1, iy2 - iy1);
}
glScissor(m_currentScissorRect.x(), m_currentScissorRect.y(),
m_currentScissorRect.width(), m_currentScissorRect.height());
} else {
- if (!(clipType & StencilClip)) {
+ if (!(clipType & ClipState::StencilClip)) {
if (!m_clipProgram.isLinked()) {
QSGShaderSourceBuilder::initializeProgramFromFiles(
&m_clipProgram,
@@ -2097,7 +2479,7 @@ Renderer::ClipType Renderer::updateStencilClip(const QSGClipNode *clip)
m_clipProgram.bind();
m_clipProgram.enableAttributeArray(0);
- clipType |= StencilClip;
+ clipType |= ClipState::StencilClip;
}
glStencilFunc(GL_EQUAL, m_currentStencilValue, 0xff); // stencil test, ref, test mask
@@ -2148,7 +2530,7 @@ Renderer::ClipType Renderer::updateStencilClip(const QSGClipNode *clip)
if (vbo)
glDeleteBuffers(1, &vbo);
- if (clipType & StencilClip) {
+ if (clipType & ClipState::StencilClip) {
m_clipProgram.disableAttributeArray(0);
glStencilFunc(GL_EQUAL, m_currentStencilValue, 0xff); // stencil test, ref, test mask
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // stencil fail, z fail, z pass
@@ -2160,7 +2542,7 @@ Renderer::ClipType Renderer::updateStencilClip(const QSGClipNode *clip)
return clipType;
}
-void Renderer::updateClip(const QSGClipNode *clipList, const Batch *batch)
+void Renderer::updateClip(const QSGClipNode *clipList, const Batch *batch) // legacy (GL-only)
{
if (clipList != m_currentClip && Q_LIKELY(!debug_noclip())) {
m_currentClip = clipList;
@@ -2174,7 +2556,7 @@ void Renderer::updateClip(const QSGClipNode *clipList, const Batch *batch)
m_currentClipType = updateStencilClip(m_currentClip);
if (batch->isOpaque) {
glEnable(GL_DEPTH_TEST);
- if (m_currentClipType & StencilClip)
+ if (m_currentClipType & ClipState::StencilClip)
glDepthMask(true);
}
}
@@ -2185,13 +2567,14 @@ void Renderer::updateClip(const QSGClipNode *clipList, const Batch *batch)
* which vertex attribute arrays need to be enabled and not. Then update the current
* Shader and current QSGMaterialShader.
*/
-void Renderer::setActiveShader(QSGMaterialShader *program, ShaderManager::Shader *shader)
+void Renderer::setActiveShader(QSGMaterialShader *program, ShaderManager::Shader *shader) // legacy (GL-only)
{
+ Q_ASSERT(!m_rhi);
const char * const *c = m_currentProgram ? m_currentProgram->attributeNames() : nullptr;
const char * const *n = program ? program->attributeNames() : nullptr;
- int cza = m_currentShader ? m_currentShader->pos_order : -1;
- int nza = shader ? shader->pos_order : -1;
+ int cza = m_currentShader ? m_currentShader->programGL.pos_order : -1;
+ int nza = shader ? shader->programGL.pos_order : -1;
int i = 0;
while (c || n) {
@@ -2233,7 +2616,373 @@ void Renderer::setActiveShader(QSGMaterialShader *program, ShaderManager::Shader
}
}
-void Renderer::renderMergedBatch(const Batch *batch)
+void Renderer::applyClipStateToGraphicsState() // RHI only
+{
+ m_gstate.usesScissor = (m_currentClipState.type & ClipState::ScissorClip);
+ m_gstate.stencilTest = (m_currentClipState.type & ClipState::StencilClip);
+}
+
+QRhiGraphicsPipeline *Renderer::buildStencilPipeline(const Batch *batch, bool firstStencilClipInBatch)
+{
+ QRhiGraphicsPipeline *ps = m_rhi->newGraphicsPipeline();
+ ps->setFlags(QRhiGraphicsPipeline::UsesStencilRef);
+ QRhiGraphicsPipeline::TargetBlend blend;
+ blend.colorWrite = 0;
+ ps->setTargetBlends({ blend });
+ ps->setSampleCount(renderTarget()->sampleCount());
+ ps->setStencilTest(true);
+ QRhiGraphicsPipeline::StencilOpState stencilOp;
+ if (firstStencilClipInBatch) {
+ stencilOp.compareOp = QRhiGraphicsPipeline::Always;
+ stencilOp.failOp = QRhiGraphicsPipeline::Keep;
+ stencilOp.depthFailOp = QRhiGraphicsPipeline::Keep;
+ stencilOp.passOp = QRhiGraphicsPipeline::Replace;
+ } else {
+ stencilOp.compareOp = QRhiGraphicsPipeline::Equal;
+ stencilOp.failOp = QRhiGraphicsPipeline::Keep;
+ stencilOp.depthFailOp = QRhiGraphicsPipeline::Keep;
+ stencilOp.passOp = QRhiGraphicsPipeline::IncrementAndClamp;
+ }
+ ps->setStencilFront(stencilOp);
+ ps->setStencilBack(stencilOp);
+
+ ps->setTopology(m_stencilClipCommon.topology);
+
+ ps->setShaderStages({ QRhiGraphicsShaderStage(QRhiGraphicsShaderStage::Vertex, m_stencilClipCommon.vs),
+ QRhiGraphicsShaderStage(QRhiGraphicsShaderStage::Fragment, m_stencilClipCommon.fs) });
+ ps->setVertexInputLayout(m_stencilClipCommon.inputLayout);
+ ps->setShaderResourceBindings(batch->stencilClipState.srb); // use something, it just needs to be layout-compatible
+ ps->setRenderPassDescriptor(renderPassDescriptor());
+
+ if (!ps->build()) {
+ qWarning("Failed to build stencil clip pipeline");
+ delete ps;
+ return nullptr;
+ }
+
+ return ps;
+}
+
+void Renderer::updateClipState(const QSGClipNode *clipList, Batch *batch) // RHI only
+{
+ // Note: No use of the clip-related speparate m_current* vars is allowed
+ // here. All stored in batch->clipState instead. To collect state during
+ // the prepare steps, m_currentClipState is used. It should not be used in
+ // the render steps afterwards.
+
+ // The stenciling logic is slightly different from the legacy GL path as we
+ // cannot just randomly clear the stencil buffer. We now put all clip
+ // shapes into the stencil buffer for all batches in the frame. This means
+ // that the number of total clips in a scene is reduced (since the stencil
+ // value cannot exceed 255) but we do not need any clears inbetween.
+
+ Q_ASSERT(m_rhi);
+ batch->stencilClipState.updateStencilBuffer = false;
+ if (clipList == m_currentClipState.clipList || Q_UNLIKELY(debug_noclip())) {
+ applyClipStateToGraphicsState();
+ batch->clipState = m_currentClipState;
+ return;
+ }
+
+ ClipState::ClipType clipType = ClipState::NoClip;
+ QRect scissorRect;
+ QVarLengthArray<const QSGClipNode *, 4> stencilClipNodes;
+ const QSGClipNode *clip = clipList;
+
+ batch->stencilClipState.drawCalls.reset();
+ int totalVSize = 0;
+ int totalISize = 0;
+ int totalUSize = 0;
+ const int StencilClipUbufSize = 64;
+
+ while (clip) {
+ QMatrix4x4 m = m_current_projection_matrix_native_ndc;
+ if (clip->matrix())
+ m *= *clip->matrix();
+
+ bool isRectangleWithNoPerspective = clip->isRectangular()
+ && qFuzzyIsNull(m(3, 0)) && qFuzzyIsNull(m(3, 1));
+ bool noRotate = qFuzzyIsNull(m(0, 1)) && qFuzzyIsNull(m(1, 0));
+ bool isRotate90 = qFuzzyIsNull(m(0, 0)) && qFuzzyIsNull(m(1, 1));
+
+ if (isRectangleWithNoPerspective && (noRotate || isRotate90)) {
+ QRectF bbox = clip->clipRect();
+ qreal invW = 1 / m(3, 3);
+ qreal fx1, fy1, fx2, fy2;
+ if (noRotate) {
+ fx1 = (bbox.left() * m(0, 0) + m(0, 3)) * invW;
+ fy1 = (bbox.bottom() * m(1, 1) + m(1, 3)) * invW;
+ fx2 = (bbox.right() * m(0, 0) + m(0, 3)) * invW;
+ fy2 = (bbox.top() * m(1, 1) + m(1, 3)) * invW;
+ } else {
+ Q_ASSERT(isRotate90);
+ fx1 = (bbox.bottom() * m(0, 1) + m(0, 3)) * invW;
+ fy1 = (bbox.left() * m(1, 0) + m(1, 3)) * invW;
+ fx2 = (bbox.top() * m(0, 1) + m(0, 3)) * invW;
+ fy2 = (bbox.right() * m(1, 0) + m(1, 3)) * invW;
+ }
+
+ if (fx1 > fx2)
+ qSwap(fx1, fx2);
+ if (fy1 > fy2)
+ qSwap(fy1, fy2);
+
+ QRect deviceRect = this->deviceRect();
+
+ GLint ix1 = qRound((fx1 + 1) * deviceRect.width() * qreal(0.5));
+ GLint iy1 = qRound((fy1 + 1) * deviceRect.height() * qreal(0.5));
+ GLint ix2 = qRound((fx2 + 1) * deviceRect.width() * qreal(0.5));
+ GLint iy2 = qRound((fy2 + 1) * deviceRect.height() * qreal(0.5));
+
+ if (!(clipType & ClipState::ScissorClip)) {
+ clipType |= ClipState::ScissorClip;
+ scissorRect = QRect(ix1, iy1, ix2 - ix1, iy2 - iy1);
+ } else {
+ scissorRect &= QRect(ix1, iy1, ix2 - ix1, iy2 - iy1);
+ }
+ } else {
+ clipType |= ClipState::StencilClip;
+
+ const QSGGeometry *g = clip->geometry();
+ Q_ASSERT(g->attributeCount() > 0);
+
+ const int vertexByteSize = g->sizeOfVertex() * g->vertexCount();
+ // the 4 byte alignment may not actually be needed here
+ totalVSize = aligned(totalVSize, 4) + vertexByteSize;
+ if (g->indexCount()) {
+ const int indexByteSize = g->sizeOfIndex() * g->indexCount();
+ // so no need to worry about NonFourAlignedEffectiveIndexBufferOffset
+ totalISize = aligned(totalISize, 4) + indexByteSize;
+ }
+ // ubuf start offsets must be aligned (typically to 256 bytes)
+ totalUSize = aligned(totalUSize, m_ubufAlignment) + StencilClipUbufSize;
+
+ stencilClipNodes.append(clip);
+ }
+
+ clip = clip->clipList();
+ }
+
+ if (clipType & ClipState::StencilClip) {
+ bool rebuildVBuf = false;
+ if (!batch->stencilClipState.vbuf) {
+ batch->stencilClipState.vbuf = m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::VertexBuffer, totalVSize);
+ rebuildVBuf = true;
+ } else if (batch->stencilClipState.vbuf->size() < totalVSize) {
+ batch->stencilClipState.vbuf->setSize(totalVSize);
+ rebuildVBuf = true;
+ }
+ if (rebuildVBuf) {
+ if (!batch->stencilClipState.vbuf->build()) {
+ qWarning("Failed to build stencil clip vertex buffer");
+ delete batch->stencilClipState.vbuf;
+ batch->stencilClipState.vbuf = nullptr;
+ return;
+ }
+ }
+
+ if (totalISize) {
+ bool rebuildIBuf = false;
+ if (!batch->stencilClipState.ibuf) {
+ batch->stencilClipState.ibuf = m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::IndexBuffer, totalISize);
+ rebuildIBuf = true;
+ } else if (batch->stencilClipState.ibuf->size() < totalISize) {
+ batch->stencilClipState.ibuf->setSize(totalISize);
+ rebuildIBuf = true;
+ }
+ if (rebuildIBuf) {
+ if (!batch->stencilClipState.ibuf->build()) {
+ qWarning("Failed to build stencil clip index buffer");
+ delete batch->stencilClipState.ibuf;
+ batch->stencilClipState.ibuf = nullptr;
+ return;
+ }
+ }
+ }
+
+ bool rebuildUBuf = false;
+ if (!batch->stencilClipState.ubuf) {
+ batch->stencilClipState.ubuf = m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, totalUSize);
+ rebuildUBuf = true;
+ } else if (batch->stencilClipState.ubuf->size() < totalUSize) {
+ batch->stencilClipState.ubuf->setSize(totalUSize);
+ rebuildUBuf = true;
+ }
+ if (rebuildUBuf) {
+ if (!batch->stencilClipState.ubuf->build()) {
+ qWarning("Failed to build stencil clip uniform buffer");
+ delete batch->stencilClipState.ubuf;
+ batch->stencilClipState.ubuf = nullptr;
+ return;
+ }
+ }
+
+ if (!batch->stencilClipState.srb) {
+ batch->stencilClipState.srb = m_rhi->newShaderResourceBindings();
+ const QRhiShaderResourceBinding ubufBinding = QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(
+ 0, QRhiShaderResourceBinding::VertexStage, batch->stencilClipState.ubuf, StencilClipUbufSize);
+ batch->stencilClipState.srb->setBindings({ ubufBinding });
+ if (!batch->stencilClipState.srb->build()) {
+ qWarning("Failed to build stencil clip srb");
+ delete batch->stencilClipState.srb;
+ batch->stencilClipState.srb = nullptr;
+ return;
+ }
+ }
+
+ int vOffset = 0;
+ int iOffset = 0;
+ int uOffset = 0;
+ for (const QSGClipNode *clip : stencilClipNodes) {
+ const QSGGeometry *g = clip->geometry();
+ const QSGGeometry::Attribute *a = g->attributes();
+ StencilClipState::StencilDrawCall drawCall;
+ const bool firstStencilClipInBatch = batch->stencilClipState.drawCalls.isEmpty();
+
+ if (firstStencilClipInBatch) {
+ m_stencilClipCommon.inputLayout.setBindings({ QRhiVertexInputBinding(g->sizeOfVertex()) });
+ m_stencilClipCommon.inputLayout.setAttributes({ QRhiVertexInputAttribute(0, 0, qsg_vertexInputFormat(*a), 0) });
+ m_stencilClipCommon.topology = qsg_topology(g->drawingMode());
+ }
+#ifndef QT_NO_DEBUG
+ else {
+ if (qsg_topology(g->drawingMode()) != m_stencilClipCommon.topology)
+ qWarning("updateClipState: Clip list entries have different primitive topologies, this is not currently supported.");
+ if (qsg_vertexInputFormat(*a) != m_stencilClipCommon.inputLayout.cbeginAttributes()->format())
+ qWarning("updateClipState: Clip list entries have different vertex input layouts, this is must not happen.");
+ }
+#endif
+
+ drawCall.vbufOffset = aligned(vOffset, 4);
+ const int vertexByteSize = g->sizeOfVertex() * g->vertexCount();
+ vOffset = drawCall.vbufOffset + vertexByteSize;
+
+ int indexByteSize = 0;
+ if (g->indexCount()) {
+ drawCall.ibufOffset = aligned(iOffset, 4);
+ indexByteSize = g->sizeOfIndex() * g->indexCount();
+ iOffset = drawCall.ibufOffset + indexByteSize;
+ }
+
+ drawCall.ubufOffset = aligned(uOffset, m_ubufAlignment);
+ uOffset = drawCall.ubufOffset + StencilClipUbufSize;
+
+ QMatrix4x4 matrixYUpNDC = m_current_projection_matrix;
+ if (clip->matrix())
+ matrixYUpNDC *= *clip->matrix();
+
+ m_resourceUpdates->updateDynamicBuffer(batch->stencilClipState.ubuf, drawCall.ubufOffset, 64, matrixYUpNDC.constData());
+ m_resourceUpdates->updateDynamicBuffer(batch->stencilClipState.vbuf, drawCall.vbufOffset, vertexByteSize, g->vertexData());
+ if (indexByteSize)
+ m_resourceUpdates->updateDynamicBuffer(batch->stencilClipState.ibuf, drawCall.ibufOffset, indexByteSize, g->indexData());
+
+ // stencil ref goes 1, 1, 2, 3, 4, ..., N for the clips in the first batch,
+ // then N+1, N+1, N+2, N+3, ... for the next batch,
+ // and so on.
+ // Note the different stencilOp for the first and the subsequent clips.
+ drawCall.stencilRef = firstStencilClipInBatch ? m_currentClipState.stencilRef + 1 : m_currentClipState.stencilRef;
+ m_currentClipState.stencilRef += 1;
+
+ drawCall.vertexCount = g->vertexCount();
+ drawCall.indexCount = g->indexCount();
+ drawCall.indexFormat = qsg_indexFormat(g);
+ batch->stencilClipState.drawCalls.add(drawCall);
+ }
+
+ if (!m_stencilClipCommon.vs.isValid())
+ m_stencilClipCommon.vs = QSGMaterialRhiShaderPrivate::loadShader(QLatin1String(":/qt-project.org/scenegraph/shaders_ng/stencilclip.vert.qsb"));
+
+ if (!m_stencilClipCommon.fs.isValid())
+ m_stencilClipCommon.fs = QSGMaterialRhiShaderPrivate::loadShader(QLatin1String(":/qt-project.org/scenegraph/shaders_ng/stencilclip.frag.qsb"));
+
+ if (!m_stencilClipCommon.replacePs)
+ m_stencilClipCommon.replacePs = buildStencilPipeline(batch, true);
+
+ if (!m_stencilClipCommon.incrPs)
+ m_stencilClipCommon.incrPs = buildStencilPipeline(batch, false);
+
+ batch->stencilClipState.updateStencilBuffer = true;
+ }
+
+ m_currentClipState.clipList = clipList;
+ m_currentClipState.type = clipType;
+ m_currentClipState.scissor = QRhiScissor(scissorRect.x(), scissorRect.y(),
+ scissorRect.width(), scissorRect.height());
+
+ applyClipStateToGraphicsState();
+ batch->clipState = m_currentClipState;
+}
+
+void Renderer::enqueueStencilDraw(const Batch *batch) // RHI only
+{
+ // cliptype stencil + updateStencilBuffer==false means the batch uses
+ // stenciling but relies on the stencil data generated by a previous batch
+ // (due to the having the same clip node). Do not enqueue draw calls for
+ // stencil in this case as the stencil buffer is already up-to-date.
+ if (!batch->stencilClipState.updateStencilBuffer)
+ return;
+
+ QRhiCommandBuffer *cb = commandBuffer();
+ const int count = batch->stencilClipState.drawCalls.size();
+ for (int i = 0; i < count; ++i) {
+ const StencilClipState::StencilDrawCall &drawCall(batch->stencilClipState.drawCalls.at(i));
+ QRhiShaderResourceBindings *srb = batch->stencilClipState.srb;
+ QRhiCommandBuffer::DynamicOffset ubufOffset(0, drawCall.ubufOffset);
+ if (i == 0) {
+ cb->setGraphicsPipeline(m_stencilClipCommon.replacePs);
+ cb->setViewport(m_pstate.viewport);
+ } else if (i == 1) {
+ cb->setGraphicsPipeline(m_stencilClipCommon.incrPs);
+ cb->setViewport(m_pstate.viewport);
+ }
+ // else incrPs is already bound
+ cb->setShaderResources(srb, 1, &ubufOffset);
+ cb->setStencilRef(drawCall.stencilRef);
+ const QRhiCommandBuffer::VertexInput vbufBinding(batch->stencilClipState.vbuf, drawCall.vbufOffset);
+ if (drawCall.indexCount) {
+ cb->setVertexInput(0, 1, &vbufBinding,
+ batch->stencilClipState.ibuf, drawCall.ibufOffset, drawCall.indexFormat);
+ cb->drawIndexed(drawCall.indexCount);
+ } else {
+ cb->setVertexInput(0, 1, &vbufBinding);
+ cb->draw(drawCall.vertexCount);
+ }
+ }
+}
+
+void Renderer::setActiveRhiShader(QSGMaterialRhiShader *program, ShaderManager::Shader *shader) // RHI only
+{
+ Q_ASSERT(m_rhi);
+ m_currentRhiProgram = program;
+ m_currentShader = shader;
+ m_currentMaterial = nullptr;
+}
+
+void Renderer::updateLineWidth(QSGGeometry *g) // legacy (GL-only)
+{
+ if (g->drawingMode() == GL_LINE_STRIP || g->drawingMode() == GL_LINE_LOOP || g->drawingMode() == GL_LINES)
+ glLineWidth(g->lineWidth());
+#if !defined(QT_OPENGL_ES_2)
+ else {
+ QOpenGLContext *ctx = m_context->openglContext();
+ if (!ctx->isOpenGLES() && g->drawingMode() == GL_POINTS) {
+ QOpenGLFunctions_1_0 *gl1funcs = nullptr;
+ QOpenGLFunctions_3_2_Core *gl3funcs = nullptr;
+ if (ctx->format().profile() == QSurfaceFormat::CoreProfile)
+ gl3funcs = ctx->versionFunctions<QOpenGLFunctions_3_2_Core>();
+ else
+ gl1funcs = ctx->versionFunctions<QOpenGLFunctions_1_0>();
+ Q_ASSERT(gl1funcs || gl3funcs);
+ if (gl1funcs)
+ gl1funcs->glPointSize(g->lineWidth());
+ else
+ gl3funcs->glPointSize(g->lineWidth());
+ }
+ }
+#endif
+}
+
+void Renderer::renderMergedBatch(const Batch *batch) // legacy (GL-only)
{
if (batch->vertexCount == 0 || batch->indexCount == 0)
return;
@@ -2289,13 +3038,14 @@ void Renderer::renderMergedBatch(const Batch *batch)
QSGMaterial *material = gn->activeMaterial();
- ShaderManager::Shader *sms = m_useDepthBuffer ? m_shaderManager->prepareMaterial(material) : m_shaderManager->prepareMaterialNoRewrite(material);
+ ShaderManager::Shader *sms = m_useDepthBuffer ? m_shaderManager->prepareMaterial(material)
+ : m_shaderManager->prepareMaterialNoRewrite(material);
if (!sms)
return;
- QSGMaterialShader *program = sms->program;
+ Q_ASSERT(sms->programGL.program);
if (m_currentShader != sms)
- setActiveShader(program, sms);
+ setActiveShader(sms->programGL.program, sms);
m_current_opacity = gn->inheritedOpacity();
if (!qFuzzyCompare(sms->lastOpacity, float(m_current_opacity))) {
@@ -2303,7 +3053,7 @@ void Renderer::renderMergedBatch(const Batch *batch)
sms->lastOpacity = m_current_opacity;
}
- program->updateState(state(dirty), material, m_currentMaterial);
+ sms->programGL.program->updateState(state(dirty), material, m_currentMaterial);
#ifndef QT_NO_DEBUG
if (qsg_test_and_clear_material_failure()) {
@@ -2320,9 +3070,9 @@ void Renderer::renderMergedBatch(const Batch *batch)
m_currentMaterial = material;
- QSGGeometry* g = gn->geometry();
+ QSGGeometry *g = gn->geometry();
updateLineWidth(g);
- char const *const *attrNames = program->attributeNames();
+ char const *const *attrNames = sms->programGL.program->attributeNames();
for (int i=0; i<batch->drawSets.size(); ++i) {
const DrawSet &draw = batch->drawSets.at(i);
int offset = 0;
@@ -2335,13 +3085,13 @@ void Renderer::renderMergedBatch(const Batch *batch)
offset += a.tupleSize * size_of_type(a.type);
}
if (m_useDepthBuffer)
- glVertexAttribPointer(sms->pos_order, 1, GL_FLOAT, false, 0, (void *) (qintptr) (draw.zorders));
+ glVertexAttribPointer(sms->programGL.pos_order, 1, GL_FLOAT, false, 0, (void *) (qintptr) (draw.zorders));
glDrawElements(g->drawingMode(), draw.indexCount, GL_UNSIGNED_SHORT, (void *) (qintptr) (indexBase + draw.indices));
}
}
-void Renderer::renderUnmergedBatch(const Batch *batch)
+void Renderer::renderUnmergedBatch(const Batch *batch) // legacy (GL-only)
{
if (batch->vertexCount == 0)
return;
@@ -2371,7 +3121,7 @@ void Renderer::renderUnmergedBatch(const Batch *batch)
glBindBuffer(GL_ARRAY_BUFFER, batch->vbo.id);
char *indexBase = nullptr;
- const auto separateIndexBuffer = m_context->separateIndexBuffer();
+ const bool separateIndexBuffer = m_context->separateIndexBuffer();
const Buffer *indexBuf = separateIndexBuffer ? &batch->ibo : &batch->vbo;
if (batch->indexCount) {
if (m_context->hasBrokenIndexBufferObjects()) {
@@ -2389,10 +3139,10 @@ void Renderer::renderUnmergedBatch(const Batch *batch)
ShaderManager::Shader *sms = m_shaderManager->prepareMaterialNoRewrite(material);
if (!sms)
return;
- QSGMaterialShader *program = sms->program;
- if (sms != m_currentShader)
- setActiveShader(program, sms);
+ Q_ASSERT(sms->programGL.program);
+ if (m_currentShader != sms)
+ setActiveShader(sms->programGL.program, sms);
m_current_opacity = gn->inheritedOpacity();
if (sms->lastOpacity != m_current_opacity) {
@@ -2419,7 +3169,7 @@ void Renderer::renderUnmergedBatch(const Batch *batch)
m_current_projection_matrix(2, 3) = 1.0f - e->order * m_zRange;
}
- program->updateState(state(dirty), material, m_currentMaterial);
+ sms->programGL.program->updateState(state(dirty), material, m_currentMaterial);
#ifndef QT_NO_DEBUG
if (qsg_test_and_clear_material_failure()) {
@@ -2435,8 +3185,8 @@ void Renderer::renderUnmergedBatch(const Batch *batch)
// are all identical (compare==0) since they are in the same batch.
m_currentMaterial = material;
- QSGGeometry* g = gn->geometry();
- char const *const *attrNames = program->attributeNames();
+ QSGGeometry *g = gn->geometry();
+ char const *const *attrNames = sms->programGL.program->attributeNames();
int offset = 0;
for (int j = 0; attrNames[j]; ++j) {
if (!*attrNames[j])
@@ -2463,101 +3213,933 @@ void Renderer::renderUnmergedBatch(const Batch *batch)
}
}
-void Renderer::updateLineWidth(QSGGeometry *g)
+static inline bool needsBlendConstant(QRhiGraphicsPipeline::BlendFactor f)
{
- if (g->drawingMode() == GL_LINE_STRIP || g->drawingMode() == GL_LINE_LOOP || g->drawingMode() == GL_LINES)
- glLineWidth(g->lineWidth());
-#if !defined(QT_OPENGL_ES_2)
- else {
- QOpenGLContext *ctx = m_context->openglContext();
- if (!ctx->isOpenGLES() && g->drawingMode() == GL_POINTS) {
- QOpenGLFunctions_1_0 *gl1funcs = nullptr;
- QOpenGLFunctions_3_2_Core *gl3funcs = nullptr;
- if (ctx->format().profile() == QSurfaceFormat::CoreProfile)
- gl3funcs = ctx->versionFunctions<QOpenGLFunctions_3_2_Core>();
- else
- gl1funcs = ctx->versionFunctions<QOpenGLFunctions_1_0>();
- Q_ASSERT(gl1funcs || gl3funcs);
- if (gl1funcs)
- gl1funcs->glPointSize(g->lineWidth());
- else
- gl3funcs->glPointSize(g->lineWidth());
+ return f == QRhiGraphicsPipeline::ConstantColor
+ || f == QRhiGraphicsPipeline::OneMinusConstantColor
+ || f == QRhiGraphicsPipeline::ConstantAlpha
+ || f == QRhiGraphicsPipeline::OneMinusConstantAlpha;
+}
+
+// With QRhi renderBatches() is split to two steps: prepare and render.
+//
+// Prepare goes through the batches and elements, and set up a graphics
+// pipeline, srb, uniform buffer, calculates clipping, based on m_gstate, the
+// material (shaders), and the batches. This step does not touch the command
+// buffer or renderpass-related state (m_pstate).
+//
+// The render step then starts a renderpass, and goes through all
+// batches/elements again and records setGraphicsPipeline, drawIndexed, etc. on
+// the command buffer. The prepare step's accumulated global state like
+// m_gstate must not be used here. Rather, all data needed for rendering is
+// available from Batch/Element at this stage. Bookkeeping of state in the
+// renderpass is done via m_pstate.
+
+bool Renderer::ensurePipelineState(Element *e, const ShaderManager::Shader *sms) // RHI only, [prepare step]
+{
+ // In unmerged batches the srbs in the elements are all compatible layout-wise.
+ const GraphicsPipelineStateKey k { m_gstate, sms, renderPassDescriptor(), e->srb };
+
+ // Note: dynamic state (viewport rect, scissor rect, stencil ref, blend
+ // constant) is never a part of GraphicsState/QRhiGraphicsPipeline.
+
+ // See if there is an existing, matching pipeline state object.
+ auto it = m_pipelines.constFind(k);
+ if (it != m_pipelines.constEnd()) {
+ e->ps = *it;
+ return true;
+ }
+
+ // Build a new one. This is potentially expensive.
+ QRhiGraphicsPipeline *ps = m_rhi->newGraphicsPipeline();
+ ps->setShaderStages(sms->programRhi.shaderStages.cbegin(), sms->programRhi.shaderStages.cend());
+ ps->setVertexInputLayout(sms->programRhi.inputLayout);
+ ps->setShaderResourceBindings(e->srb);
+ ps->setRenderPassDescriptor(renderPassDescriptor());
+
+ QRhiGraphicsPipeline::Flags flags = 0;
+ if (needsBlendConstant(m_gstate.srcColor) || needsBlendConstant(m_gstate.dstColor))
+ flags |= QRhiGraphicsPipeline::UsesBlendConstants;
+ if (m_gstate.usesScissor)
+ flags |= QRhiGraphicsPipeline::UsesScissor;
+ if (m_gstate.stencilTest)
+ flags |= QRhiGraphicsPipeline::UsesStencilRef;
+
+ ps->setFlags(flags);
+ ps->setTopology(qsg_topology(m_gstate.drawMode));
+ ps->setCullMode(m_gstate.cullMode);
+
+ QRhiGraphicsPipeline::TargetBlend blend;
+ blend.colorWrite = m_gstate.colorWrite;
+ blend.enable = m_gstate.blending;
+ blend.srcColor = m_gstate.srcColor;
+ blend.dstColor = m_gstate.dstColor;
+ ps->setTargetBlends({ blend });
+
+ ps->setDepthTest(m_gstate.depthTest);
+ ps->setDepthWrite(m_gstate.depthWrite);
+ ps->setDepthOp(m_gstate.depthFunc);
+
+ if (m_gstate.stencilTest) {
+ ps->setStencilTest(true);
+ QRhiGraphicsPipeline::StencilOpState stencilOp;
+ stencilOp.compareOp = QRhiGraphicsPipeline::Equal;
+ stencilOp.failOp = QRhiGraphicsPipeline::Keep;
+ stencilOp.depthFailOp = QRhiGraphicsPipeline::Keep;
+ stencilOp.passOp = QRhiGraphicsPipeline::Keep;
+ ps->setStencilFront(stencilOp);
+ ps->setStencilBack(stencilOp);
+ }
+
+ ps->setSampleCount(m_gstate.sampleCount);
+
+ ps->setLineWidth(m_gstate.lineWidth);
+
+ //qDebug("building new ps %p", ps);
+ if (!ps->build()) {
+ qWarning("Failed to build graphics pipeline state");
+ delete ps;
+ return false;
+ }
+
+ m_pipelines.insert(k, ps);
+ e->ps = ps;
+ return true;
+}
+
+static QRhiSampler *newSampler(QRhi *rhi, const QSGSamplerDescription &desc)
+{
+ QRhiSampler::Filter magFilter;
+ QRhiSampler::Filter minFilter;
+ QRhiSampler::Filter mipmapMode;
+ QRhiSampler::AddressMode u;
+ QRhiSampler::AddressMode v;
+
+ switch (desc.filtering) {
+ case QSGTexture::None:
+ Q_FALLTHROUGH();
+ case QSGTexture::Nearest:
+ magFilter = minFilter = QRhiSampler::Nearest;
+ break;
+ case QSGTexture::Linear:
+ magFilter = minFilter = QRhiSampler::Linear;
+ break;
+ default:
+ Q_UNREACHABLE();
+ magFilter = minFilter = QRhiSampler::Nearest;
+ break;
+ }
+
+ switch (desc.mipmapFiltering) {
+ case QSGTexture::None:
+ mipmapMode = QRhiSampler::None;
+ break;
+ case QSGTexture::Nearest:
+ mipmapMode = QRhiSampler::Nearest;
+ break;
+ case QSGTexture::Linear:
+ mipmapMode = QRhiSampler::Linear;
+ break;
+ default:
+ Q_UNREACHABLE();
+ mipmapMode = QRhiSampler::None;
+ break;
+ }
+
+ switch (desc.horizontalWrap) {
+ case QSGTexture::Repeat:
+ u = QRhiSampler::Repeat;
+ break;
+ case QSGTexture::ClampToEdge:
+ u = QRhiSampler::ClampToEdge;
+ break;
+ case QSGTexture::MirroredRepeat:
+ u = QRhiSampler::Mirror;
+ break;
+ default:
+ Q_UNREACHABLE();
+ u = QRhiSampler::ClampToEdge;
+ break;
+ }
+
+ switch (desc.verticalWrap) {
+ case QSGTexture::Repeat:
+ v = QRhiSampler::Repeat;
+ break;
+ case QSGTexture::ClampToEdge:
+ v = QRhiSampler::ClampToEdge;
+ break;
+ case QSGTexture::MirroredRepeat:
+ v = QRhiSampler::Mirror;
+ break;
+ default:
+ Q_UNREACHABLE();
+ v = QRhiSampler::ClampToEdge;
+ break;
+ }
+
+ return rhi->newSampler(magFilter, minFilter, mipmapMode, u, v);
+}
+
+QRhiTexture *Renderer::dummyTexture()
+{
+ if (!m_dummyTexture) {
+ m_dummyTexture = m_rhi->newTexture(QRhiTexture::RGBA8, QSize(64, 64));
+ if (m_dummyTexture->build()) {
+ if (m_resourceUpdates) {
+ QImage img(m_dummyTexture->pixelSize(), QImage::Format_RGBA8888_Premultiplied);
+ img.fill(0);
+ m_resourceUpdates->uploadTexture(m_dummyTexture, img);
+ }
+ }
+ }
+ return m_dummyTexture;
+}
+
+static void rendererToMaterialGraphicsState(QSGMaterialRhiShader::GraphicsPipelineState *dst,
+ GraphicsState *src)
+{
+ dst->blendEnable = src->blending;
+
+ // the enum values should match, sanity check it
+ Q_ASSERT(int(QSGMaterialRhiShader::GraphicsPipelineState::OneMinusSrc1Alpha) == int(QRhiGraphicsPipeline::OneMinusSrc1Alpha));
+ Q_ASSERT(int(QSGMaterialRhiShader::GraphicsPipelineState::A) == int(QRhiGraphicsPipeline::A));
+ Q_ASSERT(int(QSGMaterialRhiShader::GraphicsPipelineState::CullBack) == int(QRhiGraphicsPipeline::Back));
+
+ dst->srcColor = QSGMaterialRhiShader::GraphicsPipelineState::BlendFactor(src->srcColor);
+ dst->dstColor = QSGMaterialRhiShader::GraphicsPipelineState::BlendFactor(src->dstColor);
+
+ dst->colorWrite = QSGMaterialRhiShader::GraphicsPipelineState::ColorMask(int(src->colorWrite));
+
+ dst->cullMode = QSGMaterialRhiShader::GraphicsPipelineState::CullMode(src->cullMode);
+}
+
+static void materialToRendererGraphicsState(GraphicsState *dst,
+ QSGMaterialRhiShader::GraphicsPipelineState *src)
+{
+ dst->blending = src->blendEnable;
+ dst->srcColor = QRhiGraphicsPipeline::BlendFactor(src->srcColor);
+ dst->dstColor = QRhiGraphicsPipeline::BlendFactor(src->dstColor);
+ dst->colorWrite = QRhiGraphicsPipeline::ColorMask(int(src->colorWrite));
+ dst->cullMode = QRhiGraphicsPipeline::CullMode(src->cullMode);
+}
+
+void Renderer::updateMaterialDynamicData(ShaderManager::Shader *sms,
+ QSGMaterialRhiShader::RenderState &renderState,
+ QSGMaterial *material,
+ ShaderManager::ShaderResourceBindingList *bindings,
+ const Batch *batch,
+ int ubufOffset,
+ int ubufRegionSize) // RHI only, [prepare step]
+{
+ m_current_resource_update_batch = m_resourceUpdates;
+
+ QSGMaterialRhiShader *shader = sms->programRhi.program;
+ QSGMaterialRhiShaderPrivate *pd = QSGMaterialRhiShaderPrivate::get(shader);
+ if (pd->ubufBinding >= 0) {
+ m_current_uniform_data = &pd->masterUniformData;
+ const bool changed = shader->updateUniformData(renderState, material, m_currentMaterial);
+ m_current_uniform_data = nullptr;
+
+ if (changed || !batch->ubufDataValid)
+ m_resourceUpdates->updateDynamicBuffer(batch->ubuf, ubufOffset, ubufRegionSize, pd->masterUniformData.constData());
+
+ bindings->append(QRhiShaderResourceBinding::uniformBuffer(pd->ubufBinding,
+ pd->ubufStages,
+ batch->ubuf,
+ ubufOffset,
+ ubufRegionSize));
+ }
+
+ for (int binding = 0; binding < QSGMaterialRhiShaderPrivate::MAX_SHADER_RESOURCE_BINDINGS; ++binding) {
+ const QRhiShaderResourceBinding::StageFlags stages = pd->combinedImageSamplerBindings[binding];
+ if (!stages)
+ continue;
+
+ QSGTexture *prevTex = pd->textureBindingTable[binding];
+ QSGTexture *t = prevTex;
+
+ shader->updateSampledImage(renderState, binding, &t, material, m_currentMaterial);
+ if (!t) {
+ qWarning("No QSGTexture provided from updateSampledImage(). This is wrong.");
+ continue;
+ }
+
+ QSGTexturePrivate *td = QSGTexturePrivate::get(t);
+ // prevTex may be invalid at this point, avoid dereferencing it
+ if (t != prevTex || td->hasDirtySamplerOptions()) {
+ // The QSGTexture, and so the sampler parameters, may have changed.
+ // The rhiTexture is not relevant here.
+ td->resetDirtySamplerOptions();
+ pd->textureBindingTable[binding] = t; // does not own
+ pd->samplerBindingTable[binding] = nullptr;
+ if (t->anisotropyLevel() != QSGTexture::AnisotropyNone) // ###
+ qWarning("QSGTexture anisotropy levels are not currently supported");
+
+ const QSGSamplerDescription samplerDesc = QSGSamplerDescription::fromTexture(t);
+ QRhiSampler *sampler = nullptr;
+ auto it = m_samplers.constFind(samplerDesc);
+ if (it != m_samplers.constEnd()) {
+ sampler = *it;
+ Q_ASSERT(sampler);
+ } else {
+ sampler = newSampler(m_rhi, samplerDesc);
+ if (!sampler->build()) {
+ qWarning("Failed to build sampler");
+ delete sampler;
+ continue;
+ }
+ m_samplers.insert(samplerDesc, sampler);
+ }
+ pd->samplerBindingTable[binding] = sampler; // does not own
+ }
+
+ if (pd->textureBindingTable[binding] && pd->samplerBindingTable[binding]) {
+ QRhiTexture *texture = QSGTexturePrivate::get(pd->textureBindingTable[binding])->rhiTexture();
+ // texture may be null if the update above failed for any reason,
+ // or if the QSGTexture chose to return null intentionally. This is
+ // valid and we still need to provide something to the shader.
+ if (!texture)
+ texture = dummyTexture();
+ QRhiSampler *sampler = pd->samplerBindingTable[binding];
+ bindings->append(QRhiShaderResourceBinding::sampledTexture(binding,
+ stages,
+ texture,
+ sampler));
}
}
+
+#ifndef QT_NO_DEBUG
+ if (bindings->isEmpty())
+ qWarning("No shader resources for material %p, this is odd.", material);
#endif
}
-void Renderer::renderBatches()
+void Renderer::updateMaterialStaticData(ShaderManager::Shader *sms,
+ QSGMaterialRhiShader::RenderState &renderState,
+ QSGMaterial *material,
+ Batch *batch,
+ bool *gstateChanged) // RHI only, [prepare step]
+{
+ QSGMaterialRhiShader *shader = sms->programRhi.program;
+ *gstateChanged = false;
+ if (shader->flags().testFlag(QSGMaterialRhiShader::UpdatesGraphicsPipelineState)) {
+ // generate the public mini-state from m_gstate, invoke the material,
+ // write the changes, if any, back to m_gstate, together with a way to
+ // roll those back.
+ QSGMaterialRhiShader::GraphicsPipelineState shaderPs;
+ rendererToMaterialGraphicsState(&shaderPs, &m_gstate);
+ const bool changed = shader->updateGraphicsPipelineState(renderState, &shaderPs, material, m_currentMaterial);
+ if (changed) {
+ m_gstateStack.push(m_gstate);
+ materialToRendererGraphicsState(&m_gstate, &shaderPs);
+ if (needsBlendConstant(m_gstate.srcColor) || needsBlendConstant(m_gstate.dstColor))
+ batch->blendConstant = shaderPs.blendConstant;
+ *gstateChanged = true;
+ }
+ }
+}
+
+bool Renderer::prepareRenderMergedBatch(Batch *batch, PreparedRenderBatch *renderBatch) // split prepare-render (RHI only)
{
+ if (batch->vertexCount == 0 || batch->indexCount == 0)
+ return false;
+
+ Element *e = batch->first;
+ Q_ASSERT(e);
+
+#ifndef QT_NO_DEBUG_OUTPUT
if (Q_UNLIKELY(debug_render())) {
- qDebug().nospace() << "Rendering:" << endl
- << " -> Opaque: " << qsg_countNodesInBatches(m_opaqueBatches) << " nodes in " << m_opaqueBatches.size() << " batches..." << endl
- << " -> Alpha: " << qsg_countNodesInBatches(m_alphaBatches) << " nodes in " << m_alphaBatches.size() << " batches...";
+ QDebug debug = qDebug();
+ debug << " -"
+ << batch
+ << (batch->uploadedThisFrame ? "[ upload]" : "[retained]")
+ << (e->node->clipList() ? "[ clip]" : "[noclip]")
+ << (batch->isOpaque ? "[opaque]" : "[ alpha]")
+ << "[ merged]"
+ << " Nodes:" << QString::fromLatin1("%1").arg(qsg_countNodesInBatch(batch), 4).toLatin1().constData()
+ << " Vertices:" << QString::fromLatin1("%1").arg(batch->vertexCount, 5).toLatin1().constData()
+ << " Indices:" << QString::fromLatin1("%1").arg(batch->indexCount, 5).toLatin1().constData()
+ << " root:" << batch->root;
+ if (batch->drawSets.size() > 1)
+ debug << "sets:" << batch->drawSets.size();
+ if (!batch->isOpaque)
+ debug << "opacity:" << e->node->inheritedOpacity();
+ batch->uploadedThisFrame = false;
}
+#endif
- QRect r = viewportRect();
- glViewport(r.x(), deviceRect().bottom() - r.bottom(), r.width(), r.height());
- glClearColor(clearColor().redF(), clearColor().greenF(), clearColor().blueF(), clearColor().alphaF());
+ QSGGeometryNode *gn = e->node;
- if (m_useDepthBuffer) {
- glClearDepthf(1); // calls glClearDepth() under the hood for desktop OpenGL
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LESS);
- glDepthMask(true);
- glDisable(GL_BLEND);
+ // We always have dirty matrix as all batches are at a unique z range.
+ QSGMaterialShader::RenderState::DirtyStates dirty = QSGMaterialShader::RenderState::DirtyMatrix;
+ if (batch->root)
+ m_current_model_view_matrix = qsg_matrixForRoot(batch->root);
+ else
+ m_current_model_view_matrix.setToIdentity();
+ m_current_determinant = m_current_model_view_matrix.determinant();
+ m_current_projection_matrix = projectionMatrix();
+ m_current_projection_matrix_native_ndc = projectionMatrixWithNativeNDC();
+
+ QSGMaterial *material = gn->activeMaterial();
+ updateClipState(gn->clipList(), batch);
+
+ const QSGGeometry *g = gn->geometry();
+ ShaderManager::Shader *sms = m_useDepthBuffer ? m_shaderManager->prepareMaterial(material, true, g)
+ : m_shaderManager->prepareMaterialNoRewrite(material, true, g);
+ if (!sms)
+ return false;
+
+ Q_ASSERT(sms->programRhi.program);
+ if (m_currentShader != sms)
+ setActiveRhiShader(sms->programRhi.program, sms);
+
+ m_current_opacity = gn->inheritedOpacity();
+ if (!qFuzzyCompare(sms->lastOpacity, float(m_current_opacity))) {
+ dirty |= QSGMaterialShader::RenderState::DirtyOpacity;
+ sms->lastOpacity = m_current_opacity;
+ }
+
+ QSGMaterialRhiShaderPrivate *pd = QSGMaterialRhiShaderPrivate::get(sms->programRhi.program);
+ const int ubufSize = pd->masterUniformData.size();
+ if (pd->ubufBinding >= 0) {
+ bool ubufRebuild = false;
+ if (!batch->ubuf) {
+ batch->ubuf = m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, ubufSize);
+ ubufRebuild = true;
+ } else {
+ if (batch->ubuf->size() < ubufSize) {
+ batch->ubuf->setSize(ubufSize);
+ ubufRebuild = true;
+ }
+ }
+ if (ubufRebuild) {
+ batch->ubufDataValid = false;
+ if (!batch->ubuf->build()) {
+ qWarning("Failed to build uniform buffer of size %d bytes", ubufSize);
+ delete batch->ubuf;
+ batch->ubuf = nullptr;
+ return false;
+ }
+ }
+ }
+
+ QSGMaterialRhiShader::RenderState renderState = rhiState(QSGMaterialRhiShader::RenderState::DirtyStates(int(dirty)));
+
+ bool pendingGStatePop = false;
+ updateMaterialStaticData(sms, renderState, material, batch, &pendingGStatePop);
+
+ ShaderManager::ShaderResourceBindingList bindings;
+ updateMaterialDynamicData(sms, renderState, material, &bindings, batch, 0, ubufSize);
+
+#ifndef QT_NO_DEBUG
+ if (qsg_test_and_clear_material_failure()) {
+ qDebug("QSGMaterial::updateState triggered an error (merged), batch will be skipped:");
+ Element *ee = e;
+ while (ee) {
+ qDebug() << " -" << ee->node;
+ ee = ee->nextInBatch;
+ }
+ QSGNodeDumper::dump(rootNode());
+ qFatal("Aborting: scene graph is invalid...");
+ }
+#endif
+
+ e->srb = m_shaderManager->srb(bindings);
+
+ m_gstate.drawMode = QSGGeometry::DrawingMode(g->drawingMode());
+ m_gstate.lineWidth = g->lineWidth();
+
+ const bool hasPipeline = ensurePipelineState(e, sms);
+
+ if (pendingGStatePop)
+ m_gstate = m_gstateStack.pop();
+
+ if (!hasPipeline)
+ return false;
+
+ batch->ubufDataValid = true;
+
+ m_currentMaterial = material;
+
+ renderBatch->batch = batch;
+ renderBatch->sms = sms;
+
+ return true;
+}
+
+void Renderer::checkLineWidth(QSGGeometry *g)
+{
+ if (g->drawingMode() == QSGGeometry::DrawLines || g->drawingMode() == QSGGeometry::DrawLineLoop
+ || g->drawingMode() == QSGGeometry::DrawLineStrip)
+ {
+ if (g->lineWidth() != 1.0f) {
+ static bool checkedWideLineSupport = false;
+ if (!checkedWideLineSupport) {
+ checkedWideLineSupport = true;
+ if (!m_rhi->isFeatureSupported(QRhi::WideLines))
+ qWarning("Line widths other than 1 are not supported by the graphics API");
+ }
+ }
+ } else if (g->drawingMode() == QSGGeometry::DrawPoints) {
+ if (g->lineWidth() != 1.0f) {
+ static bool warnedPointSize = false;
+ if (!warnedPointSize) {
+ warnedPointSize = true;
+ qWarning("Point size is not controllable by QSGGeometry. "
+ "Set gl_PointSize from the vertex shader instead.");
+ }
+ }
+ }
+}
+
+void Renderer::renderMergedBatch(PreparedRenderBatch *renderBatch) // split prepare-render (RHI only)
+{
+ const Batch *batch = renderBatch->batch;
+ Element *e = batch->first;
+ QSGGeometryNode *gn = e->node;
+ QSGGeometry *g = gn->geometry();
+ checkLineWidth(g);
+
+ if (batch->clipState.type & ClipState::StencilClip)
+ enqueueStencilDraw(batch);
+
+ QRhiCommandBuffer *cb = commandBuffer();
+ setGraphicsPipeline(cb, batch, e);
+
+ for (int i = 0, ie = batch->drawSets.size(); i != ie; ++i) {
+ const DrawSet &draw = batch->drawSets.at(i);
+ const QRhiCommandBuffer::VertexInput vbufBindings[] = {
+ { batch->vbo.buf, quint32(draw.vertices) },
+ { batch->vbo.buf, quint32(draw.zorders) }
+ };
+ cb->setVertexInput(VERTEX_BUFFER_BINDING, 2, vbufBindings,
+ batch->ibo.buf, draw.indices,
+ m_uint32IndexForRhi ? QRhiCommandBuffer::IndexUInt32 : QRhiCommandBuffer::IndexUInt16);
+ cb->drawIndexed(draw.indexCount);
+ }
+}
+
+bool Renderer::prepareRenderUnmergedBatch(Batch *batch, PreparedRenderBatch *renderBatch) // split prepare-render (RHI only)
+{
+ if (batch->vertexCount == 0)
+ return false;
+
+ Element *e = batch->first;
+ Q_ASSERT(e);
+
+ if (Q_UNLIKELY(debug_render())) {
+ qDebug() << " -"
+ << batch
+ << (batch->uploadedThisFrame ? "[ upload]" : "[retained]")
+ << (e->node->clipList() ? "[ clip]" : "[noclip]")
+ << (batch->isOpaque ? "[opaque]" : "[ alpha]")
+ << "[unmerged]"
+ << " Nodes:" << QString::fromLatin1("%1").arg(qsg_countNodesInBatch(batch), 4).toLatin1().constData()
+ << " Vertices:" << QString::fromLatin1("%1").arg(batch->vertexCount, 5).toLatin1().constData()
+ << " Indices:" << QString::fromLatin1("%1").arg(batch->indexCount, 5).toLatin1().constData()
+ << " root:" << batch->root;
+
+ batch->uploadedThisFrame = false;
+ }
+
+ m_current_projection_matrix = projectionMatrix();
+ m_current_projection_matrix_native_ndc = projectionMatrixWithNativeNDC();
+
+ QSGGeometryNode *gn = e->node;
+ updateClipState(gn->clipList(), batch);
+
+ // We always have dirty matrix as all batches are at a unique z range.
+ QSGMaterialShader::RenderState::DirtyStates dirty = QSGMaterialShader::RenderState::DirtyMatrix;
+
+ // The vertex attributes are assumed to be the same for all elements in the
+ // unmerged batch since the material (and so the shaders) is the same.
+ QSGGeometry *g = gn->geometry();
+ QSGMaterial *material = gn->activeMaterial();
+ ShaderManager::Shader *sms = m_shaderManager->prepareMaterialNoRewrite(material, m_rhi, g);
+ if (!sms)
+ return false;
+
+ Q_ASSERT(sms->programRhi.program);
+ if (m_currentShader != sms)
+ setActiveRhiShader(sms->programRhi.program, sms);
+
+ m_current_opacity = gn->inheritedOpacity();
+ if (sms->lastOpacity != m_current_opacity) {
+ dirty |= QSGMaterialShader::RenderState::DirtyOpacity;
+ sms->lastOpacity = m_current_opacity;
+ }
+
+ QMatrix4x4 rootMatrix = batch->root ? qsg_matrixForRoot(batch->root) : QMatrix4x4();
+
+ QSGMaterialRhiShaderPrivate *pd = QSGMaterialRhiShaderPrivate::get(sms->programRhi.program);
+ const int ubufSize = pd->masterUniformData.size();
+ if (pd->ubufBinding >= 0) {
+ int totalUBufSize = 0;
+ while (e) {
+ totalUBufSize += aligned(ubufSize, m_ubufAlignment);
+ e = e->nextInBatch;
+ }
+ bool ubufRebuild = false;
+ if (!batch->ubuf) {
+ batch->ubuf = m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, totalUBufSize);
+ ubufRebuild = true;
+ } else {
+ if (batch->ubuf->size() < totalUBufSize) {
+ batch->ubuf->setSize(totalUBufSize);
+ ubufRebuild = true;
+ }
+ }
+ if (ubufRebuild) {
+ batch->ubufDataValid = false;
+ if (!batch->ubuf->build()) {
+ qWarning("Failed to build uniform buffer of size %d bytes", totalUBufSize);
+ delete batch->ubuf;
+ batch->ubuf = nullptr;
+ return false;
+ }
+ }
+ }
+
+ QSGMaterialRhiShader::RenderState renderState = rhiState(QSGMaterialRhiShader::RenderState::DirtyStates(int(dirty)));
+ bool pendingGStatePop = false;
+ updateMaterialStaticData(sms, renderState,
+ material, batch, &pendingGStatePop);
+
+ int ubufOffset = 0;
+ QRhiGraphicsPipeline *ps = nullptr;
+ e = batch->first;
+ while (e) {
+ gn = e->node;
+
+ m_current_model_view_matrix = rootMatrix * *gn->matrix();
+ m_current_determinant = m_current_model_view_matrix.determinant();
+
+ m_current_projection_matrix = projectionMatrix();
+ m_current_projection_matrix_native_ndc = projectionMatrixWithNativeNDC();
+ if (m_useDepthBuffer) {
+ m_current_projection_matrix(2, 2) = m_zRange;
+ m_current_projection_matrix(2, 3) = 1.0f - e->order * m_zRange;
+ }
+
+ QSGMaterialRhiShader::RenderState renderState = rhiState(QSGMaterialRhiShader::RenderState::DirtyStates(int(dirty)));
+ ShaderManager::ShaderResourceBindingList bindings;
+ updateMaterialDynamicData(sms, renderState,
+ material, &bindings, batch, ubufOffset, ubufSize);
+
+#ifndef QT_NO_DEBUG
+ if (qsg_test_and_clear_material_failure()) {
+ qDebug("QSGMaterial::updateState() triggered an error (unmerged), batch will be skipped:");
+ qDebug() << " - offending node is" << e->node;
+ QSGNodeDumper::dump(rootNode());
+ qFatal("Aborting: scene graph is invalid...");
+ return false;
+ }
+#endif
+
+ e->srb = m_shaderManager->srb(bindings);
+
+ ubufOffset += aligned(ubufSize, m_ubufAlignment);
+
+ const QSGGeometry::DrawingMode prevDrawMode = m_gstate.drawMode;
+ const float prevLineWidth = m_gstate.lineWidth;
+ m_gstate.drawMode = QSGGeometry::DrawingMode(g->drawingMode());
+ m_gstate.lineWidth = g->lineWidth();
+
+ // Do not bother even looking up the ps if the topology has not changed
+ // since everything else is the same for all elements in the batch.
+ // (except if the material modified blend state)
+ if (!ps || m_gstate.drawMode != prevDrawMode || m_gstate.lineWidth != prevLineWidth || pendingGStatePop) {
+ if (!ensurePipelineState(e, sms)) {
+ if (pendingGStatePop)
+ m_gstate = m_gstateStack.pop();
+ return false;
+ }
+ ps = e->ps;
+ } else {
+ e->ps = ps;
+ }
+
+ // We don't need to bother with asking each node for its material as they
+ // are all identical (compare==0) since they are in the same batch.
+ m_currentMaterial = material;
+
+ // We only need to push this on the very first iteration...
+ dirty &= ~QSGMaterialShader::RenderState::DirtyOpacity;
+
+ e = e->nextInBatch;
+ }
+
+ if (pendingGStatePop)
+ m_gstate = m_gstateStack.pop();
+
+ batch->ubufDataValid = true;
+
+ renderBatch->batch = batch;
+ renderBatch->sms = sms;
+
+ return true;
+}
+
+void Renderer::renderUnmergedBatch(PreparedRenderBatch *renderBatch) // split prepare-render (RHI only)
+{
+ const Batch *batch = renderBatch->batch;
+ Element *e = batch->first;
+ QSGGeometryNode *gn = e->node;
+
+ if (batch->clipState.type & ClipState::StencilClip)
+ enqueueStencilDraw(batch);
+
+ int vOffset = 0;
+ int iOffset = 0;
+ QRhiCommandBuffer *cb = commandBuffer();
+
+ while (e) {
+ gn = e->node;
+ QSGGeometry *g = gn->geometry();
+ checkLineWidth(g);
+ const int effectiveIndexSize = m_uint32IndexForRhi ? sizeof(quint32) : g->sizeOfIndex();
+
+ setGraphicsPipeline(cb, batch, e);
+
+ const QRhiCommandBuffer::VertexInput vbufBinding(batch->vbo.buf, vOffset);
+ if (g->indexCount()) {
+ cb->setVertexInput(VERTEX_BUFFER_BINDING, 1, &vbufBinding,
+ batch->ibo.buf, iOffset,
+ effectiveIndexSize == sizeof(quint32) ? QRhiCommandBuffer::IndexUInt32
+ : QRhiCommandBuffer::IndexUInt16);
+ cb->drawIndexed(g->indexCount());
+ } else {
+ cb->setVertexInput(VERTEX_BUFFER_BINDING, 1, &vbufBinding);
+ cb->draw(g->vertexCount());
+ }
+
+ vOffset += g->sizeOfVertex() * g->vertexCount();
+ iOffset += g->indexCount() * effectiveIndexSize;
+
+ e = e->nextInBatch;
+ }
+}
+
+void Renderer::setGraphicsPipeline(QRhiCommandBuffer *cb, const Batch *batch, Element *e) // RHI only, [render step]
+{
+ cb->setGraphicsPipeline(e->ps);
+
+ if (!m_pstate.viewportSet) {
+ m_pstate.viewportSet = true;
+ cb->setViewport(m_pstate.viewport);
+ }
+ if (batch->clipState.type & ClipState::ScissorClip) {
+ Q_ASSERT(e->ps->flags().testFlag(QRhiGraphicsPipeline::UsesScissor));
+ m_pstate.scissorSet = true;
+ cb->setScissor(batch->clipState.scissor);
} else {
- glDisable(GL_DEPTH_TEST);
- glDepthMask(false);
+ Q_ASSERT(!e->ps->flags().testFlag(QRhiGraphicsPipeline::UsesScissor));
+ // Regardless of the ps not using scissor, the scissor may need to be
+ // reset, depending on the backend. So set the viewport again, which in
+ // turn also sets the scissor on backends where a scissor rect is
+ // always-on (Vulkan).
+ if (m_pstate.scissorSet) {
+ m_pstate.scissorSet = false;
+ cb->setViewport(m_pstate.viewport);
+ }
}
- glDisable(GL_CULL_FACE);
- glColorMask(true, true, true, true);
- glDisable(GL_SCISSOR_TEST);
- glDisable(GL_STENCIL_TEST);
+ if (batch->clipState.type & ClipState::StencilClip) {
+ Q_ASSERT(e->ps->flags().testFlag(QRhiGraphicsPipeline::UsesStencilRef));
+ cb->setStencilRef(batch->clipState.stencilRef);
+ }
+ if (e->ps->flags().testFlag(QRhiGraphicsPipeline::UsesBlendConstants))
+ cb->setBlendConstants(batch->blendConstant);
- bindable()->clear(clearMode());
+ cb->setShaderResources(e->srb);
+}
+
+void Renderer::renderBatches()
+{
+ if (Q_UNLIKELY(debug_render())) {
+ qDebug().nospace() << "Rendering:" << endl
+ << " -> Opaque: " << qsg_countNodesInBatches(m_opaqueBatches) << " nodes in " << m_opaqueBatches.size() << " batches..." << endl
+ << " -> Alpha: " << qsg_countNodesInBatches(m_alphaBatches) << " nodes in " << m_alphaBatches.size() << " batches...";
+ }
m_current_opacity = 1;
m_currentMaterial = nullptr;
m_currentShader = nullptr;
m_currentProgram = nullptr;
+ m_currentRhiProgram = nullptr;
m_currentClip = nullptr;
+ m_currentClipState.reset();
+
+ const QRect viewport = viewportRect();
bool renderOpaque = !debug_noopaque();
bool renderAlpha = !debug_noalpha();
- if (Q_LIKELY(renderOpaque)) {
- for (int i=0; i<m_opaqueBatches.size(); ++i) {
- Batch *b = m_opaqueBatches.at(i);
- if (b->merged)
- renderMergedBatch(b);
- else
- renderUnmergedBatch(b);
+ if (!m_rhi) {
+ // legacy, GL-only path
+
+ glViewport(viewport.x(), deviceRect().bottom() - viewport.bottom(), viewport.width(), viewport.height());
+ glClearColor(clearColor().redF(), clearColor().greenF(), clearColor().blueF(), clearColor().alphaF());
+
+ if (m_useDepthBuffer) {
+ glClearDepthf(1); // calls glClearDepth() under the hood for desktop OpenGL
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LESS);
+ glDepthMask(true);
+ glDisable(GL_BLEND);
+ } else {
+ glDisable(GL_DEPTH_TEST);
+ glDepthMask(false);
}
- }
+ glDisable(GL_CULL_FACE);
+ glColorMask(true, true, true, true);
+ glDisable(GL_SCISSOR_TEST);
+ glDisable(GL_STENCIL_TEST);
+
+ bindable()->clear(clearMode());
- glEnable(GL_BLEND);
- if (m_useDepthBuffer)
- glDepthMask(false);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ if (m_renderPassRecordingCallbacks.start)
+ m_renderPassRecordingCallbacks.start(m_renderPassRecordingCallbacks.userData);
- if (Q_LIKELY(renderAlpha)) {
- for (int i=0; i<m_alphaBatches.size(); ++i) {
- Batch *b = m_alphaBatches.at(i);
- if (b->merged)
- renderMergedBatch(b);
- else if (b->isRenderNode)
- renderRenderNode(b);
+ if (Q_LIKELY(renderOpaque)) {
+ for (int i=0; i<m_opaqueBatches.size(); ++i) {
+ Batch *b = m_opaqueBatches.at(i);
+ if (b->merged)
+ renderMergedBatch(b);
+ else
+ renderUnmergedBatch(b);
+ }
+ }
+
+ glEnable(GL_BLEND);
+ if (m_useDepthBuffer)
+ glDepthMask(false);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ if (Q_LIKELY(renderAlpha)) {
+ for (int i=0; i<m_alphaBatches.size(); ++i) {
+ Batch *b = m_alphaBatches.at(i);
+ if (b->merged)
+ renderMergedBatch(b);
+ else if (b->isRenderNode)
+ renderRenderNode(b);
+ else
+ renderUnmergedBatch(b);
+ }
+ }
+
+ if (m_currentShader)
+ setActiveShader(nullptr, nullptr);
+
+ updateStencilClip(nullptr);
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ glDepthMask(true);
+
+ if (m_renderPassRecordingCallbacks.end)
+ m_renderPassRecordingCallbacks.end(m_renderPassRecordingCallbacks.userData);
+
+ } else {
+ // RHI path
+
+ m_pstate.viewport = QRhiViewport(viewport.x(), deviceRect().bottom() - viewport.bottom(), viewport.width(), viewport.height());
+ m_pstate.clearColor = clearColor();
+ m_pstate.dsClear = QRhiDepthStencilClearValue(1.0f, 0);
+ m_pstate.viewportSet = false;
+ m_pstate.scissorSet = false;
+
+ m_gstate.depthTest = true;
+ m_gstate.depthWrite = true;
+ m_gstate.depthFunc = QRhiGraphicsPipeline::Less;
+ m_gstate.blending = false;
+
+ m_gstate.cullMode = QRhiGraphicsPipeline::None;
+ m_gstate.colorWrite = QRhiGraphicsPipeline::R
+ | QRhiGraphicsPipeline::G
+ | QRhiGraphicsPipeline::B
+ | QRhiGraphicsPipeline::A;
+ m_gstate.usesScissor = false;
+ m_gstate.stencilTest = false;
+
+ m_gstate.sampleCount = renderTarget()->sampleCount();
+
+ QVarLengthArray<PreparedRenderBatch, 64> opaqueRenderBatches;
+ if (Q_LIKELY(renderOpaque)) {
+ for (int i = 0, ie = m_opaqueBatches.size(); i != ie; ++i) {
+ Batch *b = m_opaqueBatches.at(i);
+ PreparedRenderBatch renderBatch;
+ bool ok;
+ if (b->merged)
+ ok = prepareRenderMergedBatch(b, &renderBatch);
+ else
+ ok = prepareRenderUnmergedBatch(b, &renderBatch);
+ if (ok)
+ opaqueRenderBatches.append(renderBatch);
+ }
+ }
+
+ m_gstate.blending = true;
+ // factors never change, always set for premultiplied alpha based blending
+
+ // depth test stays enabled but no need to write out depth from the
+ // transparent (back-to-front) pass
+ m_gstate.depthWrite = false;
+
+ QVarLengthArray<PreparedRenderBatch, 64> alphaRenderBatches;
+ if (Q_LIKELY(renderAlpha)) {
+ for (int i = 0, ie = m_alphaBatches.size(); i != ie; ++i) {
+ Batch *b = m_alphaBatches.at(i);
+ PreparedRenderBatch renderBatch;
+ bool ok;
+ if (b->merged)
+ ok = prepareRenderMergedBatch(b, &renderBatch);
+ else if (b->isRenderNode)
+ ok = prepareRhiRenderNode(b, &renderBatch);
+ else
+ ok = prepareRenderUnmergedBatch(b, &renderBatch);
+ if (ok)
+ alphaRenderBatches.append(renderBatch);
+ }
+ }
+
+ if (m_visualizer->mode() != Visualizer::VisualizeNothing)
+ m_visualizer->prepareVisualize();
+
+ QRhiCommandBuffer *cb = commandBuffer();
+ cb->beginPass(renderTarget(), m_pstate.clearColor, m_pstate.dsClear, m_resourceUpdates);
+ m_resourceUpdates = nullptr;
+
+ if (m_renderPassRecordingCallbacks.start)
+ m_renderPassRecordingCallbacks.start(m_renderPassRecordingCallbacks.userData);
+
+ for (int i = 0, ie = opaqueRenderBatches.count(); i != ie; ++i) {
+ PreparedRenderBatch *renderBatch = &opaqueRenderBatches[i];
+ if (renderBatch->batch->merged)
+ renderMergedBatch(renderBatch);
else
- renderUnmergedBatch(b);
+ renderUnmergedBatch(renderBatch);
}
- }
- if (m_currentShader)
- setActiveShader(nullptr, nullptr);
- updateStencilClip(nullptr);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- glDepthMask(true);
+ for (int i = 0, ie = alphaRenderBatches.count(); i != ie; ++i) {
+ PreparedRenderBatch *renderBatch = &alphaRenderBatches[i];
+ if (renderBatch->batch->merged)
+ renderMergedBatch(renderBatch);
+ else if (renderBatch->batch->isRenderNode)
+ renderRhiRenderNode(renderBatch->batch);
+ else
+ renderUnmergedBatch(renderBatch);
+ }
+
+ if (m_currentShader)
+ setActiveRhiShader(nullptr, nullptr);
+
+ if (m_renderPassRecordingCallbacks.end)
+ m_renderPassRecordingCallbacks.end(m_renderPassRecordingCallbacks.userData);
+
+ if (m_visualizer->mode() == Visualizer::VisualizeNothing)
+ cb->endPass();
+ }
}
void Renderer::deleteRemovedElements()
@@ -2588,8 +4170,6 @@ void Renderer::deleteRemovedElements()
void Renderer::render()
{
- Q_ASSERT(m_context->openglContext() == QOpenGLContext::currentContext());
-
if (Q_UNLIKELY(debug_dump())) {
qDebug("\n");
QSGNodeDumper::dump(rootNode());
@@ -2622,8 +4202,13 @@ void Renderer::render()
timer.start();
}
- if (m_vao)
- m_vao->bind();
+ if (!m_rhi) {
+ Q_ASSERT(m_context->openglContext() == QOpenGLContext::currentContext());
+ if (m_vao)
+ m_vao->bind();
+ } else {
+ m_resourceUpdates = m_rhi->nextResourceUpdateBatch();
+ }
if (m_rebuild & (BuildRenderLists | BuildRenderListsForTaggedRoots)) {
bool complete = (m_rebuild & BuildRenderLists) != 0;
@@ -2747,11 +4332,21 @@ void Renderer::render()
m_renderOrderRebuildLower = -1;
m_renderOrderRebuildUpper = -1;
- if (m_visualizeMode != VisualizeNothing)
- visualize();
+ if (m_visualizer->mode() != Visualizer::VisualizeNothing)
+ m_visualizer->visualize();
- if (m_vao)
- m_vao->release();
+ if (!m_rhi) {
+ if (m_vao)
+ m_vao->release();
+ } else {
+ if (m_visualizer->mode() != Visualizer::VisualizeNothing)
+ commandBuffer()->endPass();
+
+ if (m_resourceUpdates) {
+ m_resourceUpdates->release();
+ m_resourceUpdates = nullptr;
+ }
+ }
}
struct RenderNodeState : public QSGRenderNode::RenderState
@@ -2770,7 +4365,7 @@ struct RenderNodeState : public QSGRenderNode::RenderState
bool m_stencilEnabled;
};
-void Renderer::renderRenderNode(Batch *batch)
+void Renderer::renderRenderNode(Batch *batch) // legacy (GL-only)
{
if (Q_UNLIKELY(debug_render()))
qDebug() << " -" << batch << "rendernode";
@@ -2801,8 +4396,8 @@ void Renderer::renderRenderNode(Batch *batch)
RenderNodeState state;
state.m_projectionMatrix = &pm;
- state.m_scissorEnabled = m_currentClipType & ScissorClip;
- state.m_stencilEnabled = m_currentClipType & StencilClip;
+ state.m_scissorEnabled = m_currentClipType & ClipState::ScissorClip;
+ state.m_stencilEnabled = m_currentClipType & ClipState::StencilClip;
state.m_scissorRect = m_currentScissorRect;
state.m_stencilValue = m_currentStencilValue;
@@ -2863,7 +4458,7 @@ void Renderer::renderRenderNode(Batch *batch)
if (changes & (QSGRenderNode::StencilState | QSGRenderNode::ScissorState)) {
glDisable(GL_SCISSOR_TEST);
m_currentClip = nullptr;
- m_currentClipType = NoClip;
+ m_currentClipType = ClipState::NoClip;
}
if (changes & QSGRenderNode::DepthState)
@@ -2886,320 +4481,210 @@ void Renderer::renderRenderNode(Batch *batch)
glBindFramebuffer(GL_FRAMEBUFFER, prevFbo);
}
-void Renderer::releaseCachedResources()
+bool Renderer::prepareRhiRenderNode(Batch *batch, PreparedRenderBatch *renderBatch) // split prepare-render (RHI only)
{
- m_shaderManager->invalidated();
-}
+ if (Q_UNLIKELY(debug_render()))
+ qDebug() << " -" << batch << "rendernode";
-class VisualizeShader : public QOpenGLShaderProgram
-{
-public:
- int color;
- int matrix;
- int rotation;
- int pattern;
- int projection;
-};
+ Q_ASSERT(batch->first->isRenderNode);
+ RenderNodeElement *e = static_cast<RenderNodeElement *>(batch->first);
-void Renderer::visualizeDrawGeometry(const QSGGeometry *g)
-{
- if (g->attributeCount() < 1)
- return;
- const QSGGeometry::Attribute *a = g->attributes();
- glVertexAttribPointer(0, a->tupleSize, a->type, false, g->sizeOfVertex(), g->vertexData());
- if (g->indexCount())
- glDrawElements(g->drawingMode(), g->indexCount(), g->indexType(), g->indexData());
- else
- glDrawArrays(g->drawingMode(), 0, g->vertexCount());
+ setActiveRhiShader(nullptr, nullptr);
-}
+ QSGNode *clip = e->renderNode->parent();
+ QSGRenderNodePrivate *rd = QSGRenderNodePrivate::get(e->renderNode);
+ rd->m_clip_list = nullptr;
+ while (clip != rootNode()) {
+ if (clip->type() == QSGNode::ClipNodeType) {
+ rd->m_clip_list = static_cast<QSGClipNode *>(clip);
+ break;
+ }
+ clip = clip->parent();
+ }
-void Renderer::visualizeBatch(Batch *b)
-{
- VisualizeShader *shader = static_cast<VisualizeShader *>(m_shaderManager->visualizeProgram);
+ updateClipState(rd->m_clip_list, batch);
- if (b->positionAttribute != 0)
- return;
+ renderBatch->batch = batch;
+ renderBatch->sms = nullptr;
- QSGGeometryNode *gn = b->first->node;
- QSGGeometry *g = gn->geometry();
- const QSGGeometry::Attribute &a = g->attributes()[b->positionAttribute];
+ return true;
+}
- glBindBuffer(GL_ARRAY_BUFFER, b->vbo.id);
+void Renderer::renderRhiRenderNode(const Batch *batch) // split prepare-render (RHI only)
+{
+ if (batch->clipState.type & ClipState::StencilClip)
+ enqueueStencilDraw(batch);
- QMatrix4x4 matrix(m_current_projection_matrix);
- if (b->root)
- matrix = matrix * qsg_matrixForRoot(b->root);
+ RenderNodeElement *e = static_cast<RenderNodeElement *>(batch->first);
+ QSGRenderNodePrivate *rd = QSGRenderNodePrivate::get(e->renderNode);
- shader->setUniformValue(shader->pattern, float(b->merged ? 0 : 1));
+ QMatrix4x4 pm = projectionMatrix();
+ if (m_useDepthBuffer) {
+ pm(2, 2) = m_zRange;
+ pm(2, 3) = 1.0f - e->order * m_zRange;
+ }
- QColor color = QColor::fromHsvF((rand() & 1023) / 1023.0, 1.0, 1.0);
- float cr = color.redF();
- float cg = color.greenF();
- float cb = color.blueF();
- shader->setUniformValue(shader->color, cr, cg, cb, 1.0);
+ RenderNodeState state;
+ state.m_projectionMatrix = &pm;
+ const std::array<int, 4> scissor = batch->clipState.scissor.scissor();
+ state.m_scissorRect = QRect(scissor[0], scissor[1], scissor[2], scissor[3]);
+ state.m_stencilValue = batch->clipState.stencilRef;
+ state.m_scissorEnabled = batch->clipState.type & ClipState::ScissorClip;
+ state.m_stencilEnabled = batch->clipState.type & ClipState::StencilClip;
- if (b->merged) {
- shader->setUniformValue(shader->matrix, matrix);
- const auto &dataStart = m_context->separateIndexBuffer() ? b->ibo.data : b->vbo.data;
- for (int ds=0; ds<b->drawSets.size(); ++ds) {
- const DrawSet &set = b->drawSets.at(ds);
- glVertexAttribPointer(a.position, 2, a.type, false, g->sizeOfVertex(), (void *) (qintptr) (set.vertices));
- glDrawElements(g->drawingMode(), set.indexCount, GL_UNSIGNED_SHORT,
- (void *)(qintptr)(dataStart + set.indices));
+ QSGNode *xform = e->renderNode->parent();
+ QMatrix4x4 matrix;
+ QSGNode *root = rootNode();
+ if (e->root) {
+ matrix = qsg_matrixForRoot(e->root);
+ root = e->root->sgNode;
+ }
+ while (xform != root) {
+ if (xform->type() == QSGNode::TransformNodeType) {
+ matrix = matrix * static_cast<QSGTransformNode *>(xform)->combinedMatrix();
+ break;
}
- } else {
- Element *e = b->first;
- int offset = 0;
- while (e) {
- gn = e->node;
- g = gn->geometry();
- shader->setUniformValue(shader->matrix, matrix * *gn->matrix());
- glVertexAttribPointer(a.position, a.tupleSize, a.type, false, g->sizeOfVertex(), (void *) (qintptr) offset);
- if (g->indexCount())
- glDrawElements(g->drawingMode(), g->indexCount(), g->indexType(), g->indexData());
- else
- glDrawArrays(g->drawingMode(), 0, g->vertexCount());
- offset += g->sizeOfVertex() * g->vertexCount();
- e = e->nextInBatch;
+ xform = xform->parent();
+ }
+ rd->m_matrix = &matrix;
+
+ QSGNode *opacity = e->renderNode->parent();
+ rd->m_opacity = 1.0;
+ while (opacity != rootNode()) {
+ if (opacity->type() == QSGNode::OpacityNodeType) {
+ rd->m_opacity = static_cast<QSGOpacityNode *>(opacity)->combinedOpacity();
+ break;
}
+ opacity = opacity->parent();
}
-}
+ const QSGRenderNode::StateFlags changes = e->renderNode->changedStates();
+ QRhiCommandBuffer *cb = commandBuffer();
+ cb->beginExternal();
+ e->renderNode->render(&state);
+ cb->endExternal();
+ rd->m_matrix = nullptr;
+ rd->m_clip_list = nullptr;
-void Renderer::visualizeClipping(QSGNode *node)
-{
- if (node->type() == QSGNode::ClipNodeType) {
- VisualizeShader *shader = static_cast<VisualizeShader *>(m_shaderManager->visualizeProgram);
- QSGClipNode *clipNode = static_cast<QSGClipNode *>(node);
- QMatrix4x4 matrix = m_current_projection_matrix;
- if (clipNode->matrix())
- matrix = matrix * *clipNode->matrix();
- shader->setUniformValue(shader->matrix, matrix);
- visualizeDrawGeometry(clipNode->geometry());
+ if ((changes & QSGRenderNode::ViewportState)
+ || (changes & QSGRenderNode::ScissorState))
+ {
+ // Reset both flags if either is reported as changed, since with the rhi
+ // it could be setViewport() that will record the resetting of the scissor.
+ m_pstate.viewportSet = false;
+ m_pstate.scissorSet = false;
}
- QSGNODE_TRAVERSE(node) {
- visualizeClipping(child);
- }
+ // Do not bother with RenderTargetState. Where applicable, endExternal()
+ // ensures the correct target is rebound. For others (like Vulkan) it makes
+ // no sense since render() could not possibly do that on our command buffer
+ // which is in renderpass recording state.
}
-#define QSGNODE_DIRTY_PARENT (QSGNode::DirtyNodeAdded \
- | QSGNode::DirtyOpacity \
- | QSGNode::DirtyMatrix \
- | QSGNode::DirtyNodeRemoved)
-
-void Renderer::visualizeChangesPrepare(Node *n, uint parentChanges)
+void Renderer::setCustomRenderMode(const QByteArray &mode)
{
- uint childDirty = (parentChanges | n->dirtyState) & QSGNODE_DIRTY_PARENT;
- uint selfDirty = n->dirtyState | parentChanges;
- if (n->type() == QSGNode::GeometryNodeType && selfDirty != 0)
- m_visualizeChanceSet.insert(n, selfDirty);
- SHADOWNODE_TRAVERSE(n) {
- visualizeChangesPrepare(child, childDirty);
- }
+ if (mode.isEmpty())
+ m_visualizer->setMode(Visualizer::VisualizeNothing);
+ else if (mode == "clip")
+ m_visualizer->setMode(Visualizer::VisualizeClipping);
+ else if (mode == "overdraw")
+ m_visualizer->setMode(Visualizer::VisualizeOverdraw);
+ else if (mode == "batches")
+ m_visualizer->setMode(Visualizer::VisualizeBatches);
+ else if (mode == "changes")
+ m_visualizer->setMode(Visualizer::VisualizeChanges);
}
-void Renderer::visualizeChanges(Node *n)
+bool Renderer::hasCustomRenderModeWithContinuousUpdate() const
{
-
- if (n->type() == QSGNode::GeometryNodeType && n->element()->batch && m_visualizeChanceSet.contains(n)) {
- uint dirty = m_visualizeChanceSet.value(n);
- bool tinted = (dirty & QSGNODE_DIRTY_PARENT) != 0;
-
- VisualizeShader *shader = static_cast<VisualizeShader *>(m_shaderManager->visualizeProgram);
- QColor color = QColor::fromHsvF((rand() & 1023) / 1023.0, 0.3, 1.0);
- float ca = 0.5;
- float cr = color.redF() * ca;
- float cg = color.greenF() * ca;
- float cb = color.blueF() * ca;
- shader->setUniformValue(shader->color, cr, cg, cb, ca);
- shader->setUniformValue(shader->pattern, float(tinted ? 0.5 : 0));
-
- QSGGeometryNode *gn = static_cast<QSGGeometryNode *>(n->sgNode);
-
- QMatrix4x4 matrix = m_current_projection_matrix;
- if (n->element()->batch->root)
- matrix = matrix * qsg_matrixForRoot(n->element()->batch->root);
- matrix = matrix * *gn->matrix();
- shader->setUniformValue(shader->matrix, matrix);
- visualizeDrawGeometry(gn->geometry());
-
- // This is because many changes don't propegate their dirty state to the
- // parent so the node updater will not unset these states. They are
- // not used for anything so, unsetting it should have no side effects.
- n->dirtyState = nullptr;
- }
-
- SHADOWNODE_TRAVERSE(n) {
- visualizeChanges(child);
- }
+ return m_visualizer->mode() == Visualizer::VisualizeOverdraw;
}
-void Renderer::visualizeOverdraw_helper(Node *node)
+bool operator==(const GraphicsState &a, const GraphicsState &b) Q_DECL_NOTHROW
{
- if (node->type() == QSGNode::GeometryNodeType && node->element()->batch) {
- VisualizeShader *shader = static_cast<VisualizeShader *>(m_shaderManager->visualizeProgram);
- QSGGeometryNode *gn = static_cast<QSGGeometryNode *>(node->sgNode);
-
- QMatrix4x4 matrix = m_current_projection_matrix;
- matrix(2, 2) = m_zRange;
- matrix(2, 3) = 1.0f - node->element()->order * m_zRange;
-
- if (node->element()->batch->root)
- matrix = matrix * qsg_matrixForRoot(node->element()->batch->root);
- matrix = matrix * *gn->matrix();
- shader->setUniformValue(shader->matrix, matrix);
-
- QColor color = node->element()->batch->isOpaque ? QColor::fromRgbF(0.3, 1.0, 0.3) : QColor::fromRgbF(1.0, 0.3, 0.3);
- float ca = 0.33f;
- shader->setUniformValue(shader->color, color.redF() * ca, color.greenF() * ca, color.blueF() * ca, ca);
-
- visualizeDrawGeometry(gn->geometry());
- }
-
- SHADOWNODE_TRAVERSE(node) {
- visualizeOverdraw_helper(child);
- }
+ return a.depthTest == b.depthTest
+ && a.depthWrite == b.depthWrite
+ && a.depthFunc == b.depthFunc
+ && a.blending == b.blending
+ && a.srcColor == b.srcColor
+ && a.dstColor == b.dstColor
+ && a.colorWrite == b.colorWrite
+ && a.cullMode == b.cullMode
+ && a.usesScissor == b.usesScissor
+ && a.stencilTest == b.stencilTest
+ && a.sampleCount == b.sampleCount
+ && a.drawMode == b.drawMode
+ && a.lineWidth == b.lineWidth;
}
-void Renderer::visualizeOverdraw()
+bool operator!=(const GraphicsState &a, const GraphicsState &b) Q_DECL_NOTHROW
{
- VisualizeShader *shader = static_cast<VisualizeShader *>(m_shaderManager->visualizeProgram);
- shader->setUniformValue(shader->color, 0.5f, 0.5f, 1.0f, 1.0f);
- shader->setUniformValue(shader->projection, 1);
-
- glBlendFunc(GL_ONE, GL_ONE);
-
- static float step = 0;
- step += static_cast<float>(M_PI * 2 / 1000.);
- if (step > M_PI * 2)
- step = 0;
- float angle = 80.0 * std::sin(step);
-
- QMatrix4x4 xrot; xrot.rotate(20, 1, 0, 0);
- QMatrix4x4 zrot; zrot.rotate(angle, 0, 0, 1);
- QMatrix4x4 tx; tx.translate(0, 0, 1);
-
- QMatrix4x4 m;
-
-// m.rotate(180, 0, 1, 0);
-
- m.translate(0, 0.5, 4);
- m.scale(2, 2, 1);
-
- m.rotate(-30, 1, 0, 0);
- m.rotate(angle, 0, 1, 0);
- m.translate(0, 0, -1);
+ return !(a == b);
+}
- shader->setUniformValue(shader->rotation, m);
+uint qHash(const GraphicsState &s, uint seed) Q_DECL_NOTHROW
+{
+ // do not bother with all fields
+ return seed
+ + s.depthTest * 1000
+ + s.depthWrite * 100
+ + s.depthFunc
+ + s.blending * 10
+ + s.srcColor
+ + s.cullMode
+ + s.usesScissor
+ + s.stencilTest
+ + s.sampleCount;
+}
- float box[] = {
- // lower
- -1, 1, 0, 1, 1, 0,
- -1, 1, 0, -1, -1, 0,
- 1, 1, 0, 1, -1, 0,
- -1, -1, 0, 1, -1, 0,
+bool operator==(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) Q_DECL_NOTHROW
+{
+ return a.state == b.state
+ && a.sms->programRhi.program == b.sms->programRhi.program
+ && a.rpDesc == b.rpDesc
+ && a.layoutCompatibleSrb->isLayoutCompatible(b.layoutCompatibleSrb);
+}
- // upper
- -1, 1, 1, 1, 1, 1,
- -1, 1, 1, -1, -1, 1,
- 1, 1, 1, 1, -1, 1,
- -1, -1, 1, 1, -1, 1,
+bool operator!=(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) Q_DECL_NOTHROW
+{
+ return !(a == b);
+}
- // sides
- -1, -1, 0, -1, -1, 1,
- 1, -1, 0, 1, -1, 1,
- -1, 1, 0, -1, 1, 1,
- 1, 1, 0, 1, 1, 1
- };
- glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, box);
- glLineWidth(2);
- glDrawArrays(GL_LINES, 0, 24);
+uint qHash(const GraphicsPipelineStateKey &k, uint seed) Q_DECL_NOTHROW
+{
+ return qHash(k.state, seed) + qHash(k.sms->programRhi.program, seed) + qHash(k.rpDesc, seed);
+}
- visualizeOverdraw_helper(m_nodes.value(rootNode()));
+Visualizer::Visualizer(Renderer *renderer)
+ : m_renderer(renderer),
+ m_visualizeMode(VisualizeNothing)
+{
+}
- // Animate the view...
- QSurface *surface = m_context->openglContext()->surface();
- if (surface->surfaceClass() == QSurface::Window)
- if (QQuickWindow *window = qobject_cast<QQuickWindow *>(static_cast<QWindow *>(surface)))
- window->update();
+Visualizer::~Visualizer()
+{
}
-void Renderer::setCustomRenderMode(const QByteArray &mode)
+#define QSGNODE_DIRTY_PARENT (QSGNode::DirtyNodeAdded \
+ | QSGNode::DirtyOpacity \
+ | QSGNode::DirtyMatrix \
+ | QSGNode::DirtyNodeRemoved)
+
+void Visualizer::visualizeChangesPrepare(Node *n, uint parentChanges)
{
- if (mode.isEmpty()) m_visualizeMode = VisualizeNothing;
- else if (mode == "clip") m_visualizeMode = VisualizeClipping;
- else if (mode == "overdraw") m_visualizeMode = VisualizeOverdraw;
- else if (mode == "batches") m_visualizeMode = VisualizeBatches;
- else if (mode == "changes") m_visualizeMode = VisualizeChanges;
-}
-
-void Renderer::visualize()
-{
- if (!m_shaderManager->visualizeProgram) {
- VisualizeShader *prog = new VisualizeShader();
- QSGShaderSourceBuilder::initializeProgramFromFiles(
- prog,
- QStringLiteral(":/qt-project.org/scenegraph/shaders/visualization.vert"),
- QStringLiteral(":/qt-project.org/scenegraph/shaders/visualization.frag"));
- prog->bindAttributeLocation("v", 0);
- prog->link();
- prog->bind();
- prog->color = prog->uniformLocation("color");
- prog->pattern = prog->uniformLocation("pattern");
- prog->projection = prog->uniformLocation("projection");
- prog->matrix = prog->uniformLocation("matrix");
- prog->rotation = prog->uniformLocation("rotation");
- m_shaderManager->visualizeProgram = prog;
- } else {
- m_shaderManager->visualizeProgram->bind();
+ uint childDirty = (parentChanges | n->dirtyState) & QSGNODE_DIRTY_PARENT;
+ uint selfDirty = n->dirtyState | parentChanges;
+ if (n->type() == QSGNode::GeometryNodeType && selfDirty != 0)
+ m_visualizeChangeSet.insert(n, selfDirty);
+ SHADOWNODE_TRAVERSE(n) {
+ visualizeChangesPrepare(child, childDirty);
}
- VisualizeShader *shader = static_cast<VisualizeShader *>(m_shaderManager->visualizeProgram);
-
- glDisable(GL_DEPTH_TEST);
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- glEnableVertexAttribArray(0);
-
- // Blacken out the actual rendered content...
- float bgOpacity = 0.8f;
- if (m_visualizeMode == VisualizeBatches)
- bgOpacity = 1.0;
- float v[] = { -1, 1, 1, 1, -1, -1, 1, -1 };
- shader->setUniformValue(shader->color, 0.0f, 0.0f, 0.0f, bgOpacity);
- shader->setUniformValue(shader->matrix, QMatrix4x4());
- shader->setUniformValue(shader->rotation, QMatrix4x4());
- shader->setUniformValue(shader->pattern, 0.0f);
- shader->setUniformValue(shader->projection, false);
- glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, v);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- if (m_visualizeMode == VisualizeBatches) {
- srand(0); // To force random colors to be roughly the same every time..
- for (int i=0; i<m_opaqueBatches.size(); ++i) visualizeBatch(m_opaqueBatches.at(i));
- for (int i=0; i<m_alphaBatches.size(); ++i) visualizeBatch(m_alphaBatches.at(i));
- } else if (m_visualizeMode == VisualizeClipping) {
- shader->setUniformValue(shader->pattern, 0.5f);
- shader->setUniformValue(shader->color, 0.2f, 0.0f, 0.0f, 0.2f);
- visualizeClipping(rootNode());
- } else if (m_visualizeMode == VisualizeChanges) {
- visualizeChanges(m_nodes.value(rootNode()));
- m_visualizeChanceSet.clear();
- } else if (m_visualizeMode == VisualizeOverdraw) {
- visualizeOverdraw();
- }
-
- // Reset state back to defaults..
- glDisable(GL_BLEND);
- glDisableVertexAttribArray(0);
- shader->release();
}
-QT_END_NAMESPACE
+} // namespace QSGBatchRenderer
-}
+QT_END_NAMESPACE
#include "moc_qsgbatchrenderer_p.cpp"
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
index 12b48c1451..297df2232a 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
@@ -58,11 +58,14 @@
#include <private/qsgnodeupdater_p.h>
#include <private/qsgrendernode_p.h>
#include <private/qdatabuffer_p.h>
+#include <private/qsgtexture_p.h>
#include <QtCore/QBitArray>
-
+#include <QtCore/QStack>
#include <QtGui/QOpenGLFunctions>
+#include <QtGui/private/qrhi_p.h>
+
QT_BEGIN_NAMESPACE
class QOpenGLVertexArrayObject;
@@ -300,10 +303,11 @@ struct Buffer {
// Data is only valid while preparing the upload. Exception is if we are using the
// broken IBO workaround or we are using a visualization mode.
char *data;
+ QRhiBuffer *buf;
+ uint nonDynamicChangeCount;
};
struct Element {
-
Element()
: boundsComputed(false)
, boundsOutsideFloatRange(false)
@@ -334,6 +338,8 @@ struct Element {
Rect bounds; // in device coordinates
int order = 0;
+ QRhiShaderResourceBindings *srb = nullptr;
+ QRhiGraphicsPipeline *ps = nullptr;
uint boundsComputed : 1;
uint boundsOutsideFloatRange : 1;
@@ -390,6 +396,48 @@ enum BatchCompatibility
BatchIsCompatible
};
+struct ClipState
+{
+ enum ClipTypeBit
+ {
+ NoClip = 0x00,
+ ScissorClip = 0x01,
+ StencilClip = 0x02
+ };
+ Q_DECLARE_FLAGS(ClipType, ClipTypeBit)
+
+ const QSGClipNode *clipList;
+ ClipType type;
+ QRhiScissor scissor;
+ int stencilRef;
+
+ inline void reset();
+};
+
+struct StencilClipState
+{
+ StencilClipState() : drawCalls(1) { }
+
+ bool updateStencilBuffer = false;
+ QRhiShaderResourceBindings *srb = nullptr;
+ QRhiBuffer *vbuf = nullptr;
+ QRhiBuffer *ibuf = nullptr;
+ QRhiBuffer *ubuf = nullptr;
+
+ struct StencilDrawCall {
+ int stencilRef;
+ int vertexCount;
+ int indexCount;
+ QRhiCommandBuffer::IndexFormat indexFormat;
+ quint32 vbufOffset;
+ quint32 ibufOffset;
+ quint32 ubufOffset;
+ };
+ QDataBuffer<StencilDrawCall> drawCalls;
+
+ inline void reset();
+};
+
struct Batch
{
Batch() : drawSets(1) {}
@@ -403,6 +451,7 @@ struct Batch
// pseudo-constructor...
void init() {
+ // Only non-reusable members are reset here. See Renderer::newBatch().
first = nullptr;
root = nullptr;
vertexCount = 0;
@@ -413,6 +462,9 @@ struct Batch
positionAttribute = -1;
uploadedThisFrame = false;
isRenderNode = false;
+ ubufDataValid = false;
+ clipState.reset();
+ blendConstant = QColor();
}
Element *first;
@@ -429,16 +481,21 @@ struct Batch
uint needsUpload : 1;
uint merged : 1;
uint isRenderNode : 1;
+ uint ubufDataValid : 1;
mutable uint uploadedThisFrame : 1; // solely for debugging purposes
Buffer vbo;
Buffer ibo;
+ QRhiBuffer *ubuf;
+ ClipState clipState;
+ StencilClipState stencilClipState;
+ QColor blendConstant;
QDataBuffer<DrawSet> drawSets;
};
-// NOTE: Node is zero-allocated by the Allocator.
+// NOTE: Node is zero-initialized by the Allocator.
struct Node
{
QSGNode *sgNode;
@@ -574,28 +631,41 @@ class ShaderManager : public QObject
Q_OBJECT
public:
struct Shader {
- ~Shader() { delete program; }
- int id_zRange;
- int pos_order;
- QSGMaterialShader *program;
+ ~Shader() {
+ delete programRhi.program;
+ delete programGL.program;
+ }
+ struct {
+ QSGMaterialShader *program = nullptr;
+ int pos_order;
+ } programGL;
+ struct {
+ QSGMaterialRhiShader *program = nullptr;
+ QRhiVertexInputLayout inputLayout;
+ QVarLengthArray<QRhiGraphicsShaderStage, 2> shaderStages;
+ } programRhi;
float lastOpacity;
};
- ShaderManager(QSGDefaultRenderContext *ctx) : visualizeProgram(nullptr), blitProgram(nullptr), context(ctx) { }
+ ShaderManager(QSGDefaultRenderContext *ctx) : blitProgram(nullptr), context(ctx) { }
~ShaderManager() {
qDeleteAll(rewrittenShaders);
qDeleteAll(stockShaders);
}
+ void clearCachedRendererData();
+
+ using ShaderResourceBindingList = QVarLengthArray<QRhiShaderResourceBinding, 8>;
+
+ QRhiShaderResourceBindings *srb(const ShaderResourceBindingList &bindings);
+
public Q_SLOTS:
void invalidated();
public:
- Shader *prepareMaterial(QSGMaterial *material);
- Shader *prepareMaterialNoRewrite(QSGMaterial *material);
-
- QOpenGLShaderProgram *visualizeProgram;
+ Shader *prepareMaterial(QSGMaterial *material, bool enableRhiShaders = false, const QSGGeometry *geometry = nullptr);
+ Shader *prepareMaterialNoRewrite(QSGMaterial *material, bool enableRhiShaders = false, const QSGGeometry *geometry = nullptr);
private:
QHash<QSGMaterialType *, Shader *> rewrittenShaders;
@@ -603,14 +673,55 @@ private:
QOpenGLShaderProgram *blitProgram;
QSGDefaultRenderContext *context;
+
+ QHash<ShaderResourceBindingList, QRhiShaderResourceBindings *> srbCache;
};
-class Q_QUICK_PRIVATE_EXPORT Renderer : public QSGRenderer, public QOpenGLFunctions
+struct GraphicsState
{
-public:
- Renderer(QSGDefaultRenderContext *);
- ~Renderer();
+ bool depthTest = false;
+ bool depthWrite = false;
+ QRhiGraphicsPipeline::CompareOp depthFunc = QRhiGraphicsPipeline::Less;
+ bool blending = false;
+ QRhiGraphicsPipeline::BlendFactor srcColor = QRhiGraphicsPipeline::One;
+ QRhiGraphicsPipeline::BlendFactor dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
+ QRhiGraphicsPipeline::ColorMask colorWrite = QRhiGraphicsPipeline::ColorMask(0xF);
+ QRhiGraphicsPipeline::CullMode cullMode = QRhiGraphicsPipeline::None;
+ bool usesScissor = false;
+ bool stencilTest = false;
+ int sampleCount = 1;
+ QSGGeometry::DrawingMode drawMode = QSGGeometry::DrawTriangles;
+ float lineWidth = 1.0f;
+};
+
+bool operator==(const GraphicsState &a, const GraphicsState &b) Q_DECL_NOTHROW;
+bool operator!=(const GraphicsState &a, const GraphicsState &b) Q_DECL_NOTHROW;
+uint qHash(const GraphicsState &s, uint seed = 0) Q_DECL_NOTHROW;
+
+struct GraphicsPipelineStateKey
+{
+ GraphicsState state;
+ const ShaderManager::Shader *sms;
+ const QRhiRenderPassDescriptor *rpDesc;
+ const QRhiShaderResourceBindings *layoutCompatibleSrb;
+};
+
+bool operator==(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) Q_DECL_NOTHROW;
+bool operator!=(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) Q_DECL_NOTHROW;
+uint qHash(const GraphicsPipelineStateKey &k, uint seed = 0) Q_DECL_NOTHROW;
+
+struct RenderPassState
+{
+ QRhiViewport viewport;
+ QColor clearColor;
+ QRhiDepthStencilClearValue dsClear;
+ bool viewportSet;
+ bool scissorSet;
+};
+class Visualizer
+{
+public:
enum VisualizeMode {
VisualizeNothing,
VisualizeBatches,
@@ -619,20 +730,36 @@ public:
VisualizeOverdraw
};
+ Visualizer(Renderer *renderer);
+ virtual ~Visualizer();
+
+ VisualizeMode mode() const { return m_visualizeMode; }
+ void setMode(VisualizeMode mode) { m_visualizeMode = mode; }
+
+ virtual void visualizeChangesPrepare(Node *n, uint parentChanges = 0);
+ virtual void prepareVisualize() = 0;
+ virtual void visualize() = 0;
+
+ virtual void releaseResources() = 0;
+
+protected:
+ Renderer *m_renderer;
+ VisualizeMode m_visualizeMode;
+ QHash<Node *, uint> m_visualizeChangeSet;
+};
+
+class Q_QUICK_PRIVATE_EXPORT Renderer : public QSGRenderer, public QOpenGLFunctions
+{
+public:
+ Renderer(QSGDefaultRenderContext *);
+ ~Renderer();
+
protected:
void nodeChanged(QSGNode *node, QSGNode::DirtyState state) override;
void render() override;
void releaseCachedResources() override;
private:
- enum ClipTypeBit
- {
- NoClip = 0x00,
- ScissorClip = 0x01,
- StencilClip = 0x02
- };
- Q_DECLARE_FLAGS(ClipType, ClipTypeBit)
-
enum RebuildFlag {
BuildRenderListsForTaggedRoots = 0x0001,
BuildRenderLists = 0x0002,
@@ -641,7 +768,10 @@ private:
};
friend class Updater;
+ friend class OpenGLVisualizer;
+ friend class RhiVisualizer;
+ void destroyGraphicsResources();
void map(Buffer *buffer, int size, bool isIndexBuf = false);
void unmap(Buffer *buffer, bool isIndexBuf = false);
@@ -658,16 +788,41 @@ private:
void invalidateBatchAndOverlappingRenderOrders(Batch *batch);
void uploadBatch(Batch *b);
- void uploadMergedElement(Element *e, int vaOffset, char **vertexData, char **zData, char **indexData, quint16 *iBase, int *indexCount);
+ void uploadMergedElement(Element *e, int vaOffset, char **vertexData, char **zData, char **indexData, void *iBasePtr, int *indexCount);
+
+ struct PreparedRenderBatch {
+ const Batch *batch;
+ ShaderManager::Shader *sms;
+ };
void renderBatches();
- void renderMergedBatch(const Batch *batch);
- void renderUnmergedBatch(const Batch *batch);
- ClipType updateStencilClip(const QSGClipNode *clip);
+ bool ensurePipelineState(Element *e, const ShaderManager::Shader *sms);
+ QRhiTexture *dummyTexture();
+ void updateMaterialDynamicData(ShaderManager::Shader *sms, QSGMaterialRhiShader::RenderState &renderState,
+ QSGMaterial *material, ShaderManager::ShaderResourceBindingList *bindings,
+ const Batch *batch, int ubufOffset, int ubufRegionSize);
+ void updateMaterialStaticData(ShaderManager::Shader *sms, QSGMaterialRhiShader::RenderState &renderState,
+ QSGMaterial *material, Batch *batch, bool *gstateChanged);
+ void checkLineWidth(QSGGeometry *g);
+ bool prepareRenderMergedBatch(Batch *batch, PreparedRenderBatch *renderBatch);
+ void renderMergedBatch(PreparedRenderBatch *renderBatch);
+ bool prepareRenderUnmergedBatch(Batch *batch, PreparedRenderBatch *renderBatch);
+ void renderUnmergedBatch(PreparedRenderBatch *renderBatch);
+ void setGraphicsPipeline(QRhiCommandBuffer *cb, const Batch *batch, Element *e);
+ void renderMergedBatch(const Batch *batch); // GL
+ void renderUnmergedBatch(const Batch *batch); // GL
+ ClipState::ClipType updateStencilClip(const QSGClipNode *clip);
void updateClip(const QSGClipNode *clipList, const Batch *batch);
+ void applyClipStateToGraphicsState();
+ QRhiGraphicsPipeline *buildStencilPipeline(const Batch *batch, bool firstStencilClipInBatch);
+ void updateClipState(const QSGClipNode *clipList, Batch *batch);
+ void enqueueStencilDraw(const Batch *batch);
const QMatrix4x4 &matrixForRoot(Node *node);
void renderRenderNode(Batch *batch);
+ bool prepareRhiRenderNode(Batch *batch, PreparedRenderBatch *renderBatch);
+ void renderRhiRenderNode(const Batch *batch);
void setActiveShader(QSGMaterialShader *program, ShaderManager::Shader *shader);
+ void setActiveRhiShader(QSGMaterialRhiShader *program, ShaderManager::Shader *shader);
bool changeBatchRoot(Node *node, Node *newRoot);
void registerBatchRoot(Node *childRoot, Node *parentRoot);
@@ -683,15 +838,8 @@ private:
inline Batch *newBatch();
void invalidateAndRecycleBatch(Batch *b);
- void visualize();
- void visualizeBatch(Batch *b);
- void visualizeClipping(QSGNode *node);
- void visualizeChangesPrepare(Node *n, uint parentChanges = 0);
- void visualizeChanges(Node *n);
- void visualizeOverdraw();
- void visualizeOverdraw_helper(Node *node);
- void visualizeDrawGeometry(const QSGGeometry *g);
void setCustomRenderMode(const QByteArray &mode) override;
+ bool hasCustomRenderModeWithContinuousUpdate() const override;
QSGDefaultRenderContext *m_context;
QSet<Node *> m_taggedRoots;
@@ -722,29 +870,54 @@ private:
int m_batchNodeThreshold;
int m_batchVertexThreshold;
+ Visualizer *m_visualizer;
+
// Stuff used during rendering only...
- ShaderManager *m_shaderManager;
+ ShaderManager *m_shaderManager; // per rendercontext, shared
QSGMaterial *m_currentMaterial;
QSGMaterialShader *m_currentProgram;
+ QSGMaterialRhiShader *m_currentRhiProgram;
ShaderManager::Shader *m_currentShader;
+ ClipState m_currentClipState;
+ // *** legacy (GL) only
QRect m_currentScissorRect;
int m_currentStencilValue;
QOpenGLShaderProgram m_clipProgram;
int m_clipMatrixId;
const QSGClipNode *m_currentClip;
- ClipType m_currentClipType;
+ ClipState::ClipType m_currentClipType;
+ // ***
QDataBuffer<char> m_vertexUploadPool;
QDataBuffer<char> m_indexUploadPool;
// For minimal OpenGL core profile support
QOpenGLVertexArrayObject *m_vao;
- QHash<Node *, uint> m_visualizeChanceSet;
- VisualizeMode m_visualizeMode;
-
Allocator<Node, 256> m_nodeAllocator;
Allocator<Element, 64> m_elementAllocator;
+
+ QRhiResourceUpdateBatch *m_resourceUpdates = nullptr;
+ uint m_ubufAlignment;
+ bool m_uint32IndexForRhi;
+ GraphicsState m_gstate;
+ RenderPassState m_pstate;
+ QStack<GraphicsState> m_gstateStack;
+ QHash<GraphicsPipelineStateKey, QRhiGraphicsPipeline *> m_pipelines;
+ QHash<QSGSamplerDescription, QRhiSampler *> m_samplers;
+ QRhiTexture *m_dummyTexture = nullptr;
+
+ struct StencilClipCommonData {
+ QRhiGraphicsPipeline *replacePs = nullptr;
+ QRhiGraphicsPipeline *incrPs = nullptr;
+ QShader vs;
+ QShader fs;
+ QRhiVertexInputLayout inputLayout;
+ QRhiGraphicsPipeline::Topology topology;
+ inline void reset();
+ } m_stencilClipCommon;
+
+ inline int mergedIndexElemSize() const;
};
Batch *Renderer::newBatch()
@@ -753,18 +926,69 @@ Batch *Renderer::newBatch()
int size = m_batchPool.size();
if (size) {
b = m_batchPool.at(size - 1);
+ // vbo, ibo, ubuf, stencil-related buffers are reused
m_batchPool.resize(size - 1);
} else {
b = new Batch();
Q_ASSERT(offsetof(Batch, ibo) == sizeof(Buffer) + offsetof(Batch, vbo));
memset(&b->vbo, 0, sizeof(Buffer) * 2); // Clear VBO & IBO
+ b->ubuf = nullptr;
+ b->stencilClipState.reset();
}
+ // initialize (when new batch) or reset (when reusing a batch) the non-reusable fields
b->init();
return b;
}
+int Renderer::mergedIndexElemSize() const
+{
+ return m_uint32IndexForRhi ? sizeof(quint32) : sizeof(quint16);
+}
+
+void Renderer::StencilClipCommonData::reset()
+{
+ delete replacePs;
+ replacePs = nullptr;
+
+ delete incrPs;
+ incrPs = nullptr;
+
+ vs = QShader();
+ fs = QShader();
+}
+
+void ClipState::reset()
+{
+ clipList = nullptr;
+ type = NoClip;
+ stencilRef = 0;
+}
+
+void StencilClipState::reset()
+{
+ updateStencilBuffer = false;
+
+ delete srb;
+ srb = nullptr;
+
+ delete vbuf;
+ vbuf = nullptr;
+
+ delete ibuf;
+ ibuf = nullptr;
+
+ delete ubuf;
+ ubuf = nullptr;
+
+ drawCalls.reset();
}
+}
+
+Q_DECLARE_TYPEINFO(QSGBatchRenderer::GraphicsState, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QSGBatchRenderer::GraphicsPipelineStateKey, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QSGBatchRenderer::RenderPassState, Q_MOVABLE_TYPE);
+
QT_END_NAMESPACE
#endif // QSGBATCHRENDERER_P_H
diff --git a/src/quick/scenegraph/coreapi/qsggeometry.cpp b/src/quick/scenegraph/coreapi/qsggeometry.cpp
index dd701fba5f..a28eee5288 100644
--- a/src/quick/scenegraph/coreapi/qsggeometry.cpp
+++ b/src/quick/scenegraph/coreapi/qsggeometry.cpp
@@ -443,6 +443,7 @@ QSGGeometry::QSGGeometry(const QSGGeometry::AttributeSet &attributes,
Q_ASSERT(m_attributes.stride > 0);
#if QT_CONFIG(opengl)
Q_ASSERT_X(indexType != GL_UNSIGNED_INT
+ || !QOpenGLContext::currentContext() // rhi, support for uint cannot be checked here
|| static_cast<QOpenGLExtensions *>(QOpenGLContext::currentContext()->functions())
->hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint),
"QSGGeometry::QSGGeometry",
@@ -575,6 +576,10 @@ const void *QSGGeometry::indexData() const
\value IntType
\value UnsignedIntType
\value FloatType
+ \value Bytes2Type Added in Qt 5.14.
+ \value Bytes3Type Added in Qt 5.14.
+ \value Bytes4Type Added in Qt 5.14.
+ \value DoubleType Added in Qt 5.14.
*/
/*!
diff --git a/src/quick/scenegraph/coreapi/qsggeometry.h b/src/quick/scenegraph/coreapi/qsggeometry.h
index 7a916610e3..d17915a842 100644
--- a/src/quick/scenegraph/coreapi/qsggeometry.h
+++ b/src/quick/scenegraph/coreapi/qsggeometry.h
@@ -88,7 +88,11 @@ public:
UnsignedShortType = 0x1403,
IntType = 0x1404,
UnsignedIntType = 0x1405,
- FloatType = 0x1406
+ FloatType = 0x1406,
+ Bytes2Type = 0x1407,
+ Bytes3Type = 0x1408,
+ Bytes4Type = 0x1409,
+ DoubleType = 0x140A
};
struct Q_QUICK_EXPORT Attribute
diff --git a/src/quick/scenegraph/coreapi/qsgmaterial.cpp b/src/quick/scenegraph/coreapi/qsgmaterial.cpp
index 8557de1b1f..c8ae26311b 100644
--- a/src/quick/scenegraph/coreapi/qsgmaterial.cpp
+++ b/src/quick/scenegraph/coreapi/qsgmaterial.cpp
@@ -39,14 +39,6 @@
#include "qsgmaterial.h"
#include "qsgrenderer_p.h"
-#include "qsgmaterialshader_p.h"
-#if QT_CONFIG(opengl)
-# include <private/qsgshadersourcebuilder_p.h>
-# include <private/qsgdefaultcontext_p.h>
-# include <private/qsgdefaultrendercontext_p.h>
-# include <QtGui/QOpenGLFunctions>
-# include <QtGui/QOpenGLContext>
-#endif
QT_BEGIN_NAMESPACE
@@ -64,17 +56,6 @@ void qsg_set_material_failure()
qsg_material_failure = true;
}
#endif
-#if QT_CONFIG(opengl)
-const char *QSGMaterialShaderPrivate::loadShaderSource(QOpenGLShader::ShaderType type) const
-{
- const QStringList files = m_sourceFiles[type];
- QSGShaderSourceBuilder builder;
- for (const QString &file : files)
- builder.appendSourceFile(file);
- m_sources[type] = builder.source();
- return m_sources[type].constData();
-}
-#endif
#ifndef QT_NO_DEBUG
static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK");
@@ -89,494 +70,6 @@ static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK"
\l {scene graph}{Qt Quick Scene Graph}.
*/
-/*!
- \class QSGMaterialShader
- \brief The QSGMaterialShader class represents an OpenGL shader program
- in the renderer.
- \inmodule QtQuick
- \ingroup qtquick-scenegraph-materials
-
- The QSGMaterialShader API is very low-level. A more convenient API, which
- provides almost all the same features, is available through
- QSGSimpleMaterialShader.
-
- The QSGMaterial and QSGMaterialShader form a tight relationship. For one
- scene graph (including nested graphs), there is one unique QSGMaterialShader
- instance which encapsulates the QOpenGLShaderProgram the scene graph uses
- to render that material, such as a shader to flat coloring of geometry.
- Each QSGGeometryNode can have a unique QSGMaterial containing the
- how the shader should be configured when drawing that node, such as
- the actual color used to render the geometry.
-
- An instance of QSGMaterialShader is never created explicitly by the user,
- it will be created on demand by the scene graph through
- QSGMaterial::createShader(). The scene graph will make sure that there
- is only one instance of each shader implementation through a scene graph.
-
- The source code returned from vertexShader() is used to control what the
- material does with the vertiex data that comes in from the geometry.
- The source code returned from the fragmentShader() is used to control
- what how the material should fill each individual pixel in the geometry.
- The vertex and fragment source code is queried once during initialization,
- changing what is returned from these functions later will not have
- any effect.
-
- The activate() function is called by the scene graph when a shader is
- is starting to be used. The deactivate function is called by the scene
- graph when the shader is no longer going to be used. While active,
- the scene graph may make one or more calls to updateState() which
- will update the state of the shader for each individual geometry to
- render.
-
- The attributeNames() returns the name of the attributes used in the
- vertexShader(). These are used in the default implementation of
- activate() and deactivate() to decide whice vertex registers are enabled.
-
- The initialize() function is called during program creation to allow
- subclasses to prepare for use, such as resolve uniform names in the
- vertexShader() and fragmentShader().
-
- A minimal example:
- \code
- class Shader : public QSGMaterialShader
- {
- public:
- const char *vertexShader() const {
- return
- "attribute highp vec4 vertex; \n"
- "uniform highp mat4 matrix; \n"
- "void main() { \n"
- " gl_Position = matrix * vertex; \n"
- "}";
- }
-
- const char *fragmentShader() const {
- return
- "uniform lowp float opacity; \n"
- "void main() { \n"
- " gl_FragColor = vec4(1, 0, 0, 1) * opacity; \n"
- "}";
- }
-
- char const *const *attributeNames() const
- {
- static char const *const names[] = { "vertex", 0 };
- return names;
- }
-
- void initialize()
- {
- QSGMaterialShader::initialize();
- m_id_matrix = program()->uniformLocation("matrix");
- m_id_opacity = program()->uniformLocation("opacity");
- }
-
- void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
- {
- Q_ASSERT(program()->isLinked());
- if (state.isMatrixDirty())
- program()->setUniformValue(m_id_matrix, state.combinedMatrix());
- if (state.isOpacityDirty())
- program()->setUniformValue(m_id_opacity, state.opacity());
- }
-
- private:
- int m_id_matrix;
- int m_id_opacity;
- };
- \endcode
-
- \note All classes with QSG prefix should be used solely on the scene graph's
- rendering thread. See \l {Scene Graph and Rendering} for more information.
-
- */
-
-
-
-/*!
- Creates a new QSGMaterialShader.
- */
-QSGMaterialShader::QSGMaterialShader()
- : d_ptr(new QSGMaterialShaderPrivate)
-{
-}
-
-/*!
- \internal
- */
-QSGMaterialShader::QSGMaterialShader(QSGMaterialShaderPrivate &dd)
- : d_ptr(&dd)
-{
-}
-
-/*!
- \internal
- */
-QSGMaterialShader::~QSGMaterialShader()
-{
-}
-
-/*!
- \fn char const *const *QSGMaterialShader::attributeNames() const
-
- Returns a zero-terminated array describing the names of the
- attributes used in the vertex shader.
-
- This function is called when the shader is compiled to specify
- which attributes exist. The order of the attribute names
- defines the attribute register position in the vertex shader.
- */
-
-#if QT_CONFIG(opengl)
-/*!
- \fn const char *QSGMaterialShader::vertexShader() const
-
- Called when the shader is being initialized to get the vertex
- shader source code.
-
- The contents returned from this function should never change.
-*/
-const char *QSGMaterialShader::vertexShader() const
-{
- Q_D(const QSGMaterialShader);
- return d->loadShaderSource(QOpenGLShader::Vertex);
-}
-
-
-/*!
- \fn const char *QSGMaterialShader::fragmentShader() const
-
- Called when the shader is being initialized to get the fragment
- shader source code.
-
- The contents returned from this function should never change.
-*/
-const char *QSGMaterialShader::fragmentShader() const
-{
- Q_D(const QSGMaterialShader);
- return d->loadShaderSource(QOpenGLShader::Fragment);
-}
-
-
-/*!
- \fn QOpenGLShaderProgram *QSGMaterialShader::program()
-
- Returns the shader program used by this QSGMaterialShader.
- */
-#endif
-
-/*!
- \fn void QSGMaterialShader::initialize()
-
- Reimplement this function to do one-time initialization when the
- shader program is compiled. The OpenGL shader program is compiled
- and linked, but not bound, when this function is called.
- */
-
-
-/*!
- This function is called by the scene graph to indicate that geometry is
- about to be rendered using this shader.
-
- State that is global for all uses of the shader, independent of the geometry
- that is being drawn, can be setup in this function.
- */
-
-void QSGMaterialShader::activate()
-{
-}
-
-
-
-/*!
- This function is called by the scene graph to indicate that geometry will
- no longer to be rendered using this shader.
- */
-
-void QSGMaterialShader::deactivate()
-{
-}
-
-
-
-/*!
- This function is called by the scene graph before geometry is rendered
- to make sure the shader is in the right state.
-
- The current rendering \a state is passed from the scene graph. If the state
- indicates that any state is dirty, the updateState implementation must
- update accordingly for the geometry to render correctly.
-
- The subclass specific state, such as the color of a flat color material, should
- be extracted from \a newMaterial to update the color uniforms accordingly.
-
- The \a oldMaterial can be used to minimze state changes when updating
- material states. The \a oldMaterial is 0 if this shader was just activated.
-
- \sa activate(), deactivate()
- */
-
-void QSGMaterialShader::updateState(const RenderState & /* state */, QSGMaterial * /* newMaterial */, QSGMaterial * /* oldMaterial */)
-{
-}
-
-#if QT_CONFIG(opengl)
-/*!
- Sets the GLSL source file for the shader stage \a type to \a sourceFile. The
- default implementation of the vertexShader() and fragmentShader() functions
- will load the source files set by this function.
-
- This function is useful when you have a single source file for a given shader
- stage. If your shader consists of multiple source files then use
- setShaderSourceFiles()
-
- \sa setShaderSourceFiles(), vertexShader(), fragmentShader()
- */
-void QSGMaterialShader::setShaderSourceFile(QOpenGLShader::ShaderType type, const QString &sourceFile)
-{
- Q_D(QSGMaterialShader);
- d->m_sourceFiles[type] = (QStringList() << sourceFile);
-}
-
-/*!
- Sets the GLSL source files for the shader stage \a type to \a sourceFiles. The
- default implementation of the vertexShader() and fragmentShader() functions
- will load the source files set by this function in the order given.
-
- \sa setShaderSourceFile(), vertexShader(), fragmentShader()
- */
-void QSGMaterialShader::setShaderSourceFiles(QOpenGLShader::ShaderType type, const QStringList &sourceFiles)
-{
- Q_D(QSGMaterialShader);
- d->m_sourceFiles[type] = sourceFiles;
-}
-
-/*!
- This function is called when the shader is initialized to compile the
- actual QOpenGLShaderProgram. Do not call it explicitly.
-
- The default implementation will extract the vertexShader() and
- fragmentShader() and bind the names returned from attributeNames()
- to consecutive vertex attribute registers starting at 0.
- */
-
-void QSGMaterialShader::compile()
-{
- Q_ASSERT_X(!m_program.isLinked(), "QSGSMaterialShader::compile()", "Compile called multiple times!");
-
- program()->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexShader());
- program()->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShader());
-
- char const *const *attr = attributeNames();
-#ifndef QT_NO_DEBUG
- int maxVertexAttribs = 0;
- QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
- funcs->glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
- for (int i = 0; attr[i]; ++i) {
- if (i >= maxVertexAttribs) {
- qFatal("List of attribute names is either too long or not null-terminated.\n"
- "Maximum number of attributes on this hardware is %i.\n"
- "Vertex shader:\n%s\n"
- "Fragment shader:\n%s\n",
- maxVertexAttribs, vertexShader(), fragmentShader());
- }
- if (*attr[i])
- program()->bindAttributeLocation(attr[i], i);
- }
-#else
- for (int i = 0; attr[i]; ++i) {
- if (*attr[i])
- program()->bindAttributeLocation(attr[i], i);
- }
-#endif
-
- if (!program()->link()) {
- qWarning("QSGMaterialShader: Shader compilation failed:");
- qWarning() << program()->log();
- }
-}
-
-#endif
-
-/*!
- \class QSGMaterialShader::RenderState
- \brief The QSGMaterialShader::RenderState encapsulates the current rendering state
- during a call to QSGMaterialShader::updateState().
- \inmodule QtQuick
-
- The render state contains a number of accessors that the shader needs to respect
- in order to conform to the current state of the scene graph.
-
- The instance is only valid inside a call to QSGMaterialShader::updateState() and
- should not be used outisde this function.
- */
-
-
-
-/*!
- \enum QSGMaterialShader::RenderState::DirtyState
-
- \value DirtyMatrix Used to indicate that the matrix has changed and must be updated.
-
- \value DirtyOpacity Used to indicate that the opacity has changed and must be updated.
-
- \value DirtyCachedMaterialData Used to indicate that the cached material data have changed and must be updated.
-
- \value DirtyAll Used to indicate that everything needs to be updated.
- */
-
-
-
-/*!
- \fn bool QSGMaterialShader::RenderState::isMatrixDirty() const
-
- Returns \c true if the dirtyStates() contain the dirty matrix state,
- otherwise returns \c false.
- */
-
-
-
-/*!
- \fn bool QSGMaterialShader::RenderState::isOpacityDirty() const
-
- Returns \c true if the dirtyStates() contains the dirty opacity state,
- otherwise returns \c false.
- */
-
-/*!
- \fn bool QSGMaterialShader::RenderState::isCachedMaterialDataDirty() const
-
- Returns \c true if the dirtyStates() contains the dirty cached material state,
- otherwise returns \c false.
- */
-
-/*!
- \fn QSGMaterialShader::RenderState::DirtyStates QSGMaterialShader::RenderState::dirtyStates() const
-
- Returns which rendering states that have changed and needs to be updated
- for geometry rendered with this material to conform to the current
- rendering state.
- */
-
-
-
-/*!
- Returns the accumulated opacity to be used for rendering.
- */
-
-float QSGMaterialShader::RenderState::opacity() const
-{
- Q_ASSERT(m_data);
- return static_cast<const QSGRenderer *>(m_data)->currentOpacity();
-}
-
-/*!
- Returns the modelview determinant to be used for rendering.
- */
-
-float QSGMaterialShader::RenderState::determinant() const
-{
- Q_ASSERT(m_data);
- return static_cast<const QSGRenderer *>(m_data)->determinant();
-}
-
-/*!
- Returns the matrix combined of modelview matrix and project matrix.
- */
-
-QMatrix4x4 QSGMaterialShader::RenderState::combinedMatrix() const
-{
- Q_ASSERT(m_data);
- return static_cast<const QSGRenderer *>(m_data)->currentCombinedMatrix();
-}
-/*!
- Returns the ratio between physical pixels and device-independent pixels
- to be used for rendering.
-*/
-float QSGMaterialShader::RenderState::devicePixelRatio() const
-{
- Q_ASSERT(m_data);
- return static_cast<const QSGRenderer *>(m_data)->devicePixelRatio();
-}
-
-
-
-/*!
- Returns the model view matrix.
-
- If the material has the RequiresFullMatrix flag
- set, this is guaranteed to be the complete transform
- matrix calculated from the scenegraph.
-
- However, if this flag is not set, the renderer may
- choose to alter this matrix. For example, it may
- pre-transform vertices on the CPU and set this matrix
- to identity.
-
- In a situation such as the above, it is still possible
- to retrieve the actual matrix determinant by setting
- the RequiresDeterminant flag in the material and
- calling the determinant() accessor.
- */
-
-QMatrix4x4 QSGMaterialShader::RenderState::modelViewMatrix() const
-{
- Q_ASSERT(m_data);
- return static_cast<const QSGRenderer *>(m_data)->currentModelViewMatrix();
-}
-
-/*!
- Returns the projection matrix.
- */
-
-QMatrix4x4 QSGMaterialShader::RenderState::projectionMatrix() const
-{
- Q_ASSERT(m_data);
- return static_cast<const QSGRenderer *>(m_data)->currentProjectionMatrix();
-}
-
-
-
-/*!
- Returns the viewport rect of the surface being rendered to.
- */
-
-QRect QSGMaterialShader::RenderState::viewportRect() const
-{
- Q_ASSERT(m_data);
- return static_cast<const QSGRenderer *>(m_data)->viewportRect();
-}
-
-
-
-/*!
- Returns the device rect of the surface being rendered to
- */
-
-QRect QSGMaterialShader::RenderState::deviceRect() const
-{
- Q_ASSERT(m_data);
- return static_cast<const QSGRenderer *>(m_data)->deviceRect();
-}
-
-#if QT_CONFIG(opengl)
-
-/*!
- Returns the QOpenGLContext that is being used for rendering
- */
-
-QOpenGLContext *QSGMaterialShader::RenderState::context() const
-{
- // Only the QSGDefaultRenderContext will have an OpenGL Context to query
- auto openGLRenderContext = static_cast<const QSGDefaultRenderContext *>(static_cast<const QSGRenderer *>(m_data)->context());
- if (openGLRenderContext != nullptr)
- return openGLRenderContext->openglContext();
- else
- return nullptr;
-}
-
-#endif
-
#ifndef QT_NO_DEBUG
static int qt_material_count = 0;
@@ -605,22 +98,20 @@ static void qt_print_material_count()
\inmodule QtQuick
\ingroup qtquick-scenegraph-materials
- The QSGMaterial API is very low-level. A more convenient API, which
- provides almost all the same features, is available through
- QSGSimpleMaterialShader.
-
- The QSGMaterial and QSGMaterialShader subclasses form a tight relationship. For
- one scene graph (including nested graphs), there is one unique QSGMaterialShader
- instance which encapsulates the QOpenGLShaderProgram the scene graph uses
- to render that material, such as a shader to flat coloring of geometry.
- Each QSGGeometryNode can have a unique QSGMaterial containing the
- how the shader should be configured when drawing that node, such as
- the actual color to used to render the geometry.
-
- The QSGMaterial has two virtual functions that both need to be implemented.
- The function type() should return a unique instance for all instances of a
+ The QSGMaterial, QSGMaterialShader and QSGMaterialRhiShader subclasses
+ form a tight relationship. For one scene graph (including nested graphs),
+ there is one unique QSGMaterialShader or QSGMaterialRhiShader instance
+ which encapsulates the shaders the scene graph uses to render that
+ material, such as a shader to flat coloring of geometry. Each
+ QSGGeometryNode can have a unique QSGMaterial containing the how the shader
+ should be configured when drawing that node, such as the actual color to
+ used to render the geometry.
+
+ QSGMaterial has two virtual functions that both need to be implemented. The
+ function type() should return a unique instance for all instances of a
specific subclass. The createShader() function should return a new instance
- of QSGMaterialShader, specific to the subclass of QSGMaterial.
+ of QSGMaterialShader or QSGMaterialRhiShader, specific to that subclass of
+ QSGMaterial.
A minimal QSGMaterial implementation could look like this:
\code
@@ -632,6 +123,27 @@ static void qt_print_material_count()
};
\endcode
+ This is suitable only for the OpenGL-based, traditional renderer of the
+ scene graph. When using the new, graphics API abstracted renderer,
+ materials must create QSGMaterialRhiShader instances instead, or in
+ addition:
+ \code
+ class Material : public QSGMaterial
+ {
+ public:
+ Material() { setFlag(SupportsRhiShader, true); }
+ QSGMaterialType *type() const { static QSGMaterialType type; return &type; }
+ QSGMaterialShader *createShader() {
+ if (flags().testFlag(RhiShaderWanted)) {
+ return new RhiShader;
+ } else {
+ // this is optional, relevant for materials that intend to be usable with the legacy OpenGL renderer as well
+ return new Shader;
+ }
+ }
+ };
+ \endcode
+
\note All classes with QSG prefix should be used solely on the scene graph's
rendering thread. See \l {Scene Graph and Rendering} for more information.
*/
@@ -693,6 +205,16 @@ QSGMaterial::~QSGMaterial()
QSGMaterialShader::compile() when its shader program is compiled and linked.
Set this flag to enforce that the function is called.
+ \value SupportsRhiShader Starting with Qt 5.14, the scene graph supports
+ QSGMaterialRhiShader as an alternative to the OpenGL-specific
+ QSGMaterialShader. Set this flag to indicate createShader() is capable of
+ returning QSGMaterialRhiShader instances when the RhiShaderWanted flag is
+ set.
+
+ \value RhiShaderWanted This flag is set by the scene graph, not by the
+ QSGMaterial. When set, and that can only happen when SupportsRhiShader was
+ set by the material, it indicates that createShader() must return a
+ QSGMaterialRhiShader instance instead of QSGMaterialShader.
*/
/*!
@@ -757,7 +279,11 @@ int QSGMaterial::compare(const QSGMaterial *other) const
The function will be called only once for each material type that
exists in the scene graph and will be cached internally.
-*/
+ When the QSGMaterial reports SupportsRhiShader in flags(), the scene graph
+ may request a QSGMaterialRhiShader instead of QSGMaterialShader. This is
+ indicated by having the RhiShaderWanted flag set. In this case the return
+ value must be a QSGRhiMaterialShader subclass.
+*/
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/coreapi/qsgmaterial.h b/src/quick/scenegraph/coreapi/qsgmaterial.h
index c002cd5d5e..cb6e9a456a 100644
--- a/src/quick/scenegraph/coreapi/qsgmaterial.h
+++ b/src/quick/scenegraph/coreapi/qsgmaterial.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -41,95 +41,12 @@
#define QSGMATERIAL_H
#include <QtQuick/qtquickglobal.h>
-#if QT_CONFIG(opengl)
-# include <QtGui/qopenglshaderprogram.h>
-#endif
-#include <QtGui/QMatrix4x4>
-#include <QtCore/QRect>
+#include <QtQuick/qsgmaterialshader.h>
+#include <QtQuick/qsgmaterialrhishader.h>
+#include <QtQuick/qsgmaterialtype.h>
QT_BEGIN_NAMESPACE
-class QSGMaterial;
-class QSGMaterialShaderPrivate;
-
-namespace QSGBatchRenderer {
- class ShaderManager;
-}
-
-class Q_QUICK_EXPORT QSGMaterialShader
-{
-public:
- class Q_QUICK_EXPORT RenderState {
- public:
- enum DirtyState
- {
- DirtyMatrix = 0x0001,
- DirtyOpacity = 0x0002,
- DirtyCachedMaterialData = 0x0004,
- DirtyAll = 0xFFFF
- };
- Q_DECLARE_FLAGS(DirtyStates, DirtyState)
-
- inline DirtyStates dirtyStates() const { return m_dirty; }
-
- inline bool isMatrixDirty() const { return m_dirty & DirtyMatrix; }
- inline bool isOpacityDirty() const { return m_dirty & DirtyOpacity; }
- bool isCachedMaterialDataDirty() const { return m_dirty & DirtyCachedMaterialData; }
-
- float opacity() const;
- QMatrix4x4 combinedMatrix() const;
- QMatrix4x4 modelViewMatrix() const;
- QMatrix4x4 projectionMatrix() const;
- QRect viewportRect() const;
- QRect deviceRect() const;
- float determinant() const;
- float devicePixelRatio() const;
-#if QT_CONFIG(opengl)
- QOpenGLContext *context() const;
-#endif
- private:
- friend class QSGRenderer;
- DirtyStates m_dirty;
- const void *m_data;
- };
-
- QSGMaterialShader();
- virtual ~QSGMaterialShader();
-
- virtual void activate();
- virtual void deactivate();
- // First time a material is used, oldMaterial is null.
- virtual void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
- virtual char const *const *attributeNames() const = 0; // Array must end with null.
-#if QT_CONFIG(opengl)
- inline QOpenGLShaderProgram *program() { return &m_program; }
-#endif
-protected:
- Q_DECLARE_PRIVATE(QSGMaterialShader)
- QSGMaterialShader(QSGMaterialShaderPrivate &dd);
-
- friend class QSGDefaultRenderContext;
- friend class QSGBatchRenderer::ShaderManager;
-#if QT_CONFIG(opengl)
- void setShaderSourceFile(QOpenGLShader::ShaderType type, const QString &sourceFile);
- void setShaderSourceFiles(QOpenGLShader::ShaderType type, const QStringList &sourceFiles);
-
- virtual void compile();
-#endif
- virtual void initialize() { }
-#if QT_CONFIG(opengl)
- virtual const char *vertexShader() const;
- virtual const char *fragmentShader() const;
-#endif
-private:
-#if QT_CONFIG(opengl)
- QOpenGLShaderProgram m_program;
-#endif
- QScopedPointer<QSGMaterialShaderPrivate> d_ptr;
-};
-
-struct QSGMaterialType { };
-
class Q_QUICK_EXPORT QSGMaterial
{
public:
@@ -139,7 +56,11 @@ public:
RequiresFullMatrixExceptTranslate = 0x0004 | RequiresDeterminant, // Allow precalculated translation
RequiresFullMatrix = 0x0008 | RequiresFullMatrixExceptTranslate,
- CustomCompileStep = 0x0010
+ CustomCompileStep = 0x0010,
+
+ SupportsRhiShader = 0x0020,
+
+ RhiShaderWanted = 0x1000 // // ### Qt 6: remove
};
Q_DECLARE_FLAGS(Flags, Flag)
@@ -160,7 +81,6 @@ private:
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterial::Flags)
-Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialShader::RenderState::DirtyStates)
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/coreapi/qsgmaterialrhishader.cpp b/src/quick/scenegraph/coreapi/qsgmaterialrhishader.cpp
new file mode 100644
index 0000000000..117d477f9a
--- /dev/null
+++ b/src/quick/scenegraph/coreapi/qsgmaterialrhishader.cpp
@@ -0,0 +1,630 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgmaterial.h"
+#include "qsgrenderer_p.h"
+#include "qsgmaterialrhishader_p.h"
+#include <QtCore/QFile>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QSGMaterialRhiShader
+ \brief The QSGMaterialRhiShader class represents a graphics API independent shader program.
+ \inmodule QtQuick
+ \ingroup qtquick-scenegraph-materials
+ \since 5.14
+
+ QSGMaterialRhiShader is a modern, cross-platform alternative to
+ QSGMaterialShader. The latter is tied to OpenGL and GLSL by design, whereas
+ QSGMaterialRhiShader is based on QShader, a container for multiple
+ versions of a graphics shader together with reflection information.
+
+ \note All classes with QSG prefix should be used solely on the scene graph's
+ rendering thread. See \l {Scene Graph and Rendering} for more information.
+ */
+
+/*!
+ \enum QSGMaterialRhiShader::Flag
+ Flag values to indicate special material properties.
+
+ \value UpdatesGraphicsPipelineState Setting this flag enables calling
+ updateGraphicsPipelineState().
+ */
+
+QShader QSGMaterialRhiShaderPrivate::loadShader(const QString &filename)
+{
+ QFile f(filename);
+ if (!f.open(QIODevice::ReadOnly)) {
+ qWarning() << "Failed to find shader" << filename;
+ return QShader();
+ }
+ return QShader::fromSerialized(f.readAll());
+}
+
+void QSGMaterialRhiShaderPrivate::clearCachedRendererData()
+{
+ for (int i = 0; i < MAX_SHADER_RESOURCE_BINDINGS; ++i)
+ textureBindingTable[i] = nullptr;
+ for (int i = 0; i < MAX_SHADER_RESOURCE_BINDINGS; ++i)
+ samplerBindingTable[i] = nullptr;
+}
+
+static inline QRhiShaderResourceBinding::StageFlags toSrbStage(QShader::Stage stage)
+{
+ switch (stage) {
+ case QShader::VertexStage:
+ return QRhiShaderResourceBinding::VertexStage;
+ case QShader::FragmentStage:
+ return QRhiShaderResourceBinding::FragmentStage;
+ default:
+ Q_UNREACHABLE();
+ break;
+ }
+ return 0;
+}
+
+void QSGMaterialRhiShaderPrivate::prepare(QShader::Variant vertexShaderVariant)
+{
+ ubufBinding = -1;
+ ubufSize = 0;
+ ubufStages = 0;
+ memset(combinedImageSamplerBindings, 0, sizeof(combinedImageSamplerBindings));
+ vertexShader = fragmentShader = nullptr;
+ masterUniformData.clear();
+
+ clearCachedRendererData();
+
+ for (QShader::Stage stage : { QShader::VertexStage, QShader::FragmentStage }) {
+ auto it = shaderFileNames.find(stage);
+ if (it != shaderFileNames.end()) {
+ QString fn = *it;
+ const QShader s = loadShader(*it);
+ if (!s.isValid())
+ continue;
+ shaders[stage] = ShaderStageData(s);
+ // load only once, subsequent prepare() calls will have it all in shaders already
+ shaderFileNames.erase(it);
+ }
+ }
+
+ auto vsIt = shaders.find(QShader::VertexStage);
+ if (vsIt != shaders.end()) {
+ vsIt->shaderVariant = vertexShaderVariant;
+ vsIt->vertexInputLocations.clear();
+ vsIt->qt_order_attrib_location = -1;
+
+ const QShaderDescription desc = vsIt->shader.description();
+ const QVector<QShaderDescription::InOutVariable> vertexInputs = desc.inputVariables();
+ for (const QShaderDescription::InOutVariable &v : vertexInputs) {
+ const QByteArray name = v.name.toUtf8();
+ if (vertexShaderVariant == QShader::BatchableVertexShader
+ && name == QByteArrayLiteral("_qt_order"))
+ {
+ vsIt->qt_order_attrib_location = v.location;
+ } else {
+ vsIt->vertexInputLocations.append(v.location);
+ }
+ }
+
+ if (vsIt->vertexInputLocations.contains(vsIt->qt_order_attrib_location)) {
+ qWarning("Vertex input clash in rewritten (batchable) vertex shader at input location %d. "
+ "Vertex shaders must avoid using this location.", vsIt->qt_order_attrib_location);
+ }
+ }
+
+ for (auto it = shaders.begin(); it != shaders.end(); ++it) {
+ const QShaderDescription desc = it->shader.description();
+
+ const QVector<QShaderDescription::UniformBlock> ubufs = desc.uniformBlocks();
+ const int ubufCount = ubufs.count();
+ if (ubufCount > 1) {
+ qWarning("Multiple uniform blocks found in shader. "
+ "This should be avoided as Qt Quick supports only one.");
+ }
+ for (int i = 0; i < ubufCount; ++i) {
+ const QShaderDescription::UniformBlock &ubuf(ubufs[i]);
+ if (ubufBinding == -1 && ubuf.binding >= 0) {
+ ubufBinding = ubuf.binding;
+ ubufSize = ubuf.size;
+ ubufStages |= toSrbStage(it->shader.stage());
+ masterUniformData.fill('\0', ubufSize);
+ } else if (ubufBinding == ubuf.binding && ubuf.binding >= 0) {
+ if (ubuf.size > ubufSize) {
+ ubufSize = ubuf.size;
+ masterUniformData.fill('\0', ubufSize);
+ }
+ ubufStages |= toSrbStage(it->shader.stage());
+ } else {
+ qWarning("Uniform block %s (binding %d) ignored", qPrintable(ubuf.blockName), ubuf.binding);
+ }
+ }
+
+ const QVector<QShaderDescription::InOutVariable> imageSamplers = desc.combinedImageSamplers();
+ const int imageSamplersCount = imageSamplers.count();
+ for (int i = 0; i < imageSamplersCount; ++i) {
+ const QShaderDescription::InOutVariable &var(imageSamplers[i]);
+ if (var.binding >= 0 && var.binding < MAX_SHADER_RESOURCE_BINDINGS)
+ combinedImageSamplerBindings[var.binding] |= toSrbStage(it->shader.stage());
+ else
+ qWarning("Encountered invalid combined image sampler (%s) binding %d",
+ qPrintable(var.name), var.binding);
+ }
+
+ if (it.key() == QShader::VertexStage)
+ vertexShader = &it.value();
+ else if (it.key() == QShader::FragmentStage)
+ fragmentShader = &it.value();
+ }
+
+ if (vertexShader && vertexShaderVariant == QShader::BatchableVertexShader && vertexShader->qt_order_attrib_location == -1)
+ qWarning("No rewriter-inserted attribute found, this should not happen.");
+}
+
+/*!
+ Constructs a new QSGMaterialRhiShader.
+ */
+QSGMaterialRhiShader::QSGMaterialRhiShader()
+ : d_ptr(new QSGMaterialRhiShaderPrivate(this))
+{
+}
+
+/*!
+ \internal
+ */
+QSGMaterialRhiShader::QSGMaterialRhiShader(QSGMaterialRhiShaderPrivate &dd)
+ : d_ptr(&dd)
+{
+}
+
+/*!
+ \internal
+ */
+QSGMaterialRhiShader::~QSGMaterialRhiShader()
+{
+}
+
+// We have our own enum as QShader is not initially public. Internally
+// everything works with QShader::Stage however. So convert.
+static inline QShader::Stage toShaderStage(QSGMaterialRhiShader::Stage stage)
+{
+ switch (stage) {
+ case QSGMaterialRhiShader::VertexStage:
+ return QShader::VertexStage;
+ case QSGMaterialRhiShader::FragmentStage:
+ return QShader::FragmentStage;
+ default:
+ Q_UNREACHABLE();
+ return QShader::VertexStage;
+ }
+}
+
+/*!
+ Sets the \a shader for the specified \a stage.
+ */
+void QSGMaterialRhiShader::setShader(Stage stage, const QShader &shader)
+{
+ Q_D(QSGMaterialRhiShader);
+ d->shaders[toShaderStage(stage)] = QSGMaterialRhiShaderPrivate::ShaderStageData(shader);
+}
+
+/*!
+ Sets the \a filename for the shader for the specified \a stage.
+
+ The file is expected to contain a serialized QRhiShader.
+ */
+void QSGMaterialRhiShader::setShaderFileName(Stage stage, const QString &filename)
+{
+ Q_D(QSGMaterialRhiShader);
+ d->shaderFileNames[toShaderStage(stage)] = filename;
+}
+
+/*!
+ \return the currently set flags for this material shader.
+ */
+QSGMaterialRhiShader::Flags QSGMaterialRhiShader::flags() const
+{
+ Q_D(const QSGMaterialRhiShader);
+ return d->flags;
+}
+
+/*!
+ Sets the \a flags on this material shader if \a on is true;
+ otherwise clears the specified flags.
+*/
+void QSGMaterialRhiShader::setFlag(Flags flags, bool on)
+{
+ Q_D(QSGMaterialRhiShader);
+ if (on)
+ d->flags |= flags;
+ else
+ d->flags &= ~flags;
+}
+
+/*!
+ This function is called by the scene graph to get the contents of the
+ shader program's uniform buffer updated. The implementation is not expected
+ to perform any real graphics operations, it is merely responsible for
+ copying data to the QByteArray returned from RenderState::uniformData().
+ The scene graph takes care of making that buffer visible in the shaders.
+
+ The current rendering \a state is passed from the scene graph. If the state
+ indicates that any relevant state is dirty, the implementation must update
+ the appropriate region in the buffer data that is accessible via
+ RenderState::uniformData(). When a state, such as, matrix or opacity, is
+ not dirty, there is no need to touch the corresponding region since the
+ data is persistent.
+
+ The return value must be \c true whenever any change was made to the uniform data.
+
+ The subclass specific state, such as the color of a flat color material,
+ should be extracted from \a newMaterial to update the relevant regions in
+ the buffer accordingly.
+
+ \a oldMaterial can be used to minimize buffer changes (which are typically
+ memcpy calls) when updating material states. When \a oldMaterial is null,
+ this shader was just activated.
+ */
+bool QSGMaterialRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial,
+ QSGMaterial *oldMaterial)
+{
+ Q_UNUSED(state);
+ Q_UNUSED(newMaterial);
+ Q_UNUSED(oldMaterial);
+ return false;
+}
+
+/*!
+ This function is called by the scene graph to prepare using a sampled image
+ in the shader, typically in form of a combined image sampler.
+
+ \a binding is the binding number of the sampler. The function is called for
+ each variable in the material's shaders'
+ \l{QShaderDescription::combinedImageSamplers()}.
+
+ When \c{*texture} is null, it must be set to a QSGTexture pointer before
+ returning. When non-null, it is up to the material to decide if a new
+ \c{QSGTexture *} is stored to it, or if it updates some parameters on the
+ already known QSGTexture. The ownership of the QSGTexture is not
+ transferred.
+
+ The current rendering \a state is passed from the scene graph. It is up to
+ the material to enqueue the texture data uploads to the
+ QRhiResourceUpdateBatch retriveable via RenderState::resourceUpdateBatch().
+
+ The subclass specific state can be extracted from \a newMaterial.
+
+ \a oldMaterial can be used to minimize changes. When \a oldMaterial is null,
+ this shader was just activated.
+ */
+void QSGMaterialRhiShader::updateSampledImage(RenderState &state,
+ int binding,
+ QSGTexture **texture,
+ QSGMaterial *newMaterial,
+ QSGMaterial *oldMaterial)
+{
+ Q_UNUSED(state);
+ Q_UNUSED(binding);
+ Q_UNUSED(texture);
+ Q_UNUSED(newMaterial);
+ Q_UNUSED(oldMaterial);
+}
+
+/*!
+ This function is called by the scene graph to enable the material to
+ provide a custom set of graphics state. The set of states that are
+ customizable by material is limited to blending and related settings.
+
+ \note This function is only called when the UpdatesGraphicsPipelineState
+ flag was enabled via setFlags(). By default it is not set, and so this
+ function is never called.
+
+ The return value must be \c true whenever a change was made to any of the
+ members in \a ps.
+
+ \note The contents of \a ps is not persistent between invocations of this
+ function.
+
+ The current rendering \a state is passed from the scene graph.
+
+ The subclass specific state can be extracted from \a newMaterial. When \a
+ oldMaterial is null, this shader was just activated.
+ */
+bool QSGMaterialRhiShader::updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ Q_UNUSED(state);
+ Q_UNUSED(ps);
+ Q_UNUSED(newMaterial);
+ Q_UNUSED(oldMaterial);
+ return false;
+}
+
+/*!
+ \class QSGMaterialRhiShader::RenderState
+
+ \brief Encapsulates the current rendering state during a call to
+ QSGMaterialRhiShader::updateUniformData() and the other \c update type of
+ functions.
+
+ \inmodule QtQuick
+ \since 5.14
+
+ The render state contains a number of accessors that the shader needs to
+ respect in order to conform to the current state of the scene graph.
+ */
+
+/*!
+ \enum QSGMaterialRhiShader::RenderState::DirtyState
+
+ \value DirtyMatrix Used to indicate that the matrix has changed and must be
+ updated.
+
+ \value DirtyOpacity Used to indicate that the opacity has changed and must
+ be updated.
+
+ \value DirtyAll Used to indicate that everything needs to be updated.
+ */
+
+/*!
+ \fn bool QSGMaterialRhiShader::RenderState::isMatrixDirty() const
+
+ Returns \c true if the dirtyStates() contain the dirty matrix state,
+ otherwise returns \c false.
+ */
+
+/*!
+ \fn bool QSGMaterialRhiShader::RenderState::isOpacityDirty() const
+
+ Returns \c true if the dirtyStates() contains the dirty opacity state,
+ otherwise returns \c false.
+ */
+
+/*!
+ \fn QSGMaterialRhiShader::RenderState::DirtyStates QSGMaterialRhiShader::RenderState::dirtyStates() const
+
+ Returns which rendering states that have changed and needs to be updated
+ for geometry rendered with this material to conform to the current
+ rendering state.
+ */
+
+/*!
+ \class QSGMaterialRhiShader::GraphicsPipelineState
+
+ \brief Describes state changes that the material wants to apply to the
+ currently active graphics pipeline state.
+
+ \inmodule QtQuick
+ \since 5.14
+
+ Unlike QSGMaterialShader, directly issuing state change commands with the
+ underlying graphics API is not possible with QSGMaterialRhiShader. This is
+ mainly because the concept of individually changeable states is considered
+ deprecated and not supported with modern graphics APIs.
+
+ Therefore, it is up to QSGMaterialRhiShader to expose a data structure with
+ the set of supported states, which the material can change in its
+ updatePipelineState() implementation, if there is one. The scenegraph will
+ then internally apply these changes to the active graphics pipeline state,
+ then rolling them back as appropriate.
+ */
+
+/*!
+ \enum QSGMaterialRhiShader::GraphicsPipelineState::BlendFactor
+ \since 5.14
+
+ \value Zero
+ \value One
+ \value SrcColor
+ \value OneMinusSrcColor
+ \value DstColor
+ \value OneMinusDstColor
+ \value SrcAlpha
+ \value OneMinusSrcAlpha
+ \value DstAlpha
+ \value OneMinusDstAlpha
+ \value ConstantColor
+ \value OneMinusConstantColor
+ \value ConstantAlpha
+ \value OneMinusConstantAlpha
+ \value SrcAlphaSaturate
+ \value Src1Color
+ \value OneMinusSrc1Color
+ \value Src1Alpha
+ \value OneMinusSrc1Alpha
+ */
+
+/*!
+ \enum QSGMaterialRhiShader::GraphicsPipelineState::ColorMaskComponent
+ \since 5.14
+
+ \value R
+ \value G
+ \value B
+ \value A
+ */
+
+/*!
+ \enum QSGMaterialRhiShader::GraphicsPipelineState::CullMode
+ \since 5.14
+
+ \value CullNone
+ \value CullFront
+ \value CullBack
+ */
+
+/*!
+ Returns the accumulated opacity to be used for rendering.
+ */
+float QSGMaterialRhiShader::RenderState::opacity() const
+{
+ Q_ASSERT(m_data);
+ return float(static_cast<const QSGRenderer *>(m_data)->currentOpacity());
+}
+
+/*!
+ Returns the modelview determinant to be used for rendering.
+ */
+float QSGMaterialRhiShader::RenderState::determinant() const
+{
+ Q_ASSERT(m_data);
+ return float(static_cast<const QSGRenderer *>(m_data)->determinant());
+}
+
+/*!
+ Returns the matrix combined of modelview matrix and project matrix.
+ */
+QMatrix4x4 QSGMaterialRhiShader::RenderState::combinedMatrix() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->currentCombinedMatrix();
+}
+
+/*!
+ Returns the ratio between physical pixels and device-independent pixels
+ to be used for rendering.
+*/
+float QSGMaterialRhiShader::RenderState::devicePixelRatio() const
+{
+ Q_ASSERT(m_data);
+ return float(static_cast<const QSGRenderer *>(m_data)->devicePixelRatio());
+}
+
+/*!
+ Returns the model view matrix.
+
+ If the material has the RequiresFullMatrix flag set, this is guaranteed to
+ be the complete transform matrix calculated from the scenegraph.
+
+ However, if this flag is not set, the renderer may choose to alter this
+ matrix. For example, it may pre-transform vertices on the CPU and set this
+ matrix to identity.
+
+ In a situation such as the above, it is still possible to retrieve the
+ actual matrix determinant by setting the RequiresDeterminant flag in the
+ material and calling the determinant() accessor.
+ */
+QMatrix4x4 QSGMaterialRhiShader::RenderState::modelViewMatrix() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->currentModelViewMatrix();
+}
+
+/*!
+ Returns the projection matrix.
+ */
+QMatrix4x4 QSGMaterialRhiShader::RenderState::projectionMatrix() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->currentProjectionMatrix();
+}
+
+/*!
+ Returns the viewport rect of the surface being rendered to.
+ */
+QRect QSGMaterialRhiShader::RenderState::viewportRect() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->viewportRect();
+}
+
+/*!
+ Returns the device rect of the surface being rendered to
+ */
+QRect QSGMaterialRhiShader::RenderState::deviceRect() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->deviceRect();
+}
+
+/*!
+ Returns a pointer to the data for the uniform (constant) buffer in the
+ shader. Uniform data must only be updated from
+ QSGMaterialRhiShader::updateUniformData(). The return value is null in the
+ other reimplementable functions, such as,
+ QSGMaterialRhiShader::updateSampledImage().
+
+ \note It is strongly recommended to declare the uniform block with \c
+ std140 in the shader, and to carefully study the standard uniform block
+ layout as described in section 7.6.2.2 of the OpenGL specification. It is
+ up to the QSGMaterialRhiShader implementation to ensure data gets placed
+ at the right location in this QByteArray, taking alignment requirements
+ into account. Shader code translated to other shading languages is expected
+ to use the same offsets for block members, even when the target language
+ uses different packing rules by default.
+
+ \note Avoid copying from C++ POD types, such as, structs, in order to
+ update multiple members at once, unless it has been verified that the
+ layouts of the C++ struct and the GLSL uniform block match.
+ */
+QByteArray *QSGMaterialRhiShader::RenderState::uniformData()
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->currentUniformData();
+}
+
+/*!
+ Returns a resource update batch to which upload and copy operatoins can be
+ queued. This is typically used by
+ QSGMaterialRhiShader::updateSampledImage() to enqueue texture image
+ content updates.
+ */
+QRhiResourceUpdateBatch *QSGMaterialRhiShader::RenderState::resourceUpdateBatch()
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->currentResourceUpdateBatch();
+}
+
+/*!
+ Returns the current QRhi.
+ */
+QRhi *QSGMaterialRhiShader::RenderState::rhi()
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->currentRhi();
+}
+
+char const *const *QSGMaterialRhiShader::attributeNames() const
+{
+ Q_ASSERT_X(false, "QSGMaterialRhiShader::attributeNames()", "Not implemented for RHI");
+ return nullptr;
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/coreapi/qsgmaterialrhishader.h b/src/quick/scenegraph/coreapi/qsgmaterialrhishader.h
new file mode 100644
index 0000000000..86208516cd
--- /dev/null
+++ b/src/quick/scenegraph/coreapi/qsgmaterialrhishader.h
@@ -0,0 +1,182 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGMATERIALRHISHADER_H
+#define QSGMATERIALRHISHADER_H
+
+#include <QtQuick/qtquickglobal.h>
+#include <QtCore/QRect>
+#include <QtGui/QMatrix4x4>
+#include <QtGui/QColor>
+#include <QtQuick/qsgmaterialshader.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGMaterial;
+class QSGMaterialRhiShaderPrivate;
+class QSGTexture;
+class QRhiResourceUpdateBatch;
+class QRhi;
+class QShader;
+
+class Q_QUICK_EXPORT QSGMaterialRhiShader : public QSGMaterialShader // ### Qt 6: remove inheritance
+{
+public:
+ class Q_QUICK_EXPORT RenderState {
+ public:
+ using DirtyStates = QSGMaterialShader::RenderState::DirtyStates;
+
+ inline DirtyStates dirtyStates() const { return m_dirty; }
+
+ inline bool isMatrixDirty() const { return m_dirty & QSGMaterialShader::RenderState::DirtyMatrix; }
+ inline bool isOpacityDirty() const { return m_dirty & QSGMaterialShader::RenderState::DirtyOpacity; }
+
+ float opacity() const;
+ QMatrix4x4 combinedMatrix() const;
+ QMatrix4x4 modelViewMatrix() const;
+ QMatrix4x4 projectionMatrix() const;
+ QRect viewportRect() const;
+ QRect deviceRect() const;
+ float determinant() const;
+ float devicePixelRatio() const;
+
+ QByteArray *uniformData();
+ QRhiResourceUpdateBatch *resourceUpdateBatch();
+ QRhi *rhi();
+
+ private:
+ friend class QSGRenderer;
+ DirtyStates m_dirty;
+ const void *m_data;
+ };
+
+ struct Q_QUICK_EXPORT GraphicsPipelineState {
+ enum BlendFactor {
+ Zero,
+ One,
+ SrcColor,
+ OneMinusSrcColor,
+ DstColor,
+ OneMinusDstColor,
+ SrcAlpha,
+ OneMinusSrcAlpha,
+ DstAlpha,
+ OneMinusDstAlpha,
+ ConstantColor,
+ OneMinusConstantColor,
+ ConstantAlpha,
+ OneMinusConstantAlpha,
+ SrcAlphaSaturate,
+ Src1Color,
+ OneMinusSrc1Color,
+ Src1Alpha,
+ OneMinusSrc1Alpha
+ };
+
+ enum ColorMaskComponent {
+ R = 1 << 0,
+ G = 1 << 1,
+ B = 1 << 2,
+ A = 1 << 3
+ };
+ Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
+
+ enum CullMode {
+ CullNone,
+ CullFront,
+ CullBack
+ };
+
+ bool blendEnable;
+ BlendFactor srcColor;
+ BlendFactor dstColor;
+ ColorMask colorWrite;
+ QColor blendConstant;
+ CullMode cullMode;
+ // This struct is extensible while keeping BC since apps only ever get
+ // a ptr to the struct, it is not created by them.
+ };
+
+ enum Flag {
+ UpdatesGraphicsPipelineState = 0x0001
+ };
+ Q_DECLARE_FLAGS(Flags, Flag)
+
+ enum Stage {
+ VertexStage,
+ FragmentStage,
+ };
+
+ QSGMaterialRhiShader();
+ virtual ~QSGMaterialRhiShader();
+
+ virtual bool updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
+
+ virtual void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
+
+ virtual bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
+
+ Flags flags() const;
+ void setFlag(Flags flags, bool on = true);
+
+ // dummy impl for base class pure virtual, never called
+ char const *const *attributeNames() const override;
+
+protected:
+ Q_DECLARE_PRIVATE(QSGMaterialRhiShader)
+ QSGMaterialRhiShader(QSGMaterialRhiShaderPrivate &dd);
+
+ // filename is for a file containing a serialized QShader.
+ void setShaderFileName(Stage stage, const QString &filename);
+
+ void setShader(Stage stage, const QShader &shader);
+
+private:
+ QScopedPointer<QSGMaterialRhiShaderPrivate> d_ptr;
+};
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialRhiShader::GraphicsPipelineState::ColorMask)
+Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialRhiShader::Flags)
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/quick/scenegraph/coreapi/qsgmaterialrhishader_p.h b/src/quick/scenegraph/coreapi/qsgmaterialrhishader_p.h
new file mode 100644
index 0000000000..153b4b120a
--- /dev/null
+++ b/src/quick/scenegraph/coreapi/qsgmaterialrhishader_p.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGMATERIALRHISHADER_P_H
+#define QSGMATERIALRHISHADER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtquickglobal_p.h>
+#include "qsgmaterialrhishader.h"
+#include "qsgmaterial.h"
+#include <QtGui/private/qrhi_p.h>
+#include <QtGui/private/qshader_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QRhiSampler;
+
+class Q_QUICK_PRIVATE_EXPORT QSGMaterialRhiShaderPrivate
+{
+public:
+ Q_DECLARE_PUBLIC(QSGMaterialRhiShader)
+
+ QSGMaterialRhiShaderPrivate(QSGMaterialRhiShader *q) : q_ptr(q) { }
+ static QSGMaterialRhiShaderPrivate *get(QSGMaterialRhiShader *s) { return s->d_func(); }
+ static const QSGMaterialRhiShaderPrivate *get(const QSGMaterialRhiShader *s) { return s->d_func(); }
+
+ void clearCachedRendererData();
+ void prepare(QShader::Variant vertexShaderVariant);
+
+ QShader shader(QShader::Stage stage) const { return shaders[stage].shader; }
+
+ static QShader loadShader(const QString &filename);
+
+ QSGMaterialRhiShader *q_ptr;
+ QHash<QShader::Stage, QString> shaderFileNames;
+ QSGMaterialRhiShader::Flags flags;
+
+ struct ShaderStageData {
+ ShaderStageData() { } // so shader.isValid() == false
+ ShaderStageData(const QShader &shader) : shader(shader) { }
+ QShader shader;
+ QShader::Variant shaderVariant = QShader::StandardShader;
+ QVector<int> vertexInputLocations; // excluding rewriter-inserted ones
+ int qt_order_attrib_location = -1; // rewriter-inserted
+ };
+ QHash<QShader::Stage, ShaderStageData> shaders;
+
+ static const int MAX_SHADER_RESOURCE_BINDINGS = 32;
+
+ int ubufBinding = -1;
+ int ubufSize = 0;
+ QRhiShaderResourceBinding::StageFlags ubufStages;
+ QRhiShaderResourceBinding::StageFlags combinedImageSamplerBindings[MAX_SHADER_RESOURCE_BINDINGS];
+
+ ShaderStageData *vertexShader = nullptr;
+ ShaderStageData *fragmentShader = nullptr;
+
+ QByteArray masterUniformData;
+
+ QSGTexture *textureBindingTable[MAX_SHADER_RESOURCE_BINDINGS];
+ QRhiSampler *samplerBindingTable[MAX_SHADER_RESOURCE_BINDINGS];
+};
+
+Q_DECLARE_TYPEINFO(QSGMaterialRhiShaderPrivate::ShaderStageData, Q_MOVABLE_TYPE);
+
+QT_END_NAMESPACE
+
+#endif // QSGMATERIALRHISHADER_P_H
diff --git a/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp b/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp
new file mode 100644
index 0000000000..d614f9be4c
--- /dev/null
+++ b/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp
@@ -0,0 +1,556 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgmaterial.h"
+#include "qsgrenderer_p.h"
+#include "qsgmaterialshader_p.h"
+#if QT_CONFIG(opengl)
+# include <private/qsgshadersourcebuilder_p.h>
+# include <private/qsgdefaultcontext_p.h>
+# include <private/qsgdefaultrendercontext_p.h>
+# include <QtGui/QOpenGLFunctions>
+# include <QtGui/QOpenGLContext>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+#if QT_CONFIG(opengl)
+const char *QSGMaterialShaderPrivate::loadShaderSource(QOpenGLShader::ShaderType type) const
+{
+ const QStringList files = m_sourceFiles[type];
+ QSGShaderSourceBuilder builder;
+ for (const QString &file : files)
+ builder.appendSourceFile(file);
+ m_sources[type] = builder.source();
+ return m_sources[type].constData();
+}
+#endif
+
+/*!
+ \class QSGMaterialShader
+ \brief The QSGMaterialShader class represents an OpenGL shader program
+ in the renderer.
+ \inmodule QtQuick
+ \ingroup qtquick-scenegraph-materials
+
+ The QSGMaterialShader API is relatively low-level. A more convenient API,
+ which provides almost all the same features, is available through
+ QSGSimpleMaterialShader.
+
+ \warning This class is only functional when running with the legacy OpenGL
+ renderer of the Qt Quick scenegraph.
+
+ The QSGMaterial and QSGMaterialShader form a tight relationship. For one
+ scene graph (including nested graphs), there is one unique QSGMaterialShader
+ instance which encapsulates the QOpenGLShaderProgram the scene graph uses
+ to render that material, such as a shader to flat coloring of geometry.
+ Each QSGGeometryNode can have a unique QSGMaterial containing the
+ how the shader should be configured when drawing that node, such as
+ the actual color used to render the geometry.
+
+ An instance of QSGMaterialShader is never created explicitly by the user,
+ it will be created on demand by the scene graph through
+ QSGMaterial::createShader(). The scene graph will make sure that there
+ is only one instance of each shader implementation through a scene graph.
+
+ The source code returned from vertexShader() is used to control what the
+ material does with the vertiex data that comes in from the geometry.
+ The source code returned from the fragmentShader() is used to control
+ what how the material should fill each individual pixel in the geometry.
+ The vertex and fragment source code is queried once during initialization,
+ changing what is returned from these functions later will not have
+ any effect.
+
+ The activate() function is called by the scene graph when a shader is
+ is starting to be used. The deactivate function is called by the scene
+ graph when the shader is no longer going to be used. While active,
+ the scene graph may make one or more calls to updateState() which
+ will update the state of the shader for each individual geometry to
+ render.
+
+ The attributeNames() returns the name of the attributes used in the
+ vertexShader(). These are used in the default implementation of
+ activate() and deactivate() to decide whice vertex registers are enabled.
+
+ The initialize() function is called during program creation to allow
+ subclasses to prepare for use, such as resolve uniform names in the
+ vertexShader() and fragmentShader().
+
+ A minimal example:
+ \code
+ class Shader : public QSGMaterialShader
+ {
+ public:
+ const char *vertexShader() const {
+ return
+ "attribute highp vec4 vertex; \n"
+ "uniform highp mat4 matrix; \n"
+ "void main() { \n"
+ " gl_Position = matrix * vertex; \n"
+ "}";
+ }
+
+ const char *fragmentShader() const {
+ return
+ "uniform lowp float opacity; \n"
+ "void main() { \n"
+ " gl_FragColor = vec4(1, 0, 0, 1) * opacity; \n"
+ "}";
+ }
+
+ char const *const *attributeNames() const
+ {
+ static char const *const names[] = { "vertex", 0 };
+ return names;
+ }
+
+ void initialize()
+ {
+ QSGMaterialShader::initialize();
+ m_id_matrix = program()->uniformLocation("matrix");
+ m_id_opacity = program()->uniformLocation("opacity");
+ }
+
+ void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+ {
+ Q_ASSERT(program()->isLinked());
+ if (state.isMatrixDirty())
+ program()->setUniformValue(m_id_matrix, state.combinedMatrix());
+ if (state.isOpacityDirty())
+ program()->setUniformValue(m_id_opacity, state.opacity());
+ }
+
+ private:
+ int m_id_matrix;
+ int m_id_opacity;
+ };
+ \endcode
+
+ \note All classes with QSG prefix should be used solely on the scene graph's
+ rendering thread. See \l {Scene Graph and Rendering} for more information.
+
+ */
+
+
+
+/*!
+ Creates a new QSGMaterialShader.
+ */
+QSGMaterialShader::QSGMaterialShader()
+ : d_ptr(new QSGMaterialShaderPrivate)
+{
+}
+
+/*!
+ \internal
+ */
+QSGMaterialShader::QSGMaterialShader(QSGMaterialShaderPrivate &dd)
+ : d_ptr(&dd)
+{
+}
+
+/*!
+ \internal
+ */
+QSGMaterialShader::~QSGMaterialShader()
+{
+}
+
+/*!
+ \fn char const *const *QSGMaterialShader::attributeNames() const
+
+ Returns a zero-terminated array describing the names of the
+ attributes used in the vertex shader.
+
+ This function is called when the shader is compiled to specify
+ which attributes exist. The order of the attribute names
+ defines the attribute register position in the vertex shader.
+ */
+
+#if QT_CONFIG(opengl)
+/*!
+ \fn const char *QSGMaterialShader::vertexShader() const
+
+ Called when the shader is being initialized to get the vertex
+ shader source code.
+
+ The contents returned from this function should never change.
+*/
+const char *QSGMaterialShader::vertexShader() const
+{
+ Q_D(const QSGMaterialShader);
+ return d->loadShaderSource(QOpenGLShader::Vertex);
+}
+
+
+/*!
+ \fn const char *QSGMaterialShader::fragmentShader() const
+
+ Called when the shader is being initialized to get the fragment
+ shader source code.
+
+ The contents returned from this function should never change.
+*/
+const char *QSGMaterialShader::fragmentShader() const
+{
+ Q_D(const QSGMaterialShader);
+ return d->loadShaderSource(QOpenGLShader::Fragment);
+}
+
+
+/*!
+ \fn QOpenGLShaderProgram *QSGMaterialShader::program()
+
+ Returns the shader program used by this QSGMaterialShader.
+ */
+#endif
+
+/*!
+ \fn void QSGMaterialShader::initialize()
+
+ Reimplement this function to do one-time initialization when the
+ shader program is compiled. The OpenGL shader program is compiled
+ and linked, but not bound, when this function is called.
+ */
+
+
+/*!
+ This function is called by the scene graph to indicate that geometry is
+ about to be rendered using this shader.
+
+ State that is global for all uses of the shader, independent of the geometry
+ that is being drawn, can be setup in this function.
+ */
+
+void QSGMaterialShader::activate()
+{
+}
+
+
+
+/*!
+ This function is called by the scene graph to indicate that geometry will
+ no longer to be rendered using this shader.
+ */
+
+void QSGMaterialShader::deactivate()
+{
+}
+
+
+
+/*!
+ This function is called by the scene graph before geometry is rendered
+ to make sure the shader is in the right state.
+
+ The current rendering \a state is passed from the scene graph. If the state
+ indicates that any state is dirty, the updateState implementation must
+ update accordingly for the geometry to render correctly.
+
+ The subclass specific state, such as the color of a flat color material, should
+ be extracted from \a newMaterial to update the color uniforms accordingly.
+
+ The \a oldMaterial can be used to minimze state changes when updating
+ material states. The \a oldMaterial is 0 if this shader was just activated.
+
+ \sa activate(), deactivate()
+ */
+
+void QSGMaterialShader::updateState(const RenderState & /* state */, QSGMaterial * /* newMaterial */, QSGMaterial * /* oldMaterial */)
+{
+}
+
+#if QT_CONFIG(opengl)
+/*!
+ Sets the GLSL source file for the shader stage \a type to \a sourceFile. The
+ default implementation of the vertexShader() and fragmentShader() functions
+ will load the source files set by this function.
+
+ This function is useful when you have a single source file for a given shader
+ stage. If your shader consists of multiple source files then use
+ setShaderSourceFiles()
+
+ \sa setShaderSourceFiles(), vertexShader(), fragmentShader()
+ */
+void QSGMaterialShader::setShaderSourceFile(QOpenGLShader::ShaderType type, const QString &sourceFile)
+{
+ Q_D(QSGMaterialShader);
+ d->m_sourceFiles[type] = (QStringList() << sourceFile);
+}
+
+/*!
+ Sets the GLSL source files for the shader stage \a type to \a sourceFiles. The
+ default implementation of the vertexShader() and fragmentShader() functions
+ will load the source files set by this function in the order given.
+
+ \sa setShaderSourceFile(), vertexShader(), fragmentShader()
+ */
+void QSGMaterialShader::setShaderSourceFiles(QOpenGLShader::ShaderType type, const QStringList &sourceFiles)
+{
+ Q_D(QSGMaterialShader);
+ d->m_sourceFiles[type] = sourceFiles;
+}
+
+/*!
+ This function is called when the shader is initialized to compile the
+ actual QOpenGLShaderProgram. Do not call it explicitly.
+
+ The default implementation will extract the vertexShader() and
+ fragmentShader() and bind the names returned from attributeNames()
+ to consecutive vertex attribute registers starting at 0.
+ */
+
+void QSGMaterialShader::compile()
+{
+ Q_ASSERT_X(!m_program.isLinked(), "QSGSMaterialShader::compile()", "Compile called multiple times!");
+
+ program()->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexShader());
+ program()->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShader());
+
+ char const *const *attr = attributeNames();
+#ifndef QT_NO_DEBUG
+ int maxVertexAttribs = 0;
+ QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
+ funcs->glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
+ for (int i = 0; attr[i]; ++i) {
+ if (i >= maxVertexAttribs) {
+ qFatal("List of attribute names is either too long or not null-terminated.\n"
+ "Maximum number of attributes on this hardware is %i.\n"
+ "Vertex shader:\n%s\n"
+ "Fragment shader:\n%s\n",
+ maxVertexAttribs, vertexShader(), fragmentShader());
+ }
+ if (*attr[i])
+ program()->bindAttributeLocation(attr[i], i);
+ }
+#else
+ for (int i = 0; attr[i]; ++i) {
+ if (*attr[i])
+ program()->bindAttributeLocation(attr[i], i);
+ }
+#endif
+
+ if (!program()->link()) {
+ qWarning("QSGMaterialShader: Shader compilation failed:");
+ qWarning() << program()->log();
+ }
+}
+
+#endif
+
+/*!
+ \class QSGMaterialShader::RenderState
+ \brief The QSGMaterialShader::RenderState encapsulates the current rendering state
+ during a call to QSGMaterialShader::updateState().
+ \inmodule QtQuick
+
+ The render state contains a number of accessors that the shader needs to respect
+ in order to conform to the current state of the scene graph.
+
+ The instance is only valid inside a call to QSGMaterialShader::updateState() and
+ should not be used outisde this function.
+ */
+
+
+
+/*!
+ \enum QSGMaterialShader::RenderState::DirtyState
+
+ \value DirtyMatrix Used to indicate that the matrix has changed and must be updated.
+
+ \value DirtyOpacity Used to indicate that the opacity has changed and must be updated.
+
+ \value DirtyCachedMaterialData Used to indicate that the cached material data have changed and must be updated.
+
+ \value DirtyAll Used to indicate that everything needs to be updated.
+ */
+
+
+
+/*!
+ \fn bool QSGMaterialShader::RenderState::isMatrixDirty() const
+
+ Returns \c true if the dirtyStates() contain the dirty matrix state,
+ otherwise returns \c false.
+ */
+
+
+
+/*!
+ \fn bool QSGMaterialShader::RenderState::isOpacityDirty() const
+
+ Returns \c true if the dirtyStates() contains the dirty opacity state,
+ otherwise returns \c false.
+ */
+
+/*!
+ \fn bool QSGMaterialShader::RenderState::isCachedMaterialDataDirty() const
+
+ Returns \c true if the dirtyStates() contains the dirty cached material state,
+ otherwise returns \c false.
+ */
+
+/*!
+ \fn QSGMaterialShader::RenderState::DirtyStates QSGMaterialShader::RenderState::dirtyStates() const
+
+ Returns which rendering states that have changed and needs to be updated
+ for geometry rendered with this material to conform to the current
+ rendering state.
+ */
+
+
+
+/*!
+ Returns the accumulated opacity to be used for rendering.
+ */
+
+float QSGMaterialShader::RenderState::opacity() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->currentOpacity();
+}
+
+/*!
+ Returns the modelview determinant to be used for rendering.
+ */
+
+float QSGMaterialShader::RenderState::determinant() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->determinant();
+}
+
+/*!
+ Returns the matrix combined of modelview matrix and project matrix.
+ */
+
+QMatrix4x4 QSGMaterialShader::RenderState::combinedMatrix() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->currentCombinedMatrix();
+}
+/*!
+ Returns the ratio between physical pixels and device-independent pixels
+ to be used for rendering.
+*/
+float QSGMaterialShader::RenderState::devicePixelRatio() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->devicePixelRatio();
+}
+
+
+
+/*!
+ Returns the model view matrix.
+
+ If the material has the RequiresFullMatrix flag
+ set, this is guaranteed to be the complete transform
+ matrix calculated from the scenegraph.
+
+ However, if this flag is not set, the renderer may
+ choose to alter this matrix. For example, it may
+ pre-transform vertices on the CPU and set this matrix
+ to identity.
+
+ In a situation such as the above, it is still possible
+ to retrieve the actual matrix determinant by setting
+ the RequiresDeterminant flag in the material and
+ calling the determinant() accessor.
+ */
+
+QMatrix4x4 QSGMaterialShader::RenderState::modelViewMatrix() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->currentModelViewMatrix();
+}
+
+/*!
+ Returns the projection matrix.
+ */
+
+QMatrix4x4 QSGMaterialShader::RenderState::projectionMatrix() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->currentProjectionMatrix();
+}
+
+
+
+/*!
+ Returns the viewport rect of the surface being rendered to.
+ */
+
+QRect QSGMaterialShader::RenderState::viewportRect() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->viewportRect();
+}
+
+
+
+/*!
+ Returns the device rect of the surface being rendered to
+ */
+
+QRect QSGMaterialShader::RenderState::deviceRect() const
+{
+ Q_ASSERT(m_data);
+ return static_cast<const QSGRenderer *>(m_data)->deviceRect();
+}
+
+#if QT_CONFIG(opengl)
+
+/*!
+ Returns the QOpenGLContext that is being used for rendering
+ */
+
+QOpenGLContext *QSGMaterialShader::RenderState::context() const
+{
+ // Only the QSGDefaultRenderContext will have an OpenGL Context to query
+ auto openGLRenderContext = static_cast<const QSGDefaultRenderContext *>(static_cast<const QSGRenderer *>(m_data)->context());
+ if (openGLRenderContext != nullptr)
+ return openGLRenderContext->openglContext();
+ else
+ return nullptr;
+}
+
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/coreapi/qsgmaterialshader.h b/src/quick/scenegraph/coreapi/qsgmaterialshader.h
new file mode 100644
index 0000000000..d7ee23384f
--- /dev/null
+++ b/src/quick/scenegraph/coreapi/qsgmaterialshader.h
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGMATERIALSHADER_H
+#define QSGMATERIALSHADER_H
+
+#include <QtQuick/qtquickglobal.h>
+#if QT_CONFIG(opengl)
+# include <QtGui/qopenglshaderprogram.h>
+#endif
+#include <QtGui/QMatrix4x4>
+#include <QtCore/QRect>
+#include <QtQuick/qsgmaterialtype.h> // for source compat
+
+QT_BEGIN_NAMESPACE
+
+class QSGMaterial;
+class QSGMaterialShaderPrivate;
+
+namespace QSGBatchRenderer {
+ class ShaderManager;
+}
+
+class Q_QUICK_EXPORT QSGMaterialShader
+{
+public:
+ class Q_QUICK_EXPORT RenderState {
+ public:
+ enum DirtyState
+ {
+ DirtyMatrix = 0x0001,
+ DirtyOpacity = 0x0002,
+ DirtyCachedMaterialData = 0x0004,
+ DirtyAll = 0xFFFF
+ };
+ Q_DECLARE_FLAGS(DirtyStates, DirtyState)
+
+ inline DirtyStates dirtyStates() const { return m_dirty; }
+
+ inline bool isMatrixDirty() const { return m_dirty & DirtyMatrix; }
+ inline bool isOpacityDirty() const { return m_dirty & DirtyOpacity; }
+ bool isCachedMaterialDataDirty() const { return m_dirty & DirtyCachedMaterialData; }
+
+ float opacity() const;
+ QMatrix4x4 combinedMatrix() const;
+ QMatrix4x4 modelViewMatrix() const;
+ QMatrix4x4 projectionMatrix() const;
+ QRect viewportRect() const;
+ QRect deviceRect() const;
+ float determinant() const;
+ float devicePixelRatio() const;
+#if QT_CONFIG(opengl)
+ QOpenGLContext *context() const;
+#endif
+ private:
+ friend class QSGRenderer;
+ DirtyStates m_dirty;
+ const void *m_data;
+ };
+
+ QSGMaterialShader();
+ virtual ~QSGMaterialShader();
+
+ virtual void activate();
+ virtual void deactivate();
+ // First time a material is used, oldMaterial is null.
+ virtual void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
+ virtual char const *const *attributeNames() const = 0; // Array must end with null.
+#if QT_CONFIG(opengl)
+ inline QOpenGLShaderProgram *program() { return &m_program; }
+#endif
+protected:
+ Q_DECLARE_PRIVATE(QSGMaterialShader)
+ QSGMaterialShader(QSGMaterialShaderPrivate &dd);
+
+ friend class QSGDefaultRenderContext;
+ friend class QSGBatchRenderer::ShaderManager;
+#if QT_CONFIG(opengl)
+ void setShaderSourceFile(QOpenGLShader::ShaderType type, const QString &sourceFile);
+ void setShaderSourceFiles(QOpenGLShader::ShaderType type, const QStringList &sourceFiles);
+
+ virtual void compile();
+#endif
+ virtual void initialize() { }
+#if QT_CONFIG(opengl)
+ virtual const char *vertexShader() const;
+ virtual const char *fragmentShader() const;
+#endif
+private:
+#if QT_CONFIG(opengl)
+ QOpenGLShaderProgram m_program;
+#endif
+ QScopedPointer<QSGMaterialShaderPrivate> d_ptr;
+};
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialShader::RenderState::DirtyStates)
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/quick/scenegraph/coreapi/qsgmaterialshader_p.h b/src/quick/scenegraph/coreapi/qsgmaterialshader_p.h
index 47f5e5de09..ae23b4a8ce 100644
--- a/src/quick/scenegraph/coreapi/qsgmaterialshader_p.h
+++ b/src/quick/scenegraph/coreapi/qsgmaterialshader_p.h
@@ -1,5 +1,6 @@
/****************************************************************************
**
+** Copyright (C) 2019 The Qt Company Ltd.
** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
** Contact: https://www.qt.io/licensing/
**
@@ -52,7 +53,7 @@
//
#include <private/qtquickglobal_p.h>
-#include <QOpenGLShader>
+#include "qsgmaterial.h"
QT_BEGIN_NAMESPACE
@@ -67,11 +68,6 @@ public:
#endif
};
-#ifndef QT_NO_DEBUG
-Q_QUICK_PRIVATE_EXPORT bool qsg_test_and_clear_material_failure();
-Q_QUICK_PRIVATE_EXPORT void qsg_set_material_failure();
-#endif
-
QT_END_NAMESPACE
#endif // QSGMATERIALSHADER_P_H
diff --git a/src/quick/scenegraph/coreapi/qsgmaterialtype.h b/src/quick/scenegraph/coreapi/qsgmaterialtype.h
new file mode 100644
index 0000000000..15141c2d9e
--- /dev/null
+++ b/src/quick/scenegraph/coreapi/qsgmaterialtype.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGMATERIALTYPE_H
+#define QSGMATERIALTYPE_H
+
+#include <QtQuick/qtquickglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+struct QSGMaterialType { };
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/quick/scenegraph/coreapi/qsgopenglvisualizer.cpp b/src/quick/scenegraph/coreapi/qsgopenglvisualizer.cpp
new file mode 100644
index 0000000000..6c2ff0b176
--- /dev/null
+++ b/src/quick/scenegraph/coreapi/qsgopenglvisualizer.cpp
@@ -0,0 +1,365 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
+** Copyright (C) 2016 Robin Burchell <robin.burchell@viroteck.net>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenglvisualizer_p.h"
+#include <qmath.h>
+#include <private/qsgshadersourcebuilder_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QSGBatchRenderer
+{
+
+#define QSGNODE_TRAVERSE(NODE) for (QSGNode *child = NODE->firstChild(); child; child = child->nextSibling())
+#define SHADOWNODE_TRAVERSE(NODE) for (Node *child = NODE->firstChild(); child; child = child->sibling())
+#define QSGNODE_DIRTY_PARENT (QSGNode::DirtyNodeAdded \
+ | QSGNode::DirtyOpacity \
+ | QSGNode::DirtyMatrix \
+ | QSGNode::DirtyNodeRemoved)
+
+QMatrix4x4 qsg_matrixForRoot(Node *node);
+
+class VisualizeShader : public QOpenGLShaderProgram
+{
+public:
+ int color;
+ int matrix;
+ int rotation;
+ int pattern;
+ int projection;
+};
+
+OpenGLVisualizer::OpenGLVisualizer(Renderer *renderer)
+ : Visualizer(renderer),
+ m_funcs(QOpenGLContext::currentContext()->functions()),
+ m_visualizeProgram(nullptr)
+{
+}
+
+OpenGLVisualizer::~OpenGLVisualizer()
+{
+ releaseResources();
+}
+
+void OpenGLVisualizer::releaseResources()
+{
+ delete m_visualizeProgram;
+ m_visualizeProgram = nullptr;
+}
+
+void OpenGLVisualizer::prepareVisualize()
+{
+ // nothing to do here
+}
+
+void OpenGLVisualizer::visualizeDrawGeometry(const QSGGeometry *g)
+{
+ if (g->attributeCount() < 1)
+ return;
+ const QSGGeometry::Attribute *a = g->attributes();
+ m_funcs->glVertexAttribPointer(0, a->tupleSize, a->type, false, g->sizeOfVertex(), g->vertexData());
+ if (g->indexCount())
+ m_funcs->glDrawElements(g->drawingMode(), g->indexCount(), g->indexType(), g->indexData());
+ else
+ m_funcs->glDrawArrays(g->drawingMode(), 0, g->vertexCount());
+
+}
+
+void OpenGLVisualizer::visualizeBatch(Batch *b)
+{
+ VisualizeShader *shader = static_cast<VisualizeShader *>(m_visualizeProgram);
+
+ if (b->positionAttribute != 0)
+ return;
+
+ QSGGeometryNode *gn = b->first->node;
+ QSGGeometry *g = gn->geometry();
+ const QSGGeometry::Attribute &a = g->attributes()[b->positionAttribute];
+
+ m_funcs->glBindBuffer(GL_ARRAY_BUFFER, b->vbo.id);
+
+ QMatrix4x4 matrix(m_renderer->m_current_projection_matrix);
+ if (b->root)
+ matrix = matrix * qsg_matrixForRoot(b->root);
+
+ shader->setUniformValue(shader->pattern, float(b->merged ? 0 : 1));
+
+ QColor color = QColor::fromHsvF((rand() & 1023) / 1023.0, 1.0, 1.0);
+ float cr = color.redF();
+ float cg = color.greenF();
+ float cb = color.blueF();
+ shader->setUniformValue(shader->color, cr, cg, cb, 1.0);
+
+ if (b->merged) {
+ shader->setUniformValue(shader->matrix, matrix);
+ const char *dataStart = m_renderer->m_context->separateIndexBuffer() ? b->ibo.data : b->vbo.data;
+ for (int ds=0; ds<b->drawSets.size(); ++ds) {
+ const DrawSet &set = b->drawSets.at(ds);
+ m_funcs->glVertexAttribPointer(a.position, 2, a.type, false, g->sizeOfVertex(),
+ (void *) (qintptr) (set.vertices));
+ m_funcs->glDrawElements(g->drawingMode(), set.indexCount, GL_UNSIGNED_SHORT,
+ (void *)(qintptr)(dataStart + set.indices));
+ }
+ } else {
+ Element *e = b->first;
+ int offset = 0;
+ while (e) {
+ gn = e->node;
+ g = gn->geometry();
+ shader->setUniformValue(shader->matrix, matrix * *gn->matrix());
+ m_funcs->glVertexAttribPointer(a.position, a.tupleSize, a.type, false, g->sizeOfVertex(),
+ (void *) (qintptr) offset);
+ if (g->indexCount())
+ m_funcs->glDrawElements(g->drawingMode(), g->indexCount(), g->indexType(), g->indexData());
+ else
+ m_funcs->glDrawArrays(g->drawingMode(), 0, g->vertexCount());
+ offset += g->sizeOfVertex() * g->vertexCount();
+ e = e->nextInBatch;
+ }
+ }
+}
+
+void OpenGLVisualizer::visualizeClipping(QSGNode *node)
+{
+ if (node->type() == QSGNode::ClipNodeType) {
+ VisualizeShader *shader = static_cast<VisualizeShader *>(m_visualizeProgram);
+ QSGClipNode *clipNode = static_cast<QSGClipNode *>(node);
+ QMatrix4x4 matrix = m_renderer->m_current_projection_matrix;
+ if (clipNode->matrix())
+ matrix = matrix * *clipNode->matrix();
+ shader->setUniformValue(shader->matrix, matrix);
+ visualizeDrawGeometry(clipNode->geometry());
+ }
+
+ QSGNODE_TRAVERSE(node) {
+ visualizeClipping(child);
+ }
+}
+
+void OpenGLVisualizer::visualizeChanges(Node *n)
+{
+
+ if (n->type() == QSGNode::GeometryNodeType && n->element()->batch && m_visualizeChangeSet.contains(n)) {
+ uint dirty = m_visualizeChangeSet.value(n);
+ bool tinted = (dirty & QSGNODE_DIRTY_PARENT) != 0;
+
+ VisualizeShader *shader = static_cast<VisualizeShader *>(m_visualizeProgram);
+ QColor color = QColor::fromHsvF((rand() & 1023) / 1023.0, 0.3, 1.0);
+ float ca = 0.5;
+ float cr = color.redF() * ca;
+ float cg = color.greenF() * ca;
+ float cb = color.blueF() * ca;
+ shader->setUniformValue(shader->color, cr, cg, cb, ca);
+ shader->setUniformValue(shader->pattern, float(tinted ? 0.5 : 0));
+
+ QSGGeometryNode *gn = static_cast<QSGGeometryNode *>(n->sgNode);
+
+ QMatrix4x4 matrix = m_renderer->m_current_projection_matrix;
+ if (n->element()->batch->root)
+ matrix = matrix * qsg_matrixForRoot(n->element()->batch->root);
+ matrix = matrix * *gn->matrix();
+ shader->setUniformValue(shader->matrix, matrix);
+ visualizeDrawGeometry(gn->geometry());
+
+ // This is because many changes don't propegate their dirty state to the
+ // parent so the node updater will not unset these states. They are
+ // not used for anything so, unsetting it should have no side effects.
+ n->dirtyState = nullptr;
+ }
+
+ SHADOWNODE_TRAVERSE(n) {
+ visualizeChanges(child);
+ }
+}
+
+void OpenGLVisualizer::visualizeOverdraw_helper(Node *node)
+{
+ if (node->type() == QSGNode::GeometryNodeType && node->element()->batch) {
+ VisualizeShader *shader = static_cast<VisualizeShader *>(m_visualizeProgram);
+ QSGGeometryNode *gn = static_cast<QSGGeometryNode *>(node->sgNode);
+
+ QMatrix4x4 matrix = m_renderer->m_current_projection_matrix;
+ matrix(2, 2) = m_renderer->m_zRange;
+ matrix(2, 3) = 1.0f - node->element()->order * m_renderer->m_zRange;
+
+ if (node->element()->batch->root)
+ matrix = matrix * qsg_matrixForRoot(node->element()->batch->root);
+ matrix = matrix * *gn->matrix();
+ shader->setUniformValue(shader->matrix, matrix);
+
+ QColor color = node->element()->batch->isOpaque ? QColor::fromRgbF(0.3, 1.0, 0.3) : QColor::fromRgbF(1.0, 0.3, 0.3);
+ float ca = 0.33f;
+ shader->setUniformValue(shader->color, color.redF() * ca, color.greenF() * ca, color.blueF() * ca, ca);
+
+ visualizeDrawGeometry(gn->geometry());
+ }
+
+ SHADOWNODE_TRAVERSE(node) {
+ visualizeOverdraw_helper(child);
+ }
+}
+
+void OpenGLVisualizer::visualizeOverdraw()
+{
+ VisualizeShader *shader = static_cast<VisualizeShader *>(m_visualizeProgram);
+ shader->setUniformValue(shader->color, 0.5f, 0.5f, 1.0f, 1.0f);
+ shader->setUniformValue(shader->projection, 1);
+
+ m_funcs->glBlendFunc(GL_ONE, GL_ONE);
+
+ static float step = 0;
+ step += static_cast<float>(M_PI * 2 / 1000.);
+ if (step > M_PI * 2)
+ step = 0;
+ float angle = 80.0 * std::sin(step);
+
+ QMatrix4x4 xrot; xrot.rotate(20, 1, 0, 0);
+ QMatrix4x4 zrot; zrot.rotate(angle, 0, 0, 1);
+ QMatrix4x4 tx; tx.translate(0, 0, 1);
+
+ QMatrix4x4 m;
+
+// m.rotate(180, 0, 1, 0);
+
+ m.translate(0, 0.5, 4);
+ m.scale(2, 2, 1);
+
+ m.rotate(-30, 1, 0, 0);
+ m.rotate(angle, 0, 1, 0);
+ m.translate(0, 0, -1);
+
+ shader->setUniformValue(shader->rotation, m);
+
+ float box[] = {
+ // lower
+ -1, 1, 0, 1, 1, 0,
+ -1, 1, 0, -1, -1, 0,
+ 1, 1, 0, 1, -1, 0,
+ -1, -1, 0, 1, -1, 0,
+
+ // upper
+ -1, 1, 1, 1, 1, 1,
+ -1, 1, 1, -1, -1, 1,
+ 1, 1, 1, 1, -1, 1,
+ -1, -1, 1, 1, -1, 1,
+
+ // sides
+ -1, -1, 0, -1, -1, 1,
+ 1, -1, 0, 1, -1, 1,
+ -1, 1, 0, -1, 1, 1,
+ 1, 1, 0, 1, 1, 1
+ };
+ m_funcs->glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, box);
+ m_funcs->glLineWidth(2);
+ m_funcs->glDrawArrays(GL_LINES, 0, 24);
+
+ visualizeOverdraw_helper(m_renderer->m_nodes.value(m_renderer->rootNode()));
+}
+
+void OpenGLVisualizer::visualize()
+{
+ if (m_visualizeMode == VisualizeNothing)
+ return;
+
+ if (!m_visualizeProgram) {
+ VisualizeShader *prog = new VisualizeShader();
+ QSGShaderSourceBuilder::initializeProgramFromFiles(
+ prog,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders/visualization.vert"),
+ QStringLiteral(":/qt-project.org/scenegraph/shaders/visualization.frag"));
+ prog->bindAttributeLocation("v", 0);
+ prog->link();
+ prog->bind();
+ prog->color = prog->uniformLocation("color");
+ prog->pattern = prog->uniformLocation("pattern");
+ prog->projection = prog->uniformLocation("projection");
+ prog->matrix = prog->uniformLocation("matrix");
+ prog->rotation = prog->uniformLocation("rotation");
+ m_visualizeProgram = prog;
+ } else {
+ m_visualizeProgram->bind();
+ }
+ VisualizeShader *shader = static_cast<VisualizeShader *>(m_visualizeProgram);
+
+ m_funcs->glDisable(GL_DEPTH_TEST);
+ m_funcs->glEnable(GL_BLEND);
+ m_funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ m_funcs->glEnableVertexAttribArray(0);
+
+ // Blacken out the actual rendered content...
+ float bgOpacity = 0.8f;
+ if (m_visualizeMode == VisualizeBatches)
+ bgOpacity = 1.0;
+ float v[] = { -1, 1, 1, 1, -1, -1, 1, -1 };
+ shader->setUniformValue(shader->color, 0.0f, 0.0f, 0.0f, bgOpacity);
+ shader->setUniformValue(shader->matrix, QMatrix4x4());
+ shader->setUniformValue(shader->rotation, QMatrix4x4());
+ shader->setUniformValue(shader->pattern, 0.0f);
+ shader->setUniformValue(shader->projection, false);
+ m_funcs->glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, v);
+ m_funcs->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ if (m_visualizeMode == VisualizeBatches) {
+ srand(0); // To force random colors to be roughly the same every time..
+ for (int i = 0; i < m_renderer->m_opaqueBatches.size(); ++i)
+ visualizeBatch(m_renderer->m_opaqueBatches.at(i));
+ for (int i = 0; i < m_renderer->m_alphaBatches.size(); ++i)
+ visualizeBatch(m_renderer->m_alphaBatches.at(i));
+ } else if (m_visualizeMode == VisualizeClipping) {
+ shader->setUniformValue(shader->pattern, 0.5f);
+ shader->setUniformValue(shader->color, 0.2f, 0.0f, 0.0f, 0.2f);
+ visualizeClipping(m_renderer->rootNode());
+ } else if (m_visualizeMode == VisualizeChanges) {
+ visualizeChanges(m_renderer->m_nodes.value(m_renderer->rootNode()));
+ m_visualizeChangeSet.clear();
+ } else if (m_visualizeMode == VisualizeOverdraw) {
+ visualizeOverdraw();
+ }
+
+ // Reset state back to defaults..
+ m_funcs->glDisable(GL_BLEND);
+ m_funcs->glDisableVertexAttribArray(0);
+ shader->release();
+}
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/coreapi/qsgopenglvisualizer_p.h b/src/quick/scenegraph/coreapi/qsgopenglvisualizer_p.h
new file mode 100644
index 0000000000..0b21694351
--- /dev/null
+++ b/src/quick/scenegraph/coreapi/qsgopenglvisualizer_p.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
+** Copyright (C) 2016 Robin Burchell <robin.burchell@viroteck.net>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENGLVISUALIZER_P_H
+#define QSGOPENGLVISUALIZER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qsgbatchrenderer_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QSGBatchRenderer
+{
+
+// ### Qt 6: remove
+class OpenGLVisualizer : public Visualizer
+{
+public:
+ OpenGLVisualizer(Renderer *renderer);
+ ~OpenGLVisualizer();
+
+ void prepareVisualize() override;
+ void visualize() override;
+
+ void releaseResources() override;
+
+private:
+ void visualizeBatch(Batch *b);
+ void visualizeClipping(QSGNode *node);
+ void visualizeChanges(Node *n);
+ void visualizeOverdraw();
+ void visualizeOverdraw_helper(Node *node);
+ void visualizeDrawGeometry(const QSGGeometry *g);
+
+ QOpenGLFunctions *m_funcs;
+ QOpenGLShaderProgram *m_visualizeProgram;
+};
+
+} // namespace QSGBatchRenderer
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENGLVISUALIZER_P_H
diff --git a/src/quick/scenegraph/coreapi/qsgrenderer.cpp b/src/quick/scenegraph/coreapi/qsgrenderer.cpp
index e1ba001d2d..7af932eeb5 100644
--- a/src/quick/scenegraph/coreapi/qsgrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgrenderer.cpp
@@ -132,6 +132,12 @@ QSGRenderer::QSGRenderer(QSGRenderContext *context)
, m_current_determinant(1)
, m_device_pixel_ratio(1)
, m_context(context)
+ , m_current_uniform_data(nullptr)
+ , m_current_resource_update_batch(nullptr)
+ , m_rhi(nullptr)
+ , m_rt(nullptr)
+ , m_cb(nullptr)
+ , m_rp_desc(nullptr)
, m_node_updater(nullptr)
, m_bindable(nullptr)
, m_changed_emitted(false)
@@ -184,21 +190,30 @@ bool QSGRenderer::isMirrored() const
void QSGRenderer::renderScene(uint fboId)
{
-#if QT_CONFIG(opengl)
- if (fboId) {
- QSGBindableFboId bindable(fboId);
- renderScene(bindable);
- } else {
+ if (m_rt) {
class B : public QSGBindable
{
public:
- void bind() const override { QOpenGLFramebufferObject::bindDefault(); }
+ void bind() const override { }
} bindable;
renderScene(bindable);
- }
+ } else {
+#if QT_CONFIG(opengl)
+ if (fboId) {
+ QSGBindableFboId bindable(fboId);
+ renderScene(bindable);
+ } else {
+ class B : public QSGBindable
+ {
+ public:
+ void bind() const override { QOpenGLFramebufferObject::bindDefault(); }
+ } bindable;
+ renderScene(bindable);
+ }
#else
- Q_UNUSED(fboId)
+ Q_UNUSED(fboId)
#endif
+ }
}
void QSGRenderer::renderScene(const QSGBindable &bindable)
diff --git a/src/quick/scenegraph/coreapi/qsgrenderer_p.h b/src/quick/scenegraph/coreapi/qsgrenderer_p.h
index d4ff6ea9fe..c4ed0072f6 100644
--- a/src/quick/scenegraph/coreapi/qsgrenderer_p.h
+++ b/src/quick/scenegraph/coreapi/qsgrenderer_p.h
@@ -62,6 +62,10 @@ QT_BEGIN_NAMESPACE
class QSGBindable;
class QSGNodeUpdater;
+class QRhiRenderTarget;
+class QRhiCommandBuffer;
+class QRhiRenderPassDescriptor;
+class QRhiResourceUpdateBatch;
Q_QUICK_PRIVATE_EXPORT bool qsg_test_and_clear_fatal_render_error();
Q_QUICK_PRIVATE_EXPORT void qsg_set_fatal_renderer_error();
@@ -69,11 +73,10 @@ Q_QUICK_PRIVATE_EXPORT void qsg_set_fatal_renderer_error();
class Q_QUICK_PRIVATE_EXPORT QSGRenderer : public QSGAbstractRenderer
{
public:
-
QSGRenderer(QSGRenderContext *context);
virtual ~QSGRenderer();
- // Accessed by QSGMaterialShader::RenderState.
+ // Accessed by QSGMaterial[Rhi]Shader::RenderState.
QMatrix4x4 currentProjectionMatrix() const { return m_current_projection_matrix; }
QMatrix4x4 currentModelViewMatrix() const { return m_current_model_view_matrix; }
QMatrix4x4 currentCombinedMatrix() const { return m_current_projection_matrix * m_current_model_view_matrix; }
@@ -92,11 +95,36 @@ public:
QSGNodeUpdater *nodeUpdater() const;
void setNodeUpdater(QSGNodeUpdater *updater);
inline QSGMaterialShader::RenderState state(QSGMaterialShader::RenderState::DirtyStates dirty) const;
+ inline QSGMaterialRhiShader::RenderState rhiState(QSGMaterialRhiShader::RenderState::DirtyStates dirty) const;
virtual void setCustomRenderMode(const QByteArray &) { }
+ virtual bool hasCustomRenderModeWithContinuousUpdate() const { return false; }
virtual void releaseCachedResources() { }
void clearChangedFlag() { m_changed_emitted = false; }
+ // Accessed by QSGMaterialRhiShader::RenderState.
+ QByteArray *currentUniformData() const { return m_current_uniform_data; }
+ QRhiResourceUpdateBatch *currentResourceUpdateBatch() const { return m_current_resource_update_batch; }
+ QRhi *currentRhi() const { return m_rhi; }
+
+ void setRenderTarget(QRhiRenderTarget *rt) { m_rt = rt; }
+ QRhiRenderTarget *renderTarget() const { return m_rt; }
+
+ void setCommandBuffer(QRhiCommandBuffer *cb) { m_cb = cb; }
+ QRhiCommandBuffer *commandBuffer() const { return m_cb; }
+
+ void setRenderPassDescriptor(QRhiRenderPassDescriptor *rpDesc) { m_rp_desc = rpDesc; }
+ QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_rp_desc; }
+
+ void setRenderPassRecordingCallbacks(QSGRenderContext::RenderPassCallback start,
+ QSGRenderContext::RenderPassCallback end,
+ void *userData)
+ {
+ m_renderPassRecordingCallbacks.start = start;
+ m_renderPassRecordingCallbacks.end = end;
+ m_renderPassRecordingCallbacks.userData = userData;
+ }
+
protected:
virtual void render() = 0;
@@ -107,7 +135,8 @@ protected:
void addNodesToPreprocess(QSGNode *node);
void removeNodesToPreprocess(QSGNode *node);
- QMatrix4x4 m_current_projection_matrix;
+ QMatrix4x4 m_current_projection_matrix; // includes adjustment, where applicable, so can be treated as Y up in NDC always
+ QMatrix4x4 m_current_projection_matrix_native_ndc; // Vulkan has Y down in normalized device coordinates, others Y up...
QMatrix4x4 m_current_model_view_matrix;
qreal m_current_opacity;
qreal m_current_determinant;
@@ -115,6 +144,18 @@ protected:
QSGRenderContext *m_context;
+ QByteArray *m_current_uniform_data;
+ QRhiResourceUpdateBatch *m_current_resource_update_batch;
+ QRhi *m_rhi;
+ QRhiRenderTarget *m_rt;
+ QRhiCommandBuffer *m_cb;
+ QRhiRenderPassDescriptor *m_rp_desc;
+ struct {
+ QSGRenderContext::RenderPassCallback start = nullptr;
+ QSGRenderContext::RenderPassCallback end = nullptr;
+ void *userData = nullptr;
+ } m_renderPassRecordingCallbacks;
+
private:
QSGNodeUpdater *m_node_updater;
@@ -156,6 +197,14 @@ QSGMaterialShader::RenderState QSGRenderer::state(QSGMaterialShader::RenderState
return s;
}
+QSGMaterialRhiShader::RenderState QSGRenderer::rhiState(QSGMaterialRhiShader::RenderState::DirtyStates dirty) const
+{
+ QSGMaterialRhiShader::RenderState s;
+ s.m_dirty = dirty;
+ s.m_data = this;
+ return s;
+}
+
class Q_QUICK_PRIVATE_EXPORT QSGNodeDumper : public QSGNodeVisitor {
diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp
index 0f49e615e4..0fee1486cf 100644
--- a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp
+++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp
@@ -55,13 +55,13 @@ QT_BEGIN_NAMESPACE
the Direct3D or Vulkan device) that is used by the scenegraph.
QSGRendererInterface's functions have varying availability. API and
- language queries, like graphicsApi() or shaderType() are always available,
- meaning it is sufficient to construct a QQuickWindow or QQuickView, and the
- graphics API or shading language in use can be queried right after via
- QQuickWindow::rendererInterface(). This guarantees that utilities like the
- GraphicsInfo QML type are able to report the correct values as early as
- possible, without having conditional property values - depending on for
- instance shaderType() - evaluate to unexpected values.
+ language queries, such as, graphicsApi() or shaderType() are always
+ available, meaning it is sufficient to construct a QQuickWindow or
+ QQuickView, and the graphics API or shading language in use can be queried
+ right after via QQuickWindow::rendererInterface(). This guarantees that
+ utilities like the GraphicsInfo QML type are able to report the correct
+ values as early as possible, without having conditional property values -
+ depending on for instance shaderType() - evaluate to unexpected values.
Engine-specific accessors, like getResource(), are however available only
after the scenegraph is initialized. Additionally, there may be
@@ -78,14 +78,69 @@ QT_BEGIN_NAMESPACE
\value OpenGL OpenGL ES 2.0 or higher
\value Direct3D12 Direct3D 12
\value OpenVG OpenVG via EGL
+ \value OpenGLRhi OpenGL ES 2.0 or higher via a graphics abstraction layer. This value was introduced in Qt 5.14.
+ \value Direct3D11Rhi Direct3D 11 via a graphics abstraction layer. This value was introduced in Qt 5.14.
+ \value VulkanRhi Vulkan 1.0 via a graphics abstraction layer. This value was introduced in Qt 5.14.
+ \value MetalRhi Metal via a graphics abstraction layer. This value was introduced in Qt 5.14.
+ \value NullRhi Null (no output) via a graphics abstraction layer. This value was introduced in Qt 5.14.
*/
/*!
\enum QSGRendererInterface::Resource
- \value DeviceResource The graphics device, when applicable.
- \value CommandQueueResource The graphics command queue used by the scenegraph, when applicable.
- \value CommandListResource The command list or buffer used by the scenegraph, when applicable.
- \value PainterResource The active QPainter used by the scenegraph, when running with the software backend.
+
+ \value DeviceResource The resource is a pointer to the graphics device,
+ when applicable. For example, a \c{VkDevice *}, \c{MTLDevice *} or
+ \c{ID3D11Device *}. Note that with Vulkan the returned value is a pointer
+ to the VkDevice, not the handle itself. This is because Vulkan handles may
+ not be pointers, and may use a different size from the architecture's
+ pointer size so merely casting to/from \c{void *} is wrong.
+
+ \value CommandQueueResource The resource is a pointer to the graphics
+ command queue used by the scenegraph, when applicable. For example, a
+ \c{VkQueue *} or \c{MTLCommandQueue *}. Note that with Vulkan the returned
+ value is a pointer to the VkQueue, not the handle itself.
+
+ \value CommandListResource The resource is a pointer to the command list or
+ buffer used by the scenegraph, when applicable. For example, a
+ \c{VkCommandBuffer *} or \c{MTLCommandBuffer *}. This object has limited
+ validity, and is only valid while the scene graph is preparing the next
+ frame. Note that with Vulkan the returned value is a pointer to the
+ VkCommandBuffer, not the handle itself.
+
+ \value PainterResource The resource is a pointer to the active QPainter
+ used by the scenegraph, when running with the software backend.
+
+ \value RhiResource The resource is a pointer to the QRhi instance used by
+ the scenegraph, when applicable. This value was introduced in Qt 5.14.
+
+ \value PhysicalDeviceResource The resource is a pointer to the pysical
+ device object used by the scenegraph, when applicable. For example, a
+ \c{VkPhysicalDevice *}. Note that with Vulkan the returned value is a
+ pointer to the VkPhysicalDevice, not the handle itself. This value was
+ introduced in Qt 5.14.
+
+ \value OpenGLContextResource The resource is a pointer to the
+ QOpenGLContext used by the scenegraph (on the render thread), when
+ applicable. This value was introduced in Qt 5.14.
+
+ \value DeviceContextResource The resource is a pointer to the device
+ context used by the scenegraph, when applicable. For example, a
+ \c{ID3D11DeviceContext *}. This value was introduced in Qt 5.14.
+
+ \value CommandEncoderResource The resource is a pointer to the currently
+ active render command encoder object used by the scenegraph, when
+ applicable. For example, a \c{MTLRenderCommandEncoder *}. This object has
+ limited validity, and is only valid while the scene graph is recording a
+ render pass for the next frame. This value was introduced in Qt 5.14.
+
+ \value VulkanInstanceResource The resource is a pointer to the
+ QVulkanInstance used by the scenegraph, when applicable. This value was
+ introduced in Qt 5.14.
+
+ \value RenderPassResource The resource is a pointer to the render pass used
+ by the scenegraph, describing the color and depth/stecil attachments and
+ how they are used. For example, a \c{VkRenderPass *}. This value was
+ introduced in Qt 5.14.
*/
/*!
@@ -93,6 +148,9 @@ QT_BEGIN_NAMESPACE
\value UnknownShadingLanguage Not yet known due to no window and scenegraph associated
\value GLSL GLSL or GLSL ES
\value HLSL HLSL
+ \value RhiShader Consumes QShader instances containing shader variants for
+ multiple target languages and intermediate formats. This value was introduced in
+ Qt 5.14.
*/
/*!
@@ -164,6 +222,32 @@ void *QSGRendererInterface::getResource(QQuickWindow *window, const char *resour
}
/*!
+ \return true if \a api is based on a graphics abstraction layer (QRhi)
+ instead of directly calling the native graphics API.
+
+ \note This function can be called on any thread.
+
+ \since 5.14
+ */
+bool QSGRendererInterface::isApiRhiBased(GraphicsApi api)
+{
+ switch (api) {
+ case OpenGLRhi:
+ Q_FALLTHROUGH();
+ case Direct3D11Rhi:
+ Q_FALLTHROUGH();
+ case VulkanRhi:
+ Q_FALLTHROUGH();
+ case MetalRhi:
+ Q_FALLTHROUGH();
+ case NullRhi:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/*!
\fn QSGRendererInterface::ShaderType QSGRendererInterface::shaderType() const
\return the shading language supported by the Qt Quick backend the
diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.h b/src/quick/scenegraph/coreapi/qsgrendererinterface.h
index 722488201b..7aa7d0e769 100644
--- a/src/quick/scenegraph/coreapi/qsgrendererinterface.h
+++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.h
@@ -54,20 +54,33 @@ public:
Software,
OpenGL,
Direct3D12,
- OpenVG
+ OpenVG,
+ OpenGLRhi,
+ Direct3D11Rhi,
+ VulkanRhi,
+ MetalRhi,
+ NullRhi,
};
enum Resource {
DeviceResource,
CommandQueueResource,
CommandListResource,
- PainterResource
+ PainterResource,
+ RhiResource,
+ PhysicalDeviceResource,
+ OpenGLContextResource,
+ DeviceContextResource,
+ CommandEncoderResource,
+ VulkanInstanceResource,
+ RenderPassResource
};
enum ShaderType {
UnknownShadingLanguage,
GLSL,
- HLSL
+ HLSL,
+ RhiShader
};
enum ShaderCompilationType {
@@ -93,6 +106,8 @@ public:
virtual ShaderType shaderType() const = 0;
virtual ShaderCompilationTypes shaderCompilationType() const = 0;
virtual ShaderSourceTypes shaderSourceType() const = 0;
+
+ static bool isApiRhiBased(GraphicsApi api);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QSGRendererInterface::ShaderCompilationTypes)
diff --git a/src/quick/scenegraph/coreapi/qsgrendernode.cpp b/src/quick/scenegraph/coreapi/qsgrendernode.cpp
index df3fa16a32..2892f2f966 100644
--- a/src/quick/scenegraph/coreapi/qsgrendernode.cpp
+++ b/src/quick/scenegraph/coreapi/qsgrendernode.cpp
@@ -81,8 +81,10 @@ QSGRenderNodePrivate::QSGRenderNodePrivate()
}
/*!
- This function should return a mask where each bit represents graphics states changed by
- the \l render() function:
+ When the underlying rendering API is OpenGL, this function should return a
+ mask where each bit represents graphics states changed by the \l render()
+ function:
+
\list
\li DepthState - depth write mask, depth test enabled, depth comparison function
\li StencilState - stencil write masks, stencil test enabled, stencil operations,
@@ -95,6 +97,29 @@ QSGRenderNodePrivate::QSGRenderNodePrivate()
\li RenderTargetState - render target
\endlist
+ With APIs other than OpenGL, the only relevant values are the ones that
+ correspond to dynamic state changes recorded on the command list/buffer.
+ For example, RSSetViewports, RSSetScissorRects, OMSetBlendFactor,
+ OMSetStencilRef in case of D3D12, or vkCmdSetViewport, vkCmdSetScissor,
+ vkCmdSetBlendConstants, vkCmdSetStencilRef in case of Vulkan, and only when
+ such commands were added to the scenegraph's command list queried via the
+ QSGRendererInterface::CommandList resource enum. States set in pipeline
+ state objects do not need to be reported here. Similarly, draw call related
+ settings (pipeline states, descriptor sets, vertex or index buffer
+ bindings, root signature, descriptor heaps, etc.) are always set again by
+ the scenegraph so render() can freely change them.
+
+ \note RenderTargetState is no longer supported with APIs like Vulkan. This
+ is by nature. render() is invoked while the Qt Quick scenegraph's main
+ command buffer is recording a renderpass, so there is no possibility of
+ changing the target and starting another renderpass (on that command buffer
+ at least). Therefore returning a value with RenderTargetState set is not
+ sensible.
+
+ The software backend exposes its QPainter and saves and restores before and
+ after invoking render(). Therefore reporting any changed states from here
+ is not necessary.
+
The function is called by the renderer so it can reset the states after
rendering this node. This makes the implementation of render() simpler
since it does not have to query and restore these states.
@@ -102,19 +127,6 @@ QSGRenderNodePrivate::QSGRenderNodePrivate()
The default implementation returns 0, meaning no relevant state was changed
in render().
- With APIs other than OpenGL the relevant states are only those that are set
- via the command list (for example, OMSetRenderTargets, RSSetViewports,
- RSSetScissorRects, OMSetBlendFactor, OMSetStencilRef in case of D3D12), and
- only when such commands were added to the scenegraph's command list queried
- via the QSGRendererInterface::CommandList resource enum. States set in
- pipeline state objects do not need to be reported here. Similarly, draw
- call related settings (root signature, descriptor heaps, etc.) are always
- set again by the scenegraph so render() can freely change them.
-
- The software backend exposes its QPainter and saves and restores before and
- after invoking render(). Therefore reporting any changed states from here
- is not necessary.
-
\note This function may be called before render().
*/
QSGRenderNode::StateFlags QSGRenderNode::changedStates() const
@@ -149,18 +161,31 @@ QSGRenderNode::StateFlags QSGRenderNode::changedStates() const
QQuickFramebufferObject, QQuickWindow::beforeRendering(), or the
equivalents of those for APIs other than OpenGL.
- Clip information is calculated before the function is called, it is however
- not enabled. Implementations wishing to take clipping into account can set
- up scissoring or stencil based on the information in \a state. Some
- scenegraph backends, software in particular, use no scissor or stencil.
- There the clip region is provided as an ordinary QRegion.
+ \note QSGRenderNode can perform significantly better than texture-based
+ approaches (such as, QQuickFramebufferObject), especially on systems where
+ the fragment processing power is limited. This is because it avoids
+ rendering to a texture and then drawing a textured quad. Rather,
+ QSGRenderNode allows recording draw calls in line with the scenegraph's
+ other commands, avoiding an additional render target and the potentially
+ expensive texturing and blending.
+
+ Clip information is calculated before the function is called.
+ Implementations wishing to take clipping into account can set up scissoring
+ or stencil based on the information in \a state. The stencil buffer is
+ filled with the necessary clip shapes, but it is up to the implementation
+ to enable stencil testing.
+
+ Some scenegraph backends, software in particular, use no scissor or
+ stencil. There the clip region is provided as an ordinary QRegion.
+
+ With the legacy, direct OpenGL based renderer, the following states are set
+ on the render thread's context before this function is called:
- For OpenGL the following states are set on the render thread's context
- before this function is called:
\list
+ \li glColorMask(true, true, true, true)
\li glDepthMask(false)
\li glDisable(GL_DEPTH_TEST)
- \li glStencilFunc(GL_EQUAL, state.stencilValue, 0xff) depending on clip
+ \li glStencilFunc(GL_EQUAL, state.stencilValue, 0xff); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP) depending on clip
\li glScissor(state.scissorRect.x(), state.scissorRect.y(),
state.scissorRect.width(), state.scissorRect.height()) depending on clip
\li glEnable(GL_BLEND)
@@ -168,23 +193,42 @@ QSGRenderNode::StateFlags QSGRenderNode::changedStates() const
\li glDisable(GL_CULL_FACE)
\endlist
- States that are not listed above, but are included in \l StateFlags, can
+ States that are not listed above, but are covered by \l StateFlags, can
have arbitrary values.
+ \note There is no state set with other graphics APIs, considering that many
+ of them do not have a concept of the traditional OpenGL state machine.
+ Rather, it is up to the implementation to create pipeline state objects
+ with the desired blending, scissor, and stencil tests enabled. Note that
+ this also includes OpenGL via the RHI. New QSGRenderNode implementations
+ are recommended to set all scissor, stencil and blend state explicitly (as
+ shown in the above list), even if they are targeting OpenGL.
+
\l changedStates() should return which states this function changes. If a
state is not covered by \l StateFlags, the state should be set to the
default value according to the OpenGL specification. For other APIs, see
the documentation for changedStates() for more information.
- \note Depth writes are disabled when this function is called (for example,
- glDepthMask(false) in case of OpenGL). Enabling depth writes can lead to
- unexpected results, depending on the scenegraph backend in use, so nodes
- should avoid this.
+ \note Depth writes are disabled when this function is called
+ (glDepthMask(false) with OpenGL). Enabling depth writes can lead to
+ unexpected results, depending on the scenegraph backend in use and the
+ content in the scene, so exercise caution with this.
For APIs other than OpenGL, it will likely be necessary to query certain
API-specific resources (for example, the graphics device or the command
list/buffer to add the commands to). This is done via QSGRendererInterface.
+ Assume nothing about the pipelines and dynamic states bound on the command
+ list/buffer when this function is called.
+
+ With some graphics APIs it can be necessary to also connect to the
+ QQuickWindow::beforeRendering() signal, because that is emitted before
+ recording the beginning of a renderpass on the command buffer
+ (vkCmdBeginRenderPass with Vulkan, or starting to encode via
+ MTLRenderCommandEncoder in case of Metal). Recording copy operations cannot
+ be done inside render() with such APIs. Rather, do it in the slot connected
+ (with DirectConnection) to the beforeRendering signal.
+
\sa QSGRendererInterface, QQuickWindow::rendererInterface()
*/
@@ -335,7 +379,8 @@ QSGRenderNode::RenderState::~RenderState()
/*!
\fn const QMatrix4x4 *QSGRenderNode::RenderState::scissorRect() const
- \return the current scissor rectangle when clipping is active.
+ \return the current scissor rectangle when clipping is active. x and y are
+ the bottom left coordinates.
\note Be aware of the differences between graphics APIs: for some the
scissor rect is only active when scissoring is enabled (for example,
diff --git a/src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp b/src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp
new file mode 100644
index 0000000000..38d4c4440f
--- /dev/null
+++ b/src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp
@@ -0,0 +1,929 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
+** Copyright (C) 2016 Robin Burchell <robin.burchell@viroteck.net>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgrhivisualizer_p.h"
+#include <qmath.h>
+#include <QQuickWindow>
+#include <private/qsgmaterialrhishader_p.h>
+#include <private/qsgshadersourcebuilder_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QSGBatchRenderer
+{
+
+#define QSGNODE_TRAVERSE(NODE) for (QSGNode *child = NODE->firstChild(); child; child = child->nextSibling())
+#define SHADOWNODE_TRAVERSE(NODE) for (Node *child = NODE->firstChild(); child; child = child->sibling())
+#define QSGNODE_DIRTY_PARENT (QSGNode::DirtyNodeAdded \
+ | QSGNode::DirtyOpacity \
+ | QSGNode::DirtyMatrix \
+ | QSGNode::DirtyNodeRemoved)
+
+QMatrix4x4 qsg_matrixForRoot(Node *node);
+QRhiVertexInputAttribute::Format qsg_vertexInputFormat(const QSGGeometry::Attribute &a);
+QRhiCommandBuffer::IndexFormat qsg_indexFormat(const QSGGeometry *geometry);
+QRhiGraphicsPipeline::Topology qsg_topology(int geomDrawMode);
+
+RhiVisualizer::RhiVisualizer(Renderer *renderer)
+ : Visualizer(renderer)
+{
+}
+
+RhiVisualizer::~RhiVisualizer()
+{
+ releaseResources();
+}
+
+void RhiVisualizer::releaseResources()
+{
+ m_pipelines.releaseResources();
+
+ m_fade.releaseResources();
+
+ m_changeVis.releaseResources();
+ m_batchVis.releaseResources();
+ m_clipVis.releaseResources();
+ m_overdrawVis.releaseResources();
+}
+
+void RhiVisualizer::prepareVisualize()
+{
+ // Called before the render pass has begun (but after preparing the
+ // batches). Now is the time to put resource updates to the renderer's
+ // current m_resourceUpdates instance.
+
+ if (m_visualizeMode == VisualizeNothing)
+ return;
+
+ if (!m_vs.isValid()) {
+ m_vs = QSGMaterialRhiShaderPrivate::loadShader(
+ QLatin1String(":/qt-project.org/scenegraph/shaders_ng/visualization.vert.qsb"));
+ m_fs = QSGMaterialRhiShaderPrivate::loadShader(
+ QLatin1String(":/qt-project.org/scenegraph/shaders_ng/visualization.frag.qsb"));
+ }
+
+ m_fade.prepare(this, m_renderer->m_rhi, m_renderer->m_resourceUpdates, m_renderer->renderPassDescriptor());
+
+ const bool forceUintIndex = m_renderer->m_uint32IndexForRhi;
+
+ switch (m_visualizeMode) {
+ case VisualizeBatches:
+ m_batchVis.prepare(m_renderer->m_opaqueBatches, m_renderer->m_alphaBatches,
+ this,
+ m_renderer->m_rhi, m_renderer->m_resourceUpdates,
+ forceUintIndex);
+ break;
+ case VisualizeClipping:
+ m_clipVis.prepare(m_renderer->rootNode(), this,
+ m_renderer->m_rhi, m_renderer->m_resourceUpdates);
+ break;
+ case VisualizeChanges:
+ m_changeVis.prepare(m_renderer->m_nodes.value(m_renderer->rootNode()),
+ this,
+ m_renderer->m_rhi, m_renderer->m_resourceUpdates);
+ m_visualizeChangeSet.clear();
+ break;
+ case VisualizeOverdraw:
+ m_overdrawVis.prepare(m_renderer->m_nodes.value(m_renderer->rootNode()),
+ this,
+ m_renderer->m_rhi, m_renderer->m_resourceUpdates);
+ break;
+ default:
+ Q_UNREACHABLE();
+ break;
+ }
+}
+
+void RhiVisualizer::visualize()
+{
+ if (m_visualizeMode == VisualizeNothing)
+ return;
+
+ QRhiCommandBuffer *cb = m_renderer->commandBuffer();
+ m_fade.render(cb);
+
+ switch (m_visualizeMode) {
+ case VisualizeBatches:
+ m_batchVis.render(cb);
+ break;
+ case VisualizeClipping:
+ m_clipVis.render(cb);
+ break;
+ case VisualizeChanges:
+ m_changeVis.render(cb);
+ break;
+ case VisualizeOverdraw:
+ m_overdrawVis.render(cb);
+ break;
+ default:
+ Q_UNREACHABLE();
+ break;
+ }
+}
+
+void RhiVisualizer::recordDrawCalls(const QVector<DrawCall> &drawCalls,
+ QRhiCommandBuffer *cb,
+ QRhiShaderResourceBindings *srb,
+ bool blendOneOne)
+{
+ for (const DrawCall &dc : drawCalls) {
+ QRhiGraphicsPipeline *ps = m_pipelines.pipeline(this, m_renderer->m_rhi, srb, m_renderer->renderPassDescriptor(),
+ dc.vertex.topology, dc.vertex.format, dc.vertex.stride,
+ blendOneOne);
+ if (!ps)
+ continue;
+ cb->setGraphicsPipeline(ps); // no-op if same as the last one
+ QRhiCommandBuffer::DynamicOffset dynofs(0, dc.buf.ubufOffset);
+ cb->setShaderResources(srb, 1, &dynofs);
+ QRhiCommandBuffer::VertexInput vb(dc.buf.vbuf, dc.buf.vbufOffset);
+ if (dc.index.count) {
+ cb->setVertexInput(0, 1, &vb, dc.buf.ibuf, dc.buf.ibufOffset, dc.index.format);
+ cb->drawIndexed(dc.index.count);
+ } else {
+ cb->setVertexInput(0, 1, &vb);
+ cb->draw(dc.vertex.count);
+ }
+ }
+}
+
+const QRhiShaderResourceBinding::StageFlags ubufVisibility =
+ QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage;
+
+void RhiVisualizer::Fade::prepare(RhiVisualizer *visualizer,
+ QRhi *rhi, QRhiResourceUpdateBatch *u, QRhiRenderPassDescriptor *rpDesc)
+{
+ this->visualizer = visualizer;
+
+ if (!vbuf) {
+ float v[] = { -1, 1, 1, 1, -1, -1, 1, -1 };
+ vbuf = rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(v));
+ if (!vbuf->build())
+ return;
+ u->uploadStaticBuffer(vbuf, v);
+ }
+
+ if (!ubuf) {
+ ubuf = rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, DrawCall::UBUF_SIZE);
+ if (!ubuf->build())
+ return;
+ float bgOpacity = 0.8f;
+ if (visualizer->m_visualizeMode == Visualizer::VisualizeBatches)
+ bgOpacity = 1.0;
+ QMatrix4x4 ident;
+ u->updateDynamicBuffer(ubuf, 0, 64, ident.constData()); // matrix
+ u->updateDynamicBuffer(ubuf, 64, 64, ident.constData()); // rotation
+ float color[4] = { 0.0f, 0.0f, 0.0f, bgOpacity };
+ u->updateDynamicBuffer(ubuf, 128, 16, color);
+ float pattern = 0.0f;
+ u->updateDynamicBuffer(ubuf, 144, 4, &pattern);
+ qint32 projection = 0;
+ u->updateDynamicBuffer(ubuf, 148, 4, &projection);
+ }
+
+ if (!srb) {
+ srb = rhi->newShaderResourceBindings();
+ srb->setBindings({ QRhiShaderResourceBinding::uniformBuffer(0, ubufVisibility, ubuf) });
+ if (!srb->build())
+ return;
+ }
+
+ if (!ps) {
+ ps = rhi->newGraphicsPipeline();
+ ps->setTopology(QRhiGraphicsPipeline::TriangleStrip);
+ QRhiGraphicsPipeline::TargetBlend blend; // defaults to premul alpha, just what we need
+ blend.enable = true;
+ ps->setTargetBlends({ blend });
+ ps->setShaderStages({ { QRhiShaderStage::Vertex, visualizer->m_vs },
+ { QRhiShaderStage::Fragment, visualizer->m_fs } });
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({ { 2 * sizeof(float) } });
+ inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float2, 0 } });
+ ps->setVertexInputLayout(inputLayout);
+ ps->setShaderResourceBindings(srb);
+ ps->setRenderPassDescriptor(rpDesc);
+ if (!ps->build())
+ return;
+ }
+}
+
+void RhiVisualizer::Fade::releaseResources()
+{
+ delete ps;
+ ps = nullptr;
+
+ delete srb;
+ srb = nullptr;
+
+ delete ubuf;
+ ubuf = nullptr;
+
+ delete vbuf;
+ vbuf = nullptr;
+}
+
+void RhiVisualizer::Fade::render(QRhiCommandBuffer *cb)
+{
+ cb->setGraphicsPipeline(ps);
+ cb->setViewport(visualizer->m_renderer->m_pstate.viewport);
+ cb->setShaderResources();
+ QRhiCommandBuffer::VertexInput vb(vbuf, 0);
+ cb->setVertexInput(0, 1, &vb);
+ cb->draw(4);
+}
+
+static void fillVertexIndex(RhiVisualizer::DrawCall *dc, QSGGeometry *g, bool withData, bool forceUintIndex)
+{
+ dc->vertex.topology = qsg_topology(g->drawingMode());
+ dc->vertex.format = qsg_vertexInputFormat(g->attributes()[0]);
+ dc->vertex.count = g->vertexCount();
+ dc->vertex.stride = g->sizeOfVertex();
+ if (withData)
+ dc->vertex.data = g->vertexData();
+
+ dc->index.format = forceUintIndex ? QRhiCommandBuffer::IndexUInt32 : qsg_indexFormat(g);
+ dc->index.count = g->indexCount();
+ dc->index.stride = forceUintIndex ? sizeof(quint32) : g->sizeOfIndex();
+ if (withData && g->indexCount())
+ dc->index.data = g->indexData();
+}
+
+static inline uint aligned(uint v, uint byteAlign)
+{
+ return (v + byteAlign - 1) & ~(byteAlign - 1);
+}
+
+static bool ensureBuffer(QRhi *rhi, QRhiBuffer **buf, QRhiBuffer::UsageFlags usage, int newSize)
+{
+ if (!*buf) {
+ *buf = rhi->newBuffer(QRhiBuffer::Dynamic, usage, newSize);
+ if (!(*buf)->build())
+ return false;
+ } else if ((*buf)->size() < newSize) {
+ (*buf)->setSize(newSize);
+ if (!(*buf)->build())
+ return false;
+ }
+ return true;
+}
+
+QRhiGraphicsPipeline *RhiVisualizer::PipelineCache::pipeline(RhiVisualizer *visualizer,
+ QRhi *rhi,
+ QRhiShaderResourceBindings *srb,
+ QRhiRenderPassDescriptor *rpDesc,
+ QRhiGraphicsPipeline::Topology topology,
+ QRhiVertexInputAttribute::Format vertexFormat,
+ quint32 vertexStride,
+ bool blendOneOne)
+{
+ for (int i = 0, ie = pipelines.count(); i != ie; ++i) {
+ const Pipeline &p(pipelines.at(i));
+ if (p.topology == topology && p.format == vertexFormat && p.stride == vertexStride)
+ return p.ps;
+ }
+
+ QRhiGraphicsPipeline *ps = rhi->newGraphicsPipeline();
+ ps->setTopology(topology);
+ QRhiGraphicsPipeline::TargetBlend blend; // premul alpha
+ blend.enable = true;
+ if (blendOneOne) {
+ // only for visualizing overdraw, other modes use premul alpha
+ blend.srcColor = QRhiGraphicsPipeline::One;
+ blend.dstColor = QRhiGraphicsPipeline::One;
+ blend.srcAlpha = QRhiGraphicsPipeline::One;
+ blend.dstAlpha = QRhiGraphicsPipeline::One;
+ }
+ ps->setTargetBlends({ blend });
+ ps->setShaderStages({ { QRhiShaderStage::Vertex, visualizer->m_vs },
+ { QRhiShaderStage::Fragment, visualizer->m_fs } });
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({ { vertexStride } });
+ inputLayout.setAttributes({ { 0, 0, vertexFormat, 0 } });
+ ps->setVertexInputLayout(inputLayout);
+ ps->setShaderResourceBindings(srb);
+ ps->setRenderPassDescriptor(rpDesc);
+ if (!ps->build())
+ return nullptr;
+
+ Pipeline p;
+ p.topology = topology;
+ p.format = vertexFormat;
+ p.stride = vertexStride;
+ p.ps = ps;
+ pipelines.append(p);
+
+ return ps;
+}
+
+void RhiVisualizer::PipelineCache::releaseResources()
+{
+ for (int i = 0, ie = pipelines.count(); i != ie; ++i)
+ delete pipelines.at(i).ps;
+
+ pipelines.clear();
+}
+
+void RhiVisualizer::ChangeVis::gather(Node *n)
+{
+ if (n->type() == QSGNode::GeometryNodeType && n->element()->batch && visualizer->m_visualizeChangeSet.contains(n)) {
+ const uint dirty = visualizer->m_visualizeChangeSet.value(n);
+ const bool tinted = (dirty & QSGNODE_DIRTY_PARENT) != 0;
+ const QColor color = QColor::fromHsvF((rand() & 1023) / 1023.0f, 0.3f, 1.0f);
+ const float alpha = 0.5f;
+
+ QMatrix4x4 matrix = visualizer->m_renderer->m_current_projection_matrix;
+ if (n->element()->batch->root)
+ matrix = matrix * qsg_matrixForRoot(n->element()->batch->root);
+
+ QSGGeometryNode *gn = static_cast<QSGGeometryNode *>(n->sgNode);
+ matrix = matrix * *gn->matrix();
+
+ QSGGeometry *g = gn->geometry();
+ if (g->attributeCount() >= 1) {
+ DrawCall dc;
+ memcpy(dc.uniforms.data, matrix.constData(), 64);
+ QMatrix4x4 rotation;
+ memcpy(dc.uniforms.data + 64, rotation.constData(), 64);
+ float c[4] = {
+ float(color.redF()) * alpha,
+ float(color.greenF()) * alpha,
+ float(color.blueF()) * alpha,
+ alpha
+ };
+ memcpy(dc.uniforms.data + 128, c, 16);
+ float pattern = tinted ? 0.5f : 0.0f;
+ memcpy(dc.uniforms.data + 144, &pattern, 4);
+ qint32 projection = 0;
+ memcpy(dc.uniforms.data + 148, &projection, 4);
+
+ fillVertexIndex(&dc, g, true, false);
+ drawCalls.append(dc);
+ }
+
+ // This is because many changes don't propegate their dirty state to the
+ // parent so the node updater will not unset these states. They are
+ // not used for anything so, unsetting it should have no side effects.
+ n->dirtyState = nullptr;
+ }
+
+ SHADOWNODE_TRAVERSE(n) {
+ gather(child);
+ }
+}
+
+void RhiVisualizer::ChangeVis::prepare(Node *n, RhiVisualizer *visualizer,
+ QRhi *rhi, QRhiResourceUpdateBatch *u)
+{
+ this->visualizer = visualizer;
+
+ drawCalls.clear();
+ gather(n);
+
+ if (drawCalls.isEmpty())
+ return;
+
+ const int ubufAlign = rhi->ubufAlignment();
+ int vbufOffset = 0;
+ int ibufOffset = 0;
+ int ubufOffset = 0;
+ for (RhiVisualizer::DrawCall &dc : drawCalls) {
+ dc.buf.vbufOffset = aligned(vbufOffset, 4);
+ vbufOffset = dc.buf.vbufOffset + dc.vertex.count * dc.vertex.stride;
+
+ dc.buf.ibufOffset = aligned(ibufOffset, 4);
+ ibufOffset = dc.buf.ibufOffset + dc.index.count * dc.index.stride;
+
+ dc.buf.ubufOffset = aligned(ubufOffset, ubufAlign);
+ ubufOffset = dc.buf.ubufOffset + DrawCall::UBUF_SIZE;
+ }
+
+ ensureBuffer(rhi, &vbuf, QRhiBuffer::VertexBuffer, vbufOffset);
+ if (ibufOffset)
+ ensureBuffer(rhi, &ibuf, QRhiBuffer::IndexBuffer, ibufOffset);
+ const int ubufSize = ubufOffset;
+ ensureBuffer(rhi, &ubuf, QRhiBuffer::UniformBuffer, ubufSize);
+
+ for (RhiVisualizer::DrawCall &dc : drawCalls) {
+ u->updateDynamicBuffer(vbuf, dc.buf.vbufOffset, dc.vertex.count * dc.vertex.stride, dc.vertex.data);
+ dc.buf.vbuf = vbuf;
+ if (dc.index.count) {
+ u->updateDynamicBuffer(ibuf, dc.buf.ibufOffset, dc.index.count * dc.index.stride, dc.index.data);
+ dc.buf.ibuf = ibuf;
+ }
+ u->updateDynamicBuffer(ubuf, dc.buf.ubufOffset, DrawCall::UBUF_SIZE, dc.uniforms.data);
+ }
+
+ if (!srb) {
+ srb = rhi->newShaderResourceBindings();
+ srb->setBindings({ QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(0, ubufVisibility, ubuf, DrawCall::UBUF_SIZE) });
+ if (!srb->build())
+ return;
+ }
+}
+
+void RhiVisualizer::ChangeVis::releaseResources()
+{
+ delete srb;
+ srb = nullptr;
+
+ delete ubuf;
+ ubuf = nullptr;
+
+ delete ibuf;
+ ibuf = nullptr;
+
+ delete vbuf;
+ vbuf = nullptr;
+}
+
+void RhiVisualizer::ChangeVis::render(QRhiCommandBuffer *cb)
+{
+ visualizer->recordDrawCalls(drawCalls, cb, srb);
+}
+
+void RhiVisualizer::BatchVis::gather(Batch *b)
+{
+ if (b->positionAttribute != 0)
+ return;
+
+ QMatrix4x4 matrix(visualizer->m_renderer->m_current_projection_matrix);
+ if (b->root)
+ matrix = matrix * qsg_matrixForRoot(b->root);
+
+ DrawCall dc;
+
+ QMatrix4x4 rotation;
+ memcpy(dc.uniforms.data + 64, rotation.constData(), 64);
+
+ QColor color = QColor::fromHsvF((rand() & 1023) / 1023.0, 1.0, 1.0);
+
+ float c[4] = {
+ float(color.redF()),
+ float(color.greenF()),
+ float(color.blueF()),
+ 1.0f
+ };
+ memcpy(dc.uniforms.data + 128, c, 16);
+
+ float pattern = b->merged ? 0.0f : 1.0f;
+ memcpy(dc.uniforms.data + 144, &pattern, 4);
+
+ qint32 projection = 0;
+ memcpy(dc.uniforms.data + 148, &projection, 4);
+
+ if (b->merged) {
+ memcpy(dc.uniforms.data, matrix.constData(), 64);
+
+ QSGGeometryNode *gn = b->first->node;
+ QSGGeometry *g = gn->geometry();
+
+ fillVertexIndex(&dc, g, false, forceUintIndex);
+
+ for (int ds = 0; ds < b->drawSets.size(); ++ds) {
+ const DrawSet &set = b->drawSets.at(ds);
+ dc.buf.vbuf = b->vbo.buf;
+ dc.buf.vbufOffset = set.vertices;
+ dc.buf.ibuf = b->ibo.buf;
+ dc.buf.ibufOffset = set.indices;
+ dc.index.count = set.indexCount;
+ drawCalls.append(dc);
+ }
+ } else {
+ Element *e = b->first;
+ int vOffset = 0;
+ int iOffset = 0;
+
+ while (e) {
+ QSGGeometryNode *gn = e->node;
+ QSGGeometry *g = gn->geometry();
+
+ QMatrix4x4 m = matrix * *gn->matrix();
+ memcpy(dc.uniforms.data, m.constData(), 64);
+
+ fillVertexIndex(&dc, g, false, forceUintIndex);
+
+ dc.buf.vbuf = b->vbo.buf;
+ dc.buf.vbufOffset = vOffset;
+ if (g->indexCount()) {
+ dc.buf.ibuf = b->ibo.buf;
+ dc.buf.ibufOffset = iOffset;
+ }
+
+ drawCalls.append(dc);
+
+ vOffset += dc.vertex.count * dc.vertex.stride;
+ iOffset += dc.index.count * dc.index.stride;
+
+ e = e->nextInBatch;
+ }
+ }
+}
+
+void RhiVisualizer::BatchVis::prepare(const QDataBuffer<Batch *> &opaqueBatches, const QDataBuffer<Batch *> &alphaBatches,
+ RhiVisualizer *visualizer,
+ QRhi *rhi, QRhiResourceUpdateBatch *u,
+ bool forceUintIndex)
+{
+ this->visualizer = visualizer;
+ this->forceUintIndex = forceUintIndex;
+
+ drawCalls.clear();
+
+ srand(0); // To force random colors to be roughly the same every time..
+ for (int i = 0; i < opaqueBatches.size(); ++i)
+ gather(opaqueBatches.at(i));
+ for (int i = 0; i < alphaBatches.size(); ++i)
+ gather(alphaBatches.at(i));
+
+ if (drawCalls.isEmpty())
+ return;
+
+ const int ubufAlign = rhi->ubufAlignment();
+ int ubufOffset = 0;
+ for (RhiVisualizer::DrawCall &dc : drawCalls) {
+ dc.buf.ubufOffset = aligned(ubufOffset, ubufAlign);
+ ubufOffset = dc.buf.ubufOffset + DrawCall::UBUF_SIZE;
+ }
+
+ const int ubufSize = ubufOffset;
+ ensureBuffer(rhi, &ubuf, QRhiBuffer::UniformBuffer, ubufSize);
+
+ for (RhiVisualizer::DrawCall &dc : drawCalls)
+ u->updateDynamicBuffer(ubuf, dc.buf.ubufOffset, DrawCall::UBUF_SIZE, dc.uniforms.data);
+
+ if (!srb) {
+ srb = rhi->newShaderResourceBindings();
+ srb->setBindings({ QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(0, ubufVisibility, ubuf, DrawCall::UBUF_SIZE) });
+ if (!srb->build())
+ return;
+ }
+}
+
+void RhiVisualizer::BatchVis::releaseResources()
+{
+ delete srb;
+ srb = nullptr;
+
+ delete ubuf;
+ ubuf = nullptr;
+}
+
+void RhiVisualizer::BatchVis::render(QRhiCommandBuffer *cb)
+{
+ visualizer->recordDrawCalls(drawCalls, cb, srb);
+}
+
+void RhiVisualizer::ClipVis::gather(QSGNode *node)
+{
+ if (node->type() == QSGNode::ClipNodeType) {
+ QSGClipNode *clipNode = static_cast<QSGClipNode *>(node);
+ QMatrix4x4 matrix = visualizer->m_renderer->m_current_projection_matrix;
+ if (clipNode->matrix())
+ matrix = matrix * *clipNode->matrix();
+
+ QSGGeometry *g = clipNode->geometry();
+ if (g->attributeCount() >= 1) {
+ DrawCall dc;
+ memcpy(dc.uniforms.data, matrix.constData(), 64);
+ QMatrix4x4 rotation;
+ memcpy(dc.uniforms.data + 64, rotation.constData(), 64);
+ float c[4] = { 0.2f, 0.0f, 0.0f, 0.2f };
+ memcpy(dc.uniforms.data + 128, c, 16);
+ float pattern = 0.5f;
+ memcpy(dc.uniforms.data + 144, &pattern, 4);
+ qint32 projection = 0;
+ memcpy(dc.uniforms.data + 148, &projection, 4);
+ fillVertexIndex(&dc, g, true, false);
+ drawCalls.append(dc);
+ }
+ }
+
+ QSGNODE_TRAVERSE(node) {
+ gather(child);
+ }
+}
+
+void RhiVisualizer::ClipVis::prepare(QSGNode *node, RhiVisualizer *visualizer,
+ QRhi *rhi, QRhiResourceUpdateBatch *u)
+{
+ this->visualizer = visualizer;
+
+ drawCalls.clear();
+ gather(node);
+
+ if (drawCalls.isEmpty())
+ return;
+
+ const int ubufAlign = rhi->ubufAlignment();
+ int vbufOffset = 0;
+ int ibufOffset = 0;
+ int ubufOffset = 0;
+ for (RhiVisualizer::DrawCall &dc : drawCalls) {
+ dc.buf.vbufOffset = aligned(vbufOffset, 4);
+ vbufOffset = dc.buf.vbufOffset + dc.vertex.count * dc.vertex.stride;
+
+ dc.buf.ibufOffset = aligned(ibufOffset, 4);
+ ibufOffset = dc.buf.ibufOffset + dc.index.count * dc.index.stride;
+
+ dc.buf.ubufOffset = aligned(ubufOffset, ubufAlign);
+ ubufOffset = dc.buf.ubufOffset + DrawCall::UBUF_SIZE;
+ }
+
+ ensureBuffer(rhi, &vbuf, QRhiBuffer::VertexBuffer, vbufOffset);
+ if (ibufOffset)
+ ensureBuffer(rhi, &ibuf, QRhiBuffer::IndexBuffer, ibufOffset);
+ const int ubufSize = ubufOffset;
+ ensureBuffer(rhi, &ubuf, QRhiBuffer::UniformBuffer, ubufSize);
+
+ for (RhiVisualizer::DrawCall &dc : drawCalls) {
+ u->updateDynamicBuffer(vbuf, dc.buf.vbufOffset, dc.vertex.count * dc.vertex.stride, dc.vertex.data);
+ dc.buf.vbuf = vbuf;
+ if (dc.index.count) {
+ u->updateDynamicBuffer(ibuf, dc.buf.ibufOffset, dc.index.count * dc.index.stride, dc.index.data);
+ dc.buf.ibuf = ibuf;
+ }
+ u->updateDynamicBuffer(ubuf, dc.buf.ubufOffset, DrawCall::UBUF_SIZE, dc.uniforms.data);
+ }
+
+ if (!srb) {
+ srb = rhi->newShaderResourceBindings();
+ srb->setBindings({ QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(0, ubufVisibility, ubuf, DrawCall::UBUF_SIZE) });
+ if (!srb->build())
+ return;
+ }
+}
+
+void RhiVisualizer::ClipVis::releaseResources()
+{
+ delete srb;
+ srb = nullptr;
+
+ delete ubuf;
+ ubuf = nullptr;
+
+ delete ibuf;
+ ibuf = nullptr;
+
+ delete vbuf;
+ vbuf = nullptr;
+}
+
+void RhiVisualizer::ClipVis::render(QRhiCommandBuffer *cb)
+{
+ visualizer->recordDrawCalls(drawCalls, cb, srb);
+}
+
+void RhiVisualizer::OverdrawVis::gather(Node *n)
+{
+ if (n->type() == QSGNode::GeometryNodeType && n->element()->batch) {
+ QMatrix4x4 matrix = visualizer->m_renderer->m_current_projection_matrix;
+ matrix(2, 2) = visualizer->m_renderer->m_zRange;
+ matrix(2, 3) = 1.0f - n->element()->order * visualizer->m_renderer->m_zRange;
+
+ if (n->element()->batch->root)
+ matrix = matrix * qsg_matrixForRoot(n->element()->batch->root);
+
+ QSGGeometryNode *gn = static_cast<QSGGeometryNode *>(n->sgNode);
+ matrix = matrix * *gn->matrix();
+
+ QSGGeometry *g = gn->geometry();
+ if (g->attributeCount() >= 1) {
+ DrawCall dc;
+ memcpy(dc.uniforms.data, matrix.constData(), 64);
+ memcpy(dc.uniforms.data + 64, rotation.constData(), 64);
+
+ float c[4];
+ const float ca = 0.33f;
+ if (n->element()->batch->isOpaque) {
+ c[0] = ca * 0.3f; c[1] = ca * 1.0f; c[2] = ca * 0.3f; c[3] = ca;
+ } else {
+ c[0] = ca * 1.0f; c[1] = ca * 0.3f; c[2] = ca * 0.3f; c[3] = ca;
+ }
+ memcpy(dc.uniforms.data + 128, c, 16);
+ float pattern = 0.0f;
+ memcpy(dc.uniforms.data + 144, &pattern, 4);
+ qint32 projection = 1;
+ memcpy(dc.uniforms.data + 148, &projection, 4);
+
+ fillVertexIndex(&dc, g, true, false);
+ drawCalls.append(dc);
+ }
+ }
+
+ SHADOWNODE_TRAVERSE(n) {
+ gather(child);
+ }
+}
+
+void RhiVisualizer::OverdrawVis::prepare(Node *n, RhiVisualizer *visualizer,
+ QRhi *rhi, QRhiResourceUpdateBatch *u)
+{
+ this->visualizer = visualizer;
+
+ step += float(M_PI * 2 / 1000.0);
+ if (step > float(M_PI * 2))
+ step = 0.0f;
+
+ const float yfix = rhi->isYUpInNDC() ? 1.0f : -1.0f;
+ rotation.setToIdentity();
+ rotation.translate(0.0f, 0.5f * yfix, 4.0f);
+ rotation.scale(2.0f, 2.0f, 1.0f);
+ rotation.rotate(-30.0f * yfix, 1.0f, 0.0f, 0.0f);
+ rotation.rotate(80.0f * std::sin(step), 0.0f, 1.0f, 0.0f);
+ rotation.translate(0.0f, 0.0f, -1.0f);
+
+ drawCalls.clear();
+ gather(n);
+
+ if (!box.vbuf) {
+ const float v[] = {
+ // lower
+ -1, 1, 0, 1, 1, 0,
+ -1, 1, 0, -1, -1, 0,
+ 1, 1, 0, 1, -1, 0,
+ -1, -1, 0, 1, -1, 0,
+
+ // upper
+ -1, 1, 1, 1, 1, 1,
+ -1, 1, 1, -1, -1, 1,
+ 1, 1, 1, 1, -1, 1,
+ -1, -1, 1, 1, -1, 1,
+
+ // sides
+ -1, -1, 0, -1, -1, 1,
+ 1, -1, 0, 1, -1, 1,
+ -1, 1, 0, -1, 1, 1,
+ 1, 1, 0, 1, 1, 1
+ };
+ box.vbuf = rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(v));
+ if (!box.vbuf->build())
+ return;
+ u->uploadStaticBuffer(box.vbuf, v);
+ }
+
+ if (!box.ubuf) {
+ box.ubuf = rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, DrawCall::UBUF_SIZE);
+ if (!box.ubuf->build())
+ return;
+ QMatrix4x4 ident;
+ u->updateDynamicBuffer(box.ubuf, 0, 64, ident.constData());
+ float color[4] = { 0.5f, 0.5f, 1.0f, 1.0f };
+ u->updateDynamicBuffer(box.ubuf, 128, 16, color);
+ float pattern = 0.0f;
+ u->updateDynamicBuffer(box.ubuf, 144, 4, &pattern);
+ qint32 projection = 1;
+ u->updateDynamicBuffer(box.ubuf, 148, 4, &projection);
+ }
+
+ u->updateDynamicBuffer(box.ubuf, 64, 64, rotation.constData());
+
+ if (!box.srb) {
+ box.srb = rhi->newShaderResourceBindings();
+ box.srb->setBindings({ QRhiShaderResourceBinding::uniformBuffer(0, ubufVisibility, box.ubuf) });
+ if (!box.srb->build())
+ return;
+ }
+
+ if (!box.ps) {
+ box.ps = rhi->newGraphicsPipeline();
+ box.ps->setTopology(QRhiGraphicsPipeline::Lines);
+ box.ps->setLineWidth(2); // may be be ignored (D3D, Metal), but may be used on GL and Vulkan
+ QRhiGraphicsPipeline::TargetBlend blend;
+ blend.enable = true;
+ blend.srcColor = QRhiGraphicsPipeline::One;
+ blend.dstColor = QRhiGraphicsPipeline::One;
+ blend.srcAlpha = QRhiGraphicsPipeline::One;
+ blend.dstAlpha = QRhiGraphicsPipeline::One;
+ box.ps->setTargetBlends({ blend });
+ box.ps->setShaderStages({ { QRhiShaderStage::Vertex, visualizer->m_vs },
+ { QRhiShaderStage::Fragment, visualizer->m_fs } });
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({ { 3 * sizeof(float) } });
+ inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float3, 0 } });
+ box.ps->setVertexInputLayout(inputLayout);
+ box.ps->setShaderResourceBindings(box.srb);
+ box.ps->setRenderPassDescriptor(visualizer->m_renderer->renderPassDescriptor());
+ if (!box.ps->build())
+ return;
+ }
+
+ if (drawCalls.isEmpty())
+ return;
+
+ const int ubufAlign = rhi->ubufAlignment();
+ int vbufOffset = 0;
+ int ibufOffset = 0;
+ int ubufOffset = 0;
+ for (RhiVisualizer::DrawCall &dc : drawCalls) {
+ dc.buf.vbufOffset = aligned(vbufOffset, 4);
+ vbufOffset = dc.buf.vbufOffset + dc.vertex.count * dc.vertex.stride;
+
+ dc.buf.ibufOffset = aligned(ibufOffset, 4);
+ ibufOffset = dc.buf.ibufOffset + dc.index.count * dc.index.stride;
+
+ dc.buf.ubufOffset = aligned(ubufOffset, ubufAlign);
+ ubufOffset = dc.buf.ubufOffset + DrawCall::UBUF_SIZE;
+ }
+
+ ensureBuffer(rhi, &vbuf, QRhiBuffer::VertexBuffer, vbufOffset);
+ if (ibufOffset)
+ ensureBuffer(rhi, &ibuf, QRhiBuffer::IndexBuffer, ibufOffset);
+ const int ubufSize = ubufOffset;
+ ensureBuffer(rhi, &ubuf, QRhiBuffer::UniformBuffer, ubufSize);
+
+ for (RhiVisualizer::DrawCall &dc : drawCalls) {
+ u->updateDynamicBuffer(vbuf, dc.buf.vbufOffset, dc.vertex.count * dc.vertex.stride, dc.vertex.data);
+ dc.buf.vbuf = vbuf;
+ if (dc.index.count) {
+ u->updateDynamicBuffer(ibuf, dc.buf.ibufOffset, dc.index.count * dc.index.stride, dc.index.data);
+ dc.buf.ibuf = ibuf;
+ }
+ u->updateDynamicBuffer(ubuf, dc.buf.ubufOffset, DrawCall::UBUF_SIZE, dc.uniforms.data);
+ }
+
+ if (!srb) {
+ srb = rhi->newShaderResourceBindings();
+ srb->setBindings({ QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(0, ubufVisibility, ubuf, DrawCall::UBUF_SIZE) });
+ if (!srb->build())
+ return;
+ }
+}
+
+void RhiVisualizer::OverdrawVis::releaseResources()
+{
+ delete srb;
+ srb = nullptr;
+
+ delete ubuf;
+ ubuf = nullptr;
+
+ delete ibuf;
+ ibuf = nullptr;
+
+ delete vbuf;
+ vbuf = nullptr;
+
+ delete box.ps;
+ box.ps = nullptr;
+
+ delete box.srb;
+ box.srb = nullptr;
+
+ delete box.ubuf;
+ box.ubuf = nullptr;
+
+ delete box.vbuf;
+ box.vbuf = nullptr;
+}
+
+void RhiVisualizer::OverdrawVis::render(QRhiCommandBuffer *cb)
+{
+ cb->setGraphicsPipeline(box.ps);
+ cb->setShaderResources();
+ QRhiCommandBuffer::VertexInput vb(box.vbuf, 0);
+ cb->setVertexInput(0, 1, &vb);
+ cb->draw(24);
+
+ visualizer->recordDrawCalls(drawCalls, cb, srb, true);
+}
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/coreapi/qsgrhivisualizer_p.h b/src/quick/scenegraph/coreapi/qsgrhivisualizer_p.h
new file mode 100644
index 0000000000..1ce52a81f1
--- /dev/null
+++ b/src/quick/scenegraph/coreapi/qsgrhivisualizer_p.h
@@ -0,0 +1,233 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
+** Copyright (C) 2016 Robin Burchell <robin.burchell@viroteck.net>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGRHIVISUALIZER_P_H
+#define QSGRHIVISUALIZER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qsgbatchrenderer_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace QSGBatchRenderer
+{
+
+class RhiVisualizer : public Visualizer
+{
+public:
+ RhiVisualizer(Renderer *renderer);
+ ~RhiVisualizer();
+
+ void prepareVisualize() override;
+ void visualize() override;
+
+ void releaseResources() override;
+
+ struct DrawCall
+ {
+ static const int UBUF_SIZE = 152; // visualization.vert/frag
+ struct {
+ char data[UBUF_SIZE]; // matrix, rotation, color, pattern, projection
+ } uniforms;
+ struct {
+ QRhiGraphicsPipeline::Topology topology;
+ QRhiVertexInputAttribute::Format format;
+ int count;
+ int stride;
+ const void *data; // only when using own vbuf
+ } vertex;
+ struct {
+ QRhiCommandBuffer::IndexFormat format;
+ int count;
+ int stride;
+ const void *data; // only when using own ibuf
+ } index;
+ struct {
+ QRhiBuffer *vbuf; // either same for all draw calls and owned by the *Vis, or points to a Batch.Buffer.vbo.buf
+ int vbufOffset;
+ QRhiBuffer *ibuf; // same, but for index
+ int ibufOffset;
+ int ubufOffset;
+ } buf;
+ };
+
+private:
+ QShader m_vs;
+ QShader m_fs;
+
+ void recordDrawCalls(const QVector<DrawCall> &drawCalls,
+ QRhiCommandBuffer *cb,
+ QRhiShaderResourceBindings *srb,
+ bool blendOneOne = false);
+
+ class PipelineCache {
+ public:
+ QRhiGraphicsPipeline *pipeline(RhiVisualizer *visualizer,
+ QRhi *rhi,
+ QRhiShaderResourceBindings *srb,
+ QRhiRenderPassDescriptor *rpDesc,
+ QRhiGraphicsPipeline::Topology topology,
+ QRhiVertexInputAttribute::Format vertexFormat,
+ quint32 vertexStride,
+ bool blendOneOne);
+ void releaseResources();
+ private:
+ struct Pipeline {
+ QRhiGraphicsPipeline::Topology topology;
+ QRhiVertexInputAttribute::Format format;
+ quint32 stride;
+ QRhiGraphicsPipeline *ps;
+ };
+ QVarLengthArray<Pipeline, 16> pipelines;
+ };
+
+ PipelineCache m_pipelines;
+
+ class Fade {
+ public:
+ void prepare(RhiVisualizer *visualizer,
+ QRhi *rhi, QRhiResourceUpdateBatch *u, QRhiRenderPassDescriptor *rpDesc);
+ void releaseResources();
+ void render(QRhiCommandBuffer *cb);
+ private:
+ RhiVisualizer *visualizer;
+ QRhiBuffer *vbuf = nullptr;
+ QRhiBuffer *ubuf = nullptr;
+ QRhiGraphicsPipeline *ps = nullptr;
+ QRhiShaderResourceBindings *srb = nullptr;
+ } m_fade;
+
+ class ChangeVis {
+ public:
+ void prepare(Node *n, RhiVisualizer *visualizer,
+ QRhi *rhi, QRhiResourceUpdateBatch *u);
+ void releaseResources();
+ void render(QRhiCommandBuffer *cb);
+ private:
+ void gather(Node *n);
+ RhiVisualizer *visualizer;
+ QVector<DrawCall> drawCalls;
+ QRhiBuffer *vbuf = nullptr;
+ QRhiBuffer *ibuf = nullptr;
+ QRhiBuffer *ubuf = nullptr;
+ QRhiShaderResourceBindings *srb = nullptr;
+ } m_changeVis;
+
+ class BatchVis {
+ public:
+ void prepare(const QDataBuffer<Batch *> &opaqueBatches,
+ const QDataBuffer<Batch *> &alphaBatches,
+ RhiVisualizer *visualizer,
+ QRhi *rhi, QRhiResourceUpdateBatch *u,
+ bool forceUintIndex);
+ void releaseResources();
+ void render(QRhiCommandBuffer *cb);
+ private:
+ void gather(Batch *b);
+ RhiVisualizer *visualizer;
+ bool forceUintIndex;
+ QVector<DrawCall> drawCalls;
+ QRhiBuffer *ubuf = nullptr;
+ QRhiShaderResourceBindings *srb = nullptr;
+ } m_batchVis;
+
+ class ClipVis {
+ public:
+ void prepare(QSGNode *node, RhiVisualizer *visualizer,
+ QRhi *rhi, QRhiResourceUpdateBatch *u);
+ void releaseResources();
+ void render(QRhiCommandBuffer *cb);
+ private:
+ void gather(QSGNode *node);
+ RhiVisualizer *visualizer;
+ QVector<DrawCall> drawCalls;
+ QRhiBuffer *vbuf = nullptr;
+ QRhiBuffer *ibuf = nullptr;
+ QRhiBuffer *ubuf = nullptr;
+ QRhiShaderResourceBindings *srb = nullptr;
+ } m_clipVis;
+
+ class OverdrawVis {
+ public:
+ void prepare(Node *n, RhiVisualizer *visualizer,
+ QRhi *rhi, QRhiResourceUpdateBatch *u);
+ void releaseResources();
+ void render(QRhiCommandBuffer *cb);
+ private:
+ void gather(Node *n);
+ RhiVisualizer *visualizer;
+ QVector<DrawCall> drawCalls;
+ QRhiBuffer *vbuf = nullptr;
+ QRhiBuffer *ibuf = nullptr;
+ QRhiBuffer *ubuf = nullptr;
+ QRhiShaderResourceBindings *srb = nullptr;
+ float step = 0.0f;
+ QMatrix4x4 rotation;
+ struct {
+ QRhiBuffer *vbuf = nullptr;
+ QRhiBuffer *ubuf = nullptr;
+ QRhiShaderResourceBindings *srb = nullptr;
+ QRhiGraphicsPipeline *ps = nullptr;
+ } box;
+ } m_overdrawVis;
+
+ friend class Fade;
+ friend class PipelineCache;
+ friend class ChangeVis;
+ friend class ClipVis;
+ friend class OverdrawVis;
+};
+
+} // namespace QSGBatchRenderer
+
+QT_END_NAMESPACE
+
+#endif // QSGRHIVISUALIZER_P_H
diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/coreapi/qsgtexture.cpp
index 042eee19f5..edcee96bdb 100644
--- a/src/quick/scenegraph/util/qsgtexture.cpp
+++ b/src/quick/scenegraph/coreapi/qsgtexture.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -38,21 +38,13 @@
****************************************************************************/
#include "qsgtexture_p.h"
-#include <QtQuick/private/qsgcontext_p.h>
-#include <qthread.h>
-#include <qmath.h>
-#include <private/qquickprofiler_p.h>
-#include <private/qqmlglobal_p.h>
-#include <QtGui/qguiapplication.h>
-#include <QtGui/qpa/qplatformnativeinterface.h>
#if QT_CONFIG(opengl)
-# include <qopenglfunctions.h>
# include <QtGui/qopenglcontext.h>
# include <QtGui/qopenglfunctions.h>
-# include <QtGui/private/qopengltextureuploader_p.h>
-# include <private/qsgdefaultrendercontext_p.h>
#endif
+#include <private/qqmlglobal_p.h>
#include <private/qsgmaterialshader_p.h>
+#include <QtGui/private/qrhi_p.h>
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) && defined(__GLIBC__)
#define CAN_BACKTRACE_EXECINFO
@@ -71,32 +63,55 @@
#include <QHash>
#endif
-#if QT_CONFIG(opengl)
-static QElapsedTimer qsg_renderer_timer;
-#endif
-
#ifndef QT_NO_DEBUG
static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK");
#endif
+QT_BEGIN_NAMESPACE
-#ifndef GL_BGRA
-#define GL_BGRA 0x80E1
-#endif
+bool operator==(const QSGSamplerDescription &a, const QSGSamplerDescription &b) Q_DECL_NOTHROW
+{
+ return a.filtering == b.filtering
+ && a.mipmapFiltering == b.mipmapFiltering
+ && a.horizontalWrap == b.horizontalWrap
+ && a.verticalWrap == b.verticalWrap
+ && a.anisotropylevel == b.anisotropylevel;
+}
-#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
-#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
-#endif
+bool operator!=(const QSGSamplerDescription &a, const QSGSamplerDescription &b) Q_DECL_NOTHROW
+{
+ return !(a == b);
+}
-QT_BEGIN_NAMESPACE
+uint qHash(const QSGSamplerDescription &s, uint seed) Q_DECL_NOTHROW
+{
+ const int f = s.filtering;
+ const int m = s.mipmapFiltering;
+ const int w = s.horizontalWrap;
+ const int a = s.anisotropylevel;
+ return (((f & 7) << 24) | ((m & 7) << 16) | ((w & 7) << 8) | (a & 7)) ^ seed;
+}
-#if QT_CONFIG(opengl) && !defined(QT_NO_DEBUG)
+QSGSamplerDescription QSGSamplerDescription::fromTexture(QSGTexture *t)
+{
+ QSGSamplerDescription s;
+ s.filtering = t->filtering();
+ s.mipmapFiltering = t->mipmapFiltering();
+ s.horizontalWrap = t->horizontalWrapMode();
+ s.verticalWrap = t->verticalWrapMode();
+ s.anisotropylevel = t->anisotropyLevel();
+ return s;
+}
+
+#if QT_CONFIG(opengl)
+#ifndef QT_NO_DEBUG
inline static bool isPowerOfTwo(int x)
{
// Assumption: x >= 1
return x == (x & -x);
}
#endif
+#endif
QSGTexturePrivate::QSGTexturePrivate()
: wrapChanged(false)
@@ -302,10 +317,9 @@ static void qt_debug_remove_texture(QSGTexture* texture)
\since 5.9
*/
-/*!
- \fn QSGTexture::QSGTexture(QSGTexturePrivate &dd)
- \internal
- */
+#ifndef QT_NO_DEBUG
+Q_QUICK_PRIVATE_EXPORT void qsg_set_material_failure();
+#endif
#ifndef QT_NO_DEBUG
Q_GLOBAL_STATIC(QSet<QSGTexture *>, qsg_valid_texture_set)
@@ -344,6 +358,21 @@ QSGTexture::QSGTexture()
}
/*!
+ \internal
+ */
+QSGTexture::QSGTexture(QSGTexturePrivate &dd)
+ : QObject(dd)
+{
+#ifndef QT_NO_DEBUG
+ if (qsg_leak_check)
+ qt_debug_add_texture(this);
+
+ QMutexLocker locker(qsg_valid_texture_mutex());
+ qsg_valid_texture_set()->insert(this);
+#endif
+}
+
+/*!
Destroys the QSGTexture.
*/
QSGTexture::~QSGTexture()
@@ -357,7 +386,6 @@ QSGTexture::~QSGTexture()
#endif
}
-
/*!
\fn void QSGTexture::bind()
@@ -389,7 +417,7 @@ QSGTexture::~QSGTexture()
it to a shader that operates on the texture coordinates 0-1 instead
of the texture subrect inside the atlas.
- If the texture is not part of a texture atlas, this function returns \nullptr.
+ If the texture is not part of a texture atlas, this function returns 0.
Implementations of this function are recommended to return the same instance
for multiple calls to limit memory usage.
@@ -426,6 +454,34 @@ bool QSGTexture::isAtlasTexture() const
*/
/*!
+ Returns a key suitable for comparing textures. Typically used in
+ QSGMaterial::compare() implementations.
+
+ Just comparing QSGTexture pointers is not always sufficient because two
+ QSGTexture instances that refer to the same native texture object
+ underneath should also be considered equal. Hence this function.
+
+ \note Unlike textureId(), implementations of this function are not expected
+ to and should not create any graphics resources (so texture objects) in
+ case there is none yet.
+
+ A QSGTexture that does not have a native texture object underneath is
+ typically not equal to any other QSGTexture. There are exceptions to this,
+ in particular when atlasing is used (where multiple textures share the same
+ atlas texture under the hood), that is then up to the subclass
+ implementations to deal with as appropriate.
+
+ \warning This function can only be called from the rendering thread.
+
+ \since 5.14
+ */
+int QSGTexture::comparisonKey() const
+{
+ Q_D(const QSGTexture);
+ return d->comparisonKey();
+}
+
+/*!
\fn QSize QSGTexture::textureSize() const
Returns the size of the texture.
@@ -579,7 +635,7 @@ QSGTexture::WrapMode QSGTexture::verticalWrapMode() const
If \a force is true, all properties will be updated regardless of weither
they have changed or not.
*/
-void QSGTexture::updateBindOptions(bool force)
+void QSGTexture::updateBindOptions(bool force) // legacy (GL-only)
{
#if QT_CONFIG(opengl)
Q_D(QSGTexture);
@@ -639,185 +695,82 @@ void QSGTexture::updateBindOptions(bool force)
#endif
}
-QSGPlainTexture::QSGPlainTexture()
- : QSGTexture()
- , m_texture_id(0)
- , m_has_alpha(false)
- , m_dirty_texture(false)
- , m_dirty_bind_options(false)
- , m_owns_texture(true)
- , m_mipmaps_generated(false)
- , m_retain_image(false)
-{
-}
+/*!
+ Call this function to enqueue image upload operations to \a
+ resourceUpdates, in case there are any pending ones. When there is no new
+ data (for example, because there was no setImage() since the last call to
+ this function), the function does nothing.
+ Materials involving textures are expected to call this function from their
+ updateSampledImage() implementation, typically without any conditions.
-QSGPlainTexture::~QSGPlainTexture()
+ \note This function is only used when running the graphics API independent
+ rendering path of the scene graph.
+
+ \warning This function can only be called from the rendering thread.
+
+ \since 5.14
+ */
+void QSGTexture::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
{
-#if QT_CONFIG(opengl)
- if (m_texture_id && m_owns_texture && QOpenGLContext::currentContext())
- QOpenGLContext::currentContext()->functions()->glDeleteTextures(1, &m_texture_id);
-#endif
+ Q_D(QSGTexture);
+ d->updateRhiTexture(rhi, resourceUpdates);
}
-void QSGPlainTexture::setImage(const QImage &image)
+/*!
+ \internal
+ */
+void QSGTexture::setWorkResourceUpdateBatch(QRhiResourceUpdateBatch *resourceUpdates)
{
- m_image = image;
- m_texture_size = image.size();
- m_has_alpha = image.hasAlphaChannel();
- m_dirty_texture = true;
- m_dirty_bind_options = true;
- m_mipmaps_generated = false;
- }
+ Q_D(QSGTexture);
+ d->workResourceUpdateBatch = resourceUpdates;
+}
-int QSGPlainTexture::textureId() const
+bool QSGTexturePrivate::hasDirtySamplerOptions() const
{
- if (m_dirty_texture) {
- if (m_image.isNull()) {
- // The actual texture and id will be updated/deleted in a later bind()
- // or ~QSGPlainTexture so just keep it minimal here.
- return 0;
- } else if (m_texture_id == 0){
-#if QT_CONFIG(opengl)
- // Generate a texture id for use later and return it.
- QOpenGLContext::currentContext()->functions()->glGenTextures(1, &const_cast<QSGPlainTexture *>(this)->m_texture_id);
-#endif
- return m_texture_id;
- }
- }
- return m_texture_id;
+ return wrapChanged || filteringChanged || anisotropyChanged;
}
-void QSGPlainTexture::setTextureId(int id)
+void QSGTexturePrivate::resetDirtySamplerOptions()
{
-#if QT_CONFIG(opengl)
- if (m_texture_id && m_owns_texture)
- QOpenGLContext::currentContext()->functions()->glDeleteTextures(1, &m_texture_id);
-#endif
-
- m_texture_id = id;
- m_dirty_texture = false;
- m_dirty_bind_options = true;
- m_image = QImage();
- m_mipmaps_generated = false;
+ wrapChanged = filteringChanged = anisotropyChanged = false;
}
-void QSGPlainTexture::bind()
+int QSGTexturePrivate::comparisonKey() const
{
-#if QT_CONFIG(opengl)
- QOpenGLContext *context = QOpenGLContext::currentContext();
- QOpenGLFunctions *funcs = context->functions();
- if (!m_dirty_texture) {
- funcs->glBindTexture(GL_TEXTURE_2D, m_texture_id);
- if (mipmapFiltering() != QSGTexture::None && !m_mipmaps_generated) {
- funcs->glGenerateMipmap(GL_TEXTURE_2D);
- m_mipmaps_generated = true;
- }
- updateBindOptions(m_dirty_bind_options);
- m_dirty_bind_options = false;
- return;
- }
-
- m_dirty_texture = false;
-
- bool profileFrames = QSG_LOG_TIME_TEXTURE().isDebugEnabled();
- if (profileFrames)
- qsg_renderer_timer.start();
- Q_QUICK_SG_PROFILE_START_SYNCHRONIZED(QQuickProfiler::SceneGraphTexturePrepare,
- QQuickProfiler::SceneGraphTextureDeletion);
-
-
- if (m_image.isNull()) {
- if (m_texture_id && m_owns_texture) {
- funcs->glDeleteTextures(1, &m_texture_id);
- qCDebug(QSG_LOG_TIME_TEXTURE, "plain texture deleted in %dms - %dx%d",
- (int) qsg_renderer_timer.elapsed(),
- m_texture_size.width(),
- m_texture_size.height());
- Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphTextureDeletion,
- QQuickProfiler::SceneGraphTextureDeletionDelete);
- }
- m_texture_id = 0;
- m_texture_size = QSize();
- m_has_alpha = false;
-
- return;
- }
-
- if (m_texture_id == 0)
- funcs->glGenTextures(1, &m_texture_id);
- funcs->glBindTexture(GL_TEXTURE_2D, m_texture_id);
-
- qint64 bindTime = 0;
- if (profileFrames)
- bindTime = qsg_renderer_timer.nsecsElapsed();
- Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphTexturePrepare,
- QQuickProfiler::SceneGraphTexturePrepareBind);
-
- // ### TODO: check for out-of-memory situations...
-
- QOpenGLTextureUploader::BindOptions options = QOpenGLTextureUploader::PremultipliedAlphaBindOption;
-
- // Downscale the texture to fit inside the max texture limit if it is too big.
- // It would be better if the image was already downscaled to the right size,
- // but this information is not always available at that time, so as a last
- // resort we can do it here. Texture coordinates are normalized, so it
- // won't cause any problems and actual texture sizes will be written
- // based on QSGTexture::textureSize which is updated after this, so that
- // should be ok.
- int max;
- if (auto rc = QSGDefaultRenderContext::from(context))
- max = rc->maxTextureSize();
- else
- funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
-
- m_texture_size = m_texture_size.boundedTo(QSize(max, max));
-
- // Scale to a power of two size if mipmapping is requested and the
- // texture is npot and npot textures are not properly supported.
- if (mipmapFiltering() != QSGTexture::None
- && !funcs->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)) {
- options |= QOpenGLTextureUploader::PowerOfTwoBindOption;
- }
-
- updateBindOptions(m_dirty_bind_options);
+ // Must be overridden in subclasses but we cannot make this pure virtual
+ // before Qt 6 because the simple QSGTexture ctor must be kept working.
+ Q_Q(const QSGTexture);
+ return q->textureId(); // this is semantically wrong but at least compatible with existing, non-RHI-aware subclasses
+}
- QOpenGLTextureUploader::textureImage(GL_TEXTURE_2D, m_image, options, QSize(max, max));
+/*!
+ \internal
- qint64 uploadTime = 0;
- if (profileFrames)
- uploadTime = qsg_renderer_timer.nsecsElapsed();
- Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphTexturePrepare,
- QQuickProfiler::SceneGraphTexturePrepareUpload);
+ \return the QRhiTexture for this QSGTexture or null if there is none.
- if (mipmapFiltering() != QSGTexture::None) {
- funcs->glGenerateMipmap(GL_TEXTURE_2D);
- m_mipmaps_generated = true;
- }
+ Unlike textureId(), this function is not expected to create a new
+ QRhiTexture in case there is none. Just return null in that case. The
+ expectation towards the renderer is that a null texture leads to using a
+ transparent, dummy texture instead.
- qint64 mipmapTime = 0;
- if (profileFrames) {
- mipmapTime = qsg_renderer_timer.nsecsElapsed();
- qCDebug(QSG_LOG_TIME_TEXTURE,
- "plain texture uploaded in: %dms (%dx%d), bind=%d, upload=%d, mipmap=%d%s",
- int(mipmapTime / 1000000),
- m_texture_size.width(), m_texture_size.height(),
- int(bindTime / 1000000),
- int((uploadTime - bindTime)/1000000),
- int((mipmapTime - uploadTime)/1000000),
- m_texture_size != m_image.size() ? " (scaled to GL_MAX_TEXTURE_SIZE)" : "");
- }
- Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphTexturePrepare,
- QQuickProfiler::SceneGraphTexturePrepareMipmap);
+ \note This function is only used when running the graphics API independent
+ rendering path of the scene graph.
- m_texture_rect = QRectF(0, 0, 1, 1);
+ \warning This function can only be called from the rendering thread.
- m_dirty_bind_options = false;
- if (!m_retain_image)
- m_image = QImage();
-#endif
+ \since 5.14
+ */
+QRhiTexture *QSGTexturePrivate::rhiTexture() const
+{
+ return nullptr;
}
+void QSGTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+{
+ Q_UNUSED(rhi);
+ Q_UNUSED(resourceUpdates);
+}
/*!
\class QSGDynamicTexture
@@ -843,9 +796,14 @@ void QSGPlainTexture::bind()
returns false.
*/
-
+/*!
+ \internal
+ */
+QSGDynamicTexture::QSGDynamicTexture(QSGTexturePrivate &dd)
+ : QSGTexture(dd)
+{
+}
QT_END_NAMESPACE
#include "moc_qsgtexture.cpp"
-#include "moc_qsgtexture_p.cpp"
diff --git a/src/quick/scenegraph/util/qsgtexture.h b/src/quick/scenegraph/coreapi/qsgtexture.h
index 7bd57a16e3..2efdd8b7c3 100644
--- a/src/quick/scenegraph/util/qsgtexture.h
+++ b/src/quick/scenegraph/coreapi/qsgtexture.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -47,6 +47,10 @@
QT_BEGIN_NAMESPACE
class QSGTexturePrivate;
+class QRhi;
+class QRhiTexture;
+class QRhiResourceUpdateBatch;
+
class Q_QUICK_EXPORT QSGTexture : public QObject
{
Q_OBJECT
@@ -76,7 +80,7 @@ public:
Anisotropy16x
};
- virtual int textureId() const = 0;
+ virtual int textureId() const = 0; // ### Qt 6: remove
virtual QSize textureSize() const = 0;
virtual bool hasAlphaChannel() const = 0;
virtual bool hasMipmaps() const = 0;
@@ -107,6 +111,13 @@ public:
inline QRectF convertToNormalizedSourceRect(const QRectF &rect) const;
+ // ### Qt 6: make these virtual
+ int comparisonKey() const;
+ void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates);
+
+ // ### Qt 6: make this an argument for removedFromAtlas()
+ void setWorkResourceUpdateBatch(QRhiResourceUpdateBatch *resourceUpdates);
+
protected:
QSGTexture(QSGTexturePrivate &dd);
};
@@ -125,12 +136,16 @@ QRectF QSGTexture::convertToNormalizedSourceRect(const QRectF &rect) const
rect.height() * sy);
}
-
class Q_QUICK_EXPORT QSGDynamicTexture : public QSGTexture
{
Q_OBJECT
+
public:
+ QSGDynamicTexture() = default;
virtual bool updateTexture() = 0;
+
+protected:
+ QSGDynamicTexture(QSGTexturePrivate &dd);
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/coreapi/qsgtexture_p.h b/src/quick/scenegraph/coreapi/qsgtexture_p.h
new file mode 100644
index 0000000000..cb59d32012
--- /dev/null
+++ b/src/quick/scenegraph/coreapi/qsgtexture_p.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGTEXTURE_P_H
+#define QSGTEXTURE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuick/private/qtquickglobal_p.h>
+#include <private/qobject_p.h>
+#include "qsgtexture.h"
+
+QT_BEGIN_NAMESPACE
+
+struct QSGSamplerDescription
+{
+ QSGTexture::Filtering filtering = QSGTexture::Nearest;
+ QSGTexture::Filtering mipmapFiltering = QSGTexture::None;
+ QSGTexture::WrapMode horizontalWrap = QSGTexture::ClampToEdge;
+ QSGTexture::WrapMode verticalWrap = QSGTexture::ClampToEdge;
+ QSGTexture::AnisotropyLevel anisotropylevel = QSGTexture::AnisotropyNone;
+
+ static QSGSamplerDescription fromTexture(QSGTexture *t);
+};
+
+Q_DECLARE_TYPEINFO(QSGSamplerDescription, Q_MOVABLE_TYPE);
+
+bool operator==(const QSGSamplerDescription &a, const QSGSamplerDescription &b) Q_DECL_NOTHROW;
+bool operator!=(const QSGSamplerDescription &a, const QSGSamplerDescription &b) Q_DECL_NOTHROW;
+uint qHash(const QSGSamplerDescription &s, uint seed = 0) Q_DECL_NOTHROW;
+
+class Q_QUICK_PRIVATE_EXPORT QSGTexturePrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QSGTexture)
+public:
+ QSGTexturePrivate();
+ static QSGTexturePrivate *get(QSGTexture *t) { return t->d_func(); }
+ void resetDirtySamplerOptions();
+ bool hasDirtySamplerOptions() const;
+
+ virtual QRhiTexture *rhiTexture() const;
+
+ // ### Qt 6: these should be virtuals in the public class instead
+ virtual int comparisonKey() const; // ### Qt 6: pure virtual
+ virtual void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates);
+
+ QRhiResourceUpdateBatch *workResourceUpdateBatch = nullptr; // ### Qt 6: remove
+
+ uint wrapChanged : 1;
+ uint filteringChanged : 1;
+ uint anisotropyChanged : 1;
+
+ uint horizontalWrap : 2;
+ uint verticalWrap : 2;
+ uint mipmapMode : 2;
+ uint filterMode : 2;
+ uint anisotropyLevel: 3;
+};
+
+Q_QUICK_PRIVATE_EXPORT bool qsg_safeguard_texture(QSGTexture *);
+
+QT_END_NAMESPACE
+
+#endif // QSGTEXTURE_P_H
diff --git a/src/quick/scenegraph/qsgadaptationlayer.cpp b/src/quick/scenegraph/qsgadaptationlayer.cpp
index 252e5a9c55..f7b07d724a 100644
--- a/src/quick/scenegraph/qsgadaptationlayer.cpp
+++ b/src/quick/scenegraph/qsgadaptationlayer.cpp
@@ -306,6 +306,19 @@ void QSGDistanceFieldGlyphCache::updateTexture(uint oldTex, uint newTex, const Q
}
}
+void QSGDistanceFieldGlyphCache::updateRhiTexture(QRhiTexture *oldTex, QRhiTexture *newTex, const QSize &newTexSize)
+{
+ int count = m_textures.count();
+ for (int i = 0; i < count; ++i) {
+ Texture &tex = m_textures[i];
+ if (tex.texture == oldTex) {
+ tex.texture = newTex;
+ tex.size = newTexSize;
+ return;
+ }
+ }
+}
+
#if defined(QSG_DISTANCEFIELD_CACHE_DEBUG)
#include <QtGui/qopenglfunctions.h>
@@ -526,14 +539,6 @@ void QSGNodeVisitorEx::visitChildren(QSGNode *node)
}
#ifndef QT_NO_DEBUG_STREAM
-QDebug operator<<(QDebug debug, const QSGGuiThreadShaderEffectManager::ShaderInfo::InputParameter &p)
-{
- QDebugStateSaver saver(debug);
- debug.space();
- debug << p.semanticName << "semindex" << p.semanticIndex;
- return debug;
-}
-
QDebug operator<<(QDebug debug, const QSGGuiThreadShaderEffectManager::ShaderInfo::Variable &v)
{
QDebugStateSaver saver(debug);
@@ -564,6 +569,14 @@ QDebug operator<<(QDebug debug, const QSGShaderEffectNode::VariableData &vd)
}
#endif
+/*!
+ \internal
+ */
+QSGLayer::QSGLayer(QSGTexturePrivate &dd)
+ : QSGDynamicTexture(dd)
+{
+}
+
QT_END_NAMESPACE
#include "moc_qsgadaptationlayer_p.cpp"
diff --git a/src/quick/scenegraph/qsgadaptationlayer_p.h b/src/quick/scenegraph/qsgadaptationlayer_p.h
index 58ecae94e7..6baee33b53 100644
--- a/src/quick/scenegraph/qsgadaptationlayer_p.h
+++ b/src/quick/scenegraph/qsgadaptationlayer_p.h
@@ -64,6 +64,7 @@
#include <QtGui/private/qdatabuffer_p.h>
#include <private/qdistancefield_p.h>
#include <private/qintrusivelist_p.h>
+#include <QtGui/private/qshader_p.h>
// ### remove
#include <QtQuick/private/qquicktext_p.h>
@@ -82,6 +83,7 @@ class QSGRootNode;
class QSGSpriteNode;
class QSGRenderNode;
class QSGRenderContext;
+class QRhiTexture;
class Q_QUICK_PRIVATE_EXPORT QSGNodeVisitorEx
{
@@ -216,6 +218,9 @@ public:
Q_SIGNALS:
void updateRequested();
void scheduledUpdateCompleted();
+
+protected:
+ QSGLayer(QSGTexturePrivate &dd);
};
#if QT_CONFIG(quick_sprite)
@@ -266,27 +271,26 @@ public:
Sampler,
Texture // for APIs with separate texture and sampler objects
};
- struct InputParameter {
- InputParameter() {}
- // Semantics use the D3D keys (POSITION, TEXCOORD).
- // Attribute name based APIs can map based on pre-defined names.
- QByteArray semanticName;
- int semanticIndex = 0;
- };
struct Variable {
Variable() {}
VariableType type = Constant;
QByteArray name;
uint offset = 0; // for cbuffer members
uint size = 0; // for cbuffer members
- int bindPoint = 0; // for textures and samplers; for register-based APIs
+ int bindPoint = 0; // for textures/samplers, where applicable
};
- QByteArray blob; // source or bytecode
+ QString name; // optional, f.ex. the filename, used for debugging purposes only
+ QByteArray blob; // source or bytecode (when not using QRhi)
+ QShader rhiShader;
Type type;
- QVector<InputParameter> inputParameters;
QVector<Variable> variables;
uint constantDataSize;
+
+ // Vertex inputs are not tracked here as QSGGeometry::AttributeSet
+ // hardwires that anyways so it is up to the shader to provide
+ // compatible inputs (e.g. compatible with
+ // QSGGeometry::defaultAttributes_TexturedPoint2D()).
};
virtual void prepareShaderCode(ShaderInfo::Type typeHint, const QByteArray &src, ShaderInfo *result) = 0;
@@ -298,7 +302,6 @@ Q_SIGNALS:
};
#ifndef QT_NO_DEBUG_STREAM
-Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug debug, const QSGGuiThreadShaderEffectManager::ShaderInfo::InputParameter &p);
Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug debug, const QSGGuiThreadShaderEffectManager::ShaderInfo::Variable &v);
#endif
@@ -439,10 +442,18 @@ public:
struct Texture {
uint textureId = 0;
+ QRhiTexture *texture = nullptr;
QSize size;
-
- Texture() : size(QSize()) { }
- bool operator == (const Texture &other) const { return textureId == other.textureId; }
+ bool rhiBased = false;
+
+ bool operator == (const Texture &other) const {
+ if (rhiBased != other.rhiBased)
+ return false;
+ if (rhiBased)
+ return texture == other.texture;
+ else
+ return textureId == other.textureId;
+ }
};
const QRawFont &referenceFont() const { return m_referenceFont; }
@@ -474,6 +485,8 @@ public:
virtual void unregisterOwnerElement(QQuickItem *ownerElement);
virtual void processPendingGlyphs();
+ virtual bool eightBitFormatIsAlphaSwizzled() const = 0;
+
protected:
struct GlyphPosition {
glyph_t glyph;
@@ -501,6 +514,7 @@ protected:
inline void removeGlyph(glyph_t glyph);
void updateTexture(uint oldTex, uint newTex, const QSize &newTexSize);
+ void updateRhiTexture(QRhiTexture *oldTex, QRhiTexture *newTex, const QSize &newTexSize);
inline bool containsGlyph(glyph_t glyph);
uint textureIdForGlyph(glyph_t glyph) const;
diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp
index 53648e352a..17eb1e312c 100644
--- a/src/quick/scenegraph/qsgcontext.cpp
+++ b/src/quick/scenegraph/qsgcontext.cpp
@@ -332,15 +332,61 @@ QSGRenderContext::~QSGRenderContext()
{
}
-void QSGRenderContext::initialize(void *context)
+void QSGRenderContext::initialize(const InitParams *params)
{
- Q_UNUSED(context);
+ Q_UNUSED(params);
}
void QSGRenderContext::invalidate()
{
}
+void QSGRenderContext::prepareSync(qreal devicePixelRatio)
+{
+ Q_UNUSED(devicePixelRatio);
+}
+
+void QSGRenderContext::beginNextFrame(QSGRenderer *renderer,
+ RenderPassCallback mainPassRecordingStart,
+ RenderPassCallback mainPassRecordingEnd,
+ void *callbackUserData)
+{
+ Q_UNUSED(renderer);
+ Q_UNUSED(mainPassRecordingStart);
+ Q_UNUSED(mainPassRecordingEnd);
+ Q_UNUSED(callbackUserData);
+}
+
+void QSGRenderContext::endNextFrame(QSGRenderer *renderer)
+{
+ Q_UNUSED(renderer);
+}
+
+void QSGRenderContext::beginNextRhiFrame(QSGRenderer *renderer,
+ QRhiRenderTarget *rt, QRhiRenderPassDescriptor *rp, QRhiCommandBuffer *cb,
+ RenderPassCallback mainPassRecordingStart,
+ RenderPassCallback mainPassRecordingEnd,
+ void *callbackUserData)
+{
+ Q_UNUSED(renderer);
+ Q_UNUSED(rt);
+ Q_UNUSED(rp);
+ Q_UNUSED(cb);
+ Q_UNUSED(mainPassRecordingStart);
+ Q_UNUSED(mainPassRecordingEnd);
+ Q_UNUSED(callbackUserData);
+}
+
+void QSGRenderContext::renderNextRhiFrame(QSGRenderer *renderer)
+{
+ Q_UNUSED(renderer);
+}
+
+void QSGRenderContext::endNextRhiFrame(QSGRenderer *renderer)
+{
+ Q_UNUSED(renderer);
+}
+
void QSGRenderContext::endSync()
{
qDeleteAll(m_texturesToDelete);
@@ -362,6 +408,11 @@ void QSGRenderContext::registerFontengineForCleanup(QFontEngine *engine)
m_fontEnginesToClean << engine;
}
+QRhi *QSGRenderContext::rhi() const
+{
+ return nullptr;
+}
+
/*!
Factory function for the scene graph renderers.
diff --git a/src/quick/scenegraph/qsgcontext_p.h b/src/quick/scenegraph/qsgcontext_p.h
index 282ce828af..244bcfabd1 100644
--- a/src/quick/scenegraph/qsgcontext_p.h
+++ b/src/quick/scenegraph/qsgcontext_p.h
@@ -89,6 +89,10 @@ class QSGImageNode;
class QSGNinePatchNode;
class QSGSpriteNode;
class QSGRenderContext;
+class QRhi;
+class QRhiRenderTarget;
+class QRhiRenderPassDescriptor;
+class QRhiCommandBuffer;
Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERLOOP)
Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_COMPILATION)
@@ -119,7 +123,7 @@ public:
QSGInternalRectangleNode *createInternalRectangleNode(const QRectF &rect, const QColor &c);
virtual QSGInternalRectangleNode *createInternalRectangleNode() = 0;
- virtual QSGInternalImageNode *createInternalImageNode() = 0;
+ virtual QSGInternalImageNode *createInternalImageNode(QSGRenderContext *renderContext) = 0;
virtual QSGPainterNode *createPainterNode(QQuickPaintedItem *item) = 0;
virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode) = 0;
virtual QSGLayer *createLayer(QSGRenderContext *renderContext) = 0;
@@ -164,9 +168,28 @@ public:
QSGContext *sceneGraphContext() const { return m_sg; }
virtual bool isValid() const { return true; }
- virtual void initialize(void *context);
+ struct InitParams { };
+ virtual void initialize(const InitParams *params);
virtual void invalidate();
+
+ using RenderPassCallback = void (*)(void *);
+
+ virtual void prepareSync(qreal devicePixelRatio);
+ virtual void beginNextFrame(QSGRenderer *renderer,
+ RenderPassCallback mainPassRecordingStart,
+ RenderPassCallback mainPassRecordingEnd,
+ void *callbackUserData);
virtual void renderNextFrame(QSGRenderer *renderer, uint fboId) = 0;
+ virtual void endNextFrame(QSGRenderer *renderer);
+
+ virtual void beginNextRhiFrame(QSGRenderer *renderer,
+ QRhiRenderTarget *rt, QRhiRenderPassDescriptor *rp, QRhiCommandBuffer *cb,
+ RenderPassCallback mainPassRecordingStart,
+ RenderPassCallback mainPassRecordingEnd,
+ void *callbackUserData);
+ virtual void renderNextRhiFrame(QSGRenderer *renderer);
+ virtual void endNextRhiFrame(QSGRenderer *renderer);
+
virtual void endSync();
virtual QSGDistanceFieldGlyphCache *distanceFieldGlyphCache(const QRawFont &font);
@@ -182,6 +205,8 @@ public:
void registerFontengineForCleanup(QFontEngine *engine);
+ virtual QRhi *rhi() const;
+
Q_SIGNALS:
void initialized();
void invalidated();
diff --git a/src/quick/scenegraph/qsgdefaultcontext.cpp b/src/quick/scenegraph/qsgdefaultcontext.cpp
index 70b74b8877..ea01b0a3b4 100644
--- a/src/quick/scenegraph/qsgdefaultcontext.cpp
+++ b/src/quick/scenegraph/qsgdefaultcontext.cpp
@@ -45,8 +45,9 @@
#include <QtQuick/private/qsgdefaultglyphnode_p.h>
#include <QtQuick/private/qsgdistancefieldglyphnode_p.h>
#include <QtQuick/private/qsgdistancefieldglyphnode_p_p.h>
-#include <QtQuick/private/qsgrenderloop_p.h>
-#include <QtQuick/private/qsgdefaultlayer_p.h>
+#include <QtQuick/private/qsgopengllayer_p.h>
+#include <QtQuick/private/qsgrhisupport_p.h>
+#include <QtQuick/private/qsgrhilayer_p.h>
#include <QtQuick/private/qsgdefaultrendercontext_p.h>
#include <QtQuick/private/qsgdefaultrectanglenode_p.h>
#include <QtQuick/private/qsgdefaultimagenode_p.h>
@@ -54,25 +55,29 @@
#if QT_CONFIG(quick_sprite)
#include <QtQuick/private/qsgdefaultspritenode_p.h>
#endif
+#include <QtQuick/private/qsgrhishadereffectnode_p.h>
#include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLFramebufferObject>
-#include <QtQuick/QQuickWindow>
+#include <QtQuick/private/qquickwindow_p.h>
#include <private/qqmlglobal_p.h>
#include <algorithm>
+#include <QtGui/private/qrhi_p.h>
+#include <QtGui/private/qrhigles2_p.h>
+
QT_BEGIN_NAMESPACE
namespace QSGMultisampleAntialiasing {
class ImageNode : public QSGDefaultInternalImageNode {
public:
+ ImageNode(QSGDefaultRenderContext *rc) : QSGDefaultInternalImageNode(rc) { }
void setAntialiasing(bool) override { }
};
-
class RectangleNode : public QSGDefaultInternalRectangleNode {
public:
void setAntialiasing(bool) override { }
@@ -118,7 +123,7 @@ void QSGDefaultContext::renderContextInitialized(QSGRenderContext *renderContext
{
m_mutex.lock();
- auto openglRenderContext = static_cast<const QSGDefaultRenderContext *>(renderContext);
+ auto rc = static_cast<const QSGDefaultRenderContext *>(renderContext);
if (m_antialiasingMethod == UndecidedAntialiasing) {
if (Q_UNLIKELY(qEnvironmentVariableIsSet("QSG_ANTIALIASING_METHOD"))) {
const QByteArray aaType = qgetenv("QSG_ANTIALIASING_METHOD");
@@ -127,12 +132,8 @@ void QSGDefaultContext::renderContextInitialized(QSGRenderContext *renderContext
else if (aaType == "vertex")
m_antialiasingMethod = VertexAntialiasing;
}
- if (m_antialiasingMethod == UndecidedAntialiasing) {
- if (openglRenderContext->openglContext()->format().samples() > 0)
- m_antialiasingMethod = MsaaAntialiasing;
- else
- m_antialiasingMethod = VertexAntialiasing;
- }
+ if (m_antialiasingMethod == UndecidedAntialiasing)
+ m_antialiasingMethod = rc->msaaSampleCount() > 1 ? MsaaAntialiasing : VertexAntialiasing;
}
// With OpenGL ES, except for Angle on Windows, use GrayAntialiasing, unless
@@ -141,15 +142,23 @@ void QSGDefaultContext::renderContextInitialized(QSGRenderContext *renderContext
if (!m_distanceFieldAntialiasingDecided) {
m_distanceFieldAntialiasingDecided = true;
#ifndef Q_OS_WIN32
- if (openglRenderContext->openglContext()->isOpenGLES())
- m_distanceFieldAntialiasing = QSGGlyphNode::GrayAntialiasing;
+ if (rc->rhi()) {
+ if (rc->rhi()->backend() == QRhi::OpenGLES2
+ && static_cast<const QRhiGles2NativeHandles *>(rc->rhi()->nativeHandles())->context->isOpenGLES())
+ {
+ m_distanceFieldAntialiasing = QSGGlyphNode::GrayAntialiasing;
+ }
+ } else {
+ if (rc->openglContext()->isOpenGLES())
+ m_distanceFieldAntialiasing = QSGGlyphNode::GrayAntialiasing;
+ }
#endif
}
static bool dumped = false;
- if (!dumped && QSG_LOG_INFO().isDebugEnabled()) {
+ if (!dumped && QSG_LOG_INFO().isDebugEnabled() && !rc->rhi()) {
dumped = true;
- QSurfaceFormat format = openglRenderContext->openglContext()->format();
+ QSurfaceFormat format = rc->openglContext()->format();
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
qCDebug(QSG_LOG_INFO, "R/G/B/A Buffers: %d %d %d %d", format.redBufferSize(),
format.greenBufferSize(), format.blueBufferSize(), format.alphaBufferSize());
@@ -160,10 +169,10 @@ void QSGDefaultContext::renderContextInitialized(QSGRenderContext *renderContext
qCDebug(QSG_LOG_INFO, "GL_RENDERER: %s",
(const char*)funcs->glGetString(GL_RENDERER));
qCDebug(QSG_LOG_INFO, "GL_VERSION: %s", (const char*)funcs->glGetString(GL_VERSION));
- QByteArrayList exts = openglRenderContext->openglContext()->extensions().toList();
+ QByteArrayList exts = rc->openglContext()->extensions().values();
std::sort(exts.begin(), exts.end());
qCDebug(QSG_LOG_INFO, "GL_EXTENSIONS: %s", exts.join(' ').constData());
- qCDebug(QSG_LOG_INFO, "Max Texture Size: %d", openglRenderContext->maxTextureSize());
+ qCDebug(QSG_LOG_INFO, "Max Texture Size: %d", rc->maxTextureSize());
qCDebug(QSG_LOG_INFO, "Debug context: %s",
format.testOption(QSurfaceFormat::DebugContext) ? "true" : "false");
}
@@ -187,11 +196,11 @@ QSGInternalRectangleNode *QSGDefaultContext::createInternalRectangleNode()
: new QSGDefaultInternalRectangleNode;
}
-QSGInternalImageNode *QSGDefaultContext::createInternalImageNode()
+QSGInternalImageNode *QSGDefaultContext::createInternalImageNode(QSGRenderContext *renderContext)
{
return m_antialiasingMethod == MsaaAntialiasing
- ? new QSGMultisampleAntialiasing::ImageNode
- : new QSGDefaultInternalImageNode;
+ ? new QSGMultisampleAntialiasing::ImageNode(static_cast<QSGDefaultRenderContext *>(renderContext))
+ : new QSGDefaultInternalImageNode(static_cast<QSGDefaultRenderContext *>(renderContext));
}
QSGPainterNode *QSGDefaultContext::createPainterNode(QQuickPaintedItem *item)
@@ -202,7 +211,7 @@ QSGPainterNode *QSGDefaultContext::createPainterNode(QQuickPaintedItem *item)
QSGGlyphNode *QSGDefaultContext::createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode)
{
if (m_distanceFieldDisabled || preferNativeGlyphNode) {
- return new QSGDefaultGlyphNode;
+ return new QSGDefaultGlyphNode(rc);
} else {
QSGDistanceFieldGlyphNode *node = new QSGDistanceFieldGlyphNode(rc);
node->setPreferredAntialiasingMode(m_distanceFieldAntialiasing);
@@ -212,7 +221,11 @@ QSGGlyphNode *QSGDefaultContext::createGlyphNode(QSGRenderContext *rc, bool pref
QSGLayer *QSGDefaultContext::createLayer(QSGRenderContext *renderContext)
{
- return new QSGDefaultLayer(renderContext);
+ auto rc = static_cast<const QSGDefaultRenderContext *>(renderContext);
+ if (rc->rhi())
+ return new QSGRhiLayer(renderContext);
+ else
+ return new QSGOpenGLLayer(renderContext);
}
QSurfaceFormat QSGDefaultContext::defaultSurfaceFormat() const
@@ -275,24 +288,73 @@ QSGSpriteNode *QSGDefaultContext::createSpriteNode()
}
#endif
+QSGGuiThreadShaderEffectManager *QSGDefaultContext::createGuiThreadShaderEffectManager()
+{
+ if (QSGRhiSupport::instance()->isRhiEnabled())
+ return new QSGRhiGuiThreadShaderEffectManager;
+
+ return nullptr;
+}
+
+QSGShaderEffectNode *QSGDefaultContext::createShaderEffectNode(QSGRenderContext *renderContext,
+ QSGGuiThreadShaderEffectManager *mgr)
+{
+ if (QSGRhiSupport::instance()->isRhiEnabled()) {
+ return new QSGRhiShaderEffectNode(static_cast<QSGDefaultRenderContext *>(renderContext),
+ static_cast<QSGRhiGuiThreadShaderEffectManager *>(mgr));
+ }
+
+ return nullptr;
+}
+
QSGRendererInterface::GraphicsApi QSGDefaultContext::graphicsApi() const
{
- return OpenGL;
+ return QSGRhiSupport::instance()->graphicsApi();
+}
+
+void *QSGDefaultContext::getResource(QQuickWindow *window, Resource resource) const
+{
+ if (!window)
+ return nullptr;
+
+ // Unlike the graphicsApi and shaderType and similar queries, getting a
+ // native resource is only possible when there is an initialized
+ // rendercontext, or rather, only within rendering a frame, as per
+ // QSGRendererInterface docs. This is good since getting some things is
+ // only possible within a beginFrame - endFrame with the RHI.
+
+ const QSGDefaultRenderContext *rc = static_cast<const QSGDefaultRenderContext *>(
+ QQuickWindowPrivate::get(window)->context);
+ QSGRhiSupport *rhiSupport = QSGRhiSupport::instance();
+
+ switch (resource) {
+ case OpenGLContextResource:
+ if (rhiSupport->graphicsApi() == OpenGL)
+ return rc->openglContext();
+ else
+ return const_cast<void *>(rhiSupport->rifResource(resource, rc));
+#if QT_CONFIG(vulkan)
+ case VulkanInstanceResource:
+ return window->vulkanInstance();
+#endif
+ default:
+ return const_cast<void *>(rhiSupport->rifResource(resource, rc));
+ }
}
QSGRendererInterface::ShaderType QSGDefaultContext::shaderType() const
{
- return GLSL;
+ return QSGRhiSupport::instance()->isRhiEnabled() ? RhiShader : GLSL;
}
QSGRendererInterface::ShaderCompilationTypes QSGDefaultContext::shaderCompilationType() const
{
- return RuntimeCompilation;
+ return QSGRhiSupport::instance()->isRhiEnabled() ? OfflineCompilation : RuntimeCompilation;
}
QSGRendererInterface::ShaderSourceTypes QSGDefaultContext::shaderSourceType() const
{
- return ShaderSourceString | ShaderSourceFile;
+ return QSGRhiSupport::instance()->isRhiEnabled() ? ShaderSourceFile : (ShaderSourceString | ShaderSourceFile);
}
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgdefaultcontext_p.h b/src/quick/scenegraph/qsgdefaultcontext_p.h
index 6dfd197cf6..8fdd29caee 100644
--- a/src/quick/scenegraph/qsgdefaultcontext_p.h
+++ b/src/quick/scenegraph/qsgdefaultcontext_p.h
@@ -67,7 +67,7 @@ public:
void renderContextInvalidated(QSGRenderContext *) override;
QSGRenderContext *createRenderContext() override;
QSGInternalRectangleNode *createInternalRectangleNode() override;
- QSGInternalImageNode *createInternalImageNode() override;
+ QSGInternalImageNode *createInternalImageNode(QSGRenderContext *renderContext) override;
QSGPainterNode *createPainterNode(QQuickPaintedItem *item) override;
QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode) override;
QSGLayer *createLayer(QSGRenderContext *renderContext) override;
@@ -79,11 +79,15 @@ public:
#if QT_CONFIG(quick_sprite)
QSGSpriteNode *createSpriteNode() override;
#endif
+ QSGGuiThreadShaderEffectManager *createGuiThreadShaderEffectManager() override;
+ QSGShaderEffectNode *createShaderEffectNode(QSGRenderContext *renderContext,
+ QSGGuiThreadShaderEffectManager *mgr) override;
void setDistanceFieldEnabled(bool enabled);
bool isDistanceFieldEnabled() const;
GraphicsApi graphicsApi() const override;
+ void *getResource(QQuickWindow *window, Resource resource) const override;
ShaderType shaderType() const override;
ShaderCompilationTypes shaderCompilationType() const override;
ShaderSourceTypes shaderSourceType() const override;
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode.cpp b/src/quick/scenegraph/qsgdefaultglyphnode.cpp
index cae0eda3f4..5bd5cc4891 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode.cpp
+++ b/src/quick/scenegraph/qsgdefaultglyphnode.cpp
@@ -42,8 +42,9 @@
QT_BEGIN_NAMESPACE
-QSGDefaultGlyphNode::QSGDefaultGlyphNode()
- : m_glyphNodeType(RootGlyphNode)
+QSGDefaultGlyphNode::QSGDefaultGlyphNode(QSGRenderContext *context)
+ : m_context(context)
+ , m_glyphNodeType(RootGlyphNode)
, m_dirtyGeometry(false)
{
setFlag(UsePreprocess);
@@ -75,14 +76,14 @@ void QSGDefaultGlyphNode::update()
QMargins margins(0, 0, 0, 0);
if (m_style == QQuickText::Normal) {
- m_material = new QSGTextMaskMaterial(QVector4D(m_color.redF(), m_color.greenF(), m_color.blueF(), m_color.alphaF()), font);
+ m_material = new QSGTextMaskMaterial(m_context, QVector4D(m_color.redF(), m_color.greenF(), m_color.blueF(), m_color.alphaF()), font);
} else if (m_style == QQuickText::Outline) {
- QSGOutlinedTextMaterial *material = new QSGOutlinedTextMaterial(font);
+ QSGOutlinedTextMaterial *material = new QSGOutlinedTextMaterial(m_context, font);
material->setStyleColor(m_styleColor);
m_material = material;
margins = QMargins(1, 1, 1, 1);
} else {
- QSGStyledTextMaterial *material = new QSGStyledTextMaterial(font);
+ QSGStyledTextMaterial *material = new QSGStyledTextMaterial(m_context, font);
if (m_style == QQuickText::Sunken) {
material->setStyleShift(QVector2D(0, -1));
margins.setTop(1);
@@ -158,7 +159,7 @@ void QSGDefaultGlyphNode::updateGeometry()
subNodeGlyphRun.setGlyphIndexes(glyphInfo.indexes);
subNodeGlyphRun.setPositions(glyphInfo.positions);
- QSGDefaultGlyphNode *subNode = new QSGDefaultGlyphNode();
+ QSGDefaultGlyphNode *subNode = new QSGDefaultGlyphNode(m_context);
subNode->setGlyphNodeType(SubGlyphNode);
subNode->setColor(m_color);
subNode->setStyle(m_style);
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
index b9a22dd44b..be6ef25feb 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
@@ -71,6 +71,28 @@ static inline QVector4D qsg_premultiply(const QVector4D &c, float globalOpacity)
return QVector4D(c.x() * o, c.y() * o, c.z() * o, o);
}
+static inline qreal qt_sRGB_to_linear_RGB(qreal f)
+{
+ return f > 0.04045 ? qPow((f + 0.055) / 1.055, 2.4) : f / 12.92;
+}
+
+static inline QVector4D qt_sRGB_to_linear_RGB(const QVector4D &color)
+{
+ return QVector4D(qt_sRGB_to_linear_RGB(color.x()),
+ qt_sRGB_to_linear_RGB(color.y()),
+ qt_sRGB_to_linear_RGB(color.z()),
+ color.w());
+}
+
+static inline qreal fontSmoothingGamma()
+{
+ static qreal fontSmoothingGamma = QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
+ return fontSmoothingGamma;
+}
+
+
+// ***** legacy (GL) material shader implementations
+
static inline qreal qsg_device_pixel_ratio(QOpenGLContext *ctx)
{
qreal devicePixelRatio = 1;
@@ -122,12 +144,6 @@ QSGTextMaskShader::QSGTextMaskShader(QFontEngine::GlyphFormat glyphFormat)
setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/textmask.frag"));
}
-static inline qreal fontSmoothingGamma()
-{
- static qreal fontSmoothingGamma = QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal();
- return fontSmoothingGamma;
-}
-
void QSGTextMaskShader::initialize()
{
m_matrix_id = program()->uniformLocation("matrix");
@@ -149,8 +165,8 @@ void QSGTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEf
if (updated
|| oldMaterial == nullptr
|| oldMaterial->texture()->textureId() != material->texture()->textureId()) {
- program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->cacheTextureWidth(),
- 1.0 / material->cacheTextureHeight()));
+ program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->openglGlyphCache()->width(),
+ 1.0 / material->openglGlyphCache()->height()));
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
funcs->glBindTexture(GL_TEXTURE_2D, material->texture()->textureId());
@@ -263,19 +279,6 @@ void QSG24BitTextMaskShader::deactivate()
funcs->glDisable(GL_FRAMEBUFFER_SRGB);
}
-static inline qreal qt_sRGB_to_linear_RGB(qreal f)
-{
- return f > 0.04045 ? qPow((f + 0.055) / 1.055, 2.4) : f / 12.92;
-}
-
-static inline QVector4D qt_sRGB_to_linear_RGB(const QVector4D &color)
-{
- return QVector4D(qt_sRGB_to_linear_RGB(color.x()),
- qt_sRGB_to_linear_RGB(color.y()),
- qt_sRGB_to_linear_RGB(color.z()),
- color.w());
-}
-
void QSG24BitTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
{
QSGTextMaskShader::updateState(state, newEffect, oldEffect);
@@ -371,12 +374,12 @@ void QSGStyledTextShader::updateState(const RenderState &state,
if (updated
|| oldMaterial == nullptr
|| oldMaterial->texture()->textureId() != material->texture()->textureId()) {
- program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->cacheTextureWidth(),
- 1.0 / material->cacheTextureHeight()));
+ program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->openglGlyphCache()->width(),
+ 1.0 / material->openglGlyphCache()->height()));
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
funcs->glBindTexture(GL_TEXTURE_2D, material->texture()->textureId());
- // Set the mag/min filters to be linear. We only need to do this when the texture
+ // Set the mag/min filters to be nearest. We only need to do this when the texture
// has been recreated.
if (updated) {
funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -399,8 +402,296 @@ public:
}
};
-QSGTextMaskMaterial::QSGTextMaskMaterial(const QVector4D &color, const QRawFont &font, QFontEngine::GlyphFormat glyphFormat)
- : m_texture(nullptr)
+
+// ***** RHI shader implementations
+
+class QSGTextMaskRhiShader : public QSGMaterialRhiShader
+{
+public:
+ QSGTextMaskRhiShader(QFontEngine::GlyphFormat glyphFormat);
+
+ bool updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+ void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+
+protected:
+ QFontEngine::GlyphFormat m_glyphFormat;
+};
+
+QSGTextMaskRhiShader::QSGTextMaskRhiShader(QFontEngine::GlyphFormat glyphFormat)
+ : m_glyphFormat(glyphFormat)
+{
+ setShaderFileName(VertexStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/textmask.vert.qsb"));
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/textmask.frag.qsb"));
+}
+
+bool QSGTextMaskRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ Q_ASSERT(oldMaterial == nullptr || newMaterial->type() == oldMaterial->type());
+ QSGTextMaskMaterial *mat = static_cast<QSGTextMaskMaterial *>(newMaterial);
+ QSGTextMaskMaterial *oldMat = static_cast<QSGTextMaskMaterial *>(oldMaterial);
+
+ // updateUniformData() is called before updateSampledImage() by the
+ // renderer. Hence updating the glyph cache stuff here.
+ const bool updated = mat->ensureUpToDate();
+ Q_ASSERT(mat->texture());
+ Q_ASSERT(oldMat == nullptr || oldMat->texture());
+
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 92);
+
+ if (state.isMatrixDirty()) {
+ const QMatrix4x4 m = state.combinedMatrix();
+ memcpy(buf->data(), m.constData(), 64);
+ changed = true;
+ }
+
+ QRhiTexture *oldRtex = oldMat ? QSGTexturePrivate::get(oldMat->texture())->rhiTexture() : nullptr;
+ QRhiTexture *newRtex = QSGTexturePrivate::get(mat->texture())->rhiTexture();
+ if (updated || !oldMat || oldRtex != newRtex) {
+ const QVector2D textureScale = QVector2D(1.0f / mat->rhiGlyphCache()->width(),
+ 1.0f / mat->rhiGlyphCache()->height());
+ memcpy(buf->data() + 64 + 16, &textureScale, 8);
+ changed = true;
+ }
+
+ if (!oldMat) {
+ float dpr = state.devicePixelRatio();
+ memcpy(buf->data() + 64 + 16 + 8, &dpr, 4);
+ }
+
+ // move texture uploads/copies onto the renderer's soon-to-be-committed list
+ mat->rhiGlyphCache()->commitResourceUpdates(state.resourceUpdateBatch());
+
+ return changed;
+}
+
+void QSGTextMaskRhiShader::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *)
+{
+ Q_UNUSED(state);
+ if (binding != 1)
+ return;
+
+ QSGTextMaskMaterial *mat = static_cast<QSGTextMaskMaterial *>(newMaterial);
+ QSGTexture *t = mat->texture();
+ t->setFiltering(QSGTexture::Nearest);
+ *texture = t;
+}
+
+class QSG8BitTextMaskRhiShader : public QSGTextMaskRhiShader
+{
+public:
+ QSG8BitTextMaskRhiShader(QFontEngine::GlyphFormat glyphFormat, bool alphaTexture)
+ : QSGTextMaskRhiShader(glyphFormat)
+ {
+ if (alphaTexture)
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/8bittextmask_a.frag.qsb"));
+ else
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/8bittextmask.frag.qsb"));
+ }
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+bool QSG8BitTextMaskRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ bool changed = QSGTextMaskRhiShader::updateUniformData(state, newMaterial, oldMaterial);
+
+ QSGTextMaskMaterial *mat = static_cast<QSGTextMaskMaterial *>(newMaterial);
+ QSGTextMaskMaterial *oldMat = static_cast<QSGTextMaskMaterial *>(oldMaterial);
+
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 80);
+
+ if (oldMat == nullptr || mat->color() != oldMat->color() || state.isOpacityDirty()) {
+ const QVector4D color = qsg_premultiply(mat->color(), state.opacity());
+ memcpy(buf->data() + 64, &color, 16);
+ changed = true;
+ }
+
+ return changed;
+}
+
+class QSG24BitTextMaskRhiShader : public QSGTextMaskRhiShader
+{
+public:
+ QSG24BitTextMaskRhiShader(QFontEngine::GlyphFormat glyphFormat)
+ : QSGTextMaskRhiShader(glyphFormat)
+ {
+ setFlag(UpdatesGraphicsPipelineState, true);
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/24bittextmask.frag.qsb"));
+ }
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+ bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+// ### gamma correction (sRGB) Unsurprisingly, the GL approach is not portable
+// to anything else - it just does not work that way, there is no opt-in/out
+// switch and magic winsys-provided maybe-sRGB buffers. When requesting an sRGB
+// QRhiSwapChain (which we do not do), it is full sRGB, with the sRGB
+// framebuffer update and blending always on... Could we do gamma correction in
+// the shader for text? (but that's bad for blending?)
+
+bool QSG24BitTextMaskRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ bool changed = QSGTextMaskRhiShader::updateUniformData(state, newMaterial, oldMaterial);
+
+ QSGTextMaskMaterial *mat = static_cast<QSGTextMaskMaterial *>(newMaterial);
+ QSGTextMaskMaterial *oldMat = static_cast<QSGTextMaskMaterial *>(oldMaterial);
+
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 92);
+
+ if (oldMat == nullptr || mat->color() != oldMat->color() || state.isOpacityDirty()) {
+ // shader takes vec4 but uses alpha only; coloring happens via the blend constant
+ const QVector4D color = qsg_premultiply(mat->color(), state.opacity());
+ memcpy(buf->data() + 64, &color, 16);
+ changed = true;
+ }
+
+ return changed;
+}
+
+bool QSG24BitTextMaskRhiShader::updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ Q_UNUSED(state);
+ Q_UNUSED(oldMaterial);
+ QSGTextMaskMaterial *mat = static_cast<QSGTextMaskMaterial *>(newMaterial);
+
+ ps->blendEnable = true;
+ ps->srcColor = GraphicsPipelineState::ConstantColor;
+ ps->dstColor = GraphicsPipelineState::OneMinusSrcColor;
+
+ QVector4D color = qsg_premultiply(mat->color(), state.opacity());
+ // if (useSRGB())
+ // color = qt_sRGB_to_linear_RGB(color);
+
+ // this is dynamic state but it's - magic! - taken care of by the renderer
+ ps->blendConstant = QColor::fromRgbF(color.x(), color.y(), color.z(), color.w());
+
+ return true;
+}
+
+class QSG32BitColorTextRhiShader : public QSGTextMaskRhiShader
+{
+public:
+ QSG32BitColorTextRhiShader(QFontEngine::GlyphFormat glyphFormat)
+ : QSGTextMaskRhiShader(glyphFormat)
+ {
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/32bitcolortext.frag.qsb"));
+ }
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+bool QSG32BitColorTextRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ bool changed = QSGTextMaskRhiShader::updateUniformData(state, newMaterial, oldMaterial);
+
+ QSGTextMaskMaterial *mat = static_cast<QSGTextMaskMaterial *>(newMaterial);
+ QSGTextMaskMaterial *oldMat = static_cast<QSGTextMaskMaterial *>(oldMaterial);
+
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 92);
+
+ if (oldMat == nullptr || mat->color() != oldMat->color() || state.isOpacityDirty()) {
+ // shader takes vec4 but uses alpha only
+ const QVector4D color(0, 0, 0, mat->color().w() * state.opacity());
+ memcpy(buf->data() + 64, &color, 16);
+ changed = true;
+ }
+
+ return changed;
+}
+
+class QSGStyledTextRhiShader : public QSG8BitTextMaskRhiShader
+{
+public:
+ QSGStyledTextRhiShader(QFontEngine::GlyphFormat glyphFormat, bool alphaTexture)
+ : QSG8BitTextMaskRhiShader(glyphFormat, alphaTexture)
+ {
+ setShaderFileName(VertexStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/styledtext.vert.qsb"));
+ if (alphaTexture)
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/styledtext_a.frag.qsb"));
+ else
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/styledtext.frag.qsb"));
+ }
+
+ bool updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+bool QSGStyledTextRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ bool changed = QSG8BitTextMaskRhiShader::updateUniformData(state, newMaterial, oldMaterial);
+
+ QSGStyledTextMaterial *mat = static_cast<QSGStyledTextMaterial *>(newMaterial);
+ QSGStyledTextMaterial *oldMat = static_cast<QSGStyledTextMaterial *>(oldMaterial);
+
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 120);
+
+ // matrix..dpr + 1 float padding (vec4 must be aligned to 16)
+ const int startOffset = 64 + 16 + 8 + 4 + 4;
+
+ if (oldMat == nullptr || mat->styleColor() != oldMat->styleColor() || state.isOpacityDirty()) {
+ const QVector4D styleColor = qsg_premultiply(mat->styleColor(), state.opacity());
+ memcpy(buf->data() + startOffset, &styleColor, 16);
+ changed = true;
+ }
+
+ if (oldMat == nullptr || oldMat->styleShift() != mat->styleShift()) {
+ const QVector2D v = mat->styleShift();
+ memcpy(buf->data() + startOffset + 16, &v, 8);
+ changed = true;
+ }
+
+ return changed;
+}
+
+class QSGOutlinedTextRhiShader : public QSGStyledTextRhiShader
+{
+public:
+ QSGOutlinedTextRhiShader(QFontEngine::GlyphFormat glyphFormat, bool alphaTexture)
+ : QSGStyledTextRhiShader(glyphFormat, alphaTexture)
+ {
+ setShaderFileName(VertexStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/outlinedtext.vert.qsb"));
+ if (alphaTexture)
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/outlinedtext_a.frag.qsb"));
+ else
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/outlinedtext.frag.qsb"));
+ }
+};
+
+
+// ***** common material stuff
+
+QSGTextMaskMaterial::QSGTextMaskMaterial(QSGRenderContext *rc, const QVector4D &color, const QRawFont &font, QFontEngine::GlyphFormat glyphFormat)
+ : m_rc(qobject_cast<QSGDefaultRenderContext *>(rc))
+ , m_texture(nullptr)
, m_glyphCache(nullptr)
, m_font(font)
, m_color(color)
@@ -430,16 +721,17 @@ void QSGTextMaskMaterial::init(QFontEngine::GlyphFormat glyphFormat)
{
Q_ASSERT(m_font.isValid());
+ setFlag(SupportsRhiShader, true);
setFlag(Blending, true);
+ Q_ASSERT(m_rc);
+ m_rhi = m_rc->rhi();
+
updateCache(glyphFormat);
}
void QSGTextMaskMaterial::updateCache(QFontEngine::GlyphFormat glyphFormat)
{
- QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext());
- Q_ASSERT(ctx != nullptr);
-
// The following piece of code will read/write to the font engine's caches,
// potentially from different threads. However, this is safe because this
// code is only called from QQuickItem::updatePaintNode() which is called
@@ -454,23 +746,38 @@ void QSGTextMaskMaterial::updateCache(QFontEngine::GlyphFormat glyphFormat)
: QFontEngine::Format_A32;
}
- qreal devicePixelRatio = qsg_device_pixel_ratio(ctx);
+ QOpenGLContext *ctx = nullptr;
+ qreal devicePixelRatio;
+ void *cacheKey;
+ if (m_rhi) {
+ cacheKey = m_rhi;
+ // Get the dpr the modern way. This value retrieved via the
+ // rendercontext matches what RenderState::devicePixelRatio()
+ // exposes to the material shaders later on.
+ devicePixelRatio = m_rc->currentDevicePixelRatio();
+ } else {
+ ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext());
+ Q_ASSERT(ctx != nullptr);
+ cacheKey = ctx;
+ devicePixelRatio = qsg_device_pixel_ratio(ctx); // this is technically incorrect, see other branch above
+ }
QTransform glyphCacheTransform = QTransform::fromScale(devicePixelRatio, devicePixelRatio);
if (!fontEngine->supportsTransformation(glyphCacheTransform))
glyphCacheTransform = QTransform();
QColor color = glyphFormat == QFontEngine::Format_ARGB ? QColor::fromRgbF(m_color.x(), m_color.y(), m_color.z(), m_color.w()) : QColor();
- m_glyphCache = fontEngine->glyphCache(ctx, glyphFormat, glyphCacheTransform, color);
+ m_glyphCache = fontEngine->glyphCache(cacheKey, glyphFormat, glyphCacheTransform, color);
if (!m_glyphCache || int(m_glyphCache->glyphFormat()) != glyphFormat) {
- m_glyphCache = new QOpenGLTextureGlyphCache(glyphFormat, glyphCacheTransform, color);
- fontEngine->setGlyphCache(ctx, m_glyphCache.data());
- auto sg = QSGDefaultRenderContext::from(ctx);
- Q_ASSERT(sg);
- sg->registerFontengineForCleanup(fontEngine);
+ if (m_rhi)
+ m_glyphCache = new QSGRhiTextureGlyphCache(m_rhi, glyphFormat, glyphCacheTransform, color);
+ else
+ m_glyphCache = new QOpenGLTextureGlyphCache(glyphFormat, glyphCacheTransform, color);
+
+ fontEngine->setGlyphCache(cacheKey, m_glyphCache.data());
+ m_rc->registerFontengineForCleanup(fontEngine);
}
}
-
}
void QSGTextMaskMaterial::populate(const QPointF &p,
@@ -578,21 +885,45 @@ QSGMaterialType *QSGTextMaskMaterial::type() const
}
}
-QOpenGLTextureGlyphCache *QSGTextMaskMaterial::glyphCache() const
+QTextureGlyphCache *QSGTextMaskMaterial::glyphCache() const
{
- return static_cast<QOpenGLTextureGlyphCache*>(m_glyphCache.data());
+ return static_cast<QTextureGlyphCache *>(m_glyphCache.data());
+}
+
+QOpenGLTextureGlyphCache *QSGTextMaskMaterial::openglGlyphCache() const
+{
+ return static_cast<QOpenGLTextureGlyphCache *>(glyphCache());
+}
+
+QSGRhiTextureGlyphCache *QSGTextMaskMaterial::rhiGlyphCache() const
+{
+ return static_cast<QSGRhiTextureGlyphCache *>(glyphCache());
}
QSGMaterialShader *QSGTextMaskMaterial::createShader() const
{
- switch (QFontEngine::GlyphFormat glyphFormat = glyphCache()->glyphFormat()) {
- case QFontEngine::Format_ARGB:
- return new QSG32BitColorTextShader(glyphFormat);
- case QFontEngine::Format_A32:
- return new QSG24BitTextMaskShader(glyphFormat);
- case QFontEngine::Format_A8:
- default:
- return new QSG8BitTextMaskShader(glyphFormat);
+ if (flags().testFlag(RhiShaderWanted)) {
+ QSGRhiTextureGlyphCache *gc = rhiGlyphCache();
+ const QFontEngine::GlyphFormat glyphFormat = gc->glyphFormat();
+ switch (glyphFormat) {
+ case QFontEngine::Format_ARGB:
+ return new QSG32BitColorTextRhiShader(glyphFormat);
+ case QFontEngine::Format_A32:
+ return new QSG24BitTextMaskRhiShader(glyphFormat);
+ case QFontEngine::Format_A8:
+ default:
+ return new QSG8BitTextMaskRhiShader(glyphFormat, gc->eightBitFormatIsAlphaSwizzled());
+ }
+ } else {
+ switch (QFontEngine::GlyphFormat glyphFormat = glyphCache()->glyphFormat()) {
+ case QFontEngine::Format_ARGB:
+ return new QSG32BitColorTextShader(glyphFormat);
+ case QFontEngine::Format_A32:
+ return new QSG24BitTextMaskShader(glyphFormat);
+ case QFontEngine::Format_A8:
+ default:
+ return new QSG8BitTextMaskShader(glyphFormat);
+ }
}
}
@@ -620,36 +951,40 @@ int QSGTextMaskMaterial::compare(const QSGMaterial *o) const
bool QSGTextMaskMaterial::ensureUpToDate()
{
- QSize glyphCacheSize(glyphCache()->width(), glyphCache()->height());
- if (glyphCacheSize != m_size) {
- if (m_texture)
- delete m_texture;
- m_texture = new QSGPlainTexture();
- m_texture->setTextureId(glyphCache()->texture());
- m_texture->setTextureSize(QSize(glyphCache()->width(), glyphCache()->height()));
- m_texture->setOwnsTexture(false);
-
- m_size = glyphCacheSize;
+ if (m_rhi) {
+ QSGRhiTextureGlyphCache *gc = rhiGlyphCache();
+ QSize glyphCacheSize(gc->width(), gc->height());
+ if (glyphCacheSize != m_size) {
+ if (m_texture)
+ delete m_texture;
+ m_texture = new QSGPlainTexture;
+ m_texture->setTexture(gc->texture());
+ m_texture->setTextureSize(QSize(gc->width(), gc->height()));
+ m_texture->setOwnsTexture(false);
+ m_size = glyphCacheSize;
+ return true;
+ }
+ return false;
- return true;
} else {
+ QSize glyphCacheSize(openglGlyphCache()->width(), openglGlyphCache()->height());
+ if (glyphCacheSize != m_size) {
+ if (m_texture)
+ delete m_texture;
+ m_texture = new QSGPlainTexture();
+ m_texture->setTextureId(openglGlyphCache()->texture());
+ m_texture->setTextureSize(QSize(openglGlyphCache()->width(), openglGlyphCache()->height()));
+ m_texture->setOwnsTexture(false);
+ m_size = glyphCacheSize;
+ return true;
+ }
return false;
}
}
-int QSGTextMaskMaterial::cacheTextureWidth() const
-{
- return glyphCache()->width();
-}
-int QSGTextMaskMaterial::cacheTextureHeight() const
-{
- return glyphCache()->height();
-}
-
-
-QSGStyledTextMaterial::QSGStyledTextMaterial(const QRawFont &font)
- : QSGTextMaskMaterial(QVector4D(), font, QFontEngine::Format_A8)
+QSGStyledTextMaterial::QSGStyledTextMaterial(QSGRenderContext *rc, const QRawFont &font)
+ : QSGTextMaskMaterial(rc, QVector4D(), font, QFontEngine::Format_A8)
{
}
@@ -661,7 +996,12 @@ QSGMaterialType *QSGStyledTextMaterial::type() const
QSGMaterialShader *QSGStyledTextMaterial::createShader() const
{
- return new QSGStyledTextShader(glyphCache()->glyphFormat());
+ if (flags().testFlag(RhiShaderWanted)) {
+ QSGRhiTextureGlyphCache *gc = rhiGlyphCache();
+ return new QSGStyledTextRhiShader(gc->glyphFormat(), gc->eightBitFormatIsAlphaSwizzled());
+ } else {
+ return new QSGStyledTextShader(glyphCache()->glyphFormat());
+ }
}
int QSGStyledTextMaterial::compare(const QSGMaterial *o) const
@@ -678,8 +1018,8 @@ int QSGStyledTextMaterial::compare(const QSGMaterial *o) const
}
-QSGOutlinedTextMaterial::QSGOutlinedTextMaterial(const QRawFont &font)
- : QSGStyledTextMaterial(font)
+QSGOutlinedTextMaterial::QSGOutlinedTextMaterial(QSGRenderContext *rc, const QRawFont &font)
+ : QSGStyledTextMaterial(rc, font)
{
}
@@ -691,7 +1031,12 @@ QSGMaterialType *QSGOutlinedTextMaterial::type() const
QSGMaterialShader *QSGOutlinedTextMaterial::createShader() const
{
- return new QSGOutlinedTextShader(glyphCache()->glyphFormat());
+ if (flags().testFlag(RhiShaderWanted)) {
+ QSGRhiTextureGlyphCache *gc = rhiGlyphCache();
+ return new QSGOutlinedTextRhiShader(gc->glyphFormat(), gc->eightBitFormatIsAlphaSwizzled());
+ } else {
+ return new QSGOutlinedTextShader(glyphCache()->glyphFormat());
+ }
}
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.h b/src/quick/scenegraph/qsgdefaultglyphnode_p.h
index 37a89c70b9..4cff2d3d24 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p.h
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.h
@@ -53,13 +53,14 @@
#include <private/qsgadaptationlayer_p.h>
#include <private/qsgbasicglyphnode_p.h>
+#include <qlinkedlist.h>
QT_BEGIN_NAMESPACE
class QSGDefaultGlyphNode : public QSGBasicGlyphNode
{
public:
- QSGDefaultGlyphNode();
+ QSGDefaultGlyphNode(QSGRenderContext *context);
~QSGDefaultGlyphNode();
void setMaterialColor(const QColor &color) override;
void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) override;
@@ -75,8 +76,9 @@ private:
void setGlyphNodeType(DefaultGlyphNodeType type) { m_glyphNodeType = type; }
+ QSGRenderContext *m_context;
DefaultGlyphNodeType m_glyphNodeType;
- QLinkedList<QSGNode *> m_nodesToDelete;
+ QVector<QSGNode *> m_nodesToDelete;
struct GlyphInfo {
QVector<quint32> indexes;
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h b/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
index 56084dea96..7d2635794d 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
@@ -57,7 +57,8 @@
#include <QtQuick/qsgtexture.h>
#include <QtQuick/qsggeometry.h>
#include <qshareddata.h>
-#include <QtQuick/private/qsgtexture_p.h>
+#include <QtQuick/private/qsgplaintexture_p.h>
+#include <QtQuick/private/qsgrhitextureglyphcache_p.h>
#include <qrawfont.h>
#include <qmargins.h>
@@ -65,10 +66,13 @@ QT_BEGIN_NAMESPACE
class QFontEngine;
class Geometry;
+class QSGRenderContext;
+class QSGDefaultRenderContext;
+
class QSGTextMaskMaterial: public QSGMaterial
{
public:
- QSGTextMaskMaterial(const QVector4D &color, const QRawFont &font, QFontEngine::GlyphFormat glyphFormat = QFontEngine::Format_None);
+ QSGTextMaskMaterial(QSGRenderContext *rc, const QVector4D &color, const QRawFont &font, QFontEngine::GlyphFormat glyphFormat = QFontEngine::Format_None);
virtual ~QSGTextMaskMaterial();
QSGMaterialType *type() const override;
@@ -81,12 +85,12 @@ public:
QSGTexture *texture() const { return m_texture; }
- int cacheTextureWidth() const;
- int cacheTextureHeight() const;
-
bool ensureUpToDate();
- QOpenGLTextureGlyphCache *glyphCache() const;
+ QTextureGlyphCache *glyphCache() const;
+ QOpenGLTextureGlyphCache *openglGlyphCache() const;
+ QSGRhiTextureGlyphCache *rhiGlyphCache() const;
+
void populate(const QPointF &position,
const QVector<quint32> &glyphIndexes, const QVector<QPointF> &glyphPositions,
QSGGeometry *geometry, QRectF *boundingRect, QPointF *baseLine,
@@ -96,9 +100,11 @@ private:
void init(QFontEngine::GlyphFormat glyphFormat);
void updateCache(QFontEngine::GlyphFormat glyphFormat);
+ QSGDefaultRenderContext *m_rc;
QSGPlainTexture *m_texture;
QExplicitlySharedDataPointer<QFontEngineGlyphCache> m_glyphCache;
QRawFont m_font;
+ QRhi *m_rhi;
QVector4D m_color;
QSize m_size;
};
@@ -106,7 +112,7 @@ private:
class QSGStyledTextMaterial : public QSGTextMaskMaterial
{
public:
- QSGStyledTextMaterial(const QRawFont &font);
+ QSGStyledTextMaterial(QSGRenderContext *rc, const QRawFont &font);
virtual ~QSGStyledTextMaterial() { }
void setStyleShift(const QVector2D &shift) { m_styleShift = shift; }
@@ -118,7 +124,6 @@ public:
QSGMaterialType *type() const override;
QSGMaterialShader *createShader() const override;
-
int compare(const QSGMaterial *other) const override;
private:
@@ -129,7 +134,7 @@ private:
class QSGOutlinedTextMaterial : public QSGStyledTextMaterial
{
public:
- QSGOutlinedTextMaterial(const QRawFont &font);
+ QSGOutlinedTextMaterial(QSGRenderContext *rc, const QRawFont &font);
~QSGOutlinedTextMaterial() { }
QSGMaterialType *type() const override;
diff --git a/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp b/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp
index 5dd6eaa4ca..500d4e6e95 100644
--- a/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp
+++ b/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp
@@ -38,10 +38,12 @@
****************************************************************************/
#include "qsgdefaultinternalimagenode_p.h"
+#include <private/qsgdefaultrendercontext_p.h>
#include <private/qsgmaterialshader_p.h>
#include <private/qsgtexturematerial_p.h>
#include <QtGui/qopenglfunctions.h>
#include <QtCore/qmath.h>
+#include <QtGui/private/qrhi_p.h>
QT_BEGIN_NAMESPACE
@@ -59,9 +61,18 @@ protected:
int m_pixelSizeLoc;
};
+class SmoothTextureMaterialRhiShader : public QSGTextureMaterialRhiShader
+{
+public:
+ SmoothTextureMaterialRhiShader();
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
QSGSmoothTextureMaterial::QSGSmoothTextureMaterial()
{
+ setFlag(SupportsRhiShader, true);
setFlag(RequiresFullMatrixExceptTranslate, true);
setFlag(Blending, true);
}
@@ -79,7 +90,10 @@ QSGMaterialType *QSGSmoothTextureMaterial::type() const
QSGMaterialShader *QSGSmoothTextureMaterial::createShader() const
{
- return new SmoothTextureMaterialShader;
+ if (flags().testFlag(RhiShaderWanted))
+ return new SmoothTextureMaterialRhiShader;
+ else
+ return new SmoothTextureMaterialShader;
}
SmoothTextureMaterialShader::SmoothTextureMaterialShader()
@@ -116,7 +130,33 @@ void SmoothTextureMaterialShader::initialize()
QSGTextureMaterialShader::initialize();
}
-QSGDefaultInternalImageNode::QSGDefaultInternalImageNode()
+SmoothTextureMaterialRhiShader::SmoothTextureMaterialRhiShader()
+{
+ setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothtexture.vert.qsb"));
+ setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothtexture.frag.qsb"));
+}
+
+bool SmoothTextureMaterialRhiShader::updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+
+ if (!oldMaterial) {
+ // The viewport is constant, so set the pixel size uniform only once (per batches with the same material).
+ const QRect r = state.viewportRect();
+ const QVector2D v(2.0f / r.width(), 2.0f / r.height());
+ memcpy(buf->data() + 64 + 8, &v, 8);
+ changed = true;
+ }
+
+ changed |= QSGTextureMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
+
+ return changed;
+}
+
+
+QSGDefaultInternalImageNode::QSGDefaultInternalImageNode(QSGDefaultRenderContext *rc)
+ : m_rc(rc)
{
setMaterial(&m_materialO);
setOpaqueMaterial(&m_material);
@@ -209,14 +249,19 @@ bool QSGDefaultInternalImageNode::supportsWrap(const QSize &size) const
{
bool wrapSupported = true;
- QOpenGLContext *ctx = QOpenGLContext::currentContext();
+ if (m_rc->rhi()) {
+ wrapSupported = m_rc->rhi()->isFeatureSupported(QRhi::NPOTTextureRepeat)
+ || (isPowerOfTwo(size.width()) && isPowerOfTwo(size.height()));
+ } else {
+ QOpenGLContext *ctx = QOpenGLContext::currentContext();
#ifndef QT_OPENGL_ES_2
- if (ctx->isOpenGLES())
+ if (ctx->isOpenGLES())
#endif
- {
- bool npotSupported = ctx->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat);
- const bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height());
- wrapSupported = npotSupported || !isNpot;
+ {
+ bool npotSupported = ctx->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat);
+ const bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height());
+ wrapSupported = npotSupported || !isNpot;
+ }
}
return wrapSupported;
diff --git a/src/quick/scenegraph/qsgdefaultinternalimagenode_p.h b/src/quick/scenegraph/qsgdefaultinternalimagenode_p.h
index 1fc7834bd1..b4cfbd9ece 100644
--- a/src/quick/scenegraph/qsgdefaultinternalimagenode_p.h
+++ b/src/quick/scenegraph/qsgdefaultinternalimagenode_p.h
@@ -58,6 +58,8 @@
QT_BEGIN_NAMESPACE
+class QSGDefaultRenderContext;
+
class Q_QUICK_PRIVATE_EXPORT QSGSmoothTextureMaterial : public QSGTextureMaterial
{
public:
@@ -73,7 +75,7 @@ protected:
class Q_QUICK_PRIVATE_EXPORT QSGDefaultInternalImageNode : public QSGBasicInternalImageNode
{
public:
- QSGDefaultInternalImageNode();
+ QSGDefaultInternalImageNode(QSGDefaultRenderContext *rc);
void setMipmapFiltering(QSGTexture::Filtering filtering) override;
void setFiltering(QSGTexture::Filtering filtering) override;
@@ -87,6 +89,7 @@ public:
bool supportsWrap(const QSize &size) const override;
private:
+ QSGDefaultRenderContext *m_rc;
QSGOpaqueTextureMaterial m_material;
QSGTextureMaterial m_materialO;
QSGSmoothTextureMaterial m_smoothMaterial;
diff --git a/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp b/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp
index fd0dcebd57..5e4affbf90 100644
--- a/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp
+++ b/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp
@@ -105,14 +105,61 @@ void SmoothColorMaterialShader::initialize()
m_pixelSizeLoc = program()->uniformLocation("pixelSize");
}
+
+class SmoothColorMaterialRhiShader : public QSGMaterialRhiShader
+{
+public:
+ SmoothColorMaterialRhiShader();
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+SmoothColorMaterialRhiShader::SmoothColorMaterialRhiShader()
+{
+ setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothcolor.vert.qsb"));
+ setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothcolor.frag.qsb"));
+}
+
+bool SmoothColorMaterialRhiShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *oldMaterial)
+{
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+
+ if (state.isMatrixDirty()) {
+ const QMatrix4x4 m = state.combinedMatrix();
+ memcpy(buf->data(), m.constData(), 64);
+ changed = true;
+ }
+
+ if (oldMaterial == nullptr) {
+ // The viewport is constant, so set the pixel size uniform only once.
+ const QRect r = state.viewportRect();
+ const QVector2D v(2.0f / r.width(), 2.0f / r.height());
+ Q_ASSERT(sizeof(v) == 8);
+ memcpy(buf->data() + 64, &v, 8);
+ changed = true;
+ }
+
+ if (state.isOpacityDirty()) {
+ const float opacity = state.opacity();
+ memcpy(buf->data() + 72, &opacity, 4);
+ changed = true;
+ }
+
+ return changed;
+}
+
+
QSGSmoothColorMaterial::QSGSmoothColorMaterial()
{
setFlag(RequiresFullMatrixExceptTranslate, true);
setFlag(Blending, true);
+ setFlag(SupportsRhiShader, true);
}
int QSGSmoothColorMaterial::compare(const QSGMaterial *) const
{
+ // all state in vertex attributes -> all smoothcolor materials are equal
return 0;
}
@@ -124,7 +171,10 @@ QSGMaterialType *QSGSmoothColorMaterial::type() const
QSGMaterialShader *QSGSmoothColorMaterial::createShader() const
{
- return new SmoothColorMaterialShader;
+ if (flags().testFlag(RhiShaderWanted))
+ return new SmoothColorMaterialRhiShader;
+ else
+ return new SmoothColorMaterialShader;
}
QSGDefaultInternalRectangleNode::QSGDefaultInternalRectangleNode()
diff --git a/src/quick/scenegraph/qsgdefaultrendercontext.cpp b/src/quick/scenegraph/qsgdefaultrendercontext.cpp
index 73b79c6300..2bf4a83a8e 100644
--- a/src/quick/scenegraph/qsgdefaultrendercontext.cpp
+++ b/src/quick/scenegraph/qsgdefaultrendercontext.cpp
@@ -44,9 +44,13 @@
#include <QtQuick/private/qsgbatchrenderer_p.h>
#include <QtQuick/private/qsgrenderer_p.h>
-#include <QtQuick/private/qsgatlastexture_p.h>
+#include <QtQuick/private/qsgrhiatlastexture_p.h>
+#include <QtQuick/private/qsgrhidistancefieldglyphcache_p.h>
+#include <QtQuick/private/qsgmaterialrhishader_p.h>
+
+#include <QtQuick/private/qsgopenglatlastexture_p.h>
#include <QtQuick/private/qsgcompressedtexture_p.h>
-#include <QtQuick/private/qsgdefaultdistancefieldglyphcache_p.h>
+#include <QtQuick/private/qsgopengldistancefieldglyphcache_p.h>
QT_BEGIN_NAMESPACE
@@ -54,68 +58,82 @@ QT_BEGIN_NAMESPACE
QSGDefaultRenderContext::QSGDefaultRenderContext(QSGContext *context)
: QSGRenderContext(context)
+ , m_rhi(nullptr)
, m_gl(nullptr)
, m_depthStencilManager(nullptr)
, m_maxTextureSize(0)
, m_brokenIBOs(false)
, m_serializedRender(false)
, m_attachToGLContext(true)
- , m_atlasManager(nullptr)
+ , m_glAtlasManager(nullptr)
+ , m_rhiAtlasManager(nullptr)
+ , m_currentFrameCommandBuffer(nullptr)
+ , m_currentFrameRenderPass(nullptr)
{
-
}
/*!
Initializes the scene graph render context with the GL context \a context. This also
emits the ready() signal so that the QML graph can start building scene graph nodes.
*/
-void QSGDefaultRenderContext::initialize(void *context)
+void QSGDefaultRenderContext::initialize(const QSGRenderContext::InitParams *params)
{
if (!m_sg)
return;
- QOpenGLContext *openglContext = static_cast<QOpenGLContext *>(context);
-
- QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
- funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize);
+ const InitParams *initParams = static_cast<const InitParams *>(params);
+ if (initParams->sType != INIT_PARAMS_MAGIC)
+ qFatal("QSGDefaultRenderContext: Invalid parameters passed to initialize()");
- // Sanity check the surface format, in case it was overridden by the application
- QSurfaceFormat requested = m_sg->defaultSurfaceFormat();
- QSurfaceFormat actual = openglContext->format();
- if (requested.depthBufferSize() > 0 && actual.depthBufferSize() <= 0)
- qWarning("QSGContext::initialize: depth buffer support missing, expect rendering errors");
- if (requested.stencilBufferSize() > 0 && actual.stencilBufferSize() <= 0)
- qWarning("QSGContext::initialize: stencil buffer support missing, expect rendering errors");
+ m_initParams = *initParams;
- if (!m_atlasManager)
- m_atlasManager = new QSGAtlasTexture::Manager();
+ m_rhi = m_initParams.rhi;
+ if (m_rhi) {
+ m_maxTextureSize = m_rhi->resourceLimit(QRhi::TextureSizeMax);
+ if (!m_rhiAtlasManager)
+ m_rhiAtlasManager = new QSGRhiAtlasTexture::Manager(this, m_initParams.initialSurfacePixelSize, m_initParams.maybeSurface);
+ } else {
+ QOpenGLFunctions *funcs = m_rhi ? nullptr : QOpenGLContext::currentContext()->functions();
+ funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize);
- Q_ASSERT_X(!m_gl, "QSGRenderContext::initialize", "already initialized!");
- m_gl = openglContext;
- if (m_attachToGLContext) {
- Q_ASSERT(!openglContext->property(QSG_RENDERCONTEXT_PROPERTY).isValid());
- openglContext->setProperty(QSG_RENDERCONTEXT_PROPERTY, QVariant::fromValue(this));
- }
- m_sg->renderContextInitialized(this);
+ // Sanity check the surface format, in case it was overridden by the application
+ QSurfaceFormat requested = m_sg->defaultSurfaceFormat();
+ QSurfaceFormat actual = m_initParams.openGLContext->format();
+ if (requested.depthBufferSize() > 0 && actual.depthBufferSize() <= 0)
+ qWarning("QSGContext::initialize: depth buffer support missing, expect rendering errors");
+ if (requested.stencilBufferSize() > 0 && actual.stencilBufferSize() <= 0)
+ qWarning("QSGContext::initialize: stencil buffer support missing, expect rendering errors");
#ifdef Q_OS_LINUX
- const char *vendor = (const char *) funcs->glGetString(GL_VENDOR);
- if (vendor && strstr(vendor, "nouveau"))
- m_brokenIBOs = true;
- const char *renderer = (const char *) funcs->glGetString(GL_RENDERER);
- if (renderer && strstr(renderer, "llvmpipe"))
- m_serializedRender = true;
- if (vendor && renderer && strstr(vendor, "Hisilicon Technologies") && strstr(renderer, "Immersion.16"))
- m_brokenIBOs = true;
+ const char *vendor = (const char *) funcs->glGetString(GL_VENDOR);
+ if (vendor && strstr(vendor, "nouveau"))
+ m_brokenIBOs = true;
+ const char *renderer = (const char *) funcs->glGetString(GL_RENDERER);
+ if (renderer && strstr(renderer, "llvmpipe"))
+ m_serializedRender = true;
+ if (vendor && renderer && strstr(vendor, "Hisilicon Technologies") && strstr(renderer, "Immersion.16"))
+ m_brokenIBOs = true;
#endif
+ Q_ASSERT_X(!m_gl, "QSGRenderContext::initialize", "already initialized!");
+ m_gl = m_initParams.openGLContext;
+ if (m_attachToGLContext) {
+ Q_ASSERT(!m_gl->property(QSG_RENDERCONTEXT_PROPERTY).isValid());
+ m_gl->setProperty(QSG_RENDERCONTEXT_PROPERTY, QVariant::fromValue(this));
+ }
+
+ if (!m_glAtlasManager)
+ m_glAtlasManager = new QSGOpenGLAtlasTexture::Manager(m_initParams.initialSurfacePixelSize);
+ }
+
+ m_sg->renderContextInitialized(this);
+
emit initialized();
}
-
void QSGDefaultRenderContext::invalidate()
{
- if (!m_gl)
+ if (!m_gl && !m_rhi)
return;
qDeleteAll(m_texturesToDelete);
@@ -138,11 +156,18 @@ void QSGDefaultRenderContext::invalidate()
deferred deleted last.
Another alternative would be to use a QPointer in
- QSGAtlasTexture::Texture, but this seemed simpler.
+ QSGOpenGLAtlasTexture::Texture, but this seemed simpler.
*/
- m_atlasManager->invalidate();
- m_atlasManager->deleteLater();
- m_atlasManager = nullptr;
+ if (m_glAtlasManager) {
+ m_glAtlasManager->invalidate();
+ m_glAtlasManager->deleteLater();
+ m_glAtlasManager = nullptr;
+ }
+ if (m_rhiAtlasManager) {
+ m_rhiAtlasManager->invalidate();
+ m_rhiAtlasManager->deleteLater();
+ m_rhiAtlasManager = nullptr;
+ }
// The following piece of code will read/write to the font engine's caches,
// potentially from different threads. However, this is safe because this
@@ -151,7 +176,7 @@ void QSGDefaultRenderContext::invalidate()
// sequence. (see qsgdefaultglyphnode_p.cpp's init())
for (QSet<QFontEngine *>::const_iterator it = m_fontEnginesToClean.constBegin(),
end = m_fontEnginesToClean.constEnd(); it != end; ++it) {
- (*it)->clearGlyphCache(m_gl);
+ (*it)->clearGlyphCache(m_gl ? (void *) m_gl : (void *) m_rhi);
if (!(*it)->ref.deref())
delete *it;
}
@@ -163,17 +188,33 @@ void QSGDefaultRenderContext::invalidate()
qDeleteAll(m_glyphCaches);
m_glyphCaches.clear();
- if (m_gl->property(QSG_RENDERCONTEXT_PROPERTY) == QVariant::fromValue(this))
+ if (m_gl && m_gl->property(QSG_RENDERCONTEXT_PROPERTY) == QVariant::fromValue(this))
m_gl->setProperty(QSG_RENDERCONTEXT_PROPERTY, QVariant());
+
m_gl = nullptr;
+ m_rhi = nullptr;
if (m_sg)
m_sg->renderContextInvalidated(this);
+
emit invalidated();
}
+void QSGDefaultRenderContext::prepareSync(qreal devicePixelRatio)
+{
+ m_currentDevicePixelRatio = devicePixelRatio;
+}
+
static QBasicMutex qsg_framerender_mutex;
+void QSGDefaultRenderContext::beginNextFrame(QSGRenderer *renderer,
+ RenderPassCallback mainPassRecordingStart,
+ RenderPassCallback mainPassRecordingEnd,
+ void *callbackUserData)
+{
+ renderer->setRenderPassRecordingCallbacks(mainPassRecordingStart, mainPassRecordingEnd, callbackUserData);
+}
+
void QSGDefaultRenderContext::renderNextFrame(QSGRenderer *renderer, uint fboId)
{
if (m_serializedRender)
@@ -185,6 +226,40 @@ void QSGDefaultRenderContext::renderNextFrame(QSGRenderer *renderer, uint fboId)
qsg_framerender_mutex.unlock();
}
+void QSGDefaultRenderContext::endNextFrame(QSGRenderer *renderer)
+{
+ Q_UNUSED(renderer);
+}
+
+void QSGDefaultRenderContext::beginNextRhiFrame(QSGRenderer *renderer, QRhiRenderTarget *rt, QRhiRenderPassDescriptor *rp,
+ QRhiCommandBuffer *cb,
+ RenderPassCallback mainPassRecordingStart,
+ RenderPassCallback mainPassRecordingEnd,
+ void *callbackUserData)
+{
+ Q_ASSERT(!m_currentFrameCommandBuffer);
+
+ renderer->setRenderTarget(rt);
+ renderer->setRenderPassDescriptor(rp);
+ renderer->setCommandBuffer(cb);
+ renderer->setRenderPassRecordingCallbacks(mainPassRecordingStart, mainPassRecordingEnd, callbackUserData);
+
+ m_currentFrameCommandBuffer = cb;
+ m_currentFrameRenderPass = rp;
+}
+
+void QSGDefaultRenderContext::renderNextRhiFrame(QSGRenderer *renderer)
+{
+ renderer->renderScene();
+}
+
+void QSGDefaultRenderContext::endNextRhiFrame(QSGRenderer *renderer)
+{
+ Q_UNUSED(renderer);
+ m_currentFrameCommandBuffer = nullptr;
+ m_currentFrameRenderPass = nullptr;
+}
+
/*!
Returns a shared pointer to a depth stencil buffer that can be used with \a fbo.
*/
@@ -226,13 +301,21 @@ QSGTexture *QSGDefaultRenderContext::createTexture(const QImage &image, uint fla
// The atlas implementation is only supported from the render thread and
// does not support mipmaps.
- if (!mipmap && atlas && openglContext() && QThread::currentThread() == openglContext()->thread()) {
- QSGTexture *t = m_atlasManager->create(image, alpha);
- if (t)
- return t;
+ if (m_rhi) {
+ if (!mipmap && atlas && QThread::currentThread() == m_rhi->thread()) {
+ QSGTexture *t = m_rhiAtlasManager->create(image, alpha);
+ if (t)
+ return t;
+ }
+ } else {
+ if (!mipmap && atlas && openglContext() && QThread::currentThread() == openglContext()->thread()) {
+ QSGTexture *t = m_glAtlasManager->create(image, alpha);
+ if (t)
+ return t;
+ }
}
- QSGPlainTexture *texture = new QSGPlainTexture();
+ QSGPlainTexture *texture = new QSGPlainTexture;
texture->setImage(image);
if (texture->hasAlphaChannel() && !alpha)
texture->setHasAlphaChannel(false);
@@ -247,9 +330,15 @@ QSGRenderer *QSGDefaultRenderContext::createRenderer()
QSGTexture *QSGDefaultRenderContext::compressedTextureForFactory(const QSGCompressedTextureFactory *factory) const
{
- // The atlas implementation is only supported from the render thread
- if (openglContext() && QThread::currentThread() == openglContext()->thread())
- return m_atlasManager->create(factory);
+ // This is only used for atlasing compressed textures. Returning null implies no atlas.
+
+ if (m_rhi) {
+ // ###
+ } else if (openglContext() && QThread::currentThread() == openglContext()->thread()) {
+ // The atlas implementation is only supported from the render thread
+ return m_glAtlasManager->create(factory);
+ }
+
return nullptr;
}
@@ -307,6 +396,11 @@ void QSGDefaultRenderContext::initializeShader(QSGMaterialShader *shader)
shader->initialize();
}
+void QSGDefaultRenderContext::initializeRhiShader(QSGMaterialRhiShader *shader, QShader::Variant shaderVariant)
+{
+ QSGMaterialRhiShaderPrivate::get(shader)->prepare(shaderVariant);
+}
+
void QSGDefaultRenderContext::setAttachToGraphicsContext(bool attach)
{
Q_ASSERT(!isValid());
@@ -320,6 +414,9 @@ QSGDefaultRenderContext *QSGDefaultRenderContext::from(QOpenGLContext *context)
bool QSGDefaultRenderContext::separateIndexBuffer() const
{
+ if (m_rhi)
+ return true;
+
// WebGL: A given WebGLBuffer object may only be bound to one of
// the ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target in its
// lifetime. An attempt to bind a buffer object to the other
@@ -335,7 +432,10 @@ QSGDistanceFieldGlyphCache *QSGDefaultRenderContext::distanceFieldGlyphCache(con
QString key = fontKey(font);
QSGDistanceFieldGlyphCache *cache = m_glyphCaches.value(key, 0);
if (!cache) {
- cache = new QSGDefaultDistanceFieldGlyphCache(openglContext(), font);
+ if (m_rhi)
+ cache = new QSGRhiDistanceFieldGlyphCache(m_rhi, font);
+ else
+ cache = new QSGOpenGLDistanceFieldGlyphCache(openglContext(), font);
m_glyphCaches.insert(key, cache);
}
diff --git a/src/quick/scenegraph/qsgdefaultrendercontext_p.h b/src/quick/scenegraph/qsgdefaultrendercontext_p.h
index 57aa4b4c90..2fdb3a48dd 100644
--- a/src/quick/scenegraph/qsgdefaultrendercontext_p.h
+++ b/src/quick/scenegraph/qsgdefaultrendercontext_p.h
@@ -52,15 +52,29 @@
//
#include <QtQuick/private/qsgcontext_p.h>
+#include <QtGui/private/qshader_p.h>
+
+#if QT_CONFIG(opengl)
#include <QtQuick/private/qsgdepthstencilbuffer_p.h>
+#endif
QT_BEGIN_NAMESPACE
+class QRhi;
+class QRhiCommandBuffer;
+class QRhiRenderPassDescriptor;
class QOpenGLContext;
class QSGMaterialShader;
+class QSGMaterialRhiShader;
class QOpenGLFramebufferObject;
+class QSGDepthStencilBufferManager;
+class QSGDepthStencilBuffer;
+
+namespace QSGOpenGLAtlasTexture {
+ class Manager;
+}
-namespace QSGAtlasTexture {
+namespace QSGRhiAtlasTexture {
class Manager;
}
@@ -70,12 +84,41 @@ class Q_QUICK_PRIVATE_EXPORT QSGDefaultRenderContext : public QSGRenderContext
public:
QSGDefaultRenderContext(QSGContext *context);
+ QRhi *rhi() const override { return m_rhi; }
QOpenGLContext *openglContext() const { return m_gl; }
- bool isValid() const override { return m_gl; }
-
- void initialize(void *context) override;
+ bool isValid() const override { return m_gl || m_rhi; }
+
+ static const int INIT_PARAMS_MAGIC = 0x50E;
+ struct InitParams : public QSGRenderContext::InitParams {
+ int sType = INIT_PARAMS_MAGIC; // help discovering broken code passing something else as 'context'
+ QRhi *rhi = nullptr;
+ int sampleCount = 1; // 1, 4, 8, ...
+ QOpenGLContext *openGLContext = nullptr; // ### Qt 6: remove
+ // only used as a hint f.ex. in the texture atlas init
+ QSize initialSurfacePixelSize;
+ // The first window that will be used with this rc, if available.
+ // Only a hint, to help picking better values for atlases.
+ QSurface *maybeSurface = nullptr;
+ };
+
+ void initialize(const QSGRenderContext::InitParams *params) override;
void invalidate() override;
+
+ void prepareSync(qreal devicePixelRatio) override;
+ void beginNextFrame(QSGRenderer *renderer,
+ RenderPassCallback mainPassRecordingStart,
+ RenderPassCallback mainPassRecordingEnd,
+ void *callbackUserData) override;
void renderNextFrame(QSGRenderer *renderer, uint fboId) override;
+ void endNextFrame(QSGRenderer *renderer) override;
+
+ void beginNextRhiFrame(QSGRenderer *renderer,
+ QRhiRenderTarget *rt, QRhiRenderPassDescriptor *rp, QRhiCommandBuffer *cb,
+ RenderPassCallback mainPassRecordingStart,
+ RenderPassCallback mainPassRecordingEnd,
+ void *callbackUserData) override;
+ void renderNextRhiFrame(QSGRenderer *renderer) override;
+ void endNextRhiFrame(QSGRenderer *renderer) override;
QSGDistanceFieldGlyphCache *distanceFieldGlyphCache(const QRawFont &font) override;
@@ -88,6 +131,7 @@ public:
virtual void compileShader(QSGMaterialShader *shader, QSGMaterial *material, const char *vertexCode = nullptr, const char *fragmentCode = nullptr);
virtual void initializeShader(QSGMaterialShader *shader);
+ virtual void initializeRhiShader(QSGMaterialRhiShader *shader, QShader::Variant shaderVariant);
void setAttachToGraphicsContext(bool attach) override;
@@ -97,16 +141,44 @@ public:
int maxTextureSize() const override { return m_maxTextureSize; }
bool separateIndexBuffer() const;
+ int msaaSampleCount() const { return m_initParams.sampleCount; }
+
+ QRhiCommandBuffer *currentFrameCommandBuffer() const {
+ // may be null if not in an active frame, but returning null is valid then
+ return m_currentFrameCommandBuffer;
+ }
+ QRhiRenderPassDescriptor *currentFrameRenderPass() const {
+ // may be null if not in an active frame, but returning null is valid then
+ return m_currentFrameRenderPass;
+ }
+
+ qreal currentDevicePixelRatio() const
+ {
+ // Valid starting from QQuickWindow::syncSceneGraph(). This takes the
+ // redirections, e.g. QQuickWindow::setRenderTarget(), into account.
+ // This calculation logic matches what the renderer does, so this is
+ // the same value that gets exposed in RenderState::devicePixelRatio()
+ // to material shaders. This getter is useful to perform dpr-related
+ // operations in the sync phase (in updatePaintNode()).
+ return m_currentDevicePixelRatio;
+ }
+
protected:
static QString fontKey(const QRawFont &font);
+ InitParams m_initParams;
+ QRhi *m_rhi;
QOpenGLContext *m_gl;
QSGDepthStencilBufferManager *m_depthStencilManager;
int m_maxTextureSize;
bool m_brokenIBOs;
bool m_serializedRender;
bool m_attachToGLContext;
- QSGAtlasTexture::Manager *m_atlasManager;
+ QSGOpenGLAtlasTexture::Manager *m_glAtlasManager;
+ QSGRhiAtlasTexture::Manager *m_rhiAtlasManager;
+ QRhiCommandBuffer *m_currentFrameCommandBuffer;
+ QRhiRenderPassDescriptor *m_currentFrameRenderPass;
+ qreal m_currentDevicePixelRatio;
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgdefaultspritenode.cpp b/src/quick/scenegraph/qsgdefaultspritenode.cpp
index 8761d99c1f..6422a252d9 100644
--- a/src/quick/scenegraph/qsgdefaultspritenode.cpp
+++ b/src/quick/scenegraph/qsgdefaultspritenode.cpp
@@ -84,6 +84,7 @@ public:
QQuickSpriteMaterial::QQuickSpriteMaterial()
{
setFlag(Blending, true);
+ setFlag(SupportsRhiShader, true);
}
QQuickSpriteMaterial::~QQuickSpriteMaterial()
@@ -91,10 +92,10 @@ QQuickSpriteMaterial::~QQuickSpriteMaterial()
delete texture;
}
-class SpriteMaterialData : public QSGMaterialShader
+class SpriteMaterialShader : public QSGMaterialShader
{
public:
- SpriteMaterialData()
+ SpriteMaterialShader()
{
setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/sprite.vert"));
setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/sprite.frag"));
@@ -135,9 +136,79 @@ public:
int m_animPos_id;
};
+class SpriteMaterialRhiShader : public QSGMaterialRhiShader
+{
+public:
+ SpriteMaterialRhiShader();
+
+ bool updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+ void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+SpriteMaterialRhiShader::SpriteMaterialRhiShader()
+{
+ setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/sprite.vert.qsb"));
+ setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/sprite.frag.qsb"));
+}
+
+bool SpriteMaterialRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+#ifdef QT_NO_DEBUG
+ Q_UNUSED(oldMaterial);
+#endif
+ Q_ASSERT(oldMaterial == nullptr || newMaterial->type() == oldMaterial->type());
+ QQuickSpriteMaterial *mat = static_cast<QQuickSpriteMaterial *>(newMaterial);
+
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 96);
+
+ if (state.isMatrixDirty()) {
+ const QMatrix4x4 m = state.combinedMatrix();
+ memcpy(buf->data(), m.constData(), 64);
+ changed = true;
+ }
+
+ float animPosAndData[7] = { mat->animX1, mat->animY1, mat->animX2, mat->animY2,
+ mat->animW, mat->animH, mat->animT };
+ memcpy(buf->data() + 64, animPosAndData, 28);
+ changed = true;
+
+ if (state.isOpacityDirty()) {
+ const float opacity = state.opacity();
+ memcpy(buf->data() + 92, &opacity, 4);
+ changed = true;
+ }
+
+ return changed;
+}
+
+void SpriteMaterialRhiShader::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ if (binding != 1)
+ return;
+
+#ifdef QT_NO_DEBUG
+ Q_UNUSED(oldMaterial);
+#endif
+ Q_ASSERT(oldMaterial == nullptr || newMaterial->type() == oldMaterial->type());
+ QQuickSpriteMaterial *mat = static_cast<QQuickSpriteMaterial *>(newMaterial);
+
+ QSGTexture *t = mat->texture;
+ t->updateRhiTexture(state.rhi(), state.resourceUpdateBatch());
+ *texture = t;
+}
+
QSGMaterialShader *QQuickSpriteMaterial::createShader() const
{
- return new SpriteMaterialData;
+ if (flags().testFlag(RhiShaderWanted))
+ return new SpriteMaterialRhiShader;
+ else
+ return new SpriteMaterialShader;
}
static QSGGeometry::Attribute Sprite_Attributes[] = {
diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode.cpp b/src/quick/scenegraph/qsgdistancefieldglyphnode.cpp
index ae6336718e..0fa680a244 100644
--- a/src/quick/scenegraph/qsgdistancefieldglyphnode.cpp
+++ b/src/quick/scenegraph/qsgdistancefieldglyphnode.cpp
@@ -224,15 +224,19 @@ void QSGDistanceFieldGlyphNode::updateGeometry()
const QPointF position = positions.at(i);
const QSGDistanceFieldGlyphCache::Texture *texture = m_glyph_cache->glyphTexture(glyphIndex);
- if (texture->textureId && !m_texture)
+ if ((!texture->rhiBased && texture->textureId && !m_texture)
+ || (texture->rhiBased && texture->texture && !m_texture))
+ {
m_texture = texture;
+ }
// As we use UNSIGNED_SHORT indexing in the geometry, we overload the
- // "glyphsInOtherTextures" concept as overflow for if there are more than
- // 65536 vertices to render which would otherwise exceed the maximum index
- // size. This will cause sub-nodes to be recursively created to handle any
- // number of glyphs.
- if (m_texture != texture || vp.size() >= 65536) {
+ // "glyphsInOtherTextures" concept as overflow for if there are more
+ // than 65535 vertices to render which would otherwise exceed the
+ // maximum index size. (leave 0xFFFF unused in order not to clash with
+ // primitive restart) This will cause sub-nodes to be recursively
+ // created to handle any number of glyphs.
+ if (m_texture != texture || vp.size() >= 65535) {
if (texture->textureId) {
GlyphInfo &glyphInfo = glyphsInOtherTextures[texture];
glyphInfo.indexes.append(glyphIndex);
diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp
index aa58218505..e8e9f76d04 100644
--- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp
+++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -38,7 +38,7 @@
****************************************************************************/
#include "qsgdistancefieldglyphnode_p_p.h"
-#include <QtQuick/private/qsgtexture_p.h>
+#include "qsgrhidistancefieldglyphcache_p.h"
#include <QtGui/qopenglfunctions.h>
#include <QtGui/qsurface.h>
#include <QtGui/qwindow.h>
@@ -46,6 +46,30 @@
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 thresholdFunc(float glyphScale)
+{
+ 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 spreadFunc(float glyphScale)
+{
+ static const float range = qt_sg_envFloat("QT_DF_RANGE", 0.06f);
+ return range / glyphScale;
+}
+
class QSGDistanceFieldTextMaterialShader : public QSGMaterialShader
{
public:
@@ -87,30 +111,6 @@ QSGDistanceFieldTextMaterialShader::QSGDistanceFieldTextMaterialShader()
setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/distancefieldtext.frag"));
}
-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 thresholdFunc(float glyphScale)
-{
- 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 spreadFunc(float glyphScale)
-{
- static const float range = qt_sg_envFloat("QT_DF_RANGE", 0.06f);
- return range / glyphScale;
-}
-
void QSGDistanceFieldTextMaterialShader::updateAlphaRange()
{
float combinedScale = m_fontScale * m_matrixScale;
@@ -207,16 +207,115 @@ void QSGDistanceFieldTextMaterialShader::updateState(const RenderState &state, Q
}
}
+class QSGDistanceFieldTextMaterialRhiShader : public QSGMaterialRhiShader
+{
+public:
+ QSGDistanceFieldTextMaterialRhiShader(bool alphaTexture);
+
+ bool updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+
+ void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+
+protected:
+ float m_fontScale = 1.0;
+ float m_matrixScale = 1.0;
+};
+
+QSGDistanceFieldTextMaterialRhiShader::QSGDistanceFieldTextMaterialRhiShader(bool alphaTexture)
+{
+ setShaderFileName(VertexStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldtext.vert.qsb"));
+ if (alphaTexture)
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldtext_a.frag.qsb"));
+ else
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldtext.frag.qsb"));
+}
+
+bool QSGDistanceFieldTextMaterialRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ Q_ASSERT(oldMaterial == nullptr || newMaterial->type() == oldMaterial->type());
+ QSGDistanceFieldTextMaterial *mat = static_cast<QSGDistanceFieldTextMaterial *>(newMaterial);
+ QSGDistanceFieldTextMaterial *oldMat = static_cast<QSGDistanceFieldTextMaterial *>(oldMaterial);
+
+ // updateUniformData() is called before updateSampledImage() by the
+ // renderer. Hence updating the glyph cache stuff here.
+ const bool textureUpdated = mat->updateTextureSizeAndWrapper();
+ Q_ASSERT(mat->wrapperTexture());
+ Q_ASSERT(oldMat == nullptr || oldMat->texture());
+
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 104);
+
+ bool updateRange = false;
+ if (!oldMat || mat->fontScale() != oldMat->fontScale()) {
+ m_fontScale = mat->fontScale();
+ updateRange = true;
+ }
+ if (state.isMatrixDirty()) {
+ const QMatrix4x4 m = state.combinedMatrix();
+ memcpy(buf->data(), m.constData(), 64);
+ changed = true;
+ m_matrixScale = qSqrt(qAbs(state.determinant())) * state.devicePixelRatio();
+ updateRange = true;
+ }
+ if (textureUpdated || !oldMat || oldMat->texture()->texture != mat->texture()->texture) {
+ const QVector2D ts(1.0f / mat->textureSize().width(), 1.0f / mat->textureSize().height());
+ Q_ASSERT(sizeof(ts) == 8);
+ memcpy(buf->data() + 64, &ts, 8);
+ changed = true;
+ }
+ if (!oldMat || mat->color() != oldMat->color() || state.isOpacityDirty()) {
+ const QVector4D color = mat->color() * state.opacity();
+ Q_ASSERT(sizeof(color) == 16);
+ memcpy(buf->data() + 80, &color, 16);
+ changed = true;
+ }
+ if (updateRange) { // deferred because depends on m_fontScale and m_matrixScale
+ const float combinedScale = m_fontScale * m_matrixScale;
+ const float base = thresholdFunc(combinedScale);
+ const float range = spreadFunc(combinedScale);
+ const QVector2D alphaMinMax(qMax(0.0f, base - range), qMin(base + range, 1.0f));
+ memcpy(buf->data() + 96, &alphaMinMax, 8);
+ changed = true;
+ }
+
+ // move texture uploads/copies onto the renderer's soon-to-be-committed list
+ static_cast<QSGRhiDistanceFieldGlyphCache *>(mat->glyphCache())->commitResourceUpdates(state.resourceUpdateBatch());
+
+ return changed;
+}
+
+void QSGDistanceFieldTextMaterialRhiShader::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *)
+{
+ Q_UNUSED(state);
+ if (binding != 1)
+ return;
+
+ QSGDistanceFieldTextMaterial *mat = static_cast<QSGDistanceFieldTextMaterial *>(newMaterial);
+ QSGTexture *t = mat->wrapperTexture();
+ t->setFiltering(QSGTexture::Linear);
+ *texture = t;
+}
+
QSGDistanceFieldTextMaterial::QSGDistanceFieldTextMaterial()
: m_glyph_cache(nullptr)
, m_texture(nullptr)
, m_fontScale(1.0)
+ , m_sgTexture(nullptr)
{
- setFlag(Blending | RequiresDeterminant, true);
+ setFlag(Blending | RequiresDeterminant | SupportsRhiShader, true);
}
QSGDistanceFieldTextMaterial::~QSGDistanceFieldTextMaterial()
{
+ delete m_sgTexture;
}
QSGMaterialType *QSGDistanceFieldTextMaterial::type() const
@@ -235,7 +334,10 @@ void QSGDistanceFieldTextMaterial::setColor(const QColor &color)
QSGMaterialShader *QSGDistanceFieldTextMaterial::createShader() const
{
- return new QSGDistanceFieldTextMaterialShader;
+ if (flags().testFlag(RhiShaderWanted))
+ return new QSGDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled());
+ else
+ return new QSGDistanceFieldTextMaterialShader;
}
bool QSGDistanceFieldTextMaterial::updateTextureSize()
@@ -246,9 +348,26 @@ bool QSGDistanceFieldTextMaterial::updateTextureSize()
if (m_texture->size != m_size) {
m_size = m_texture->size;
return true;
- } else {
- return false;
}
+
+ return false;
+}
+
+// When using the RHI we need a QSGTexture wrapping the QRhiTexture, just
+// exposing a QRhiTexture * (which would be the equivalent of GLuint textureId)
+// is not sufficient to play nice with the material.
+bool QSGDistanceFieldTextMaterial::updateTextureSizeAndWrapper()
+{
+ bool updated = updateTextureSize();
+ if (updated) {
+ if (m_sgTexture)
+ delete m_sgTexture;
+ m_sgTexture = new QSGPlainTexture;
+ m_sgTexture->setTexture(m_texture->texture);
+ m_sgTexture->setTextureSize(m_size);
+ m_sgTexture->setOwnsTexture(false);
+ }
+ return updated;
}
int QSGDistanceFieldTextMaterial::compare(const QSGMaterial *o) const
@@ -262,8 +381,8 @@ int QSGDistanceFieldTextMaterial::compare(const QSGMaterial *o) const
}
if (m_color != other->m_color)
return &m_color < &other->m_color ? -1 : 1;
- int t0 = m_texture ? m_texture->textureId : 0;
- int t1 = other->m_texture ? other->m_texture->textureId : 0;
+ int t0 = m_texture ? (m_texture->rhiBased ? qintptr(m_texture->texture) : m_texture->textureId) : 0;
+ int t1 = other->m_texture ? (other->m_texture->rhiBased ? qintptr(other->m_texture->texture) : other->m_texture->textureId) : 0;
return t0 - t1;
}
@@ -308,6 +427,39 @@ void DistanceFieldStyledTextMaterialShader::updateState(const RenderState &state
}
}
+class DistanceFieldStyledTextMaterialRhiShader : public QSGDistanceFieldTextMaterialRhiShader
+{
+public:
+ DistanceFieldStyledTextMaterialRhiShader(bool alphaTexture);
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+DistanceFieldStyledTextMaterialRhiShader::DistanceFieldStyledTextMaterialRhiShader(bool alphaTexture)
+ : QSGDistanceFieldTextMaterialRhiShader(alphaTexture)
+{
+}
+
+bool DistanceFieldStyledTextMaterialRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ bool changed = QSGDistanceFieldTextMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
+ QSGDistanceFieldStyledTextMaterial *mat = static_cast<QSGDistanceFieldStyledTextMaterial *>(newMaterial);
+ QSGDistanceFieldStyledTextMaterial *oldMat = static_cast<QSGDistanceFieldStyledTextMaterial *>(oldMaterial);
+
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 128);
+
+ if (!oldMat || mat->styleColor() != oldMat->styleColor() || state.isOpacityDirty()) {
+ QVector4D styleColor = mat->styleColor();
+ styleColor *= state.opacity();
+ memcpy(buf->data() + 112, &styleColor, 16);
+ changed = true;
+ }
+
+ return changed;
+}
+
QSGDistanceFieldStyledTextMaterial::QSGDistanceFieldStyledTextMaterial()
: QSGDistanceFieldTextMaterial()
{
@@ -391,6 +543,53 @@ void DistanceFieldOutlineTextMaterialShader::updateState(const RenderState &stat
updateOutlineAlphaRange(material->glyphCache()->distanceFieldRadius());
}
+class DistanceFieldOutlineTextMaterialRhiShader : public DistanceFieldStyledTextMaterialRhiShader
+{
+public:
+ DistanceFieldOutlineTextMaterialRhiShader(bool alphaTexture);
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+DistanceFieldOutlineTextMaterialRhiShader::DistanceFieldOutlineTextMaterialRhiShader(bool alphaTexture)
+ : DistanceFieldStyledTextMaterialRhiShader(alphaTexture)
+{
+ setShaderFileName(VertexStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldoutlinetext.vert.qsb"));
+ if (alphaTexture)
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag.qsb"));
+ else
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldoutlinetext.frag.qsb"));
+}
+
+bool DistanceFieldOutlineTextMaterialRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ bool changed = DistanceFieldStyledTextMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
+ QSGDistanceFieldOutlineTextMaterial *mat = static_cast<QSGDistanceFieldOutlineTextMaterial *>(newMaterial);
+ QSGDistanceFieldOutlineTextMaterial *oldMat = static_cast<QSGDistanceFieldOutlineTextMaterial *>(oldMaterial);
+
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 136);
+
+ if (!oldMat || mat->fontScale() != oldMat->fontScale() || state.isMatrixDirty()) {
+ float dfRadius = mat->glyphCache()->distanceFieldRadius();
+ float combinedScale = m_fontScale * m_matrixScale;
+ float base = thresholdFunc(combinedScale);
+ float range = spreadFunc(combinedScale);
+ float outlineLimit = qMax(0.2f, base - 0.5f / dfRadius / m_fontScale);
+ float alphaMin = qMax(0.0f, base - range);
+ float styleAlphaMin0 = qMax(0.0f, outlineLimit - range);
+ float styleAlphaMin1 = qMin(outlineLimit + range, alphaMin);
+ memcpy(buf->data() + 128, &styleAlphaMin0, 4);
+ memcpy(buf->data() + 132, &styleAlphaMin1, 4);
+ changed = true;
+ }
+
+ return changed;
+}
QSGDistanceFieldOutlineTextMaterial::QSGDistanceFieldOutlineTextMaterial()
: QSGDistanceFieldStyledTextMaterial()
@@ -409,7 +608,10 @@ QSGMaterialType *QSGDistanceFieldOutlineTextMaterial::type() const
QSGMaterialShader *QSGDistanceFieldOutlineTextMaterial::createShader() const
{
- return new DistanceFieldOutlineTextMaterialShader;
+ if (flags().testFlag(RhiShaderWanted))
+ return new DistanceFieldOutlineTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled());
+ else
+ return new DistanceFieldOutlineTextMaterialShader;
}
@@ -463,6 +665,49 @@ void DistanceFieldShiftedStyleTextMaterialShader::updateShift(qreal fontScale, c
program()->setUniformValue(m_shift_id, texel);
}
+class DistanceFieldShiftedStyleTextMaterialRhiShader : public DistanceFieldStyledTextMaterialRhiShader
+{
+public:
+ DistanceFieldShiftedStyleTextMaterialRhiShader(bool alphaTexture);
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+DistanceFieldShiftedStyleTextMaterialRhiShader::DistanceFieldShiftedStyleTextMaterialRhiShader(bool alphaTexture)
+ : DistanceFieldStyledTextMaterialRhiShader(alphaTexture)
+{
+ setShaderFileName(VertexStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldshiftedtext.vert.qsb"));
+ if (alphaTexture)
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldshiftedtext_a.frag.qsb"));
+ else
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldshiftedtext.frag.qsb"));
+}
+
+bool DistanceFieldShiftedStyleTextMaterialRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ bool changed = DistanceFieldStyledTextMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
+ QSGDistanceFieldShiftedStyleTextMaterial *mat = static_cast<QSGDistanceFieldShiftedStyleTextMaterial *>(newMaterial);
+ QSGDistanceFieldShiftedStyleTextMaterial *oldMat = static_cast<QSGDistanceFieldShiftedStyleTextMaterial *>(oldMaterial);
+
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 136);
+
+ if (!oldMat || oldMat->fontScale() != mat->fontScale() || oldMat->shift() != mat->shift()
+ || oldMat->textureSize() != mat->textureSize())
+ {
+ QPointF shift(1.0 / mat->fontScale() * mat->shift().x(),
+ 1.0 / mat->fontScale() * mat->shift().y());
+ memcpy(buf->data() + 128, &shift, 8);
+ changed = true;
+ }
+
+ return changed;
+}
+
QSGDistanceFieldShiftedStyleTextMaterial::QSGDistanceFieldShiftedStyleTextMaterial()
: QSGDistanceFieldStyledTextMaterial()
{
@@ -480,7 +725,10 @@ QSGMaterialType *QSGDistanceFieldShiftedStyleTextMaterial::type() const
QSGMaterialShader *QSGDistanceFieldShiftedStyleTextMaterial::createShader() const
{
- return new DistanceFieldShiftedStyleTextMaterialShader;
+ if (flags().testFlag(RhiShaderWanted))
+ return new DistanceFieldShiftedStyleTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled());
+ else
+ return new DistanceFieldShiftedStyleTextMaterialShader;
}
int QSGDistanceFieldShiftedStyleTextMaterial::compare(const QSGMaterial *o) const
@@ -491,6 +739,7 @@ int QSGDistanceFieldShiftedStyleTextMaterial::compare(const QSGMaterial *o) cons
return QSGDistanceFieldStyledTextMaterial::compare(o);
}
+
class QSGHiQSubPixelDistanceFieldTextMaterialShader : public QSGDistanceFieldTextMaterialShader
{
public:
@@ -555,6 +804,75 @@ void QSGHiQSubPixelDistanceFieldTextMaterialShader::updateState(const RenderStat
QSGDistanceFieldTextMaterialShader::updateState(state, newEffect, oldEffect);
}
+class QSGHiQSubPixelDistanceFieldTextMaterialRhiShader : public QSGDistanceFieldTextMaterialRhiShader
+{
+public:
+ QSGHiQSubPixelDistanceFieldTextMaterialRhiShader(bool alphaTexture);
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+ bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+QSGHiQSubPixelDistanceFieldTextMaterialRhiShader::QSGHiQSubPixelDistanceFieldTextMaterialRhiShader(bool alphaTexture)
+ : QSGDistanceFieldTextMaterialRhiShader(alphaTexture)
+{
+ setFlag(UpdatesGraphicsPipelineState, true);
+
+ setShaderFileName(VertexStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.vert.qsb"));
+ if (alphaTexture)
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext_a.frag.qsb"));
+ else
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.frag.qsb"));
+}
+
+bool QSGHiQSubPixelDistanceFieldTextMaterialRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ bool changed = QSGDistanceFieldTextMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
+ QSGHiQSubPixelDistanceFieldTextMaterial *mat = static_cast<QSGHiQSubPixelDistanceFieldTextMaterial *>(newMaterial);
+ QSGHiQSubPixelDistanceFieldTextMaterial *oldMat = static_cast<QSGHiQSubPixelDistanceFieldTextMaterial *>(oldMaterial);
+
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 128);
+
+ if (!oldMat || mat->fontScale() != oldMat->fontScale()) {
+ float fontScale = mat->fontScale();
+ memcpy(buf->data() + 104, &fontScale, 4);
+ changed = true;
+ }
+
+ if (!oldMat || state.isMatrixDirty()) {
+ int viewportWidth = state.viewportRect().width();
+ QMatrix4x4 mat = state.combinedMatrix().inverted();
+ QVector4D vecDelta = mat.column(0) * (qreal(2) / viewportWidth);
+ memcpy(buf->data() + 112, &vecDelta, 16);
+ }
+
+ return changed;
+}
+
+bool QSGHiQSubPixelDistanceFieldTextMaterialRhiShader::updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ Q_UNUSED(state);
+ Q_UNUSED(oldMaterial);
+ QSGHiQSubPixelDistanceFieldTextMaterial *mat = static_cast<QSGHiQSubPixelDistanceFieldTextMaterial *>(newMaterial);
+
+ ps->blendEnable = true;
+ ps->srcColor = GraphicsPipelineState::ConstantColor;
+ ps->dstColor = GraphicsPipelineState::OneMinusSrcColor;
+
+ const QVector4D color = mat->color();
+ // this is dynamic state but it's - magic! - taken care of by the renderer
+ ps->blendConstant = QColor::fromRgbF(color.x(), color.y(), color.z(), 1.0f);
+
+ return true;
+}
+
QSGMaterialType *QSGHiQSubPixelDistanceFieldTextMaterial::type() const
{
static QSGMaterialType type;
@@ -563,7 +881,10 @@ QSGMaterialType *QSGHiQSubPixelDistanceFieldTextMaterial::type() const
QSGMaterialShader *QSGHiQSubPixelDistanceFieldTextMaterial::createShader() const
{
- return new QSGHiQSubPixelDistanceFieldTextMaterialShader;
+ if (flags().testFlag(RhiShaderWanted))
+ return new QSGHiQSubPixelDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled());
+ else
+ return new QSGHiQSubPixelDistanceFieldTextMaterialShader;
}
@@ -580,6 +901,25 @@ QSGLoQSubPixelDistanceFieldTextMaterialShader::QSGLoQSubPixelDistanceFieldTextMa
setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/loqsubpixeldistancefieldtext.frag"));
}
+class QSGLoQSubPixelDistanceFieldTextMaterialRhiShader : public QSGHiQSubPixelDistanceFieldTextMaterialRhiShader
+{
+public:
+ QSGLoQSubPixelDistanceFieldTextMaterialRhiShader(bool alphaTexture);
+};
+
+QSGLoQSubPixelDistanceFieldTextMaterialRhiShader::QSGLoQSubPixelDistanceFieldTextMaterialRhiShader(bool alphaTexture)
+ : QSGHiQSubPixelDistanceFieldTextMaterialRhiShader(alphaTexture)
+{
+ setShaderFileName(VertexStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.vert.qsb"));
+ if (alphaTexture)
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/loqsubpixeldistancefieldtext_a.frag.qsb"));
+ else
+ setShaderFileName(FragmentStage,
+ QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.frag.qsb"));
+}
+
QSGMaterialType *QSGLoQSubPixelDistanceFieldTextMaterial::type() const
{
static QSGMaterialType type;
@@ -588,7 +928,10 @@ QSGMaterialType *QSGLoQSubPixelDistanceFieldTextMaterial::type() const
QSGMaterialShader *QSGLoQSubPixelDistanceFieldTextMaterial::createShader() const
{
- return new QSGLoQSubPixelDistanceFieldTextMaterialShader;
+ if (flags().testFlag(RhiShaderWanted))
+ return new QSGLoQSubPixelDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled());
+ else
+ return new QSGLoQSubPixelDistanceFieldTextMaterialShader;
}
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.h b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.h
index 7008f20925..7b6be29bcb 100644
--- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.h
+++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.h
@@ -60,7 +60,8 @@ QT_BEGIN_NAMESPACE
class QSGRenderContext;
class QSGDistanceFieldTextMaterial;
-class QSGDistanceFieldGlyphNode: public QSGGlyphNode, public QSGDistanceFieldGlyphConsumer
+
+class QSGDistanceFieldGlyphNode : public QSGGlyphNode, public QSGDistanceFieldGlyphConsumer
{
public:
QSGDistanceFieldGlyphNode(QSGRenderContext *context);
diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h b/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h
index c13a0898eb..ee1ed8f337 100644
--- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h
+++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h
@@ -52,11 +52,14 @@
//
#include <QtQuick/qsgmaterial.h>
+#include <QtQuick/private/qsgplaintexture_p.h>
#include "qsgdistancefieldglyphnode_p.h"
#include "qsgadaptationlayer_p.h"
QT_BEGIN_NAMESPACE
+class QSGPlainTexture;
+
class Q_QUICK_PRIVATE_EXPORT QSGDistanceFieldTextMaterial: public QSGMaterial
{
public:
@@ -82,6 +85,8 @@ public:
QSize textureSize() const { return m_size; }
bool updateTextureSize();
+ bool updateTextureSizeAndWrapper();
+ QSGTexture *wrapperTexture() const { return m_sgTexture; }
protected:
QSize m_size;
@@ -89,6 +94,7 @@ protected:
QSGDistanceFieldGlyphCache *m_glyph_cache;
const QSGDistanceFieldGlyphCache::Texture *m_texture;
qreal m_fontScale;
+ QSGPlainTexture *m_sgTexture;
};
class Q_QUICK_PRIVATE_EXPORT QSGDistanceFieldStyledTextMaterial : public QSGDistanceFieldTextMaterial
diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp b/src/quick/scenegraph/qsgopengldistancefieldglyphcache.cpp
index c51358df7c..b6b6f3b057 100644
--- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp
+++ b/src/quick/scenegraph/qsgopengldistancefieldglyphcache.cpp
@@ -37,10 +37,11 @@
**
****************************************************************************/
-#include "qsgdefaultdistancefieldglyphcache_p.h"
+#include "qsgopengldistancefieldglyphcache_p.h"
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qbuffer.h>
+#include <QtCore/qendian.h>
#include <QtQml/qqmlfile.h>
#include <QtGui/private/qdistancefield_p.h>
@@ -61,12 +62,12 @@ QT_BEGIN_NAMESPACE
DEFINE_BOOL_CONFIG_OPTION(qmlUseGlyphCacheWorkaround, QML_USE_GLYPHCACHE_WORKAROUND)
DEFINE_BOOL_CONFIG_OPTION(qsgPreferFullSizeGlyphCacheTextures, QSG_PREFER_FULLSIZE_GLYPHCACHE_TEXTURES)
-#if !defined(QSG_DEFAULT_DISTANCEFIELD_GLYPH_CACHE_PADDING)
-# define QSG_DEFAULT_DISTANCEFIELD_GLYPH_CACHE_PADDING 2
+#if !defined(QSG_OPENGL_DISTANCEFIELD_GLYPH_CACHE_PADDING)
+# define QSG_OPENGL_DISTANCEFIELD_GLYPH_CACHE_PADDING 2
#endif
-QSGDefaultDistanceFieldGlyphCache::QSGDefaultDistanceFieldGlyphCache(QOpenGLContext *c,
- const QRawFont &font)
+QSGOpenGLDistanceFieldGlyphCache::QSGOpenGLDistanceFieldGlyphCache(QOpenGLContext *c,
+ const QRawFont &font)
: QSGDistanceFieldGlyphCache(font)
, m_maxTextureWidth(0)
, m_maxTextureHeight(0)
@@ -96,7 +97,7 @@ QSGDefaultDistanceFieldGlyphCache::QSGDefaultDistanceFieldGlyphCache(QOpenGLCont
loadPregeneratedCache(font);
}
-QSGDefaultDistanceFieldGlyphCache::~QSGDefaultDistanceFieldGlyphCache()
+QSGOpenGLDistanceFieldGlyphCache::~QSGOpenGLDistanceFieldGlyphCache()
{
for (int i = 0; i < m_textures.count(); ++i)
m_funcs->glDeleteTextures(1, &m_textures[i].texture);
@@ -108,12 +109,12 @@ QSGDefaultDistanceFieldGlyphCache::~QSGDefaultDistanceFieldGlyphCache()
delete m_areaAllocator;
}
-void QSGDefaultDistanceFieldGlyphCache::requestGlyphs(const QSet<glyph_t> &glyphs)
+void QSGOpenGLDistanceFieldGlyphCache::requestGlyphs(const QSet<glyph_t> &glyphs)
{
QList<GlyphPosition> glyphPositions;
QVector<glyph_t> glyphsToRender;
- const int padding = QSG_DEFAULT_DISTANCEFIELD_GLYPH_CACHE_PADDING;
+ const int padding = QSG_OPENGL_DISTANCEFIELD_GLYPH_CACHE_PADDING;
const qreal scaleFactor = qreal(1) / QT_DISTANCEFIELD_SCALE(m_doubleGlyphResolution);
if (m_maxTextureHeight == 0) {
@@ -182,7 +183,7 @@ void QSGDefaultDistanceFieldGlyphCache::requestGlyphs(const QSet<glyph_t> &glyph
markGlyphsToRender(glyphsToRender);
}
-void QSGDefaultDistanceFieldGlyphCache::storeGlyphs(const QList<QDistanceField> &glyphs)
+void QSGOpenGLDistanceFieldGlyphCache::storeGlyphs(const QList<QDistanceField> &glyphs)
{
typedef QHash<TextureInfo *, QVector<glyph_t> > GlyphTextureHash;
typedef GlyphTextureHash::const_iterator GlyphTextureHashConstIt;
@@ -248,21 +249,22 @@ void QSGDefaultDistanceFieldGlyphCache::storeGlyphs(const QList<QDistanceField>
Texture t;
t.textureId = i.key()->texture;
t.size = i.key()->size;
+ t.rhiBased = false;
setGlyphsTexture(i.value(), t);
}
}
-void QSGDefaultDistanceFieldGlyphCache::referenceGlyphs(const QSet<glyph_t> &glyphs)
+void QSGOpenGLDistanceFieldGlyphCache::referenceGlyphs(const QSet<glyph_t> &glyphs)
{
m_unusedGlyphs -= glyphs;
}
-void QSGDefaultDistanceFieldGlyphCache::releaseGlyphs(const QSet<glyph_t> &glyphs)
+void QSGOpenGLDistanceFieldGlyphCache::releaseGlyphs(const QSet<glyph_t> &glyphs)
{
m_unusedGlyphs += glyphs;
}
-void QSGDefaultDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo,
+void QSGOpenGLDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo,
int width,
int height)
{
@@ -270,7 +272,7 @@ void QSGDefaultDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo,
createTexture(texInfo, width, height, zeroBuf.constData());
}
-void QSGDefaultDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo,
+void QSGOpenGLDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo,
int width,
int height,
const void *pixels)
@@ -317,7 +319,7 @@ static void freeFramebufferFunc(QOpenGLFunctions *funcs, GLuint id)
funcs->glDeleteFramebuffers(1, &id);
}
-void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int width, int height)
+void QSGOpenGLDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int width, int height)
{
QOpenGLContext *ctx = QOpenGLContext::currentContext();
Q_ASSERT(ctx);
@@ -520,7 +522,7 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int
m_vao.release();
}
-bool QSGDefaultDistanceFieldGlyphCache::useTextureResizeWorkaround() const
+bool QSGOpenGLDistanceFieldGlyphCache::useTextureResizeWorkaround() const
{
static bool set = false;
static bool useWorkaround = false;
@@ -533,7 +535,7 @@ bool QSGDefaultDistanceFieldGlyphCache::useTextureResizeWorkaround() const
return useWorkaround;
}
-bool QSGDefaultDistanceFieldGlyphCache::useTextureUploadWorkaround() const
+bool QSGOpenGLDistanceFieldGlyphCache::useTextureUploadWorkaround() const
{
static bool set = false;
static bool useWorkaround = false;
@@ -545,7 +547,7 @@ bool QSGDefaultDistanceFieldGlyphCache::useTextureUploadWorkaround() const
return useWorkaround;
}
-bool QSGDefaultDistanceFieldGlyphCache::createFullSizeTextures() const
+bool QSGOpenGLDistanceFieldGlyphCache::createFullSizeTextures() const
{
return qsgPreferFullSizeGlyphCacheTextures() && glyphCount() > QT_DISTANCEFIELD_HIGHGLYPHCOUNT();
}
@@ -602,7 +604,7 @@ namespace {
};
}
-bool QSGDefaultDistanceFieldGlyphCache::loadPregeneratedCache(const QRawFont &font)
+bool QSGOpenGLDistanceFieldGlyphCache::loadPregeneratedCache(const QRawFont &font)
{
// The pregenerated data must be loaded first, otherwise the area allocator
// will be wrong
@@ -672,11 +674,11 @@ bool QSGDefaultDistanceFieldGlyphCache::loadPregeneratedCache(const QRawFont &fo
m_maxTextureWidth);
}
- if (padding != QSG_DEFAULT_DISTANCEFIELD_GLYPH_CACHE_PADDING) {
+ if (padding != QSG_OPENGL_DISTANCEFIELD_GLYPH_CACHE_PADDING) {
qWarning("Padding mismatch in '%s'. Font requires %d, but Qt is compiled with %d.",
qPrintable(font.familyName()),
padding,
- QSG_DEFAULT_DISTANCEFIELD_GLYPH_CACHE_PADDING);
+ QSG_OPENGL_DISTANCEFIELD_GLYPH_CACHE_PADDING);
}
m_referenceFont.setPixelSize(pixelSize);
@@ -787,6 +789,7 @@ bool QSGDefaultDistanceFieldGlyphCache::loadPregeneratedCache(const QRawFont &fo
Texture t;
t.textureId = texInfo->texture;
t.size = texInfo->size;
+ t.rhiBased = false;
setGlyphsTexture(glyphs, t);
diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h b/src/quick/scenegraph/qsgopengldistancefieldglyphcache_p.h
index 0420ef251e..66d1b52f86 100644
--- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
+++ b/src/quick/scenegraph/qsgopengldistancefieldglyphcache_p.h
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef QSGDEFAULTDISTANCEFIELDGLYPHCACHE_H
-#define QSGDEFAULTDISTANCEFIELDGLYPHCACHE_H
+#ifndef QSGOPENGLDISTANCEFIELDGLYPHCACHE_H
+#define QSGOPENGLDISTANCEFIELDGLYPHCACHE_H
//
// W A R N I N G
@@ -66,11 +66,11 @@ class QOpenGLSharedResourceGuard;
class QOpenGLFunctions_3_2_Core;
#endif
-class Q_QUICK_PRIVATE_EXPORT QSGDefaultDistanceFieldGlyphCache : public QSGDistanceFieldGlyphCache
+class Q_QUICK_PRIVATE_EXPORT QSGOpenGLDistanceFieldGlyphCache : public QSGDistanceFieldGlyphCache
{
public:
- QSGDefaultDistanceFieldGlyphCache(QOpenGLContext *c, const QRawFont &font);
- virtual ~QSGDefaultDistanceFieldGlyphCache();
+ QSGOpenGLDistanceFieldGlyphCache(QOpenGLContext *c, const QRawFont &font);
+ virtual ~QSGOpenGLDistanceFieldGlyphCache();
void requestGlyphs(const QSet<glyph_t> &glyphs) override;
void storeGlyphs(const QList<QDistanceField> &glyphs) override;
@@ -84,6 +84,7 @@ public:
void setMaxTextureCount(int max) { m_maxTextureCount = max; }
int maxTextureCount() const { return m_maxTextureCount; }
+ bool eightBitFormatIsAlphaSwizzled() const override { return !m_coreProfile; }
private:
bool loadPregeneratedCache(const QRawFont &font);
@@ -160,4 +161,4 @@ private:
QT_END_NAMESPACE
-#endif // QSGDEFAULTDISTANCEFIELDGLYPHCACHE_H
+#endif // QSGOPENGLDISTANCEFIELDGLYPHCACHE_H
diff --git a/src/quick/scenegraph/qsgdefaultlayer.cpp b/src/quick/scenegraph/qsgopengllayer.cpp
index b2b123912f..ae5032231d 100644
--- a/src/quick/scenegraph/qsgdefaultlayer.cpp
+++ b/src/quick/scenegraph/qsgopengllayer.cpp
@@ -36,7 +36,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "qsgdefaultlayer_p.h"
+#include "qsgopengllayer_p.h"
#include <private/qqmlglobal_p.h>
#include <private/qsgrenderer_p.h>
@@ -88,8 +88,8 @@ namespace
}
}
-QSGDefaultLayer::QSGDefaultLayer(QSGRenderContext *context)
- : QSGLayer()
+QSGOpenGLLayer::QSGOpenGLLayer(QSGRenderContext *context)
+ : QSGLayer(*(new QSGOpenGLLayerPrivate))
, m_item(nullptr)
, m_device_pixel_ratio(1)
, m_format(GL_RGBA)
@@ -114,12 +114,12 @@ QSGDefaultLayer::QSGDefaultLayer(QSGRenderContext *context)
m_context = static_cast<QSGDefaultRenderContext *>(context);
}
-QSGDefaultLayer::~QSGDefaultLayer()
+QSGOpenGLLayer::~QSGOpenGLLayer()
{
invalidated();
}
-void QSGDefaultLayer::invalidated()
+void QSGOpenGLLayer::invalidated()
{
delete m_renderer;
m_renderer = nullptr;
@@ -136,23 +136,29 @@ void QSGDefaultLayer::invalidated()
}
}
-int QSGDefaultLayer::textureId() const
+int QSGOpenGLLayer::textureId() const
{
return m_fbo ? m_fbo->texture() : 0;
}
-bool QSGDefaultLayer::hasAlphaChannel() const
+int QSGOpenGLLayerPrivate::comparisonKey() const
+{
+ Q_Q(const QSGOpenGLLayer);
+ return q->m_fbo ? q->m_fbo->texture() : 0;
+}
+
+bool QSGOpenGLLayer::hasAlphaChannel() const
{
return m_format != GL_RGB;
}
-bool QSGDefaultLayer::hasMipmaps() const
+bool QSGOpenGLLayer::hasMipmaps() const
{
return m_mipmap;
}
-void QSGDefaultLayer::bind()
+void QSGOpenGLLayer::bind()
{
#ifndef QT_NO_DEBUG
if (!m_recursive && m_fbo && ((m_multisampling && m_secondaryFbo->isBound()) || m_fbo->isBound()))
@@ -174,7 +180,7 @@ void QSGDefaultLayer::bind()
}
}
-bool QSGDefaultLayer::updateTexture()
+bool QSGOpenGLLayer::updateTexture()
{
bool doGrab = (m_live || m_grab) && m_dirtyTexture;
if (doGrab)
@@ -185,7 +191,7 @@ bool QSGDefaultLayer::updateTexture()
return doGrab;
}
-void QSGDefaultLayer::setHasMipmaps(bool mipmap)
+void QSGOpenGLLayer::setHasMipmaps(bool mipmap)
{
if (mipmap == m_mipmap)
return;
@@ -195,7 +201,7 @@ void QSGDefaultLayer::setHasMipmaps(bool mipmap)
}
-void QSGDefaultLayer::setItem(QSGNode *item)
+void QSGOpenGLLayer::setItem(QSGNode *item)
{
if (item == m_item)
return;
@@ -211,7 +217,7 @@ void QSGDefaultLayer::setItem(QSGNode *item)
markDirtyTexture();
}
-void QSGDefaultLayer::setRect(const QRectF &rect)
+void QSGOpenGLLayer::setRect(const QRectF &rect)
{
if (rect == m_rect)
return;
@@ -219,7 +225,7 @@ void QSGDefaultLayer::setRect(const QRectF &rect)
markDirtyTexture();
}
-void QSGDefaultLayer::setSize(const QSize &size)
+void QSGOpenGLLayer::setSize(const QSize &size)
{
if (size == m_size)
return;
@@ -235,7 +241,7 @@ void QSGDefaultLayer::setSize(const QSize &size)
markDirtyTexture();
}
-void QSGDefaultLayer::setFormat(GLenum format)
+void QSGOpenGLLayer::setFormat(GLenum format)
{
if (format == m_format)
return;
@@ -243,7 +249,7 @@ void QSGDefaultLayer::setFormat(GLenum format)
markDirtyTexture();
}
-void QSGDefaultLayer::setLive(bool live)
+void QSGOpenGLLayer::setLive(bool live)
{
if (live == m_live)
return;
@@ -259,7 +265,7 @@ void QSGDefaultLayer::setLive(bool live)
markDirtyTexture();
}
-void QSGDefaultLayer::scheduleUpdate()
+void QSGOpenGLLayer::scheduleUpdate()
{
if (m_grab)
return;
@@ -268,29 +274,29 @@ void QSGDefaultLayer::scheduleUpdate()
emit updateRequested();
}
-void QSGDefaultLayer::setRecursive(bool recursive)
+void QSGOpenGLLayer::setRecursive(bool recursive)
{
m_recursive = recursive;
}
-void QSGDefaultLayer::setMirrorHorizontal(bool mirror)
+void QSGOpenGLLayer::setMirrorHorizontal(bool mirror)
{
m_mirrorHorizontal = mirror;
}
-void QSGDefaultLayer::setMirrorVertical(bool mirror)
+void QSGOpenGLLayer::setMirrorVertical(bool mirror)
{
m_mirrorVertical = mirror;
}
-void QSGDefaultLayer::markDirtyTexture()
+void QSGOpenGLLayer::markDirtyTexture()
{
m_dirtyTexture = true;
if (m_live || m_grab)
emit updateRequested();
}
-void QSGDefaultLayer::grab()
+void QSGOpenGLLayer::grab()
{
if (!m_item || m_size.isNull()) {
delete m_fbo;
@@ -457,7 +463,7 @@ void QSGDefaultLayer::grab()
markDirtyTexture(); // Continuously update if 'live' and 'recursive'.
}
-QImage QSGDefaultLayer::toImage() const
+QImage QSGOpenGLLayer::toImage() const
{
if (m_fbo)
return m_fbo->toImage();
@@ -465,7 +471,7 @@ QImage QSGDefaultLayer::toImage() const
return QImage();
}
-QRectF QSGDefaultLayer::normalizedTextureSubRect() const
+QRectF QSGOpenGLLayer::normalizedTextureSubRect() const
{
return QRectF(m_mirrorHorizontal ? 1 : 0,
m_mirrorVertical ? 0 : 1,
@@ -473,4 +479,4 @@ QRectF QSGDefaultLayer::normalizedTextureSubRect() const
m_mirrorVertical ? 1 : -1);
}
-#include "moc_qsgdefaultlayer_p.cpp"
+#include "moc_qsgopengllayer_p.cpp"
diff --git a/src/quick/scenegraph/qsgdefaultlayer_p.h b/src/quick/scenegraph/qsgopengllayer_p.h
index 06355e0c21..c6246843e2 100644
--- a/src/quick/scenegraph/qsgdefaultlayer_p.h
+++ b/src/quick/scenegraph/qsgopengllayer_p.h
@@ -36,8 +36,8 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef QSGDEFAULTLAYER_P_H
-#define QSGDEFAULTLAYER_P_H
+#ifndef QSGOPENGLLAYER_P_H
+#define QSGOPENGLLAYER_P_H
//
// W A R N I N G
@@ -52,6 +52,7 @@
#include <private/qsgadaptationlayer_p.h>
#include <private/qsgcontext_p.h>
+#include <private/qsgtexture_p.h>
#include <qsgsimplerectnode.h>
QT_BEGIN_NAMESPACE
@@ -61,13 +62,15 @@ QT_BEGIN_NAMESPACE
class QOpenGLFramebufferObject;
class QSGDepthStencilBuffer;
class QSGDefaultRenderContext;
+class QSGOpenGLLayerPrivate;
-class Q_QUICK_PRIVATE_EXPORT QSGDefaultLayer : public QSGLayer
+class Q_QUICK_PRIVATE_EXPORT QSGOpenGLLayer : public QSGLayer
{
+ Q_DECLARE_PRIVATE(QSGOpenGLLayer)
Q_OBJECT
public:
- QSGDefaultLayer(QSGRenderContext *context);
- ~QSGDefaultLayer();
+ QSGOpenGLLayer(QSGRenderContext *context);
+ ~QSGOpenGLLayer();
bool updateTexture() override;
@@ -154,6 +157,13 @@ private:
uint m_mirrorVertical : 1;
};
+class QSGOpenGLLayerPrivate : public QSGTexturePrivate
+{
+ Q_DECLARE_PUBLIC(QSGOpenGLLayer)
+public:
+ int comparisonKey() const override;
+};
+
QT_END_NAMESPACE
-#endif // QSGDEFAULTLAYER_P_H
+#endif // QSGOPENGLLAYER_P_H
diff --git a/src/quick/scenegraph/qsgrenderloop.cpp b/src/quick/scenegraph/qsgrenderloop.cpp
index 2e91bafa7c..f609055677 100644
--- a/src/quick/scenegraph/qsgrenderloop.cpp
+++ b/src/quick/scenegraph/qsgrenderloop.cpp
@@ -40,6 +40,7 @@
#include "qsgrenderloop_p.h"
#include "qsgthreadedrenderloop_p.h"
#include "qsgwindowsrenderloop_p.h"
+#include "qsgrhisupport_p.h"
#include <private/qquickanimatorcontroller_p.h>
#include <QtCore/QCoreApplication>
@@ -50,6 +51,7 @@
#include <QtGui/QOffscreenSurface>
#include <QtGui/private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
+#include <QPlatformSurfaceEvent>
#include <QtQml/private/qqmlglobal_p.h>
@@ -59,23 +61,35 @@
#include <QtQuick/private/qsgrenderer_p.h>
#include <private/qquickprofiler_p.h>
+#include <private/qsgrhishadereffectnode_p.h>
+
#if QT_CONFIG(opengl)
-# include <QtGui/QOpenGLContext>
-# include <private/qsgdefaultrendercontext_p.h>
+#include <QtGui/QOpenGLContext>
#if QT_CONFIG(quick_shadereffect)
-# include <private/qquickopenglshadereffectnode_p.h>
+#include <private/qquickopenglshadereffectnode_p.h>
#endif
+#include <private/qsgdefaultrendercontext_p.h>
#endif
#ifdef Q_OS_WIN
-# include <QtCore/qt_windows.h>
+#include <QtCore/qt_windows.h>
#endif
QT_BEGIN_NAMESPACE
extern bool qsg_useConsistentTiming();
extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha);
-#if QT_CONFIG(opengl)
+
+// ### We do not yet support using Qt Quick with QRhi (and Vulkan, D3D
+// or Metal) in -no-opengl builds as of Qt 5.14. This is due to to the
+// widespread direct OpenGL usage all over the place in qsgdefault*
+// and the related classes. To be cleaned up in Qt 6 when the direct
+// GL code path is removed.
+
+#if QT_CONFIG(opengl) /* || QT_CONFIG(vulkan) || defined(Q_OS_WIN) || defined(Q_OS_DARWIN) */
+
+#define ENABLE_DEFAULT_BACKEND
+
/*
expectations for this manager to work:
- one opengl context to render multiple windows
@@ -88,17 +102,13 @@ extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_
DEFINE_BOOL_CONFIG_OPTION(qmlNoThreadedRenderer, QML_BAD_GUI_RENDER_LOOP);
DEFINE_BOOL_CONFIG_OPTION(qmlForceThreadedRenderer, QML_FORCE_THREADED_RENDERER); // Might trigger graphics driver threading bugs, use at own risk
#endif
+
QSGRenderLoop *QSGRenderLoop::s_instance = nullptr;
QSGRenderLoop::~QSGRenderLoop()
{
}
-QSurface::SurfaceType QSGRenderLoop::windowSurfaceType() const
-{
- return QSurface::OpenGLSurface;
-}
-
void QSGRenderLoop::cleanup()
{
if (!s_instance)
@@ -112,18 +122,36 @@ void QSGRenderLoop::cleanup()
}
delete s_instance;
s_instance = nullptr;
+
+#ifdef ENABLE_DEFAULT_BACKEND
+ QSGRhiSupport::instance()->cleanup();
+ QSGRhiProfileConnection::instance()->cleanup();
+#endif
+}
+
+QSurface::SurfaceType QSGRenderLoop::windowSurfaceType() const
+{
+#ifdef ENABLE_DEFAULT_BACKEND
+ return QSGRhiSupport::instance()->windowSurfaceType();
+#else
+ return QSurface::RasterSurface;
+#endif
}
-/*!
- * Non-threaded render loops immediately run the job if there is a context.
- */
void QSGRenderLoop::postJob(QQuickWindow *window, QRunnable *job)
{
Q_ASSERT(job);
-#if QT_CONFIG(opengl)
+#ifdef ENABLE_DEFAULT_BACKEND
Q_ASSERT(window);
- if (window->openglContext()) {
- window->openglContext()->makeCurrent(window);
+ if (!QSGRhiSupport::instance()->isRhiEnabled()) {
+ if (window->openglContext()) {
+ window->openglContext()->makeCurrent(window);
+ job->run();
+ }
+ } else {
+ QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window);
+ if (cd->rhi)
+ cd->rhi->makeThreadLocalNativeContextCurrent();
job->run();
}
#else
@@ -132,7 +160,8 @@ void QSGRenderLoop::postJob(QQuickWindow *window, QRunnable *job)
#endif
delete job;
}
-#if QT_CONFIG(opengl)
+
+#ifdef ENABLE_DEFAULT_BACKEND
class QSGGuiThreadRenderLoop : public QSGRenderLoop
{
Q_OBJECT
@@ -160,6 +189,11 @@ public:
QSGContext *sceneGraphContext() const override;
QSGRenderContext *createRenderContext(QSGContext *) const override { return rc; }
+ void releaseSwapchain(QQuickWindow *window);
+ void handleDeviceLoss();
+
+ bool eventFilter(QObject *watched, QEvent *event) override;
+
struct WindowData {
bool updatePending : 1;
bool grabOnly : 1;
@@ -167,44 +201,76 @@ public:
QHash<QQuickWindow *, WindowData> m_windows;
- QOpenGLContext *gl;
+ QOpenGLContext *gl = nullptr;
+ QOffscreenSurface *offscreenSurface = nullptr;
+ QRhi *rhi = nullptr;
QSGContext *sg;
QSGRenderContext *rc;
QImage grabContent;
};
#endif
+
QSGRenderLoop *QSGRenderLoop::instance()
{
if (!s_instance) {
- // For compatibility with 5.3 and earlier's QSG_INFO environment variables
- if (qEnvironmentVariableIsSet("QSG_INFO"))
- const_cast<QLoggingCategory &>(QSG_LOG_INFO()).setEnabled(QtDebugMsg, true);
+ QSGRhiSupport::checkEnvQSgInfo();
s_instance = QSGContext::createWindowManager();
-#if QT_CONFIG(opengl)
+#ifdef ENABLE_DEFAULT_BACKEND
if (!s_instance) {
+ QSGRhiSupport *rhiSupport = QSGRhiSupport::instance();
- enum RenderLoopType {
- BasicRenderLoop,
- ThreadedRenderLoop,
- WindowsRenderLoop
- };
-
- RenderLoopType loopType = BasicRenderLoop;
-
-#ifdef Q_OS_WIN
- // With desktop OpenGL (opengl32.dll), use threaded. Otherwise (ANGLE) use windows.
- if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL
- && QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL))
+ QSGRenderLoopType loopType;
+ if (rhiSupport->isRhiEnabled() && rhiSupport->rhiBackend() != QRhi::OpenGLES2) {
loopType = ThreadedRenderLoop;
- else
- loopType = WindowsRenderLoop;
+ } else {
+ loopType = BasicRenderLoop;
+#ifdef Q_OS_WIN
+ // With desktop OpenGL (opengl32.dll), use threaded. Otherwise (ANGLE) use windows.
+ if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL
+ && QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL))
+ {
+ loopType = ThreadedRenderLoop;
+ } else {
+ loopType = WindowsRenderLoop;
+ }
#else
- if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL))
- loopType = ThreadedRenderLoop;
+ if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL))
+ loopType = ThreadedRenderLoop;
#endif
+ }
+
+ if (rhiSupport->isRhiEnabled()) {
+ switch (rhiSupport->rhiBackend()) {
+ case QRhi::Null:
+ loopType = BasicRenderLoop;
+ break;
+
+ case QRhi::D3D11:
+ // The threaded loop's model may not be suitable for DXGI
+ // due to the possibility of having the main thread (with
+ // the Windows message pump) blocked while issuing a
+ // Present on the render thread. However, according to the
+ // docs this can be a problem for fullscreen swapchains
+ // only. So leave threaded enabled by default for now and
+ // revisit later if there are problems.
+ break;
+
+ default:
+ break;
+ }
+
+ // no 'windows' because that's not yet ported to the rhi
+ if (loopType == WindowsRenderLoop)
+ loopType = BasicRenderLoop;
+ }
+
+ // The environment variables can always override. This is good
+ // because in some situations it makes perfect sense to try out a
+ // render loop that is otherwise disabled by default.
+
if (qmlNoThreadedRenderer())
loopType = BasicRenderLoop;
else if (qmlForceThreadedRenderer())
@@ -275,14 +341,15 @@ void QSGRenderLoop::handleContextCreationFailure(QQuickWindow *window,
if (!signalEmitted)
qFatal("%s", qPrintable(untranslatedMessage));
}
-#if QT_CONFIG(opengl)
+
+#ifdef ENABLE_DEFAULT_BACKEND
QSGGuiThreadRenderLoop::QSGGuiThreadRenderLoop()
- : gl(nullptr)
{
if (qsg_useConsistentTiming()) {
QUnifiedTimer::instance(true)->setConsistentTiming(true);
qCDebug(QSG_LOG_INFO, "using fixed animation steps");
}
+
sg = QSGContext::createDefaultContext();
rc = sg->createRenderContext();
}
@@ -318,36 +385,108 @@ void QSGGuiThreadRenderLoop::windowDestroyed(QQuickWindow *window)
QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
bool current = false;
- QScopedPointer<QOffscreenSurface> offscreenSurface;
- if (gl) {
- QSurface *surface = window;
- // There may be no platform window if the window got closed.
- if (!window->handle()) {
- offscreenSurface.reset(new QOffscreenSurface);
- offscreenSurface->setFormat(gl->format());
- offscreenSurface->create();
- surface = offscreenSurface.data();
+ if (gl || rhi) {
+ if (rhi) {
+ // Direct OpenGL calls in user code need a current context, like
+ // when rendering; ensure this (no-op when not running on GL).
+ // Also works when there is no handle() anymore.
+ rhi->makeThreadLocalNativeContextCurrent();
+ current = true;
+ } else {
+ QSurface *surface = window;
+ // There may be no platform window if the window got closed.
+ if (!window->handle())
+ surface = offscreenSurface;
+ current = gl->makeCurrent(surface);
}
- current = gl->makeCurrent(surface);
+ if (Q_UNLIKELY(!current))
+ qCDebug(QSG_LOG_RENDERLOOP, "cleanup without an OpenGL context");
}
- if (Q_UNLIKELY(!current))
- qCDebug(QSG_LOG_RENDERLOOP, "cleanup without an OpenGL context");
-#if QT_CONFIG(quick_shadereffect) && QT_CONFIG(opengl)
- if (current)
- QQuickOpenGLShaderEffectMaterial::cleanupMaterialCache();
+#if QT_CONFIG(quick_shadereffect)
+ QSGRhiShaderEffectNode::cleanupMaterialTypeCache();
+#if QT_CONFIG(opengl)
+ QQuickOpenGLShaderEffectMaterial::cleanupMaterialCache();
+#endif
#endif
+ if (d->swapchain) {
+ if (window->handle()) {
+ // We get here when exiting via QCoreApplication::quit() instead of
+ // through QWindow::close().
+ releaseSwapchain(window);
+ } else {
+ qWarning("QSGGuiThreadRenderLoop cleanup with QQuickWindow %p swapchain %p still alive, this should not happen.",
+ window, d->swapchain);
+ }
+ }
+
d->cleanupNodesOnShutdown();
if (m_windows.size() == 0) {
rc->invalidate();
+ d->rhi = nullptr;
+ delete rhi;
+ rhi = nullptr;
delete gl;
gl = nullptr;
+ delete offscreenSurface;
+ offscreenSurface = nullptr;
} else if (gl && window == gl->surface() && current) {
- gl->doneCurrent();
+ if (!rhi)
+ gl->doneCurrent();
}
- delete d->animationController;
+ d->animationController.reset();
+}
+
+void QSGGuiThreadRenderLoop::handleDeviceLoss()
+{
+ if (!rhi || !rhi->isDeviceLost())
+ return;
+
+ qWarning("Graphics device lost, cleaning up scenegraph and releasing RHI");
+
+ for (auto it = m_windows.constBegin(), itEnd = m_windows.constEnd(); it != itEnd; ++it)
+ QQuickWindowPrivate::get(it.key())->cleanupNodesOnShutdown();
+
+ rc->invalidate();
+
+ for (auto it = m_windows.constBegin(), itEnd = m_windows.constEnd(); it != itEnd; ++it)
+ releaseSwapchain(it.key());
+
+ delete rhi;
+ rhi = nullptr;
+}
+
+void QSGGuiThreadRenderLoop::releaseSwapchain(QQuickWindow *window)
+{
+ QQuickWindowPrivate *wd = QQuickWindowPrivate::get(window);
+ delete wd->rpDescForSwapchain;
+ wd->rpDescForSwapchain = nullptr;
+ delete wd->swapchain;
+ wd->swapchain = nullptr;
+ delete wd->depthStencilForSwapchain;
+ wd->depthStencilForSwapchain = nullptr;
+ wd->hasActiveSwapchain = wd->hasRenderableSwapchain = wd->swapchainJustBecameRenderable = false;
+}
+
+bool QSGGuiThreadRenderLoop::eventFilter(QObject *watched, QEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::PlatformSurface:
+ // this is the proper time to tear down the swapchain (while the native window and surface are still around)
+ if (static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
+ QQuickWindow *w = qobject_cast<QQuickWindow *>(watched);
+ if (w) {
+ releaseSwapchain(w);
+ w->removeEventFilter(this);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return QObject::eventFilter(watched, event);
}
void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
@@ -364,8 +503,39 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
return;
bool current = false;
+ QSGRhiSupport *rhiSupport = QSGRhiSupport::instance();
+ int rhiSampleCount = 1;
+ const bool enableRhi = rhiSupport->isRhiEnabled();
+
+ if (enableRhi && !rhi) {
+ if (!offscreenSurface)
+ offscreenSurface = rhiSupport->maybeCreateOffscreenSurface(window);
+
+ rhi = rhiSupport->createRhi(window, offscreenSurface);
+
+ if (rhi) {
+ if (rhiSupport->isProfilingRequested())
+ QSGRhiProfileConnection::instance()->initialize(rhi);
+
+ current = true;
+ rhi->makeThreadLocalNativeContextCurrent();
+
+ // The sample count cannot vary between windows as we use the same
+ // rendercontext for all of them. Decide it here and now.
+ rhiSampleCount = rhiSupport->chooseSampleCountForWindowWithRhi(window, rhi);
- if (!gl) {
+ cd->rhi = rhi; // set this early in case something hooked up to rc initialized() accesses it
+
+ QSGDefaultRenderContext::InitParams rcParams;
+ rcParams.rhi = rhi;
+ rcParams.sampleCount = rhiSampleCount;
+ rcParams.initialSurfacePixelSize = window->size() * window->effectiveDevicePixelRatio();
+ rcParams.maybeSurface = window;
+ cd->context->initialize(&rcParams);
+ } else {
+ handleContextCreationFailure(window, false);
+ }
+ } else if (!enableRhi && !gl) {
gl = new QOpenGLContext();
gl->setFormat(window->requestedFormat());
gl->setScreen(window->screen());
@@ -377,15 +547,66 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
gl = nullptr;
handleContextCreationFailure(window, isEs);
} else {
+ if (!offscreenSurface) {
+ offscreenSurface = new QOffscreenSurface;
+ offscreenSurface->setFormat(gl->format());
+ offscreenSurface->create();
+ }
cd->fireOpenGLContextCreated(gl);
current = gl->makeCurrent(window);
}
if (current) {
- auto openglRenderContext = static_cast<QSGDefaultRenderContext *>(cd->context);
- openglRenderContext->initialize(gl);
+ QSGDefaultRenderContext::InitParams rcParams;
+ rcParams.sampleCount = qMax(1, gl->format().samples());
+ rcParams.openGLContext = gl;
+ rcParams.initialSurfacePixelSize = window->size() * window->effectiveDevicePixelRatio();
+ rcParams.maybeSurface = window;
+ cd->context->initialize(&rcParams);
}
} else {
- current = gl->makeCurrent(window);
+ if (rhi) {
+ current = true;
+ // With the rhi making the (OpenGL) context current serves only one
+ // purpose: to enable external OpenGL rendering connected to one of
+ // the QQuickWindow signals (beforeSynchronizing, beforeRendering,
+ // etc.) to function like it did on the direct OpenGL path. For our
+ // own rendering this call would not be necessary.
+ rhi->makeThreadLocalNativeContextCurrent();
+ } else {
+ current = gl->makeCurrent(window);
+ }
+ }
+
+ if (enableRhi && rhi && !cd->swapchain) {
+ // if it's not the first window then the rhi is not yet stored to
+ // QQuickWindowPrivate, do it now
+ cd->rhi = rhi;
+
+ QRhiSwapChain::Flags flags = QRhiSwapChain::UsedAsTransferSource; // may be used in a grab
+
+ // QQ is always premul alpha. Decide based on alphaBufferSize in
+ // requestedFormat(). (the platform plugin can override format() but
+ // what matters here is what the application wanted, hence using the
+ // requested one)
+ const bool alpha = window->requestedFormat().alphaBufferSize() > 0;
+ if (alpha)
+ flags |= QRhiSwapChain::SurfaceHasPreMulAlpha;
+
+ cd->swapchain = rhi->newSwapChain();
+ cd->depthStencilForSwapchain = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
+ QSize(),
+ rhiSampleCount,
+ QRhiRenderBuffer::UsedWithSwapChainOnly);
+ cd->swapchain->setWindow(window);
+ cd->swapchain->setDepthStencil(cd->depthStencilForSwapchain);
+ qCDebug(QSG_LOG_INFO, "MSAA sample count for the swapchain is %d. Alpha channel requested = %s",
+ rhiSampleCount, alpha ? "yes" : "no");
+ cd->swapchain->setSampleCount(rhiSampleCount);
+ cd->swapchain->setFlags(flags);
+ cd->rpDescForSwapchain = cd->swapchain->newCompatibleRenderPassDescriptor();
+ cd->swapchain->setRenderPassDescriptor(cd->rpDescForSwapchain);
+
+ window->installEventFilter(this);
}
bool lastDirtyWindow = true;
@@ -398,6 +619,24 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
i++;
}
+ // Check for context loss.
+ if (!current && !rhi && !gl->isValid()) {
+ for (auto it = m_windows.constBegin() ; it != m_windows.constEnd(); it++) {
+ QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(it.key());
+ windowPrivate->cleanupNodesOnShutdown();
+ }
+ rc->invalidate();
+ current = gl->create() && gl->makeCurrent(window);
+ if (current) {
+ QSGDefaultRenderContext::InitParams rcParams;
+ rcParams.sampleCount = qMax(1, gl->format().samples());
+ rcParams.openGLContext = gl;
+ rcParams.initialSurfacePixelSize = window->size() * window->effectiveDevicePixelRatio();
+ rcParams.maybeSurface = window;
+ rc->initialize(&rcParams);
+ }
+ }
+
if (!current)
return;
@@ -407,6 +646,17 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
if (!m_windows.contains(window))
return;
}
+
+ QSize effectiveOutputSize; // always prefer what the surface tells us, not the QWindow
+ if (cd->swapchain) {
+ effectiveOutputSize = cd->swapchain->surfacePixelSize();
+ // An update request could still be delivered right before we get an
+ // unexpose. With Vulkan on Windows for example attempting to render
+ // leads to failures at this stage since the surface size is already 0.
+ if (effectiveOutputSize.isEmpty())
+ return;
+ }
+
QElapsedTimer renderTimer;
qint64 renderTime = 0, syncTime = 0, polishTime = 0;
bool profileFrames = QSG_LOG_TIME_RENDERLOOP().isDebugEnabled();
@@ -424,6 +674,51 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
emit window->afterAnimating();
+ // Begin the frame before syncing -> sync is where we may invoke
+ // updatePaintNode() on the items and they may want to do resource updates.
+ // Also relevant for applications that connect to the before/afterSynchronizing
+ // signals and want to do graphics stuff already there.
+ if (cd->swapchain) {
+ Q_ASSERT(!effectiveOutputSize.isEmpty());
+ const QSize previousOutputSize = cd->swapchain->currentPixelSize();
+ if (previousOutputSize != effectiveOutputSize || cd->swapchainJustBecameRenderable) {
+ if (cd->swapchainJustBecameRenderable)
+ qCDebug(QSG_LOG_RENDERLOOP, "just became exposed");
+
+ cd->hasActiveSwapchain = cd->swapchain->buildOrResize();
+ if (!cd->hasActiveSwapchain && rhi->isDeviceLost()) {
+ handleDeviceLoss();
+ return;
+ }
+
+ cd->swapchainJustBecameRenderable = false;
+ cd->hasRenderableSwapchain = cd->hasActiveSwapchain;
+
+ if (cd->hasActiveSwapchain) {
+ // surface size atomicity: now that buildOrResize() succeeded,
+ // query the size that was used in there by the swapchain, and
+ // that is the size we will use while preparing the next frame.
+ effectiveOutputSize = cd->swapchain->currentPixelSize();
+ qCDebug(QSG_LOG_RENDERLOOP) << "rhi swapchain size" << effectiveOutputSize;
+ } else {
+ qWarning("Failed to build or resize swapchain");
+ }
+ }
+
+ Q_ASSERT(rhi == cd->rhi);
+ // ### the flag should only be set when the app requests it, but there's no way to do that right now
+ QRhi::BeginFrameFlags frameFlags = QRhi::ExternalContentsInPass;
+ QRhi::FrameOpResult frameResult = rhi->beginFrame(cd->swapchain, frameFlags);
+ if (frameResult != QRhi::FrameOpSuccess) {
+ if (frameResult == QRhi::FrameOpDeviceLost)
+ handleDeviceLoss();
+ else if (frameResult == QRhi::FrameOpError)
+ qWarning("Failed to start frame");
+ // out of date is not worth warning about - it may happen even during resizing on some platforms
+ return;
+ }
+ }
+
cd->syncSceneGraph();
if (lastDirtyWindow)
rc->endSync();
@@ -433,7 +728,7 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRenderLoopFrame,
QQuickProfiler::SceneGraphRenderLoopSync);
- cd->renderSceneGraph(window->size());
+ cd->renderSceneGraph(window->size(), effectiveOutputSize);
if (profileFrames)
renderTime = renderTimer.nsecsElapsed();
@@ -441,17 +736,33 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
QQuickProfiler::SceneGraphRenderLoopRender);
if (data.grabOnly) {
- bool alpha = window->format().alphaBufferSize() > 0 && window->color().alpha() != 255;
- grabContent = qt_gl_read_framebuffer(window->size() * window->effectiveDevicePixelRatio(), alpha, alpha);
+ const bool alpha = window->format().alphaBufferSize() > 0 && window->color().alpha() != 255;
+ if (cd->swapchain)
+ grabContent = rhiSupport->grabAndBlockInCurrentFrame(rhi, cd->swapchain);
+ else
+ grabContent = qt_gl_read_framebuffer(window->size() * window->effectiveDevicePixelRatio(), alpha, alpha);
grabContent.setDevicePixelRatio(window->effectiveDevicePixelRatio());
data.grabOnly = false;
}
- if (alsoSwap && window->isVisible()) {
+ const bool needsPresent = alsoSwap && window->isVisible();
+ if (cd->swapchain) {
+ QRhi::EndFrameFlags flags = 0;
+ if (!needsPresent)
+ flags |= QRhi::SkipPresent;
+ QRhi::FrameOpResult frameResult = rhi->endFrame(cd->swapchain, flags);
+ if (frameResult != QRhi::FrameOpSuccess) {
+ if (frameResult == QRhi::FrameOpDeviceLost)
+ handleDeviceLoss();
+ else if (frameResult == QRhi::FrameOpError)
+ qWarning("Failed to end frame");
+ }
+ } else if (needsPresent) {
if (!cd->customRenderStage || !cd->customRenderStage->swap())
gl->swapBuffers(window);
- cd->fireFrameSwapped();
}
+ if (needsPresent)
+ cd->fireFrameSwapped();
qint64 swapTime = 0;
if (profileFrames)
@@ -472,6 +783,8 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
lastFrameTime = QTime::currentTime();
}
+ QSGRhiProfileConnection::instance()->send(rhi);
+
// Might have been set during syncSceneGraph()
if (data.updatePending)
maybeUpdate(window);
@@ -479,7 +792,26 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
void QSGGuiThreadRenderLoop::exposureChanged(QQuickWindow *window)
{
- if (window->isExposed()) {
+ QQuickWindowPrivate *wd = QQuickWindowPrivate::get(window);
+
+ // This is tricker than used to be. We want to detect having an empty
+ // surface size (which may be the case even when window->size() is
+ // non-empty, on some platforms with some graphics APIs!) as well as the
+ // case when the window just became "newly exposed" (e.g. after a
+ // minimize-restore on Windows, or when switching between fully obscured -
+ // not fully obscured on macOS)
+
+ if (!window->isExposed() || (wd->hasActiveSwapchain && wd->swapchain->surfacePixelSize().isEmpty()))
+ wd->hasRenderableSwapchain = false;
+
+ if (window->isExposed() && !wd->hasRenderableSwapchain && wd->hasActiveSwapchain
+ && !wd->swapchain->surfacePixelSize().isEmpty())
+ {
+ wd->hasRenderableSwapchain = true;
+ wd->swapchainJustBecameRenderable = true;
+ }
+
+ if (window->isExposed() && (!rhi || !wd->hasActiveSwapchain || wd->hasRenderableSwapchain)) {
m_windows[window].updatePending = true;
renderWindow(window);
}
@@ -527,7 +859,7 @@ void QSGGuiThreadRenderLoop::handleUpdateRequest(QQuickWindow *window)
renderWindow(window);
}
-#endif
+#endif // ENABLE_DEFAULT_BACKEND
#include "qsgrenderloop.moc"
#include "moc_qsgrenderloop_p.cpp"
diff --git a/src/quick/scenegraph/qsgrenderloop_p.h b/src/quick/scenegraph/qsgrenderloop_p.h
index 7bf40ecac4..02d0b84de1 100644
--- a/src/quick/scenegraph/qsgrenderloop_p.h
+++ b/src/quick/scenegraph/qsgrenderloop_p.h
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef QSGRenderLoop_P_H
-#define QSGRenderLoop_P_H
+#ifndef QSGRENDERLOOP_P_H
+#define QSGRENDERLOOP_P_H
//
// W A R N I N G
@@ -124,6 +124,13 @@ private:
QSet<QQuickWindow *> m_windows;
};
+enum QSGRenderLoopType
+{
+ BasicRenderLoop,
+ ThreadedRenderLoop,
+ WindowsRenderLoop
+};
+
QT_END_NAMESPACE
-#endif // QSGRenderLoop_P_H
+#endif // QSGRENDERLOOP_P_H
diff --git a/src/quick/scenegraph/qsgrhidistancefieldglyphcache.cpp b/src/quick/scenegraph/qsgrhidistancefieldglyphcache.cpp
new file mode 100644
index 0000000000..53b6fe117f
--- /dev/null
+++ b/src/quick/scenegraph/qsgrhidistancefieldglyphcache.cpp
@@ -0,0 +1,570 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgrhidistancefieldglyphcache_p.h"
+#include "qsgcontext_p.h"
+#include <QtGui/private/qdistancefield_p.h>
+#include <QtCore/qelapsedtimer.h>
+#include <QtQml/private/qqmlglobal_p.h>
+#include <qmath.h>
+#include <qendian.h>
+
+QT_BEGIN_NAMESPACE
+
+DEFINE_BOOL_CONFIG_OPTION(qmlUseGlyphCacheWorkaround, QML_USE_GLYPHCACHE_WORKAROUND)
+DEFINE_BOOL_CONFIG_OPTION(qsgPreferFullSizeGlyphCacheTextures, QSG_PREFER_FULLSIZE_GLYPHCACHE_TEXTURES)
+
+#if !defined(QSG_RHI_DISTANCEFIELD_GLYPH_CACHE_PADDING)
+# define QSG_RHI_DISTANCEFIELD_GLYPH_CACHE_PADDING 2
+#endif
+
+QSGRhiDistanceFieldGlyphCache::QSGRhiDistanceFieldGlyphCache(QRhi *rhi, const QRawFont &font)
+ : QSGDistanceFieldGlyphCache(font)
+ , m_rhi(rhi)
+{
+ // Load a pregenerated cache if the font contains one
+ loadPregeneratedCache(font);
+}
+
+QSGRhiDistanceFieldGlyphCache::~QSGRhiDistanceFieldGlyphCache()
+{
+ for (int i = 0; i < m_textures.count(); ++i)
+ delete m_textures[i].texture;
+
+ delete m_areaAllocator;
+
+ // should be empty, but just in case
+ qDeleteAll(m_pendingDispose);
+}
+
+void QSGRhiDistanceFieldGlyphCache::requestGlyphs(const QSet<glyph_t> &glyphs)
+{
+ QList<GlyphPosition> glyphPositions;
+ QVector<glyph_t> glyphsToRender;
+
+ if (m_areaAllocator == nullptr)
+ m_areaAllocator = new QSGAreaAllocator(QSize(maxTextureSize(), m_maxTextureCount * maxTextureSize()));
+
+ for (QSet<glyph_t>::const_iterator it = glyphs.constBegin(); it != glyphs.constEnd() ; ++it) {
+ glyph_t glyphIndex = *it;
+
+ int padding = QSG_RHI_DISTANCEFIELD_GLYPH_CACHE_PADDING;
+ QRectF boundingRect = glyphData(glyphIndex).boundingRect;
+ int glyphWidth = qCeil(boundingRect.width()) + distanceFieldRadius() * 2;
+ int glyphHeight = qCeil(boundingRect.height()) + distanceFieldRadius() * 2;
+ QSize glyphSize(glyphWidth + padding * 2, glyphHeight + padding * 2);
+ QRect alloc = m_areaAllocator->allocate(glyphSize);
+
+ if (alloc.isNull()) {
+ // Unallocate unused glyphs until we can allocated the new glyph
+ while (alloc.isNull() && !m_unusedGlyphs.isEmpty()) {
+ glyph_t unusedGlyph = *m_unusedGlyphs.constBegin();
+
+ TexCoord unusedCoord = glyphTexCoord(unusedGlyph);
+ QRectF unusedGlyphBoundingRect = glyphData(unusedGlyph).boundingRect;
+ int unusedGlyphWidth = qCeil(unusedGlyphBoundingRect.width()) + distanceFieldRadius() * 2;
+ int unusedGlyphHeight = qCeil(unusedGlyphBoundingRect.height()) + distanceFieldRadius() * 2;
+ m_areaAllocator->deallocate(QRect(unusedCoord.x - padding,
+ unusedCoord.y - padding,
+ padding * 2 + unusedGlyphWidth,
+ padding * 2 + unusedGlyphHeight));
+
+ m_unusedGlyphs.remove(unusedGlyph);
+ m_glyphsTexture.remove(unusedGlyph);
+ removeGlyph(unusedGlyph);
+
+ alloc = m_areaAllocator->allocate(glyphSize);
+ }
+
+ // Not enough space left for this glyph... skip to the next one
+ if (alloc.isNull())
+ continue;
+ }
+
+ TextureInfo *tex = textureInfo(alloc.y() / maxTextureSize());
+ alloc = QRect(alloc.x(), alloc.y() % maxTextureSize(), alloc.width(), alloc.height());
+
+ tex->allocatedArea |= alloc;
+ Q_ASSERT(tex->padding == padding || tex->padding < 0);
+ tex->padding = padding;
+
+ GlyphPosition p;
+ p.glyph = glyphIndex;
+ p.position = alloc.topLeft() + QPoint(padding, padding);
+
+ glyphPositions.append(p);
+ glyphsToRender.append(glyphIndex);
+ m_glyphsTexture.insert(glyphIndex, tex);
+ }
+
+ setGlyphsPosition(glyphPositions);
+ markGlyphsToRender(glyphsToRender);
+}
+
+void QSGRhiDistanceFieldGlyphCache::storeGlyphs(const QList<QDistanceField> &glyphs)
+{
+ typedef QHash<TextureInfo *, QVector<glyph_t> > GlyphTextureHash;
+ typedef GlyphTextureHash::const_iterator GlyphTextureHashConstIt;
+
+ GlyphTextureHash glyphTextures;
+
+ QVarLengthArray<QRhiTextureUploadEntry, 32> uploads;
+ for (int i = 0; i < glyphs.size(); ++i) {
+ QDistanceField glyph = glyphs.at(i);
+ glyph_t glyphIndex = glyph.glyph();
+ TexCoord c = glyphTexCoord(glyphIndex);
+ TextureInfo *texInfo = m_glyphsTexture.value(glyphIndex);
+
+ resizeTexture(texInfo, texInfo->allocatedArea.width(), texInfo->allocatedArea.height());
+
+ glyphTextures[texInfo].append(glyphIndex);
+
+ int padding = texInfo->padding;
+ int expectedWidth = qCeil(c.width + c.xMargin * 2);
+ glyph = glyph.copy(-padding, -padding,
+ expectedWidth + padding * 2, glyph.height() + padding * 2);
+
+ if (useTextureResizeWorkaround()) {
+ uchar *inBits = glyph.scanLine(0);
+ uchar *outBits = texInfo->image.scanLine(int(c.y) - padding) + int(c.x) - padding;
+ for (int y = 0; y < glyph.height(); ++y) {
+ memcpy(outBits, inBits, glyph.width());
+ inBits += glyph.width();
+ outBits += texInfo->image.width();
+ }
+ }
+
+ QRhiTextureSubresourceUploadDescription subresDesc(glyph.constBits(), glyph.width() * glyph.height());
+ subresDesc.setSourceSize(QSize(glyph.width(), glyph.height()));
+ subresDesc.setDestinationTopLeft(QPoint(c.x - padding, c.y - padding));
+ texInfo->uploads.append(QRhiTextureUploadEntry(0, 0, subresDesc));
+ }
+
+ if (!m_resourceUpdates)
+ m_resourceUpdates = m_rhi->nextResourceUpdateBatch();
+
+ for (int i = 0; i < glyphs.size(); ++i) {
+ TextureInfo *texInfo = m_glyphsTexture.value(glyphs.at(i).glyph());
+ if (!texInfo->uploads.isEmpty()) {
+ QRhiTextureUploadDescription desc;
+ desc.setEntries(texInfo->uploads.cbegin(), texInfo->uploads.cend());
+ m_resourceUpdates->uploadTexture(texInfo->texture, desc);
+ texInfo->uploads.clear();
+ }
+ }
+
+ for (GlyphTextureHashConstIt i = glyphTextures.constBegin(), cend = glyphTextures.constEnd(); i != cend; ++i) {
+ Texture t;
+ t.texture = i.key()->texture;
+ t.size = i.key()->size;
+ t.rhiBased = true;
+ setGlyphsTexture(i.value(), t);
+ }
+}
+
+void QSGRhiDistanceFieldGlyphCache::referenceGlyphs(const QSet<glyph_t> &glyphs)
+{
+ m_unusedGlyphs -= glyphs;
+}
+
+void QSGRhiDistanceFieldGlyphCache::releaseGlyphs(const QSet<glyph_t> &glyphs)
+{
+ m_unusedGlyphs += glyphs;
+}
+
+void QSGRhiDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo,
+ int width,
+ int height)
+{
+ QByteArray zeroBuf(width * height, 0);
+ createTexture(texInfo, width, height, zeroBuf.constData());
+}
+
+void QSGRhiDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo,
+ int width,
+ int height,
+ const void *pixels)
+{
+ if (useTextureResizeWorkaround() && texInfo->image.isNull()) {
+ texInfo->image = QDistanceField(width, height);
+ memcpy(texInfo->image.bits(), pixels, width * height);
+ }
+
+ texInfo->texture = m_rhi->newTexture(QRhiTexture::RED_OR_ALPHA8, QSize(width, height), 1, QRhiTexture::UsedAsTransferSource);
+ if (texInfo->texture->build()) {
+ if (!m_resourceUpdates)
+ m_resourceUpdates = m_rhi->nextResourceUpdateBatch();
+
+ QRhiTextureSubresourceUploadDescription subresDesc(pixels, width * height);
+ subresDesc.setSourceSize(QSize(width, height));
+ m_resourceUpdates->uploadTexture(texInfo->texture, QRhiTextureUploadEntry(0, 0, subresDesc));
+ } else {
+ qWarning("Failed to create distance field glyph cache");
+ }
+
+ texInfo->size = QSize(width, height);
+}
+
+void QSGRhiDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int width, int height)
+{
+ int oldWidth = texInfo->size.width();
+ int oldHeight = texInfo->size.height();
+ if (width == oldWidth && height == oldHeight)
+ return;
+
+ QRhiTexture *oldTexture = texInfo->texture;
+ createTexture(texInfo, width, height);
+
+ if (!oldTexture)
+ return;
+
+ updateRhiTexture(oldTexture, texInfo->texture, texInfo->size);
+
+ if (!m_resourceUpdates)
+ m_resourceUpdates = m_rhi->nextResourceUpdateBatch();
+
+ if (useTextureResizeWorkaround()) {
+ QRhiTextureSubresourceUploadDescription subresDesc(texInfo->image.constBits(),
+ oldWidth * oldHeight);
+ subresDesc.setSourceSize(QSize(oldWidth, oldHeight));
+ m_resourceUpdates->uploadTexture(texInfo->texture, QRhiTextureUploadEntry(0, 0, subresDesc));
+ texInfo->image = texInfo->image.copy(0, 0, width, height);
+ } else {
+ m_resourceUpdates->copyTexture(texInfo->texture, oldTexture);
+ }
+
+ m_pendingDispose.insert(oldTexture);
+}
+
+bool QSGRhiDistanceFieldGlyphCache::useTextureResizeWorkaround() const
+{
+ static bool set = false;
+ static bool useWorkaround = false;
+ if (!set) {
+ useWorkaround = m_rhi->backend() == QRhi::OpenGLES2 || qmlUseGlyphCacheWorkaround();
+ set = true;
+ }
+ return useWorkaround;
+}
+
+bool QSGRhiDistanceFieldGlyphCache::createFullSizeTextures() const
+{
+ return qsgPreferFullSizeGlyphCacheTextures() && glyphCount() > QT_DISTANCEFIELD_HIGHGLYPHCOUNT();
+}
+
+int QSGRhiDistanceFieldGlyphCache::maxTextureSize() const
+{
+ if (!m_maxTextureSize)
+ m_maxTextureSize = m_rhi->resourceLimit(QRhi::TextureSizeMax);
+ return m_maxTextureSize;
+}
+
+namespace {
+ struct Qtdf {
+ // We need these structs to be tightly packed, but some compilers we use do not
+ // support #pragma pack(1), so we need to hardcode the offsets/sizes in the
+ // file format
+ enum TableSize {
+ HeaderSize = 14,
+ GlyphRecordSize = 46,
+ TextureRecordSize = 17
+ };
+
+ enum Offset {
+ // Header
+ majorVersion = 0,
+ minorVersion = 1,
+ pixelSize = 2,
+ textureSize = 4,
+ flags = 8,
+ headerPadding = 9,
+ numGlyphs = 10,
+
+ // Glyph record
+ glyphIndex = 0,
+ textureOffsetX = 4,
+ textureOffsetY = 8,
+ textureWidth = 12,
+ textureHeight = 16,
+ xMargin = 20,
+ yMargin = 24,
+ boundingRectX = 28,
+ boundingRectY = 32,
+ boundingRectWidth = 36,
+ boundingRectHeight = 40,
+ textureIndex = 44,
+
+ // Texture record
+ allocatedX = 0,
+ allocatedY = 4,
+ allocatedWidth = 8,
+ allocatedHeight = 12,
+ texturePadding = 16
+
+ };
+
+ template <typename T>
+ static inline T fetch(const char *data, Offset offset)
+ {
+ return qFromBigEndian<T>(data + int(offset));
+ }
+ };
+}
+
+bool QSGRhiDistanceFieldGlyphCache::loadPregeneratedCache(const QRawFont &font)
+{
+ // The pregenerated data must be loaded first, otherwise the area allocator
+ // will be wrong
+ if (m_areaAllocator != nullptr) {
+ qWarning("Font cache must be loaded before cache is used");
+ return false;
+ }
+
+ static QElapsedTimer timer;
+
+ bool profile = QSG_LOG_TIME_GLYPH().isDebugEnabled();
+ if (profile)
+ timer.start();
+
+ QByteArray qtdfTable = font.fontTable("qtdf");
+ if (qtdfTable.isEmpty())
+ return false;
+
+ typedef QHash<TextureInfo *, QVector<glyph_t> > GlyphTextureHash;
+
+ GlyphTextureHash glyphTextures;
+
+ if (uint(qtdfTable.size()) < Qtdf::HeaderSize) {
+ qWarning("Invalid qtdf table in font '%s'",
+ qPrintable(font.familyName()));
+ return false;
+ }
+
+ const char *qtdfTableStart = qtdfTable.constData();
+ const char *qtdfTableEnd = qtdfTableStart + qtdfTable.size();
+
+ int padding = 0;
+ int textureCount = 0;
+ {
+ quint8 majorVersion = Qtdf::fetch<quint8>(qtdfTableStart, Qtdf::majorVersion);
+ quint8 minorVersion = Qtdf::fetch<quint8>(qtdfTableStart, Qtdf::minorVersion);
+ if (majorVersion != 5 || minorVersion != 12) {
+ qWarning("Invalid version of qtdf table %d.%d in font '%s'",
+ majorVersion,
+ minorVersion,
+ qPrintable(font.familyName()));
+ return false;
+ }
+
+ qreal pixelSize = qreal(Qtdf::fetch<quint16>(qtdfTableStart, Qtdf::pixelSize));
+ m_maxTextureSize = Qtdf::fetch<quint32>(qtdfTableStart, Qtdf::textureSize);
+ m_doubleGlyphResolution = Qtdf::fetch<quint8>(qtdfTableStart, Qtdf::flags) == 1;
+ padding = Qtdf::fetch<quint8>(qtdfTableStart, Qtdf::headerPadding);
+
+ if (pixelSize <= 0.0) {
+ qWarning("Invalid pixel size in '%s'", qPrintable(font.familyName()));
+ return false;
+ }
+
+ if (m_maxTextureSize <= 0) {
+ qWarning("Invalid texture size in '%s'", qPrintable(font.familyName()));
+ return false;
+ }
+
+ int systemMaxTextureSize = m_rhi->resourceLimit(QRhi::TextureSizeMax);
+
+ if (m_maxTextureSize > systemMaxTextureSize) {
+ qWarning("System maximum texture size is %d. This is lower than the value in '%s', which is %d",
+ systemMaxTextureSize,
+ qPrintable(font.familyName()),
+ m_maxTextureSize);
+ }
+
+ if (padding != QSG_RHI_DISTANCEFIELD_GLYPH_CACHE_PADDING) {
+ qWarning("Padding mismatch in '%s'. Font requires %d, but Qt is compiled with %d.",
+ qPrintable(font.familyName()),
+ padding,
+ QSG_RHI_DISTANCEFIELD_GLYPH_CACHE_PADDING);
+ }
+
+ m_referenceFont.setPixelSize(pixelSize);
+
+ quint32 glyphCount = Qtdf::fetch<quint32>(qtdfTableStart, Qtdf::numGlyphs);
+ m_unusedGlyphs.reserve(glyphCount);
+
+ const char *allocatorData = qtdfTableStart + Qtdf::HeaderSize;
+ {
+ m_areaAllocator = new QSGAreaAllocator(QSize(0, 0));
+ allocatorData = m_areaAllocator->deserialize(allocatorData, qtdfTableEnd - allocatorData);
+ if (allocatorData == nullptr)
+ return false;
+ }
+
+ if (m_areaAllocator->size().height() % m_maxTextureSize != 0) {
+ qWarning("Area allocator size mismatch in '%s'", qPrintable(font.familyName()));
+ return false;
+ }
+
+ textureCount = m_areaAllocator->size().height() / m_maxTextureSize;
+ m_maxTextureCount = qMax(m_maxTextureCount, textureCount);
+
+ const char *textureRecord = allocatorData;
+ for (int i = 0; i < textureCount; ++i, textureRecord += Qtdf::TextureRecordSize) {
+ if (textureRecord + Qtdf::TextureRecordSize > qtdfTableEnd) {
+ qWarning("qtdf table too small in font '%s'.",
+ qPrintable(font.familyName()));
+ return false;
+ }
+
+ TextureInfo *tex = textureInfo(i);
+ tex->allocatedArea.setX(Qtdf::fetch<quint32>(textureRecord, Qtdf::allocatedX));
+ tex->allocatedArea.setY(Qtdf::fetch<quint32>(textureRecord, Qtdf::allocatedY));
+ tex->allocatedArea.setWidth(Qtdf::fetch<quint32>(textureRecord, Qtdf::allocatedWidth));
+ tex->allocatedArea.setHeight(Qtdf::fetch<quint32>(textureRecord, Qtdf::allocatedHeight));
+ tex->padding = Qtdf::fetch<quint8>(textureRecord, Qtdf::texturePadding);
+ }
+
+ const char *glyphRecord = textureRecord;
+ for (quint32 i = 0; i < glyphCount; ++i, glyphRecord += Qtdf::GlyphRecordSize) {
+ if (glyphRecord + Qtdf::GlyphRecordSize > qtdfTableEnd) {
+ qWarning("qtdf table too small in font '%s'.",
+ qPrintable(font.familyName()));
+ return false;
+ }
+
+ glyph_t glyph = Qtdf::fetch<quint32>(glyphRecord, Qtdf::glyphIndex);
+ m_unusedGlyphs.insert(glyph);
+
+ GlyphData &glyphData = emptyData(glyph);
+
+#define FROM_FIXED_POINT(value) \
+(((qreal)value)/(qreal)65536)
+
+ glyphData.texCoord.x = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::textureOffsetX));
+ glyphData.texCoord.y = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::textureOffsetY));
+ glyphData.texCoord.width = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::textureWidth));
+ glyphData.texCoord.height = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::textureHeight));
+ glyphData.texCoord.xMargin = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::xMargin));
+ glyphData.texCoord.yMargin = FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::yMargin));
+ glyphData.boundingRect.setX(FROM_FIXED_POINT(Qtdf::fetch<qint32>(glyphRecord, Qtdf::boundingRectX)));
+ glyphData.boundingRect.setY(FROM_FIXED_POINT(Qtdf::fetch<qint32>(glyphRecord, Qtdf::boundingRectY)));
+ glyphData.boundingRect.setWidth(FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::boundingRectWidth)));
+ glyphData.boundingRect.setHeight(FROM_FIXED_POINT(Qtdf::fetch<quint32>(glyphRecord, Qtdf::boundingRectHeight)));
+
+#undef FROM_FIXED_POINT
+
+ int textureIndex = Qtdf::fetch<quint16>(glyphRecord, Qtdf::textureIndex);
+ if (textureIndex < 0 || textureIndex >= textureCount) {
+ qWarning("Invalid texture index %d (texture count == %d) in '%s'",
+ textureIndex,
+ textureCount,
+ qPrintable(font.familyName()));
+ return false;
+ }
+
+
+ TextureInfo *texInfo = textureInfo(textureIndex);
+ m_glyphsTexture.insert(glyph, texInfo);
+
+ glyphTextures[texInfo].append(glyph);
+ }
+
+ const uchar *textureData = reinterpret_cast<const uchar *>(glyphRecord);
+ for (int i = 0; i < textureCount; ++i) {
+
+ TextureInfo *texInfo = textureInfo(i);
+
+ int width = texInfo->allocatedArea.width();
+ int height = texInfo->allocatedArea.height();
+ qint64 size = width * height;
+ if (reinterpret_cast<const char *>(textureData + size) > qtdfTableEnd) {
+ qWarning("qtdf table too small in font '%s'.",
+ qPrintable(font.familyName()));
+ return false;
+ }
+
+ createTexture(texInfo, width, height, textureData);
+
+ QVector<glyph_t> glyphs = glyphTextures.value(texInfo);
+
+ Texture t;
+ t.texture = texInfo->texture;
+ t.size = texInfo->size;
+ t.rhiBased = true;
+
+ setGlyphsTexture(glyphs, t);
+
+ textureData += size;
+ }
+ }
+
+ if (profile) {
+ quint64 now = timer.elapsed();
+ qCDebug(QSG_LOG_TIME_GLYPH,
+ "distancefield: %d pre-generated glyphs loaded in %dms",
+ m_unusedGlyphs.size(),
+ (int) now);
+ }
+
+ return true;
+}
+
+void QSGRhiDistanceFieldGlyphCache::commitResourceUpdates(QRhiResourceUpdateBatch *mergeInto)
+{
+ if (m_resourceUpdates) {
+ mergeInto->merge(m_resourceUpdates);
+ m_resourceUpdates->release();
+ m_resourceUpdates = nullptr;
+ }
+
+ // now let's assume the resource updates will be committed in this frame
+ for (QRhiTexture *t : m_pendingDispose)
+ t->releaseAndDestroyLater(); // will be releaseAndDestroyed after the frame is submitted -> safe
+
+ m_pendingDispose.clear();
+}
+
+bool QSGRhiDistanceFieldGlyphCache::eightBitFormatIsAlphaSwizzled() const
+{
+ // return true when the shaders for 8-bit formats need .a instead of .r
+ // when sampling the texture
+ return !m_rhi->isFeatureSupported(QRhi::RedOrAlpha8IsRed);
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgrhidistancefieldglyphcache_p.h b/src/quick/scenegraph/qsgrhidistancefieldglyphcache_p.h
new file mode 100644
index 0000000000..d43b0aa5d4
--- /dev/null
+++ b/src/quick/scenegraph/qsgrhidistancefieldglyphcache_p.h
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGRHIDISTANCEFIELDGLYPHCACHE_H
+#define QSGRHIDISTANCEFIELDGLYPHCACHE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qsgadaptationlayer_p.h"
+#include <private/qsgareaallocator_p.h>
+#include <QtGui/private/qrhi_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_QUICK_PRIVATE_EXPORT QSGRhiDistanceFieldGlyphCache : public QSGDistanceFieldGlyphCache
+{
+public:
+ QSGRhiDistanceFieldGlyphCache(QRhi *rhi, const QRawFont &font);
+ virtual ~QSGRhiDistanceFieldGlyphCache();
+
+ void requestGlyphs(const QSet<glyph_t> &glyphs) override;
+ void storeGlyphs(const QList<QDistanceField> &glyphs) override;
+ void referenceGlyphs(const QSet<glyph_t> &glyphs) override;
+ void releaseGlyphs(const QSet<glyph_t> &glyphs) override;
+
+ bool useTextureResizeWorkaround() const;
+ bool createFullSizeTextures() const;
+ int maxTextureSize() const;
+
+ void setMaxTextureCount(int max) { m_maxTextureCount = max; }
+ int maxTextureCount() const { return m_maxTextureCount; }
+
+ void commitResourceUpdates(QRhiResourceUpdateBatch *mergeInto);
+
+ bool eightBitFormatIsAlphaSwizzled() const override;
+
+private:
+ bool loadPregeneratedCache(const QRawFont &font);
+
+ struct TextureInfo {
+ QRhiTexture *texture;
+ QSize size;
+ QRect allocatedArea;
+ QDistanceField image;
+ int padding = -1;
+ QVarLengthArray<QRhiTextureUploadEntry, 16> uploads;
+
+ TextureInfo(const QRect &preallocRect = QRect()) : texture(nullptr), allocatedArea(preallocRect) { }
+ };
+
+ void createTexture(TextureInfo *texInfo, int width, int height, const void *pixels);
+ void createTexture(TextureInfo *texInfo, int width, int height);
+ void resizeTexture(TextureInfo *texInfo, int width, int height);
+
+ TextureInfo *textureInfo(int index)
+ {
+ for (int i = m_textures.count(); i <= index; ++i) {
+ if (createFullSizeTextures())
+ m_textures.append(QRect(0, 0, maxTextureSize(), maxTextureSize()));
+ else
+ m_textures.append(TextureInfo());
+ }
+
+ return &m_textures[index];
+ }
+
+ QRhi *m_rhi;
+ mutable int m_maxTextureSize = 0;
+ int m_maxTextureCount = 3;
+ QSGAreaAllocator *m_areaAllocator = nullptr;
+ QRhiResourceUpdateBatch *m_resourceUpdates = nullptr;
+ QList<TextureInfo> m_textures;
+ QHash<glyph_t, TextureInfo *> m_glyphsTexture;
+ QSet<glyph_t> m_unusedGlyphs;
+ QSet<QRhiTexture *> m_pendingDispose;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGRHIDISTANCEFIELDGLYPHCACHE_H
diff --git a/src/quick/scenegraph/qsgrhilayer.cpp b/src/quick/scenegraph/qsgrhilayer.cpp
new file mode 100644
index 0000000000..757410eded
--- /dev/null
+++ b/src/quick/scenegraph/qsgrhilayer.cpp
@@ -0,0 +1,474 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgrhilayer_p.h"
+
+#include <private/qqmlglobal_p.h>
+#include <private/qsgrenderer_p.h>
+#include <private/qsgdefaultrendercontext_p.h>
+
+QSGRhiLayer::QSGRhiLayer(QSGRenderContext *context)
+ : QSGLayer(*(new QSGRhiLayerPrivate))
+ , m_mipmap(false)
+ , m_live(true)
+ , m_recursive(false)
+ , m_dirtyTexture(true)
+ , m_multisampling(false)
+ , m_grab(false)
+ , m_mirrorHorizontal(false)
+ , m_mirrorVertical(true)
+{
+ m_context = static_cast<QSGDefaultRenderContext *>(context);
+ m_rhi = m_context->rhi();
+ Q_ASSERT(m_rhi);
+}
+
+QSGRhiLayer::~QSGRhiLayer()
+{
+ invalidated();
+}
+
+void QSGRhiLayer::invalidated()
+{
+ releaseResources();
+
+ delete m_renderer;
+ m_renderer = nullptr;
+}
+
+int QSGRhiLayerPrivate::comparisonKey() const
+{
+ Q_Q(const QSGRhiLayer);
+ return int(qintptr(q->m_texture));
+}
+
+bool QSGRhiLayer::hasAlphaChannel() const
+{
+ return true;
+}
+
+bool QSGRhiLayer::hasMipmaps() const
+{
+ return m_mipmap;
+}
+
+int QSGRhiLayer::textureId() const
+{
+ Q_ASSERT_X(false, "QSGRhiLayer::textureId()", "Not implemented for RHI");
+ return 0;
+}
+
+void QSGRhiLayer::bind()
+{
+ Q_ASSERT_X(false, "QSGRhiLayer::bind()", "Not implemented for RHI");
+}
+
+QRhiTexture *QSGRhiLayerPrivate::rhiTexture() const
+{
+ Q_Q(const QSGRhiLayer);
+ return q->m_texture;
+}
+
+void QSGRhiLayerPrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+{
+ Q_UNUSED(rhi);
+ Q_UNUSED(resourceUpdates);
+}
+
+bool QSGRhiLayer::updateTexture()
+{
+ // called during the preprocess phase, outside of frame rendering -> good
+
+ bool doGrab = (m_live || m_grab) && m_dirtyTexture;
+ if (doGrab)
+ grab();
+
+ if (m_grab)
+ emit scheduledUpdateCompleted();
+
+ m_grab = false;
+ return doGrab;
+}
+
+void QSGRhiLayer::setHasMipmaps(bool mipmap)
+{
+ if (mipmap == m_mipmap)
+ return;
+
+ m_mipmap = mipmap;
+ if (m_mipmap && m_texture)
+ markDirtyTexture();
+}
+
+
+void QSGRhiLayer::setItem(QSGNode *item)
+{
+ if (item == m_item)
+ return;
+
+ m_item = item;
+
+ if (m_live && !m_item)
+ releaseResources();
+
+ markDirtyTexture();
+}
+
+void QSGRhiLayer::setRect(const QRectF &rect)
+{
+ if (rect == m_rect)
+ return;
+
+ m_rect = rect;
+ markDirtyTexture();
+}
+
+void QSGRhiLayer::setSize(const QSize &size)
+{
+ if (size == m_size)
+ return;
+
+ m_size = size;
+
+ if (m_live && m_size.isNull())
+ releaseResources();
+
+ markDirtyTexture();
+}
+
+void QSGRhiLayer::setFormat(uint format)
+{
+ Q_UNUSED(format);
+}
+
+void QSGRhiLayer::setLive(bool live)
+{
+ if (live == m_live)
+ return;
+
+ m_live = live;
+
+ if (m_live && (!m_item || m_size.isNull()))
+ releaseResources();
+
+ markDirtyTexture();
+}
+
+void QSGRhiLayer::scheduleUpdate()
+{
+ if (m_grab)
+ return;
+
+ m_grab = true;
+ if (m_dirtyTexture)
+ emit updateRequested();
+}
+
+void QSGRhiLayer::setRecursive(bool recursive)
+{
+ m_recursive = recursive;
+}
+
+void QSGRhiLayer::setMirrorHorizontal(bool mirror)
+{
+ m_mirrorHorizontal = mirror;
+}
+
+void QSGRhiLayer::setMirrorVertical(bool mirror)
+{
+ m_mirrorVertical = mirror;
+}
+
+void QSGRhiLayer::markDirtyTexture()
+{
+ m_dirtyTexture = true;
+ if (m_live || m_grab)
+ emit updateRequested();
+}
+
+void QSGRhiLayer::releaseResources()
+{
+ delete m_rt;
+ m_rt = nullptr;
+
+ delete m_rtRp;
+ m_rtRp = nullptr;
+
+ delete m_ds;
+ m_ds = nullptr;
+
+ delete m_msaaColorBuffer;
+ m_msaaColorBuffer = nullptr;
+
+ delete m_texture;
+ m_texture = nullptr;
+
+ delete m_secondaryTexture;
+ m_secondaryTexture = nullptr;
+}
+
+void QSGRhiLayer::grab()
+{
+ if (!m_item || m_size.isNull()) {
+ releaseResources();
+ m_dirtyTexture = false;
+ return;
+ }
+
+ int effectiveSamples = m_samples;
+ // if no layer.samples was provided use the window's msaa setting
+ if (effectiveSamples <= 1)
+ effectiveSamples = m_context->msaaSampleCount();
+
+ const bool needsNewRt = !m_rt || m_rt->pixelSize() != m_size || (m_recursive && !m_secondaryTexture);
+ const bool mipmapSettingChanged = m_texture && m_texture->flags().testFlag(QRhiTexture::MipMapped) != m_mipmap;
+ const bool msaaSettingChanged = (effectiveSamples > 1 && !m_msaaColorBuffer) || (effectiveSamples <= 1 && m_msaaColorBuffer);
+
+ if (needsNewRt ||mipmapSettingChanged || msaaSettingChanged) {
+ if (effectiveSamples <= 1) {
+ m_multisampling = false;
+ } else {
+ m_multisampling = m_rhi->isFeatureSupported(QRhi::MultisampleRenderBuffer);
+ if (!m_multisampling)
+ qWarning("Layer requested %d samples but multisample renderbuffers are not supported", effectiveSamples);
+ }
+
+ QRhiTexture::Flags textureFlags = QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource;
+ if (m_mipmap)
+ textureFlags |= QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips;
+
+ if (m_multisampling) {
+ releaseResources();
+ m_msaaColorBuffer = m_rhi->newRenderBuffer(QRhiRenderBuffer::Color, m_size, effectiveSamples);
+ if (!m_msaaColorBuffer->build()) {
+ qWarning("Failed to build multisample color buffer for layer of size %dx%d, sample count %d",
+ m_size.width(), m_size.height(), effectiveSamples);
+ releaseResources();
+ return;
+ }
+ m_texture = m_rhi->newTexture(m_format, m_size, 1, textureFlags);
+ if (!m_texture->build()) {
+ qWarning("Failed to build texture for layer of size %dx%d", m_size.width(), m_size.height());
+ releaseResources();
+ return;
+ }
+ m_ds = m_rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, m_size, effectiveSamples);
+ if (!m_ds->build()) {
+ qWarning("Failed to build depth-stencil buffer for layer");
+ releaseResources();
+ return;
+ }
+ QRhiTextureRenderTargetDescription desc;
+ QRhiColorAttachment color0(m_msaaColorBuffer);
+ color0.setResolveTexture(m_texture);
+ desc.setColorAttachments({ color0 });
+ desc.setDepthStencilBuffer(m_ds);
+ m_rt = m_rhi->newTextureRenderTarget(desc);
+ m_rtRp = m_rt->newCompatibleRenderPassDescriptor();
+ if (!m_rtRp) {
+ qWarning("Failed to build render pass descriptor for layer");
+ releaseResources();
+ return;
+ }
+ m_rt->setRenderPassDescriptor(m_rtRp);
+ if (!m_rt->build()) {
+ qWarning("Failed to build texture render target for layer");
+ releaseResources();
+ return;
+ }
+ } else {
+ releaseResources();
+ m_texture = m_rhi->newTexture(m_format, m_size, 1, textureFlags);
+ if (!m_texture->build()) {
+ qWarning("Failed to build texture for layer of size %dx%d", m_size.width(), m_size.height());
+ releaseResources();
+ return;
+ }
+ m_ds = m_rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, m_size);
+ if (!m_ds->build()) {
+ qWarning("Failed to build depth-stencil buffer for layer");
+ releaseResources();
+ return;
+ }
+ QRhiColorAttachment color0(m_texture);
+ if (m_recursive) {
+ // Here rt is associated with m_secondaryTexture instead of m_texture.
+ // We will issue a copy to m_texture afterwards.
+ m_secondaryTexture = m_rhi->newTexture(m_format, m_size, 1, textureFlags);
+ if (!m_secondaryTexture->build()) {
+ qWarning("Failed to build texture for layer of size %dx%d", m_size.width(), m_size.height());
+ releaseResources();
+ return;
+ }
+ color0.setTexture(m_secondaryTexture);
+ }
+ m_rt = m_rhi->newTextureRenderTarget({ color0, m_ds });
+ m_rtRp = m_rt->newCompatibleRenderPassDescriptor();
+ if (!m_rtRp) {
+ qWarning("Failed to build render pass descriptor for layer");
+ releaseResources();
+ return;
+ }
+ m_rt->setRenderPassDescriptor(m_rtRp);
+ if (!m_rt->build()) {
+ qWarning("Failed to build texture render target for layer");
+ releaseResources();
+ return;
+ }
+ }
+ }
+
+ QSGNode *root = m_item;
+ while (root->firstChild() && root->type() != QSGNode::RootNodeType)
+ root = root->firstChild();
+ if (root->type() != QSGNode::RootNodeType)
+ return;
+
+ if (!m_renderer) {
+ m_renderer = m_context->createRenderer();
+ connect(m_renderer, SIGNAL(sceneGraphChanged()), this, SLOT(markDirtyTexture()));
+ }
+ m_renderer->setRootNode(static_cast<QSGRootNode *>(root));
+ root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip and opacity update.
+ m_renderer->nodeChanged(root, QSGNode::DirtyForceUpdate); // Force render list update.
+
+ // This must not be moved. The flag must be reset only after the
+ // nodeChanged otherwise we end up with constantly updating even when the
+ // layer contents do not change.
+ m_dirtyTexture = false;
+
+ m_renderer->setDevicePixelRatio(m_dpr);
+ m_renderer->setDeviceRect(m_size);
+ m_renderer->setViewportRect(m_size);
+ QRectF mirrored;
+ if (m_rhi->isYUpInFramebuffer()) {
+ mirrored = QRectF(m_mirrorHorizontal ? m_rect.right() : m_rect.left(),
+ m_mirrorVertical ? m_rect.bottom() : m_rect.top(),
+ m_mirrorHorizontal ? -m_rect.width() : m_rect.width(),
+ m_mirrorVertical ? -m_rect.height() : m_rect.height());
+ } else {
+ mirrored = QRectF(m_mirrorHorizontal ? m_rect.right() : m_rect.left(),
+ m_mirrorVertical ? m_rect.top() : m_rect.bottom(),
+ m_mirrorHorizontal ? -m_rect.width() : m_rect.width(),
+ m_mirrorVertical ? m_rect.height() : -m_rect.height());
+ }
+ QSGAbstractRenderer::MatrixTransformFlags matrixFlags = 0;
+ if (!m_rhi->isYUpInNDC())
+ matrixFlags |= QSGAbstractRenderer::MatrixTransformFlipY;
+ m_renderer->setProjectionMatrixToRect(mirrored, matrixFlags);
+ m_renderer->setClearColor(Qt::transparent);
+ m_renderer->setRenderTarget(m_rt);
+ m_renderer->setCommandBuffer(m_context->currentFrameCommandBuffer());
+ m_renderer->setRenderPassDescriptor(m_rtRp);
+
+ QRhiResourceUpdateBatch *resourceUpdates = nullptr;
+
+ // render with our own "sub-renderer" (this will just add a render pass to the command buffer)
+ if (m_multisampling) {
+ m_context->renderNextRhiFrame(m_renderer);
+ } else {
+ if (m_recursive) {
+ m_context->renderNextRhiFrame(m_renderer);
+ if (!resourceUpdates)
+ resourceUpdates = m_rhi->nextResourceUpdateBatch();
+ resourceUpdates->copyTexture(m_texture, m_secondaryTexture);
+ } else {
+ m_context->renderNextRhiFrame(m_renderer);
+ }
+ }
+
+ if (m_mipmap) {
+ if (!resourceUpdates)
+ resourceUpdates = m_rhi->nextResourceUpdateBatch();
+ // going to be expensive - if done every frame - but the user asked for it...
+ resourceUpdates->generateMips(m_texture);
+ }
+
+ // Do not defer committing the resource updates to the main pass - with
+ // multiple layers there can be dependencies, so the texture should be
+ // usable once we return.
+ m_context->currentFrameCommandBuffer()->resourceUpdate(resourceUpdates);
+
+ root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip, opacity and render list update.
+
+ if (m_recursive)
+ markDirtyTexture(); // Continuously update if 'live' and 'recursive'.
+}
+
+QImage QSGRhiLayer::toImage() const
+{
+ if (!m_texture)
+ return QImage();
+
+ QRhiCommandBuffer *cb = m_context->currentFrameCommandBuffer();
+ QRhiResourceUpdateBatch *resourceUpdates = m_rhi->nextResourceUpdateBatch();
+ QRhiReadbackResult result;
+ QRhiReadbackDescription readbackDesc(m_texture);
+ resourceUpdates->readBackTexture(readbackDesc, &result);
+
+ cb->resourceUpdate(resourceUpdates);
+
+ // Inefficient but what can you do. We need the results right away. This is
+ // not something that occurs in a normal rendering process anyway. (used by
+ // QQuickItem's grabToImage).
+ m_rhi->finish();
+
+ if (result.data.isEmpty()) {
+ qWarning("Layer grab failed");
+ return QImage();
+ }
+
+ // There is no room for negotiation here, the texture is RGBA8, and the
+ // readback happens with GL_RGBA on GL, so RGBA8888 is the only option.
+ // Also, Quick is always premultiplied alpha.
+ const QImage::Format imageFormat = QImage::Format_RGBA8888_Premultiplied;
+
+ const uchar *p = reinterpret_cast<const uchar *>(result.data.constData());
+ return QImage(p, result.pixelSize.width(), result.pixelSize.height(), imageFormat).mirrored();
+}
+
+QRectF QSGRhiLayer::normalizedTextureSubRect() const
+{
+ return QRectF(m_mirrorHorizontal ? 1 : 0,
+ m_mirrorVertical ? 0 : 1,
+ m_mirrorHorizontal ? -1 : 1,
+ m_mirrorVertical ? 1 : -1);
+}
+
+#include "moc_qsgrhilayer_p.cpp"
diff --git a/src/quick/scenegraph/qsgrhilayer_p.h b/src/quick/scenegraph/qsgrhilayer_p.h
new file mode 100644
index 0000000000..6c4953ce17
--- /dev/null
+++ b/src/quick/scenegraph/qsgrhilayer_p.h
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QSGRHILAYER_P_H
+#define QSGRHILAYER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qsgadaptationlayer_p.h>
+#include <private/qsgcontext_p.h>
+#include <private/qsgtexture_p.h>
+#include <QtGui/private/qrhi_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGDefaultRenderContext;
+class QSGRhiLayerPrivate;
+
+class Q_QUICK_PRIVATE_EXPORT QSGRhiLayer : public QSGLayer
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QSGRhiLayer)
+public:
+ QSGRhiLayer(QSGRenderContext *context);
+ ~QSGRhiLayer();
+
+ bool updateTexture() override;
+
+ bool hasAlphaChannel() const override;
+ bool hasMipmaps() const override;
+ QSize textureSize() const override { return m_size; }
+
+ void bind() override;
+ int textureId() const override;
+
+ void setItem(QSGNode *item) override;
+ void setRect(const QRectF &rect) override;
+ void setSize(const QSize &size) override;
+ void setHasMipmaps(bool mipmap) override;
+ void setFormat(uint format) override;
+ void setLive(bool live) override;
+ void setRecursive(bool recursive) override;
+ void setDevicePixelRatio(qreal ratio) override { m_dpr = ratio; }
+ void setMirrorHorizontal(bool mirror) override;
+ void setMirrorVertical(bool mirror) override;
+ QRectF normalizedTextureSubRect() const override;
+ void setSamples(int samples) override { m_samples = samples; }
+
+ void scheduleUpdate() override;
+ QImage toImage() const override;
+
+public Q_SLOTS:
+ void markDirtyTexture() override;
+ void invalidated() override;
+
+private:
+ void grab();
+ void releaseResources();
+
+ QSGNode *m_item = nullptr;
+ QRectF m_rect;
+ QSize m_size;
+ qreal m_dpr = 1;
+ QRhiTexture::Format m_format = QRhiTexture::RGBA8;
+
+ QSGRenderer *m_renderer = nullptr;
+ QRhiTexture *m_texture = nullptr;
+ QRhiRenderBuffer *m_ds = nullptr;
+ QRhiRenderBuffer *m_msaaColorBuffer = nullptr;
+ QRhiTexture *m_secondaryTexture = nullptr;
+ QRhiTextureRenderTarget *m_rt = nullptr;
+ QRhiRenderPassDescriptor *m_rtRp = nullptr;
+
+ QSGDefaultRenderContext *m_context = nullptr;
+ QRhi *m_rhi = nullptr;
+ int m_samples = 0;
+
+ uint m_mipmap : 1;
+ uint m_live : 1;
+ uint m_recursive : 1;
+ uint m_dirtyTexture : 1;
+ uint m_multisampling : 1;
+ uint m_grab : 1;
+ uint m_mirrorHorizontal : 1;
+ uint m_mirrorVertical : 1;
+};
+
+class QSGRhiLayerPrivate : public QSGTexturePrivate
+{
+ Q_DECLARE_PUBLIC(QSGRhiLayer)
+public:
+ int comparisonKey() const override;
+ QRhiTexture *rhiTexture() const override;
+ void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGRHILAYER_P_H
diff --git a/src/quick/scenegraph/qsgrhishadereffectnode.cpp b/src/quick/scenegraph/qsgrhishadereffectnode.cpp
new file mode 100644
index 0000000000..6f6544548c
--- /dev/null
+++ b/src/quick/scenegraph/qsgrhishadereffectnode.cpp
@@ -0,0 +1,886 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgrhishadereffectnode_p.h"
+#include "qsgdefaultrendercontext_p.h"
+#include "qsgrhisupport_p.h"
+#include <qsgmaterialrhishader.h>
+#include <qsgtextureprovider.h>
+#include <private/qsgplaintexture_p.h>
+#include <QtGui/private/qshaderdescription_p.h>
+#include <QQmlFile>
+#include <QFile>
+#include <QFileSelector>
+
+QT_BEGIN_NAMESPACE
+
+void QSGRhiShaderLinker::reset(const QShader &vs, const QShader &fs)
+{
+ Q_ASSERT(vs.isValid() && fs.isValid());
+ m_vs = vs;
+ m_fs = fs;
+
+ m_error = false;
+
+ m_constantBufferSize = 0;
+ m_constants.clear();
+ m_samplers.clear();
+ m_samplerNameMap.clear();
+}
+
+void QSGRhiShaderLinker::feedConstants(const QSGShaderEffectNode::ShaderData &shader, const QSet<int> *dirtyIndices)
+{
+ Q_ASSERT(shader.shaderInfo.variables.count() == shader.varData.count());
+ if (!dirtyIndices) {
+ m_constantBufferSize = qMax(m_constantBufferSize, shader.shaderInfo.constantDataSize);
+ for (int i = 0; i < shader.shaderInfo.variables.count(); ++i) {
+ const QSGGuiThreadShaderEffectManager::ShaderInfo::Variable &var(shader.shaderInfo.variables.at(i));
+ if (var.type == QSGGuiThreadShaderEffectManager::ShaderInfo::Constant) {
+ const QSGShaderEffectNode::VariableData &vd(shader.varData.at(i));
+ Constant c;
+ c.size = var.size;
+ c.specialType = vd.specialType;
+ if (c.specialType != QSGShaderEffectNode::VariableData::SubRect) {
+ c.value = vd.value;
+ if (QSGRhiSupport::instance()->isShaderEffectDebuggingRequested()) {
+ if (c.specialType == QSGShaderEffectNode::VariableData::None) {
+ qDebug() << "cbuf prepare" << shader.shaderInfo.name << var.name
+ << "offset" << var.offset << "value" << c.value;
+ } else {
+ qDebug() << "cbuf prepare" << shader.shaderInfo.name << var.name
+ << "offset" << var.offset << "special" << c.specialType;
+ }
+ }
+ } else {
+ Q_ASSERT(var.name.startsWith(QByteArrayLiteral("qt_SubRect_")));
+ c.value = var.name.mid(11);
+ }
+ m_constants[var.offset] = c;
+ }
+ }
+ } else {
+ for (int idx : *dirtyIndices) {
+ const int offset = shader.shaderInfo.variables.at(idx).offset;
+ const QVariant value = shader.varData.at(idx).value;
+ m_constants[offset].value = value;
+ if (QSGRhiSupport::instance()->isShaderEffectDebuggingRequested()) {
+ qDebug() << "cbuf update" << shader.shaderInfo.name
+ << "offset" << offset << "value" << value;
+ }
+ }
+ }
+}
+
+void QSGRhiShaderLinker::feedSamplers(const QSGShaderEffectNode::ShaderData &shader, const QSet<int> *dirtyIndices)
+{
+ if (!dirtyIndices) {
+ for (int i = 0; i < shader.shaderInfo.variables.count(); ++i) {
+ const QSGGuiThreadShaderEffectManager::ShaderInfo::Variable &var(shader.shaderInfo.variables.at(i));
+ const QSGShaderEffectNode::VariableData &vd(shader.varData.at(i));
+ if (var.type == QSGGuiThreadShaderEffectManager::ShaderInfo::Sampler) {
+ Q_ASSERT(vd.specialType == QSGShaderEffectNode::VariableData::Source);
+ m_samplers.insert(var.bindPoint, vd.value);
+ m_samplerNameMap.insert(var.name, var.bindPoint);
+ }
+ }
+ } else {
+ for (int idx : *dirtyIndices) {
+ const QSGGuiThreadShaderEffectManager::ShaderInfo::Variable &var(shader.shaderInfo.variables.at(idx));
+ const QSGShaderEffectNode::VariableData &vd(shader.varData.at(idx));
+ m_samplers.insert(var.bindPoint, vd.value);
+ m_samplerNameMap.insert(var.name, var.bindPoint);
+ }
+ }
+}
+
+void QSGRhiShaderLinker::linkTextureSubRects()
+{
+ // feedConstants stores <name> in Constant::value for subrect entries. Now
+ // that both constants and textures are known, replace the name with the
+ // texture binding point.
+ for (Constant &c : m_constants) {
+ if (c.specialType == QSGShaderEffectNode::VariableData::SubRect) {
+ if (c.value.type() == QVariant::ByteArray) {
+ const QByteArray name = c.value.toByteArray();
+ if (!m_samplerNameMap.contains(name))
+ qWarning("ShaderEffect: qt_SubRect_%s refers to unknown source texture", name.constData());
+ c.value = m_samplerNameMap[name];
+ }
+ }
+ }
+}
+
+void QSGRhiShaderLinker::dump()
+{
+ if (m_error) {
+ qDebug() << "Failed to generate program data";
+ return;
+ }
+ qDebug() << "Combined shader data" << m_vs << m_fs << "cbuffer size" << m_constantBufferSize;
+ qDebug() << " - constants" << m_constants;
+ qDebug() << " - samplers" << m_samplers;
+}
+
+QDebug operator<<(QDebug debug, const QSGRhiShaderLinker::Constant &c)
+{
+ QDebugStateSaver saver(debug);
+ debug.space();
+ debug << "size" << c.size;
+ if (c.specialType != QSGShaderEffectNode::VariableData::None)
+ debug << "special" << c.specialType;
+ else
+ debug << "value" << c.value;
+ return debug;
+}
+
+struct QSGRhiShaderMaterialTypeCache
+{
+ QSGMaterialType *get(const QShader &vs, const QShader &fs);
+ void reset() { qDeleteAll(m_types); m_types.clear(); }
+
+ struct Key {
+ QShader blob[2];
+ Key() { }
+ Key(const QShader &vs, const QShader &fs) { blob[0] = vs; blob[1] = fs; }
+ bool operator==(const Key &other) const {
+ return blob[0] == other.blob[0] && blob[1] == other.blob[1];
+ }
+ };
+ QHash<Key, QSGMaterialType *> m_types;
+};
+
+uint qHash(const QSGRhiShaderMaterialTypeCache::Key &key, uint seed = 0)
+{
+ uint hash = seed;
+ for (int i = 0; i < 2; ++i)
+ hash = hash * 31337 + qHash(key.blob[i]);
+ return hash;
+}
+
+QSGMaterialType *QSGRhiShaderMaterialTypeCache::get(const QShader &vs, const QShader &fs)
+{
+ const Key k(vs, fs);
+ if (m_types.contains(k))
+ return m_types.value(k);
+
+ QSGMaterialType *t = new QSGMaterialType;
+ m_types.insert(k, t);
+ return t;
+}
+
+static QSGRhiShaderMaterialTypeCache shaderMaterialTypeCache;
+
+class QSGRhiShaderEffectMaterialShader : public QSGMaterialRhiShader
+{
+public:
+ QSGRhiShaderEffectMaterialShader(const QSGRhiShaderEffectMaterial *material);
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+ void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+ bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+QSGRhiShaderEffectMaterialShader::QSGRhiShaderEffectMaterialShader(const QSGRhiShaderEffectMaterial *material)
+{
+ setFlag(UpdatesGraphicsPipelineState, true);
+ setShader(VertexStage, material->m_vertexShader);
+ setShader(FragmentStage, material->m_fragmentShader);
+}
+
+static inline QColor qsg_premultiply_color(const QColor &c)
+{
+ return QColor::fromRgbF(c.redF() * c.alphaF(), c.greenF() * c.alphaF(), c.blueF() * c.alphaF(), c.alphaF());
+}
+
+bool QSGRhiShaderEffectMaterialShader::updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ Q_UNUSED(oldMaterial);
+ QSGRhiShaderEffectMaterial *mat = static_cast<QSGRhiShaderEffectMaterial *>(newMaterial);
+
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+
+ for (auto it = mat->m_linker.m_constants.constBegin(), itEnd = mat->m_linker.m_constants.constEnd(); it != itEnd; ++it) {
+ const int offset = it.key();
+ char *dst = buf->data() + offset;
+ const QSGRhiShaderLinker::Constant &c(it.value());
+ if (c.specialType == QSGShaderEffectNode::VariableData::Opacity) {
+ if (state.isOpacityDirty()) {
+ const float f = state.opacity();
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, &f, sizeof(f));
+ changed = true;
+ }
+ } else if (c.specialType == QSGShaderEffectNode::VariableData::Matrix) {
+ if (state.isMatrixDirty()) {
+ const int sz = 16 * sizeof(float);
+ Q_ASSERT(sz == c.size);
+ memcpy(dst, state.combinedMatrix().constData(), sz);
+ changed = true;
+ }
+ } else if (c.specialType == QSGShaderEffectNode::VariableData::SubRect) {
+ // vec4
+ QRectF subRect(0, 0, 1, 1);
+ const int binding = c.value.toInt(); // filled in by linkTextureSubRects
+ if (binding < QSGRhiShaderEffectMaterial::MAX_BINDINGS) {
+ if (QSGTextureProvider *tp = mat->m_textureProviders.at(binding)) {
+ if (QSGTexture *t = tp->texture())
+ subRect = t->normalizedTextureSubRect();
+ }
+ }
+ const float f[4] = { float(subRect.x()), float(subRect.y()),
+ float(subRect.width()), float(subRect.height()) };
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, f, sizeof(f));
+ } else if (c.specialType == QSGShaderEffectNode::VariableData::None) {
+ changed = true;
+ switch (int(c.value.type())) {
+ case QMetaType::QColor: {
+ const QColor v = qsg_premultiply_color(qvariant_cast<QColor>(c.value));
+ const float f[4] = { float(v.redF()), float(v.greenF()), float(v.blueF()), float(v.alphaF()) };
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, f, sizeof(f));
+ break;
+ }
+ case QMetaType::Float: {
+ const float f = qvariant_cast<float>(c.value);
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, &f, sizeof(f));
+ break;
+ }
+ case QMetaType::Double: {
+ const float f = float(qvariant_cast<double>(c.value));
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, &f, sizeof(f));
+ break;
+ }
+ case QMetaType::Int: {
+ const int i = c.value.toInt();
+ Q_ASSERT(sizeof(i) == c.size);
+ memcpy(dst, &i, sizeof(i));
+ break;
+ }
+ case QMetaType::Bool: {
+ const bool b = c.value.toBool();
+ Q_ASSERT(sizeof(b) == c.size);
+ memcpy(dst, &b, sizeof(b));
+ break;
+ }
+ case QMetaType::QTransform: { // mat3
+ const QTransform v = qvariant_cast<QTransform>(c.value);
+ const float m[3][3] = {
+ { float(v.m11()), float(v.m12()), float(v.m13()) },
+ { float(v.m21()), float(v.m22()), float(v.m23()) },
+ { float(v.m31()), float(v.m32()), float(v.m33()) }
+ };
+ Q_ASSERT(sizeof(m) == c.size);
+ memcpy(dst, m[0], sizeof(m));
+ break;
+ }
+ case QMetaType::QSize:
+ case QMetaType::QSizeF: { // vec2
+ const QSizeF v = c.value.toSizeF();
+ const float f[2] = { float(v.width()), float(v.height()) };
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, f, sizeof(f));
+ break;
+ }
+ case QMetaType::QPoint:
+ case QMetaType::QPointF: { // vec2
+ const QPointF v = c.value.toPointF();
+ const float f[2] = { float(v.x()), float(v.y()) };
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, f, sizeof(f));
+ break;
+ }
+ case QMetaType::QRect:
+ case QMetaType::QRectF: { // vec4
+ const QRectF v = c.value.toRectF();
+ const float f[4] = { float(v.x()), float(v.y()), float(v.width()), float(v.height()) };
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, f, sizeof(f));
+ break;
+ }
+ case QMetaType::QVector2D: { // vec2
+ const QVector2D v = qvariant_cast<QVector2D>(c.value);
+ const float f[2] = { float(v.x()), float(v.y()) };
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, f, sizeof(f));
+ break;
+ }
+ case QMetaType::QVector3D: { // vec3
+ const QVector3D v = qvariant_cast<QVector3D>(c.value);
+ const float f[3] = { float(v.x()), float(v.y()), float(v.z()) };
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, f, sizeof(f));
+ break;
+ }
+ case QMetaType::QVector4D: { // vec4
+ const QVector4D v = qvariant_cast<QVector4D>(c.value);
+ const float f[4] = { float(v.x()), float(v.y()), float(v.z()), float(v.w()) };
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, f, sizeof(f));
+ break;
+ }
+ case QMetaType::QQuaternion: { // vec4
+ const QQuaternion v = qvariant_cast<QQuaternion>(c.value);
+ const float f[4] = { float(v.x()), float(v.y()), float(v.z()), float(v.scalar()) };
+ Q_ASSERT(sizeof(f) == c.size);
+ memcpy(dst, f, sizeof(f));
+ break;
+ }
+ case QMetaType::QMatrix4x4: { // mat4
+ const QMatrix4x4 v = qvariant_cast<QMatrix4x4>(c.value);
+ const int sz = 16 * sizeof(float);
+ Q_ASSERT(sz == c.size);
+ memcpy(dst, v.constData(), sz);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ }
+
+ return changed;
+}
+
+void QSGRhiShaderEffectMaterialShader::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ Q_UNUSED(oldMaterial);
+ QSGRhiShaderEffectMaterial *mat = static_cast<QSGRhiShaderEffectMaterial *>(newMaterial);
+
+ if (binding >= QSGRhiShaderEffectMaterial::MAX_BINDINGS)
+ return;
+
+ QSGTextureProvider *tp = mat->m_textureProviders.at(binding);
+ if (tp) {
+ if (QSGTexture *t = tp->texture()) {
+ t->updateRhiTexture(state.rhi(), state.resourceUpdateBatch());
+ if (t->isAtlasTexture() && !mat->m_geometryUsesTextureSubRect) {
+ // Why the hassle with the batch: while removedFromAtlas() is
+ // able to operate with its own resource update batch (which is
+ // then committed immediately), that approach is wrong when the
+ // atlas enqueued (in the updateRhiTexture() above) not yet
+ // committed operations to state.resourceUpdateBatch()... The
+ // only safe way then is to use the same batch the atlas'
+ // updateRhiTexture() used.
+ t->setWorkResourceUpdateBatch(state.resourceUpdateBatch());
+ QSGTexture *newTexture = t->removedFromAtlas();
+ t->setWorkResourceUpdateBatch(nullptr);
+ if (newTexture)
+ t = newTexture;
+ }
+ *texture = t;
+ return;
+ }
+ }
+
+ if (!mat->m_dummyTexture) {
+ mat->m_dummyTexture = new QSGPlainTexture;
+ mat->m_dummyTexture->setFiltering(QSGTexture::Nearest);
+ mat->m_dummyTexture->setHorizontalWrapMode(QSGTexture::Repeat);
+ mat->m_dummyTexture->setVerticalWrapMode(QSGTexture::Repeat);
+ QImage img(128, 128, QImage::Format_ARGB32_Premultiplied);
+ img.fill(0);
+ mat->m_dummyTexture->setImage(img);
+ mat->m_dummyTexture->updateRhiTexture(state.rhi(), state.resourceUpdateBatch());
+ }
+ *texture = mat->m_dummyTexture;
+}
+
+bool QSGRhiShaderEffectMaterialShader::updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ Q_UNUSED(state);
+ Q_UNUSED(oldMaterial);
+ QSGRhiShaderEffectMaterial *mat = static_cast<QSGRhiShaderEffectMaterial *>(newMaterial);
+
+ switch (mat->m_cullMode) {
+ case QSGShaderEffectNode::FrontFaceCulling:
+ ps->cullMode = GraphicsPipelineState::CullFront;
+ return true;
+ case QSGShaderEffectNode::BackFaceCulling:
+ ps->cullMode = GraphicsPipelineState::CullBack;
+ return true;
+ default:
+ return false;
+ }
+}
+
+QSGRhiShaderEffectMaterial::QSGRhiShaderEffectMaterial(QSGRhiShaderEffectNode *node)
+ : m_node(node)
+{
+ setFlag(SupportsRhiShader | Blending | RequiresFullMatrix, true); // may be changed in syncMaterial()
+}
+
+QSGRhiShaderEffectMaterial::~QSGRhiShaderEffectMaterial()
+{
+ delete m_dummyTexture;
+}
+
+static bool hasAtlasTexture(const QVector<QSGTextureProvider *> &textureProviders)
+{
+ for (QSGTextureProvider *tp : textureProviders) {
+ if (tp && tp->texture() && tp->texture()->isAtlasTexture())
+ return true;
+ }
+ return false;
+}
+
+int QSGRhiShaderEffectMaterial::compare(const QSGMaterial *other) const
+{
+ Q_ASSERT(other && type() == other->type());
+ const QSGRhiShaderEffectMaterial *o = static_cast<const QSGRhiShaderEffectMaterial *>(other);
+
+ if (int diff = m_cullMode - o->m_cullMode)
+ return diff;
+
+ if (int diff = m_textureProviders.count() - o->m_textureProviders.count())
+ return diff;
+
+ if (m_linker.m_constants != o->m_linker.m_constants)
+ return 1;
+
+ if (hasAtlasTexture(m_textureProviders) && !m_geometryUsesTextureSubRect)
+ return -1;
+
+ if (hasAtlasTexture(o->m_textureProviders) && !o->m_geometryUsesTextureSubRect)
+ return 1;
+
+ for (int binding = 0, count = m_textureProviders.count(); binding != count; ++binding) {
+ QSGTextureProvider *tp1 = m_textureProviders.at(binding);
+ QSGTextureProvider *tp2 = o->m_textureProviders.at(binding);
+ if (tp1 && tp2) {
+ QSGTexture *t1 = tp1->texture();
+ QSGTexture *t2 = tp2->texture();
+ if (t1 && t2) {
+ if (int diff = t1->comparisonKey() - t2->comparisonKey())
+ return diff;
+ } else {
+ if (!t1 && t2)
+ return -1;
+ if (t1 && !t2)
+ return 1;
+ }
+ } else {
+ if (!tp1 && tp2)
+ return -1;
+ if (tp1 && !tp2)
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+QSGMaterialType *QSGRhiShaderEffectMaterial::type() const
+{
+ return m_materialType;
+}
+
+QSGMaterialShader *QSGRhiShaderEffectMaterial::createShader() const
+{
+ Q_ASSERT(flags().testFlag(RhiShaderWanted));
+ return new QSGRhiShaderEffectMaterialShader(this);
+}
+
+void QSGRhiShaderEffectMaterial::updateTextureProviders(bool layoutChange)
+{
+ if (layoutChange) {
+ for (QSGTextureProvider *tp : m_textureProviders) {
+ if (tp) {
+ QObject::disconnect(tp, SIGNAL(textureChanged()), m_node,
+ SLOT(handleTextureChange()));
+ QObject::disconnect(tp, SIGNAL(destroyed(QObject*)), m_node,
+ SLOT(handleTextureProviderDestroyed(QObject*)));
+ }
+ }
+ m_textureProviders.fill(nullptr, MAX_BINDINGS);
+ }
+
+ for (auto it = m_linker.m_samplers.constBegin(), itEnd = m_linker.m_samplers.constEnd(); it != itEnd; ++it) {
+ const int binding = it.key();
+ QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(it.value()));
+ QSGTextureProvider *newProvider = source && source->isTextureProvider() ? source->textureProvider() : nullptr;
+ if (binding >= MAX_BINDINGS) {
+ qWarning("Sampler at binding %d exceeds the available ShaderEffect binding slots; ignored",
+ binding);
+ continue;
+ }
+ QSGTextureProvider *&activeProvider(m_textureProviders[binding]);
+ if (newProvider != activeProvider) {
+ if (activeProvider) {
+ QObject::disconnect(activeProvider, SIGNAL(textureChanged()), m_node,
+ SLOT(handleTextureChange()));
+ QObject::disconnect(activeProvider, SIGNAL(destroyed(QObject*)), m_node,
+ SLOT(handleTextureProviderDestroyed(QObject*)));
+ }
+ if (newProvider) {
+ Q_ASSERT_X(newProvider->thread() == QThread::currentThread(),
+ "QSGRhiShaderEffectMaterial::updateTextureProviders",
+ "Texture provider must belong to the rendering thread");
+ QObject::connect(newProvider, SIGNAL(textureChanged()), m_node, SLOT(handleTextureChange()));
+ QObject::connect(newProvider, SIGNAL(destroyed(QObject*)), m_node,
+ SLOT(handleTextureProviderDestroyed(QObject*)));
+ } else {
+ const char *typeName = source ? source->metaObject()->className() : it.value().typeName();
+ qWarning("ShaderEffect: Texture t%d is not assigned a valid texture provider (%s).",
+ binding, typeName);
+ }
+ activeProvider = newProvider;
+ }
+ }
+}
+
+QSGRhiShaderEffectNode::QSGRhiShaderEffectNode(QSGDefaultRenderContext *rc, QSGRhiGuiThreadShaderEffectManager *mgr)
+ : QSGShaderEffectNode(mgr),
+ m_rc(rc),
+ m_mgr(mgr),
+ m_material(this)
+{
+ setFlag(UsePreprocess, true);
+ setMaterial(&m_material);
+}
+
+QRectF QSGRhiShaderEffectNode::updateNormalizedTextureSubRect(bool supportsAtlasTextures)
+{
+ QRectF srcRect(0, 0, 1, 1);
+ bool geometryUsesTextureSubRect = false;
+ if (supportsAtlasTextures) {
+ QSGTextureProvider *tp = nullptr;
+ for (int binding = 0, count = m_material.m_textureProviders.count(); binding != count; ++binding) {
+ if (QSGTextureProvider *candidate = m_material.m_textureProviders.at(binding)) {
+ if (!tp) {
+ tp = candidate;
+ } else { // there can only be one...
+ tp = nullptr;
+ break;
+ }
+ }
+ }
+ if (tp && tp->texture()) {
+ srcRect = tp->texture()->normalizedTextureSubRect();
+ geometryUsesTextureSubRect = true;
+ }
+ }
+
+ if (m_material.m_geometryUsesTextureSubRect != geometryUsesTextureSubRect) {
+ m_material.m_geometryUsesTextureSubRect = geometryUsesTextureSubRect;
+ markDirty(QSGNode::DirtyMaterial);
+ }
+
+ return srcRect;
+}
+
+static QShader loadShader(const QString &filename)
+{
+ QFile f(filename);
+ if (!f.open(QIODevice::ReadOnly)) {
+ qWarning() << "Failed to find shader" << filename;
+ return QShader();
+ }
+ return QShader::fromSerialized(f.readAll());
+}
+
+void QSGRhiShaderEffectNode::syncMaterial(SyncData *syncData)
+{
+ static QShader defaultVertexShader;
+ static QShader defaultFragmentShader;
+
+ if (bool(m_material.flags() & QSGMaterial::Blending) != syncData->blending) {
+ m_material.setFlag(QSGMaterial::Blending, syncData->blending);
+ markDirty(QSGNode::DirtyMaterial);
+ }
+
+ if (m_material.m_cullMode != syncData->cullMode) {
+ m_material.m_cullMode = syncData->cullMode;
+ markDirty(QSGNode::DirtyMaterial);
+ }
+
+ if (syncData->dirty & QSGShaderEffectNode::DirtyShaders) {
+ m_material.m_hasCustomVertexShader = syncData->vertex.shader->hasShaderCode;
+ if (m_material.m_hasCustomVertexShader) {
+ m_material.m_vertexShader = syncData->vertex.shader->shaderInfo.rhiShader;
+ } else {
+ if (!defaultVertexShader.isValid())
+ defaultVertexShader = loadShader(QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/shadereffect.vert.qsb"));
+ m_material.m_vertexShader = defaultVertexShader;
+ }
+
+ m_material.m_hasCustomFragmentShader = syncData->fragment.shader->hasShaderCode;
+ if (m_material.m_hasCustomFragmentShader) {
+ m_material.m_fragmentShader = syncData->fragment.shader->shaderInfo.rhiShader;
+ } else {
+ if (!defaultFragmentShader.isValid())
+ defaultFragmentShader = loadShader(QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/shadereffect.frag.qsb"));
+ m_material.m_fragmentShader = defaultFragmentShader;
+ }
+
+ m_material.m_materialType = shaderMaterialTypeCache.get(m_material.m_vertexShader, m_material.m_fragmentShader);
+ m_material.m_linker.reset(m_material.m_vertexShader, m_material.m_fragmentShader);
+
+ if (m_material.m_hasCustomVertexShader) {
+ m_material.m_linker.feedConstants(*syncData->vertex.shader);
+ m_material.m_linker.feedSamplers(*syncData->vertex.shader);
+ } else {
+ QSGShaderEffectNode::ShaderData defaultSD;
+ defaultSD.shaderInfo.name = QLatin1String("Default ShaderEffect vertex shader");
+ defaultSD.shaderInfo.rhiShader = m_material.m_vertexShader;
+ defaultSD.shaderInfo.type = QSGGuiThreadShaderEffectManager::ShaderInfo::TypeVertex;
+
+ // { mat4 qt_Matrix; float qt_Opacity; } where only the matrix is used
+ QSGGuiThreadShaderEffectManager::ShaderInfo::Variable v;
+ v.name = QByteArrayLiteral("qt_Matrix");
+ v.offset = 0;
+ v.size = 16 * sizeof(float);
+ defaultSD.shaderInfo.variables.append(v);
+ QSGShaderEffectNode::VariableData vd;
+ vd.specialType = QSGShaderEffectNode::VariableData::Matrix;
+ defaultSD.varData.append(vd);
+ defaultSD.shaderInfo.constantDataSize = (16 + 1) * sizeof(float);
+ m_material.m_linker.feedConstants(defaultSD);
+ }
+
+ if (m_material.m_hasCustomFragmentShader) {
+ m_material.m_linker.feedConstants(*syncData->fragment.shader);
+ m_material.m_linker.feedSamplers(*syncData->fragment.shader);
+ } else {
+ QSGShaderEffectNode::ShaderData defaultSD;
+ defaultSD.shaderInfo.name = QLatin1String("Default ShaderEffect fragment shader");
+ defaultSD.shaderInfo.rhiShader = m_material.m_fragmentShader;
+ defaultSD.shaderInfo.type = QSGGuiThreadShaderEffectManager::ShaderInfo::TypeFragment;
+
+ // { mat4 qt_Matrix; float qt_Opacity; } where only the opacity is used
+ QSGGuiThreadShaderEffectManager::ShaderInfo::Variable v;
+ v.name = QByteArrayLiteral("qt_Opacity");
+ v.offset = 16 * sizeof(float);
+ v.size = sizeof(float);
+ defaultSD.shaderInfo.variables.append(v);
+ QSGShaderEffectNode::VariableData vd;
+ vd.specialType = QSGShaderEffectNode::VariableData::Opacity;
+ defaultSD.varData.append(vd);
+
+ v.name = QByteArrayLiteral("source");
+ v.bindPoint = 1;
+ v.type = QSGGuiThreadShaderEffectManager::ShaderInfo::Sampler;
+ defaultSD.shaderInfo.variables.append(v);
+ for (const QSGShaderEffectNode::VariableData &extVarData : qAsConst(syncData->fragment.shader->varData)) {
+ if (extVarData.specialType == QSGShaderEffectNode::VariableData::Source) {
+ vd.value = extVarData.value;
+ break;
+ }
+ }
+ vd.specialType = QSGShaderEffectNode::VariableData::Source;
+ defaultSD.varData.append(vd);
+
+ defaultSD.shaderInfo.constantDataSize = (16 + 1) * sizeof(float);
+
+ m_material.m_linker.feedConstants(defaultSD);
+ m_material.m_linker.feedSamplers(defaultSD);
+ }
+
+ m_material.m_linker.linkTextureSubRects();
+ m_material.updateTextureProviders(true);
+ markDirty(QSGNode::DirtyMaterial);
+
+ } else {
+
+ if (syncData->dirty & QSGShaderEffectNode::DirtyShaderConstant) {
+ if (!syncData->vertex.dirtyConstants->isEmpty())
+ m_material.m_linker.feedConstants(*syncData->vertex.shader, syncData->vertex.dirtyConstants);
+ if (!syncData->fragment.dirtyConstants->isEmpty())
+ m_material.m_linker.feedConstants(*syncData->fragment.shader, syncData->fragment.dirtyConstants);
+ markDirty(QSGNode::DirtyMaterial);
+ }
+
+ if (syncData->dirty & QSGShaderEffectNode::DirtyShaderTexture) {
+ if (!syncData->vertex.dirtyTextures->isEmpty())
+ m_material.m_linker.feedSamplers(*syncData->vertex.shader, syncData->vertex.dirtyTextures);
+ if (!syncData->fragment.dirtyTextures->isEmpty())
+ m_material.m_linker.feedSamplers(*syncData->fragment.shader, syncData->fragment.dirtyTextures);
+ m_material.m_linker.linkTextureSubRects();
+ m_material.updateTextureProviders(false);
+ markDirty(QSGNode::DirtyMaterial);
+ }
+ }
+
+ if (bool(m_material.flags() & QSGMaterial::RequiresFullMatrix) != m_material.m_hasCustomVertexShader) {
+ m_material.setFlag(QSGMaterial::RequiresFullMatrix, m_material.m_hasCustomVertexShader);
+ markDirty(QSGNode::DirtyMaterial);
+ }
+}
+
+void QSGRhiShaderEffectNode::handleTextureChange()
+{
+ markDirty(QSGNode::DirtyMaterial);
+ emit m_mgr->textureChanged();
+}
+
+void QSGRhiShaderEffectNode::handleTextureProviderDestroyed(QObject *object)
+{
+ for (QSGTextureProvider *&tp : m_material.m_textureProviders) {
+ if (tp == object)
+ tp = nullptr;
+ }
+}
+
+void QSGRhiShaderEffectNode::preprocess()
+{
+ for (QSGTextureProvider *tp : m_material.m_textureProviders) {
+ if (tp) {
+ if (QSGDynamicTexture *texture = qobject_cast<QSGDynamicTexture *>(tp->texture()))
+ texture->updateTexture();
+ }
+ }
+}
+
+void QSGRhiShaderEffectNode::cleanupMaterialTypeCache()
+{
+ shaderMaterialTypeCache.reset();
+}
+
+bool QSGRhiGuiThreadShaderEffectManager::hasSeparateSamplerAndTextureObjects() const
+{
+ return false; // because SPIR-V and QRhi make it look so, regardless of the underlying API
+}
+
+QString QSGRhiGuiThreadShaderEffectManager::log() const
+{
+ return QString();
+}
+
+QSGGuiThreadShaderEffectManager::Status QSGRhiGuiThreadShaderEffectManager::status() const
+{
+ return m_status;
+}
+
+void QSGRhiGuiThreadShaderEffectManager::prepareShaderCode(ShaderInfo::Type typeHint, const QByteArray &src, ShaderInfo *result)
+{
+ QUrl srcUrl(QString::fromUtf8(src));
+ if (!srcUrl.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) || srcUrl.isLocalFile()) {
+ if (!m_fileSelector) {
+ m_fileSelector = new QFileSelector(this);
+ m_fileSelector->setExtraSelectors(QStringList() << QStringLiteral("qsb"));
+ }
+ const QString fn = m_fileSelector->select(QQmlFile::urlToLocalFileOrQrc(srcUrl));
+ QFile f(fn);
+ if (!f.open(QIODevice::ReadOnly)) {
+ qWarning("ShaderEffect: Failed to read %s", qPrintable(fn));
+ m_status = Error;
+ emit shaderCodePrepared(false, typeHint, src, result);
+ emit logAndStatusChanged();
+ return;
+ }
+ const QShader s = QShader::fromSerialized(f.readAll());
+ f.close();
+ if (!s.isValid()) {
+ qWarning("ShaderEffect: Failed to deserialize QShader from %s", qPrintable(fn));
+ m_status = Error;
+ emit shaderCodePrepared(false, typeHint, src, result);
+ emit logAndStatusChanged();
+ return;
+ }
+ result->name = fn;
+ result->rhiShader = s;
+ const bool ok = reflect(result);
+ m_status = ok ? Compiled : Error;
+ emit shaderCodePrepared(ok, typeHint, src, result);
+ emit logAndStatusChanged();
+ } else {
+ qWarning("rhi shader effect only supports files (qrc or local) at the moment");
+ emit shaderCodePrepared(false, typeHint, src, result);
+ }
+}
+
+bool QSGRhiGuiThreadShaderEffectManager::reflect(ShaderInfo *result)
+{
+ switch (result->rhiShader.stage()) {
+ case QShader::VertexStage:
+ result->type = ShaderInfo::TypeVertex;
+ break;
+ case QShader::FragmentStage:
+ result->type = ShaderInfo::TypeFragment;
+ break;
+ default:
+ result->type = ShaderInfo::TypeOther;
+ qWarning("Unsupported shader stage (%d)", result->rhiShader.stage());
+ return false;
+ }
+
+ const QShaderDescription desc = result->rhiShader.description();
+ result->constantDataSize = 0;
+
+ int ubufBinding = -1;
+ const QVector<QShaderDescription::UniformBlock> ubufs = desc.uniformBlocks();
+ const int ubufCount = ubufs.count();
+ for (int i = 0; i < ubufCount; ++i) {
+ const QShaderDescription::UniformBlock &ubuf(ubufs[i]);
+ if (ubufBinding == -1 && ubuf.binding >= 0) {
+ ubufBinding = ubuf.binding;
+ result->constantDataSize = ubuf.size;
+ for (const QShaderDescription::BlockVariable &member : ubuf.members) {
+ ShaderInfo::Variable v;
+ v.type = ShaderInfo::Constant;
+ v.name = member.name.toUtf8();
+ v.offset = member.offset;
+ v.size = member.size;
+ result->variables.append(v);
+ }
+ } else {
+ qWarning("Uniform block %s (binding %d) ignored", qPrintable(ubuf.blockName), ubuf.binding);
+ }
+ }
+
+ const QVector<QShaderDescription::InOutVariable> combinedImageSamplers = desc.combinedImageSamplers();
+ const int samplerCount = combinedImageSamplers.count();
+ for (int i = 0; i < samplerCount; ++i) {
+ const QShaderDescription::InOutVariable &combinedImageSampler(combinedImageSamplers[i]);
+ ShaderInfo::Variable v;
+ v.type = ShaderInfo::Sampler;
+ v.name = combinedImageSampler.name.toUtf8();
+ v.bindPoint = combinedImageSampler.binding;
+ result->variables.append(v);
+ }
+
+ return true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgrhishadereffectnode_p.h b/src/quick/scenegraph/qsgrhishadereffectnode_p.h
new file mode 100644
index 0000000000..26460d24b2
--- /dev/null
+++ b/src/quick/scenegraph/qsgrhishadereffectnode_p.h
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGRHISHADEREFFECTNODE_P_H
+#define QSGRHISHADEREFFECTNODE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qsgadaptationlayer_p.h>
+#include <qsgmaterial.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGDefaultRenderContext;
+class QSGPlainTexture;
+class QSGRhiShaderEffectNode;
+class QSGRhiGuiThreadShaderEffectManager;
+class QFileSelector;
+
+class QSGRhiShaderLinker
+{
+public:
+ void reset(const QShader &vs, const QShader &fs);
+
+ void feedConstants(const QSGShaderEffectNode::ShaderData &shader, const QSet<int> *dirtyIndices = nullptr);
+ void feedSamplers(const QSGShaderEffectNode::ShaderData &shader, const QSet<int> *dirtyIndices = nullptr);
+ void linkTextureSubRects();
+
+ void dump();
+
+ struct Constant {
+ uint size;
+ QSGShaderEffectNode::VariableData::SpecialType specialType;
+ QVariant value;
+ bool operator==(const Constant &other) const {
+ return size == other.size && specialType == other.specialType
+ && (specialType == QSGShaderEffectNode::VariableData::None ? value == other.value : true);
+ }
+ };
+
+ bool m_error;
+ QShader m_vs;
+ QShader m_fs;
+ uint m_constantBufferSize;
+ QHash<uint, Constant> m_constants; // offset -> Constant
+ QHash<int, QVariant> m_samplers; // binding -> value (source ref)
+ QHash<QByteArray, int> m_samplerNameMap; // name -> binding
+};
+
+QDebug operator<<(QDebug debug, const QSGRhiShaderLinker::Constant &c);
+
+class QSGRhiShaderEffectMaterial : public QSGMaterial
+{
+public:
+ QSGRhiShaderEffectMaterial(QSGRhiShaderEffectNode *node);
+ ~QSGRhiShaderEffectMaterial();
+
+ int compare(const QSGMaterial *other) const override;
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
+
+ void updateTextureProviders(bool layoutChange);
+
+ static const int MAX_BINDINGS = 32;
+
+ QSGRhiShaderEffectNode *m_node;
+ QSGMaterialType *m_materialType = nullptr;
+ QSGRhiShaderLinker m_linker;
+ QVector<QSGTextureProvider *> m_textureProviders; // [binding] = QSGTextureProvider
+ bool m_geometryUsesTextureSubRect = false;
+ QSGShaderEffectNode::CullMode m_cullMode = QSGShaderEffectNode::NoCulling;
+ bool m_hasCustomVertexShader = false;
+ bool m_hasCustomFragmentShader = false;
+ QShader m_vertexShader;
+ QShader m_fragmentShader;
+ QSGPlainTexture *m_dummyTexture = nullptr;
+};
+
+class QSGRhiShaderEffectNode : public QObject, public QSGShaderEffectNode
+{
+ Q_OBJECT
+
+public:
+ QSGRhiShaderEffectNode(QSGDefaultRenderContext *rc, QSGRhiGuiThreadShaderEffectManager *mgr);
+
+ QRectF updateNormalizedTextureSubRect(bool supportsAtlasTextures) override;
+ void syncMaterial(SyncData *syncData) override;
+ void preprocess() override;
+
+ static void cleanupMaterialTypeCache();
+
+private Q_SLOTS:
+ void handleTextureChange();
+ void handleTextureProviderDestroyed(QObject *object);
+
+private:
+ QSGDefaultRenderContext *m_rc;
+ QSGRhiGuiThreadShaderEffectManager *m_mgr;
+ QSGRhiShaderEffectMaterial m_material;
+};
+
+class QSGRhiGuiThreadShaderEffectManager : public QSGGuiThreadShaderEffectManager
+{
+public:
+ bool hasSeparateSamplerAndTextureObjects() const override;
+ QString log() const override;
+ Status status() const override;
+ void prepareShaderCode(ShaderInfo::Type typeHint, const QByteArray &src, ShaderInfo *result) override;
+
+private:
+ bool reflect(ShaderInfo *result);
+ Status m_status = Uncompiled;
+ QFileSelector *m_fileSelector = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGRHISHADEREFFECTNODE_P_H
diff --git a/src/quick/scenegraph/qsgrhisupport.cpp b/src/quick/scenegraph/qsgrhisupport.cpp
new file mode 100644
index 0000000000..12c6742342
--- /dev/null
+++ b/src/quick/scenegraph/qsgrhisupport.cpp
@@ -0,0 +1,608 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgrhisupport_p.h"
+#include "qsgdefaultrendercontext_p.h"
+#include <QtGui/qwindow.h>
+
+#if QT_CONFIG(vulkan)
+#include <QtGui/qvulkaninstance.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+#if QT_CONFIG(vulkan)
+QVulkanInstance *s_vulkanInstance = nullptr;
+#endif
+
+QVulkanInstance *QSGRhiSupport::vulkanInstance()
+{
+#if QT_CONFIG(vulkan)
+ QSGRhiSupport *inst = QSGRhiSupport::instance();
+ if (!inst->isRhiEnabled() || inst->rhiBackend() != QRhi::Vulkan)
+ return nullptr;
+
+ if (!s_vulkanInstance) {
+ s_vulkanInstance = new QVulkanInstance;
+ if (inst->isDebugLayerRequested()) {
+#ifndef Q_OS_ANDROID
+ s_vulkanInstance->setLayers(QByteArrayList() << "VK_LAYER_LUNARG_standard_validation");
+#else
+ s_vulkanInstance->setLayers(QByteArrayList()
+ << "VK_LAYER_GOOGLE_threading"
+ << "VK_LAYER_LUNARG_parameter_validation"
+ << "VK_LAYER_LUNARG_object_tracker"
+ << "VK_LAYER_LUNARG_core_validation"
+ << "VK_LAYER_LUNARG_image"
+ << "VK_LAYER_LUNARG_swapchain"
+ << "VK_LAYER_GOOGLE_unique_objects");
+#endif
+ }
+ s_vulkanInstance->setExtensions(QByteArrayList()
+ << "VK_KHR_get_physical_device_properties2");
+ if (!s_vulkanInstance->create()) {
+ qWarning("Failed to create Vulkan instance");
+ delete s_vulkanInstance;
+ s_vulkanInstance = nullptr;
+ }
+ }
+ return s_vulkanInstance;
+#else
+ return nullptr;
+#endif
+}
+
+void QSGRhiSupport::cleanup()
+{
+#if QT_CONFIG(vulkan)
+ delete s_vulkanInstance;
+ s_vulkanInstance = nullptr;
+#endif
+}
+
+QSGRhiSupport::QSGRhiSupport()
+ : m_set(false),
+ m_enableRhi(false),
+ m_debugLayer(false),
+ m_profile(false),
+ m_shaderEffectDebug(false),
+ m_preferSoftwareRenderer(false)
+{
+}
+
+void QSGRhiSupport::applySettings()
+{
+ m_set = true;
+
+ // This is also done when creating the renderloop but we may be before that
+ // in case we get here due to a setScenegraphBackend() -> configure() early
+ // on in main(). Avoid losing info logs since troubleshooting gets
+ // confusing otherwise.
+ QSGRhiSupport::checkEnvQSgInfo();
+
+ if (m_requested.valid) {
+ // explicit rhi backend request from C++ (e.g. via QQuickWindow)
+ m_enableRhi = m_requested.rhi;
+ switch (m_requested.api) {
+ case QSGRendererInterface::OpenGLRhi:
+ m_rhiBackend = QRhi::OpenGLES2;
+ break;
+ case QSGRendererInterface::Direct3D11Rhi:
+ m_rhiBackend = QRhi::D3D11;
+ break;
+ case QSGRendererInterface::VulkanRhi:
+ m_rhiBackend = QRhi::Vulkan;
+ break;
+ case QSGRendererInterface::MetalRhi:
+ m_rhiBackend = QRhi::Metal;
+ break;
+ case QSGRendererInterface::NullRhi:
+ m_rhiBackend = QRhi::Null;
+ break;
+ default:
+ Q_ASSERT_X(false, "QSGRhiSupport", "Internal error: unhandled GraphicsApi type");
+ break;
+ }
+ } else {
+ // check env.vars., fall back to platform-specific defaults when backend is not set
+ m_enableRhi = uint(qEnvironmentVariableIntValue("QSG_RHI"));
+ const QByteArray rhiBackend = qgetenv("QSG_RHI_BACKEND");
+ if (rhiBackend == QByteArrayLiteral("gl")
+ || rhiBackend == QByteArrayLiteral("gles2")
+ || rhiBackend == QByteArrayLiteral("opengl"))
+ {
+ m_rhiBackend = QRhi::OpenGLES2;
+ } else if (rhiBackend == QByteArrayLiteral("d3d11") || rhiBackend == QByteArrayLiteral("d3d")) {
+ m_rhiBackend = QRhi::D3D11;
+ } else if (rhiBackend == QByteArrayLiteral("vulkan")) {
+ m_rhiBackend = QRhi::Vulkan;
+ } else if (rhiBackend == QByteArrayLiteral("metal")) {
+ m_rhiBackend = QRhi::Metal;
+ } else if (rhiBackend == QByteArrayLiteral("null")) {
+ m_rhiBackend = QRhi::Null;
+ } else {
+#if defined(Q_OS_WIN)
+ m_rhiBackend = QRhi::D3D11;
+#elif defined(Q_OS_DARWIN)
+ m_rhiBackend = QRhi::Metal;
+#else
+ m_rhiBackend = QRhi::OpenGLES2;
+#endif
+ // Vulkan has to be requested explicitly
+ }
+ }
+
+ if (!m_enableRhi)
+ return;
+
+ // validation layers (Vulkan) or debug layer (D3D)
+ m_debugLayer = uint(qEnvironmentVariableIntValue("QSG_RHI_DEBUG_LAYER"));
+
+ // EnableProfiling + DebugMarkers
+ m_profile = uint(qEnvironmentVariableIntValue("QSG_RHI_PROFILE"));
+
+ m_shaderEffectDebug = uint(qEnvironmentVariableIntValue("QSG_RHI_SHADEREFFECT_DEBUG"));
+
+ m_preferSoftwareRenderer = uint(qEnvironmentVariableIntValue("QSG_RHI_PREFER_SOFTWARE_RENDERER"));
+
+ m_killDeviceFrameCount = qEnvironmentVariableIntValue("QSG_RHI_SIMULATE_DEVICE_LOSS");
+ if (m_killDeviceFrameCount > 0 && m_rhiBackend == QRhi::D3D11)
+ qDebug("Graphics device will be reset every %d frames", m_killDeviceFrameCount);
+
+ const char *backendName = "unknown";
+ switch (m_rhiBackend) {
+ case QRhi::Null:
+ backendName = "Null";
+ break;
+ case QRhi::Vulkan:
+ backendName = "Vulkan";
+ break;
+ case QRhi::OpenGLES2:
+ backendName = "OpenGL";
+ break;
+ case QRhi::D3D11:
+ backendName = "D3D11";
+ break;
+ case QRhi::Metal:
+ backendName = "Metal";
+ break;
+ default:
+ break;
+ }
+ qCDebug(QSG_LOG_INFO,
+ "Using QRhi with backend %s\n graphics API debug/validation layers: %d\n QRhi profiling and debug markers: %d",
+ backendName, m_debugLayer, m_profile);
+ if (m_preferSoftwareRenderer)
+ qCDebug(QSG_LOG_INFO, "Prioritizing software renderers");
+}
+
+QSGRhiSupport *QSGRhiSupport::staticInst()
+{
+ static QSGRhiSupport inst;
+ return &inst;
+}
+
+void QSGRhiSupport::checkEnvQSgInfo()
+{
+ // For compatibility with 5.3 and earlier's QSG_INFO environment variables
+ if (qEnvironmentVariableIsSet("QSG_INFO"))
+ const_cast<QLoggingCategory &>(QSG_LOG_INFO()).setEnabled(QtDebugMsg, true);
+}
+
+void QSGRhiSupport::configure(QSGRendererInterface::GraphicsApi api)
+{
+ Q_ASSERT(QSGRendererInterface::isApiRhiBased(api));
+ QSGRhiSupport *inst = staticInst();
+ if (inst->m_set) {
+ qWarning("QRhi is already configured, request ignored");
+ return;
+ }
+ inst->m_requested.valid = true;
+ inst->m_requested.api = api;
+ inst->m_requested.rhi = true;
+ inst->applySettings();
+}
+
+QSGRhiSupport *QSGRhiSupport::instance()
+{
+ QSGRhiSupport *inst = staticInst();
+ if (!inst->m_set)
+ inst->applySettings();
+ return inst;
+}
+
+QSGRendererInterface::GraphicsApi QSGRhiSupport::graphicsApi() const
+{
+ if (!m_enableRhi)
+ return QSGRendererInterface::OpenGL;
+
+ switch (m_rhiBackend) {
+ case QRhi::Null:
+ return QSGRendererInterface::NullRhi;
+ case QRhi::Vulkan:
+ return QSGRendererInterface::VulkanRhi;
+ case QRhi::OpenGLES2:
+ return QSGRendererInterface::OpenGLRhi;
+ case QRhi::D3D11:
+ return QSGRendererInterface::Direct3D11Rhi;
+ case QRhi::Metal:
+ return QSGRendererInterface::MetalRhi;
+ default:
+ return QSGRendererInterface::Unknown;
+ }
+}
+
+QSurface::SurfaceType QSGRhiSupport::windowSurfaceType() const
+{
+ if (!m_enableRhi)
+ return QSurface::OpenGLSurface;
+
+ switch (m_rhiBackend) {
+ case QRhi::Vulkan:
+ return QSurface::VulkanSurface;
+ case QRhi::OpenGLES2:
+ return QSurface::OpenGLSurface;
+ case QRhi::D3D11:
+ return QSurface::OpenGLSurface; // yup, OpenGLSurface
+ case QRhi::Metal:
+ return QSurface::MetalSurface;
+ default:
+ return QSurface::OpenGLSurface;
+ }
+}
+
+#if QT_CONFIG(vulkan)
+static const void *qsgrhi_vk_rifResource(QSGRendererInterface::Resource res,
+ const QRhiNativeHandles *nat,
+ const QRhiNativeHandles *cbNat,
+ const QRhiNativeHandles *rpNat)
+{
+ const QRhiVulkanNativeHandles *vknat = static_cast<const QRhiVulkanNativeHandles *>(nat);
+ const QRhiVulkanCommandBufferNativeHandles *maybeVkCbNat =
+ static_cast<const QRhiVulkanCommandBufferNativeHandles *>(cbNat);
+ const QRhiVulkanRenderPassNativeHandles *maybeVkRpNat =
+ static_cast<const QRhiVulkanRenderPassNativeHandles *>(rpNat);
+
+ switch (res) {
+ case QSGRendererInterface::DeviceResource:
+ return &vknat->dev;
+ case QSGRendererInterface::CommandQueueResource:
+ return &vknat->gfxQueue;
+ case QSGRendererInterface::CommandListResource:
+ if (maybeVkCbNat)
+ return &maybeVkCbNat->commandBuffer;
+ else
+ return nullptr;
+ case QSGRendererInterface::PhysicalDeviceResource:
+ return &vknat->physDev;
+ case QSGRendererInterface::RenderPassResource:
+ if (maybeVkRpNat)
+ return &maybeVkRpNat->renderPass;
+ else
+ return nullptr;
+ default:
+ return nullptr;
+ }
+}
+#endif
+
+#if QT_CONFIG(opengl)
+static const void *qsgrhi_gl_rifResource(QSGRendererInterface::Resource res, const QRhiNativeHandles *nat)
+{
+ const QRhiGles2NativeHandles *glnat = static_cast<const QRhiGles2NativeHandles *>(nat);
+ switch (res) {
+ case QSGRendererInterface::OpenGLContextResource:
+ return glnat->context;
+ default:
+ return nullptr;
+ }
+}
+#endif
+
+#ifdef Q_OS_WIN
+static const void *qsgrhi_d3d11_rifResource(QSGRendererInterface::Resource res, const QRhiNativeHandles *nat)
+{
+ const QRhiD3D11NativeHandles *d3dnat = static_cast<const QRhiD3D11NativeHandles *>(nat);
+ switch (res) {
+ case QSGRendererInterface::DeviceResource:
+ return d3dnat->dev;
+ case QSGRendererInterface::DeviceContextResource:
+ return d3dnat->context;
+ default:
+ return nullptr;
+ }
+}
+#endif
+
+#ifdef Q_OS_DARWIN
+static const void *qsgrhi_mtl_rifResource(QSGRendererInterface::Resource res, const QRhiNativeHandles *nat,
+ const QRhiNativeHandles *cbNat)
+{
+ const QRhiMetalNativeHandles *mtlnat = static_cast<const QRhiMetalNativeHandles *>(nat);
+ const QRhiMetalCommandBufferNativeHandles *maybeMtlCbNat =
+ static_cast<const QRhiMetalCommandBufferNativeHandles *>(cbNat);
+
+ switch (res) {
+ case QSGRendererInterface::DeviceResource:
+ return mtlnat->dev;
+ case QSGRendererInterface::CommandQueueResource:
+ return mtlnat->cmdQueue;
+ case QSGRendererInterface::CommandListResource:
+ if (maybeMtlCbNat)
+ return maybeMtlCbNat->commandBuffer;
+ else
+ return nullptr;
+ case QSGRendererInterface::CommandEncoderResource:
+ if (maybeMtlCbNat)
+ return maybeMtlCbNat->encoder;
+ else
+ return nullptr;
+ default:
+ return nullptr;
+ }
+}
+#endif
+
+const void *QSGRhiSupport::rifResource(QSGRendererInterface::Resource res, const QSGDefaultRenderContext *rc)
+{
+ QRhi *rhi = rc->rhi();
+ if (res == QSGRendererInterface::RhiResource || !rhi)
+ return rhi;
+
+ const QRhiNativeHandles *nat = rhi->nativeHandles();
+ if (!nat)
+ return nullptr;
+
+ switch (m_rhiBackend) {
+#if QT_CONFIG(vulkan)
+ case QRhi::Vulkan:
+ {
+ QRhiCommandBuffer *cb = rc->currentFrameCommandBuffer();
+ QRhiRenderPassDescriptor *rp = rc->currentFrameRenderPass();
+ return qsgrhi_vk_rifResource(res, nat,
+ cb ? cb->nativeHandles() : nullptr,
+ rp ? rp->nativeHandles() : nullptr);
+ }
+#endif
+#if QT_CONFIG(opengl)
+ case QRhi::OpenGLES2:
+ return qsgrhi_gl_rifResource(res, nat);
+#endif
+#ifdef Q_OS_WIN
+ case QRhi::D3D11:
+ return qsgrhi_d3d11_rifResource(res, nat);
+#endif
+#ifdef Q_OS_DARWIN
+ case QRhi::Metal:
+ {
+ QRhiCommandBuffer *cb = rc->currentFrameCommandBuffer();
+ return qsgrhi_mtl_rifResource(res, nat, cb ? cb->nativeHandles() : nullptr);
+ }
+#endif
+ default:
+ return nullptr;
+ }
+}
+
+int QSGRhiSupport::chooseSampleCountForWindowWithRhi(QWindow *window, QRhi *rhi)
+{
+ int msaaSampleCount = qMax(QSurfaceFormat::defaultFormat().samples(), window->requestedFormat().samples());
+ if (qEnvironmentVariableIsSet("QSG_SAMPLES"))
+ msaaSampleCount = qEnvironmentVariableIntValue("QSG_SAMPLES");
+ msaaSampleCount = qMax(1, msaaSampleCount);
+ if (msaaSampleCount > 1) {
+ const QVector<int> supportedSampleCounts = rhi->supportedSampleCounts();
+ if (!supportedSampleCounts.contains(msaaSampleCount)) {
+ int reducedSampleCount = 1;
+ for (int i = supportedSampleCounts.count() - 1; i >= 0; --i) {
+ if (supportedSampleCounts[i] <= msaaSampleCount) {
+ reducedSampleCount = supportedSampleCounts[i];
+ break;
+ }
+ }
+ qWarning() << "Requested MSAA sample count" << msaaSampleCount
+ << "but supported sample counts are" << supportedSampleCounts
+ << ", using sample count" << reducedSampleCount << "instead";
+ msaaSampleCount = reducedSampleCount;
+ }
+ }
+ return msaaSampleCount;
+}
+
+// must be called on the main thread
+QOffscreenSurface *QSGRhiSupport::maybeCreateOffscreenSurface(QWindow *window)
+{
+ QOffscreenSurface *offscreenSurface = nullptr;
+#if QT_CONFIG(opengl)
+ if (rhiBackend() == QRhi::OpenGLES2) {
+ const QSurfaceFormat format = window->requestedFormat();
+ offscreenSurface = QRhiGles2InitParams::newFallbackSurface(format);
+ }
+#else
+ Q_UNUSED(window);
+#endif
+ return offscreenSurface;
+}
+
+// must be called on the render thread
+QRhi *QSGRhiSupport::createRhi(QWindow *window, QOffscreenSurface *offscreenSurface)
+{
+ QRhi *rhi = nullptr;
+
+ QRhi::Flags flags = 0;
+ if (isProfilingRequested())
+ flags |= QRhi::EnableProfiling | QRhi::EnableDebugMarkers;
+ if (isSoftwareRendererRequested())
+ flags |= QRhi::PreferSoftwareRenderer;
+
+ QRhi::Implementation backend = rhiBackend();
+ if (backend == QRhi::Null) {
+ QRhiNullInitParams rhiParams;
+ rhi = QRhi::create(backend, &rhiParams, flags);
+ }
+#if QT_CONFIG(opengl)
+ if (backend == QRhi::OpenGLES2) {
+ const QSurfaceFormat format = window->requestedFormat();
+ QRhiGles2InitParams rhiParams;
+ rhiParams.format = format;
+ rhiParams.fallbackSurface = offscreenSurface;
+ rhiParams.window = window;
+ rhi = QRhi::create(backend, &rhiParams, flags);
+ }
+#endif
+#if QT_CONFIG(vulkan)
+ if (backend == QRhi::Vulkan) {
+ QRhiVulkanInitParams rhiParams;
+ rhiParams.inst = window->vulkanInstance();
+ if (!rhiParams.inst)
+ qWarning("No QVulkanInstance set for QQuickWindow, this is wrong.");
+ rhiParams.window = window;
+ rhi = QRhi::create(backend, &rhiParams, flags);
+ }
+#endif
+#ifdef Q_OS_WIN
+ if (backend == QRhi::D3D11) {
+ QRhiD3D11InitParams rhiParams;
+ rhiParams.enableDebugLayer = isDebugLayerRequested();
+ if (m_killDeviceFrameCount > 0) {
+ rhiParams.framesUntilKillingDeviceViaTdr = m_killDeviceFrameCount;
+ rhiParams.repeatDeviceKill = true;
+ }
+ rhi = QRhi::create(backend, &rhiParams, flags);
+ }
+#endif
+#ifdef Q_OS_DARWIN
+ if (backend == QRhi::Metal) {
+ QRhiMetalInitParams rhiParams;
+ rhi = QRhi::create(backend, &rhiParams, flags);
+ }
+#endif
+
+ if (!rhi)
+ qWarning("Failed to create RHI (backend %d)", backend);
+
+ return rhi;
+}
+
+QImage QSGRhiSupport::grabAndBlockInCurrentFrame(QRhi *rhi, QRhiSwapChain *swapchain)
+{
+ Q_ASSERT(rhi->isRecordingFrame());
+
+ QRhiReadbackResult result;
+ QRhiReadbackDescription readbackDesc; // read from swapchain backbuffer
+ QRhiResourceUpdateBatch *resourceUpdates = rhi->nextResourceUpdateBatch();
+ resourceUpdates->readBackTexture(readbackDesc, &result);
+
+ swapchain->currentFrameCommandBuffer()->resourceUpdate(resourceUpdates);
+ rhi->finish(); // make sure the readback has finished, stall the pipeline if needed
+
+ // May be RGBA or BGRA. Plus premultiplied alpha.
+ QImage::Format imageFormat;
+ if (result.format == QRhiTexture::BGRA8) {
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ imageFormat = QImage::Format_ARGB32_Premultiplied;
+#else
+ imageFormat = QImage::Format_RGBA8888_Premultiplied;
+ // ### and should swap too
+#endif
+ } else {
+ imageFormat = QImage::Format_RGBA8888_Premultiplied;
+ }
+
+ const uchar *p = reinterpret_cast<const uchar *>(result.data.constData());
+ const QImage img(p, result.pixelSize.width(), result.pixelSize.height(), imageFormat);
+
+ if (rhi->isYUpInFramebuffer())
+ return img.mirrored();
+
+ return img.copy();
+}
+
+QSGRhiProfileConnection *QSGRhiProfileConnection::instance()
+{
+ static QSGRhiProfileConnection inst;
+ return &inst;
+}
+
+void QSGRhiProfileConnection::initialize(QRhi *rhi)
+{
+#ifdef RHI_REMOTE_PROFILER
+ const QString profHost = qEnvironmentVariable("QSG_RHI_PROFILE_HOST");
+ if (!profHost.isEmpty()) {
+ int profPort = qEnvironmentVariableIntValue("QSG_RHI_PROFILE_PORT");
+ if (!profPort)
+ profPort = 30667;
+ qCDebug(QSG_LOG_INFO, "Sending RHI profiling output to %s:%d", qPrintable(profHost), profPort);
+ m_profConn.reset(new QTcpSocket);
+ QObject::connect(m_profConn.data(), QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), m_profConn.data(),
+ [this](QAbstractSocket::SocketError socketError) { qWarning(" RHI profiler error: %d (%s)",
+ socketError, qPrintable(m_profConn->errorString())); });
+ m_profConn->connectToHost(profHost, profPort);
+ m_profConn->waitForConnected(); // blocking wait because we want to send stuff already from the init below
+ rhi->profiler()->setDevice(m_profConn.data());
+ m_lastMemStatWrite.start();
+ }
+#else
+ Q_UNUSED(rhi);
+#endif
+}
+
+void QSGRhiProfileConnection::cleanup()
+{
+#ifdef RHI_REMOTE_PROFILER
+ m_profConn.reset();
+#endif
+}
+
+void QSGRhiProfileConnection::send(QRhi *rhi)
+{
+#ifdef RHI_REMOTE_PROFILER
+ if (m_profConn) {
+ // do this every 5 sec at most
+ if (m_lastMemStatWrite.elapsed() >= 5000) {
+ rhi->profiler()->addVMemAllocatorStats();
+ m_lastMemStatWrite.restart();
+ }
+ }
+#else
+ Q_UNUSED(rhi);
+#endif
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgrhisupport_p.h b/src/quick/scenegraph/qsgrhisupport_p.h
new file mode 100644
index 0000000000..d008ecd0af
--- /dev/null
+++ b/src/quick/scenegraph/qsgrhisupport_p.h
@@ -0,0 +1,171 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGRHISUPPORT_P_H
+#define QSGRHISUPPORT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qsgrenderloop_p.h"
+#include "qsgrendererinterface.h"
+
+#include <QtGui/private/qrhi_p.h>
+
+#include <QtGui/private/qrhinull_p.h>
+
+#if QT_CONFIG(opengl)
+#include <QtGui/private/qrhigles2_p.h>
+#endif
+
+#if QT_CONFIG(vulkan)
+#include <QtGui/private/qrhivulkan_p.h>
+#endif
+
+#ifdef Q_OS_WIN
+#include <QtGui/private/qrhid3d11_p.h>
+#endif
+
+#ifdef Q_OS_DARWIN
+#include <QtGui/private/qrhimetal_p.h>
+#endif
+
+#if QT_CONFIG(qml_network)
+#define RHI_REMOTE_PROFILER
+#include <QtCore/qelapsedtimer.h>
+#include <QtCore/qscopedpointer.h>
+#include <QtNetwork/qtcpsocket.h>
+#include <QtGui/private/qrhiprofiler_p.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class QSGDefaultRenderContext;
+class QVulkanInstance;
+class QOffscreenSurface;
+
+// Opting in/out of QRhi and choosing the default/requested backend is managed
+// by this singleton. This is because this information may be needed before
+// creating a render loop. A well-written render loop sets up its QRhi and
+// related machinery based on the settings queriable from here.
+//
+// cleanup() must be called to perform global (not per thread) cleanup, such
+// as, destroying the QVulkanInstance (if one was created in vulkanInstance()).
+//
+// In addition, the class provides handy conversion and query stuff for the
+// renderloop and the QSGRendererInterface implementations.
+//
+class QSGRhiSupport
+{
+public:
+ static void configure(QSGRendererInterface::GraphicsApi api);
+ static QSGRhiSupport *instance();
+ static QVulkanInstance *vulkanInstance();
+ void cleanup();
+
+ bool isRhiEnabled() const { return m_enableRhi; }
+ QRhi::Implementation rhiBackend() const { return m_rhiBackend; }
+ QSGRendererInterface::GraphicsApi graphicsApi() const;
+
+ bool isDebugLayerRequested() const { return m_debugLayer; }
+ bool isProfilingRequested() const { return m_profile; }
+ bool isShaderEffectDebuggingRequested() const { return m_shaderEffectDebug; }
+ bool isSoftwareRendererRequested() const { return m_preferSoftwareRenderer; }
+
+ QSurface::SurfaceType windowSurfaceType() const;
+
+ const void *rifResource(QSGRendererInterface::Resource res, const QSGDefaultRenderContext *rc);
+
+ int chooseSampleCountForWindowWithRhi(QWindow *window, QRhi *rhi);
+
+ QOffscreenSurface *maybeCreateOffscreenSurface(QWindow *window);
+ QRhi *createRhi(QWindow *window, QOffscreenSurface *offscreenSurface);
+
+ QImage grabAndBlockInCurrentFrame(QRhi *rhi, QRhiSwapChain *swapchain);
+
+ static void checkEnvQSgInfo();
+
+private:
+ QSGRhiSupport();
+ void applySettings();
+ static QSGRhiSupport *staticInst();
+ struct {
+ bool valid = false;
+ QSGRendererInterface::GraphicsApi api;
+ uint rhi : 1;
+ } m_requested;
+ QRhi::Implementation m_rhiBackend = QRhi::Null;
+ int m_killDeviceFrameCount;
+ uint m_set : 1;
+ uint m_enableRhi : 1;
+ uint m_debugLayer : 1;
+ uint m_profile : 1;
+ uint m_shaderEffectDebug : 1;
+ uint m_preferSoftwareRenderer : 1;
+};
+
+// Sends QRhi resource statistics over a QTcpSocket. To be initialized by the
+// renderloop when QSGRhiSupport::isProfilingRequested() is true. Will not do
+// anything unless extra env vars (QSG_RHI_PROFILE_HOST) are set.
+class QSGRhiProfileConnection
+{
+public:
+ static QSGRhiProfileConnection *instance();
+ void initialize(QRhi *rhi);
+ void cleanup();
+ void send(QRhi *rhi);
+
+private:
+#ifdef RHI_REMOTE_PROFILER
+ QScopedPointer<QTcpSocket> m_profConn;
+ QElapsedTimer m_lastMemStatWrite;
+#endif
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGRHISUPPORT_P_H
diff --git a/src/quick/scenegraph/qsgrhitextureglyphcache.cpp b/src/quick/scenegraph/qsgrhitextureglyphcache.cpp
new file mode 100644
index 0000000000..d0108bc56e
--- /dev/null
+++ b/src/quick/scenegraph/qsgrhitextureglyphcache.cpp
@@ -0,0 +1,272 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgrhitextureglyphcache_p.h"
+#include <qrgb.h>
+#include <private/qdrawhelper_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QSGRhiTextureGlyphCache::QSGRhiTextureGlyphCache(QRhi *rhi, QFontEngine::GlyphFormat format, const QTransform &matrix,
+ const QColor &color)
+ : QImageTextureGlyphCache(format, matrix, color),
+ m_rhi(rhi)
+{
+ // Some OpenGL implementations, for instance macOS, have issues with
+ // GL_ALPHA render targets. Similarly, BGRA may be problematic on GLES 2.0.
+ // So stick with plain image uploads on GL.
+ m_resizeWithTextureCopy = m_rhi->backend() != QRhi::OpenGLES2;
+}
+
+QSGRhiTextureGlyphCache::~QSGRhiTextureGlyphCache()
+{
+ if (m_resourceUpdates)
+ m_resourceUpdates->release();
+
+ delete m_texture;
+
+ // should be empty, but just in case
+ qDeleteAll(m_pendingDispose);
+}
+
+QRhiTexture *QSGRhiTextureGlyphCache::createEmptyTexture(QRhiTexture::Format format)
+{
+ QRhiTexture *t = m_rhi->newTexture(format, m_size, 1, QRhiTexture::UsedAsTransferSource);
+ if (!t->build()) {
+ qWarning("Failed to build new glyph cache texture of size %dx%d", m_size.width(), m_size.height());
+ return nullptr;
+ }
+
+ if (!m_resourceUpdates)
+ m_resourceUpdates = m_rhi->nextResourceUpdateBatch();
+
+ // The new texture must be cleared to 0 always, this cannot be avoided
+ // otherwise artifacts will occur around the glyphs.
+ QByteArray data;
+ if (format == QRhiTexture::RED_OR_ALPHA8)
+ data.fill(0, m_size.width() * m_size.height());
+ else
+ data.fill(0, m_size.width() * m_size.height() * 4);
+ QRhiTextureSubresourceUploadDescription subresDesc(data.constData(), data.size());
+ subresDesc.setSourceSize(m_size);
+ m_resourceUpdates->uploadTexture(t, QRhiTextureUploadEntry(0, 0, subresDesc));
+
+ return t;
+}
+
+void QSGRhiTextureGlyphCache::createTextureData(int width, int height)
+{
+ width = qMax(128, width);
+ height = qMax(32, height);
+
+ if (!m_resizeWithTextureCopy)
+ QImageTextureGlyphCache::createTextureData(width, height);
+
+ m_size = QSize(width, height);
+}
+
+void QSGRhiTextureGlyphCache::resizeTextureData(int width, int height)
+{
+ width = qMax(128, width);
+ height = qMax(32, height);
+
+ if (m_size.width() >= width && m_size.height() >= height)
+ return;
+
+ m_size = QSize(width, height);
+
+ if (m_texture) {
+ QRhiTexture *t = createEmptyTexture(m_texture->format());
+ if (!t)
+ return;
+
+ if (!m_resourceUpdates)
+ m_resourceUpdates = m_rhi->nextResourceUpdateBatch();
+
+ if (m_resizeWithTextureCopy) {
+ m_resourceUpdates->copyTexture(t, m_texture);
+ } else {
+ QImageTextureGlyphCache::resizeTextureData(width, height);
+ QImage img = image();
+ prepareGlyphImage(&img);
+ QRhiTextureSubresourceUploadDescription subresDesc(img);
+ const QSize oldSize = m_texture->pixelSize();
+ subresDesc.setSourceSize(QSize(qMin(oldSize.width(), width), qMin(oldSize.height(), height)));
+ m_resourceUpdates->uploadTexture(t, QRhiTextureUploadEntry(0, 0, subresDesc));
+ }
+
+ m_pendingDispose.insert(m_texture);
+ m_texture = t;
+ }
+}
+
+void QSGRhiTextureGlyphCache::beginFillTexture()
+{
+ Q_ASSERT(m_uploads.isEmpty());
+}
+
+void QSGRhiTextureGlyphCache::prepareGlyphImage(QImage *img)
+{
+ const int maskWidth = img->width();
+ const int maskHeight = img->height();
+ const bool supportsBgra = m_rhi->isTextureFormatSupported(QRhiTexture::BGRA8);
+ m_bgra = false;
+
+ if (img->format() == QImage::Format_Mono) {
+ *img = img->convertToFormat(QImage::Format_Grayscale8);
+ } else if (img->depth() == 32) {
+ if (img->format() == QImage::Format_RGB32 || img->format() == QImage::Format_ARGB32_Premultiplied) {
+ // We need to make the alpha component equal to the average of the RGB values.
+ // This is needed when drawing sub-pixel antialiased text on translucent targets.
+ for (int y = 0; y < maskHeight; ++y) {
+ QRgb *src = (QRgb *) img->scanLine(y);
+ for (int x = 0; x < maskWidth; ++x) {
+ int r = qRed(src[x]);
+ int g = qGreen(src[x]);
+ int b = qBlue(src[x]);
+ int avg;
+ if (img->format() == QImage::Format_RGB32)
+ avg = (r + g + b + 1) / 3; // "+1" for rounding.
+ else // Format_ARGB_Premultiplied
+ avg = qAlpha(src[x]);
+
+ src[x] = qRgba(r, g, b, avg);
+#if Q_BYTE_ORDER != Q_BIG_ENDIAN
+ if (supportsBgra) {
+ m_bgra = true;
+ } else {
+ // swizzle the bits to accommodate for the RGBA upload.
+ src[x] = ARGB2RGBA(src[x]);
+ m_bgra = false;
+ }
+#endif
+ }
+ }
+ }
+ }
+}
+
+void QSGRhiTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed subPixelPosition)
+{
+ QRhiTextureSubresourceUploadDescription subresDesc;
+ QImage mask;
+
+ if (!m_resizeWithTextureCopy) {
+ QImageTextureGlyphCache::fillTexture(c, glyph, subPixelPosition);
+ mask = image();
+ subresDesc.setSourceTopLeft(QPoint(c.x, c.y));
+ subresDesc.setSourceSize(QSize(c.w, c.h));
+ } else {
+ mask = textureMapForGlyph(glyph, subPixelPosition);
+ }
+
+ prepareGlyphImage(&mask);
+
+ subresDesc.setImage(mask);
+ subresDesc.setDestinationTopLeft(QPoint(c.x, c.y));
+ m_uploads.append(QRhiTextureUploadEntry(0, 0, subresDesc));
+}
+
+void QSGRhiTextureGlyphCache::endFillTexture()
+{
+ if (m_uploads.isEmpty())
+ return;
+
+ if (!m_texture) {
+ QRhiTexture::Format texFormat;
+ if (m_format == QFontEngine::Format_A32 || m_format == QFontEngine::Format_ARGB)
+ texFormat = m_bgra ? QRhiTexture::BGRA8 : QRhiTexture::RGBA8;
+ else // should be R8, but there is the OpenGL ES 2.0 nonsense
+ texFormat = QRhiTexture::RED_OR_ALPHA8;
+
+ m_texture = createEmptyTexture(texFormat);
+ if (!m_texture)
+ return;
+ }
+
+ if (!m_resourceUpdates)
+ m_resourceUpdates = m_rhi->nextResourceUpdateBatch();
+
+ QRhiTextureUploadDescription desc;
+ desc.setEntries(m_uploads.cbegin(), m_uploads.cend());
+ m_resourceUpdates->uploadTexture(m_texture, desc);
+ m_uploads.clear();
+}
+
+int QSGRhiTextureGlyphCache::glyphPadding() const
+{
+ return 1;
+}
+
+int QSGRhiTextureGlyphCache::maxTextureWidth() const
+{
+ return m_rhi->resourceLimit(QRhi::TextureSizeMax);
+}
+
+int QSGRhiTextureGlyphCache::maxTextureHeight() const
+{
+ if (!m_resizeWithTextureCopy)
+ return qMin(1024, m_rhi->resourceLimit(QRhi::TextureSizeMax));
+
+ return m_rhi->resourceLimit(QRhi::TextureSizeMax);
+}
+
+void QSGRhiTextureGlyphCache::commitResourceUpdates(QRhiResourceUpdateBatch *mergeInto)
+{
+ if (m_resourceUpdates) {
+ mergeInto->merge(m_resourceUpdates);
+ m_resourceUpdates->release();
+ m_resourceUpdates = nullptr;
+ }
+
+ // now let's assume the resource updates will be committed in this frame
+ for (QRhiTexture *t : m_pendingDispose)
+ t->releaseAndDestroyLater(); // will be releaseAndDestroyed after the frame is submitted -> safe
+
+ m_pendingDispose.clear();
+}
+
+bool QSGRhiTextureGlyphCache::eightBitFormatIsAlphaSwizzled() const
+{
+ // return true when the shaders for 8-bit formats need .a instead of .r
+ // when sampling the texture
+ return !m_rhi->isFeatureSupported(QRhi::RedOrAlpha8IsRed);
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgrhitextureglyphcache_p.h b/src/quick/scenegraph/qsgrhitextureglyphcache_p.h
new file mode 100644
index 0000000000..49854a596e
--- /dev/null
+++ b/src/quick/scenegraph/qsgrhitextureglyphcache_p.h
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGRHITEXTUREGLYPHCACHE_P_H
+#define QSGRHITEXTUREGLYPHCACHE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/private/qtextureglyphcache_p.h>
+#include <QtGui/private/qrhi_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGRhiTextureGlyphCache : public QImageTextureGlyphCache
+{
+public:
+ QSGRhiTextureGlyphCache(QRhi *rhi, QFontEngine::GlyphFormat format, const QTransform &matrix,
+ const QColor &color = QColor());
+ ~QSGRhiTextureGlyphCache();
+
+ void createTextureData(int width, int height) override;
+ void resizeTextureData(int width, int height) override;
+ void beginFillTexture() override;
+ void fillTexture(const Coord &c, glyph_t glyph, QFixed subPixelPosition) override;
+ void endFillTexture() override;
+ int glyphPadding() const override;
+ int maxTextureWidth() const override;
+ int maxTextureHeight() const override;
+
+ QRhiTexture *texture() const { return m_texture; }
+ void commitResourceUpdates(QRhiResourceUpdateBatch *mergeInto);
+
+ // Clamp the default -1 width and height to 0 for compatibility with
+ // QOpenGLTextureGlyphCache.
+ int width() const { return qMax(0, m_size.width()); }
+ int height() const { return qMax(0, m_size.height()); }
+
+ bool eightBitFormatIsAlphaSwizzled() const;
+
+private:
+ void prepareGlyphImage(QImage *img);
+ QRhiTexture *createEmptyTexture(QRhiTexture::Format format);
+
+ QRhi *m_rhi;
+ bool m_resizeWithTextureCopy;
+ QRhiResourceUpdateBatch *m_resourceUpdates = nullptr;
+ QRhiTexture *m_texture = nullptr;
+ QSize m_size;
+ bool m_bgra = false;
+ QVarLengthArray<QRhiTextureUploadEntry, 16> m_uploads;
+ QSet<QRhiTexture *> m_pendingDispose;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGRHITEXTUREGLYPHCACHE_P_H
diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
index 232ef77324..dc1f97de54 100644
--- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp
+++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
@@ -57,6 +57,7 @@
#include <QtQuick/private/qsgrenderer_p.h>
#include "qsgthreadedrenderloop_p.h"
+#include "qsgrhisupport_p.h"
#include <private/qquickanimatorcontroller_p.h>
#include <private/qquickprofiler_p.h>
@@ -66,6 +67,7 @@
#if QT_CONFIG(quick_shadereffect)
#include <private/qquickopenglshadereffectnode_p.h>
#endif
+#include <private/qsgrhishadereffectnode_p.h>
#include <private/qsgdefaultrendercontext_p.h>
/*
@@ -145,10 +147,6 @@ const QEvent::Type WM_Obscure = QEvent::Type(QEvent::User + 1);
// (updatePaintNode())
const QEvent::Type WM_RequestSync = QEvent::Type(QEvent::User + 2);
-// Passed by the RT to itself to trigger another render pass. This is
-// typically a result of QQuickWindow::update().
-const QEvent::Type WM_RequestRepaint = QEvent::Type(QEvent::User + 3);
-
// Passed by the RL to the RT to free up maybe release SG and GL contexts
// if no windows are rendering.
const QEvent::Type WM_TryRelease = QEvent::Type(QEvent::User + 4);
@@ -160,6 +158,10 @@ const QEvent::Type WM_Grab = QEvent::Type(QEvent::User + 5);
// Passed by the window when there is a render job to run
const QEvent::Type WM_PostJob = QEvent::Type(QEvent::User + 6);
+// When using the QRhi this is sent upon PlatformSurfaceAboutToBeDestroyed from
+// the event filter installed on the QQuickWindow.
+const QEvent::Type WM_ReleaseSwapchain = QEvent::Type(QEvent::User + 7);
+
template <typename T> T *windowFor(const QList<T> &list, QQuickWindow *window)
{
for (int i=0; i<list.size(); ++i) {
@@ -181,14 +183,14 @@ public:
class WMTryReleaseEvent : public WMWindowEvent
{
public:
- WMTryReleaseEvent(QQuickWindow *win, bool destroy, QOffscreenSurface *fallback)
+ WMTryReleaseEvent(QQuickWindow *win, bool destroy, bool needsFallbackSurface)
: WMWindowEvent(win, WM_TryRelease)
, inDestructor(destroy)
- , fallbackSurface(fallback)
+ , needsFallback(needsFallbackSurface)
{}
bool inDestructor;
- QOffscreenSurface *fallbackSurface;
+ bool needsFallback;
};
class WMSyncEvent : public WMWindowEvent
@@ -197,10 +199,12 @@ public:
WMSyncEvent(QQuickWindow *c, bool inExpose, bool force)
: WMWindowEvent(c, WM_RequestSync)
, size(c->size())
+ , dpr(float(c->effectiveDevicePixelRatio()))
, syncInExpose(inExpose)
, forceRenderPass(force)
{}
QSize size;
+ float dpr;
bool syncInExpose;
bool forceRenderPass;
};
@@ -222,6 +226,12 @@ public:
QRunnable *job;
};
+class WMReleaseSwapchainEvent : public WMWindowEvent
+{
+public:
+ WMReleaseSwapchainEvent(QQuickWindow *c) : WMWindowEvent(c, WM_ReleaseSwapchain) { }
+};
+
class QSGRenderThreadEventQueue : public QQueue<QEvent *>
{
public:
@@ -271,6 +281,9 @@ public:
QSGRenderThread(QSGThreadedRenderLoop *w, QSGRenderContext *renderContext)
: wm(w)
, gl(nullptr)
+ , enableRhi(false)
+ , rhi(nullptr)
+ , offscreenSurface(nullptr)
, animatorDriver(nullptr)
, pendingUpdate(0)
, sleeping(false)
@@ -290,16 +303,16 @@ public:
~QSGRenderThread()
{
delete sgrc;
+ delete offscreenSurface;
}
- void invalidateOpenGL(QQuickWindow *window, bool inDestructor, QOffscreenSurface *backupSurface);
- void initializeOpenGL();
+ void invalidateGraphics(QQuickWindow *window, bool inDestructor, QOffscreenSurface *backupSurface);
bool event(QEvent *) override;
void run() override;
- void syncAndRender();
- void sync(bool inExpose);
+ void syncAndRender(QImage *grabImage = nullptr);
+ void sync(bool inExpose, bool inGrab);
void requestRepaint()
{
@@ -326,9 +339,15 @@ public:
ExposeRequest = 0x04 | RepaintRequest | SyncRequest
};
+ void ensureRhi();
+ void handleDeviceLoss();
+
QSGThreadedRenderLoop *wm;
QOpenGLContext *gl;
+ bool enableRhi;
+ QRhi *rhi;
QSGDefaultRenderContext *sgrc;
+ QOffscreenSurface *offscreenSurface;
QAnimationDriver *animatorDriver;
@@ -347,6 +366,8 @@ public:
QQuickWindow *window; // Will be 0 when window is not exposed
QSize windowSize;
+ float dpr = 1;
+ int rhiSampleCount = 1;
// Local event queue stuff...
bool stopEventProcessing;
@@ -380,6 +401,7 @@ bool QSGRenderThread::event(QEvent *e)
stopEventProcessing = true;
window = se->window;
windowSize = se->size;
+ dpr = se->dpr;
pendingUpdate |= SyncRequest;
if (se->syncInExpose) {
@@ -399,9 +421,9 @@ bool QSGRenderThread::event(QEvent *e)
WMTryReleaseEvent *wme = static_cast<WMTryReleaseEvent *>(e);
if (!window || wme->inDestructor) {
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- setting exit flag and invalidating OpenGL");
- invalidateOpenGL(wme->window, wme->inDestructor, wme->fallbackSurface);
- active = gl;
- Q_ASSERT_X(!wme->inDestructor || !active, "QSGRenderThread::invalidateOpenGL()", "Thread's active state is not set to false when shutting down");
+ invalidateGraphics(wme->window, wme->inDestructor, wme->needsFallback ? offscreenSurface : nullptr);
+ active = gl || rhi;
+ Q_ASSERT_X(!wme->inDestructor || !active, "QSGRenderThread::invalidateGraphics()", "Thread's active state is not set to false when shutting down");
if (sleeping)
stopEventProcessing = true;
} else {
@@ -427,19 +449,25 @@ bool QSGRenderThread::event(QEvent *e)
Q_ASSERT(ce->window == window || !window);
mutex.lock();
if (ce->window) {
- gl->makeCurrent(ce->window);
-
- qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- sync scene graph");
- QQuickWindowPrivate *d = QQuickWindowPrivate::get(ce->window);
- d->syncSceneGraph();
- sgrc->endSync();
-
- qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- rendering scene graph");
- QQuickWindowPrivate::get(ce->window)->renderSceneGraph(ce->window->size());
-
- qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- grabbing result");
- bool alpha = ce->window->format().alphaBufferSize() > 0 && ce->window->color().alpha() != 255;
- *ce->image = qt_gl_read_framebuffer(windowSize * ce->window->effectiveDevicePixelRatio(), alpha, alpha);
+ const bool alpha = ce->window->format().alphaBufferSize() > 0 && ce->window->color().alpha() != 255;
+ const QSize readbackSize = windowSize * ce->window->effectiveDevicePixelRatio();
+ if (rhi) {
+ rhi->makeThreadLocalNativeContextCurrent();
+ syncAndRender(ce->image);
+ } else {
+ gl->makeCurrent(ce->window);
+
+ qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- sync scene graph");
+ QQuickWindowPrivate *d = QQuickWindowPrivate::get(ce->window);
+ d->syncSceneGraph();
+ sgrc->endSync();
+
+ qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- rendering scene graph");
+ QQuickWindowPrivate::get(ce->window)->renderSceneGraph(ce->window->size());
+
+ qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- grabbing result");
+ *ce->image = qt_gl_read_framebuffer(readbackSize, alpha, alpha);
+ }
ce->image->setDevicePixelRatio(ce->window->effectiveDevicePixelRatio());
}
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- waking gui to handle result");
@@ -453,7 +481,10 @@ bool QSGRenderThread::event(QEvent *e)
WMJobEvent *ce = static_cast<WMJobEvent *>(e);
Q_ASSERT(ce->window == window);
if (window) {
- gl->makeCurrent(window);
+ if (rhi)
+ rhi->makeThreadLocalNativeContextCurrent();
+ else
+ gl->makeCurrent(window);
ce->job->run();
delete ce->job;
ce->job = nullptr;
@@ -462,12 +493,20 @@ bool QSGRenderThread::event(QEvent *e)
return true;
}
- case WM_RequestRepaint:
- qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_RequestPaint");
- // When GUI posts this event, it is followed by a polishAndSync, so we mustn't
- // exit the event loop yet.
- pendingUpdate |= RepaintRequest;
- break;
+ case WM_ReleaseSwapchain: {
+ qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "WM_ReleaseSwapchain");
+ WMReleaseSwapchainEvent *ce = static_cast<WMReleaseSwapchainEvent *>(e);
+ // forget about 'window' here that may be null when already unexposed
+ Q_ASSERT(ce->window);
+ mutex.lock();
+ if (ce->window) {
+ wm->releaseSwapchain(ce->window);
+ qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- swapchain released");
+ }
+ waitCondition.wakeOne();
+ mutex.unlock();
+ return true;
+ }
default:
break;
@@ -475,11 +514,11 @@ bool QSGRenderThread::event(QEvent *e)
return QThread::event(e);
}
-void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor, QOffscreenSurface *fallback)
+void QSGRenderThread::invalidateGraphics(QQuickWindow *window, bool inDestructor, QOffscreenSurface *fallback)
{
- qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "invalidateOpenGL()");
+ qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "invalidateGraphics()");
- if (!gl)
+ if (!gl && !rhi)
return;
if (!window) {
@@ -491,7 +530,12 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor,
bool wipeSG = inDestructor || !window->isPersistentSceneGraph();
bool wipeGL = inDestructor || (wipeSG && !window->isPersistentOpenGLContext());
- bool current = gl->makeCurrent(fallback ? static_cast<QSurface *>(fallback) : static_cast<QSurface *>(window));
+ bool current = true;
+ if (gl)
+ current = gl->makeCurrent(fallback ? static_cast<QSurface *>(fallback) : static_cast<QSurface *>(window));
+ else if (rhi)
+ rhi->makeThreadLocalNativeContextCurrent();
+
if (Q_UNLIKELY(!current)) {
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- cleanup without an OpenGL context");
}
@@ -499,16 +543,19 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor,
QQuickWindowPrivate *dd = QQuickWindowPrivate::get(window);
#if QT_CONFIG(quick_shadereffect)
+ QSGRhiShaderEffectNode::cleanupMaterialTypeCache();
+#if QT_CONFIG(opengl)
if (current)
QQuickOpenGLShaderEffectMaterial::cleanupMaterialCache();
#endif
+#endif
// The canvas nodes must be cleaned up regardless if we are in the destructor..
if (wipeSG) {
dd->cleanupNodesOnShutdown();
} else {
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- persistent SG, avoiding cleanup");
- if (current)
+ if (current && gl)
gl->doneCurrent();
return;
}
@@ -517,14 +564,26 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor,
QCoreApplication::processEvents();
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
if (inDestructor)
- delete dd->animationController;
- if (current)
+ dd->animationController.reset();
+ if (current && gl)
gl->doneCurrent();
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- invalidating scene graph");
if (wipeGL) {
+ if (dd->swapchain) {
+ if (window->handle()) {
+ // We get here when exiting via QCoreApplication::quit() instead of
+ // through QWindow::close().
+ wm->releaseSwapchain(window);
+ } else {
+ qWarning("QSGThreadedRenderLoop cleanup with QQuickWindow %p swapchain %p still alive, this should not happen.",
+ window, dd->swapchain);
+ }
+ }
delete gl;
gl = nullptr;
+ delete rhi;
+ rhi = nullptr;
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- invalidated OpenGL");
} else {
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- persistent GL, avoiding cleanup");
@@ -535,23 +594,41 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor,
Enters the mutex lock to make sure GUI is blocking and performs
sync, then wakes GUI.
*/
-void QSGRenderThread::sync(bool inExpose)
+void QSGRenderThread::sync(bool inExpose, bool inGrab)
{
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "sync()");
- mutex.lock();
+ if (!inGrab)
+ mutex.lock();
Q_ASSERT_X(wm->m_lockedForSync, "QSGRenderThread::sync()", "sync triggered on bad terms as gui is not already locked...");
- bool current = false;
- if (windowSize.width() > 0 && windowSize.height() > 0)
- current = gl->makeCurrent(window);
- // Check for context loss.
- if (!current && !gl->isValid()) {
- QQuickWindowPrivate::get(window)->cleanupNodesOnShutdown();
- sgrc->invalidate();
- current = gl->create() && gl->makeCurrent(window);
- if (current)
- sgrc->initialize(gl);
+ bool current = true;
+ if (gl) {
+ if (windowSize.width() > 0 && windowSize.height() > 0)
+ current = gl->makeCurrent(window);
+ else
+ current = false;
+ // Check for context loss.
+ if (!current && !gl->isValid()) {
+ QQuickWindowPrivate::get(window)->cleanupNodesOnShutdown();
+ sgrc->invalidate();
+ current = gl->create() && gl->makeCurrent(window);
+ if (current) {
+ QSGDefaultRenderContext::InitParams rcParams;
+ rcParams.sampleCount = qMax(1, gl->format().samples());
+ rcParams.openGLContext = gl;
+ rcParams.initialSurfacePixelSize = windowSize * qreal(dpr);
+ rcParams.maybeSurface = window;
+ sgrc->initialize(&rcParams);
+ }
+ }
+ } else {
+ // With the rhi making the (OpenGL) context current serves only one
+ // purpose: to enable external OpenGL rendering connected to one of
+ // the QQuickWindow signals (beforeSynchronizing, beforeRendering,
+ // etc.) to function like it did on the direct OpenGL path. For our
+ // own rendering this call would not be necessary.
+ rhi->makeThreadLocalNativeContextCurrent();
}
if (current) {
QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
@@ -576,14 +653,27 @@ void QSGRenderThread::sync(bool inExpose)
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- window has bad size, sync aborted");
}
- if (!inExpose) {
+ if (!inExpose && !inGrab) {
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- sync complete, waking Gui");
waitCondition.wakeOne();
mutex.unlock();
}
}
-void QSGRenderThread::syncAndRender()
+void QSGRenderThread::handleDeviceLoss()
+{
+ if (!rhi || !rhi->isDeviceLost())
+ return;
+
+ qWarning("Graphics device lost, cleaning up scenegraph and releasing RHI");
+ QQuickWindowPrivate::get(window)->cleanupNodesOnShutdown();
+ sgrc->invalidate();
+ wm->releaseSwapchain(window);
+ delete rhi;
+ rhi = nullptr;
+}
+
+void QSGRenderThread::syncAndRender(QImage *grabImage)
{
bool profileFrames = QSG_LOG_TIME_RENDERLOOP().isDebugEnabled();
if (profileFrames) {
@@ -600,14 +690,78 @@ void QSGRenderThread::syncAndRender()
syncResultedInChanges = false;
QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
- bool repaintRequested = (pendingUpdate & RepaintRequest) || d->customRenderStage;
- bool syncRequested = pendingUpdate & SyncRequest;
- bool exposeRequested = (pendingUpdate & ExposeRequest) == ExposeRequest;
+ const bool repaintRequested = (pendingUpdate & RepaintRequest) || d->customRenderStage || grabImage;
+ const bool syncRequested = (pendingUpdate & SyncRequest) || grabImage;
+ const bool exposeRequested = (pendingUpdate & ExposeRequest) == ExposeRequest;
pendingUpdate = 0;
+ const bool grabRequested = grabImage != nullptr;
+
+ QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window);
+ // Begin the frame before syncing -> sync is where we may invoke
+ // updatePaintNode() on the items and they may want to do resource updates.
+ // Also relevant for applications that connect to the before/afterSynchronizing
+ // signals and want to do graphics stuff already there.
+ if (cd->swapchain && windowSize.width() > 0 && windowSize.height() > 0) {
+ // always prefer what the surface tells us, not the QWindow
+ const QSize effectiveOutputSize = cd->swapchain->surfacePixelSize();
+ // An update request could still be delivered right before we get an
+ // unexpose. With Vulkan on Windows for example attempting to render
+ // leads to failures at this stage since the surface size is already 0.
+ if (effectiveOutputSize.isEmpty())
+ return;
+
+ const QSize previousOutputSize = cd->swapchain->currentPixelSize();
+ if (previousOutputSize != effectiveOutputSize || cd->swapchainJustBecameRenderable) {
+ if (cd->swapchainJustBecameRenderable)
+ qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "just became exposed");
+
+ cd->hasActiveSwapchain = cd->swapchain->buildOrResize();
+ if (!cd->hasActiveSwapchain && rhi->isDeviceLost()) {
+ handleDeviceLoss();
+ QCoreApplication::postEvent(window, new QEvent(QEvent::Type(QQuickWindowPrivate::FullUpdateRequest)));
+ return;
+ }
+
+ cd->swapchainJustBecameRenderable = false;
+ cd->hasRenderableSwapchain = cd->hasActiveSwapchain;
+
+ if (!cd->hasActiveSwapchain)
+ qWarning("Failed to build or resize swapchain");
+ else
+ qCDebug(QSG_LOG_RENDERLOOP) << "rhi swapchain size" << cd->swapchain->currentPixelSize();
+ }
+
+ Q_ASSERT(rhi == cd->rhi);
+ // ### the flag should only be set when the app requests it, but there's no way to do that right now
+ QRhi::BeginFrameFlags frameFlags = QRhi::ExternalContentsInPass;
+ QRhi::FrameOpResult frameResult = rhi->beginFrame(cd->swapchain, frameFlags);
+ if (frameResult != QRhi::FrameOpSuccess) {
+ if (frameResult == QRhi::FrameOpDeviceLost)
+ handleDeviceLoss();
+ else if (frameResult == QRhi::FrameOpError)
+ qWarning("Failed to start frame");
+ // try again later
+ if (frameResult == QRhi::FrameOpDeviceLost || frameResult == QRhi::FrameOpSwapChainOutOfDate)
+ QCoreApplication::postEvent(window, new QEvent(QEvent::Type(QQuickWindowPrivate::FullUpdateRequest)));
+ // Before returning we need to ensure the same wake up logic that
+ // would have happened if beginFrame() had suceeded.
+ if (exposeRequested) {
+ qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- bailing out due to failed beginFrame, wake Gui");
+ waitCondition.wakeOne();
+ mutex.unlock();
+ } else if (syncRequested && !grabRequested) {
+ qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- bailing out due to failed beginFrame, wake Gui like sync would do");
+ mutex.lock();
+ waitCondition.wakeOne();
+ mutex.unlock();
+ }
+ return;
+ }
+ }
if (syncRequested) {
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- updatePending, doing sync");
- sync(exposeRequested);
+ sync(exposeRequested, grabRequested);
}
#ifndef QSG_NO_RENDER_TIMING
if (profileFrames)
@@ -616,41 +770,80 @@ void QSGRenderThread::syncAndRender()
Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRenderLoopFrame,
QQuickProfiler::SceneGraphRenderLoopSync);
- if (!syncResultedInChanges && !repaintRequested && sgrc->isValid()) {
- qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- no changes, render aborted");
- int waitTime = vsyncDelta - (int) waitTimer.elapsed();
- if (waitTime > 0)
- msleep(waitTime);
- return;
+ if (!syncResultedInChanges && !repaintRequested && sgrc->isValid() && !grabImage) {
+ if (gl || !rhi->isRecordingFrame()) {
+ qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- no changes, render aborted");
+ int waitTime = vsyncDelta - (int) waitTimer.elapsed();
+ if (waitTime > 0)
+ msleep(waitTime);
+ return;
+ }
}
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "- rendering started");
- if (animatorDriver->isRunning()) {
+ if (animatorDriver->isRunning() && !grabImage) {
d->animationController->lock();
animatorDriver->advance();
d->animationController->unlock();
}
- bool current = false;
- if (d->renderer && windowSize.width() > 0 && windowSize.height() > 0)
- current = gl->makeCurrent(window);
- // Check for context loss.
- if (!current && !gl->isValid()) {
- // Cannot do anything here because gui is not locked. Request a new
- // sync+render round on the gui thread and let the sync handle it.
- QCoreApplication::postEvent(window, new QEvent(QEvent::Type(QQuickWindowPrivate::FullUpdateRequest)));
+ bool current = true;
+ if (d->renderer && windowSize.width() > 0 && windowSize.height() > 0) {
+ if (gl)
+ current = gl->makeCurrent(window);
+ else if (rhi)
+ rhi->makeThreadLocalNativeContextCurrent();
+ } else {
+ current = false;
+ }
+ // Check for context loss (GL, RHI case handled after the beginFrame() above)
+ if (gl) {
+ if (!current && !gl->isValid()) {
+ // Cannot do anything here because gui is not locked. Request a new
+ // sync+render round on the gui thread and let the sync handle it.
+ QCoreApplication::postEvent(window, new QEvent(QEvent::Type(QQuickWindowPrivate::FullUpdateRequest)));
+ }
}
if (current) {
- d->renderSceneGraph(windowSize);
+ d->renderSceneGraph(windowSize, rhi ? cd->swapchain->currentPixelSize() : QSize());
+
if (profileFrames)
renderTime = threadTimer.nsecsElapsed();
Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRenderLoopFrame,
QQuickProfiler::SceneGraphRenderLoopRender);
- if (!d->customRenderStage || !d->customRenderStage->swap())
- gl->swapBuffers(window);
- d->fireFrameSwapped();
+
+ // With the rhi grabs can only be done by adding a readback and then
+ // blocking in a real frame. The legacy GL path never gets here with
+ // grabs as it rather invokes sync/render directly without going
+ // through syncAndRender().
+ if (grabImage) {
+ Q_ASSERT(rhi && !gl && cd->swapchain);
+ *grabImage = QSGRhiSupport::instance()->grabAndBlockInCurrentFrame(rhi, cd->swapchain);
+ }
+
+ if (cd->swapchain) {
+ QRhi::EndFrameFlags flags = 0;
+ if (grabImage)
+ flags |= QRhi::SkipPresent;
+ QRhi::FrameOpResult frameResult = rhi->endFrame(cd->swapchain, flags);
+ if (frameResult != QRhi::FrameOpSuccess) {
+ if (frameResult == QRhi::FrameOpDeviceLost)
+ handleDeviceLoss();
+ else if (frameResult == QRhi::FrameOpError)
+ qWarning("Failed to end frame");
+ if (frameResult == QRhi::FrameOpDeviceLost || frameResult == QRhi::FrameOpSwapChainOutOfDate)
+ QCoreApplication::postEvent(window, new QEvent(QEvent::Type(QQuickWindowPrivate::FullUpdateRequest)));
+ }
+ } else {
+ if (!cd->customRenderStage || !cd->customRenderStage->swap())
+ gl->swapBuffers(window);
+ }
+
+ if (!grabImage)
+ d->fireFrameSwapped();
+
} else {
Q_QUICK_SG_PROFILE_SKIP(QQuickProfiler::SceneGraphRenderLoopFrame,
QQuickProfiler::SceneGraphRenderLoopSync, 1);
@@ -680,6 +873,8 @@ void QSGRenderThread::syncAndRender()
Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphRenderLoopFrame,
QQuickProfiler::SceneGraphRenderLoopSwap);
+
+ QSGRhiProfileConnection::instance()->send(rhi);
}
@@ -714,6 +909,57 @@ void QSGRenderThread::processEventsAndWaitForMore()
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "--- done processEventsAndWaitForMore()");
}
+void QSGRenderThread::ensureRhi()
+{
+ if (!rhi) {
+ QSGRhiSupport *rhiSupport = QSGRhiSupport::instance();
+ rhi = rhiSupport->createRhi(window, offscreenSurface);
+ if (rhi) {
+ rhiSampleCount = rhiSupport->chooseSampleCountForWindowWithRhi(window, rhi);
+ if (rhiSupport->isProfilingRequested())
+ QSGRhiProfileConnection::instance()->initialize(rhi); // ### this breaks down with multiple windows
+ } else {
+ qWarning("Failed to create QRhi on the render thread; scenegraph is not functional");
+ return;
+ }
+ }
+ if (!sgrc->rhi() && windowSize.width() > 0 && windowSize.height() > 0) {
+ rhi->makeThreadLocalNativeContextCurrent();
+ QSGDefaultRenderContext::InitParams rcParams;
+ rcParams.rhi = rhi;
+ rcParams.sampleCount = rhiSampleCount;
+ rcParams.openGLContext = nullptr;
+ rcParams.initialSurfacePixelSize = windowSize * qreal(dpr);
+ rcParams.maybeSurface = window;
+ sgrc->initialize(&rcParams);
+ }
+ QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window);
+ if (rhi && !cd->swapchain) {
+ cd->rhi = rhi;
+ QRhiSwapChain::Flags flags = QRhiSwapChain::UsedAsTransferSource; // may be used in a grab
+ // QQ is always premul alpha. Decide based on alphaBufferSize in
+ // requestedFormat(). (the platform plugin can override format() but
+ // what matters here is what the application wanted, hence using the
+ // requested one)
+ const bool alpha = window->requestedFormat().alphaBufferSize() > 0;
+ if (alpha)
+ flags |= QRhiSwapChain::SurfaceHasPreMulAlpha;
+ cd->swapchain = rhi->newSwapChain();
+ cd->depthStencilForSwapchain = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
+ QSize(),
+ rhiSampleCount,
+ QRhiRenderBuffer::UsedWithSwapChainOnly);
+ cd->swapchain->setWindow(window);
+ cd->swapchain->setDepthStencil(cd->depthStencilForSwapchain);
+ qCDebug(QSG_LOG_INFO, "MSAA sample count for the swapchain is %d. Alpha channel requested = %s.",
+ rhiSampleCount, alpha ? "yes" : "no");
+ cd->swapchain->setSampleCount(rhiSampleCount);
+ cd->swapchain->setFlags(flags);
+ cd->rpDescForSwapchain = cd->swapchain->newCompatibleRenderPassDescriptor();
+ cd->swapchain->setRenderPassDescriptor(cd->rpDescForSwapchain);
+ }
+}
+
void QSGRenderThread::run()
{
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "run()");
@@ -723,11 +969,26 @@ void QSGRenderThread::run()
QQuickProfiler::registerAnimationCallback();
while (active) {
+#ifdef Q_OS_DARWIN
+ QMacAutoReleasePool frameReleasePool;
+#endif
if (window) {
- if (!sgrc->openglContext() && windowSize.width() > 0 && windowSize.height() > 0 && gl->makeCurrent(window))
- sgrc->initialize(gl);
- syncAndRender();
+ if (enableRhi) {
+ ensureRhi();
+ if (rhi)
+ syncAndRender();
+ } else {
+ if (!sgrc->openglContext() && windowSize.width() > 0 && windowSize.height() > 0 && gl->makeCurrent(window)) {
+ QSGDefaultRenderContext::InitParams rcParams;
+ rcParams.sampleCount = qMax(1, gl->format().samples());
+ rcParams.openGLContext = gl;
+ rcParams.initialSurfacePixelSize = windowSize * qreal(dpr);
+ rcParams.maybeSurface = window;
+ sgrc->initialize(&rcParams);
+ }
+ syncAndRender();
+ }
}
processEvents();
@@ -741,7 +1002,7 @@ void QSGRenderThread::run()
}
}
- Q_ASSERT_X(!gl, "QSGRenderThread::run()", "The OpenGL context should be cleaned up before exiting the render thread...");
+ Q_ASSERT_X(!gl && !rhi, "QSGRenderThread::run()", "The graphics context should be cleaned up before exiting the render thread...");
qCDebug(QSG_LOG_RENDERLOOP, QSG_RT_PAD, "run() completed");
@@ -911,12 +1172,48 @@ void QSGThreadedRenderLoop::windowDestroyed(QQuickWindow *window)
qCDebug(QSG_LOG_RENDERLOOP) << "done windowDestroyed()" << window;
}
+void QSGThreadedRenderLoop::releaseSwapchain(QQuickWindow *window)
+{
+ QQuickWindowPrivate *wd = QQuickWindowPrivate::get(window);
+ delete wd->rpDescForSwapchain;
+ wd->rpDescForSwapchain = nullptr;
+ delete wd->swapchain;
+ wd->swapchain = nullptr;
+ delete wd->depthStencilForSwapchain;
+ wd->depthStencilForSwapchain = nullptr;
+ wd->hasActiveSwapchain = wd->hasRenderableSwapchain = wd->swapchainJustBecameRenderable = false;
+}
void QSGThreadedRenderLoop::exposureChanged(QQuickWindow *window)
{
qCDebug(QSG_LOG_RENDERLOOP) << "exposureChanged()" << window;
+
+ // This is tricker than used to be. We want to detect having an empty
+ // surface size (which may be the case even when window->size() is
+ // non-empty, on some platforms with some graphics APIs!) as well as the
+ // case when the window just became "newly exposed" (e.g. after a
+ // minimize-restore on Windows, or when switching between fully obscured -
+ // not fully obscured on macOS)
+ QQuickWindowPrivate *wd = QQuickWindowPrivate::get(window);
+ if (!window->isExposed())
+ wd->hasRenderableSwapchain = false;
+
+ bool skipThisExpose = false;
+ if (window->isExposed() && wd->hasActiveSwapchain && wd->swapchain->surfacePixelSize().isEmpty()) {
+ wd->hasRenderableSwapchain = false;
+ skipThisExpose = true;
+ }
+
+ if (window->isExposed() && !wd->hasRenderableSwapchain && wd->hasActiveSwapchain
+ && !wd->swapchain->surfacePixelSize().isEmpty())
+ {
+ wd->hasRenderableSwapchain = true;
+ wd->swapchainJustBecameRenderable = true;
+ }
+
if (window->isExposed()) {
- handleExposure(window);
+ if (!skipThisExpose)
+ handleExposure(window);
} else {
Window *w = windowFor(m_windows, window);
if (w)
@@ -968,30 +1265,43 @@ void QSGThreadedRenderLoop::handleExposure(QQuickWindow *window)
// Start render thread if it is not running
if (!w->thread->isRunning()) {
-
qCDebug(QSG_LOG_RENDERLOOP, "- starting render thread");
- if (!w->thread->gl) {
- w->thread->gl = new QOpenGLContext();
- if (qt_gl_global_share_context())
- w->thread->gl->setShareContext(qt_gl_global_share_context());
- w->thread->gl->setFormat(w->window->requestedFormat());
- w->thread->gl->setScreen(w->window->screen());
- if (!w->thread->gl->create()) {
- const bool isEs = w->thread->gl->isOpenGLES();
- delete w->thread->gl;
- w->thread->gl = nullptr;
- handleContextCreationFailure(w->window, isEs);
- return;
+ w->thread->enableRhi = QSGRhiSupport::instance()->isRhiEnabled();
+ if (w->thread->enableRhi) {
+ if (!w->thread->rhi) {
+ QSGRhiSupport *rhiSupport = QSGRhiSupport::instance();
+ w->thread->offscreenSurface = rhiSupport->maybeCreateOffscreenSurface(window);
+ window->installEventFilter(this);
}
+ } else {
+ if (!w->thread->gl) {
+ w->thread->gl = new QOpenGLContext();
+ if (qt_gl_global_share_context())
+ w->thread->gl->setShareContext(qt_gl_global_share_context());
+ w->thread->gl->setFormat(w->window->requestedFormat());
+ w->thread->gl->setScreen(w->window->screen());
+ if (!w->thread->gl->create()) {
+ const bool isEs = w->thread->gl->isOpenGLES();
+ delete w->thread->gl;
+ w->thread->gl = nullptr;
+ handleContextCreationFailure(w->window, isEs);
+ return;
+ }
+
+ QQuickWindowPrivate::get(w->window)->fireOpenGLContextCreated(w->thread->gl);
- QQuickWindowPrivate::get(w->window)->fireOpenGLContextCreated(w->thread->gl);
+ w->thread->gl->moveToThread(w->thread);
+ qCDebug(QSG_LOG_RENDERLOOP, "- OpenGL context created");
- w->thread->gl->moveToThread(w->thread);
- qCDebug(QSG_LOG_RENDERLOOP, "- OpenGL context created");
+ w->thread->offscreenSurface = new QOffscreenSurface();
+ w->thread->offscreenSurface->setFormat(w->actualWindowFormat);
+ w->thread->offscreenSurface->create();
+ }
}
- QQuickAnimatorController *controller = QQuickWindowPrivate::get(w->window)->animationController;
+ QQuickAnimatorController *controller
+ = QQuickWindowPrivate::get(w->window)->animationController.get();
if (controller->thread() != w->thread)
controller->moveToThread(w->thread);
@@ -1033,6 +1343,30 @@ void QSGThreadedRenderLoop::handleObscurity(Window *w)
startOrStopAnimationTimer();
}
+bool QSGThreadedRenderLoop::eventFilter(QObject *watched, QEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::PlatformSurface:
+ // this is the proper time to tear down the swapchain (while the native window and surface are still around)
+ if (static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(watched);
+ if (window) {
+ Window *w = windowFor(m_windows, window);
+ if (w) {
+ w->thread->mutex.lock();
+ w->thread->postEvent(new WMReleaseSwapchainEvent(window));
+ w->thread->waitCondition.wait(&w->thread->mutex);
+ w->thread->mutex.unlock();
+ }
+ window->removeEventFilter(this);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return QObject::eventFilter(watched, event);
+}
void QSGThreadedRenderLoop::handleUpdateRequest(QQuickWindow *window)
{
@@ -1062,6 +1396,8 @@ void QSGThreadedRenderLoop::maybeUpdate(Window *w)
return;
QThread *current = QThread::currentThread();
+ if (current == w->thread && w->thread->rhi && w->thread->rhi->isDeviceLost())
+ return;
if (current != QCoreApplication::instance()->thread() && (current != w->thread || !m_lockedForSync)) {
qWarning() << "Updates can only be scheduled from GUI thread or from QQuickItem::updatePaintNode()";
return;
@@ -1125,23 +1461,14 @@ void QSGThreadedRenderLoop::releaseResources(Window *w, bool inDestructor)
QQuickWindow *window = w->window;
// The platform window might have been destroyed before
- // hide/release/windowDestroyed is called, so we need to have a
- // fallback surface to perform the cleanup of the scene graph
- // and the OpenGL resources.
- // QOffscreenSurface must be created on the GUI thread, so we
- // create it here and pass it on to QSGRenderThread::invalidateGL()
- QOffscreenSurface *fallback = nullptr;
- if (!window->handle()) {
- qCDebug(QSG_LOG_RENDERLOOP, "- using fallback surface");
- fallback = new QOffscreenSurface();
- fallback->setFormat(w->actualWindowFormat);
- fallback->create();
- }
+ // hide/release/windowDestroyed is called, so we may need to have a
+ // fallback surface to perform the cleanup of the scene graph and the
+ // OpenGL resources. QOffscreenSurface must be created on the GUI
+ // thread so that is done for us already.
qCDebug(QSG_LOG_RENDERLOOP, "- posting release request to render thread");
- w->thread->postEvent(new WMTryReleaseEvent(window, inDestructor, fallback));
+ w->thread->postEvent(new WMTryReleaseEvent(window, inDestructor, window->handle() == nullptr));
w->thread->waitCondition.wait(&w->thread->mutex);
- delete fallback;
// Avoid a shutdown race condition.
// If SG is invalidated and 'active' becomes false, the thread's run()
diff --git a/src/quick/scenegraph/qsgthreadedrenderloop_p.h b/src/quick/scenegraph/qsgthreadedrenderloop_p.h
index b8fae8e8da..e5e9fa8b48 100644
--- a/src/quick/scenegraph/qsgthreadedrenderloop_p.h
+++ b/src/quick/scenegraph/qsgthreadedrenderloop_p.h
@@ -121,7 +121,9 @@ private:
void handleExposure(QQuickWindow *w);
void handleObscurity(Window *w);
+ void releaseSwapchain(QQuickWindow *window);
+ bool eventFilter(QObject *watched, QEvent *event) override;
QSGContext *sg;
// Set of contexts that have been created but are now owned by
diff --git a/src/quick/scenegraph/qsgwindowsrenderloop.cpp b/src/quick/scenegraph/qsgwindowsrenderloop.cpp
index 95df700a15..5b48b86568 100644
--- a/src/quick/scenegraph/qsgwindowsrenderloop.cpp
+++ b/src/quick/scenegraph/qsgwindowsrenderloop.cpp
@@ -62,6 +62,10 @@
QT_BEGIN_NAMESPACE
+// Single-threaded render loop with a custom animation driver. Like a
+// combination of basic+threaded but still working on the main thread. Only
+// compatible with direct OpenGL, no RHI support here.
+
extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha);
#define RLDEBUG(x) qCDebug(QSG_LOG_RENDERLOOP, x)
@@ -188,8 +192,14 @@ void QSGWindowsRenderLoop::show(QQuickWindow *window)
RLDEBUG(" - making current");
bool current = m_gl->makeCurrent(window);
RLDEBUG(" - initializing SG");
- if (current)
- m_rc->initialize(m_gl);
+ if (current) {
+ QSGDefaultRenderContext::InitParams rcParams;
+ rcParams.sampleCount = qMax(1, m_gl->format().samples());
+ rcParams.openGLContext = m_gl;
+ rcParams.initialSurfacePixelSize = window->size() * window->effectiveDevicePixelRatio();
+ rcParams.maybeSurface = window;
+ m_rc->initialize(&rcParams);
+ }
}
WindowData data;
@@ -259,7 +269,7 @@ void QSGWindowsRenderLoop::windowDestroyed(QQuickWindow *window)
m_gl->doneCurrent();
}
- delete d->animationController;
+ d->animationController.reset();
}
bool QSGWindowsRenderLoop::anyoneShowing() const
@@ -440,10 +450,16 @@ void QSGWindowsRenderLoop::renderWindow(QQuickWindow *window)
if (!m_gl->isValid()) {
d->cleanupNodesOnShutdown();
m_rc->invalidate();
- if (m_gl->create() && m_gl->makeCurrent(window))
- m_rc->initialize(m_gl);
- else
+ if (m_gl->create() && m_gl->makeCurrent(window)) {
+ QSGDefaultRenderContext::InitParams rcParams;
+ rcParams.sampleCount = qMax(1, m_gl->format().samples());
+ rcParams.openGLContext = m_gl;
+ rcParams.initialSurfacePixelSize = window->size() * window->effectiveDevicePixelRatio();
+ rcParams.maybeSurface = window;
+ m_rc->initialize(&rcParams);
+ } else {
return;
+ }
}
}
diff --git a/src/quick/scenegraph/scenegraph.pri b/src/quick/scenegraph/scenegraph.pri
index ddd7fb7f4c..56d97226fb 100644
--- a/src/quick/scenegraph/scenegraph.pri
+++ b/src/quick/scenegraph/scenegraph.pri
@@ -4,7 +4,11 @@
HEADERS += \
$$PWD/coreapi/qsggeometry.h \
$$PWD/coreapi/qsgmaterial.h \
+ $$PWD/coreapi/qsgmaterialtype.h \
+ $$PWD/coreapi/qsgmaterialshader.h \
$$PWD/coreapi/qsgmaterialshader_p.h \
+ $$PWD/coreapi/qsgmaterialrhishader.h \
+ $$PWD/coreapi/qsgmaterialrhishader_p.h \
$$PWD/coreapi/qsgnode.h \
$$PWD/coreapi/qsgnode_p.h \
$$PWD/coreapi/qsgnodeupdater_p.h \
@@ -14,12 +18,17 @@ HEADERS += \
$$PWD/coreapi/qsgrendernode.h \
$$PWD/coreapi/qsgrendernode_p.h \
$$PWD/coreapi/qsgrendererinterface.h \
- $$PWD/coreapi/qsggeometry_p.h
+ $$PWD/coreapi/qsggeometry_p.h \
+ $$PWD/coreapi/qsgtexture.h \
+ $$PWD/coreapi/qsgtexture_p.h
SOURCES += \
$$PWD/coreapi/qsgabstractrenderer.cpp \
$$PWD/coreapi/qsggeometry.cpp \
$$PWD/coreapi/qsgmaterial.cpp \
+ $$PWD/coreapi/qsgmaterialshader.cpp \
+ $$PWD/coreapi/qsgmaterialrhishader.cpp \
+ $$PWD/coreapi/qsgtexture.cpp \
$$PWD/coreapi/qsgnode.cpp \
$$PWD/coreapi/qsgnodeupdater.cpp \
$$PWD/coreapi/qsgrenderer.cpp \
@@ -28,9 +37,13 @@ SOURCES += \
qtConfig(opengl(es1|es2)?) {
HEADERS += \
- $$PWD/coreapi/qsgbatchrenderer_p.h
+ $$PWD/coreapi/qsgbatchrenderer_p.h \
+ $$PWD/coreapi/qsgopenglvisualizer_p.h \
+ $$PWD/coreapi/qsgrhivisualizer_p.h
SOURCES += \
$$PWD/coreapi/qsgbatchrenderer.cpp \
+ $$PWD/coreapi/qsgopenglvisualizer.cpp \
+ $$PWD/coreapi/qsgrhivisualizer.cpp \
$$PWD/coreapi/qsgshaderrewriter.cpp
}
@@ -39,10 +52,10 @@ HEADERS += \
$$PWD/util/qsgareaallocator_p.h \
$$PWD/util/qsgengine.h \
$$PWD/util/qsgengine_p.h \
+ $$PWD/util/qsgplaintexture_p.h \
+ $$PWD/util/qsgrhinativetextureimporter_p.h \
$$PWD/util/qsgsimplerectnode.h \
$$PWD/util/qsgsimpletexturenode.h \
- $$PWD/util/qsgtexture.h \
- $$PWD/util/qsgtexture_p.h \
$$PWD/util/qsgtextureprovider.h \
$$PWD/util/qsgflatcolormaterial.h \
$$PWD/util/qsgsimplematerial.h \
@@ -56,9 +69,10 @@ HEADERS += \
SOURCES += \
$$PWD/util/qsgareaallocator.cpp \
$$PWD/util/qsgengine.cpp \
+ $$PWD/util/qsgplaintexture.cpp \
+ $$PWD/util/qsgrhinativetextureimporter.cpp \
$$PWD/util/qsgsimplerectnode.cpp \
$$PWD/util/qsgsimpletexturenode.cpp \
- $$PWD/util/qsgtexture.cpp \
$$PWD/util/qsgtextureprovider.cpp \
$$PWD/util/qsgflatcolormaterial.cpp \
$$PWD/util/qsgsimplematerial.cpp \
@@ -72,13 +86,27 @@ qtConfig(opengl(es1|es2)?) {
HEADERS += \
$$PWD/util/qsgdepthstencilbuffer_p.h \
$$PWD/util/qsgshadersourcebuilder_p.h \
- $$PWD/util/qsgatlastexture_p.h
+ $$PWD/util/qsgopenglatlastexture_p.h
SOURCES += \
$$PWD/util/qsgdepthstencilbuffer.cpp \
- $$PWD/util/qsgatlastexture.cpp \
+ $$PWD/util/qsgopenglatlastexture.cpp \
$$PWD/util/qsgshadersourcebuilder.cpp
-}
+ # rhi, still tied to OpenGL-enabled Qt builds for now
+ HEADERS += \
+ $$PWD/qsgrhitextureglyphcache_p.h \
+ $$PWD/util/qsgrhiatlastexture_p.h \
+ $$PWD/qsgrhilayer_p.h \
+ $$PWD/qsgrhishadereffectnode_p.h \
+ $$PWD/qsgrhidistancefieldglyphcache_p.h
+
+ SOURCES += \
+ $$PWD/qsgrhitextureglyphcache.cpp \
+ $$PWD/qsgrhilayer.cpp \
+ $$PWD/qsgrhishadereffectnode.cpp \
+ $$PWD/util/qsgrhiatlastexture.cpp \
+ $$PWD/qsgrhidistancefieldglyphcache.cpp
+}
# QML / Adaptations API
HEADERS += \
@@ -88,7 +116,8 @@ HEADERS += \
$$PWD/qsgbasicinternalrectanglenode_p.h \
$$PWD/qsgbasicinternalimagenode_p.h \
$$PWD/qsgbasicglyphnode_p.h \
- $$PWD/qsgrenderloop_p.h
+ $$PWD/qsgrenderloop_p.h \
+ $$PWD/qsgrhisupport_p.h
SOURCES += \
$$PWD/qsgadaptationlayer.cpp \
@@ -97,13 +126,14 @@ SOURCES += \
$$PWD/qsgbasicinternalrectanglenode.cpp \
$$PWD/qsgbasicinternalimagenode.cpp \
$$PWD/qsgbasicglyphnode.cpp \
- $$PWD/qsgrenderloop.cpp
+ $$PWD/qsgrenderloop.cpp \
+ $$PWD/qsgrhisupport.cpp
qtConfig(opengl(es1|es2)?) {
SOURCES += \
$$PWD/qsgdefaultglyphnode.cpp \
$$PWD/qsgdefaultglyphnode_p.cpp \
- $$PWD/qsgdefaultdistancefieldglyphcache.cpp \
+ $$PWD/qsgopengldistancefieldglyphcache.cpp \
$$PWD/qsgdistancefieldglyphnode.cpp \
$$PWD/qsgdistancefieldglyphnode_p.cpp \
$$PWD/qsgdefaultinternalimagenode.cpp \
@@ -114,11 +144,11 @@ qtConfig(opengl(es1|es2)?) {
$$PWD/util/qsgdefaultrectanglenode.cpp \
$$PWD/util/qsgdefaultimagenode.cpp \
$$PWD/util/qsgdefaultninepatchnode.cpp \
- $$PWD/qsgdefaultlayer.cpp \
+ $$PWD/qsgopengllayer.cpp \
$$PWD/qsgwindowsrenderloop.cpp
HEADERS += \
$$PWD/qsgdefaultglyphnode_p.h \
- $$PWD/qsgdefaultdistancefieldglyphcache_p.h \
+ $$PWD/qsgopengldistancefieldglyphcache_p.h \
$$PWD/qsgdistancefieldglyphnode_p.h \
$$PWD/qsgdistancefieldglyphnode_p_p.h \
$$PWD/qsgdefaultglyphnode_p_p.h \
@@ -130,7 +160,7 @@ qtConfig(opengl(es1|es2)?) {
$$PWD/util/qsgdefaultrectanglenode_p.h \
$$PWD/util/qsgdefaultimagenode_p.h \
$$PWD/util/qsgdefaultninepatchnode_p.h \
- $$PWD/qsgdefaultlayer_p.h \
+ $$PWD/qsgopengllayer_p.h \
$$PWD/qsgwindowsrenderloop_p.h
qtConfig(thread) {
diff --git a/src/quick/scenegraph/scenegraph.qrc b/src/quick/scenegraph/scenegraph.qrc
index 0687530be1..e409f07610 100644
--- a/src/quick/scenegraph/scenegraph.qrc
+++ b/src/quick/scenegraph/scenegraph.qrc
@@ -72,5 +72,57 @@
<file>shaders/sprite.vert</file>
<file>shaders/sprite_core.frag</file>
<file>shaders/sprite_core.vert</file>
+
+ <file>shaders_ng/vertexcolor.vert.qsb</file>
+ <file>shaders_ng/vertexcolor.frag.qsb</file>
+ <file>shaders_ng/flatcolor.vert.qsb</file>
+ <file>shaders_ng/flatcolor.frag.qsb</file>
+ <file>shaders_ng/smoothcolor.vert.qsb</file>
+ <file>shaders_ng/smoothcolor.frag.qsb</file>
+ <file>shaders_ng/stencilclip.vert.qsb</file>
+ <file>shaders_ng/stencilclip.frag.qsb</file>
+ <file>shaders_ng/texture.vert.qsb</file>
+ <file>shaders_ng/texture.frag.qsb</file>
+ <file>shaders_ng/opaquetexture.vert.qsb</file>
+ <file>shaders_ng/opaquetexture.frag.qsb</file>
+ <file>shaders_ng/smoothtexture.vert.qsb</file>
+ <file>shaders_ng/smoothtexture.frag.qsb</file>
+
+ <file>shaders_ng/textmask.vert.qsb</file>
+ <file>shaders_ng/textmask.frag.qsb</file>
+ <file>shaders_ng/8bittextmask.frag.qsb</file>
+ <file>shaders_ng/8bittextmask_a.frag.qsb</file>
+ <file>shaders_ng/24bittextmask.frag.qsb</file>
+ <file>shaders_ng/32bitcolortext.frag.qsb</file>
+ <file>shaders_ng/outlinedtext.vert.qsb</file>
+ <file>shaders_ng/outlinedtext.frag.qsb</file>
+ <file>shaders_ng/outlinedtext_a.frag.qsb</file>
+ <file>shaders_ng/styledtext.vert.qsb</file>
+ <file>shaders_ng/styledtext.frag.qsb</file>
+ <file>shaders_ng/styledtext_a.frag.qsb</file>
+
+ <file>shaders_ng/distancefieldtext.vert.qsb</file>
+ <file>shaders_ng/distancefieldtext.frag.qsb</file>
+ <file>shaders_ng/distancefieldtext_a.frag.qsb</file>
+ <file>shaders_ng/distancefieldshiftedtext.vert.qsb</file>
+ <file>shaders_ng/distancefieldshiftedtext.frag.qsb</file>
+ <file>shaders_ng/distancefieldshiftedtext_a.frag.qsb</file>
+ <file>shaders_ng/distancefieldoutlinetext.vert.qsb</file>
+ <file>shaders_ng/distancefieldoutlinetext.frag.qsb</file>
+ <file>shaders_ng/distancefieldoutlinetext_a.frag.qsb</file>
+ <file>shaders_ng/hiqsubpixeldistancefieldtext.vert.qsb</file>
+ <file>shaders_ng/hiqsubpixeldistancefieldtext.frag.qsb</file>
+ <file>shaders_ng/hiqsubpixeldistancefieldtext_a.frag.qsb</file>
+ <file>shaders_ng/loqsubpixeldistancefieldtext.vert.qsb</file>
+ <file>shaders_ng/loqsubpixeldistancefieldtext.frag.qsb</file>
+ <file>shaders_ng/loqsubpixeldistancefieldtext_a.frag.qsb</file>
+
+ <file>shaders_ng/shadereffect.vert.qsb</file>
+ <file>shaders_ng/shadereffect.frag.qsb</file>
+ <file>shaders_ng/sprite.vert.qsb</file>
+ <file>shaders_ng/sprite.frag.qsb</file>
+
+ <file>shaders_ng/visualization.vert.qsb</file>
+ <file>shaders_ng/visualization.frag.qsb</file>
</qresource>
</RCC>
diff --git a/src/quick/scenegraph/shaders_ng/24bittextmask.frag b/src/quick/scenegraph/shaders_ng/24bittextmask.frag
new file mode 100644
index 0000000000..bc3826a924
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/24bittextmask.frag
@@ -0,0 +1,19 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 color; // only alpha is used, but must be vec4 due to layout compat
+ vec2 textureScale;
+ float dpr;
+} ubuf;
+
+void main()
+{
+ vec4 glyph = texture(_qt_texture, sampleCoord);
+ fragColor = vec4(glyph.rgb * ubuf.color.a, glyph.a);
+}
diff --git a/src/quick/scenegraph/shaders_ng/24bittextmask.frag.qsb b/src/quick/scenegraph/shaders_ng/24bittextmask.frag.qsb
new file mode 100644
index 0000000000..b16da4d76a
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/24bittextmask.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/32bitcolortext.frag b/src/quick/scenegraph/shaders_ng/32bitcolortext.frag
new file mode 100644
index 0000000000..63e445f90b
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/32bitcolortext.frag
@@ -0,0 +1,18 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 color; // only alpha is used, but must be vec4 due to layout compat
+ vec2 textureScale;
+ float dpr;
+} ubuf;
+
+void main()
+{
+ fragColor = texture(_qt_texture, sampleCoord) * ubuf.color.a;
+}
diff --git a/src/quick/scenegraph/shaders_ng/32bitcolortext.frag.qsb b/src/quick/scenegraph/shaders_ng/32bitcolortext.frag.qsb
new file mode 100644
index 0000000000..1a12a35b49
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/32bitcolortext.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/8bittextmask.frag b/src/quick/scenegraph/shaders_ng/8bittextmask.frag
new file mode 100644
index 0000000000..6304e821ff
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/8bittextmask.frag
@@ -0,0 +1,18 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 color;
+ vec2 textureScale;
+ float dpr;
+} ubuf;
+
+void main()
+{
+ fragColor = ubuf.color * texture(_qt_texture, sampleCoord).r;
+}
diff --git a/src/quick/scenegraph/shaders_ng/8bittextmask.frag.qsb b/src/quick/scenegraph/shaders_ng/8bittextmask.frag.qsb
new file mode 100644
index 0000000000..2d0d23d813
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/8bittextmask.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/8bittextmask_a.frag b/src/quick/scenegraph/shaders_ng/8bittextmask_a.frag
new file mode 100644
index 0000000000..0d0fa1cd3a
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/8bittextmask_a.frag
@@ -0,0 +1,18 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 color;
+ vec2 textureScale;
+ float dpr;
+} ubuf;
+
+void main()
+{
+ fragColor = ubuf.color * texture(_qt_texture, sampleCoord).a; // take .a instead of .r
+}
diff --git a/src/quick/scenegraph/shaders_ng/8bittextmask_a.frag.qsb b/src/quick/scenegraph/shaders_ng/8bittextmask_a.frag.qsb
new file mode 100644
index 0000000000..65d9af4736
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/8bittextmask_a.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/compile.bat b/src/quick/scenegraph/shaders_ng/compile.bat
new file mode 100755
index 0000000000..a0c74c22c7
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/compile.bat
@@ -0,0 +1,86 @@
+:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+::
+:: Copyright (C) 2019 The Qt Company Ltd.
+:: Contact: https://www.qt.io/licensing/
+::
+:: This file is part of the QtQuick module of the Qt Toolkit.
+::
+:: $QT_BEGIN_LICENSE:LGPL$
+:: 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 Lesser General Public License Usage
+:: Alternatively, this file may be used under the terms of the GNU Lesser
+:: General Public License version 3 as published by the Free Software
+:: Foundation and appearing in the file LICENSE.LGPL3 included in the
+:: packaging of this file. Please review the following information to
+:: ensure the GNU Lesser General Public License version 3 requirements
+:: will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+::
+:: GNU General Public License Usage
+:: Alternatively, this file may be used under the terms of the GNU
+:: General Public License version 2.0 or (at your option) the GNU General
+:: Public license version 3 or any later version approved by the KDE Free
+:: Qt Foundation. The licenses are as published by the Free Software
+:: Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+:: 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-2.0.html and
+:: https://www.gnu.org/licenses/gpl-3.0.html.
+::
+:: $QT_END_LICENSE$
+::
+:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o vertexcolor.vert.qsb vertexcolor.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o vertexcolor.frag.qsb vertexcolor.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o flatcolor.vert.qsb flatcolor.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o flatcolor.frag.qsb flatcolor.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o smoothcolor.vert.qsb smoothcolor.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o smoothcolor.frag.qsb smoothcolor.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o stencilclip.vert.qsb stencilclip.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o stencilclip.frag.qsb stencilclip.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o texture.vert.qsb texture.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o texture.frag.qsb texture.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o opaquetexture.vert.qsb opaquetexture.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o opaquetexture.frag.qsb opaquetexture.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o smoothtexture.vert.qsb smoothtexture.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o smoothtexture.frag.qsb smoothtexture.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o textmask.vert.qsb textmask.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o textmask.frag.qsb textmask.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o 8bittextmask.frag.qsb 8bittextmask.frag
+qsb --glsl "150,120,100 es" -o 8bittextmask_a.frag.qsb 8bittextmask_a.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o 24bittextmask.frag.qsb 24bittextmask.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o 32bitcolortext.frag.qsb 32bitcolortext.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o outlinedtext.vert.qsb outlinedtext.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o outlinedtext.frag.qsb outlinedtext.frag
+qsb --glsl "150,120,100 es" -o outlinedtext_a.frag.qsb outlinedtext_a.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o styledtext.vert.qsb styledtext.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o styledtext.frag.qsb styledtext.frag
+qsb --glsl "150,120,100 es" -o styledtext_a.frag.qsb styledtext_a.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o distancefieldtext.vert.qsb distancefieldtext.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o distancefieldtext.frag.qsb distancefieldtext.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o distancefieldtext_a.frag.qsb distancefieldtext_a.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o distancefieldshiftedtext.vert.qsb distancefieldshiftedtext.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o distancefieldshiftedtext.frag.qsb distancefieldshiftedtext.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o distancefieldshiftedtext_a.frag.qsb distancefieldshiftedtext_a.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o distancefieldoutlinetext.vert.qsb distancefieldoutlinetext.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o distancefieldoutlinetext.frag.qsb distancefieldoutlinetext.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o distancefieldoutlinetext_a.frag.qsb distancefieldoutlinetext_a.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o hiqsubpixeldistancefieldtext.vert.qsb hiqsubpixeldistancefieldtext.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o hiqsubpixeldistancefieldtext.frag.qsb hiqsubpixeldistancefieldtext.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o hiqsubpixeldistancefieldtext_a.frag.qsb hiqsubpixeldistancefieldtext_a.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o loqsubpixeldistancefieldtext.vert.qsb loqsubpixeldistancefieldtext.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o loqsubpixeldistancefieldtext.frag.qsb loqsubpixeldistancefieldtext.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o loqsubpixeldistancefieldtext_a.frag.qsb loqsubpixeldistancefieldtext_a.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o shadereffect.vert.qsb shadereffect.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o shadereffect.frag.qsb shadereffect.frag
+qsb -b --glsl "150,120,100 es" --hlsl 50 --msl 12 -o sprite.vert.qsb sprite.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o sprite.frag.qsb sprite.frag
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o visualization.vert.qsb visualization.vert
+qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o visualization.frag.qsb visualization.frag
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag
new file mode 100644
index 0000000000..c8c1ac89dc
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag
@@ -0,0 +1,25 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ vec4 styleColor;
+ float outlineAlphaMax0;
+ float outlineAlphaMax1;
+} ubuf;
+
+void main()
+{
+ float d = texture(_qt_texture, sampleCoord).r;
+ fragColor = mix(ubuf.styleColor, ubuf.color, smoothstep(ubuf.alphaMin, ubuf.alphaMax, d))
+ * smoothstep(ubuf.outlineAlphaMax0, ubuf.outlineAlphaMax1, d);
+}
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag.qsb b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag.qsb
new file mode 100644
index 0000000000..5753794649
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.vert b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.vert
new file mode 100644
index 0000000000..8f0d618503
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.vert
@@ -0,0 +1,26 @@
+#version 440
+
+layout(location = 0) in vec4 vCoord;
+layout(location = 1) in vec2 tCoord;
+
+layout(location = 0) out vec2 sampleCoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ vec4 styleColor;
+ float outlineAlphaMax0;
+ float outlineAlphaMax1;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ sampleCoord = tCoord * ubuf.textureScale;
+ gl_Position = ubuf.matrix * vCoord;
+}
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.vert.qsb b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.vert.qsb
new file mode 100644
index 0000000000..6026960d68
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag
new file mode 100644
index 0000000000..70fb80852d
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag
@@ -0,0 +1,25 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ vec4 styleColor;
+ float outlineAlphaMax0;
+ float outlineAlphaMax1;
+} ubuf;
+
+void main()
+{
+ float d = texture(_qt_texture, sampleCoord).a;
+ fragColor = mix(ubuf.styleColor, ubuf.color, smoothstep(ubuf.alphaMin, ubuf.alphaMax, d))
+ * smoothstep(ubuf.outlineAlphaMax0, ubuf.outlineAlphaMax1, d);
+}
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag.qsb b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag.qsb
new file mode 100644
index 0000000000..451ccbac5b
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.frag b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.frag
new file mode 100644
index 0000000000..aa3390094b
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.frag
@@ -0,0 +1,27 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 1) in vec2 shiftedSampleCoord;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ vec4 styleColor;
+ vec2 shift;
+} ubuf;
+
+void main()
+{
+ float a = smoothstep(ubuf.alphaMin, ubuf.alphaMax, texture(_qt_texture, sampleCoord).r);
+ vec4 shifted = ubuf.styleColor * smoothstep(ubuf.alphaMin, ubuf.alphaMax,
+ texture(_qt_texture, shiftedSampleCoord).r);
+ fragColor = mix(shifted, ubuf.color, a);
+}
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.frag.qsb b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.frag.qsb
new file mode 100644
index 0000000000..41ebc12abf
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.vert b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.vert
new file mode 100644
index 0000000000..f3a7671435
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.vert
@@ -0,0 +1,27 @@
+#version 440
+
+layout(location = 0) in vec4 vCoord;
+layout(location = 1) in vec2 tCoord;
+
+layout(location = 0) out vec2 sampleCoord;
+layout(location = 1) out vec2 shiftedSampleCoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ vec4 styleColor;
+ vec2 shift;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ sampleCoord = tCoord * ubuf.textureScale;
+ shiftedSampleCoord = (tCoord - ubuf.shift) * ubuf.textureScale;
+ gl_Position = ubuf.matrix * vCoord;
+}
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.vert.qsb b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.vert.qsb
new file mode 100644
index 0000000000..0c37ccb6ed
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext_a.frag b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext_a.frag
new file mode 100644
index 0000000000..ab3a5f63ff
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext_a.frag
@@ -0,0 +1,27 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 1) in vec2 shiftedSampleCoord;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ vec4 styleColor;
+ vec2 shift;
+} ubuf;
+
+void main()
+{
+ float a = smoothstep(ubuf.alphaMin, ubuf.alphaMax, texture(_qt_texture, sampleCoord).a);
+ vec4 shifted = ubuf.styleColor * smoothstep(ubuf.alphaMin, ubuf.alphaMax,
+ texture(_qt_texture, shiftedSampleCoord).a);
+ fragColor = mix(shifted, ubuf.color, a);
+}
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext_a.frag.qsb b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext_a.frag.qsb
new file mode 100644
index 0000000000..b92235eec3
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldshiftedtext_a.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldtext.frag b/src/quick/scenegraph/shaders_ng/distancefieldtext.frag
new file mode 100644
index 0000000000..d594207567
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldtext.frag
@@ -0,0 +1,20 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+} ubuf;
+
+void main()
+{
+ fragColor = ubuf.color * smoothstep(ubuf.alphaMin, ubuf.alphaMax,
+ texture(_qt_texture, sampleCoord).r);
+}
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldtext.frag.qsb b/src/quick/scenegraph/shaders_ng/distancefieldtext.frag.qsb
new file mode 100644
index 0000000000..28ba15e3de
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldtext.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldtext.vert b/src/quick/scenegraph/shaders_ng/distancefieldtext.vert
new file mode 100644
index 0000000000..d56ddddd24
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldtext.vert
@@ -0,0 +1,22 @@
+#version 440
+
+layout(location = 0) in vec4 vCoord;
+layout(location = 1) in vec2 tCoord;
+
+layout(location = 0) out vec2 sampleCoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ sampleCoord = tCoord * ubuf.textureScale;
+ gl_Position = ubuf.matrix * vCoord;
+}
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldtext.vert.qsb b/src/quick/scenegraph/shaders_ng/distancefieldtext.vert.qsb
new file mode 100644
index 0000000000..2877ab92db
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldtext.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldtext_a.frag b/src/quick/scenegraph/shaders_ng/distancefieldtext_a.frag
new file mode 100644
index 0000000000..bb807d86d8
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldtext_a.frag
@@ -0,0 +1,20 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+} ubuf;
+
+void main()
+{
+ fragColor = ubuf.color * smoothstep(ubuf.alphaMin, ubuf.alphaMax,
+ texture(_qt_texture, sampleCoord).a);
+}
diff --git a/src/quick/scenegraph/shaders_ng/distancefieldtext_a.frag.qsb b/src/quick/scenegraph/shaders_ng/distancefieldtext_a.frag.qsb
new file mode 100644
index 0000000000..2e6085aa39
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/distancefieldtext_a.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/flatcolor.frag b/src/quick/scenegraph/shaders_ng/flatcolor.frag
new file mode 100644
index 0000000000..3a677b7c93
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/flatcolor.frag
@@ -0,0 +1,13 @@
+#version 440
+
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 color;
+} ubuf;
+
+void main()
+{
+ fragColor = ubuf.color;
+}
diff --git a/src/quick/scenegraph/shaders_ng/flatcolor.frag.qsb b/src/quick/scenegraph/shaders_ng/flatcolor.frag.qsb
new file mode 100644
index 0000000000..a528c667fd
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/flatcolor.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/flatcolor.vert b/src/quick/scenegraph/shaders_ng/flatcolor.vert
new file mode 100644
index 0000000000..b5dfd32197
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/flatcolor.vert
@@ -0,0 +1,15 @@
+#version 440
+
+layout(location = 0) in vec4 vertexCoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 color;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ gl_Position = ubuf.matrix * vertexCoord;
+}
diff --git a/src/quick/scenegraph/shaders_ng/flatcolor.vert.qsb b/src/quick/scenegraph/shaders_ng/flatcolor.vert.qsb
new file mode 100644
index 0000000000..e83de529e6
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/flatcolor.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.frag b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.frag
new file mode 100644
index 0000000000..723227a04d
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.frag
@@ -0,0 +1,40 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 1) in vec3 sampleFarLeft;
+layout(location = 2) in vec3 sampleNearLeft;
+layout(location = 3) in vec3 sampleNearRight;
+layout(location = 4) in vec3 sampleFarRight;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ float fontScale;
+ vec4 vecDelta;
+} ubuf;
+
+void main()
+{
+ vec4 n;
+ n.x = textureProj(_qt_texture, sampleFarLeft).r;
+ n.y = textureProj(_qt_texture, sampleNearLeft).r;
+ float c = texture(_qt_texture, sampleCoord).r;
+ n.z = textureProj(_qt_texture, sampleNearRight).r;
+ n.w = textureProj(_qt_texture, sampleFarRight).r;
+
+ vec2 d = min(abs(n.yw - n.xz) * 2., 0.67);
+ vec2 lo = mix(vec2(ubuf.alphaMin), vec2(0.5), d);
+ vec2 hi = mix(vec2(ubuf.alphaMax), vec2(0.5), d);
+ n = smoothstep(lo.xxyy, hi.xxyy, n);
+ c = smoothstep(lo.x + lo.y, hi.x + hi.y, 2. * c);
+
+ fragColor = vec4(0.333 * (n.xyz + n.yzw + c), c) * ubuf.color.w;
+}
diff --git a/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.frag.qsb b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.frag.qsb
new file mode 100644
index 0000000000..81c51321bb
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.vert b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.vert
new file mode 100644
index 0000000000..9c7281c31c
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.vert
@@ -0,0 +1,44 @@
+#version 440
+
+layout(location = 0) in vec4 vCoord;
+layout(location = 1) in vec2 tCoord;
+
+layout(location = 0) out vec2 sampleCoord;
+layout(location = 1) out vec3 sampleFarLeft;
+layout(location = 2) out vec3 sampleNearLeft;
+layout(location = 3) out vec3 sampleNearRight;
+layout(location = 4) out vec3 sampleFarRight;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ float fontScale;
+ vec4 vecDelta;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ sampleCoord = tCoord * ubuf.textureScale;
+ gl_Position = ubuf.matrix * vCoord;
+
+ // Calculate neighbor pixel position in item space.
+ vec3 wDelta = gl_Position.w * ubuf.vecDelta.xyw;
+ vec3 farLeft = vCoord.xyw - 0.667 * wDelta;
+ vec3 nearLeft = vCoord.xyw - 0.333 * wDelta;
+ vec3 nearRight = vCoord.xyw + 0.333 * wDelta;
+ vec3 farRight = vCoord.xyw + 0.667 * wDelta;
+
+ // Calculate neighbor texture coordinate.
+ vec2 scale = ubuf.textureScale / ubuf.fontScale;
+ vec2 base = sampleCoord - scale * vCoord.xy;
+ sampleFarLeft = vec3(base * farLeft.z + scale * farLeft.xy, farLeft.z);
+ sampleNearLeft = vec3(base * nearLeft.z + scale * nearLeft.xy, nearLeft.z);
+ sampleNearRight = vec3(base * nearRight.z + scale * nearRight.xy, nearRight.z);
+ sampleFarRight = vec3(base * farRight.z + scale * farRight.xy, farRight.z);
+}
diff --git a/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.vert.qsb b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.vert.qsb
new file mode 100644
index 0000000000..6bf01658a1
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext_a.frag b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext_a.frag
new file mode 100644
index 0000000000..a9d56f6380
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext_a.frag
@@ -0,0 +1,40 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 1) in vec3 sampleFarLeft;
+layout(location = 2) in vec3 sampleNearLeft;
+layout(location = 3) in vec3 sampleNearRight;
+layout(location = 4) in vec3 sampleFarRight;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ float fontScale;
+ vec4 vecDelta;
+} ubuf;
+
+void main()
+{
+ vec4 n;
+ n.x = textureProj(_qt_texture, sampleFarLeft).a;
+ n.y = textureProj(_qt_texture, sampleNearLeft).a;
+ float c = texture(_qt_texture, sampleCoord).a;
+ n.z = textureProj(_qt_texture, sampleNearRight).a;
+ n.w = textureProj(_qt_texture, sampleFarRight).a;
+
+ vec2 d = min(abs(n.yw - n.xz) * 2., 0.67);
+ vec2 lo = mix(vec2(ubuf.alphaMin), vec2(0.5), d);
+ vec2 hi = mix(vec2(ubuf.alphaMax), vec2(0.5), d);
+ n = smoothstep(lo.xxyy, hi.xxyy, n);
+ c = smoothstep(lo.x + lo.y, hi.x + hi.y, 2. * c);
+
+ fragColor = vec4(0.333 * (n.xyz + n.yzw + c), c) * ubuf.color.w;
+}
diff --git a/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext_a.frag.qsb b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext_a.frag.qsb
new file mode 100644
index 0000000000..4a9ac900a6
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext_a.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.frag b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.frag
new file mode 100644
index 0000000000..08b2ce5187
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.frag
@@ -0,0 +1,29 @@
+#version 440
+
+layout(location = 0) in vec3 sampleNearLeft;
+layout(location = 1) in vec3 sampleNearRight;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ float fontScale;
+ vec4 vecDelta;
+} ubuf;
+
+void main()
+{
+ vec2 n;
+ n.x = textureProj(_qt_texture, sampleNearLeft).r;
+ n.y = textureProj(_qt_texture, sampleNearRight).r;
+ n = smoothstep(ubuf.alphaMin, ubuf.alphaMax, n);
+ float c = 0.5 * (n.x + n.y);
+ fragColor = vec4(n.x, c, n.y, c) * ubuf.color.w;
+}
diff --git a/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.frag.qsb b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.frag.qsb
new file mode 100644
index 0000000000..76c2459edf
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.vert b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.vert
new file mode 100644
index 0000000000..187c384959
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.vert
@@ -0,0 +1,37 @@
+#version 440
+
+layout(location = 0) in vec4 vCoord;
+layout(location = 1) in vec2 tCoord;
+
+layout(location = 0) out vec3 sampleNearLeft;
+layout(location = 1) out vec3 sampleNearRight;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ float fontScale;
+ vec4 vecDelta;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ vec2 sampleCoord = tCoord * ubuf.textureScale;
+ gl_Position = ubuf.matrix * vCoord;
+
+ // Calculate neighbor pixel position in item space.
+ vec3 wDelta = gl_Position.w * ubuf.vecDelta.xyw;
+ vec3 nearLeft = vCoord.xyw - 0.25 * wDelta;
+ vec3 nearRight = vCoord.xyw + 0.25 * wDelta;
+
+ // Calculate neighbor texture coordinate.
+ vec2 scale = ubuf.textureScale / ubuf.fontScale;
+ vec2 base = sampleCoord - scale * vCoord.xy;
+ sampleNearLeft = vec3(base * nearLeft.z + scale * nearLeft.xy, nearLeft.z);
+ sampleNearRight = vec3(base * nearRight.z + scale * nearRight.xy, nearRight.z);
+}
diff --git a/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.vert.qsb b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.vert.qsb
new file mode 100644
index 0000000000..7bfa7ccd4a
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext_a.frag b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext_a.frag
new file mode 100644
index 0000000000..ef9407491b
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext_a.frag
@@ -0,0 +1,29 @@
+#version 440
+
+layout(location = 0) in vec3 sampleNearLeft;
+layout(location = 1) in vec3 sampleNearRight;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 textureScale;
+ vec4 color;
+ float alphaMin;
+ float alphaMax;
+ // up to this point it must match distancefieldtext
+ float fontScale;
+ vec4 vecDelta;
+} ubuf;
+
+void main()
+{
+ vec2 n;
+ n.x = textureProj(_qt_texture, sampleNearLeft).a;
+ n.y = textureProj(_qt_texture, sampleNearRight).a;
+ n = smoothstep(ubuf.alphaMin, ubuf.alphaMax, n);
+ float c = 0.5 * (n.x + n.y);
+ fragColor = vec4(n.x, c, n.y, c) * ubuf.color.w;
+}
diff --git a/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext_a.frag.qsb b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext_a.frag.qsb
new file mode 100644
index 0000000000..8f8304fb49
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/loqsubpixeldistancefieldtext_a.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/opaquetexture.frag b/src/quick/scenegraph/shaders_ng/opaquetexture.frag
new file mode 100644
index 0000000000..2cd2175f87
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/opaquetexture.frag
@@ -0,0 +1,11 @@
+#version 440
+
+layout(location = 0) in vec2 qt_TexCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D qt_Texture;
+
+void main()
+{
+ fragColor = texture(qt_Texture, qt_TexCoord);
+}
diff --git a/src/quick/scenegraph/shaders_ng/opaquetexture.frag.qsb b/src/quick/scenegraph/shaders_ng/opaquetexture.frag.qsb
new file mode 100644
index 0000000000..0b4554568b
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/opaquetexture.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/opaquetexture.vert b/src/quick/scenegraph/shaders_ng/opaquetexture.vert
new file mode 100644
index 0000000000..5b52a59004
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/opaquetexture.vert
@@ -0,0 +1,18 @@
+#version 440
+
+layout(location = 0) in vec4 qt_VertexPosition;
+layout(location = 1) in vec2 qt_VertexTexCoord;
+
+layout(location = 0) out vec2 qt_TexCoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 qt_Matrix;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ qt_TexCoord = qt_VertexTexCoord;
+ gl_Position = ubuf.qt_Matrix * qt_VertexPosition;
+}
diff --git a/src/quick/scenegraph/shaders_ng/opaquetexture.vert.qsb b/src/quick/scenegraph/shaders_ng/opaquetexture.vert.qsb
new file mode 100644
index 0000000000..2872af0200
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/opaquetexture.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/outlinedtext.frag b/src/quick/scenegraph/shaders_ng/outlinedtext.frag
new file mode 100644
index 0000000000..0023ed5467
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/outlinedtext.frag
@@ -0,0 +1,33 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 1) in vec2 sCoordUp;
+layout(location = 2) in vec2 sCoordDown;
+layout(location = 3) in vec2 sCoordLeft;
+layout(location = 4) in vec2 sCoordRight;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ // must match styledtext
+ mat4 matrix;
+ vec4 color;
+ vec2 textureScale;
+ float dpr;
+ vec4 styleColor;
+ vec2 shift;
+} ubuf;
+
+void main()
+{
+ float glyph = texture(_qt_texture, sampleCoord).r;
+ float outline = clamp(clamp(texture(_qt_texture, sCoordUp).r +
+ texture(_qt_texture, sCoordDown).r +
+ texture(_qt_texture, sCoordLeft).r +
+ texture(_qt_texture, sCoordRight).r,
+ 0.0, 1.0) - glyph,
+ 0.0, 1.0);
+ fragColor = outline * ubuf.styleColor + glyph * ubuf.color;
+}
diff --git a/src/quick/scenegraph/shaders_ng/outlinedtext.frag.qsb b/src/quick/scenegraph/shaders_ng/outlinedtext.frag.qsb
new file mode 100644
index 0000000000..5ab92fecca
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/outlinedtext.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/outlinedtext.vert b/src/quick/scenegraph/shaders_ng/outlinedtext.vert
new file mode 100644
index 0000000000..c683a4273c
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/outlinedtext.vert
@@ -0,0 +1,32 @@
+#version 440
+
+layout(location = 0) in vec4 vCoord;
+layout(location = 1) in vec2 tCoord;
+
+layout(location = 0) out vec2 sampleCoord;
+layout(location = 1) out vec2 sCoordUp;
+layout(location = 2) out vec2 sCoordDown;
+layout(location = 3) out vec2 sCoordLeft;
+layout(location = 4) out vec2 sCoordRight;
+
+layout(std140, binding = 0) uniform buf {
+ // must match styledtext
+ mat4 matrix;
+ vec4 color;
+ vec2 textureScale;
+ float dpr;
+ vec4 styleColor;
+ vec2 shift;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ sampleCoord = tCoord * ubuf.textureScale;
+ sCoordUp = (tCoord - vec2(0.0, -1.0)) * ubuf.textureScale;
+ sCoordDown = (tCoord - vec2(0.0, 1.0)) * ubuf.textureScale;
+ sCoordLeft = (tCoord - vec2(-1.0, 0.0)) * ubuf.textureScale;
+ sCoordRight = (tCoord - vec2(1.0, 0.0)) * ubuf.textureScale;
+ gl_Position = ubuf.matrix * vCoord;
+}
diff --git a/src/quick/scenegraph/shaders_ng/outlinedtext.vert.qsb b/src/quick/scenegraph/shaders_ng/outlinedtext.vert.qsb
new file mode 100644
index 0000000000..6aee048faa
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/outlinedtext.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag b/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag
new file mode 100644
index 0000000000..9a3d8cf5ed
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag
@@ -0,0 +1,33 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 1) in vec2 sCoordUp;
+layout(location = 2) in vec2 sCoordDown;
+layout(location = 3) in vec2 sCoordLeft;
+layout(location = 4) in vec2 sCoordRight;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ // must match styledtext
+ mat4 matrix;
+ vec4 color;
+ vec2 textureScale;
+ float dpr;
+ vec4 styleColor;
+ vec2 shift;
+} ubuf;
+
+void main()
+{
+ float glyph = texture(_qt_texture, sampleCoord).a; // take .a instead of .r
+ float outline = clamp(clamp(texture(_qt_texture, sCoordUp).a +
+ texture(_qt_texture, sCoordDown).a +
+ texture(_qt_texture, sCoordLeft).a +
+ texture(_qt_texture, sCoordRight).a,
+ 0.0, 1.0) - glyph,
+ 0.0, 1.0);
+ fragColor = outline * ubuf.styleColor + glyph * ubuf.color;
+}
diff --git a/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag.qsb b/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag.qsb
new file mode 100644
index 0000000000..6e6b1ab6c2
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/outlinedtext_a.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/shadereffect.frag b/src/quick/scenegraph/shaders_ng/shadereffect.frag
new file mode 100644
index 0000000000..bde493f6ce
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/shadereffect.frag
@@ -0,0 +1,16 @@
+#version 440
+
+layout(location = 0) in vec2 qt_TexCoord0;
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform qt_buf {
+ mat4 qt_Matrix;
+ float qt_Opacity;
+} qt_ubuf;
+
+layout(binding = 1) uniform sampler2D source;
+
+void main()
+{
+ fragColor = texture(source, qt_TexCoord0) * qt_ubuf.qt_Opacity;
+}
diff --git a/src/quick/scenegraph/shaders_ng/shadereffect.frag.qsb b/src/quick/scenegraph/shaders_ng/shadereffect.frag.qsb
new file mode 100644
index 0000000000..4b08ee2ce4
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/shadereffect.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/shadereffect.vert b/src/quick/scenegraph/shaders_ng/shadereffect.vert
new file mode 100644
index 0000000000..ae65059f19
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/shadereffect.vert
@@ -0,0 +1,19 @@
+#version 440
+
+layout(location = 0) in vec4 qt_Vertex;
+layout(location = 1) in vec2 qt_MultiTexCoord0;
+
+layout(location = 0) out vec2 qt_TexCoord0;
+
+layout(std140, binding = 0) uniform qt_buf {
+ mat4 qt_Matrix;
+ float qt_Opacity;
+} qt_ubuf; // must use a name that does not clash with custom code when no uniform blocks
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ qt_TexCoord0 = qt_MultiTexCoord0;
+ gl_Position = qt_ubuf.qt_Matrix * qt_Vertex;
+}
diff --git a/src/quick/scenegraph/shaders_ng/shadereffect.vert.qsb b/src/quick/scenegraph/shaders_ng/shadereffect.vert.qsb
new file mode 100644
index 0000000000..4a8c646a21
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/shadereffect.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/smoothcolor.frag b/src/quick/scenegraph/shaders_ng/smoothcolor.frag
new file mode 100644
index 0000000000..ede283be0c
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/smoothcolor.frag
@@ -0,0 +1,9 @@
+#version 440
+
+layout(location = 0) in vec4 color;
+layout(location = 0) out vec4 fragColor;
+
+void main()
+{
+ fragColor = color;
+}
diff --git a/src/quick/scenegraph/shaders_ng/smoothcolor.frag.qsb b/src/quick/scenegraph/shaders_ng/smoothcolor.frag.qsb
new file mode 100644
index 0000000000..f99cdf1176
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/smoothcolor.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/smoothcolor.vert b/src/quick/scenegraph/shaders_ng/smoothcolor.vert
new file mode 100644
index 0000000000..03a3ff8975
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/smoothcolor.vert
@@ -0,0 +1,51 @@
+#version 440
+
+layout(location = 0) in vec4 vertex;
+layout(location = 1) in vec4 vertexColor;
+layout(location = 2) in vec4 vertexOffset;
+
+layout(location = 0) out vec4 color;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec2 pixelSize;
+ float opacity;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ vec4 pos = ubuf.matrix * vertex;
+ gl_Position = pos;
+
+ if (vertexOffset.x != 0.) {
+ vec4 delta = ubuf.matrix[0] * vertexOffset.x;
+ vec2 dir = delta.xy * pos.w - pos.xy * delta.w;
+ vec2 ndir = .5 * ubuf.pixelSize * normalize(dir / ubuf.pixelSize);
+ dir -= ndir * delta.w * pos.w;
+ float numerator = dot(dir, ndir * pos.w * pos.w);
+ float scale = 0.0;
+ if (numerator < 0.0)
+ scale = 1.0;
+ else
+ scale = min(1.0, numerator / dot(dir, dir));
+ gl_Position += scale * delta;
+ }
+
+ if (vertexOffset.y != 0.) {
+ vec4 delta = ubuf.matrix[1] * vertexOffset.y;
+ vec2 dir = delta.xy * pos.w - pos.xy * delta.w;
+ vec2 ndir = .5 * ubuf.pixelSize * normalize(dir / ubuf.pixelSize);
+ dir -= ndir * delta.w * pos.w;
+ float numerator = dot(dir, ndir * pos.w * pos.w);
+ float scale = 0.0;
+ if (numerator < 0.0)
+ scale = 1.0;
+ else
+ scale = min(1.0, numerator / dot(dir, dir));
+ gl_Position += scale * delta;
+ }
+
+ color = vertexColor * ubuf.opacity;
+}
diff --git a/src/quick/scenegraph/shaders_ng/smoothcolor.vert.qsb b/src/quick/scenegraph/shaders_ng/smoothcolor.vert.qsb
new file mode 100644
index 0000000000..59c4104a2c
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/smoothcolor.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/smoothtexture.frag b/src/quick/scenegraph/shaders_ng/smoothtexture.frag
new file mode 100644
index 0000000000..b06764ad95
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/smoothtexture.frag
@@ -0,0 +1,13 @@
+#version 440
+
+layout(location = 0) in vec2 texCoord;
+layout(location = 1) in float vertexOpacity;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D qt_Texture;
+
+void main()
+{
+ fragColor = texture(qt_Texture, texCoord) * vertexOpacity;
+}
diff --git a/src/quick/scenegraph/shaders_ng/smoothtexture.frag.qsb b/src/quick/scenegraph/shaders_ng/smoothtexture.frag.qsb
new file mode 100644
index 0000000000..ffaecbb56c
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/smoothtexture.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/smoothtexture.vert b/src/quick/scenegraph/shaders_ng/smoothtexture.vert
new file mode 100644
index 0000000000..965c837852
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/smoothtexture.vert
@@ -0,0 +1,61 @@
+#version 440
+
+layout(location = 0) in vec4 vertex;
+layout(location = 1) in vec2 multiTexCoord;
+layout(location = 2) in vec2 vertexOffset;
+layout(location = 3) in vec2 texCoordOffset;
+
+layout(location = 0) out vec2 texCoord;
+layout(location = 1) out float vertexOpacity;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 qt_Matrix;
+ float opacity;
+ vec2 pixelSize;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ vec4 pos = ubuf.qt_Matrix * vertex;
+ gl_Position = pos;
+ texCoord = multiTexCoord;
+
+ if (vertexOffset.x != 0.) {
+ vec4 delta = ubuf.qt_Matrix[0] * vertexOffset.x;
+ vec2 dir = delta.xy * pos.w - pos.xy * delta.w;
+ vec2 ndir = .5 * ubuf.pixelSize * normalize(dir / ubuf.pixelSize);
+ dir -= ndir * delta.w * pos.w;
+ float numerator = dot(dir, ndir * pos.w * pos.w);
+ float scale = 0.0;
+ if (numerator < 0.0)
+ scale = 1.0;
+ else
+ scale = min(1.0, numerator / dot(dir, dir));
+ gl_Position += scale * delta;
+ texCoord.x += scale * texCoordOffset.x;
+ }
+
+ if (vertexOffset.y != 0.) {
+ vec4 delta = ubuf.qt_Matrix[1] * vertexOffset.y;
+ vec2 dir = delta.xy * pos.w - pos.xy * delta.w;
+ vec2 ndir = .5 * ubuf.pixelSize * normalize(dir / ubuf.pixelSize);
+ dir -= ndir * delta.w * pos.w;
+ float numerator = dot(dir, ndir * pos.w * pos.w);
+ float scale = 0.0;
+ if (numerator < 0.0)
+ scale = 1.0;
+ else
+ scale = min(1.0, numerator / dot(dir, dir));
+ gl_Position += scale * delta;
+ texCoord.y += scale * texCoordOffset.y;
+ }
+
+ bool onEdge = any(notEqual(vertexOffset, vec2(0.)));
+ bool outerEdge = all(equal(texCoordOffset, vec2(0.)));
+ if (onEdge && outerEdge)
+ vertexOpacity = 0.;
+ else
+ vertexOpacity = ubuf.opacity;
+}
diff --git a/src/quick/scenegraph/shaders_ng/smoothtexture.vert.qsb b/src/quick/scenegraph/shaders_ng/smoothtexture.vert.qsb
new file mode 100644
index 0000000000..b7715d4dd5
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/smoothtexture.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/sprite.frag b/src/quick/scenegraph/shaders_ng/sprite.frag
new file mode 100644
index 0000000000..338f5e957e
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/sprite.frag
@@ -0,0 +1,22 @@
+#version 440
+
+layout(location = 0) in vec4 fTexS;
+layout(location = 1) in float progress;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D tex;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 animPos;
+ vec3 animData;
+ float opacity;
+} ubuf;
+
+void main()
+{
+ fragColor = mix(texture(tex, fTexS.xy),
+ texture(tex, fTexS.zw),
+ progress) * ubuf.opacity;
+}
diff --git a/src/quick/scenegraph/shaders_ng/sprite.frag.qsb b/src/quick/scenegraph/shaders_ng/sprite.frag.qsb
new file mode 100644
index 0000000000..45d5bc14ee
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/sprite.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/sprite.vert b/src/quick/scenegraph/shaders_ng/sprite.vert
new file mode 100644
index 0000000000..b76e2b206f
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/sprite.vert
@@ -0,0 +1,29 @@
+#version 440
+
+layout(location = 0) in vec2 vPos;
+layout(location = 1) in vec2 vTex;
+
+layout(location = 0) out vec4 fTexS;
+layout(location = 1) out float progress;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 animPos; // x,y, x,y (two frames for interpolation)
+ vec3 animData; // w,h(premultiplied of anim), interpolation progress
+ float opacity;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ progress = ubuf.animData.z;
+
+ // Calculate frame location in texture
+ fTexS.xy = ubuf.animPos.xy + vTex.xy * ubuf.animData.xy;
+
+ // Next frame is also passed, for interpolation
+ fTexS.zw = ubuf.animPos.zw + vTex.xy * ubuf.animData.xy;
+
+ gl_Position = ubuf.matrix * vec4(vPos.x, vPos.y, 0, 1);
+}
diff --git a/src/quick/scenegraph/shaders_ng/sprite.vert.qsb b/src/quick/scenegraph/shaders_ng/sprite.vert.qsb
new file mode 100644
index 0000000000..b55f881734
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/sprite.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/stencilclip.frag b/src/quick/scenegraph/shaders_ng/stencilclip.frag
new file mode 100644
index 0000000000..3f6222389d
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/stencilclip.frag
@@ -0,0 +1,8 @@
+#version 440
+
+layout(location = 0) out vec4 fragColor;
+
+void main()
+{
+ fragColor = vec4(0.81, 0.83, 0.12, 1.0); // Trolltech green ftw!
+}
diff --git a/src/quick/scenegraph/shaders_ng/stencilclip.frag.qsb b/src/quick/scenegraph/shaders_ng/stencilclip.frag.qsb
new file mode 100644
index 0000000000..6ae7a51f7a
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/stencilclip.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/stencilclip.vert b/src/quick/scenegraph/shaders_ng/stencilclip.vert
new file mode 100644
index 0000000000..d8b491f775
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/stencilclip.vert
@@ -0,0 +1,14 @@
+#version 440
+
+layout(location = 0) in vec4 vCoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ gl_Position = ubuf.matrix * vCoord;
+}
diff --git a/src/quick/scenegraph/shaders_ng/stencilclip.vert.qsb b/src/quick/scenegraph/shaders_ng/stencilclip.vert.qsb
new file mode 100644
index 0000000000..ce2ed3c5b3
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/stencilclip.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/styledtext.frag b/src/quick/scenegraph/shaders_ng/styledtext.frag
new file mode 100644
index 0000000000..0b16396037
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/styledtext.frag
@@ -0,0 +1,26 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 1) in vec2 shiftedSampleCoord;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 color;
+ vec2 textureScale;
+ float dpr;
+ // the above must stay compatible with textmask/8bittextmask
+ vec4 styleColor;
+ vec2 shift;
+} ubuf;
+
+void main()
+{
+ float glyph = texture(_qt_texture, sampleCoord).r;
+ float style = clamp(texture(_qt_texture, shiftedSampleCoord).r - glyph,
+ 0.0, 1.0);
+ fragColor = style * ubuf.styleColor + glyph * ubuf.color;
+}
diff --git a/src/quick/scenegraph/shaders_ng/styledtext.frag.qsb b/src/quick/scenegraph/shaders_ng/styledtext.frag.qsb
new file mode 100644
index 0000000000..66ebc5f827
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/styledtext.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/styledtext.vert b/src/quick/scenegraph/shaders_ng/styledtext.vert
new file mode 100644
index 0000000000..10565107c6
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/styledtext.vert
@@ -0,0 +1,26 @@
+#version 440
+
+layout(location = 0) in vec4 vCoord;
+layout(location = 1) in vec2 tCoord;
+
+layout(location = 0) out vec2 sampleCoord;
+layout(location = 1) out vec2 shiftedSampleCoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 color;
+ vec2 textureScale;
+ float dpr;
+ // the above must stay compatible with textmask/8bittextmask
+ vec4 styleColor;
+ vec2 shift;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ sampleCoord = tCoord * ubuf.textureScale;
+ shiftedSampleCoord = (tCoord - ubuf.shift) * ubuf.textureScale;
+ gl_Position = ubuf.matrix * floor((vCoord * ubuf.dpr) + 0.5) / ubuf.dpr;
+}
diff --git a/src/quick/scenegraph/shaders_ng/styledtext.vert.qsb b/src/quick/scenegraph/shaders_ng/styledtext.vert.qsb
new file mode 100644
index 0000000000..9a27ed0eb8
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/styledtext.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/styledtext_a.frag b/src/quick/scenegraph/shaders_ng/styledtext_a.frag
new file mode 100644
index 0000000000..b673137895
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/styledtext_a.frag
@@ -0,0 +1,26 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 1) in vec2 shiftedSampleCoord;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 color;
+ vec2 textureScale;
+ float dpr;
+ // the above must stay compatible with textmask/8bittextmask
+ vec4 styleColor;
+ vec2 shift;
+} ubuf;
+
+void main()
+{
+ float glyph = texture(_qt_texture, sampleCoord).a; // take .a instead of .r
+ float style = clamp(texture(_qt_texture, shiftedSampleCoord).a - glyph,
+ 0.0, 1.0);
+ fragColor = style * ubuf.styleColor + glyph * ubuf.color;
+}
diff --git a/src/quick/scenegraph/shaders_ng/styledtext_a.frag.qsb b/src/quick/scenegraph/shaders_ng/styledtext_a.frag.qsb
new file mode 100644
index 0000000000..9dd4137072
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/styledtext_a.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/textmask.frag b/src/quick/scenegraph/shaders_ng/textmask.frag
new file mode 100644
index 0000000000..518d5c965f
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/textmask.frag
@@ -0,0 +1,19 @@
+#version 440
+
+layout(location = 0) in vec2 sampleCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D _qt_texture;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 color;
+ vec2 textureScale;
+ float dpr;
+} ubuf;
+
+void main()
+{
+ vec4 glyph = texture(_qt_texture, sampleCoord);
+ fragColor = vec4(glyph.rgb * ubuf.color.a, glyph.a);
+}
diff --git a/src/quick/scenegraph/shaders_ng/textmask.frag.qsb b/src/quick/scenegraph/shaders_ng/textmask.frag.qsb
new file mode 100644
index 0000000000..b16da4d76a
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/textmask.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/textmask.vert b/src/quick/scenegraph/shaders_ng/textmask.vert
new file mode 100644
index 0000000000..d7d3bf892e
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/textmask.vert
@@ -0,0 +1,21 @@
+#version 440
+
+layout(location = 0) in vec4 vCoord;
+layout(location = 1) in vec2 tCoord;
+
+layout(location = 0) out vec2 sampleCoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ vec4 color;
+ vec2 textureScale;
+ float dpr;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ sampleCoord = tCoord * ubuf.textureScale;
+ gl_Position = ubuf.matrix * floor((vCoord * ubuf.dpr) + 0.5) / ubuf.dpr;
+}
diff --git a/src/quick/scenegraph/shaders_ng/textmask.vert.qsb b/src/quick/scenegraph/shaders_ng/textmask.vert.qsb
new file mode 100644
index 0000000000..ae196ed0ad
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/textmask.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/texture.frag b/src/quick/scenegraph/shaders_ng/texture.frag
new file mode 100644
index 0000000000..bd22f817e0
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/texture.frag
@@ -0,0 +1,16 @@
+#version 440
+
+layout(location = 0) in vec2 qt_TexCoord;
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 qt_Matrix;
+ float opacity;
+} ubuf;
+
+layout(binding = 1) uniform sampler2D qt_Texture;
+
+void main()
+{
+ fragColor = texture(qt_Texture, qt_TexCoord) * ubuf.opacity;
+}
diff --git a/src/quick/scenegraph/shaders_ng/texture.frag.qsb b/src/quick/scenegraph/shaders_ng/texture.frag.qsb
new file mode 100644
index 0000000000..3f4aa3713c
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/texture.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/texture.vert b/src/quick/scenegraph/shaders_ng/texture.vert
new file mode 100644
index 0000000000..537852d2bd
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/texture.vert
@@ -0,0 +1,19 @@
+#version 440
+
+layout(location = 0) in vec4 qt_VertexPosition;
+layout(location = 1) in vec2 qt_VertexTexCoord;
+
+layout(location = 0) out vec2 qt_TexCoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 qt_Matrix;
+ float opacity;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ qt_TexCoord = qt_VertexTexCoord;
+ gl_Position = ubuf.qt_Matrix * qt_VertexPosition;
+}
diff --git a/src/quick/scenegraph/shaders_ng/texture.vert.qsb b/src/quick/scenegraph/shaders_ng/texture.vert.qsb
new file mode 100644
index 0000000000..bf0bc7d9fa
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/texture.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/vertexcolor.frag b/src/quick/scenegraph/shaders_ng/vertexcolor.frag
new file mode 100644
index 0000000000..ede283be0c
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/vertexcolor.frag
@@ -0,0 +1,9 @@
+#version 440
+
+layout(location = 0) in vec4 color;
+layout(location = 0) out vec4 fragColor;
+
+void main()
+{
+ fragColor = color;
+}
diff --git a/src/quick/scenegraph/shaders_ng/vertexcolor.frag.qsb b/src/quick/scenegraph/shaders_ng/vertexcolor.frag.qsb
new file mode 100644
index 0000000000..93965a55dd
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/vertexcolor.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/vertexcolor.vert b/src/quick/scenegraph/shaders_ng/vertexcolor.vert
new file mode 100644
index 0000000000..bfb9a95073
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/vertexcolor.vert
@@ -0,0 +1,19 @@
+#version 440
+
+layout(location = 0) in vec4 vertexCoord;
+layout(location = 1) in vec4 vertexColor;
+
+layout(location = 0) out vec4 color;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ float opacity;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ gl_Position = ubuf.matrix * vertexCoord;
+ color = vertexColor * ubuf.opacity;
+}
diff --git a/src/quick/scenegraph/shaders_ng/vertexcolor.vert.qsb b/src/quick/scenegraph/shaders_ng/vertexcolor.vert.qsb
new file mode 100644
index 0000000000..98abe4ef6f
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/vertexcolor.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/visualization.frag b/src/quick/scenegraph/shaders_ng/visualization.frag
new file mode 100644
index 0000000000..29f718fe5d
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/visualization.frag
@@ -0,0 +1,19 @@
+#version 440
+
+layout(location = 0) in vec2 pos;
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ mat4 rotation;
+ vec4 color;
+ float pattern;
+ int projection;
+} ubuf;
+
+void main(void)
+{
+ vec4 c = ubuf.color;
+ c.xyz += pow(max(sin(pos.x + pos.y), 0.0), 2.0) * ubuf.pattern * 0.25;
+ fragColor = c;
+}
diff --git a/src/quick/scenegraph/shaders_ng/visualization.frag.qsb b/src/quick/scenegraph/shaders_ng/visualization.frag.qsb
new file mode 100644
index 0000000000..eadad927dc
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/visualization.frag.qsb
Binary files differ
diff --git a/src/quick/scenegraph/shaders_ng/visualization.vert b/src/quick/scenegraph/shaders_ng/visualization.vert
new file mode 100644
index 0000000000..e2447948c2
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/visualization.vert
@@ -0,0 +1,30 @@
+#version 440
+
+layout(location = 0) in vec4 v;
+layout(location = 0) out vec2 pos;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 matrix;
+ mat4 rotation;
+ vec4 color;
+ float pattern;
+ int projection;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; float gl_PointSize; };
+
+void main()
+{
+ vec4 p = ubuf.matrix * v;
+
+ if (ubuf.projection != 0) {
+ vec4 proj = ubuf.rotation * p;
+ gl_Position = vec4(proj.x, proj.y, 0, proj.z);
+ } else {
+ gl_Position = p;
+ }
+
+ pos = v.xy * 1.37;
+
+ gl_PointSize = 1.0;
+}
diff --git a/src/quick/scenegraph/shaders_ng/visualization.vert.qsb b/src/quick/scenegraph/shaders_ng/visualization.vert.qsb
new file mode 100644
index 0000000000..7ba27cb4b5
--- /dev/null
+++ b/src/quick/scenegraph/shaders_ng/visualization.vert.qsb
Binary files differ
diff --git a/src/quick/scenegraph/util/qsgdefaultpainternode.cpp b/src/quick/scenegraph/util/qsgdefaultpainternode.cpp
index 981ea089be..f15ea67b46 100644
--- a/src/quick/scenegraph/util/qsgdefaultpainternode.cpp
+++ b/src/quick/scenegraph/util/qsgdefaultpainternode.cpp
@@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
#define QT_MINIMUM_DYNAMIC_FBO_SIZE 64U
QSGPainterTexture::QSGPainterTexture()
- : QSGPlainTexture()
+ : QSGPlainTexture(*(new QSGPainterTexturePrivate))
{
m_retain_image = true;
}
@@ -73,6 +73,16 @@ void QSGPainterTexture::bind()
m_dirty_rect = QRect();
}
+void QSGPainterTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+{
+ Q_Q(QSGPainterTexture);
+ if (!q->m_dirty_rect.isNull()) {
+ q->setImage(q->m_image);
+ q->m_dirty_rect = QRect();
+ }
+ QSGPlainTexturePrivate::updateRhiTexture(rhi, resourceUpdates);
+}
+
QSGDefaultPainterNode::QSGDefaultPainterNode(QQuickPaintedItem *item)
: QSGPainterNode()
, m_preferredRenderTarget(QQuickPaintedItem::Image)
@@ -126,6 +136,7 @@ void QSGDefaultPainterNode::paint()
return;
painter.begin(&m_image);
} else {
+ Q_ASSERT(!m_context->rhi());
if (!m_gl_device) {
m_gl_device = new QOpenGLPaintDevice(m_fboSize);
m_gl_device->setPaintFlipped(true);
@@ -237,7 +248,7 @@ void QSGDefaultPainterNode::updateGeometry()
void QSGDefaultPainterNode::updateRenderTarget()
{
- if (!m_extensionsChecked) {
+ if (!m_extensionsChecked && !m_context->rhi()) {
QOpenGLExtensions *e = static_cast<QOpenGLExtensions *>(QOpenGLContext::currentContext()->functions());
m_multisamplingSupported = e->hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample)
&& e->hasOpenGLExtension(QOpenGLExtensions::FramebufferBlit);
@@ -250,7 +261,10 @@ void QSGDefaultPainterNode::updateRenderTarget()
if (m_preferredRenderTarget == QQuickPaintedItem::Image) {
m_actualRenderTarget = QQuickPaintedItem::Image;
} else {
- if (!m_multisamplingSupported && m_smoothPainting)
+ // Image is the only option when there is no multisample framebuffer
+ // support and smooth painting is wanted, and when using the RHI. The
+ // latter may change in the future.
+ if ((!m_multisamplingSupported && m_smoothPainting) || m_context->rhi())
m_actualRenderTarget = QQuickPaintedItem::Image;
else
m_actualRenderTarget = m_preferredRenderTarget;
@@ -265,7 +279,9 @@ void QSGDefaultPainterNode::updateRenderTarget()
}
if (m_actualRenderTarget == QQuickPaintedItem::FramebufferObject ||
- m_actualRenderTarget == QQuickPaintedItem::InvertedYFramebufferObject) {
+ m_actualRenderTarget == QQuickPaintedItem::InvertedYFramebufferObject)
+ {
+ Q_ASSERT(!m_context->rhi());
const QOpenGLContext *ctx = m_context->openglContext();
if (m_fbo && !m_dirtyGeometry && (!ctx->format().samples() || !m_multisamplingSupported))
return;
diff --git a/src/quick/scenegraph/util/qsgdefaultpainternode_p.h b/src/quick/scenegraph/util/qsgdefaultpainternode_p.h
index 084fc1e004..a86f7397be 100644
--- a/src/quick/scenegraph/util/qsgdefaultpainternode_p.h
+++ b/src/quick/scenegraph/util/qsgdefaultpainternode_p.h
@@ -53,7 +53,7 @@
#include <private/qsgadaptationlayer_p.h>
#include "qsgtexturematerial.h"
-#include "qsgtexture_p.h"
+#include "qsgplaintexture_p.h"
#include <QtQuick/qquickpainteditem.h>
@@ -64,9 +64,11 @@ QT_BEGIN_NAMESPACE
class QOpenGLFramebufferObject;
class QOpenGLPaintDevice;
class QSGDefaultRenderContext;
+class QSGPainterTexturePrivate;
class Q_QUICK_PRIVATE_EXPORT QSGPainterTexture : public QSGPlainTexture
{
+ Q_DECLARE_PRIVATE(QSGPainterTexture)
public:
QSGPainterTexture();
@@ -78,6 +80,13 @@ private:
QRect m_dirty_rect;
};
+class QSGPainterTexturePrivate : public QSGPlainTexturePrivate
+{
+ Q_DECLARE_PUBLIC(QSGPainterTexture)
+public:
+ void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
+};
+
class Q_QUICK_PRIVATE_EXPORT QSGDefaultPainterNode : public QSGPainterNode
{
public:
diff --git a/src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp b/src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp
index 94912778f8..1154c06d7c 100644
--- a/src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp
+++ b/src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp
@@ -183,7 +183,9 @@ void QSGDefaultDepthStencilBuffer::free()
QSGDepthStencilBufferManager::~QSGDepthStencilBufferManager()
{
for (Hash::const_iterator it = m_buffers.constBegin(), cend = m_buffers.constEnd(); it != cend; ++it) {
- QSGDepthStencilBuffer *buffer = it.value().data();
+ QSharedPointer<QSGDepthStencilBuffer> buffer = it.value().toStrongRef();
+ Q_ASSERT_X(buffer, "~QSGDepthStencilBufferManager",
+ "~QSGDepthStencilBuffer is supposed to unregister from the manager");
buffer->free();
buffer->m_manager = nullptr;
}
diff --git a/src/quick/scenegraph/util/qsgengine.cpp b/src/quick/scenegraph/util/qsgengine.cpp
index 91fa46033c..4880d98871 100644
--- a/src/quick/scenegraph/util/qsgengine.cpp
+++ b/src/quick/scenegraph/util/qsgengine.cpp
@@ -42,7 +42,7 @@
#include <QtQuick/qsgtexture.h>
#include <private/qsgcontext_p.h>
#include <private/qsgrenderer_p.h>
-#include <private/qsgtexture_p.h>
+#include <private/qsgplaintexture_p.h>
#if QT_CONFIG(opengl)
# include <QtGui/QOpenGLContext>
@@ -69,6 +69,10 @@ QT_BEGIN_NAMESPACE
Most of the time you will instead want to subclass QQuickItem and insert
your QSGNode in a normal QtQuick scene by overriding QQuickItem::updatePaintNode().
+ \warning This class is only suitable when working directly with OpenGL. It
+ is not compatible with the \l{Scene Graph Adaptations}{RHI-based rendering
+ path}.
+
\sa QSGAbstractRenderer
*/
@@ -126,12 +130,29 @@ void QSGEngine::initialize(QOpenGLContext *context)
#endif
if (d->sgRenderContext && !d->sgRenderContext->isValid()) {
d->sgRenderContext->setAttachToGraphicsContext(false);
- d->sgRenderContext->initialize(context);
+#if QT_CONFIG(opengl)
+ QSGDefaultRenderContext *rc = qobject_cast<QSGDefaultRenderContext *>(d->sgRenderContext.data());
+ if (rc) {
+ QSGDefaultRenderContext::InitParams params;
+ params.sampleCount = qMax(1, context->format().samples());
+ params.openGLContext = context;
+ // leave the size hint and surface unset, we do not know, that's fine
+ rc->initialize(&params);
+ } else {
+ d->sgRenderContext->initialize(nullptr);
+ }
+#else
+ d->sgRenderContext->initialize(nullptr);
+#endif
#if QT_CONFIG(opengl)
if (context)
connect(context, &QOpenGLContext::aboutToBeDestroyed, this, &QSGEngine::invalidate);
#endif
}
+
+#if !QT_CONFIG(opengl)
+ Q_UNUSED(context);
+#endif
}
/*!
diff --git a/src/quick/scenegraph/util/qsgengine.h b/src/quick/scenegraph/util/qsgengine.h
index e48b7784ae..c5a59b47e7 100644
--- a/src/quick/scenegraph/util/qsgengine.h
+++ b/src/quick/scenegraph/util/qsgengine.h
@@ -54,6 +54,8 @@ class QSGRectangleNode;
class QSGImageNode;
class QSGNinePatchNode;
+// ### Qt 6: Remove or redesign.
+
class Q_QUICK_EXPORT QSGEngine : public QObject
{
Q_OBJECT
diff --git a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp
index 28f6113a60..87941bf31a 100644
--- a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp
+++ b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp
@@ -116,6 +116,51 @@ void FlatColorMaterialShader::initialize()
}
+class FlatColorMaterialRhiShader : public QSGMaterialRhiShader
+{
+public:
+ FlatColorMaterialRhiShader();
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+FlatColorMaterialRhiShader::FlatColorMaterialRhiShader()
+{
+ setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/flatcolor.vert.qsb"));
+ setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/flatcolor.frag.qsb"));
+}
+
+bool FlatColorMaterialRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial,
+ QSGMaterial *oldMaterial)
+{
+ Q_ASSERT(!oldMaterial || newMaterial->type() == oldMaterial->type());
+ QSGFlatColorMaterial *oldMat = static_cast<QSGFlatColorMaterial *>(oldMaterial);
+ QSGFlatColorMaterial *mat = static_cast<QSGFlatColorMaterial *>(newMaterial);
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+
+ if (state.isMatrixDirty()) {
+ const QMatrix4x4 m = state.combinedMatrix();
+ memcpy(buf->data(), m.constData(), 64);
+ changed = true;
+ }
+
+ const QColor &c = mat->color();
+ if (!oldMat || c != oldMat->color() || state.isOpacityDirty()) {
+ const float opacity = state.opacity() * c.alphaF();
+ QVector4D v(c.redF() * opacity,
+ c.greenF() * opacity,
+ c.blueF() * opacity,
+ opacity);
+ Q_ASSERT(sizeof(v) == 16);
+ memcpy(buf->data() + 64, &v, 16);
+ changed = true;
+ }
+
+ return changed;
+}
+
/*!
\class QSGFlatColorMaterial
@@ -126,7 +171,7 @@ void FlatColorMaterialShader::initialize()
\inmodule QtQuick
\ingroup qtquick-scenegraph-materials
- \warning This utility class is only functional when running with the OpenGL
+ \warning This utility class is only functional when running with the default
backend of the Qt Quick scenegraph.
The flat color material will fill every pixel in a geometry using
@@ -150,10 +195,9 @@ void FlatColorMaterialShader::initialize()
QSGFlatColorMaterial::QSGFlatColorMaterial() : m_color(QColor(255, 255, 255))
{
+ setFlag(SupportsRhiShader, true);
}
-
-
/*!
\fn const QColor &QSGFlatColorMaterial::color() const
@@ -193,7 +237,10 @@ QSGMaterialType *QSGFlatColorMaterial::type() const
QSGMaterialShader *QSGFlatColorMaterial::createShader() const
{
- return new FlatColorMaterialShader;
+ if (flags().testFlag(RhiShaderWanted))
+ return new FlatColorMaterialRhiShader;
+ else
+ return new FlatColorMaterialShader;
}
diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgopenglatlastexture.cpp
index 921ed0c1fc..75a874424a 100644
--- a/src/quick/scenegraph/util/qsgatlastexture.cpp
+++ b/src/quick/scenegraph/util/qsgopenglatlastexture.cpp
@@ -37,7 +37,7 @@
**
****************************************************************************/
-#include "qsgatlastexture_p.h"
+#include "qsgopenglatlastexture_p.h"
#include <QtCore/QVarLengthArray>
#include <QtCore/QElapsedTimer>
@@ -71,24 +71,22 @@ static QElapsedTimer qsg_renderer_timer;
DEFINE_BOOL_CONFIG_OPTION(qsgEnableCompressedAtlas, QSG_ENABLE_COMPRESSED_ATLAS)
-namespace QSGAtlasTexture
+namespace QSGOpenGLAtlasTexture
{
-Manager::Manager()
+Manager::Manager(const QSize &surfacePixelSize)
: m_atlas(nullptr)
{
QOpenGLContext *gl = QOpenGLContext::currentContext();
Q_ASSERT(gl);
- QSurface *surface = gl->surface();
- QSize surfaceSize = surface->size();
int max;
gl->functions()->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
- 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))));
+ int w = qMin(max, qt_sg_envInt("QSG_ATLAS_WIDTH", qMax(512U, qNextPowerOfTwo(surfacePixelSize.width() - 1))));
+ int h = qMin(max, qt_sg_envInt("QSG_ATLAS_HEIGHT", qMax(512U, qNextPowerOfTwo(surfacePixelSize.height() - 1))));
- if (surface->surfaceClass() == QSurface::Window) {
- QWindow *window = static_cast<QWindow *>(surface);
+ if (gl->surface()->surfaceClass() == QSurface::Window) {
+ QWindow *window = static_cast<QWindow *>(gl->surface());
// Coverwindows, optimize for memory rather than speed
if ((window->type() & Qt::CoverWindow) == Qt::CoverWindow) {
w /= 2;
@@ -99,10 +97,9 @@ Manager::Manager()
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);
+ qCDebug(QSG_LOG_INFO, "opengl texture atlas dimensions: %dx%d", w, h);
}
-
Manager::~Manager()
{
Q_ASSERT(m_atlas == nullptr);
@@ -153,6 +150,10 @@ QSGTexture *Manager::create(const QSGCompressedTextureFactory *factory)
case QOpenGLTexture::RGB8_ETC2:
case QOpenGLTexture::RGBA8_ETC2_EAC:
case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2:
+ case QOpenGLTexture::RGB_DXT1:
+ case QOpenGLTexture::RGBA_DXT1:
+ case QOpenGLTexture::RGBA_DXT3:
+ case QOpenGLTexture::RGBA_DXT5:
break;
default:
return t;
@@ -161,8 +162,12 @@ QSGTexture *Manager::create(const QSGCompressedTextureFactory *factory)
QSize size = factory->m_textureData.size();
if (size.width() < m_atlas_size_limit && size.height() < m_atlas_size_limit) {
QHash<unsigned int, QSGCompressedAtlasTexture::Atlas*>::iterator i = m_atlases.find(format);
- if (i == m_atlases.end())
- i = m_atlases.insert(format, new QSGCompressedAtlasTexture::Atlas(m_atlas_size, format));
+ if (i == m_atlases.end()) {
+ // must be multiple of 4
+ QSize paddedSize(((m_atlas_size.width() + 3) / 4) * 4, ((m_atlas_size.height() + 3) / 4) * 4);
+ i = m_atlases.insert(format, new QSGCompressedAtlasTexture::Atlas(paddedSize, format));
+ }
+
// must be multiple of 4
QSize paddedSize(((size.width() + 3) / 4) * 4, ((size.height() + 3) / 4) * 4);
QByteArray data = factory->m_textureData.data();
@@ -593,4 +598,4 @@ QSGTexture *Texture::removedFromAtlas() const
QT_END_NAMESPACE
-#include "moc_qsgatlastexture_p.cpp"
+#include "moc_qsgopenglatlastexture_p.cpp"
diff --git a/src/quick/scenegraph/util/qsgatlastexture_p.h b/src/quick/scenegraph/util/qsgopenglatlastexture_p.h
index 14dc8f7958..f8dd7cdf02 100644
--- a/src/quick/scenegraph/util/qsgatlastexture_p.h
+++ b/src/quick/scenegraph/util/qsgopenglatlastexture_p.h
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef QSGATLASTEXTURE_P_H
-#define QSGATLASTEXTURE_P_H
+#ifndef QSGOPENGLATLASTEXTURE_P_H
+#define QSGOPENGLATLASTEXTURE_P_H
//
// W A R N I N G
@@ -56,7 +56,7 @@
#include <QtGui/qopengl.h>
#include <QtQuick/QSGTexture>
-#include <QtQuick/private/qsgtexture_p.h>
+#include <QtQuick/private/qsgplaintexture_p.h>
#include <QtQuick/private/qsgareaallocator_p.h>
QT_BEGIN_NAMESPACE
@@ -66,7 +66,7 @@ namespace QSGCompressedAtlasTexture {
}
class QSGCompressedTextureFactory;
-namespace QSGAtlasTexture
+namespace QSGOpenGLAtlasTexture
{
class Texture;
@@ -78,7 +78,7 @@ class Manager : public QObject
Q_OBJECT
public:
- Manager();
+ Manager(const QSize &surfacePixelSize);
~Manager();
QSGTexture *create(const QImage &image, bool hasAlphaChannel);
diff --git a/src/quick/scenegraph/util/qsgplaintexture.cpp b/src/quick/scenegraph/util/qsgplaintexture.cpp
new file mode 100644
index 0000000000..fdebe03494
--- /dev/null
+++ b/src/quick/scenegraph/util/qsgplaintexture.cpp
@@ -0,0 +1,457 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgplaintexture_p.h"
+#include "qsgrhinativetextureimporter_p.h"
+#include <QtQuick/private/qsgcontext_p.h>
+#include <qmath.h>
+#include <private/qquickprofiler_p.h>
+#include <private/qqmlglobal_p.h>
+#include <QtGui/qguiapplication.h>
+#include <QtGui/qpa/qplatformnativeinterface.h>
+#if QT_CONFIG(opengl)
+# include <QtGui/qopenglcontext.h>
+# include <QtGui/qopenglfunctions.h>
+# include <QtGui/private/qopengltextureuploader_p.h>
+# include <private/qsgdefaultrendercontext_p.h>
+#endif
+#include <QtGui/private/qrhi_p.h>
+
+#if QT_CONFIG(opengl)
+static QElapsedTimer qsg_renderer_timer;
+#endif
+
+#ifndef GL_BGRA
+#define GL_BGRA 0x80E1
+#endif
+
+#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
+#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#endif
+
+QT_BEGIN_NAMESPACE
+
+QSGPlainTexture::QSGPlainTexture()
+ : QSGTexture(*(new QSGPlainTexturePrivate))
+ , m_texture_id(0)
+ , m_texture(nullptr)
+ , m_has_alpha(false)
+ , m_dirty_texture(false)
+ , m_dirty_bind_options(false)
+ , m_owns_texture(true)
+ , m_mipmaps_generated(false)
+ , m_retain_image(false)
+ , m_mipmap_warned(false)
+{
+}
+
+QSGPlainTexture::QSGPlainTexture(QSGPlainTexturePrivate &dd)
+ : QSGTexture(dd)
+ , m_texture_id(0)
+ , m_texture(nullptr)
+ , m_has_alpha(false)
+ , m_dirty_texture(false)
+ , m_dirty_bind_options(false)
+ , m_owns_texture(true)
+ , m_mipmaps_generated(false)
+ , m_retain_image(false)
+ , m_mipmap_warned(false)
+{
+}
+
+QSGPlainTexture::~QSGPlainTexture()
+{
+#if QT_CONFIG(opengl)
+ if (m_texture_id && m_owns_texture && QOpenGLContext::currentContext())
+ QOpenGLContext::currentContext()->functions()->glDeleteTextures(1, &m_texture_id);
+#endif
+ if (m_texture && m_owns_texture)
+ delete m_texture;
+}
+
+void QSGPlainTexture::setImage(const QImage &image)
+{
+ m_image = image;
+ m_texture_size = image.size();
+ m_has_alpha = image.hasAlphaChannel();
+ m_dirty_texture = true;
+ m_dirty_bind_options = true;
+ m_mipmaps_generated = false;
+ }
+
+int QSGPlainTexture::textureId() const // legacy (GL-only)
+{
+ if (m_dirty_texture) {
+ if (m_image.isNull()) {
+ // The actual texture and id will be updated/deleted in a later bind()
+ // or ~QSGPlainTexture so just keep it minimal here.
+ return 0;
+ } else if (m_texture_id == 0){
+#if QT_CONFIG(opengl)
+ // Generate a texture id for use later and return it.
+ QOpenGLContext::currentContext()->functions()->glGenTextures(1, &const_cast<QSGPlainTexture *>(this)->m_texture_id);
+#endif
+ return m_texture_id;
+ }
+ }
+ return m_texture_id;
+}
+
+void QSGPlainTexture::setTextureId(int id) // legacy (GL-only)
+{
+#if QT_CONFIG(opengl)
+ if (m_texture_id && m_owns_texture)
+ QOpenGLContext::currentContext()->functions()->glDeleteTextures(1, &m_texture_id);
+#endif
+
+ m_texture_id = id;
+ m_dirty_texture = false;
+ m_dirty_bind_options = true;
+ m_image = QImage();
+ m_mipmaps_generated = false;
+}
+
+void QSGPlainTexture::bind() // legacy (GL-only)
+{
+#if QT_CONFIG(opengl)
+ QOpenGLContext *context = QOpenGLContext::currentContext();
+ QOpenGLFunctions *funcs = context->functions();
+ if (!m_dirty_texture) {
+ funcs->glBindTexture(GL_TEXTURE_2D, m_texture_id);
+ if (mipmapFiltering() != QSGTexture::None && !m_mipmaps_generated) {
+ funcs->glGenerateMipmap(GL_TEXTURE_2D);
+ m_mipmaps_generated = true;
+ }
+ updateBindOptions(m_dirty_bind_options);
+ m_dirty_bind_options = false;
+ return;
+ }
+
+ m_dirty_texture = false;
+
+ bool profileFrames = QSG_LOG_TIME_TEXTURE().isDebugEnabled();
+ if (profileFrames)
+ qsg_renderer_timer.start();
+ Q_QUICK_SG_PROFILE_START_SYNCHRONIZED(QQuickProfiler::SceneGraphTexturePrepare,
+ QQuickProfiler::SceneGraphTextureDeletion);
+
+
+ if (m_image.isNull()) {
+ if (m_texture_id && m_owns_texture) {
+ funcs->glDeleteTextures(1, &m_texture_id);
+ qCDebug(QSG_LOG_TIME_TEXTURE, "plain texture deleted in %dms - %dx%d",
+ (int) qsg_renderer_timer.elapsed(),
+ m_texture_size.width(),
+ m_texture_size.height());
+ Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphTextureDeletion,
+ QQuickProfiler::SceneGraphTextureDeletionDelete);
+ }
+ m_texture_id = 0;
+ m_texture_size = QSize();
+ m_has_alpha = false;
+
+ return;
+ }
+
+ if (m_texture_id == 0)
+ funcs->glGenTextures(1, &m_texture_id);
+ funcs->glBindTexture(GL_TEXTURE_2D, m_texture_id);
+
+ qint64 bindTime = 0;
+ if (profileFrames)
+ bindTime = qsg_renderer_timer.nsecsElapsed();
+ Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphTexturePrepare,
+ QQuickProfiler::SceneGraphTexturePrepareBind);
+
+ // ### TODO: check for out-of-memory situations...
+
+ QOpenGLTextureUploader::BindOptions options = QOpenGLTextureUploader::PremultipliedAlphaBindOption;
+
+ // Downscale the texture to fit inside the max texture limit if it is too big.
+ // It would be better if the image was already downscaled to the right size,
+ // but this information is not always available at that time, so as a last
+ // resort we can do it here. Texture coordinates are normalized, so it
+ // won't cause any problems and actual texture sizes will be written
+ // based on QSGTexture::textureSize which is updated after this, so that
+ // should be ok.
+ int max;
+ if (auto rc = QSGDefaultRenderContext::from(context))
+ max = rc->maxTextureSize();
+ else
+ funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
+
+ m_texture_size = m_texture_size.boundedTo(QSize(max, max));
+
+ // Scale to a power of two size if mipmapping is requested and the
+ // texture is npot and npot textures are not properly supported.
+ if (mipmapFiltering() != QSGTexture::None
+ && !funcs->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)) {
+ options |= QOpenGLTextureUploader::PowerOfTwoBindOption;
+ }
+
+ updateBindOptions(m_dirty_bind_options);
+
+ QOpenGLTextureUploader::textureImage(GL_TEXTURE_2D, m_image, options, QSize(max, max));
+
+ qint64 uploadTime = 0;
+ if (profileFrames)
+ uploadTime = qsg_renderer_timer.nsecsElapsed();
+ Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphTexturePrepare,
+ QQuickProfiler::SceneGraphTexturePrepareUpload);
+
+ if (mipmapFiltering() != QSGTexture::None) {
+ funcs->glGenerateMipmap(GL_TEXTURE_2D);
+ m_mipmaps_generated = true;
+ }
+
+ qint64 mipmapTime = 0;
+ if (profileFrames) {
+ mipmapTime = qsg_renderer_timer.nsecsElapsed();
+ qCDebug(QSG_LOG_TIME_TEXTURE,
+ "plain texture uploaded in: %dms (%dx%d), bind=%d, upload=%d, mipmap=%d%s",
+ int(mipmapTime / 1000000),
+ m_texture_size.width(), m_texture_size.height(),
+ int(bindTime / 1000000),
+ int((uploadTime - bindTime)/1000000),
+ int((mipmapTime - uploadTime)/1000000),
+ m_texture_size != m_image.size() ? " (scaled to GL_MAX_TEXTURE_SIZE)" : "");
+ }
+ Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphTexturePrepare,
+ QQuickProfiler::SceneGraphTexturePrepareMipmap);
+
+ m_texture_rect = QRectF(0, 0, 1, 1);
+
+ m_dirty_bind_options = false;
+ if (!m_retain_image)
+ m_image = QImage();
+#endif
+}
+
+void QSGPlainTexture::setTexture(QRhiTexture *texture) // RHI only
+{
+ if (m_texture && m_owns_texture && m_texture != texture)
+ delete m_texture;
+
+ m_texture = texture;
+ m_dirty_texture = false;
+ m_dirty_bind_options = true;
+ m_image = QImage();
+ m_mipmaps_generated = false;
+}
+
+void QSGPlainTexture::setTextureFromNativeObject(QRhi *rhi, QQuickWindow::NativeObjectType type,
+ const void *nativeObjectPtr, int nativeLayout,
+ const QSize &size, bool mipmap)
+{
+ Q_UNUSED(type);
+
+ QRhiTexture::Flags flags = 0;
+ if (mipmap)
+ flags |= QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips;
+
+ QRhiTexture *t = rhi->newTexture(QRhiTexture::RGBA8, size, 1, flags);
+
+ // ownership of the native object is never taken
+ QSGRhiNativeTextureImporter::buildWrapper(rhi, t, nativeObjectPtr, nativeLayout);
+
+ setTexture(t);
+}
+
+int QSGPlainTexturePrivate::comparisonKey() const
+{
+ Q_Q(const QSGPlainTexture);
+
+ // not textureId() as that would create an id when not yet done - that's not wanted here
+ if (q->m_texture_id)
+ return q->m_texture_id;
+
+ if (q->m_texture)
+ return int(qintptr(q->m_texture));
+
+ // two textures (and so materials) with not-yet-created texture underneath are never equal
+ return int(qintptr(q));
+}
+
+QRhiTexture *QSGPlainTexturePrivate::rhiTexture() const
+{
+ Q_Q(const QSGPlainTexture);
+ return q->m_texture;
+}
+
+void QSGPlainTexturePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+{
+ Q_Q(QSGPlainTexture);
+
+ const bool hasMipMaps = q->mipmapFiltering() != QSGTexture::None;
+ const bool mipmappingChanged = q->m_texture && ((hasMipMaps && !q->m_texture->flags().testFlag(QRhiTexture::MipMapped)) // did not have it before
+ || (!hasMipMaps && q->m_texture->flags().testFlag(QRhiTexture::MipMapped))); // does not have it anymore
+
+ if (!q->m_dirty_texture) {
+ if (!q->m_texture)
+ return;
+ if (q->m_texture && !mipmappingChanged) {
+ if (hasMipMaps && !q->m_mipmaps_generated) {
+ resourceUpdates->generateMips(q->m_texture);
+ q->m_mipmaps_generated = true;
+ }
+ return;
+ }
+ }
+
+ if (q->m_image.isNull()) {
+ if (!q->m_dirty_texture && mipmappingChanged) {
+ // Full Mipmap Panic!
+ if (!q->m_mipmap_warned) {
+ qWarning("QSGPlainTexture: Mipmap settings changed without having image data available. "
+ "Call setImage() again or enable m_retain_image. "
+ "Falling back to previous mipmap filtering mode.");
+ q->m_mipmap_warned = true;
+ }
+ // leave the texture valid and rather ignore the mipmap mode change attempt
+ q->setMipmapFiltering(m_last_mipmap_filter);
+ return;
+ }
+
+ if (q->m_texture && q->m_owns_texture)
+ delete q->m_texture;
+
+ q->m_texture = nullptr;
+ q->m_texture_size = QSize();
+ q->m_has_alpha = false;
+
+ q->m_dirty_texture = false;
+ return;
+ }
+
+ q->m_dirty_texture = false;
+
+ QImage tmp;
+ bool bgra = false;
+ bool needsConvert = false;
+ if (q->m_image.format() == QImage::Format_RGB32 || q->m_image.format() == QImage::Format_ARGB32_Premultiplied) {
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ if (rhi->isTextureFormatSupported(QRhiTexture::BGRA8)) {
+ tmp = q->m_image;
+ bgra = true;
+ } else {
+ needsConvert = true;
+ }
+#else
+ needsConvert = true;
+#endif
+ } else if (q->m_image.format() == QImage::Format_RGBX8888 || q->m_image.format() == QImage::Format_RGBA8888_Premultiplied) {
+ tmp = q->m_image;
+ } else {
+ needsConvert = true;
+ }
+
+ if (needsConvert)
+ tmp = q->m_image.convertToFormat(QImage::Format_RGBA8888_Premultiplied);
+
+ // Downscale the texture to fit inside the max texture limit if it is too big.
+ // It would be better if the image was already downscaled to the right size,
+ // but this information is not always available at that time, so as a last
+ // resort we can do it here. Texture coordinates are normalized, so it
+ // won't cause any problems and actual texture sizes will be written
+ // based on QSGTexture::textureSize which is updated after this, so that
+ // should be ok.
+ const int max = rhi->resourceLimit(QRhi::TextureSizeMax);
+ if (tmp.width() > max || tmp.height() > max) {
+ tmp = tmp.scaled(qMin(max, tmp.width()), qMin(max, tmp.height()), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ q->m_texture_size = tmp.size();
+ }
+
+ if ((q->mipmapFiltering() != QSGTexture::None
+ || q->horizontalWrapMode() != QSGTexture::ClampToEdge
+ || q->verticalWrapMode() != QSGTexture::ClampToEdge)
+ && !rhi->isFeatureSupported(QRhi::NPOTTextureRepeat))
+ {
+ const int w = qNextPowerOfTwo(tmp.width() - 1);
+ const int h = qNextPowerOfTwo(tmp.height() - 1);
+ if (tmp.width() != w || tmp.height() != h) {
+ tmp = tmp.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ q->m_texture_size = tmp.size();
+ }
+ }
+
+ bool needsRebuild = q->m_texture && q->m_texture->pixelSize() != q->m_texture_size;
+
+ if (mipmappingChanged) {
+ QRhiTexture::Flags f = q->m_texture->flags();
+ f.setFlag(QRhiTexture::MipMapped, hasMipMaps);
+ f.setFlag(QRhiTexture::UsedWithGenerateMips, hasMipMaps);
+ q->m_texture->setFlags(f);
+ needsRebuild = true;
+ }
+
+ if (!q->m_texture) {
+ QRhiTexture::Flags f = 0;
+ if (hasMipMaps)
+ f |= QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips;
+
+ q->m_texture = rhi->newTexture(bgra ? QRhiTexture::BGRA8 : QRhiTexture::RGBA8, q->m_texture_size, 1, f);
+ needsRebuild = true;
+ }
+
+ if (needsRebuild) {
+ if (!q->m_texture->build()) {
+ qWarning("Failed to build texture for QSGPlainTexture (size %dx%d)",
+ q->m_texture_size.width(), q->m_texture_size.height());
+ return;
+ }
+ }
+
+ if (tmp.width() * 4 != tmp.bytesPerLine())
+ tmp = tmp.copy();
+
+ resourceUpdates->uploadTexture(q->m_texture, tmp);
+
+ if (hasMipMaps) {
+ resourceUpdates->generateMips(q->m_texture);
+ q->m_mipmaps_generated = true;
+ }
+
+ m_last_mipmap_filter = q->mipmapFiltering();
+ q->m_texture_rect = QRectF(0, 0, 1, 1);
+
+ if (!q->m_retain_image)
+ q->m_image = QImage();
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgtexture_p.h b/src/quick/scenegraph/util/qsgplaintexture_p.h
index 18dd5eff68..1eb0b59d2e 100644
--- a/src/quick/scenegraph/util/qsgtexture_p.h
+++ b/src/quick/scenegraph/util/qsgplaintexture_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef QSGTEXTURE_P_H
-#define QSGTEXTURE_P_H
+#ifndef QSGPLAINTEXTURE_P_H
+#define QSGPLAINTEXTURE_P_H
//
// W A R N I N G
@@ -51,36 +51,18 @@
// We mean it.
//
-#include <QtQuick/qtquickglobal.h>
-#include <private/qobject_p.h>
-#if QT_CONFIG(opengl)
-# include <QtGui/qopengl.h>
-#endif
-#include "qsgtexture.h"
-#include <QtQuick/private/qsgcontext_p.h>
+#include <QtQuick/private/qtquickglobal_p.h>
+#include <QtQuick/private/qsgtexture_p.h>
+#include <QtQuick/qquickwindow.h>
QT_BEGIN_NAMESPACE
-class QSGTexturePrivate : public QObjectPrivate
-{
- Q_DECLARE_PUBLIC(QSGTexture)
-public:
- QSGTexturePrivate();
-
- uint wrapChanged : 1;
- uint filteringChanged : 1;
- uint anisotropyChanged : 1;
-
- uint horizontalWrap : 2;
- uint verticalWrap : 2;
- uint mipmapMode : 2;
- uint filterMode : 2;
- uint anisotropyLevel: 3;
-};
+class QSGPlainTexturePrivate;
class Q_QUICK_PRIVATE_EXPORT QSGPlainTexture : public QSGTexture
{
Q_OBJECT
+ Q_DECLARE_PRIVATE(QSGPlainTexture)
public:
QSGPlainTexture();
~QSGPlainTexture() override;
@@ -103,6 +85,11 @@ public:
void bind() override;
+ void setTexture(QRhiTexture *texture);
+ void setTextureFromNativeObject(QRhi *rhi, QQuickWindow::NativeObjectType type,
+ const void *nativeObjectPtr, int nativeLayout,
+ const QSize &size, bool mipmap);
+
static QSGPlainTexture *fromImage(const QImage &image) {
QSGPlainTexture *t = new QSGPlainTexture();
t->setImage(image);
@@ -110,22 +97,35 @@ public:
}
protected:
+ QSGPlainTexture(QSGPlainTexturePrivate &dd);
+
QImage m_image;
uint m_texture_id;
QSize m_texture_size;
QRectF m_texture_rect;
+ QRhiTexture *m_texture;
uint m_has_alpha : 1;
uint m_dirty_texture : 1;
- uint m_dirty_bind_options : 1;
+ uint m_dirty_bind_options : 1; // legacy (GL-only)
uint m_owns_texture : 1;
uint m_mipmaps_generated : 1;
- uint m_retain_image: 1;
+ uint m_retain_image : 1;
+ uint m_mipmap_warned : 1; // RHI only
};
-Q_QUICK_PRIVATE_EXPORT bool qsg_safeguard_texture(QSGTexture *);
+class QSGPlainTexturePrivate : public QSGTexturePrivate
+{
+ Q_DECLARE_PUBLIC(QSGPlainTexture)
+public:
+ int comparisonKey() const override;
+ QRhiTexture *rhiTexture() const override;
+ void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
+
+ QSGTexture::Filtering m_last_mipmap_filter = QSGTexture::None;
+};
QT_END_NAMESPACE
-#endif // QSGTEXTURE_P_H
+#endif // QSGPLAINTEXTURE_P_H
diff --git a/src/quick/scenegraph/util/qsgrhiatlastexture.cpp b/src/quick/scenegraph/util/qsgrhiatlastexture.cpp
new file mode 100644
index 0000000000..3dc1f5f526
--- /dev/null
+++ b/src/quick/scenegraph/util/qsgrhiatlastexture.cpp
@@ -0,0 +1,491 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgrhiatlastexture_p.h"
+
+#include <QtCore/QVarLengthArray>
+#include <QtCore/QElapsedTimer>
+#include <QtCore/QtMath>
+
+#include <QtGui/QWindow>
+
+#include <private/qqmlglobal_p.h>
+#include <private/qquickprofiler_p.h>
+#include <private/qsgdefaultrendercontext_p.h>
+#include <private/qsgtexture_p.h>
+#if 0
+#include <private/qsgcompressedtexture_p.h>
+#include <private/qsgcompressedatlastexture_p.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+int qt_sg_envInt(const char *name, int defaultValue);
+
+static QElapsedTimer qsg_renderer_timer;
+
+//DEFINE_BOOL_CONFIG_OPTION(qsgEnableCompressedAtlas, QSG_ENABLE_COMPRESSED_ATLAS)
+
+namespace QSGRhiAtlasTexture
+{
+
+Manager::Manager(QSGDefaultRenderContext *rc, const QSize &surfacePixelSize, QSurface *maybeSurface)
+ : m_rc(rc)
+ , m_rhi(rc->rhi())
+{
+ const int maxSize = m_rhi->resourceLimit(QRhi::TextureSizeMax);
+ int w = qMin(maxSize, qt_sg_envInt("QSG_ATLAS_WIDTH", qMax(512U, qNextPowerOfTwo(surfacePixelSize.width() - 1))));
+ int h = qMin(maxSize, qt_sg_envInt("QSG_ATLAS_HEIGHT", qMax(512U, qNextPowerOfTwo(surfacePixelSize.height() - 1))));
+
+ if (maybeSurface && maybeSurface->surfaceClass() == QSurface::Window) {
+ QWindow *window = static_cast<QWindow *>(maybeSurface);
+ // Coverwindows, optimize for memory rather than speed
+ if ((window->type() & Qt::CoverWindow) == Qt::CoverWindow) {
+ w /= 2;
+ 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, "rhi texture atlas dimensions: %dx%d", w, h);
+}
+
+Manager::~Manager()
+{
+ Q_ASSERT(m_atlas == nullptr);
+ Q_ASSERT(m_atlases.isEmpty());
+}
+
+void Manager::invalidate()
+{
+ if (m_atlas) {
+ m_atlas->invalidate();
+ m_atlas->deleteLater();
+ m_atlas = nullptr;
+ }
+
+ #if 0
+ QHash<unsigned int, QSGCompressedAtlasTexture::Atlas*>::iterator i = m_atlases.begin();
+ while (i != m_atlases.end()) {
+ i.value()->invalidate();
+ i.value()->deleteLater();
+ ++i;
+ }
+ m_atlases.clear();
+#endif
+}
+
+QSGTexture *Manager::create(const QImage &image, bool hasAlphaChannel)
+{
+ Texture *t = nullptr;
+ if (image.width() < m_atlas_size_limit && image.height() < m_atlas_size_limit) {
+ if (!m_atlas)
+ m_atlas = new Atlas(m_rc, m_atlas_size);
+ t = m_atlas->create(image);
+ if (t && !hasAlphaChannel && t->hasAlphaChannel())
+ t->setHasAlphaChannel(false);
+ }
+ return t;
+}
+
+QSGTexture *Manager::create(const QSGCompressedTextureFactory *factory)
+{
+ Q_UNUSED(factory);
+ return nullptr;
+ // ###
+
+#if 0
+ QSGTexture *t = nullptr;
+ if (!qsgEnableCompressedAtlas() || !factory->m_textureData.isValid())
+ return t;
+
+ // TODO: further abstract the atlas and remove this restriction
+ unsigned int format = factory->m_textureData.glInternalFormat();
+ switch (format) {
+ case QOpenGLTexture::RGB8_ETC1:
+ case QOpenGLTexture::RGB8_ETC2:
+ case QOpenGLTexture::RGBA8_ETC2_EAC:
+ case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2:
+ break;
+ default:
+ return t;
+ }
+
+ QSize size = factory->m_textureData.size();
+ if (size.width() < m_atlas_size_limit && size.height() < m_atlas_size_limit) {
+ QHash<unsigned int, QSGCompressedAtlasTexture::Atlas*>::iterator i = m_atlases.find(format);
+ if (i == m_atlases.end())
+ i = m_atlases.insert(format, new QSGCompressedAtlasTexture::Atlas(m_atlas_size, format));
+ // must be multiple of 4
+ QSize paddedSize(((size.width() + 3) / 4) * 4, ((size.height() + 3) / 4) * 4);
+ QByteArray data = factory->m_textureData.data();
+ t = i.value()->create(data, factory->m_textureData.dataLength(), factory->m_textureData.dataOffset(), size, paddedSize);
+ }
+#endif
+}
+
+AtlasBase::AtlasBase(QSGDefaultRenderContext *rc, const QSize &size)
+ : m_rc(rc)
+ , m_rhi(rc->rhi())
+ , m_allocator(size)
+ , m_size(size)
+{
+}
+
+AtlasBase::~AtlasBase()
+{
+ Q_ASSERT(!m_texture);
+}
+
+void AtlasBase::invalidate()
+{
+ delete m_texture;
+ m_texture = nullptr;
+}
+
+void AtlasBase::updateRhiTexture(QRhiResourceUpdateBatch *resourceUpdates)
+{
+ if (!m_allocated) {
+ m_allocated = true;
+ if (!generateTexture()) {
+ qWarning("QSGTextureAtlas: Failed to create texture");
+ return;
+ }
+ }
+
+ for (TextureBase *t : m_pending_uploads) {
+ // ### this profiling is all wrong, the real work is done elsewhere
+ bool profileFrames = QSG_LOG_TIME_TEXTURE().isDebugEnabled();
+ if (profileFrames)
+ qsg_renderer_timer.start();
+
+ Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphTexturePrepare);
+
+ // Skip bind, convert, swizzle; they're irrelevant
+ Q_QUICK_SG_PROFILE_SKIP(QQuickProfiler::SceneGraphTexturePrepare,
+ QQuickProfiler::SceneGraphTexturePrepareStart, 3);
+
+ enqueueTextureUpload(t, resourceUpdates);
+
+ Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphTexturePrepare,
+ QQuickProfiler::SceneGraphTexturePrepareUpload);
+
+ // Skip mipmap; unused
+ Q_QUICK_SG_PROFILE_SKIP(QQuickProfiler::SceneGraphTexturePrepare,
+ QQuickProfiler::SceneGraphTexturePrepareUpload, 1);
+ Q_QUICK_SG_PROFILE_REPORT(QQuickProfiler::SceneGraphTexturePrepare,
+ QQuickProfiler::SceneGraphTexturePrepareMipmap);
+ }
+
+ m_pending_uploads.clear();
+}
+
+void AtlasBase::remove(TextureBase *t)
+{
+ QRect atlasRect = t->atlasSubRect();
+ m_allocator.deallocate(atlasRect);
+ m_pending_uploads.removeOne(t);
+}
+
+Atlas::Atlas(QSGDefaultRenderContext *rc, const QSize &size)
+ : AtlasBase(rc, size)
+{
+ // use RGBA texture internally as that is the only one guaranteed to be always supported
+ m_format = QRhiTexture::RGBA8;
+
+ m_debug_overlay = qt_sg_envInt("QSG_ATLAS_OVERLAY", 0);
+
+ // images smaller than this will retain their QImage.
+ // by default no images are retained (favoring memory)
+ // set to a very large value to retain all images (allowing quick removal from the atlas)
+ m_atlas_transient_image_threshold = qt_sg_envInt("QSG_ATLAS_TRANSIENT_IMAGE_THRESHOLD", 0);
+}
+
+Atlas::~Atlas()
+{
+}
+
+Texture *Atlas::create(const QImage &image)
+{
+ // No need to lock, as manager already locked it.
+ QRect rect = m_allocator.allocate(QSize(image.width() + 2, image.height() + 2));
+ if (rect.width() > 0 && rect.height() > 0) {
+ Texture *t = new Texture(this, rect, image);
+ m_pending_uploads << t;
+ return t;
+ }
+ return nullptr;
+}
+
+bool Atlas::generateTexture()
+{
+ m_texture = m_rhi->newTexture(m_format, m_size, 1, QRhiTexture::UsedAsTransferSource);
+ if (!m_texture)
+ return false;
+
+ if (!m_texture->build()) {
+ delete m_texture;
+ m_texture = nullptr;
+ return false;
+ }
+
+ return true;
+}
+
+void Atlas::enqueueTextureUpload(TextureBase *t, QRhiResourceUpdateBatch *resourceUpdates)
+{
+ Texture *tex = static_cast<Texture *>(t);
+ const QRect &r = tex->atlasSubRect();
+ QImage image = tex->image();
+
+ if (image.isNull())
+ return;
+
+ if (image.format() != QImage::Format_RGBA8888_Premultiplied)
+ image = std::move(image).convertToFormat(QImage::Format_RGBA8888_Premultiplied);
+
+ if (m_debug_overlay) {
+ QPainter p(&image);
+ p.setCompositionMode(QPainter::CompositionMode_SourceAtop);
+ p.fillRect(0, 0, image.width(), image.height(), QBrush(QColor::fromRgbF(0, 1, 1, 0.5)));
+ }
+
+ const int iw = image.width();
+ const int ih = image.height();
+ const int bpl = image.bytesPerLine() / 4;
+ QVarLengthArray<quint32, 1024> tmpBits(qMax(iw + 2, ih + 2));
+ const int tmpBitsSize = tmpBits.size() * 4;
+ const quint32 *src = reinterpret_cast<const quint32 *>(image.constBits());
+ quint32 *dst = tmpBits.data();
+ QVarLengthArray<QRhiTextureUploadEntry, 5> entries;
+
+ // top row, padding corners
+ dst[0] = src[0];
+ memcpy(dst + 1, src, iw * sizeof(quint32));
+ dst[1 + iw] = src[iw - 1];
+ {
+ QRhiTextureSubresourceUploadDescription subresDesc(dst, tmpBitsSize);
+ subresDesc.setDestinationTopLeft(QPoint(r.x(), r.y()));
+ subresDesc.setSourceSize(QSize(iw + 2, 1));
+ entries.append(QRhiTextureUploadEntry(0, 0, subresDesc));
+ }
+
+ // bottom row, padded corners
+ const quint32 *lastRow = src + bpl * (ih - 1);
+ dst[0] = lastRow[0];
+ memcpy(dst + 1, lastRow, iw * sizeof(quint32));
+ dst[1 + iw] = lastRow[iw - 1];
+ {
+ QRhiTextureSubresourceUploadDescription subresDesc(dst, tmpBitsSize);
+ subresDesc.setDestinationTopLeft(QPoint(r.x(), r.y() + ih + 1));
+ subresDesc.setSourceSize(QSize(iw + 2, 1));
+ entries.append(QRhiTextureUploadEntry(0, 0, subresDesc));
+ }
+
+ // left column
+ for (int i = 0; i < ih; ++i)
+ dst[i] = src[i * bpl];
+ {
+ QRhiTextureSubresourceUploadDescription subresDesc(dst, tmpBitsSize);
+ subresDesc.setDestinationTopLeft(QPoint(r.x(), r.y() + 1));
+ subresDesc.setSourceSize(QSize(1, ih));
+ entries.append(QRhiTextureUploadEntry(0, 0, subresDesc));
+ }
+
+
+ // right column
+ for (int i = 0; i < ih; ++i)
+ dst[i] = src[i * bpl + iw - 1];
+ {
+ QRhiTextureSubresourceUploadDescription subresDesc(dst, tmpBitsSize);
+ subresDesc.setDestinationTopLeft(QPoint(r.x() + iw + 1, r.y() + 1));
+ subresDesc.setSourceSize(QSize(1, ih));
+ entries.append(QRhiTextureUploadEntry(0, 0, subresDesc));
+ }
+
+ // Inner part of the image....
+ if (bpl != iw) {
+ int sy = r.y() + 1;
+ int ey = sy + r.height() - 2;
+ entries.reserve(4 + (ey - sy));
+ for (int y = sy; y < ey; ++y) {
+ QRhiTextureSubresourceUploadDescription subresDesc(src, image.bytesPerLine());
+ subresDesc.setDestinationTopLeft(QPoint(r.x() + 1, y));
+ subresDesc.setSourceSize(QSize(r.width() - 2, 1));
+ entries.append(QRhiTextureUploadEntry(0, 0, subresDesc));
+ src += bpl;
+ }
+ } else {
+ QRhiTextureSubresourceUploadDescription subresDesc(src, image.sizeInBytes());
+ subresDesc.setDestinationTopLeft(QPoint(r.x() + 1, r.y() + 1));
+ subresDesc.setSourceSize(QSize(r.width() - 2, r.height() - 2));
+ entries.append(QRhiTextureUploadEntry(0, 0, subresDesc));
+ }
+
+ QRhiTextureUploadDescription desc;
+ desc.setEntries(entries.cbegin(), entries.cend());
+ resourceUpdates->uploadTexture(m_texture, desc);
+
+ const QSize textureSize = t->textureSize();
+ if (textureSize.width() > m_atlas_transient_image_threshold || textureSize.height() > m_atlas_transient_image_threshold)
+ tex->releaseImage();
+
+ qCDebug(QSG_LOG_TIME_TEXTURE, "atlastexture upload enqueued in: %lldms (%dx%d)",
+ qsg_renderer_timer.elapsed(),
+ t->textureSize().width(),
+ t->textureSize().height());
+}
+
+TextureBase::TextureBase(AtlasBase *atlas, const QRect &textureRect)
+ : QSGTexture(*(new TextureBasePrivate))
+ , m_allocated_rect(textureRect)
+ , m_atlas(atlas)
+{
+}
+
+TextureBase::~TextureBase()
+{
+ m_atlas->remove(this);
+}
+
+QRhiResourceUpdateBatch *TextureBase::workResourceUpdateBatch() const
+{
+ Q_D(const TextureBase);
+ return d->workResourceUpdateBatch;
+}
+
+int TextureBasePrivate::comparisonKey() const
+{
+ Q_Q(const TextureBase);
+
+ // We need special care here: a typical comparisonKey() implementation
+ // returns a unique result when there is no underlying texture yet. This is
+ // not quite ideal for atlasing however since textures with the same atlas
+ // should be considered equal regardless of the state of the underlying
+ // graphics resources.
+
+ // base the comparison on the atlas ptr; this way textures for the same
+ // atlas are considered equal
+ return int(qintptr(q->m_atlas));
+}
+
+QRhiTexture *TextureBasePrivate::rhiTexture() const
+{
+ Q_Q(const TextureBase);
+ return q->m_atlas->m_texture;
+}
+
+void TextureBasePrivate::updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
+{
+ Q_Q(TextureBase);
+#ifdef QT_NO_DEBUG
+ Q_UNUSED(rhi);
+#endif
+ Q_ASSERT(rhi == q->m_atlas->m_rhi);
+ q->m_atlas->updateRhiTexture(resourceUpdates);
+}
+
+Texture::Texture(Atlas *atlas, const QRect &textureRect, const QImage &image)
+ : TextureBase(atlas, textureRect)
+ , m_image(image)
+ , m_has_alpha(image.hasAlphaChannel())
+{
+ float w = atlas->size().width();
+ float h = atlas->size().height();
+ QRect nopad = atlasSubRectWithoutPadding();
+ m_texture_coords_rect = QRectF(nopad.x() / w,
+ nopad.y() / h,
+ nopad.width() / w,
+ nopad.height() / h);
+}
+
+Texture::~Texture()
+{
+ if (m_nonatlas_texture)
+ delete m_nonatlas_texture;
+}
+
+QSGTexture *Texture::removedFromAtlas() const
+{
+ if (!m_nonatlas_texture) {
+ m_nonatlas_texture = new QSGPlainTexture;
+ if (!m_image.isNull()) {
+ m_nonatlas_texture->setImage(m_image);
+ m_nonatlas_texture->setFiltering(filtering());
+ } else {
+ QSGDefaultRenderContext *rc = m_atlas->renderContext();
+ QRhi *rhi = m_atlas->rhi();
+ Q_ASSERT(rhi->isRecordingFrame());
+ const QRect r = atlasSubRectWithoutPadding();
+
+ QRhiTexture *extractTex = rhi->newTexture(m_atlas->texture()->format(), r.size());
+ if (extractTex->build()) {
+ bool ownResUpd = false;
+ QRhiResourceUpdateBatch *resUpd = workResourceUpdateBatch(); // ### Qt 6: should be an arg to this function
+ if (!resUpd) {
+ ownResUpd = true;
+ resUpd = rhi->nextResourceUpdateBatch();
+ }
+ QRhiTextureCopyDescription desc;
+ desc.setSourceTopLeft(r.topLeft());
+ desc.setPixelSize(r.size());
+ resUpd->copyTexture(extractTex, m_atlas->texture(), desc);
+ if (ownResUpd)
+ rc->currentFrameCommandBuffer()->resourceUpdate(resUpd);
+ }
+
+ m_nonatlas_texture->setTexture(extractTex);
+ m_nonatlas_texture->setOwnsTexture(true);
+ m_nonatlas_texture->setHasAlphaChannel(m_has_alpha);
+ m_nonatlas_texture->setTextureSize(r.size());
+ }
+ }
+
+ m_nonatlas_texture->setMipmapFiltering(mipmapFiltering());
+ m_nonatlas_texture->setFiltering(filtering());
+ return m_nonatlas_texture;
+}
+
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qsgrhiatlastexture_p.cpp"
diff --git a/src/quick/scenegraph/util/qsgrhiatlastexture_p.h b/src/quick/scenegraph/util/qsgrhiatlastexture_p.h
new file mode 100644
index 0000000000..50d7b2a53f
--- /dev/null
+++ b/src/quick/scenegraph/util/qsgrhiatlastexture_p.h
@@ -0,0 +1,217 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGRHIATLASTEXTURE_P_H
+#define QSGRHIATLASTEXTURE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/QSize>
+#include <QtQuick/private/qsgplaintexture_p.h>
+#include <QtQuick/private/qsgareaallocator_p.h>
+#include <QtGui/QSurface>
+#include <QtGui/private/qrhi_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGDefaultRenderContext;
+
+namespace QSGCompressedAtlasTexture {
+ class Atlas;
+}
+class QSGCompressedTextureFactory;
+
+namespace QSGRhiAtlasTexture
+{
+
+class Texture;
+class TextureBase;
+class TextureBasePrivate;
+class Atlas;
+
+class Manager : public QObject
+{
+ Q_OBJECT
+
+public:
+ Manager(QSGDefaultRenderContext *rc, const QSize &surfacePixelSize, QSurface *maybeSurface);
+ ~Manager();
+
+ QSGTexture *create(const QImage &image, bool hasAlphaChannel);
+ QSGTexture *create(const QSGCompressedTextureFactory *factory);
+ void invalidate();
+
+private:
+ QSGDefaultRenderContext *m_rc;
+ QRhi *m_rhi;
+ Atlas *m_atlas = nullptr;
+ // set of atlases for different compressed formats
+ QHash<unsigned int, QSGCompressedAtlasTexture::Atlas*> m_atlases;
+
+ QSize m_atlas_size;
+ int m_atlas_size_limit;
+};
+
+class AtlasBase : public QObject
+{
+ Q_OBJECT
+public:
+ AtlasBase(QSGDefaultRenderContext *rc, const QSize &size);
+ ~AtlasBase();
+
+ void invalidate();
+ void updateRhiTexture(QRhiResourceUpdateBatch *resourceUpdates);
+ void remove(TextureBase *t);
+
+ QSGDefaultRenderContext *renderContext() const { return m_rc; }
+ QRhi *rhi() const { return m_rhi; }
+ QRhiTexture *texture() const { return m_texture; }
+ QSize size() const { return m_size; }
+
+protected:
+ virtual bool generateTexture() = 0;
+ virtual void enqueueTextureUpload(TextureBase *t, QRhiResourceUpdateBatch *resourceUpdates) = 0;
+
+protected:
+ QSGDefaultRenderContext *m_rc;
+ QRhi *m_rhi;
+ QSGAreaAllocator m_allocator;
+ QRhiTexture *m_texture = nullptr;
+ QSize m_size;
+ QVector<TextureBase *> m_pending_uploads;
+ friend class TextureBase;
+ friend class TextureBasePrivate;
+
+private:
+ bool m_allocated = false;
+};
+
+class Atlas : public AtlasBase
+{
+public:
+ Atlas(QSGDefaultRenderContext *rc, const QSize &size);
+ ~Atlas();
+
+ bool generateTexture() override;
+ void enqueueTextureUpload(TextureBase *t, QRhiResourceUpdateBatch *resourceUpdates) override;
+
+ Texture *create(const QImage &image);
+
+ QRhiTexture::Format format() const { return m_format; }
+
+private:
+ QRhiTexture::Format m_format;
+ int m_atlas_transient_image_threshold = 0;
+
+ uint m_debug_overlay : 1;
+};
+
+class TextureBase : public QSGTexture
+{
+ Q_DECLARE_PRIVATE(TextureBase)
+ Q_OBJECT
+public:
+ TextureBase(AtlasBase *atlas, const QRect &textureRect);
+ ~TextureBase();
+
+ int textureId() const override { return 0; } // not used
+ void bind() override { } // not used
+
+ bool isAtlasTexture() const override { return true; }
+ QRect atlasSubRect() const { return m_allocated_rect; }
+
+ QRhiResourceUpdateBatch *workResourceUpdateBatch() const;
+
+protected:
+ QRect m_allocated_rect;
+ AtlasBase *m_atlas;
+};
+
+class TextureBasePrivate : public QSGTexturePrivate
+{
+ Q_DECLARE_PUBLIC(TextureBase)
+public:
+ int comparisonKey() const override;
+ QRhiTexture *rhiTexture() const override;
+ void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) override;
+};
+
+class Texture : public TextureBase
+{
+ Q_OBJECT
+public:
+ Texture(Atlas *atlas, const QRect &textureRect, const QImage &image);
+ ~Texture();
+
+ QSize textureSize() const override { return atlasSubRectWithoutPadding().size(); }
+ void setHasAlphaChannel(bool alpha) { m_has_alpha = alpha; }
+ bool hasAlphaChannel() const override { return m_has_alpha; }
+ bool hasMipmaps() const override { return false; }
+
+ QRectF normalizedTextureSubRect() const override { return m_texture_coords_rect; }
+
+ QRect atlasSubRect() const { return m_allocated_rect; }
+ QRect atlasSubRectWithoutPadding() const { return m_allocated_rect.adjusted(1, 1, -1, -1); }
+
+ QSGTexture *removedFromAtlas() const override;
+
+ void releaseImage() { m_image = QImage(); }
+ const QImage &image() const { return m_image; }
+
+private:
+ QRectF m_texture_coords_rect;
+ QImage m_image;
+ mutable QSGPlainTexture *m_nonatlas_texture = nullptr;
+ bool m_has_alpha;
+};
+
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/quick/scenegraph/util/qsgrhinativetextureimporter.cpp b/src/quick/scenegraph/util/qsgrhinativetextureimporter.cpp
new file mode 100644
index 0000000000..7a7c19f587
--- /dev/null
+++ b/src/quick/scenegraph/util/qsgrhinativetextureimporter.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgrhinativetextureimporter_p.h"
+#include <private/qsgrhisupport_p.h> // to get all the relevant qrhi headers
+
+QT_BEGIN_NAMESPACE
+
+void QSGRhiNativeTextureImporter::buildWrapper(QRhi *rhi, QRhiTexture *t,
+ const void *nativeObjectPtr, int nativeLayout)
+{
+#if !QT_CONFIG(vulkan)
+ Q_UNUSED(nativeLayout);
+#endif
+#if !QT_CONFIG(opengl) && !QT_CONFIG(vulkan) && !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN)
+ Q_UNUSED(nativeObjectPtr);
+#endif
+
+ switch (rhi->backend()) {
+ case QRhi::OpenGLES2:
+ {
+#if QT_CONFIG(opengl)
+ QRhiGles2TextureNativeHandles h;
+ h.texture = *reinterpret_cast<const uint *>(nativeObjectPtr);
+ t->buildFrom(&h);
+#endif
+ }
+ break;
+ case QRhi::Vulkan:
+ {
+#if QT_CONFIG(vulkan)
+ QRhiVulkanTextureNativeHandles h;
+ h.image = *reinterpret_cast<const VkImage *>(nativeObjectPtr);
+ h.layout = VkImageLayout(nativeLayout);
+ t->buildFrom(&h);
+#endif
+ }
+ break;
+ case QRhi::D3D11:
+ {
+#ifdef Q_OS_WIN
+ QRhiD3D11TextureNativeHandles h;
+ h.texture = *reinterpret_cast<void * const *>(nativeObjectPtr);
+ t->buildFrom(&h);
+#endif
+ }
+ break;
+ case QRhi::Metal:
+ {
+#ifdef Q_OS_DARWIN
+ QRhiMetalTextureNativeHandles h;
+ h.texture = *reinterpret_cast<void * const *>(nativeObjectPtr);
+ t->buildFrom(&h);
+#endif
+ }
+ break;
+ case QRhi::Null:
+ t->build();
+ break;
+ default:
+ qWarning("QSGRhiNativeTextureImporter: encountered an unsupported QRhi backend (%d)",
+ int(rhi->backend()));
+ t->build();
+ break;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgrhinativetextureimporter_p.h b/src/quick/scenegraph/util/qsgrhinativetextureimporter_p.h
new file mode 100644
index 0000000000..e811109a94
--- /dev/null
+++ b/src/quick/scenegraph/util/qsgrhinativetextureimporter_p.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGRHINATIVETEXTUREIMPORTER_P_H
+#define QSGRHINATIVETEXTUREIMPORTER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuick/private/qtquickglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QRhi;
+class QRhiTexture;
+
+class QSGRhiNativeTextureImporter
+{
+public:
+ static void buildWrapper(QRhi *rhi, QRhiTexture *t,
+ const void *nativeObjectPtr, int nativeLayout);
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGRHINATIVETEXTUREIMPORTER_P_H
diff --git a/src/quick/scenegraph/util/qsgsimplematerial.cpp b/src/quick/scenegraph/util/qsgsimplematerial.cpp
index 376f7dce5c..1064caccc7 100644
--- a/src/quick/scenegraph/util/qsgsimplematerial.cpp
+++ b/src/quick/scenegraph/util/qsgsimplematerial.cpp
@@ -46,8 +46,9 @@
\inmodule QtQuick
\ingroup qtquick-scenegraph-materials
- \warning This utility class is only functional when running with the OpenGL
- backend of the Qt Quick scenegraph.
+ \warning This utility class is only functional when running with the legacy
+ OpenGL renderer of the Qt Quick scenegraph. Its usage is not recommended in
+ new application code.
Where the QSGMaterial and QSGMaterialShader API requires a bit of
boilerplate code to create a functioning material, the
diff --git a/src/quick/scenegraph/util/qsgsimplerectnode.cpp b/src/quick/scenegraph/util/qsgsimplerectnode.cpp
index 28b177be84..7b96a3fdde 100644
--- a/src/quick/scenegraph/util/qsgsimplerectnode.cpp
+++ b/src/quick/scenegraph/util/qsgsimplerectnode.cpp
@@ -49,10 +49,10 @@ QT_BEGIN_NAMESPACE
solid filled rectangles using scenegraph.
\inmodule QtQuick
- \warning This utility class is only functional when running with the OpenGL
- or software backends of the Qt Quick scenegraph. For a proper cross-platform
- alternative prefer using QSGRectangleNode via
- QQuickWindow::createRectangleNode() or QSGEngine::createRectangleNode().
+ \warning This utility class is only functional when running with the default
+ or software backends of the Qt Quick scenegraph. As an alternative, prefer
+ using QSGRectangleNode via QQuickWindow::createRectangleNode() or
+ QSGEngine::createRectangleNode().
\deprecated
*/
diff --git a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
index 0c49ca9aa5..1d0a423aa9 100644
--- a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
+++ b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
@@ -97,10 +97,10 @@ static void qsgsimpletexturenode_update(QSGGeometry *g,
\warning The simple texture node class must have a texture before being
added to the scene graph to be rendered.
- \warning This utility class is only functional when running with the OpenGL
- or software backends of the Qt Quick scenegraph. For a proper cross-platform
- alternative prefer using QSGImageNode via
- QQuickWindow::createImageNode() or QSGEngine::createImageNode().
+ \warning This utility class is only functional when running with the default
+ or software backends of the Qt Quick scenegraph. As an alternative, prefer
+ using QSGImageNode via QQuickWindow::createImageNode() or
+ QSGEngine::createImageNode().
\deprecated
*/
diff --git a/src/quick/scenegraph/util/qsgtexturematerial.cpp b/src/quick/scenegraph/util/qsgtexturematerial.cpp
index 7b1d5abb26..67b8748119 100644
--- a/src/quick/scenegraph/util/qsgtexturematerial.cpp
+++ b/src/quick/scenegraph/util/qsgtexturematerial.cpp
@@ -38,23 +38,20 @@
****************************************************************************/
#include "qsgtexturematerial_p.h"
-#include "qsgtexture_p.h"
+#include <private/qsgtexture_p.h>
#if QT_CONFIG(opengl)
# include <QtGui/qopenglshaderprogram.h>
# include <QtGui/qopenglfunctions.h>
#endif
+#include <QtGui/private/qrhi_p.h>
QT_BEGIN_NAMESPACE
-#if QT_CONFIG(opengl)
inline static bool isPowerOfTwo(int x)
{
// Assumption: x >= 1
return x == (x & -x);
}
-#endif
-
-QSGMaterialType QSGOpaqueTextureMaterialShader::type;
QSGOpaqueTextureMaterialShader::QSGOpaqueTextureMaterialShader()
{
@@ -122,6 +119,60 @@ void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMa
}
+QSGOpaqueTextureMaterialRhiShader::QSGOpaqueTextureMaterialRhiShader()
+{
+ setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/opaquetexture.vert.qsb"));
+ setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/opaquetexture.frag.qsb"));
+}
+
+bool QSGOpaqueTextureMaterialRhiShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *)
+{
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+
+ if (state.isMatrixDirty()) {
+ const QMatrix4x4 m = state.combinedMatrix();
+ memcpy(buf->data(), m.constData(), 64);
+ changed = true;
+ }
+
+ return changed;
+}
+
+void QSGOpaqueTextureMaterialRhiShader::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ if (binding != 1)
+ return;
+
+#ifdef QT_NO_DEBUG
+ Q_UNUSED(oldMaterial);
+#endif
+ Q_ASSERT(oldMaterial == nullptr || newMaterial->type() == oldMaterial->type());
+ QSGOpaqueTextureMaterial *tx = static_cast<QSGOpaqueTextureMaterial *>(newMaterial);
+ QSGTexture *t = tx->texture();
+
+ t->setFiltering(tx->filtering());
+ t->setMipmapFiltering(tx->mipmapFiltering());
+ t->setAnisotropyLevel(tx->anisotropyLevel());
+
+ t->setHorizontalWrapMode(tx->horizontalWrapMode());
+ t->setVerticalWrapMode(tx->verticalWrapMode());
+ if (!state.rhi()->isFeatureSupported(QRhi::NPOTTextureRepeat)) {
+ QSize size = t->textureSize();
+ const bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height());
+ if (isNpot) {
+ t->setHorizontalWrapMode(QSGTexture::ClampToEdge);
+ t->setVerticalWrapMode(QSGTexture::ClampToEdge);
+ t->setMipmapFiltering(QSGTexture::None);
+ }
+ }
+
+ t->updateRhiTexture(state.rhi(), state.resourceUpdateBatch());
+ *texture = t;
+}
+
+
/*!
\class QSGOpaqueTextureMaterial
\brief The QSGOpaqueTextureMaterial class provides a convenient way of
@@ -129,8 +180,8 @@ void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMa
\inmodule QtQuick
\ingroup qtquick-scenegraph-materials
- \warning This utility class is only functional when running with the OpenGL
- backend of the Qt Quick scenegraph.
+ \warning This utility class is only functional when running with the
+ default backend of the Qt Quick scenegraph.
The opaque textured material will fill every pixel in a geometry with
the supplied texture. The material does not respect the opacity of the
@@ -175,6 +226,7 @@ QSGOpaqueTextureMaterial::QSGOpaqueTextureMaterial()
, m_vertical_wrap(QSGTexture::ClampToEdge)
, m_anisotropy_level(QSGTexture::AnisotropyNone)
{
+ setFlag(SupportsRhiShader, true);
}
@@ -183,7 +235,8 @@ QSGOpaqueTextureMaterial::QSGOpaqueTextureMaterial()
*/
QSGMaterialType *QSGOpaqueTextureMaterial::type() const
{
- return &QSGOpaqueTextureMaterialShader::type;
+ static QSGMaterialType type;
+ return &type;
}
/*!
@@ -191,11 +244,13 @@ QSGMaterialType *QSGOpaqueTextureMaterial::type() const
*/
QSGMaterialShader *QSGOpaqueTextureMaterial::createShader() const
{
- return new QSGOpaqueTextureMaterialShader;
+ if (flags().testFlag(RhiShaderWanted))
+ return new QSGOpaqueTextureMaterialRhiShader;
+ else
+ return new QSGOpaqueTextureMaterialShader;
}
-
/*!
\fn QSGTexture *QSGOpaqueTextureMaterial::texture() const
@@ -323,7 +378,7 @@ int QSGOpaqueTextureMaterial::compare(const QSGMaterial *o) const
{
Q_ASSERT(o && type() == o->type());
const QSGOpaqueTextureMaterial *other = static_cast<const QSGOpaqueTextureMaterial *>(o);
- if (int diff = m_texture->textureId() - other->texture()->textureId())
+ if (int diff = m_texture->comparisonKey() - other->texture()->comparisonKey())
return diff;
return int(m_filtering) - int(other->m_filtering);
}
@@ -337,8 +392,8 @@ int QSGOpaqueTextureMaterial::compare(const QSGMaterial *o) const
\inmodule QtQuick
\ingroup qtquick-scenegraph-materials
- \warning This utility class is only functional when running with the OpenGL
- backend of the Qt Quick scenegraph.
+ \warning This utility class is only functional when running with the
+ default backend of the Qt Quick scenegraph.
The textured material will fill every pixel in a geometry with
the supplied texture.
@@ -363,32 +418,30 @@ int QSGOpaqueTextureMaterial::compare(const QSGMaterial *o) const
a material in the scene graph.
*/
-QSGMaterialType QSGTextureMaterialShader::type;
-
-
-
/*!
\internal
*/
QSGMaterialType *QSGTextureMaterial::type() const
{
- return &QSGTextureMaterialShader::type;
+ static QSGMaterialType type;
+ return &type;
}
-
-
/*!
\internal
*/
QSGMaterialShader *QSGTextureMaterial::createShader() const
{
- return new QSGTextureMaterialShader;
+ if (flags().testFlag(RhiShaderWanted))
+ return new QSGTextureMaterialRhiShader;
+ else
+ return new QSGTextureMaterialShader;
}
+
QSGTextureMaterialShader::QSGTextureMaterialShader()
- : QSGOpaqueTextureMaterialShader()
{
#if QT_CONFIG(opengl)
setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/texture.frag"));
@@ -413,4 +466,27 @@ void QSGTextureMaterialShader::initialize()
#endif
}
+
+QSGTextureMaterialRhiShader::QSGTextureMaterialRhiShader()
+{
+ setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/texture.vert.qsb"));
+ setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/texture.frag.qsb"));
+}
+
+bool QSGTextureMaterialRhiShader::updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+{
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+
+ if (state.isOpacityDirty()) {
+ const float opacity = state.opacity();
+ memcpy(buf->data() + 64, &opacity, 4);
+ changed = true;
+ }
+
+ changed |= QSGOpaqueTextureMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
+
+ return changed;
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgtexturematerial_p.h b/src/quick/scenegraph/util/qsgtexturematerial_p.h
index a99e872580..d1ef7d1d7f 100644
--- a/src/quick/scenegraph/util/qsgtexturematerial_p.h
+++ b/src/quick/scenegraph/util/qsgtexturematerial_p.h
@@ -64,15 +64,22 @@ public:
void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;
char const *const *attributeNames() const override;
- static QSGMaterialType type;
-
protected:
void initialize() override;
int m_matrix_id;
};
-class Q_QUICK_PRIVATE_EXPORT QSGTextureMaterialShader : public QSGOpaqueTextureMaterialShader
+class Q_QUICK_PRIVATE_EXPORT QSGOpaqueTextureMaterialRhiShader : public QSGMaterialRhiShader
+{
+public:
+ QSGOpaqueTextureMaterialRhiShader();
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+ void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+class QSGTextureMaterialShader : public QSGOpaqueTextureMaterialShader
{
public:
QSGTextureMaterialShader();
@@ -80,12 +87,18 @@ public:
void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;
void initialize() override;
- static QSGMaterialType type;
-
protected:
int m_opacity_id;
};
+class QSGTextureMaterialRhiShader : public QSGOpaqueTextureMaterialRhiShader
+{
+public:
+ QSGTextureMaterialRhiShader();
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
QT_END_NAMESPACE
#endif // QSGTEXTUREMATERIAL_P_H
diff --git a/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp b/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp
index cb61430e2e..c27dd7d1f0 100644
--- a/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp
+++ b/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp
@@ -51,8 +51,6 @@ public:
void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;
char const *const *attributeNames() const override;
- static QSGMaterialType type;
-
private:
void initialize() override;
#if QT_CONFIG(opengl)
@@ -61,8 +59,6 @@ private:
#endif
};
-QSGMaterialType QSGVertexColorMaterialShader::type;
-
QSGVertexColorMaterialShader::QSGVertexColorMaterialShader()
{
#if QT_CONFIG(opengl)
@@ -99,6 +95,43 @@ void QSGVertexColorMaterialShader::initialize()
}
+class QSGVertexColorMaterialRhiShader : public QSGMaterialRhiShader
+{
+public:
+ QSGVertexColorMaterialRhiShader();
+
+ bool updateUniformData(RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;
+};
+
+QSGVertexColorMaterialRhiShader::QSGVertexColorMaterialRhiShader()
+{
+ setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/vertexcolor.vert.qsb"));
+ setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/vertexcolor.frag.qsb"));
+}
+
+bool QSGVertexColorMaterialRhiShader::updateUniformData(RenderState &state,
+ QSGMaterial * /*newEffect*/,
+ QSGMaterial * /*oldEffect*/)
+{
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+
+ if (state.isMatrixDirty()) {
+ const QMatrix4x4 m = state.combinedMatrix();
+ memcpy(buf->data(), m.constData(), 64);
+ changed = true;
+ }
+
+ if (state.isOpacityDirty()) {
+ const float opacity = state.opacity();
+ memcpy(buf->data() + 64, &opacity, 4);
+ changed = true;
+ }
+
+ return changed;
+}
+
+
/*!
\class QSGVertexColorMaterial
\brief The QSGVertexColorMaterial class provides a convenient way of rendering per-vertex
@@ -107,8 +140,8 @@ void QSGVertexColorMaterialShader::initialize()
\inmodule QtQuick
\ingroup qtquick-scenegraph-materials
- \warning This utility class is only functional when running with the OpenGL
- backend of the Qt Quick scenegraph.
+ \warning This utility class is only functional when running with the
+ default backend of the Qt Quick scenegraph.
The vertex color material will give each vertex in a geometry a color. Pixels between
vertices will be linearly interpolated. The colors can contain transparency.
@@ -135,6 +168,7 @@ void QSGVertexColorMaterialShader::initialize()
QSGVertexColorMaterial::QSGVertexColorMaterial()
{
setFlag(Blending, true);
+ setFlag(SupportsRhiShader, true);
}
@@ -158,7 +192,8 @@ int QSGVertexColorMaterial::compare(const QSGMaterial * /* other */) const
QSGMaterialType *QSGVertexColorMaterial::type() const
{
- return &QSGVertexColorMaterialShader::type;
+ static QSGMaterialType type;
+ return &type;
}
@@ -169,7 +204,10 @@ QSGMaterialType *QSGVertexColorMaterial::type() const
QSGMaterialShader *QSGVertexColorMaterial::createShader() const
{
- return new QSGVertexColorMaterialShader;
+ if (flags().testFlag(RhiShaderWanted))
+ return new QSGVertexColorMaterialRhiShader;
+ else
+ return new QSGVertexColorMaterialShader;
}
QT_END_NAMESPACE
diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp
index 2043b50545..fe5b372da8 100644
--- a/src/quick/util/qquickanimation.cpp
+++ b/src/quick/util/qquickanimation.cpp
@@ -2636,7 +2636,7 @@ QQuickStateActions QQuickPropertyAnimation::createTransitionActions(QQuickStateA
for (int j = 0; j < targets.count(); ++j) {
QQuickStateAction myAction;
QString errorMessage;
- const QString propertyName = props.at(i);
+ const QString &propertyName = props.at(i);
myAction.property = d->createProperty(targets.at(j), propertyName, this, &errorMessage);
if (myAction.property.isValid()) {
if (usingDefaultProperties)
diff --git a/src/quick/util/qquickanimatorjob.cpp b/src/quick/util/qquickanimatorjob.cpp
index 03be78ab15..a9caedec4f 100644
--- a/src/quick/util/qquickanimatorjob.cpp
+++ b/src/quick/util/qquickanimatorjob.cpp
@@ -207,7 +207,7 @@ void QQuickAnimatorProxyJob::setWindow(QQuickWindow *window)
stop();
} else if (!m_controller && m_job) {
- m_controller = QQuickWindowPrivate::get(window)->animationController;
+ m_controller = QQuickWindowPrivate::get(window)->animationController.get();
if (window->isSceneGraphInitialized())
readyToAnimate();
else
diff --git a/src/quick/util/qquickbehavior.cpp b/src/quick/util/qquickbehavior.cpp
index 76d464e7f8..ae5c481e2f 100644
--- a/src/quick/util/qquickbehavior.cpp
+++ b/src/quick/util/qquickbehavior.cpp
@@ -143,7 +143,7 @@ void QQuickBehavior::setAnimation(QQuickAbstractAnimation *animation)
void QQuickBehaviorPrivate::animationStateChanged(QAbstractAnimationJob *, QAbstractAnimationJob::State newState,QAbstractAnimationJob::State)
{
- if (!blockRunningChanged)
+ if (!blockRunningChanged && animation)
animation->notifyRunningChanged(newState == QAbstractAnimationJob::Running);
}
diff --git a/src/quick/util/qquickboundaryrule.cpp b/src/quick/util/qquickboundaryrule.cpp
new file mode 100644
index 0000000000..3558c8bfa0
--- /dev/null
+++ b/src/quick/util/qquickboundaryrule.cpp
@@ -0,0 +1,574 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickboundaryrule_p.h"
+
+#include <qqmlcontext.h>
+#include <qqmlinfo.h>
+#include <private/qqmlproperty_p.h>
+#include <private/qqmlengine_p.h>
+#include <private/qobject_p.h>
+#include <private/qquickanimation_p_p.h>
+#include <QtCore/qloggingcategory.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(lcBR, "qt.quick.boundaryrule")
+
+class QQuickBoundaryReturnJob;
+class QQuickBoundaryRulePrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QQuickBoundaryRule)
+public:
+ QQuickBoundaryRulePrivate() {}
+
+ QQmlProperty property;
+ QEasingCurve easing = QEasingCurve(QEasingCurve::OutQuad);
+ QQuickBoundaryReturnJob *returnAnimationJob = nullptr;
+ // read-only properties, updated on each write()
+ qreal targetValue = 0; // after easing was applied
+ qreal peakOvershoot = 0;
+ qreal currentOvershoot = 0;
+ // settable properties
+ qreal minimum = 0;
+ qreal maximum = 0;
+ qreal minimumOvershoot = 0;
+ qreal maximumOvershoot = 0;
+ qreal overshootScale = 0.5;
+ int returnDuration = 100;
+ QQuickBoundaryRule::OvershootFilter overshootFilter = QQuickBoundaryRule::OvershootFilter::None;
+ bool enabled = true;
+ bool finalized = false;
+
+ qreal easedOvershoot(qreal overshootingValue);
+ void resetOvershoot();
+};
+
+class QQuickBoundaryReturnJob : public QAbstractAnimationJob
+{
+public:
+ QQuickBoundaryReturnJob(QQuickBoundaryRulePrivate *br, qreal to)
+ : QAbstractAnimationJob()
+ , boundaryRule(br)
+ , fromValue(br->targetValue)
+ , toValue(to) {}
+
+ int duration() const override { return boundaryRule->returnDuration; }
+
+ void updateCurrentTime(int) override;
+
+ void updateState(QAbstractAnimationJob::State newState,
+ QAbstractAnimationJob::State oldState) override;
+
+ QQuickBoundaryRulePrivate *boundaryRule;
+ qreal fromValue; // snapshot of initial value from which we're returning
+ qreal toValue; // target property value to which we're returning
+};
+
+void QQuickBoundaryReturnJob::updateCurrentTime(int t)
+{
+ // The easing property tells how to behave when the property is being
+ // externally manipulated beyond the bounds. During returnToBounds()
+ // we run it in reverse, by reversing time.
+ qreal progress = (duration() - t) / qreal(duration());
+ qreal easingValue = boundaryRule->easing.valueForProgress(progress);
+ qreal delta = qAbs(fromValue - toValue) * easingValue;
+ qreal value = (fromValue > toValue ? toValue + delta : toValue - delta);
+ qCDebug(lcBR) << t << "ms" << qRound(progress * 100) << "% easing" << easingValue << "->" << value;
+ QQmlPropertyPrivate::write(boundaryRule->property, value,
+ QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
+}
+
+void QQuickBoundaryReturnJob::updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState)
+{
+ Q_UNUSED(oldState)
+ if (newState == QAbstractAnimationJob::Stopped) {
+ qCDebug(lcBR) << "return animation done";
+ boundaryRule->resetOvershoot();
+ boundaryRule->returnAnimationJob = nullptr;
+ delete this;
+ }
+}
+
+/*!
+ \qmltype BoundaryRule
+ \instantiates QQuickBoundaryRule
+ \inqmlmodule Qt.labs.animation
+ \ingroup qtquick-transitions-animations
+ \ingroup qtquick-interceptors
+ \brief Defines a restriction on the range of values that can be set on a numeric property.
+ \since 5.14
+
+ A BoundaryRule defines the range of values that a particular property is
+ allowed to have. When an out-of-range value would otherwise be set,
+ it applies "resistance" via an easing curve.
+
+ For example, the following BoundaryRule prevents DragHandler from dragging
+ the Rectangle too far:
+
+ \snippet qml/boundaryRule.qml 0
+
+ Note that a property cannot have more than one assigned BoundaryRule.
+
+ \sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation#Behaviors}{Behavior example}, {Qt QML}
+*/
+
+QQuickBoundaryRule::QQuickBoundaryRule(QObject *parent)
+ : QObject(*(new QQuickBoundaryRulePrivate), parent)
+ , QQmlPropertyValueInterceptor()
+{
+}
+
+QQuickBoundaryRule::~QQuickBoundaryRule()
+{
+ Q_D(QQuickBoundaryRule);
+ // stop any running animation and
+ // prevent QQuickBoundaryReturnJob::updateState() from accessing QQuickBoundaryRulePrivate
+ delete d->returnAnimationJob;
+}
+
+/*!
+ \qmlproperty bool QtQuick::BoundaryRule::enabled
+
+ This property holds whether the rule will be enforced when the tracked
+ property changes value.
+
+ By default a BoundaryRule is enabled.
+*/
+bool QQuickBoundaryRule::enabled() const
+{
+ Q_D(const QQuickBoundaryRule);
+ return d->enabled;
+}
+
+void QQuickBoundaryRule::setEnabled(bool enabled)
+{
+ Q_D(QQuickBoundaryRule);
+ if (d->enabled == enabled)
+ return;
+ d->enabled = enabled;
+ emit enabledChanged();
+}
+
+/*!
+ \qmlproperty qreal QtQuick::BoundaryRule::minimum
+
+ This property holds the smallest unconstrained value that the property is
+ allowed to have. If the property is set to a smaller value, it will be
+ constrained by \l easing and \l minimumOvershoot.
+
+ The default is \c 0.
+*/
+qreal QQuickBoundaryRule::minimum() const
+{
+ Q_D(const QQuickBoundaryRule);
+ return d->minimum;
+}
+
+void QQuickBoundaryRule::setMinimum(qreal minimum)
+{
+ Q_D(QQuickBoundaryRule);
+ if (qFuzzyCompare(d->minimum, minimum))
+ return;
+ d->minimum = minimum;
+ emit minimumChanged();
+}
+
+/*!
+ \qmlproperty qreal QtQuick::BoundaryRule::minimumOvershoot
+
+ This property holds the amount that the property is allowed to be
+ less than \l minimum. Whenever the value is less than \l minimum
+ and greater than \c {minimum - minimumOvershoot}, it is constrained
+ by the \l easing curve. When the value attempts to go under
+ \c {minimum - minimumOvershoots} there is a hard stop.
+
+ The default is \c 0.
+*/
+qreal QQuickBoundaryRule::minimumOvershoot() const
+{
+ Q_D(const QQuickBoundaryRule);
+ return d->minimumOvershoot;
+}
+
+void QQuickBoundaryRule::setMinimumOvershoot(qreal minimumOvershoot)
+{
+ Q_D(QQuickBoundaryRule);
+ if (qFuzzyCompare(d->minimumOvershoot, minimumOvershoot))
+ return;
+ d->minimumOvershoot = minimumOvershoot;
+ emit minimumOvershootChanged();
+}
+
+/*!
+ \qmlproperty qreal QtQuick::BoundaryRule::maximum
+
+ This property holds the largest unconstrained value that the property is
+ allowed to have. If the property is set to a larger value, it will be
+ constrained by \l easing and \l maximumOvershoot.
+
+ The default is \c 1.
+*/
+qreal QQuickBoundaryRule::maximum() const
+{
+ Q_D(const QQuickBoundaryRule);
+ return d->maximum;
+}
+
+void QQuickBoundaryRule::setMaximum(qreal maximum)
+{
+ Q_D(QQuickBoundaryRule);
+ if (qFuzzyCompare(d->maximum, maximum))
+ return;
+ d->maximum = maximum;
+ emit maximumChanged();
+}
+
+/*!
+ \qmlproperty qreal QtQuick::BoundaryRule::maximumOvershoot
+
+ This property holds the amount that the property is allowed to be
+ more than \l maximum. Whenever the value is greater than \l maximum
+ and less than \c {maximum + maximumOvershoot}, it is constrained
+ by the \l easing curve. When the value attempts to exceed
+ \c {maximum + maximumOvershoot} there is a hard stop.
+
+ The default is 0.
+*/
+qreal QQuickBoundaryRule::maximumOvershoot() const
+{
+ Q_D(const QQuickBoundaryRule);
+ return d->maximumOvershoot;
+}
+
+void QQuickBoundaryRule::setMaximumOvershoot(qreal maximumOvershoot)
+{
+ Q_D(QQuickBoundaryRule);
+ if (qFuzzyCompare(d->maximumOvershoot, maximumOvershoot))
+ return;
+ d->maximumOvershoot = maximumOvershoot;
+ emit maximumOvershootChanged();
+}
+
+/*!
+ \qmlproperty qreal QtQuick::BoundaryRule::overshootScale
+
+ This property holds the amount by which the \l easing is scaled during the
+ overshoot condition. For example if an Item is restricted from moving more
+ than 100 pixels beyond some limit, and the user (by means of some Input
+ Handler) is trying to drag it 100 pixels past the limit, if overshootScale
+ is set to 1, the user will succeed: the only effect of the easing curve is
+ to change the rate at which the item moves from overshoot 0 to overshoot
+ 100. But if it is set to 0.5, the BoundaryRule provides resistance such
+ that when the user tries to move 100 pixels, the Item will only move 50
+ pixels; and the easing curve modulates the rate of movement such that it
+ may move in sync with the user's attempted movement at the beginning, and
+ then slows down, depending on the shape of the easing curve.
+
+ The default is 0.5.
+*/
+qreal QQuickBoundaryRule::overshootScale() const
+{
+ Q_D(const QQuickBoundaryRule);
+ return d->overshootScale;
+}
+
+void QQuickBoundaryRule::setOvershootScale(qreal overshootScale)
+{
+ Q_D(QQuickBoundaryRule);
+ if (qFuzzyCompare(d->overshootScale, overshootScale))
+ return;
+ d->overshootScale = overshootScale;
+ emit overshootScaleChanged();
+}
+
+/*!
+ \qmlproperty qreal QtQuick::BoundaryRule::currentOvershoot
+
+ This property holds the amount by which the most recently set value of the
+ intercepted property exceeds \l maximum or is less than \l minimum.
+
+ It is positive if the property value exceeds \l maximum, negative if the
+ property value is less than \l minimum, or 0 if the property value is
+ within both boundaries.
+*/
+qreal QQuickBoundaryRule::currentOvershoot() const
+{
+ Q_D(const QQuickBoundaryRule);
+ return d->currentOvershoot;
+}
+
+/*!
+ \qmlproperty qreal QtQuick::BoundaryRule::peakOvershoot
+
+ This property holds the most-positive or most-negative value of
+ \l currentOvershoot that has been seen, until \l returnToBounds() is called.
+
+ This can be useful when the intercepted property value is known to
+ fluctuate, and you want to find and react to the maximum amount of
+ overshoot rather than to the fluctuations.
+
+ \sa overshootFilter
+*/
+qreal QQuickBoundaryRule::peakOvershoot() const
+{
+ Q_D(const QQuickBoundaryRule);
+ return d->peakOvershoot;
+}
+
+/*!
+ \qmlproperty enum QtQuick::BoundaryRule::overshootFilter
+
+ This property specifies the aggregation function that will be applied to
+ the intercepted property value.
+
+ If this is set to \c BoundaryRule.None (the default), the intercepted
+ property will hold a value whose overshoot is limited to \l currentOvershoot.
+ If this is set to \c BoundaryRule.Peak, the intercepted property will hold
+ a value whose overshoot is limited to \l peakOvershoot.
+*/
+QQuickBoundaryRule::OvershootFilter QQuickBoundaryRule::overshootFilter() const
+{
+ Q_D(const QQuickBoundaryRule);
+ return d->overshootFilter;
+}
+
+void QQuickBoundaryRule::setOvershootFilter(OvershootFilter overshootFilter)
+{
+ Q_D(QQuickBoundaryRule);
+ if (d->overshootFilter == overshootFilter)
+ return;
+ d->overshootFilter = overshootFilter;
+ emit overshootFilterChanged();
+}
+
+/*!
+ \qmlmethod bool QtQuick::BoundaryRule::returnToBounds
+
+ Returns the intercepted property to a value between \l minimum and
+ \l maximum, such that \l currentOvershoot and \l peakOvershoot are both
+ zero. This will be animated if \l returnDuration is greater than zero.
+
+ Returns true if the value needed to be adjusted, or false if it was already
+ within bounds.
+*/
+bool QQuickBoundaryRule::returnToBounds()
+{
+ Q_D(QQuickBoundaryRule);
+ if (d->returnAnimationJob) {
+ qCDebug(lcBR) << "animation already in progress";
+ return true;
+ }
+ if (currentOvershoot() > 0) {
+ if (d->returnDuration > 0)
+ d->returnAnimationJob = new QQuickBoundaryReturnJob(d, maximum());
+ else
+ write(maximum());
+ } else if (currentOvershoot() < 0) {
+ if (d->returnDuration > 0)
+ d->returnAnimationJob = new QQuickBoundaryReturnJob(d, minimum());
+ else
+ write(minimum());
+ } else {
+ return false;
+ }
+ if (d->returnAnimationJob) {
+ qCDebug(lcBR) << "animating from" << d->returnAnimationJob->fromValue << "to" << d->returnAnimationJob->toValue;
+ d->returnAnimationJob->start();
+ } else {
+ d->resetOvershoot();
+ qCDebug(lcBR) << "returned to" << d->property.read();
+ }
+ return true;
+}
+
+/*!
+ \qmlproperty qreal QtQuick::BoundaryRule::easing
+
+ This property holds the easing curve to be applied in overshoot mode
+ (whenever the \l minimum or \l maximum constraint is violated, while
+ the value is still within the respective overshoot range).
+
+ The default easing curve is \l QEasingCurve::OutQuad.
+*/
+QEasingCurve QQuickBoundaryRule::easing() const
+{
+ Q_D(const QQuickBoundaryRule);
+ return d->easing;
+}
+
+void QQuickBoundaryRule::setEasing(const QEasingCurve &easing)
+{
+ Q_D(QQuickBoundaryRule);
+ if (d->easing == easing)
+ return;
+ d->easing = easing;
+ emit easingChanged();
+}
+
+/*!
+ \qmlproperty int QtQuick::BoundaryRule::returnDuration
+
+ This property holds the amount of time in milliseconds that
+ \l returnToBounds() will take to return the target property to the nearest bound.
+ If it is set to 0, returnToBounds() will set the property immediately
+ rather than creating an animation job.
+
+ The default is 100 ms.
+*/
+int QQuickBoundaryRule::returnDuration() const
+{
+ Q_D(const QQuickBoundaryRule);
+ return d->returnDuration;
+}
+
+void QQuickBoundaryRule::setReturnDuration(int duration)
+{
+ Q_D(QQuickBoundaryRule);
+ if (d->returnDuration == duration)
+ return;
+ d->returnDuration = duration;
+ emit returnDurationChanged();
+}
+
+void QQuickBoundaryRule::write(const QVariant &value)
+{
+ bool conversionOk = false;
+ qreal rValue = value.toReal(&conversionOk);
+ if (!conversionOk) {
+ qWarning() << "BoundaryRule doesn't work with non-numeric values:" << value;
+ return;
+ }
+ Q_D(QQuickBoundaryRule);
+ bool bypass = !d->enabled || !d->finalized || QQmlEnginePrivate::designerMode();
+ if (bypass) {
+ QQmlPropertyPrivate::write(d->property, value,
+ QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
+ return;
+ }
+
+ qmlExecuteDeferred(this);
+ d->targetValue = d->easedOvershoot(rValue);
+ QQmlPropertyPrivate::write(d->property, d->targetValue,
+ QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
+}
+
+void QQuickBoundaryRule::setTarget(const QQmlProperty &property)
+{
+ Q_D(QQuickBoundaryRule);
+ d->property = property;
+
+ QQmlEnginePrivate *engPriv = QQmlEnginePrivate::get(qmlEngine(this));
+ static int finalizedIdx = -1;
+ if (finalizedIdx < 0)
+ finalizedIdx = metaObject()->indexOfSlot("componentFinalized()");
+ engPriv->registerFinalizeCallback(this, finalizedIdx);
+}
+
+void QQuickBoundaryRule::componentFinalized()
+{
+ Q_D(QQuickBoundaryRule);
+ d->finalized = true;
+}
+
+/*!
+ \internal
+ Given that something is trying to set the target property to \a value,
+ this function applies the easing curve and returns the value that the
+ property should actually get instead.
+*/
+qreal QQuickBoundaryRulePrivate::easedOvershoot(qreal value)
+{
+ qreal ret = value;
+ Q_Q(QQuickBoundaryRule);
+ if (value > maximum) {
+ qreal overshootWas = currentOvershoot;
+ currentOvershoot = value - maximum;
+ if (!qFuzzyCompare(overshootWas, currentOvershoot))
+ emit q->currentOvershootChanged();
+ overshootWas = peakOvershoot;
+ peakOvershoot = qMax(currentOvershoot, peakOvershoot);
+ if (!qFuzzyCompare(overshootWas, peakOvershoot))
+ emit q->peakOvershootChanged();
+ ret = maximum + maximumOvershoot * easing.valueForProgress(
+ (overshootFilter == QQuickBoundaryRule::OvershootFilter::Peak ? peakOvershoot : currentOvershoot)
+ * overshootScale / maximumOvershoot);
+ qCDebug(lcBR).nospace() << value << " overshoots maximum " << maximum << " by "
+ << currentOvershoot << " (peak " << peakOvershoot << "): eased to " << ret;
+ } else if (value < minimum) {
+ qreal overshootWas = currentOvershoot;
+ currentOvershoot = value - minimum;
+ if (!qFuzzyCompare(overshootWas, currentOvershoot))
+ emit q->currentOvershootChanged();
+ overshootWas = peakOvershoot;
+ peakOvershoot = qMin(currentOvershoot, peakOvershoot);
+ if (!qFuzzyCompare(overshootWas, peakOvershoot))
+ emit q->peakOvershootChanged();
+ ret = minimum - minimumOvershoot * easing.valueForProgress(
+ -(overshootFilter == QQuickBoundaryRule::OvershootFilter::Peak ? peakOvershoot : currentOvershoot)
+ * overshootScale / minimumOvershoot);
+ qCDebug(lcBR).nospace() << value << " overshoots minimum " << minimum << " by "
+ << currentOvershoot << " (peak " << peakOvershoot << "): eased to " << ret;
+ } else {
+ resetOvershoot();
+ }
+ return ret;
+}
+
+/*!
+ \internal
+ Resets the currentOvershoot and peakOvershoot
+ properties to zero.
+*/
+void QQuickBoundaryRulePrivate::resetOvershoot()
+{
+ Q_Q(QQuickBoundaryRule);
+ if (!qFuzzyCompare(peakOvershoot, 0)) {
+ peakOvershoot = 0;
+ emit q->peakOvershootChanged();
+ }
+ if (!qFuzzyCompare(currentOvershoot, 0)) {
+ currentOvershoot = 0;
+ emit q->currentOvershootChanged();
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qquickboundaryrule_p.cpp"
diff --git a/src/quick/util/qquickboundaryrule_p.h b/src/quick/util/qquickboundaryrule_p.h
new file mode 100644
index 0000000000..3325b675c5
--- /dev/null
+++ b/src/quick/util/qquickboundaryrule_p.h
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKBOUNDARYRULE_H
+#define QQUICKBOUNDARYRULE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtquickglobal_p.h>
+
+#include <private/qqmlpropertyvalueinterceptor_p.h>
+#include <qqml.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickAbstractAnimation;
+class QQuickBoundaryRulePrivate;
+class Q_QUICK_PRIVATE_EXPORT QQuickBoundaryRule : public QObject, public QQmlPropertyValueInterceptor
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QQuickBoundaryRule)
+
+ Q_INTERFACES(QQmlPropertyValueInterceptor)
+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
+ Q_PROPERTY(qreal minimum READ minimum WRITE setMinimum NOTIFY minimumChanged)
+ Q_PROPERTY(qreal minimumOvershoot READ minimumOvershoot WRITE setMinimumOvershoot NOTIFY minimumOvershootChanged)
+ Q_PROPERTY(qreal maximum READ maximum WRITE setMaximum NOTIFY maximumChanged)
+ Q_PROPERTY(qreal maximumOvershoot READ maximumOvershoot WRITE setMaximumOvershoot NOTIFY maximumOvershootChanged)
+ Q_PROPERTY(qreal overshootScale READ overshootScale WRITE setOvershootScale NOTIFY overshootScaleChanged)
+ Q_PROPERTY(qreal currentOvershoot READ currentOvershoot NOTIFY currentOvershootChanged)
+ Q_PROPERTY(qreal peakOvershoot READ peakOvershoot NOTIFY peakOvershootChanged)
+ Q_PROPERTY(OvershootFilter overshootFilter READ overshootFilter WRITE setOvershootFilter NOTIFY overshootFilterChanged)
+ Q_PROPERTY(QEasingCurve easing READ easing WRITE setEasing NOTIFY easingChanged)
+ Q_PROPERTY(int returnDuration READ returnDuration WRITE setReturnDuration NOTIFY returnDurationChanged)
+
+public:
+ enum OvershootFilter {
+ None,
+ Peak
+ };
+ Q_ENUM(OvershootFilter)
+
+ QQuickBoundaryRule(QObject *parent=nullptr);
+ ~QQuickBoundaryRule();
+
+ void setTarget(const QQmlProperty &) override;
+ void write(const QVariant &value) override;
+
+ bool enabled() const;
+ void setEnabled(bool enabled);
+
+ qreal minimum() const;
+ void setMinimum(qreal minimum);
+ qreal minimumOvershoot() const;
+ void setMinimumOvershoot(qreal minimum);
+
+ qreal maximum() const;
+ void setMaximum(qreal maximum);
+ qreal maximumOvershoot() const;
+ void setMaximumOvershoot(qreal maximum);
+
+ qreal overshootScale() const;
+ void setOvershootScale(qreal scale);
+
+ qreal currentOvershoot() const;
+ qreal peakOvershoot() const;
+
+ OvershootFilter overshootFilter() const;
+ void setOvershootFilter(OvershootFilter overshootFilter);
+
+ Q_INVOKABLE bool returnToBounds();
+
+ QEasingCurve easing() const;
+ void setEasing(const QEasingCurve &easing);
+
+ int returnDuration() const;
+ void setReturnDuration(int duration);
+
+Q_SIGNALS:
+ void enabledChanged();
+ void minimumChanged();
+ void minimumOvershootChanged();
+ void maximumChanged();
+ void maximumOvershootChanged();
+ void overshootScaleChanged();
+ void currentOvershootChanged();
+ void peakOvershootChanged();
+ void overshootFilterChanged();
+ void easingChanged();
+ void returnDurationChanged();
+
+private Q_SLOTS:
+ void componentFinalized();
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickBoundaryRule)
+
+#endif // QQUICKBOUNDARYRULE_H
diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp
index 5337bfd640..527274e6be 100644
--- a/src/quick/util/qquickglobal.cpp
+++ b/src/quick/util/qquickglobal.cpp
@@ -41,7 +41,6 @@
#include <private/qquickvaluetypes_p.h>
#include <private/qquickapplication_p.h>
#include <private/qqmlglobal_p.h>
-#include <private/qv8engine_p.h>
#include <QtGui/QGuiApplication>
#include <QtGui/qdesktopservices.h>
@@ -274,7 +273,7 @@ public:
return QMatrix4x4();
}
- static QFont fontFromObject(QQmlV4Handle object, QV4::ExecutionEngine *v4, bool *ok)
+ static QFont fontFromObject(const QV4::Value &object, QV4::ExecutionEngine *v4, bool *ok)
{
if (ok)
*ok = false;
@@ -373,7 +372,7 @@ public:
return retn;
}
- static QMatrix4x4 matrix4x4FromObject(QQmlV4Handle object, QV4::ExecutionEngine *v4, bool *ok)
+ static QMatrix4x4 matrix4x4FromObject(const QV4::Value &object, QV4::ExecutionEngine *v4, bool *ok)
{
if (ok)
*ok = false;
@@ -639,7 +638,7 @@ public:
return false;
}
- bool variantFromJsObject(int type, QQmlV4Handle object, QV4::ExecutionEngine *v4, QVariant *v) override
+ bool variantFromJsObject(int type, const QV4::Value &object, QV4::ExecutionEngine *v4, QVariant *v) override
{
QV4::Scope scope(v4);
#ifndef QT_NO_DEBUG
diff --git a/src/quick/util/qquickimageprovider_p.h b/src/quick/util/qquickimageprovider_p.h
index b5baf79319..67e17010d4 100644
--- a/src/quick/util/qquickimageprovider_p.h
+++ b/src/quick/util/qquickimageprovider_p.h
@@ -61,7 +61,7 @@ class QQuickImageResponsePrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QQuickImageResponse)
public:
- bool finished = false;
+ QAtomicInteger<qint32> finished = false;
void _q_finished() { finished = true; }
};
diff --git a/src/quick/util/qquickpath.cpp b/src/quick/util/qquickpath.cpp
index 60d725d650..61319c388c 100644
--- a/src/quick/util/qquickpath.cpp
+++ b/src/quick/util/qquickpath.cpp
@@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE
This type is the base for all path types. It cannot
be instantiated.
- \sa Path, PathAttribute, PathPercent, PathLine, PathQuad, PathCubic, PathArc,
+ \sa Path, PathAttribute, PathPercent, PathLine, PathPolyline, PathQuad, PathCubic, PathArc,
PathAngleArc, PathCurve, PathSvg
*/
@@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE
\ingroup qtquick-animation-paths
\brief Defines a path for use by \l PathView and \l Shape.
- A Path is composed of one or more path segments - PathLine, PathQuad,
+ A Path is composed of one or more path segments - PathLine, PathPolyline, PathQuad,
PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg.
The spacing of the items along the Path can be adjusted via a
@@ -104,6 +104,17 @@ QT_BEGIN_NAMESPACE
\li Yes
\li Yes
\row
+ \li PathPolyline
+ \li Yes
+ \li Yes
+ \li Yes
+ \li Yes
+ \li PathMultiLine
+ \li Yes
+ \li Yes
+ \li Yes
+ \li Yes
+ \row
\li PathQuad
\li Yes
\li Yes
@@ -156,7 +167,7 @@ QT_BEGIN_NAMESPACE
\note Path is a non-visual type; it does not display anything on its own.
To draw a path, use \l Shape.
- \sa PathView, Shape, PathAttribute, PathPercent, PathLine, PathMove, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg
+ \sa PathView, Shape, PathAttribute, PathPercent, PathLine, PathPolyline, PathMove, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg
*/
QQuickPath::QQuickPath(QObject *parent)
: QObject(*(new QQuickPathPrivate), parent)
@@ -240,6 +251,8 @@ bool QQuickPath::isClosed() const
A path can contain the following path objects:
\list
\li \l PathLine - a straight line to a given position.
+ \li \l PathPolyline - a polyline specified as a list of coordinates.
+ \li \l PathMultiline - a list of polylines specified as a list of lists of coordinates.
\li \l PathQuad - a quadratic Bezier curve to a given position with a control point.
\li \l PathCubic - a cubic Bezier curve to a given position with two control points.
\li \l PathArc - an arc to a given position with a radius.
@@ -407,6 +420,19 @@ void QQuickPath::processPath()
emit changed();
}
+inline static void scalePath(QPainterPath &path, const QSizeF &scale)
+{
+ const qreal xscale = scale.width();
+ const qreal yscale = scale.height();
+ if (xscale == 1 && yscale == 1)
+ return;
+
+ for (int i = 0; i < path.elementCount(); ++i) {
+ const QPainterPath::Element &element = path.elementAt(i);
+ path.setElementPositionAt(i, element.x * xscale, element.y * yscale);
+ }
+}
+
QPainterPath QQuickPath::createPath(const QPointF &startPoint, const QPointF &endPoint, const QStringList &attributes, qreal &pathLength, QList<AttributePoint> &attributePoints, bool *closed)
{
Q_D(QQuickPath);
@@ -465,7 +491,7 @@ QPainterPath QQuickPath::createPath(const QPointF &startPoint, const QPointF &en
d->_attributePoints.last().values[percentString] = 1;
interpolate(d->_attributePoints.count() - 1, percentString, 1);
}
-
+ scalePath(path, d->scale);
// Adjust percent
qreal length = path.length();
@@ -491,7 +517,7 @@ QPainterPath QQuickPath::createPath(const QPointF &startPoint, const QPointF &en
if (closed) {
QPointF end = path.currentPosition();
- *closed = length > 0 && startX == end.x() && startY == end.y();
+ *closed = length > 0 && startX * d->scale.width() == end.x() && startY * d->scale.height() == end.y();
}
pathLength = length;
@@ -525,6 +551,7 @@ QPainterPath QQuickPath::createShapePath(const QPointF &startPoint, const QPoint
QPointF end = path.currentPosition();
*closed = startX == end.x() && startY == end.y();
}
+ scalePath(path, d->scale);
// Note: Length of paths inside ShapePath is not used, so currently
// length is always 0. This avoids potentially heavy path.length()
@@ -570,7 +597,7 @@ void QQuickPath::gatherAttributes()
attributes.insert(attribute->name());
}
- d->_attributes = attributes.toList();
+ d->_attributes = attributes.values();
}
void QQuickPath::componentComplete()
@@ -603,7 +630,7 @@ QStringList QQuickPath::attributes() const
qobject_cast<QQuickPathAttribute *>(pathElement))
attrs.insert(attribute->name());
}
- return attrs.toList();
+ return attrs.values();
}
return d->_attributes;
}
@@ -723,6 +750,33 @@ void QQuickPath::invalidateSequentialHistory() const
d->prevBez.isValid = false;
}
+/*!
+ \qmlproperty size QtQuick::Path::scale
+
+ This property holds the scale factor for the path.
+ The width and height of \a scale can be different, to
+ achieve anisotropic scaling.
+
+ \note Setting this property will not affect the border width.
+
+ \since QtQuick 2.14
+*/
+QSizeF QQuickPath::scale() const
+{
+ Q_D(const QQuickPath);
+ return d->scale;
+}
+
+void QQuickPath::setScale(const QSizeF &scale)
+{
+ Q_D(QQuickPath);
+ if (scale == d->scale)
+ return;
+ d->scale = scale;
+ emit scaleChanged();
+ processPath();
+}
+
QPointF QQuickPath::sequentialPointAt(qreal p, qreal *angle) const
{
Q_D(const QQuickPath);
@@ -852,9 +906,28 @@ QPointF QQuickPath::backwardsPointAt(const QPainterPath &path, const qreal &path
return QPointF(0,0);
}
-QPointF QQuickPath::pointAt(qreal p) const
+/*!
+ \qmlmethod point Path::pointAtPercent(real t)
+
+ Returns the point at the percentage \a t of the current path.
+ The argument \a t has to be between 0 and 1.
+
+ \note Similarly to other percent methods in \l QPainterPath,
+ the percentage measurement is not linear with regards to the length,
+ if curves are present in the path.
+ When curves are present, the percentage argument is mapped to the \c t
+ parameter of the Bezier equations.
+
+ \sa QPainterPath::pointAt
+
+ \since QtQuick 2.14
+*/
+QPointF QQuickPath::pointAtPercent(qreal t) const
{
Q_D(const QQuickPath);
+ if (d->isShapePath) // this since ShapePath does not calculate the length at all,
+ return d->_path.pointAtPercent(t); // in order to be faster.
+
if (d->_pointCache.isEmpty()) {
createPointCache();
if (d->_pointCache.isEmpty())
@@ -862,7 +935,7 @@ QPointF QQuickPath::pointAt(qreal p) const
}
const int segmentCount = d->_pointCache.size() - 1;
- qreal idxf = p*segmentCount;
+ qreal idxf = t*segmentCount;
int idx1 = qFloor(idxf);
qreal delta = idxf - idx1;
if (idx1 > segmentCount)
@@ -1127,7 +1200,7 @@ void QQuickPathAttribute::setValue(qreal value)
}
\endqml
- \sa Path, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg, PathMove
+ \sa Path, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg, PathMove, PathPolyline
*/
/*!
@@ -2286,6 +2359,266 @@ void QQuickPathPercent::setValue(qreal value)
emit changed();
}
}
+
+/*!
+ \qmltype PathPolyline
+ \instantiates QQuickPathPolyline
+ \inqmlmodule QtQuick
+ \ingroup qtquick-animation-paths
+ \brief Defines a polyline through a list of coordinates.
+ \since QtQuick 2.14
+
+ The example below creates a triangular path consisting of four vertices
+ on the edge of the containing Shape's bounding box.
+ Through the containing shape's \l scale property, the path will be
+ rescaled together with its containing shape.
+
+ \qml
+ PathPolyline {
+ id: ppl
+ path: [ Qt.point(0.0, 0.0),
+ Qt.point(1.0, 0.0),
+ Qt.point(0.5, 1.0),
+ Qt.point(0.0, 0.0)
+ ]
+ }
+ \endqml
+
+ \sa Path, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg, PathMove, PathPolyline
+*/
+
+/*!
+ \qmlproperty point QtQuick::PathPolyline::start
+
+ This read-only property contains the beginning of the polyline.
+*/
+
+/*!
+ \qmlproperty list<point> QtQuick::PathPolyline::path
+
+ This property defines the vertices of the polyline.
+
+ It can be a JS array of points constructed with \c Qt.point(),
+ a QList or QVector of QPointF, or QPolygonF.
+ If you are binding this to a custom property in some C++ object,
+ QPolygonF is the most appropriate type to use.
+*/
+
+QQuickPathPolyline::QQuickPathPolyline(QObject *parent) : QQuickCurve(parent)
+{
+}
+
+QVariant QQuickPathPolyline::path() const
+{
+ return QVariant::fromValue(m_path);
+}
+
+void QQuickPathPolyline::setPath(const QVariant &path)
+{
+ if (path.type() == QVariant::PolygonF) {
+ setPath(path.value<QPolygonF>());
+ } else if (path.canConvert<QVector<QPointF>>()) {
+ setPath(path.value<QVector<QPointF>>());
+ } else if (path.canConvert<QVariantList>()) {
+ // This handles cases other than QPolygonF or QVector<QPointF>, such as
+ // QList<QPointF>, QVector<QPoint>, QVariantList of QPointF, QVariantList of QPoint.
+ QVector<QPointF> pathList;
+ QVariantList vl = path.value<QVariantList>();
+ // If path is a QJSValue, e.g. coming from a JS array of Qt.point() in QML,
+ // then path.value<QVariantList>() is inefficient.
+ // TODO We should be able to iterate over path.value<QSequentialIterable>() eventually
+ for (const QVariant &v : vl)
+ pathList.append(v.toPointF());
+ setPath(pathList);
+ } else {
+ qWarning() << "PathPolyline: path of type" << path.type() << "not supported";
+ }
+}
+
+void QQuickPathPolyline::setPath(const QVector<QPointF> &path)
+{
+ if (m_path != path) {
+ const QPointF &oldStart = start();
+ m_path = path;
+ const QPointF &newStart = start();
+ emit pathChanged();
+ if (oldStart != newStart)
+ emit startChanged();
+ emit changed();
+ }
+}
+
+QPointF QQuickPathPolyline::start() const
+{
+ if (m_path.size()) {
+ const QPointF &p = m_path.first();
+ return p;
+ }
+ return QPointF();
+}
+
+void QQuickPathPolyline::addToPath(QPainterPath &path, const QQuickPathData &/*data*/)
+{
+ if (m_path.size() < 2)
+ return;
+
+ path.moveTo(m_path.first());
+ for (int i = 1; i < m_path.size(); ++i)
+ path.lineTo(m_path.at(i));
+}
+
+
+/*!
+ \qmltype PathMultiline
+ \instantiates QQuickPathMultiline
+ \inqmlmodule QtQuick
+ \ingroup qtquick-animation-paths
+ \brief Defines a set of polylines through a list of lists of coordinates.
+ \since QtQuick 2.14
+
+ This element allows to define a list of polylines at once.
+ Each polyline in the list will be preceded by a \l{QPainterPath::moveTo}{moveTo}
+ command, effectively making each polyline a separate one.
+ The polylines in this list are supposed to be non-intersecting with each other.
+ In any case, when used in conjunction with a \l ShapePath, the containing ShapePath's
+ \l ShapePath::fillRule applies.
+ That is, with the default \c OddEvenFill and non intersecting shapes, the largest shape in the list defines an area to be filled;
+ areas where two shapes overlap are holes; areas where three shapes overlap are filled areas inside holes, etc.
+
+ The example below creates a high voltage symbol by adding each path
+ of the symbol to the list of paths.
+ The coordinates of the vertices are normalized, and through the containing shape's
+ \l scale property, the path will be rescaled together with its containing shape.
+
+ \qml
+ PathMultiline {
+ paths: [
+ [Qt.point(0.5, 0.06698),
+ Qt.point(1, 0.93301),
+ Qt.point(0, 0.93301),
+ Qt.point(0.5, 0.06698)],
+
+ [Qt.point(0.5, 0.12472),
+ Qt.point(0.95, 0.90414),
+ Qt.point(0.05, 0.90414),
+ Qt.point(0.5, 0.12472)],
+
+ [Qt.point(0.47131, 0.32986),
+ Qt.point(0.36229, 0.64789),
+ Qt.point(0.51492, 0.58590),
+ Qt.point(0.47563, 0.76014),
+ Qt.point(0.44950, 0.73590),
+ Qt.point(0.46292, 0.83392),
+ Qt.point(0.52162, 0.75190),
+ Qt.point(0.48531, 0.76230),
+ Qt.point(0.57529, 0.53189),
+ Qt.point(0.41261, 0.59189),
+ Qt.point(0.53001, 0.32786),
+ Qt.point(0.47131, 0.32986)]
+ ]
+ }
+ \endqml
+
+ \sa Path, QPainterPath::setFillRule, PathPolyline, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg, PathMove
+*/
+
+/*!
+ \qmlproperty point QtQuick::PathMultiline::start
+
+ This read-only property contains the beginning of the polylines.
+*/
+
+/*!
+ \qmlproperty list<list<point>> QtQuick::PathMultiline::paths
+
+ This property defines the vertices of the polylines.
+
+ It can be a JS array of JS arrays of points constructed with \c Qt.point(),
+ a QList or QVector of QPolygonF, or QVector<QVector<QPointF>>.
+ If you are binding this to a custom property in some C++ object,
+ QVector<QPolygonF> or QVector<QVector<QPointF>> is the most
+ appropriate type to use.
+*/
+
+QQuickPathMultiline::QQuickPathMultiline(QObject *parent) : QQuickCurve(parent)
+{
+}
+
+QVariant QQuickPathMultiline::paths() const
+{
+ return QVariant::fromValue(m_paths);
+}
+
+void QQuickPathMultiline::setPaths(const QVariant &paths)
+{
+ if (paths.canConvert<QVector<QPolygonF>>()) {
+ const QVector<QPolygonF> pathPolygons = paths.value<QVector<QPolygonF>>();
+ QVector<QVector<QPointF>> pathVectors;
+ for (const QPolygonF &p : pathPolygons)
+ pathVectors << p;
+ setPaths(pathVectors);
+ } else if (paths.canConvert<QVector<QVector<QPointF>>>()) {
+ setPaths(paths.value<QVector<QVector<QPointF>>>());
+ } else if (paths.canConvert<QVariantList>()) {
+ // This handles cases other than QVector<QPolygonF> or QVector<QVector<QPointF>>, such as
+ // QList<QVector<QPointF>>, QList<QList<QPointF>>, QVariantList of QVector<QPointF>,
+ // QVariantList of QVariantList of QPointF, QVector<QList<QPoint>> etc.
+ QVector<QVector<QPointF>> pathsList;
+ QVariantList vll = paths.value<QVariantList>();
+ for (const QVariant &v : vll) {
+ // If we bind a QVector<QPolygonF> property directly, rather than via QVariant,
+ // it will come through as QJSValue that can be converted to QVariantList of QPolygonF.
+ if (v.canConvert<QPolygonF>()) {
+ pathsList.append(v.value<QPolygonF>());
+ } else {
+ QVariantList vl = v.value<QVariantList>();
+ QVector<QPointF> l;
+ for (const QVariant &point : vl) {
+ if (point.canConvert<QPointF>())
+ l.append(point.toPointF());
+ }
+ if (l.size() >= 2)
+ pathsList.append(l);
+ }
+ }
+ setPaths(pathsList);
+ } else {
+ qWarning() << "PathMultiline: paths of type" << paths.type() << "not supported";
+ setPaths(QVector<QVector<QPointF>>());
+ }
+}
+
+void QQuickPathMultiline::setPaths(const QVector<QVector<QPointF>> &paths)
+{
+ if (m_paths != paths) {
+ const QPointF &oldStart = start();
+ m_paths = paths;
+ const QPointF &newStart = start();
+ emit pathsChanged();
+ if (oldStart != newStart)
+ emit startChanged();
+ emit changed();
+ }
+}
+
+QPointF QQuickPathMultiline::start() const
+{
+ if (m_paths.size())
+ return m_paths.first().first();
+ return QPointF();
+}
+
+void QQuickPathMultiline::addToPath(QPainterPath &path, const QQuickPathData &)
+{
+ if (!m_paths.size())
+ return;
+ for (const QVector<QPointF> &p: m_paths) {
+ path.moveTo(p.first());
+ for (int i = 1; i < p.size(); ++i)
+ path.lineTo(p.at(i));
+ }
+}
+
QT_END_NAMESPACE
#include "moc_qquickpath_p.cpp"
diff --git a/src/quick/util/qquickpath_p.h b/src/quick/util/qquickpath_p.h
index 6b9a40fe6d..5987ae8f35 100644
--- a/src/quick/util/qquickpath_p.h
+++ b/src/quick/util/qquickpath_p.h
@@ -290,7 +290,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPathArc : public QQuickCurve
Q_PROPERTY(qreal radiusY READ radiusY WRITE setRadiusY NOTIFY radiusYChanged)
Q_PROPERTY(bool useLargeArc READ useLargeArc WRITE setUseLargeArc NOTIFY useLargeArcChanged)
Q_PROPERTY(ArcDirection direction READ direction WRITE setDirection NOTIFY directionChanged)
- Q_PROPERTY(qreal xAxisRotation READ xAxisRotation WRITE setXAxisRotation NOTIFY xAxisRotationChanged REVISION 2)
+ Q_PROPERTY(qreal xAxisRotation READ xAxisRotation WRITE setXAxisRotation NOTIFY xAxisRotationChanged REVISION 9)
public:
QQuickPathArc(QObject *parent=nullptr)
@@ -321,7 +321,7 @@ Q_SIGNALS:
void radiusYChanged();
void useLargeArcChanged();
void directionChanged();
- Q_REVISION(2) void xAxisRotationChanged();
+ Q_REVISION(9) void xAxisRotationChanged();
private:
qreal _radiusX = 0;
@@ -424,6 +424,52 @@ private:
qreal _value = 0;
};
+class Q_QUICK_PRIVATE_EXPORT QQuickPathPolyline : public QQuickCurve
+{
+ Q_OBJECT
+ Q_PROPERTY(QPointF start READ start NOTIFY startChanged)
+ Q_PROPERTY(QVariant path READ path WRITE setPath NOTIFY pathChanged)
+public:
+ QQuickPathPolyline(QObject *parent=nullptr);
+
+ QVariant path() const;
+ void setPath(const QVariant &path);
+ void setPath(const QVector<QPointF> &path);
+ QPointF start() const;
+ void addToPath(QPainterPath &path, const QQuickPathData &data) override;
+
+Q_SIGNALS:
+ void pathChanged();
+ void startChanged();
+
+private:
+ QVector<QPointF> m_path;
+};
+
+class Q_QUICK_PRIVATE_EXPORT QQuickPathMultiline : public QQuickCurve
+{
+ Q_OBJECT
+ Q_PROPERTY(QPointF start READ start NOTIFY startChanged)
+ Q_PROPERTY(QVariant paths READ paths WRITE setPaths NOTIFY pathsChanged)
+public:
+ QQuickPathMultiline(QObject *parent=nullptr);
+
+ QVariant paths() const;
+ void setPaths(const QVariant &paths);
+ void setPaths(const QVector<QVector<QPointF>> &paths);
+ QPointF start() const;
+ void addToPath(QPainterPath &path, const QQuickPathData &) override;
+
+Q_SIGNALS:
+ void pathsChanged();
+ void startChanged();
+
+private:
+ QPointF absolute(const QPointF &relative) const;
+
+ QVector<QVector<QPointF>> m_paths;
+};
+
struct QQuickCachedBezier
{
QQuickCachedBezier() {}
@@ -445,6 +491,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPath : public QObject, public QQmlParserStatu
Q_PROPERTY(qreal startX READ startX WRITE setStartX NOTIFY startXChanged)
Q_PROPERTY(qreal startY READ startY WRITE setStartY NOTIFY startYChanged)
Q_PROPERTY(bool closed READ isClosed NOTIFY changed)
+ Q_PROPERTY(QSizeF scale READ scale WRITE setScale NOTIFY scaleChanged REVISION 14)
Q_CLASSINFO("DefaultProperty", "pathElements")
Q_INTERFACES(QQmlParserStatus)
public:
@@ -466,14 +513,18 @@ public:
QPainterPath path() const;
QStringList attributes() const;
qreal attributeAt(const QString &, qreal) const;
- QPointF pointAt(qreal) const;
+ Q_REVISION(14) Q_INVOKABLE QPointF pointAtPercent(qreal t) const;
QPointF sequentialPointAt(qreal p, qreal *angle = nullptr) const;
void invalidateSequentialHistory() const;
+ QSizeF scale() const;
+ void setScale(const QSizeF &scale);
+
Q_SIGNALS:
void changed();
void startXChanged();
void startYChanged();
+ Q_REVISION(14) void scaleChanged();
protected:
QQuickPath(QQuickPathPrivate &dd, QObject *parent = nullptr);
@@ -540,6 +591,7 @@ QML_DECLARE_TYPE(QQuickPathArc)
QML_DECLARE_TYPE(QQuickPathAngleArc)
QML_DECLARE_TYPE(QQuickPathSvg)
QML_DECLARE_TYPE(QQuickPathPercent)
+QML_DECLARE_TYPE(QQuickPathPolyline)
QML_DECLARE_TYPE(QQuickPath)
#endif // QQUICKPATH_H
diff --git a/src/quick/util/qquickpath_p_p.h b/src/quick/util/qquickpath_p_p.h
index 9735d51264..e26001ec77 100644
--- a/src/quick/util/qquickpath_p_p.h
+++ b/src/quick/util/qquickpath_p_p.h
@@ -84,6 +84,7 @@ public:
QQmlNullableValue<qreal> startX;
QQmlNullableValue<qreal> startY;
qreal pathLength = 0;
+ QSizeF scale = QSizeF(1, 1);
bool closed = false;
bool componentComplete = true;
bool isShapePath = false;
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp
index ced0acd9ab..56ad8ebf0b 100644
--- a/src/quick/util/qquickpixmapcache.cpp
+++ b/src/quick/util/qquickpixmapcache.cpp
@@ -49,7 +49,7 @@
#include <QtGui/private/qimage_p.h>
#include <qpa/qplatformintegration.h>
-#include <QtQuick/private/qsgtexture_p.h>
+#include <QtQuick/private/qsgcontext_p.h>
#include <QtQuick/private/qsgtexturereader_p.h>
#include <QQuickWindow>
@@ -207,7 +207,7 @@ protected:
private:
friend class QQuickPixmapReaderThreadObject;
void processJobs();
- void processJob(QQuickPixmapReply *, const QUrl &, const QString &, QQuickImageProvider::ImageType, QQuickImageProvider *);
+ void processJob(QQuickPixmapReply *, const QUrl &, const QString &, QQuickImageProvider::ImageType, const QSharedPointer<QQuickImageProvider> &);
#if QT_CONFIG(qml_network)
void networkRequestDone(QNetworkReply *);
#endif
@@ -241,7 +241,7 @@ class QQuickPixmapData
{
public:
QQuickPixmapData(QQuickPixmap *pixmap, const QUrl &u, const QSize &s, const QQuickImageProviderOptions &po, const QString &e)
- : refCount(1), inCache(false), pixmapStatus(QQuickPixmap::Error),
+ : refCount(1), frameCount(1), frame(0), inCache(false), pixmapStatus(QQuickPixmap::Error),
url(u), errorString(e), requestSize(s),
providerOptions(po), appliedTransform(QQuickImageProviderOptions::UsePluginDefaultTransform),
textureFactory(nullptr), reply(nullptr), prevUnreferenced(nullptr),
@@ -250,8 +250,8 @@ public:
declarativePixmaps.insert(pixmap);
}
- QQuickPixmapData(QQuickPixmap *pixmap, const QUrl &u, const QSize &r, const QQuickImageProviderOptions &po, QQuickImageProviderOptions::AutoTransform aTransform)
- : refCount(1), inCache(false), pixmapStatus(QQuickPixmap::Loading),
+ QQuickPixmapData(QQuickPixmap *pixmap, const QUrl &u, const QSize &r, const QQuickImageProviderOptions &po, QQuickImageProviderOptions::AutoTransform aTransform, int frame=0, int frameCount=1)
+ : refCount(1), frameCount(frameCount), frame(frame), inCache(false), pixmapStatus(QQuickPixmap::Loading),
url(u), requestSize(r),
providerOptions(po), appliedTransform(aTransform),
textureFactory(nullptr), reply(nullptr), prevUnreferenced(nullptr), prevUnreferencedPtr(nullptr),
@@ -261,8 +261,8 @@ public:
}
QQuickPixmapData(QQuickPixmap *pixmap, const QUrl &u, QQuickTextureFactory *texture,
- const QSize &s, const QSize &r, const QQuickImageProviderOptions &po, QQuickImageProviderOptions::AutoTransform aTransform)
- : refCount(1), inCache(false), pixmapStatus(QQuickPixmap::Ready),
+ const QSize &s, const QSize &r, const QQuickImageProviderOptions &po, QQuickImageProviderOptions::AutoTransform aTransform, int frame=0, int frameCount=1)
+ : refCount(1), frameCount(frameCount), frame(frame), inCache(false), pixmapStatus(QQuickPixmap::Ready),
url(u), implicitSize(s), requestSize(r),
providerOptions(po), appliedTransform(aTransform),
textureFactory(texture), reply(nullptr), prevUnreferenced(nullptr),
@@ -272,7 +272,7 @@ public:
}
QQuickPixmapData(QQuickPixmap *pixmap, QQuickTextureFactory *texture)
- : refCount(1), inCache(false), pixmapStatus(QQuickPixmap::Ready),
+ : refCount(1), frameCount(1), frame(0), inCache(false), pixmapStatus(QQuickPixmap::Ready),
appliedTransform(QQuickImageProviderOptions::UsePluginDefaultTransform),
textureFactory(texture), reply(nullptr), prevUnreferenced(nullptr),
prevUnreferencedPtr(nullptr), nextUnreferenced(nullptr)
@@ -299,6 +299,8 @@ public:
void removeFromCache();
uint refCount;
+ int frameCount;
+ int frame;
bool inCache:1;
@@ -396,9 +398,9 @@ static void maybeRemoveAlpha(QImage *image)
}
}
-static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *errorString, QSize *impsize,
+static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *errorString, QSize *impsize, int *frameCount,
const QSize &requestSize, const QQuickImageProviderOptions &providerOptions,
- QQuickImageProviderOptions::AutoTransform *appliedTransform = nullptr)
+ QQuickImageProviderOptions::AutoTransform *appliedTransform = nullptr, int frame = 0)
{
QImageReader imgio(dev);
if (providerOptions.autoTransform() != QQuickImageProviderOptions::UsePluginDefaultTransform)
@@ -406,6 +408,12 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e
else if (appliedTransform)
*appliedTransform = imgio.autoTransform() ? QQuickImageProviderOptions::ApplyTransform : QQuickImageProviderOptions::DoNotApplyTransform;
+ if (frame < imgio.imageCount())
+ imgio.jumpToImage(frame);
+
+ if (frameCount)
+ *frameCount = imgio.imageCount();
+
QSize scSize = QQuickImageProviderWithOptions::loadSize(imgio.size(), requestSize, imgio.format(), providerOptions);
if (scSize.isValid())
imgio.setScaledSize(scSize);
@@ -558,9 +566,12 @@ void QQuickPixmapReader::networkRequestDone(QNetworkReply *reply)
QByteArray all = reply->readAll();
QBuffer buff(&all);
buff.open(QIODevice::ReadOnly);
- if (!readImage(reply->url(), &buff, &image, &errorString, &readSize, job->requestSize, job->providerOptions))
+ int frameCount;
+ if (!readImage(reply->url(), &buff, &image, &errorString, &readSize, &frameCount, job->requestSize, job->providerOptions, nullptr, job->data->frame))
error = QQuickPixmapReply::Decoding;
- }
+ else
+ job->data->frameCount = frameCount;
+ }
// send completion event to the QQuickPixmapReply
mutex.lock();
if (!cancelled.contains(job))
@@ -683,10 +694,11 @@ void QQuickPixmapReader::processJobs()
const QUrl url = job->url;
QString localFile;
QQuickImageProvider::ImageType imageType = QQuickImageProvider::Invalid;
- QQuickImageProvider *provider = nullptr;
+ QSharedPointer<QQuickImageProvider> provider;
if (url.scheme() == QLatin1String("image")) {
- provider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageProviderId(url)));
+ QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine);
+ provider = enginePrivate->imageProvider(imageProviderId(url)).staticCast<QQuickImageProvider>();
if (provider)
imageType = provider->imageType();
@@ -721,7 +733,7 @@ void QQuickPixmapReader::processJobs()
}
void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &url, const QString &localFile,
- QQuickImageProvider::ImageType imageType, QQuickImageProvider *provider)
+ QQuickImageProvider::ImageType imageType, const QSharedPointer<QQuickImageProvider> &provider)
{
// fetch
if (url.scheme() == QLatin1String("image")) {
@@ -737,7 +749,8 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
return;
}
- QQuickImageProviderWithOptions *providerV2 = QQuickImageProviderWithOptions::checkedCast(provider);
+ // This is safe because we ensure that provider does outlive providerV2 and it does not escape the function
+ QQuickImageProviderWithOptions *providerV2 = QQuickImageProviderWithOptions::checkedCast(provider.get());
switch (imageType) {
case QQuickImageProvider::Invalid:
@@ -817,17 +830,24 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
if (providerV2) {
response = providerV2->requestImageResponse(imageId(url), runningJob->requestSize, runningJob->providerOptions);
} else {
- QQuickAsyncImageProvider *asyncProvider = static_cast<QQuickAsyncImageProvider*>(provider);
+ QQuickAsyncImageProvider *asyncProvider = static_cast<QQuickAsyncImageProvider*>(provider.get());
response = asyncProvider->requestImageResponse(imageId(url), runningJob->requestSize);
}
+ {
+ QObject::connect(response, SIGNAL(finished()), threadObject, SLOT(asyncResponseFinished()));
+ // as the response object can outlive the provider QSharedPointer, we have to extend the pointee's lifetime by that of the response
+ // we do this by capturing a copy of the QSharedPointer in a lambda, and dropping it once the lambda has been called
+ auto provider_copy = provider; // capturing provider would capture it as a const reference, and copy capture with initializer is only available in C++14
+ QObject::connect(response, &QQuickImageResponse::destroyed, response, [provider_copy]() {
+ // provider_copy will be deleted when the connection gets deleted
+ });
+ }
// Might be that the async provider was so quick it emitted the signal before we
// could connect to it.
- if (static_cast<QQuickImageResponsePrivate*>(QObjectPrivate::get(response))->finished) {
+ if (static_cast<QQuickImageResponsePrivate*>(QObjectPrivate::get(response))->finished.loadAcquire()) {
QMetaObject::invokeMethod(threadObject, "asyncResponseFinished",
Qt::QueuedConnection, Q_ARG(QQuickImageResponse*, response));
- } else {
- QObject::connect(response, SIGNAL(finished()), threadObject, SLOT(asyncResponseFinished()));
}
asyncResponses.insert(response, runningJob);
@@ -861,10 +881,13 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
mutex.unlock();
return;
} else {
- if (!readImage(url, &f, &image, &errorStr, &readSize, runningJob->requestSize, runningJob->providerOptions)) {
+ int frameCount;
+ if (!readImage(url, &f, &image, &errorStr, &readSize, &frameCount, runningJob->requestSize, runningJob->providerOptions, nullptr, runningJob->data->frame)) {
errorCode = QQuickPixmapReply::Loading;
if (f.fileName() != localFile)
errorStr += QString::fromLatin1(" (%1)").arg(f.fileName());
+ } else if (runningJob->data) {
+ runningJob->data->frameCount = frameCount;
}
}
} else {
@@ -973,17 +996,18 @@ class QQuickPixmapKey
public:
const QUrl *url;
const QSize *size;
+ int frame;
QQuickImageProviderOptions options;
};
inline bool operator==(const QQuickPixmapKey &lhs, const QQuickPixmapKey &rhs)
{
- return *lhs.size == *rhs.size && *lhs.url == *rhs.url && lhs.options == rhs.options;
+ return *lhs.size == *rhs.size && *lhs.url == *rhs.url && lhs.options == rhs.options && lhs.frame == rhs.frame;
}
inline uint qHash(const QQuickPixmapKey &key)
{
- return qHash(*key.url) ^ (key.size->width()*7) ^ (key.size->height()*17) ^ (key.options.autoTransform() * 0x5c5c5c5c);
+ return qHash(*key.url) ^ (key.size->width()*7) ^ (key.size->height()*17) ^ (key.frame*23) ^ (key.options.autoTransform() * 0x5c5c5c5c);
}
class QQuickPixmapStore : public QObject
@@ -1245,7 +1269,7 @@ void QQuickPixmapData::release()
void QQuickPixmapData::addToCache()
{
if (!inCache) {
- QQuickPixmapKey key = { &url, &requestSize, providerOptions };
+ QQuickPixmapKey key = { &url, &requestSize, frame, providerOptions };
pixmapStore()->m_cache.insert(key, this);
inCache = true;
PIXMAP_PROFILE(pixmapCountChanged<QQuickProfiler::PixmapCacheCountChanged>(
@@ -1256,7 +1280,7 @@ void QQuickPixmapData::addToCache()
void QQuickPixmapData::removeFromCache()
{
if (inCache) {
- QQuickPixmapKey key = { &url, &requestSize, providerOptions };
+ QQuickPixmapKey key = { &url, &requestSize, frame, providerOptions };
pixmapStore()->m_cache.remove(key);
inCache = false;
PIXMAP_PROFILE(pixmapCountChanged<QQuickProfiler::PixmapCacheCountChanged>(
@@ -1264,14 +1288,16 @@ void QQuickPixmapData::removeFromCache()
}
}
-static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, QQmlEngine *engine, const QUrl &url, const QSize &requestSize, const QQuickImageProviderOptions &providerOptions, bool *ok)
+static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, QQmlEngine *engine, const QUrl &url, const QSize &requestSize, const QQuickImageProviderOptions &providerOptions, int frame, bool *ok)
{
if (url.scheme() == QLatin1String("image")) {
QSize readSize;
QQuickImageProvider::ImageType imageType = QQuickImageProvider::Invalid;
- QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageProviderId(url)));
- QQuickImageProviderWithOptions *providerV2 = QQuickImageProviderWithOptions::checkedCast(provider);
+ QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine);
+ QSharedPointer<QQuickImageProvider> provider = enginePrivate->imageProvider(imageProviderId(url)).dynamicCast<QQuickImageProvider>();
+ // it is safe to use get() as providerV2 does not escape and is outlived by provider
+ QQuickImageProviderWithOptions *providerV2 = QQuickImageProviderWithOptions::checkedCast(provider.get());
if (provider)
imageType = provider->imageType();
@@ -1285,7 +1311,7 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
: provider->requestTexture(imageId(url), &readSize, requestSize);
if (texture) {
*ok = true;
- return new QQuickPixmapData(declarativePixmap, url, texture, readSize, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform);
+ return new QQuickPixmapData(declarativePixmap, url, texture, readSize, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform, frame);
}
break;
}
@@ -1296,7 +1322,7 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
: provider->requestImage(imageId(url), &readSize, requestSize);
if (!image.isNull()) {
*ok = true;
- return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(image), readSize, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform);
+ return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(image), readSize, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform, frame);
}
break;
}
@@ -1306,7 +1332,7 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
: provider->requestPixmap(imageId(url), &readSize, requestSize);
if (!pixmap.isNull()) {
*ok = true;
- return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(pixmap.toImage()), readSize, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform);
+ return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(pixmap.toImage()), readSize, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform, frame);
}
break;
}
@@ -1336,7 +1362,7 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
QQuickTextureFactory *factory = texReader.read();
if (factory) {
*ok = true;
- return new QQuickPixmapData(declarativePixmap, url, factory, factory->textureSize(), requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform);
+ return new QQuickPixmapData(declarativePixmap, url, factory, factory->textureSize(), requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform, frame);
} else {
errorString = QQuickPixmap::tr("Error decoding: %1").arg(url.toString());
if (f.fileName() != localFile)
@@ -1345,9 +1371,10 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
} else {
QImage image;
QQuickImageProviderOptions::AutoTransform appliedTransform = providerOptions.autoTransform();
- if (readImage(url, &f, &image, &errorString, &readSize, requestSize, providerOptions, &appliedTransform)) {
+ int frameCount;
+ if (readImage(url, &f, &image, &errorString, &readSize, &frameCount, requestSize, providerOptions, &appliedTransform, frame)) {
*ok = true;
- return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(image), readSize, requestSize, providerOptions, appliedTransform);
+ return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(image), readSize, requestSize, providerOptions, appliedTransform, frame, frameCount);
} else if (f.fileName() != localFile) {
errorString += QString::fromLatin1(" (%1)").arg(f.fileName());
}
@@ -1465,6 +1492,13 @@ QQuickImageProviderOptions::AutoTransform QQuickPixmap::autoTransform() const
return QQuickImageProviderOptions::UsePluginDefaultTransform;
}
+int QQuickPixmap::frameCount() const
+{
+ if (d)
+ return d->frameCount;
+ return 0;
+}
+
QQuickTextureFactory *QQuickPixmap::textureFactory() const
{
if (d)
@@ -1543,7 +1577,7 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
load(engine, url, requestSize, options, QQuickImageProviderOptions());
}
-void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &requestSize, QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions)
+void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &requestSize, QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions, int frame, int frameCount)
{
if (d) {
d->declarativePixmaps.remove(this);
@@ -1551,7 +1585,7 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
d = nullptr;
}
- QQuickPixmapKey key = { &url, &requestSize, providerOptions };
+ QQuickPixmapKey key = { &url, &requestSize, frame, providerOptions };
QQuickPixmapStore *store = pixmapStore();
QHash<QQuickPixmapKey, QQuickPixmapData *>::Iterator iter = store->m_cache.end();
@@ -1563,14 +1597,15 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
QSize dummy;
if (requestSize != dummy)
qWarning() << "Ignoring sourceSize request for image url that came from grabToImage. Use the targetSize parameter of the grabToImage() function instead.";
- const QQuickPixmapKey grabberKey = { &url, &dummy, QQuickImageProviderOptions() };
+ const QQuickPixmapKey grabberKey = { &url, &dummy, 0, QQuickImageProviderOptions() };
iter = store->m_cache.find(grabberKey);
} else if (options & QQuickPixmap::Cache)
iter = store->m_cache.find(key);
if (iter == store->m_cache.end()) {
if (url.scheme() == QLatin1String("image")) {
- if (QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageProviderId(url)))) {
+ QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine);
+ if (auto provider = enginePrivate->imageProvider(imageProviderId(url)).staticCast<QQuickImageProvider>()) {
const bool threadedPixmaps = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps);
if (!threadedPixmaps && provider->imageType() == QQuickImageProvider::Pixmap) {
// pixmaps can only be loaded synchronously
@@ -1584,7 +1619,7 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
if (!(options & QQuickPixmap::Asynchronous)) {
bool ok = false;
PIXMAP_PROFILE(pixmapStateChanged<QQuickProfiler::PixmapLoadingStarted>(url));
- d = createPixmapDataSync(this, engine, url, requestSize, providerOptions, &ok);
+ d = createPixmapDataSync(this, engine, url, requestSize, providerOptions, frame, &ok);
if (ok) {
PIXMAP_PROFILE(pixmapLoadingFinished(url, QSize(width(), height())));
if (options & QQuickPixmap::Cache)
@@ -1601,7 +1636,7 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
return;
- d = new QQuickPixmapData(this, url, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform);
+ d = new QQuickPixmapData(this, url, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform, frame, frameCount);
if (options & QQuickPixmap::Cache)
d->addToCache();
@@ -1635,9 +1670,9 @@ void QQuickPixmap::clear(QObject *obj)
}
}
-bool QQuickPixmap::isCached(const QUrl &url, const QSize &requestSize, const QQuickImageProviderOptions &options)
+bool QQuickPixmap::isCached(const QUrl &url, const QSize &requestSize, const int frame, const QQuickImageProviderOptions &options)
{
- QQuickPixmapKey key = { &url, &requestSize, options };
+ QQuickPixmapKey key = { &url, &requestSize, frame, options };
QQuickPixmapStore *store = pixmapStore();
return store->m_cache.contains(key);
diff --git a/src/quick/util/qquickpixmapcache_p.h b/src/quick/util/qquickpixmapcache_p.h
index 91fb1ed3bb..ab5d391fa2 100644
--- a/src/quick/util/qquickpixmapcache_p.h
+++ b/src/quick/util/qquickpixmapcache_p.h
@@ -150,6 +150,7 @@ public:
const QSize &implicitSize() const;
const QSize &requestSize() const;
QQuickImageProviderOptions::AutoTransform autoTransform() const;
+ int frameCount() const;
QImage image() const;
void setImage(const QImage &);
void setPixmap(const QQuickPixmap &other);
@@ -164,7 +165,7 @@ public:
void load(QQmlEngine *, const QUrl &, QQuickPixmap::Options options);
void load(QQmlEngine *, const QUrl &, const QSize &);
void load(QQmlEngine *, const QUrl &, const QSize &, QQuickPixmap::Options options);
- void load(QQmlEngine *, const QUrl &, const QSize &, QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions);
+ void load(QQmlEngine *, const QUrl &, const QSize &, QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions, int frame = 0, int frameCount = 1);
void clear();
void clear(QObject *);
@@ -175,7 +176,7 @@ public:
bool connectDownloadProgress(QObject *, int);
static void purgeCache();
- static bool isCached(const QUrl &url, const QSize &requestSize, const QQuickImageProviderOptions &options);
+ static bool isCached(const QUrl &url, const QSize &requestSize, const int frame, const QQuickImageProviderOptions &options);
static const QLatin1String itemGrabberScheme;
diff --git a/src/quick/util/qquickpropertychanges.cpp b/src/quick/util/qquickpropertychanges.cpp
index d739c8a017..1cb30f5a8d 100644
--- a/src/quick/util/qquickpropertychanges.cpp
+++ b/src/quick/util/qquickpropertychanges.cpp
@@ -51,6 +51,7 @@
#include <private/qqmlcontext_p.h>
#include <private/qquickstate_p_p.h>
#include <private/qqmlboundsignal_p.h>
+#include <private/qv4qmlcontext_p.h>
#include <QtCore/qdebug.h>
@@ -201,14 +202,14 @@ public:
QPointer<QObject> object;
QList<const QV4::CompiledData::Binding *> bindings;
- QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit;
+ QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit;
bool decoded : 1;
bool restore : 1;
bool isExplicit : 1;
void decode();
- void decodeBinding(const QString &propertyPrefix, const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &qmlUnit, const QV4::CompiledData::Binding *binding);
+ void decodeBinding(const QString &propertyPrefix, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &qmlUnit, const QV4::CompiledData::Binding *binding);
class ExpressionChange {
public:
@@ -236,7 +237,7 @@ public:
QQmlProperty property(const QString &);
};
-void QQuickPropertyChangesParser::verifyList(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit, const QV4::CompiledData::Binding *binding)
+void QQuickPropertyChangesParser::verifyList(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QV4::CompiledData::Binding *binding)
{
if (binding->type == QV4::CompiledData::Binding::Type_Object) {
error(compilationUnit->objectAt(binding->value.objectIndex), QQuickPropertyChanges::tr("PropertyChanges does not support creating state-specific objects."));
@@ -266,7 +267,7 @@ void QQuickPropertyChangesPrivate::decode()
decoded = true;
}
-void QQuickPropertyChangesPrivate::decodeBinding(const QString &propertyPrefix, const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit, const QV4::CompiledData::Binding *binding)
+void QQuickPropertyChangesPrivate::decodeBinding(const QString &propertyPrefix, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QV4::CompiledData::Binding *binding)
{
Q_Q(QQuickPropertyChanges);
@@ -314,7 +315,7 @@ void QQuickPropertyChangesPrivate::decodeBinding(const QString &propertyPrefix,
QQmlBinding::Identifier id = QQmlBinding::Invalid;
if (!binding->isTranslationBinding()) {
- expression = binding->valueAsString(compilationUnit.data());
+ expression = compilationUnit->bindingValueAsString(binding);
id = binding->value.compiledScriptIndex;
}
expressions << ExpressionChange(propertyName, binding, id, expression, url, line, column);
@@ -328,10 +329,10 @@ void QQuickPropertyChangesPrivate::decodeBinding(const QString &propertyPrefix,
case QV4::CompiledData::Binding::Type_TranslationById:
Q_UNREACHABLE();
case QV4::CompiledData::Binding::Type_String:
- var = binding->valueAsString(compilationUnit.data());
+ var = compilationUnit->bindingValueAsString(binding);
break;
case QV4::CompiledData::Binding::Type_Number:
- var = binding->valueAsNumber(compilationUnit->constants);
+ var = compilationUnit->bindingValueAsNumber(binding);
break;
case QV4::CompiledData::Binding::Type_Boolean:
var = binding->valueAsBoolean();
@@ -346,13 +347,13 @@ void QQuickPropertyChangesPrivate::decodeBinding(const QString &propertyPrefix,
properties << qMakePair(propertyName, var);
}
-void QQuickPropertyChangesParser::verifyBindings(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &props)
+void QQuickPropertyChangesParser::verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &props)
{
for (int ii = 0; ii < props.count(); ++ii)
verifyList(compilationUnit, props.at(ii));
}
-void QQuickPropertyChangesParser::applyBindings(QObject *obj, const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings)
+void QQuickPropertyChangesParser::applyBindings(QObject *obj, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings)
{
QQuickPropertyChangesPrivate *p =
static_cast<QQuickPropertyChangesPrivate *>(QObjectPrivate::get(obj));
@@ -539,9 +540,7 @@ bool QQuickPropertyChanges::containsValue(const QString &name) const
Q_D(const QQuickPropertyChanges);
typedef QPair<QString, QVariant> PropertyEntry;
- QListIterator<PropertyEntry> propertyIterator(d->properties);
- while (propertyIterator.hasNext()) {
- const PropertyEntry &entry = propertyIterator.next();
+ for (const PropertyEntry &entry : d->properties) {
if (entry.first == name) {
return true;
}
@@ -555,9 +554,7 @@ bool QQuickPropertyChanges::containsExpression(const QString &name) const
Q_D(const QQuickPropertyChanges);
typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry;
- QListIterator<ExpressionEntry> expressionIterator(d->expressions);
- while (expressionIterator.hasNext()) {
- const ExpressionEntry &entry = expressionIterator.next();
+ for (const ExpressionEntry &entry : d->expressions) {
if (entry.name == name) {
return true;
}
@@ -575,13 +572,10 @@ void QQuickPropertyChanges::changeValue(const QString &name, const QVariant &val
{
Q_D(QQuickPropertyChanges);
typedef QPair<QString, QVariant> PropertyEntry;
- typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry;
- QMutableListIterator<ExpressionEntry> expressionIterator(d->expressions);
- while (expressionIterator.hasNext()) {
- const ExpressionEntry &entry = expressionIterator.next();
- if (entry.name == name) {
- expressionIterator.remove();
+ for (auto it = d->expressions.begin(), end = d->expressions.end(); it != end; ++it) {
+ if (it->name == name) {
+ d->expressions.erase(it);
if (state() && state()->isStateActive()) {
QQmlPropertyPrivate::removeBinding(d->property(name));
d->property(name).write(value);
@@ -592,11 +586,9 @@ void QQuickPropertyChanges::changeValue(const QString &name, const QVariant &val
}
}
- QMutableListIterator<PropertyEntry> propertyIterator(d->properties);
- while (propertyIterator.hasNext()) {
- PropertyEntry &entry = propertyIterator.next();
- if (entry.first == name) {
- entry.second = value;
+ for (auto it = d->properties.begin(), end = d->properties.end(); it != end; ++it) {
+ if (it->first == name) {
+ it->second = value;
if (state() && state()->isStateActive())
d->property(name).write(value);
return;
@@ -611,7 +603,7 @@ void QQuickPropertyChanges::changeValue(const QString &name, const QVariant &val
action.specifiedProperty = name;
action.toValue = value;
- propertyIterator.insert(PropertyEntry(name, value));
+ d->properties.append(PropertyEntry(name, value));
if (state() && state()->isStateActive()) {
state()->addEntryToRevertList(action);
QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::binding(action.property);
@@ -624,26 +616,21 @@ void QQuickPropertyChanges::changeValue(const QString &name, const QVariant &val
void QQuickPropertyChanges::changeExpression(const QString &name, const QString &expression)
{
Q_D(QQuickPropertyChanges);
- typedef QPair<QString, QVariant> PropertyEntry;
typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry;
bool hadValue = false;
- QMutableListIterator<PropertyEntry> propertyIterator(d->properties);
- while (propertyIterator.hasNext()) {
- PropertyEntry &entry = propertyIterator.next();
- if (entry.first == name) {
- propertyIterator.remove();
+ for (auto it = d->properties.begin(), end = d->properties.end(); it != end; ++it) {
+ if (it->first == name) {
+ d->properties.erase(it);
hadValue = true;
break;
}
}
- QMutableListIterator<ExpressionEntry> expressionIterator(d->expressions);
- while (expressionIterator.hasNext()) {
- ExpressionEntry &entry = expressionIterator.next();
- if (entry.name == name) {
- entry.expression = expression;
+ for (auto it = d->expressions.begin(), end = d->expressions.end(); it != end; ++it) {
+ if (it->name == name) {
+ it->expression = expression;
if (state() && state()->isStateActive()) {
auto prop = d->property(name);
QQmlBinding *newBinding = QQmlBinding::create(
@@ -657,7 +644,7 @@ void QQuickPropertyChanges::changeExpression(const QString &name, const QString
}
// adding a new expression.
- expressionIterator.insert(ExpressionEntry(name, nullptr, QQmlBinding::Invalid, expression, QUrl(), -1, -1));
+ d->expressions.append(ExpressionEntry(name, nullptr, QQmlBinding::Invalid, expression, QUrl(), -1, -1));
if (state() && state()->isStateActive()) {
if (hadValue) {
@@ -713,17 +700,13 @@ QVariant QQuickPropertyChanges::property(const QString &name) const
typedef QPair<QString, QVariant> PropertyEntry;
typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry;
- QListIterator<PropertyEntry> propertyIterator(d->properties);
- while (propertyIterator.hasNext()) {
- const PropertyEntry &entry = propertyIterator.next();
+ for (const PropertyEntry &entry : d->properties) {
if (entry.first == name) {
return entry.second;
}
}
- QListIterator<ExpressionEntry> expressionIterator(d->expressions);
- while (expressionIterator.hasNext()) {
- const ExpressionEntry &entry = expressionIterator.next();
+ for (const ExpressionEntry &entry : d->expressions) {
if (entry.name == name) {
return QVariant(entry.expression);
}
@@ -735,24 +718,18 @@ QVariant QQuickPropertyChanges::property(const QString &name) const
void QQuickPropertyChanges::removeProperty(const QString &name)
{
Q_D(QQuickPropertyChanges);
- typedef QPair<QString, QVariant> PropertyEntry;
- typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry;
- QMutableListIterator<ExpressionEntry> expressionIterator(d->expressions);
- while (expressionIterator.hasNext()) {
- const ExpressionEntry &entry = expressionIterator.next();
- if (entry.name == name) {
- expressionIterator.remove();
+ for (auto it = d->expressions.begin(), end = d->expressions.end(); it != end; ++it) {
+ if (it->name == name) {
+ d->expressions.erase(it);
state()->removeEntryFromRevertList(object(), name);
return;
}
}
- QMutableListIterator<PropertyEntry> propertyIterator(d->properties);
- while (propertyIterator.hasNext()) {
- const PropertyEntry &entry = propertyIterator.next();
- if (entry.first == name) {
- propertyIterator.remove();
+ for (auto it = d->properties.begin(), end = d->properties.end(); it != end; ++it) {
+ if (it->first == name) {
+ d->properties.erase(it);
state()->removeEntryFromRevertList(object(), name);
return;
}
@@ -764,9 +741,7 @@ QVariant QQuickPropertyChanges::value(const QString &name) const
Q_D(const QQuickPropertyChanges);
typedef QPair<QString, QVariant> PropertyEntry;
- QListIterator<PropertyEntry> propertyIterator(d->properties);
- while (propertyIterator.hasNext()) {
- const PropertyEntry &entry = propertyIterator.next();
+ for (const PropertyEntry &entry : d->properties) {
if (entry.first == name) {
return entry.second;
}
@@ -780,9 +755,7 @@ QString QQuickPropertyChanges::expression(const QString &name) const
Q_D(const QQuickPropertyChanges);
typedef QQuickPropertyChangesPrivate::ExpressionChange ExpressionEntry;
- QListIterator<ExpressionEntry> expressionIterator(d->expressions);
- while (expressionIterator.hasNext()) {
- const ExpressionEntry &entry = expressionIterator.next();
+ for (const ExpressionEntry &entry : d->expressions) {
if (entry.name == name) {
return entry.expression;
}
diff --git a/src/quick/util/qquickpropertychanges_p.h b/src/quick/util/qquickpropertychanges_p.h
index 74fe511d6e..82a6ebffac 100644
--- a/src/quick/util/qquickpropertychanges_p.h
+++ b/src/quick/util/qquickpropertychanges_p.h
@@ -101,10 +101,10 @@ public:
QQuickPropertyChangesParser()
: QQmlCustomParser(AcceptsAttachedProperties) {}
- void verifyList(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit, const QV4::CompiledData::Binding *binding);
+ void verifyList(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QV4::CompiledData::Binding *binding);
- void verifyBindings(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &props) override;
- void applyBindings(QObject *obj, const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) override;
+ void verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &props) override;
+ void applyBindings(QObject *obj, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) override;
};
diff --git a/src/quick/util/qquickshortcut.cpp b/src/quick/util/qquickshortcut.cpp
index 730a14369e..5d227b4613 100644
--- a/src/quick/util/qquickshortcut.cpp
+++ b/src/quick/util/qquickshortcut.cpp
@@ -216,7 +216,7 @@ void QQuickShortcut::setSequences(const QVariantList &values)
bool changed = !remainder.isEmpty();
for (int i = 0; i < values.count(); ++i) {
- QVariant value = values.at(i);
+ const QVariant &value = values.at(i);
Shortcut& shortcut = m_shortcuts[i];
if (value == shortcut.userValue)
continue;
diff --git a/src/quick/util/qquickshortcut_p.h b/src/quick/util/qquickshortcut_p.h
index c5d5501cb7..712cca7696 100644
--- a/src/quick/util/qquickshortcut_p.h
+++ b/src/quick/util/qquickshortcut_p.h
@@ -67,8 +67,8 @@ class QQuickShortcut : public QObject, public QQmlParserStatus
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(QVariant sequence READ sequence WRITE setSequence NOTIFY sequenceChanged FINAL)
Q_PROPERTY(QVariantList sequences READ sequences WRITE setSequences NOTIFY sequencesChanged FINAL REVISION 9)
- Q_PROPERTY(QString nativeText READ nativeText NOTIFY sequenceChanged FINAL REVISION 1)
- Q_PROPERTY(QString portableText READ portableText NOTIFY sequenceChanged FINAL REVISION 1)
+ Q_PROPERTY(QString nativeText READ nativeText NOTIFY sequenceChanged FINAL REVISION 6)
+ Q_PROPERTY(QString portableText READ portableText NOTIFY sequenceChanged FINAL REVISION 6)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL)
Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY autoRepeatChanged FINAL)
Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext NOTIFY contextChanged FINAL)
diff --git a/src/quick/util/qquickstate.cpp b/src/quick/util/qquickstate.cpp
index 3ca6440784..c106528f45 100644
--- a/src/quick/util/qquickstate.cpp
+++ b/src/quick/util/qquickstate.cpp
@@ -192,7 +192,7 @@ bool QQuickState::isNamed() const
bool QQuickState::isWhenKnown() const
{
Q_D(const QQuickState);
- return d->when != nullptr;
+ return d->whenKnown;
}
/*!
@@ -219,15 +219,16 @@ bool QQuickState::isWhenKnown() const
}
\endqml
*/
-QQmlBinding *QQuickState::when() const
+bool QQuickState::when() const
{
Q_D(const QQuickState);
- return d->when.data();
+ return d->when;
}
-void QQuickState::setWhen(QQmlBinding *when)
+void QQuickState::setWhen(bool when)
{
Q_D(QQuickState);
+ d->whenKnown = true;
d->when = when;
if (d->group)
d->group->updateAutoState();
@@ -371,10 +372,7 @@ bool QQuickState::containsPropertyInRevertList(QObject *target, const QString &n
Q_D(const QQuickState);
if (isStateActive()) {
- QListIterator<QQuickSimpleAction> revertListIterator(d->revertList);
-
- while (revertListIterator.hasNext()) {
- const QQuickSimpleAction &simpleAction = revertListIterator.next();
+ for (const QQuickSimpleAction &simpleAction : d->revertList) {
if (simpleAction.specifiedObject() == target && simpleAction.specifiedProperty() == name)
return true;
}
@@ -388,10 +386,7 @@ bool QQuickState::changeValueInRevertList(QObject *target, const QString &name,
Q_D(QQuickState);
if (isStateActive()) {
- QMutableListIterator<QQuickSimpleAction> revertListIterator(d->revertList);
-
- while (revertListIterator.hasNext()) {
- QQuickSimpleAction &simpleAction = revertListIterator.next();
+ for (QQuickSimpleAction &simpleAction : d->revertList) {
if (simpleAction.specifiedObject() == target && simpleAction.specifiedProperty() == name) {
simpleAction.setValue(revertValue);
return true;
@@ -407,10 +402,7 @@ bool QQuickState::changeBindingInRevertList(QObject *target, const QString &name
Q_D(QQuickState);
if (isStateActive()) {
- QMutableListIterator<QQuickSimpleAction> revertListIterator(d->revertList);
-
- while (revertListIterator.hasNext()) {
- QQuickSimpleAction &simpleAction = revertListIterator.next();
+ for (QQuickSimpleAction &simpleAction : d->revertList) {
if (simpleAction.specifiedObject() == target && simpleAction.specifiedProperty() == name) {
simpleAction.setBinding(binding);
return true;
@@ -426,10 +418,8 @@ bool QQuickState::removeEntryFromRevertList(QObject *target, const QString &name
Q_D(QQuickState);
if (isStateActive()) {
- QMutableListIterator<QQuickSimpleAction> revertListIterator(d->revertList);
-
- while (revertListIterator.hasNext()) {
- QQuickSimpleAction &simpleAction = revertListIterator.next();
+ for (auto it = d->revertList.begin(), end = d->revertList.end(); it != end; ++it) {
+ QQuickSimpleAction &simpleAction = *it;
if (simpleAction.property().object() == target && simpleAction.property().name() == name) {
QQmlPropertyPrivate::removeBinding(simpleAction.property());
@@ -437,7 +427,7 @@ bool QQuickState::removeEntryFromRevertList(QObject *target, const QString &name
if (simpleAction.binding())
QQmlPropertyPrivate::setBinding(simpleAction.binding());
- revertListIterator.remove();
+ d->revertList.erase(it);
return true;
}
}
@@ -460,10 +450,7 @@ void QQuickState::removeAllEntriesFromRevertList(QObject *target)
Q_D(QQuickState);
if (isStateActive()) {
- QMutableListIterator<QQuickSimpleAction> revertListIterator(d->revertList);
-
- while (revertListIterator.hasNext()) {
- QQuickSimpleAction &simpleAction = revertListIterator.next();
+ const auto actionMatchesTarget = [target](QQuickSimpleAction &simpleAction) {
if (simpleAction.property().object() == target) {
QQmlPropertyPrivate::removeBinding(simpleAction.property());
@@ -471,9 +458,14 @@ void QQuickState::removeAllEntriesFromRevertList(QObject *target)
if (simpleAction.binding())
QQmlPropertyPrivate::setBinding(simpleAction.binding());
- revertListIterator.remove();
+ return true;
}
- }
+ return false;
+ };
+
+ d->revertList.erase(std::remove_if(d->revertList.begin(), d->revertList.end(),
+ actionMatchesTarget),
+ d->revertList.end());
}
}
@@ -484,9 +476,7 @@ void QQuickState::addEntriesToRevertList(const QList<QQuickStateAction> &actionL
QList<QQuickSimpleAction> simpleActionList;
simpleActionList.reserve(actionList.count());
- QListIterator<QQuickStateAction> actionListIterator(actionList);
- while(actionListIterator.hasNext()) {
- const QQuickStateAction &action = actionListIterator.next();
+ for (const QQuickStateAction &action : actionList) {
QQuickSimpleAction simpleAction(action);
action.property.write(action.toValue);
if (action.toBinding)
@@ -504,10 +494,7 @@ QVariant QQuickState::valueInRevertList(QObject *target, const QString &name) co
Q_D(const QQuickState);
if (isStateActive()) {
- QListIterator<QQuickSimpleAction> revertListIterator(d->revertList);
-
- while (revertListIterator.hasNext()) {
- const QQuickSimpleAction &simpleAction = revertListIterator.next();
+ for (const QQuickSimpleAction &simpleAction : d->revertList) {
if (simpleAction.specifiedObject() == target && simpleAction.specifiedProperty() == name)
return simpleAction.value();
}
@@ -521,10 +508,7 @@ QQmlAbstractBinding *QQuickState::bindingInRevertList(QObject *target, const QSt
Q_D(const QQuickState);
if (isStateActive()) {
- QListIterator<QQuickSimpleAction> revertListIterator(d->revertList);
-
- while (revertListIterator.hasNext()) {
- const QQuickSimpleAction &simpleAction = revertListIterator.next();
+ for (const QQuickSimpleAction &simpleAction : d->revertList) {
if (simpleAction.specifiedObject() == target && simpleAction.specifiedProperty() == name)
return simpleAction.binding();
}
diff --git a/src/quick/util/qquickstate_p.h b/src/quick/util/qquickstate_p.h
index 79874ee78e..576ba9834c 100644
--- a/src/quick/util/qquickstate_p.h
+++ b/src/quick/util/qquickstate_p.h
@@ -152,7 +152,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickState : public QObject
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(QQmlBinding *when READ when WRITE setWhen)
+ Q_PROPERTY(bool when READ when WRITE setWhen)
Q_PROPERTY(QString extend READ extends WRITE setExtends)
Q_PROPERTY(QQmlListProperty<QQuickStateOperation> changes READ changes)
Q_CLASSINFO("DefaultProperty", "changes")
@@ -166,11 +166,9 @@ public:
void setName(const QString &);
bool isNamed() const;
- /*'when' is a QQmlBinding to limit state changes oscillation
- due to the unpredictable order of evaluation of bound expressions*/
bool isWhenKnown() const;
- QQmlBinding *when() const;
- void setWhen(QQmlBinding *);
+ bool when() const;
+ void setWhen(bool);
QString extends() const;
void setExtends(const QString &);
diff --git a/src/quick/util/qquickstate_p_p.h b/src/quick/util/qquickstate_p_p.h
index 61472b4d06..2fa5321165 100644
--- a/src/quick/util/qquickstate_p_p.h
+++ b/src/quick/util/qquickstate_p_p.h
@@ -203,12 +203,13 @@ class QQuickStatePrivate : public QObjectPrivate
public:
QQuickStatePrivate()
- : named(false), inState(false), group(nullptr) {}
+ : when(false), whenKnown(false), named(false), inState(false), group(nullptr) {}
typedef QList<QQuickSimpleAction> SimpleActionList;
QString name;
- QQmlBinding::Ptr when;
+ bool when;
+ bool whenKnown;
bool named;
struct OperationGuard : public QQmlGuard<QQuickStateOperation>
@@ -231,9 +232,8 @@ public:
}
static void operations_clear(QQmlListProperty<QQuickStateOperation> *prop) {
QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
- QMutableListIterator<OperationGuard> listIterator(*list);
- while(listIterator.hasNext())
- listIterator.next()->setState(nullptr);
+ for (auto &e : *list)
+ e->setState(nullptr);
list->clear();
}
static int operations_count(QQmlListProperty<QQuickStateOperation> *prop) {
diff --git a/src/quick/util/qquickstategroup.cpp b/src/quick/util/qquickstategroup.cpp
index b53949d21c..46e7d62fc1 100644
--- a/src/quick/util/qquickstategroup.cpp
+++ b/src/quick/util/qquickstategroup.cpp
@@ -311,7 +311,7 @@ void QQuickStateGroup::componentComplete()
if (!state->isNamed())
state->setName(QLatin1String("anonymousState") + QString::number(++d->unnamedCount));
- const QString stateName = state->name();
+ QString stateName = state->name();
if (names.contains(stateName)) {
qmlWarning(state->parent()) << "Found duplicate state name: " << stateName;
} else {
@@ -348,10 +348,9 @@ bool QQuickStateGroupPrivate::updateAutoState()
QQuickState *state = states.at(ii);
if (state->isWhenKnown()) {
if (state->isNamed()) {
- if (state->when() && state->when()->evaluate().toBool()) {
+ if (state->when()) {
if (stateChangeDebug())
- qWarning() << "Setting auto state due to:"
- << state->when()->expression();
+ qWarning() << "Setting auto state due to expression";
if (currentState != state->name()) {
q->setState(state->name());
return true;
diff --git a/src/quick/util/qquickutilmodule.cpp b/src/quick/util/qquickutilmodule.cpp
index 5147ebc6f6..93b6599506 100644
--- a/src/quick/util/qquickutilmodule.cpp
+++ b/src/quick/util/qquickutilmodule.cpp
@@ -99,10 +99,13 @@ void QQuickUtilModule::defineModule()
qmlRegisterType<QQuickVector3dAnimation>("QtQuick",2,0,"Vector3dAnimation");
#if QT_CONFIG(validator)
- qmlRegisterType<QValidator>();
+ qmlRegisterAnonymousType<QValidator>("QtQuick", 2);
qmlRegisterType<QQuickIntValidator>("QtQuick",2,0,"IntValidator");
qmlRegisterType<QQuickDoubleValidator>("QtQuick",2,0,"DoubleValidator");
qmlRegisterType<QRegExpValidator>("QtQuick",2,0,"RegExpValidator");
+#if QT_CONFIG(regularexpression)
+ qmlRegisterType<QRegularExpressionValidator>("QtQuick", 2, 14, "RegularExpressionValidator");
+#endif
#endif
qmlRegisterUncreatableType<QQuickAnimator>("QtQuick", 2, 2, "Animator", QQuickAbstractAnimation::tr("Animator is an abstract class"));
@@ -114,7 +117,7 @@ void QQuickUtilModule::defineModule()
#if QT_CONFIG(quick_shadereffect) && QT_CONFIG(opengl)
qmlRegisterType<QQuickUniformAnimator>("QtQuick", 2, 2, "UniformAnimator");
#endif
- qmlRegisterType<QQuickStateOperation>();
+ qmlRegisterAnonymousType<QQuickStateOperation>("QtQuick", 2);
qmlRegisterCustomType<QQuickPropertyChanges>("QtQuick",2,0,"PropertyChanges", new QQuickPropertyChangesParser);
@@ -128,7 +131,7 @@ void QQuickUtilModule::defineModule()
#if QT_CONFIG(shortcut)
qmlRegisterType<QQuickShortcut>("QtQuick", 2, 5, "Shortcut");
- qmlRegisterType<QQuickShortcut,1>("QtQuick", 2, 6, "Shortcut");
+ qmlRegisterType<QQuickShortcut,6>("QtQuick", 2, 6, "Shortcut");
qmlRegisterType<QQuickShortcut,9>("QtQuick", 2, 9, "Shortcut");
#endif
diff --git a/src/quick/util/qquickvalidator.cpp b/src/quick/util/qquickvalidator.cpp
index b2b773cd94..4709b3dda3 100644
--- a/src/quick/util/qquickvalidator.cpp
+++ b/src/quick/util/qquickvalidator.cpp
@@ -206,9 +206,13 @@ void QQuickDoubleValidator::resetLocaleName()
\inqmlmodule QtQuick
\ingroup qtquick-text-utility
\brief Provides a string validator.
+ \deprecated
The RegExpValidator type provides a validator, which counts as valid any string which
matches a specified regular expression.
+
+ RegExpValidator is deprecated since it is based on the deprecated \l {QRegExp}. Use
+ \l RegularExpressionValidator instead.
*/
/*!
\qmlproperty regExp QtQuick::RegExpValidator::regExp
@@ -239,6 +243,48 @@ void QQuickDoubleValidator::resetLocaleName()
\endcode
\endlist
*/
+/*!
+ \qmltype RegularExpressionValidator
+ \instantiates QRegularExpressionValidator
+ \inqmlmodule QtQuick
+ \ingroup qtquick-text-utility
+ \brief Provides a string validator.
+ \since 5.14
+
+ The RegularExpressionValidator type provides a validator, that counts as valid any string which
+ matches a specified regular expression.
+*/
+/*!
+ \qmlproperty regularExpression QtQuick::RegularExpressionValidator::regularExpression
+
+ This property holds the regular expression used for validation.
+
+ Note that this property should be a regular expression in JS syntax, e.g /a/ for the regular
+ expression matching "a".
+
+ By default, this property contains a regular expression with the pattern \c{.*} that matches any
+ string.
+
+ Below you can find an example of a \l TextInput object with a RegularExpressionValidator
+ specified:
+
+ \snippet qml/regularexpression.qml 0
+
+ Some more examples of regular expressions:
+
+ \list
+ \li A list of numbers with one to three positions separated by a comma:
+ \badcode
+ /\d{1,3}(?:,\d{1,3})+$/
+ \endcode
+
+ \li An amount consisting of up to 3 numbers before the decimal point, and
+ 1 to 2 after the decimal point:
+ \badcode
+ /(\d{1,3})([.,]\d{1,2})?$/
+ \endcode
+ \endlist
+*/
#endif // validator
diff --git a/src/quick/util/qquickvalidator_p.h b/src/quick/util/qquickvalidator_p.h
index 812e552d8e..9212efa044 100644
--- a/src/quick/util/qquickvalidator_p.h
+++ b/src/quick/util/qquickvalidator_p.h
@@ -95,6 +95,9 @@ QML_DECLARE_TYPE(QValidator)
QML_DECLARE_TYPE(QQuickIntValidator)
QML_DECLARE_TYPE(QQuickDoubleValidator)
QML_DECLARE_TYPE(QRegExpValidator)
+#if QT_CONFIG(regularexpression)
+QML_DECLARE_TYPE(QRegularExpressionValidator)
+#endif
#endif
#endif // QQUICKVALIDATOR_P_H
diff --git a/src/quick/util/qquickvaluetypes.cpp b/src/quick/util/qquickvaluetypes.cpp
index e4a03f3b52..0af29aed1c 100644
--- a/src/quick/util/qquickvaluetypes.cpp
+++ b/src/quick/util/qquickvaluetypes.cpp
@@ -109,6 +109,11 @@ qreal QQuickColorValueType::hslLightness() const
return v.lightnessF();
}
+bool QQuickColorValueType::isValid() const
+{
+ return v.isValid();
+}
+
void QQuickColorValueType::setR(qreal r)
{
v.setRedF(r);
diff --git a/src/quick/util/qquickvaluetypes_p.h b/src/quick/util/qquickvaluetypes_p.h
index 5a9af970e8..4305006f91 100644
--- a/src/quick/util/qquickvaluetypes_p.h
+++ b/src/quick/util/qquickvaluetypes_p.h
@@ -84,6 +84,7 @@ class QQuickColorValueType
Q_PROPERTY(qreal hslHue READ hslHue WRITE setHslHue FINAL)
Q_PROPERTY(qreal hslSaturation READ hslSaturation WRITE setHslSaturation FINAL)
Q_PROPERTY(qreal hslLightness READ hslLightness WRITE setHslLightness FINAL)
+ Q_PROPERTY(bool valid READ isValid)
Q_GADGET
public:
Q_INVOKABLE QString toString() const;
@@ -98,6 +99,7 @@ public:
qreal hslHue() const;
qreal hslSaturation() const;
qreal hslLightness() const;
+ bool isValid() const;
void setR(qreal);
void setG(qreal);
void setB(qreal);
diff --git a/src/quick/util/util.pri b/src/quick/util/util.pri
index c51f082d03..63d995e34c 100644
--- a/src/quick/util/util.pri
+++ b/src/quick/util/util.pri
@@ -15,6 +15,7 @@ SOURCES += \
$$PWD/qquicktimeline.cpp \
$$PWD/qquickpixmapcache.cpp \
$$PWD/qquickbehavior.cpp \
+ $$PWD/qquickboundaryrule.cpp \
$$PWD/qquickfontloader.cpp \
$$PWD/qquickstyledtext.cpp \
$$PWD/qquickimageprovider.cpp \
@@ -50,6 +51,7 @@ HEADERS += \
$$PWD/qquicktimeline_p_p.h \
$$PWD/qquickpixmapcache_p.h \
$$PWD/qquickbehavior_p.h \
+ $$PWD/qquickboundaryrule_p.h \
$$PWD/qquickfontloader_p.h \
$$PWD/qquickstyledtext_p.h \
$$PWD/qquickimageprovider.h \