Unverified Commit 40668d6a authored by Nikolay Igotti's avatar Nikolay Igotti Committed by GitHub

Make native sources Android-friendly. (#209)

parent 93367672
...@@ -10,7 +10,7 @@ public: ...@@ -10,7 +10,7 @@ public:
~SkijaDrawableImpl() { ~SkijaDrawableImpl() {
JNIEnv* env; JNIEnv* env;
if (fJavaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_8) == JNI_OK) if (fJavaVM->GetEnv(reinterpret_cast<void**>(&env), SKIKO_JNI_VERSION) == JNI_OK)
env->DeleteWeakGlobalRef(fObject); env->DeleteWeakGlobalRef(fObject);
} }
......
#include "SkCanvas.h" #include "SkCanvas.h"
#include "SkFont.h" #include "SkFont.h"
#include "SkFontMetrics.h"
#include "SkPoint.h" #include "SkPoint.h"
#include "SkRefCnt.h" #include "SkRefCnt.h"
#include "SkTextBlob.h" #include "SkTextBlob.h"
......
#include <cstdint> #include <cstdint>
#include <jni.h>
#ifdef SK_BUILD_FOR_ANDROID
#include <stdlib.h>
#else
#include <jawt_md.h> #include <jawt_md.h>
#include "jni_helpers.h" #include "jni_helpers.h"
#endif
#ifndef SK_BUILD_FOR_ANDROID
extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt); extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt);
#endif
extern "C" extern "C"
{ {
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getAWT(JNIEnv *env, jobject obj) JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getAWT(JNIEnv *env, jobject obj)
{ {
#ifdef SK_BUILD_FOR_ANDROID
abort();
return 0;
#else
JAWT *awt = new JAWT(); JAWT *awt = new JAWT();
awt->version = (jint)JAWT_VERSION_9; awt->version = (jint)JAWT_VERSION_9;
jboolean result = Skiko_GetAWT(env, awt); jboolean result = Skiko_GetAWT(env, awt);
...@@ -20,51 +30,87 @@ extern "C" ...@@ -20,51 +30,87 @@ extern "C"
{ {
return toJavaPointer(awt); return toJavaPointer(awt);
} }
#endif
} }
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getDrawingSurface(JNIEnv *env, jobject obj, jlong awtPtr, jobject layer) JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getDrawingSurface(JNIEnv *env, jobject obj, jlong awtPtr, jobject layer)
{ {
#ifdef SK_BUILD_FOR_ANDROID
abort();
return 0;
#else
JAWT *awt = fromJavaPointer<JAWT *>(awtPtr); JAWT *awt = fromJavaPointer<JAWT *>(awtPtr);
JAWT_DrawingSurface *ds = awt->GetDrawingSurface(env, layer); JAWT_DrawingSurface *ds = awt->GetDrawingSurface(env, layer);
return toJavaPointer(ds); return toJavaPointer(ds);
#endif
} }
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_freeDrawingSurface(JNIEnv *env, jobject obj, jlong awtPtr, jlong drawingSurfacePtr) JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_freeDrawingSurface(JNIEnv *env, jobject obj, jlong awtPtr, jlong drawingSurfacePtr)
{ {
#ifdef SK_BUILD_FOR_ANDROID
abort();
return;
#else
JAWT *awt = fromJavaPointer<JAWT *>(awtPtr); JAWT *awt = fromJavaPointer<JAWT *>(awtPtr);
JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr); JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr);
awt->FreeDrawingSurface(ds); awt->FreeDrawingSurface(ds);
#endif
} }
JNIEXPORT jint JNICALL Java_org_jetbrains_skiko_AWTKt_lockDrawingSurface(JNIEnv *env, jobject obj, jlong drawingSurfacePtr) JNIEXPORT jint JNICALL Java_org_jetbrains_skiko_AWTKt_lockDrawingSurface(JNIEnv *env, jobject obj, jlong drawingSurfacePtr)
{ {
#ifdef SK_BUILD_FOR_ANDROID
abort();
return 0;
#else
JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr); JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr);
return (ds->Lock(ds) & JAWT_LOCK_ERROR) != 0; return (ds->Lock(ds) & JAWT_LOCK_ERROR) != 0;
#endif
} }
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_unlockDrawingSurface(JNIEnv *env, jobject obj, jlong drawingSurfacePtr) JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_unlockDrawingSurface(JNIEnv *env, jobject obj, jlong drawingSurfacePtr)
{ {
#ifdef SK_BUILD_FOR_ANDROID
abort();
return;
#else
JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr); JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr);
ds->Unlock(ds); ds->Unlock(ds);
#endif
} }
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getDrawingSurfaceInfo(JNIEnv *env, jobject obj, jlong drawingSurfacePtr) JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getDrawingSurfaceInfo(JNIEnv *env, jobject obj, jlong drawingSurfacePtr)
{ {
#ifdef SK_BUILD_FOR_ANDROID
abort();
return 0;
#else
JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr); JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr);
JAWT_DrawingSurfaceInfo *dsi = ds->GetDrawingSurfaceInfo(ds); JAWT_DrawingSurfaceInfo *dsi = ds->GetDrawingSurfaceInfo(ds);
return toJavaPointer(dsi); return toJavaPointer(dsi);
#endif
} }
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_freeDrawingSurfaceInfo(JNIEnv *env, jobject obj, jlong drawingSurfacePtr, jlong drawingSurfaceInfoPtr) JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_freeDrawingSurfaceInfo(JNIEnv *env, jobject obj, jlong drawingSurfacePtr, jlong drawingSurfaceInfoPtr)
{ {
#ifdef SK_BUILD_FOR_ANDROID
abort();
return;
#else
JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr); JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr);
JAWT_DrawingSurfaceInfo *dsi = fromJavaPointer<JAWT_DrawingSurfaceInfo *>(drawingSurfaceInfoPtr); JAWT_DrawingSurfaceInfo *dsi = fromJavaPointer<JAWT_DrawingSurfaceInfo *>(drawingSurfaceInfoPtr);
ds->FreeDrawingSurfaceInfo(dsi); ds->FreeDrawingSurfaceInfo(dsi);
#endif
} }
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getPlatformInfo(JNIEnv *env, jobject obj, jlong drawingSurfaceInfoPtr) JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getPlatformInfo(JNIEnv *env, jobject obj, jlong drawingSurfaceInfoPtr)
{ {
#ifdef SK_BUILD_FOR_ANDROID
abort();
return 0;
#else
JAWT_DrawingSurfaceInfo *dsi = fromJavaPointer<JAWT_DrawingSurfaceInfo *>(drawingSurfaceInfoPtr); JAWT_DrawingSurfaceInfo *dsi = fromJavaPointer<JAWT_DrawingSurfaceInfo *>(drawingSurfaceInfoPtr);
return toJavaPointer(dsi->platformInfo); return toJavaPointer(dsi->platformInfo);
#endif
} }
} }
\ No newline at end of file
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
JNIEnv* env; JNIEnv* env;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_8) != JNI_OK) if (vm->GetEnv(reinterpret_cast<void**>(&env), SKIKO_JNI_VERSION) != JNI_OK)
return JNI_ERR; return JNI_ERR;
return JNI_VERSION_1_8; return SKIKO_JNI_VERSION;
} }
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_impl_Library__1nAfterLoad extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_impl_Library__1nAfterLoad
...@@ -26,7 +26,7 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_impl_Library__1nAfterL ...@@ -26,7 +26,7 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_impl_Library__1nAfterL
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) { JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {
JNIEnv* env; JNIEnv* env;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_8) != JNI_OK) if (vm->GetEnv(reinterpret_cast<void**>(&env), SKIKO_JNI_VERSION) != JNI_OK)
return; return;
skija::svg::onUnload(env); skija::svg::onUnload(env);
......
...@@ -532,7 +532,7 @@ namespace skija { ...@@ -532,7 +532,7 @@ namespace skija {
bool onFilter(jobject obj, SkPaint& paint) { bool onFilter(jobject obj, SkPaint& paint) {
JNIEnv *env; JNIEnv *env;
_vm->AttachCurrentThread((void **) &env, NULL); _vm->AttachCurrentThread(AS_JNI_ENV_PTR(&env), NULL);
jboolean result = env->CallBooleanMethod(obj, onFilterId, reinterpret_cast<jlong>(&paint)); jboolean result = env->CallBooleanMethod(obj, onFilterId, reinterpret_cast<jlong>(&paint));
_vm->DetachCurrentThread(); _vm->DetachCurrentThread();
return result; return result;
...@@ -544,7 +544,7 @@ namespace skija { ...@@ -544,7 +544,7 @@ namespace skija {
void detach(jobject obj) { void detach(jobject obj) {
JNIEnv *env; JNIEnv *env;
_vm->AttachCurrentThread((void **) &env, NULL); _vm->AttachCurrentThread(AS_JNI_ENV_PTR(&env), NULL);
env->DeleteGlobalRef(obj); env->DeleteGlobalRef(obj);
_vm->DetachCurrentThread(); _vm->DetachCurrentThread();
} }
......
...@@ -360,3 +360,10 @@ inline T jlongToPtr(jlong ptr) { ...@@ -360,3 +360,10 @@ inline T jlongToPtr(jlong ptr) {
void deleteJBytes(void* addr, void*); void deleteJBytes(void* addr, void*);
#ifdef SK_BUILD_FOR_ANDROID
#define SKIKO_JNI_VERSION JNI_VERSION_1_6
#define AS_JNI_ENV_PTR(env) (env)
#else
#define SKIKO_JNI_VERSION JNI_VERSION_1_8
#define AS_JNI_ENV_PTR(env) ((void**)(env))
#endif
\ No newline at end of file
#ifndef SK_BUILD_FOR_ANDROID
#include <jawt.h> #include <jawt.h>
#include <jawt_md.h> #include <jawt_md.h>
#include <stdlib.h> #include <stdlib.h>
#if SK_BUILD_FOR_WIN #if SK_BUILD_FOR_WIN
...@@ -96,4 +98,6 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt) { ...@@ -96,4 +98,6 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt) {
} }
#endif #endif
return func(env, awt); return func(env, awt);
} }
\ No newline at end of file
#endif
\ No newline at end of file
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#endif #endif
#if SK_BUILD_FOR_MAC #if SK_BUILD_FOR_MAC
#import <OpenGL/gl3.h> #import <OpenGL/gl3.h>
#elif SK_BUILD_FOR_ANDROID
#include <GLES/gl.h>
#else #else
#include <GL/gl.h> #include <GL/gl.h>
#endif #endif
......
#include <jni.h> #include <jni.h>
#if SK_BUILD_FOR_LINUX #if SK_BUILD_FOR_LINUX
#include <stdint.h> #include <stdint.h>
#endif #endif
#include "jni_helpers.h" #include "jni_helpers.h"
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "../TextLine.hh" #include "../TextLine.hh"
#include "SkShaper.h" #include "SkShaper.h"
#include "SkTextBlob.h" #include "SkTextBlob.h"
#include "unicode/ubrk.h"
class TextLineRunHandler: public SkShaper::RunHandler { class TextLineRunHandler: public SkShaper::RunHandler {
public: public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment