Add multiBackend Android flavor for runtime OpenGL/Vulkan switching (#4288)
This commit is contained in:
committed by
GitHub
parent
ccb9af119e
commit
b0388d186d
@@ -53,23 +53,7 @@ public final class MapLibre {
|
||||
@UiThread
|
||||
@NonNull
|
||||
public static synchronized MapLibre getInstance(@NonNull Context context) {
|
||||
ThreadUtils.init(context);
|
||||
ThreadUtils.checkThread(TAG);
|
||||
if (INSTANCE == null) {
|
||||
Context appContext = context.getApplicationContext();
|
||||
FileSource.initializeFileDirsPaths(appContext);
|
||||
INSTANCE = new MapLibre(appContext, null);
|
||||
ConnectivityReceiver.instance(appContext);
|
||||
}
|
||||
|
||||
TileServerOptions tileServerOptions = TileServerOptions.get(WellKnownTileServer.MapLibre);
|
||||
INSTANCE.tileServerOptions = tileServerOptions;
|
||||
INSTANCE.apiKey = null;
|
||||
FileSource fileSource = FileSource.getInstance(context);
|
||||
fileSource.setTileServerOptions(tileServerOptions);
|
||||
fileSource.setApiKey(null);
|
||||
|
||||
return INSTANCE;
|
||||
return getInstance(context, null, WellKnownTileServer.MapLibre);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,12 +73,42 @@ public final class MapLibre {
|
||||
@UiThread
|
||||
@NonNull
|
||||
public static synchronized MapLibre getInstance(@NonNull Context context, @Nullable String apiKey,
|
||||
WellKnownTileServer tileServer) {
|
||||
@NonNull WellKnownTileServer tileServer) {
|
||||
return getInstance(context, apiKey, tileServer, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of MapLibre, explicitly picking the rendering engine to use.
|
||||
* <p>
|
||||
* This class manages the API key, application context, and connectivity state.
|
||||
* </p>
|
||||
*
|
||||
* @param context Android context which holds or is an application context
|
||||
* @param apiKey api key
|
||||
* @param tileServer the tile server whose predefined configuration will be used to
|
||||
* bootstrap the SDK. The predefined configuration includes
|
||||
* rules for converting resource URLs between normal and canonical forms
|
||||
* and set of predefined styles available on the server.
|
||||
* @param type the rendering engine to use; ignored if MapLibre has already been
|
||||
* initialized in this process. If null, the default rendering engine will be used.
|
||||
* @return the single instance of MapLibre
|
||||
* @throws UnsupportedOperationException if {@code type} isn't supported by this
|
||||
* build of the SDK (single-backend flavors only support their compiled-in backend).
|
||||
*/
|
||||
@UiThread
|
||||
@NonNull
|
||||
public static synchronized MapLibre getInstance(@NonNull Context context, @Nullable String apiKey,
|
||||
@NonNull WellKnownTileServer tileServer,
|
||||
@Nullable RenderingEngine.Type type) {
|
||||
ThreadUtils.init(context);
|
||||
ThreadUtils.checkThread(TAG);
|
||||
if (INSTANCE == null) {
|
||||
Timber.plant();
|
||||
Context appContext = context.getApplicationContext();
|
||||
if (type == null) {
|
||||
type = RenderingEngine.getDefaultRenderingEngine(appContext);
|
||||
}
|
||||
RenderingEngine.setCurrentType(type);
|
||||
FileSource.initializeFileDirsPaths(appContext);
|
||||
INSTANCE = new MapLibre(appContext, apiKey);
|
||||
ConnectivityReceiver.instance(appContext);
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.maplibre.android.maps.renderer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Surface;
|
||||
import android.view.TextureView;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.maplibre.android.maps.renderer.surfaceview.SurfaceViewMapRenderer;
|
||||
import org.maplibre.android.maps.renderer.textureview.TextureViewMapRenderer;
|
||||
|
||||
/**
|
||||
* Shared factory used by MapRenderer.create(). The shape of renderer construction
|
||||
* (anonymous subclass wiring of initCallback, render-thread attachment) lives here;
|
||||
* the backend-specific concrete-type instantiation is delegated to the
|
||||
* flavor-provided {@link RendererStrategy}.
|
||||
*/
|
||||
@Keep
|
||||
public final class MapRendererFactory {
|
||||
|
||||
private MapRendererFactory() {}
|
||||
|
||||
public static TextureViewMapRenderer newTextureViewMapRenderer(@NonNull Context context,
|
||||
TextureView textureView,
|
||||
String localFontFamily,
|
||||
boolean translucentSurface,
|
||||
Runnable initCallback) {
|
||||
TextureViewMapRenderer mapRenderer = new TextureViewMapRenderer(context, textureView,
|
||||
localFontFamily, translucentSurface) {
|
||||
@Override
|
||||
protected void onSurfaceCreated(Surface surface) {
|
||||
initCallback.run();
|
||||
super.onSurfaceCreated(surface);
|
||||
}
|
||||
};
|
||||
RendererStrategy.attachTextureRenderThread(textureView, mapRenderer);
|
||||
return mapRenderer;
|
||||
}
|
||||
|
||||
public static SurfaceViewMapRenderer newSurfaceViewMapRenderer(@NonNull Context context,
|
||||
String localFontFamily,
|
||||
boolean renderSurfaceOnTop,
|
||||
Runnable initCallback) {
|
||||
return RendererStrategy.createSurfaceViewRenderer(
|
||||
context, localFontFamily, renderSurfaceOnTop, initCallback);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package org.maplibre.android.module.loader;
|
||||
|
||||
import org.maplibre.android.LibraryLoader;
|
||||
import org.maplibre.android.LibraryLoaderProvider;
|
||||
|
||||
/**
|
||||
* Concrete implementation of a native library loader.
|
||||
* <p>
|
||||
* </p>
|
||||
*/
|
||||
public class LibraryLoaderProviderImpl implements LibraryLoaderProvider {
|
||||
|
||||
/**
|
||||
* Creates and returns a the default Library Loader.
|
||||
*
|
||||
* @return the default library loader
|
||||
*/
|
||||
@Override
|
||||
public LibraryLoader getDefaultLibraryLoader() {
|
||||
return new SystemLibraryLoader();
|
||||
}
|
||||
|
||||
/**
|
||||
* Concrete implementation of a LibraryLoader using System.loadLibrary.
|
||||
*/
|
||||
private static class SystemLibraryLoader extends LibraryLoader {
|
||||
@Override
|
||||
public void load(String name) {
|
||||
System.loadLibrary(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user