//
// Automatically generated by ipdlc.
// Edit at your own risk
//


#include "mozilla/layers/PCompositorManagerChild.h"
#include "gfxipc/ShadowLayerUtils.h"
#include "mozilla/GfxMessageUtils.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/ipc/IPCCore.h"
#include "mozilla/layers/CompositorManagerChild.h"
#include "mozilla/layers/LayersMessageUtils.h"
#include "mozilla/layers/WebRenderMessageUtils.h"

#include "mozilla/gfx/PCanvasManagerChild.h"
#include "mozilla/layers/PCompositorBridgeChild.h"

#include "ipc/IPCMessageUtils.h"
#include "ipc/IPCMessageUtilsSpecializations.h"
#include "nsIFile.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/ProtocolMessageUtils.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/ShmemMessageUtils.h"
#include "mozilla/ipc/TaintingIPCUtils.h"

namespace mozilla {
namespace layers {


auto PCompositorManagerChild::ProcessingError(
        Result aCode,
        const char* aReason) -> void
{
}

auto PCompositorManagerChild::ShouldContinueFromReplyTimeout() -> bool
{
    return true;
}

MOZ_IMPLICIT PCompositorManagerChild::PCompositorManagerChild() :
    mozilla::ipc::IToplevelProtocol("PCompositorManagerChild", kProtocolId, mozilla::ipc::ChildSide)
{
    MOZ_COUNT_CTOR(PCompositorManagerChild);
}

PCompositorManagerChild::~PCompositorManagerChild()
{
    MOZ_COUNT_DTOR(PCompositorManagerChild);
}

auto PCompositorManagerChild::ActorAlloc() -> void
{
    MOZ_RELEASE_ASSERT(XRE_IsParentProcess() || XRE_IsContentProcess(), "Invalid process for `PCompositorManagerChild'");
    AddRef();
}

auto PCompositorManagerChild::ActorDealloc() -> void
{
    Release();
}

auto PCompositorManagerChild::OtherPid() const -> ::base::ProcessId
{
    ::base::ProcessId pid =
        ::mozilla::ipc::IProtocol::ToplevelProtocol()->OtherPidMaybeInvalid();
    MOZ_RELEASE_ASSERT(pid != ::base::kInvalidProcessId);
    return pid;
}

auto PCompositorManagerChild::OtherChildID() const -> ::GeckoChildID
{
    ::GeckoChildID childID =
        ::mozilla::ipc::IProtocol::ToplevelProtocol()->OtherChildIDMaybeInvalid();
    MOZ_RELEASE_ASSERT(childID != -1);
    return childID;
}

auto PCompositorManagerChild::OtherEndpointProcInfo() const -> ::mozilla::ipc::EndpointProcInfo
{
    return ::mozilla::ipc::EndpointProcInfo{OtherPid(), OtherChildID()};
}

auto PCompositorManagerChild::ManagedPCompositorBridgeChild(nsTArray<PCompositorBridgeChild*>& aArr) const -> void
{
    mManagedPCompositorBridgeChild.ToArray(aArr);
}

auto PCompositorManagerChild::ManagedPCompositorBridgeChild() const -> const ManagedContainer<PCompositorBridgeChild>&
{
    return mManagedPCompositorBridgeChild;
}

auto PCompositorManagerChild::ManagedProtocolIds() const -> mozilla::Span<mozilla::ipc::ProtocolId const>
{
    static constexpr ::mozilla::ipc::ProtocolId sIds[] = {
        PCompositorBridgeMsgStart
    };
    return sIds;
}

auto PCompositorManagerChild::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    case PCompositorBridgeMsgStart:
        return (&(mManagedPCompositorBridgeChild));
    default:
        return nullptr;
    }
}

auto PCompositorManagerChild::RejectPendingResponses(ResponseRejectReason aReason) -> void
{
    mAsyncCallbacks.RejectPendingResponses(aReason);
}

auto PCompositorManagerChild::OpenPCompositorBridgeEndpoint(PCompositorBridgeChild* aActor) -> ManagedEndpoint<PCompositorBridgeParent>
{
    if (!aActor) {
        NS_WARNING("Cannot bind null PCompositorBridgeChild actor");
        return ManagedEndpoint<PCompositorBridgeParent>();
    }

    if (!aActor->SetManagerAndRegister(this)) {
        NS_WARNING("Failed to bind PCompositorBridgeChild actor");
        return ManagedEndpoint<PCompositorBridgeParent>();
    }

    // Mark our actor as awaiting the other side to be bound. This will
    // be cleared when a `MANAGED_ENDPOINT_{DROPPED,BOUND}` message is
    // received.
    aActor->mAwaitingManagedEndpointBind = true;
    return ManagedEndpoint<PCompositorBridgeParent>(mozilla::ipc::PrivateIPDLInterface(), aActor);
}

auto PCompositorManagerChild::BindPCompositorBridgeEndpoint(
        ManagedEndpoint<PCompositorBridgeChild> aEndpoint,
        PCompositorBridgeChild* aActor) -> bool
{
    return aEndpoint.Bind(mozilla::ipc::PrivateIPDLInterface(), aActor, this);
}

auto PCompositorManagerChild::SendPCompositorBridgeConstructor(
        PCompositorBridgeChild* actor,
        const CompositorBridgeOptions& options) -> PCompositorBridgeChild*
{
    if (!actor) {
        NS_WARNING("Cannot bind null PCompositorBridgeChild actor");
        return nullptr;
    }

    if (!actor->SetManagerAndRegister(this)) {
        NS_WARNING("Failed to bind PCompositorBridgeChild actor");
        return nullptr;
    }


    // Build our constructor message.
    UniquePtr<IPC::Message> msg__ = PCompositorManager::Msg_PCompositorBridgeConstructor(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), (actor)->Id());
    // Sentinel = 'actorid'
    ((&(writer__)))->WriteSentinel(193725159);
    IPC::WriteParam((&(writer__)), options);
    // Sentinel = 'options'
    ((&(writer__)))->WriteSentinel(204735245);


    // Notify the other side about the newly created actor. This can
    // fail if our manager has already been destroyed.
    //
    // NOTE: If the send call fails due to toplevel channel teardown,
    // the `IProtocol::ChannelSend` wrapper absorbs the error for us,
    // so we don't tear down actors unexpectedly.

    if (mozilla::ipc::LoggingEnabledFor("PCompositorManager", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PCompositorManagerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PCompositorManager::Msg_PCompositorBridgeConstructor", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));


    // Warn, destroy the actor, and return null if the message failed to
    // send. Otherwise, return the successfully created actor reference.
    if (!sendok__) {
        NS_WARNING("Error sending PCompositorBridgeChild constructor");
        actor->ActorDisconnected(FailedConstructor);

        return nullptr;
    }
    return actor;
}

auto PCompositorManagerChild::SendAddSharedSurface(
        const ExternalImageId& aId,
        SurfaceDescriptorShared&& aDesc) -> bool
{
    UniquePtr<IPC::Message> msg__ = PCompositorManager::Msg_AddSharedSurface(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aId);
    // Sentinel = 'aId'
    ((&(writer__)))->WriteSentinel(35389711);
    IPC::WriteParam((&(writer__)), std::move(aDesc));
    // Sentinel = 'aDesc'
    ((&(writer__)))->WriteSentinel(91357665);


    if (mozilla::ipc::LoggingEnabledFor("PCompositorManager", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PCompositorManagerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PCompositorManager::Msg_AddSharedSurface", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PCompositorManagerChild::SendRemoveSharedSurface(const ExternalImageId& aId) -> bool
{
    UniquePtr<IPC::Message> msg__ = PCompositorManager::Msg_RemoveSharedSurface(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aId);
    // Sentinel = 'aId'
    ((&(writer__)))->WriteSentinel(35389711);


    if (mozilla::ipc::LoggingEnabledFor("PCompositorManager", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PCompositorManagerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PCompositorManager::Msg_RemoveSharedSurface", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PCompositorManagerChild::SendReportSharedSurfacesMemory(
        mozilla::ipc::ResolveCallback<SharedSurfacesMemoryReport>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PCompositorManager::Msg_ReportSharedSurfacesMemory(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



    if (mozilla::ipc::LoggingEnabledFor("PCompositorManager", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PCompositorManagerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PCompositorManager::Msg_ReportSharedSurfacesMemory", OTHER);

    IPC::Message::seqno_t seqno__ = 0;
    if (ChannelSend(std::move(msg__), (&(seqno__)))) {
        mAsyncCallbacks.AddCallback(seqno__, PCompositorManager::Reply_ReportSharedSurfacesMemory__ID, [resolve=std::move(aResolve)](IPC::MessageReader* aReader) mutable {
            auto maybe__aReport = IPC::ReadParam<SharedSurfacesMemoryReport>(aReader);
            if (!maybe__aReport) {
                (aReader)->FatalError("Error deserializing 'SharedSurfacesMemoryReport'");
                return MsgValueError;

            }
            auto& aReport = *maybe__aReport;
            // Sentinel = 'aReport'
            if ((!((aReader)->ReadSentinel(184025822)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'SharedSurfacesMemoryReport'");
                return MsgValueError;
            }


            aReader->EndRead();

            resolve(std::move(aReport));
            return MsgProcessed;
        }, std::move(aReject));
    }
    else {
        aReject(::mozilla::ipc::ResponseRejectReason::SendError);
    }
    return;
}

auto PCompositorManagerChild::SendReportSharedSurfacesMemory() -> RefPtr<ReportSharedSurfacesMemoryPromise>
{
    RefPtr<MozPromise<SharedSurfacesMemoryReport, ResponseRejectReason, true>::Private> promise__ = new MozPromise<SharedSurfacesMemoryReport, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendReportSharedSurfacesMemory([promise__](SharedSurfacesMemoryReport&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PCompositorManagerChild::SendNotifyMemoryPressure() -> bool
{
    UniquePtr<IPC::Message> msg__ = PCompositorManager::Msg_NotifyMemoryPressure(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



    if (mozilla::ipc::LoggingEnabledFor("PCompositorManager", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PCompositorManagerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PCompositorManager::Msg_NotifyMemoryPressure", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PCompositorManagerChild::SendReportMemory(
        mozilla::ipc::ResolveCallback<MemoryReport>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PCompositorManager::Msg_ReportMemory(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



    if (mozilla::ipc::LoggingEnabledFor("PCompositorManager", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PCompositorManagerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PCompositorManager::Msg_ReportMemory", OTHER);

    IPC::Message::seqno_t seqno__ = 0;
    if (ChannelSend(std::move(msg__), (&(seqno__)))) {
        mAsyncCallbacks.AddCallback(seqno__, PCompositorManager::Reply_ReportMemory__ID, [resolve=std::move(aResolve)](IPC::MessageReader* aReader) mutable {
            auto maybe__aReport = IPC::ReadParam<MemoryReport>(aReader);
            if (!maybe__aReport) {
                (aReader)->FatalError("Error deserializing 'MemoryReport'");
                return MsgValueError;

            }
            auto& aReport = *maybe__aReport;
            // Sentinel = 'aReport'
            if ((!((aReader)->ReadSentinel(184025822)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'MemoryReport'");
                return MsgValueError;
            }


            aReader->EndRead();

            resolve(std::move(aReport));
            return MsgProcessed;
        }, std::move(aReject));
    }
    else {
        aReject(::mozilla::ipc::ResponseRejectReason::SendError);
    }
    return;
}

auto PCompositorManagerChild::SendReportMemory() -> RefPtr<ReportMemoryPromise>
{
    RefPtr<MozPromise<MemoryReport, ResponseRejectReason, true>::Private> promise__ = new MozPromise<MemoryReport, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendReportMemory([promise__](MemoryReport&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PCompositorManagerChild::SendInitCanvasManager(Endpoint<::mozilla::gfx::PCanvasManagerParent>&& endpoint) -> bool
{
    UniquePtr<IPC::Message> msg__ = PCompositorManager::Msg_InitCanvasManager(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), std::move(endpoint));
    // Sentinel = 'endpoint'
    ((&(writer__)))->WriteSentinel(251724642);


    if (mozilla::ipc::LoggingEnabledFor("PCompositorManager", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PCompositorManagerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PCompositorManager::Msg_InitCanvasManager", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PCompositorManagerChild::DeallocManagee(
        mozilla::ipc::ProtocolId aProtocolId,
        IProtocol* aListener) -> void
{
    switch (aProtocolId) {
    default:
        FatalError("unreached");
        return;
    }
}

auto PCompositorManagerChild::OnMessageReceived(const Message& msg__) -> PCompositorManagerChild::Result
{
    IPC::Message::routeid_t route__ = msg__.routing_id();
    if (MSG_ROUTING_CONTROL != route__) {
        IProtocol* routed__ = Lookup(route__);
        if (!routed__ || !routed__->GetLifecycleProxy()) {
            if (mozilla::ipc::LoggingEnabledFor("PCompositorManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PCompositorManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Ignored message for dead actor",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eSending);
            }
            return MsgProcessed;

        }

        RefPtr<mozilla::ipc::ActorLifecycleProxy> proxy__ =
            routed__->GetLifecycleProxy();
        return proxy__->Get()->OnMessageReceived(msg__);
    }

    switch (msg__.type()) {
    case PCompositorManager::Reply_PCompositorBridgeConstructor__ID:
        {
            return MsgProcessed;
        }
    case PCompositorManager::Reply_ReportSharedSurfacesMemory__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PCompositorManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PCompositorManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PCompositorManager::Msg_ReportSharedSurfacesMemory", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PCompositorManager::Reply_ReportMemory__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PCompositorManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PCompositorManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PCompositorManager::Msg_ReportMemory", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PCompositorManager::Msg_NotifyWebRenderError__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PCompositorManager", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PCompositorManagerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PCompositorManager::Msg_NotifyWebRenderError", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__error = IPC::ReadParam<WebRenderError>((&(reader__)));
            if (!maybe__error) {
                FatalError("Error deserializing 'WebRenderError'");
                return MsgValueError;

            }
            auto& error = *maybe__error;
            // Sentinel = 'error'
            if ((!(((&(reader__)))->ReadSentinel(107741739)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'WebRenderError'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (static_cast<CompositorManagerChild*>(this))->RecvNotifyWebRenderError(std::move(error));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    case SHMEM_CREATED_MESSAGE_TYPE:
        {
            if (!ShmemCreated(msg__)) {
                return MsgPayloadError;
            }
            return MsgProcessed;
        }
    case SHMEM_DESTROYED_MESSAGE_TYPE:
        {
            if (!ShmemDestroyed(msg__)) {
                return MsgPayloadError;
            }
            return MsgProcessed;
        }
    }
}

auto PCompositorManagerChild::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PCompositorManagerChild::Result
{
    IPC::Message::routeid_t route__ = msg__.routing_id();
    if (MSG_ROUTING_CONTROL != route__) {
        IProtocol* routed__ = Lookup(route__);
        if (!routed__ || !routed__->GetLifecycleProxy()) {
            return MsgDropped;

        }

        RefPtr<mozilla::ipc::ActorLifecycleProxy> proxy__ =
            routed__->GetLifecycleProxy();
        return proxy__->Get()->OnMessageReceived(msg__, reply__);
    }

    return MsgNotKnown;
}



} // namespace layers
} // namespace mozilla
namespace IPC {
auto ParamTraits<::mozilla::layers::PCompositorManagerChild*>::Write(
        IPC::MessageWriter* aWriter,
        const paramType& aVar) -> void
{
    IPC::WriteParam(aWriter, static_cast<mozilla::ipc::IProtocol*>(aVar));
    // Sentinel = 'PCompositorManager'
    (aWriter)->WriteSentinel(1134364475);
}

auto ParamTraits<::mozilla::layers::PCompositorManagerChild*>::Read(IPC::MessageReader* aReader) -> IPC::ReadResult<paramType>
{
    auto maybe__actor = IPC::ReadParam<mozilla::ipc::IProtocol*>(aReader);
    if (!maybe__actor) {
        aReader->FatalError("Error deserializing managed PCompositorManager actor");
        return {};

    }
    auto& actor = *maybe__actor;
    // Sentinel = 'PCompositorManager'
    if ((!((aReader)->ReadSentinel(1134364475)))) {
        mozilla::ipc::SentinelReadError("Error deserializing managed PCompositorManager actor");
        return {};
    }

    if (actor && actor->GetProtocolId() != PCompositorManagerMsgStart) {
        aReader->FatalError("Unexpected actor type (expected PCompositorManager)");

        return {};
    }
    return static_cast<::mozilla::layers::PCompositorManagerChild*>(actor);
}

} // namespace IPC
