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

// Copyright 2013 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_H_
#define SERVICES_VIZ_PUBLIC_MOJOM_COMPOSITING_TRANSFERABLE_RESOURCE_MOJOM_H_

#include <stdint.h>

#include <limits>
#include <optional>
#include <type_traits>
#include <utility>
#include "mojo/public/cpp/bindings/clone_traits.h"
#include "mojo/public/cpp/bindings/equals_traits.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "mojo/public/cpp/bindings/union_traits.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"

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

#include "services/viz/public/mojom/compositing/transferable_resource.mojom-features.h"  // IWYU pragma: export
#include "services/viz/public/mojom/compositing/transferable_resource.mojom-shared.h"  // IWYU pragma: export
#include "services/viz/public/mojom/compositing/transferable_resource.mojom-forward.h"  // IWYU pragma: export
#include "gpu/ipc/common/exported_shared_image.mojom.h"
#include "gpu/ipc/common/sync_token.mojom.h"
#include "gpu/ipc/common/vulkan_ycbcr_info.mojom.h"
#include "services/viz/public/mojom/compositing/shared_image_format.mojom-forward.h"
#include "services/viz/public/mojom/compositing/resource_id.mojom.h"
#include "ui/gfx/geometry/mojom/geometry.mojom-forward.h"
#include "ui/gfx/mojom/color_space.mojom.h"
#include "ui/gfx/mojom/hdr_metadata.mojom.h"
#include "skia/public/mojom/image_info.mojom.h"
#include <string>
#include <vector>

#include "mojo/public/cpp/bindings/lib/control_message_handler.h"
#include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h"


#include "services/viz/public/cpp/compositing/transferable_resource_mojom_traits.h"




namespace viz::mojom {









class  MetadataOverride {
 public:
  template <typename T>
  using EnableIfSame = std::enable_if_t<std::is_same<MetadataOverride, T>::value>;
  using DataView = MetadataOverrideDataView;
  using Data_ = internal::MetadataOverride_Data;

  template <typename... Args>
  static MetadataOverridePtr New(Args&&... args) {
    return MetadataOverridePtr(
        std::in_place, std::forward<Args>(args)...);
  }

  template <typename U>
  static MetadataOverridePtr From(const U& u) {
    return mojo::TypeConverter<MetadataOverridePtr, U>::Convert(u);
  }

  template <typename U>
  U To() const {
    return mojo::TypeConverter<U, MetadataOverride>::Convert(*this);
  }


  MetadataOverride();

  MetadataOverride(
      std::optional<bool> is_overlay_candidate,
      const std::optional<::gfx::ColorSpace>& color_space,
      std::optional<::SkAlphaType> alpha_type);


  ~MetadataOverride();

  // Clone() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Clone() or copy
  // constructor/assignment are available for members.
  template <typename StructPtrType = MetadataOverridePtr>
  MetadataOverridePtr Clone() const;

  // Equals() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Equals() or == operator
  // are available for members.
  template <typename T, MetadataOverride::EnableIfSame<T>* = nullptr>
  bool Equals(const T& other) const;

  template <typename T, MetadataOverride::EnableIfSame<T>* = nullptr>
  bool operator==(const T& rhs) const { return Equals(rhs); }

  template <typename T, MetadataOverride::EnableIfSame<T>* = nullptr>
  bool operator!=(const T& rhs) const { return !operator==(rhs); }

  template <mojo::internal::SendValidation send_validation, typename UserType>
  static std::vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        MetadataOverride::DataView, std::vector<uint8_t>, send_validation>(input);
  }

  template <typename UserType>
  static std::vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        MetadataOverride::DataView, std::vector<uint8_t>>(input);
  }

  template <typename UserType>
  static mojo::Message SerializeAsMessage(UserType* input) {
    return mojo::internal::SerializeAsMessageImpl<
        MetadataOverride::DataView>(input);
  }

  // The returned Message is serialized only if the message is moved
  // cross-process or cross-language. Otherwise if the message is Deserialized
  // as the same UserType |input| will just be moved to |output| in
  // DeserializeFromMessage.
  template <typename UserType>
  static mojo::Message WrapAsMessage(UserType input) {
    return mojo::Message(std::make_unique<
        internal::MetadataOverride_UnserializedMessageContext<
            UserType, MetadataOverride::DataView>>(0, 0, std::move(input)),
        MOJO_CREATE_MESSAGE_FLAG_NONE);
  }

  template <typename UserType>
  static bool Deserialize(const void* data,
                          size_t data_num_bytes,
                          UserType* output) {
    mojo::Message message;
    return mojo::internal::DeserializeImpl<MetadataOverride::DataView>(
        message, data, data_num_bytes, output, Validate);
  }

  template <typename UserType>
  static bool Deserialize(base::span<const uint8_t> input,
                          UserType* output) {
    return MetadataOverride::Deserialize(
        input.empty() ? nullptr : input.data(), input.size(), output);
  }

  template <typename UserType>
  static bool DeserializeFromMessage(mojo::Message input,
                                     UserType* output) {
    auto context = input.TakeUnserializedContext<
        internal::MetadataOverride_UnserializedMessageContext<
            UserType, MetadataOverride::DataView>>();
    if (context) {
      *output = std::move(context->TakeData());
      return true;
    }
    input.SerializeIfNecessary();
    return mojo::internal::DeserializeImpl<MetadataOverride::DataView>(
        input, input.payload(), input.payload_num_bytes(), output, Validate);
  }

  
  std::optional<bool> is_overlay_candidate;
  
  std::optional<::gfx::ColorSpace> color_space;
  
  std::optional<::SkAlphaType> alpha_type;

  // Serialise this struct into a trace.
  void WriteIntoTrace(perfetto::TracedValue traced_context) const;

 private:
  static bool Validate(const void* data,
                       mojo::internal::ValidationContext* validation_context);
};

// The comparison operators are templates, so they are only instantiated if they
// are used. Thus, the bindings generator does not need to know whether
// comparison operators are available for members.
template <typename T, MetadataOverride::EnableIfSame<T>* = nullptr>
bool operator<(const T& lhs, const T& rhs);

template <typename T, MetadataOverride::EnableIfSame<T>* = nullptr>
bool operator<=(const T& lhs, const T& rhs) {
  return !(rhs < lhs);
}

template <typename T, MetadataOverride::EnableIfSame<T>* = nullptr>
bool operator>(const T& lhs, const T& rhs) {
  return rhs < lhs;
}

template <typename T, MetadataOverride::EnableIfSame<T>* = nullptr>
bool operator>=(const T& lhs, const T& rhs) {
  return !(lhs < rhs);
}





class  TransferableResource {
 public:
  template <typename T>
  using EnableIfSame = std::enable_if_t<std::is_same<TransferableResource, T>::value>;
  using DataView = TransferableResourceDataView;
  using Data_ = internal::TransferableResource_Data;

  template <typename... Args>
  static TransferableResourcePtr New(Args&&... args) {
    return TransferableResourcePtr(
        std::in_place, std::forward<Args>(args)...);
  }

  template <typename U>
  static TransferableResourcePtr From(const U& u) {
    return mojo::TypeConverter<TransferableResourcePtr, U>::Convert(u);
  }

  template <typename U>
  U To() const {
    return mojo::TypeConverter<U, TransferableResource>::Convert(*this);
  }


  TransferableResource();

  TransferableResource(
      const ::viz::ResourceId& id,
      ::gpu::ExportedSharedImage shared_image,
      const ::gpu::SyncToken& sync_token,
      SynchronizationType synchronization_type,
      bool is_backed_by_surface_view,
      bool wants_promotion_hint,
      const ::gfx::HDRMetadata& hdr_metadata,
      bool needs_detiling,
      std::optional<::gpu::VulkanYCbCrInfo> ycbcr_info,
      ResourceSource resource_source,
      MetadataOverridePtr metadata_override);

TransferableResource(const TransferableResource&) = delete;
TransferableResource& operator=(const TransferableResource&) = delete;

  ~TransferableResource();

  // Clone() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Clone() or copy
  // constructor/assignment are available for members.
  template <typename StructPtrType = TransferableResourcePtr>
  TransferableResourcePtr Clone() const;

  // Equals() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Equals() or == operator
  // are available for members.
  template <typename T, TransferableResource::EnableIfSame<T>* = nullptr>
  bool Equals(const T& other) const;

  template <typename T, TransferableResource::EnableIfSame<T>* = nullptr>
  bool operator==(const T& rhs) const { return Equals(rhs); }

  template <typename T, TransferableResource::EnableIfSame<T>* = nullptr>
  bool operator!=(const T& rhs) const { return !operator==(rhs); }

  template <typename UserType>
  static mojo::Message SerializeAsMessage(UserType* input) {
    return mojo::internal::SerializeAsMessageImpl<
        TransferableResource::DataView>(input);
  }

  // The returned Message is serialized only if the message is moved
  // cross-process or cross-language. Otherwise if the message is Deserialized
  // as the same UserType |input| will just be moved to |output| in
  // DeserializeFromMessage.
  template <typename UserType>
  static mojo::Message WrapAsMessage(UserType input) {
    return mojo::Message(std::make_unique<
        internal::TransferableResource_UnserializedMessageContext<
            UserType, TransferableResource::DataView>>(0, 0, std::move(input)),
        MOJO_CREATE_MESSAGE_FLAG_NONE);
  }

  template <typename UserType>
  static bool Deserialize(const void* data,
                          size_t data_num_bytes,
                          UserType* output) {
    mojo::Message message;
    return mojo::internal::DeserializeImpl<TransferableResource::DataView>(
        message, data, data_num_bytes, output, Validate);
  }

  template <typename UserType>
  static bool Deserialize(base::span<const uint8_t> input,
                          UserType* output) {
    return TransferableResource::Deserialize(
        input.empty() ? nullptr : input.data(), input.size(), output);
  }

  template <typename UserType>
  static bool DeserializeFromMessage(mojo::Message input,
                                     UserType* output) {
    auto context = input.TakeUnserializedContext<
        internal::TransferableResource_UnserializedMessageContext<
            UserType, TransferableResource::DataView>>();
    if (context) {
      *output = std::move(context->TakeData());
      return true;
    }
    input.SerializeIfNecessary();
    return mojo::internal::DeserializeImpl<TransferableResource::DataView>(
        input, input.payload(), input.payload_num_bytes(), output, Validate);
  }

  
  ::viz::ResourceId id;
  
  ::gpu::ExportedSharedImage shared_image;
  
  ::gpu::SyncToken sync_token;
  
  SynchronizationType synchronization_type;
  
  bool is_backed_by_surface_view;
  
  bool wants_promotion_hint;
  
  ::gfx::HDRMetadata hdr_metadata;
  
  bool needs_detiling;
  
  std::optional<::gpu::VulkanYCbCrInfo> ycbcr_info;
  
  ResourceSource resource_source;
  
  MetadataOverridePtr metadata_override;

  // Serialise this struct into a trace.
  void WriteIntoTrace(perfetto::TracedValue traced_context) const;

 private:
  static bool Validate(const void* data,
                       mojo::internal::ValidationContext* validation_context);
};

// The comparison operators are templates, so they are only instantiated if they
// are used. Thus, the bindings generator does not need to know whether
// comparison operators are available for members.
template <typename T, TransferableResource::EnableIfSame<T>* = nullptr>
bool operator<(const T& lhs, const T& rhs);

template <typename T, TransferableResource::EnableIfSame<T>* = nullptr>
bool operator<=(const T& lhs, const T& rhs) {
  return !(rhs < lhs);
}

template <typename T, TransferableResource::EnableIfSame<T>* = nullptr>
bool operator>(const T& lhs, const T& rhs) {
  return rhs < lhs;
}

template <typename T, TransferableResource::EnableIfSame<T>* = nullptr>
bool operator>=(const T& lhs, const T& rhs) {
  return !(lhs < rhs);
}

template <typename StructPtrType>
MetadataOverridePtr MetadataOverride::Clone() const {
  return New(
      mojo::Clone(is_overlay_candidate),
      mojo::Clone(color_space),
      mojo::Clone(alpha_type)
  );
}

template <typename T, MetadataOverride::EnableIfSame<T>*>
bool MetadataOverride::Equals(const T& other_struct) const {
  if (!mojo::Equals(this->is_overlay_candidate, other_struct.is_overlay_candidate))
    return false;
  if (!mojo::Equals(this->color_space, other_struct.color_space))
    return false;
  if (!mojo::Equals(this->alpha_type, other_struct.alpha_type))
    return false;
  return true;
}

template <typename T, MetadataOverride::EnableIfSame<T>*>
bool operator<(const T& lhs, const T& rhs) {
  if (lhs.is_overlay_candidate < rhs.is_overlay_candidate)
    return true;
  if (rhs.is_overlay_candidate < lhs.is_overlay_candidate)
    return false;
  if (lhs.color_space < rhs.color_space)
    return true;
  if (rhs.color_space < lhs.color_space)
    return false;
  if (lhs.alpha_type < rhs.alpha_type)
    return true;
  if (rhs.alpha_type < lhs.alpha_type)
    return false;
  return false;
}
template <typename StructPtrType>
TransferableResourcePtr TransferableResource::Clone() const {
  return New(
      mojo::Clone(id),
      mojo::Clone(shared_image),
      mojo::Clone(sync_token),
      mojo::Clone(synchronization_type),
      mojo::Clone(is_backed_by_surface_view),
      mojo::Clone(wants_promotion_hint),
      mojo::Clone(hdr_metadata),
      mojo::Clone(needs_detiling),
      mojo::Clone(ycbcr_info),
      mojo::Clone(resource_source),
      mojo::Clone(metadata_override)
  );
}

template <typename T, TransferableResource::EnableIfSame<T>*>
bool TransferableResource::Equals(const T& other_struct) const {
  if (!mojo::Equals(this->id, other_struct.id))
    return false;
  if (!mojo::Equals(this->shared_image, other_struct.shared_image))
    return false;
  if (!mojo::Equals(this->sync_token, other_struct.sync_token))
    return false;
  if (!mojo::Equals(this->synchronization_type, other_struct.synchronization_type))
    return false;
  if (!mojo::Equals(this->is_backed_by_surface_view, other_struct.is_backed_by_surface_view))
    return false;
  if (!mojo::Equals(this->wants_promotion_hint, other_struct.wants_promotion_hint))
    return false;
  if (!mojo::Equals(this->hdr_metadata, other_struct.hdr_metadata))
    return false;
  if (!mojo::Equals(this->needs_detiling, other_struct.needs_detiling))
    return false;
  if (!mojo::Equals(this->ycbcr_info, other_struct.ycbcr_info))
    return false;
  if (!mojo::Equals(this->resource_source, other_struct.resource_source))
    return false;
  if (!mojo::Equals(this->metadata_override, other_struct.metadata_override))
    return false;
  return true;
}

template <typename T, TransferableResource::EnableIfSame<T>*>
bool operator<(const T& lhs, const T& rhs) {
  if (lhs.id < rhs.id)
    return true;
  if (rhs.id < lhs.id)
    return false;
  if (lhs.shared_image < rhs.shared_image)
    return true;
  if (rhs.shared_image < lhs.shared_image)
    return false;
  if (lhs.sync_token < rhs.sync_token)
    return true;
  if (rhs.sync_token < lhs.sync_token)
    return false;
  if (lhs.synchronization_type < rhs.synchronization_type)
    return true;
  if (rhs.synchronization_type < lhs.synchronization_type)
    return false;
  if (lhs.is_backed_by_surface_view < rhs.is_backed_by_surface_view)
    return true;
  if (rhs.is_backed_by_surface_view < lhs.is_backed_by_surface_view)
    return false;
  if (lhs.wants_promotion_hint < rhs.wants_promotion_hint)
    return true;
  if (rhs.wants_promotion_hint < lhs.wants_promotion_hint)
    return false;
  if (lhs.hdr_metadata < rhs.hdr_metadata)
    return true;
  if (rhs.hdr_metadata < lhs.hdr_metadata)
    return false;
  if (lhs.needs_detiling < rhs.needs_detiling)
    return true;
  if (rhs.needs_detiling < lhs.needs_detiling)
    return false;
  if (lhs.ycbcr_info < rhs.ycbcr_info)
    return true;
  if (rhs.ycbcr_info < lhs.ycbcr_info)
    return false;
  if (lhs.resource_source < rhs.resource_source)
    return true;
  if (rhs.resource_source < lhs.resource_source)
    return false;
  if (lhs.metadata_override < rhs.metadata_override)
    return true;
  if (rhs.metadata_override < lhs.metadata_override)
    return false;
  return false;
}


}  // viz::mojom

namespace mojo {


template <>
struct  StructTraits<::viz::mojom::MetadataOverride::DataView,
                                         ::viz::mojom::MetadataOverridePtr> {
  static bool IsNull(const ::viz::mojom::MetadataOverridePtr& input) { return !input; }
  static void SetToNull(::viz::mojom::MetadataOverridePtr* output) { output->reset(); }

  static decltype(::viz::mojom::MetadataOverride::is_overlay_candidate) is_overlay_candidate(
      const ::viz::mojom::MetadataOverridePtr& input) {
    return input->is_overlay_candidate;
  }

  static const decltype(::viz::mojom::MetadataOverride::color_space)& color_space(
      const ::viz::mojom::MetadataOverridePtr& input) {
    return input->color_space;
  }

  static decltype(::viz::mojom::MetadataOverride::alpha_type) alpha_type(
      const ::viz::mojom::MetadataOverridePtr& input) {
    return input->alpha_type;
  }

  static bool Read(::viz::mojom::MetadataOverride::DataView input, ::viz::mojom::MetadataOverridePtr* output);
};


template <>
struct  StructTraits<::viz::mojom::TransferableResource::DataView,
                                         ::viz::mojom::TransferableResourcePtr> {
  static bool IsNull(const ::viz::mojom::TransferableResourcePtr& input) { return !input; }
  static void SetToNull(::viz::mojom::TransferableResourcePtr* output) { output->reset(); }

  static const decltype(::viz::mojom::TransferableResource::id)& id(
      const ::viz::mojom::TransferableResourcePtr& input) {
    return input->id;
  }

  static  decltype(::viz::mojom::TransferableResource::shared_image)& shared_image(
       ::viz::mojom::TransferableResourcePtr& input) {
    return input->shared_image;
  }

  static const decltype(::viz::mojom::TransferableResource::sync_token)& sync_token(
      const ::viz::mojom::TransferableResourcePtr& input) {
    return input->sync_token;
  }

  static decltype(::viz::mojom::TransferableResource::synchronization_type) synchronization_type(
      const ::viz::mojom::TransferableResourcePtr& input) {
    return input->synchronization_type;
  }

  static decltype(::viz::mojom::TransferableResource::is_backed_by_surface_view) is_backed_by_surface_view(
      const ::viz::mojom::TransferableResourcePtr& input) {
    return input->is_backed_by_surface_view;
  }

  static decltype(::viz::mojom::TransferableResource::wants_promotion_hint) wants_promotion_hint(
      const ::viz::mojom::TransferableResourcePtr& input) {
    return input->wants_promotion_hint;
  }

  static const decltype(::viz::mojom::TransferableResource::hdr_metadata)& hdr_metadata(
      const ::viz::mojom::TransferableResourcePtr& input) {
    return input->hdr_metadata;
  }

  static decltype(::viz::mojom::TransferableResource::needs_detiling) needs_detiling(
      const ::viz::mojom::TransferableResourcePtr& input) {
    return input->needs_detiling;
  }

  static const decltype(::viz::mojom::TransferableResource::ycbcr_info)& ycbcr_info(
      const ::viz::mojom::TransferableResourcePtr& input) {
    return input->ycbcr_info;
  }

  static decltype(::viz::mojom::TransferableResource::resource_source) resource_source(
      const ::viz::mojom::TransferableResourcePtr& input) {
    return input->resource_source;
  }

  static const decltype(::viz::mojom::TransferableResource::metadata_override)& metadata_override(
      const ::viz::mojom::TransferableResourcePtr& input) {
    return input->metadata_override;
  }

  static bool Read(::viz::mojom::TransferableResource::DataView input, ::viz::mojom::TransferableResourcePtr* output);
};

}  // namespace mojo

#endif  // SERVICES_VIZ_PUBLIC_MOJOM_COMPOSITING_TRANSFERABLE_RESOURCE_MOJOM_H_