Skip to content

Commit

Permalink
Bug 1733465 part 5: Store nsView::mDirtyRegion in a UniquePtr rather …
Browse files Browse the repository at this point in the history
…than a raw pointer. r=tnikkel

This lets us remove the last explicit 'delete' invocation from the /view
subdirectory. Hooray!

As part of this change, I'm also updating the getter for this member-var to
return a reference instead of a pointer, since it's infallible.

Differential Revision: https://phabricator.services.mozilla.com/D127187
  • Loading branch information
dholbert committed Oct 1, 2021
1 parent 1d08981 commit 582d90d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
3 changes: 0 additions & 3 deletions view/nsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ nsView::nsView(nsViewManager* aViewManager, nsViewVisibility aVisibility)
mNextSibling(nullptr),
mFirstChild(nullptr),
mFrame(nullptr),
mDirtyRegion(nullptr),
mZIndex(0),
mVis(aVisibility),
mPosX(0),
Expand Down Expand Up @@ -104,8 +103,6 @@ nsView::~nsView() {
DestroyWidget();

MOZ_RELEASE_ASSERT(!mFrame);

delete mDirtyRegion;
}

class DestroyWidgetRunnable : public Runnable {
Expand Down
10 changes: 5 additions & 5 deletions view/nsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Units.h"
#include "mozilla/Attributes.h"
#include "mozilla/EventForwards.h"
#include "mozilla/UniquePtr.h"

class nsViewManager;
class nsIWidget;
Expand Down Expand Up @@ -431,14 +432,13 @@ class nsView final : public nsIWidgetListener {
mNextSibling = aSibling;
}

nsRegion* GetDirtyRegion() {
nsRegion& GetDirtyRegion() {
if (!mDirtyRegion) {
NS_ASSERTION(!mParent || GetFloating(),
"Only display roots should have dirty regions");
mDirtyRegion = new nsRegion();
NS_ASSERTION(mDirtyRegion, "Out of memory!");
mDirtyRegion = mozilla::MakeUnique<nsRegion>();
}
return mDirtyRegion;
return *mDirtyRegion;
}

// nsIWidgetListener
Expand Down Expand Up @@ -547,7 +547,7 @@ class nsView final : public nsIWidgetListener {
nsView* mNextSibling;
nsView* mFirstChild;
nsIFrame* mFrame;
nsRegion* mDirtyRegion;
mozilla::UniquePtr<nsRegion> mDirtyRegion;
int32_t mZIndex;
nsViewVisibility mVis;
// position relative our parent view origin but in our appunits
Expand Down
18 changes: 9 additions & 9 deletions view/nsViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,20 +453,22 @@ void nsViewManager::FlushDirtyRegionToWidget(nsView* aView) {
NS_ASSERTION(aView->GetViewManager() == this,
"FlushDirtyRegionToWidget called on view we don't own");

if (!aView->HasNonEmptyDirtyRegion()) return;
if (!aView->HasNonEmptyDirtyRegion()) {
return;
}

nsRegion* dirtyRegion = aView->GetDirtyRegion();
nsRegion& dirtyRegion = aView->GetDirtyRegion();
nsView* nearestViewWithWidget = aView;
while (!nearestViewWithWidget->HasWidget() &&
nearestViewWithWidget->GetParent()) {
nearestViewWithWidget = nearestViewWithWidget->GetParent();
}
nsRegion r =
ConvertRegionBetweenViews(*dirtyRegion, aView, nearestViewWithWidget);
ConvertRegionBetweenViews(dirtyRegion, aView, nearestViewWithWidget);

nsViewManager* widgetVM = nearestViewWithWidget->GetViewManager();
widgetVM->InvalidateWidgetArea(nearestViewWithWidget, r);
dirtyRegion->SetEmpty();
dirtyRegion.SetEmpty();
}

void nsViewManager::InvalidateView(nsView* aView) {
Expand All @@ -475,11 +477,9 @@ void nsViewManager::InvalidateView(nsView* aView) {
}

static void AddDirtyRegion(nsView* aView, const nsRegion& aDamagedRegion) {
nsRegion* dirtyRegion = aView->GetDirtyRegion();
if (!dirtyRegion) return;

dirtyRegion->Or(*dirtyRegion, aDamagedRegion);
dirtyRegion->SimplifyOutward(8);
nsRegion& dirtyRegion = aView->GetDirtyRegion();
dirtyRegion.Or(dirtyRegion, aDamagedRegion);
dirtyRegion.SimplifyOutward(8);
}

void nsViewManager::PostPendingUpdate() {
Expand Down

0 comments on commit 582d90d

Please sign in to comment.