Skip to content

Commit

Permalink
cc: Add PaintOp::operator==
Browse files Browse the repository at this point in the history
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/777840
Reviewed-by: Khushal <khushalsagar@chromium.org>
Commit-Queue: enne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517675}
  • Loading branch information
quisquous authored and Commit Bot committed Nov 18, 2017
1 parent 4e68cd4 commit 6ac3063
Show file tree
Hide file tree
Showing 10 changed files with 582 additions and 442 deletions.
59 changes: 59 additions & 0 deletions cc/paint/paint_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "cc/paint/paint_flags.h"

#include "cc/paint/paint_op_buffer.h"
#include "third_party/skia/include/core/SkFlattenableSerialization.h"

namespace {

Expand Down Expand Up @@ -128,6 +129,64 @@ bool PaintFlags::IsValid() const {
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 {
if (!shader_)
return false;
Expand Down
2 changes: 2 additions & 0 deletions cc/paint/paint_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class CC_PAINT_EXPORT PaintFlags {
SkPaint ToSkPaint() const;

bool IsValid() const;
bool operator==(const PaintFlags& other) const;
bool operator!=(const PaintFlags& other) const { return !(*this == other); }

bool HasDiscardableImages() const;

Expand Down
32 changes: 23 additions & 9 deletions cc/paint/paint_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,29 @@ PaintImage& PaintImage::operator=(const PaintImage& other) = default;
PaintImage& PaintImage::operator=(PaintImage&& other) = default;

bool PaintImage::operator==(const PaintImage& other) const {
return sk_image_ == other.sk_image_ && paint_record_ == other.paint_record_ &&
paint_record_rect_ == other.paint_record_rect_ &&
paint_record_content_id_ == other.paint_record_content_id_ &&
paint_image_generator_ == other.paint_image_generator_ &&
id_ == other.id_ && animation_type_ == other.animation_type_ &&
completion_state_ == other.completion_state_ &&
subset_rect_ == other.subset_rect_ &&
frame_index_ == other.frame_index_ &&
is_multipart_ == other.is_multipart_;
if (sk_image_ != other.sk_image_)
return false;
if (paint_record_ != other.paint_record_)
return false;
if (paint_record_rect_ != other.paint_record_rect_)
return false;
if (paint_record_content_id_ != other.paint_record_content_id_)
return false;
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
Expand Down
1 change: 1 addition & 0 deletions cc/paint/paint_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class CC_PAINT_EXPORT PaintImage {
PaintImage& operator=(PaintImage&& other);

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
// such that we can decode to exactly that scale. If the requested size is
Expand Down
Loading

0 comments on commit 6ac3063

Please sign in to comment.