// services/viz/public/mojom/compositing/transferable_resource.mojom-shared.h is auto generated by mojom_bindings_generator.py, do not edit

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_VIZ_PUBLIC_MOJOM_COMPOSITING_TRANSFERABLE_RESOURCE_MOJOM_SHARED_H_
#define SERVICES_VIZ_PUBLIC_MOJOM_COMPOSITING_TRANSFERABLE_RESOURCE_MOJOM_SHARED_H_

#include <stdint.h>

#include <functional>
#include <iosfwd>
#include <type_traits>
#include <utility>
#include "mojo/public/cpp/bindings/array_data_view.h"
#include "mojo/public/cpp/bindings/map_data_view.h"
#include "mojo/public/cpp/bindings/string_data_view.h"
#include "mojo/public/cpp/system/message_pipe.h"

#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"

#include "services/viz/public/mojom/compositing/transferable_resource.mojom-shared-internal.h"
#include "gpu/ipc/common/exported_shared_image.mojom-shared.h"
#include "gpu/ipc/common/sync_token.mojom-shared.h"
#include "gpu/ipc/common/vulkan_ycbcr_info.mojom-shared.h"
#include "services/viz/public/mojom/compositing/shared_image_format.mojom-shared.h"
#include "services/viz/public/mojom/compositing/resource_id.mojom-shared.h"
#include "ui/gfx/geometry/mojom/geometry.mojom-shared.h"
#include "ui/gfx/mojom/color_space.mojom-shared.h"
#include "ui/gfx/mojom/hdr_metadata.mojom-shared.h"
#include "skia/public/mojom/image_info.mojom-shared.h"
#include "mojo/public/cpp/bindings/lib/interface_serialization.h"
#include "mojo/public/cpp/system/data_pipe.h"



#include "services/viz/public/mojom/compositing/transferable_resource.mojom-data-view.h"  // IWYU pragma: export




namespace std {

template <>
struct hash<::viz::mojom::SynchronizationType>
    : public mojo::internal::EnumHashImpl<::viz::mojom::SynchronizationType> {};

template <>
struct hash<::viz::mojom::ResourceSource>
    : public mojo::internal::EnumHashImpl<::viz::mojom::ResourceSource> {};

}  // namespace std

namespace mojo {


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::viz::mojom::SynchronizationType, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = EnumTraits<::viz::mojom::SynchronizationType, UserType>;

  static void Serialize(UserType input, int32_t* output) {
    *output = static_cast<int32_t>(Traits::ToMojom(input));
  }

  static bool Deserialize(int32_t input, UserType* output) {
    auto known_value = ::mojo::internal::ToKnownEnumValueHelper(
        static_cast<::viz::mojom::SynchronizationType>(input));
    if constexpr (requires {
                    {
                      Traits::FromMojom(known_value)
                    } -> std::same_as<UserType>;
                  }) {
      static_assert(std::same_as<::viz::mojom::SynchronizationType, UserType> ||
                        HasInfallibleConversion(::viz::mojom::SynchronizationType()),
                    "::viz::mojom::SynchronizationType does not have an infallible conversion, "
                    "use an optional return type.");
      *output = Traits::FromMojom(known_value);
      return true;
    } else {
      static_assert(
          requires {
            {
              Traits::FromMojom(known_value)
            } -> std::same_as<std::optional<UserType>>;
          }, "FromMojom must return by value or optional.");
      std::optional<UserType> from_mojom = Traits::FromMojom(known_value);
      if (from_mojom) {
        *output = *from_mojom;
      }
      return from_mojom.has_value();
    }
  }
};

}  // namespace internal


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::viz::mojom::ResourceSource, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = EnumTraits<::viz::mojom::ResourceSource, UserType>;

  static void Serialize(UserType input, int32_t* output) {
    *output = static_cast<int32_t>(Traits::ToMojom(input));
  }

  static bool Deserialize(int32_t input, UserType* output) {
    auto known_value = ::mojo::internal::ToKnownEnumValueHelper(
        static_cast<::viz::mojom::ResourceSource>(input));
    if constexpr (requires {
                    {
                      Traits::FromMojom(known_value)
                    } -> std::same_as<UserType>;
                  }) {
      static_assert(std::same_as<::viz::mojom::ResourceSource, UserType> ||
                        HasInfallibleConversion(::viz::mojom::ResourceSource()),
                    "::viz::mojom::ResourceSource does not have an infallible conversion, "
                    "use an optional return type.");
      *output = Traits::FromMojom(known_value);
      return true;
    } else {
      static_assert(
          requires {
            {
              Traits::FromMojom(known_value)
            } -> std::same_as<std::optional<UserType>>;
          }, "FromMojom must return by value or optional.");
      std::optional<UserType> from_mojom = Traits::FromMojom(known_value);
      if (from_mojom) {
        *output = *from_mojom;
      }
      return from_mojom.has_value();
    }
  }
};

}  // namespace internal


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::viz::mojom::MetadataOverrideDataView, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = StructTraits<::viz::mojom::MetadataOverrideDataView, UserType>;

  static void Serialize(
      MaybeConstUserType& input,
      mojo::internal::MessageFragment<::viz::mojom::internal::MetadataOverride_Data>& fragment) {
    if (CallIsNullIfExists<Traits>(input))
      return;
    fragment.Allocate();
    fragment->is_overlay_candidate_$flag = Traits::is_overlay_candidate(input).has_value();
    if (Traits::is_overlay_candidate(input).has_value()) {
      fragment->is_overlay_candidate_$value = Traits::is_overlay_candidate(input).value();
    }

    decltype(Traits::color_space(input)) in_color_space = Traits::color_space(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->color_space)::BaseType> color_space_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::gfx::mojom::ColorSpaceDataView>(
      in_color_space,
      color_space_fragment);

    fragment->color_space.Set(
        color_space_fragment.is_null() ? nullptr : color_space_fragment.data());
    fragment->alpha_type_$flag = Traits::alpha_type(input).has_value();
    if (Traits::alpha_type(input).has_value()) {
      
      mojo::internal::Serialize<::skia::mojom::AlphaType>(
        Traits::alpha_type(input).value(),
        &fragment->alpha_type_$value);
    } else {
      fragment->alpha_type_$value =
          static_cast<int32_t>(::skia::mojom::AlphaType::kMinValue);
    }
  }

  static bool Deserialize(::viz::mojom::internal::MetadataOverride_Data* input,
                          UserType* output,
                          Message* message) {
    if (!input)
      return CallSetToNullIfExists<Traits>(output);

    ::viz::mojom::MetadataOverrideDataView data_view(input, message);
    return CallTraitsRead<Traits>(data_view, output);
  }
};

}  // namespace internal


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::viz::mojom::TransferableResourceDataView, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = StructTraits<::viz::mojom::TransferableResourceDataView, UserType>;

  static void Serialize(
      MaybeConstUserType& input,
      mojo::internal::MessageFragment<::viz::mojom::internal::TransferableResource_Data>& fragment) {
    if (CallIsNullIfExists<Traits>(input))
      return;
    fragment.Allocate();

    decltype(Traits::id(input)) in_id = Traits::id(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->id)::BaseType> id_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::viz::mojom::ResourceIdDataView>(
      in_id,
      id_fragment);

    fragment->id.Set(
        id_fragment.is_null() ? nullptr : id_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->id.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null id in TransferableResource struct");

    decltype(Traits::shared_image(input)) in_shared_image = Traits::shared_image(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->shared_image)::BaseType> shared_image_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::gpu::mojom::ExportedSharedImageDataView>(
      in_shared_image,
      shared_image_fragment);

    fragment->shared_image.Set(
        shared_image_fragment.is_null() ? nullptr : shared_image_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->shared_image.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null shared_image in TransferableResource struct");

    decltype(Traits::sync_token(input)) in_sync_token = Traits::sync_token(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->sync_token)::BaseType> sync_token_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::gpu::mojom::SyncTokenDataView>(
      in_sync_token,
      sync_token_fragment);

    fragment->sync_token.Set(
        sync_token_fragment.is_null() ? nullptr : sync_token_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->sync_token.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null sync_token in TransferableResource struct");

    
    mojo::internal::Serialize<::viz::mojom::SynchronizationType>(
      Traits::synchronization_type(input),
      &fragment->synchronization_type);

    fragment->is_backed_by_surface_view = Traits::is_backed_by_surface_view(input);

    fragment->wants_promotion_hint = Traits::wants_promotion_hint(input);

    decltype(Traits::hdr_metadata(input)) in_hdr_metadata = Traits::hdr_metadata(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->hdr_metadata)::BaseType> hdr_metadata_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::gfx::mojom::HDRMetadataDataView>(
      in_hdr_metadata,
      hdr_metadata_fragment);

    fragment->hdr_metadata.Set(
        hdr_metadata_fragment.is_null() ? nullptr : hdr_metadata_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->hdr_metadata.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null hdr_metadata in TransferableResource struct");

    fragment->needs_detiling = Traits::needs_detiling(input);

    decltype(Traits::ycbcr_info(input)) in_ycbcr_info = Traits::ycbcr_info(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->ycbcr_info)::BaseType> ycbcr_info_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::gpu::mojom::VulkanYCbCrInfoDataView>(
      in_ycbcr_info,
      ycbcr_info_fragment);

    fragment->ycbcr_info.Set(
        ycbcr_info_fragment.is_null() ? nullptr : ycbcr_info_fragment.data());

    
    mojo::internal::Serialize<::viz::mojom::ResourceSource>(
      Traits::resource_source(input),
      &fragment->resource_source);

    decltype(Traits::metadata_override(input)) in_metadata_override = Traits::metadata_override(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->metadata_override)::BaseType> metadata_override_fragment(
            fragment.message());
    
    mojo::internal::Serialize<::viz::mojom::MetadataOverrideDataView>(
      in_metadata_override,
      metadata_override_fragment);

    fragment->metadata_override.Set(
        metadata_override_fragment.is_null() ? nullptr : metadata_override_fragment.data());

    
    MOJO_INTERNAL_CHECK_SERIALIZATION(
      mojo::internal::SendValidation::kDefault,
      !(fragment->metadata_override.is_null()),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null metadata_override in TransferableResource struct");
  }

  static bool Deserialize(::viz::mojom::internal::TransferableResource_Data* input,
                          UserType* output,
                          Message* message) {
    if (!input)
      return CallSetToNullIfExists<Traits>(output);

    ::viz::mojom::TransferableResourceDataView data_view(input, message);
    return CallTraitsRead<Traits>(data_view, output);
  }
};

}  // namespace internal

}  // namespace mojo


namespace viz::mojom {

inline void MetadataOverrideDataView::GetColorSpaceDataView(
    ::gfx::mojom::ColorSpaceDataView* output) {
  auto pointer = data_->color_space.Get();
  *output = ::gfx::mojom::ColorSpaceDataView(pointer, message_);
}


inline void TransferableResourceDataView::GetIdDataView(
    ::viz::mojom::ResourceIdDataView* output) {
  auto pointer = data_->id.Get();
  *output = ::viz::mojom::ResourceIdDataView(pointer, message_);
}
inline void TransferableResourceDataView::GetSharedImageDataView(
    ::gpu::mojom::ExportedSharedImageDataView* output) {
  auto pointer = data_->shared_image.Get();
  *output = ::gpu::mojom::ExportedSharedImageDataView(pointer, message_);
}
inline void TransferableResourceDataView::GetSyncTokenDataView(
    ::gpu::mojom::SyncTokenDataView* output) {
  auto pointer = data_->sync_token.Get();
  *output = ::gpu::mojom::SyncTokenDataView(pointer, message_);
}
inline void TransferableResourceDataView::GetHdrMetadataDataView(
    ::gfx::mojom::HDRMetadataDataView* output) {
  auto pointer = data_->hdr_metadata.Get();
  *output = ::gfx::mojom::HDRMetadataDataView(pointer, message_);
}
inline void TransferableResourceDataView::GetYcbcrInfoDataView(
    ::gpu::mojom::VulkanYCbCrInfoDataView* output) {
  auto pointer = data_->ycbcr_info.Get();
  *output = ::gpu::mojom::VulkanYCbCrInfoDataView(pointer, message_);
}
inline void TransferableResourceDataView::GetMetadataOverrideDataView(
    MetadataOverrideDataView* output) {
  auto pointer = data_->metadata_override.Get();
  *output = MetadataOverrideDataView(pointer, message_);
}



}  // viz::mojom

// Declare TraceFormatTraits for enums, which should be defined in ::perfetto
// namespace.

namespace perfetto {

template <>
struct  TraceFormatTraits<::viz::mojom::SynchronizationType> {
 static void WriteIntoTrace(perfetto::TracedValue context, ::viz::mojom::SynchronizationType value);
};

} // namespace perfetto

namespace perfetto {

template <>
struct  TraceFormatTraits<::viz::mojom::ResourceSource> {
 static void WriteIntoTrace(perfetto::TracedValue context, ::viz::mojom::ResourceSource value);
};

} // namespace perfetto

#endif  // SERVICES_VIZ_PUBLIC_MOJOM_COMPOSITING_TRANSFERABLE_RESOURCE_MOJOM_SHARED_H_