Commit 6ac3063a authored by Adrienne Walker's avatar Adrienne Walker Committed by Commit Bot

cc: Add PaintOp::operator==

This moves test-only paint op comparisons from unittests into paint ops
themselves.

This is to support a fuzzing correctness test that serializing and then
deserializing an op results in the same op.

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: I351b4fb5329ee9ff64d54bb9dd49d0a1a34f7b13
Reviewed-on: https://chromium-review.googlesource.com/777840Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Commit-Queue: enne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517675}
parent 4e68cd40
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "cc/paint/paint_flags.h" #include "cc/paint/paint_flags.h"
#include "cc/paint/paint_op_buffer.h" #include "cc/paint/paint_op_buffer.h"
#include "third_party/skia/include/core/SkFlattenableSerialization.h"
namespace { namespace {
...@@ -128,6 +129,64 @@ bool PaintFlags::IsValid() const { ...@@ -128,6 +129,64 @@ bool PaintFlags::IsValid() const {
return PaintOp::IsValidPaintFlagsSkBlendMode(getBlendMode()); return PaintOp::IsValidPaintFlagsSkBlendMode(getBlendMode());
} }
static bool AreFlattenablesEqual(SkFlattenable* left, SkFlattenable* right) {
sk_sp<SkData> left_data(SkValidatingSerializeFlattenable(left));
sk_sp<SkData> right_data(SkValidatingSerializeFlattenable(right));
if (left_data->size() != right_data->size())
return false;
if (!left_data->equals(right_data.get()))
return false;
return true;
}
bool PaintFlags::operator==(const PaintFlags& other) const {
// Can't just ToSkPaint and operator== here as SkPaint does pointer
// comparisons on all the ref'd skia objects on the SkPaint, which
// is not true after serialization.
if (getTextSize() != other.getTextSize())
return false;
if (getColor() != other.getColor())
return false;
if (getStrokeWidth() != other.getStrokeWidth())
return false;
if (getStrokeMiter() != other.getStrokeMiter())
return false;
if (getBlendMode() != other.getBlendMode())
return false;
if (getStrokeCap() != other.getStrokeCap())
return false;
if (getStrokeJoin() != other.getStrokeJoin())
return false;
if (getStyle() != other.getStyle())
return false;
if (getTextEncoding() != other.getTextEncoding())
return false;
if (getHinting() != other.getHinting())
return false;
if (getFilterQuality() != other.getFilterQuality())
return false;
// TODO(enne): compare typeface too
if (!AreFlattenablesEqual(getPathEffect().get(), other.getPathEffect().get()))
return false;
if (!AreFlattenablesEqual(getMaskFilter().get(), other.getMaskFilter().get()))
return false;
if (!AreFlattenablesEqual(getColorFilter().get(),
other.getColorFilter().get()))
return false;
if (!AreFlattenablesEqual(getLooper().get(), other.getLooper().get()))
return false;
if (!AreFlattenablesEqual(getImageFilter().get(),
other.getImageFilter().get()))
return false;
if (!getShader() != !other.getShader())
return false;
if (getShader() && *getShader() != *other.getShader())
return false;
return true;
}
bool PaintFlags::HasDiscardableImages() const { bool PaintFlags::HasDiscardableImages() const {
if (!shader_) if (!shader_)
return false; return false;
......
...@@ -218,6 +218,8 @@ class CC_PAINT_EXPORT PaintFlags { ...@@ -218,6 +218,8 @@ class CC_PAINT_EXPORT PaintFlags {
SkPaint ToSkPaint() const; SkPaint ToSkPaint() const;
bool IsValid() const; bool IsValid() const;
bool operator==(const PaintFlags& other) const;
bool operator!=(const PaintFlags& other) const { return !(*this == other); }
bool HasDiscardableImages() const; bool HasDiscardableImages() const;
......
...@@ -31,15 +31,29 @@ PaintImage& PaintImage::operator=(const PaintImage& other) = default; ...@@ -31,15 +31,29 @@ PaintImage& PaintImage::operator=(const PaintImage& other) = default;
PaintImage& PaintImage::operator=(PaintImage&& other) = default; PaintImage& PaintImage::operator=(PaintImage&& other) = default;
bool PaintImage::operator==(const PaintImage& other) const { bool PaintImage::operator==(const PaintImage& other) const {
return sk_image_ == other.sk_image_ && paint_record_ == other.paint_record_ && if (sk_image_ != other.sk_image_)
paint_record_rect_ == other.paint_record_rect_ && return false;
paint_record_content_id_ == other.paint_record_content_id_ && if (paint_record_ != other.paint_record_)
paint_image_generator_ == other.paint_image_generator_ && return false;
id_ == other.id_ && animation_type_ == other.animation_type_ && if (paint_record_rect_ != other.paint_record_rect_)
completion_state_ == other.completion_state_ && return false;
subset_rect_ == other.subset_rect_ && if (paint_record_content_id_ != other.paint_record_content_id_)
frame_index_ == other.frame_index_ && return false;
is_multipart_ == other.is_multipart_; if (paint_image_generator_ != other.paint_image_generator_)
return false;
if (id_ != other.id_)
return false;
if (animation_type_ != other.animation_type_)
return false;
if (completion_state_ != other.completion_state_)
return false;
if (subset_rect_ != other.subset_rect_)
return false;
if (frame_index_ != other.frame_index_)
return false;
if (is_multipart_ != other.is_multipart_)
return false;
return true;
} }
// static // static
......
...@@ -106,6 +106,7 @@ class CC_PAINT_EXPORT PaintImage { ...@@ -106,6 +106,7 @@ class CC_PAINT_EXPORT PaintImage {
PaintImage& operator=(PaintImage&& other); PaintImage& operator=(PaintImage&& other);
bool operator==(const PaintImage& other) const; bool operator==(const PaintImage& other) const;
bool operator!=(const PaintImage& other) const { return !(*this == other); }
// Returns the smallest size that is at least as big as the requested_size // Returns the smallest size that is at least as big as the requested_size
// such that we can decode to exactly that scale. If the requested size is // such that we can decode to exactly that scale. If the requested size is
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -394,4 +394,53 @@ bool PaintShader::IsValid() const { ...@@ -394,4 +394,53 @@ bool PaintShader::IsValid() const {
return false; return false;
} }
bool PaintShader::operator==(const PaintShader& other) const {
if (shader_type_ != other.shader_type_)
return false;
if (flags_ != other.flags_)
return false;
if (end_radius_ != other.end_radius_)
return false;
if (start_radius_ != other.start_radius_)
return false;
if (tx_ != other.tx_)
return false;
if (ty_ != other.ty_)
return false;
if (fallback_color_ != other.fallback_color_)
return false;
if (scaling_behavior_ != other.scaling_behavior_)
return false;
if (local_matrix_) {
if (!other.local_matrix_.has_value())
return false;
if (*local_matrix_ != *other.local_matrix_)
return false;
} else {
if (other.local_matrix_.has_value())
return false;
}
if (center_ != other.center_)
return false;
if (tile_ != other.tile_)
return false;
if (start_point_ != other.start_point_)
return false;
if (end_point_ != other.end_point_)
return false;
if (start_degrees_ != other.start_degrees_)
return false;
if (end_degrees_ != other.end_degrees_)
return false;
// TODO(enne): add comparison of records once those are serialized.
// TODO(enne): add comparison of images once those are serialized.
if (colors_ != other.colors_)
return false;
if (positions_ != other.positions_)
return false;
return true;
}
} // namespace cc } // namespace cc
...@@ -126,6 +126,9 @@ class CC_PAINT_EXPORT PaintShader : public SkRefCnt { ...@@ -126,6 +126,9 @@ class CC_PAINT_EXPORT PaintShader : public SkRefCnt {
// shader is correct is hard. // shader is correct is hard.
bool IsValid() const; bool IsValid() const;
bool operator==(const PaintShader& other) const;
bool operator!=(const PaintShader& other) const { return !(*this == other); }
private: private:
friend class PaintFlags; friend class PaintFlags;
friend class PaintOpReader; friend class PaintOpReader;
......
...@@ -19,7 +19,7 @@ namespace cc { ...@@ -19,7 +19,7 @@ namespace cc {
// implementation should be limited ot the header. // implementation should be limited ot the header.
class PaintOpHelper { class PaintOpHelper {
public: public:
static std::string ToString(PaintOp* base_op) { static std::string ToString(const PaintOp* base_op) {
std::ostringstream str; std::ostringstream str;
str << std::boolalpha; str << std::boolalpha;
switch (base_op->GetType()) { switch (base_op->GetType()) {
...@@ -378,4 +378,8 @@ class PaintOpHelper { ...@@ -378,4 +378,8 @@ class PaintOpHelper {
} // namespace cc } // namespace cc
inline ::std::ostream& operator<<(::std::ostream& os, const cc::PaintOp& op) {
return os << cc::PaintOpHelper::ToString(&op);
}
#endif // CC_TEST_PAINT_OP_HELPER_H_ #endif // CC_TEST_PAINT_OP_HELPER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment