6#include "QskDirtyItemFilter.h"
8#include "QskInternalMacros.h"
11#include <private/qquickitem_p.h>
12#include <private/qquickwindow_p.h>
15static inline bool qskIsUpdateBlocked(
const QQuickItem* item )
17 if ( !item->isVisible() )
19 if (
auto qskItem = qobject_cast< const QskItem* >( item ) )
29 else if (
const auto control = qskControlCast( item ) )
31 const QRectF itemRect( item->mapToScene( QPointF() ), item->size() );
32 const QRectF sceneRect( 0, 0, item->window()->width(), item->window()->height() );
34 return !itemRect.intersects( sceneRect );
41static inline void qskBlockDirty( QQuickItem* item,
bool on )
43 if ( qskIsUpdateBlocked( item ) )
44 QQuickItemPrivate::get( item )->componentComplete = !on;
46 const auto children = item->childItems();
47 for (
auto child : children )
48 qskBlockDirty( child, on );
53 class ResetBlockedDirtyJob final :
public QRunnable
56 inline ResetBlockedDirtyJob( QQuickWindow* window )
63 qskBlockDirty( m_window->contentItem(),
false );
67 const QQuickWindow* m_window;
71QskDirtyItemFilter::QskDirtyItemFilter( QObject* parent )
76QskDirtyItemFilter::~QskDirtyItemFilter()
80void QskDirtyItemFilter::addWindow( QQuickWindow* window )
82 if ( m_windows.contains( window ) )
85 m_windows.insert( window );
97 connect( window, &QQuickWindow::beforeSynchronizing,
98 window, [
this, window ] { beforeSynchronizing( window ); },
99 Qt::DirectConnection );
101 connect( window, &QObject::destroyed,
102 this, [
this, window ] { m_windows.remove( window ); } );
105void QskDirtyItemFilter::beforeSynchronizing( QQuickWindow* window )
107 filterDirtyList( window, qskIsUpdateBlocked );
109 if ( QQuickWindowPrivate::get( window )->renderer ==
nullptr )
117 qskBlockDirty( window->contentItem(),
true );
119 window->scheduleRenderJob(
new ResetBlockedDirtyJob( window ),
120 QQuickWindow::AfterSynchronizingStage );
124void QskDirtyItemFilter::filterDirtyList(
125 QQuickWindow* window,
bool ( *isBlocked )(
const QQuickItem* ) )
127 if ( window ==
nullptr )
130 auto d = QQuickWindowPrivate::get( window );
131 for (
auto item = d->dirtyItemList; item !=
nullptr; )
133 auto nextItem = QQuickItemPrivate::get( item )->nextDirtyItem;
135 if ( isBlocked( item ) )
136 QQuickItemPrivate::get( item )->removeFromDirtyList();