Working commit
This commit is contained in:
parent
5abab74cda
commit
82e4307ed5
11 changed files with 192 additions and 103 deletions
|
@ -66,9 +66,8 @@ public class NativeLibrary {
|
|||
protected static native void initRenderingRulesStorage(RenderingRulesStorage storage);
|
||||
|
||||
|
||||
protected static native RenderingGenerationResult generateRendering_Indirect(RenderingContext rc, int searchResultHandler,
|
||||
int requestedBitmapWidth, int requestedBitmapHeight, int rowBytes, boolean isTransparent, boolean useEnglishNames,
|
||||
RenderingRuleSearchRequest render, int defaultColor);
|
||||
protected static native RenderingGenerationResult generateRenderingIndirect(RenderingContext rc, int searchResultHandler,
|
||||
boolean isTransparent, RenderingRuleSearchRequest render, boolean encodePng);
|
||||
|
||||
protected static native int searchNativeObjectsForRendering(int sleft, int sright, int stop, int sbottom, int zoom,
|
||||
RenderingRuleSearchRequest request, boolean skipDuplicates, Object objectWithInterruptedField, String msgIfNothingFound);
|
||||
|
|
|
@ -17,6 +17,8 @@ public class RenderingContext {
|
|||
// FIELDS OF THAT CLASS ARE USED IN C++
|
||||
public boolean interrupted = false;
|
||||
public boolean nightMode = false;
|
||||
public boolean useEnglishNames = false;
|
||||
public int defaultColor = 0xf1eee8;
|
||||
|
||||
public RenderingContext() {
|
||||
}
|
||||
|
|
|
@ -199,6 +199,11 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
|||
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
showMainWindow(512, 512, null);
|
||||
}
|
||||
|
||||
|
||||
public static void showMainWindow(int wx, int hy, NativeSwingRendering rendering) {
|
||||
JFrame frame = new JFrame(Messages.getString("MapPanel.MAP.VIEW")); //$NON-NLS-1$
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
|
@ -207,6 +212,7 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
|||
}
|
||||
|
||||
final MapPanel panel = new MapPanel(DataExtractionSettings.getSettings().getTilesDirectory());
|
||||
panel.nativeRenderingImg = img;
|
||||
frame.addWindowListener(new WindowAdapter(){
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
|
@ -222,9 +228,8 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
|||
JMenuBar bar = new JMenuBar();
|
||||
bar.add(getMenuToChooseSource(panel));
|
||||
frame.setJMenuBar(bar);
|
||||
frame.setSize(512, 512);
|
||||
frame.setSize(wx, hy);
|
||||
frame.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
private File tilesLocation = null;
|
||||
|
@ -232,6 +237,9 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
|||
// name of source map
|
||||
private ITileSource map = TileSourceManager.getMapnikSource();
|
||||
|
||||
private NativeSwingRendering nativeLibRendering;
|
||||
private Image nativeRenderingImg;
|
||||
|
||||
// zoom level
|
||||
private int zoom = 1;
|
||||
|
||||
|
@ -343,7 +351,9 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
|||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
if (images != null) {
|
||||
if(nativeLibRendering != null) {
|
||||
g.drawImage(nativeRenderingImg, 0, 0, this);
|
||||
} else if (images != null) {
|
||||
for (int i = 0; i < images.length; i++) {
|
||||
for (int j = 0; j < images[i].length; j++) {
|
||||
if (images[i][j] == null) {
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
package net.osmand.swing;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.MemoryCacheImageInputStream;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
@ -17,7 +27,9 @@ public class NativeSwingRendering extends NativeLibrary {
|
|||
System.load("/home/victor/projects/OsmAnd/git/Osmand-kernel/jni-prebuilt/linux-x86/osmand.lib");
|
||||
}
|
||||
|
||||
private static RenderingRulesStorage getDefault() throws SAXException, IOException{
|
||||
RenderingRulesStorage storage;
|
||||
|
||||
private RenderingRulesStorage getDefault() throws SAXException, IOException{
|
||||
RenderingRulesStorage storage = new RenderingRulesStorage();
|
||||
final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() {
|
||||
@Override
|
||||
|
@ -36,29 +48,75 @@ public class NativeSwingRendering extends NativeLibrary {
|
|||
return storage;
|
||||
}
|
||||
|
||||
public NativeSwingRendering(){
|
||||
try {
|
||||
storage = getDefault();
|
||||
} catch (SAXException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public BufferedImage renderImage(int sleft, int sright, int stop, int sbottom, int zoom) throws IOException {
|
||||
RenderingContext rctx = new RenderingContext();
|
||||
RenderingRuleSearchRequest request = new RenderingRuleSearchRequest(storage);
|
||||
NativeSearchResult res = searchObjectsForRendering(sleft, sright, stop, sbottom, zoom, request, true,
|
||||
rctx, "Nothing found");
|
||||
|
||||
rctx.leftX = (float) (((double)sleft)/ MapUtils.getPowZoom(31-zoom));
|
||||
rctx.topY = (float) (((double)stop)/ MapUtils.getPowZoom(31-zoom));
|
||||
rctx.width = (int) ((sright - sleft) / MapUtils.getPowZoom(31 - zoom - 8));
|
||||
rctx.height = (int) ((sbottom - stop) / MapUtils.getPowZoom(31 - zoom - 8));
|
||||
rctx.shadowRenderingMode = 2;
|
||||
rctx.zoom = zoom;
|
||||
|
||||
final RenderingGenerationResult rres = NativeSwingRendering.generateRenderingIndirect(rctx, res.nativeHandler,
|
||||
false, request, true);
|
||||
System.out.println(rres.bitmapBuffer.capacity());
|
||||
InputStream inputStream = new InputStream() {
|
||||
int nextInd = 0;
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
if(nextInd >= rres.bitmapBuffer.capacity()) {
|
||||
return -1;
|
||||
}
|
||||
byte b = rres.bitmapBuffer.get(nextInd++) ;
|
||||
if(b < 0) {
|
||||
return b + 256;
|
||||
} else {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
};
|
||||
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("png");
|
||||
ImageReader reader = readers.next();
|
||||
reader.setInput(new MemoryCacheImageInputStream(inputStream), true);
|
||||
BufferedImage img = reader.read(0);
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws SAXException, IOException {
|
||||
// ByteBuffer buff = java.nio.ByteBuffer.wrap(new byte[10]);
|
||||
// new ByteBufferI
|
||||
// ImageIO.read(new ByteInputStream());
|
||||
System.out.println("Native!");
|
||||
NativeSwingRendering lib = new NativeSwingRendering();
|
||||
lib.initMapFile("/home/victor/projects/OsmAnd/data/osm-gen/Cuba2.obf");
|
||||
lib.initMapFile("/home/victor/projects/OsmAnd/data/osm-gen/basemap_2.obf");
|
||||
RenderingContext ctx = new RenderingContext();
|
||||
RenderingRulesStorage df = getDefault();
|
||||
lib.initRenderingRulesStorage(df);
|
||||
|
||||
RenderingRuleSearchRequest request = new RenderingRuleSearchRequest(df);
|
||||
double latTop = 23.5;
|
||||
double latTop = 22.5;
|
||||
double lonLeft = -80;
|
||||
double latBottom = 23;
|
||||
double lonRight = -79;
|
||||
float tileX = 2;
|
||||
float tileY = 2;
|
||||
int zoom = 11;
|
||||
|
||||
double latBottom = MapUtils.getLatitudeFromTile(zoom, MapUtils.getTileNumberY(zoom, latTop) + tileY);
|
||||
double lonRight = MapUtils.getLongitudeFromTile(zoom, MapUtils.getTileNumberX(zoom, lonLeft) + tileX);
|
||||
int sleft = MapUtils.get31TileNumberX(lonLeft);
|
||||
int sright = MapUtils.get31TileNumberX(lonRight);
|
||||
int stop = MapUtils.get31TileNumberY(latTop);
|
||||
int sbottom = MapUtils.get31TileNumberY(latBottom);
|
||||
|
||||
NativeSearchResult res = lib.searchObjectsForRendering(sleft, sright, stop, sbottom, 11, request, true,
|
||||
ctx, "Nothing found");
|
||||
MapPanel.showMainWindow(512, 512, lib.renderImage(sleft, sright, stop, sbottom, zoom));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -539,11 +539,10 @@ public class MapRenderRepositories {
|
|||
final long searchTime = System.currentTimeMillis() - now;
|
||||
|
||||
currentRenderingContext = new OsmandRenderer.RenderingContext(context);
|
||||
int fillColor = 0xf1eee8;
|
||||
renderingReq.clearState();
|
||||
renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getZoom());
|
||||
if(renderingReq.searchRenderingAttribute(RenderingRuleStorageProperties.A_DEFAULT_COLOR)) {
|
||||
fillColor = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_COLOR_VALUE);
|
||||
currentRenderingContext.defaultColor = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_COLOR_VALUE);
|
||||
}
|
||||
renderingReq.clearState();
|
||||
renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getZoom());
|
||||
|
@ -558,6 +557,7 @@ public class MapRenderRepositories {
|
|||
currentRenderingContext.width = (int) (requestedBox.getTileWidth() * OsmandRenderer.TILE_SIZE);
|
||||
currentRenderingContext.height = (int) (requestedBox.getTileHeight() * OsmandRenderer.TILE_SIZE);
|
||||
currentRenderingContext.nightMode = nightMode;
|
||||
currentRenderingContext.useEnglishNames = prefs.USE_ENGLISH_NAMES.get();
|
||||
currentRenderingContext.setDensityValue(prefs.USE_HIGH_RES_MAPS.get(),
|
||||
prefs.MAP_TEXT_SIZE.get(), renderer.getDensity());
|
||||
if (checkWhetherInterrupted()) {
|
||||
|
@ -585,11 +585,9 @@ public class MapRenderRepositories {
|
|||
|
||||
|
||||
if(nativeLib != null) {
|
||||
renderer.generateNewBitmapNative(currentRenderingContext, nativeLib, cNativeObjects, bmp, prefs.USE_ENGLISH_NAMES.get(), renderingReq,
|
||||
notifyList, fillColor);
|
||||
renderer.generateNewBitmapNative(currentRenderingContext, nativeLib, cNativeObjects, bmp, renderingReq, notifyList);
|
||||
} else {
|
||||
renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp, prefs.USE_ENGLISH_NAMES.get(), renderingReq,
|
||||
notifyList, fillColor);
|
||||
renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp, renderingReq, notifyList);
|
||||
}
|
||||
// Force to use rendering request in order to prevent Garbage Collector when it is used in C++
|
||||
if(renderingReq != null){
|
||||
|
|
|
@ -80,8 +80,7 @@ public class NativeOsmandLibrary extends NativeLibrary {
|
|||
}
|
||||
|
||||
public RenderingGenerationResult generateRendering(RenderingContext rc, NativeSearchResult searchResultHandler,
|
||||
Bitmap bitmap, int requestedBitmapWidth, int requestedBitmapHeight, int rowBytes, boolean isTransparent,
|
||||
boolean useEnglishNames, RenderingRuleSearchRequest render, int defaultColor) {
|
||||
Bitmap bitmap, boolean isTransparent, RenderingRuleSearchRequest render) {
|
||||
if (searchResultHandler == null) {
|
||||
log.error("Error searchresult = null"); //$NON-NLS-1$
|
||||
return new RenderingGenerationResult(null);
|
||||
|
@ -89,16 +88,15 @@ public class NativeOsmandLibrary extends NativeLibrary {
|
|||
|
||||
// Android 2.2+
|
||||
if(android.os.Build.VERSION.SDK_INT >= 8) {
|
||||
return generateRendering_Direct(rc, searchResultHandler.nativeHandler, bitmap, useEnglishNames, render, defaultColor);
|
||||
return generateRenderingDirect(rc, searchResultHandler.nativeHandler, bitmap, render);
|
||||
} else {
|
||||
return generateRendering_Indirect(rc, searchResultHandler.nativeHandler, requestedBitmapWidth, requestedBitmapHeight, rowBytes, isTransparent, useEnglishNames, render, defaultColor);
|
||||
return generateRenderingIndirect(rc, searchResultHandler.nativeHandler, isTransparent, render, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static native RenderingGenerationResult generateRendering_Direct(RenderingContext rc, int searchResultHandler,
|
||||
Bitmap bitmap, boolean useEnglishNames,
|
||||
RenderingRuleSearchRequest render, int defaultColor);
|
||||
private static native RenderingGenerationResult generateRenderingDirect(RenderingContext rc, int searchResultHandler,
|
||||
Bitmap bitmap, RenderingRuleSearchRequest render);
|
||||
|
||||
public static native int getCpuCount();
|
||||
public static native boolean cpuHasNeonSupport();
|
||||
|
|
|
@ -157,8 +157,7 @@ public class OsmandRenderer {
|
|||
*/
|
||||
public void generateNewBitmapNative(RenderingContext rc, NativeOsmandLibrary library,
|
||||
NativeSearchResult searchResultHandler,
|
||||
Bitmap bmp, boolean useEnglishNames,
|
||||
RenderingRuleSearchRequest render, final List<IMapDownloaderCallback> notifyList, int defaultColor) {
|
||||
Bitmap bmp, RenderingRuleSearchRequest render, final List<IMapDownloaderCallback> notifyList) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (rc.width > 0 && rc.height > 0 && searchResultHandler != null) {
|
||||
// init rendering context
|
||||
|
@ -175,9 +174,7 @@ public class OsmandRenderer {
|
|||
// If res.bitmapBuffer is null, it indicates that rendering was done directly to
|
||||
// memory of passed bitmap, but this is supported only on Android >= 2.2
|
||||
final NativeLibrary.RenderingGenerationResult res = library.generateRendering(
|
||||
rc, searchResultHandler,
|
||||
bmp, bmp.getWidth(), bmp.getHeight(), bmp.getRowBytes(), bmp.hasAlpha(),
|
||||
useEnglishNames, render, defaultColor);
|
||||
rc, searchResultHandler, bmp, bmp.hasAlpha(), render);
|
||||
rc.ended = true;
|
||||
notifyListeners(notifyList);
|
||||
long time = System.currentTimeMillis() - now;
|
||||
|
@ -195,8 +192,8 @@ public class OsmandRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
public void generateNewBitmap(RenderingContext rc, List<BinaryMapDataObject> objects, Bitmap bmp, boolean useEnglishNames,
|
||||
RenderingRuleSearchRequest render, final List<IMapDownloaderCallback> notifyList, int defaultColor) {
|
||||
public void generateNewBitmap(RenderingContext rc, List<BinaryMapDataObject> objects, Bitmap bmp,
|
||||
RenderingRuleSearchRequest render, final List<IMapDownloaderCallback> notifyList) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
if (objects != null && !objects.isEmpty() && rc.width > 0 && rc.height > 0) {
|
||||
|
@ -206,8 +203,8 @@ public class OsmandRenderer {
|
|||
rc.sinRotateTileSize = FloatMath.sin((float) Math.toRadians(rc.rotate)) * TILE_SIZE;
|
||||
// fill area
|
||||
Canvas cv = new Canvas(bmp);
|
||||
if (defaultColor != 0) {
|
||||
cv.drawColor(defaultColor);
|
||||
if (rc.defaultColor != 0) {
|
||||
cv.drawColor(rc.defaultColor);
|
||||
}
|
||||
// put in order map
|
||||
TIntObjectHashMap<TIntArrayList> orderMap = sortObjectsByProperOrder(rc, objects, render);
|
||||
|
@ -267,7 +264,7 @@ public class OsmandRenderer {
|
|||
drawIconsOverCanvas(rc, cv);
|
||||
|
||||
notifyListeners(notifyList);
|
||||
textRenderer.drawTextOverCanvas(rc, cv, useEnglishNames);
|
||||
textRenderer.drawTextOverCanvas(rc, cv, rc.useEnglishNames);
|
||||
|
||||
long time = System.currentTimeMillis() - now;
|
||||
rc.renderingDebugInfo = String.format("Rendering: %s ms (%s text)\n"
|
||||
|
|
|
@ -346,6 +346,7 @@ bool acceptTypes(SearchQuery* req, std::vector<tag_value>& types, MapIndex* root
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -163,6 +163,7 @@ private :
|
|||
float topY;
|
||||
int width;
|
||||
int height;
|
||||
int defaultColor;
|
||||
|
||||
int zoom;
|
||||
float rotate;
|
||||
|
@ -206,6 +207,7 @@ public:
|
|||
pointInsideCount(0), visible(0), allObjects(0){
|
||||
setRotate(0);
|
||||
setZoom(15);
|
||||
setDefaultColor(0xf1eee8);
|
||||
}
|
||||
virtual ~RenderingContext();
|
||||
|
||||
|
@ -221,6 +223,11 @@ public:
|
|||
this->zoom = z;
|
||||
this->tileDivisor = (1 << (31 - z));
|
||||
}
|
||||
|
||||
void setDefaultColor(int z) {
|
||||
this->defaultColor = z;
|
||||
}
|
||||
|
||||
void setRotate(float rot) {
|
||||
this->rotate = rot;
|
||||
this->cosRotateTileSize = cos(toRadians(rot)) * TILE_SIZE;
|
||||
|
@ -245,6 +252,10 @@ public:
|
|||
return width;
|
||||
}
|
||||
|
||||
inline int getDefaultColor(){
|
||||
return defaultColor;
|
||||
}
|
||||
|
||||
inline int getHeight(){
|
||||
return height;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <SkBitmap.h>
|
||||
#include <SkCanvas.h>
|
||||
#include <SkImageDecoder.h>
|
||||
#include <SkImageEncoder.h>
|
||||
#include <SkStream.h>
|
||||
#include "java_renderRules.h"
|
||||
#include "common.h"
|
||||
#include "java_wrap.h"
|
||||
|
@ -62,7 +64,6 @@ extern "C" JNIEXPORT jboolean JNICALL Java_net_osmand_NativeLibrary_initBinaryMa
|
|||
|
||||
|
||||
|
||||
|
||||
// Global object
|
||||
HMAP::hash_map<void*, RenderingRulesStorage*> cachedStorages;
|
||||
|
||||
|
@ -117,9 +118,8 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_NativeLibrary_searchNativeObje
|
|||
#ifdef ANDROID_BUILD
|
||||
#include <android/bitmap.h>
|
||||
|
||||
extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_generateRendering_1Direct( JNIEnv* ienv, jobject obj,
|
||||
jobject renderingContext, jint searchResult,
|
||||
jobject targetBitmap, jboolean useEnglishNames, jobject renderingRuleSearchRequest, jint defaultColor) {
|
||||
extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_generateRenderingDirect( JNIEnv* ienv, jobject obj,
|
||||
jobject renderingContext, jint searchResult, jobject targetBitmap, jobject renderingRuleSearchRequest) {
|
||||
|
||||
// libJniGraphics interface
|
||||
typedef int (*PTR_AndroidBitmap_getInfo)(JNIEnv*, jobject, AndroidBitmapInfo*);
|
||||
|
@ -215,7 +215,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
|
|||
delete bitmap;
|
||||
// deleteObjects(mapDataObjects);
|
||||
|
||||
jclass resultClass = findClass(ienv, "net/osmand/NativeLibrary$8RenderingGenerationResult");
|
||||
jclass resultClass = findClass(ienv, "net/osmand/NativeLibrary$RenderingGenerationResult");
|
||||
|
||||
jmethodID resultClassCtorId = ienv->GetMethodID(resultClass, "<init>", "(Ljava/nio/ByteBuffer;)V");
|
||||
|
||||
|
@ -237,78 +237,85 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
|
|||
|
||||
void* bitmapData = NULL;
|
||||
size_t bitmapDataSize = 0;
|
||||
extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_generateRendering_1Indirect( JNIEnv* ienv, jobject obj,
|
||||
jobject renderingContext, jint searchResult,
|
||||
jint requestedBitmapWidth, jint requestedBitmapHeight, jint rowBytes, jboolean isTransparent,
|
||||
jboolean useEnglishNames, jobject renderingRuleSearchRequest, jint defaultColor) {
|
||||
extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_NativeLibrary_generateRenderingIndirect( JNIEnv* ienv,
|
||||
jobject obj, jobject renderingContext, jint searchResult, jboolean isTransparent,
|
||||
jobject renderingRuleSearchRequest, jboolean encodePNG) {
|
||||
|
||||
osmand_log_print(LOG_INFO, "Creating SkBitmap in native w:%d h:%d!", requestedBitmapWidth, requestedBitmapHeight);
|
||||
JNIRenderingContext rc;
|
||||
pullFromJavaRenderingContext(ienv, renderingContext, &rc);
|
||||
|
||||
SkBitmap* bitmap = new SkBitmap();
|
||||
if(isTransparent == JNI_TRUE)
|
||||
bitmap->setConfig(SkBitmap::kARGB_8888_Config, requestedBitmapWidth, requestedBitmapHeight, rowBytes);
|
||||
else
|
||||
bitmap->setConfig(SkBitmap::kRGB_565_Config, requestedBitmapWidth, requestedBitmapHeight, rowBytes);
|
||||
osmand_log_print(LOG_INFO, "Creating SkBitmap in native w:%d h:%d!", rc.getWidth(), rc.getHeight());
|
||||
|
||||
if(bitmapData != NULL && bitmapDataSize != bitmap->getSize()) {
|
||||
free(bitmapData);
|
||||
bitmapData = NULL;
|
||||
bitmapDataSize = 0;
|
||||
}
|
||||
if(bitmapData == NULL && bitmapDataSize == 0) {
|
||||
bitmapDataSize = bitmap->getSize();
|
||||
bitmapData = malloc(bitmapDataSize);
|
||||
SkBitmap* bitmap = new SkBitmap();
|
||||
if (isTransparent == JNI_TRUE)
|
||||
bitmap->setConfig(SkBitmap::kARGB_8888_Config, rc.getWidth(), rc.getHeight(), 0);
|
||||
else
|
||||
bitmap->setConfig(SkBitmap::kRGB_565_Config, rc.getWidth(), rc.getHeight(), 0);
|
||||
|
||||
osmand_log_print(LOG_INFO, "Allocated %d bytes at %p", bitmapDataSize, bitmapData);
|
||||
}
|
||||
if (bitmapData != NULL && bitmapDataSize != bitmap->getSize()) {
|
||||
free(bitmapData);
|
||||
bitmapData = NULL;
|
||||
bitmapDataSize = 0;
|
||||
}
|
||||
if (bitmapData == NULL && bitmapDataSize == 0) {
|
||||
bitmapDataSize = bitmap->getSize();
|
||||
bitmapData = malloc(bitmapDataSize);
|
||||
osmand_log_print(LOG_INFO, "Allocated %d bytes at %p", bitmapDataSize, bitmapData);
|
||||
}
|
||||
|
||||
bitmap->setPixels(bitmapData);
|
||||
bitmap->setPixels(bitmapData);
|
||||
ElapsedTimer initObjects;
|
||||
initObjects.start();
|
||||
|
||||
RenderingRuleSearchRequest* req = initSearchRequest(ienv, renderingRuleSearchRequest);
|
||||
|
||||
osmand_log_print(LOG_INFO, "Initializing rendering");
|
||||
ElapsedTimer initObjects;
|
||||
initObjects.start();
|
||||
ResultPublisher* result = ((ResultPublisher*) searchResult);
|
||||
// std::vector <BaseMapDataObject* > mapDataObjects = marshalObjects(binaryMapDataObjects);
|
||||
|
||||
RenderingRuleSearchRequest* req = initSearchRequest(ienv, renderingRuleSearchRequest);
|
||||
JNIRenderingContext rc;
|
||||
pullFromJavaRenderingContext(ienv, renderingContext, &rc);
|
||||
rc.setUseEnglishNames(useEnglishNames);
|
||||
ResultPublisher* result = ((ResultPublisher*) searchResult);
|
||||
// std::vector <BaseMapDataObject* > mapDataObjects = marshalObjects(binaryMapDataObjects);
|
||||
initObjects.pause();
|
||||
// Main part do rendering
|
||||
|
||||
osmand_log_print(LOG_INFO, "Rendering image");
|
||||
initObjects.pause();
|
||||
// Main part do rendering
|
||||
SkCanvas* canvas = new SkCanvas(*bitmap);
|
||||
canvas->drawColor(rc.getDefaultColor());
|
||||
if (result != NULL) {
|
||||
doRendering(result->result, canvas, req, &rc);
|
||||
}
|
||||
delete canvas;
|
||||
delete req;
|
||||
pushToJavaRenderingContext(ienv, renderingContext, &rc);
|
||||
|
||||
SkCanvas* canvas = new SkCanvas(*bitmap);
|
||||
canvas->drawColor(defaultColor);
|
||||
if(result != NULL) {
|
||||
doRendering(result->result, canvas, req, &rc);
|
||||
}
|
||||
pushToJavaRenderingContext(ienv, renderingContext, &rc);
|
||||
osmand_log_print(LOG_INFO, "End Rendering image");
|
||||
jclass resultClass = findClass(ienv, "net/osmand/NativeLibrary$RenderingGenerationResult");
|
||||
|
||||
// delete variables
|
||||
delete canvas;
|
||||
delete req;
|
||||
delete bitmap;
|
||||
jclass resultClass = findClass(ienv, "net/osmand/plus/render/NativeOsmandLibrary$RenderingGenerationResult");
|
||||
|
||||
jmethodID resultClassCtorId = ienv->GetMethodID(resultClass, "<init>", "(Ljava/nio/ByteBuffer;)V");
|
||||
jmethodID resultClassCtorId = ienv->GetMethodID(resultClass, "<init>", "(Ljava/nio/ByteBuffer;)V");
|
||||
|
||||
#ifdef DEBUG_NAT_OPERATIONS
|
||||
osmand_log_print(LOG_INFO, "Native ok (init %d, native op %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
|
||||
osmand_log_print(LOG_INFO, "Native ok (init %d, native op %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
|
||||
#else
|
||||
osmand_log_print(LOG_INFO, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime());
|
||||
osmand_log_print(LOG_INFO, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(),
|
||||
rc.nativeOperations.getElapsedTime());
|
||||
#endif
|
||||
// Allocate ctor paramters
|
||||
jobject bitmapBuffer;
|
||||
if(encodePNG) {
|
||||
SkImageEncoder* enc = SkImageEncoder::Create(SkImageEncoder::kPNG_Type);
|
||||
SkDynamicMemoryWStream* stream = new SkDynamicMemoryWStream();
|
||||
enc->encodeStream(stream, *bitmap, 50);
|
||||
// clean previous data
|
||||
free(bitmapData);
|
||||
bitmapDataSize = stream->bytesWritten();
|
||||
bitmapData = malloc(bitmapDataSize);
|
||||
|
||||
// Allocate ctor paramters
|
||||
jobject bitmapBuffer = ienv->NewDirectByteBuffer(bitmapData, bitmap->getSize());
|
||||
stream->copyTo(bitmapData);
|
||||
}
|
||||
bitmapBuffer = ienv->NewDirectByteBuffer(bitmapData, bitmapDataSize);
|
||||
|
||||
/* Construct a result object */
|
||||
jobject resultObject = ienv->NewObject(resultClass, resultClassCtorId, bitmapBuffer);
|
||||
// delete variables
|
||||
delete bitmap;
|
||||
|
||||
return resultObject;
|
||||
/* Construct a result object */
|
||||
jobject resultObject = ienv->NewObject(resultClass, resultClassCtorId, bitmapBuffer);
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
|
||||
|
@ -325,12 +332,14 @@ jfieldID jfield_RenderingContext_width = NULL;
|
|||
jfieldID jfield_RenderingContext_height = NULL;
|
||||
jfieldID jfield_RenderingContext_zoom = NULL;
|
||||
jfieldID jfield_RenderingContext_rotate = NULL;
|
||||
jfieldID jfield_RenderingContext_useEnglishNames = NULL;
|
||||
jfieldID jfield_RenderingContext_pointCount = NULL;
|
||||
jfieldID jfield_RenderingContext_pointInsideCount = NULL;
|
||||
jfieldID jfield_RenderingContext_visible = NULL;
|
||||
jfieldID jfield_RenderingContext_allObjects = NULL;
|
||||
jfieldID jfield_RenderingContext_density = NULL;
|
||||
jfieldID jfield_RenderingContext_shadowRenderingMode = NULL;
|
||||
jfieldID jfield_RenderingContext_defaultColor = NULL;
|
||||
jfieldID jfield_RenderingContext_textRenderingTime = NULL;
|
||||
jfieldID jfield_RenderingContext_lastRenderedKey = NULL;
|
||||
|
||||
|
@ -346,12 +355,14 @@ void loadJniRenderingContext(JNIEnv* env)
|
|||
jfield_RenderingContext_height = getFid(env, jclass_RenderingContext, "height", "I" );
|
||||
jfield_RenderingContext_zoom = getFid(env, jclass_RenderingContext, "zoom", "I" );
|
||||
jfield_RenderingContext_rotate = getFid(env, jclass_RenderingContext, "rotate", "F" );
|
||||
jfield_RenderingContext_useEnglishNames = getFid(env, jclass_RenderingContext, "useEnglishNames", "Z" );
|
||||
jfield_RenderingContext_pointCount = getFid(env, jclass_RenderingContext, "pointCount", "I" );
|
||||
jfield_RenderingContext_pointInsideCount = getFid(env, jclass_RenderingContext, "pointInsideCount", "I" );
|
||||
jfield_RenderingContext_visible = getFid(env, jclass_RenderingContext, "visible", "I" );
|
||||
jfield_RenderingContext_allObjects = getFid(env, jclass_RenderingContext, "allObjects", "I" );
|
||||
jfield_RenderingContext_density = getFid(env, jclass_RenderingContext, "density", "F" );
|
||||
jfield_RenderingContext_shadowRenderingMode = getFid(env, jclass_RenderingContext, "shadowRenderingMode", "I" );
|
||||
jfield_RenderingContext_defaultColor = getFid(env, jclass_RenderingContext, "defaultColor", "I" );
|
||||
jfield_RenderingContext_textRenderingTime = getFid(env, jclass_RenderingContext, "textRenderingTime", "I" );
|
||||
jfield_RenderingContext_lastRenderedKey = getFid(env, jclass_RenderingContext, "lastRenderedKey", "I" );
|
||||
jmethod_RenderingContext_getIconRawData = env->GetMethodID(jclass_RenderingContext,
|
||||
|
@ -372,6 +383,8 @@ void pullFromJavaRenderingContext(JNIEnv* env, jobject jrc, JNIRenderingContext*
|
|||
rc->setRotate(env->GetFloatField( jrc, jfield_RenderingContext_rotate ));
|
||||
rc->setDensityScale(env->GetFloatField( jrc, jfield_RenderingContext_density ));
|
||||
rc->setShadowRenderingMode(env->GetIntField( jrc, jfield_RenderingContext_shadowRenderingMode ));
|
||||
rc->setDefaultColor(env->GetIntField( jrc, jfield_RenderingContext_defaultColor ));
|
||||
rc->setUseEnglishNames(env->GetBooleanField( jrc, jfield_RenderingContext_useEnglishNames ));
|
||||
rc->javaRenderingContext = jrc;
|
||||
}
|
||||
|
||||
|
|
|
@ -369,7 +369,9 @@ public:
|
|||
RenderingRulesStorage(const void* storage, bool createDefProperties = true) : storageId(storage),
|
||||
PROPS(createDefProperties) {
|
||||
tagValueGlobalRules = new HMAP::hash_map<int, RenderingRule*>[SIZE_STATES];
|
||||
getDictionaryValue("");
|
||||
if(createDefProperties) {
|
||||
getDictionaryValue("");
|
||||
}
|
||||
}
|
||||
|
||||
~RenderingRulesStorage() {
|
||||
|
|
Loading…
Reference in a new issue