| // camera/mojo/gpu/dmabuf.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 "camera/mojo/gpu/dmabuf.mojom-shared.h" |
| |
| // Used to support stream output operator for enums. |
| // TODO(dcheng): Consider omitting this somehow if not needed. |
| #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 "camera/mojo/gpu/dmabuf.mojom-params-data.h" |
| namespace cros { |
| namespace mojom { |
| |
| NOINLINE static const char* VideoPixelFormatToStringHelper(VideoPixelFormat value) { |
| // Defined in a helper function to ensure that Clang generates a lookup table. |
| switch(value) { |
| case VideoPixelFormat::PIXEL_FORMAT_UNKNOWN: |
| return "PIXEL_FORMAT_UNKNOWN"; |
| case VideoPixelFormat::PIXEL_FORMAT_I420: |
| return "PIXEL_FORMAT_I420"; |
| case VideoPixelFormat::PIXEL_FORMAT_NV12: |
| return "PIXEL_FORMAT_NV12"; |
| default: |
| return nullptr; |
| } |
| } |
| |
| std::string VideoPixelFormatToString(VideoPixelFormat value) { |
| const char *str = VideoPixelFormatToStringHelper(value); |
| if (!str) { |
| return base::StringPrintf("Unknown VideoPixelFormat value: %i", static_cast<int32_t>(value)); |
| } |
| return str; |
| } |
| |
| std::ostream& operator<<(std::ostream& os, VideoPixelFormat value) { |
| return os << VideoPixelFormatToString(value); |
| } |
| |
| namespace internal { |
| |
| |
| // static |
| bool DmaBufPlane_Data::Validate( |
| const void* data, |
| mojo::internal::ValidationContext* validation_context) { |
| if (!data) |
| return true; |
| if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory( |
| data, 24, 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 DmaBufPlane_Data* object = |
| static_cast<const DmaBufPlane_Data*>(data); |
| |
| if (!mojo::internal::ValidateHandleOrInterfaceNonNullable( |
| object->fd_handle, 1, validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateHandleOrInterface(object->fd_handle, |
| validation_context)) { |
| return false; |
| } |
| |
| return true; |
| } |
| |
| DmaBufPlane_Data::DmaBufPlane_Data() |
| : header_({sizeof(*this), 0}) {} |
| |
| |
| // static |
| bool DmaBufVideoFrame_Data::Validate( |
| const void* data, |
| mojo::internal::ValidationContext* validation_context) { |
| if (!data) |
| return true; |
| static constexpr mojo::internal::StructVersionSize kVersionSizes[] = { |
| { 0, 32 }, |
| { 1, 40 }, |
| }; |
| if (!ValidateStructHeaderAndVersionSizeAndClaimMemory( |
| data, kVersionSizes, 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 DmaBufVideoFrame_Data* object = |
| static_cast<const DmaBufVideoFrame_Data*>(data); |
| |
| |
| if (!::cros::mojom::internal::VideoPixelFormat_Data |
| ::Validate(object->format, validation_context)) |
| return false; |
| |
| if (!mojo::internal::ValidatePointerNonNullable( |
| object->planes, 4, validation_context)) { |
| return false; |
| } |
| constexpr const mojo::internal::ContainerValidateParams& planes_validate_params = |
| mojo::internal::GetArrayValidator<0, false, nullptr>(); |
| if (!mojo::internal::ValidateContainer(object->planes, validation_context, |
| &planes_validate_params)) { |
| return false; |
| } |
| |
| return true; |
| } |
| |
| DmaBufVideoFrame_Data::DmaBufVideoFrame_Data() |
| : header_({sizeof(*this), 1}) {} |
| |
| } // namespace internal |
| } // namespace mojom |
| } // namespace cros |
| |
| namespace perfetto { |
| |
| // static |
| void TraceFormatTraits<::cros::mojom::VideoPixelFormat>::WriteIntoTrace( |
| perfetto::TracedValue context, ::cros::mojom::VideoPixelFormat value) { |
| return std::move(context).WriteString(::cros::mojom::VideoPixelFormatToString(value)); |
| } |
| |
| } // namespace perfetto |