Bug 1671592 - Remove PuppetWidget::PaintTask and PuppetWidget::Paint r=emilio

After Bug 1669239, The way we use `PuppetWidget::Paint` starts to be
more async. For instance, `PuppetWidget::Invalidate` will schedule
an async `PaintTask`, when the `PaintTask` runs, it'll request
the next `Tick` to paint which is also async.

It starts to cause some tests to fail because of the timing. This
patch just improves the overall usage to be less async.

Differential Revision: https://phabricator.services.mozilla.com/D93855
This commit is contained in:
Sean Feng 2020-10-17 18:07:03 +00:00
Родитель 8264ddfcc9
Коммит 6eb1ed8c33
2 изменённых файлов: 21 добавлений и 56 удалений

Просмотреть файл

@ -162,7 +162,6 @@ void PuppetWidget::Destroy() {
Base::OnDestroy();
Base::Destroy();
mPaintTask.Revoke();
if (mMemoryPressureObserver) {
mMemoryPressureObserver->Unregister();
mMemoryPressureObserver = nullptr;
@ -269,11 +268,10 @@ void PuppetWidget::Invalidate(const LayoutDeviceIntRect& aRect) {
return;
}
if (mBrowserChild && !aRect.IsEmpty() && !mPaintTask.IsPending()) {
mPaintTask = new PaintTask(this, false);
nsCOMPtr<nsIRunnable> event(mPaintTask.get());
SchedulerGroup::Dispatch(TaskCategory::Other, event.forget());
return;
if (mBrowserChild && !aRect.IsEmpty()) {
if (RefPtr<nsRefreshDriver> refreshDriver = GetTopLevelRefreshDriver()) {
refreshDriver->ScheduleViewManagerFlush();
}
}
}
@ -701,6 +699,18 @@ bool PuppetWidget::HaveValidInputContextCache() const {
IMEStateManager::GetWidgetForActiveInputContext() == this);
}
nsRefreshDriver* PuppetWidget::GetTopLevelRefreshDriver() const {
if (!mBrowserChild) {
return nullptr;
}
if (PresShell* presShell = mBrowserChild->GetTopLevelPresShell()) {
return presShell->GetRefreshDriver();
}
return nullptr;
}
void PuppetWidget::SetInputContext(const InputContext& aContext,
const InputContextAction& aAction) {
mInputContext = aContext;
@ -979,30 +989,6 @@ void PuppetWidget::ClearCachedCursor() {
mCustomCursor = nullptr;
}
nsresult PuppetWidget::Paint(bool aDoTick) {
if (!GetCurrentWidgetListener()) {
return NS_OK;
}
// reset repaint tracking
mPaintTask.Revoke();
RefPtr<PuppetWidget> strongThis(this);
if (PresShell* presShell = mBrowserChild->GetTopLevelPresShell()) {
if (RefPtr<nsRefreshDriver> refreshDriver = presShell->GetRefreshDriver()) {
refreshDriver->ScheduleViewManagerFlush();
// The Tick here is mainly for optimization purpose; Ticking
// here allows us to notify layer updates faster.
if (aDoTick) {
refreshDriver->DoTick();
}
}
}
return NS_OK;
}
void PuppetWidget::SetChild(PuppetWidget* aChild) {
MOZ_ASSERT(this != aChild, "can't parent a widget to itself");
MOZ_ASSERT(!aChild->mChild,
@ -1011,17 +997,11 @@ void PuppetWidget::SetChild(PuppetWidget* aChild) {
mChild = aChild;
}
NS_IMETHODIMP
PuppetWidget::PaintTask::Run() {
if (mWidget) {
mWidget->Paint(mDoTick);
}
return NS_OK;
}
void PuppetWidget::PaintNowIfNeeded() {
if (IsVisible() && mPaintTask.IsPending()) {
Paint(true);
if (IsVisible()) {
if (RefPtr<nsRefreshDriver> refreshDriver = GetTopLevelRefreshDriver()) {
refreshDriver->DoTick();
}
}
}

Просмотреть файл

@ -326,8 +326,6 @@ class PuppetWidget : public nsBaseWidget,
virtual void OnMemoryPressure(layers::MemoryPressureReason aWhy) override;
private:
nsresult Paint(bool aDoTick);
void SetChild(PuppetWidget* aChild);
nsresult RequestIMEToCommitComposition(bool aCancel);
@ -352,19 +350,7 @@ class PuppetWidget : public nsBaseWidget,
// IMEStateManager, the cache is valid.
bool HaveValidInputContextCache() const;
class PaintTask : public Runnable {
public:
NS_DECL_NSIRUNNABLE
explicit PaintTask(PuppetWidget* widget, bool aDoTick)
: Runnable("PuppetWidget::PaintTask"),
mWidget(widget),
mDoTick(aDoTick) {}
void Revoke() { mWidget = nullptr; }
private:
PuppetWidget* mWidget;
bool mDoTick;
};
nsRefreshDriver* GetTopLevelRefreshDriver() const;
// BrowserChild normally holds a strong reference to this PuppetWidget
// or its root ancestor, but each PuppetWidget also needs a
@ -376,7 +362,6 @@ class PuppetWidget : public nsBaseWidget,
// The "widget" to which we delegate events if we don't have an
// event handler.
RefPtr<PuppetWidget> mChild;
nsRevocableEventPtr<PaintTask> mPaintTask;
RefPtr<layers::MemoryPressureObserver> mMemoryPressureObserver;
// XXX/cjones: keeping this around until we teach LayerManager to do
// retained-content-only transactions