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

Conversation

@ColdPaleLight
Copy link
Member

@ColdPaleLight ColdPaleLight commented Feb 16, 2022

revert #29923
reland #29889

I think it can be reland since flutter/flutter#98824 has been closed.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

@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 (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

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

@ColdPaleLight ColdPaleLight changed the title Reland "Listen for Vsync callback on the UI thread directly" [WIP] Reland "Listen for Vsync callback on the UI thread directly" Feb 16, 2022
@ColdPaleLight ColdPaleLight changed the title [WIP] Reland "Listen for Vsync callback on the UI thread directly" Reland "Listen for Vsync callback on the UI thread directly" Feb 20, 2022
@blasten
Copy link

blasten commented Feb 24, 2022

@ColdPaleLight Is #31546 the fix for the revert?

@ColdPaleLight
Copy link
Member Author

@ColdPaleLight Is #31546 the fix for the revert?

Yes! I was able to reproduce the failed test locally, and finally located the cause. I have verified it myself

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

Reland LGTM

bool MessageLoopAndroid::Register(JNIEnv* env) {
jclass clazz = env->FindClass("android/os/Looper");

if (clazz == nullptr) {
Copy link

Choose a reason for hiding this comment

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

simplification nit: this could be a FML_CHECK, and the FML_CHECK in the consumption side can be dropped.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

g_looper_class->obj(), "myLooper", "()Landroid/os/Looper;");
FML_CHECK(g_looper_my_looper_method_ != nullptr);

g_looper_quit_method_ =
Copy link

@blasten blasten Feb 24, 2022

Choose a reason for hiding this comment

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

There's no check for g_looper_quit_method_ != nullptr. Is this intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's missed before, added now

running_ = false;
}
}
LooperPrepare();
Copy link

Choose a reason for hiding this comment

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

does this means that ALooper_forThread() returns null? or are we calling prepare unnecessarily?

Copy link

Choose a reason for hiding this comment

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

nvm, this is initializing the state in the JVM, right? could we add comments?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

}
}

bool MessageLoopAndroid::Register(JNIEnv* env) {
Copy link

Choose a reason for hiding this comment

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

is it possible to add a comment to indicate that this could just use AChoreographer once Flutter drops supports for API level < 24?

There's not concrete plan, but worth mentioning for future maintainers that using the NDK simplifies this quite a bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a related issue here: flutter/flutter#62166.
I think in the future, if we need to replace the current implementation with NDK, we need to re-evaluate the possible benefits it brings, such as how much performance can be improved, whether the code is simple and maintainable, etc. So I think it's more reasonable to let it exist as an issue instead of writing it in the comments :-)

@ColdPaleLight ColdPaleLight 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 Feb 24, 2022
@fluttergithubbot fluttergithubbot merged commit a67a366 into flutter:main Feb 24, 2022
jason-simmons added a commit to jason-simmons/flutter_engine that referenced this pull request Mar 1, 2022
…lutter#31494)"

This reverts commit a67a366.

This was causing a StrictMode.detectLeakedClosableObjects warning because
a Choreographer instance was obtained on the Dart/UI thread but it
was not being disposed on some versions of Android.

The engine may need to implement this using NDK APIs instead of JNI
(see flutter/flutter#62166)
@blasten
Copy link

blasten commented Mar 1, 2022

@ColdPaleLight this change got reverted for the reason specified in the revert PR.

This is generally a good optimization, so if you'd like to reland it, you could try to use the NDK API for API level >= 24 and add TODO to remove the JNI fallback when we drop support for API level < 24.

@ColdPaleLight
Copy link
Member Author

@blasten I filed a new PR #31859 to reland it by using NDK API, would you mind reviewing it when you have a chance, thank you :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs tests platform-android 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.

3 participants