Skip to content

Commit

Permalink
Replace old render cache API with new implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
pengdev committed Jun 8, 2021
1 parent 5825f21 commit 209d441
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 120 deletions.
35 changes: 19 additions & 16 deletions sdk/src/androidTest/java/com/mapbox/maps/RenderCacheTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException

@MapboxExperimental
class RenderCacheTest {

@get:Rule
Expand Down Expand Up @@ -36,10 +37,10 @@ class RenderCacheTest {
fun setDisabledRenderCache() {
rule.scenario.onActivity {
it.runOnUiThread {
mapView.setRenderCache(RenderCache.Disabled)
mapView.getMapboxMap().setRenderCacheOptions(RenderCacheOptions.Builder().setDisabled().build())
Assert.assertEquals(
RenderCache.CACHE_DISABLED,
Settings.get(RenderCache.RENDER_CACHE_SETTING).contents as Long
RENDER_CACHE_DISABLED,
mapView.getMapboxMap().getRenderCacheOptions().size
)
}
}
Expand All @@ -49,10 +50,10 @@ class RenderCacheTest {
fun setSmallRenderCache() {
rule.scenario.onActivity {
it.runOnUiThread {
mapView.setRenderCache(RenderCache.Small)
mapView.getMapboxMap().setRenderCacheOptions(RenderCacheOptions.Builder().setSmallSize().build())
Assert.assertEquals(
RenderCache.CACHE_SIZE_SMALL_MB,
Settings.get(RenderCache.RENDER_CACHE_SETTING).contents as Long
RENDER_CACHE_SIZE_SMALL_MB,
mapView.getMapboxMap().getRenderCacheOptions().size
)
}
}
Expand All @@ -62,10 +63,10 @@ class RenderCacheTest {
fun setLargeRenderCache() {
rule.scenario.onActivity {
it.runOnUiThread {
mapView.setRenderCache(RenderCache.Large)
mapView.getMapboxMap().setRenderCacheOptions(RenderCacheOptions.Builder().setLargeSize().build())
Assert.assertEquals(
RenderCache.CACHE_SIZE_LARGE_MB,
Settings.get(RenderCache.RENDER_CACHE_SETTING).contents as Long
RENDER_CACHE_SIZE_LARGE_MB,
mapView.getMapboxMap().getRenderCacheOptions().size
)
}
}
Expand All @@ -75,24 +76,26 @@ class RenderCacheTest {
fun setCustomRenderCache() {
rule.scenario.onActivity {
it.runOnUiThread {
val customSize = 256L
mapView.setRenderCache(RenderCache.Custom(customSize))
val customSize = 256
mapView.getMapboxMap().setRenderCacheOptions(RenderCacheOptions.Builder().size(customSize).build())
Assert.assertEquals(
customSize, Settings.get(RenderCache.RENDER_CACHE_SETTING).contents as Long
customSize,
mapView.getMapboxMap().getRenderCacheOptions().size
)
}
}
}

@Test
@Ignore("TODO Uncomment after https://github.com/mapbox/mapbox-maps-android/issues/402")
fun setInvalidRenderCache() {
rule.scenario.onActivity {
it.runOnUiThread {
val customSize = -1L
mapView.setRenderCache(RenderCache.Custom(customSize))
// render cache disabled by default now so checking for 0 here
val customSize = -1
mapView.getMapboxMap().setRenderCacheOptions(RenderCacheOptions.Builder().size(customSize).build())
Assert.assertEquals(
0L, Settings.get(RenderCache.RENDER_CACHE_SETTING).contents as Long
0,
mapView.getMapboxMap().getRenderCacheOptions().size
)
}
}
Expand Down
14 changes: 0 additions & 14 deletions sdk/src/main/java/com/mapbox/maps/MapControllable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@ interface MapControllable {
*/
fun onSizeChanged(w: Int, h: Int)

/**
* Render cache is introduced to store intermediate rendering results of tiles into cache textures
* to be reused in future frames.
* It's considerably smaller effort from the GPU to render quads with single texture lookups
* rather than rendering geometries of individual layers and tiles separately.
*
* Using render cache may bring improvement to rendering performance
* and reduce communication between CPU and GPU.
*
* @param cache [RenderCache] to apply to given [MapView].
*/
@MapboxExperimental
fun setRenderCache(cache: RenderCache)

/**
* Queue a runnable to be executed on the map renderer thread.
*
Expand Down
11 changes: 0 additions & 11 deletions sdk/src/main/java/com/mapbox/maps/MapController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import android.os.Looper
import android.util.AttributeSet
import android.view.MotionEvent
import com.mapbox.annotation.module.MapboxModuleType
import com.mapbox.bindgen.Value
import com.mapbox.common.Logger
import com.mapbox.common.module.provider.MapboxModuleProvider
import com.mapbox.common.module.provider.ModuleProviderArgument
import com.mapbox.maps.RenderCache.Companion.RENDER_CACHE_SETTING
import com.mapbox.maps.assets.AssetManagerProvider
import com.mapbox.maps.loader.MapboxMapStaticInitializer
import com.mapbox.maps.module.MapTelemetry
Expand Down Expand Up @@ -145,15 +143,6 @@ internal class MapController : MapPluginProviderDelegate, MapControllable {
pluginRegistry.onSizeChanged(w, h)
}

@MapboxExperimental
override fun setRenderCache(cache: RenderCache) {
if (cache.cacheSizeMb >= 0) {
Settings.set(RENDER_CACHE_SETTING, Value(cache.cacheSizeMb))
} else {
Logger.e(TAG, "Render cache size must be >= 0!")
}
}

override fun queueEvent(event: Runnable, needRender: Boolean) {
if (needRender) {
renderer.queueRenderEvent(event)
Expand Down
16 changes: 0 additions & 16 deletions sdk/src/main/java/com/mapbox/maps/MapSurface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,6 @@ class MapSurface(
mapController.onSizeChanged(w, h)
}

/**
* Render cache is introduced to store intermediate rendering results of tiles into cache textures
* to be reused in future frames.
* It's considerably smaller effort from the GPU to render quads with single texture lookups
* rather than rendering geometries of individual layers and tiles separately.
*
* Using render cache may bring improvement to rendering performance
* and reduce communication between CPU and GPU.
*
* @param cache [RenderCache] to apply to given [MapView].
*/
@MapboxExperimental
override fun setRenderCache(cache: RenderCache) {
mapController.setRenderCache(cache)
}

/**
* Queue a runnable to be executed on the map renderer thread.
*
Expand Down
18 changes: 0 additions & 18 deletions sdk/src/main/java/com/mapbox/maps/MapView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ open class MapView : FrameLayout, MapPluginProviderDelegate, MapControllable {
},
resolvedMapInitOptions
)
// render cache disabled explicitly by default
mapController.setRenderCache(RenderCache.Disabled)
addView(view, 0)
mapController.initializePlugins(resolvedMapInitOptions, this)
}
Expand Down Expand Up @@ -166,22 +164,6 @@ open class MapView : FrameLayout, MapPluginProviderDelegate, MapControllable {
mapController.onSizeChanged(w, h)
}

/**
* Render cache is introduced to store intermediate rendering results of tiles into cache textures
* to be reused in future frames.
* It's considerably smaller effort from the GPU to render quads with single texture lookups
* rather than rendering geometries of individual layers and tiles separately.
*
* Using render cache may bring improvement to rendering performance
* and reduce communication between CPU and GPU.
*
* @param cache [RenderCache] to apply to given [MapView].
*/
@MapboxExperimental
override fun setRenderCache(cache: RenderCache) {
mapController.setRenderCache(cache)
}

/**
* You must call this method from the parent's Activity#onStart() or Fragment#onStart()
* @see android.app.Activity.onStart
Expand Down
45 changes: 0 additions & 45 deletions sdk/src/main/java/com/mapbox/maps/RenderCache.kt

This file was deleted.

33 changes: 33 additions & 0 deletions sdk/src/main/java/com/mapbox/maps/RenderCacheOptionsExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mapbox.maps

/**
* Set render cache size to 0MB in order to disable it.
*/
fun RenderCacheOptions.Builder.setDisabled(): RenderCacheOptions.Builder = also {
size(RENDER_CACHE_DISABLED)
}

/**
* Set render cache size to small(64MB).
*
* Works best with devices with not so powerful GPUs, or devices with pixel ratio of 1.0.
*/
fun RenderCacheOptions.Builder.setSmallSize(): RenderCacheOptions.Builder = also {
size(RENDER_CACHE_SIZE_SMALL_MB)
}

/**
* Set render cache size to large(128MB).
*
* Works best with devices powerful GPUs, or devices with pixel ratio > 1.0.
*/
fun RenderCacheOptions.Builder.setLargeSize(): RenderCacheOptions.Builder = also {
size(RENDER_CACHE_SIZE_LARGE_MB)
}

/**
* Static variables.
*/
internal const val RENDER_CACHE_DISABLED = 0
internal const val RENDER_CACHE_SIZE_SMALL_MB = 64
internal const val RENDER_CACHE_SIZE_LARGE_MB = 128

0 comments on commit 209d441

Please sign in to comment.