Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web] Update SurfacePath to use PathRef #19557

Merged
merged 17 commits into from
Jul 9, 2020
Merged

Conversation

ferhatb
Copy link
Contributor

@ferhatb ferhatb commented Jul 7, 2020

Description

Moves SurfacePath to use skia based PathRef with points,verbs and conicWeights.
Implement convexity/winding.

Related Issues

Related: flutter/flutter#44572, flutter/flutter#57682

Tests

I added the following tests:
path_winding_test.dart.
Updated path_test and path_metrics_test.dart.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the [contributor guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [C++, Objective-C, Java style guides] for the engine.
  • I read the [tree hygiene] wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read [handling breaking changes].

Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM. Most comments are about making the Dart port of the Skia path code more Darty/efficient

static const int kInitialPointsCapacity = 8;
static const int kInitialVerbsCapacity = 8;

/// Returns a const pointer to the first point.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stray comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

///
/// Tracking whether a path is an oval is considered an
/// optimization for performance and so some paths that are in
// fact ovals can report false.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: should be a /// comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


static Uint8List _fVerbsFromSource(PathRef source) {
Uint8List verbs = Uint8List(source._fVerbsCapacity);
js_util.callMethod(verbs, 'set', <dynamic>[source._fVerbs]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use verbs.setAll(0, source._fVerbs) and dart2js will call set under the hood but without having to go through all of the overhead of JS-interop: https://github.com/dart-lang/sdk/blob/master/sdk/lib/_internal/js_runtime/lib/native_typed_data.dart#L692

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

_conicWeightsLength = source._conicWeightsLength;
if (source._conicWeights != null) {
_conicWeights = Float32List(_conicWeightsCapacity);
js_util
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use setAll here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
_fVerbsCapacity = source._fVerbsCapacity;
_fVerbsLength = source._fVerbsLength;
_fVerbs = Uint8List(_fVerbsCapacity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these 2 lines are redundant because we already initialized _fVerbs = _fVerbsFromSource(source) in the initializers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

resetToSize(verbCount, pointCount, weightCount, additionalReserveVerbs,
additionalReservePoints);

js_util.callMethod(_fVerbs, 'set', [ref._fVerbs]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto above re: setAll

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

fSegmentMask = 0;
startEdit();

_resizePoints(pointCount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use reservePoints here and reserveVerbs below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks for finding this.

if (numVerbs != 0) {
int curLength = countVerbs();
_resizePoints(curLength + numVerbs);
for (int i = 0; i < numVerbs; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably also do setAll here too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
final PathRefIterator iter = PathRefIterator(path.pathRef);
int verb = 0;
final Float32List outPts = Float32List(10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can be length 8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added a const to PageRefIterator.

@@ -509,69 +509,47 @@ class _CanvasPool extends _SaveStackTracking {
}
}

// Float buffer used for path iteration.
static Float32List _runBuffer = Float32List(10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can be length 8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ferhatb
Copy link
Contributor Author

ferhatb commented Jul 9, 2020

bench_path_recording.html.recordPathConstruction.average 4083.45 (4.12%) 4918.23 (2.12%) 0.83x
bench_path_recording.html.recordPathConstruction.outlierRatio 1.15 (2.19%) 1.28 (2.51%) 0.90x

mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants