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

android: Allow redraws and resizes when a Surface is present #3897

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MarijnS95
Copy link
Member

... and not just when the activity is active. Android's activity lifecycle denotes that onResume() and onPause() are called when the activity changes the "active" state (which is separate from the "focused" state) and may or may not be followed or preceded by the onStart() - onStop() lifecycle which denotes Activity visibility. The latter more closely relates to when a surface is present (since when the activity is not active, but still visible redraws and resizes are still possible and expected) but also doesn't exactly represent it.

Note that Android fires its WindowResized and RedrawNeeded callbacks at least once, directly after InitWindow, and should (but this is not explicitly documented) never fire again after TerminateWindow.

Theoretically this isn't the right state to key off of for arbitrary EventLoop wakeups via the Proxy though.

(PR spun out from #3786)

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

Comment on lines +297 to 298
if self.window_has_surface {
if resized {
Copy link
Member Author

Choose a reason for hiding this comment

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

Given the asserts above I want to get rid of this double checking, except for handling a user-triggered redraw request.

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we also assert if the user triggers request_redraw while there is no surface?

Copy link
Member Author

@MarijnS95 MarijnS95 Sep 2, 2024

Choose a reason for hiding this comment

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

Since it could be async, I don't want to be that harsh on them - for now.

Perhaps that changes once we wire redraws up to Choreographer (and perhaps have a default "keep automatically requesting redraws every vsync" mode).

Comment on lines +500 to 502
// TODO: Theoretically the wake-up should also be handled when there's no surface
timeout = if self.window_has_surface
&& (self.pending_redraw || self.window_target.proxy_wake_up.load(Ordering::Relaxed))
Copy link
Member Author

Choose a reason for hiding this comment

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

Specifically, a non-pending_redraw arbitrary wakeup.

Comment on lines +106 to +112
// /// `onStart()` - `onStop()` lifecycle, denoting when the app is visible
// TODO: Might use activity_visible for allowing proxy wakeup events?
// activity_visible: bool,
// /// `onResume()` - `onPause()` lifecycle, denoting when the app is actively interacted with
// activity_active: bool,
// TODO: This should be per-Activity (likely analogous to per-Window) state.
window_has_surface: bool,
Copy link
Member Author

@MarijnS95 MarijnS95 Sep 2, 2024

Choose a reason for hiding this comment

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

I started with these states just to see what would happen, but it's quite common to have:

  • onStart()
  • onResume()
  • NativeWindowCreated
  • NativeWindowResized
  • NativeWindowRedrawNeeded
  • WindowFocusChanged to 1
  • ...
  • WindowFocusChanged to 0
  • onPause()
  • NativeWindowDestroyed
  • onStop()
  • (SaveInstanceState...)

So keying off of NativeWindowCreated/Destroyed is our only safe bet.

Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

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

Looks like an improvement so far

... and not _just when the activity is active_.  [Android's activity
lifecycle] denotes that `onResume()` and `onPause()` are called when
the activity changes the "active" state (which is separate from the
"focused" state) and may _or may not_ be followed or preceded by the
`onStart()` - `onStop()` lifecycle which denotes Activity _visibility_.
The latter more closely relates to when a surface is present (since when
the activity is not active, but still visible redraws and resizes are
still possible and expected) but also doesn't exactly represent it.

Note that Android fires its `WindowResized` and `RedrawNeeded` callbacks
at least once, directly after `InitWindow`, and _should_ (but this is
not explicitly documented) never fire again after `TerminateWindow`.

Theoretically this isn't the right state to key off of for arbitrary
`EventLoop` wakeups via the `Proxy` though.

[Android's activity lifecycle]: https://developer.android.com/guide/components/activities/activity-lifecycle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants