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


#include "mozilla/layers/PVideoBridgeParent.h"
#include "gfxipc/ShadowLayerUtils.h"
#include "mozilla/GfxMessageUtils.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/ipc/IPCCore.h"
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/LayersMessageUtils.h"
#include "mozilla/layers/VideoBridgeParent.h"
#include "mozilla/layers/WebRenderMessageUtils.h"
#include "nsPoint.h"
#include "nsRect.h"

#include "mozilla/layers/PTextureParent.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 PVideoBridgeParent::RecvPTextureConstructor(
        PTextureParent* actor,
        const SurfaceDescriptor& aSharedData,
        ReadLockDescriptor&& aReadLock,
        const LayersBackend& aBackend,
        const TextureFlags& aTextureFlags,
        const ContentParentId& aContentId,
        const uint64_t& aSerial) -> mozilla::ipc::IPCResult
{
    return IPC_OK();
}

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

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

MOZ_IMPLICIT PVideoBridgeParent::PVideoBridgeParent() :
    mozilla::ipc::IToplevelProtocol("PVideoBridgeParent", kProtocolId, mozilla::ipc::ParentSide)
{
    MOZ_COUNT_CTOR(PVideoBridgeParent);
}

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

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

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

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

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

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

auto PVideoBridgeParent::ManagedPTextureParent(nsTArray<PTextureParent*>& aArr) const -> void
{
    mManagedPTextureParent.ToArray(aArr);
}

auto PVideoBridgeParent::ManagedPTextureParent() const -> const ManagedContainer<PTextureParent>&
{
    return mManagedPTextureParent;
}

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

auto PVideoBridgeParent::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    case PTextureMsgStart:
        return (&(mManagedPTextureParent));
    default:
        return nullptr;
    }
}

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

auto PVideoBridgeParent::OpenPTextureEndpoint(PTextureParent* aActor) -> ManagedEndpoint<PTextureChild>
{
    if (!aActor) {
        NS_WARNING("Cannot bind null PTextureParent actor");
        return ManagedEndpoint<PTextureChild>();
    }

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

    // 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<PTextureChild>(mozilla::ipc::PrivateIPDLInterface(), aActor);
}

auto PVideoBridgeParent::BindPTextureEndpoint(
        ManagedEndpoint<PTextureParent> aEndpoint,
        PTextureParent* aActor) -> bool
{
    return aEndpoint.Bind(mozilla::ipc::PrivateIPDLInterface(), aActor, this);
}

auto PVideoBridgeParent::SendPing(
        mozilla::ipc::ResolveCallback<void_t>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PVideoBridge::Msg_Ping(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



    if (mozilla::ipc::LoggingEnabledFor("PVideoBridge", mozilla::ipc::ParentSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PVideoBridgeParent",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PVideoBridge::Msg_Ping", OTHER);

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

            }
            auto& ok = *maybe__ok;
            // Sentinel = 'ok'
            if ((!((aReader)->ReadSentinel(21692635)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'void_t'");
                return MsgValueError;
            }


            aReader->EndRead();

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

auto PVideoBridgeParent::SendPing() -> RefPtr<PingPromise>
{
    RefPtr<MozPromise<void_t, ResponseRejectReason, true>::Private> promise__ = new MozPromise<void_t, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendPing([promise__](void_t&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PVideoBridgeParent::DeallocManagee(
        mozilla::ipc::ProtocolId aProtocolId,
        IProtocol* aListener) -> void
{
    switch (aProtocolId) {
    case PTextureMsgStart:
        static_cast<VideoBridgeParent*>(this)->DeallocPTextureParent(static_cast<PTextureParent*>(aListener));
        return;
    default:
        FatalError("unreached");
        return;
    }
}

auto PVideoBridgeParent::OnMessageReceived(const Message& msg__) -> PVideoBridgeParent::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("PVideoBridge", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PVideoBridgeParent",
                    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 PVideoBridge::Reply_Ping__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PVideoBridge", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PVideoBridgeParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PVideoBridge::Msg_Ping", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PVideoBridge::Msg_PTextureConstructor__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PVideoBridge", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PVideoBridgeParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PVideoBridge::Msg_PTextureConstructor", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__actorid__ = IPC::ReadParam<mozilla::ipc::ActorId>((&(reader__)));
            if (!maybe__actorid__) {
                FatalError("Error deserializing 'mozilla::ipc::ActorId'");
                return MsgValueError;

            }
            auto& actorid__ = *maybe__actorid__;
            // Sentinel = 'actorid'
            if ((!(((&(reader__)))->ReadSentinel(193725159)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'mozilla::ipc::ActorId'");
                return MsgValueError;
            }
            auto maybe__aSharedData = IPC::ReadParam<SurfaceDescriptor>((&(reader__)));
            if (!maybe__aSharedData) {
                FatalError("Error deserializing 'SurfaceDescriptor'");
                return MsgValueError;

            }
            auto& aSharedData = *maybe__aSharedData;
            // Sentinel = 'aSharedData'
            if ((!(((&(reader__)))->ReadSentinel(420480051)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'SurfaceDescriptor'");
                return MsgValueError;
            }
            auto maybe__aReadLock = IPC::ReadParam<ReadLockDescriptor>((&(reader__)));
            if (!maybe__aReadLock) {
                FatalError("Error deserializing 'ReadLockDescriptor'");
                return MsgValueError;

            }
            auto& aReadLock = *maybe__aReadLock;
            // Sentinel = 'aReadLock'
            if ((!(((&(reader__)))->ReadSentinel(279774055)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'ReadLockDescriptor'");
                return MsgValueError;
            }
            auto maybe__aBackend = IPC::ReadParam<LayersBackend>((&(reader__)));
            if (!maybe__aBackend) {
                FatalError("Error deserializing 'LayersBackend'");
                return MsgValueError;

            }
            auto& aBackend = *maybe__aBackend;
            // Sentinel = 'aBackend'
            if ((!(((&(reader__)))->ReadSentinel(221119242)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'LayersBackend'");
                return MsgValueError;
            }
            auto maybe__aTextureFlags = IPC::ReadParam<TextureFlags>((&(reader__)));
            if (!maybe__aTextureFlags) {
                FatalError("Error deserializing 'TextureFlags'");
                return MsgValueError;

            }
            auto& aTextureFlags = *maybe__aTextureFlags;
            // Sentinel = 'aTextureFlags'
            if ((!(((&(reader__)))->ReadSentinel(614139200)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'TextureFlags'");
                return MsgValueError;
            }
            auto maybe__aContentId = IPC::ReadParam<ContentParentId>((&(reader__)));
            if (!maybe__aContentId) {
                FatalError("Error deserializing 'ContentParentId'");
                return MsgValueError;

            }
            auto& aContentId = *maybe__aContentId;
            // Sentinel = 'aContentId'
            if ((!(((&(reader__)))->ReadSentinel(358876138)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'ContentParentId'");
                return MsgValueError;
            }
            auto maybe__aSerial = IPC::ReadParam<uint64_t>((&(reader__)));
            if (!maybe__aSerial) {
                FatalError("Error deserializing 'uint64_t'");
                return MsgValueError;

            }
            auto& aSerial = *maybe__aSerial;
            // Sentinel = 'aSerial'
            if ((!(((&(reader__)))->ReadSentinel(181011138)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'uint64_t'");
                return MsgValueError;
            }
            reader__.EndRead();
            PTextureParent* actor = (static_cast<VideoBridgeParent*>(this))->AllocPTextureParent(aSharedData, aReadLock, aBackend, aTextureFlags, aContentId, aSerial);
            if (!actor) {
                NS_WARNING("Cannot bind null PTextureParent actor");
                return MsgValueError;
            }

            if (!actor->SetManagerAndRegister(this, actorid__)) {
                NS_WARNING("Failed to bind PTextureParent actor");
                return MsgValueError;
            }

            mozilla::ipc::IPCResult __ok = (static_cast<VideoBridgeParent*>(this))->RecvPTextureConstructor(std::move(actor), std::move(aSharedData), std::move(aReadLock), std::move(aBackend), std::move(aTextureFlags), std::move(aContentId), std::move(aSerial));
            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 PVideoBridgeParent::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PVideoBridgeParent::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::PVideoBridgeParent*>::Write(
        IPC::MessageWriter* aWriter,
        const paramType& aVar) -> void
{
    IPC::WriteParam(aWriter, static_cast<mozilla::ipc::IProtocol*>(aVar));
    // Sentinel = 'PVideoBridge'
    (aWriter)->WriteSentinel(487982229);
}

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

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

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

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

} // namespace IPC
