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