Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor scheduling events in render thread #1068

Merged
merged 19 commits into from
Feb 3, 2022
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Mapbox welcomes participation and contributions from everyone.

# 10.4.0-beta.1

## Features ✨ and improvements 🏁
* Refactor scheduling logic for render thread in general slightly improving rendering performance. ([#1068](https://github.com/mapbox/mapbox-maps-android/pull/1068))

## Bug fixes 🐞
* Fix skipping / crashing user events scheduled on a render thread with `MapView#queueEvent`. ([#1068](https://github.com/mapbox/mapbox-maps-android/pull/1068))

# 10.3.0 February 7, 2022

## Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mapbox.maps.testapp.examples.SimpleMapActivity
import com.mapbox.maps.testapp.examples.TextureViewActivity
import com.mapbox.maps.testapp.integration.BaseIntegrationTest
import com.mapbox.maps.testapp.integration.launchActivity
import org.junit.Rule
Expand All @@ -30,7 +29,7 @@ class SurfaceViewReopenTest : BaseIntegrationTest() {
device.pressHome()
device.waitForIdle()
activityRule.scenario.onActivity {
device.launchActivity(it, TextureViewActivity::class.java)
device.launchActivity(it, SimpleMapActivity::class.java)
device.waitForIdle()
}
}
Expand Down
60 changes: 60 additions & 0 deletions sdk/src/androidTest/java/com/mapbox/maps/RenderTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.mapbox.maps

import android.opengl.GLES20
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.filters.LargeTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException

@RunWith(Parameterized::class)
@LargeTest
class RenderTest(
private val useTexture: Boolean,
private val eventNeedRender: Boolean,
) {

@get:Rule
val rule = ActivityScenarioRule(EmptyActivity::class.java)

@Test
fun userQueueEventNeedRender() {
val latch = CountDownLatch(1)
var openGlVersionString = ""
rule.scenario.onActivity {
it.runOnUiThread {
val mapView = MapView(it, MapInitOptions(it, textureView = useTexture))
mapView.queueEvent(
{
openGlVersionString = GLES20.glGetString(GLES20.GL_VERSION)
// assume anything should already have OpenGL ES 3+...
assert(openGlVersionString.contains("OpenGL ES 3."))
latch.countDown()
},
needRender = eventNeedRender
)
it.frameLayout.addView(mapView)
mapView.onStart()
}
}
if (!latch.await(LATCH_TIMEOUT_SEC, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}

companion object {
private const val LATCH_TIMEOUT_SEC = 5L
@JvmStatic
@Parameterized.Parameters
fun data() = listOf(
arrayOf(/* useTexture */ true, /* eventNeedRender */ true),
arrayOf(/* useTexture */ true, /* eventNeedRender */ false),
arrayOf(/* useTexture */ false, /* eventNeedRender */ true),
arrayOf(/* useTexture */ false, /* eventNeedRender */ false),
)
}
}
4 changes: 2 additions & 2 deletions sdk/src/main/java/com/mapbox/maps/MapView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ open class MapView : FrameLayout, MapPluginProviderDelegate, MapControllable {
@JvmStatic
fun isRenderingSupported(): Boolean {
EGLCore(false, DEFAULT_ANTIALIASING_SAMPLE_COUNT).apply {
prepareEgl()
val eglConfigOk = prepareEgl()
release()
return eglStatusSuccess
return eglConfigOk
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions sdk/src/main/java/com/mapbox/maps/renderer/EventType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mapbox.maps.renderer

/**
* Render event type.
*/
internal enum class EventType {
kiryldz marked this conversation as resolved.
Show resolved Hide resolved
/**
* Those events are scheduled by our SDK.
* Such events get cleared when Android provides new surface or texture.
*/
SDK,

/**
* Those events are scheduled by not our SDK (most likely by the user using MapView#queueEvent)
* Such events do not get cleared when Android provides new surface or texture.
* In case render thread is not fully prepared - such messages will keep being rescheduled until thread is prepared or killed.
*/
OTHER,

/**
* TODO remove when gl-native fix will land
kiryldz marked this conversation as resolved.
Show resolved Hide resolved
*/
DESTROY_RENDERER,
}
Loading