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:
~SkijaDrawableImpl() {
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);
}
......
#include "SkCanvas.h"
#include "SkFont.h"
#include "SkFontMetrics.h"
#include "SkPoint.h"
#include "SkRefCnt.h"
#include "SkTextBlob.h"
......
#include <cstdint>
#include <jni.h>
#ifdef SK_BUILD_FOR_ANDROID
#include <stdlib.h>
#else
#include <jawt_md.h>
#include "jni_helpers.h"
#endif
#ifndef SK_BUILD_FOR_ANDROID
extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt);
#endif
extern "C"
{
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();
awt->version = (jint)JAWT_VERSION_9;
jboolean result = Skiko_GetAWT(env, awt);
......@@ -20,51 +30,87 @@ extern "C"
{
return toJavaPointer(awt);
}
#endif
}
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_DrawingSurface *ds = awt->GetDrawingSurface(env, layer);
return toJavaPointer(ds);
#endif
}
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_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr);
awt->FreeDrawingSurface(ds);
#endif
}
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);
return (ds->Lock(ds) & JAWT_LOCK_ERROR) != 0;
#endif
}
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);
ds->Unlock(ds);
#endif
}
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_DrawingSurfaceInfo *dsi = ds->GetDrawingSurfaceInfo(ds);
return toJavaPointer(dsi);
#endif
}
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_DrawingSurfaceInfo *dsi = fromJavaPointer<JAWT_DrawingSurfaceInfo *>(drawingSurfaceInfoPtr);
ds->FreeDrawingSurfaceInfo(dsi);
#endif
}
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);
return toJavaPointer(dsi->platformInfo);
#endif
}
}
\ No newline at end of file
......@@ -7,10 +7,10 @@
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
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_VERSION_1_8;
return SKIKO_JNI_VERSION;
}
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
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {
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;
skija::svg::onUnload(env);
......
......@@ -532,7 +532,7 @@ namespace skija {
bool onFilter(jobject obj, SkPaint& paint) {
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));
_vm->DetachCurrentThread();
return result;
......@@ -544,7 +544,7 @@ namespace skija {
void detach(jobject obj) {
JNIEnv *env;
_vm->AttachCurrentThread((void **) &env, NULL);
_vm->AttachCurrentThread(AS_JNI_ENV_PTR(&env), NULL);
env->DeleteGlobalRef(obj);
_vm->DetachCurrentThread();
}
......
......@@ -360,3 +360,10 @@ inline T jlongToPtr(jlong ptr) {
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_md.h>
#include <stdlib.h>
#if SK_BUILD_FOR_WIN
......@@ -97,3 +99,5 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt) {
#endif
return func(env, awt);
}
#endif
\ No newline at end of file
......@@ -4,6 +4,8 @@
#endif
#if SK_BUILD_FOR_MAC
#import <OpenGL/gl3.h>
#elif SK_BUILD_FOR_ANDROID
#include <GLES/gl.h>
#else
#include <GL/gl.h>
#endif
......
#include <jni.h>
#if SK_BUILD_FOR_LINUX
#include <stdint.h>
#include <stdint.h>
#endif
#include "jni_helpers.h"
......
......@@ -4,6 +4,7 @@
#include "../TextLine.hh"
#include "SkShaper.h"
#include "SkTextBlob.h"
#include "unicode/ubrk.h"
class TextLineRunHandler: public SkShaper::RunHandler {
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