#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "cc/paint/paint_filter.h"
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/span.h"
#include "base/memory/values_equivalent.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/types/optional_util.h"
#include "build/build_config.h"
#include "cc/paint/draw_image.h"
#include "cc/paint/filter_operations.h"
#include "cc/paint/image_provider.h"
#include "cc/paint/paint_image_builder.h"
#include "cc/paint/paint_op_writer.h"
#include "cc/paint/paint_record.h"
#include "cc/paint/scoped_raster_flags.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkScalar.h"
#include "third_party/skia/include/core/SkShader.h"
#include "third_party/skia/include/core/SkString.h"
#include "third_party/skia/include/core/SkTileMode.h"
#include "third_party/skia/include/effects/SkImageFilters.h"
#include "third_party/skia/include/effects/SkPerlinNoiseShader.h"
#include "third_party/skia/include/effects/SkRuntimeEffect.h"
namespace cc {
namespace {
const bool kHasNoDiscardableImages = …;
template <typename T>
bool AreValuesEqualForTesting(const sk_sp<T>& a, const sk_sp<T>& b) { … }
template <typename T>
bool AreEqualForTesting(const PaintFilter& a, const PaintFilter& b) { … }
bool HasDiscardableImages(const sk_sp<PaintFilter>& filter) { … }
bool HasDiscardableImages(const sk_sp<PaintFilter>* const filters, int count) { … }
sk_sp<PaintFilter> Snapshot(const sk_sp<PaintFilter>& filter,
ImageProvider* image_provider) { … }
}
PaintFilter::PaintFilter(Type type,
const CropRect* crop_rect,
bool has_discardable_images)
: … { … }
PaintFilter::~PaintFilter() = default;
std::string PaintFilter::TypeToString(Type type) { … }
SkIRect PaintFilter::MapRect(const SkIRect& src,
const SkMatrix* ctm,
MapDirection direction) const { … }
const PaintFilter::CropRect* PaintFilter::GetCropRect() const { … }
base::CheckedNumeric<size_t> PaintFilter::BaseSerializedSize() const { … }
sk_sp<PaintFilter> PaintFilter::SnapshotWithImages(
ImageProvider* image_provider) const { … }
bool PaintFilter::EqualsForTesting(const PaintFilter& other) const { … }
std::vector<sk_sp<SkImageFilter>> PaintFilter::ToSkImageFilters(
base::span<const sk_sp<PaintFilter>> filters) { … }
OneInputPaintFilter::OneInputPaintFilter(Type type,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
OneInputPaintFilter::~OneInputPaintFilter() = default;
gfx::ContentColorUsage OneInputPaintFilter::GetContentColorUsage() const { … }
base::CheckedNumeric<size_t> OneInputPaintFilter::BaseSerializedSize() const { … }
bool OneInputPaintFilter::EqualsForTesting(
const OneInputPaintFilter& other) const { … }
TwoInputPaintFilter::TwoInputPaintFilter(Type type,
sk_sp<PaintFilter> first,
sk_sp<PaintFilter> second,
const CropRect* crop_rect)
: … { … }
TwoInputPaintFilter::~TwoInputPaintFilter() = default;
gfx::ContentColorUsage TwoInputPaintFilter::GetContentColorUsage() const { … }
base::CheckedNumeric<size_t> TwoInputPaintFilter::BaseSerializedSize() const { … }
bool TwoInputPaintFilter::EqualsForTesting(
const TwoInputPaintFilter& other) const { … }
ColorFilterPaintFilter::ColorFilterPaintFilter(sk_sp<ColorFilter> color_filter,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
ColorFilterPaintFilter::~ColorFilterPaintFilter() = default;
size_t ColorFilterPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> ColorFilterPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool ColorFilterPaintFilter::EqualsForTesting(
const ColorFilterPaintFilter& other) const { … }
BlurPaintFilter::BlurPaintFilter(SkScalar sigma_x,
SkScalar sigma_y,
SkTileMode tile_mode,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
BlurPaintFilter::~BlurPaintFilter() = default;
size_t BlurPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> BlurPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool BlurPaintFilter::EqualsForTesting(const BlurPaintFilter& other) const { … }
DropShadowPaintFilter::DropShadowPaintFilter(SkScalar dx,
SkScalar dy,
SkScalar sigma_x,
SkScalar sigma_y,
SkColor4f color,
ShadowMode shadow_mode,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
DropShadowPaintFilter::~DropShadowPaintFilter() = default;
size_t DropShadowPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> DropShadowPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool DropShadowPaintFilter::EqualsForTesting(
const DropShadowPaintFilter& other) const { … }
MagnifierPaintFilter::MagnifierPaintFilter(const SkRect& lens_bounds,
SkScalar zoom_amount,
SkScalar inset,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
MagnifierPaintFilter::~MagnifierPaintFilter() = default;
size_t MagnifierPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> MagnifierPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool MagnifierPaintFilter::EqualsForTesting(
const MagnifierPaintFilter& other) const { … }
ComposePaintFilter::ComposePaintFilter(sk_sp<PaintFilter> outer,
sk_sp<PaintFilter> inner)
: … { … }
ComposePaintFilter::~ComposePaintFilter() = default;
size_t ComposePaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> ComposePaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool ComposePaintFilter::EqualsForTesting(
const ComposePaintFilter& other) const { … }
AlphaThresholdPaintFilter::AlphaThresholdPaintFilter(const SkRegion& region,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
AlphaThresholdPaintFilter::~AlphaThresholdPaintFilter() = default;
size_t AlphaThresholdPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> AlphaThresholdPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool AlphaThresholdPaintFilter::EqualsForTesting(
const AlphaThresholdPaintFilter& other) const { … }
XfermodePaintFilter::XfermodePaintFilter(SkBlendMode blend_mode,
sk_sp<PaintFilter> background,
sk_sp<PaintFilter> foreground,
const CropRect* crop_rect)
: … { … }
XfermodePaintFilter::~XfermodePaintFilter() = default;
size_t XfermodePaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> XfermodePaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool XfermodePaintFilter::EqualsForTesting(
const XfermodePaintFilter& other) const { … }
ArithmeticPaintFilter::ArithmeticPaintFilter(float k1,
float k2,
float k3,
float k4,
bool enforce_pm_color,
sk_sp<PaintFilter> background,
sk_sp<PaintFilter> foreground,
const CropRect* crop_rect)
: … { … }
ArithmeticPaintFilter::~ArithmeticPaintFilter() = default;
size_t ArithmeticPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> ArithmeticPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool ArithmeticPaintFilter::EqualsForTesting(
const ArithmeticPaintFilter& other) const { … }
MatrixConvolutionPaintFilter::MatrixConvolutionPaintFilter(
const SkISize& kernel_size,
const SkScalar* kernel,
SkScalar gain,
SkScalar bias,
const SkIPoint& kernel_offset,
SkTileMode tile_mode,
bool convolve_alpha,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
MatrixConvolutionPaintFilter::~MatrixConvolutionPaintFilter() = default;
size_t MatrixConvolutionPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> MatrixConvolutionPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool MatrixConvolutionPaintFilter::EqualsForTesting(
const MatrixConvolutionPaintFilter& other) const { … }
DisplacementMapEffectPaintFilter::DisplacementMapEffectPaintFilter(
SkColorChannel channel_x,
SkColorChannel channel_y,
SkScalar scale,
sk_sp<PaintFilter> displacement,
sk_sp<PaintFilter> color,
const CropRect* crop_rect)
: … { … }
DisplacementMapEffectPaintFilter::~DisplacementMapEffectPaintFilter() = default;
size_t DisplacementMapEffectPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> DisplacementMapEffectPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool DisplacementMapEffectPaintFilter::EqualsForTesting(
const DisplacementMapEffectPaintFilter& other) const { … }
ImagePaintFilter::ImagePaintFilter(PaintImage image,
const SkRect& src_rect,
const SkRect& dst_rect,
PaintFlags::FilterQuality filter_quality)
: … { … }
ImagePaintFilter::~ImagePaintFilter() = default;
gfx::ContentColorUsage ImagePaintFilter::GetContentColorUsage() const { … }
size_t ImagePaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> ImagePaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool ImagePaintFilter::EqualsForTesting(const ImagePaintFilter& other) const { … }
RecordPaintFilter::RecordPaintFilter(PaintRecord record,
const SkRect& record_bounds,
const gfx::SizeF& raster_scale,
ScalingBehavior scaling_behavior)
: … { … }
RecordPaintFilter::RecordPaintFilter(PaintRecord record,
const SkRect& record_bounds,
const gfx::SizeF& raster_scale,
ScalingBehavior scaling_behavior,
ImageProvider* image_provider)
: … { … }
RecordPaintFilter::~RecordPaintFilter() = default;
gfx::ContentColorUsage RecordPaintFilter::GetContentColorUsage() const { … }
sk_sp<RecordPaintFilter> RecordPaintFilter::CreateScaledPaintRecord(
const SkMatrix& ctm,
int max_texture_size) const { … }
size_t RecordPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> RecordPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool RecordPaintFilter::EqualsForTesting(const RecordPaintFilter& other) const { … }
MergePaintFilter::MergePaintFilter(const sk_sp<PaintFilter>* const filters,
int count,
const CropRect* crop_rect)
: … { … }
MergePaintFilter::MergePaintFilter(const sk_sp<PaintFilter>* const filters,
int count,
const CropRect* crop_rect,
ImageProvider* image_provider)
: … { … }
MergePaintFilter::~MergePaintFilter() = default;
gfx::ContentColorUsage MergePaintFilter::GetContentColorUsage() const { … }
size_t MergePaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> MergePaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool MergePaintFilter::EqualsForTesting(const MergePaintFilter& other) const { … }
MorphologyPaintFilter::MorphologyPaintFilter(MorphType morph_type,
float radius_x,
float radius_y,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
MorphologyPaintFilter::~MorphologyPaintFilter() = default;
size_t MorphologyPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> MorphologyPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool MorphologyPaintFilter::EqualsForTesting(
const MorphologyPaintFilter& other) const { … }
OffsetPaintFilter::OffsetPaintFilter(SkScalar dx,
SkScalar dy,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
OffsetPaintFilter::~OffsetPaintFilter() = default;
size_t OffsetPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> OffsetPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool OffsetPaintFilter::EqualsForTesting(const OffsetPaintFilter& other) const { … }
TilePaintFilter::TilePaintFilter(const SkRect& src,
const SkRect& dst,
sk_sp<PaintFilter> input)
: … { … }
TilePaintFilter::~TilePaintFilter() = default;
size_t TilePaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> TilePaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool TilePaintFilter::EqualsForTesting(const TilePaintFilter& other) const { … }
TurbulencePaintFilter::TurbulencePaintFilter(TurbulenceType turbulence_type,
SkScalar base_frequency_x,
SkScalar base_frequency_y,
int num_octaves,
SkScalar seed,
const SkISize* tile_size,
const CropRect* crop_rect)
: … { … }
TurbulencePaintFilter::~TurbulencePaintFilter() = default;
gfx::ContentColorUsage TurbulencePaintFilter::GetContentColorUsage() const { … }
size_t TurbulencePaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> TurbulencePaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool TurbulencePaintFilter::EqualsForTesting(
const TurbulencePaintFilter& other) const { … }
ShaderPaintFilter::ShaderPaintFilter(sk_sp<PaintShader> shader,
float alpha,
PaintFlags::FilterQuality filter_quality,
SkImageFilters::Dither dither,
const CropRect* crop_rect)
: … { … }
ShaderPaintFilter::~ShaderPaintFilter() = default;
gfx::ContentColorUsage ShaderPaintFilter::GetContentColorUsage() const { … }
size_t ShaderPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> ShaderPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool ShaderPaintFilter::EqualsForTesting(const ShaderPaintFilter& other) const { … }
MatrixPaintFilter::MatrixPaintFilter(const SkMatrix& matrix,
PaintFlags::FilterQuality filter_quality,
sk_sp<PaintFilter> input)
: … { … }
MatrixPaintFilter::~MatrixPaintFilter() = default;
size_t MatrixPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> MatrixPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool MatrixPaintFilter::EqualsForTesting(const MatrixPaintFilter& other) const { … }
LightingDistantPaintFilter::LightingDistantPaintFilter(
LightingType lighting_type,
const SkPoint3& direction,
SkColor4f light_color,
SkScalar surface_scale,
SkScalar kconstant,
SkScalar shininess,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
LightingDistantPaintFilter::~LightingDistantPaintFilter() = default;
size_t LightingDistantPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> LightingDistantPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool LightingDistantPaintFilter::EqualsForTesting(
const LightingDistantPaintFilter& other) const { … }
LightingPointPaintFilter::LightingPointPaintFilter(LightingType lighting_type,
const SkPoint3& location,
SkColor4f light_color,
SkScalar surface_scale,
SkScalar kconstant,
SkScalar shininess,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
LightingPointPaintFilter::~LightingPointPaintFilter() = default;
size_t LightingPointPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> LightingPointPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool LightingPointPaintFilter::EqualsForTesting(
const LightingPointPaintFilter& other) const { … }
LightingSpotPaintFilter::LightingSpotPaintFilter(LightingType lighting_type,
const SkPoint3& location,
const SkPoint3& target,
SkScalar specular_exponent,
SkScalar cutoff_angle,
SkColor4f light_color,
SkScalar surface_scale,
SkScalar kconstant,
SkScalar shininess,
sk_sp<PaintFilter> input,
const CropRect* crop_rect)
: … { … }
LightingSpotPaintFilter::~LightingSpotPaintFilter() = default;
size_t LightingSpotPaintFilter::SerializedSize() const { … }
sk_sp<PaintFilter> LightingSpotPaintFilter::SnapshotWithImagesInternal(
ImageProvider* image_provider) const { … }
bool LightingSpotPaintFilter::EqualsForTesting(
const LightingSpotPaintFilter& other) const { … }
}