Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d80cbbd364 |
No files matched your search
@@ -2987,10 +2987,12 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
Log.i(TAG, "hdr: " + (if (on) "on" else "off") + " for this $mode session")
|
||||
}
|
||||
com.droiddeck.launcher.gpu.DriverSetupLog.write(this, "compositor.start driver=$driverId")
|
||||
val outputRefresh = refreshHz(holder)
|
||||
CompositorHost.startOrAttach(
|
||||
this, holder.surface, runtimeDir.path,
|
||||
driverId?.let { turnip.driverPath(it) }, driverId?.let { turnip.libraryName(it) },
|
||||
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(holder), outputFpsLimit(),
|
||||
applicationInfo.nativeLibraryDir, size.first, size.second, outputRefresh, outputFpsLimit(),
|
||||
outputFrameRateVote(outputRefresh),
|
||||
)
|
||||
onOutputAttached(holder)
|
||||
if (SessionState.running && size != previous) {
|
||||
@@ -3200,6 +3202,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
}
|
||||
|
||||
private fun outputFrameRateVote(hz: Float): Float =
|
||||
if (glassesScreen == null && !bottomOutputActive && !panelHeld) PerfMode.frameRateVote(this, hz) else hz
|
||||
|
||||
private fun applyOutputPacing() {
|
||||
val frameGen = appliedFrameGenMode
|
||||
pacedFrameGenMode = frameGen
|
||||
@@ -3218,7 +3223,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
)
|
||||
val hz = refreshHz()
|
||||
val changed = kotlin.math.abs(SessionState.refreshHz - hz) > 0.1f
|
||||
CompositorHost.updatePacing(hz, outputFpsLimit())
|
||||
CompositorHost.updatePacing(hz, outputFpsLimit(), outputFrameRateVote(hz))
|
||||
pushCardboard(activeCardboard)
|
||||
if (changed && ::surfaceView.isInitialized) applyFrameGen()
|
||||
}
|
||||
|
||||
@@ -82,6 +82,16 @@ object PerfMode {
|
||||
internal fun panelHeld(requestedHz: Float, activeHz: Float): Boolean =
|
||||
requestedHz > 1f && activeHz > 1f && Math.abs(requestedHz - activeHz) > 0.5f
|
||||
|
||||
fun frameRateVote(a: Activity, activeHz: Float): Float = try {
|
||||
val display = if (Build.VERSION.SDK_INT >= 30) a.display else @Suppress("DEPRECATION") a.windowManager.defaultDisplay
|
||||
val wanted = a.window.attributes.preferredDisplayModeId
|
||||
val requested = display?.supportedModes?.firstOrNull { wanted != 0 && it.modeId == wanted }
|
||||
frameRateVote(requested?.refreshRate ?: 0f, activeHz)
|
||||
} catch (t: Throwable) { Log.w(TAG, "frame rate vote", t); activeHz }
|
||||
|
||||
internal fun frameRateVote(requestedHz: Float, activeHz: Float): Float =
|
||||
requestedHz.takeIf { it > 1f } ?: activeHz
|
||||
|
||||
fun pacedRate(ownLimit: Int, limiterRate: Int, limiterRefresh: Int, steadyRate: Int): Int = when {
|
||||
ownLimit > 0 -> ownLimit
|
||||
limiterRate <= 0 -> steadyRate
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.Process
|
||||
import android.util.Log
|
||||
import android.view.Choreographer
|
||||
import android.view.Surface
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
@@ -67,13 +68,14 @@ object CompositorHost {
|
||||
outputHeight: Int,
|
||||
refreshHz: Float,
|
||||
fpsLimit: Int,
|
||||
frameRateVote: Float = refreshHz,
|
||||
): Boolean {
|
||||
WaylandCompositor.nativeSetClockControl(java.io.File(context.filesDir, "${com.droiddeck.launcher.runtime.LinuxRuntime.DIR}/tmp/.dd-clock").path)
|
||||
ownVsyncThread = SessionPrefs.vsyncThread(context)
|
||||
WaylandCompositor.nativeSetRenderOnCommit(SessionPrefs.renderOnCommit(context))
|
||||
blackFrameInsertion = SessionPrefs.blackFrameInsertion(context)
|
||||
WaylandCompositor.nativeSetBlackFrameInsertion(blackFrameInsertion)
|
||||
pace(refreshHz, fpsLimit)
|
||||
pace(refreshHz, fpsLimit, frameRateVote)
|
||||
if (!SessionState.running) WaylandCompositor.nativeSetOutputSize(outputWidth, outputHeight)
|
||||
if (started) {
|
||||
attached = surface
|
||||
@@ -95,16 +97,21 @@ object CompositorHost {
|
||||
private var blackFrameInsertion = false
|
||||
private var pictureHolds = 0
|
||||
|
||||
private fun pace(refreshHz: Float, fpsLimit: Int) {
|
||||
private fun pace(refreshHz: Float, fpsLimit: Int, frameRateVote: Float = refreshHz) {
|
||||
WaylandCompositor.nativeSetFpsLimit(fpsLimit)
|
||||
WaylandCompositor.nativeSetLayerFrameRate(if (fpsLimit > 0 && !blackFrameInsertion) fpsLimit.toFloat() else refreshHz)
|
||||
surfaceFrameRate = layerFrameRate(frameRateVote, fpsLimit, blackFrameInsertion)
|
||||
applySurfaceFrameRate()
|
||||
WaylandCompositor.nativeSetLayerFrameRate(surfaceFrameRate)
|
||||
WaylandCompositor.nativeSetOutputRefreshRate(refreshHz)
|
||||
SessionState.refreshHz = refreshHz
|
||||
}
|
||||
|
||||
internal fun layerFrameRate(refreshHz: Float, fpsLimit: Int, blackFrameInsertion: Boolean): Float =
|
||||
if (fpsLimit > 0 && !blackFrameInsertion) fpsLimit.toFloat() else refreshHz
|
||||
|
||||
@Synchronized
|
||||
fun updatePacing(refreshHz: Float, fpsLimit: Int) {
|
||||
if (started) pace(refreshHz, fpsLimit)
|
||||
fun updatePacing(refreshHz: Float, fpsLimit: Int, frameRateVote: Float = refreshHz) {
|
||||
if (started) pace(refreshHz, fpsLimit, frameRateVote)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@@ -146,7 +153,31 @@ object CompositorHost {
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(rearm, 600)
|
||||
}
|
||||
|
||||
private var surfaceFrameRate = 0f
|
||||
private var appliedSurfaceFrameRate = Float.NaN
|
||||
private var attached: Surface? = null
|
||||
set(value) {
|
||||
field = value
|
||||
appliedSurfaceFrameRate = Float.NaN
|
||||
applySurfaceFrameRate()
|
||||
}
|
||||
|
||||
private fun applySurfaceFrameRate() {
|
||||
val surface = attached ?: return
|
||||
if (Build.VERSION.SDK_INT < 30 || !surface.isValid || appliedSurfaceFrameRate == surfaceFrameRate) return
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= 31) {
|
||||
surface.setFrameRate(surfaceFrameRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT, Surface.CHANGE_FRAME_RATE_ALWAYS)
|
||||
} else {
|
||||
surface.setFrameRate(surfaceFrameRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT)
|
||||
}
|
||||
appliedSurfaceFrameRate = surfaceFrameRate
|
||||
} catch (t: IllegalArgumentException) {
|
||||
Log.w("CompositorHost", "surface frame rate", t)
|
||||
} catch (t: IllegalStateException) {
|
||||
Log.w("CompositorHost", "surface frame rate", t)
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun attachXr() {
|
||||
|
||||
@@ -17,6 +17,22 @@ class PerfModeTest {
|
||||
ShadowDisplayManager.ModeBuilder.modeBuilder(id)
|
||||
.setWidth(width).setHeight(2520).setRefreshRate(hz).build()
|
||||
|
||||
@Test fun aPendingModeSwitchVotesForTheSelectedRateWithoutChangingMeasuredPacing() {
|
||||
assertEquals(185f, PerfMode.frameRateVote(185f, 60f), 0f)
|
||||
assertEquals(60f, PerfMode.frameRateVote(60f, 185f), 0f)
|
||||
assertEquals(120f, PerfMode.frameRateVote(120f, 120f), 0f)
|
||||
assertEquals(60f, PerfMode.frameRateVote(0f, 60f), 0f)
|
||||
}
|
||||
|
||||
@Test fun aSurfaceVoteUsesTheSelectedCapAndGuestCadence() {
|
||||
val modes = arrayOf(mode(1, 60f), mode(2, 90f), mode(3, 120f), mode(4, 185f))
|
||||
val current = modes[0]
|
||||
val capped = PerfMode.selectMode(modes, current, 0, 90f)!!
|
||||
val limited = PerfMode.selectMode(modes, current, 60, Float.POSITIVE_INFINITY)!!
|
||||
assertEquals(90f, PerfMode.frameRateVote(capped.refreshRate, 60f), 0f)
|
||||
assertEquals(120f, PerfMode.frameRateVote(limited.refreshRate, 60f), 0f)
|
||||
}
|
||||
|
||||
@Test fun sixtyHzMirrorChoosesSixtyEvenThoughOneTwentyHasMatchingCadence() {
|
||||
val low = mode(1, 60f)
|
||||
val high = mode(2, 120f)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.droiddeck.launcher.wayland
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class CompositorHostTest {
|
||||
@Test fun aPendingRefreshVotePreservesExplicitLimitsAndBlackFrameInsertion() {
|
||||
assertEquals(185f, CompositorHost.layerFrameRate(185f, 0, false), 0f)
|
||||
assertEquals(30f, CompositorHost.layerFrameRate(185f, 30, false), 0f)
|
||||
assertEquals(185f, CompositorHost.layerFrameRate(185f, 30, true), 0f)
|
||||
assertEquals(60f, CompositorHost.layerFrameRate(60f, 0, false), 0f)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user