Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class DdSdkImplementation(
internal val initialized = AtomicBoolean(false)
private var frameRateProvider: FrameRateProvider? = null

@Volatile
private var maxDisplayRefreshRate: Double? = null

// region DdSdk

/**
Expand Down Expand Up @@ -383,7 +386,7 @@ class DdSdkImplementation(
val frameTimeMs = frameTimeSeconds * 1000.0
val frameBudgetHz = fpsBudget ?: DEFAULT_REFRESH_HZ
val maxDeviceDisplayHz = deviceDisplayFps ?: getMaxDisplayRefreshRate(context)
?: 60.0
?: DEFAULT_REFRESH_HZ
Comment thread
sbarrio marked this conversation as resolved.

val maxDeviceFrameTimeMs = 1000.0 / maxDeviceDisplayHz
val budgetFrameTimeMs = 1000.0 / frameBudgetHz
Expand All @@ -402,10 +405,14 @@ class DdSdkImplementation(

@Suppress("CyclomaticComplexMethod")
private fun getMaxDisplayRefreshRate(context: Context?): Double {
val dm = context?.getSystemService(Context.DISPLAY_SERVICE) as? DisplayManager ?: return 60.0
maxDisplayRefreshRate?.let { return it }

val dm = context?.getSystemService(Context.DISPLAY_SERVICE) as? DisplayManager ?: return DEFAULT_REFRESH_HZ
Comment thread
Copilot marked this conversation as resolved.
val display: Display = dm.getDisplay(Display.DEFAULT_DISPLAY) ?: return DEFAULT_REFRESH_HZ
val hz = display.supportedModes.maxOfOrNull { it.refreshRate.toDouble() } ?: DEFAULT_REFRESH_HZ
maxDisplayRefreshRate = hz
Comment thread
sbarrio marked this conversation as resolved.

return display.supportedModes.maxOfOrNull { it.refreshRate.toDouble() } ?: DEFAULT_REFRESH_HZ
return hz
}

// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import org.junit.jupiter.params.provider.MethodSource
import org.mockito.Answers
import org.mockito.Mock
import org.mockito.Mockito.mock
import org.mockito.Mockito.times
import org.mockito.Mockito.`when`
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.jupiter.MockitoSettings
Expand Down Expand Up @@ -3595,6 +3596,35 @@ internal class DdSdkTest {
assertThat(result).isEqualTo(0.016, Offset.offset(0.001))
}

@Test
fun `M read supportedModes only once W normalizeFrameTime called multiple times`() {
// Given
val mockContext = mock(Context::class.java)
val mockDisplayManager = mock(DisplayManager::class.java)
val mockDisplay = mock(Display::class.java)

`when`(mockContext.getSystemService(Context.DISPLAY_SERVICE)).thenReturn(mockDisplayManager)
`when`(mockDisplayManager.getDisplay(Display.DEFAULT_DISPLAY)).thenReturn(mockDisplay)
`when`(mockDisplay.supportedModes).thenReturn(arrayOf())

// When
testedBridgeSdk.normalizeFrameTime(
frameTimeSeconds = 0.016,
context = mockContext,
fpsBudget = null,
deviceDisplayFps = null
)
testedBridgeSdk.normalizeFrameTime(
frameTimeSeconds = 0.016,
context = mockContext,
fpsBudget = null,
deviceDisplayFps = null
)

// Then
verify(mockDisplay, times(1)).supportedModes
}

// endregion

// region Internal
Expand Down