// services/viz/public/mojom/compositing/copy_output_result.mojom-shared.cc 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.

#include "services/viz/public/mojom/compositing/copy_output_result.mojom-shared.h"
#include <ostream>
#include <utility>
#include "base/strings/stringprintf.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/bindings/lib/validation_util.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"

#include "services/viz/public/mojom/compositing/copy_output_result.mojom-params-data.h"
namespace viz {
namespace mojom {

NOINLINE static const char* CopyOutputResultFormatToStringHelper(CopyOutputResultFormat value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case CopyOutputResultFormat::RGBA:
      return "RGBA";
    default:
      return nullptr;
  }
}

std::string CopyOutputResultFormatToString(CopyOutputResultFormat value) {
  const char *str = CopyOutputResultFormatToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown CopyOutputResultFormat value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, CopyOutputResultFormat value) {
  return os << CopyOutputResultFormatToString(value);
}

NOINLINE static const char* CopyOutputResultDestinationToStringHelper(CopyOutputResultDestination value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case CopyOutputResultDestination::kSystemMemory:
      return "kSystemMemory";
    case CopyOutputResultDestination::kSharedImage:
      return "kSharedImage";
    default:
      return nullptr;
  }
}

std::string CopyOutputResultDestinationToString(CopyOutputResultDestination value) {
  const char *str = CopyOutputResultDestinationToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown CopyOutputResultDestination value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, CopyOutputResultDestination value) {
  return os << CopyOutputResultDestinationToString(value);
}

NOINLINE static const char* CopyOutputResultErrorToStringHelper(CopyOutputResultError value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case CopyOutputResultError::kNone:
      return "kNone";
    case CopyOutputResultError::kUnknown:
      return "kUnknown";
    case CopyOutputResultError::kTimeout:
      return "kTimeout";
    case CopyOutputResultError::kEmbeddingTokenChanged:
      return "kEmbeddingTokenChanged";
    default:
      return nullptr;
  }
}

std::string CopyOutputResultErrorToString(CopyOutputResultError value) {
  const char *str = CopyOutputResultErrorToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown CopyOutputResultError value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, CopyOutputResultError value) {
  return os << CopyOutputResultErrorToString(value);
}

namespace internal {


// static
bool CopyOutputResult_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 72, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const CopyOutputResult_Data* object =
      static_cast<const CopyOutputResult_Data*>(data);


  if (!::viz::mojom::internal::CopyOutputResultFormat_Data
        ::Validate(object->format, validation_context))
    return false;


  if (!::viz::mojom::internal::CopyOutputResultDestination_Data
        ::Validate(object->destination, validation_context))
    return false;

  if (!mojo::internal::ValidatePointerNonNullable(
          object->rect, 3, validation_context)) {
    return false;
  }
  if (!mojo::internal::ValidateStruct(object->rect, validation_context))
    return false;

  if (!mojo::internal::ValidateStruct(object->bitmap, validation_context))
    return false;

  if (!mojo::internal::ValidateStruct(object->mailbox, validation_context))
    return false;

  if (!mojo::internal::ValidateStruct(object->color_space, validation_context))
    return false;

  if (!mojo::internal::ValidateHandleOrInterface(object->releaser,
                                                 validation_context)) {
    return false;
  }

  if (!mojo::internal::ValidatePointerNonNullable(
          object->tracked_element_rects, 8, validation_context)) {
    return false;
  }
  if (!mojo::internal::ValidateStruct(object->tracked_element_rects, validation_context))
    return false;


  if (!::viz::mojom::internal::CopyOutputResultError_Data
        ::Validate(object->error, validation_context))
    return false;

  return true;
}

CopyOutputResult_Data::CopyOutputResult_Data()
    : header_({sizeof(*this), 0}) {}

}  // namespace internal
}  // namespace mojom
}  // namespace viz

namespace perfetto {

// static
void TraceFormatTraits<::viz::mojom::CopyOutputResultFormat>::WriteIntoTrace(
   perfetto::TracedValue context, ::viz::mojom::CopyOutputResultFormat value) {
  return std::move(context).WriteString(::viz::mojom::CopyOutputResultFormatToString(value));
}

} // namespace perfetto

namespace perfetto {

// static
void TraceFormatTraits<::viz::mojom::CopyOutputResultDestination>::WriteIntoTrace(
   perfetto::TracedValue context, ::viz::mojom::CopyOutputResultDestination value) {
  return std::move(context).WriteString(::viz::mojom::CopyOutputResultDestinationToString(value));
}

} // namespace perfetto

namespace perfetto {

// static
void TraceFormatTraits<::viz::mojom::CopyOutputResultError>::WriteIntoTrace(
   perfetto::TracedValue context, ::viz::mojom::CopyOutputResultError value) {
  return std::move(context).WriteString(::viz::mojom::CopyOutputResultErrorToString(value));
}

} // namespace perfetto