chromium/components/viz/common/resources/shared_image_format.h

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_VIZ_COMMON_RESOURCES_SHARED_IMAGE_FORMAT_H_
#define COMPONENTS_VIZ_COMMON_RESOURCES_SHARED_IMAGE_FORMAT_H_

#include <stdint.h>

#include <compare>
#include <optional>
#include <string>

#include "base/check.h"
#include "base/component_export.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "mojo/public/cpp/bindings/union_traits.h"
#include "services/viz/public/mojom/compositing/internal/singleplanar_format.mojom.h"
#include "ui/gfx/geometry/size.h"

namespace viz {

class LegacyMultiPlaneFormat;
class SinglePlaneFormat;

namespace mojom {
class SharedImageFormatDataView;
class MultiplanarFormatDataView;
}  // namespace mojom

// This class represents the image format used by SharedImages for single plane
// images (eg. RGBA) or multiplanar images (eg. NV12). This format can be
// either SingleplanarFormat or MultiplanarFormat (PlaneConfig + Subsampling +
// ChannelFormat).
class COMPONENT_EXPORT(VIZ_SHARED_IMAGE_FORMAT) SharedImageFormat final {};

// Constants for common single-planar formats.
// NOTE: This is a class rather than a namespace so that SharedImageFormat can
// friend it to give it access to the private constructor needed for creating
// these constants.
class SinglePlaneFormat {};

// Constants for legacy single-plane representations of multiplanar formats.
// NOTE: This is a class rather than a namespace so that SharedImageFormat can
// friend it to give it access to the private constructor needed for creating
// these constants.
// TODO(crbug.com/40239769): Eliminate these once the codebase is completely
// converted to using MultiplanarSharedImage.
class LegacyMultiPlaneFormat {};

// Constants for common multi-planar formats.
namespace MultiPlaneFormat {
inline constexpr SharedImageFormat kYV12 =;
inline constexpr SharedImageFormat kNV12 =;
inline constexpr SharedImageFormat kNV12A =;
inline constexpr SharedImageFormat kP010 =;
// NOTE: These formats do not have an equivalent BufferFormat as they are not
// used with GpuMemoryBuffers.
inline constexpr SharedImageFormat kNV16 =;
inline constexpr SharedImageFormat kNV24 =;
inline constexpr SharedImageFormat kP210 =;
inline constexpr SharedImageFormat kP410 =;
inline constexpr SharedImageFormat kI420 =;
inline constexpr SharedImageFormat kI420A =;
}  // namespace MultiPlaneFormat

}  // namespace viz

#endif  // COMPONENTS_VIZ_COMMON_RESOURCES_SHARED_IMAGE_FORMAT_H_