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

Use preTranslate when applying offset to matrix #21648

Merged
merged 1 commit into from Oct 29, 2020

Conversation

@knopp
Copy link
Member

@knopp knopp commented Oct 7, 2020

Description

matrix.preTranslate(x,y) is identical to matrix.setConcat(matrix, SkMatrix::Translate(x,y)) which is the desired effect.

Related Issues

flutter/flutter#33939

Tests

I added the following tests:

OpacityLayerTest.TranslateChildren

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.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
@googlebot googlebot added the cla: yes label Oct 7, 2020
@auto-assign auto-assign bot requested a review from jason-simmons Oct 7, 2020
@knopp knopp requested review from flar and removed request for jason-simmons Oct 7, 2020
@chinmaygarde
Copy link
Member

@chinmaygarde chinmaygarde commented Oct 22, 2020

cc @liyuqian who wrote the original version.

@liyuqian
Copy link
Contributor

@liyuqian liyuqian commented Oct 23, 2020

@knopp : do you happen to also have a sample Flutter app that exhibits the difference before and after this PR? I'm very curious about what triggered you to discover this issue, and I'd like to dive deep to see if there are similar issues in other places (e.g., in PictureLayer). I personally tried the gallery app but couldn't find anything. A sample app would also help us see whether someone could rely on the old behavior which makes this a breaking change.

@knopp
Copy link
Member Author

@knopp knopp commented Oct 23, 2020

@liyuqian, This is related to partial redraw, which is work in progress. The issue here is that if I compute a damage area between last frame and current and then set it as cull-rect in preroll, some layers will be culled out even though they are within damage area due to wrongly calculated screen-space coordinates (as the unit test shows).

Given that this only causes issue when doing partial repaint you can't really reproduce it with current engine code. But I also can't imagine how any app would rely on wrong screen-space layer coordinates during pre-roll.

There are few other subtle issues that manifest while doing partial repaint related to Backdrop and ImageFilterLayers bounds, but I plan to address them in separate PRs.

@flar
Copy link
Contributor

@flar flar commented Oct 23, 2020

In both cases (opacity and picture layer), these layers use SkMatrix::postTranslate in their preroll, but leaf_nodes_canvas->translate in their Paint methods. The canvas translate method uses SkM44::preTranslate to do the operation.

(Actually, opacity uses a mixture of leaf_nodes_canvas and internal_nodes_canvas in its Paint method whereas picture uses only the leaf version. I don't know if that is another issue to consider...?)

The matrix in the Preroll method is only used for rasterizing layers AFAICT, and since we ignore the translation when we rasterize the layer, it won't affect the resulting image. During paint we then work out where to place the rasterized image and at that point the translation is correct and so we put it in the right position. So, even raster caching wouldn't detect this issue.

But, we do integer CTM adjustments on the transforms which might round in different directions if the offset was a fractional pixel, so this could lead to "off by 1" errors in the placement of cached layers?

@knopp
Copy link
Member Author

@knopp knopp commented Oct 23, 2020

Good point with the integer CTM. I think both ::Diff and ::Preroll needs be consistent with ::Paint for partial redraws.

@liyuqian
Copy link
Contributor

@liyuqian liyuqian commented Oct 26, 2020

The off by 1 error should be fine as we've already relaxed the constraint in

std::abs(bounds.size().width() - image_->dimensions().width()) <= 1 &&

Since this translation only affects the raster cache slightly, I'm ready to approve it. Let's also correct the usage in PictureLayer to make it consistent. Then I think it's ready to merge.

@knopp
Copy link
Member Author

@knopp knopp commented Oct 26, 2020

Since this translation only affects the raster cache slightly, I'm ready to approve it. Let's also correct the usage in PictureLayer to make it consistent. Then I think it's ready to merge.

Not entirely sure what you mean. The patch already changes PictureLayer to preTranslate here. Is there something else you have in mind?

Copy link
Contributor

@liyuqian liyuqian left a comment

Ah, I missed that file. LGTM!

@flar
flar approved these changes Oct 26, 2020
Copy link
Contributor

@flar flar left a comment

That's a +1 from me too...

matrix.preTranslate(x,y) is identical to
matrix.setConcat(matrix, SkMatrix::Translate(x,y));
@knopp knopp force-pushed the knopp:layer.use_pretranslate branch from 717b82f to 1cfe7db Oct 27, 2020
@fluttergithubbot fluttergithubbot merged commit ed0f477 into flutter:master Oct 29, 2020
15 checks passed
15 checks passed
Linux Android AOT Engine
Details
Linux Android Debug Engine
Details
Linux Android Scenarios
Details
Linux Fuchsia
Details
Linux Host Engine
Details
Mac Android AOT Engine
Details
Mac Android Debug Engine
Details
Mac Host Engine
Details
Mac iOS Engine
Details
WIP Ready for review
Details
Windows Android AOT Engine
Details
Windows Host Engine
Details
build_and_test_linux_unopt_debug Task Summary
Details
cla/google All necessary CLAs are signed
luci-engine
Details
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 29, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 29, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 30, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 30, 2020
GaryQian pushed a commit to flutter/flutter that referenced this pull request Oct 30, 2020
* 53d5d6853 Add dart-lang/sdk's new package:clock dependency (flutter/engine#22142)

* c32e3d8fd Roll Skia from 7737a5bd2510 to 5567a6091ceb (8 revisions) (flutter/engine#22146)

* 376045c00 Roll Fuchsia Linux SDK from XYN02FThN... to UKgKCjxSA... (flutter/engine#22147)

* 03395debd Roll Fuchsia Mac SDK from GKPwGj1Ux... to xHjtLQPQ5... (flutter/engine#22151)

* 0c7e9528a Manual Dart SDK roll 6e015bd9cddb to 9c6e76468ca4 (6 revisions (flutter/engine#22153)

* e5f168a67 Update constraint to latest integration test (flutter/engine#22169)

* e61e8c248 Smooth window resizing on macOS (flutter/engine#21525)

* acece00f0 Allow parse_and_send to use access tokens (flutter/engine#22019)

* 0270632d8 Includes roles for links, checkboxes, and radio buttons in semantics (flutter/engine#22061)

* 632354d96 Roll Fuchsia Linux SDK from UKgKCjxSA... to PY5hNI-wY... (flutter/engine#22175)

* 62d50af37 Add plumbing for command line arguments on Windows (flutter/engine#22094)

* 06b0910e2 Fix possible use of std::moved value in Rasterizer (flutter/engine#22125)

* 005dec449 [web] Clean up unused previousStyle logic (flutter/engine#22150)

* ca05bdccc Roll Skia from 5567a6091ceb to f548a028ce70 (7 revisions) (flutter/engine#22155)

* 5b07ac4c4 Roll Fuchsia Mac SDK from xHjtLQPQ5... to ICK_JlnKJ... (flutter/engine#22188)

* d615a97a1 Roll Fuchsia Linux SDK from PY5hNI-wY... to Usec4YBzR... (flutter/engine#22197)

* 11ed711eb Invalidate the cached SkParagraph font collection when a new font manager is installed (flutter/engine#22157)

* 07c780bd9 [web] Assign default natural width/height for svgs that report 0,0 on firefox and ie11 (flutter/engine#22184)

* b54bb88f0 Migrate runZoned to runZonedGuarded (flutter/engine#22198)

* 247139a8c [web] Fix transform not invalidating path bounds causing debugValidate failure (flutter/engine#22172)

* e4dffc107 [web] Fix scroll wheel line delta on Firefox. (flutter/engine#21928)

* d6627c6a7 Reland [ios] Refactor IOSSurface factory and unify surface creation (flutter/engine#22016)

* ce1dd11f5 Standardize macro names for dartdoc macros (flutter/engine#22180)

* f81bc371c [profiling] Handle thread_info to account for killed threads (flutter/engine#22170)

* fd94c863d Fix for firefox custom clipping (flutter/engine#22182)

* 9ccf9f120 bring back build_test to ensure we validate licenses (flutter/engine#22201)

* 38f6665bd Set strut font to Roboto if the given font hasn't been registered (flutter/engine#22129)

* caf32d5b2 Add a proc table version of embedder API (flutter/engine#21813)

* ed0f477c5 Use preTranslate when applying offset to matrix (flutter/engine#21648)

* b457e2dd8 Refactor make_mock_engine into fl_test (flutter/engine#21585)

* 28497c864 Fix typos in FlValue docs (flutter/engine#21875)

* bb32446c6 Fix FlTextInputPlugin tear down (flutter/engine#22007)

* 7a7804b6d Add "input shield" to capture pointer input for reinjection (flutter/engine#22067)

* fe85f946d Update painting.dart (flutter/engine#22195)

* 99cc50dff [ios] Surface factory holds the canonical reference to the external view embedder (flutter/engine#22206)
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.