chromium/gpu/ipc/common/gpu_info_mojom_traits.h

// 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_INFO_MOJOM_TRAITS_H_
#define GPU_IPC_COMMON_GPU_INFO_MOJOM_TRAITS_H_

#include <optional>

#include "base/time/time.h"
#include "build/build_config.h"
#include "gpu/config/gpu_info.h"
#include "gpu/gpu_export.h"
#include "gpu/ipc/common/gpu_info.mojom.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/mojom/geometry_mojom_traits.h"

#if BUILDFLAG(IS_WIN)
#include "base/win/windows_types.h"
#endif

namespace mojo {

template <>
struct GPU_EXPORT
    StructTraits<gpu::mojom::GpuDeviceDataView, gpu::GPUInfo::GPUDevice> {};

template <>
struct GPU_EXPORT
    EnumTraits<gpu::mojom::VideoCodecProfile, gpu::VideoCodecProfile> {};

template <>
struct GPU_EXPORT
    StructTraits<gpu::mojom::VideoDecodeAcceleratorSupportedProfileDataView,
                 gpu::VideoDecodeAcceleratorSupportedProfile> {};

template <>
struct GPU_EXPORT
    StructTraits<gpu::mojom::VideoDecodeAcceleratorCapabilitiesDataView,
                 gpu::VideoDecodeAcceleratorCapabilities> {};

template <>
struct GPU_EXPORT
    StructTraits<gpu::mojom::VideoEncodeAcceleratorSupportedProfileDataView,
                 gpu::VideoEncodeAcceleratorSupportedProfile> {};

template <>
struct GPU_EXPORT EnumTraits<gpu::mojom::ImageDecodeAcceleratorType,
                             gpu::ImageDecodeAcceleratorType> {};

template <>
struct GPU_EXPORT EnumTraits<gpu::mojom::ImageDecodeAcceleratorSubsampling,
                             gpu::ImageDecodeAcceleratorSubsampling> {};

template <>
struct GPU_EXPORT
    StructTraits<gpu::mojom::ImageDecodeAcceleratorSupportedProfileDataView,
                 gpu::ImageDecodeAcceleratorSupportedProfile> {};

#if BUILDFLAG(IS_WIN)
template <>
struct GPU_EXPORT EnumTraits<gpu::mojom::OverlaySupport, gpu::OverlaySupport> {
  static gpu::mojom::OverlaySupport ToMojom(gpu::OverlaySupport support);
  static bool FromMojom(gpu::mojom::OverlaySupport input,
                        gpu::OverlaySupport* out);
};

template <>
struct GPU_EXPORT
    StructTraits<gpu::mojom::OverlayInfoDataView, gpu::OverlayInfo> {
  static bool Read(gpu::mojom::OverlayInfoDataView data, gpu::OverlayInfo* out);

  static bool direct_composition(const gpu::OverlayInfo& input) {
    return input.direct_composition;
  }

  static bool supports_overlays(const gpu::OverlayInfo& input) {
    return input.supports_overlays;
  }

  static gpu::OverlaySupport yuy2_overlay_support(
      const gpu::OverlayInfo& input) {
    return input.yuy2_overlay_support;
  }

  static gpu::OverlaySupport nv12_overlay_support(
      const gpu::OverlayInfo& input) {
    return input.nv12_overlay_support;
  }

  static gpu::OverlaySupport bgra8_overlay_support(
      const gpu::OverlayInfo& input) {
    return input.bgra8_overlay_support;
  }

  static gpu::OverlaySupport rgb10a2_overlay_support(
      const gpu::OverlayInfo& input) {
    return input.rgb10a2_overlay_support;
  }

  static gpu::OverlaySupport p010_overlay_support(
      const gpu::OverlayInfo& input) {
    return input.p010_overlay_support;
  }
};

#endif

template <>
struct GPU_EXPORT StructTraits<gpu::mojom::GpuInfoDataView, gpu::GPUInfo> {};

}  // namespace mojo
#endif  // GPU_IPC_COMMON_GPU_INFO_MOJOM_TRAITS_H_