mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-30 14:17:36 -10:00
Instead of always discarding the compositor animation id, and then sometimes un-discarding it (which involves a linear lookup in nsTArray), this patch now has the WebRenderLayerManager keep a set of active animation ids, and uses that to avoid discarding the same animation twice. In addition, because the display item can be destroyed at any time (e.g. in the middle of an animation), we were previously "leaking" compositor animations in that the compositor side never got notified to discard the IDs. This resulted in infinite composition loops. This patch solves this problem by having any unused WebRenderAnimationData trigger discard of the animation id during destruction. This way, even if the nsDisplayItem is deleted in the middle of the animation we have a fallback mechanism to discard the id. MozReview-Commit-ID: 8G3EYHcg9Kl
257 lines
7.9 KiB
C++
257 lines
7.9 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "WebRenderUserData.h"
|
|
|
|
#include "mozilla/layers/ImageClient.h"
|
|
#include "mozilla/layers/WebRenderBridgeChild.h"
|
|
#include "mozilla/layers/WebRenderLayerManager.h"
|
|
#include "mozilla/layers/WebRenderMessages.h"
|
|
#include "mozilla/layers/IpcResourceUpdateQueue.h"
|
|
#include "nsDisplayListInvalidation.h"
|
|
#include "WebRenderCanvasRenderer.h"
|
|
|
|
namespace mozilla {
|
|
namespace layers {
|
|
|
|
WebRenderUserData::WebRenderUserData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem,
|
|
WebRenderUserDataRefTable* aTable)
|
|
: mWRManager(aWRManager)
|
|
, mFrame(aItem->Frame())
|
|
, mDisplayItemKey(aItem->GetPerFrameKey())
|
|
, mTable(aTable)
|
|
, mUsed(false)
|
|
{
|
|
}
|
|
|
|
WebRenderUserData::~WebRenderUserData()
|
|
{
|
|
}
|
|
|
|
bool
|
|
WebRenderUserData::IsDataValid(WebRenderLayerManager* aManager)
|
|
{
|
|
return aManager == mWRManager;
|
|
}
|
|
|
|
void
|
|
WebRenderUserData::RemoveFromTable()
|
|
{
|
|
mTable->RemoveEntry(this);
|
|
}
|
|
|
|
WebRenderBridgeChild*
|
|
WebRenderUserData::WrBridge() const
|
|
{
|
|
return mWRManager->WrBridge();
|
|
}
|
|
|
|
WebRenderImageData::WebRenderImageData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem,
|
|
WebRenderUserDataRefTable* aTable)
|
|
: WebRenderUserData(aWRManager, aItem, aTable)
|
|
{
|
|
}
|
|
|
|
WebRenderImageData::~WebRenderImageData()
|
|
{
|
|
if (mKey) {
|
|
mWRManager->AddImageKeyForDiscard(mKey.value());
|
|
}
|
|
|
|
if (mExternalImageId) {
|
|
WrBridge()->DeallocExternalImageId(mExternalImageId.ref());
|
|
}
|
|
|
|
if (mPipelineId) {
|
|
WrBridge()->RemovePipelineIdForCompositable(mPipelineId.ref());
|
|
}
|
|
}
|
|
|
|
Maybe<wr::ImageKey>
|
|
WebRenderImageData::UpdateImageKey(ImageContainer* aContainer,
|
|
wr::IpcResourceUpdateQueue& aResources,
|
|
bool aForceUpdate)
|
|
{
|
|
CreateImageClientIfNeeded();
|
|
CreateExternalImageIfNeeded();
|
|
|
|
if (mContainer != aContainer) {
|
|
mContainer = aContainer;
|
|
}
|
|
|
|
if (!mImageClient || !mExternalImageId) {
|
|
return Nothing();
|
|
}
|
|
|
|
MOZ_ASSERT(mImageClient->AsImageClientSingle());
|
|
MOZ_ASSERT(aContainer);
|
|
|
|
ImageClientSingle* imageClient = mImageClient->AsImageClientSingle();
|
|
uint32_t oldCounter = imageClient->GetLastUpdateGenerationCounter();
|
|
|
|
bool ret = imageClient->UpdateImage(aContainer, /* unused */0);
|
|
if (!ret || imageClient->IsEmpty()) {
|
|
// Delete old key
|
|
if (mKey) {
|
|
mWRManager->AddImageKeyForDiscard(mKey.value());
|
|
mKey = Nothing();
|
|
}
|
|
return Nothing();
|
|
}
|
|
|
|
// Reuse old key if generation is not updated.
|
|
if (!aForceUpdate && oldCounter == imageClient->GetLastUpdateGenerationCounter() && mKey) {
|
|
return mKey;
|
|
}
|
|
|
|
// Delete old key, we are generating a new key.
|
|
// TODO(nical): noooo... we need to reuse image keys.
|
|
if (mKey) {
|
|
mWRManager->AddImageKeyForDiscard(mKey.value());
|
|
}
|
|
|
|
wr::WrImageKey key = WrBridge()->GetNextImageKey();
|
|
aResources.AddExternalImage(mExternalImageId.value(), key);
|
|
mKey = Some(key);
|
|
|
|
return mKey;
|
|
}
|
|
|
|
already_AddRefed<ImageClient>
|
|
WebRenderImageData::GetImageClient()
|
|
{
|
|
RefPtr<ImageClient> imageClient = mImageClient;
|
|
return imageClient.forget();
|
|
}
|
|
|
|
void
|
|
WebRenderImageData::CreateAsyncImageWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
|
ImageContainer* aContainer,
|
|
const StackingContextHelper& aSc,
|
|
const LayerRect& aBounds,
|
|
const LayerRect& aSCBounds,
|
|
const gfx::Matrix4x4& aSCTransform,
|
|
const gfx::MaybeIntSize& aScaleToSize,
|
|
const wr::ImageRendering& aFilter,
|
|
const wr::MixBlendMode& aMixBlendMode,
|
|
bool aIsBackfaceVisible)
|
|
{
|
|
MOZ_ASSERT(aContainer->IsAsync());
|
|
if (!mPipelineId) {
|
|
// Alloc async image pipeline id.
|
|
mPipelineId = Some(WrBridge()->GetCompositorBridgeChild()->GetNextPipelineId());
|
|
WrBridge()->AddPipelineIdForAsyncCompositable(mPipelineId.ref(),
|
|
aContainer->GetAsyncContainerHandle());
|
|
}
|
|
MOZ_ASSERT(!mImageClient);
|
|
MOZ_ASSERT(!mExternalImageId);
|
|
|
|
// Push IFrame for async image pipeline.
|
|
//
|
|
// We don't push a stacking context for this async image pipeline here.
|
|
// Instead, we do it inside the iframe that hosts the image. As a result,
|
|
// a bunch of the calculations normally done as part of that stacking
|
|
// context need to be done manually and pushed over to the parent side,
|
|
// where it will be done when we build the display list for the iframe.
|
|
// That happens in AsyncImagePipelineManager.
|
|
wr::LayoutRect r = aSc.ToRelativeLayoutRect(aBounds);
|
|
aBuilder.PushIFrame(r, aIsBackfaceVisible, mPipelineId.ref());
|
|
|
|
WrBridge()->AddWebRenderParentCommand(OpUpdateAsyncImagePipeline(mPipelineId.value(),
|
|
aSCBounds,
|
|
aSCTransform,
|
|
aScaleToSize,
|
|
aFilter,
|
|
aMixBlendMode));
|
|
}
|
|
|
|
void
|
|
WebRenderImageData::CreateImageClientIfNeeded()
|
|
{
|
|
if (!mImageClient) {
|
|
mImageClient = ImageClient::CreateImageClient(CompositableType::IMAGE,
|
|
WrBridge(),
|
|
TextureFlags::DEFAULT);
|
|
if (!mImageClient) {
|
|
return;
|
|
}
|
|
|
|
mImageClient->Connect();
|
|
}
|
|
}
|
|
|
|
void
|
|
WebRenderImageData::CreateExternalImageIfNeeded()
|
|
{
|
|
if (!mExternalImageId) {
|
|
mExternalImageId = Some(WrBridge()->AllocExternalImageIdForCompositable(mImageClient));
|
|
}
|
|
}
|
|
|
|
WebRenderFallbackData::WebRenderFallbackData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem,
|
|
WebRenderUserDataRefTable* aTable)
|
|
: WebRenderImageData(aWRManager, aItem, aTable)
|
|
, mInvalid(false)
|
|
{
|
|
}
|
|
|
|
WebRenderFallbackData::~WebRenderFallbackData()
|
|
{
|
|
}
|
|
|
|
nsAutoPtr<nsDisplayItemGeometry>
|
|
WebRenderFallbackData::GetGeometry()
|
|
{
|
|
return mGeometry;
|
|
}
|
|
|
|
void
|
|
WebRenderFallbackData::SetGeometry(nsAutoPtr<nsDisplayItemGeometry> aGeometry)
|
|
{
|
|
mGeometry = aGeometry;
|
|
}
|
|
|
|
WebRenderAnimationData::WebRenderAnimationData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem,
|
|
WebRenderUserDataRefTable* aTable)
|
|
: WebRenderUserData(aWRManager, aItem, aTable)
|
|
, mAnimationInfo(aWRManager)
|
|
{
|
|
}
|
|
|
|
WebRenderAnimationData::~WebRenderAnimationData()
|
|
{
|
|
// It may be the case that nsDisplayItem that created this WebRenderUserData
|
|
// gets destroyed without getting a chance to discard the compositor animation
|
|
// id, so we should do it as part of cleanup here.
|
|
uint64_t animationId = mAnimationInfo.GetCompositorAnimationsId();
|
|
// animationId might be 0 if mAnimationInfo never held any active animations.
|
|
if (animationId) {
|
|
mWRManager->AddCompositorAnimationsIdForDiscard(animationId);
|
|
}
|
|
}
|
|
|
|
WebRenderCanvasData::WebRenderCanvasData(WebRenderLayerManager* aWRManager, nsDisplayItem* aItem,
|
|
WebRenderUserDataRefTable* aTable)
|
|
: WebRenderUserData(aWRManager, aItem, aTable)
|
|
{
|
|
}
|
|
|
|
WebRenderCanvasData::~WebRenderCanvasData()
|
|
{
|
|
}
|
|
|
|
WebRenderCanvasRendererAsync*
|
|
WebRenderCanvasData::GetCanvasRenderer()
|
|
{
|
|
if (!mCanvasRenderer) {
|
|
mCanvasRenderer = MakeUnique<WebRenderCanvasRendererAsync>(mWRManager);
|
|
}
|
|
|
|
return mCanvasRenderer.get();
|
|
}
|
|
|
|
} // namespace layers
|
|
} // namespace mozilla
|