diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-03-08 13:07:32 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-03-08 13:40:10 +0000 |
commit | 818d9aed569afd192f6d4f6d9b28b72912df8b93 (patch) | |
tree | fa30cbdffa3e8fdc09dbbe37ffc0a721b40fced1 /chromium/cc/paint | |
parent | 66a2147d838e293f4a5db7711c8eba4e6faaaf0f (diff) | |
download | qtwebengine-chromium-818d9aed569afd192f6d4f6d9b28b72912df8b93.tar.gz |
BASELINE: Update Chromium to 65.0.3325.151
Change-Id: I3c71dd500483eb29491ac3eee4123714dda52da9
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/cc/paint')
-rw-r--r-- | chromium/cc/paint/paint_filter.cc | 197 | ||||
-rw-r--r-- | chromium/cc/paint/paint_filter.h | 38 | ||||
-rw-r--r-- | chromium/cc/paint/paint_flags.cc | 15 | ||||
-rw-r--r-- | chromium/cc/paint/paint_flags.h | 2 | ||||
-rw-r--r-- | chromium/cc/paint/paint_op_buffer_unittest.cc | 63 | ||||
-rw-r--r-- | chromium/cc/paint/paint_op_reader.cc | 4 | ||||
-rw-r--r-- | chromium/cc/paint/paint_op_writer.cc | 79 | ||||
-rw-r--r-- | chromium/cc/paint/paint_op_writer.h | 9 | ||||
-rw-r--r-- | chromium/cc/paint/paint_shader.cc | 24 | ||||
-rw-r--r-- | chromium/cc/paint/paint_shader.h | 2 |
10 files changed, 374 insertions, 59 deletions
diff --git a/chromium/cc/paint/paint_filter.cc b/chromium/cc/paint/paint_filter.cc index 469b107bd5d..c05fb3d51e5 100644 --- a/chromium/cc/paint/paint_filter.cc +++ b/chromium/cc/paint/paint_filter.cc @@ -5,6 +5,7 @@ #include "cc/paint/paint_filter.h" #include "cc/paint/filter_operations.h" +#include "cc/paint/paint_op_writer.h" #include "cc/paint/paint_record.h" #include "third_party/skia/include/core/SkColorFilter.h" #include "third_party/skia/include/core/SkMath.h" @@ -93,6 +94,27 @@ std::string PaintFilter::TypeToString(Type type) { return "Unknown"; } +size_t PaintFilter::GetFilterSize(const PaintFilter* filter) { + // A null type is used to indicate no filter. + if (!filter) + return sizeof(uint32_t); + return filter->SerializedSize() + PaintOpWriter::Alignment(); +} + +size_t PaintFilter::BaseSerializedSize() const { + size_t total_size = 0u; + // Filter type. + total_size += sizeof(uint32_t); + // Bool to indicate whether crop exists. + total_size += sizeof(uint32_t); + if (crop_rect_) { + // CropRect. + total_size += sizeof(crop_rect_->flags()); + total_size += sizeof(crop_rect_->rect()); + } + return total_size; +} + bool PaintFilter::operator==(const PaintFilter& other) const { if (type_ != other.type_) return false; @@ -194,6 +216,14 @@ ColorFilterPaintFilter::ColorFilterPaintFilter( ColorFilterPaintFilter::~ColorFilterPaintFilter() = default; +size_t ColorFilterPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = 0u; + total_size += BaseSerializedSize(); + total_size += PaintOpWriter::GetFlattenableSize(color_filter_.get()); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool ColorFilterPaintFilter::operator==( const ColorFilterPaintFilter& other) const { return PaintOp::AreSkFlattenablesEqual(color_filter_.get(), @@ -217,6 +247,14 @@ BlurPaintFilter::BlurPaintFilter(SkScalar sigma_x, BlurPaintFilter::~BlurPaintFilter() = default; +size_t BlurPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(sigma_x_) + sizeof(sigma_y_) + + sizeof(tile_mode_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool BlurPaintFilter::operator==(const BlurPaintFilter& other) const { return PaintOp::AreEqualEvenIfNaN(sigma_x_, other.sigma_x_) && PaintOp::AreEqualEvenIfNaN(sigma_y_, other.sigma_y_) && @@ -247,6 +285,14 @@ DropShadowPaintFilter::DropShadowPaintFilter(SkScalar dx, DropShadowPaintFilter::~DropShadowPaintFilter() = default; +size_t DropShadowPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(dx_) + sizeof(dy_) + sizeof(sigma_x_) + + sizeof(sigma_y_) + sizeof(color_) + sizeof(shadow_mode_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool DropShadowPaintFilter::operator==( const DropShadowPaintFilter& other) const { return PaintOp::AreEqualEvenIfNaN(dx_, other.dx_) && @@ -271,6 +317,13 @@ MagnifierPaintFilter::MagnifierPaintFilter(const SkRect& src_rect, MagnifierPaintFilter::~MagnifierPaintFilter() = default; +size_t MagnifierPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(src_rect_) + sizeof(inset_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool MagnifierPaintFilter::operator==(const MagnifierPaintFilter& other) const { return PaintOp::AreSkRectsEqual(src_rect_, other.src_rect_) && PaintOp::AreEqualEvenIfNaN(inset_, other.inset_) && @@ -288,6 +341,13 @@ ComposePaintFilter::ComposePaintFilter(sk_sp<PaintFilter> outer, ComposePaintFilter::~ComposePaintFilter() = default; +size_t ComposePaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = BaseSerializedSize(); + total_size += GetFilterSize(outer_.get()); + total_size += GetFilterSize(inner_.get()); + return total_size.ValueOrDefault(0u); +} + bool ComposePaintFilter::operator==(const ComposePaintFilter& other) const { return AreFiltersEqual(outer_.get(), other.outer_.get()) && AreFiltersEqual(inner_.get(), other.inner_.get()); @@ -309,6 +369,15 @@ AlphaThresholdPaintFilter::AlphaThresholdPaintFilter(const SkRegion& region, AlphaThresholdPaintFilter::~AlphaThresholdPaintFilter() = default; +size_t AlphaThresholdPaintFilter::SerializedSize() const { + size_t region_size = region_.writeToMemory(nullptr); + base::CheckedNumeric<size_t> total_size; + total_size = BaseSerializedSize() + sizeof(region_size) + region_size + + sizeof(inner_min_) + sizeof(outer_max_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool AlphaThresholdPaintFilter::operator==( const AlphaThresholdPaintFilter& other) const { return region_ == other.region_ && @@ -332,6 +401,14 @@ XfermodePaintFilter::XfermodePaintFilter(SkBlendMode blend_mode, XfermodePaintFilter::~XfermodePaintFilter() = default; +size_t XfermodePaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(blend_mode_); + total_size += GetFilterSize(background_.get()); + total_size += GetFilterSize(foreground_.get()); + return total_size.ValueOrDefault(0u); +} + bool XfermodePaintFilter::operator==(const XfermodePaintFilter& other) const { return blend_mode_ == other.blend_mode_ && AreFiltersEqual(background_.get(), other.background_.get()) && @@ -361,6 +438,15 @@ ArithmeticPaintFilter::ArithmeticPaintFilter(float k1, ArithmeticPaintFilter::~ArithmeticPaintFilter() = default; +size_t ArithmeticPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(k1_) + sizeof(k2_) + sizeof(k3_) + + sizeof(k4_) + sizeof(enforce_pm_color_); + total_size += GetFilterSize(background_.get()); + total_size += GetFilterSize(foreground_.get()); + return total_size.ValueOrDefault(0u); +} + bool ArithmeticPaintFilter::operator==( const ArithmeticPaintFilter& other) const { return PaintOp::AreEqualEvenIfNaN(k1_, other.k1_) && @@ -403,6 +489,15 @@ MatrixConvolutionPaintFilter::MatrixConvolutionPaintFilter( MatrixConvolutionPaintFilter::~MatrixConvolutionPaintFilter() = default; +size_t MatrixConvolutionPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(kernel_size_) + sizeof(size_t) + + kernel_->size() * sizeof(SkScalar) + sizeof(gain_) + sizeof(bias_) + + sizeof(kernel_offset_) + sizeof(tile_mode_) + sizeof(convolve_alpha_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool MatrixConvolutionPaintFilter::operator==( const MatrixConvolutionPaintFilter& other) const { return kernel_size_ == other.kernel_size_ && @@ -435,6 +530,15 @@ DisplacementMapEffectPaintFilter::DisplacementMapEffectPaintFilter( DisplacementMapEffectPaintFilter::~DisplacementMapEffectPaintFilter() = default; +size_t DisplacementMapEffectPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = BaseSerializedSize() + + sizeof(uint32_t) + + sizeof(uint32_t) + sizeof(scale_); + total_size += GetFilterSize(displacement_.get()); + total_size += GetFilterSize(color_.get()); + return total_size.ValueOrDefault(0u); +} + bool DisplacementMapEffectPaintFilter::operator==( const DisplacementMapEffectPaintFilter& other) const { return channel_x_ == other.channel_x_ && channel_y_ == other.channel_y_ && @@ -458,6 +562,14 @@ ImagePaintFilter::ImagePaintFilter(PaintImage image, ImagePaintFilter::~ImagePaintFilter() = default; +size_t ImagePaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(src_rect_) + sizeof(dst_rect_) + + sizeof(filter_quality_); + total_size += PaintOpWriter::GetImageSize(image_); + return total_size.ValueOrDefault(0u); +} + bool ImagePaintFilter::operator==(const ImagePaintFilter& other) const { return !!image_ == !!other.image_ && PaintOp::AreSkRectsEqual(src_rect_, other.src_rect_) && @@ -476,6 +588,13 @@ RecordPaintFilter::RecordPaintFilter(sk_sp<PaintRecord> record, RecordPaintFilter::~RecordPaintFilter() = default; +size_t RecordPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(record_bounds_); + total_size += PaintOpWriter::GetRecordSize(record_.get()); + return total_size.ValueOrDefault(0u); +} + bool RecordPaintFilter::operator==(const RecordPaintFilter& other) const { return !!record_ == !!other.record_ && PaintOp::AreSkRectsEqual(record_bounds_, other.record_bounds_); @@ -499,6 +618,15 @@ MergePaintFilter::MergePaintFilter(sk_sp<PaintFilter>* const filters, MergePaintFilter::~MergePaintFilter() = default; +size_t MergePaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = 0u; + for (size_t i = 0; i < input_count(); ++i) + total_size += GetFilterSize(input_at(i)); + total_size += BaseSerializedSize(); + total_size += sizeof(input_count()); + return total_size.ValueOrDefault(0u); +} + bool MergePaintFilter::operator==(const MergePaintFilter& other) const { if (inputs_->size() != other.inputs_->size()) return false; @@ -533,6 +661,14 @@ MorphologyPaintFilter::MorphologyPaintFilter(MorphType morph_type, MorphologyPaintFilter::~MorphologyPaintFilter() = default; +size_t MorphologyPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(morph_type_) + sizeof(radius_x_) + + sizeof(radius_y_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool MorphologyPaintFilter::operator==( const MorphologyPaintFilter& other) const { return morph_type_ == other.morph_type_ && radius_x_ == other.radius_x_ && @@ -554,6 +690,13 @@ OffsetPaintFilter::OffsetPaintFilter(SkScalar dx, OffsetPaintFilter::~OffsetPaintFilter() = default; +size_t OffsetPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(dx_) + sizeof(dy_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool OffsetPaintFilter::operator==(const OffsetPaintFilter& other) const { return PaintOp::AreEqualEvenIfNaN(dx_, other.dx_) && PaintOp::AreEqualEvenIfNaN(dy_, other.dy_) && @@ -573,6 +716,13 @@ TilePaintFilter::TilePaintFilter(const SkRect& src, TilePaintFilter::~TilePaintFilter() = default; +size_t TilePaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(src_) + sizeof(dst_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool TilePaintFilter::operator==(const TilePaintFilter& other) const { return PaintOp::AreSkRectsEqual(src_, other.src_) && PaintOp::AreSkRectsEqual(dst_, other.dst_) && @@ -614,6 +764,12 @@ TurbulencePaintFilter::TurbulencePaintFilter(TurbulenceType turbulence_type, TurbulencePaintFilter::~TurbulencePaintFilter() = default; +size_t TurbulencePaintFilter::SerializedSize() const { + return BaseSerializedSize() + sizeof(turbulence_type_) + + sizeof(base_frequency_x_) + sizeof(base_frequency_y_) + + sizeof(num_octaves_) + sizeof(seed_) + sizeof(tile_size_); +} + bool TurbulencePaintFilter::operator==( const TurbulencePaintFilter& other) const { return turbulence_type_ == other.turbulence_type_ && @@ -634,6 +790,12 @@ PaintFlagsPaintFilter::PaintFlagsPaintFilter(PaintFlags flags, PaintFlagsPaintFilter::~PaintFlagsPaintFilter() = default; +size_t PaintFlagsPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = BaseSerializedSize(); + total_size += flags_.GetSerializedSize(); + return total_size.ValueOrDefault(0u); +} + bool PaintFlagsPaintFilter::operator==( const PaintFlagsPaintFilter& other) const { return flags_ == other.flags_; @@ -652,6 +814,13 @@ MatrixPaintFilter::MatrixPaintFilter(const SkMatrix& matrix, MatrixPaintFilter::~MatrixPaintFilter() = default; +size_t MatrixPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(matrix_) + sizeof(filter_quality_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool MatrixPaintFilter::operator==(const MatrixPaintFilter& other) const { return PaintOp::AreSkMatricesEqual(matrix_, other.matrix_) && filter_quality_ == other.filter_quality_ && @@ -691,6 +860,15 @@ LightingDistantPaintFilter::LightingDistantPaintFilter( LightingDistantPaintFilter::~LightingDistantPaintFilter() = default; +size_t LightingDistantPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(lighting_type_) + sizeof(direction_) + + sizeof(light_color_) + sizeof(surface_scale_) + sizeof(kconstant_) + + sizeof(shininess_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool LightingDistantPaintFilter::operator==( const LightingDistantPaintFilter& other) const { return lighting_type_ == other.lighting_type_ && @@ -734,6 +912,15 @@ LightingPointPaintFilter::LightingPointPaintFilter(LightingType lighting_type, LightingPointPaintFilter::~LightingPointPaintFilter() = default; +size_t LightingPointPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(lighting_type_) + sizeof(location_) + + sizeof(light_color_) + sizeof(surface_scale_) + sizeof(kconstant_) + + sizeof(shininess_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool LightingPointPaintFilter::operator==( const LightingPointPaintFilter& other) const { return lighting_type_ == other.lighting_type_ && @@ -784,6 +971,16 @@ LightingSpotPaintFilter::LightingSpotPaintFilter(LightingType lighting_type, LightingSpotPaintFilter::~LightingSpotPaintFilter() = default; +size_t LightingSpotPaintFilter::SerializedSize() const { + base::CheckedNumeric<size_t> total_size = + BaseSerializedSize() + sizeof(lighting_type_) + sizeof(location_) + + sizeof(target_) + sizeof(specular_exponent_) + sizeof(cutoff_angle_) + + sizeof(light_color_) + sizeof(surface_scale_) + sizeof(kconstant_) + + sizeof(shininess_); + total_size += GetFilterSize(input_.get()); + return total_size.ValueOrDefault(0u); +} + bool LightingSpotPaintFilter::operator==( const LightingSpotPaintFilter& other) const { return lighting_type_ == other.lighting_type_ && diff --git a/chromium/cc/paint/paint_filter.h b/chromium/cc/paint/paint_filter.h index 716a153834e..107289bf0af 100644 --- a/chromium/cc/paint/paint_filter.h +++ b/chromium/cc/paint/paint_filter.h @@ -29,7 +29,7 @@ namespace cc { class CC_PAINT_EXPORT PaintFilter : public SkRefCnt { public: - enum class Type : uint8_t { + enum class Type : uint32_t { // For serialization purposes, we reserve one enum to indicate that there // was no PaintFilter, ie the filter is "null". kNullFilter, @@ -58,7 +58,7 @@ class CC_PAINT_EXPORT PaintFilter : public SkRefCnt { // Update the following if kLightingSpot is not the max anymore. kMaxFilterType = kLightingSpot }; - enum class LightingType : uint8_t { + enum class LightingType : uint32_t { kDiffuse, kSpecular, // Update the following if kSpecular is not the max anymore. @@ -72,6 +72,10 @@ class CC_PAINT_EXPORT PaintFilter : public SkRefCnt { static std::string TypeToString(Type type); + // Returns the size required to serialize the |filter|. Note that |filter| can + // be nullptr. + static size_t GetFilterSize(const PaintFilter* filter); + Type type() const { return type_; } SkIRect filter_bounds(const SkIRect& src, const SkMatrix& ctm, @@ -88,6 +92,8 @@ class CC_PAINT_EXPORT PaintFilter : public SkRefCnt { return crop_rect_ ? &*crop_rect_ : nullptr; } + virtual size_t SerializedSize() const = 0; + // Note that this operation is potentially slow. It also only compares things // that are easy to compare. As an example, it doesn't compare equality of // images, rather only its existence. This is meant to be used only by tests @@ -107,6 +113,8 @@ class CC_PAINT_EXPORT PaintFilter : public SkRefCnt { return cached_sk_filter_; } + size_t BaseSerializedSize() const; + // This should be created by each sub-class at construction time, to ensure // that subsequent access to the filter is thread-safe. sk_sp<SkImageFilter> cached_sk_filter_; @@ -135,6 +143,7 @@ class CC_PAINT_EXPORT ColorFilterPaintFilter final : public PaintFilter { const sk_sp<SkColorFilter>& color_filter() const { return color_filter_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const ColorFilterPaintFilter& other) const; private: @@ -159,6 +168,7 @@ class CC_PAINT_EXPORT BlurPaintFilter final : public PaintFilter { SkScalar sigma_y() const { return sigma_y_; } TileMode tile_mode() const { return tile_mode_; } + size_t SerializedSize() const override; bool operator==(const BlurPaintFilter& other) const; private: @@ -190,6 +200,7 @@ class CC_PAINT_EXPORT DropShadowPaintFilter final : public PaintFilter { ShadowMode shadow_mode() const { return shadow_mode_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const DropShadowPaintFilter& other) const; private: @@ -215,6 +226,7 @@ class CC_PAINT_EXPORT MagnifierPaintFilter final : public PaintFilter { SkScalar inset() const { return inset_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const MagnifierPaintFilter& other) const; private: @@ -232,6 +244,7 @@ class CC_PAINT_EXPORT ComposePaintFilter final : public PaintFilter { const sk_sp<PaintFilter>& outer() const { return outer_; } const sk_sp<PaintFilter>& inner() const { return inner_; } + size_t SerializedSize() const override; bool operator==(const ComposePaintFilter& other) const; private: @@ -254,6 +267,7 @@ class CC_PAINT_EXPORT AlphaThresholdPaintFilter final : public PaintFilter { SkScalar outer_max() const { return outer_max_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const AlphaThresholdPaintFilter& other) const; private: @@ -276,6 +290,7 @@ class CC_PAINT_EXPORT XfermodePaintFilter final : public PaintFilter { const sk_sp<PaintFilter>& background() const { return background_; } const sk_sp<PaintFilter>& foreground() const { return foreground_; } + size_t SerializedSize() const override; bool operator==(const XfermodePaintFilter& other) const; private: @@ -305,6 +320,7 @@ class CC_PAINT_EXPORT ArithmeticPaintFilter final : public PaintFilter { const sk_sp<PaintFilter>& background() const { return background_; } const sk_sp<PaintFilter>& foreground() const { return foreground_; } + size_t SerializedSize() const override; bool operator==(const ArithmeticPaintFilter& other) const; private: @@ -341,6 +357,7 @@ class CC_PAINT_EXPORT MatrixConvolutionPaintFilter final : public PaintFilter { bool convolve_alpha() const { return convolve_alpha_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const MatrixConvolutionPaintFilter& other) const; private: @@ -373,6 +390,7 @@ class CC_PAINT_EXPORT DisplacementMapEffectPaintFilter final const sk_sp<PaintFilter>& displacement() const { return displacement_; } const sk_sp<PaintFilter>& color() const { return color_; } + size_t SerializedSize() const override; bool operator==(const DisplacementMapEffectPaintFilter& other) const; private: @@ -397,6 +415,7 @@ class CC_PAINT_EXPORT ImagePaintFilter final : public PaintFilter { const SkRect& dst_rect() const { return dst_rect_; } SkFilterQuality filter_quality() const { return filter_quality_; } + size_t SerializedSize() const override; bool operator==(const ImagePaintFilter& other) const; private: @@ -415,6 +434,7 @@ class CC_PAINT_EXPORT RecordPaintFilter final : public PaintFilter { const sk_sp<PaintRecord>& record() const { return record_; } SkRect record_bounds() const { return record_bounds_; } + size_t SerializedSize() const override; bool operator==(const RecordPaintFilter& other) const; private: @@ -436,6 +456,7 @@ class CC_PAINT_EXPORT MergePaintFilter final : public PaintFilter { return inputs_[i].get(); } + size_t SerializedSize() const override; bool operator==(const MergePaintFilter& other) const; private: @@ -444,7 +465,7 @@ class CC_PAINT_EXPORT MergePaintFilter final : public PaintFilter { class CC_PAINT_EXPORT MorphologyPaintFilter final : public PaintFilter { public: - enum class MorphType : uint8_t { kDilate, kErode, kMaxMorphType = kErode }; + enum class MorphType : uint32_t { kDilate, kErode, kMaxMorphType = kErode }; static constexpr Type kType = Type::kMorphology; MorphologyPaintFilter(MorphType morph_type, int radius_x, @@ -458,6 +479,7 @@ class CC_PAINT_EXPORT MorphologyPaintFilter final : public PaintFilter { int radius_y() const { return radius_y_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const MorphologyPaintFilter& other) const; private: @@ -480,6 +502,7 @@ class CC_PAINT_EXPORT OffsetPaintFilter final : public PaintFilter { SkScalar dy() const { return dy_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const OffsetPaintFilter& other) const; private: @@ -500,6 +523,7 @@ class CC_PAINT_EXPORT TilePaintFilter final : public PaintFilter { const SkRect& dst() const { return dst_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const TilePaintFilter& other) const; private: @@ -511,7 +535,7 @@ class CC_PAINT_EXPORT TilePaintFilter final : public PaintFilter { class CC_PAINT_EXPORT TurbulencePaintFilter final : public PaintFilter { public: static constexpr Type kType = Type::kTurbulence; - enum class TurbulenceType : uint8_t { + enum class TurbulenceType : uint32_t { kTurbulence, kFractalNoise, kMaxTurbulenceType = kFractalNoise @@ -532,6 +556,7 @@ class CC_PAINT_EXPORT TurbulencePaintFilter final : public PaintFilter { SkScalar seed() const { return seed_; } SkISize tile_size() const { return tile_size_; } + size_t SerializedSize() const override; bool operator==(const TurbulencePaintFilter& other) const; private: @@ -552,6 +577,7 @@ class CC_PAINT_EXPORT PaintFlagsPaintFilter final : public PaintFilter { const PaintFlags& flags() const { return flags_; } + size_t SerializedSize() const override; bool operator==(const PaintFlagsPaintFilter& other) const; private: @@ -570,6 +596,7 @@ class CC_PAINT_EXPORT MatrixPaintFilter final : public PaintFilter { SkFilterQuality filter_quality() const { return filter_quality_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const MatrixPaintFilter& other) const; private: @@ -602,6 +629,7 @@ class CC_PAINT_EXPORT LightingDistantPaintFilter final : public PaintFilter { SkScalar shininess() const { return shininess_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const LightingDistantPaintFilter& other) const; private: @@ -638,6 +666,7 @@ class CC_PAINT_EXPORT LightingPointPaintFilter final : public PaintFilter { SkScalar shininess() const { return shininess_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const LightingPointPaintFilter& other) const; private: @@ -680,6 +709,7 @@ class CC_PAINT_EXPORT LightingSpotPaintFilter final : public PaintFilter { SkScalar shininess() const { return shininess_; } const sk_sp<PaintFilter>& input() const { return input_; } + size_t SerializedSize() const override; bool operator==(const LightingSpotPaintFilter& other) const; private: diff --git a/chromium/cc/paint/paint_flags.cc b/chromium/cc/paint/paint_flags.cc index a08298b2d94..3a75c09ff9d 100644 --- a/chromium/cc/paint/paint_flags.cc +++ b/chromium/cc/paint/paint_flags.cc @@ -6,6 +6,7 @@ #include "cc/paint/paint_filter.h" #include "cc/paint/paint_op_buffer.h" +#include "cc/paint/paint_op_writer.h" namespace { @@ -207,4 +208,18 @@ bool PaintFlags::HasDiscardableImages() const { return false; } +size_t PaintFlags::GetSerializedSize() const { + return sizeof(text_size_) + sizeof(color_) + sizeof(width_) + + sizeof(miter_limit_) + sizeof(blend_mode_) + sizeof(bitfields_uint_) + + PaintOpWriter::GetFlattenableSize(path_effect_.get()) + + PaintOpWriter::Alignment() + + PaintOpWriter::GetFlattenableSize(mask_filter_.get()) + + PaintOpWriter::Alignment() + + PaintOpWriter::GetFlattenableSize(color_filter_.get()) + + PaintOpWriter::Alignment() + + PaintOpWriter::GetFlattenableSize(draw_looper_.get()) + + PaintFilter::GetFilterSize(image_filter_.get()) + + PaintShader::GetSerializedSize(shader_.get()); +} + } // namespace cc diff --git a/chromium/cc/paint/paint_flags.h b/chromium/cc/paint/paint_flags.h index b15292585cc..a132fd702bd 100644 --- a/chromium/cc/paint/paint_flags.h +++ b/chromium/cc/paint/paint_flags.h @@ -221,6 +221,8 @@ class CC_PAINT_EXPORT PaintFlags { bool HasDiscardableImages() const; + size_t GetSerializedSize() const; + private: friend class PaintOpReader; friend class PaintOpWriter; diff --git a/chromium/cc/paint/paint_op_buffer_unittest.cc b/chromium/cc/paint/paint_op_buffer_unittest.cc index 8833e3538b9..2b4ce80f232 100644 --- a/chromium/cc/paint/paint_op_buffer_unittest.cc +++ b/chromium/cc/paint/paint_op_buffer_unittest.cc @@ -2853,7 +2853,13 @@ TEST(PaintOpBufferTest, ReplacesImagesFromProvider) { buffer.Playback(&canvas, PlaybackParams(&image_provider)); } -TEST(PaintOpBufferTest, FilterSerialization) { +class PaintFilterSerializationTest : public ::testing::TestWithParam<bool> {}; + +INSTANTIATE_TEST_CASE_P(PaintFilterSerializationTests, + PaintFilterSerializationTest, + ::testing::Values(true, false)); + +TEST_P(PaintFilterSerializationTest, Basic) { SkScalar scalars[9] = {1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f}; std::vector<sk_sp<PaintFilter>> filters = { sk_sp<PaintFilter>{new ColorFilterPaintFilter( @@ -2871,9 +2877,6 @@ TEST(PaintOpBufferTest, FilterSerialization) { SkISize::Make(3, 3), scalars, 30.f, 123.f, SkIPoint::Make(0, 0), SkMatrixConvolutionImageFilter::kClampToBlack_TileMode, true, nullptr)}, - sk_sp<PaintFilter>{ - new RecordPaintFilter(sk_sp<PaintRecord>{new PaintRecord}, - SkRect::MakeXYWH(10, 15, 20, 25))}, sk_sp<PaintFilter>{new MorphologyPaintFilter( MorphologyPaintFilter::MorphType::kErode, 15, 30, nullptr)}, sk_sp<PaintFilter>{new OffsetPaintFilter(-1.f, -2.f, nullptr)}, @@ -2909,41 +2912,33 @@ TEST(PaintOpBufferTest, FilterSerialization) { SkDisplacementMapEffect::kG_ChannelSelectorType, 10, filters[6], filters[7])); filters.emplace_back(new MergePaintFilter(filters.data(), filters.size())); + filters.emplace_back(new RecordPaintFilter( + sk_sp<PaintRecord>{new PaintRecord}, SkRect::MakeXYWH(10, 15, 20, 25))); - std::unique_ptr<char, base::AlignedFreeDeleter> memory( - static_cast<char*>(base::AlignedAlloc(PaintOpBuffer::kInitialBufferSize, - PaintOpBuffer::PaintOpAlign))); TestOptionsProvider options_provider; for (size_t i = 0; i < filters.size(); ++i) { SCOPED_TRACE(i); - auto& filter = filters[i]; - - PaintFlags flags; - flags.setImageFilter(filter); - PaintOpBuffer buffer; - buffer.push<DrawRectOp>(SkRect::MakeXYWH(1, 2, 3, 4), flags); - SimpleBufferSerializer serializer(memory.get(), - PaintOpBuffer::kInitialBufferSize, - options_provider.image_provider(), - options_provider.transfer_cache_helper()); - serializer.Serialize(&buffer); - ASSERT_TRUE(serializer.valid()); - ASSERT_GT(serializer.written(), 0u); - - auto deserialized_buffer = - PaintOpBuffer::MakeFromMemory(memory.get(), serializer.written(), - options_provider.deserialize_options()); - ASSERT_TRUE(deserialized_buffer); - PaintOpBuffer::Iterator it(deserialized_buffer.get()); - ASSERT_TRUE(it); - auto* op = *it; - ASSERT_TRUE(op->GetType() == PaintOpType::DrawRect); - auto* rect_op = static_cast<DrawRectOp*>(op); - EXPECT_FLOAT_RECT_EQ(rect_op->rect, SkRect::MakeXYWH(1, 2, 3, 4)); - EXPECT_TRUE(*filter == *rect_op->flags.getImageFilter()); - ++it; - EXPECT_FALSE(it); + auto& filter = filters[i]; + std::vector<uint8_t> memory; + size_t buffer_size = filter->type() == PaintFilter::Type::kPaintRecord + ? PaintOpBuffer::kInitialBufferSize + : PaintFilter::GetFilterSize(filter.get()); + buffer_size += PaintOpWriter::HeaderBytes(); + memory.resize(buffer_size); + + PaintOpWriter writer(memory.data(), memory.size(), + options_provider.transfer_cache_helper(), + options_provider.image_provider(), GetParam()); + writer.Write(filter.get()); + ASSERT_GT(writer.size(), 0u) << PaintFilter::TypeToString(filter->type()); + + sk_sp<PaintFilter> deserialized_filter; + PaintOpReader reader(memory.data(), writer.size(), + options_provider.transfer_cache_helper(), GetParam()); + reader.Read(&deserialized_filter); + ASSERT_TRUE(deserialized_filter); + EXPECT_TRUE(*filter == *deserialized_filter); } } diff --git a/chromium/cc/paint/paint_op_reader.cc b/chromium/cc/paint/paint_op_reader.cc index 3beadab336f..3e726ec037d 100644 --- a/chromium/cc/paint/paint_op_reader.cc +++ b/chromium/cc/paint/paint_op_reader.cc @@ -265,9 +265,13 @@ void PaintOpReader::Read(PaintImage* image) { auto serialized_type = static_cast<PaintOp::SerializedImageType>(serialized_type_int); + if (serialized_type == PaintOp::SerializedImageType::kNoImage) + return; + if (enable_security_constraints_) { switch (serialized_type) { case PaintOp::SerializedImageType::kNoImage: + NOTREACHED(); return; case PaintOp::SerializedImageType::kImageData: { SkColorType color_type; diff --git a/chromium/cc/paint/paint_op_writer.cc b/chromium/cc/paint/paint_op_writer.cc index 8940574891d..7b89776de52 100644 --- a/chromium/cc/paint/paint_op_writer.cc +++ b/chromium/cc/paint/paint_op_writer.cc @@ -22,6 +22,46 @@ void TypefaceCataloger(SkTypeface* typeface, void* ctx) { } } // namespace +// static +size_t PaintOpWriter::GetFlattenableSize(const SkFlattenable* flattenable) { + // The first bit is always written to indicate the serialized size of the + // flattenable, or zero if it doesn't exist. + size_t total_size = sizeof(size_t); + if (!flattenable) + return total_size; + + // There is no method to know the serialized size of a flattenable without + // serializing it. + sk_sp<SkData> data = flattenable->serialize(); + total_size += data->isEmpty() ? 0u : data->size(); + return total_size; +} + +// static +size_t PaintOpWriter::GetImageSize(const PaintImage& image) { + // Image Serialization type. + size_t image_size = sizeof(PaintOp::SerializedImageType); + if (image) { + auto info = SkImageInfo::Make(image.width(), image.height(), + kN32_SkColorType, kPremul_SkAlphaType); + image_size += sizeof(info.colorType()); + image_size += sizeof(info.width()); + image_size += sizeof(info.height()); + image_size += sizeof(size_t); + image_size += info.computeMinByteSize(); + } + return image_size; +} + +// static +size_t PaintOpWriter::GetRecordSize(const PaintRecord* record) { + // Zero size indicates no record. + // TODO(khushalsagar): Querying the size of a PaintRecord is not supported. + // This works only for security constrained serialization which ignores + // records. + return sizeof(size_t); +} + PaintOpWriter::PaintOpWriter(void* memory, size_t size, TransferCacheSerializeHelper* transfer_cache, @@ -36,13 +76,13 @@ PaintOpWriter::PaintOpWriter(void* memory, // Leave space for header of type/skip. DCHECK_GE(size, HeaderBytes()); } + PaintOpWriter::~PaintOpWriter() = default; template <typename T> void PaintOpWriter::WriteSimple(const T& val) { static_assert(base::is_trivially_copyable<T>::value, ""); - if (remaining_bytes_ < sizeof(T)) - valid_ = false; + EnsureBytes(sizeof(T)); if (!valid_) return; @@ -106,8 +146,7 @@ void PaintOpWriter::Write(const SkRRect& rect) { void PaintOpWriter::Write(const SkPath& path) { AlignMemory(4); size_t bytes = path.writeToMemory(nullptr); - if (bytes > remaining_bytes_) - valid_ = false; + EnsureBytes(bytes); if (!valid_) return; @@ -262,8 +301,7 @@ void PaintOpWriter::Write(SkColorType color_type) { } void PaintOpWriter::WriteData(size_t bytes, const void* input) { - if (bytes > remaining_bytes_) - valid_ = false; + EnsureBytes(bytes); if (!valid_) return; if (bytes == 0) @@ -290,8 +328,9 @@ void PaintOpWriter::AlignMemory(size_t alignment) { // because alignment is a power of two. This doesn't use modulo operator // however, since it can be slow. size_t padding = ((memory + alignment - 1) & ~(alignment - 1)) - memory; - if (padding > remaining_bytes_) - valid_ = false; + EnsureBytes(padding); + if (!valid_) + return; memory_ += padding; remaining_bytes_ -= padding; @@ -488,7 +527,7 @@ void PaintOpWriter::Write(const MergePaintFilter& filter) { } void PaintOpWriter::Write(const MorphologyPaintFilter& filter) { - WriteSimple(static_cast<uint32_t>(filter.morph_type())); + WriteSimple(filter.morph_type()); WriteSimple(filter.radius_x()); WriteSimple(filter.radius_y()); Write(filter.input().get()); @@ -507,7 +546,7 @@ void PaintOpWriter::Write(const TilePaintFilter& filter) { } void PaintOpWriter::Write(const TurbulencePaintFilter& filter) { - WriteSimple(static_cast<uint32_t>(filter.turbulence_type())); + WriteSimple(filter.turbulence_type()); WriteSimple(filter.base_frequency_x()); WriteSimple(filter.base_frequency_y()); WriteSimple(filter.num_octaves()); @@ -526,7 +565,7 @@ void PaintOpWriter::Write(const MatrixPaintFilter& filter) { } void PaintOpWriter::Write(const LightingDistantPaintFilter& filter) { - WriteSimple(static_cast<uint32_t>(filter.lighting_type())); + WriteSimple(filter.lighting_type()); WriteSimple(filter.direction()); WriteSimple(filter.light_color()); WriteSimple(filter.surface_scale()); @@ -536,7 +575,7 @@ void PaintOpWriter::Write(const LightingDistantPaintFilter& filter) { } void PaintOpWriter::Write(const LightingPointPaintFilter& filter) { - WriteSimple(static_cast<uint32_t>(filter.lighting_type())); + WriteSimple(filter.lighting_type()); WriteSimple(filter.location()); WriteSimple(filter.light_color()); WriteSimple(filter.surface_scale()); @@ -546,7 +585,7 @@ void PaintOpWriter::Write(const LightingPointPaintFilter& filter) { } void PaintOpWriter::Write(const LightingSpotPaintFilter& filter) { - WriteSimple(static_cast<uint32_t>(filter.lighting_type())); + WriteSimple(filter.lighting_type()); WriteSimple(filter.location()); WriteSimple(filter.target()); WriteSimple(filter.specular_exponent()); @@ -563,10 +602,9 @@ void PaintOpWriter::Write(const PaintRecord* record) { // information until we do the serialization. So, skip the amount needed // before writing. size_t size_offset = sizeof(size_t); - if (size_offset > remaining_bytes_) { - valid_ = false; + EnsureBytes(size_offset); + if (!valid_) return; - } char* size_memory = memory_; @@ -607,9 +645,7 @@ void PaintOpWriter::Write(const PaintRecord* record) { void PaintOpWriter::Write(const PaintImage& image) { if (!image) { - Write(static_cast<uint8_t>( - PaintOp::SerializedImageType::kTransferCacheEntry)); - Write(kInvalidImageTransferCacheEntryId); + Write(static_cast<uint8_t>(PaintOp::SerializedImageType::kNoImage)); return; } // Note that the filter quality doesn't matter here, since it's not @@ -631,4 +667,9 @@ void PaintOpWriter::Write(const SkRegion& region) { WriteData(bytes_written, data.get()); } +inline void PaintOpWriter::EnsureBytes(size_t required_bytes) { + if (remaining_bytes_ < required_bytes) + valid_ = false; +} + } // namespace cc diff --git a/chromium/cc/paint/paint_op_writer.h b/chromium/cc/paint/paint_op_writer.h index 04587c2381b..d66b61bf1bf 100644 --- a/chromium/cc/paint/paint_op_writer.h +++ b/chromium/cc/paint/paint_op_writer.h @@ -32,6 +32,10 @@ class CC_PAINT_EXPORT PaintOpWriter { ~PaintOpWriter(); static size_t constexpr HeaderBytes() { return 4u; } + static size_t constexpr Alignment() { return 4u; } + static size_t GetFlattenableSize(const SkFlattenable* flattenable); + static size_t GetImageSize(const PaintImage& image); + static size_t GetRecordSize(const PaintRecord* record); // Write a sequence of arbitrary bytes. void WriteData(size_t bytes, const void* input); @@ -123,19 +127,20 @@ class CC_PAINT_EXPORT PaintOpWriter { void Write(const PaintImage& image); void Write(const SkRegion& region); + void EnsureBytes(size_t required_bytes); + char* memory_ = nullptr; size_t size_ = 0u; size_t remaining_bytes_ = 0u; - bool valid_ = true; TransferCacheSerializeHelper* transfer_cache_; ImageProvider* image_provider_; + bool valid_ = true; // Indicates that the following security constraints must be applied during // serialization: // 1) PaintRecords and SkDrawLoopers must be ignored. // 2) Codec backed images must be decoded and only the bitmap should be // serialized. - const bool enable_security_constraints_; }; diff --git a/chromium/cc/paint/paint_shader.cc b/chromium/cc/paint/paint_shader.cc index eb5a1232b9e..fe3f6ab0331 100644 --- a/chromium/cc/paint/paint_shader.cc +++ b/chromium/cc/paint/paint_shader.cc @@ -5,6 +5,7 @@ #include "cc/paint/paint_shader.h" #include "base/memory/ptr_util.h" +#include "cc/paint/paint_op_writer.h" #include "cc/paint/paint_record.h" #include "third_party/skia/include/core/SkPictureRecorder.h" #include "third_party/skia/include/effects/SkGradientShader.h" @@ -159,6 +160,29 @@ sk_sp<PaintShader> PaintShader::MakePaintRecord( return shader; } +// static +size_t PaintShader::GetSerializedSize(const PaintShader* shader) { + size_t bool_size = sizeof(bool); + if (!shader) + return bool_size; + + return bool_size + sizeof(shader->shader_type_) + sizeof(shader->flags_) + + sizeof(shader->end_radius_) + sizeof(shader->start_radius_) + + sizeof(shader->tx_) + sizeof(shader->ty_) + + sizeof(shader->fallback_color_) + sizeof(shader->scaling_behavior_) + + bool_size + sizeof(*shader->local_matrix_) + sizeof(shader->center_) + + sizeof(shader->tile_) + sizeof(shader->start_point_) + + sizeof(shader->end_point_) + sizeof(shader->start_degrees_) + + sizeof(shader->end_degrees_) + + PaintOpWriter::GetImageSize(shader->image_) + + PaintOpWriter::GetImageSize(shader->image_) + bool_size + + PaintOpWriter::GetRecordSize(shader->record_.get()) + + sizeof(shader->colors_.size()) + + shader->colors_.size() * sizeof(SkColor) + + sizeof(shader->positions_.size()) + + shader->positions_.size() * sizeof(SkScalar); +} + PaintShader::PaintShader(Type type) : shader_type_(type) {} PaintShader::~PaintShader() = default; diff --git a/chromium/cc/paint/paint_shader.h b/chromium/cc/paint/paint_shader.h index 919141fe34e..e6bcdc6ffd0 100644 --- a/chromium/cc/paint/paint_shader.h +++ b/chromium/cc/paint/paint_shader.h @@ -100,6 +100,8 @@ class CC_PAINT_EXPORT PaintShader : public SkRefCnt { const SkMatrix* local_matrix, ScalingBehavior scaling_behavior = ScalingBehavior::kRasterAtScale); + static size_t GetSerializedSize(const PaintShader* shader); + ~PaintShader() override; SkMatrix GetLocalMatrix() const { |