From a7362cdfa071e2987e403245f0c58936485d1fba Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Mon, 15 Jun 2009 17:49:06 +0200 Subject: Optimization: Don't determine the expose if the item is invisible. If the item either sets the ItemHasNoContents flag, or if it's invisible but has child items that are not (and ignore parent opacity), then don't bother calculating the item's exposed view rect as the item will not get drawn anyway. This carves down the number of QTransform::mapRect operations by 25% when running the Declarative UI calculator transition. We'll proceed to removing such operations from the markDirty step as well. Reviewed-by: bnilsen --- src/gui/graphicsview/qgraphicsscene.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 673fd23..38a1abe 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -5073,6 +5073,9 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * opacity = parentOpacity; } + // Item is invisible. + bool invisible = !item || ((item->d_ptr->flags & QGraphicsItem::ItemHasNoContents) || invisibleButChildIgnoresParentOpacity); + // Calculate the full transform for this item. bool wasDirtyParentSceneTransform = false; bool dontDrawItem = true; @@ -5092,16 +5095,18 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * transform *= viewTransform; } - QRectF brect = item->boundingRect(); - // ### This does not take the clip into account. - _q_adjustRect(&brect); - QRect viewBoundingRect = transform.mapRect(brect).toRect(); - item->d_ptr->paintedViewBoundingRects.insert(widget, viewBoundingRect); - viewBoundingRect.adjust(-1, -1, 1, 1); - if (exposedRegion) - dontDrawItem = !exposedRegion->intersects(viewBoundingRect); - else - dontDrawItem = viewBoundingRect.isEmpty(); + if (!invisible) { + QRectF brect = item->boundingRect(); + // ### This does not take the clip into account. + _q_adjustRect(&brect); + QRect viewBoundingRect = transform.mapRect(brect).toRect(); + item->d_ptr->paintedViewBoundingRects.insert(widget, viewBoundingRect); + viewBoundingRect.adjust(-1, -1, 1, 1); + if (exposedRegion) + dontDrawItem = !exposedRegion->intersects(viewBoundingRect); + else + dontDrawItem = viewBoundingRect.isEmpty(); + } } // Find and sort children. @@ -5158,7 +5163,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * bool childClip = (item && (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape)); bool dontDrawChildren = item && dontDrawItem && childClip; childClip &= !dontDrawChildren && !children->isEmpty(); - if (item && ((item->d_ptr->flags & QGraphicsItem::ItemHasNoContents) || invisibleButChildIgnoresParentOpacity)) + if (item && invisible) dontDrawItem = true; // Clip children. -- cgit v0.12