CartoDB / mobile-sdk

CARTO Mobile SDK core project
https://carto.com/docs/carto-engine/mobile-sdk/
BSD 3-Clause "New" or "Revised" License
179 stars 65 forks source link

Render on Surface's canvas for Android Auto support #532

Open ankiimation opened 1 year ago

ankiimation commented 1 year ago

I'm using the Carto to display maps on my Android application. However, I'm having trouble figuring out how to render the map on the android-auto Navigation Template that already provides a Surface to render on.

Thanks in advance!

mtehver commented 1 year ago

I know very little about Android Car APIs, so my answer may be a bit off. But looking at the question at high level, I do not think it is possible without complex workarounds. The issue here is that Carto Mobile SDK needs to configure its rendering surface itself, as there are specific format requirement to depth buffer and stencil buffer in order to provide correct rendering. But NavigationTemplate gives a preconfigured Surface instance that may not be configured with these requirements in mind.

A possible workaround would be to render the map using normal MapView instance (or perhaps TextureMapView instance) and then copy the rendered image to the surface provided by NavigationTemplate callback.

ankiimation commented 1 year ago

I have tried with TextureView but it cant render without attached to a View

mtehver commented 1 year ago

Ok, if you need to render map without having a view, you would probably need to make a custom MapView class. On the positive side, the class can be implemented in Java/Kotlin, no changes in native C++ code are necessary (if you look at https://github.com/CartoDB/mobile-sdk/blob/master/android/java/com/carto/ui/MapView.java, you can see that most of code simply acts as a stub to BaseMapView, which is implemented in C++). On the negative side, you need to work classes/APIs like EGLDisplay, EGLContext that are rather low level.

mtehver commented 1 year ago

Perhaps there is also a way to create transparent/invisible MapView, but I am not sure whether this works.

phileo commented 9 months ago

Ok, if you need to render map without having a view, you would probably need to make a custom MapView class. On the positive side, the class can be implemented in Java/Kotlin, no changes in native C++ code are necessary (if you look at https://github.com/CartoDB/mobile-sdk/blob/master/android/java/com/carto/ui/MapView.java, you can see that most of code simply acts as a stub to BaseMapView, which is implemented in C++). On the negative side, you need to work classes/APIs like EGLDisplay, EGLContext that are rather low level.

@mtehver how would I hook up my custom Carto MapView class to the SurfaceRenderer.java in the Android auto navigation sample app?

Just a general approach or procedure would be great, thanks.