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


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

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

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

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

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

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

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

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

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

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

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

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

auto PNativeLayerRemoteParent::OnMessageReceived(const Message& msg__) -> PNativeLayerRemoteParent::Result
{
    switch (msg__.type()) {
    case PNativeLayerRemote::Msg_CommitNativeLayerCommands__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PNativeLayerRemote", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PNativeLayerRemoteParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PNativeLayerRemote::Msg_CommitNativeLayerCommands", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__commands = IPC::ReadParam<nsTArray<NativeLayerCommand>>((&(reader__)));
            if (!maybe__commands) {
                FatalError("Error deserializing 'NativeLayerCommand[]'");
                return MsgValueError;

            }
            auto& commands = *maybe__commands;
            // Sentinel = 'commands'
            if ((!(((&(reader__)))->ReadSentinel(249627475)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'NativeLayerCommand[]'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (static_cast<NativeLayerRemoteParent*>(this))->RecvCommitNativeLayerCommands(std::move(commands));
            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 PNativeLayerRemoteParent::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PNativeLayerRemoteParent::Result
{
    switch (msg__.type()) {
    case PNativeLayerRemote::Msg_RequestReadback__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PNativeLayerRemote", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PNativeLayerRemoteParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PNativeLayerRemote::Msg_RequestReadback", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

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

            }
            auto& size = *maybe__size;
            // Sentinel = 'size'
            if ((!(((&(reader__)))->ReadSentinel(73662908)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'IntSize'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::ActorId id__ = MSG_ROUTING_CONTROL;
            Shmem pixels{};
            mozilla::ipc::IPCResult __ok = (static_cast<NativeLayerRemoteParent*>(this))->RecvRequestReadback(std::move(size), (&(pixels)));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            reply__ = PNativeLayerRemote::Reply_RequestReadback(id__);
            IPC::MessageWriter writer__{
                    (*(reply__)),
                    this};

            IPC::WriteParam((&(writer__)), std::move(pixels));
            // Sentinel = 'pixels'
            ((&(writer__)))->WriteSentinel(151847574);
            if (mozilla::ipc::LoggingEnabledFor("PNativeLayerRemote", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PNativeLayerRemoteParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Sending reply ",
                    reply__->type(),
                    mozilla::ipc::MessageDirection::eSending);
            }
            return MsgProcessed;
        }
    case PNativeLayerRemote::Msg_Flush__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PNativeLayerRemote", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PNativeLayerRemoteParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PNativeLayerRemote::Msg_Flush", OTHER);

            mozilla::ipc::ActorId id__ = MSG_ROUTING_CONTROL;
            mozilla::ipc::IPCResult __ok = (static_cast<NativeLayerRemoteParent*>(this))->RecvFlush();
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            reply__ = PNativeLayerRemote::Reply_Flush(id__);
            IPC::MessageWriter writer__{
                    (*(reply__)),
                    this};

            if (mozilla::ipc::LoggingEnabledFor("PNativeLayerRemote", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PNativeLayerRemoteParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Sending reply ",
                    reply__->type(),
                    mozilla::ipc::MessageDirection::eSending);
            }
            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    }
}



} // namespace layers
} // namespace mozilla
namespace IPC {
auto ParamTraits<::mozilla::layers::PNativeLayerRemoteParent*>::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::PNativeLayerRemoteParent*>::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::PNativeLayerRemoteParent*>(actor);
}

} // namespace IPC
