Bug 1686220 - Invalidate paint on image load, not on size available. r=tnikkel

Invalidating paint on size available is too soon (we can't decode the
image anyways). Bullet frames didn't use to do this and just reflowed.

Scheduling a paint causes us to do layout way too soon when there's more
important stuff to do for the load of the page.

This is a big improvement on load times and visual metrics in a variety
of websites:

  https://treeherder.mozilla.org/perfherder/compare?originalProject=try&originalRevision=3e012dad47b7f4b22741faa46153e940d079a260&newProject=try&newRevision=ce14456c07318eb3fc8d94d9cff9f41d9d122752&framework=13

Differential Revision: https://phabricator.services.mozilla.com/D104065
This commit is contained in:
Emilio Cobos Álvarez 2021-02-04 22:20:15 +00:00
parent d38fde0c61
commit c045cd7489

View File

@ -31,8 +31,7 @@
using namespace mozilla::dom;
namespace mozilla {
namespace css {
namespace mozilla::css {
// This is a singleton observer which looks in the `GlobalRequestTable` to look
// at which loaders to notify.
@ -719,9 +718,6 @@ void ImageLoader::OnSizeAvailable(imgIRequest* aRequest,
fwf.mFrame->PresShell()->FrameNeedsReflow(
fwf.mFrame, IntrinsicDirty::StyleChange, NS_FRAME_IS_DIRTY);
}
if (fwf.mFrame->StyleVisibility()->IsVisible()) {
fwf.mFrame->SchedulePaint();
}
}
}
@ -794,23 +790,28 @@ void ImageLoader::OnLoadComplete(imgIRequest* aRequest) {
return;
}
uint32_t status = 0;
if (NS_FAILED(aRequest->GetImageStatus(&status))) {
return;
}
FrameSet* frameSet = mRequestToFrameMap.Get(aRequest);
if (!frameSet) {
return;
}
// Check if aRequest has an error state. If it does, we need to unblock
// Document onload for all the frames associated with this request that
// have blocked onload. This is what happens in a CORS mode violation, and
// may happen during other network events.
uint32_t status = 0;
if (NS_SUCCEEDED(aRequest->GetImageStatus(&status)) &&
status & imgIRequest::STATUS_ERROR) {
for (FrameWithFlags& fwf : *frameSet) {
for (FrameWithFlags& fwf : *frameSet) {
if (status & imgIRequest::STATUS_ERROR) {
// Check if aRequest has an error state. If it does, we need to unblock
// Document onload for all the frames associated with this request that
// have blocked onload. This is what happens in a CORS mode violation, and
// may happen during other network events.
UnblockOnloadIfNeeded(fwf);
}
if (fwf.mFrame->StyleVisibility()->IsVisible()) {
fwf.mFrame->SchedulePaint();
}
}
}
} // namespace css
} // namespace mozilla
} // namespace mozilla::css