Skip to content

Commit

Permalink
Fix: note11g#195 (Copy frame failed on TLHC Android)
Browse files Browse the repository at this point in the history
  • Loading branch information
note11g committed Apr 1, 2024
1 parent 05ef7d5 commit 57aff29
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package dev.note11.flutter_naver_map.flutter_naver_map.util

import android.graphics.SurfaceTexture
import android.util.Log
import android.view.TextureView
import android.view.ViewGroup

internal object TextureSurfaceViewUtil {
// check on this page: https://github.com/flutter/packages/commit/e393d452beaf4b216e2567bc2cee0225087f4662#diff-a5d65392fa8d540804d121990b51b05aa51e9a42dbbfc7e45ec4c4e181e3b872
fun installInvalidator(mapView: ViewGroup) {
val textureView = findTextureView(mapView)
if (textureView == null) {
Log.i("NaverMapView", "No TextureView found. Likely using the LEGACY renderer.")
return
}

Log.i("NaverMapView", "Installing custom TextureView driven invalidator.")
val internalListener = textureView.surfaceTextureListener
textureView.surfaceTextureListener = object : TextureView.SurfaceTextureListener {
override fun onSurfaceTextureAvailable(
surface: SurfaceTexture,
width: Int,
height: Int,
) {
internalListener?.onSurfaceTextureAvailable(surface, width, height)
}

override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean {
return internalListener?.onSurfaceTextureDestroyed(surface) ?: true
}

override fun onSurfaceTextureSizeChanged(
surface: SurfaceTexture, width: Int, height: Int,
) {
internalListener?.onSurfaceTextureSizeChanged(surface, width, height)
}

override fun onSurfaceTextureUpdated(surface: SurfaceTexture) {
internalListener?.onSurfaceTextureUpdated(surface)
mapView.invalidate()
}
}
}

private fun findTextureView(group: ViewGroup): TextureView? {
for (i in 0 until group.childCount) {
when (val view = group.getChildAt(i)) {
is TextureView -> return view
is ViewGroup -> {
val r = findTextureView(view)
if (r != null) return r
}
}
}
return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ import dev.note11.flutter_naver_map.flutter_naver_map.converter.DefaultTypeConve
import dev.note11.flutter_naver_map.flutter_naver_map.model.flutter_default_custom.NPoint
import dev.note11.flutter_naver_map.flutter_naver_map.model.map.NaverMapViewOptions
import dev.note11.flutter_naver_map.flutter_naver_map.util.NLocationSource
import dev.note11.flutter_naver_map.flutter_naver_map.util.TextureSurfaceViewUtil
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.platform.PlatformView


internal class NaverMapView(
private val activity: Activity,
private val flutterProvidedContext: Context,
private val naverMapViewOptions: NaverMapViewOptions,
private val channel: MethodChannel,
private val overlayController: OverlayHandler,
private val usingGLSurfaceView: Boolean?
private val usingGLSurfaceView: Boolean?,
) : PlatformView, Application.ActivityLifecycleCallbacks, ComponentCallbacks {

private lateinit var naverMap: NaverMap
Expand All @@ -53,6 +55,7 @@ internal class NaverMapView(
init {
setActivityThemeAppCompat()
registerLifecycleCallback()
TextureSurfaceViewUtil.installInvalidator(mapView)
}

private fun setTempMethodCallHandler() {
Expand Down

0 comments on commit 57aff29

Please sign in to comment.