From a4258ccbb8550b9dea9eac62680c4c83fc848502 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Wed, 21 Aug 2024 00:28:00 +0300 Subject: [PATCH] Toggle tile cache final API (#2723) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bart Louwers --- include/mbgl/renderer/renderer.hpp | 1 + .../src/cpp/android_renderer_frontend.cpp | 4 ++ .../src/cpp/android_renderer_frontend.hpp | 1 + .../src/cpp/native_map_view.cpp | 15 +++-- .../src/cpp/native_map_view.hpp | 6 +- .../maplibre/android/maps/MapLibreMap.java | 34 ++++++----- .../org/maplibre/android/maps/NativeMap.java | 6 +- .../maplibre/android/maps/NativeMapView.java | 32 +++++++---- .../maplibre/android/maps/MapLibreMapTest.kt | 56 +++++++++++++++++-- platform/darwin/src/MLNRendererFrontend.h | 5 ++ platform/darwin/test/MLNMapViewTests.m | 9 +++ platform/ios/src/MLNMapView.h | 21 +++---- platform/ios/src/MLNMapView.mm | 16 ++++-- src/mbgl/renderer/render_orchestrator.cpp | 8 ++- src/mbgl/renderer/render_orchestrator.hpp | 1 + src/mbgl/renderer/render_source.hpp | 2 +- src/mbgl/renderer/renderer.cpp | 4 ++ .../renderer/sources/render_tile_source.cpp | 4 +- .../renderer/sources/render_tile_source.hpp | 2 +- src/mbgl/renderer/tile_pyramid.cpp | 4 +- src/mbgl/renderer/tile_pyramid.hpp | 2 +- 21 files changed, 170 insertions(+), 63 deletions(-) diff --git a/include/mbgl/renderer/renderer.hpp b/include/mbgl/renderer/renderer.hpp index fc2a67ef8..71771b982 100644 --- a/include/mbgl/renderer/renderer.hpp +++ b/include/mbgl/renderer/renderer.hpp @@ -109,6 +109,7 @@ public: // Memory void setTileCacheEnabled(bool); + bool getTileCacheEnabled() const; void reduceMemoryUse(); void clearData(); diff --git a/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.cpp b/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.cpp index 517acb3c9..da2bbc3e8 100644 --- a/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.cpp +++ b/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.cpp @@ -92,6 +92,10 @@ void AndroidRendererFrontend::setTileCacheEnabled(bool enabled) { mapRenderer.actor().invoke(&Renderer::setTileCacheEnabled, enabled); } +bool AndroidRendererFrontend::getTileCacheEnabled() const { + return mapRenderer.actor().ask(&Renderer::getTileCacheEnabled).get(); +} + void AndroidRendererFrontend::reduceMemoryUse() { mapRenderer.actor().invoke(&Renderer::reduceMemoryUse); } diff --git a/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.hpp b/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.hpp index 85f2c254a..2eb325c9c 100644 --- a/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.hpp +++ b/platform/android/MapLibreAndroid/src/cpp/android_renderer_frontend.hpp @@ -55,6 +55,7 @@ public: // Memory void setTileCacheEnabled(bool); + bool getTileCacheEnabled() const; void reduceMemoryUse(); private: diff --git a/platform/android/MapLibreAndroid/src/cpp/native_map_view.cpp b/platform/android/MapLibreAndroid/src/cpp/native_map_view.cpp index d08f3ac34..a86de91c3 100644 --- a/platform/android/MapLibreAndroid/src/cpp/native_map_view.cpp +++ b/platform/android/MapLibreAndroid/src/cpp/native_map_view.cpp @@ -676,10 +676,6 @@ jni::Local> NativeMapView::addMarkers(jni::JNIEnv& env, return result; } -void NativeMapView::setTileCacheEnabled(JNIEnv&, jni::jboolean enabled) { - rendererFrontend->setTileCacheEnabled(enabled); -} - void NativeMapView::onLowMemory(JNIEnv&) { rendererFrontend->reduceMemoryUse(); } @@ -1215,6 +1211,14 @@ jni::jint NativeMapView::getPrefetchZoomDelta(JNIEnv&) { return jni::jint(map->getPrefetchZoomDelta()); } +void NativeMapView::setTileCacheEnabled(JNIEnv&, jni::jboolean enabled) { + rendererFrontend->setTileCacheEnabled(enabled); +} + +jni::jboolean NativeMapView::getTileCacheEnabled(JNIEnv&) { + return jni::jboolean(rendererFrontend->getTileCacheEnabled()); +} + mbgl::Map& NativeMapView::getMap() { return *map; } @@ -1288,7 +1292,6 @@ void NativeMapView::registerNative(jni::JNIEnv& env) { METHOD(&NativeMapView::setDebug, "nativeSetDebug"), METHOD(&NativeMapView::getDebug, "nativeGetDebug"), METHOD(&NativeMapView::isFullyLoaded, "nativeIsFullyLoaded"), - METHOD(&NativeMapView::setTileCacheEnabled, "nativeSetTileCacheEnabled"), METHOD(&NativeMapView::onLowMemory, "nativeOnLowMemory"), METHOD(&NativeMapView::getMetersPerPixelAtLatitude, "nativeGetMetersPerPixelAtLatitude"), METHOD(&NativeMapView::projectedMetersForLatLng, "nativeProjectedMetersForLatLng"), @@ -1333,6 +1336,8 @@ void NativeMapView::registerNative(jni::JNIEnv& env) { METHOD(&NativeMapView::getPrefetchTiles, "nativeGetPrefetchTiles"), METHOD(&NativeMapView::setPrefetchZoomDelta, "nativeSetPrefetchZoomDelta"), METHOD(&NativeMapView::getPrefetchZoomDelta, "nativeGetPrefetchZoomDelta"), + METHOD(&NativeMapView::setTileCacheEnabled, "nativeSetTileCacheEnabled"), + METHOD(&NativeMapView::getTileCacheEnabled, "nativeGetTileCacheEnabled"), METHOD(&NativeMapView::triggerRepaint, "nativeTriggerRepaint")); } diff --git a/platform/android/MapLibreAndroid/src/cpp/native_map_view.hpp b/platform/android/MapLibreAndroid/src/cpp/native_map_view.hpp index 7cc293973..56cce5160 100644 --- a/platform/android/MapLibreAndroid/src/cpp/native_map_view.hpp +++ b/platform/android/MapLibreAndroid/src/cpp/native_map_view.hpp @@ -192,8 +192,6 @@ public: jni::Local> addMarkers(jni::JNIEnv&, const jni::Array>&); - void setTileCacheEnabled(JNIEnv&, jni::jboolean); - void onLowMemory(JNIEnv& env); void setDebug(JNIEnv&, jni::jboolean); @@ -292,6 +290,10 @@ public: jni::jint getPrefetchZoomDelta(JNIEnv&); + void setTileCacheEnabled(JNIEnv&, jni::jboolean); + + jni::jboolean getTileCacheEnabled(JNIEnv&); + mbgl::Map& getMap(); void triggerRepaint(JNIEnv&); diff --git a/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/MapLibreMap.java b/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/MapLibreMap.java index ecc80b707..d870a76a3 100644 --- a/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/MapLibreMap.java +++ b/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/MapLibreMap.java @@ -324,6 +324,26 @@ public final class MapLibreMap { return nativeMapView.getPrefetchZoomDelta(); } + /** + * Indicating whether the map may cache tiles for different zoom levels or not. + * + * @param enabled true causes the map view to consume more memory and have a smoother user + * experience when zoom in/out. The default value of this property is `true`. + */ + public void setTileCacheEnabled(boolean enabled) { + nativeMapView.setTileCacheEnabled(enabled); + } + + /** + * Check whether tile cache is enabled or not. + * + * @return true if enabled + * @see MapLibreMap#setTileCacheEnabled(boolean) + */ + public boolean getTileCacheEnabled() { + return nativeMapView.getTileCacheEnabled(); + } + // // MinZoom // @@ -2504,18 +2524,4 @@ public final class MapLibreMap { listener.onDeveloperAnimationStarted(); } } - - // - // Tile cache - // - - /** - * Indicating whether the map may cache tiles for different zoom levels or not. - * - * @param enabled true causes the map view to consume more memory and have a smoother user - * experience when zoom in/out. The default value of this property is `true`. - */ - public void experimental_setTileCacheEnabled(boolean enabled) { - nativeMapView.setTileCacheEnabled(enabled); - } } diff --git a/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/NativeMap.java b/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/NativeMap.java index 25c57de4d..21ee93977 100644 --- a/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/NativeMap.java +++ b/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/NativeMap.java @@ -33,8 +33,6 @@ interface NativeMap { void resizeView(int width, int height); - void setTileCacheEnabled(boolean enabled); - void onLowMemory(); void destroy(); @@ -235,6 +233,10 @@ interface NativeMap { @IntRange(from = 0) int getPrefetchZoomDelta(); + void setTileCacheEnabled(boolean enabled); + + boolean getTileCacheEnabled(); + void setGestureInProgress(boolean inProgress); float getPixelRatio(); diff --git a/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/NativeMapView.java b/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/NativeMapView.java index 4edd87101..18879be31 100755 --- a/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/NativeMapView.java +++ b/platform/android/MapLibreAndroid/src/main/java/org/maplibre/android/maps/NativeMapView.java @@ -619,14 +619,6 @@ final class NativeMapView implements NativeMap { nativeSetVisibleCoordinateBounds(coordinates, padding, direction, duration); } - @Override - public void setTileCacheEnabled(boolean enabled) { - if (checkState("setTileCacheEnabled")) { - return; - } - nativeSetTileCacheEnabled(enabled); - } - @Override public void onLowMemory() { if (checkState("onLowMemory")) { @@ -815,6 +807,21 @@ final class NativeMapView implements NativeMap { return nativeGetPrefetchZoomDelta(); } + @Override + public void setTileCacheEnabled(boolean enabled) { + if (checkState("setTileCacheEnabled")) { + return; + } + nativeSetTileCacheEnabled(enabled); + } + + @Override + public boolean getTileCacheEnabled() { + if (checkState("getTileCacheEnabled")) { + return false; + } + return nativeGetTileCacheEnabled(); + } // Runtime style Api @Override @@ -1340,9 +1347,6 @@ final class NativeMapView implements NativeMap { private native void nativeSetVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration); - @Keep - private native void nativeSetTileCacheEnabled(boolean enabled); - @Keep private native void nativeOnLowMemory(); @@ -1510,6 +1514,12 @@ final class NativeMapView implements NativeMap { @Keep private native void nativeSetPrefetchZoomDelta(int delta); + @Keep + private native void nativeSetTileCacheEnabled(boolean enabled); + + @Keep + private native boolean nativeGetTileCacheEnabled(); + @Keep private native int nativeGetPrefetchZoomDelta(); diff --git a/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/maps/MapLibreMapTest.kt b/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/maps/MapLibreMapTest.kt index 06675e984..48a9334f9 100644 --- a/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/maps/MapLibreMapTest.kt +++ b/platform/android/MapLibreAndroidTestApp/src/androidTest/java/org/maplibre/android/maps/MapLibreMapTest.kt @@ -32,12 +32,12 @@ import org.maplibre.android.testapp.activity.EspressoTest * with the application UI-thread. * */ -@Deprecated("remove this file when removing deprecated annotations") class MapLibreMapTest : EspressoTest() { // // InfoWindow // @Test + @Deprecated("remove this test when removing deprecated annotations") fun testConcurrentInfoWindowEnabled() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -47,6 +47,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testConcurrentInfoWindowDisabled() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -56,6 +57,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testInfoWindowAdapter() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -69,6 +71,7 @@ class MapLibreMapTest : EspressoTest() { // Annotations // @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddMarker() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -79,11 +82,13 @@ class MapLibreMapTest : EspressoTest() { } @Test(expected = InvalidMarkerPositionException::class) + @Deprecated("remove this test when removing deprecated annotations") fun testAddMarkerInvalidPosition() { MarkerOptions().marker } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddMarkers() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -100,6 +105,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddMarkersEmpty() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -110,6 +116,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddMarkersSingleMarker() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -123,6 +130,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddPolygon() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -133,6 +141,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddEmptyPolygon() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -143,6 +152,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddPolygons() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -162,6 +172,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun addPolygonsEmpty() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -171,6 +182,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun addPolygonsSingle() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -184,6 +196,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddPolyline() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -194,6 +207,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddEmptyPolyline() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -204,6 +218,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddPolylines() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -219,12 +234,13 @@ class MapLibreMapTest : EspressoTest() { assertTrue(maplibreMap.polylines.contains(polygonOptions1.polyline)) assertTrue(maplibreMap.polylines.contains(polygonOptions2.polyline)) assertTrue( - "Polyline should be ignored", !maplibreMap.polylines.contains(polygonOptions3.polyline) + "Polyline should be ignored", !maplibreMap.polylines.contains(polygonOptions3.polyline) ) }) } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddPolylinesEmpty() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -234,6 +250,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testAddPolylinesSingle() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -247,6 +264,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testRemoveMarker() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -258,6 +276,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testRemovePolygon() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -269,6 +288,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testRemovePolyline() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -280,6 +300,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testRemoveAnnotation() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -291,6 +312,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testRemoveAnnotationById() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -303,6 +325,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testRemoveAnnotations() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -318,6 +341,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testClear() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -333,6 +357,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testRemoveAnnotationsByList() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -350,6 +375,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testGetAnnotationById() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -361,22 +387,25 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testGetAnnotations() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform( - MapLibreMapAction { uiController: UiController?, view: View? -> TestCase.assertNotNull("Annotations should be non null", maplibreMap.annotations) } + MapLibreMapAction { uiController: UiController?, view: View? -> TestCase.assertNotNull("Annotations should be non null", maplibreMap.annotations) } ) } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testGetMarkers() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform( - MapLibreMapAction { uiController: UiController?, view: View? -> TestCase.assertNotNull("Markers should be non null", maplibreMap.markers) } + MapLibreMapAction { uiController: UiController?, view: View? -> TestCase.assertNotNull("Markers should be non null", maplibreMap.markers) } ) } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testGetPolygons() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> TestCase.assertNotNull("Polygons should be non null", maplibreMap.polygons) } @@ -384,6 +413,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testGetPolylines() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> TestCase.assertNotNull("Polylines should be non null", maplibreMap.polylines) } @@ -391,6 +421,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testGetSelectedMarkers() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> TestCase.assertNotNull("Selected markers should be non null", maplibreMap.selectedMarkers) } @@ -398,6 +429,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testSelectMarker() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -409,6 +441,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testDeselectMarker() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -421,6 +454,7 @@ class MapLibreMapTest : EspressoTest() { } @Test + @Deprecated("remove this test when removing deprecated annotations") fun testDeselectMarkers() { validateTestSetup() onView(ViewMatchers.withId(R.id.mapView)).perform(MapLibreMapAction { uiController: UiController?, view: View? -> @@ -434,6 +468,19 @@ class MapLibreMapTest : EspressoTest() { }) } + @Test + fun testTileCache() { + validateTestSetup() + rule.runOnUiThread { + maplibreMap.tileCacheEnabled = false + assertTrue(maplibreMap.tileCacheEnabled == false) + + maplibreMap.tileCacheEnabled = true + assertTrue(maplibreMap.tileCacheEnabled == true) + } + } + + @Deprecated("remove this class when removing deprecated annotations") inner class MapLibreMapAction internal constructor(private val invokeViewAction: InvokeViewAction) : ViewAction { override fun getConstraints(): Matcher { return ViewMatchers.isDisplayed() @@ -448,6 +495,7 @@ class MapLibreMapTest : EspressoTest() { } } + @Deprecated("remove this interface when removing deprecated annotations") internal fun interface InvokeViewAction { fun onViewAction(uiController: UiController?, view: View?) } diff --git a/platform/darwin/src/MLNRendererFrontend.h b/platform/darwin/src/MLNRendererFrontend.h index 9bd58bfab..22e98780f 100644 --- a/platform/darwin/src/MLNRendererFrontend.h +++ b/platform/darwin/src/MLNRendererFrontend.h @@ -63,6 +63,11 @@ class MLNRenderFrontend : public mbgl::RendererFrontend { renderer->setTileCacheEnabled(enable); } + bool getTileCacheEnabled() { + if (!renderer) return false; + return renderer->getTileCacheEnabled(); + } + void reduceMemoryUse() { if (!renderer) return; renderer->reduceMemoryUse(); diff --git a/platform/darwin/test/MLNMapViewTests.m b/platform/darwin/test/MLNMapViewTests.m index 5658e91f7..bf48373fd 100644 --- a/platform/darwin/test/MLNMapViewTests.m +++ b/platform/darwin/test/MLNMapViewTests.m @@ -152,4 +152,13 @@ static MLNMapView *mapView; [self waitForExpectations:@[expectation] timeout:1]; } +- (void)testTileCache { + mapView.tileCacheEnabled = NO; + XCTAssertEqual(mapView.tileCacheEnabled, NO); + + mapView.tileCacheEnabled = YES; + XCTAssertEqual(mapView.tileCacheEnabled, YES); +} + + @end diff --git a/platform/ios/src/MLNMapView.h b/platform/ios/src/MLNMapView.h index fa307e1f0..1166bf942 100644 --- a/platform/ios/src/MLNMapView.h +++ b/platform/ios/src/MLNMapView.h @@ -415,6 +415,17 @@ MLN_EXPORT */ @property (nonatomic, assign) BOOL prefetchesTiles; +/** + A Boolean value indicating whether the map may cache tiles for different zoom levels or not. + + When this property is set to `YES`, the map view consumes more memory and + provide a smoother user experience when zoom in/out. + + The default value of this property is `YES`. + */ + +@property (nonatomic, assign) BOOL tileCacheEnabled; + // MARK: Displaying the User’s Location /** @@ -2093,16 +2104,6 @@ vertically on the map. predicate:(nullable NSPredicate *)predicate NS_SWIFT_NAME(visibleFeatures(in:styleLayerIdentifiers:predicate:)); -// MARK: Tile Cache - -/** - Indicating whether the map may cache tiles for different zoom levels or not. - - @param enabled causes the map view to consume more memory and have a smoother user - * experience when zoom in/out. The default value of this property is `YES`. - */ -- (void)experimental_setTileCacheEnabled:(BOOL)enabled; - // MARK: Debugging the Map /** diff --git a/platform/ios/src/MLNMapView.mm b/platform/ios/src/MLNMapView.mm index 47ace5aee..fa16cef76 100644 --- a/platform/ios/src/MLNMapView.mm +++ b/platform/ios/src/MLNMapView.mm @@ -3149,6 +3149,16 @@ static void *windowScreenContext = &windowScreenContext; return self.mbglMap.getPrefetchZoomDelta() > 0 ? YES : NO; } +- (void)setTileCacheEnabled:(BOOL)enabled +{ + _rendererFrontend->setTileCacheEnabled(enabled); +} + +- (BOOL)tileCacheEnabled +{ + return _rendererFrontend->getTileCacheEnabled(); +} + // MARK: - Accessibility - - (NSString *)accessibilityValue @@ -7340,12 +7350,6 @@ static void *windowScreenContext = &windowScreenContext; return _mbglView->getObject(); } -// MARK: Tile Cache - -- (void)experimental_setTileCacheEnabled:(BOOL)enabled { - _rendererFrontend->setTileCacheEnabled(enabled); -} - @end // MARK: - IBAdditions methods diff --git a/src/mbgl/renderer/render_orchestrator.cpp b/src/mbgl/renderer/render_orchestrator.cpp index 00c5ede7b..40e673a30 100644 --- a/src/mbgl/renderer/render_orchestrator.cpp +++ b/src/mbgl/renderer/render_orchestrator.cpp @@ -342,7 +342,7 @@ std::unique_ptr RenderOrchestrator::createRenderTree( MLN_TRACE_ZONE(create source); std::unique_ptr renderSource = RenderSource::create(entry.second, threadPool); renderSource->setObserver(this); - renderSource->enableCache(tileCacheEnabled); + renderSource->setCacheEnabled(tileCacheEnabled); renderSources.emplace(entry.first, std::move(renderSource)); } transformState = updateParameters->transformState; @@ -769,10 +769,14 @@ void RenderOrchestrator::setTileCacheEnabled(bool enable) { tileCacheEnabled = enable; for (const auto& entry : renderSources) { - entry.second->enableCache(enable); + entry.second->setCacheEnabled(enable); } } +bool RenderOrchestrator::getTileCacheEnabled() const { + return tileCacheEnabled; +} + void RenderOrchestrator::reduceMemoryUse() { MLN_TRACE_FUNC() diff --git a/src/mbgl/renderer/render_orchestrator.hpp b/src/mbgl/renderer/render_orchestrator.hpp index d04bc4742..ab5bf3df8 100644 --- a/src/mbgl/renderer/render_orchestrator.hpp +++ b/src/mbgl/renderer/render_orchestrator.hpp @@ -93,6 +93,7 @@ public: const std::optional& stateKey); void setTileCacheEnabled(bool); + bool getTileCacheEnabled() const; void reduceMemoryUse(); void dumpDebugLogs(); void collectPlacedSymbolData(bool); diff --git a/src/mbgl/renderer/render_source.hpp b/src/mbgl/renderer/render_source.hpp index f9925d491..0482acb49 100644 --- a/src/mbgl/renderer/render_source.hpp +++ b/src/mbgl/renderer/render_source.hpp @@ -101,7 +101,7 @@ public: const std::optional&, const std::optional&) {} - virtual void enableCache(bool) {}; + virtual void setCacheEnabled(bool) {}; virtual void reduceMemoryUse() = 0; diff --git a/src/mbgl/renderer/renderer.cpp b/src/mbgl/renderer/renderer.cpp index e31965001..f831f404d 100644 --- a/src/mbgl/renderer/renderer.cpp +++ b/src/mbgl/renderer/renderer.cpp @@ -138,6 +138,10 @@ void Renderer::setTileCacheEnabled(bool enable) { impl->orchestrator.setTileCacheEnabled(enable); } +bool Renderer::getTileCacheEnabled() const { + return impl->orchestrator.getTileCacheEnabled(); +} + void Renderer::reduceMemoryUse() { gfx::BackendScope guard{impl->backend}; impl->reduceMemoryUse(); diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index 30c02d926..ed203ddfb 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -497,8 +497,8 @@ void RenderTileSource::removeFeatureState(const std::optional& sour featureState.removeState(sourceLayerID, featureID, stateKey); } -void RenderTileSource::enableCache(bool enable) { - tilePyramid.enableCache(enable); +void RenderTileSource::setCacheEnabled(bool enable) { + tilePyramid.setCacheEnabled(enable); } void RenderTileSource::reduceMemoryUse() { diff --git a/src/mbgl/renderer/sources/render_tile_source.hpp b/src/mbgl/renderer/sources/render_tile_source.hpp index 5ad78e11c..66681a7f1 100644 --- a/src/mbgl/renderer/sources/render_tile_source.hpp +++ b/src/mbgl/renderer/sources/render_tile_source.hpp @@ -47,7 +47,7 @@ public: const std::optional&, const std::optional&) override; - void enableCache(bool) override; + void setCacheEnabled(bool) override; void reduceMemoryUse() override; void dumpDebugLogs() const override; diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp index cc941ad4a..71b3951d1 100644 --- a/src/mbgl/renderer/tile_pyramid.cpp +++ b/src/mbgl/renderer/tile_pyramid.cpp @@ -23,7 +23,7 @@ namespace mbgl { using namespace style; static TileObserver nullObserver; -static std::map> emptyPrefetchedTiles; +static const std::map> emptyPrefetchedTiles; TilePyramid::TilePyramid(const TaggedScheduler& threadPool_) : cache(threadPool_), @@ -398,7 +398,7 @@ std::vector TilePyramid::querySourceFeatures(const SourceQueryOptions& return result; } -void TilePyramid::enableCache(bool enable) { +void TilePyramid::setCacheEnabled(bool enable) { cacheEnabled = enable; } diff --git a/src/mbgl/renderer/tile_pyramid.hpp b/src/mbgl/renderer/tile_pyramid.hpp index c56d7ea23..351c81043 100644 --- a/src/mbgl/renderer/tile_pyramid.hpp +++ b/src/mbgl/renderer/tile_pyramid.hpp @@ -60,7 +60,7 @@ public: std::vector querySourceFeatures(const SourceQueryOptions&) const; - void enableCache(bool); + void setCacheEnabled(bool); void reduceMemoryUse(); void setObserver(TileObserver*);