Skip to content

Commit 1156eb5

Browse files
committed
migrate recently added Mutators code
1 parent 85d7e25 commit 1156eb5

File tree

6 files changed

+62
-41
lines changed

6 files changed

+62
-41
lines changed

engine/src/flutter/display_list/geometry/dl_path.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const SkPath& DlPath::GetSkPath() const {
106106
return sk_path.value();
107107
}
108108

109-
Path DlPath::GetPath() const {
109+
const Path& DlPath::GetPath() const {
110110
auto& sk_path = data_->sk_path;
111111
auto& path = data_->path;
112112
if (path.has_value()) {

engine/src/flutter/display_list/geometry/dl_path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class DlPath {
6767
DlPath& operator=(const DlPath&) = default;
6868

6969
const SkPath& GetSkPath() const;
70-
impeller::Path GetPath() const;
70+
const impeller::Path& GetPath() const;
7171

7272
/// Intent to render an SkPath multiple times will make the path
7373
/// non-volatile to enable caching in Skia. Calling this method

engine/src/flutter/display_list/skia/dl_sk_conversions_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ TEST(DisplayListSkConversions, ConicPathToQuads) {
422422
sk_path.conicTo(20, 10, 20, 20, weight);
423423

424424
DlPath dl_path(sk_path);
425-
impeller::Path i_path = dl_path.GetPath();
425+
const impeller::Path& i_path = dl_path.GetPath();
426426

427427
auto it = i_path.begin();
428428
ASSERT_EQ(it.type(), impeller::Path::ComponentType::kContour);

engine/src/flutter/shell/platform/android/platform_view_android_jni_impl.cc

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,56 +2122,78 @@ void PlatformViewAndroidJNIImpl::onDisplayPlatformView2(
21222122
break;
21232123
}
21242124
case MutatorType::kClipPath: {
2125-
const SkPath& path = (*iter)->GetPath();
2126-
2127-
// Define and populate an Android Path with data from the Skia SkPath
2125+
// Define and populate an Android Path with data from the DlPath
21282126
jobject androidPath =
21292127
env->NewObject(path_class->obj(), path_constructor);
21302128

2131-
SkPath::Iter pathIter(path, false);
2132-
SkPoint points[4];
2133-
SkPath::Verb verb;
2129+
bool subpath_needs_close = false;
2130+
std::optional<flutter::DlPoint> pending_moveto;
2131+
2132+
auto resolve_moveto = [&env, &pending_moveto, &androidPath]() {
2133+
if (pending_moveto.has_value()) {
2134+
env->CallVoidMethod(androidPath, path_move_to_method,
2135+
pending_moveto->x, pending_moveto->y);
2136+
pending_moveto.reset();
2137+
}
2138+
};
21342139

2135-
while ((verb = pathIter.next(points)) != SkPath::kDone_Verb) {
2136-
switch (verb) {
2137-
case SkPath::kMove_Verb: {
2138-
env->CallVoidMethod(androidPath, path_move_to_method,
2139-
points[0].fX, points[0].fY);
2140+
auto& path = (*iter)->GetPath().GetPath();
2141+
for (auto it = path.begin(), end = path.end(); it != end; ++it) {
2142+
switch (it.type()) {
2143+
case impeller::Path::ComponentType::kContour: {
2144+
const impeller::ContourComponent* contour = it.contour();
2145+
FML_DCHECK(contour != nullptr);
2146+
if (subpath_needs_close) {
2147+
env->CallVoidMethod(androidPath, path_close_method);
2148+
}
2149+
pending_moveto = contour->destination;
2150+
subpath_needs_close = contour->IsClosed();
21402151
break;
21412152
}
2142-
case SkPath::kLine_Verb: {
2153+
case impeller::Path::ComponentType::kLinear: {
2154+
const impeller::LinearPathComponent* linear = it.linear();
2155+
FML_DCHECK(linear != nullptr);
2156+
resolve_moveto();
21432157
env->CallVoidMethod(androidPath, path_line_to_method,
2144-
points[1].fX, points[1].fY);
2158+
linear->p2.x, linear->p2.y);
21452159
break;
21462160
}
2147-
case SkPath::kQuad_Verb: {
2161+
case impeller::Path::ComponentType::kQuadratic: {
2162+
const impeller::QuadraticPathComponent* quadratic =
2163+
it.quadratic();
2164+
FML_DCHECK(quadratic != nullptr);
2165+
resolve_moveto();
21482166
env->CallVoidMethod(androidPath, path_quad_to_method,
2149-
points[1].fX, points[1].fY, points[2].fX,
2150-
points[2].fY);
2151-
break;
2152-
}
2153-
case SkPath::kCubic_Verb: {
2154-
env->CallVoidMethod(androidPath, path_cubic_to_method,
2155-
points[1].fX, points[1].fY, points[2].fX,
2156-
points[2].fY, points[3].fX, points[3].fY);
2167+
quadratic->cp.x, quadratic->cp.y,
2168+
quadratic->p2.x, quadratic->p2.y);
21572169
break;
21582170
}
2159-
case SkPath::kConic_Verb: {
2171+
case impeller::Path::ComponentType::kConic: {
2172+
const impeller::ConicPathComponent* conic = it.conic();
2173+
FML_DCHECK(conic != nullptr);
2174+
resolve_moveto();
21602175
FML_DCHECK(path_conic_to_method != nullptr);
21612176
env->CallVoidMethod(androidPath, path_conic_to_method,
2162-
points[1].fX, points[1].fY, points[2].fX,
2163-
points[2].fY, pathIter.conicWeight());
2177+
conic->cp.x, conic->cp.y, //
2178+
conic->p2.x, conic->p2.y, conic->weight);
21642179
break;
21652180
}
2166-
2167-
case SkPath::kClose_Verb: {
2168-
env->CallVoidMethod(androidPath, path_close_method);
2181+
case impeller::Path::ComponentType::kCubic: {
2182+
const impeller::CubicPathComponent* cubic = it.cubic();
2183+
FML_DCHECK(cubic != nullptr);
2184+
resolve_moveto();
2185+
env->CallVoidMethod(androidPath, path_cubic_to_method,
2186+
cubic->cp1.x, cubic->cp1.y, //
2187+
cubic->cp2.x, cubic->cp2.y, //
2188+
cubic->p2.x, cubic->p2.y);
21692189
break;
21702190
}
2171-
default:
2172-
break;
21732191
}
21742192
}
2193+
if (subpath_needs_close) {
2194+
env->CallVoidMethod(androidPath, path_close_method);
2195+
}
2196+
21752197
env->CallVoidMethod(mutatorsStack,
21762198
g_mutators_stack_push_clippath_method, androidPath);
21772199
}

engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ - (void)clipPath:(const flutter::DlPath&)dlPath matrix:(const flutter::DlMatrix&
393393
}
394394
};
395395

396-
auto path = dlPath.GetPath();
396+
auto& path = dlPath.GetPath();
397397
for (auto it = path.begin(), end = path.end(); it != end; ++it) {
398398
switch (it.type()) {
399399
case impeller::Path::ComponentType::kContour: {

engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4509,17 +4509,16 @@ - (void)testResetClearsPreviousCompositionOrder {
45094509
// Create embedded view params
45104510
flutter::MutatorsStack stack;
45114511
// Layer tree always pushes a screen scale factor to the stack
4512-
CGFloat screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale;
4513-
SkMatrix screenScaleMatrix = SkMatrix::Scale(screenScale, screenScale);
4512+
flutter::DlScalar screenScale = [mockFlutterViewController flutterScreenIfViewLoaded].scale;
4513+
flutter::DlMatrix screenScaleMatrix = flutter::DlMatrix::MakeScale({screenScale, screenScale, 1});
45144514
stack.PushTransform(screenScaleMatrix);
45154515
// Push a translate matrix
4516-
SkMatrix translateMatrix = SkMatrix::Translate(100, 100);
4516+
flutter::DlMatrix translateMatrix = flutter::DlMatrix::MakeTranslation({100, 100});
45174517
stack.PushTransform(translateMatrix);
4518-
SkMatrix finalMatrix;
4519-
finalMatrix.setConcat(screenScaleMatrix, translateMatrix);
4518+
flutter::DlMatrix finalMatrix = screenScaleMatrix * translateMatrix;
45204519

4521-
auto embeddedViewParams =
4522-
std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
4520+
auto embeddedViewParams = std::make_unique<flutter::EmbeddedViewParams>(
4521+
flutter::ToSkMatrix(finalMatrix), SkSize::Make(300, 300), stack);
45234522

45244523
[flutterPlatformViewsController prerollCompositeEmbeddedView:2
45254524
withParams:std::move(embeddedViewParams)];

0 commit comments

Comments
 (0)