Skip to content

Commit

Permalink
Bug 1722258 - Convert more LayerManager usage to use WindowRenderer. …
Browse files Browse the repository at this point in the history
…r=miko

Differential Revision: https://phabricator.services.mozilla.com/D120920
  • Loading branch information
mattwoodrow committed Jul 28, 2021
1 parent 73493e2 commit 76fc994
Show file tree
Hide file tree
Showing 20 changed files with 220 additions and 186 deletions.
2 changes: 1 addition & 1 deletion dom/ipc/BrowserBridgeParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void BrowserBridgeParent::Destroy() {
}

IPCResult BrowserBridgeParent::RecvShow(const OwnerShowInfo& aOwnerInfo) {
mBrowserParent->AttachLayerManager();
mBrowserParent->AttachWindowRenderer();
Unused << mBrowserParent->SendShow(mBrowserParent->GetShowInfo(), aOwnerInfo);
return IPC_OK();
}
Expand Down
51 changes: 28 additions & 23 deletions dom/ipc/BrowserChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2672,12 +2672,12 @@ mozilla::ipc::IPCResult BrowserChild::RecvRenderLayers(
MOZ_ASSERT(mPuppetWidget);
RefPtr<LayerManager> lm =
mPuppetWidget->GetWindowRenderer()->AsLayerManager();
MOZ_ASSERT(lm);

// We send the current layer observer epoch to the compositor so that
// BrowserParent knows whether a layer update notification corresponds to
// the latest RecvRenderLayers request that was made.
lm->SetLayersObserverEpoch(mLayersObserverEpoch);
if (lm) {
// We send the current layer observer epoch to the compositor so that
// BrowserParent knows whether a layer update notification corresponds to
// the latest RecvRenderLayers request that was made.
lm->SetLayersObserverEpoch(mLayersObserverEpoch);
}
}

mRenderLayers = aEnabled;
Expand Down Expand Up @@ -2855,8 +2855,9 @@ void BrowserChild::InitRenderingState(
InitAPZState();
RefPtr<LayerManager> lm =
mPuppetWidget->GetWindowRenderer()->AsLayerManager();
MOZ_ASSERT(lm);
lm->SetLayersObserverEpoch(mLayersObserverEpoch);
if (lm) {
lm->SetLayersObserverEpoch(mLayersObserverEpoch);
}
} else {
NS_WARNING("Fallback to BasicLayerManager");
mLayersConnected = Some(false);
Expand Down Expand Up @@ -3154,7 +3155,9 @@ void BrowserChild::DidComposite(mozilla::layers::TransactionId aTransactionId,
mPuppetWidget->GetWindowRenderer()->AsLayerManager();
MOZ_ASSERT(lm);

lm->DidComposite(aTransactionId, aCompositeStart, aCompositeEnd);
if (lm) {
lm->DidComposite(aTransactionId, aCompositeStart, aCompositeEnd);
}
}

void BrowserChild::DidRequestComposite(const TimeStamp& aCompositeReqStart,
Expand Down Expand Up @@ -3185,9 +3188,9 @@ void BrowserChild::ClearCachedResources() {
MOZ_ASSERT(mPuppetWidget);
RefPtr<LayerManager> lm =
mPuppetWidget->GetWindowRenderer()->AsLayerManager();
MOZ_ASSERT(lm);

lm->ClearCachedResources();
if (lm) {
lm->ClearCachedResources();
}

if (nsCOMPtr<Document> document = GetTopLevelDocument()) {
nsPresContext* presContext = document->GetPresContext();
Expand All @@ -3201,9 +3204,9 @@ void BrowserChild::InvalidateLayers() {
MOZ_ASSERT(mPuppetWidget);
RefPtr<LayerManager> lm =
mPuppetWidget->GetWindowRenderer()->AsLayerManager();
MOZ_ASSERT(lm);

FrameLayerBuilder::InvalidateAllLayers(lm);
if (lm) {
FrameLayerBuilder::InvalidateAllLayers(lm);
}
}

void BrowserChild::SchedulePaint() {
Expand Down Expand Up @@ -3259,8 +3262,9 @@ void BrowserChild::ReinitRendering() {
InitAPZState();
RefPtr<LayerManager> lm =
mPuppetWidget->GetWindowRenderer()->AsLayerManager();
MOZ_ASSERT(lm);
lm->SetLayersObserverEpoch(mLayersObserverEpoch);
if (lm) {
lm->SetLayersObserverEpoch(mLayersObserverEpoch);
}

nsCOMPtr<Document> doc(GetTopLevelDocument());
doc->NotifyLayerManagerRecreated();
Expand All @@ -3271,10 +3275,10 @@ void BrowserChild::ReinitRenderingForDeviceReset() {

RefPtr<LayerManager> lm =
mPuppetWidget->GetWindowRenderer()->AsLayerManager();
if (WebRenderLayerManager* wlm = lm->AsWebRenderLayerManager()) {
wlm->DoDestroy(/* aIsSync */ true);
} else if (ClientLayerManager* clm = lm->AsClientLayerManager()) {
if (ShadowLayerForwarder* fwd = clm->AsShadowForwarder()) {
if (lm && lm->AsWebRenderLayerManager()) {
lm->AsWebRenderLayerManager()->DoDestroy(/* aIsSync */ true);
} else if (lm && lm->AsClientLayerManager()) {
if (ShadowLayerForwarder* fwd = lm->AsShadowForwarder()) {
// Force the LayerTransactionChild to synchronously shutdown. It is
// okay to do this early, we'll simply stop sending messages. This
// step is necessary since otherwise the compositor will think we
Expand Down Expand Up @@ -3312,8 +3316,9 @@ void BrowserChild::NotifyJankedAnimations(
MOZ_ASSERT(mPuppetWidget);
RefPtr<LayerManager> lm =
mPuppetWidget->GetWindowRenderer()->AsLayerManager();
MOZ_ASSERT(lm);
lm->UpdatePartialPrerenderedAnimations(aJankedAnimations);
if (lm) {
lm->UpdatePartialPrerenderedAnimations(aJankedAnimations);
}
}

mozilla::ipc::IPCResult BrowserChild::RecvRequestNotifyAfterRemotePaint() {
Expand Down
6 changes: 3 additions & 3 deletions dom/ipc/BrowserParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,8 @@ void BrowserParent::InitRendering() {
#endif
}

bool BrowserParent::AttachLayerManager() {
return !!mRemoteLayerTreeOwner.AttachLayerManager();
bool BrowserParent::AttachWindowRenderer() {
return mRemoteLayerTreeOwner.AttachWindowRenderer();
}

void BrowserParent::MaybeShowFrame() {
Expand All @@ -931,7 +931,7 @@ bool BrowserParent::Show(const OwnerShowInfo& aOwnerInfo) {
}

MOZ_ASSERT(mRemoteLayerTreeOwner.IsInitialized());
if (!mRemoteLayerTreeOwner.AttachLayerManager()) {
if (!mRemoteLayerTreeOwner.AttachWindowRenderer()) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/BrowserParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ class BrowserParent final : public PBrowserParent,
void ResumeLoad(uint64_t aPendingSwitchID);

void InitRendering();
bool AttachLayerManager();
bool AttachWindowRenderer();
void MaybeShowFrame();

bool Show(const OwnerShowInfo&);
Expand Down
18 changes: 1 addition & 17 deletions gfx/layers/LayerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ class DidCompositeObserver {
* root layer, and each container layer holds a reference to its children.
*/
class LayerManager : public WindowRenderer {
NS_INLINE_DECL_REFCOUNTING(LayerManager)

protected:
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::IntSize IntSize;
Expand All @@ -160,7 +158,7 @@ class LayerManager : public WindowRenderer {
* for its widget going away. After this call, only user data calls
* are valid on the layer manager.
*/
virtual void Destroy();
void Destroy() override;
bool IsDestroyed() { return mDestroyed; }

virtual LayerManager* AsLayerManager() override { return this; }
Expand Down Expand Up @@ -507,15 +505,6 @@ class LayerManager : public WindowRenderer {
static bool IsLogEnabled();
static mozilla::LogModule* GetLog();

bool IsCompositingCheap(LayersBackend aBackend) {
// LayersBackend::LAYERS_NONE is an error state, but in that case we should
// try to avoid loading the compositor!
return LayersBackend::LAYERS_BASIC != aBackend &&
LayersBackend::LAYERS_NONE != aBackend;
}

virtual bool IsCompositingCheap() { return true; }

bool IsInTransaction() const { return mInTransaction; }

virtual void SetRegionToClear(const nsIntRegion& aRegion) {
Expand All @@ -524,8 +513,6 @@ class LayerManager : public WindowRenderer {

virtual float RequestProperty(const nsAString& property) { return -1; }

const TimeStamp& GetAnimationReadyTime() const { return mAnimationReadyTime; }

virtual bool AsyncPanZoomEnabled() const { return false; }

static void LayerUserDataDestroy(void* data);
Expand Down Expand Up @@ -600,9 +587,6 @@ class LayerManager : public WindowRenderer {

// Used for tracking CONTENT_FRAME_TIME_WITH_SVG
bool mContainsSVG;
// The time when painting most recently finished. This is recorded so that
// we can time any play-pending animations from this point.
TimeStamp mAnimationReadyTime;
// The count of pixels that were painted in the current transaction.
uint32_t mPaintedPixelCount;
// The payload associated with currently pending painting work, for
Expand Down
6 changes: 4 additions & 2 deletions gfx/layers/client/ClientLayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,10 @@ ShadowableLayer* ClientLayerManager::Hold(Layer* aLayer) {
bool ClientLayerManager::IsCompositingCheap() {
// Whether compositing is cheap depends on the parent backend.
return mForwarder->mShadowManager &&
LayerManager::IsCompositingCheap(
mForwarder->GetCompositorBackendType());
(mForwarder->GetCompositorBackendType() !=
LayersBackend::LAYERS_NONE &&
mForwarder->GetCompositorBackendType() !=
LayersBackend::LAYERS_BASIC);
}

bool ClientLayerManager::AreComponentAlphaLayersEnabled() {
Expand Down
12 changes: 5 additions & 7 deletions layout/base/PresShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6438,17 +6438,17 @@ void PresShell::Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,
return;
}

bgcolor = NS_ComposeColors(bgcolor, mCanvasBackgroundColor);

if (!layerManager) {
// TODO: Once we support WindowRenderers that aren't a LayerManager,
// then we need to handle this single color case for them.
return;
}

if (layerManager->GetBackendType() == layers::LayersBackend::LAYERS_WR) {
nsPresContext* pc = GetPresContext();
LayoutDeviceRect bounds = LayoutDeviceRect::FromAppUnits(
pc->GetVisibleArea(), pc->AppUnitsPerDevPixel());
bgcolor = NS_ComposeColors(bgcolor, mCanvasBackgroundColor);
presContext->GetVisibleArea(), presContext->AppUnitsPerDevPixel());
WebRenderBackgroundData data(wr::ToLayoutRect(bounds),
wr::ToColorF(ToDeviceColor(bgcolor)));
WrFiltersHolder wrFilters;
Expand All @@ -6461,10 +6461,8 @@ void PresShell::Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,

RefPtr<ColorLayer> root = layerManager->CreateColorLayer();
if (root) {
nsPresContext* pc = GetPresContext();
nsIntRect bounds =
pc->GetVisibleArea().ToOutsidePixels(pc->AppUnitsPerDevPixel());
bgcolor = NS_ComposeColors(bgcolor, mCanvasBackgroundColor);
nsIntRect bounds = presContext->GetVisibleArea().ToOutsidePixels(
presContext->AppUnitsPerDevPixel());
root->SetColor(ToDeviceColor(bgcolor));
root->SetVisibleRegion(LayerIntRegion::FromUnknownRegion(bounds));
layerManager->SetRoot(root);
Expand Down
64 changes: 32 additions & 32 deletions layout/ipc/RemoteLayerTreeOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ using namespace mozilla::layers;
namespace mozilla {
namespace layout {

static already_AddRefed<LayerManager> GetLayerManager(
static already_AddRefed<WindowRenderer> GetWindowRenderer(
BrowserParent* aBrowserParent) {
RefPtr<LayerManager> lm;
RefPtr<WindowRenderer> renderer;
if (Element* element = aBrowserParent->GetOwnerElement()) {
if (WindowRenderer* renderer =
nsContentUtils::WindowRendererForContent(element)) {
lm = renderer->AsLayerManager();
return lm.forget();
renderer = nsContentUtils::WindowRendererForContent(element);
if (renderer) {
return renderer.forget();
}
if (WindowRenderer* renderer =
nsContentUtils::WindowRendererForDocument(element->OwnerDoc())) {
lm = renderer->AsLayerManager();
return lm.forget();
renderer = nsContentUtils::WindowRendererForDocument(element->OwnerDoc());
if (renderer) {
return renderer.forget();
}
}
return nullptr;
Expand All @@ -51,7 +49,6 @@ static already_AddRefed<LayerManager> GetLayerManager(
RemoteLayerTreeOwner::RemoteLayerTreeOwner()
: mLayersId{0},
mBrowserParent(nullptr),
mLayerManager(nullptr),
mInitialized(false),
mLayersConnected(false) {}

Expand All @@ -63,9 +60,9 @@ bool RemoteLayerTreeOwner::Initialize(BrowserParent* aBrowserParent) {
}

mBrowserParent = aBrowserParent;
RefPtr<LayerManager> lm = GetLayerManager(mBrowserParent);
RefPtr<WindowRenderer> renderer = GetWindowRenderer(mBrowserParent);
PCompositorBridgeChild* compositor =
lm ? lm->GetCompositorBridgeChild() : nullptr;
renderer ? renderer->GetCompositorBridgeChild() : nullptr;
mTabProcessId = mBrowserParent->Manager()->OtherPid();

// Our remote frame will push layers updates to the compositor,
Expand All @@ -84,53 +81,56 @@ void RemoteLayerTreeOwner::Destroy() {
}

mBrowserParent = nullptr;
mLayerManager = nullptr;
mWindowRenderer = nullptr;
}

void RemoteLayerTreeOwner::EnsureLayersConnected(
CompositorOptions* aCompositorOptions) {
RefPtr<LayerManager> lm = GetLayerManager(mBrowserParent);
if (!lm) {
RefPtr<WindowRenderer> renderer = GetWindowRenderer(mBrowserParent);
if (!renderer) {
return;
}

if (!lm->GetCompositorBridgeChild()) {
if (!renderer->GetCompositorBridgeChild()) {
return;
}

mLayersConnected = lm->GetCompositorBridgeChild()->SendNotifyChildRecreated(
mLayersId, &mCompositorOptions);
mLayersConnected =
renderer->GetCompositorBridgeChild()->SendNotifyChildRecreated(
mLayersId, &mCompositorOptions);
*aCompositorOptions = mCompositorOptions;
}

LayerManager* RemoteLayerTreeOwner::AttachLayerManager() {
RefPtr<LayerManager> lm;
bool RemoteLayerTreeOwner::AttachWindowRenderer() {
RefPtr<WindowRenderer> renderer;
if (mBrowserParent) {
lm = GetLayerManager(mBrowserParent);
renderer = GetWindowRenderer(mBrowserParent);
}

// Perhaps the document containing this frame currently has no presentation?
if (lm && lm->GetCompositorBridgeChild() && lm != mLayerManager) {
if (renderer && renderer->GetCompositorBridgeChild() &&
renderer != mWindowRenderer) {
mLayersConnected =
lm->GetCompositorBridgeChild()->SendAdoptChild(mLayersId);
FrameLayerBuilder::InvalidateAllLayers(lm);
renderer->GetCompositorBridgeChild()->SendAdoptChild(mLayersId);
FrameLayerBuilder::InvalidateAllLayers(renderer->AsLayerManager());
}

mLayerManager = std::move(lm);
return mLayerManager;
mWindowRenderer = std::move(renderer);
return !!mWindowRenderer;
}

void RemoteLayerTreeOwner::OwnerContentChanged() {
Unused << AttachLayerManager();
Unused << AttachWindowRenderer();
}

void RemoteLayerTreeOwner::GetTextureFactoryIdentifier(
TextureFactoryIdentifier* aTextureFactoryIdentifier) const {
RefPtr<LayerManager> lm =
mBrowserParent ? GetLayerManager(mBrowserParent) : nullptr;
RefPtr<WindowRenderer> renderer =
mBrowserParent ? GetWindowRenderer(mBrowserParent) : nullptr;
// Perhaps the document containing this frame currently has no presentation?
if (lm) {
*aTextureFactoryIdentifier = lm->GetTextureFactoryIdentifier();
if (renderer && renderer->AsLayerManager()) {
*aTextureFactoryIdentifier =
renderer->AsLayerManager()->GetTextureFactoryIdentifier();
} else {
*aTextureFactoryIdentifier = TextureFactoryIdentifier();
}
Expand Down
4 changes: 2 additions & 2 deletions layout/ipc/RemoteLayerTreeOwner.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RemoteLayerTreeOwner final {
void Destroy();

void EnsureLayersConnected(CompositorOptions* aCompositorOptions);
LayerManager* AttachLayerManager();
bool AttachWindowRenderer();
void OwnerContentChanged();

LayersId GetLayersId() const { return mLayersId; }
Expand All @@ -73,7 +73,7 @@ class RemoteLayerTreeOwner final {
CompositorOptions mCompositorOptions;

dom::BrowserParent* mBrowserParent;
RefPtr<LayerManager> mLayerManager;
RefPtr<WindowRenderer> mWindowRenderer;

bool mInitialized;
// A flag that indicates whether or not the compositor knows about the
Expand Down
Loading

0 comments on commit 76fc994

Please sign in to comment.