Skip to content

Commit 382959a

Browse files
committedNov 25, 2024
Bug 1933094 - Simplify view invalidation. r=tnikkel,layout-reviewers
We only invalidate with the whole view dimensions so we can simplify the whole region code and just store a bool. Differential Revision: https://phabricator.services.mozilla.com/D230059
1 parent d32f377 commit 382959a

File tree

3 files changed

+14
-68
lines changed

3 files changed

+14
-68
lines changed
 

‎view/nsView.h

+3-12
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,6 @@ class nsView final : public nsIWidgetListener {
383383
mNextSibling = aSibling;
384384
}
385385

386-
nsRegion& GetDirtyRegion() {
387-
if (!mDirtyRegion) {
388-
NS_ASSERTION(!mParent, "Only display roots should have dirty regions");
389-
mDirtyRegion = mozilla::MakeUnique<nsRegion>();
390-
}
391-
return *mDirtyRegion;
392-
}
393-
394386
// nsIWidgetListener
395387
mozilla::PresShell* GetPresShell() override;
396388
nsView* GetView() override { return this; }
@@ -460,9 +452,8 @@ class nsView final : public nsIWidgetListener {
460452
// parent, if we can)
461453
void DropMouseGrabbing();
462454

463-
bool HasNonEmptyDirtyRegion() {
464-
return mDirtyRegion && !mDirtyRegion->IsEmpty();
465-
}
455+
bool IsDirty() const { return mIsDirty; }
456+
void SetIsDirty(bool aDirty) { mIsDirty = aDirty; }
466457

467458
void InsertChild(nsView* aChild, nsView* aSibling);
468459
void RemoveChild(nsView* aChild);
@@ -486,7 +477,6 @@ class nsView final : public nsIWidgetListener {
486477
nsView* mNextSibling;
487478
nsView* mFirstChild;
488479
nsIFrame* mFrame;
489-
mozilla::UniquePtr<nsRegion> mDirtyRegion;
490480
ViewVisibility mVis;
491481
// position relative our parent view origin but in our appunits
492482
nscoord mPosX, mPosY;
@@ -498,6 +488,7 @@ class nsView final : public nsIWidgetListener {
498488
bool mWidgetIsTopLevel;
499489
bool mForcedRepaint;
500490
bool mNeedsWindowPropertiesSync;
491+
bool mIsDirty = false;
501492
};
502493

503494
#endif

‎view/nsViewManager.cpp

+11-45
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ void nsViewManager::FlushDelayedResize() {
200200

201201
// Convert aIn from being relative to and in appunits of aFromView, to being
202202
// relative to and in appunits of aToView.
203-
static nsRegion ConvertRegionBetweenViews(const nsRegion& aIn,
204-
nsView* aFromView, nsView* aToView) {
205-
nsRegion out = aIn;
203+
static nsRect ConvertRectBetweenViews(const nsRect& aIn, nsView* aFromView,
204+
nsView* aToView) {
205+
nsRect out = aIn;
206206
out.MoveBy(aFromView->GetOffsetTo(aToView));
207207
out = out.ScaleToOtherAppUnitsRoundOut(
208208
aFromView->GetViewManager()->AppUnitsPerDevPixel(),
@@ -413,33 +413,20 @@ void nsViewManager::FlushDirtyRegionToWidget(nsView* aView) {
413413
NS_ASSERTION(aView->GetViewManager() == this,
414414
"FlushDirtyRegionToWidget called on view we don't own");
415415

416-
if (!aView->HasNonEmptyDirtyRegion()) {
416+
if (!aView->IsDirty()) {
417417
return;
418418
}
419419

420-
nsRegion& dirtyRegion = aView->GetDirtyRegion();
420+
const nsRect dirtyRegion = aView->GetDimensions();
421421
nsView* nearestViewWithWidget = aView;
422422
while (!nearestViewWithWidget->HasWidget() &&
423423
nearestViewWithWidget->GetParent()) {
424424
nearestViewWithWidget = nearestViewWithWidget->GetParent();
425425
}
426-
nsRegion r =
427-
ConvertRegionBetweenViews(dirtyRegion, aView, nearestViewWithWidget);
428-
426+
nsRect r = ConvertRectBetweenViews(dirtyRegion, aView, nearestViewWithWidget);
429427
nsViewManager* widgetVM = nearestViewWithWidget->GetViewManager();
430428
widgetVM->InvalidateWidgetArea(nearestViewWithWidget, r);
431-
dirtyRegion.SetEmpty();
432-
}
433-
434-
void nsViewManager::InvalidateView(nsView* aView) {
435-
// Mark the entire view as damaged
436-
InvalidateView(aView, aView->GetDimensions());
437-
}
438-
439-
static void AddDirtyRegion(nsView* aView, const nsRegion& aDamagedRegion) {
440-
nsRegion& dirtyRegion = aView->GetDirtyRegion();
441-
dirtyRegion.Or(dirtyRegion, aDamagedRegion);
442-
dirtyRegion.SimplifyOutward(8);
429+
aView->SetIsDirty(false);
443430
}
444431

445432
void nsViewManager::PostPendingUpdate() {
@@ -500,41 +487,20 @@ static bool ShouldIgnoreInvalidation(nsViewManager* aVM) {
500487
return false;
501488
}
502489

503-
void nsViewManager::InvalidateView(nsView* aView, const nsRect& aRect) {
490+
void nsViewManager::InvalidateView(nsView* aView) {
504491
// If painting is suppressed in the presshell or an ancestor drop all
505492
// invalidates, it will invalidate everything when it unsuppresses.
506493
if (ShouldIgnoreInvalidation(this)) {
507494
return;
508495
}
509496

510-
InvalidateViewNoSuppression(aView, aRect);
511-
}
512-
513-
void nsViewManager::InvalidateViewNoSuppression(nsView* aView,
514-
const nsRect& aRect) {
515-
MOZ_ASSERT(nullptr != aView, "null view");
516-
517497
NS_ASSERTION(aView->GetViewManager() == this,
518-
"InvalidateViewNoSuppression called on view we don't own");
498+
"InvalidateView called on view we don't own");
519499

520-
nsRect damagedRect(aRect);
521-
if (damagedRect.IsEmpty()) {
500+
if (aView->GetBounds().IsEmpty()) {
522501
return;
523502
}
524-
525-
nsView* displayRoot = GetDisplayRootFor(aView);
526-
nsViewManager* displayRootVM = displayRoot->GetViewManager();
527-
// Propagate the update to the displayRoot, since iframes, for example,
528-
// can overlap each other and be translucent. So we have to possibly
529-
// invalidate our rect in each of the widgets we have lying about.
530-
damagedRect.MoveBy(aView->GetOffsetTo(displayRoot));
531-
int32_t rootAPD = displayRootVM->AppUnitsPerDevPixel();
532-
int32_t APD = AppUnitsPerDevPixel();
533-
damagedRect = damagedRect.ScaleToOtherAppUnitsRoundOut(APD, rootAPD);
534-
535-
// accumulate this rectangle in the view's dirty region, so we can
536-
// process it later.
537-
AddDirtyRegion(displayRoot, nsRegion(damagedRect));
503+
GetDisplayRootFor(aView)->SetIsDirty(true);
538504
}
539505

540506
void nsViewManager::InvalidateAllViews() {

‎view/nsViewManager.h

-11
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,6 @@ class nsViewManager final {
108108
*/
109109
void InvalidateView(nsView* aView);
110110

111-
/**
112-
* Called to inform the view manager that some portion of a view is dirty and
113-
* needs to be redrawn. The rect passed in should be in the view's coordinate
114-
* space. Does not check for paint suppression.
115-
* @param aView view to paint. should be root view
116-
* @param rect rect to mark as damaged
117-
*/
118-
void InvalidateViewNoSuppression(nsView* aView, const nsRect& aRect);
119-
120111
/**
121112
* Called to inform the view manager that it should invalidate all views.
122113
*/
@@ -348,8 +339,6 @@ class nsViewManager final {
348339

349340
void SetPainting(bool aPainting) { RootViewManager()->mPainting = aPainting; }
350341

351-
void InvalidateView(nsView* aView, const nsRect& aRect);
352-
353342
nsViewManager* RootViewManager() const {
354343
return mRootViewManager ? mRootViewManager.get()
355344
: const_cast<nsViewManager*>(this);

0 commit comments

Comments
 (0)
Failed to load comments.