chromium/gpu/command_buffer/service/shared_image/shared_image_format_service_utils.cc

// 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.

#include "gpu/command_buffer/service/shared_image/shared_image_format_service_utils.h"

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES3/gl3.h>

#include "base/check.h"
#include "base/check_op.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "build/buildflag.h"
#include "components/crash/core/common/crash_key.h"
#include "components/viz/common/resources/shared_image_format_utils.h"
#include "gpu/command_buffer/service/feature_info.h"
#include "gpu/ipc/common/vulkan_ycbcr_info.h"
#include "ui/gl/gl_version_info.h"

#if BUILDFLAG(SKIA_USE_DAWN)
#include "third_party/skia/include/gpu/graphite/dawn/DawnTypes.h"
#endif

namespace gpu {

PlaneConfig;
ChannelFormat;
Subsampling;

namespace {

#if BUILDFLAG(ENABLE_VULKAN)
VkFormat ToVkFormatSinglePlanarInternal(viz::SharedImageFormat format) {}
#endif

// Returns GL data format for given `format`.
GLenum GLDataFormat(viz::SharedImageFormat format, int plane_index) {}

// Returns GL data type for given `format`.
GLenum GLDataType(viz::SharedImageFormat format) {}

// Returns the GL format used internally for matching with the texture format
// for a given `format`.
GLenum GLInternalFormat(viz::SharedImageFormat format, int plane_index) {}

}  // namespace

// Wraps functions from shared_image_format_utils.h that are made private with
// friending to prevent their existing client-side usage (which is an
// anti-pattern) from growing within a class that
// SharedImageFormatRestrictedUtils can friend. (Note that if
// SharedImageFormatRestrictedUtils instead directly friended the
// service-side calling functions, any client-side code could then also
// directly call those service-side calling functions as well, defeating the
// purpose).
class SharedImageFormatRestrictedUtilsAccessor {};

// This class method is primarily meant to be accessed by gpu service side code
// with the exception of some client needing access temporarily until the
// BufferFormat usage is deprecated. This requires usage of below wrapper class
// to access this method from service side code conveniently.
class GPU_GLES2_EXPORT SharedImageFormatToBufferFormatRestrictedUtilsAccessor {};

gfx::BufferFormat ToBufferFormat(viz::SharedImageFormat format) {}

SkYUVAInfo::PlaneConfig ToSkYUVAPlaneConfig(viz::SharedImageFormat format) {}

SkYUVAInfo::Subsampling ToSkYUVASubsampling(viz::SharedImageFormat format) {}

SkColorType ToClosestSkColorTypeExternalSampler(viz::SharedImageFormat format) {}

GLFormatCaps::GLFormatCaps(const gles2::FeatureInfo* feature_info)
    :{}

GLFormatDesc GLFormatCaps::ToGLFormatDescExternalSampler(
    viz::SharedImageFormat format) const {}

GLFormatDesc GLFormatCaps::ToGLFormatDesc(viz::SharedImageFormat format,
                                          int plane_index) const {}

GLFormatDesc GLFormatCaps::ToGLFormatDescOverrideHalfFloatType(
    viz::SharedImageFormat format,
    int plane_index) const {}

GLenum GLFormatCaps::GetFallbackFormatIfNotSupported(GLenum gl_format) const {}

#if BUILDFLAG(ENABLE_VULKAN)
bool HasVkFormat(viz::SharedImageFormat format) {}

VkFormat ToVkFormatExternalSampler(viz::SharedImageFormat format) {}

VkFormat ToVkFormatSinglePlanar(viz::SharedImageFormat format) {}

VkFormat ToVkFormat(viz::SharedImageFormat format, int plane_index) {}
#endif

wgpu::TextureFormat ToDawnFormat(viz::SharedImageFormat format) {}

wgpu::TextureFormat ToDawnTextureViewFormat(viz::SharedImageFormat format,
                                            int plane_index) {}

wgpu::TextureUsage SupportedDawnTextureUsage(
    viz::SharedImageFormat format,
    bool is_yuv_plane,
    bool is_dcomp_surface,
    bool supports_multiplanar_rendering,
    bool supports_multiplanar_copy) {}

wgpu::TextureAspect ToDawnTextureAspect(bool is_yuv_plane, int plane_index) {}

skgpu::graphite::TextureInfo GraphiteBackendTextureInfo(
    GrContextType gr_context_type,
    viz::SharedImageFormat format,
    bool readonly,
    int plane_index,
    bool is_yuv_plane,
    bool mipmapped,
    bool scanout_dcomp_surface,
    bool supports_multiplanar_rendering,
    bool supports_multiplanar_copy) {}

skgpu::graphite::TextureInfo GraphitePromiseTextureInfo(
    GrContextType gr_context_type,
    viz::SharedImageFormat format,
    std::optional<VulkanYCbCrInfo> ycbcr_info,
    int plane_index,
    bool mipmapped) {}

#if BUILDFLAG(SKIA_USE_DAWN)
skgpu::graphite::DawnTextureInfo DawnBackendTextureInfo(
    viz::SharedImageFormat format,
    bool readonly,
    bool is_yuv_plane,
    int plane_index,
    int array_slice,
    bool mipmapped,
    bool scanout_dcomp_surface,
    bool supports_multiplanar_rendering,
    bool supports_multiplanar_copy) {}
#endif

skgpu::graphite::TextureInfo FallbackGraphiteBackendTextureInfo(
    const skgpu::graphite::TextureInfo& texture_info) {}

}  // namespace gpu