Skip to content

Commit 3dd74e0

Browse files
committedJun 22, 2023
Bug 1837960. Remove array of all nsViewManagers. r=emilio
The only thing it's used for is calling will paint on a document tree. To iterate every viewmanager looking for those in one document tree is a bit silly, we can just walk the view tree. Since there are only 3 types of views (root views, popup views for menupopupframes, and subdocument frame views (and their inner view)) we don't have to walk many pointers: menupopupframes are controlled by chrome code and are limited, and the other two types of views correspond to the number of view managers in the tree (one view manager per document). Differential Revision: https://phabricator.services.mozilla.com/D180677
1 parent 9ae30df commit 3dd74e0

File tree

2 files changed

+25
-39
lines changed

2 files changed

+25
-39
lines changed
 

‎view/nsViewManager.cpp

+22-36
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ using namespace mozilla::layers;
4949

5050
#undef DEBUG_MOUSE_LOCATION
5151

52-
// Weakly held references to all of the view managers
53-
StaticAutoPtr<nsTArray<nsViewManager*>> nsViewManager::gViewManagers;
5452
uint32_t nsViewManager::gLastUserEventTime = 0;
5553

5654
nsViewManager::nsViewManager()
@@ -60,14 +58,7 @@ nsViewManager::nsViewManager()
6058
mRefreshDisableCount(0),
6159
mPainting(false),
6260
mRecursiveRefreshPending(false),
63-
mHasPendingWidgetGeometryChanges(false) {
64-
if (gViewManagers == nullptr) {
65-
// Create an array to hold a list of view managers
66-
gViewManagers = new nsTArray<nsViewManager*>;
67-
}
68-
69-
gViewManagers->AppendElement(this);
70-
}
61+
mHasPendingWidgetGeometryChanges(false) {}
7162

7263
nsViewManager::~nsViewManager() {
7364
if (mRootView) {
@@ -78,22 +69,6 @@ nsViewManager::~nsViewManager() {
7869

7970
mRootViewManager = nullptr;
8071

81-
NS_ASSERTION(gViewManagers != nullptr, "About to use null gViewManagers");
82-
83-
#ifdef DEBUG
84-
bool removed =
85-
#endif
86-
gViewManagers->RemoveElement(this);
87-
NS_ASSERTION(
88-
removed,
89-
"Viewmanager instance was not in the global list of viewmanagers");
90-
91-
if (gViewManagers->IsEmpty()) {
92-
// There aren't any more view managers so
93-
// release the global array of view managers
94-
gViewManagers = nullptr;
95-
}
96-
9772
MOZ_RELEASE_ASSERT(!mPresShell,
9873
"Releasing nsViewManager without having called Destroy on "
9974
"the PresShell!");
@@ -960,22 +935,33 @@ void nsViewManager::UpdateWidgetGeometry() {
960935
}
961936
}
962937

938+
/* static */ void nsViewManager::CollectVMsForWillPaint(
939+
nsView* aView, nsViewManager* aParentVM,
940+
nsTArray<RefPtr<nsViewManager>>& aVMs) {
941+
nsViewManager* vm = aView->GetViewManager();
942+
if (vm != aParentVM) {
943+
aVMs.AppendElement(vm);
944+
}
945+
946+
for (nsView* child = aView->GetFirstChild(); child;
947+
child = child->GetNextSibling()) {
948+
CollectVMsForWillPaint(child, vm, aVMs);
949+
}
950+
}
951+
963952
void nsViewManager::CallWillPaintOnObservers() {
964953
MOZ_ASSERT(IsRootVM(), "Must be root VM for this to be called!");
965954

966-
if (NS_WARN_IF(!gViewManagers)) {
955+
if (!mRootView) {
967956
return;
968957
}
969958

970-
uint32_t index;
971-
for (index = 0; index < gViewManagers->Length(); index++) {
972-
nsViewManager* vm = gViewManagers->ElementAt(index);
973-
if (vm->RootViewManager() == this) {
974-
// One of our kids.
975-
if (vm->mRootView && vm->mRootView->IsEffectivelyVisible()) {
976-
if (RefPtr<PresShell> presShell = vm->GetPresShell()) {
977-
presShell->WillPaint();
978-
}
959+
AutoTArray<RefPtr<nsViewManager>, 2> VMs;
960+
CollectVMsForWillPaint(mRootView, nullptr, VMs);
961+
for (const auto& vm : VMs) {
962+
if (vm->GetRootView() && vm->GetRootView()->IsEffectivelyVisible()) {
963+
if (RefPtr<PresShell> presShell = vm->GetPresShell()) {
964+
presShell->WillPaint();
979965
}
980966
}
981967
}

‎view/nsViewManager.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ class nsViewManager final {
342342
* Call WillPaint() on all view observers under this vm root.
343343
*/
344344
MOZ_CAN_RUN_SCRIPT_BOUNDARY void CallWillPaintOnObservers();
345+
static void CollectVMsForWillPaint(nsView* aView, nsViewManager* aParentVM,
346+
nsTArray<RefPtr<nsViewManager>>& aVMs);
347+
345348
void ReparentChildWidgets(nsView* aView, nsIWidget* aNewWidget);
346349
void ReparentWidgets(nsView* aView, nsView* aParent);
347350
void InvalidateWidgetArea(nsView* aWidgetView,
@@ -422,9 +425,6 @@ class nsViewManager final {
422425
bool mHasPendingWidgetGeometryChanges;
423426

424427
// from here to public should be static and locked... MMP
425-
426-
// list of view managers
427-
static mozilla::StaticAutoPtr<nsTArray<nsViewManager*>> gViewManagers;
428428
};
429429

430430
/**

0 commit comments

Comments
 (0)
Failed to load comments.