diff --git a/platform/android/MapLibreAndroid/src/cpp/android_vulkan_renderer_backend.cpp b/platform/android/MapLibreAndroid/src/cpp/android_vulkan_renderer_backend.cpp index 752d2cb78..043bc5c4f 100644 --- a/platform/android/MapLibreAndroid/src/cpp/android_vulkan_renderer_backend.cpp +++ b/platform/android/MapLibreAndroid/src/cpp/android_vulkan_renderer_backend.cpp @@ -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 diff --git a/platform/android/MapLibreAndroid/src/cpp/android_vulkan_renderer_backend.hpp b/platform/android/MapLibreAndroid/src/cpp/android_vulkan_renderer_backend.hpp index 8094a2f5c..1d6f988ca 100644 --- a/platform/android/MapLibreAndroid/src/cpp/android_vulkan_renderer_backend.hpp +++ b/platform/android/MapLibreAndroid/src/cpp/android_vulkan_renderer_backend.hpp @@ -21,6 +21,7 @@ public: std::vector getInstanceExtensions() override; void resizeFramebuffer(int width, int height) override; + PremultipliedImage readFramebuffer() override; // mbgl::gfx::RendererBackend implementation public: diff --git a/platform/android/MapLibreAndroid/src/cpp/map_renderer.cpp b/platform/android/MapLibreAndroid/src/cpp/map_renderer.cpp index 9fd889e05..fd75d2828 100644 --- a/platform/android/MapLibreAndroid/src/cpp/map_renderer.cpp +++ b/platform/android/MapLibreAndroid/src/cpp/map_renderer.cpp @@ -234,8 +234,14 @@ void MapRenderer::onSurfaceCreated(JNIEnv& env, const jni::ObjectmarkContextLost(); - 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(nullObj)); } +#endif backend->resizeFramebuffer(width, height); framebufferSizeChanged = true; diff --git a/platform/android/MapLibreAndroid/src/vulkan/java/org/maplibre/android/maps/renderer/surfaceview/MapLibreVulkanSurfaceView.java b/platform/android/MapLibreAndroid/src/vulkan/java/org/maplibre/android/maps/renderer/surfaceview/MapLibreVulkanSurfaceView.java index 7d38575ef..433dbae4e 100644 --- a/platform/android/MapLibreAndroid/src/vulkan/java/org/maplibre/android/maps/renderer/surfaceview/MapLibreVulkanSurfaceView.java +++ b/platform/android/MapLibreAndroid/src/vulkan/java/org/maplibre/android/maps/renderer/surfaceview/MapLibreVulkanSurfaceView.java @@ -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; } } diff --git a/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/GLSurfaceViewReopenTest.kt b/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/SurfaceViewReopenTest.kt similarity index 85% rename from platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/GLSurfaceViewReopenTest.kt rename to platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/SurfaceViewReopenTest.kt index 485f1476f..8684216c4 100644 --- a/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/GLSurfaceViewReopenTest.kt +++ b/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/SurfaceViewReopenTest.kt @@ -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 = ActivityTestRule(SimpleMapActivity::class.java) diff --git a/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/GLSurfaceViewReuseTest.kt b/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/SurfaceViewReuseTest.kt similarity index 61% rename from platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/GLSurfaceViewReuseTest.kt rename to platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/SurfaceViewReuseTest.kt index 0839de3f6..3240c2300 100644 --- a/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/GLSurfaceViewReuseTest.kt +++ b/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/integration/SurfaceViewReuseTest.kt @@ -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 = ActivityTestRule(GLSurfaceRecyclerViewActivity::class.java) + var activityRule: ActivityTestRule = ActivityTestRule(SurfaceRecyclerViewActivity::class.java) @Test @LargeTest diff --git a/platform/android/MapLibreAndroidTestApp/src/main/AndroidManifest.xml b/platform/android/MapLibreAndroidTestApp/src/main/AndroidManifest.xml index 85aaf0875..348e3557e 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapLibreAndroidTestApp/src/main/AndroidManifest.xml @@ -1129,10 +1129,10 @@ android:value=".activity.FeatureOverviewActivity" /> + android:label="@string/activity_recyclerview_surfaceview"> diff --git a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/maplayout/GLSurfaceRecyclerViewActivity.kt b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/maplayout/SurfaceRecyclerViewActivity.kt similarity index 89% rename from platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/maplayout/GLSurfaceRecyclerViewActivity.kt rename to platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/maplayout/SurfaceRecyclerViewActivity.kt index 9a4827ba6..14e585c29 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/maplayout/GLSurfaceRecyclerViewActivity.kt +++ b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/maplayout/SurfaceRecyclerViewActivity.kt @@ -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. *

* It requires calling the correct lifecycle methods when detaching and attaching the View to * the RecyclerView with onViewAttachedToWindow and onViewDetachedFromWindow. *

*/ @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() { + class ItemAdapter(private val activity: SurfaceRecyclerViewActivity, private val inflater: LayoutInflater) : androidx.recyclerview.widget.RecyclerView.Adapter() { private val items: List = 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 = mutableListOf() diff --git a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/maplayout/TextureRecyclerViewActivity.kt b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/maplayout/TextureRecyclerViewActivity.kt index 2db941fe1..6c1d7f467 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/maplayout/TextureRecyclerViewActivity.kt +++ b/platform/android/MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/maplayout/TextureRecyclerViewActivity.kt @@ -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 diff --git a/platform/android/MapLibreAndroidTestApp/src/main/res/values/descriptions.xml b/platform/android/MapLibreAndroidTestApp/src/main/res/values/descriptions.xml index fcfdcb842..cbeab37c0 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/res/values/descriptions.xml +++ b/platform/android/MapLibreAndroidTestApp/src/main/res/values/descriptions.xml @@ -95,7 +95,7 @@ Force location updates and don\'t rely on the engine Use LocationComponentActivationOptions to set options Show multiple TextureView MapViews as recyclerView items - Show multiple GLSurfaceView MapViews as recyclerView items + Show multiple SurfaceView MapViews as recyclerView items Show a MapView inside a viewpager inside a recyclerView Show the use PerformanceEvent for performance measurements Use TurfTransformation#circle() to show a Cirlce expressed in physical units diff --git a/platform/android/MapLibreAndroidTestApp/src/main/res/values/titles.xml b/platform/android/MapLibreAndroidTestApp/src/main/res/values/titles.xml index 6a0953d43..66121464a 100644 --- a/platform/android/MapLibreAndroidTestApp/src/main/res/values/titles.xml +++ b/platform/android/MapLibreAndroidTestApp/src/main/res/values/titles.xml @@ -91,7 +91,7 @@ Manual Location updates Build Location Activation RecyclerView TextureView - RecyclerView GLSurfaceView + RecyclerView SurfaceView Nested ViewPager Performance Measurement Physical Unit Circle diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 6ce4bb0ee..d7757e15c 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -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; diff --git a/src/mbgl/gl/resource_pool.cpp b/src/mbgl/gl/resource_pool.cpp index 2de7b8056..e9f8e2ad4 100644 --- a/src/mbgl/gl/resource_pool.cpp +++ b/src/mbgl/gl/resource_pool.cpp @@ -74,6 +74,10 @@ Texture2DPool::Texture2DPool(Context* context_, size_t maxPoolStorage_) } Texture2DPool::~Texture2DPool() { + if (!context->getCleanupOnDestruction()) { + return; + } + assert(usedStorage() == 0); assert(unusedStorage() == poolStorage); shrink();