#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "cc/paint/paint_op_reader.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>
#include "base/bits.h"
#include "base/compiler_specific.h"
#include "base/containers/heap_array.h"
#include "base/debug/dump_without_crashing.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/types/optional_util.h"
#include "cc/base/features.h"
#include "cc/paint/color_filter.h"
#include "cc/paint/draw_looper.h"
#include "cc/paint/image_transfer_cache_entry.h"
#include "cc/paint/paint_cache.h"
#include "cc/paint/paint_flags.h"
#include "cc/paint/paint_image_builder.h"
#include "cc/paint/paint_op_buffer.h"
#include "cc/paint/paint_shader.h"
#include "cc/paint/path_effect.h"
#include "cc/paint/shader_transfer_cache_entry.h"
#include "cc/paint/skottie_transfer_cache_entry.h"
#include "cc/paint/skottie_wrapper.h"
#include "cc/paint/transfer_cache_deserialize_helper.h"
#include "components/crash/core/common/crash_key.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkRRect.h"
#include "third_party/skia/include/core/SkScalar.h"
#include "third_party/skia/include/effects/SkHighContrastFilter.h"
#include "third_party/skia/include/private/SkGainmapInfo.h"
#include "third_party/skia/include/private/chromium/SkChromeRemoteGlyphCache.h"
#include "third_party/skia/include/private/chromium/Slug.h"
#include "ui/gfx/hdr_metadata.h"
#include "ui/gfx/mojom/hdr_metadata.mojom.h"
#include "ui/gfx/mojom/hdr_metadata_mojom_traits.h"
namespace cc {
namespace {
bool IsValidPaintShaderType(PaintShader::Type type) { … }
bool IsValidPaintShaderScalingBehavior(PaintShader::ScalingBehavior behavior) { … }
}
PaintOpReader::PaintOpReader(const volatile void* memory,
size_t size,
const PaintOp::DeserializeOptions& options,
bool enable_security_constraints)
: … { … }
void PaintOpReader::FixupMatrixPostSerialization(SkMatrix* matrix) { … }
bool PaintOpReader::ReadAndValidateOpHeader(uint8_t* type,
size_t* serialized_size) { … }
template <typename T>
void PaintOpReader::ReadSimple(T* val) { … }
uint8_t* PaintOpReader::CopyScratchSpace(size_t bytes) { … }
void PaintOpReader::ReadData(base::span<uint8_t> data) { … }
void PaintOpReader::ReadSize(size_t* size) { … }
void PaintOpReader::Read(SkScalar* data) { … }
void PaintOpReader::Read(uint8_t* data) { … }
void PaintOpReader::Read(uint32_t* data) { … }
void PaintOpReader::Read(uint64_t* data) { … }
void PaintOpReader::Read(int32_t* data) { … }
void PaintOpReader::Read(SkRect* rect) { … }
void PaintOpReader::Read(SkIRect* rect) { … }
void PaintOpReader::Read(SkRRect* rect) { … }
void PaintOpReader::Read(SkColor4f* color) { … }
void PaintOpReader::Read(SkPath* path) { … }
void PaintOpReader::Read(PaintFlags* flags) { … }
void PaintOpReader::Read(CorePaintFlags* flags) { … }
void PaintOpReader::Read(
PaintImage* image,
PaintFlags::DynamicRangeLimitMixture dynamic_range_limit) { … }
void PaintOpReader::Read(sk_sp<SkData>* data) { … }
void PaintOpReader::Read(sk_sp<SkColorSpace>* color_space) { … }
void PaintOpReader::Read(SkGainmapInfo* gainmap_info) { … }
void PaintOpReader::Read(sk_sp<sktext::gpu::Slug>* slug) { … }
void PaintOpReader::Read(sk_sp<DrawLooper>* looper) { … }
void PaintOpReader::Read(sk_sp<PaintShader>* shader) { … }
void PaintOpReader::Read(SkMatrix* matrix) { … }
void PaintOpReader::Read(SkM44* matrix) { … }
void PaintOpReader::Read(SkSamplingOptions* sampling) { … }
void PaintOpReader::Read(SkYUVColorSpace* yuv_color_space) { … }
void PaintOpReader::Read(SkYUVAInfo::PlaneConfig* plane_config) { … }
void PaintOpReader::Read(SkYUVAInfo::Subsampling* subsampling) { … }
void PaintOpReader::Read(gpu::Mailbox* mailbox) { … }
void PaintOpReader::Read(SkHighContrastConfig* config) { … }
void PaintOpReader::Read(gfx::HDRMetadata* hdr_metadata) { … }
void PaintOpReader::Read(SkGradientShader::Interpolation* interpolation) { … }
void PaintOpReader::Read(scoped_refptr<SkottieWrapper>* skottie) { … }
void PaintOpReader::AlignMemory(size_t alignment) { … }
NOINLINE void PaintOpReader::SetInvalid(DeserializationError error) { … }
const volatile void* PaintOpReader::ExtractReadableMemory(size_t bytes) { … }
void PaintOpReader::Read(sk_sp<ColorFilter>* filter) { … }
void PaintOpReader::Read(sk_sp<PathEffect>* effect) { … }
void PaintOpReader::Read(sk_sp<PaintFilter>* filter) { … }
void PaintOpReader::ReadColorFilterPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadBlurPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadDropShadowPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadMagnifierPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadComposePaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadAlphaThresholdPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadXfermodePaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadArithmeticPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadMatrixConvolutionPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadDisplacementMapEffectPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadImagePaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadRecordPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadMergePaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadMorphologyPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadOffsetPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadTilePaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadTurbulencePaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadShaderPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadMatrixPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadLightingDistantPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadLightingPointPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
void PaintOpReader::ReadLightingSpotPaintFilter(
sk_sp<PaintFilter>* filter,
const std::optional<PaintFilter::CropRect>& crop_rect) { … }
size_t PaintOpReader::Read(std::optional<PaintRecord>* record) { … }
void PaintOpReader::Read(SkRegion* region) { … }
inline void PaintOpReader::DidRead(size_t bytes_read) { … }
}