Bug 1772692 - AnimationInfo::EnumerateGenerationOnFrame shouldn't need to create a window renderer. r=hiro

There's no need to lazily create a renderer here. We already avoided
this in content processes, but there's no need to do so in the parent
process either.

This shouldn't change behavior, but might help with bug 1772691, and
generally seems cleaner.

Differential Revision: https://phabricator.services.mozilla.com/D148337
This commit is contained in:
Emilio Cobos Álvarez 2022-06-05 23:20:45 +00:00
Родитель 9b518ab15c
Коммит 94ea7b0820
4 изменённых файлов: 46 добавлений и 48 удалений

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

@ -171,55 +171,47 @@ void AnimationInfo::EnumerateGenerationOnFrame(
const nsIFrame* aFrame, const nsIContent* aContent,
const CompositorAnimatableDisplayItemTypes& aDisplayItemTypes,
AnimationGenerationCallback aCallback) {
if (XRE_IsContentProcess()) {
if (nsIWidget* widget = nsContentUtils::WidgetForContent(aContent)) {
// In case of child processes, we might not have yet created the layer
// manager. That means there is no animation generation we have, thus
// we call the callback function with |Nothing()| for the generation.
//
// Note that we need to use nsContentUtils::WidgetForContent() instead of
// BrowserChild::GetFrom(aFrame->PresShell())->WebWidget() because in the
// case of child popup content PuppetWidget::mBrowserChild is the same as
// the parent's one, which means mBrowserChild->IsLayersConnected() check
// in PuppetWidget::GetLayerManager queries the parent state, it results
// the assertion in the function failure.
if (widget->GetOwningBrowserChild() &&
!static_cast<widget::PuppetWidget*>(widget)->HasWindowRenderer()) {
for (auto displayItem : LayerAnimationInfo::sDisplayItemTypes) {
aCallback(Nothing(), displayItem);
}
return;
}
}
nsIWidget* widget = nsContentUtils::WidgetForContent(aContent);
if (!widget) {
return;
}
WindowRenderer* renderer = nsContentUtils::WindowRendererForContent(aContent);
if (renderer && renderer->AsWebRender()) {
// In case of continuation, nsDisplayItem uses its last continuation, so we
// have to use the last continuation frame here.
if (nsLayoutUtils::IsFirstContinuationOrIBSplitSibling(aFrame)) {
aFrame = nsLayoutUtils::LastContinuationOrIBSplitSibling(aFrame);
}
// If we haven't created a window renderer there's no animation generation
// that we can have, thus we call the callback function with |Nothing()| for
// the generation.
if (!widget->HasWindowRenderer()) {
for (auto displayItem : LayerAnimationInfo::sDisplayItemTypes) {
// For transform animations, the animation is on the primary frame but
// |aFrame| is the style frame.
const nsIFrame* frameToQuery =
displayItem == DisplayItemType::TYPE_TRANSFORM
? nsLayoutUtils::GetPrimaryFrameFromStyleFrame(aFrame)
: aFrame;
RefPtr<WebRenderAnimationData> animationData =
GetWebRenderUserData<WebRenderAnimationData>(frameToQuery,
(uint32_t)displayItem);
Maybe<uint64_t> generation;
if (animationData) {
generation = animationData->GetAnimationInfo().GetAnimationGeneration();
}
aCallback(generation, displayItem);
aCallback(Nothing(), displayItem);
}
return;
}
WindowRenderer* renderer = widget->GetWindowRenderer();
MOZ_ASSERT(renderer);
if (!renderer->AsWebRender()) {
return;
}
// In case of continuation, nsDisplayItem uses its last continuation, so we
// have to use the last continuation frame here.
if (nsLayoutUtils::IsFirstContinuationOrIBSplitSibling(aFrame)) {
aFrame = nsLayoutUtils::LastContinuationOrIBSplitSibling(aFrame);
}
for (auto displayItem : LayerAnimationInfo::sDisplayItemTypes) {
// For transform animations, the animation is on the primary frame but
// |aFrame| is the style frame.
const nsIFrame* frameToQuery =
displayItem == DisplayItemType::TYPE_TRANSFORM
? nsLayoutUtils::GetPrimaryFrameFromStyleFrame(aFrame)
: aFrame;
RefPtr<WebRenderAnimationData> animationData =
GetWebRenderUserData<WebRenderAnimationData>(frameToQuery,
(uint32_t)displayItem);
Maybe<uint64_t> generation;
if (animationData) {
generation = animationData->GetAnimationInfo().GetAnimationGeneration();
}
aCallback(generation, displayItem);
}
}
static StyleTransformOperation ResolveTranslate(

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

@ -185,8 +185,6 @@ class PuppetWidget : public nsBaseWidget,
bool CreateRemoteLayerManager(
const std::function<bool(WebRenderLayerManager*)>& aInitializeFunc);
bool HasWindowRenderer() { return !!mWindowRenderer; }
virtual void SetInputContext(const InputContext& aContext,
const InputContextAction& aAction) override;
virtual InputContext GetInputContext() override;

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

@ -212,6 +212,7 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference {
void InfallibleMakeFullScreen(bool aFullScreen);
WindowRenderer* GetWindowRenderer() override;
bool HasWindowRenderer() const final { return !!mWindowRenderer; }
// A remote compositor session tied to this window has been lost and IPC
// messages will no longer work. The widget must clean up any lingering

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

@ -1199,11 +1199,18 @@ class nsIWidget : public nsISupports {
};
/**
* Return the widget's LayerManager. The layer tree for that
* LayerManager is what gets rendered to the widget.
* Return the widget's LayerManager. The layer tree for that LayerManager is
* what gets rendered to the widget.
*
* Note that this tries to create a renderer if it doesn't exist.
*/
virtual WindowRenderer* GetWindowRenderer() = 0;
/**
* Returns whether there's an existing window renderer.
*/
virtual bool HasWindowRenderer() const = 0;
/**
* Called before each layer manager transaction to allow any preparation
* for DrawWindowUnderlay/Overlay that needs to be on the main thread.