Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Dec 11, 2019

Refactor the HTML vs CanvasKit a bit more:

  • Move more html-backend classes under surface/ so they don't pollute the canvaskit API.
  • Introduce SkPaint.

There should be no functional changes. This prepares code for a future change that will allow managing Skia objects more efficiently (caching and deleting reusable objects, such as Paint, Path, and Paragraph).

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

I didn't realize this was a refactor until I've already added some comments on the code. Feel free to consider them at a later PR. The refactoring looks good to me, didn't notice anything out of place. I'll let someone who knows the web code make the call if it's kosher.


static const ui.Color _defaultPaintColor = ui.Color(0xFF000000);

ui.BlendMode get blendMode => _blendMode;
Copy link
Member

Choose a reason for hiding this comment

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

The linter doesn't complain that all public components should have a docstring?

Copy link
Contributor

Choose a reason for hiding this comment

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

The code in engine is in a private dart library dart:_engine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! This reminded me to add @override annotations on these.


skPaint.callMethod('setAntiAlias', <bool>[isAntiAlias]);

if (strokeWidth != 0.0) {
Copy link
Member

Choose a reason for hiding this comment

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

if (strokeWidth > 0.0)?

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 ui.BlurStyle blurStyle = maskFilter.webOnlyBlurStyle;
final double sigma = maskFilter.webOnlySigma;

js.JsObject skBlurStyle;
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't all these switch statements be condensed to 2 expressions?

_dict = {ui.BlurStyle.normal:'Normal', ui.BlurStyle.solid:'Solid',...};
js.JsObject skBlurStyle = canvasKit['BlurStyle'][_dict[blurStyle]];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The long-term solution is to canonicalize these values in a static location so we don't have to look them up every time we need them. There are several places in the code that use this pattern. I'm going to leave it as is right now. I moved this code from another file.


part of engine;

/// The implementatin of [ui.Paint] used by the CanvasKit backend.
Copy link
Contributor

Choose a reason for hiding this comment

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

implementatin -> implementation

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.

fillType = ui.PathFillType.nonZero;
}

SkPath.from(SkPath other) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a TODO to add this

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.

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.

LGTM with a couple nits

@yjbanov yjbanov merged commit 18c89f1 into flutter:master Dec 12, 2019
part of engine;

/// The implementation of [ui.Paint] used by the CanvasKit backend.
class SkPaint implements ui.Paint {
Copy link
Contributor

Choose a reason for hiding this comment

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

fwiw, having multiple implementations of Paint is going to hurt performance as it means everywhere that calls into a Paint now has to do a dynamic lookup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessarily. Since experimentalUseSkia is const, dart2js should be able to figure out that only one non-abstract subclass of Paint is live, and avoid dynamic dispatch. I will double check this

Copy link
Contributor

Choose a reason for hiding this comment

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

Just built the gallery with this change and it looks like dart2js has inlined the SkPaint constructor into every new Paint() call, so dynamic dispatch is avoided. Here's a sample function that creates a Paint:

skpaint-verify

filmil pushed a commit to filmil/engine that referenced this pull request Mar 13, 2020
* Split surface and canvaskit classes more

* fix licenses

* address comments
@yjbanov yjbanov deleted the cache-sk-paint branch June 22, 2021 21:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants