bool
RenderFrameParent::Init(nsFrameLoader* aFrameLoader)
{
  if (mInitted || !aFrameLoader) {
    return false;
  }

  mFrameLoader = aFrameLoader;

  RefPtr<LayerManager> lm = GetFrom(mFrameLoader);

  mAsyncPanZoomEnabled = lm && lm->AsyncPanZoomEnabled();

  TabParent* browser = TabParent::GetFrom(mFrameLoader);
  if (XRE_IsParentProcess()) {
    // Our remote frame will push layers updates to the compositor,
    // and we'll keep an indirect reference to that tree.
    browser->Manager()->AsContentParent()->AllocateLayerTreeId(browser, &mLayersId);
    if (lm && lm->AsClientLayerManager()) {
      lm->AsClientLayerManager()->GetRemoteRenderer()->SendNotifyChildCreated(mLayersId);
    }
  } else if (XRE_IsContentProcess()) {
    ContentChild::GetSingleton()->SendAllocateLayerTreeId(browser->Manager()->ChildID(), browser->GetTabId(), &mLayersId);
    CompositorBridgeChild::Get()->SendNotifyChildCreated(mLayersId);
  }

  mInitted = true;
  return true;
}
void
RenderFrameParent::GetTextureFactoryIdentifier(TextureFactoryIdentifier* aTextureFactoryIdentifier)
{
  RefPtr<LayerManager> lm = mFrameLoader ? GetFrom(mFrameLoader) : nullptr;
  // Perhaps the document containing this frame currently has no presentation?
  if (lm && lm->AsClientLayerManager()) {
    *aTextureFactoryIdentifier = lm->AsClientLayerManager()->GetTextureFactoryIdentifier();
  } else {
    *aTextureFactoryIdentifier = TextureFactoryIdentifier();
  }
}
void
RenderFrameParent::OwnerContentChanged(nsIContent* aContent)
{
  MOZ_ASSERT(!mFrameLoader || mFrameLoader->GetOwnerContent() == aContent,
             "Don't build new map if owner is same!");

  RefPtr<LayerManager> lm = mFrameLoader ? GetFrom(mFrameLoader) : nullptr;
  // Perhaps the document containing this frame currently has no presentation?
  if (lm && lm->AsClientLayerManager()) {
    lm->AsClientLayerManager()->GetRemoteRenderer()->SendAdoptChild(mLayersId);
    FrameLayerBuilder::InvalidateAllLayers(lm);
  }
}
void
RenderFrameParent::EnsureLayersConnected()
{
  RefPtr<LayerManager> lm = GetFrom(mFrameLoader);
  if (!lm) {
    return;
  }

  ClientLayerManager* client = lm->AsClientLayerManager();
  if (!client) {
    return;
  }

  client->GetRemoteRenderer()->SendNotifyChildRecreated(mLayersId);
}