blob: 114bf3b48df533f24264b9a7ffc83b74dfa30abf [file] [log] [blame]
// camera/mojo/gpu/dmabuf.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 CAMERA_MOJO_GPU_DMABUF_MOJOM_SHARED_H_
#define CAMERA_MOJO_GPU_DMABUF_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/enum_traits.h"
#include "mojo/public/cpp/bindings/interface_data_view.h"
#include "mojo/public/cpp/bindings/lib/bindings_internal.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"
#include "mojo/public/cpp/bindings/map_data_view.h"
#include "mojo/public/cpp/bindings/string_data_view.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"
#include "camera/mojo/gpu/dmabuf.mojom-shared-internal.h"
#include "mojo/public/cpp/bindings/lib/interface_serialization.h"
#include "mojo/public/cpp/system/data_pipe.h"
namespace cros::mojom {
class DmaBufPlaneDataView;
class DmaBufVideoFrameDataView;
} // cros::mojom
namespace mojo {
namespace internal {
template <>
struct MojomTypeTraits<::cros::mojom::DmaBufPlaneDataView> {
using Data = ::cros::mojom::internal::DmaBufPlane_Data;
using DataAsArrayElement = Pointer<Data>;
static constexpr MojomTypeCategory category = MojomTypeCategory::kStruct;
};
template <>
struct MojomTypeTraits<::cros::mojom::DmaBufVideoFrameDataView> {
using Data = ::cros::mojom::internal::DmaBufVideoFrame_Data;
using DataAsArrayElement = Pointer<Data>;
static constexpr MojomTypeCategory category = MojomTypeCategory::kStruct;
};
} // namespace internal
} // namespace mojo
namespace cros::mojom {
enum class VideoPixelFormat : int32_t {
PIXEL_FORMAT_UNKNOWN = 0,
PIXEL_FORMAT_I420 = 1,
PIXEL_FORMAT_NV12 = 6,
kMinValue = 0,
kMaxValue = 6,
};
std::ostream& operator<<(std::ostream& os, VideoPixelFormat value);
inline bool IsKnownEnumValue(VideoPixelFormat value) {
return internal::VideoPixelFormat_Data::IsKnownValue(
static_cast<int32_t>(value));
}
class DmaBufPlaneDataView {
public:
DmaBufPlaneDataView() = default;
DmaBufPlaneDataView(
internal::DmaBufPlane_Data* data,
mojo::Message* message)
: data_(data), message_(message) {}
bool is_null() const { return !data_; }
mojo::ScopedHandle TakeFdHandle() {
mojo::ScopedHandle result;
bool ret =
mojo::internal::Deserialize<mojo::ScopedHandle>(
&data_->fd_handle, &result, message_);
DCHECK(ret);
return result;
}
int32_t stride() const {
return data_->stride;
}
uint32_t offset() const {
return data_->offset;
}
uint32_t size() const {
return data_->size;
}
private:
internal::DmaBufPlane_Data* data_ = nullptr;
mojo::Message* message_ = nullptr;
};
class DmaBufVideoFrameDataView {
public:
DmaBufVideoFrameDataView() = default;
DmaBufVideoFrameDataView(
internal::DmaBufVideoFrame_Data* data,
mojo::Message* message)
: data_(data), message_(message) {}
bool is_null() const { return !data_; }
template <typename UserType>
[[nodiscard]] bool ReadFormat(UserType* output) const {
auto data_value = data_->format;
return mojo::internal::Deserialize<::cros::mojom::VideoPixelFormat>(
data_value, output);
}
VideoPixelFormat format() const {
return ::mojo::internal::ToKnownEnumValueHelper(
static_cast<::cros::mojom::VideoPixelFormat>(data_->format));
}
uint32_t coded_width() const {
return data_->coded_width;
}
uint32_t coded_height() const {
return data_->coded_height;
}
inline void GetPlanesDataView(
mojo::ArrayDataView<DmaBufPlaneDataView>* output);
template <typename UserType>
[[nodiscard]] bool ReadPlanes(UserType* output) {
auto* pointer = data_->planes.Get();
return mojo::internal::Deserialize<mojo::ArrayDataView<::cros::mojom::DmaBufPlaneDataView>>(
pointer, output, message_);
}
bool has_modifier() const {
if (data_->header_.version < 1)
return bool{};
return data_->has_modifier;
}
uint64_t modifier() const {
if (data_->header_.version < 1)
return uint64_t{};
return data_->modifier;
}
private:
internal::DmaBufVideoFrame_Data* data_ = nullptr;
mojo::Message* message_ = nullptr;
};
} // cros::mojom
namespace std {
template <>
struct hash<::cros::mojom::VideoPixelFormat>
: public mojo::internal::EnumHashImpl<::cros::mojom::VideoPixelFormat> {};
} // namespace std
namespace mojo {
namespace internal {
template <typename MaybeConstUserType>
struct Serializer<::cros::mojom::VideoPixelFormat, MaybeConstUserType> {
using UserType = typename std::remove_const<MaybeConstUserType>::type;
using Traits = EnumTraits<::cros::mojom::VideoPixelFormat, 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) {
return Traits::FromMojom(::mojo::internal::ToKnownEnumValueHelper(
static_cast<::cros::mojom::VideoPixelFormat>(input)), output);
}
};
} // namespace internal
namespace internal {
template <typename MaybeConstUserType>
struct Serializer<::cros::mojom::DmaBufPlaneDataView, MaybeConstUserType> {
using UserType = typename std::remove_const<MaybeConstUserType>::type;
using Traits = StructTraits<::cros::mojom::DmaBufPlaneDataView, UserType>;
static void Serialize(
MaybeConstUserType& input,
mojo::internal::MessageFragment<::cros::mojom::internal::DmaBufPlane_Data>& fragment) {
if (CallIsNullIfExists<Traits>(input))
return;
fragment.Allocate();
decltype(Traits::fd_handle(input)) in_fd_handle = Traits::fd_handle(input);
mojo::internal::Serialize<mojo::ScopedHandle>(
in_fd_handle, &fragment->fd_handle, &fragment.message());
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
!mojo::internal::IsHandleOrInterfaceValid(fragment->fd_handle),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
"invalid fd_handle in DmaBufPlane struct");
fragment->stride = Traits::stride(input);
fragment->offset = Traits::offset(input);
fragment->size = Traits::size(input);
}
static bool Deserialize(::cros::mojom::internal::DmaBufPlane_Data* input,
UserType* output,
Message* message) {
if (!input)
return CallSetToNullIfExists<Traits>(output);
::cros::mojom::DmaBufPlaneDataView data_view(input, message);
return Traits::Read(data_view, output);
}
};
} // namespace internal
namespace internal {
template <typename MaybeConstUserType>
struct Serializer<::cros::mojom::DmaBufVideoFrameDataView, MaybeConstUserType> {
using UserType = typename std::remove_const<MaybeConstUserType>::type;
using Traits = StructTraits<::cros::mojom::DmaBufVideoFrameDataView, UserType>;
static void Serialize(
MaybeConstUserType& input,
mojo::internal::MessageFragment<::cros::mojom::internal::DmaBufVideoFrame_Data>& fragment) {
if (CallIsNullIfExists<Traits>(input))
return;
fragment.Allocate();
mojo::internal::Serialize<::cros::mojom::VideoPixelFormat>(
Traits::format(input), &fragment->format);
fragment->coded_width = Traits::coded_width(input);
fragment->coded_height = Traits::coded_height(input);
decltype(Traits::planes(input)) in_planes = Traits::planes(input);
mojo::internal::MessageFragment<
typename decltype(fragment->planes)::BaseType>
planes_fragment(fragment.message());
constexpr const mojo::internal::ContainerValidateParams& planes_validate_params =
mojo::internal::GetArrayValidator<0, false, nullptr>();
mojo::internal::Serialize<mojo::ArrayDataView<::cros::mojom::DmaBufPlaneDataView>>(
in_planes, planes_fragment, &planes_validate_params);
fragment->planes.Set(
planes_fragment.is_null() ? nullptr : planes_fragment.data());
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
fragment->planes.is_null(),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
"null planes in DmaBufVideoFrame struct");
fragment->has_modifier = Traits::has_modifier(input);
fragment->modifier = Traits::modifier(input);
}
static bool Deserialize(::cros::mojom::internal::DmaBufVideoFrame_Data* input,
UserType* output,
Message* message) {
if (!input)
return CallSetToNullIfExists<Traits>(output);
::cros::mojom::DmaBufVideoFrameDataView data_view(input, message);
return Traits::Read(data_view, output);
}
};
} // namespace internal
} // namespace mojo
namespace cros::mojom {
inline void DmaBufVideoFrameDataView::GetPlanesDataView(
mojo::ArrayDataView<DmaBufPlaneDataView>* output) {
auto pointer = data_->planes.Get();
*output = mojo::ArrayDataView<DmaBufPlaneDataView>(pointer, message_);
}
} // cros::mojom
// Declare TraceFormatTraits for enums, which should be defined in ::perfetto
// namespace.
namespace perfetto {
template <>
struct TraceFormatTraits<::cros::mojom::VideoPixelFormat> {
static void WriteIntoTrace(perfetto::TracedValue context, ::cros::mojom::VideoPixelFormat value);
};
} // namespace perfetto
#endif // CAMERA_MOJO_GPU_DMABUF_MOJOM_SHARED_H_