// gpu/ipc/common/gpu_preferences.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 GPU_IPC_COMMON_GPU_PREFERENCES_MOJOM_SHARED_H_
#define GPU_IPC_COMMON_GPU_PREFERENCES_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 "gpu/ipc/common/gpu_preferences.mojom-shared-internal.h"
#include "ui/gfx/mojom/buffer_types.mojom-shared.h"




#include "gpu/ipc/common/gpu_preferences.mojom-data-view.h"  // IWYU pragma: export




namespace std {

template <>
struct hash<::gpu::mojom::VulkanImplementationName>
    : public mojo::internal::EnumHashImpl<::gpu::mojom::VulkanImplementationName> {};

template <>
struct hash<::gpu::mojom::WebGPUAdapterName>
    : public mojo::internal::EnumHashImpl<::gpu::mojom::WebGPUAdapterName> {};

template <>
struct hash<::gpu::mojom::WebGPUPowerPreference>
    : public mojo::internal::EnumHashImpl<::gpu::mojom::WebGPUPowerPreference> {};

template <>
struct hash<::gpu::mojom::GrContextType>
    : public mojo::internal::EnumHashImpl<::gpu::mojom::GrContextType> {};

template <>
struct hash<::gpu::mojom::DawnBackendValidationLevel>
    : public mojo::internal::EnumHashImpl<::gpu::mojom::DawnBackendValidationLevel> {};

}  // namespace std

namespace mojo {


namespace internal {

template <typename MaybeConstUserType>
struct Serializer<::gpu::mojom::VulkanImplementationName, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = EnumTraits<::gpu::mojom::VulkanImplementationName, 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<::gpu::mojom::VulkanImplementationName>(input));
    if constexpr (requires {
                    {
                      Traits::FromMojom(known_value)
                    } -> std::same_as<UserType>;
                  }) {
      static_assert(std::same_as<::gpu::mojom::VulkanImplementationName, UserType> ||
                        HasInfallibleConversion(::gpu::mojom::VulkanImplementationName()),
                    "::gpu::mojom::VulkanImplementationName 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<::gpu::mojom::WebGPUAdapterName, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = EnumTraits<::gpu::mojom::WebGPUAdapterName, 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<::gpu::mojom::WebGPUAdapterName>(input));
    if constexpr (requires {
                    {
                      Traits::FromMojom(known_value)
                    } -> std::same_as<UserType>;
                  }) {
      static_assert(std::same_as<::gpu::mojom::WebGPUAdapterName, UserType> ||
                        HasInfallibleConversion(::gpu::mojom::WebGPUAdapterName()),
                    "::gpu::mojom::WebGPUAdapterName 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<::gpu::mojom::WebGPUPowerPreference, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = EnumTraits<::gpu::mojom::WebGPUPowerPreference, 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<::gpu::mojom::WebGPUPowerPreference>(input));
    if constexpr (requires {
                    {
                      Traits::FromMojom(known_value)
                    } -> std::same_as<UserType>;
                  }) {
      static_assert(std::same_as<::gpu::mojom::WebGPUPowerPreference, UserType> ||
                        HasInfallibleConversion(::gpu::mojom::WebGPUPowerPreference()),
                    "::gpu::mojom::WebGPUPowerPreference 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<::gpu::mojom::GrContextType, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = EnumTraits<::gpu::mojom::GrContextType, 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<::gpu::mojom::GrContextType>(input));
    if constexpr (requires {
                    {
                      Traits::FromMojom(known_value)
                    } -> std::same_as<UserType>;
                  }) {
      static_assert(std::same_as<::gpu::mojom::GrContextType, UserType> ||
                        HasInfallibleConversion(::gpu::mojom::GrContextType()),
                    "::gpu::mojom::GrContextType 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<::gpu::mojom::DawnBackendValidationLevel, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = EnumTraits<::gpu::mojom::DawnBackendValidationLevel, 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<::gpu::mojom::DawnBackendValidationLevel>(input));
    if constexpr (requires {
                    {
                      Traits::FromMojom(known_value)
                    } -> std::same_as<UserType>;
                  }) {
      static_assert(std::same_as<::gpu::mojom::DawnBackendValidationLevel, UserType> ||
                        HasInfallibleConversion(::gpu::mojom::DawnBackendValidationLevel()),
                    "::gpu::mojom::DawnBackendValidationLevel 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<::gpu::mojom::GpuPreferencesDataView, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = StructTraits<::gpu::mojom::GpuPreferencesDataView, UserType>;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    decltype(Traits::ignored_gpu_blocklist_entries(input)) in_ignored_gpu_blocklist_entries = Traits::ignored_gpu_blocklist_entries(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->ignored_gpu_blocklist_entries)::BaseType>
        ignored_gpu_blocklist_entries_fragment(fragment.message());
    constexpr const mojo::internal::ContainerValidateParams& ignored_gpu_blocklist_entries_validate_params =
        mojo::internal::GetArrayValidator<0, false, nullptr>();
    
    mojo::internal::Serialize<mojo::ArrayDataView<uint32_t>>(
      in_ignored_gpu_blocklist_entries,
      ignored_gpu_blocklist_entries_fragment,
      &ignored_gpu_blocklist_entries_validate_params);

    fragment->ignored_gpu_blocklist_entries.Set(
        ignored_gpu_blocklist_entries_fragment.is_null() ? nullptr : ignored_gpu_blocklist_entries_fragment.data());

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

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

    
    mojo::internal::Serialize<::gpu::mojom::GrContextType>(
      Traits::gr_context_type(input),
      &fragment->gr_context_type);

    decltype(Traits::fallback_gr_context_types(input)) in_fallback_gr_context_types = Traits::fallback_gr_context_types(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->fallback_gr_context_types)::BaseType>
        fallback_gr_context_types_fragment(fragment.message());
    constexpr const mojo::internal::ContainerValidateParams& fallback_gr_context_types_validate_params =
        mojo::internal::GetArrayOfEnumsValidator<0, false, ::gpu::mojom::internal::GrContextType_Data::Validate>();
    
    mojo::internal::Serialize<mojo::ArrayDataView<::gpu::mojom::GrContextType>>(
      in_fallback_gr_context_types,
      fallback_gr_context_types_fragment,
      &fallback_gr_context_types_validate_params);

    fragment->fallback_gr_context_types.Set(
        fallback_gr_context_types_fragment.is_null() ? nullptr : fallback_gr_context_types_fragment.data());

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

    
    mojo::internal::Serialize<::gpu::mojom::VulkanImplementationName>(
      Traits::use_vulkan(input),
      &fragment->use_vulkan);

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

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

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

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

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

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

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

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

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

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

    
    mojo::internal::Serialize<::gpu::mojom::WebGPUAdapterName>(
      Traits::use_webgpu_adapter(input),
      &fragment->use_webgpu_adapter);

    
    mojo::internal::Serialize<::gpu::mojom::WebGPUPowerPreference>(
      Traits::use_webgpu_power_preference(input),
      &fragment->use_webgpu_power_preference);

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

    
    mojo::internal::Serialize<::gpu::mojom::DawnBackendValidationLevel>(
      Traits::enable_dawn_backend_validation(input),
      &fragment->enable_dawn_backend_validation);

    decltype(Traits::enabled_dawn_features_list(input)) in_enabled_dawn_features_list = Traits::enabled_dawn_features_list(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->enabled_dawn_features_list)::BaseType>
        enabled_dawn_features_list_fragment(fragment.message());
    constexpr const mojo::internal::ContainerValidateParams& enabled_dawn_features_list_validate_params =
        mojo::internal::GetArrayValidator<0, false, &mojo::internal::GetArrayValidator<0, false, nullptr>()>();
    
    mojo::internal::Serialize<mojo::ArrayDataView<mojo::StringDataView>>(
      in_enabled_dawn_features_list,
      enabled_dawn_features_list_fragment,
      &enabled_dawn_features_list_validate_params);

    fragment->enabled_dawn_features_list.Set(
        enabled_dawn_features_list_fragment.is_null() ? nullptr : enabled_dawn_features_list_fragment.data());

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

    decltype(Traits::disabled_dawn_features_list(input)) in_disabled_dawn_features_list = Traits::disabled_dawn_features_list(input);
    mojo::internal::MessageFragment<
        typename decltype(fragment->disabled_dawn_features_list)::BaseType>
        disabled_dawn_features_list_fragment(fragment.message());
    constexpr const mojo::internal::ContainerValidateParams& disabled_dawn_features_list_validate_params =
        mojo::internal::GetArrayValidator<0, false, &mojo::internal::GetArrayValidator<0, false, nullptr>()>();
    
    mojo::internal::Serialize<mojo::ArrayDataView<mojo::StringDataView>>(
      in_disabled_dawn_features_list,
      disabled_dawn_features_list_fragment,
      &disabled_dawn_features_list_validate_params);

    fragment->disabled_dawn_features_list.Set(
        disabled_dawn_features_list_fragment.is_null() ? nullptr : disabled_dawn_features_list_fragment.data());

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

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

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

    fragment->force_separate_egl_display_for_webgl_testing = Traits::force_separate_egl_display_for_webgl_testing(input);
  }

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

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

}  // namespace internal

}  // namespace mojo


namespace gpu::mojom {

inline void GpuPreferencesDataView::GetIgnoredGpuBlocklistEntriesDataView(
    mojo::ArrayDataView<uint32_t>* output) {
  auto pointer = data_->ignored_gpu_blocklist_entries.Get();
  *output = mojo::ArrayDataView<uint32_t>(pointer, message_);
}
inline void GpuPreferencesDataView::GetFallbackGrContextTypesDataView(
    mojo::ArrayDataView<GrContextType>* output) {
  auto pointer = data_->fallback_gr_context_types.Get();
  *output = mojo::ArrayDataView<GrContextType>(pointer, message_);
}
inline void GpuPreferencesDataView::GetEnabledDawnFeaturesListDataView(
    mojo::ArrayDataView<mojo::StringDataView>* output) {
  auto pointer = data_->enabled_dawn_features_list.Get();
  *output = mojo::ArrayDataView<mojo::StringDataView>(pointer, message_);
}
inline void GpuPreferencesDataView::GetDisabledDawnFeaturesListDataView(
    mojo::ArrayDataView<mojo::StringDataView>* output) {
  auto pointer = data_->disabled_dawn_features_list.Get();
  *output = mojo::ArrayDataView<mojo::StringDataView>(pointer, message_);
}



}  // gpu::mojom

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

namespace perfetto {

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

} // namespace perfetto

namespace perfetto {

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

} // namespace perfetto

namespace perfetto {

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

} // namespace perfetto

namespace perfetto {

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

} // namespace perfetto

namespace perfetto {

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

} // namespace perfetto

#endif  // GPU_IPC_COMMON_GPU_PREFERENCES_MOJOM_SHARED_H_