mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
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")
|
Log.i(TAG, "hdr: " + (if (on) "on" else "off") + " for this $mode session")
|
||||||
}
|
}
|
||||||
com.droiddeck.launcher.gpu.DriverSetupLog.write(this, "compositor.start driver=$driverId")
|
com.droiddeck.launcher.gpu.DriverSetupLog.write(this, "compositor.start driver=$driverId")
|
||||||
|
val outputRefresh = refreshHz(holder)
|
||||||
CompositorHost.startOrAttach(
|
CompositorHost.startOrAttach(
|
||||||
this, holder.surface, runtimeDir.path,
|
this, holder.surface, runtimeDir.path,
|
||||||
driverId?.let { turnip.driverPath(it) }, driverId?.let { turnip.libraryName(it) },
|
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)
|
onOutputAttached(holder)
|
||||||
if (SessionState.running && size != previous) {
|
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() {
|
private fun applyOutputPacing() {
|
||||||
val frameGen = appliedFrameGenMode
|
val frameGen = appliedFrameGenMode
|
||||||
pacedFrameGenMode = frameGen
|
pacedFrameGenMode = frameGen
|
||||||
@@ -3218,7 +3223,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
|||||||
)
|
)
|
||||||
val hz = refreshHz()
|
val hz = refreshHz()
|
||||||
val changed = kotlin.math.abs(SessionState.refreshHz - hz) > 0.1f
|
val changed = kotlin.math.abs(SessionState.refreshHz - hz) > 0.1f
|
||||||
CompositorHost.updatePacing(hz, outputFpsLimit())
|
CompositorHost.updatePacing(hz, outputFpsLimit(), outputFrameRateVote(hz))
|
||||||
pushCardboard(activeCardboard)
|
pushCardboard(activeCardboard)
|
||||||
if (changed && ::surfaceView.isInitialized) applyFrameGen()
|
if (changed && ::surfaceView.isInitialized) applyFrameGen()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,16 @@ object PerfMode {
|
|||||||
internal fun panelHeld(requestedHz: Float, activeHz: Float): Boolean =
|
internal fun panelHeld(requestedHz: Float, activeHz: Float): Boolean =
|
||||||
requestedHz > 1f && activeHz > 1f && Math.abs(requestedHz - activeHz) > 0.5f
|
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 {
|
fun pacedRate(ownLimit: Int, limiterRate: Int, limiterRefresh: Int, steadyRate: Int): Int = when {
|
||||||
ownLimit > 0 -> ownLimit
|
ownLimit > 0 -> ownLimit
|
||||||
limiterRate <= 0 -> steadyRate
|
limiterRate <= 0 -> steadyRate
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.os.Build
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.HandlerThread
|
import android.os.HandlerThread
|
||||||
import android.os.Process
|
import android.os.Process
|
||||||
|
import android.util.Log
|
||||||
import android.view.Choreographer
|
import android.view.Choreographer
|
||||||
import android.view.Surface
|
import android.view.Surface
|
||||||
import com.droiddeck.launcher.session.SessionPrefs
|
import com.droiddeck.launcher.session.SessionPrefs
|
||||||
@@ -67,13 +68,14 @@ object CompositorHost {
|
|||||||
outputHeight: Int,
|
outputHeight: Int,
|
||||||
refreshHz: Float,
|
refreshHz: Float,
|
||||||
fpsLimit: Int,
|
fpsLimit: Int,
|
||||||
|
frameRateVote: Float = refreshHz,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
WaylandCompositor.nativeSetClockControl(java.io.File(context.filesDir, "${com.droiddeck.launcher.runtime.LinuxRuntime.DIR}/tmp/.dd-clock").path)
|
WaylandCompositor.nativeSetClockControl(java.io.File(context.filesDir, "${com.droiddeck.launcher.runtime.LinuxRuntime.DIR}/tmp/.dd-clock").path)
|
||||||
ownVsyncThread = SessionPrefs.vsyncThread(context)
|
ownVsyncThread = SessionPrefs.vsyncThread(context)
|
||||||
WaylandCompositor.nativeSetRenderOnCommit(SessionPrefs.renderOnCommit(context))
|
WaylandCompositor.nativeSetRenderOnCommit(SessionPrefs.renderOnCommit(context))
|
||||||
blackFrameInsertion = SessionPrefs.blackFrameInsertion(context)
|
blackFrameInsertion = SessionPrefs.blackFrameInsertion(context)
|
||||||
WaylandCompositor.nativeSetBlackFrameInsertion(blackFrameInsertion)
|
WaylandCompositor.nativeSetBlackFrameInsertion(blackFrameInsertion)
|
||||||
pace(refreshHz, fpsLimit)
|
pace(refreshHz, fpsLimit, frameRateVote)
|
||||||
if (!SessionState.running) WaylandCompositor.nativeSetOutputSize(outputWidth, outputHeight)
|
if (!SessionState.running) WaylandCompositor.nativeSetOutputSize(outputWidth, outputHeight)
|
||||||
if (started) {
|
if (started) {
|
||||||
attached = surface
|
attached = surface
|
||||||
@@ -95,16 +97,21 @@ object CompositorHost {
|
|||||||
private var blackFrameInsertion = false
|
private var blackFrameInsertion = false
|
||||||
private var pictureHolds = 0
|
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.nativeSetFpsLimit(fpsLimit)
|
||||||
WaylandCompositor.nativeSetLayerFrameRate(if (fpsLimit > 0 && !blackFrameInsertion) fpsLimit.toFloat() else refreshHz)
|
surfaceFrameRate = layerFrameRate(frameRateVote, fpsLimit, blackFrameInsertion)
|
||||||
|
applySurfaceFrameRate()
|
||||||
|
WaylandCompositor.nativeSetLayerFrameRate(surfaceFrameRate)
|
||||||
WaylandCompositor.nativeSetOutputRefreshRate(refreshHz)
|
WaylandCompositor.nativeSetOutputRefreshRate(refreshHz)
|
||||||
SessionState.refreshHz = refreshHz
|
SessionState.refreshHz = refreshHz
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun layerFrameRate(refreshHz: Float, fpsLimit: Int, blackFrameInsertion: Boolean): Float =
|
||||||
|
if (fpsLimit > 0 && !blackFrameInsertion) fpsLimit.toFloat() else refreshHz
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun updatePacing(refreshHz: Float, fpsLimit: Int) {
|
fun updatePacing(refreshHz: Float, fpsLimit: Int, frameRateVote: Float = refreshHz) {
|
||||||
if (started) pace(refreshHz, fpsLimit)
|
if (started) pace(refreshHz, fpsLimit, frameRateVote)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
@@ -146,7 +153,31 @@ object CompositorHost {
|
|||||||
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(rearm, 600)
|
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(rearm, 600)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var surfaceFrameRate = 0f
|
||||||
|
private var appliedSurfaceFrameRate = Float.NaN
|
||||||
private var attached: Surface? = null
|
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
|
@Synchronized
|
||||||
fun attachXr() {
|
fun attachXr() {
|
||||||
|
|||||||
@@ -17,6 +17,22 @@ class PerfModeTest {
|
|||||||
ShadowDisplayManager.ModeBuilder.modeBuilder(id)
|
ShadowDisplayManager.ModeBuilder.modeBuilder(id)
|
||||||
.setWidth(width).setHeight(2520).setRefreshRate(hz).build()
|
.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() {
|
@Test fun sixtyHzMirrorChoosesSixtyEvenThoughOneTwentyHasMatchingCadence() {
|
||||||
val low = mode(1, 60f)
|
val low = mode(1, 60f)
|
||||||
val high = mode(2, 120f)
|
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