pass in/store ptr to JNIEnv* rather than env itself

This commit is contained in:
ehouse 2010-01-10 17:25:46 +00:00
parent 148d433e81
commit cc527acb49
4 changed files with 50 additions and 33 deletions

View file

@ -23,7 +23,7 @@
typedef struct _AndDraw {
DrawCtxVTable* vtable;
JNIEnv *env;
JNIEnv** env;
jobject j_draw; /* global ref; free it! */
MPSLOT
} AndDraw;
@ -105,7 +105,7 @@ and_draw_scoreBegin( DrawCtx* dctx, const XP_Rect* rect,
XP_S16 remCount, DrawFocusState dfs )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;I[III)V";
jmethodID mid = getMethodID( env, draw->j_draw, "scoreBegin", sig );
@ -130,7 +130,7 @@ and_draw_measureRemText( DrawCtx* dctx, const XP_Rect* r,
XP_U16* width, XP_U16* height )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;I[I[I)V";
jmethodID mid = getMethodID( env, draw->j_draw, "measureRemText", sig );
@ -154,7 +154,7 @@ and_draw_measureScoreText( DrawCtx* dctx,
XP_U16* width, XP_U16* height )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
jobject jrect = makeJRect( env, r );
jobject jdsi = makeDSI( env, dsi );
@ -181,7 +181,7 @@ and_draw_drawRemText( DrawCtx* dctx, const XP_Rect* rInner,
XP_S16 nTilesLeft, XP_Bool focussed )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;Landroid/graphics/Rect;IZ)V";
jmethodID mid = getMethodID( env, draw->j_draw, "drawRemText", sig );
@ -202,7 +202,7 @@ and_draw_score_drawPlayer( DrawCtx* dctx,
const DrawScoreInfo* dsi )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;Landroid/graphics/Rect;"
"Lorg/eehouse/android/xw4/jni/DrawScoreInfo;)V";
jmethodID mid = getMethodID( env, draw->j_draw, "score_drawPlayer", sig );
@ -230,7 +230,7 @@ and_draw_drawCell( DrawCtx* dctx, const XP_Rect* rect, const XP_UCHAR* text,
XWBonusType bonus, HintAtts hintAtts, CellFlags flags )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;Ljava/lang/String;"
"[Ljava/lang/Object;IIIII)Z";
@ -260,7 +260,7 @@ and_draw_drawBoardArrow(DrawCtx* dctx, const XP_Rect* rect, XWBonusType bonus,
XP_Bool vert, HintAtts hintAtts, CellFlags flags )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;IZII)V";
jmethodID mid = getMethodID( env, draw->j_draw, "drawBoardArrow", sig );
@ -276,7 +276,7 @@ and_draw_vertScrollBoard( DrawCtx* dctx, XP_Rect* rect, XP_S16 dist,
{
LOG_FUNC();
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;II)Z";
jmethodID mid = getMethodID( env, draw->j_draw, "vertScrollBoard", sig );
jobject jrect = makeJRect( env, rect );
@ -293,7 +293,7 @@ and_draw_trayBegin( DrawCtx* dctx, const XP_Rect* rect, XP_U16 owner,
DrawFocusState dfs )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;II)Z";
jmethodID mid = getMethodID( env, draw->j_draw, "trayBegin", sig );
@ -312,7 +312,7 @@ and_draw_drawTile( DrawCtx* dctx, const XP_Rect* rect, const XP_UCHAR* text,
const XP_Bitmaps* bitmaps, XP_U16 val, CellFlags flags )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;Ljava/lang/String;"
"[Ljava/lang/Object;II)V";
jmethodID mid = getMethodID( env, draw->j_draw, "drawTile", sig );
@ -338,7 +338,7 @@ and_draw_drawTileMidDrag( DrawCtx* dctx, const XP_Rect* rect,
XP_U16 val, XP_U16 owner, CellFlags flags )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;Ljava/lang/String;"
"[Ljava/lang/Object;III)V";
jmethodID mid = getMethodID( env, draw->j_draw, "drawTileMidDrag", sig );
@ -362,7 +362,7 @@ static void
and_draw_drawTileBack( DrawCtx* dctx, const XP_Rect* rect, CellFlags flags )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;I)V";
jmethodID mid = getMethodID( env, draw->j_draw, "drawTileBack", sig );
@ -378,7 +378,7 @@ static void
and_draw_drawTrayDivider( DrawCtx* dctx, const XP_Rect* rect, CellFlags flags )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;I)V";
jmethodID mid = getMethodID( env, draw->j_draw, "drawTrayDivider", sig );
@ -396,7 +396,7 @@ and_draw_score_pendingScore( DrawCtx* dctx, const XP_Rect* rect,
CellFlags flags )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
const char* sig = "(Landroid/graphics/Rect;III)V";
jmethodID mid = getMethodID( env, draw->j_draw, "score_pendingScore", sig );
@ -450,12 +450,13 @@ draw_doNothing( DrawCtx* dctx, ... )
} /* draw_doNothing */
DrawCtx*
makeDraw( MPFORMAL JNIEnv *env, jobject j_draw )
makeDraw( MPFORMAL JNIEnv** envp, jobject j_draw )
{
AndDraw* draw = (AndDraw*)XP_CALLOC( mpool, sizeof(*draw) );
JNIEnv* env = *envp;
draw->vtable = XP_MALLOC( mpool, sizeof(*draw->vtable) );
draw->j_draw = (*env)->NewGlobalRef( env, j_draw );
draw->env = env;
draw->env = envp;
MPASSIGN( draw->mpool, mpool );
int ii;
@ -497,7 +498,7 @@ void
destroyDraw( DrawCtx* dctx )
{
AndDraw* draw = (AndDraw*)dctx;
JNIEnv* env = draw->env;
JNIEnv* env = *draw->env;
(*env)->DeleteGlobalRef( env, draw->j_draw );
XP_FREE( draw->mpool, draw->vtable );
XP_FREE( draw->mpool, draw );

View file

@ -25,8 +25,7 @@
#include "draw.h"
DrawCtx* makeDraw( MPFORMAL JNIEnv *env, jobject j_draw );
DrawCtx* makeDraw( MPFORMAL JNIEnv** env, jobject j_draw );
void destroyDraw( DrawCtx* dctx );

View file

@ -28,7 +28,7 @@ typedef struct _TimerStorage {
typedef struct _AndUtil {
XW_UtilCtxt util;
JNIEnv* env;
JNIEnv** env;
jobject j_util; /* global ref to object implementing XW_UtilCtxt */
TimerStorage timerStorage[NUM_TIMERS_PLUS_ONE];
} AndUtil;
@ -37,7 +37,6 @@ typedef struct _AndUtil {
static VTableMgr*
and_util_getVTManager( XW_UtilCtxt* uc )
{
LOG_FUNC();
AndGlobals* globals = (AndGlobals*)uc->closure;
return globals->vtMgr;
}
@ -54,7 +53,7 @@ static XWBonusType and_util_getSquareBonus( XW_UtilCtxt* uc,
XP_U16 col, XP_U16 row )
{
AndUtil* util = (AndUtil*)uc;
JNIEnv* env = util->env;
JNIEnv* env = *util->env;
const char* sig = "(II)I";
jmethodID mid = getMethodID( env, util->j_util, "getSquareBonus", sig );
return (*env)->CallIntMethod( env, util->j_util, mid,
@ -78,8 +77,25 @@ static XP_S16
and_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* pi,
XP_U16 playerNum, const XP_UCHAR** texts, XP_U16 nTiles )
{
LOG_FUNC();
}
XP_S16 result = -1;
AndUtil* util = (AndUtil*)uc;
JNIEnv* env = *util->env;
const char* sig = "(I[Ljava/lang/String;)I";
jmethodID mid = getMethodID( env, util->j_util, "userPickTile", sig );
#ifdef FEATURE_TRAY_EDIT
++error; /* need to pass pi if this is on */
#endif
jobject jtexts = makeStringArray( env, nTiles, texts );
result = (*env)->CallIntMethod( env, util->j_util, mid,
playerNum, jtexts );
(*env)->DeleteLocalRef( env, jtexts );
return result;
} /* and_util_userPickTile */
static XP_Bool
@ -102,7 +118,7 @@ and_util_yOffsetChange(XW_UtilCtxt* uc, XP_U16 oldOffset, XP_U16 newOffset )
{
#if 0
AndUtil* util = (AndUtil*)uc;
JNIEnv* env = util->env;
JNIEnv* env = *util->env;
const char* sig = "(II)V";
jmethodID mid = getMethodID( env, util->j_util, "yOffsetChange", sig );
@ -155,7 +171,7 @@ and_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why, XP_U16 when,
XWTimerProc proc, void* closure )
{
AndUtil* util = (AndUtil*)uc;
JNIEnv* env = util->env;
JNIEnv* env = *util->env;
const char* sig = "(III)V";
jmethodID mid = getMethodID( env, util->j_util, "setTimer", sig );
@ -171,7 +187,7 @@ static void
and_util_clearTimer( XW_UtilCtxt* uc, XWTimerReason why )
{
AndUtil* util = (AndUtil*)uc;
JNIEnv* env = util->env;
JNIEnv* env = *util->env;
const char* sig = "(I)V";
jmethodID mid = getMethodID( env, util->j_util, "clearTimer", sig );
(*env)->CallVoidMethod( env, util->j_util, mid, why );
@ -182,7 +198,7 @@ static void
and_util_requestTime( XW_UtilCtxt* uc )
{
AndUtil* util = (AndUtil*)uc;
JNIEnv* env = util->env;
JNIEnv* env = *util->env;
const char* sig = "()V";
jmethodID mid = getMethodID( env, util->j_util, "requestTime", sig );
(*env)->CallVoidMethod( env, util->j_util, mid );
@ -268,12 +284,13 @@ and_util_engineStopping( XW_UtilCtxt* uc )
XW_UtilCtxt*
makeUtil( MPFORMAL JNIEnv *env, jobject j_util, CurGameInfo* gi,
makeUtil( MPFORMAL JNIEnv** envp, jobject j_util, CurGameInfo* gi,
AndGlobals* closure )
{
AndUtil* util = (AndUtil*)XP_CALLOC( mpool, sizeof(*util) );
UtilVtable* vtable = (UtilVtable*)XP_CALLOC( mpool, sizeof(*vtable) );
util->env = env;
util->env = envp;
JNIEnv* env = *envp;
util->j_util = (*env)->NewGlobalRef( env, j_util );
util->util.vtable = vtable;
MPASSIGN( util->util.mpool, mpool );
@ -327,7 +344,7 @@ void
destroyUtil( XW_UtilCtxt* utilc )
{
AndUtil* util = (AndUtil*)utilc;
JNIEnv *env = util->env;
JNIEnv *env = *util->env;
(*env)->DeleteGlobalRef( env, util->j_util );
XP_FREE( util->util.mpool, util->util.vtable );
XP_FREE( util->util.mpool, util );

View file

@ -27,7 +27,7 @@
#include "util.h"
#include "andglobals.h"
XW_UtilCtxt* makeUtil( MPFORMAL JNIEnv *env, jobject j_util,
XW_UtilCtxt* makeUtil( MPFORMAL JNIEnv** env, jobject j_util,
CurGameInfo* gi, AndGlobals* globals );
void destroyUtil( XW_UtilCtxt* util );