Skip to content

Commit 9e17202

Browse files
jushactions-user
authored andcommitted
Fix render thread CPU affinity lost on app resumed from background (#4588)
Solves https://mapbox.atlassian.net/browse/MAPSAND-2213: > We lose CPU affinity when the activity goes to the background and returns, or when another activity comes to the foreground. cc @mapbox/core-sdk cc @mapbox/gl-native cc @mapbox/maps-android --------- Co-authored-by: Changelog autocreator bot <[email protected]> GitOrigin-RevId: 2d5343bbb5a6a8d7ec04626e91ed06a874b47601
1 parent 9e06604 commit 9e17202

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

maps-sdk/src/main/java/com/mapbox/maps/NativeMapImpl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ internal class NativeMapImpl(val map: Map) {
7676
map.render()
7777
}
7878

79+
@OptIn(com.mapbox.annotation.MapboxExperimental::class)
80+
@MapboxExperimental
81+
fun resetThreadServiceType() {
82+
map.resetThreadServiceType()
83+
}
84+
7985
fun setCamera(cameraOptions: CameraOptions) {
8086
map.setCamera(cameraOptions)
8187
}

maps-sdk/src/main/java/com/mapbox/maps/renderer/MapboxRenderThread.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ internal class MapboxRenderThread : Choreographer.FrameCallback {
224224
)
225225
}
226226

227+
/**
228+
* Resets the renderer thread service type to Interactive.
229+
* Must be called on the render thread.
230+
*/
231+
@OptIn(MapboxExperimental::class)
232+
@RenderThread
233+
private fun resetThreadServiceType() {
234+
mapboxRenderer.resetThreadServiceType()
235+
}
236+
227237
private fun setUpRenderThread(creatingSurface: Boolean): Boolean {
228238
surfaceProcessingLock.withLock {
229239
try {
@@ -717,6 +727,7 @@ internal class MapboxRenderThread : Choreographer.FrameCallback {
717727
fun resume() {
718728
paused = false
719729
logI(TAG, "Renderer resumed, renderThreadPrepared=$renderThreadPrepared, surface.isValid=${surface?.isValid}")
730+
postNonRenderEvent(RenderEvent(::resetThreadServiceType, false))
720731
// schedule render if we resume not after first create (e.g. bring map back to front)
721732
renderPreparedGuardedRun(::postPrepareRenderFrame)
722733
}

maps-sdk/src/main/java/com/mapbox/maps/renderer/MapboxRenderer.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ package com.mapbox.maps.renderer
33
import android.graphics.Bitmap
44
import android.graphics.Matrix
55
import android.opengl.GLES20
6-
import androidx.annotation.*
6+
import androidx.annotation.AnyThread
7+
import androidx.annotation.MainThread
8+
import androidx.annotation.UiThread
9+
import androidx.annotation.VisibleForTesting
710
import com.mapbox.common.Cancelable
8-
import com.mapbox.maps.*
11+
import com.mapbox.maps.DelegatingMapClient
912
import com.mapbox.maps.MapView.OnSnapshotReady
13+
import com.mapbox.maps.MapboxExperimental
14+
import com.mapbox.maps.NativeMapImpl
15+
import com.mapbox.maps.RenderFrameFinishedCallback
16+
import com.mapbox.maps.RenderModeType
1017
import com.mapbox.maps.Size
18+
import com.mapbox.maps.logE
19+
import com.mapbox.maps.logW
1120
import com.mapbox.maps.renderer.gl.PixelReader
1221
import java.util.concurrent.TimeUnit
1322
import java.util.concurrent.atomic.AtomicBoolean
@@ -113,6 +122,16 @@ internal abstract class MapboxRenderer(mapName: String) : DelegatingMapClient {
113122
map?.render()
114123
}
115124

125+
/**
126+
* Resets the renderer thread service type to Interactive.
127+
* Must be called on the render thread.
128+
*/
129+
@MapboxExperimental
130+
@RenderThread
131+
fun resetThreadServiceType() {
132+
map?.resetThreadServiceType()
133+
}
134+
116135
@UiThread
117136
fun onStop() {
118137
renderThread.pause()

0 commit comments

Comments
 (0)