// ui/gfx/mojom/ca_layer_params.mojom.cc 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.

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif

#include "ui/gfx/mojom/ca_layer_params.mojom.h"
#include <stdint.h>
#include <utility>
#include "base/notreached.h"
#include "mojo/public/cpp/bindings/lib/default_construct_tag_internal.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/bindings/mojo_buildflags.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"

#include "ui/gfx/mojom/ca_layer_params.mojom-params-data.h"
#include "ui/gfx/mojom/ca_layer_params.mojom-shared-message-ids.h"

#include "ui/gfx/mojom/ca_layer_params.mojom-import-headers.h"
#include "ui/gfx/mojom/ca_layer_params.mojom-test-utils.h"


namespace gfx::mojom {
CAContext::CAContext()
    : id(),
      fence_mach_port() {}

CAContext::CAContext(
    uint32_t id_in,
    ::mojo::PlatformHandle fence_mach_port_in)
    : id(std::move(id_in)),
      fence_mach_port(std::move(fence_mach_port_in)) {}

CAContext::~CAContext() = default;

void CAContext::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "id"), this->id,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type uint32_t>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "fence_mach_port"), this->fence_mach_port,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type ::mojo::PlatformHandle>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool CAContext::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
CALayerParams::CALayerParams()
    : content(),
      pixel_size(),
      scale_factor() {}

CALayerParams::CALayerParams(
    CALayerContentPtr content_in,
    const ::gfx::Size& pixel_size_in,
    float scale_factor_in)
    : content(std::move(content_in)),
      pixel_size(std::move(pixel_size_in)),
      scale_factor(std::move(scale_factor_in)) {}

CALayerParams::~CALayerParams() = default;

void CALayerParams::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "content"), this->content,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type CALayerContentPtr>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "pixel_size"), this->pixel_size,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const ::gfx::Size&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "scale_factor"), this->scale_factor,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type float>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool CALayerParams::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
CALayerContentPtr
CALayerContent::NewCaContext(
    CAContextPtr value) {
  return CALayerContentPtr(
      std::in_place,
      std::in_place_index<static_cast<size_t>(Tag::kCaContext)>,
      std::move(value));
}

CALayerContentPtr
CALayerContent::NewIoSurfaceMachPort(
    ::mojo::PlatformHandle value) {
  return CALayerContentPtr(
      std::in_place,
      std::in_place_index<static_cast<size_t>(Tag::kIoSurfaceMachPort)>,
      std::move(value));
}

CALayerContent::CALayerContent(
    std::in_place_index_t<static_cast<size_t>(Tag::kCaContext)>,
    CAContextPtr value)
    : tag_(Tag::kCaContext),
      data_(std::in_place_index<static_cast<size_t>(Tag::kCaContext)>,
            std::move(value)) {}

CALayerContent::CALayerContent(
    std::in_place_index_t<static_cast<size_t>(Tag::kIoSurfaceMachPort)>,
    ::mojo::PlatformHandle value)
    : tag_(Tag::kIoSurfaceMachPort),
      data_(std::in_place_index<static_cast<size_t>(Tag::kIoSurfaceMachPort)>,
            std::move(value)) {}
CALayerContent::~CALayerContent() {
  DestroyActive();
}

void CALayerContent::set_ca_context(CAContextPtr ca_context) {
  if (tag_ == Tag::kCaContext) {
    data_.ca_context = std::move(ca_context);
  } else {
    DestroyActive();
    tag_ = Tag::kCaContext;
    new (&data_.ca_context) CAContextPtr(
        std::move(ca_context));
  }
}

void CALayerContent::set_io_surface_mach_port(::mojo::PlatformHandle io_surface_mach_port) {
  if (tag_ == Tag::kIoSurfaceMachPort) {
    data_.io_surface_mach_port = std::move(io_surface_mach_port);
  } else {
    DestroyActive();
    tag_ = Tag::kIoSurfaceMachPort;
    new (&data_.io_surface_mach_port) ::mojo::PlatformHandle(
        std::move(io_surface_mach_port));
  }
}


CALayerContent::Union_::Union_(
    std::in_place_index_t<static_cast<size_t>(Tag::kCaContext)>,
    CAContextPtr value)
    : ca_context(std::move(value)) {}

CALayerContent::Union_::Union_(
    std::in_place_index_t<static_cast<size_t>(Tag::kIoSurfaceMachPort)>,
    ::mojo::PlatformHandle value)
    : io_surface_mach_port(std::move(value)) {}

void CALayerContent::DestroyActive() {
  switch (tag_) {

    case Tag::kCaContext:
      std::destroy_at(&data_.ca_context);
      break;
    case Tag::kIoSurfaceMachPort:
      std::destroy_at(&data_.io_surface_mach_port);
      break;
  }
}

bool CALayerContent::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context, false);
}


}  // gfx::mojom


namespace mojo {


// static
bool StructTraits<::gfx::mojom::CAContext::DataView, ::gfx::mojom::CAContextPtr>::Read(
    ::gfx::mojom::CAContext::DataView input,
    ::gfx::mojom::CAContextPtr* output) {
  bool success = true;
  ::gfx::mojom::CAContextPtr result(::gfx::mojom::CAContext::New());
  
      if (success)
        result->id = input.id();
      if (success)
        result->fence_mach_port = input.TakeFenceMachPort();
  *output = std::move(result);
  return success;
}


// static
bool StructTraits<::gfx::mojom::CALayerParams::DataView, ::gfx::mojom::CALayerParamsPtr>::Read(
    ::gfx::mojom::CALayerParams::DataView input,
    ::gfx::mojom::CALayerParamsPtr* output) {
  bool success = true;
  ::gfx::mojom::CALayerParamsPtr result(::gfx::mojom::CALayerParams::New());
  
      if (success && !input.ReadContent(&result->content))
        success = false;
      if (success && !input.ReadPixelSize(&result->pixel_size))
        success = false;
      if (success)
        result->scale_factor = input.scale_factor();
  *output = std::move(result);
  return success;
}

// static
bool UnionTraits<::gfx::mojom::CALayerContent::DataView, ::gfx::mojom::CALayerContentPtr>::Read(
    ::gfx::mojom::CALayerContent::DataView input,
    ::gfx::mojom::CALayerContentPtr* output) {
  using UnionType = ::gfx::mojom::CALayerContent;
  using Tag = UnionType::Tag;

  switch (input.tag()) {
    case Tag::kCaContext: {
      ::gfx::mojom::CAContextPtr result_ca_context{};
      if (!input.ReadCaContext(&result_ca_context))
        return false;

      *output = UnionType::NewCaContext(
          std::move(result_ca_context));
      break;
    }
    case Tag::kIoSurfaceMachPort: {
      *output = UnionType::NewIoSurfaceMachPort(
          input.TakeIoSurfaceMachPort());
      break;
    }
    default:

      return false;
  }
  return true;
}

}  // namespace mojo


// Symbols declared in the -test-utils.h header are defined here instead of a
// separate .cc file to save compile time.


namespace gfx::mojom {




}  // gfx::mojom


#if defined(__clang__)
#pragma clang diagnostic pop
#endif