Fix recycler view test (#3537)

This commit is contained in:
Adrian Cojocaru
2025-06-07 20:00:38 +03:00
committed by GitHub
parent b0e2e2ce85
commit 6704f0f80a
13 changed files with 42 additions and 30 deletions

View File

@@ -68,6 +68,11 @@ void AndroidVulkanRendererBackend::resizeFramebuffer(int width, int height) {
}
}
PremultipliedImage AndroidVulkanRendererBackend::readFramebuffer() {
// TODO not implemented
return PremultipliedImage(Size(2, 2));
}
} // namespace android
} // namespace mbgl

View File

@@ -21,6 +21,7 @@ public:
std::vector<const char*> getInstanceExtensions() override;
void resizeFramebuffer(int width, int height) override;
PremultipliedImage readFramebuffer() override;
// mbgl::gfx::RendererBackend implementation
public:

View File

@@ -234,8 +234,14 @@ void MapRenderer::onSurfaceCreated(JNIEnv& env, const jni::Object<AndroidSurface
// The android system will have already destroyed the underlying
// GL resources if this is not the first initialization and an
// attempt to clean them up will fail
if (backend) backend->markContextLost();
if (renderer) renderer->markContextLost();
if (backend) {
gfx::BackendScope backendGuard{backend->getImpl()};
backend->markContextLost();
}
if (renderer) {
renderer->markContextLost();
}
// Reset in opposite order
renderer.reset();
@@ -270,12 +276,14 @@ void MapRenderer::onSurfaceCreated(JNIEnv& env, const jni::Object<AndroidSurface
}
}
void MapRenderer::onSurfaceChanged(JNIEnv& env, jint width, jint height) {
void MapRenderer::onSurfaceChanged([[maybe_unused]] JNIEnv& env, jint width, jint height) {
#if MLN_RENDER_BACKEND_OPENGL
if (!renderer) {
// In case the surface has been destroyed (due to app back-grounding)
jni::jobject* nullObj = nullptr;
onSurfaceCreated(env, jni::Object<AndroidSurface>(nullObj));
}
#endif
backend->resizeFramebuffer(width, height);
framebufferSizeChanged = true;

View File

@@ -61,15 +61,6 @@ public class MapLibreVulkanSurfaceView extends MapLibreSurfaceView {
renderThreadManager.notifyAll();
}
if (paused && graphicsSurfaceCreated) {
MapLibreVulkanSurfaceView view = mSurfaceViewWeakRef.get();
if (view != null) {
destroySurface = true;
graphicsSurfaceCreated = false;
}
renderThreadManager.notifyAll();
}
// lost surface
if (!hasSurface && !waitingForSurface) {
MapLibreVulkanSurfaceView view = mSurfaceViewWeakRef.get();
@@ -105,7 +96,7 @@ public class MapLibreVulkanSurfaceView extends MapLibreSurfaceView {
}
// Ready to draw?
if (readyToDraw()) {
if (readyToDraw() && graphicsSurfaceCreated) {
if (this.sizeChanged) {
sizeChanged = true;
w = width;
@@ -144,6 +135,7 @@ public class MapLibreVulkanSurfaceView extends MapLibreSurfaceView {
if (view != null) {
view.renderer.onSurfaceDestroyed();
destroySurface = false;
continue;
}
}

View File

@@ -9,10 +9,10 @@ import org.junit.Test
import org.junit.runner.RunWith
/**
* Regression test that validates reopening an Activity with a GLSurfaceView
* Regression test that validates reopening an Activity with a SurfaceView
*/
@RunWith(AndroidJUnit4ClassRunner::class)
class GLSurfaceViewReopenTest : BaseIntegrationTest() {
class SurfaceViewReopenTest : BaseIntegrationTest() {
@get:Rule
var activityRule: ActivityTestRule<SimpleMapActivity> = ActivityTestRule(SimpleMapActivity::class.java)

View File

@@ -3,19 +3,19 @@ package org.maplibre.android.integration
import androidx.test.filters.LargeTest
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import androidx.test.rule.ActivityTestRule
import org.maplibre.android.testapp.activity.maplayout.GLSurfaceRecyclerViewActivity
import org.maplibre.android.testapp.activity.maplayout.SurfaceRecyclerViewActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
/**
* Regression test that validates if a GLSurfaceView surface can be recreated without crashing.
* Regression test that validates if a SurfaceView surface can be recreated without crashing.
*/
@RunWith(AndroidJUnit4ClassRunner::class)
class GLSurfaceViewReuseTest : BaseIntegrationTest() {
class SurfaceViewReuseTest : BaseIntegrationTest() {
@get:Rule
var activityRule: ActivityTestRule<GLSurfaceRecyclerViewActivity> = ActivityTestRule(GLSurfaceRecyclerViewActivity::class.java)
var activityRule: ActivityTestRule<SurfaceRecyclerViewActivity> = ActivityTestRule(SurfaceRecyclerViewActivity::class.java)
@Test
@LargeTest

View File

@@ -1129,10 +1129,10 @@
android:value=".activity.FeatureOverviewActivity" />
</activity>
<activity
android:name=".activity.maplayout.GLSurfaceRecyclerViewActivity"
android:description="@string/description_recyclerview_glsurfaceview"
android:name=".activity.maplayout.SurfaceRecyclerViewActivity"
android:description="@string/description_recyclerview_surfaceview"
android:exported="true"
android:label="@string/activity_recyclerview_glsurfaceview">
android:label="@string/activity_recyclerview_surfaceview">
<meta-data
android:name="@string/category"
android:value="@string/category_integration" />

View File

@@ -9,16 +9,17 @@ import androidx.appcompat.app.AppCompatActivity
import org.maplibre.android.maps.MapView
import org.maplibre.android.testapp.R
import org.maplibre.android.testapp.databinding.ActivityRecyclerviewBinding
import org.maplibre.android.testapp.styles.TestStyles
/**
* TestActivity showcasing how to integrate multiple GLSurfaceView MapViews in a RecyclerView.
* TestActivity showcasing how to integrate multiple SurfaceView MapViews in a RecyclerView.
* <p>
* It requires calling the correct lifecycle methods when detaching and attaching the View to
* the RecyclerView with onViewAttachedToWindow and onViewDetachedFromWindow.
* </p>
*/
@SuppressLint("ClickableViewAccessibility")
open class GLSurfaceRecyclerViewActivity : AppCompatActivity() {
open class SurfaceRecyclerViewActivity : AppCompatActivity() {
lateinit var binding: ActivityRecyclerviewBinding
@@ -46,12 +47,12 @@ open class GLSurfaceRecyclerViewActivity : AppCompatActivity() {
return R.layout.item_map_gl
}
class ItemAdapter(private val activity: GLSurfaceRecyclerViewActivity, private val inflater: LayoutInflater) : androidx.recyclerview.widget.RecyclerView.Adapter<androidx.recyclerview.widget.RecyclerView.ViewHolder>() {
class ItemAdapter(private val activity: SurfaceRecyclerViewActivity, private val inflater: LayoutInflater) : androidx.recyclerview.widget.RecyclerView.Adapter<androidx.recyclerview.widget.RecyclerView.ViewHolder>() {
private val items: List<Any> = listOf(
"one", "two", "three", "four", "five", "seven", "eight", "nine", "ten",
"one", "two", "three", MapItem(TestStyles.DEMOTILES), "four", "five", MapItem(TestStyles.DEMOTILES), "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
"nineteen", "twenty", "twenty-one"
"nineteen", "twenty", "twenty-one",
)
private var mapHolders: MutableList<MapHolder> = mutableListOf()

View File

@@ -7,7 +7,7 @@ import org.maplibre.android.testapp.R
* TestActivity showcasing how to integrate multiple TexureView MapViews in a RecyclerView.
*/
@SuppressLint("ClickableViewAccessibility")
class TextureRecyclerViewActivity : GLSurfaceRecyclerViewActivity() {
class TextureRecyclerViewActivity : SurfaceRecyclerViewActivity() {
override fun getMapItemLayoutId(): Int {
return R.layout.item_map_texture

View File

@@ -95,7 +95,7 @@
<string name="description_location_manual">Force location updates and don\'t rely on the engine</string>
<string name="description_location_activation_builder">Use LocationComponentActivationOptions to set options</string>
<string name="description_recyclerview_textureview">Show multiple TextureView MapViews as recyclerView items</string>
<string name="description_recyclerview_glsurfaceview">Show multiple GLSurfaceView MapViews as recyclerView items</string>
<string name="description_recyclerview_surfaceview">Show multiple SurfaceView MapViews as recyclerView items</string>
<string name="description_nested_viewpager">Show a MapView inside a viewpager inside a recyclerView</string>
<string name="description_performance_measurement">Show the use PerformanceEvent for performance measurements</string>
<string name="description_physical_circle">Use TurfTransformation#circle() to show a Cirlce expressed in physical units</string>

View File

@@ -91,7 +91,7 @@
<string name="activity_location_manual">Manual Location updates</string>
<string name="activity_location_activation_builder">Build Location Activation</string>
<string name="activity_recyclerview_textureview">RecyclerView TextureView</string>
<string name="activity_recyclerview_glsurfaceview">RecyclerView GLSurfaceView</string>
<string name="activity_recyclerview_surfaceview">RecyclerView SurfaceView</string>
<string name="activity_nested_viewpager">Nested ViewPager</string>
<string name="activity_performance_measurement">Performance Measurement</string>
<string name="activity_physical_circle">Physical Unit Circle</string>

View File

@@ -107,6 +107,7 @@ public:
extension::Debugging* getDebuggingExtension() const { return debugging.get(); }
bool getCleanupOnDestruction() { return cleanupOnDestruction; }
void setCleanupOnDestruction(bool cleanup) { cleanupOnDestruction = cleanup; }
gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override;

View File

@@ -74,6 +74,10 @@ Texture2DPool::Texture2DPool(Context* context_, size_t maxPoolStorage_)
}
Texture2DPool::~Texture2DPool() {
if (!context->getCleanupOnDestruction()) {
return;
}
assert(usedStorage() == 0);
assert(unusedStorage() == poolStorage);
shrink();