Skip to content

Commit

Permalink
Bug 1722258 - Split out fallible composite-only path of PresShell::Pa…
Browse files Browse the repository at this point in the history
…int. r=miko

Differential Revision: https://phabricator.services.mozilla.com/D120919
  • Loading branch information
mattwoodrow committed Aug 5, 2021
1 parent 0e54896 commit 9b81728
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 24 deletions.
5 changes: 2 additions & 3 deletions dom/base/nsDOMWindowUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,8 @@ nsDOMWindowUtils::UpdateLayerTree() {
RefPtr<nsViewManager> vm = presShell->GetViewManager();
if (nsView* view = vm->GetRootView()) {
nsAutoScriptBlocker scriptBlocker;
presShell->Paint(
view, view->GetBounds(),
PaintFlags::PaintLayers | PaintFlags::PaintSyncDecodeImages);
presShell->Paint(view, view->GetBounds(),
PaintFlags::PaintSyncDecodeImages);
presShell->GetWindowRenderer()->WaitOnTransactionProcessed();
}
}
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/BrowserChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2727,7 +2727,7 @@ mozilla::ipc::IPCResult BrowserChild::RecvRenderLayers(
} else {
RefPtr<nsViewManager> vm = presShell->GetViewManager();
if (nsView* view = vm->GetRootView()) {
presShell->Paint(view, view->GetBounds(), PaintFlags::PaintLayers);
presShell->Paint(view, view->GetBounds(), PaintFlags::None);
}
}
presShell->SuppressDisplayport(false);
Expand Down
44 changes: 30 additions & 14 deletions layout/base/PresShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6248,6 +6248,36 @@ class nsAutoNotifyDidPaint {
PaintFlags mFlags;
};

bool PresShell::Composite(nsView* aViewToPaint) {
nsCString url;
nsIURI* uri = mDocument->GetDocumentURI();
Document* contentRoot = GetPrimaryContentDocument();
if (contentRoot) {
uri = contentRoot->GetDocumentURI();
}
url = uri ? uri->GetSpecOrDefault() : "N/A"_ns;
AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING("PresShell::Composite", GRAPHICS, url);

nsIFrame* frame = aViewToPaint->GetFrame();
WindowRenderer* renderer = aViewToPaint->GetWidget()->GetWindowRenderer();
NS_ASSERTION(renderer, "Must be in paint event");

if (!renderer->BeginTransaction(url)) {
// If we can't begin a transaction and paint, then there's not
// much the caller can do.
return true;
}

if (frame) {
if (renderer->EndEmptyTransaction()) {
GetPresContext()->NotifyDidPaintForSubtree();
return true;
}
NS_WARNING("Must complete empty transaction when compositing!");
}
return false;
}

void PresShell::Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,
PaintFlags aFlags) {
nsCString url;
Expand Down Expand Up @@ -6326,20 +6356,6 @@ void PresShell::Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,
}

if (frame) {
// Try to do an empty transaction, if the frame tree does not
// need to be updated. Do not try to do an empty transaction on
// a non-retained layer manager (like the BasicLayerManager that
// draws the window title bar on Mac), because a) it won't work
// and b) below we don't want to clear NS_FRAME_UPDATE_LAYER_TREE,
// that will cause us to forget to update the real layer manager!

if (!(aFlags & PaintFlags::PaintLayers)) {
if (renderer->EndEmptyTransaction()) {
return;
}
NS_WARNING("Must complete empty transaction when compositing!");
}

if (!(aFlags & PaintFlags::PaintSyncDecodeImages) &&
!frame->HasAnyStateBits(NS_FRAME_UPDATE_LAYER_TREE) &&
!mNextPaintCompressed) {
Expand Down
2 changes: 2 additions & 0 deletions layout/base/PresShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,8 @@ class PresShell final : public nsStubDocumentObserver,
void Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,
PaintFlags aFlags);

bool Composite(nsView* aViewToPaint);

/**
* Notify that we're going to call Paint with PaintFlags::PaintLayers
* on the pres shell for a widget (which might not be this one, since
Expand Down
4 changes: 0 additions & 4 deletions layout/base/PresShellForwards.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(AddCanvasBackgroundColorFlags)

enum class PaintFlags {
None = 0,
/* Update the layer tree and paint PaintedLayers. If this is not specified,
* we may still have to do it if the layer tree lost PaintedLayer contents
* we need for compositing. */
PaintLayers = 1 << 0,
/* Composite layers to the window. */
PaintComposite = 1 << 1,
/* Sync-decode images. */
Expand Down
9 changes: 7 additions & 2 deletions view/nsViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,12 @@ void nsViewManager::Refresh(nsView* aView,
if (!renderer->NeedsWidgetInvalidation()) {
renderer->FlushRendering();
} else {
presShell->Paint(aView, damageRegion, PaintFlags::PaintComposite);
// Try to just Composite the current WindowRenderer contents. If
// that fails then we need tor repaint, and request that it gets
// composited as well.
if (!presShell->Composite(aView)) {
presShell->Paint(aView, damageRegion, PaintFlags::PaintComposite);
}
}
#ifdef MOZ_DUMP_PAINTING
if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) {
Expand Down Expand Up @@ -456,7 +461,7 @@ void nsViewManager::ProcessPendingUpdatesPaint(nsIWidget* aWidget) {
}
#endif

presShell->Paint(view, nsRegion(), PaintFlags::PaintLayers);
presShell->Paint(view, nsRegion(), PaintFlags::None);
view->SetForcedRepaint(false);

#ifdef MOZ_DUMP_PAINTING
Expand Down

0 comments on commit 9b81728

Please sign in to comment.