Bug 1689156 - Bring the fast tab switch paint back r=mstange,mattwoodrow

In bug 1669239, we removed the magic paint which would occur during tab
switches, and instead we requested a tick. However, this approach
didn't work well because tick was a heavy operation which did not
only paints but also many other stuff, such as running
requestAnimationFrame handlers, so it made the tab switches slower
under certain conditions.

So here we reverts the changes we made in bug 1669239.

Differential Revision: https://phabricator.services.mozilla.com/D107858
This commit is contained in:
Sean Feng 2021-03-22 20:49:04 +00:00
parent f612c014e0
commit 706997d444
2 changed files with 42 additions and 8 deletions

View File

@ -268,10 +268,10 @@ void PuppetWidget::Invalidate(const LayoutDeviceIntRect& aRect) {
return;
}
if (mBrowserChild && !aRect.IsEmpty()) {
if (RefPtr<nsRefreshDriver> refreshDriver = GetTopLevelRefreshDriver()) {
refreshDriver->ScheduleViewManagerFlush();
}
if (mBrowserChild && !aRect.IsEmpty() && !mWidgetPaintTask.IsPending()) {
mWidgetPaintTask = new WidgetPaintTask(this);
nsCOMPtr<nsIRunnable> event(mWidgetPaintTask.get());
SchedulerGroup::Dispatch(TaskCategory::Other, event.forget());
}
}
@ -963,11 +963,31 @@ void PuppetWidget::SetChild(PuppetWidget* aChild) {
mChild = aChild;
}
NS_IMETHODIMP
PuppetWidget::WidgetPaintTask::Run() {
if (mWidget) {
mWidget->Paint();
}
return NS_OK;
}
void PuppetWidget::Paint() {
if (!GetCurrentWidgetListener()) return;
mWidgetPaintTask.Revoke();
RefPtr<PuppetWidget> strongThis(this);
GetCurrentWidgetListener()->WillPaintWindow(this);
if (GetCurrentWidgetListener()) {
GetCurrentWidgetListener()->DidPaintWindow();
}
}
void PuppetWidget::PaintNowIfNeeded() {
if (IsVisible()) {
if (RefPtr<nsRefreshDriver> refreshDriver = GetTopLevelRefreshDriver()) {
refreshDriver->DoTick();
}
if (IsVisible() && mWidgetPaintTask.IsPending()) {
Paint();
}
}

View File

@ -316,6 +316,8 @@ class PuppetWidget : public nsBaseWidget,
virtual void OnMemoryPressure(layers::MemoryPressureReason aWhy) override;
private:
void Paint();
void SetChild(PuppetWidget* aChild);
nsresult RequestIMEToCommitComposition(bool aCancel);
@ -340,6 +342,17 @@ class PuppetWidget : public nsBaseWidget,
// IMEStateManager, the cache is valid.
bool HaveValidInputContextCache() const;
class WidgetPaintTask : public Runnable {
public:
NS_DECL_NSIRUNNABLE
explicit WidgetPaintTask(PuppetWidget* widget)
: Runnable("PuppetWidget::WidgetPaintTask"), mWidget(widget) {}
void Revoke() { mWidget = nullptr; }
private:
PuppetWidget* mWidget;
};
nsRefreshDriver* GetTopLevelRefreshDriver() const;
// BrowserChild normally holds a strong reference to this PuppetWidget
@ -352,6 +365,7 @@ class PuppetWidget : public nsBaseWidget,
// The "widget" to which we delegate events if we don't have an
// event handler.
RefPtr<PuppetWidget> mChild;
nsRevocableEventPtr<WidgetPaintTask> mWidgetPaintTask;
RefPtr<layers::MemoryPressureObserver> mMemoryPressureObserver;
// XXX/cjones: keeping this around until we teach LayerManager to do
// retained-content-only transactions