mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-11 02:51:10 +00:00
fix: fit output after pip resize
This commit is contained in:
1 parent
a0a7a66470
commit
7c5bf77f17
3 files changed
+17
-1
No files matched your search
@@ -2220,7 +2220,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
|
||||
private fun windowOutputSize(width: Int, height: Int): Pair<Int, Int>? {
|
||||
if (isInPictureInPictureMode || width <= 0 || height <= 0) return null
|
||||
if (width <= 0 || height <= 0) return null
|
||||
if (isInPictureInPictureMode) return com.droiddeck.launcher.session.PipPolicy.outputSize(
|
||||
width, height, SessionState.outputSize.first, SessionState.outputSize.second)
|
||||
if (bottomGame != null) return when {
|
||||
SessionState.followScreen ->
|
||||
com.droiddeck.launcher.session.SessionDisplay.followSize(width, height, false, SessionState.followScale)
|
||||
|
||||
@@ -11,4 +11,12 @@ object PipPolicy {
|
||||
height.toDouble() / width > 2.39 -> 100 to 239
|
||||
else -> width to height
|
||||
}
|
||||
|
||||
fun outputSize(width: Int, height: Int, outputWidth: Int, outputHeight: Int): Pair<Int, Int>? {
|
||||
if (width <= 0 || height <= 0 || outputWidth <= 0 || outputHeight <= 0) return null
|
||||
val scale = minOf(width.toFloat() / outputWidth, height.toFloat() / outputHeight)
|
||||
val fittedWidth = ((outputWidth * scale).toInt() and 1.inv()).coerceAtLeast(2)
|
||||
val fittedHeight = ((outputHeight * scale).toInt() and 1.inv()).coerceAtLeast(2)
|
||||
return fittedWidth to fittedHeight
|
||||
}
|
||||
}
|
||||
@@ -24,4 +24,10 @@ class PipPolicyTest {
|
||||
assertEquals(100 to 239, PipPolicy.aspect(1080, 5760))
|
||||
assertEquals(16 to 9, PipPolicy.aspect(0, 0))
|
||||
}
|
||||
|
||||
@Test fun pipOutputFitsTheResizedSurfaceWithoutChangingAspectRatio() {
|
||||
assertEquals(640 to 360, PipPolicy.outputSize(640, 480, 1920, 1080))
|
||||
assertEquals(480 to 270, PipPolicy.outputSize(480, 270, 1920, 1080))
|
||||
assertNull(PipPolicy.outputSize(0, 270, 1920, 1080))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user