Skip to content

Commit

Permalink
Verbose display list comparisons (flutter#32737)
Browse files Browse the repository at this point in the history
  • Loading branch information
flar authored Apr 20, 2022
1 parent 47af169 commit 1ef3f75
Show file tree
Hide file tree
Showing 11 changed files with 1,105 additions and 29 deletions.
11 changes: 7 additions & 4 deletions display_list/display_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,19 @@ void DisplayList::RenderTo(SkCanvas* canvas, SkScalar opacity) const {
Dispatch(dispatcher);
}

bool DisplayList::Equals(const DisplayList& other) const {
if (byte_count_ != other.byte_count_ || op_count_ != other.op_count_) {
bool DisplayList::Equals(const DisplayList* other) const {
if (this == other) {
return true;
}
if (byte_count_ != other->byte_count_ || op_count_ != other->op_count_) {
return false;
}
uint8_t* ptr = storage_.get();
uint8_t* o_ptr = other.storage_.get();
uint8_t* o_ptr = other->storage_.get();
if (ptr == o_ptr) {
return true;
}
return CompareOps(ptr, ptr + byte_count_, o_ptr, o_ptr + other.byte_count_);
return CompareOps(ptr, ptr + byte_count_, o_ptr, o_ptr + other->byte_count_);
}

} // namespace flutter
6 changes: 5 additions & 1 deletion display_list/display_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ class DisplayList : public SkRefCnt {
return bounds_;
}

bool Equals(const DisplayList& other) const;
bool Equals(const DisplayList* other) const;
bool Equals(const DisplayList& other) const { return Equals(&other); }
bool Equals(sk_sp<const DisplayList> other) const {
return Equals(other.get());
}

bool can_apply_group_opacity() { return can_apply_group_opacity_; }

Expand Down
14 changes: 14 additions & 0 deletions display_list/display_list_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,20 @@ void DisplayListBuilder::transformFullPerspective(
void DisplayListBuilder::transformReset() {
Push<TransformResetOp>(0, 0);
}
void DisplayListBuilder::transform(const SkMatrix* matrix) {
if (matrix != nullptr) {
transform(SkM44(*matrix));
}
}
void DisplayListBuilder::transform(const SkM44* m44) {
if (m44 != nullptr) {
transformFullPerspective(
m44->rc(0, 0), m44->rc(0, 1), m44->rc(0, 2), m44->rc(0, 3),
m44->rc(1, 0), m44->rc(1, 1), m44->rc(1, 2), m44->rc(1, 3),
m44->rc(2, 0), m44->rc(2, 1), m44->rc(2, 2), m44->rc(2, 3),
m44->rc(3, 0), m44->rc(3, 1), m44->rc(3, 2), m44->rc(3, 3));
}
}

void DisplayListBuilder::clipRect(const SkRect& rect,
SkClipOp clip_op,
Expand Down
4 changes: 4 additions & 0 deletions display_list/display_list_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ class DisplayListBuilder final : public virtual Dispatcher,
SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) override;
// clang-format on
void transformReset() override;
void transform(const SkMatrix* matrix);
void transform(const SkM44* matrix44);
void transform(const SkMatrix& matrix) { transform(&matrix); }
void transform(const SkM44& matrix44) { transform(&matrix44); }

void clipRect(const SkRect& rect, SkClipOp clip_op, bool is_aa) override;
void clipRRect(const SkRRect& rrect, SkClipOp clip_op, bool is_aa) override;
Expand Down
9 changes: 2 additions & 7 deletions display_list/display_list_canvas_recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ sk_sp<DisplayList> DisplayListCanvasRecorder::Build() {

// clang-format off
void DisplayListCanvasRecorder::didConcat44(const SkM44& m44) {
// transform4x4 takes a full 4x4 transform in row major order
builder_->transformFullPerspective(
m44.rc(0, 0), m44.rc(0, 1), m44.rc(0, 2), m44.rc(0, 3),
m44.rc(1, 0), m44.rc(1, 1), m44.rc(1, 2), m44.rc(1, 3),
m44.rc(2, 0), m44.rc(2, 1), m44.rc(2, 2), m44.rc(2, 3),
m44.rc(3, 0), m44.rc(3, 1), m44.rc(3, 2), m44.rc(3, 3));
builder_->transform(m44);
}
// clang-format on
void DisplayListCanvasRecorder::didSetM44(const SkM44& matrix) {
builder_->transformReset();
didConcat44(matrix);
builder_->transform(matrix);
}
void DisplayListCanvasRecorder::didTranslate(SkScalar tx, SkScalar ty) {
builder_->translate(tx, ty);
Expand Down
5 changes: 3 additions & 2 deletions display_list/display_list_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "flutter/display_list/display_list_canvas_recorder.h"
#include "flutter/display_list/display_list_utils.h"
#include "flutter/fml/math.h"
#include "flutter/testing/display_list_testing.h"
#include "flutter/testing/testing.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkSurface.h"
Expand Down Expand Up @@ -860,10 +861,10 @@ TEST(DisplayList, SingleOpDisplayListsNotEqualEmpty) {
auto desc =
group.op_name + "(variant " + std::to_string(i + 1) + " != empty)";
if (group.variants[i].is_empty()) {
ASSERT_TRUE(dl->Equals(*empty)) << desc;
ASSERT_TRUE(DisplayListsEQ_Verbose(dl, empty));
ASSERT_TRUE(empty->Equals(*dl)) << desc;
} else {
ASSERT_FALSE(dl->Equals(*empty)) << desc;
ASSERT_TRUE(DisplayListsNE_Verbose(dl, empty));
ASSERT_FALSE(empty->Equals(*dl)) << desc;
}
}
Expand Down
32 changes: 17 additions & 15 deletions flow/layers/opacity_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "flutter/flow/testing/layer_test.h"
#include "flutter/flow/testing/mock_layer.h"
#include "flutter/fml/macros.h"
#include "flutter/testing/display_list_testing.h"
#include "flutter/testing/mock_canvas.h"

namespace flutter {
Expand Down Expand Up @@ -302,23 +303,24 @@ TEST_F(OpacityLayerTest, HalfTransparent) {
SkRect opacity_bounds;
expected_layer_bounds.makeOffset(-layer_offset.fX, -layer_offset.fY)
.roundOut(&opacity_bounds);
auto expected_draw_calls = std::vector(
{MockCanvas::DrawCall{0, MockCanvas::SaveData{1}},
MockCanvas::DrawCall{
1, MockCanvas::ConcatMatrixData{SkM44(layer_transform)}},

auto expected_builder = DisplayListBuilder();
expected_builder.save();
expected_builder.translate(layer_offset.fX, layer_offset.fY);
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
MockCanvas::DrawCall{
1, MockCanvas::SetMatrixData{SkM44(integral_layer_transform)}},
expected_builder.transformReset();
expected_builder.transform(SkM44(integral_layer_transform));
#endif
MockCanvas::DrawCall{
1, MockCanvas::SaveLayerData{opacity_bounds, opacity_paint, nullptr,
2}},
MockCanvas::DrawCall{2,
MockCanvas::DrawPathData{child_path, child_paint}},
MockCanvas::DrawCall{2, MockCanvas::RestoreData{1}},
MockCanvas::DrawCall{1, MockCanvas::RestoreData{0}}});
layer->Paint(paint_context());
EXPECT_EQ(mock_canvas().draw_calls(), expected_draw_calls);
expected_builder.setColor(alpha_half << 24);
expected_builder.saveLayer(&opacity_bounds, true);
expected_builder.setColor(SkColors::kGreen.toSkColor());
expected_builder.drawPath(child_path);
expected_builder.restore();
expected_builder.restore();
sk_sp<DisplayList> expected_display_list = expected_builder.Build();

layer->Paint(display_list_paint_context());
EXPECT_TRUE(DisplayListsEQ_Verbose(display_list(), expected_display_list));
}

TEST_F(OpacityLayerTest, Nested) {
Expand Down
38 changes: 38 additions & 0 deletions flow/testing/layer_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "flutter/flow/testing/mock_raster_cache.h"
#include "flutter/fml/macros.h"
#include "flutter/testing/canvas_test.h"
#include "flutter/testing/display_list_testing.h"
#include "flutter/testing/mock_canvas.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkImageInfo.h"
Expand Down Expand Up @@ -71,6 +72,23 @@ class LayerTestBase : public CanvasTestBase<BaseT> {
.frame_device_pixel_ratio = 1.0f,
// clang-format on
},
display_list_recorder_(kGiantRect),
internal_display_list_canvas_(kGiantRect.width(), kGiantRect.height()),
display_list_paint_context_{
// clang-format off
.internal_nodes_canvas = &internal_display_list_canvas_,
.leaf_nodes_canvas = &display_list_recorder_,
.gr_context = nullptr,
.view_embedder = nullptr,
.raster_time = raster_time_,
.ui_time = ui_time_,
.texture_registry = texture_registry_,
.raster_cache = nullptr,
.checkerboard_offscreen_layers = false,
.frame_device_pixel_ratio = 1.0f,
.leaf_nodes_builder = display_list_recorder_.builder().get(),
// clang-format on
},
check_board_context_{
// clang-format off
.internal_nodes_canvas = TestT::mock_internal_canvas(),
Expand All @@ -85,6 +103,7 @@ class LayerTestBase : public CanvasTestBase<BaseT> {
.frame_device_pixel_ratio = 1.0f,
// clang-format on
} {
internal_display_list_canvas_.addCanvas(&display_list_recorder_);
use_null_raster_cache();
}

Expand Down Expand Up @@ -141,9 +160,24 @@ class LayerTestBase : public CanvasTestBase<BaseT> {
RasterCache* raster_cache() { return raster_cache_.get(); }
PrerollContext* preroll_context() { return &preroll_context_; }
Layer::PaintContext& paint_context() { return paint_context_; }
Layer::PaintContext& display_list_paint_context() {
return display_list_paint_context_;
}
Layer::PaintContext& check_board_context() { return check_board_context_; }
LayerSnapshotStore& layer_snapshot_store() { return snapshot_store_; }

sk_sp<DisplayList> display_list() {
if (display_list_ == nullptr) {
display_list_ = display_list_recorder_.Build();
// null out the canvas and recorder fields of the PaintContext
// to prevent future use.
display_list_paint_context_.leaf_nodes_canvas = nullptr;
display_list_paint_context_.internal_nodes_canvas = nullptr;
display_list_paint_context_.leaf_nodes_builder = nullptr;
}
return display_list_;
}

void enable_leaf_layer_tracing() {
paint_context_.enable_leaf_layer_tracing = true;
paint_context_.layer_snapshot_store = &snapshot_store_;
Expand All @@ -169,6 +203,10 @@ class LayerTestBase : public CanvasTestBase<BaseT> {
std::unique_ptr<RasterCache> raster_cache_;
PrerollContext preroll_context_;
Layer::PaintContext paint_context_;
DisplayListCanvasRecorder display_list_recorder_;
sk_sp<DisplayList> display_list_;
SkNWayCanvas internal_display_list_canvas_;
Layer::PaintContext display_list_paint_context_;
Layer::PaintContext check_board_context_;
LayerSnapshotStore snapshot_store_;

Expand Down
3 changes: 3 additions & 0 deletions testing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ source_set("testing_lib") {

sources = [
"assertions.h",
"display_list_testing.cc",
"display_list_testing.h",
"post_task_sync.cc",
"post_task_sync.h",
"testing.cc",
Expand All @@ -26,6 +28,7 @@ source_set("testing_lib") {
]

public_deps = [
"//flutter/display_list",
"//flutter/fml",
"//third_party/googletest:gmock",
"//third_party/googletest:gtest",
Expand Down
Loading

0 comments on commit 1ef3f75

Please sign in to comment.