Initialize native rendering lazy
This commit is contained in:
parent
e2e37bb7e4
commit
2175ad0c17
9 changed files with 51 additions and 27 deletions
|
@ -7,7 +7,6 @@
|
|||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>?children?</key>
|
||||
|
|
|
@ -276,11 +276,24 @@ void RenderingRuleSearchRequest::initObject(jobject rrs) {
|
|||
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_initRenderingRulesStorage(JNIEnv* ienv,
|
||||
jobject obj, jobject storage) {
|
||||
setGlobalEnv(ienv);
|
||||
if (defaultStorage == NULL || defaultStorage->javaStorage != storage) {
|
||||
// multi thread will not work?
|
||||
if (defaultStorage != NULL) {
|
||||
delete defaultStorage;
|
||||
}
|
||||
defaultStorage = new RenderingRulesStorage(storage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RenderingRuleSearchRequest::RenderingRuleSearchRequest(jobject rrs) :
|
||||
renderingRuleSearch(rrs) {
|
||||
jobject storage = globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_storage);
|
||||
if (defaultStorage == NULL || defaultStorage->javaStorage != storage) {
|
||||
// multi threadn will not work?
|
||||
// multi thread will not work?
|
||||
if (defaultStorage != NULL) {
|
||||
delete defaultStorage;
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -1,3 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
</resources>
|
|
@ -28,6 +28,7 @@ import net.osmand.plus.routing.RoutingHelper;
|
|||
import net.osmand.plus.voice.CommandPlayer;
|
||||
import net.osmand.plus.voice.CommandPlayerException;
|
||||
import net.osmand.plus.voice.CommandPlayerFactory;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
|
@ -304,7 +305,8 @@ public class OsmandApplication extends Application {
|
|||
try {
|
||||
if (osmandSettings.NATIVE_RENDERING.get()) {
|
||||
startDialog.startTask(getString(R.string.init_native_library), -1);
|
||||
boolean initialized = NativeOsmandLibrary.getLibrary() != null;
|
||||
RenderingRulesStorage storage = rendererRegistry.getCurrentSelectedRenderer();
|
||||
boolean initialized = NativeOsmandLibrary.getLibrary(storage) != null;
|
||||
if (!initialized) {
|
||||
LOG.info("Native library could not loaded!");
|
||||
}
|
||||
|
@ -336,7 +338,6 @@ public class OsmandApplication extends Application {
|
|||
if (toDismiss.getOwnerActivity() != null) {
|
||||
toDismiss.getOwnerActivity().dismissDialog(PROGRESS_DIALOG);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
showWarnings(warnings, toDismiss.getContext());
|
||||
|
|
|
@ -659,6 +659,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
|
||||
public void loadNativeLibrary(){
|
||||
if (!NativeOsmandLibrary.isLoaded()) {
|
||||
final RenderingRulesStorage storage = getMyApplication().getRendererRegistry().getCurrentSelectedRenderer();
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
|
@ -668,14 +669,14 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
NativeOsmandLibrary.getLibrary();
|
||||
NativeOsmandLibrary.getLibrary(storage);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
progressDlg.dismiss();
|
||||
if (NativeOsmandLibrary.isNativeSupported()) {
|
||||
if (!NativeOsmandLibrary.isNativeSupported(storage)) {
|
||||
Toast.makeText(SettingsActivity.this, R.string.native_library_not_supported, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -232,8 +232,8 @@ public class MapRenderRepositories {
|
|||
}
|
||||
|
||||
|
||||
private boolean loadVectorDataNative(RectF dataBox, final int zoom, final RenderingRuleSearchRequest renderingReq) {
|
||||
NativeOsmandLibrary library = NativeOsmandLibrary.getLibrary();
|
||||
private boolean loadVectorDataNative(RectF dataBox, final int zoom, final RenderingRuleSearchRequest renderingReq,
|
||||
NativeOsmandLibrary library) {
|
||||
int leftX = MapUtils.get31TileNumberX(dataBox.left);
|
||||
int rightX = MapUtils.get31TileNumberX(dataBox.right);
|
||||
int bottomY = MapUtils.get31TileNumberY(dataBox.bottom);
|
||||
|
@ -428,6 +428,7 @@ public class MapRenderRepositories {
|
|||
OsmandApplication app = ((OsmandApplication) context.getApplicationContext());
|
||||
Boolean renderDay = app.getDaynightHelper().getDayNightRenderer();
|
||||
boolean nightMode = renderDay != null && !renderDay.booleanValue();
|
||||
|
||||
// boolean moreDetail = prefs.SHOW_MORE_MAP_DETAIL.get();
|
||||
RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||
RenderingRuleSearchRequest renderingReq = new RenderingRuleSearchRequest(storage);
|
||||
|
@ -450,6 +451,7 @@ public class MapRenderRepositories {
|
|||
}
|
||||
}
|
||||
renderingReq.saveState();
|
||||
NativeOsmandLibrary nativeLib = prefs.NATIVE_RENDERING.get() ? NativeOsmandLibrary.getLibrary(storage) : null;
|
||||
|
||||
// prevent editing
|
||||
requestedBox = new RotatedTileBox(tileRect);
|
||||
|
@ -459,7 +461,7 @@ public class MapRenderRepositories {
|
|||
long now = System.currentTimeMillis();
|
||||
|
||||
if (cObjectsBox.left > dataBox.left || cObjectsBox.top > dataBox.top || cObjectsBox.right < dataBox.right
|
||||
|| cObjectsBox.bottom < dataBox.bottom || prefs.NATIVE_RENDERING.get() == (cNativeObjects == null)) {
|
||||
|| cObjectsBox.bottom < dataBox.bottom || (nativeLib != null) == (cNativeObjects == null)) {
|
||||
// increase data box in order for rotate
|
||||
if ((dataBox.right - dataBox.left) > (dataBox.top - dataBox.bottom)) {
|
||||
double wi = (dataBox.right - dataBox.left) * .2;
|
||||
|
@ -472,9 +474,9 @@ public class MapRenderRepositories {
|
|||
}
|
||||
validateLatLonBox(dataBox);
|
||||
boolean loaded;
|
||||
if(prefs.NATIVE_RENDERING.get()) {
|
||||
if(nativeLib != null) {
|
||||
cObjects = new LinkedList<BinaryMapDataObject>();
|
||||
loaded = loadVectorDataNative(dataBox, requestedBox.getZoom(), renderingReq);
|
||||
loaded = loadVectorDataNative(dataBox, requestedBox.getZoom(), renderingReq, nativeLib);
|
||||
} else {
|
||||
cNativeObjects = null;
|
||||
loaded = loadVectorData(dataBox, requestedBox.getZoom(), renderingReq, nightMode);
|
||||
|
@ -530,8 +532,8 @@ public class MapRenderRepositories {
|
|||
this.bmpLocation = tileRect;
|
||||
|
||||
|
||||
if(app.getSettings().NATIVE_RENDERING.get() && NativeOsmandLibrary.isNativeSupported()) {
|
||||
renderer.generateNewBitmapNative(currentRenderingContext, cNativeObjects, bmp, prefs.USE_ENGLISH_NAMES.get(), renderingReq,
|
||||
if(nativeLib != null) {
|
||||
renderer.generateNewBitmapNative(currentRenderingContext, nativeLib, cNativeObjects, bmp, prefs.USE_ENGLISH_NAMES.get(), renderingReq,
|
||||
notifyList, fillColor);
|
||||
} else {
|
||||
renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp, prefs.USE_ENGLISH_NAMES.get(), renderingReq,
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.render;
|
|||
|
||||
import net.osmand.plus.render.OsmandRenderer.RenderingContext;
|
||||
import net.osmand.render.RenderingRuleSearchRequest;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
public class NativeOsmandLibrary {
|
||||
|
@ -10,14 +11,19 @@ public class NativeOsmandLibrary {
|
|||
private static NativeOsmandLibrary library;
|
||||
private static boolean isNativeSupported = true;
|
||||
|
||||
public static NativeOsmandLibrary getLibrary() {
|
||||
if(library == null && isNativeSupported) {
|
||||
public static NativeOsmandLibrary getLibrary(RenderingRulesStorage storage) {
|
||||
if (!isLoaded()) {
|
||||
synchronized (NativeOsmandLibrary.class) {
|
||||
if (!isLoaded()) {
|
||||
try {
|
||||
System.loadLibrary("osmand");
|
||||
library = new NativeOsmandLibrary();
|
||||
} catch (Throwable e) {
|
||||
isNativeSupported = false;
|
||||
}
|
||||
NativeOsmandLibrary.initRenderingRulesStorage(storage);
|
||||
}
|
||||
}
|
||||
}
|
||||
return library;
|
||||
}
|
||||
|
@ -26,8 +32,10 @@ public class NativeOsmandLibrary {
|
|||
return !isNativeSupported || library != null;
|
||||
}
|
||||
|
||||
public static boolean isNativeSupported() {
|
||||
getLibrary();
|
||||
public static boolean isNativeSupported(RenderingRulesStorage storage) {
|
||||
if(storage != null) {
|
||||
getLibrary(storage);
|
||||
}
|
||||
return isNativeSupported;
|
||||
}
|
||||
|
||||
|
@ -91,6 +99,8 @@ public class NativeOsmandLibrary {
|
|||
|
||||
private static native boolean initBinaryMapFile(String filePath);
|
||||
|
||||
private static native boolean initRenderingRulesStorage(RenderingRulesStorage storage);
|
||||
|
||||
private static native String generateRendering(RenderingContext rc, int searchResultHandler, Bitmap bmp, boolean useEnglishNames,
|
||||
RenderingRuleSearchRequest render, int defaultColor);
|
||||
|
||||
|
|
|
@ -197,7 +197,8 @@ public class OsmandRenderer {
|
|||
/**
|
||||
* @return if map could be replaced
|
||||
*/
|
||||
public void generateNewBitmapNative(RenderingContext rc, NativeSearchResult searchResultHandler, Bitmap bmp, boolean useEnglishNames,
|
||||
public void generateNewBitmapNative(RenderingContext rc, NativeOsmandLibrary library,
|
||||
NativeSearchResult searchResultHandler, Bitmap bmp, boolean useEnglishNames,
|
||||
RenderingRuleSearchRequest render, final List<IMapDownloaderCallback> notifyList, int defaultColor) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (rc.width > 0 && rc.height > 0 && searchResultHandler != null) {
|
||||
|
@ -211,7 +212,7 @@ public class OsmandRenderer {
|
|||
final Handler h = new Handler(Looper.getMainLooper());
|
||||
notifyListenersWithDelay(rc, notifyList, h);
|
||||
}
|
||||
String res = NativeOsmandLibrary.getLibrary().generateRendering(rc, searchResultHandler, bmp, useEnglishNames, render, defaultColor);
|
||||
String res = library.generateRendering(rc, searchResultHandler, bmp, useEnglishNames, render, defaultColor);
|
||||
rc.ended = true;
|
||||
notifyListeners(notifyList);
|
||||
long time = System.currentTimeMillis() - now;
|
||||
|
|
Loading…
Reference in a new issue