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


#include "mozilla/layers/PNativeLayerRemoteChild.h"
#include "mozilla/GfxMessageUtils.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/ProfilerMarkers.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/layers/NativeLayerRemoteChild.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 PNativeLayerRemoteChild::ProcessingError(
        Result aCode,
        const char* aReason) -> void
{
}

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

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

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

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

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

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

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

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

auto PNativeLayerRemoteChild::ManagedProtocolIds() const -> mozilla::Span<mozilla::ipc::ProtocolId const>
{
    return {};
}

auto PNativeLayerRemoteChild::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    default:
        return nullptr;
    }
}

auto PNativeLayerRemoteChild::SendCommitNativeLayerCommands(nsTArray<NativeLayerCommand>&& commands) -> bool
{
    UniquePtr<IPC::Message> msg__ = PNativeLayerRemote::Msg_CommitNativeLayerCommands(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

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


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

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

auto PNativeLayerRemoteChild::SendRequestReadback(
        const IntSize& size,
        Shmem* pixels) -> bool
{
    UniquePtr<IPC::Message> msg__ = PNativeLayerRemote::Msg_RequestReadback(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

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

    UniquePtr<Message> reply__;

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

    bool sendok__ = false;
    {
        AUTO_PROFILER_MARKER("PNativeLayerRemote::Msg_RequestReadback", IPC);
        sendok__ = ChannelSend(std::move(msg__), (&(reply__)));
    }
    if ((!(sendok__))) {
        return false;
    }

    if (mozilla::ipc::LoggingEnabledFor("PNativeLayerRemote", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PNativeLayerRemoteChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Received reply ",
            reply__->type(),
            mozilla::ipc::MessageDirection::eReceiving);
    }

    IPC::MessageReader reader__{
            (*(reply__)),
            this};

    auto maybe__pixels__reply = IPC::ReadParam<Shmem>((&(reader__)));
    if (!maybe__pixels__reply) {
        FatalError("Error deserializing 'Shmem'");
        return false;

    }
    auto& pixels__reply = *maybe__pixels__reply;
    // Sentinel = 'pixels'
    if ((!(((&(reader__)))->ReadSentinel(151847574)))) {
        mozilla::ipc::SentinelReadError("Error deserializing 'Shmem'");
        return false;
    }
    (*(pixels)) = std::move(pixels__reply);
    reader__.EndRead();

    return true;
}

auto PNativeLayerRemoteChild::SendFlush() -> bool
{
    UniquePtr<IPC::Message> msg__ = PNativeLayerRemote::Msg_Flush(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};


    UniquePtr<Message> reply__;

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

    bool sendok__ = false;
    {
        AUTO_PROFILER_MARKER("PNativeLayerRemote::Msg_Flush", IPC);
        sendok__ = ChannelSend(std::move(msg__), (&(reply__)));
    }
    if ((!(sendok__))) {
        return false;
    }

    if (mozilla::ipc::LoggingEnabledFor("PNativeLayerRemote", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PNativeLayerRemoteChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Received reply ",
            reply__->type(),
            mozilla::ipc::MessageDirection::eReceiving);
    }

    return true;
}

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

auto PNativeLayerRemoteChild::OnMessageReceived(const Message& msg__) -> PNativeLayerRemoteChild::Result
{
    switch (msg__.type()) {
    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 PNativeLayerRemoteChild::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PNativeLayerRemoteChild::Result
{
    return MsgNotKnown;
}



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

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

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

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

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

} // namespace IPC
