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

Conversation

@liyuqian
Copy link
Contributor

@liyuqian liyuqian force-pushed the new_clip_option branch 2 times, most recently from 728e080 to 1fed878 Compare July 2, 2018 18:07
namespace flow {

// This should be an exact copy of the Clip enum in
// flutter/package/flutter/lib/src/paining/basic_types.dart
Copy link
Member

Choose a reason for hiding this comment

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

typo: should be packages/flutter/lib/src/painting/basic_types.dart

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now moves the Clip enum to painting.dart.

// This should be an exact copy of the Clip enum in
// flutter/package/flutter/lib/src/paining/basic_types.dart
//
// We call it Clip in public dart API to provide our developers the shortest
Copy link
Member

Choose a reason for hiding this comment

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

capitalize "Dart"

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.

void _pushClipRRect(Float32List rrect) native 'SceneBuilder_pushClipRRect';
/// See [pop] for details about the operation stack, and [Clip] for different clip modes.
/// By default, the clip will be anti-aliased (clipMode = 1 = Clip::antiAlias).
void pushClipRRect(RRect rrect, [int clipMode = 1]) => _pushClipRRect(rrect._value, clipMode);
Copy link
Member

Choose a reason for hiding this comment

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

Can clipMode be an enum defined in the engine Dart code instead of an int?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah the public Dart API should definitely not be using an int for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

also, prefer named arguments please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I thought that only painting.dart is public and compositing.dart is private. If it's also public, then I shall definitely move the enum Clip definition from flutter/flutter's basic_types.dart into flutter/engine's painting.dart.

///
/// TODO(liyuqian): Set it to Clip.none. (https://github.com/flutter/flutter/issues/18057)
/// We currently have Clip.antiAlias to preserve our old behaviors.
const Clip defaultClipBehavior = Clip.none;
Copy link
Contributor

Choose a reason for hiding this comment

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

we should mark this deprecated so that people don't rely on it (we presumably will remove this in the near future, right?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll remove it once the default behavior switches to Clip.none. Marking as deprecated.


/// The global default value of whether and how to clip a widget.
///
/// TODO(liyuqian): Set it to Clip.none. (https://github.com/flutter/flutter/issues/18057)
Copy link
Contributor

Choose a reason for hiding this comment

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

TODOs shouldn't be in documentation (make this // not ///)

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.

/// See also:
///
/// * [antiAlias], which is much faster, and has similar clipping results.
antiAliasWithSaveLayer
Copy link
Contributor

Choose a reason for hiding this comment

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

trivial nit: missing trailing comma

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.

void pushClipPath(Path path) native 'SceneBuilder_pushClipPath';
/// See [pop] for details about the operation stack. See [Clip] for different clip modes.
/// By default, the clip will be anti-aliased (clip = [Clip.antiAlias]).
void pushClipPath(Path path, {Clip clip = Clip.antiAlias}) => _pushClipPath(path, clip.index);
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens if you push a clip path with Clip.none?

Copy link
Contributor

Choose a reason for hiding this comment

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

and does Clip.antiAliasWithSaveLayer do anything interesting 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.

Push a clip layer (e.g., ClipPath, ClipRRect) with Clip.none will trigger assert: https://github.com/flutter/engine/pull/5647/files#diff-9930584db1fb28d6064ad30841935ac1R51

Clip.antiAliasWithSaveLayer will add a Canvas.saveLayer call: https://github.com/flutter/engine/pull/5647/files#diff-9930584db1fb28d6064ad30841935ac1R55

Copy link
Contributor

@Hixie Hixie Jul 9, 2018

Choose a reason for hiding this comment

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

when you say "assert" do you mean "throw an AssertionError in Dart" or do you mean "crash the 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.

It's a FXL_DCHECK(clip_mode_ != ClipMode::none) just like FXL_DCHECK(needs_painting()). I think that it'll crash the 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.

If I implement correctly, the developer should never see this crash. The dart code check whether it's Clip.none, and if it is, drop the ClipPath layer so the C++ side should never receive any ClipPath/ClipRRect layer with ClipMode::none. If the engine somehow receives it, it's probably a much bigger issue that can't be easily bypassed by hot-reload.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused. What stops someone from calling SceneBuilder.pushClipPath(path, clip = Clip.none) ?

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 ClipPathLayer in Dart (https://github.com/flutter/flutter/pull/18576/files#diff-58600d3d2645a66835eb03f3c41b447bR725) prevents C++ engine to have Clip.none ClipPath.

But now I see that if someone is pushing a ClipPathLayer without using the Dart class ClipPathLayer, then it could be a problem. I'll print a warning and drop the layer instead of crashing then.

Copy link
Contributor

@Hixie Hixie Jul 10, 2018

Choose a reason for hiding this comment

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

I would just assert here, just like we do in other methods in this file.

assert(clip != null);
assert(clip != Clip.none);
_pushClipPath(path, clip.index);

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.

/// [elevation] is greater than 0.0, then a shadow is drawn around the layer.
/// [shadowColor] defines the color of the shadow if present and [color] defines the
/// By default, the layer's content will not be clipped (clip = [Clip.none]).
/// If clipMode is nonzero (Clip.hardEdge, Clip.antiAlias, or Clip.antiAliasWithSaveLayer),
Copy link
Contributor

Choose a reason for hiding this comment

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

please put those values in square brackets

also, rather than "is nonzero" consider "has another value" since the enum values aren't zero.

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! I clearly forgot to update the comment here when I changed int clipMode to Clip clip. Updating now.

@liyuqian
Copy link
Contributor Author

liyuqian commented Jul 9, 2018

@Hixie please let me know if the new changes look good.

// TODO(liyuqian): Set it to Clip.none. (https://github.com/flutter/flutter/issues/18057)
// We currently have Clip.antiAlias to preserve our old behaviors.
@deprecated // we'll eventually remove this and just use Clip.none.
const Clip defaultClipBehavior = Clip.none;
Copy link
Contributor

Choose a reason for hiding this comment

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

the comment doesn't match the value? i'm not sure what the purpose of this is.

Consider using @Deprecated() so you can provide a custom message explaining what this is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to @Deprecated() and Clip.antiAlias. Thanks for catching the mistake!

Copy link
Contributor

Choose a reason for hiding this comment

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

i'm worried that that didn't cause any tests to fail! is there no way to test 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.

My impression is that the flutter/engine is really under-tested. The flutter/flutter CI should definitely catch this failure once we tried to merge the engine change into flutter. Maybe we should have a engine->flutter auto-roller that does the check? It would not only save this change, but many other changes that make engine roll difficult.

Copy link
Contributor

Choose a reason for hiding this comment

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

it'll be less undertested if you add tests. :-)

An autoroller would be very useful. You should definitely feel empowered to work on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Hixie : I'm going to work on the autoroller and I'll rely on the golden tests in flutter/flutter to guard this kind of engine changes. Does that sound good to you? Other than that, any more comments on this CL?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would definitely be happy to trade some unit tests here in order to get an autoroller plus relying on framework tests. :-)

@Hixie
Copy link
Contributor

Hixie commented Jul 10, 2018

LGTM

@liyuqian liyuqian merged commit e1cf837 into flutter:master Jul 13, 2018
@liyuqian liyuqian deleted the new_clip_option branch September 12, 2018 22:51
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.

4 participants