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

Conversation

@knopp
Copy link
Member

@knopp knopp commented Sep 15, 2020

Description

This PR supersedes #21108.

This PR will ensure that after viewport change metrics event is received, layer tree with previous (wrong size) are discarded and not rasterized. This is required for smooth resizing on both Mac and Windows.

Important: This will potentially affect iOS and Android embedders. We need to make sure this doesn't cause any issues.

Related Issues

flutter/flutter#44136

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.

If this callback returns true for given layer tree, the layer tree
will be discarded and not rasterized

This is useful after the resize event, when layer tree with certain size is expected,
but there is a tree with previous size still in pipeline
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@iskakaushik
Copy link
Contributor

Looks good overall but requires tests as mentioned in this comment: #21108 (review). Let me know if you run into issues writing tests.

@knopp knopp force-pushed the discard_wrong_size_tree_wip_pr2 branch from 981a8f5 to 9dab1f2 Compare September 15, 2020 15:54
@cbracken cbracken added the Work in progress (WIP) Not ready (yet) for review! label Sep 15, 2020
@knopp
Copy link
Member Author

knopp commented Sep 15, 2020

I added test for this:
d01b804
642e383

Copy link
Contributor

@iskakaushik iskakaushik left a comment

Choose a reason for hiding this comment

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

Left some improvements to the test, we should be good to merge this PR once those are fixed.

auto layer_tree =
std::make_unique<LayerTree>(size, static_cast<float>(1));
SkMatrix identity;
identity.setIdentity();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I thought SkMatrix was default initialized to identiy.

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied that snippet from another test, but you're right. Unlike other types SkMatrix actually seems to have sane default value.

shell->GetTaskRunners().GetPlatformTaskRunner(),
[&shell, &expected_size]() {
shell->GetPlatformView()->SetViewportMetrics(
{1.0, double(expected_size.width()),
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 these be static_cast<double>?

shell->GetTaskRunners().GetUITaskRunner()->PostTask(
[runtime_delegate, size]() {
auto layer_tree =
std::make_unique<LayerTree>(size, static_cast<float>(1));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this can be 1.0f.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. Not sure why it was written like this.

@knopp knopp force-pushed the discard_wrong_size_tree_wip_pr2 branch from 642e383 to 58f1b71 Compare September 16, 2020 10:44
Copy link
Contributor

@iskakaushik iskakaushik left a comment

Choose a reason for hiding this comment

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

Is this still a WIP or do you think we can land this once the presubmits pass?

If you think it's ready, please remove WIP from the title of the PR.

GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) {
frame->Submit();
if (frame && frame->SkiaSurface()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Windows toolchain doesn't seem to be liking this:

C:\b\s\w\ir\kitchen-checkout\depot_tools\win_toolchain\vs_files\418b3076791776573a815eb298c8aa590307af63\win_sdk\bin\..\..\VC\Tools\MSVC\14.16.27023\include\atomic(620,2): error: static_assert failed due to requirement 'alignof(SkISize) >= sizeof(unsigned long long)' "You've instantiated std::atomic<T> with sizeof(T) equal to 2/4/8 and alignof(T) < sizeof(T). Before VS 2015 Update 2, this would have misbehaved at runtime. VS 2015 Update 2 was fixed to handle this correctly, but the fix inherently changes layout and breaks binary compatibility. Please define _ENABLE_ATOMIC_ALIGNMENT_FIX to acknowledge that you understand this, and that everything you're linking has been compiled with VS 2015 Update 2 (or later)."
        static_assert(alignof(_Ty) >= sizeof(_My_int),
        ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\b\s\w\ir\kitchen-checkout\depot_tools\win_toolchain\vs_files\418b3076791776573a815eb298c8aa590307af63\win_sdk\bin\..\..\VC\Tools\MSVC\14.16.27023\include\atomic(635,5): note: in instantiation of template class 'std::_Atomic_base<SkISize, 8>' requested here
                : _Atomic_base<_Ty, sizeof (_Ty)>
                  ^
../../flutter/shell/common/shell_test_external_view_embedder.h(86,24): note: in instantiation of template class 'std::atomic<SkISize>' requested here
  std::atomic<SkISize> last_submitted_frame_size_;
                       ^
1 error generated.

See https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket.appspot.com/8869006746431748192/+/steps/build_host_debug/0/stdout for full error.

Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't going to be an issue in future, in the meanwhile perhaps we could define _ENABLE_ATOMIC_ALIGNMENT_FIX. There's nothing wrong with the code, it's just a windows STL quirk.

end_frame_latch.Signal();
};

external_view_embedder = std::make_shared<ShellTestExternalViewEmbedder>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. It was accessed from the callback before. I'll move it.

@knopp knopp force-pushed the discard_wrong_size_tree_wip_pr2 branch 2 times, most recently from 1a57215 to 146a855 Compare September 16, 2020 17:18
@iskakaushik
Copy link
Contributor

@knopp I still see two errors only on windows:

C:\b\s\w\ir\kitchen-checkout\depot_tools\win_toolchain\vs_files\418b3076791776573a815eb298c8aa590307af63\win_sdk\bin\..\..\VC\Tools\MSVC\14.16.27023\include\atomic(620,2): error: static_assert failed due to requirement 'alignof(SkISize) >= sizeof(unsigned long long)' "You've instantiated std::atomic<T> with sizeof(T) equal to 2/4/8 and alignof(T) < sizeof(T). Before VS 2015 Update 2, this would have misbehaved at runtime. VS 2015 Update 2 was fixed to handle this correctly, but the fix inherently changes layout and breaks binary compatibility. Please define _ENABLE_ATOMIC_ALIGNMENT_FIX to acknowledge that you understand this, and that everything you're linking has been compiled with VS 2015 Update 2 (or later)."
        static_assert(alignof(_Ty) >= sizeof(_My_int),
        ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\b\s\w\ir\kitchen-checkout\depot_tools\win_toolchain\vs_files\418b3076791776573a815eb298c8aa590307af63\win_sdk\bin\..\..\VC\Tools\MSVC\14.16.27023\include\atomic(635,5): note: in instantiation of template class 'std::_Atomic_base<SkISize, 8>' requested here
                : _Atomic_base<_Ty, sizeof (_Ty)>
                  ^
../..\flutter/shell/common/shell_test_external_view_embedder.h(91,24): note: in instantiation of template class 'std::atomic<SkISize>' requested here
  std::atomic<SkISize> last_submitted_frame_size_;
                       ^
1 error generated.

and

In file included from ../../third_party/skia\include/core/SkRefCnt.h:13:
C:\b\s\w\ir\kitchen-checkout\depot_tools\win_toolchain\vs_files\418b3076791776573a815eb298c8aa590307af63\win_sdk\bin\..\..\VC\Tools\MSVC\14.16.27023\include\atomic(620,2): error: static_assert failed due to requirement 'alignof(SkISize) >= sizeof(unsigned long long)' "You've instantiated std::atomic<T> with sizeof(T) equal to 2/4/8 and alignof(T) < sizeof(T). Before VS 2015 Update 2, this would have misbehaved at runtime. VS 2015 Update 2 was fixed to handle this correctly, but the fix inherently changes layout and breaks binary compatibility. Please define _ENABLE_ATOMIC_ALIGNMENT_FIX to acknowledge that you understand this, and that everything you're linking has been compiled with VS 2015 Update 2 (or later)."
        static_assert(alignof(_Ty) >= sizeof(_My_int),
        ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\b\s\w\ir\kitchen-checkout\depot_tools\win_toolchain\vs_files\418b3076791776573a815eb298c8aa590307af63\win_sdk\bin\..\..\VC\Tools\MSVC\14.16.27023\include\atomic(635,5): note: in instantiation of template class 'std::_Atomic_base<SkISize, 8>' requested here
                : _Atomic_base<_Ty, sizeof (_Ty)>
                  ^
../..\flutter/shell/common/shell_test_external_view_embedder.h(91,24): note: in instantiation of template class 'std::atomic<SkISize>' requested here
  std::atomic<SkISize> last_submitted_frame_size_;
                       ^
../../flutter/shell/common/shell_test_platform_view_gl.cc(78,10): error: cannot initialize return object of type 'flutter::ExternalViewEmbedder *' with an rvalue of type 'std::_Ptr_base<flutter::ShellTestExternalViewEmbedder>::element_type *' (aka 'flutter::ShellTestExternalViewEmbedder *')
  return shell_test_external_view_embedder_.get();
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

Still seem to be artifacts of STL on windows?

@knopp
Copy link
Member Author

knopp commented Sep 17, 2020

It is artifact of windows STL, but the define on top of the file should have taken care of it. I'm building now on windows locally.

@knopp knopp force-pushed the discard_wrong_size_tree_wip_pr2 branch from a78fe6f to 19dad88 Compare September 17, 2020 21:08
@iskakaushik
Copy link
Contributor

seems like formatting is off in BUILD.gn.

@knopp knopp force-pushed the discard_wrong_size_tree_wip_pr2 branch 3 times, most recently from 08257a4 to 1e524f5 Compare September 17, 2020 22:29
@knopp knopp force-pushed the discard_wrong_size_tree_wip_pr2 branch from 1e524f5 to 9fccda2 Compare September 17, 2020 22:31
@knopp knopp changed the title WIP: Discard wrong size layer tree instead of rendering it Discard wrong size layer tree instead of rendering it Sep 18, 2020
@iskakaushik iskakaushik removed the Work in progress (WIP) Not ready (yet) for review! label Sep 18, 2020
Copy link
Contributor

@iskakaushik iskakaushik left a comment

Choose a reason for hiding this comment

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

LGTM

@iskakaushik iskakaushik added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Sep 18, 2020
@fluttergithubbot fluttergithubbot merged commit 5c9dddc into flutter:master Sep 18, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
@liyuqian liyuqian added perf: speed Performance issues related to (mostly rendering) speed severe: performance Relates to speed or footprint issues. labels Sep 22, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2020
@knopp knopp deleted the discard_wrong_size_tree_wip_pr2 branch July 17, 2021 09:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes perf: speed Performance issues related to (mostly rendering) speed severe: performance Relates to speed or footprint issues. waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants