-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from JetBrains/refactor_jni
Refactoring. Move getDrawingSurface to Java from JNI
- Loading branch information
Showing
15 changed files
with
266 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <cstdint> | ||
#include <jawt_md.h> | ||
#include "jni_helpers.h" | ||
|
||
extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt); | ||
|
||
extern "C" | ||
{ | ||
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getAWT(JNIEnv *env, jobject obj) | ||
{ | ||
JAWT *awt = new JAWT(); | ||
awt->version = (jint)JAWT_VERSION_9; | ||
jboolean result = Skiko_GetAWT(env, awt); | ||
|
||
if (result == JNI_FALSE) | ||
{ | ||
return 0; | ||
} | ||
else | ||
{ | ||
return toJavaPointer(awt); | ||
} | ||
} | ||
|
||
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getDrawingSurface(JNIEnv *env, jobject obj, jlong awtPtr, jobject layer) | ||
{ | ||
JAWT *awt = fromJavaPointer<JAWT *>(awtPtr); | ||
JAWT_DrawingSurface *ds = awt->GetDrawingSurface(env, layer); | ||
return toJavaPointer(ds); | ||
} | ||
|
||
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_freeDrawingSurface(JNIEnv *env, jobject obj, jlong awtPtr, jlong drawingSurfacePtr) | ||
{ | ||
JAWT *awt = fromJavaPointer<JAWT *>(awtPtr); | ||
JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr); | ||
awt->FreeDrawingSurface(ds); | ||
} | ||
|
||
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_lockDrawingSurface(JNIEnv *env, jobject obj, jlong drawingSurfacePtr) | ||
{ | ||
JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr); | ||
ds->Lock(ds); | ||
} | ||
|
||
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_unlockDrawingSurface(JNIEnv *env, jobject obj, jlong drawingSurfacePtr) | ||
{ | ||
JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr); | ||
ds->Unlock(ds); | ||
} | ||
|
||
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getDrawingSurfaceInfo(JNIEnv *env, jobject obj, jlong drawingSurfacePtr) | ||
{ | ||
JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr); | ||
JAWT_DrawingSurfaceInfo *dsi = ds->GetDrawingSurfaceInfo(ds); | ||
return toJavaPointer(dsi); | ||
} | ||
|
||
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_AWTKt_freeDrawingSurfaceInfo(JNIEnv *env, jobject obj, jlong drawingSurfacePtr, jlong drawingSurfaceInfoPtr) | ||
{ | ||
JAWT_DrawingSurface *ds = fromJavaPointer<JAWT_DrawingSurface *>(drawingSurfacePtr); | ||
JAWT_DrawingSurfaceInfo *dsi = fromJavaPointer<JAWT_DrawingSurfaceInfo *>(drawingSurfaceInfoPtr); | ||
ds->FreeDrawingSurfaceInfo(dsi); | ||
} | ||
|
||
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_AWTKt_getPlatformInfo(JNIEnv *env, jobject obj, jlong drawingSurfaceInfoPtr) | ||
{ | ||
JAWT_DrawingSurfaceInfo *dsi = fromJavaPointer<JAWT_DrawingSurfaceInfo *>(drawingSurfaceInfoPtr); | ||
return toJavaPointer(dsi->platformInfo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
template<typename T> | ||
T inline fromJavaPointer(jlong ptr) { return reinterpret_cast<T>(static_cast<uintptr_t>(ptr)); } | ||
|
||
template<typename T> | ||
jlong inline toJavaPointer(T ptr) { return static_cast<jlong>(reinterpret_cast<uintptr_t>(ptr)); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,20 @@ | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <jawt_md.h> | ||
|
||
extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt); | ||
#include "jni_helpers.h" | ||
|
||
extern "C" | ||
{ | ||
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_init(JNIEnv *env, jobject canvas) | ||
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_nativeInit(JNIEnv *env, jobject canvas, jlong platformInfoPtr) | ||
{ | ||
} | ||
|
||
JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_dispose(JNIEnv *env, jobject canvas) | ||
{ | ||
} | ||
|
||
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_HardwareLayer_getWindowHandle(JNIEnv *env, jobject canvas) | ||
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_HardwareLayer_getWindowHandle(JNIEnv *env, jobject canvas, jlong platformInfoPtr) | ||
{ | ||
JAWT awt; | ||
JAWT_DrawingSurface *ds = NULL; | ||
JAWT_DrawingSurfaceInfo *dsi = NULL; | ||
|
||
jboolean result = JNI_FALSE; | ||
jint lock = 0; | ||
JAWT_Win32DrawingSurfaceInfo *dsi_win; | ||
|
||
awt.version = (jint)JAWT_VERSION_9; | ||
result = Skiko_GetAWT(env, &awt); | ||
|
||
if (result == JNI_FALSE) | ||
{ | ||
fprintf(stderr, "JAWT_GetAWT failed! Result is JNI_FALSE\n"); | ||
return -1; | ||
} | ||
|
||
ds = awt.GetDrawingSurface(env, canvas); | ||
lock = ds->Lock(ds); | ||
dsi = ds->GetDrawingSurfaceInfo(ds); | ||
dsi_win = (JAWT_Win32DrawingSurfaceInfo *)dsi->platformInfo; | ||
|
||
HWND hwnd = dsi_win->hwnd; | ||
|
||
ds->FreeDrawingSurfaceInfo(dsi); | ||
ds->Unlock(ds); | ||
awt.FreeDrawingSurface(ds); | ||
|
||
return (jlong)hwnd; | ||
JAWT_Win32DrawingSurfaceInfo* dsi_win = fromJavaPointer<JAWT_Win32DrawingSurfaceInfo *>(platformInfoPtr); | ||
return (jlong) dsi_win->hwnd; | ||
} | ||
} // extern "C" |
Oops, something went wrong.