Repository navigation
gamescope: start sessions at the panel refresh rate; daemon stamps flips on the latch grid #2298
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package app.gamenative.display | ||
|
|
||
| import android.content.Context | ||
| import android.hardware.display.DisplayManager | ||
| import android.view.Display | ||
| import android.view.View | ||
| import androidx.core.content.ContextCompat | ||
| import kotlin.math.roundToInt | ||
|
|
||
| /** The panel's active refresh rate, read one way for every consumer. */ | ||
| object PanelRefresh { | ||
| /** The rate reported when the display can't be read. */ | ||
| const val FALLBACK_HZ = 60 | ||
|
|
||
| /** | ||
| * The panel's refresh rate in Hz: the mode the display is in now, not the fastest it supports, | ||
| * rounded to an integer. The daemon's advertised mode and latch-grid period | ||
| * ([GameNativeDrm.nativeSetPanelRefreshHz], which gamescope takes its refresh from) and the FPS | ||
| * limiter's ceiling both come from here, so they agree; a panel a user holds at 60 Hz counts as | ||
| * 60 even when it can do 120. | ||
| */ | ||
| @JvmStatic | ||
| fun activeHz(context: Context, attachedView: View? = null): Int { | ||
| val display = attachedView?.display | ||
| ?: runCatching { context.display }.getOrNull() | ||
| ?: ContextCompat.getSystemService(context, DisplayManager::class.java)?.getDisplay(Display.DEFAULT_DISPLAY) | ||
| return display?.refreshRate | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ?.takeIf { it.isFinite() && it > 0f } | ||
| ?.roundToInt() | ||
| ?.coerceAtLeast(5) | ||
| ?: FALLBACK_HZ | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: This claim is not true yet: LsfgVkManager, PerfSampler, PerformanceMetricsCollector and SessionReport still read the default display's refresh rate on their own. Either migrate them to
activeHzor reword this doc so it only describes the session, daemon and limiter.Prompt for AI agents