Working commit

This commit is contained in:
Victor Shcherb 2012-05-09 23:53:37 +02:00
parent 5abab74cda
commit 82e4307ed5
11 changed files with 192 additions and 103 deletions

View file

@ -66,9 +66,8 @@ public class NativeLibrary {
protected static native void initRenderingRulesStorage(RenderingRulesStorage storage); protected static native void initRenderingRulesStorage(RenderingRulesStorage storage);
protected static native RenderingGenerationResult generateRendering_Indirect(RenderingContext rc, int searchResultHandler, protected static native RenderingGenerationResult generateRenderingIndirect(RenderingContext rc, int searchResultHandler,
int requestedBitmapWidth, int requestedBitmapHeight, int rowBytes, boolean isTransparent, boolean useEnglishNames, boolean isTransparent, RenderingRuleSearchRequest render, boolean encodePng);
RenderingRuleSearchRequest render, int defaultColor);
protected static native int searchNativeObjectsForRendering(int sleft, int sright, int stop, int sbottom, int zoom, protected static native int searchNativeObjectsForRendering(int sleft, int sright, int stop, int sbottom, int zoom,
RenderingRuleSearchRequest request, boolean skipDuplicates, Object objectWithInterruptedField, String msgIfNothingFound); RenderingRuleSearchRequest request, boolean skipDuplicates, Object objectWithInterruptedField, String msgIfNothingFound);

View file

@ -17,6 +17,8 @@ public class RenderingContext {
// FIELDS OF THAT CLASS ARE USED IN C++ // FIELDS OF THAT CLASS ARE USED IN C++
public boolean interrupted = false; public boolean interrupted = false;
public boolean nightMode = false; public boolean nightMode = false;
public boolean useEnglishNames = false;
public int defaultColor = 0xf1eee8;
public RenderingContext() { public RenderingContext() {
} }

View file

@ -199,6 +199,11 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
public static void main(String[] args) throws IOException { 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$ JFrame frame = new JFrame(Messages.getString("MapPanel.MAP.VIEW")); //$NON-NLS-1$
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
@ -207,6 +212,7 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
} }
final MapPanel panel = new MapPanel(DataExtractionSettings.getSettings().getTilesDirectory()); final MapPanel panel = new MapPanel(DataExtractionSettings.getSettings().getTilesDirectory());
panel.nativeRenderingImg = img;
frame.addWindowListener(new WindowAdapter(){ frame.addWindowListener(new WindowAdapter(){
@Override @Override
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
@ -222,9 +228,8 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
JMenuBar bar = new JMenuBar(); JMenuBar bar = new JMenuBar();
bar.add(getMenuToChooseSource(panel)); bar.add(getMenuToChooseSource(panel));
frame.setJMenuBar(bar); frame.setJMenuBar(bar);
frame.setSize(512, 512); frame.setSize(wx, hy);
frame.setVisible(true); frame.setVisible(true);
} }
private File tilesLocation = null; private File tilesLocation = null;
@ -232,6 +237,9 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
// name of source map // name of source map
private ITileSource map = TileSourceManager.getMapnikSource(); private ITileSource map = TileSourceManager.getMapnikSource();
private NativeSwingRendering nativeLibRendering;
private Image nativeRenderingImg;
// zoom level // zoom level
private int zoom = 1; private int zoom = 1;
@ -343,7 +351,9 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
@Override @Override
protected void paintComponent(Graphics g) { 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 i = 0; i < images.length; i++) {
for (int j = 0; j < images[i].length; j++) { for (int j = 0; j < images[i].length; j++) {
if (images[i][j] == null) { if (images[i][j] == null) {

View file

@ -1,6 +1,16 @@
package net.osmand.swing; package net.osmand.swing;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException; 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; 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"); 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(); RenderingRulesStorage storage = new RenderingRulesStorage();
final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() { final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() {
@Override @Override
@ -36,29 +48,75 @@ public class NativeSwingRendering extends NativeLibrary {
return storage; 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 { 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(); NativeSwingRendering lib = new NativeSwingRendering();
lib.initMapFile("/home/victor/projects/OsmAnd/data/osm-gen/Cuba2.obf"); lib.initMapFile("/home/victor/projects/OsmAnd/data/osm-gen/Cuba2.obf");
lib.initMapFile("/home/victor/projects/OsmAnd/data/osm-gen/basemap_2.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 = 22.5;
double latTop = 23.5;
double lonLeft = -80; double lonLeft = -80;
double latBottom = 23; float tileX = 2;
double lonRight = -79; 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 sleft = MapUtils.get31TileNumberX(lonLeft);
int sright = MapUtils.get31TileNumberX(lonRight); int sright = MapUtils.get31TileNumberX(lonRight);
int stop = MapUtils.get31TileNumberY(latTop); int stop = MapUtils.get31TileNumberY(latTop);
int sbottom = MapUtils.get31TileNumberY(latBottom); int sbottom = MapUtils.get31TileNumberY(latBottom);
NativeSearchResult res = lib.searchObjectsForRendering(sleft, sright, stop, sbottom, 11, request, true, MapPanel.showMainWindow(512, 512, lib.renderImage(sleft, sright, stop, sbottom, zoom));
ctx, "Nothing found");
} }
} }

View file

@ -539,11 +539,10 @@ public class MapRenderRepositories {
final long searchTime = System.currentTimeMillis() - now; final long searchTime = System.currentTimeMillis() - now;
currentRenderingContext = new OsmandRenderer.RenderingContext(context); currentRenderingContext = new OsmandRenderer.RenderingContext(context);
int fillColor = 0xf1eee8;
renderingReq.clearState(); renderingReq.clearState();
renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getZoom()); renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getZoom());
if(renderingReq.searchRenderingAttribute(RenderingRuleStorageProperties.A_DEFAULT_COLOR)) { 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.clearState();
renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getZoom()); renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getZoom());
@ -558,6 +557,7 @@ public class MapRenderRepositories {
currentRenderingContext.width = (int) (requestedBox.getTileWidth() * OsmandRenderer.TILE_SIZE); currentRenderingContext.width = (int) (requestedBox.getTileWidth() * OsmandRenderer.TILE_SIZE);
currentRenderingContext.height = (int) (requestedBox.getTileHeight() * OsmandRenderer.TILE_SIZE); currentRenderingContext.height = (int) (requestedBox.getTileHeight() * OsmandRenderer.TILE_SIZE);
currentRenderingContext.nightMode = nightMode; currentRenderingContext.nightMode = nightMode;
currentRenderingContext.useEnglishNames = prefs.USE_ENGLISH_NAMES.get();
currentRenderingContext.setDensityValue(prefs.USE_HIGH_RES_MAPS.get(), currentRenderingContext.setDensityValue(prefs.USE_HIGH_RES_MAPS.get(),
prefs.MAP_TEXT_SIZE.get(), renderer.getDensity()); prefs.MAP_TEXT_SIZE.get(), renderer.getDensity());
if (checkWhetherInterrupted()) { if (checkWhetherInterrupted()) {
@ -585,11 +585,9 @@ public class MapRenderRepositories {
if(nativeLib != null) { if(nativeLib != null) {
renderer.generateNewBitmapNative(currentRenderingContext, nativeLib, cNativeObjects, bmp, prefs.USE_ENGLISH_NAMES.get(), renderingReq, renderer.generateNewBitmapNative(currentRenderingContext, nativeLib, cNativeObjects, bmp, renderingReq, notifyList);
notifyList, fillColor);
} else { } else {
renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp, prefs.USE_ENGLISH_NAMES.get(), renderingReq, renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp, renderingReq, notifyList);
notifyList, fillColor);
} }
// Force to use rendering request in order to prevent Garbage Collector when it is used in C++ // Force to use rendering request in order to prevent Garbage Collector when it is used in C++
if(renderingReq != null){ if(renderingReq != null){

View file

@ -80,8 +80,7 @@ public class NativeOsmandLibrary extends NativeLibrary {
} }
public RenderingGenerationResult generateRendering(RenderingContext rc, NativeSearchResult searchResultHandler, public RenderingGenerationResult generateRendering(RenderingContext rc, NativeSearchResult searchResultHandler,
Bitmap bitmap, int requestedBitmapWidth, int requestedBitmapHeight, int rowBytes, boolean isTransparent, Bitmap bitmap, boolean isTransparent, RenderingRuleSearchRequest render) {
boolean useEnglishNames, RenderingRuleSearchRequest render, int defaultColor) {
if (searchResultHandler == null) { if (searchResultHandler == null) {
log.error("Error searchresult = null"); //$NON-NLS-1$ log.error("Error searchresult = null"); //$NON-NLS-1$
return new RenderingGenerationResult(null); return new RenderingGenerationResult(null);
@ -89,16 +88,15 @@ public class NativeOsmandLibrary extends NativeLibrary {
// Android 2.2+ // Android 2.2+
if(android.os.Build.VERSION.SDK_INT >= 8) { 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 { } 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, private static native RenderingGenerationResult generateRenderingDirect(RenderingContext rc, int searchResultHandler,
Bitmap bitmap, boolean useEnglishNames, Bitmap bitmap, RenderingRuleSearchRequest render);
RenderingRuleSearchRequest render, int defaultColor);
public static native int getCpuCount(); public static native int getCpuCount();
public static native boolean cpuHasNeonSupport(); public static native boolean cpuHasNeonSupport();

View file

@ -157,8 +157,7 @@ public class OsmandRenderer {
*/ */
public void generateNewBitmapNative(RenderingContext rc, NativeOsmandLibrary library, public void generateNewBitmapNative(RenderingContext rc, NativeOsmandLibrary library,
NativeSearchResult searchResultHandler, NativeSearchResult searchResultHandler,
Bitmap bmp, boolean useEnglishNames, Bitmap bmp, RenderingRuleSearchRequest render, final List<IMapDownloaderCallback> notifyList) {
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) {
// init rendering context // init rendering context
@ -175,9 +174,7 @@ public class OsmandRenderer {
// If res.bitmapBuffer is null, it indicates that rendering was done directly to // 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 // memory of passed bitmap, but this is supported only on Android >= 2.2
final NativeLibrary.RenderingGenerationResult res = library.generateRendering( final NativeLibrary.RenderingGenerationResult res = library.generateRendering(
rc, searchResultHandler, rc, searchResultHandler, bmp, bmp.hasAlpha(), render);
bmp, bmp.getWidth(), bmp.getHeight(), bmp.getRowBytes(), bmp.hasAlpha(),
useEnglishNames, render, defaultColor);
rc.ended = true; rc.ended = true;
notifyListeners(notifyList); notifyListeners(notifyList);
long time = System.currentTimeMillis() - now; long time = System.currentTimeMillis() - now;
@ -195,8 +192,8 @@ public class OsmandRenderer {
} }
} }
public void generateNewBitmap(RenderingContext rc, List<BinaryMapDataObject> objects, Bitmap bmp, boolean useEnglishNames, public void generateNewBitmap(RenderingContext rc, List<BinaryMapDataObject> objects, Bitmap bmp,
RenderingRuleSearchRequest render, final List<IMapDownloaderCallback> notifyList, int defaultColor) { RenderingRuleSearchRequest render, final List<IMapDownloaderCallback> notifyList) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (objects != null && !objects.isEmpty() && rc.width > 0 && rc.height > 0) { 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; rc.sinRotateTileSize = FloatMath.sin((float) Math.toRadians(rc.rotate)) * TILE_SIZE;
// fill area // fill area
Canvas cv = new Canvas(bmp); Canvas cv = new Canvas(bmp);
if (defaultColor != 0) { if (rc.defaultColor != 0) {
cv.drawColor(defaultColor); cv.drawColor(rc.defaultColor);
} }
// put in order map // put in order map
TIntObjectHashMap<TIntArrayList> orderMap = sortObjectsByProperOrder(rc, objects, render); TIntObjectHashMap<TIntArrayList> orderMap = sortObjectsByProperOrder(rc, objects, render);
@ -267,7 +264,7 @@ public class OsmandRenderer {
drawIconsOverCanvas(rc, cv); drawIconsOverCanvas(rc, cv);
notifyListeners(notifyList); notifyListeners(notifyList);
textRenderer.drawTextOverCanvas(rc, cv, useEnglishNames); textRenderer.drawTextOverCanvas(rc, cv, rc.useEnglishNames);
long time = System.currentTimeMillis() - now; long time = System.currentTimeMillis() - now;
rc.renderingDebugInfo = String.format("Rendering: %s ms (%s text)\n" rc.renderingDebugInfo = String.format("Rendering: %s ms (%s text)\n"

View file

@ -346,6 +346,7 @@ bool acceptTypes(SearchQuery* req, std::vector<tag_value>& types, MapIndex* root
return true; return true;
} }
} }
return false; return false;
} }

View file

@ -163,6 +163,7 @@ private :
float topY; float topY;
int width; int width;
int height; int height;
int defaultColor;
int zoom; int zoom;
float rotate; float rotate;
@ -206,6 +207,7 @@ public:
pointInsideCount(0), visible(0), allObjects(0){ pointInsideCount(0), visible(0), allObjects(0){
setRotate(0); setRotate(0);
setZoom(15); setZoom(15);
setDefaultColor(0xf1eee8);
} }
virtual ~RenderingContext(); virtual ~RenderingContext();
@ -221,6 +223,11 @@ public:
this->zoom = z; this->zoom = z;
this->tileDivisor = (1 << (31 - z)); this->tileDivisor = (1 << (31 - z));
} }
void setDefaultColor(int z) {
this->defaultColor = z;
}
void setRotate(float rot) { void setRotate(float rot) {
this->rotate = rot; this->rotate = rot;
this->cosRotateTileSize = cos(toRadians(rot)) * TILE_SIZE; this->cosRotateTileSize = cos(toRadians(rot)) * TILE_SIZE;
@ -245,6 +252,10 @@ public:
return width; return width;
} }
inline int getDefaultColor(){
return defaultColor;
}
inline int getHeight(){ inline int getHeight(){
return height; return height;
} }

View file

@ -5,6 +5,8 @@
#include <SkBitmap.h> #include <SkBitmap.h>
#include <SkCanvas.h> #include <SkCanvas.h>
#include <SkImageDecoder.h> #include <SkImageDecoder.h>
#include <SkImageEncoder.h>
#include <SkStream.h>
#include "java_renderRules.h" #include "java_renderRules.h"
#include "common.h" #include "common.h"
#include "java_wrap.h" #include "java_wrap.h"
@ -62,7 +64,6 @@ extern "C" JNIEXPORT jboolean JNICALL Java_net_osmand_NativeLibrary_initBinaryMa
// Global object // Global object
HMAP::hash_map<void*, RenderingRulesStorage*> cachedStorages; HMAP::hash_map<void*, RenderingRulesStorage*> cachedStorages;
@ -117,9 +118,8 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_NativeLibrary_searchNativeObje
#ifdef ANDROID_BUILD #ifdef ANDROID_BUILD
#include <android/bitmap.h> #include <android/bitmap.h>
extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_generateRendering_1Direct( JNIEnv* ienv, jobject obj, extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_generateRenderingDirect( JNIEnv* ienv, jobject obj,
jobject renderingContext, jint searchResult, jobject renderingContext, jint searchResult, jobject targetBitmap, jobject renderingRuleSearchRequest) {
jobject targetBitmap, jboolean useEnglishNames, jobject renderingRuleSearchRequest, jint defaultColor) {
// libJniGraphics interface // libJniGraphics interface
typedef int (*PTR_AndroidBitmap_getInfo)(JNIEnv*, jobject, AndroidBitmapInfo*); 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; delete bitmap;
// deleteObjects(mapDataObjects); // 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"); jmethodID resultClassCtorId = ienv->GetMethodID(resultClass, "<init>", "(Ljava/nio/ByteBuffer;)V");
@ -237,73 +237,80 @@ extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLib
void* bitmapData = NULL; void* bitmapData = NULL;
size_t bitmapDataSize = 0; size_t bitmapDataSize = 0;
extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_generateRendering_1Indirect( JNIEnv* ienv, jobject obj, extern "C" JNIEXPORT jobject JNICALL Java_net_osmand_NativeLibrary_generateRenderingIndirect( JNIEnv* ienv,
jobject renderingContext, jint searchResult, jobject obj, jobject renderingContext, jint searchResult, jboolean isTransparent,
jint requestedBitmapWidth, jint requestedBitmapHeight, jint rowBytes, jboolean isTransparent, jobject renderingRuleSearchRequest, jboolean encodePNG) {
jboolean useEnglishNames, jobject renderingRuleSearchRequest, jint defaultColor) {
osmand_log_print(LOG_INFO, "Creating SkBitmap in native w:%d h:%d!", requestedBitmapWidth, requestedBitmapHeight); JNIRenderingContext rc;
pullFromJavaRenderingContext(ienv, renderingContext, &rc);
osmand_log_print(LOG_INFO, "Creating SkBitmap in native w:%d h:%d!", rc.getWidth(), rc.getHeight());
SkBitmap* bitmap = new SkBitmap(); SkBitmap* bitmap = new SkBitmap();
if(isTransparent == JNI_TRUE) if (isTransparent == JNI_TRUE)
bitmap->setConfig(SkBitmap::kARGB_8888_Config, requestedBitmapWidth, requestedBitmapHeight, rowBytes); bitmap->setConfig(SkBitmap::kARGB_8888_Config, rc.getWidth(), rc.getHeight(), 0);
else else
bitmap->setConfig(SkBitmap::kRGB_565_Config, requestedBitmapWidth, requestedBitmapHeight, rowBytes); bitmap->setConfig(SkBitmap::kRGB_565_Config, rc.getWidth(), rc.getHeight(), 0);
if(bitmapData != NULL && bitmapDataSize != bitmap->getSize()) { if (bitmapData != NULL && bitmapDataSize != bitmap->getSize()) {
free(bitmapData); free(bitmapData);
bitmapData = NULL; bitmapData = NULL;
bitmapDataSize = 0; bitmapDataSize = 0;
} }
if(bitmapData == NULL && bitmapDataSize == 0) { if (bitmapData == NULL && bitmapDataSize == 0) {
bitmapDataSize = bitmap->getSize(); bitmapDataSize = bitmap->getSize();
bitmapData = malloc(bitmapDataSize); bitmapData = malloc(bitmapDataSize);
osmand_log_print(LOG_INFO, "Allocated %d bytes at %p", bitmapDataSize, bitmapData); osmand_log_print(LOG_INFO, "Allocated %d bytes at %p", bitmapDataSize, bitmapData);
} }
bitmap->setPixels(bitmapData); bitmap->setPixels(bitmapData);
osmand_log_print(LOG_INFO, "Initializing rendering");
ElapsedTimer initObjects; ElapsedTimer initObjects;
initObjects.start(); initObjects.start();
RenderingRuleSearchRequest* req = initSearchRequest(ienv, renderingRuleSearchRequest); RenderingRuleSearchRequest* req = initSearchRequest(ienv, renderingRuleSearchRequest);
JNIRenderingContext rc;
pullFromJavaRenderingContext(ienv, renderingContext, &rc);
rc.setUseEnglishNames(useEnglishNames);
ResultPublisher* result = ((ResultPublisher*) searchResult); ResultPublisher* result = ((ResultPublisher*) searchResult);
// std::vector <BaseMapDataObject* > mapDataObjects = marshalObjects(binaryMapDataObjects); // std::vector <BaseMapDataObject* > mapDataObjects = marshalObjects(binaryMapDataObjects);
osmand_log_print(LOG_INFO, "Rendering image");
initObjects.pause(); initObjects.pause();
// Main part do rendering // Main part do rendering
SkCanvas* canvas = new SkCanvas(*bitmap); SkCanvas* canvas = new SkCanvas(*bitmap);
canvas->drawColor(defaultColor); canvas->drawColor(rc.getDefaultColor());
if(result != NULL) { if (result != NULL) {
doRendering(result->result, canvas, req, &rc); doRendering(result->result, canvas, req, &rc);
} }
pushToJavaRenderingContext(ienv, renderingContext, &rc);
osmand_log_print(LOG_INFO, "End Rendering image");
// delete variables
delete canvas; delete canvas;
delete req; delete req;
delete bitmap; pushToJavaRenderingContext(ienv, renderingContext, &rc);
jclass resultClass = findClass(ienv, "net/osmand/plus/render/NativeOsmandLibrary$RenderingGenerationResult");
jclass resultClass = findClass(ienv, "net/osmand/NativeLibrary$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 #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 #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 #endif
// Allocate ctor paramters // Allocate ctor paramters
jobject bitmapBuffer = ienv->NewDirectByteBuffer(bitmapData, bitmap->getSize()); 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);
stream->copyTo(bitmapData);
}
bitmapBuffer = ienv->NewDirectByteBuffer(bitmapData, bitmapDataSize);
// delete variables
delete bitmap;
/* Construct a result object */ /* Construct a result object */
jobject resultObject = ienv->NewObject(resultClass, resultClassCtorId, bitmapBuffer); jobject resultObject = ienv->NewObject(resultClass, resultClassCtorId, bitmapBuffer);
@ -325,12 +332,14 @@ jfieldID jfield_RenderingContext_width = NULL;
jfieldID jfield_RenderingContext_height = NULL; jfieldID jfield_RenderingContext_height = NULL;
jfieldID jfield_RenderingContext_zoom = NULL; jfieldID jfield_RenderingContext_zoom = NULL;
jfieldID jfield_RenderingContext_rotate = NULL; jfieldID jfield_RenderingContext_rotate = NULL;
jfieldID jfield_RenderingContext_useEnglishNames = NULL;
jfieldID jfield_RenderingContext_pointCount = NULL; jfieldID jfield_RenderingContext_pointCount = NULL;
jfieldID jfield_RenderingContext_pointInsideCount = NULL; jfieldID jfield_RenderingContext_pointInsideCount = NULL;
jfieldID jfield_RenderingContext_visible = NULL; jfieldID jfield_RenderingContext_visible = NULL;
jfieldID jfield_RenderingContext_allObjects = NULL; jfieldID jfield_RenderingContext_allObjects = NULL;
jfieldID jfield_RenderingContext_density = NULL; jfieldID jfield_RenderingContext_density = NULL;
jfieldID jfield_RenderingContext_shadowRenderingMode = NULL; jfieldID jfield_RenderingContext_shadowRenderingMode = NULL;
jfieldID jfield_RenderingContext_defaultColor = NULL;
jfieldID jfield_RenderingContext_textRenderingTime = NULL; jfieldID jfield_RenderingContext_textRenderingTime = NULL;
jfieldID jfield_RenderingContext_lastRenderedKey = 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_height = getFid(env, jclass_RenderingContext, "height", "I" );
jfield_RenderingContext_zoom = getFid(env, jclass_RenderingContext, "zoom", "I" ); jfield_RenderingContext_zoom = getFid(env, jclass_RenderingContext, "zoom", "I" );
jfield_RenderingContext_rotate = getFid(env, jclass_RenderingContext, "rotate", "F" ); 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_pointCount = getFid(env, jclass_RenderingContext, "pointCount", "I" );
jfield_RenderingContext_pointInsideCount = getFid(env, jclass_RenderingContext, "pointInsideCount", "I" ); jfield_RenderingContext_pointInsideCount = getFid(env, jclass_RenderingContext, "pointInsideCount", "I" );
jfield_RenderingContext_visible = getFid(env, jclass_RenderingContext, "visible", "I" ); jfield_RenderingContext_visible = getFid(env, jclass_RenderingContext, "visible", "I" );
jfield_RenderingContext_allObjects = getFid(env, jclass_RenderingContext, "allObjects", "I" ); jfield_RenderingContext_allObjects = getFid(env, jclass_RenderingContext, "allObjects", "I" );
jfield_RenderingContext_density = getFid(env, jclass_RenderingContext, "density", "F" ); jfield_RenderingContext_density = getFid(env, jclass_RenderingContext, "density", "F" );
jfield_RenderingContext_shadowRenderingMode = getFid(env, jclass_RenderingContext, "shadowRenderingMode", "I" ); 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_textRenderingTime = getFid(env, jclass_RenderingContext, "textRenderingTime", "I" );
jfield_RenderingContext_lastRenderedKey = getFid(env, jclass_RenderingContext, "lastRenderedKey", "I" ); jfield_RenderingContext_lastRenderedKey = getFid(env, jclass_RenderingContext, "lastRenderedKey", "I" );
jmethod_RenderingContext_getIconRawData = env->GetMethodID(jclass_RenderingContext, 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->setRotate(env->GetFloatField( jrc, jfield_RenderingContext_rotate ));
rc->setDensityScale(env->GetFloatField( jrc, jfield_RenderingContext_density )); rc->setDensityScale(env->GetFloatField( jrc, jfield_RenderingContext_density ));
rc->setShadowRenderingMode(env->GetIntField( jrc, jfield_RenderingContext_shadowRenderingMode )); 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; rc->javaRenderingContext = jrc;
} }

View file

@ -369,8 +369,10 @@ public:
RenderingRulesStorage(const void* storage, bool createDefProperties = true) : storageId(storage), RenderingRulesStorage(const void* storage, bool createDefProperties = true) : storageId(storage),
PROPS(createDefProperties) { PROPS(createDefProperties) {
tagValueGlobalRules = new HMAP::hash_map<int, RenderingRule*>[SIZE_STATES]; tagValueGlobalRules = new HMAP::hash_map<int, RenderingRule*>[SIZE_STATES];
if(createDefProperties) {
getDictionaryValue(""); getDictionaryValue("");
} }
}
~RenderingRulesStorage() { ~RenderingRulesStorage() {
delete[] tagValueGlobalRules; delete[] tagValueGlobalRules;