diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..4d57c77849 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,18 @@ +[submodule "OsmAnd/jni/jpeg/jpeg_library"] + path = OsmAnd/jni/jpeg/jpeg_library + url = https://android.googlesource.com/platform/external/jpeg.git +[submodule "OsmAnd/jni/skia/skia_library"] + path = OsmAnd/jni/skia/skia_library + url = https://android.googlesource.com/platform/external/skia.git +[submodule "OsmAnd/jni/png/png_library"] + path = OsmAnd/jni/png/png_library + url = https://android.googlesource.com/platform/external/libpng.git +[submodule "OsmAnd/jni/freetype/freetype_library"] + path = OsmAnd/jni/freetype/freetype_library + url = https://android.googlesource.com/platform/external/freetype.git +[submodule "OsmAnd/jni/expat/expat_library"] + path = OsmAnd/jni/expat/expat_library + url = https://android.googlesource.com/platform/external/expat.git +[submodule "OsmAnd/jni/gif/gif_library"] + path = OsmAnd/jni/gif/gif_library + url = https://android.googlesource.com/platform/external/giflib.git diff --git a/OsmAnd/jni/expat/expat_library b/OsmAnd/jni/expat/expat_library new file mode 160000 index 0000000000..28304159f2 --- /dev/null +++ b/OsmAnd/jni/expat/expat_library @@ -0,0 +1 @@ +Subproject commit 28304159f2fea1f702929883c634e52755d6e74b diff --git a/OsmAnd/jni/freetype/freetype_library b/OsmAnd/jni/freetype/freetype_library new file mode 160000 index 0000000000..15321e16a0 --- /dev/null +++ b/OsmAnd/jni/freetype/freetype_library @@ -0,0 +1 @@ +Subproject commit 15321e16a085b9b5c85cf029aee86bf57b2e65c1 diff --git a/OsmAnd/jni/gif/gif_library b/OsmAnd/jni/gif/gif_library new file mode 160000 index 0000000000..b2597268ae --- /dev/null +++ b/OsmAnd/jni/gif/gif_library @@ -0,0 +1 @@ +Subproject commit b2597268aef084202a8c349d1cc072c03c6e22eb diff --git a/OsmAnd/jni/jpeg/jpeg_library b/OsmAnd/jni/jpeg/jpeg_library new file mode 160000 index 0000000000..d4fad7f50f --- /dev/null +++ b/OsmAnd/jni/jpeg/jpeg_library @@ -0,0 +1 @@ +Subproject commit d4fad7f50f79626455d88523207e05b868819cd8 diff --git a/OsmAnd/jni/osmand/Android.mk b/OsmAnd/jni/osmand/Android.mk index 890e4e95eb..14d92bd5ea 100644 --- a/OsmAnd/jni/osmand/Android.mk +++ b/OsmAnd/jni/osmand/Android.mk @@ -8,8 +8,8 @@ ifeq ($(PROTOBUF),) endif # Set 'skia' folder only if it's not externally set -ifeq ($(SKIA_ABS),) - SKIA_ABS := $(LOCAL_PATH)/../skia +ifeq ($(OSMAND_SKIA_ABS),) + OSMAND_SKIA_ABS := $(LOCAL_PATH)/../skia/skia_library endif # Name of the local module @@ -23,14 +23,15 @@ endif # Include paths LOCAL_C_INCLUDES := $(LOCAL_PATH) \ $(PROTOBUF) \ - $(SKIA_ABS)/trunk/include/core \ - $(SKIA_ABS)/trunk/include/utils \ - $(SKIA_ABS)/trunk/include/config \ - $(SKIA_ABS)/trunk/include/effects \ - $(SKIA_ABS)/trunk/include/utils/android \ - $(SKIA_ABS)/trunk/src/core + $(LOCAL_PATH)/../skia \ + $(OSMAND_SKIA_ABS)/include/core \ + $(OSMAND_SKIA_ABS)/include/images \ + $(OSMAND_SKIA_ABS)/include/utils \ + $(OSMAND_SKIA_ABS)/include/config \ + $(OSMAND_SKIA_ABS)/include/effects \ + $(OSMAND_SKIA_ABS)/include/utils/android \ + $(OSMAND_SKIA_ABS)/src/core -LOCAL_CPP_EXTENSION := .cpp LOCAL_SRC_FILES := \ common.cpp \ mapObjects.cpp \ @@ -46,6 +47,11 @@ LOCAL_CFLAGS := \ -DSK_USE_POSIX_THREADS \ -DSK_RELEASE \ -DGR_RELEASE=1 + +ifdef OSMAND_PROFILE_NATIVE_OPERATIONS +LOCAL_CFLAGS += \ + -DPROFILE_NATIVE_OPERATIONS +endif ifneq ($(LOCAL_ARM_NEON),true) LOCAL_STATIC_LIBRARIES := proto skia diff --git a/OsmAnd/jni/osmand/binaryRead.cpp b/OsmAnd/jni/osmand/binaryRead.cpp index 456af3e4f7..7d2099ccf9 100644 --- a/OsmAnd/jni/osmand/binaryRead.cpp +++ b/OsmAnd/jni/osmand/binaryRead.cpp @@ -83,7 +83,7 @@ struct SearchQuery { } bool isCancelled(){ - return globalEnv()->GetBooleanField(o, interruptedField); + return getGlobalJniEnv()->GetBooleanField(o, interruptedField); } }; @@ -361,7 +361,7 @@ void loadJniBinaryRead() { extern "C" JNIEXPORT void JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_deleteSearchResult(JNIEnv* ienv, jobject obj, jint searchResult) { // DO NOT DO IT it can leads to messing thread that is not allowed - // setGlobalEnv(ienv); + // setGlobalJniEnv(ienv); SearchResult* result = (SearchResult*) searchResult; if(result != NULL){ delete result; @@ -690,7 +690,7 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar jobject obj, jint sleft, jint sright, jint stop, jint sbottom, jint zoom, jstring mapName, jobject renderingRuleSearchRequest, bool skipDuplicates, jint searchResult, jobject objInterrupted) { // TODO skipDuplicates not supported - setGlobalEnv(ienv); + setGlobalJniEnv(ienv); SearchResult* result = (SearchResult*) searchResult; if(result == NULL) { result = new SearchResult(); @@ -702,9 +702,9 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar } BinaryMapFile* file = i->second; RenderingRuleSearchRequest* req = initSearchRequest(renderingRuleSearchRequest); - jclass clObjInterrupted = globalEnv()->GetObjectClass(objInterrupted); + jclass clObjInterrupted = getGlobalJniEnv()->GetObjectClass(objInterrupted); jfieldID interruptedField = getFid(clObjInterrupted, "interrupted", "Z"); - globalEnv()->DeleteLocalRef(clObjInterrupted); + getGlobalJniEnv()->DeleteLocalRef(clObjInterrupted); SearchQuery q(sleft,sright, stop, sbottom, req, objInterrupted, interruptedField); fseek(file->f, 0, 0); @@ -757,7 +757,7 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar extern "C" JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_initBinaryMapFile(JNIEnv* ienv, jobject obj, jobject path) { // Verify that the version of the library that we linked against is - setGlobalEnv(ienv); + setGlobalJniEnv(ienv); const char* utf = ienv->GetStringUTFChars((jstring) path, NULL); std::string inputName(utf); ienv->ReleaseStringUTFChars((jstring) path, utf); diff --git a/OsmAnd/jni/osmand/common.cpp b/OsmAnd/jni/osmand/common.cpp index 9787a7aad0..96f1b3904f 100644 --- a/OsmAnd/jni/osmand/common.cpp +++ b/OsmAnd/jni/osmand/common.cpp @@ -1,252 +1,366 @@ -#ifndef _OSMAND_COMMON -#define _OSMAND_COMMON - -#include #include + #include #include #include #include #include +#include -JNIEnv* globalE; -JavaVM* globalVM; -JNIEnv* globalEnv(){ - return globalE; -} +#include "common.h" -JNIEnv* setGlobalEnv(JNIEnv* e) { - globalVM->GetEnv((void**)&globalE, JNI_VERSION_1_4); - // try to avoid problem with different thread attach -// globalE = e; - return globalE; -} +const char* const LOG_TAG = "net.osmand:native"; -extern void loadJniCommon(); -extern void loadJNIRenderingRules(); -extern void loadJNIRendering(); -extern void loadJniMapObjects(); -extern void loadJniBinaryRead(); +JavaVM* globalJVM = NULL; +JNIEnv* globalJniEnv = NULL; -extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { - if(vm->GetEnv((void **)&globalE, JNI_VERSION_1_4)){ - return JNI_ERR; /* JNI version not supported */ - } - globalVM = vm; - loadJniCommon(); - loadJNIRendering(); - loadJNIRenderingRules(); - loadJniMapObjects(); - loadJniBinaryRead(); - return JNI_VERSION_1_4; -} - -//extern "C" JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_loadLibrary(JNIEnv* ienv) {} - - -jclass RenderingContextClass; -jfieldID RenderingContext_interrupted; - -jclass RenderingIconsClass; -jmethodID RenderingIcons_getIcon; - -jclass globalRef(jobject o) +JNIEnv* getGlobalJniEnv() { - return (jclass) globalEnv()->NewGlobalRef( o); + return globalJniEnv; } - -jfieldID getFid(jclass cls,const char* fieldName, const char* sig ) +JNIEnv* setGlobalJniEnv(JNIEnv* e) { - return globalEnv()->GetFieldID( cls, fieldName, sig); + if(!globalJVM) + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "No globalJVM set"); + globalJVM->GetEnv((void**)&globalJniEnv, JNI_VERSION_1_6); + return globalJniEnv; } -watcher::watcher() { - elapsedTime = 0; - enableFlag = true; - run = false; -} -void watcher::enable() { - enableFlag = true; -} -void watcher::disable() { - pause(); - enableFlag = false; -} -void watcher::start() { - if (!enableFlag) { - return; - } - if (!run) { - clock_gettime(CLOCK_MONOTONIC, &startInit); -// gettimeofday(&startInit, NULL); - } - run = true; -} -void watcher::pause() { - if (!run) { - return; - } - clock_gettime(CLOCK_MONOTONIC, &endInit); - // gettimeofday(&endInit, NULL); - int sec = endInit.tv_sec - startInit.tv_sec; - if (sec > 0) { - elapsedTime += 1e9 * sec; - } - elapsedTime += endInit.tv_nsec - startInit.tv_nsec; -// elapsedTime += (endInit.tv_sec * 1000 + endInit.tv_usec / 1000) -// - (startInit.tv_sec * 1000 + startInit.tv_usec / 1000); - run = false; -} -int watcher::getElapsedTime() { - pause(); - return elapsedTime / 1e6; +// Forward declarations +void loadJniCommon(); +void loadJniRendering(); +void loadJniRenderingRules(); +void loadJniMapObjects(); +void loadJniBinaryRead(); +extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) +{ + if(vm->GetEnv((void **)&globalJniEnv, JNI_VERSION_1_6)) + return JNI_ERR; /* JNI version not supported */ + globalJVM = vm; + + loadJniCommon(); + loadJniRendering(); + loadJniRenderingRules(); + loadJniMapObjects(); + loadJniBinaryRead(); + + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "JNI_OnLoad completed"); + + return JNI_VERSION_1_6; } +void throwNewException(const char* msg) +{ + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, msg); + getGlobalJniEnv()->ThrowNew(getGlobalJniEnv()->FindClass("java/lang/Exception"), msg); +} +jclass findClass(const char* className, bool mustHave/* = true*/) +{ + jclass javaClass = getGlobalJniEnv()->FindClass(className); + if(!javaClass && mustHave) + throwNewException((std::string("Failed to find class ") + className).c_str()); + return (jclass)newGlobalRef(javaClass); +} + +jobject newGlobalRef(jobject o) +{ + return getGlobalJniEnv()->NewGlobalRef(o); +} + +jfieldID getFid(jclass cls, const char* fieldName, const char* sig) +{ + jfieldID jfield = getGlobalJniEnv()->GetFieldID(cls, fieldName, sig); + if(!jfield) + throwNewException((std::string("Failed to find field ") + fieldName + std::string(" with signature ") + sig).c_str()); + return jfield; +} std::string getStringField(jobject o, jfieldID fid) { - jstring st = (jstring) globalEnv()->GetObjectField(o, fid); - if(st == NULL) + jstring jstr = (jstring)getGlobalJniEnv()->GetObjectField(o, fid); + if(!jstr) { + throwNewException("Failed to get object from field"); return std::string(); } - const char* utf = globalEnv()->GetStringUTFChars(st, NULL); - std::string res(utf); - globalEnv()->ReleaseStringUTFChars(st, utf); - globalEnv()->DeleteLocalRef(st); - return res; + const char* utfBytes = getGlobalJniEnv()->GetStringUTFChars(jstr, NULL); + //TODO: I'm not quite sure that if real unicode will happen here, this will work as expected + std::string result(utfBytes); + getGlobalJniEnv()->ReleaseStringUTFChars(jstr, utfBytes); + getGlobalJniEnv()->DeleteLocalRef(jstr); + return result; } -std::string getString(jstring st) { - if (st == NULL) { - return EMPTY_STRING; +std::string getString(jstring jstr) +{ + if(!jstr) + { + throwNewException("NULL jstring passed in"); + return std::string(); } - const char* utf = globalEnv()->GetStringUTFChars(st, NULL); - std::string res(utf); - globalEnv()->ReleaseStringUTFChars(st, utf); - return res; + const char* utfBytes = getGlobalJniEnv()->GetStringUTFChars(jstr, NULL); + //TODO: I'm not quite sure that if real unicode will happen here, this will work as expected + std::string result(utfBytes); + getGlobalJniEnv()->ReleaseStringUTFChars(jstr, utfBytes); + return result; } std::string getStringMethod(jobject o, jmethodID fid) { - return getString((jstring) globalEnv()->CallObjectMethod(o, fid)); + return getString((jstring)getGlobalJniEnv()->CallObjectMethod(o, fid)); } std::string getStringMethod(jobject o, jmethodID fid, int i) { - return getString((jstring) globalEnv()->CallObjectMethod(o, fid, i)); + return getString((jstring)getGlobalJniEnv()->CallObjectMethod(o, fid, i)); } -float getDensityValue(RenderingContext* rc, float val) { - if (rc -> highResMode && rc -> density > 1) { - return val * rc -> density * rc -> mapTextSize; - } else { - return val * rc -> mapTextSize; - } +jclass jclass_RenderingContext = NULL; +jfieldID jfield_RenderingContext_interrupted = NULL; +jclass jclass_RenderingIcons = NULL; +jmethodID jmethod_RenderingIcons_getIconAsByteBuffer = NULL; +jfieldID jfield_RenderingContext_leftX = NULL; +jfieldID jfield_RenderingContext_topY = NULL; +jfieldID jfield_RenderingContext_width = NULL; +jfieldID jfield_RenderingContext_height = NULL; +jfieldID jfield_RenderingContext_zoom = NULL; +jfieldID jfield_RenderingContext_rotate = NULL; +jfieldID jfield_RenderingContext_tileDivisor = NULL; +jfieldID jfield_RenderingContext_pointCount = NULL; +jfieldID jfield_RenderingContext_pointInsideCount = NULL; +jfieldID jfield_RenderingContext_visible = NULL; +jfieldID jfield_RenderingContext_allObjects = NULL; +jfieldID jfield_RenderingContext_cosRotateTileSize = NULL; +jfieldID jfield_RenderingContext_sinRotateTileSize = NULL; +jfieldID jfield_RenderingContext_density = NULL; +jfieldID jfield_RenderingContext_highResMode = NULL; +jfieldID jfield_RenderingContext_mapTextSize = NULL; +jfieldID jfield_RenderingContext_shadowRenderingMode = NULL; +jfieldID jfield_RenderingContext_shadowLevelMin = NULL; +jfieldID jfield_RenderingContext_shadowLevelMax = NULL; +jfieldID jfield_RenderingContext_ctx = NULL; +jfieldID jfield_RenderingContext_textRenderingTime = NULL; +jfieldID jfield_RenderingContext_lastRenderedKey = NULL; + +void loadJniCommon() +{ + jclass_RenderingContext = findClass("net/osmand/plus/render/OsmandRenderer$RenderingContext"); + jfield_RenderingContext_interrupted = getFid(jclass_RenderingContext, "interrupted", "Z"); + jfield_RenderingContext_leftX = getFid( jclass_RenderingContext, "leftX", "F" ); + jfield_RenderingContext_topY = getFid( jclass_RenderingContext, "topY", "F" ); + jfield_RenderingContext_width = getFid( jclass_RenderingContext, "width", "I" ); + jfield_RenderingContext_height = getFid( jclass_RenderingContext, "height", "I" ); + jfield_RenderingContext_zoom = getFid( jclass_RenderingContext, "zoom", "I" ); + jfield_RenderingContext_rotate = getFid( jclass_RenderingContext, "rotate", "F" ); + jfield_RenderingContext_tileDivisor = getFid( jclass_RenderingContext, "tileDivisor", "F" ); + jfield_RenderingContext_pointCount = getFid( jclass_RenderingContext, "pointCount", "I" ); + jfield_RenderingContext_pointInsideCount = getFid( jclass_RenderingContext, "pointInsideCount", "I" ); + jfield_RenderingContext_visible = getFid( jclass_RenderingContext, "visible", "I" ); + jfield_RenderingContext_allObjects = getFid( jclass_RenderingContext, "allObjects", "I" ); + jfield_RenderingContext_cosRotateTileSize = getFid( jclass_RenderingContext, "cosRotateTileSize", "F" ); + jfield_RenderingContext_sinRotateTileSize = getFid( jclass_RenderingContext, "sinRotateTileSize", "F" ); + jfield_RenderingContext_density = getFid( jclass_RenderingContext, "density", "F" ); + jfield_RenderingContext_highResMode = getFid( jclass_RenderingContext, "highResMode", "Z" ); + jfield_RenderingContext_mapTextSize = getFid( jclass_RenderingContext, "mapTextSize", "F" ); + jfield_RenderingContext_shadowRenderingMode = getFid( jclass_RenderingContext, "shadowRenderingMode", "I" ); + jfield_RenderingContext_shadowLevelMin = getFid( jclass_RenderingContext, "shadowLevelMin", "I" ); + jfield_RenderingContext_shadowLevelMax = getFid( jclass_RenderingContext, "shadowLevelMax", "I" ); + jfield_RenderingContext_ctx = getFid( jclass_RenderingContext, "ctx", "Landroid/content/Context;" ); + jfield_RenderingContext_textRenderingTime = getFid( jclass_RenderingContext, "textRenderingTime", "I" ); + jfield_RenderingContext_lastRenderedKey = getFid( jclass_RenderingContext, "lastRenderedKey", "I" ); + + jclass_RenderingIcons = findClass("net/osmand/plus/render/RenderingIcons"); + jmethod_RenderingIcons_getIconAsByteBuffer = getGlobalJniEnv()->GetStaticMethodID(jclass_RenderingIcons, + "getIconAsByteBuffer", + "(Landroid/content/Context;Ljava/lang/String;)Ljava/nio/ByteBuffer;"); } -SkBitmap* getNativeBitmap(jobject bmpObj){ - if(bmpObj == NULL){ - return NULL; - } - jclass bmpClass = globalEnv()->GetObjectClass(bmpObj); - SkBitmap* bmp = (SkBitmap*)globalEnv()->CallIntMethod(bmpObj, globalEnv()->GetMethodID(bmpClass, "ni", "()I")); - globalEnv()->DeleteLocalRef(bmpClass); - return bmp; +//TODO: Dead code +/* +void unloadJniCommon() { + getGlobalJniEnv()->DeleteGlobalRef(jclass_RenderingIcons); + getGlobalJniEnv()->DeleteGlobalRef(jclass_RenderingContext); +} +*/ + +void pullFromJavaRenderingContext(jobject jrc, RenderingContext* rc) +{ + rc->leftX = getGlobalJniEnv()->GetFloatField( jrc, jfield_RenderingContext_leftX ); + rc->topY = getGlobalJniEnv()->GetFloatField( jrc, jfield_RenderingContext_topY ); + rc->width = getGlobalJniEnv()->GetIntField( jrc, jfield_RenderingContext_width ); + rc->height = getGlobalJniEnv()->GetIntField( jrc, jfield_RenderingContext_height ); + + rc->zoom = getGlobalJniEnv()->GetIntField( jrc, jfield_RenderingContext_zoom ); + rc->rotate = getGlobalJniEnv()->GetFloatField( jrc, jfield_RenderingContext_rotate ); + rc->tileDivisor = getGlobalJniEnv()->GetFloatField( jrc, jfield_RenderingContext_tileDivisor ); + + rc->pointCount = getGlobalJniEnv()->GetIntField( jrc, jfield_RenderingContext_pointCount ); + rc->pointInsideCount = getGlobalJniEnv()->GetIntField( jrc, jfield_RenderingContext_pointInsideCount ); + rc->visible = getGlobalJniEnv()->GetIntField( jrc, jfield_RenderingContext_visible ); + rc->allObjects = getGlobalJniEnv()->GetIntField( jrc, jfield_RenderingContext_allObjects ); + + rc->cosRotateTileSize = getGlobalJniEnv()->GetFloatField( jrc, jfield_RenderingContext_cosRotateTileSize ); + rc->sinRotateTileSize = getGlobalJniEnv()->GetFloatField( jrc, jfield_RenderingContext_sinRotateTileSize ); + rc->density = getGlobalJniEnv()->GetFloatField( jrc, jfield_RenderingContext_density ); + rc->highResMode = getGlobalJniEnv()->GetBooleanField( jrc, jfield_RenderingContext_highResMode ); + rc->mapTextSize = getGlobalJniEnv()->GetFloatField( jrc, jfield_RenderingContext_mapTextSize ); + + rc->shadowRenderingMode = getGlobalJniEnv()->GetIntField( jrc, jfield_RenderingContext_shadowRenderingMode ); + rc->shadowLevelMin = getGlobalJniEnv()->GetIntField( jrc, jfield_RenderingContext_shadowLevelMin ); + rc->shadowLevelMax = getGlobalJniEnv()->GetIntField( jrc, jfield_RenderingContext_shadowLevelMax ); + rc->androidContext = getGlobalJniEnv()->GetObjectField(jrc, jfield_RenderingContext_ctx ); + rc->lastRenderedKey = 0; + + rc->javaRenderingContext = jrc; +} + + +void pushToJavaRenderingContext(jobject jrc, RenderingContext* rc) +{ + getGlobalJniEnv()->SetIntField( jrc, jfield_RenderingContext_pointCount, rc->pointCount); + getGlobalJniEnv()->SetIntField( jrc, jfield_RenderingContext_pointInsideCount, rc->pointInsideCount); + getGlobalJniEnv()->SetIntField( jrc, jfield_RenderingContext_visible, rc->visible); + getGlobalJniEnv()->SetIntField( jrc, jfield_RenderingContext_allObjects, rc->allObjects); + getGlobalJniEnv()->SetIntField( jrc, jfield_RenderingContext_textRenderingTime, rc->textRendering.getElapsedTime()); + getGlobalJniEnv()->SetIntField( jrc, jfield_RenderingContext_lastRenderedKey, rc->lastRenderedKey); + + getGlobalJniEnv()->DeleteLocalRef(rc->androidContext); +} + +TextDrawInfo::TextDrawInfo(std::string itext) + : text(itext) + , drawOnPath(false) + , path(NULL) + , pathRotate(0) +{ +} + +TextDrawInfo::~TextDrawInfo() +{ + if (path) + delete path; +} + +IconDrawInfo::IconDrawInfo() + : bmp(NULL) +{ +} + +RenderingContext::RenderingContext() + : javaRenderingContext(NULL) + , androidContext(NULL) +{ +} + +RenderingContext::~RenderingContext() +{ + std::vector::iterator itTextToDraw; + for(itTextToDraw = textToDraw.begin(); itTextToDraw != textToDraw.end(); ++itTextToDraw) + delete (*itTextToDraw); +} + +bool RenderingContext::interrupted() +{ + return getGlobalJniEnv()->GetBooleanField(javaRenderingContext, jfield_RenderingContext_interrupted); +} + +float getDensityValue(RenderingContext* rc, float val) +{ + if (rc->highResMode && rc->density > 1) + return val * rc->density * rc->mapTextSize; + else + return val * rc->mapTextSize; +} + +ElapsedTimer::ElapsedTimer() + : elapsedTime(0) + , enableFlag(true) + , run(false) +{ +} + +void ElapsedTimer::enable() +{ + enableFlag = true; +} + +void ElapsedTimer::disable() +{ + pause(); + enableFlag = false; +} + +void ElapsedTimer::start() +{ + if (!enableFlag) + return; + if (!run) + clock_gettime(CLOCK_MONOTONIC, &startInit); + run = true; +} + +void ElapsedTimer::pause() +{ + if (!run) + return; + + clock_gettime(CLOCK_MONOTONIC, &endInit); + int sec = endInit.tv_sec - startInit.tv_sec; + if (sec > 0) + elapsedTime += 1e9 * sec; + elapsedTime += endInit.tv_nsec - startInit.tv_nsec; + run = false; +} + +int ElapsedTimer::getElapsedTime() +{ + pause(); + return elapsedTime / 1e6; } std::hash_map cachedBitmaps; -SkBitmap* getCachedBitmap(RenderingContext* rc, std::string js) + +SkBitmap* getCachedBitmap(RenderingContext* rc, std::string bitmapResource) { - if (cachedBitmaps.find(js) != cachedBitmaps.end()) { - return cachedBitmaps[js]; - } + // Try to find previously cached + std::hash_map::iterator itPreviouslyCachedBitmap = cachedBitmaps.find(bitmapResource); + if (itPreviouslyCachedBitmap != cachedBitmaps.end()) + return itPreviouslyCachedBitmap->second; + rc->nativeOperations.pause(); - jstring jstr = globalEnv()->NewStringUTF(js.c_str()); - jobject bmp = globalEnv()->CallStaticObjectMethod(RenderingIconsClass, RenderingIcons_getIcon, rc->androidContext, jstr); - SkBitmap* res = getNativeBitmap(bmp); + + jstring jstr = getGlobalJniEnv()->NewStringUTF(bitmapResource.c_str()); + jobject javaIconByteBuffer = getGlobalJniEnv()->CallStaticObjectMethod(jclass_RenderingIcons, jmethod_RenderingIcons_getIconAsByteBuffer, rc->androidContext, jstr); + if(!javaIconByteBuffer) + return NULL; + + // Decode bitmap + SkBitmap* iconBitmap = new SkBitmap(); + void* bitmapBuffer = getGlobalJniEnv()->GetDirectBufferAddress(javaIconByteBuffer); + size_t bufferLen = getGlobalJniEnv()->GetDirectBufferCapacity(javaIconByteBuffer); + //TODO: JPEG is badly supported! At the moment it needs sdcard to be present (sic). Patch that + if(!SkImageDecoder::DecodeMemory(bitmapBuffer, bufferLen, iconBitmap)) + { + // Failed to decode + delete iconBitmap; + + rc->nativeOperations.start(); + getGlobalJniEnv()->DeleteLocalRef(javaIconByteBuffer); + getGlobalJniEnv()->DeleteLocalRef(jstr); + + throwNewException((std::string("Failed to decode ") + bitmapResource).c_str()); + + return NULL; + } + cachedBitmaps[bitmapResource] = iconBitmap; + rc->nativeOperations.start(); - globalEnv()->DeleteLocalRef(bmp); - globalEnv()->DeleteLocalRef(jstr); - if(res != NULL){ - res = new SkBitmap(*res); - } - cachedBitmaps[js] = res; - - return res; + getGlobalJniEnv()->DeleteLocalRef(javaIconByteBuffer); + getGlobalJniEnv()->DeleteLocalRef(jstr); + + return iconBitmap; } - -void loadJniCommon() { - RenderingContextClass = globalRef(globalEnv()->FindClass("net/osmand/plus/render/OsmandRenderer$RenderingContext")); - RenderingContext_interrupted = getFid(RenderingContextClass, "interrupted", "Z"); - - RenderingIconsClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRule")); - RenderingIconsClass = globalRef(globalEnv()->FindClass("net/osmand/plus/render/RenderingIcons")); - RenderingIcons_getIcon = globalEnv()->GetStaticMethodID(RenderingIconsClass, "getIcon", - "(Landroid/content/Context;Ljava/lang/String;)Landroid/graphics/Bitmap;"); - -} - -void unloadJniCommon() { - globalEnv()->DeleteGlobalRef(RenderingContextClass); - globalEnv()->DeleteGlobalRef(RenderingIconsClass); -} - - - - - -void copyRenderingContext(jobject orc, RenderingContext* rc) -{ - rc->leftX = globalEnv()->GetFloatField( orc, getFid( RenderingContextClass, "leftX", "F" ) ); - rc->topY = globalEnv()->GetFloatField( orc, getFid( RenderingContextClass, "topY", "F" ) ); - rc->width = globalEnv()->GetIntField( orc, getFid( RenderingContextClass, "width", "I" ) ); - rc->height = globalEnv()->GetIntField( orc, getFid( RenderingContextClass, "height", "I" ) ); - - - rc->zoom = globalEnv()->GetIntField( orc, getFid( RenderingContextClass, "zoom", "I" ) ); - rc->rotate = globalEnv()->GetFloatField( orc, getFid( RenderingContextClass, "rotate", "F" ) ); - rc->tileDivisor = globalEnv()->GetFloatField( orc, getFid( RenderingContextClass, "tileDivisor", "F" ) ); - - rc->pointCount = globalEnv()->GetIntField( orc, getFid( RenderingContextClass, "pointCount", "I" ) ); - rc->pointInsideCount = globalEnv()->GetIntField( orc, getFid( RenderingContextClass, "pointInsideCount", "I" ) ); - rc->visible = globalEnv()->GetIntField( orc, getFid( RenderingContextClass, "visible", "I" ) ); - rc->allObjects = globalEnv()->GetIntField( orc, getFid( RenderingContextClass, "allObjects", "I" ) ); - - rc->cosRotateTileSize = globalEnv()->GetFloatField( orc, getFid( RenderingContextClass, "cosRotateTileSize", "F" ) ); - rc->sinRotateTileSize = globalEnv()->GetFloatField( orc, getFid( RenderingContextClass, "sinRotateTileSize", "F" ) ); - rc->density = globalEnv()->GetFloatField( orc, getFid( RenderingContextClass, "density", "F" ) ); - rc->highResMode = globalEnv()->GetBooleanField( orc, getFid( RenderingContextClass, "highResMode", "Z" ) ); - rc->mapTextSize = globalEnv()->GetFloatField( orc, getFid( RenderingContextClass, "mapTextSize", "F" ) ); - - - rc->shadowRenderingMode = globalEnv()->GetIntField( orc, getFid( RenderingContextClass, "shadowRenderingMode", "I" ) ); - rc->shadowLevelMin = globalEnv()->GetIntField( orc, getFid( RenderingContextClass, "shadowLevelMin", "I" ) ); - rc->shadowLevelMax = globalEnv()->GetIntField( orc, getFid( RenderingContextClass, "shadowLevelMax", "I" ) ); - rc->androidContext = globalEnv()->GetObjectField(orc, getFid( RenderingContextClass, "ctx", "Landroid/content/Context;")); - rc->lastRenderedKey = 0; - - rc->originalRC = orc; - -} - - -void mergeRenderingContext(jobject orc, RenderingContext* rc) -{ - globalEnv()->SetIntField( orc, getFid(RenderingContextClass, "pointCount", "I" ) , rc->pointCount); - globalEnv()->SetIntField( orc, getFid(RenderingContextClass, "pointInsideCount", "I" ) , rc->pointInsideCount); - globalEnv()->SetIntField( orc, getFid(RenderingContextClass, "visible", "I" ) , rc->visible); - globalEnv()->SetIntField( orc, getFid(RenderingContextClass, "allObjects", "I" ) , rc->allObjects); - globalEnv()->SetIntField( orc, getFid(RenderingContextClass, "textRenderingTime", "I" ) , rc->textRendering.getElapsedTime()); - globalEnv()->SetIntField( orc, getFid(RenderingContextClass, "lastRenderedKey", "I" ) , rc->lastRenderedKey); - - globalEnv()->DeleteLocalRef(rc->androidContext); -} - - - -#endif diff --git a/OsmAnd/jni/osmand/common.h b/OsmAnd/jni/osmand/common.h index 334b59aa5c..d3783d9110 100644 --- a/OsmAnd/jni/osmand/common.h +++ b/OsmAnd/jni/osmand/common.h @@ -5,107 +5,101 @@ #include #include #include + #include #include -// Constants -#define DEBUG_NAT_OPERATIONS -#ifdef DEBUG_NAT_OPERATIONS - #define NAT_COUNT(rc, op) rc->nativeOperations.pause(); op; rc->nativeOperations.start() +#ifdef PROFILE_NATIVE_OPERATIONS + #define PROFILE_NATIVE_OPERATION(rc, op) rc->nativeOperations.pause(); op; rc->nativeOperations.start() #else - #define NAT_COUNT(rc, op) op; + #define PROFILE_NATIVE_OPERATION(rc, op) op; #endif -const std::string EMPTY_STRING; -const int WHITE_COLOR = -1; -const int BLACK_COLOR = 0xff000000; +struct RenderingContext; -JNIEnv* globalEnv(); +JNIEnv* getGlobalJniEnv(); +JNIEnv* setGlobalJniEnv(JNIEnv*); -JNIEnv* setGlobalEnv(JNIEnv* e); +// Android helpers +extern const char* const LOG_TAG; // JNI Helpers -//extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved); - +void throwNewException(const char* msg); +jclass findClass(const char* className, bool mustHave = true); std::string getString(jstring st); std::string getStringMethod(jobject o, jmethodID fid, int i); std::string getStringMethod(jobject o, jmethodID fid); std::string getStringField(jobject o, jfieldID fid); -jclass globalRef(jobject o); -jfieldID getFid(jclass cls,const char* fieldName, const char* sig ); +jobject newGlobalRef(jobject o); +jfieldID getFid(jclass cls, const char* fieldName, const char* sig); +void pullFromJavaRenderingContext(jobject jrc, RenderingContext* rc); +void pushToJavaRenderingContext(jobject jrc, RenderingContext* rc); -class watcher { - +class ElapsedTimer +{ private: long elapsedTime; bool enableFlag; - // timeval startInit; - // timeval endInit; timespec startInit; timespec endInit; bool run; public: - watcher(); + ElapsedTimer(); void enable(); - void disable(); void start(); - void pause(); int getElapsedTime(); }; -// Rendering context methods -class TextDrawInfo { -public : +struct TextDrawInfo { + TextDrawInfo(std::string); + ~TextDrawInfo(); + std::string text; - TextDrawInfo(std::string itext) { - text = itext; - drawOnPath = false; - path = NULL; - pathRotate = 0; - } SkRect bounds; float centerX; float centerY; - float textSize ; - float minDistance ; + float textSize; + float minDistance; int textColor; - int textShadow ; - uint textWrap ; - bool bold ; + int textShadow; + uint textWrap; + bool bold; std::string shieldRes; int textOrder; bool drawOnPath; SkPath* path; float pathRotate; - float vOffset ; - float hOffset ; - - ~TextDrawInfo() { - if (path != NULL) { - delete path; - } - } + float vOffset; + float hOffset; }; -struct IconDrawInfo { +struct IconDrawInfo +{ + IconDrawInfo(); + SkBitmap* bmp; float x; float y; }; -extern jfieldID RenderingContext_interrupted; -struct RenderingContext { - jobject originalRC; +struct RenderingContext +{ + RenderingContext(); + ~RenderingContext(); + bool interrupted(); + + jobject javaRenderingContext; + jobject androidContext; bool useEnglishNames; @@ -130,9 +124,8 @@ struct RenderingContext { int visible; int allObjects; int lastRenderedKey; - watcher textRendering; - watcher nativeOperations; - + class ElapsedTimer textRendering; + class ElapsedTimer nativeOperations; // use to calculate points float calcX; @@ -146,23 +139,10 @@ struct RenderingContext { // not expect any shadow int shadowLevelMin; int shadowLevelMax; - - bool interrupted() { - return globalEnv()->GetBooleanField(originalRC, RenderingContext_interrupted); - } - ~RenderingContext() { - for (uint i = 0; i < textToDraw.size(); i++) { - delete textToDraw.at(i); - } - } }; -void copyRenderingContext(jobject orc, RenderingContext* rc); -void mergeRenderingContext(jobject orc, RenderingContext* rc); float getDensityValue(RenderingContext* rc, float val); -SkBitmap* getCachedBitmap(RenderingContext* rc, std::string js); -SkBitmap* getNativeBitmap(jobject bmpObj); - +SkBitmap* getCachedBitmap(RenderingContext* rc, std::string bitmapResource); #endif /*_OSMAND_COMMON_H*/ diff --git a/OsmAnd/jni/osmand/mapObjects.cpp b/OsmAnd/jni/osmand/mapObjects.cpp index 4ce42230a1..74d6bb5171 100644 --- a/OsmAnd/jni/osmand/mapObjects.cpp +++ b/OsmAnd/jni/osmand/mapObjects.cpp @@ -36,24 +36,24 @@ std::vector marshalObjects(jobjectArray binaryMapDataObjec { std::vector v; - const size_t size = globalEnv()->GetArrayLength(binaryMapDataObjects); + const size_t size = getGlobalJniEnv()->GetArrayLength(binaryMapDataObjects); size_t i = 0; for (; i < size; i++) { - jobject binaryMapDataObject = (jobject) globalEnv()->GetObjectArrayElement(binaryMapDataObjects, i); - if (globalEnv()->IsInstanceOf(binaryMapDataObject, MultiPolygonClass)) { + jobject binaryMapDataObject = (jobject) getGlobalJniEnv()->GetObjectArrayElement(binaryMapDataObjects, i); + if (getGlobalJniEnv()->IsInstanceOf(binaryMapDataObject, MultiPolygonClass)) { MultiPolygonObject* o = new MultiPolygonObject(); v.push_back((BaseMapDataObject* )o); - o->layer = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getLayer); + o->layer = getGlobalJniEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getLayer); o->tag = getStringMethod(binaryMapDataObject, MultiPolygon_getTag); o->value = getStringMethod(binaryMapDataObject, MultiPolygon_getValue); - int boundsCount = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getBoundsCount); + int boundsCount = getGlobalJniEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getBoundsCount); for (int ji = 0; ji < boundsCount; ji++) { - int cnt = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getBoundPointsCount, ji); + int cnt = getGlobalJniEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getBoundPointsCount, ji); std::vector > vs; for (int js = 0; js < cnt; js++) { - int xt = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31XTile, js, ji); - int yt = globalEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31YTile, js, ji); + int xt = getGlobalJniEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31XTile, js, ji); + int yt = getGlobalJniEnv()->CallIntMethod(binaryMapDataObject, MultiPolygon_getPoint31YTile, js, ji); vs.push_back( std::pair (xt, yt) ); } @@ -64,40 +64,40 @@ std::vector marshalObjects(jobjectArray binaryMapDataObjec } else { - jintArray types = (jintArray) globalEnv()->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTypes); + jintArray types = (jintArray) getGlobalJniEnv()->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTypes); if (types != NULL) { MapDataObject* o = new MapDataObject(); - jint sizeTypes = globalEnv()->GetArrayLength(types); - jint* els = globalEnv()->GetIntArrayElements(types, NULL); + jint sizeTypes = getGlobalJniEnv()->GetArrayLength(types); + jint* els = getGlobalJniEnv()->GetIntArrayElements(types, NULL); int j = 0; for (; j < sizeTypes; j++) { int wholeType = els[j]; o->types.push_back(wholeType); - jobject pair = globalEnv()->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTagValue, j); + jobject pair = getGlobalJniEnv()->CallObjectMethod(binaryMapDataObject, BinaryMapDataObject_getTagValue, j); if (pair != NULL) { std::string tag = getStringField(pair, TagValuePair_tag); std::string value = getStringField(pair, TagValuePair_value); o->tagValues.push_back( std::pair(tag, value)); - globalEnv()->DeleteLocalRef(pair); + getGlobalJniEnv()->DeleteLocalRef(pair); } else { - o->tagValues.push_back( std::pair(EMPTY_STRING, EMPTY_STRING)); + o->tagValues.push_back( std::pair(std::string(), std::string())); } } - jint sizePoints = globalEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPointsLength); + jint sizePoints = getGlobalJniEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPointsLength); for (j = 0; j < sizePoints; j++) { - int tx = globalEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31XTile, j); - int ty = globalEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31YTile, j); + int tx = getGlobalJniEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31XTile, j); + int ty = getGlobalJniEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getPoint31YTile, j); o->points.push_back(std::pair(tx, ty)); } o->name = getStringMethod(binaryMapDataObject, BinaryMapDataObject_getName); - o->highwayAttributes = globalEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getHighwayAttributes); - globalEnv()->ReleaseIntArrayElements(types, els, JNI_ABORT); - globalEnv()->DeleteLocalRef(types); + o->highwayAttributes = getGlobalJniEnv()->CallIntMethod(binaryMapDataObject, BinaryMapDataObject_getHighwayAttributes); + getGlobalJniEnv()->ReleaseIntArrayElements(types, els, JNI_ABORT); + getGlobalJniEnv()->DeleteLocalRef(types); v.push_back((BaseMapDataObject* )o); } } - globalEnv()->DeleteLocalRef(binaryMapDataObject); + getGlobalJniEnv()->DeleteLocalRef(binaryMapDataObject); } return v; @@ -115,38 +115,38 @@ void deleteObjects(std::vector & v) void loadJniMapObjects() { - MultiPolygonClass = globalRef(globalEnv()->FindClass("net/osmand/osm/MultyPolygon")); - MultiPolygon_getTag = globalEnv()->GetMethodID(MultiPolygonClass, "getTag", "()Ljava/lang/String;"); - MultiPolygon_getValue = globalEnv()->GetMethodID(MultiPolygonClass, "getValue", "()Ljava/lang/String;"); - MultiPolygon_getName = globalEnv()->GetMethodID(MultiPolygonClass, "getName", "(I)Ljava/lang/String;"); - MultiPolygon_getLayer = globalEnv()->GetMethodID(MultiPolygonClass, "getLayer", "()I"); - MultiPolygon_getPoint31XTile = globalEnv()->GetMethodID(MultiPolygonClass, "getPoint31XTile", "(II)I"); - MultiPolygon_getPoint31YTile = globalEnv()->GetMethodID(MultiPolygonClass, "getPoint31YTile", "(II)I"); - MultiPolygon_getBoundsCount = globalEnv()->GetMethodID(MultiPolygonClass, "getBoundsCount", "()I"); - MultiPolygon_getBoundPointsCount = globalEnv()->GetMethodID(MultiPolygonClass, "getBoundPointsCount", "(I)I"); + MultiPolygonClass = findClass("net/osmand/osm/MultyPolygon"); + MultiPolygon_getTag = getGlobalJniEnv()->GetMethodID(MultiPolygonClass, "getTag", "()Ljava/lang/String;"); + MultiPolygon_getValue = getGlobalJniEnv()->GetMethodID(MultiPolygonClass, "getValue", "()Ljava/lang/String;"); + MultiPolygon_getName = getGlobalJniEnv()->GetMethodID(MultiPolygonClass, "getName", "(I)Ljava/lang/String;"); + MultiPolygon_getLayer = getGlobalJniEnv()->GetMethodID(MultiPolygonClass, "getLayer", "()I"); + MultiPolygon_getPoint31XTile = getGlobalJniEnv()->GetMethodID(MultiPolygonClass, "getPoint31XTile", "(II)I"); + MultiPolygon_getPoint31YTile = getGlobalJniEnv()->GetMethodID(MultiPolygonClass, "getPoint31YTile", "(II)I"); + MultiPolygon_getBoundsCount = getGlobalJniEnv()->GetMethodID(MultiPolygonClass, "getBoundsCount", "()I"); + MultiPolygon_getBoundPointsCount = getGlobalJniEnv()->GetMethodID(MultiPolygonClass, "getBoundPointsCount", "(I)I"); - BinaryMapDataObjectClass = globalRef(globalEnv()->FindClass("net/osmand/binary/BinaryMapDataObject")); - BinaryMapDataObject_getPointsLength = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getPointsLength", "()I"); - BinaryMapDataObject_getPoint31YTile = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getPoint31YTile", "(I)I"); - BinaryMapDataObject_getPoint31XTile = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getPoint31XTile", "(I)I"); - BinaryMapDataObject_getHighwayAttributes = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getHighwayAttributes", "()I"); - BinaryMapDataObject_getTypes = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getTypes", "()[I"); - BinaryMapDataObject_getName = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getName", "()Ljava/lang/String;"); - BinaryMapDataObject_getTagValue = globalEnv()->GetMethodID(BinaryMapDataObjectClass, "getTagValue", + BinaryMapDataObjectClass = findClass("net/osmand/binary/BinaryMapDataObject"); + BinaryMapDataObject_getPointsLength = getGlobalJniEnv()->GetMethodID(BinaryMapDataObjectClass, "getPointsLength", "()I"); + BinaryMapDataObject_getPoint31YTile = getGlobalJniEnv()->GetMethodID(BinaryMapDataObjectClass, "getPoint31YTile", "(I)I"); + BinaryMapDataObject_getPoint31XTile = getGlobalJniEnv()->GetMethodID(BinaryMapDataObjectClass, "getPoint31XTile", "(I)I"); + BinaryMapDataObject_getHighwayAttributes = getGlobalJniEnv()->GetMethodID(BinaryMapDataObjectClass, "getHighwayAttributes", "()I"); + BinaryMapDataObject_getTypes = getGlobalJniEnv()->GetMethodID(BinaryMapDataObjectClass, "getTypes", "()[I"); + BinaryMapDataObject_getName = getGlobalJniEnv()->GetMethodID(BinaryMapDataObjectClass, "getName", "()Ljava/lang/String;"); + BinaryMapDataObject_getTagValue = getGlobalJniEnv()->GetMethodID(BinaryMapDataObjectClass, "getTagValue", "(I)Lnet/osmand/binary/BinaryMapIndexReader$TagValuePair;"); - TagValuePairClass = globalRef(globalEnv()->FindClass("net/osmand/binary/BinaryMapIndexReader$TagValuePair")); - TagValuePair_tag = globalEnv()->GetFieldID(TagValuePairClass, "tag", "Ljava/lang/String;"); - TagValuePair_value = globalEnv()->GetFieldID(TagValuePairClass, "value", "Ljava/lang/String;"); + TagValuePairClass = findClass("net/osmand/binary/BinaryMapIndexReader$TagValuePair"); + TagValuePair_tag = getGlobalJniEnv()->GetFieldID(TagValuePairClass, "tag", "Ljava/lang/String;"); + TagValuePair_value = getGlobalJniEnv()->GetFieldID(TagValuePairClass, "value", "Ljava/lang/String;"); } void unloadJniMapObjects() { - globalEnv()->DeleteGlobalRef( MultiPolygonClass ); - globalEnv()->DeleteGlobalRef( BinaryMapDataObjectClass ); - globalEnv()->DeleteGlobalRef( TagValuePairClass ); + getGlobalJniEnv()->DeleteGlobalRef( MultiPolygonClass ); + getGlobalJniEnv()->DeleteGlobalRef( BinaryMapDataObjectClass ); + getGlobalJniEnv()->DeleteGlobalRef( TagValuePairClass ); } int getNegativeWayLayer(int type) { diff --git a/OsmAnd/jni/osmand/renderRules.cpp b/OsmAnd/jni/osmand/renderRules.cpp index f88a7b3505..e83bb4735f 100644 --- a/OsmAnd/jni/osmand/renderRules.cpp +++ b/OsmAnd/jni/osmand/renderRules.cpp @@ -69,7 +69,7 @@ RenderingRuleProperty* RenderingRulesStorage::getProperty(const char* st) { std::string RenderingRulesStorage::getDictionaryValue(int i) { if (i < 0) { - return EMPTY_STRING; + return std::string(); } return dictionary.at(i); } @@ -79,54 +79,54 @@ int RenderingRulesStorage::getDictionaryValue(std::string s) { } void RenderingRulesStorage::initDictionary() { - jobject listDictionary = globalEnv()->GetObjectField(javaStorage, RenderingRulesStorageClass_dictionary); - uint sz = globalEnv()->CallIntMethod(listDictionary, List_size); + jobject listDictionary = getGlobalJniEnv()->GetObjectField(javaStorage, RenderingRulesStorageClass_dictionary); + uint sz = getGlobalJniEnv()->CallIntMethod(listDictionary, List_size); uint i = 0; for (; i < sz; i++) { - jstring st = (jstring) globalEnv()->CallObjectMethod(listDictionary, List_get, i); + jstring st = (jstring) getGlobalJniEnv()->CallObjectMethod(listDictionary, List_get, i); // if(st != NULL) // { - const char* utf = globalEnv()->GetStringUTFChars(st, NULL); + const char* utf = getGlobalJniEnv()->GetStringUTFChars(st, NULL); std::string d = std::string(utf); - globalEnv()->ReleaseStringUTFChars(st, utf); - globalEnv()->DeleteLocalRef(st); + getGlobalJniEnv()->ReleaseStringUTFChars(st, utf); + getGlobalJniEnv()->DeleteLocalRef(st); dictionary.push_back(d); dictionaryMap[d] = i; // } } - globalEnv()->DeleteLocalRef(listDictionary); + getGlobalJniEnv()->DeleteLocalRef(listDictionary); } void RenderingRulesStorage::initProperties() { - jobject props = globalEnv()->GetObjectField(javaStorage, RenderingRulesStorage_PROPS); - jobject listProps = globalEnv()->GetObjectField(props, RenderingRuleStorageProperties_rules); - uint sz = globalEnv()->CallIntMethod(listProps, List_size); + jobject props = getGlobalJniEnv()->GetObjectField(javaStorage, RenderingRulesStorage_PROPS); + jobject listProps = getGlobalJniEnv()->GetObjectField(props, RenderingRuleStorageProperties_rules); + uint sz = getGlobalJniEnv()->CallIntMethod(listProps, List_size); uint i = 0; for (; i < sz; i++) { - jobject rulePrope = globalEnv()->CallObjectMethod(listProps, List_get, i); - bool input = (globalEnv()->GetBooleanField(rulePrope, RenderingRuleProperty_input) == JNI_TRUE); - int type = globalEnv()->GetIntField(rulePrope, RenderingRuleProperty_type); + jobject rulePrope = getGlobalJniEnv()->CallObjectMethod(listProps, List_get, i); + bool input = (getGlobalJniEnv()->GetBooleanField(rulePrope, RenderingRuleProperty_input) == JNI_TRUE); + int type = getGlobalJniEnv()->GetIntField(rulePrope, RenderingRuleProperty_type); std::string name = getStringField(rulePrope, RenderingRuleProperty_attrName); RenderingRuleProperty* prop = new RenderingRuleProperty(type, input, name, i); properties.push_back(*prop); propertyMap[name] = prop; - globalEnv()->DeleteLocalRef(rulePrope); + getGlobalJniEnv()->DeleteLocalRef(rulePrope); } - globalEnv()->DeleteLocalRef(props); - globalEnv()->DeleteLocalRef(listProps); + getGlobalJniEnv()->DeleteLocalRef(props); + getGlobalJniEnv()->DeleteLocalRef(listProps); } void RenderingRulesStorage::initRules() { for (int i = 1; i < SIZE_STATES; i++) { - jobjectArray rules = (jobjectArray) globalEnv()->CallObjectMethod(javaStorage, RenderingRulesStorage_getRules, + jobjectArray rules = (jobjectArray) getGlobalJniEnv()->CallObjectMethod(javaStorage, RenderingRulesStorage_getRules, i); - jsize len = globalEnv()->GetArrayLength(rules); + jsize len = getGlobalJniEnv()->GetArrayLength(rules); for (jsize j = 0; j < len; j++) { - jobject rRule = globalEnv()->GetObjectArrayElement(rules, j); + jobject rRule = getGlobalJniEnv()->GetObjectArrayElement(rules, j); RenderingRule* rule = createRenderingRule(rRule); - globalEnv()->DeleteLocalRef(rRule); + getGlobalJniEnv()->DeleteLocalRef(rRule); if (rule != NULL) { jsize psz = rule->properties.size(); @@ -145,69 +145,69 @@ void RenderingRulesStorage::initRules() { } } } - globalEnv()->DeleteLocalRef(rules); + getGlobalJniEnv()->DeleteLocalRef(rules); } } RenderingRule* RenderingRulesStorage::createRenderingRule(jobject rRule) { RenderingRule* rule = new RenderingRule; - jobjectArray props = (jobjectArray) globalEnv()->GetObjectField(rRule, RenderingRule_properties); - jintArray intProps = (jintArray) globalEnv()->GetObjectField(rRule, RenderingRule_intProperties); - jfloatArray floatProps = (jfloatArray) globalEnv()->GetObjectField(rRule, RenderingRule_floatProperties); - jobject ifChildren = globalEnv()->GetObjectField(rRule, RenderingRule_ifChildren); - jobject ifElseChildren = globalEnv()->GetObjectField(rRule, RenderingRule_ifElseChildren); + jobjectArray props = (jobjectArray) getGlobalJniEnv()->GetObjectField(rRule, RenderingRule_properties); + jintArray intProps = (jintArray) getGlobalJniEnv()->GetObjectField(rRule, RenderingRule_intProperties); + jfloatArray floatProps = (jfloatArray) getGlobalJniEnv()->GetObjectField(rRule, RenderingRule_floatProperties); + jobject ifChildren = getGlobalJniEnv()->GetObjectField(rRule, RenderingRule_ifChildren); + jobject ifElseChildren = getGlobalJniEnv()->GetObjectField(rRule, RenderingRule_ifElseChildren); - jsize sz = globalEnv()->GetArrayLength(props); + jsize sz = getGlobalJniEnv()->GetArrayLength(props); if (floatProps != NULL) { - jfloat* fe = globalEnv()->GetFloatArrayElements(floatProps, NULL); + jfloat* fe = getGlobalJniEnv()->GetFloatArrayElements(floatProps, NULL); for (int j = 0; j < sz; j++) { rule->floatProperties.push_back(fe[j]); } - globalEnv()->ReleaseFloatArrayElements(floatProps, fe, JNI_ABORT); - globalEnv()->DeleteLocalRef(floatProps); + getGlobalJniEnv()->ReleaseFloatArrayElements(floatProps, fe, JNI_ABORT); + getGlobalJniEnv()->DeleteLocalRef(floatProps); } else { rule->floatProperties.assign(sz, 0); } if (intProps != NULL) { - jint* ie = globalEnv()->GetIntArrayElements(intProps, NULL); + jint* ie = getGlobalJniEnv()->GetIntArrayElements(intProps, NULL); for (int j = 0; j < sz; j++) { rule->intProperties.push_back(ie[j]); } - globalEnv()->ReleaseIntArrayElements(intProps, ie, JNI_ABORT); - globalEnv()->DeleteLocalRef(intProps); + getGlobalJniEnv()->ReleaseIntArrayElements(intProps, ie, JNI_ABORT); + getGlobalJniEnv()->DeleteLocalRef(intProps); } else { rule->intProperties.assign(sz, -1); } for (jsize i = 0; i < sz; i++) { - jobject prop = globalEnv()->GetObjectArrayElement(props, i); + jobject prop = getGlobalJniEnv()->GetObjectArrayElement(props, i); std::string attr = getStringField(prop, RenderingRuleProperty_attrName); RenderingRuleProperty* p = getProperty(attr.c_str()); rule->properties.push_back(p); - globalEnv()->DeleteLocalRef(prop); + getGlobalJniEnv()->DeleteLocalRef(prop); } - globalEnv()->DeleteLocalRef(props); + getGlobalJniEnv()->DeleteLocalRef(props); if (ifChildren != NULL) { - sz = globalEnv()->CallIntMethod(ifChildren, List_size); + sz = getGlobalJniEnv()->CallIntMethod(ifChildren, List_size); for (jsize i = 0; i < sz; i++) { - jobject o = globalEnv()->CallObjectMethod(ifChildren, List_get, i); + jobject o = getGlobalJniEnv()->CallObjectMethod(ifChildren, List_get, i); rule->ifChildren.push_back(*createRenderingRule(o)); - globalEnv()->DeleteLocalRef(o); + getGlobalJniEnv()->DeleteLocalRef(o); } - globalEnv()->DeleteLocalRef(ifChildren); + getGlobalJniEnv()->DeleteLocalRef(ifChildren); } if (ifElseChildren != NULL) { - sz = globalEnv()->CallIntMethod(ifElseChildren, List_size); + sz = getGlobalJniEnv()->CallIntMethod(ifElseChildren, List_size); for (jsize i = 0; i < sz; i++) { - jobject o = globalEnv()->CallObjectMethod(ifElseChildren, List_get, i); + jobject o = getGlobalJniEnv()->CallObjectMethod(ifElseChildren, List_get, i); rule->ifElseChildren.push_back(*createRenderingRule(o)); - globalEnv()->DeleteLocalRef(o); + getGlobalJniEnv()->DeleteLocalRef(o); } - globalEnv()->DeleteLocalRef(ifElseChildren); + getGlobalJniEnv()->DeleteLocalRef(ifElseChildren); } return rule; @@ -218,67 +218,67 @@ RenderingRulesStorage* defaultStorage = NULL; void RenderingRuleSearchRequest::initObject(jobject rrs) { jsize sz; - jobjectArray oa = (jobjectArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_props); - sz = globalEnv()->GetArrayLength(oa); + jobjectArray oa = (jobjectArray) getGlobalJniEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_props); + sz = getGlobalJniEnv()->GetArrayLength(oa); std::vector requestProps; for (jsize i = 0; i < sz; i++) { - jobject prop = globalEnv()->GetObjectArrayElement(oa, i); + jobject prop = getGlobalJniEnv()->GetObjectArrayElement(oa, i); std::string attr = getStringField(prop, RenderingRuleProperty_attrName); RenderingRuleProperty* p = storage->getProperty(attr.c_str()); requestProps.push_back(p); - globalEnv()->DeleteLocalRef(prop); + getGlobalJniEnv()->DeleteLocalRef(prop); } - globalEnv()->DeleteLocalRef(oa); + getGlobalJniEnv()->DeleteLocalRef(oa); sz = storage->getPropertiesSize(); { values = new int[sz]; - jintArray ia = (jintArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_values); - jint* ie = globalEnv()->GetIntArrayElements(ia, NULL); + jintArray ia = (jintArray) getGlobalJniEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_values); + jint* ie = getGlobalJniEnv()->GetIntArrayElements(ia, NULL); for (int i = 0; i < sz; i++) { values[requestProps.at(i)->id] = ie[i]; } - globalEnv()->ReleaseIntArrayElements(ia, ie, JNI_ABORT); - globalEnv()->DeleteLocalRef(ia); + getGlobalJniEnv()->ReleaseIntArrayElements(ia, ie, JNI_ABORT); + getGlobalJniEnv()->DeleteLocalRef(ia); } { fvalues = new float[sz]; - jfloatArray ia = (jfloatArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues); - jfloat* ie = globalEnv()->GetFloatArrayElements(ia, NULL); + jfloatArray ia = (jfloatArray) getGlobalJniEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues); + jfloat* ie = getGlobalJniEnv()->GetFloatArrayElements(ia, NULL); for (int i = 0; i < sz; i++) { fvalues[requestProps.at(i)->id] = ie[i]; } - globalEnv()->ReleaseFloatArrayElements(ia, ie, JNI_ABORT); - globalEnv()->DeleteLocalRef(ia); + getGlobalJniEnv()->ReleaseFloatArrayElements(ia, ie, JNI_ABORT); + getGlobalJniEnv()->DeleteLocalRef(ia); } { savedValues = new int[sz]; - jintArray ia = (jintArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_values); - jint* ie = globalEnv()->GetIntArrayElements(ia, NULL); + jintArray ia = (jintArray) getGlobalJniEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_values); + jint* ie = getGlobalJniEnv()->GetIntArrayElements(ia, NULL); for (int i = 0; i < sz; i++) { savedValues[requestProps.at(i)->id] = ie[i]; } - globalEnv()->ReleaseIntArrayElements(ia, ie, JNI_ABORT); - globalEnv()->DeleteLocalRef(ia); + getGlobalJniEnv()->ReleaseIntArrayElements(ia, ie, JNI_ABORT); + getGlobalJniEnv()->DeleteLocalRef(ia); } { savedFvalues = new float[sz]; - jfloatArray ia = (jfloatArray) globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues); - jfloat* ie = globalEnv()->GetFloatArrayElements(ia, NULL); + jfloatArray ia = (jfloatArray) getGlobalJniEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues); + jfloat* ie = getGlobalJniEnv()->GetFloatArrayElements(ia, NULL); for (int i = 0; i < sz; i++) { savedFvalues[requestProps.at(i)->id] = ie[i]; } - globalEnv()->ReleaseFloatArrayElements(ia, ie, JNI_ABORT); - globalEnv()->DeleteLocalRef(ia); + getGlobalJniEnv()->ReleaseFloatArrayElements(ia, ie, JNI_ABORT); + getGlobalJniEnv()->DeleteLocalRef(ia); } } extern "C" JNIEXPORT void JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_initRenderingRulesStorage(JNIEnv* ienv, jobject obj, jobject storage) { - setGlobalEnv(ienv); + setGlobalJniEnv(ienv); if (defaultStorage == NULL || defaultStorage->javaStorage != storage) { // multi thread will not work? if (defaultStorage != NULL) { @@ -291,7 +291,7 @@ extern "C" JNIEXPORT void JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar RenderingRuleSearchRequest::RenderingRuleSearchRequest(jobject rrs) : renderingRuleSearch(rrs) { - jobject storage = globalEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_storage); + jobject storage = getGlobalJniEnv()->GetObjectField(rrs, RenderingRuleSearchRequest_storage); if (defaultStorage == NULL || defaultStorage->javaStorage != storage) { // multi thread will not work? if (defaultStorage != NULL) { @@ -299,7 +299,7 @@ RenderingRuleSearchRequest::RenderingRuleSearchRequest(jobject rrs) : } defaultStorage = new RenderingRulesStorage(storage); } - globalEnv()->DeleteLocalRef(storage); + getGlobalJniEnv()->DeleteLocalRef(storage); this->storage = defaultStorage; PROPS = new RenderingRulesStorageProperties(this->storage); initObject(rrs); @@ -330,7 +330,7 @@ int RenderingRuleSearchRequest::getIntPropertyValue(RenderingRuleProperty* prop, std::string RenderingRuleSearchRequest::getStringPropertyValue(RenderingRuleProperty* prop) { if (prop == NULL) { - return EMPTY_STRING; + return std::string(); } int s = values[prop->id]; return storage->getDictionaryValue(s); @@ -486,59 +486,58 @@ RenderingRuleSearchRequest* initSearchRequest(jobject renderingRuleSearchRequest return new RenderingRuleSearchRequest(renderingRuleSearchRequest); } -void loadJNIRenderingRules() { - RenderingRuleClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRule")); - RenderingRule_properties = globalEnv()->GetFieldID(RenderingRuleClass, "properties", +void loadJniRenderingRules() { + RenderingRuleClass = findClass("net/osmand/render/RenderingRule"); + RenderingRule_properties = getGlobalJniEnv()->GetFieldID(RenderingRuleClass, "properties", "[Lnet/osmand/render/RenderingRuleProperty;"); - RenderingRule_intProperties = globalEnv()->GetFieldID(RenderingRuleClass, "intProperties", "[I"); - RenderingRule_floatProperties = globalEnv()->GetFieldID(RenderingRuleClass, "floatProperties", "[F"); - RenderingRule_ifElseChildren = globalEnv()->GetFieldID(RenderingRuleClass, "ifElseChildren", "Ljava/util/List;"); - RenderingRule_ifChildren = globalEnv()->GetFieldID(RenderingRuleClass, "ifChildren", "Ljava/util/List;"); + RenderingRule_intProperties = getGlobalJniEnv()->GetFieldID(RenderingRuleClass, "intProperties", "[I"); + RenderingRule_floatProperties = getGlobalJniEnv()->GetFieldID(RenderingRuleClass, "floatProperties", "[F"); + RenderingRule_ifElseChildren = getGlobalJniEnv()->GetFieldID(RenderingRuleClass, "ifElseChildren", "Ljava/util/List;"); + RenderingRule_ifChildren = getGlobalJniEnv()->GetFieldID(RenderingRuleClass, "ifChildren", "Ljava/util/List;"); - RenderingRuleStoragePropertiesClass = globalRef( - globalEnv()->FindClass("net/osmand/render/RenderingRuleStorageProperties")); - RenderingRuleStorageProperties_rules = globalEnv()->GetFieldID(RenderingRuleStoragePropertiesClass, "rules", + RenderingRuleStoragePropertiesClass = findClass("net/osmand/render/RenderingRuleStorageProperties"); + RenderingRuleStorageProperties_rules = getGlobalJniEnv()->GetFieldID(RenderingRuleStoragePropertiesClass, "rules", "Ljava/util/List;"); - RenderingRulePropertyClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRuleProperty")); - RenderingRuleProperty_type = globalEnv()->GetFieldID(RenderingRulePropertyClass, "type", "I"); - RenderingRuleProperty_input = globalEnv()->GetFieldID(RenderingRulePropertyClass, "input", "Z"); - RenderingRuleProperty_attrName = globalEnv()->GetFieldID(RenderingRulePropertyClass, "attrName", + RenderingRulePropertyClass = findClass("net/osmand/render/RenderingRuleProperty"); + RenderingRuleProperty_type = getGlobalJniEnv()->GetFieldID(RenderingRulePropertyClass, "type", "I"); + RenderingRuleProperty_input = getGlobalJniEnv()->GetFieldID(RenderingRulePropertyClass, "input", "Z"); + RenderingRuleProperty_attrName = getGlobalJniEnv()->GetFieldID(RenderingRulePropertyClass, "attrName", "Ljava/lang/String;"); - RenderingRulesStorageClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRulesStorage")); - RenderingRulesStorageClass_dictionary = globalEnv()->GetFieldID(RenderingRulesStorageClass, "dictionary", + RenderingRulesStorageClass = findClass("net/osmand/render/RenderingRulesStorage"); + RenderingRulesStorageClass_dictionary = getGlobalJniEnv()->GetFieldID(RenderingRulesStorageClass, "dictionary", "Ljava/util/List;"); - RenderingRulesStorage_PROPS = globalEnv()->GetFieldID(RenderingRulesStorageClass, "PROPS", + RenderingRulesStorage_PROPS = getGlobalJniEnv()->GetFieldID(RenderingRulesStorageClass, "PROPS", "Lnet/osmand/render/RenderingRuleStorageProperties;"); - RenderingRulesStorage_getRules = globalEnv()->GetMethodID(RenderingRulesStorageClass, "getRules", + RenderingRulesStorage_getRules = getGlobalJniEnv()->GetMethodID(RenderingRulesStorageClass, "getRules", "(I)[Lnet/osmand/render/RenderingRule;"); - ListClass = globalRef(globalEnv()->FindClass("java/util/List")); - List_size = globalEnv()->GetMethodID(ListClass, "size", "()I"); - List_get = globalEnv()->GetMethodID(ListClass, "get", "(I)Ljava/lang/Object;"); + ListClass = findClass("java/util/List"); + List_size = getGlobalJniEnv()->GetMethodID(ListClass, "size", "()I"); + List_get = getGlobalJniEnv()->GetMethodID(ListClass, "get", "(I)Ljava/lang/Object;"); - RenderingRuleSearchRequestClass = globalRef(globalEnv()->FindClass("net/osmand/render/RenderingRuleSearchRequest")); - RenderingRuleSearchRequest_storage = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "storage", + RenderingRuleSearchRequestClass = findClass("net/osmand/render/RenderingRuleSearchRequest"); + RenderingRuleSearchRequest_storage = getGlobalJniEnv()->GetFieldID(RenderingRuleSearchRequestClass, "storage", "Lnet/osmand/render/RenderingRulesStorage;"); - RenderingRuleSearchRequest_props = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "props", + RenderingRuleSearchRequest_props = getGlobalJniEnv()->GetFieldID(RenderingRuleSearchRequestClass, "props", "[Lnet/osmand/render/RenderingRuleProperty;"); - RenderingRuleSearchRequest_values = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "values", "[I"); - RenderingRuleSearchRequest_fvalues = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "fvalues", "[F"); - RenderingRuleSearchRequest_savedValues = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "savedValues", + RenderingRuleSearchRequest_values = getGlobalJniEnv()->GetFieldID(RenderingRuleSearchRequestClass, "values", "[I"); + RenderingRuleSearchRequest_fvalues = getGlobalJniEnv()->GetFieldID(RenderingRuleSearchRequestClass, "fvalues", "[F"); + RenderingRuleSearchRequest_savedValues = getGlobalJniEnv()->GetFieldID(RenderingRuleSearchRequestClass, "savedValues", "[I"); - RenderingRuleSearchRequest_savedFvalues = globalEnv()->GetFieldID(RenderingRuleSearchRequestClass, "savedFvalues", + RenderingRuleSearchRequest_savedFvalues = getGlobalJniEnv()->GetFieldID(RenderingRuleSearchRequestClass, "savedFvalues", "[F"); } void unloadJniRenderRules() { - globalEnv()->DeleteGlobalRef(RenderingRuleSearchRequestClass); - globalEnv()->DeleteGlobalRef(RenderingRuleClass); - globalEnv()->DeleteGlobalRef(RenderingRulePropertyClass); - globalEnv()->DeleteGlobalRef(RenderingRuleStoragePropertiesClass); - globalEnv()->DeleteGlobalRef(RenderingRulesStorageClass); - globalEnv()->DeleteGlobalRef(ListClass); + getGlobalJniEnv()->DeleteGlobalRef(RenderingRuleSearchRequestClass); + getGlobalJniEnv()->DeleteGlobalRef(RenderingRuleClass); + getGlobalJniEnv()->DeleteGlobalRef(RenderingRulePropertyClass); + getGlobalJniEnv()->DeleteGlobalRef(RenderingRuleStoragePropertiesClass); + getGlobalJniEnv()->DeleteGlobalRef(RenderingRulesStorageClass); + getGlobalJniEnv()->DeleteGlobalRef(ListClass); } diff --git a/OsmAnd/jni/osmand/rendering.cpp b/OsmAnd/jni/osmand/rendering.cpp index 7e021ca59f..cf1a987f4e 100644 --- a/OsmAnd/jni/osmand/rendering.cpp +++ b/OsmAnd/jni/osmand/rendering.cpp @@ -1,38 +1,36 @@ -#ifndef _OSMAND_RENDERING -#define _OSMAND_RENDERING - #include -#include #include #include + +#include #include #include #include #include #include -#include "SkTypes.h" -#include "SkBitmap.h" -#include "SkColorFilter.h" -#include "SkShader.h" -#include "SkBitmapProcShader.h" -#include "SkPathEffect.h" -#include "SkBlurDrawLooper.h" -#include "SkDashPathEffect.h" -#include "SkCanvas.h" -#include "SkPaint.h" -#include "SkPath.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "common.h" #include "renderRules.h" #include "textdraw.cpp" #include "mapObjects.h" -extern JNIEnv* globalEnv(); -char debugMessage[1024]; -jclass JUnidecodeClass; -jmethodID JUnidecode_unidecode; +jclass jclass_JUnidecode; +jmethodID jmethod_JUnidecode_unidecode; - void calcPoint(MapDataObject* mObj, jint ind, RenderingContext* rc) { +void calcPoint(MapDataObject* mObj, jint ind, RenderingContext* rc) +{ rc->pointCount++; float tx = mObj->points.at(ind).first/ (rc->tileDivisor); @@ -43,12 +41,12 @@ jmethodID JUnidecode_unidecode; rc->calcX = rc->cosRotateTileSize * dTileX - rc->sinRotateTileSize * dTileY; rc->calcY = rc->sinRotateTileSize * dTileX + rc->cosRotateTileSize * dTileY; - if (rc->calcX >= 0 && rc->calcX < rc->width && rc->calcY >= 0 && rc->calcY < rc->height) { + if (rc->calcX >= 0 && rc->calcX < rc->width && rc->calcY >= 0 && rc->calcY < rc->height) rc->pointInsideCount++; - } } - void calcMultipolygonPoint(int xt, int yt, jint ind, jint b, RenderingContext* rc) { +void calcMultipolygonPoint(int xt, int yt, jint ind, jint b, RenderingContext* rc) +{ rc->pointCount++; float tx = xt/ (rc->tileDivisor); float ty = yt / (rc->tileDivisor); @@ -58,16 +56,16 @@ jmethodID JUnidecode_unidecode; rc->calcX = rc->cosRotateTileSize * dTileX - rc->sinRotateTileSize * dTileY; rc->calcY = rc->sinRotateTileSize * dTileX + rc->cosRotateTileSize * dTileY; - if (rc->calcX >= 0 && rc->calcX < rc->width && rc->calcY >= 0 && rc->calcY < rc->height) { + if (rc->calcX >= 0 && rc->calcX < rc->width && rc->calcY >= 0 && rc->calcY < rc->height) rc->pointInsideCount++; - } } std::hash_map pathEffects; -SkPathEffect* getDashEffect(std::string input){ - if(pathEffects.find(input) != pathEffects.end()) { +SkPathEffect* getDashEffect(std::string input) +{ + if(pathEffects.find(input) != pathEffects.end()) return pathEffects[input]; - } + const char* chars = input.c_str(); int i = 0; char fval[10]; @@ -87,10 +85,15 @@ SkPathEffect* getDashEffect(std::string input){ if(chars[i] != '_') { // suppose it is a character - fval[flength++] = chars[i] ; - } else { - if(flength > 0) { fval[flength] = 0; - primFloats[floatLen++] = atof(fval); flength = 0;} + fval[flength++] = chars[i]; + } + else + { + if(flength > 0) + { + fval[flength] = 0; + primFloats[floatLen++] = atof(fval); flength = 0; + } } } } @@ -99,25 +102,28 @@ SkPathEffect* getDashEffect(std::string input){ return r; } - - - -int updatePaint(RenderingRuleSearchRequest* req, SkPaint* paint, int ind, int area, RenderingContext* rc) { +int updatePaint(RenderingRuleSearchRequest* req, SkPaint* paint, int ind, int area, RenderingContext* rc) +{ RenderingRuleProperty* rColor; RenderingRuleProperty* rStrokeW; RenderingRuleProperty* rCap; RenderingRuleProperty* rPathEff; - if (ind == 0) { + if (ind == 0) + { rColor = req->props()->R_COLOR; rStrokeW = req->props()->R_STROKE_WIDTH; rCap = req->props()->R_CAP; rPathEff = req->props()->R_PATH_EFFECT; - } else if (ind == 1) { + } + else if (ind == 1) + { rColor = req->props()->R_COLOR_2; rStrokeW = req->props()->R_STROKE_WIDTH_2; rCap = req->props()->R_CAP_2; rPathEff = req->props()->R_PATH_EFFECT_2; - } else { + } + else + { rColor = req->props()->R_COLOR_3; rStrokeW = req->props()->R_STROKE_WIDTH_3; rCap = req->props()->R_CAP_3; @@ -126,34 +132,38 @@ int updatePaint(RenderingRuleSearchRequest* req, SkPaint* paint, int ind, int ar paint->setColorFilter(NULL); paint->setShader(NULL); paint->setLooper(NULL); - if (area) { + if (area) + { paint->setStyle(SkPaint::kStrokeAndFill_Style); paint->setStrokeWidth(0); - } else { + } + else + { float stroke = req->getFloatPropertyValue(rStrokeW); - if (!(stroke > 0)) { + if (!(stroke > 0)) return 0; - } paint->setStyle(SkPaint::kStroke_Style); paint->setStrokeWidth(stroke); std::string cap = req->getStringPropertyValue(rCap); std::string pathEff = req->getStringPropertyValue(rPathEff); - if (cap == "BUTT" || cap == "") { + if (cap == "BUTT" || cap == "") paint->setStrokeCap(SkPaint::kButt_Cap); - } else if (cap == "ROUND") { + else if (cap == "ROUND") paint->setStrokeCap(SkPaint::kRound_Cap); - } else if (cap == "SQUARE") { + else if (cap == "SQUARE") paint->setStrokeCap(SkPaint::kSquare_Cap); - } else { + else paint->setStrokeCap(SkPaint::kButt_Cap); - } - if (pathEff.size() > 0) { + if (pathEff.size() > 0) + { SkPathEffect* p = getDashEffect(pathEff); paint->setPathEffect(p); - } else { + } + else + { paint->setPathEffect(NULL); } } @@ -161,62 +171,70 @@ int updatePaint(RenderingRuleSearchRequest* req, SkPaint* paint, int ind, int ar int color = req->getIntPropertyValue(rColor); paint->setColor(color); - - if (ind == 0) { + if (ind == 0) + { std::string shader = req->getStringPropertyValue(req->props()->R_SHADER); - if (shader.size() > 0) { + if (shader.size() > 0) + { SkBitmap* bmp = getCachedBitmap(rc, shader); - if (bmp != NULL) { + if (bmp != NULL) paint->setShader(new SkBitmapProcShader(*bmp, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode))->unref(); - } } } // do not check shadow color here - if (rc->shadowRenderingMode == 1 && ind == 0) { + if (rc->shadowRenderingMode == 1 && ind == 0) + { int shadowColor = req->getIntPropertyValue(req->props()->R_SHADOW_COLOR); int shadowLayer = req->getIntPropertyValue(req->props()->R_SHADOW_RADIUS); - if (shadowColor == 0) { + if (shadowColor == 0) shadowLayer = 0; - } - if (shadowLayer > 0) { + + if (shadowLayer > 0) paint->setLooper(new SkBlurDrawLooper(shadowLayer, 0, 0, shadowColor))->unref(); - } } return 1; } -void drawPointText(RenderingRuleSearchRequest* req, RenderingContext* rc, std::string tag, std::string value, - float xText, float yText, std::string name, SkPath* path) +void drawPointText(RenderingRuleSearchRequest* req, RenderingContext* rc, std::string tag, std::string value, float xText, float yText, std::string name, SkPath* path) { - if(rc->useEnglishNames){ - jstring n = globalEnv()->NewStringUTF(name.c_str()); - name = getString((jstring) globalEnv()->CallStaticObjectMethod(JUnidecodeClass, JUnidecode_unidecode, n)); - globalEnv()->DeleteLocalRef(n); + if(rc->useEnglishNames) + { + jstring n = getGlobalJniEnv()->NewStringUTF(name.c_str()); + name = getString((jstring) getGlobalJniEnv()->CallStaticObjectMethod(jclass_JUnidecode, jmethod_JUnidecode_unidecode, n)); + getGlobalJniEnv()->DeleteLocalRef(n); } - if (name.at(0) == REF_CHAR) { + + if (name.at(0) == REF_CHAR) + { std::string ref = name.substr(1); - name = ""; //$NON-NLS-1$ - for (uint k = 0; k < ref.length(); k++) { - if (ref.at(k) == REF_CHAR) { - if (k < ref.length() - 1) { + name = ""; + for (uint k = 0; k < ref.length(); k++) + { + if (ref.at(k) == REF_CHAR) + { + if (k < ref.length() - 1) + { name = ref.substr(k + 1); } ref = ref.substr(0, k); break; } } - if (ref.length() > 0) { + if (ref.length() > 0) + { req->setInitialTagValueZoom(tag, value, rc->zoom); req->setIntFilter(req->props()->R_TEXT_LENGTH, ref.length()); req->setBooleanFilter(req->props()->R_REF, true); - if (req->searchRule(RenderingRulesStorage::TEXT_RULES)) { - if (req->getIntPropertyValue(req->props()->R_TEXT_SIZE) > 0) { + if (req->searchRule(RenderingRulesStorage::TEXT_RULES)) + { + if (req->getIntPropertyValue(req->props()->R_TEXT_SIZE) > 0) + { TextDrawInfo* text = new TextDrawInfo(ref); fillTextProperties(text, req, xText, yText); - if (path != NULL) { + if (path != NULL) text->path = new SkPath(*path); - } + rc->textToDraw.push_back(text); } } @@ -227,37 +245,37 @@ void drawPointText(RenderingRuleSearchRequest* req, RenderingContext* rc, std::s req->setIntFilter(req->props()->R_TEXT_LENGTH, name.length()); req->setBooleanFilter(req->props()->R_REF, false); if (req->searchRule(RenderingRulesStorage::TEXT_RULES) && - req->getIntPropertyValue(req->props()->R_TEXT_SIZE) > 0) { - TextDrawInfo* info = new TextDrawInfo(name); - info->drawOnPath = (path != NULL) && (req->getIntPropertyValue(req->props()->R_TEXT_ON_PATH, 0) > 0); - if (path != NULL) { - info->path = new SkPath(*path); - } - fillTextProperties(info, req, xText, yText); - rc->textToDraw.push_back(info); + req->getIntPropertyValue(req->props()->R_TEXT_SIZE) > 0) + { + TextDrawInfo* info = new TextDrawInfo(name); + info->drawOnPath = (path != NULL) && (req->getIntPropertyValue(req->props()->R_TEXT_ON_PATH, 0) > 0); + if (path != NULL) + info->path = new SkPath(*path); + + fillTextProperties(info, req, xText, yText); + rc->textToDraw.push_back(info); } } +void drawPolylineShadow(SkCanvas* cv, SkPaint* paint, RenderingContext* rc, SkPath* path, int shadowColor, int shadowRadius) +{ + // blurred shadows + if (rc->shadowRenderingMode == 2 && shadowRadius > 0) { + // simply draw shadow? difference from option 3 ? + // paint->setColor(0xffffffff); + paint->setLooper(new SkBlurDrawLooper(shadowRadius, 0, 0, shadowColor))->unref(); + PROFILE_NATIVE_OPERATION(rc, cv->drawPath(*path, *paint)); + } -void drawPolylineShadow(SkCanvas* cv, SkPaint* paint, RenderingContext* rc, SkPath* path, int shadowColor, - int shadowRadius) { - // blurred shadows - if (rc->shadowRenderingMode == 2 && shadowRadius > 0) { - // simply draw shadow? difference from option 3 ? - // paint->setColor(0xffffffff); - paint->setLooper(new SkBlurDrawLooper(shadowRadius, 0, 0, shadowColor))->unref(); - NAT_COUNT(rc, cv->drawPath(*path, *paint)); - } - - // option shadow = 3 with solid border - if (rc->shadowRenderingMode == 3 && shadowRadius > 0) { - paint->setLooper(NULL); - paint->setStrokeWidth(paint->getStrokeWidth() + shadowRadius * 2); -// paint->setColor(0xffbababa); - paint->setColorFilter(SkColorFilter::CreateModeFilter(shadowColor, SkXfermode::kSrcIn_Mode))->unref(); -// paint->setColor(shadowColor); - NAT_COUNT(rc, cv->drawPath(*path, *paint)); - } + // option shadow = 3 with solid border + if (rc->shadowRenderingMode == 3 && shadowRadius > 0) { + paint->setLooper(NULL); + paint->setStrokeWidth(paint->getStrokeWidth() + shadowRadius * 2); + // paint->setColor(0xffbababa); + paint->setColorFilter(SkColorFilter::CreateModeFilter(shadowColor, SkXfermode::kSrcIn_Mode))->unref(); + // paint->setColor(shadowColor); + PROFILE_NATIVE_OPERATION(rc, cv->drawPath(*path, *paint)); + } } std::vector oneWayPaints; @@ -297,7 +315,7 @@ void drawOneWayPaints(RenderingContext* rc, SkCanvas* cv, SkPath* p) { } for (size_t i = 0; i < oneWayPaints.size(); i++) { - NAT_COUNT(rc, cv->drawPath(*p, oneWayPaints.at(i))); + PROFILE_NATIVE_OPERATION(rc, cv->drawPath(*p, oneWayPaints.at(i))); } } @@ -310,163 +328,163 @@ bool isRoundabout(int highwayAttributes) { } void drawPolyline(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* cv, SkPaint* paint, - RenderingContext* rc, std::pair pair, int layer, int drawOnlyShadow) { - jint length = mObj->points.size(); - if (length < 2) { - return; - } - std::string tag = pair.first; - std::string value = pair.second; - - req->setInitialTagValueZoom(tag, value, rc->zoom); - req->setIntFilter(req->props()->R_LAYER, layer); - bool oneway = false; - if (rc->zoom >= 16 && "highway" == pair.first && isOneWayWay(mObj->highwayAttributes)) { - oneway = true; - } - - bool rendered = req->searchRule(2); - if (!rendered || !updatePaint(req, paint, 0, 0, rc)) { - return; - } - - rc->visible++; - SkPath path; - int i = 0; - SkPoint middlePoint; - int middle = length / 2; - for (; i < length; i++) { - calcPoint(mObj, i, rc); - if (i == 0) { - path.moveTo(rc->calcX, rc->calcY); - } else { - if(i == middle){ - middlePoint.set(rc->calcX, rc->calcY); - } - path.lineTo(rc->calcX, rc->calcY); + RenderingContext* rc, std::pair pair, int layer, int drawOnlyShadow) { + jint length = mObj->points.size(); + if (length < 2) { + return; } - } - if (i > 0) { - if (drawOnlyShadow) { - int shadowColor = req->getIntPropertyValue(req->props()->R_SHADOW_COLOR); - int shadowRadius = req->getIntPropertyValue(req->props()->R_SHADOW_RADIUS); - drawPolylineShadow(cv, paint, rc, &path, shadowColor, shadowRadius); - } else { - NAT_COUNT(rc, cv->drawPath(path, *paint)); - if (updatePaint(req, paint, 1, 0, rc)) { - NAT_COUNT(rc, cv->drawPath(path, *paint)); - if (updatePaint(req, paint, 2, 0, rc)) { - NAT_COUNT(rc, cv->drawPath(path, *paint)); - } - } - if (oneway && !drawOnlyShadow) { - drawOneWayPaints(rc, cv, &path); - } - if (!drawOnlyShadow && mObj->name.length() > 0) { - drawPointText(req, rc,pair.first, pair.second, middlePoint.fX, middlePoint.fY, mObj->name, - &path); - } + std::string tag = pair.first; + std::string value = pair.second; + + req->setInitialTagValueZoom(tag, value, rc->zoom); + req->setIntFilter(req->props()->R_LAYER, layer); + bool oneway = false; + if (rc->zoom >= 16 && "highway" == pair.first && isOneWayWay(mObj->highwayAttributes)) { + oneway = true; } - } -} -void drawMultiPolygon(MultiPolygonObject* mapObject,RenderingRuleSearchRequest* req, SkCanvas* cv, SkPaint* paint, - RenderingContext* rc) { - if (req == NULL) { - return; - } - req->setInitialTagValueZoom(mapObject->tag, mapObject->value, rc->zoom); - bool rendered = req->searchRule(3); + bool rendered = req->searchRule(2); + if (!rendered || !updatePaint(req, paint, 0, 0, rc)) { + return; + } - if (!rendered || !updatePaint(req, paint, 0, 1, rc)) { - return; - } - - int boundsCount = mapObject->points.size(); - rc->visible++; - SkPath path; - - for (int i = 0; i < boundsCount; i++) { - int cnt = mapObject->points.at(i).size(); - float xText = 0; - float yText = 0; - for (int j = 0; j < cnt; j++) { - std::pair pair = mapObject->points.at(i).at(j); - calcMultipolygonPoint(pair.first, pair.second, j, i, rc); - xText += rc->calcX; - yText += rc->calcY; - if (j == 0) { + rc->visible++; + SkPath path; + int i = 0; + SkPoint middlePoint; + int middle = length / 2; + for (; i < length; i++) { + calcPoint(mObj, i, rc); + if (i == 0) { path.moveTo(rc->calcX, rc->calcY); } else { + if(i == middle){ + middlePoint.set(rc->calcX, rc->calcY); + } path.lineTo(rc->calcX, rc->calcY); } } - if (cnt > 0) { - std::string name = mapObject->names.at(i); - if (name.length() > 0) { - drawPointText(req, rc, mapObject->tag, mapObject->value, xText / cnt, yText / cnt, name, NULL); + if (i > 0) { + if (drawOnlyShadow) { + int shadowColor = req->getIntPropertyValue(req->props()->R_SHADOW_COLOR); + int shadowRadius = req->getIntPropertyValue(req->props()->R_SHADOW_RADIUS); + drawPolylineShadow(cv, paint, rc, &path, shadowColor, shadowRadius); + } else { + PROFILE_NATIVE_OPERATION(rc, cv->drawPath(path, *paint)); + if (updatePaint(req, paint, 1, 0, rc)) { + PROFILE_NATIVE_OPERATION(rc, cv->drawPath(path, *paint)); + if (updatePaint(req, paint, 2, 0, rc)) { + PROFILE_NATIVE_OPERATION(rc, cv->drawPath(path, *paint)); + } + } + if (oneway && !drawOnlyShadow) { + drawOneWayPaints(rc, cv, &path); + } + if (!drawOnlyShadow && mObj->name.length() > 0) { + drawPointText(req, rc,pair.first, pair.second, middlePoint.fX, middlePoint.fY, mObj->name, + &path); + } } } - } +} - NAT_COUNT(rc, cv->drawPath(path, *paint)); - // for test purpose -// paint->setStyle(SkPaint::kStroke_Style); -// paint->setStrokeWidth(2); -// paint->setPathEffect(NULL); -// paint->setColor(BLACK_COLOR); -// NAT_COUNT(rc, cv->drawPath(path, *paint)); - if (updatePaint(req, paint, 1, 0, rc)) { - NAT_COUNT(rc, cv->drawPath(path, *paint)); - } +void drawMultiPolygon(MultiPolygonObject* mapObject,RenderingRuleSearchRequest* req, SkCanvas* cv, SkPaint* paint, + RenderingContext* rc) { + if (req == NULL) { + return; + } + req->setInitialTagValueZoom(mapObject->tag, mapObject->value, rc->zoom); + bool rendered = req->searchRule(3); + + if (!rendered || !updatePaint(req, paint, 0, 1, rc)) { + return; + } + + int boundsCount = mapObject->points.size(); + rc->visible++; + SkPath path; + + for (int i = 0; i < boundsCount; i++) { + int cnt = mapObject->points.at(i).size(); + float xText = 0; + float yText = 0; + for (int j = 0; j < cnt; j++) { + std::pair pair = mapObject->points.at(i).at(j); + calcMultipolygonPoint(pair.first, pair.second, j, i, rc); + xText += rc->calcX; + yText += rc->calcY; + if (j == 0) { + path.moveTo(rc->calcX, rc->calcY); + } else { + path.lineTo(rc->calcX, rc->calcY); + } + } + if (cnt > 0) { + std::string name = mapObject->names.at(i); + if (name.length() > 0) { + drawPointText(req, rc, mapObject->tag, mapObject->value, xText / cnt, yText / cnt, name, NULL); + } + } + } + + PROFILE_NATIVE_OPERATION(rc, cv->drawPath(path, *paint)); + // for test purpose + // paint->setStyle(SkPaint::kStroke_Style); + // paint->setStrokeWidth(2); + // paint->setPathEffect(NULL); + // paint->setColor(BLACK_COLOR); + // PROFILE_NATIVE_OPERATION(rc, cv->drawPath(path, *paint)); + if (updatePaint(req, paint, 1, 0, rc)) { + PROFILE_NATIVE_OPERATION(rc, cv->drawPath(path, *paint)); + } } void drawPolygon(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* cv, SkPaint* paint, - RenderingContext* rc, std::pair pair) { - jint length = mObj->points.size(); - if (length <= 2) { - return; - } - std::string tag = pair.first; - std::string value = pair.second; - - req->setInitialTagValueZoom(tag, value, rc->zoom); - bool rendered = req->searchRule(3); - - float xText = 0; - float yText = 0; - if (!rendered || !updatePaint(req, paint, 0, 1, rc)) { - return; - } - - rc->visible++; - SkPath path; - int i = 0; - for (; i < length; i++) { - calcPoint(mObj, i, rc); - if (i == 0) { - path.moveTo(rc->calcX, rc->calcY); - } else { - path.lineTo(rc->calcX, rc->calcY); + RenderingContext* rc, std::pair pair) { + jint length = mObj->points.size(); + if (length <= 2) { + return; } - xText += rc->calcX; - yText += rc->calcY; - } + std::string tag = pair.first; + std::string value = pair.second; - NAT_COUNT(rc, cv->drawPath(path, *paint)); - if (updatePaint(req, paint, 1, 0, rc)) { - NAT_COUNT(rc, cv->drawPath(path, *paint)); - } - std::string name = mObj->name; - if (name.length() > 0) { - drawPointText(req, rc, tag, value, xText / length, yText / length, name, NULL); - } + req->setInitialTagValueZoom(tag, value, rc->zoom); + bool rendered = req->searchRule(3); + + float xText = 0; + float yText = 0; + if (!rendered || !updatePaint(req, paint, 0, 1, rc)) { + return; + } + + rc->visible++; + SkPath path; + int i = 0; + for (; i < length; i++) { + calcPoint(mObj, i, rc); + if (i == 0) { + path.moveTo(rc->calcX, rc->calcY); + } else { + path.lineTo(rc->calcX, rc->calcY); + } + xText += rc->calcX; + yText += rc->calcY; + } + + PROFILE_NATIVE_OPERATION(rc, cv->drawPath(path, *paint)); + if (updatePaint(req, paint, 1, 0, rc)) { + PROFILE_NATIVE_OPERATION(rc, cv->drawPath(path, *paint)); + } + std::string name = mObj->name; + if (name.length() > 0) { + drawPointText(req, rc, tag, value, xText / length, yText / length, name, NULL); + } } void drawPoint(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* cv, SkPaint* paint, - RenderingContext* rc, std::pair pair, int renderText) - { + RenderingContext* rc, std::pair pair, int renderText) +{ std::string tag = pair.first; std::string value = pair.second; @@ -474,7 +492,7 @@ void drawPoint(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* c req->searchRule(1); std::string resId = req->getStringPropertyValue(req-> props()-> R_ICON); SkBitmap* bmp = getCachedBitmap(rc, resId); - std::string name = EMPTY_STRING; + std::string name; if (renderText) { name = mObj->name; } @@ -512,32 +530,32 @@ void drawPoint(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* c } void drawObject(RenderingContext* rc, BaseMapDataObject* mapObject, SkCanvas* cv, RenderingRuleSearchRequest* req, - SkPaint* paint, int l, int renderText, int drawOnlyShadow) { - rc->allObjects++; - if (mapObject-> type == BaseMapDataObject::MULTI_POLYGON) { - if (!drawOnlyShadow) { - drawMultiPolygon((MultiPolygonObject*) mapObject, req, cv, paint, rc); + SkPaint* paint, int l, int renderText, int drawOnlyShadow) { + rc->allObjects++; + if (mapObject-> type == BaseMapDataObject::MULTI_POLYGON) { + if (!drawOnlyShadow) { + drawMultiPolygon((MultiPolygonObject*) mapObject, req, cv, paint, rc); + } + return; } - return; - } - MapDataObject* mObj = (MapDataObject*) mapObject; + MapDataObject* mObj = (MapDataObject*) mapObject; - jint mainType = mObj->types.at(l); - int t = mainType & 3; + jint mainType = mObj->types.at(l); + int t = mainType & 3; - std::pair pair = mObj->tagValues.at(l); - if (t == 1 && !drawOnlyShadow) { - // point - drawPoint(mObj, req, cv, paint, rc, pair, renderText); - } else if (t == 2) { - // polyline - int layer = getNegativeWayLayer(mainType); -// __android_log_print(ANDROID_LOG_WARN, "net.osmand", "Draw polyline"); - drawPolyline(mObj, req, cv, paint, rc, pair, layer, drawOnlyShadow); - } else if (t == 3 && !drawOnlyShadow) { - // polygon - drawPolygon(mObj, req, cv, paint, rc, pair); - } + std::pair pair = mObj->tagValues.at(l); + if (t == 1 && !drawOnlyShadow) { + // point + drawPoint(mObj, req, cv, paint, rc, pair, renderText); + } else if (t == 2) { + // polyline + int layer = getNegativeWayLayer(mainType); + // __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Draw polyline"); + drawPolyline(mObj, req, cv, paint, rc, pair, layer, drawOnlyShadow); + } else if (t == 3 && !drawOnlyShadow) { + // polygon + drawPolygon(mObj, req, cv, paint, rc, pair); + } } @@ -556,20 +574,20 @@ void drawIconsOverCanvas(RenderingContext* rc, SkCanvas* canvas) { IconDrawInfo icon = rc->iconsToDraw.at(ji); if (icon.y >= 0 && icon.y < rc -> height && icon.x >= 0 && icon.x < rc -> width && - icon.bmp != NULL) { - int z = (((int) icon.x / skewConstant) + ((int) icon.y / skewConstant) * iconsW); - int i = z / 32; - if (i >= len) { - continue; - } - int ind = alreadyDrawnIcons[i]; - int b = z % 32; - // check bit b if it is set - if (((ind >> b) & 1) == 0) { - alreadyDrawnIcons[i] = ind | (1 << b); - SkBitmap* ico = icon.bmp; - NAT_COUNT(rc, canvas->drawBitmap(*ico, icon.x - ico->width() / 2, icon.y - ico->height() / 2, &p)); - } + icon.bmp != NULL) { + int z = (((int) icon.x / skewConstant) + ((int) icon.y / skewConstant) * iconsW); + int i = z / 32; + if (i >= len) { + continue; + } + int ind = alreadyDrawnIcons[i]; + int b = z % 32; + // check bit b if it is set + if (((ind >> b) & 1) == 0) { + alreadyDrawnIcons[i] = ind | (1 << b); + SkBitmap* ico = icon.bmp; + PROFILE_NATIVE_OPERATION(rc, canvas->drawBitmap(*ico, icon.x - ico->width() / 2, icon.y - ico->height() / 2, &p)); + } } if(rc->interrupted()){ return; @@ -578,331 +596,296 @@ void drawIconsOverCanvas(RenderingContext* rc, SkCanvas* canvas) } std::hash_map > sortObjectsByProperOrder(std::vector mapDataObjects, - RenderingRuleSearchRequest* req, RenderingContext* rc) { - std::hash_map > orderMap; - if (req != NULL) { - req->clearState(); - const size_t size = mapDataObjects.size(); - size_t i = 0; - for (; i < size; i++) { - uint sh = i << 8; - BaseMapDataObject* obj = mapDataObjects.at(i); - if (obj->type == BaseMapDataObject::MULTI_POLYGON) { - MultiPolygonObject* mobj = (MultiPolygonObject*) obj; + RenderingRuleSearchRequest* req, RenderingContext* rc) { + std::hash_map > orderMap; + if (req != NULL) { + req->clearState(); + const size_t size = mapDataObjects.size(); + size_t i = 0; + for (; i < size; i++) { + uint sh = i << 8; + BaseMapDataObject* obj = mapDataObjects.at(i); + if (obj->type == BaseMapDataObject::MULTI_POLYGON) { + MultiPolygonObject* mobj = (MultiPolygonObject*) obj; - req->setTagValueZoomLayer(mobj->tag, mobj->value, rc->zoom, mobj->layer); - req->setIntFilter(req->props()->R_ORDER_TYPE, RenderingRulesStorage::POLYGON_RULES); - if (req->searchRule(RenderingRulesStorage::ORDER_RULES)) { - int order = req->getIntPropertyValue(req->props()->R_ORDER); - orderMap[order].push_back(sh); - if (req->getIntPropertyValue(req->props()->R_SHADOW_LEVEL) > 0) { - rc->shadowLevelMin = std::min(rc->shadowLevelMin, order); - rc->shadowLevelMax = std::max(rc->shadowLevelMax, order); - req->clearIntvalue(req->props()->R_SHADOW_LEVEL); - } - } - } else { - MapDataObject* mobj = (MapDataObject*) obj; - size_t sizeTypes = mobj->types.size(); - size_t j = 0; - for (; j < sizeTypes; j++) { - int wholeType = mobj->types.at(j); - int mask = wholeType & 3; - int layer = 0; - if (mask != 1) { - layer = getNegativeWayLayer(wholeType); - } - std::pair pair = mobj->tagValues.at(j); - req->setTagValueZoomLayer(pair.first, pair.second, rc->zoom, layer); - req->setIntFilter(req->props()->R_ORDER_TYPE, mask); + req->setTagValueZoomLayer(mobj->tag, mobj->value, rc->zoom, mobj->layer); + req->setIntFilter(req->props()->R_ORDER_TYPE, RenderingRulesStorage::POLYGON_RULES); if (req->searchRule(RenderingRulesStorage::ORDER_RULES)) { int order = req->getIntPropertyValue(req->props()->R_ORDER); - orderMap[order].push_back(sh + j); + orderMap[order].push_back(sh); if (req->getIntPropertyValue(req->props()->R_SHADOW_LEVEL) > 0) { rc->shadowLevelMin = std::min(rc->shadowLevelMin, order); rc->shadowLevelMax = std::max(rc->shadowLevelMax, order); req->clearIntvalue(req->props()->R_SHADOW_LEVEL); } } - } + } else { + MapDataObject* mobj = (MapDataObject*) obj; + size_t sizeTypes = mobj->types.size(); + size_t j = 0; + for (; j < sizeTypes; j++) { + int wholeType = mobj->types.at(j); + int mask = wholeType & 3; + int layer = 0; + if (mask != 1) { + layer = getNegativeWayLayer(wholeType); + } + std::pair pair = mobj->tagValues.at(j); + req->setTagValueZoomLayer(pair.first, pair.second, rc->zoom, layer); + req->setIntFilter(req->props()->R_ORDER_TYPE, mask); + if (req->searchRule(RenderingRulesStorage::ORDER_RULES)) { + int order = req->getIntPropertyValue(req->props()->R_ORDER); + orderMap[order].push_back(sh + j); + if (req->getIntPropertyValue(req->props()->R_SHADOW_LEVEL) > 0) { + rc->shadowLevelMin = std::min(rc->shadowLevelMin, order); + rc->shadowLevelMax = std::max(rc->shadowLevelMax, order); + req->clearIntvalue(req->props()->R_SHADOW_LEVEL); + } + } + } + } } } - } - return orderMap; + return orderMap; } void doRendering(std::vector mapDataObjects, SkCanvas* canvas, SkPaint* paint, - RenderingRuleSearchRequest* req, RenderingContext* rc) { - // put in order map - std::hash_map > orderMap = sortObjectsByProperOrder(mapDataObjects, req, rc); - std::set keys; - std::hash_map >::iterator it = orderMap.begin(); - while(it != orderMap.end()) - { - keys.insert(it->first); - it++; - } - bool shadowDrawn = false; + RenderingRuleSearchRequest* req, RenderingContext* rc) { + // put in order map + std::hash_map > orderMap = sortObjectsByProperOrder(mapDataObjects, req, rc); + std::set keys; + std::hash_map >::iterator it = orderMap.begin(); + while(it != orderMap.end()) + { + keys.insert(it->first); + it++; + } + bool shadowDrawn = false; - for (std::set::iterator ks = keys.begin(); ks != keys.end() ; ks++) { - if (!shadowDrawn && *ks >= rc->shadowLevelMin && *ks <= rc->shadowLevelMax && + for (std::set::iterator ks = keys.begin(); ks != keys.end() ; ks++) { + if (!shadowDrawn && *ks >= rc->shadowLevelMin && *ks <= rc->shadowLevelMax && rc->shadowRenderingMode > 1) { - for (std::set::iterator ki = ks; ki != keys.end() ; ki++) { - if (*ki > rc->shadowLevelMax || rc->interrupted()) { - break; - } - std::vector list = orderMap[*ki]; - for (std::vector::iterator ls = list.begin(); ls != list.end(); ls++) { - int i = *ls; - int ind = i >> 8; - int l = i & 0xff; - BaseMapDataObject* mapObject = mapDataObjects.at(ind); + for (std::set::iterator ki = ks; ki != keys.end() ; ki++) { + if (*ki > rc->shadowLevelMax || rc->interrupted()) { + break; + } + std::vector list = orderMap[*ki]; + for (std::vector::iterator ls = list.begin(); ls != list.end(); ls++) { + int i = *ls; + int ind = i >> 8; + int l = i & 0xff; + BaseMapDataObject* mapObject = mapDataObjects.at(ind); - // show text only for main type - drawObject(rc, mapObject, canvas, req, paint, l, l == 0, true); - } + // show text only for main type + drawObject(rc, mapObject, canvas, req, paint, l, l == 0, true); + } + } + shadowDrawn = true; } - shadowDrawn = true; + + std::vector list = orderMap[*ks]; + for (std::vector::iterator ls = list.begin(); ls != list.end(); ls++) { + int i = *ls; + int ind = i >> 8; + int l = i & 0xff; + + BaseMapDataObject* mapObject = mapDataObjects.at(ind); + // show text only for main type + drawObject(rc, mapObject, canvas, req, paint, l, l == 0, false); + } + rc->lastRenderedKey = *ks; + if (rc->interrupted()) { + return; + } + } - std::vector list = orderMap[*ks]; - for (std::vector::iterator ls = list.begin(); ls != list.end(); ls++) { - int i = *ls; - int ind = i >> 8; - int l = i & 0xff; + drawIconsOverCanvas(rc, canvas); - BaseMapDataObject* mapObject = mapDataObjects.at(ind); - // show text only for main type - drawObject(rc, mapObject, canvas, req, paint, l, l == 0, false); - } - rc->lastRenderedKey = *ks; - if (rc->interrupted()) { - return; - } - - } - - drawIconsOverCanvas(rc, canvas); - - rc->textRendering.start(); - drawTextOverCanvas(rc, canvas); - rc->textRendering.pause(); + rc->textRendering.start(); + drawTextOverCanvas(rc, canvas); + rc->textRendering.pause(); } -void loadJNIRendering(){ - JUnidecodeClass = globalRef(globalEnv()->FindClass("net/sf/junidecode/Junidecode")); - JUnidecode_unidecode = globalEnv()->GetStaticMethodID(JUnidecodeClass, "unidecode", "(Ljava/lang/String;)Ljava/lang/String;"); +void loadJniRendering() +{ + jclass_JUnidecode = findClass("net/sf/junidecode/Junidecode"); + jmethod_JUnidecode_unidecode = getGlobalJniEnv()->GetStaticMethodID(jclass_JUnidecode, "unidecode", "(Ljava/lang/String;)Ljava/lang/String;"); } -#ifdef __cplusplus -extern "C" { -#endif +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) { + setGlobalJniEnv(ienv); -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) { - setGlobalEnv(ienv); - - // Gain information about bitmap - AndroidBitmapInfo bitmapInfo; - if(AndroidBitmap_getInfo(ienv, targetBitmap, &bitmapInfo) != ANDROID_BITMAP_RESUT_SUCCESS) { - __android_log_print(ANDROID_LOG_ERROR, "net.osmand", "Failed to execute AndroidBitmap_getInfo"); - } - - sprintf(debugMessage, "Creating SkBitmap in native w:%d h:%d s:%d f:%d!", bitmapInfo.width, bitmapInfo.height, bitmapInfo.stride, bitmapInfo.format); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); - - SkBitmap* bitmap = new SkBitmap(); - if(bitmapInfo.format == ANDROID_BITMAP_FORMAT_RGBA_8888) { - int rowBytes = bitmapInfo.stride; - sprintf(debugMessage, "Row bytes for RGBA_8888 is %d", rowBytes); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); - bitmap->setConfig(SkBitmap::kARGB_8888_Config, bitmapInfo.width, bitmapInfo.height, rowBytes); - } else if(bitmapInfo.format == ANDROID_BITMAP_FORMAT_RGB_565) { - int rowBytes = bitmapInfo.stride; - sprintf(debugMessage, "Row bytes for RGB_565 is %d", rowBytes); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); - bitmap->setConfig(SkBitmap::kRGB_565_Config, bitmapInfo.width, bitmapInfo.height, rowBytes); - } else { - __android_log_print(ANDROID_LOG_ERROR, "net.osmand", "Unknown target bitmap format"); - } - - void* lockedBitmapData = NULL; - if(AndroidBitmap_lockPixels(ienv, targetBitmap, &lockedBitmapData) != ANDROID_BITMAP_RESUT_SUCCESS || !lockedBitmapData) { - __android_log_print(ANDROID_LOG_ERROR, "net.osmand", "Failed to execute AndroidBitmap_lockPixels"); - } - sprintf(debugMessage, "Locked %d bytes at %p", bitmap->getSize(), lockedBitmapData); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); - - bitmap->setPixels(lockedBitmapData); - - SkCanvas* canvas = new SkCanvas(*bitmap); - canvas->drawColor(defaultColor); + // Gain information about bitmap + AndroidBitmapInfo bitmapInfo; + if(AndroidBitmap_getInfo(getGlobalJniEnv(), targetBitmap, &bitmapInfo) != ANDROID_BITMAP_RESUT_SUCCESS) + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to execute AndroidBitmap_getInfo"); - SkPaint* paint = new SkPaint; - paint->setAntiAlias(true); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", "Initializing rendering"); - watcher initObjects; - initObjects.start(); + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Creating SkBitmap in native w:%d h:%d s:%d f:%d!", bitmapInfo.width, bitmapInfo.height, bitmapInfo.stride, bitmapInfo.format); - RenderingRuleSearchRequest* req = initSearchRequest(renderingRuleSearchRequest); - RenderingContext rc; - copyRenderingContext(renderingContext, &rc); - rc.useEnglishNames = useEnglishNames; - SearchResult* result = ((SearchResult*) searchResult); -// std::vector mapDataObjects = marshalObjects(binaryMapDataObjects); + SkBitmap* bitmap = new SkBitmap(); + if(bitmapInfo.format == ANDROID_BITMAP_FORMAT_RGBA_8888) { + int rowBytes = bitmapInfo.stride; + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Row bytes for RGBA_8888 is %d", rowBytes); + bitmap->setConfig(SkBitmap::kARGB_8888_Config, bitmapInfo.width, bitmapInfo.height, rowBytes); + } else if(bitmapInfo.format == ANDROID_BITMAP_FORMAT_RGB_565) { + int rowBytes = bitmapInfo.stride; + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Row bytes for RGB_565 is %d", rowBytes); + bitmap->setConfig(SkBitmap::kRGB_565_Config, bitmapInfo.width, bitmapInfo.height, rowBytes); + } else { + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Unknown target bitmap format"); + } - __android_log_print(ANDROID_LOG_WARN, "net.osmand", "Rendering image"); - initObjects.pause(); - + void* lockedBitmapData = NULL; + if(AndroidBitmap_lockPixels(getGlobalJniEnv(), targetBitmap, &lockedBitmapData) != ANDROID_BITMAP_RESUT_SUCCESS || !lockedBitmapData) { + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to execute AndroidBitmap_lockPixels"); + } + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Locked %d bytes at %p", bitmap->getSize(), lockedBitmapData); - // Main part do rendering - rc.nativeOperations.start(); - if(result != NULL) { - doRendering(result->result, canvas, paint, req, &rc); - } - rc.nativeOperations.pause(); + bitmap->setPixels(lockedBitmapData); - mergeRenderingContext(renderingContext, &rc); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", "End Rendering image"); - if(AndroidBitmap_unlockPixels(ienv, targetBitmap) != ANDROID_BITMAP_RESUT_SUCCESS) { - __android_log_print(ANDROID_LOG_ERROR, "net.osmand", "Failed to execute AndroidBitmap_unlockPixels"); - } - - // delete variables - delete paint; - delete canvas; - delete req; - delete bitmap; -// deleteObjects(mapDataObjects); + SkCanvas* canvas = new SkCanvas(*bitmap); + canvas->drawColor(defaultColor); - jclass resultClass = ienv->FindClass("net/osmand/plus/render/NativeOsmandLibrary$RenderingGenerationResult"); - if(!resultClass) - resultClass = ienv->FindClass("net/osmand/render/NativeOsmandLibrary$RenderingGenerationResult"); - sprintf(debugMessage, "Result class = %p", resultClass); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); - - jmethodID resultClassCtorId = ienv->GetMethodID(resultClass, "", "(Ljava/nio/ByteBuffer;Ljava/lang/String;)V"); - - sprintf(debugMessage, "Result class ctor = %p", resultClassCtorId); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); + SkPaint* paint = new SkPaint; + paint->setAntiAlias(true); + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Initializing rendering"); + ElapsedTimer initObjects; + initObjects.start(); + + RenderingRuleSearchRequest* req = initSearchRequest(renderingRuleSearchRequest); + RenderingContext rc; + pullFromJavaRenderingContext(renderingContext, &rc); + rc.useEnglishNames = useEnglishNames; + SearchResult* result = ((SearchResult*) searchResult); + // std::vector mapDataObjects = marshalObjects(binaryMapDataObjects); + + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Rendering image"); + initObjects.pause(); + + + // Main part do rendering + rc.nativeOperations.start(); + if(result != NULL) { + doRendering(result->result, canvas, paint, req, &rc); + } + rc.nativeOperations.pause(); + + pushToJavaRenderingContext(renderingContext, &rc); + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "End Rendering image"); + if(AndroidBitmap_unlockPixels(ienv, targetBitmap) != ANDROID_BITMAP_RESUT_SUCCESS) { + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to execute AndroidBitmap_unlockPixels"); + } + + // delete variables + delete paint; + delete canvas; + delete req; + delete bitmap; + // deleteObjects(mapDataObjects); + + jclass resultClass = findClass("net/osmand/plus/render/NativeOsmandLibrary$RenderingGenerationResult"); + + jmethodID resultClassCtorId = getGlobalJniEnv()->GetMethodID(resultClass, "", "(Ljava/nio/ByteBuffer;)V"); #ifdef DEBUG_NAT_OPERATIONS - sprintf(debugMessage, "Native ok (init %d, native op %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime()); + __android_log_print(ANDROID_LOG_WARN, LOG_TAG,"Native ok (init %d, native op %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime()); #else - sprintf(debugMessage, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime()); + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime()); #endif - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); - // Allocate ctor paramters - jstring message = globalEnv()->NewStringUTF(debugMessage); - - /* Construct a result object */ - jobject resultObject = ienv->NewObject(resultClass, resultClassCtorId, NULL, message); + /* Construct a result object */ + jobject resultObject = getGlobalJniEnv()->NewObject(resultClass, resultClassCtorId, NULL); - return resultObject; + return resultObject; } void* bitmapData = NULL; size_t bitmapDataSize = 0; -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) { - setGlobalEnv(ienv); - - sprintf(debugMessage, "Creating SkBitmap in native w:%d h:%d!", requestedBitmapWidth, requestedBitmapHeight); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); - - 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); - - if(bitmapData != NULL && bitmapDataSize != bitmap->getSize()) { - free(bitmapData); - bitmapData = NULL; - bitmapDataSize = 0; - } - if(bitmapData == NULL && bitmapDataSize == 0) { - bitmapDataSize = bitmap->getSize(); - bitmapData = malloc(bitmapDataSize); +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) { + setGlobalJniEnv(ienv); + + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Creating SkBitmap in native w:%d h:%d!", requestedBitmapWidth, requestedBitmapHeight); + + 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); + + if(bitmapData != NULL && bitmapDataSize != bitmap->getSize()) { + free(bitmapData); + bitmapData = NULL; + bitmapDataSize = 0; + } + if(bitmapData == NULL && bitmapDataSize == 0) { + bitmapDataSize = bitmap->getSize(); + bitmapData = malloc(bitmapDataSize); + + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Allocated %d bytes at %p", bitmapDataSize, bitmapData); + } + + bitmap->setPixels(bitmapData); + + SkCanvas* canvas = new SkCanvas(*bitmap); + canvas->drawColor(defaultColor); + + SkPaint* paint = new SkPaint; + paint->setAntiAlias(true); + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Initializing rendering"); + ElapsedTimer initObjects; + initObjects.start(); + + RenderingRuleSearchRequest* req = initSearchRequest(renderingRuleSearchRequest); + RenderingContext rc; + pullFromJavaRenderingContext(renderingContext, &rc); + rc.useEnglishNames = useEnglishNames; + SearchResult* result = ((SearchResult*) searchResult); + // std::vector mapDataObjects = marshalObjects(binaryMapDataObjects); + + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Rendering image"); + initObjects.pause(); + + + // Main part do rendering + rc.nativeOperations.start(); + if(result != NULL) { + doRendering(result->result, canvas, paint, req, &rc); + } + rc.nativeOperations.pause(); + + pushToJavaRenderingContext(renderingContext, &rc); + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "End Rendering image"); + + // delete variables + delete paint; + delete canvas; + delete req; + delete bitmap; + // deleteObjects(mapDataObjects); + + jclass resultClass = findClass("net/osmand/plus/render/NativeOsmandLibrary$RenderingGenerationResult"); - sprintf(debugMessage, "Allocated %d bytes at %p", bitmapDataSize, bitmapData); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); - } - - bitmap->setPixels(bitmapData); - - SkCanvas* canvas = new SkCanvas(*bitmap); - canvas->drawColor(defaultColor); - - SkPaint* paint = new SkPaint; - paint->setAntiAlias(true); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", "Initializing rendering"); - watcher initObjects; - initObjects.start(); - - RenderingRuleSearchRequest* req = initSearchRequest(renderingRuleSearchRequest); - RenderingContext rc; - copyRenderingContext(renderingContext, &rc); - rc.useEnglishNames = useEnglishNames; - SearchResult* result = ((SearchResult*) searchResult); -// std::vector mapDataObjects = marshalObjects(binaryMapDataObjects); - - __android_log_print(ANDROID_LOG_WARN, "net.osmand", "Rendering image"); - initObjects.pause(); - - - // Main part do rendering - rc.nativeOperations.start(); - if(result != NULL) { - doRendering(result->result, canvas, paint, req, &rc); - } - rc.nativeOperations.pause(); - - mergeRenderingContext(renderingContext, &rc); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", "End Rendering image"); - - // delete variables - delete paint; - delete canvas; - delete req; - delete bitmap; -// deleteObjects(mapDataObjects); - - jclass resultClass = ienv->FindClass("net/osmand/plus/render/NativeOsmandLibrary$RenderingGenerationResult"); - if(!resultClass) - resultClass = ienv->FindClass("net/osmand/render/NativeOsmandLibrary$RenderingGenerationResult"); - sprintf(debugMessage, "Result class = %p", resultClass); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); - - jmethodID resultClassCtorId = ienv->GetMethodID(resultClass, "", "(Ljava/nio/ByteBuffer;Ljava/lang/String;)V"); - - sprintf(debugMessage, "Result class ctor = %p", resultClassCtorId); - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); + jmethodID resultClassCtorId = ienv->GetMethodID(resultClass, "", "(Ljava/nio/ByteBuffer;)V"); #ifdef DEBUG_NAT_OPERATIONS - sprintf(debugMessage, "Native ok (init %d, native op %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime()); + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Native ok (init %d, native op %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime()); #else - sprintf(debugMessage, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime()); + __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(), rc.nativeOperations.getElapsedTime()); #endif - __android_log_print(ANDROID_LOG_WARN, "net.osmand", debugMessage); - // Allocate ctor paramters - jobject bitmapBuffer = ienv->NewDirectByteBuffer(bitmapData, bitmap->getSize()); - jstring message = globalEnv()->NewStringUTF(debugMessage); - - /* Construct a result object */ - jobject resultObject = ienv->NewObject(resultClass, resultClassCtorId, bitmapBuffer, message); + // Allocate ctor paramters + jobject bitmapBuffer = ienv->NewDirectByteBuffer(bitmapData, bitmap->getSize()); - return resultObject; + /* Construct a result object */ + jobject resultObject = ienv->NewObject(resultClass, resultClassCtorId, bitmapBuffer); + + return resultObject; } - -#ifdef __cplusplus -} -#endif -#endif /**/ diff --git a/OsmAnd/jni/osmand/textdraw.cpp b/OsmAnd/jni/osmand/textdraw.cpp index 363801da34..603a89763f 100644 --- a/OsmAnd/jni/osmand/textdraw.cpp +++ b/OsmAnd/jni/osmand/textdraw.cpp @@ -193,10 +193,10 @@ void drawWrappedText(RenderingContext* rc, SkCanvas* cv, TextDrawInfo* text, flo pos++; } if(lastSpace == -1) { - NAT_COUNT(rc, drawTextOnCanvas(cv, text->text.substr(start, pos), text->centerX, text->centerY + line * (textSize + 2), paintText, text->textShadow)); + PROFILE_NATIVE_OPERATION(rc, drawTextOnCanvas(cv, text->text.substr(start, pos), text->centerX, text->centerY + line * (textSize + 2), paintText, text->textShadow)); start = pos; } else { - NAT_COUNT(rc, drawTextOnCanvas(cv, text->text.substr(start, lastSpace), text->centerX, text->centerY + line * (textSize + 2), paintText, text->textShadow)); + PROFILE_NATIVE_OPERATION(rc, drawTextOnCanvas(cv, text->text.substr(start, lastSpace), text->centerX, text->centerY + line * (textSize + 2), paintText, text->textShadow)); start = lastSpace + 1; limit += (start - pos) - 1; } @@ -204,7 +204,7 @@ void drawWrappedText(RenderingContext* rc, SkCanvas* cv, TextDrawInfo* text, flo } } else { - NAT_COUNT(rc, drawTextOnCanvas(cv, text->text, text->centerX, text->centerY, paintText, text->textShadow)); + PROFILE_NATIVE_OPERATION(rc, drawTextOnCanvas(cv, text->text, text->centerX, text->centerY, paintText, text->textShadow)); } } @@ -514,7 +514,7 @@ void drawTextOverCanvas(RenderingContext* rc, SkCanvas* cv) { } if (text->drawOnPath && text->path != NULL) { if (text->textShadow > 0) { - paintText.setColor(WHITE_COLOR); + paintText.setColor(0xFFFFFFFF); paintText.setStyle(SkPaint::kStroke_Style); paintText.setStrokeWidth(2 + text->textShadow); rc->nativeOperations.pause(); diff --git a/OsmAnd/jni/png/png_library b/OsmAnd/jni/png/png_library new file mode 160000 index 0000000000..17b24482db --- /dev/null +++ b/OsmAnd/jni/png/png_library @@ -0,0 +1 @@ +Subproject commit 17b24482db9fb75020b91a9c17f2014beebc86ed diff --git a/OsmAnd/jni/skia/.gclient b/OsmAnd/jni/skia/.gclient deleted file mode 100755 index 9e066ea0db..0000000000 --- a/OsmAnd/jni/skia/.gclient +++ /dev/null @@ -1,13 +0,0 @@ -# To develop Skia targeting Android, -# copy this file to your root development directory as ".gclient" -# and then run "gclient sync". -solutions = [ - { - "name" : "android", - "url" : "https://skia.googlecode.com/svn/android", - }, - { - "name" : "trunk", - "url" : "https://skia.googlecode.com/svn/trunk", - }, -] diff --git a/OsmAnd/jni/skia/.gitignore b/OsmAnd/jni/skia/.gitignore deleted file mode 100755 index 49dfd06eb2..0000000000 --- a/OsmAnd/jni/skia/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -* -!.gitignore -!.gclient -!Android.mk -!FakeHost.mk -!FontHostConfiguration_android.cpp \ No newline at end of file diff --git a/OsmAnd/jni/skia/Android.mk b/OsmAnd/jni/skia/Android.mk index 3dfe8bde6c..a1dbd37cbc 100755 --- a/OsmAnd/jni/skia/Android.mk +++ b/OsmAnd/jni/skia/Android.mk @@ -11,11 +11,27 @@ LOCAL_MODULE := skia_neon LOCAL_ARM_NEON := true endif -ifeq ($(SKIA_LOC),) - SKIA_LOC := . +ifeq ($(OSMAND_SKIA_LOC),) + OSMAND_SKIA_LOC := ./skia_library endif -ifeq ($(SKIA_ABS),) - SKIA_ABS := $(LOCAL_PATH) +ifeq ($(OSMAND_SKIA_ABS),) + OSMAND_SKIA_ABS := $(LOCAL_PATH)/skia_library +endif + +ifeq ($(OSMAND_FREETYPE_ABS),) + OSMAND_FREETYPE_ABS := $(LOCAL_PATH)/../freetype/freetype_library +endif +ifeq ($(OSMAND_PNG_ABS),) + OSMAND_PNG_ABS := $(LOCAL_PATH)/../png/png_library +endif +ifeq ($(OSMAND_GIF_ABS),) + OSMAND_GIF_ABS := $(LOCAL_PATH)/../gif/gif_library +endif +ifeq ($(OSMAND_EXPAT_ABS),) + OSMAND_EXPAT_ABS := $(LOCAL_PATH)/../expat/expat_library +endif +ifeq ($(OSMAND_JPEG_ABS),) + OSMAND_JPEG_ABS := $(LOCAL_PATH)/../jpeg/jpeg_library endif LOCAL_ARM_MODE := arm @@ -35,251 +51,259 @@ ifeq ($(LOCAL_ARM_NEON),true) endif LOCAL_SRC_FILES := \ - $(SKIA_LOC)/trunk/src/core/Sk64.cpp \ - $(SKIA_LOC)/trunk/src/core/SkAAClip.cpp \ - $(SKIA_LOC)/trunk/src/core/SkAdvancedTypefaceMetrics.cpp \ - $(SKIA_LOC)/trunk/src/core/SkAlphaRuns.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBitmap.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBitmapProcShader.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBitmapProcState.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBitmapProcState_matrixProcs.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBitmapSampler.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBitmap_scroll.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBlitMask_D32.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBlitRow_D16.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBlitRow_D32.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBlitRow_D4444.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBlitter.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBlitter_4444.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBlitter_A1.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBlitter_A8.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBlitter_ARGB32.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBlitter_RGB16.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBlitter_Sprite.cpp \ - $(SKIA_LOC)/trunk/src/core/SkBuffer.cpp \ - $(SKIA_LOC)/trunk/src/core/SkCanvas.cpp \ - $(SKIA_LOC)/trunk/src/core/SkChunkAlloc.cpp \ - $(SKIA_LOC)/trunk/src/core/SkClampRange.cpp \ - $(SKIA_LOC)/trunk/src/core/SkClipStack.cpp \ - $(SKIA_LOC)/trunk/src/core/SkColor.cpp \ - $(SKIA_LOC)/trunk/src/core/SkColorFilter.cpp \ - $(SKIA_LOC)/trunk/src/core/SkColorTable.cpp \ - $(SKIA_LOC)/trunk/src/core/SkConfig8888.cpp \ - $(SKIA_LOC)/trunk/src/core/SkComposeShader.cpp \ - $(SKIA_LOC)/trunk/src/core/SkConcaveToTriangles.cpp \ - $(SKIA_LOC)/trunk/src/core/SkCordic.cpp \ - $(SKIA_LOC)/trunk/src/core/SkCubicClipper.cpp \ - $(SKIA_LOC)/trunk/src/core/SkData.cpp \ - $(SKIA_LOC)/trunk/src/core/SkDebug.cpp \ - $(SKIA_LOC)/trunk/src/core/SkDeque.cpp \ - $(SKIA_LOC)/trunk/src/core/SkDevice.cpp \ - $(SKIA_LOC)/trunk/src/core/SkDither.cpp \ - $(SKIA_LOC)/trunk/src/core/SkDraw.cpp \ - $(SKIA_LOC)/trunk/src/core/SkEdgeBuilder.cpp \ - $(SKIA_LOC)/trunk/src/core/SkEdgeClipper.cpp \ - $(SKIA_LOC)/trunk/src/core/SkEdge.cpp \ - $(SKIA_LOC)/trunk/src/core/SkFilterProc.cpp \ - $(SKIA_LOC)/trunk/src/core/SkFlattenable.cpp \ - $(SKIA_LOC)/trunk/src/core/SkFloat.cpp \ - $(SKIA_LOC)/trunk/src/core/SkFloatBits.cpp \ - $(SKIA_LOC)/trunk/src/core/SkFontHost.cpp \ - $(SKIA_LOC)/trunk/src/core/SkGeometry.cpp \ - $(SKIA_LOC)/trunk/src/core/SkGlyphCache.cpp \ - $(SKIA_LOC)/trunk/src/core/SkGraphics.cpp \ - $(SKIA_LOC)/trunk/src/core/SkLineClipper.cpp \ - $(SKIA_LOC)/trunk/src/core/SkMallocPixelRef.cpp \ - $(SKIA_LOC)/trunk/src/core/SkMask.cpp \ - $(SKIA_LOC)/trunk/src/core/SkMaskFilter.cpp \ - $(SKIA_LOC)/trunk/src/core/SkMath.cpp \ - $(SKIA_LOC)/trunk/src/core/SkMatrix.cpp \ - $(SKIA_LOC)/trunk/src/core/SkMetaData.cpp \ - $(SKIA_LOC)/trunk/src/core/SkMMapStream.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPackBits.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPaint.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPath.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPathEffect.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPathHeap.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPathMeasure.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPicture.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPictureFlat.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPicturePlayback.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPictureRecord.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPixelRef.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPoint.cpp \ - $(SKIA_LOC)/trunk/src/core/SkProcSpriteBlitter.cpp \ - $(SKIA_LOC)/trunk/src/core/SkPtrRecorder.cpp \ - $(SKIA_LOC)/trunk/src/core/SkQuadClipper.cpp \ - $(SKIA_LOC)/trunk/src/core/SkRasterClip.cpp \ - $(SKIA_LOC)/trunk/src/core/SkRasterizer.cpp \ - $(SKIA_LOC)/trunk/src/core/SkRect.cpp \ - $(SKIA_LOC)/trunk/src/core/SkRefDict.cpp \ - $(SKIA_LOC)/trunk/src/core/SkRegion.cpp \ - $(SKIA_LOC)/trunk/src/core/SkRegion_path.cpp \ - $(SKIA_LOC)/trunk/src/core/SkScalar.cpp \ - $(SKIA_LOC)/trunk/src/core/SkScalerContext.cpp \ - $(SKIA_LOC)/trunk/src/core/SkScan.cpp \ - $(SKIA_LOC)/trunk/src/core/SkScan_AntiPath.cpp \ - $(SKIA_LOC)/trunk/src/core/SkScan_Antihair.cpp \ - $(SKIA_LOC)/trunk/src/core/SkScan_Hairline.cpp \ - $(SKIA_LOC)/trunk/src/core/SkScan_Path.cpp \ - $(SKIA_LOC)/trunk/src/core/SkShader.cpp \ - $(SKIA_LOC)/trunk/src/core/SkShape.cpp \ - $(SKIA_LOC)/trunk/src/core/SkSpriteBlitter_ARGB32.cpp \ - $(SKIA_LOC)/trunk/src/core/SkSpriteBlitter_RGB16.cpp \ - $(SKIA_LOC)/trunk/src/core/SkStream.cpp \ - $(SKIA_LOC)/trunk/src/core/SkString.cpp \ - $(SKIA_LOC)/trunk/src/core/SkStroke.cpp \ - $(SKIA_LOC)/trunk/src/core/SkStrokerPriv.cpp \ - $(SKIA_LOC)/trunk/src/core/SkTSearch.cpp \ - $(SKIA_LOC)/trunk/src/core/SkTypeface.cpp \ - $(SKIA_LOC)/trunk/src/core/SkTypefaceCache.cpp \ - $(SKIA_LOC)/trunk/src/core/SkUnPreMultiply.cpp \ - $(SKIA_LOC)/trunk/src/core/SkUtils.cpp \ - $(SKIA_LOC)/trunk/src/core/SkFlate.cpp \ - $(SKIA_LOC)/trunk/src/core/SkWriter32.cpp \ - $(SKIA_LOC)/trunk/src/core/SkXfermode.cpp \ - $(SKIA_LOC)/trunk/src/effects/Sk1DPathEffect.cpp \ - $(SKIA_LOC)/trunk/src/effects/Sk2DPathEffect.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkAvoidXfermode.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkArithmeticMode.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkBitmapCache.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkBlurDrawLooper.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkBlurImageFilter.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkBlurMask.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkBlurMaskFilter.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkColorFilters.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkColorMatrixFilter.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkCornerPathEffect.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkDashPathEffect.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkDiscretePathEffect.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkEffects.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkEmbossMask.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkEmbossMaskFilter.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkGradientShader.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkGroupShape.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkKernel33MaskFilter.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkLayerDrawLooper.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkLayerRasterizer.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkPaintFlagsDrawFilter.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkPixelXorXfermode.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkPorterDuff.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkRectShape.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkTableColorFilter.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkTableMaskFilter.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkTestImageFilters.cpp \ - $(SKIA_LOC)/trunk/src/effects/SkTransparentShader.cpp \ - $(SKIA_LOC)/trunk/src/images/bmpdecoderhelper.cpp \ - $(SKIA_LOC)/trunk/src/images/SkCreateRLEPixelRef.cpp \ - $(SKIA_LOC)/trunk/src/images/SkFDStream.cpp \ - $(SKIA_LOC)/trunk/src/images/SkFlipPixelRef.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageDecoder.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageDecoder_Factory.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageDecoder_libbmp.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageDecoder_libgif.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageDecoder_libico.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageDecoder_libpng.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageDecoder_wbmp.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageEncoder.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageEncoder_Factory.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageRef.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageRefPool.cpp \ - $(SKIA_LOC)/trunk/src/images/SkImageRef_GlobalPool.cpp \ - $(SKIA_LOC)/trunk/src/images/SkMovie.cpp \ - $(SKIA_LOC)/trunk/src/images/SkMovie_gif.cpp \ - $(SKIA_LOC)/trunk/src/images/SkPageFlipper.cpp \ - $(SKIA_LOC)/trunk/src/images/SkScaledBitmapSampler.cpp \ - $(SKIA_LOC)/trunk/src/ports/SkDebug_android.cpp \ - $(SKIA_LOC)/trunk/src/ports/SkGlobalInitialization_default.cpp \ - $(SKIA_LOC)/trunk/src/ports/SkFontHost_FreeType.cpp \ - $(SKIA_LOC)/trunk/src/ports/SkFontHost_sandbox_none.cpp \ - $(SKIA_LOC)/trunk/src/ports/SkFontHost_android.cpp \ - $(SKIA_LOC)/trunk/src/ports/SkFontHost_gamma.cpp \ - $(SKIA_LOC)/trunk/src/ports/SkFontHost_tables.cpp \ - $(SKIA_LOC)/trunk/src/ports/SkMemory_malloc.cpp \ - $(SKIA_LOC)/trunk/src/ports/SkOSFile_stdio.cpp \ - $(SKIA_LOC)/trunk/src/ports/SkTime_Unix.cpp \ - $(SKIA_LOC)/trunk/src/ports/SkThread_pthread.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkBoundaryPatch.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkCamera.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkColorMatrix.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkCubicInterval.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkCullPoints.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkDumpCanvas.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkInterpolator.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkLayer.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkMatrix44.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkMeshUtils.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkNinePatch.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkNWayCanvas.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkOSFile.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkParse.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkParseColor.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkParsePath.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkProxyCanvas.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkSfntUtils.cpp \ - $(SKIA_LOC)/trunk/src/utils/SkUnitMappers.cpp + $(OSMAND_SKIA_LOC)/src/core/Sk64.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkAAClip.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkAdvancedTypefaceMetrics.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkAlphaRuns.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBitmap.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBitmapProcShader.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBitmapProcState.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBitmapProcState_matrixProcs.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBitmapSampler.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBitmap_scroll.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBlitMask_D32.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBlitRow_D16.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBlitRow_D32.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBlitRow_D4444.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBlitter.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBlitter_4444.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBlitter_A1.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBlitter_A8.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBlitter_ARGB32.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBlitter_RGB16.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBlitter_Sprite.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkBuffer.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkCanvas.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkChunkAlloc.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkClampRange.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkClipStack.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkColor.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkColorFilter.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkColorTable.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkComposeShader.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkConcaveToTriangles.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkCordic.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkCubicClipper.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkData.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkDebug.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkDeque.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkDevice.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkDither.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkDraw.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkEdgeBuilder.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkEdgeClipper.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkEdge.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkFilterProc.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkFlattenable.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkFloat.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkFloatBits.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkFontHost.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkGeometry.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkGlyphCache.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkGraphics.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkLineClipper.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkMallocPixelRef.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkMask.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkMaskFilter.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkMath.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkMatrix.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkMetaData.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkMMapStream.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPackBits.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPaint.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPath.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPathEffect.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPathHeap.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPathMeasure.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPicture.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPictureFlat.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPicturePlayback.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPictureRecord.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPixelRef.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPoint.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkProcSpriteBlitter.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkPtrRecorder.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkQuadClipper.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkRasterClip.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkRasterizer.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkRect.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkRefDict.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkRegion.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkRegion_path.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkScalar.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkScalerContext.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkScan.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkScan_AntiPath.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkScan_Antihair.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkScan_Hairline.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkScan_Path.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkShader.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkShape.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkSpriteBlitter_ARGB32.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkSpriteBlitter_RGB16.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkStream.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkString.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkStroke.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkStrokerPriv.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkTSearch.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkTypeface.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkTypefaceCache.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkUnPreMultiply.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkUtils.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkFlate.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkWriter32.cpp \ + $(OSMAND_SKIA_LOC)/src/core/SkXfermode.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/Sk1DPathEffect.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/Sk2DPathEffect.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkAvoidXfermode.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkArithmeticMode.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkBitmapCache.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkBlurDrawLooper.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkBlurImageFilter.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkBlurMask.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkBlurMaskFilter.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkColorFilters.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkColorMatrixFilter.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkCornerPathEffect.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkDashPathEffect.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkDiscretePathEffect.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkEffects.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkEmbossMask.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkEmbossMaskFilter.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkGradientShader.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkGroupShape.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkKernel33MaskFilter.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkLayerDrawLooper.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkLayerRasterizer.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkPaintFlagsDrawFilter.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkPixelXorXfermode.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkPorterDuff.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkRectShape.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkTableColorFilter.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkTableMaskFilter.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkTestImageFilters.cpp \ + $(OSMAND_SKIA_LOC)/src/effects/SkTransparentShader.cpp \ + $(OSMAND_SKIA_LOC)/src/images/bmpdecoderhelper.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkCreateRLEPixelRef.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkFDStream.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkFlipPixelRef.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageDecoder.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageDecoder_Factory.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageDecoder_libbmp.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageDecoder_libgif.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageDecoder_libico.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageDecoder_libjpeg.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageDecoder_libpng.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageDecoder_wbmp.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageEncoder.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageEncoder_Factory.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageRef.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageRefPool.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkImageRef_GlobalPool.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkMovie.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkMovie_gif.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkPageFlipper.cpp \ + $(OSMAND_SKIA_LOC)/src/images/SkScaledBitmapSampler.cpp \ + $(OSMAND_SKIA_LOC)/src/ports/SkDebug_android.cpp \ + $(OSMAND_SKIA_LOC)/src/ports/SkGlobalInitialization_default.cpp \ + $(OSMAND_SKIA_LOC)/src/ports/SkFontHost_FreeType.cpp \ + $(OSMAND_SKIA_LOC)/src/ports/SkFontHost_sandbox_none.cpp \ + $(OSMAND_SKIA_LOC)/src/ports/SkFontHost_android.cpp \ + $(OSMAND_SKIA_LOC)/src/ports/SkFontHost_gamma.cpp \ + $(OSMAND_SKIA_LOC)/src/ports/SkFontHost_tables.cpp \ + $(OSMAND_SKIA_LOC)/src/ports/SkMemory_malloc.cpp \ + $(OSMAND_SKIA_LOC)/src/ports/SkOSFile_stdio.cpp \ + $(OSMAND_SKIA_LOC)/src/ports/SkTime_Unix.cpp \ + $(OSMAND_SKIA_LOC)/src/ports/SkThread_pthread.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkBoundaryPatch.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkCamera.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkColorMatrix.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkCubicInterval.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkCullPoints.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkDumpCanvas.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkInterpolator.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkLayer.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkMatrix44.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkMeshUtils.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkNinePatch.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkNWayCanvas.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkOSFile.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkParse.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkParseColor.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkParsePath.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkProxyCanvas.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkSfntUtils.cpp \ + $(OSMAND_SKIA_LOC)/src/utils/SkUnitMappers.cpp -# This file is replacement of $(SKIA_LOC)/trunk/src/ports/FontHostConfiguration_android.cpp +# This file is replacement of $(OSMAND_SKIA_LOC)/src/ports/FontHostConfiguration_android.cpp LOCAL_SRC_FILES += \ FontHostConfiguration_android.cpp LOCAL_C_INCLUDES += \ - $(SKIA_ABS)/trunk/src/ports + $(OSMAND_SKIA_ABS)/src/ports ifeq ($(TARGET_ARCH),arm) ifeq ($(LOCAL_ARM_NEON),true) LOCAL_SRC_FILES += \ - $(SKIA_LOC)/trunk/src/opts/memset16_neon.S \ - $(SKIA_LOC)/trunk/src/opts/memset32_neon.S + $(OSMAND_SKIA_LOC)/src/opts/memset16_neon.S \ + $(OSMAND_SKIA_LOC)/src/opts/memset32_neon.S endif LOCAL_SRC_FILES += \ - $(SKIA_LOC)/trunk/src/opts/opts_check_arm.cpp \ - $(SKIA_LOC)/trunk/src/opts/memset.arm.S \ - $(SKIA_LOC)/trunk/src/opts/SkBitmapProcState_opts_arm.cpp \ - $(SKIA_LOC)/trunk/src/opts/SkBlitRow_opts_arm.cpp + $(OSMAND_SKIA_LOC)/src/opts/opts_check_arm.cpp \ + $(OSMAND_SKIA_LOC)/src/opts/memset.arm.S \ + $(OSMAND_SKIA_LOC)/src/opts/SkBitmapProcState_opts_arm.cpp \ + $(OSMAND_SKIA_LOC)/src/opts/SkBlitRow_opts_arm.cpp else LOCAL_SRC_FILES += \ - $(SKIA_LOC)/trunk/src/opts/SkBlitRow_opts_none.cpp \ - $(SKIA_LOC)/trunk/src/opts/SkBitmapProcState_opts_none.cpp \ - $(SKIA_LOC)/trunk/src/opts/SkUtils_opts_none.cpp + $(OSMAND_SKIA_LOC)/src/opts/SkBlitRow_opts_none.cpp \ + $(OSMAND_SKIA_LOC)/src/opts/SkBitmapProcState_opts_none.cpp \ + $(OSMAND_SKIA_LOC)/src/opts/SkUtils_opts_none.cpp endif LOCAL_SHARED_LIBRARIES := \ - libcutils \ - libjpeg \ libutils \ libz -LOCAL_STATIC_LIBRARIES := \ - libft2 \ +ifeq ($(LOCAL_ARM_NEON),true) +LOCAL_STATIC_LIBRARIES += \ + libjpeg_neon \ + libft2_static_neon \ + libpng_neon \ + libgif_neon \ + libexpat_static_neon +else +LOCAL_STATIC_LIBRARIES += \ + libjpeg \ + libft2_static \ libpng \ libgif \ libexpat_static +endif LOCAL_C_INCLUDES += \ - $(SKIA_ABS)/trunk/src/core \ - $(SKIA_ABS)/trunk/include/core \ - $(SKIA_ABS)/trunk/include/config \ - $(SKIA_ABS)/trunk/include/effects \ - $(SKIA_ABS)/trunk/include/images \ - $(SKIA_ABS)/trunk/include/utils \ - $(SKIA_ABS)/trunk/include/xml \ - $(SKIA_ABS)/android/third_party/externals/freetype/include \ - $(SKIA_ABS)/android/third_party/externals/png \ - $(SKIA_ABS)/android/third_party/externals/gif \ - $(SKIA_ABS)/android/third_party/externals/expat/lib + $(LOCAL_PATH) \ + $(OSMAND_SKIA_ABS)/src/core \ + $(OSMAND_SKIA_ABS)/include/core \ + $(OSMAND_SKIA_ABS)/include/config \ + $(OSMAND_SKIA_ABS)/include/effects \ + $(OSMAND_SKIA_ABS)/include/images \ + $(OSMAND_SKIA_ABS)/include/utils \ + $(OSMAND_SKIA_ABS)/include/xml \ + $(OSMAND_FREETYPE_ABS)/include \ + $(OSMAND_PNG_ABS) \ + $(OSMAND_GIF_ABS) \ + $(OSMAND_EXPAT_ABS)/lib \ + $(OSMAND_JPEG_ABS) ifeq ($(NO_FALLBACK_FONT),true) LOCAL_CFLAGS += -DNO_FALLBACK_FONT endif LOCAL_CFLAGS += \ - -DSK_SCALAR_IS_FLOAT \ - -DSK_CAN_USE_FLOAT \ -DSK_BUILD_FOR_ANDROID \ -DSK_BUILD_FOR_ANDROID_NDK \ -DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=0 \ @@ -298,11 +322,4 @@ include $(BUILD_STATIC_LIBRARY) # Fix some errors BUILD_HOST_EXECUTABLE := $(LOCAL_PATH)/FakeHost.mk -BUILD_HOST_STATIC_LIBRARY := $(LOCAL_PATH)/FakeHost.mk - -# Import skia externals -$(call import-add-path,$(SKIA_ABS)/android/third_party/externals) -$(call import-module,expat) -$(call import-module,freetype) -$(call import-module,gif) -$(call import-module,png) \ No newline at end of file +BUILD_HOST_STATIC_LIBRARY := $(LOCAL_PATH)/FakeHost.mk \ No newline at end of file diff --git a/OsmAnd/jni/skia/skia_library b/OsmAnd/jni/skia/skia_library new file mode 160000 index 0000000000..1cab2921ab --- /dev/null +++ b/OsmAnd/jni/skia/skia_library @@ -0,0 +1 @@ +Subproject commit 1cab2921ab279367f8206cdadc9259d12e603548 diff --git a/OsmAnd/src/net/osmand/plus/render/NativeOsmandLibrary.java b/OsmAnd/src/net/osmand/plus/render/NativeOsmandLibrary.java index 4a98473e17..47aa237002 100644 --- a/OsmAnd/src/net/osmand/plus/render/NativeOsmandLibrary.java +++ b/OsmAnd/src/net/osmand/plus/render/NativeOsmandLibrary.java @@ -73,7 +73,8 @@ public class NativeOsmandLibrary { Bitmap bitmap, int requestedBitmapWidth, int requestedBitmapHeight, int rowBytes, boolean isTransparent, boolean useEnglishNames, RenderingRuleSearchRequest render, int defaultColor) { if (searchResultHandler == null) { - return new RenderingGenerationResult(null, "Error searchresult = null"); + log.error("Error searchresult = null"); //$NON-NLS-1$ + return new RenderingGenerationResult(null); } if(android.os.Build.VERSION.SDK_INT >= 8) // Android 2.2+ @@ -131,14 +132,11 @@ public class NativeOsmandLibrary { } public static class RenderingGenerationResult { - public RenderingGenerationResult(ByteBuffer bitmap, String msg) { + public RenderingGenerationResult(ByteBuffer bitmap) { bitmapBuffer = bitmap; - debugMessage = msg; } public final ByteBuffer bitmapBuffer; - - public final String debugMessage; } private static native void deleteSearchResult(int searchResultHandle); diff --git a/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java b/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java index dac909876c..543e5aa8e6 100644 --- a/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java +++ b/OsmAnd/src/net/osmand/plus/render/OsmandRenderer.java @@ -226,7 +226,7 @@ public class OsmandRenderer { notifyListeners(notifyList); long time = System.currentTimeMillis() - now; rc.renderingDebugInfo = String.format("Rendering: %s ms (%s text)\n" - + "(%s points, %s points inside, %s of %s objects visible)\n" + res.debugMessage,//$NON-NLS-1$ + + "(%s points, %s points inside, %s of %s objects visible)\n",//$NON-NLS-1$ time, rc.textRenderingTime, rc.pointCount, rc.pointInsideCount, rc.visible, rc.allObjects); // See upper note diff --git a/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java b/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java index 987bf49e62..b9a6019b46 100644 --- a/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java +++ b/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java @@ -3,16 +3,23 @@ package net.osmand.plus.render; import java.lang.reflect.Field; import java.util.LinkedHashMap; import java.util.Map; +import java.nio.ByteBuffer; +import java.io.InputStream; + +import org.apache.commons.logging.Log; import android.content.Context; import android.graphics.Bitmap; import android.util.DisplayMetrics; import android.view.WindowManager; +import android.content.res.AssetFileDescriptor; import net.osmand.plus.R; import net.osmand.plus.R.drawable; +import net.osmand.LogUtil; public class RenderingIcons { + private static final Log log = LogUtil.getLog(RenderingIcons.class); private static Map icons = new LinkedHashMap(); private static Map iconsBmp = new LinkedHashMap(); @@ -22,6 +29,37 @@ public class RenderingIcons { return icons.containsKey(s); } + public static ByteBuffer getIconAsByteBuffer(Context ctx, String s) { + Integer resId = icons.get(s); + + // Quite bad error + if(resId == null) + return null; + + try { + final AssetFileDescriptor iconAssetFd = ctx.getResources().openRawResourceFd(resId.intValue()); + if(iconAssetFd == null) + return null; + + final long iconAssetLen = iconAssetFd.getLength(); + final ByteBuffer iconByteBuffer = ByteBuffer.allocate((int)iconAssetLen); + final InputStream inputStream = iconAssetFd.createInputStream(); + if(inputStream == null) + return null; + + long consumedBytes = 0; + while(consumedBytes < iconAssetLen) { + consumedBytes += inputStream.read(iconByteBuffer.array(), (int)(iconByteBuffer.arrayOffset() + consumedBytes), (int)(iconAssetLen - consumedBytes)); + } + + iconAssetFd.close(); + return iconByteBuffer; + } catch(Throwable e) { + log.error("Failed to get byte stream from icon", e); //$NON-NLS-1$ + return null; + } + } + public static Bitmap getIcon(Context ctx, String s){ if(!iconsBmp.containsKey(s)){ Integer resId = icons.get(s);