[Impeller] migrated one test over from aiks to dl (flutter/engine#52786)

A redo of https://github.com/flutter/engine/pull/52711 that maintains
our existing testing patterns.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat

---------

Co-authored-by: jonahwilliams <jonahwilliams@google.com>
This commit is contained in:
gaaclarke
2024-05-14 09:46:06 -07:00
committed by GitHub
parent e6f329968d
commit cbac232591
8 changed files with 71 additions and 26 deletions

View File

@@ -138,6 +138,7 @@
../../../flutter/impeller/compiler/shader_bundle_unittests.cc
../../../flutter/impeller/compiler/switches_unittests.cc
../../../flutter/impeller/core/allocator_unittests.cc
../../../flutter/impeller/display_list/aiks_dl_path_unittests.cc
../../../flutter/impeller/display_list/dl_golden_unittests.cc
../../../flutter/impeller/display_list/dl_golden_unittests.h
../../../flutter/impeller/display_list/dl_unittests.cc

View File

@@ -30,6 +30,7 @@ struct DlColor {
static constexpr DlColor kDarkGrey() {return DlColor(0xFF3F3F3F);};
static constexpr DlColor kMidGrey() {return DlColor(0xFF808080);};
static constexpr DlColor kLightGrey() {return DlColor(0xFFC0C0C0);};
static constexpr DlColor kAliceBlue() {return DlColor(0xFFF0F8FF);};
// clang-format on
constexpr bool isOpaque() const { return getAlpha() == 0xFF; }

View File

@@ -51,6 +51,8 @@ impeller_component("aiks_playground") {
deps = [
":aiks",
"../playground:playground_test",
"//flutter/display_list",
"//flutter/impeller/display_list:display_list",
]
public_deps = [
"//flutter/impeller/typographer/backends/skia:typographer_skia_backend",

View File

@@ -17,31 +17,6 @@
namespace impeller {
namespace testing {
TEST_P(AiksTest, RotateColorFilteredPath) {
Canvas canvas;
canvas.Concat(Matrix::MakeTranslation({300, 300}));
canvas.Concat(Matrix::MakeRotationZ(Radians(kPiOver2)));
auto arrow_stem =
PathBuilder{}.MoveTo({120, 190}).LineTo({120, 50}).TakePath();
auto arrow_head = PathBuilder{}
.MoveTo({50, 120})
.LineTo({120, 190})
.LineTo({190, 120})
.TakePath();
auto paint = Paint{
.stroke_width = 15.0,
.stroke_cap = Cap::kRound,
.stroke_join = Join::kRound,
.style = Paint::Style::kStroke,
.color_filter =
ColorFilter::MakeBlend(BlendMode::kSourceIn, Color::AliceBlue()),
};
canvas.DrawPath(arrow_stem, paint);
canvas.DrawPath(arrow_head, paint);
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
TEST_P(AiksTest, CanRenderStrokes) {
Canvas canvas;
Paint paint;

View File

@@ -7,6 +7,7 @@
#include <memory>
#include "impeller/aiks/aiks_context.h"
#include "impeller/display_list/dl_dispatcher.h"
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
#include "impeller/typographer/typographer_context.h"
@@ -63,4 +64,12 @@ bool AiksPlayground::ImGuiBegin(const char* name,
return true;
}
bool AiksPlayground::OpenPlaygroundHere(
const sk_sp<flutter::DisplayList>& list) {
DlDispatcher dispatcher;
list->Dispatch(dispatcher);
Picture picture = dispatcher.EndRecordingAsPicture();
return OpenPlaygroundHere(std::move(picture));
}
} // namespace impeller

View File

@@ -5,6 +5,7 @@
#ifndef FLUTTER_IMPELLER_AIKS_AIKS_PLAYGROUND_H_
#define FLUTTER_IMPELLER_AIKS_AIKS_PLAYGROUND_H_
#include "flutter/display_list/display_list.h"
#include "impeller/aiks/aiks_context.h"
#include "impeller/aiks/aiks_playground_inspector.h"
#include "impeller/aiks/picture.h"
@@ -32,6 +33,8 @@ class AiksPlayground : public PlaygroundTest {
bool OpenPlaygroundHere(AiksPlaygroundCallback callback);
bool OpenPlaygroundHere(const sk_sp<flutter::DisplayList>& list);
static bool ImGuiBegin(const char* name,
bool* p_open,
ImGuiWindowFlags flags);

View File

@@ -52,6 +52,7 @@ impeller_component("display_list") {
template("display_list_unittests_component") {
target_name = invoker.target_name
predefined_sources = [
"aiks_dl_path_unittests.cc",
"dl_golden_unittests.cc",
"dl_playground.cc",
"dl_playground.h",
@@ -74,7 +75,12 @@ template("display_list_unittests_component") {
}
sources = predefined_sources + additional_sources
deps = [
if (defined(invoker.deps)) {
deps = invoker.deps
} else {
deps = []
}
deps += [
":display_list",
"../playground:playground_test",
"//flutter/impeller/scene",
@@ -88,9 +94,11 @@ template("display_list_unittests_component") {
}
display_list_unittests_component("display_list_unittests") {
deps = [ "//flutter/impeller/aiks:aiks_unittests" ]
}
display_list_unittests_component("display_list_unittests_golden") {
deps = [ "//flutter/impeller/aiks:aiks_unittests_golden" ]
defines = [
"IMPELLER_GOLDEN_TESTS",
"IMPELLER_ENABLE_VALIDATION=1",

View File

@@ -0,0 +1,46 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/impeller/aiks/aiks_unittests.h"
#include "flutter/display_list/dl_blend_mode.h"
#include "flutter/display_list/dl_builder.h"
#include "flutter/display_list/dl_color.h"
#include "flutter/display_list/dl_paint.h"
#include "flutter/display_list/effects/dl_color_filter.h"
#include "flutter/testing/testing.h"
namespace impeller {
namespace testing {
using namespace flutter;
TEST_P(AiksTest, RotateColorFilteredPath) {
DisplayListBuilder builder;
builder.Transform(SkMatrix::Translate(300, 300) * SkMatrix::RotateDeg(90));
SkPath arrow_stem;
SkPath arrow_head;
arrow_stem.moveTo({120, 190}).lineTo({120, 50});
arrow_head.moveTo({50, 120}).lineTo({120, 190}).lineTo({190, 120});
auto filter =
DlBlendColorFilter::Make(DlColor::kAliceBlue(), DlBlendMode::kSrcIn);
DlPaint paint;
paint.setStrokeWidth(15.0);
paint.setStrokeCap(DlStrokeCap::kRound);
paint.setStrokeJoin(DlStrokeJoin::kRound);
paint.setDrawStyle(DlDrawStyle::kStroke);
paint.setColorFilter(filter);
paint.setColor(DlColor::kBlack());
builder.DrawPath(arrow_stem, paint);
builder.DrawPath(arrow_head, paint);
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
} // namespace testing
} // namespace impeller