chromium/components/viz/common/quads/render_pass_io.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/viz/common/quads/render_pass_io.h"

#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include "base/base64.h"
#include "base/bit_cast.h"
#include "base/containers/span.h"
#include "base/json/values_util.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_tokenizer.h"
#include "base/values.h"
#include "cc/paint/paint_op_reader.h"
#include "cc/paint/paint_op_writer.h"
#include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/quads/compositor_render_pass.h"
#include "components/viz/common/quads/compositor_render_pass_draw_quad.h"
#include "components/viz/common/quads/picture_draw_quad.h"
#include "components/viz/common/quads/solid_color_draw_quad.h"
#include "components/viz/common/quads/surface_draw_quad.h"
#include "components/viz/common/quads/texture_draw_quad.h"
#include "components/viz/common/quads/tile_draw_quad.h"
#include "components/viz/common/quads/video_hole_draw_quad.h"
#include "components/viz/common/quads/yuv_video_draw_quad.h"
#include "third_party/skia/modules/skcms/skcms.h"
#include "ui/gfx/geometry/rect_conversions.h"

namespace gfx {
struct HDRMetadata;
}

namespace viz {

namespace {

enum RenderPassField {};

// This controls which fields are processed in CompositorRenderPassToDict() and
// CompositorRenderPassFromDict().
// Values other than kAllFields should never be checked in. This is only for
// local debugging convenience.
RenderPassField g_render_pass_fields =;

bool ProcessRenderPassField(RenderPassField field) {}

base::Value::Dict RectToDict(const gfx::Rect& rect) {}

bool RectFromDict(const base::Value::Dict& dict, gfx::Rect* rect) {}

base::Value::Dict RectFToDict(const gfx::RectF& rect) {}

bool RectFFromDict(const base::Value::Dict& dict, gfx::RectF* rect) {}

base::Value::Dict SizeToDict(const gfx::Size& size) {}

bool SizeFromDict(const base::Value::Dict& dict, gfx::Size* size) {}

base::Value::Dict PointToDict(const gfx::Point& point) {}

bool PointFromDict(const base::Value::Dict& dict, gfx::Point* point) {}

base::Value::Dict SkColor4fToDict(const SkColor4f color) {}

bool SkColor4fFromDict(const base::Value::Dict& dict, SkColor4f* color) {}

// Many quads now store color as an SkColor4f, but older logs will still store
// SkColors (which are ints). For backward compatibility's sake, read either.
bool ColorFromDict(const base::Value::Dict& dict,
                   std::string_view key,
                   SkColor4f* output_color) {}

base::Value::Dict PointFToDict(const gfx::PointF& point) {}

bool PointFFromDict(const base::Value::Dict& dict, gfx::PointF* point) {}

base::Value::Dict Vector2dFToDict(const gfx::Vector2dF& v) {}

bool Vector2dFFromDict(const base::Value::Dict& dict, gfx::Vector2dF* v) {}

base::Value::List FloatArrayToList(base::span<const float> data) {}

bool FloatArrayFromList(const base::Value::List& list,
                        size_t expected_count,
                        float* data) {}

#define MAP_RRECTF_TYPE_TO_STRING
const char* RRectFTypeToString(gfx::RRectF::Type type) {}
#undef MAP_RRECTF_TYPE_TO_STRING

#define MAP_STRING_TO_RRECTF_TYPE
int StringToRRectFType(const std::string& str) {}
#undef MAP_STRING_TO_RRECTF_TYPE

base::Value::Dict RRectFToDict(const gfx::RRectF& rect) {}

bool RRectFFromDict(const base::Value::Dict& dict, gfx::RRectF* out) {}

base::Value::Dict LinearGradientToDict(
    const gfx::LinearGradient& gradient_mask) {}

bool LinearGradientFromDict(const base::Value::Dict& dict,
                            gfx::LinearGradient* out) {}

base::Value::Dict MaskFilterInfoToDict(
    const gfx::MaskFilterInfo& mask_filter_info) {}

bool MaskFilterInfoFromDict(const base::Value::Dict& dict,
                            gfx::MaskFilterInfo* out) {}

base::Value::List TransformToList(const gfx::Transform& transform) {}

bool TransformFromList(const base::Value::List& list,
                       gfx::Transform* transform) {}

base::Value::List ShapeRectsToList(
    const cc::FilterOperation::ShapeRects& shape) {}

bool ShapeRectsFromList(const base::Value::List& list,
                        cc::FilterOperation::ShapeRects* shape) {}

std::string PaintFilterToString(const sk_sp<cc::PaintFilter>& filter) {}

sk_sp<cc::PaintFilter> PaintFilterFromString(const std::string& encoded) {}

base::Value::Dict FilterOperationToDict(const cc::FilterOperation& filter) {}

bool FilterOperationFromDict(const base::Value& dict_value,
                             cc::FilterOperation* out) {}

base::Value::List FilterOperationsToList(const cc::FilterOperations& filters) {}

bool FilterOperationsFromList(const base::Value::List& list,
                              cc::FilterOperations* filters) {}

#define MATCH_ENUM_CASE

const char* ColorSpacePrimaryIdToString(gfx::ColorSpace::PrimaryID id) {}

const char* ColorSpaceTransferIdToString(gfx::ColorSpace::TransferID id) {}

const char* ColorSpaceMatrixIdToString(gfx::ColorSpace::MatrixID id) {}

const char* ColorSpaceRangeIdToString(gfx::ColorSpace::RangeID id) {}
#undef MATCH_ENUM_CASE

#define MATCH_ENUM_CASE

uint8_t StringToColorSpacePrimaryId(const std::string& token) {}

uint8_t StringToColorSpaceTransferId(const std::string& token) {}

uint8_t StringToColorSpaceMatrixId(const std::string& token) {}

uint8_t StringToColorSpaceRangeId(const std::string& token) {}
#undef MATCH_ENUM_CASE

base::Value::List Matrix3x3ToList(const skcms_Matrix3x3& mat) {}

bool Matrix3x3FromList(const base::Value::List& list, skcms_Matrix3x3* mat) {}

base::Value::List TransferFunctionToList(const skcms_TransferFunction& fn) {}

bool TransferFunctionFromList(const base::Value::List& list,
                              skcms_TransferFunction* fn) {}

base::Value::Dict ColorSpaceToDict(const gfx::ColorSpace& color_space) {}

bool ColorSpaceFromDict(const base::Value::Dict& dict,
                        gfx::ColorSpace* color_space) {}

base::Value::List DrawQuadResourcesToList(
    const DrawQuad::Resources& resources) {}

bool DrawQuadResourcesFromList(const base::Value::List& list,
                               DrawQuad::Resources* resources) {}

base::Value::Dict SurfaceIdToDict(const SurfaceId& id) {}

std::optional<SurfaceId> SurfaceIdFromDict(const base::Value::Dict& dict) {}

base::Value::Dict SurfaceRangeToDict(const SurfaceRange& range) {}

std::optional<SurfaceRange> SurfaceRangeFromDict(
    const base::Value::Dict& dict) {}

int GetSharedQuadStateIndex(const SharedQuadStateList& shared_quad_state_list,
                            const SharedQuadState* shared_quad_state) {}

#define MAP_STRING_TO_MATERIAL
int StringToDrawQuadMaterial(const std::string& str) {}
#undef MAP_STRING_TO_MATERIAL

void DrawQuadCommonToDict(const DrawQuad* draw_quad,
                          base::Value::Dict* dict,
                          const SharedQuadStateList& shared_quad_state_list) {}

void ContentDrawQuadCommonToDict(const ContentDrawQuadBase* draw_quad,
                                 base::Value::Dict* dict) {}

struct DrawQuadCommon {};

std::optional<DrawQuadCommon> GetDrawQuadCommonFromDict(
    const base::Value::Dict& dict,
    const SharedQuadStateList& shared_quad_state_list) {}

struct ContentDrawQuadCommon {};

std::optional<ContentDrawQuadCommon> GetContentDrawQuadCommonFromDict(
    const base::Value::Dict& dict) {}

void CompositorRenderPassDrawQuadToDict(
    const CompositorRenderPassDrawQuad* draw_quad,
    base::Value::Dict* dict) {}

void SolidColorDrawQuadToDict(const SolidColorDrawQuad* draw_quad,
                              base::Value::Dict* dict) {}

#define MAP_VIDEO_TYPE_TO_STRING
const char* ProtectedVideoTypeToString(gfx::ProtectedVideoType type) {}
#undef MAP_VIDEO_TYPE_TO_STRING

#define MAP_STRING_TO_VIDEO_TYPE
int StringToProtectedVideoType(const std::string& str) {}
#undef MAP_STRING_TO_VIDEO_TYPE

void SurfaceDrawQuadToDict(const SurfaceDrawQuad* draw_quad,
                           base::Value::Dict* dict) {}

void TextureDrawQuadToDict(const TextureDrawQuad* draw_quad,
                           base::Value::Dict* dict) {}

void TileDrawQuadToDict(const TileDrawQuad* draw_quad,
                        base::Value::Dict* dict) {}

void YUVVideoDrawQuadToDict(const YUVVideoDrawQuad* draw_quad,
                            base::Value::Dict* dict) {}

void VideoHoleDrawQuadToDict(const VideoHoleDrawQuad* draw_quad,
                             base::Value::Dict* dict) {}

#define UNEXPECTED_DRAW_QUAD_TYPE
#define WRITE_DRAW_QUAD_TYPE_FIELDS
base::Value::Dict DrawQuadToDict(
    const DrawQuad* draw_quad,
    const SharedQuadStateList& shared_quad_state_list) {}
#undef WRITE_DRAW_QUAD_TYPE_FIELDS
#undef UNEXPECTED_DRAW_QUAD_TYPE

base::Value::List QuadListToList(
    const QuadList& quad_list,
    const SharedQuadStateList& shared_quad_state_list) {}

bool CompositorRenderPassDrawQuadFromDict(
    const base::Value::Dict& dict,
    const DrawQuadCommon& common,
    CompositorRenderPassDrawQuad* draw_quad) {}

bool SolidColorDrawQuadFromDict(const base::Value::Dict& dict,
                                const DrawQuadCommon& common,
                                SolidColorDrawQuad* draw_quad) {}

bool SurfaceDrawQuadFromDict(const base::Value::Dict& dict,
                             const DrawQuadCommon& common,
                             SurfaceDrawQuad* draw_quad) {}

bool TextureDrawQuadFromDict(const base::Value::Dict& dict,
                             const DrawQuadCommon& common,
                             TextureDrawQuad* draw_quad) {}

bool TileDrawQuadFromDict(const base::Value::Dict& dict,
                          const DrawQuadCommon& common,
                          TileDrawQuad* draw_quad) {}

bool YUVVideoDrawQuadFromDict(const base::Value::Dict& dict,
                              const DrawQuadCommon& common,
                              YUVVideoDrawQuad* draw_quad) {}

bool VideoHoleDrawQuadFromDict(const base::Value::Dict& dict,
                               const DrawQuadCommon& common,
                               VideoHoleDrawQuad* draw_quad) {}

#define UNEXPECTED_DRAW_QUAD_TYPE
#define GET_QUAD_FROM_DICT
bool QuadListFromList(const base::Value::List& list,
                      QuadList* quad_list,
                      const SharedQuadStateList& shared_quad_state_list) {}
#undef GET_QUAD_FROM_DICT
#undef UNEXPECTED_DRAW_QUAD_TYPE

base::Value::Dict SharedQuadStateToDict(const SharedQuadState& sqs) {}

#define MAP_STRING_TO_BLEND_MODE
int StringToBlendMode(const std::string& str) {}
#undef MAP_STRING_TO_BLEND_MODE

bool SharedQuadStateFromDict(const base::Value::Dict& dict,
                             SharedQuadState* sqs) {}

base::Value::List SharedQuadStateListToList(
    const SharedQuadStateList& shared_quad_state_list) {}

bool SharedQuadStateListFromList(const base::Value::List& list,
                                 SharedQuadStateList* shared_quad_state_list) {}

base::Value::Dict GetRenderPassMetadata(
    const CompositorRenderPass& render_pass) {}

base::Value::List GetRenderPassListMetadata(
    const CompositorRenderPassList& render_pass_list) {}

}  // namespace

#define MAP_BLEND_MODE_TO_STRING
const char* BlendModeToString(SkBlendMode blend_mode) {}
#undef MAP_BLEND_MODE_TO_STRING

#define MAP_MATERIAL_TO_STRING
const char* DrawQuadMaterialToString(DrawQuad::Material material) {}
#undef MAP_MATERIAL_TO_STRING

base::Value::Dict CompositorRenderPassToDict(
    const CompositorRenderPass& render_pass) {}

std::unique_ptr<CompositorRenderPass> CompositorRenderPassFromDict(
    const base::Value::Dict& dict) {}

base::Value::Dict CompositorRenderPassListToDict(
    const CompositorRenderPassList& render_pass_list) {}

bool CompositorRenderPassListFromDict(
    const base::Value::Dict& dict,
    CompositorRenderPassList* render_pass_list) {}

base::Value::Dict CompositorFrameToDict(
    const CompositorFrame& compositor_frame) {}

bool CompositorFrameFromDict(const base::Value::Dict& dict,
                             CompositorFrame* compositor_frame) {}

base::Value::List FrameDataToList(
    const std::vector<FrameData>& frame_data_list) {}

bool FrameDataFromList(const base::Value::List& list,
                       std::vector<FrameData>* frame_data_list) {}

FrameData::FrameData() = default;
FrameData::FrameData(FrameData&& other) = default;
FrameData& FrameData::operator=(FrameData&& other) = default;

FrameData::FrameData(const SurfaceId& surface_id,
                     const uint64_t frame_index,
                     const CompositorFrame& compositor_frame)
    :{}

}  // namespace viz