6#include "QskDirtyItemFilter.h"
10#include <private/qquickitem_p.h>
11#include <private/qquickwindow_p.h>
14static inline bool qskIsUpdateBlocked(
const QQuickItem* item )
16 if ( !item->isVisible() )
18 if (
auto qskItem = qobject_cast< const QskItem* >( item ) )
28 else if (
const auto control = qskControlCast( item ) )
30 const QRectF itemRect( item->mapToScene( QPointF() ), item->size() );
31 const QRectF sceneRect( 0, 0, item->window()->width(), item->window()->height() );
33 return !itemRect.intersects( sceneRect );
40static inline void qskBlockDirty( QQuickItem* item,
bool on )
42 if ( qskIsUpdateBlocked( item ) )
43 QQuickItemPrivate::get( item )->componentComplete = !on;
45 const auto children = item->childItems();
46 for (
auto child : children )
47 qskBlockDirty( child, on );
52 class ResetBlockedDirtyJob final :
public QRunnable
55 inline ResetBlockedDirtyJob( QQuickWindow* window )
62 qskBlockDirty( m_window->contentItem(),
false );
66 const QQuickWindow* m_window;
70QskDirtyItemFilter::QskDirtyItemFilter( QObject* parent )
75QskDirtyItemFilter::~QskDirtyItemFilter()
79void QskDirtyItemFilter::addWindow( QQuickWindow* window )
81 if ( m_windows.contains( window ) )
84 m_windows.insert( window );
96 connect( window, &QQuickWindow::beforeSynchronizing,
97 window, [
this, window ] { beforeSynchronizing( window ); },
98 Qt::DirectConnection );
100 connect( window, &QObject::destroyed,
101 this, [
this, window ] { m_windows.remove( window ); } );
104void QskDirtyItemFilter::beforeSynchronizing( QQuickWindow* window )
106 filterDirtyList( window, qskIsUpdateBlocked );
108 if ( QQuickWindowPrivate::get( window )->renderer ==
nullptr )
116 qskBlockDirty( window->contentItem(),
true );
118 window->scheduleRenderJob(
new ResetBlockedDirtyJob( window ),
119 QQuickWindow::AfterSynchronizingStage );
123void QskDirtyItemFilter::filterDirtyList(
124 QQuickWindow* window,
bool ( *isBlocked )(
const QQuickItem* ) )
126 if ( window ==
nullptr )
129 auto d = QQuickWindowPrivate::get( window );
130 for (
auto item = d->dirtyItemList; item !=
nullptr; )
132 auto nextItem = QQuickItemPrivate::get( item )->nextDirtyItem;
134 if ( isBlocked( item ) )
135 QQuickItemPrivate::get( item )->removeFromDirtyList();