Skip to content

Commit 46151a5

Browse files
committed
Make it all 64bit safe
1 parent 68a080b commit 46151a5

File tree

7 files changed

+46
-32
lines changed

7 files changed

+46
-32
lines changed

bgjslibrary/jni/bgjs/BGJSContext.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ void BGJSContext::cancelAnimationFrame(int id) {
625625
&& request->view != NULL) {
626626
request->valid = false;
627627
request->callback.Dispose();
628+
request->thisObj.Dispose();
628629
#ifdef DEBUG
629630
LOGD("cancelAnimationFrame cancelled id %d", request->requestId);
630631
#endif
@@ -666,7 +667,7 @@ bool BGJSContext::runAnimationRequests(BGJSGLView* view) {
666667
request->view->prepareRedraw();
667668
Handle<Value> args[0];
668669
Handle<Value> result = request->callback->CallAsFunction(
669-
_context->Global(), 0, args);
670+
request->thisObj, 0, args);
670671

671672
if (result.IsEmpty()) {
672673
LOGE("Exception occured while running runAnimationRequest cb");
@@ -678,6 +679,7 @@ bool BGJSContext::runAnimationRequests(BGJSGLView* view) {
678679
LOGD("runAnimation number %d %s", index, *fnName);
679680
#endif
680681
request->callback.Dispose();
682+
request->thisObj.Dispose();
681683

682684
request->view->endRedraw();
683685
request->valid = false;
@@ -763,10 +765,16 @@ Handle<Value> BGJSContext::js_global_requestAnimationFrame(
763765
Handle<Object> objRef = args[1]->ToObject();
764766
BGJSGLView* view = static_cast<BGJSGLView *>(External::Unwrap(
765767
objRef->GetInternalField(0)));
768+
Persistent<Object> thisObj = Persistent<Object>::New(args.This());
766769
if (func->IsFunction()) {
767-
int id = view->requestAnimationFrameForView(func,
770+
#ifdef DEBUG
771+
LOGD("requestAnimationFrame: on BGJSGLView %p, %p", view, &thisObj);
772+
#endif
773+
int id = view->requestAnimationFrameForView(func, thisObj,
768774
(ctx->_nextTimerId)++);
769775
return scope.Close(Integer::New(id));
776+
} else {
777+
LOGI("requestAnimationFrame: Not a function");
770778
}
771779
} else {
772780
LOGI("requestAnimationFrame: Wrong number or type of parameters");

bgjslibrary/jni/bgjs/BGJSGLView.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void BGJSGLView::requestRefresh() {
156156
#endif
157157
}
158158

159-
int BGJSGLView::requestAnimationFrameForView(Persistent<Object> cb,
159+
int BGJSGLView::requestAnimationFrameForView(Persistent<Object> cb, Persistent<Object> thisObj,
160160
int id) {
161161
// make sure there is still room in the buffer
162162
#ifdef DEBUG
@@ -173,6 +173,7 @@ int BGJSGLView::requestAnimationFrameForView(Persistent<Object> cb,
173173
request->callback = cb;
174174
request->view = this;
175175
request->valid = true;
176+
request->thisObj = thisObj;
176177
request->requestId = id;
177178
_nextFrameRequest = (_nextFrameRequest + 1) % MAX_FRAME_REQUESTS;
178179

bgjslibrary/jni/bgjs/BGJSGLView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
typedef struct __tagAnimationFrameRequest {
1111
BGJSGLView *view;
1212
v8::Persistent<v8::Object> callback;
13+
v8::Persistent<v8::Object> thisObj;
1314
bool valid;
1415
int requestId;
1516
} AnimationFrameRequest;
@@ -26,7 +27,7 @@ class BGJSGLView : public BGJSView {
2627
void resize (int width, int height, bool resizeOnly);
2728
void close ();
2829
void requestRefresh();
29-
int requestAnimationFrameForView(v8::Persistent<v8::Object> cb, int id);
30+
int requestAnimationFrameForView(v8::Persistent<v8::Object> cb, v8::Persistent<v8::Object> thisObj, int id);
3031
#ifdef ANDROID
3132
void setJavaGl(JNIEnv* env, jobject javaGlView);
3233
#endif

bgjslibrary/jni/bgjs/jniext.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@ extern "C" {
99
jobject obj, jlong ctxPtr, jstring path);
1010
JNIEXPORT bool JNICALL Java_ag_boersego_bgjs_ClientAndroid_ajaxSuccess(
1111
JNIEnv * env, jobject obj, jlong ctxPtr, jstring data,
12-
jint responseCode, jint cbPtr, jint thisPtr);
12+
jint responseCode, jlong cbPtr, jlong thisPtr);
1313
JNIEXPORT void JNICALL Java_ag_boersego_bgjs_ClientAndroid_run(JNIEnv * env,
1414
jobject obj, jlong ctxPtr);
1515
JNIEXPORT void JNICALL Java_ag_boersego_bgjs_ClientAndroid_timeoutCB(
1616
JNIEnv * env, jobject obj, jlong ctxPtr, jlong jsCbPtr, jlong thisPtr, jboolean cleanup, jboolean runCb);
1717
JNIEXPORT void JNICALL Java_ag_boersego_bgjs_ClientAndroid_runCBBoolean (JNIEnv * env, jobject obj, jlong ctxPtr, jlong cbPtr, jlong thisPtr, jboolean b);
1818

1919
// BGJSGLModule
20-
JNIEXPORT jint JNICALL Java_ag_boersego_bgjs_ClientAndroid_createGL(JNIEnv * env,
20+
JNIEXPORT jlong JNICALL Java_ag_boersego_bgjs_ClientAndroid_createGL(JNIEnv * env,
2121
jobject obj, jlong ctxPtr, jobject javaGlView, jfloat pixelRatio, jboolean noClearOnFlip);
2222
JNIEXPORT bool JNICALL Java_ag_boersego_bgjs_ClientAndroid_step(JNIEnv * env,
23-
jobject obj, jlong ctxPtr, jint jsPtr);
23+
jobject obj, jlong ctxPtr, jlong jsPtr);
2424
JNIEXPORT int JNICALL Java_ag_boersego_bgjs_ClientAndroid_init(JNIEnv * env,
25-
jobject obj, jlong ctxPtr, jint objPtr, jint width, jint height, jstring callbackName);
25+
jobject obj, jlong ctxPtr, jlong objPtr, jint width, jint height, jstring callbackName);
2626
JNIEXPORT void JNICALL Java_ag_boersego_bgjs_ClientAndroid_setTouchPosition(JNIEnv * env,
27-
jobject obj, jlong ctxPtr, jint jsPtr, jint x, jint y);
27+
jobject obj, jlong ctxPtr, jlong jsPtr, jint x, jint y);
2828
JNIEXPORT void JNICALL Java_ag_boersego_bgjs_ClientAndroid_sendTouchEvent(
29-
JNIEnv * env, jobject obj, jlong ctxPtr, jint objPtr, jstring typeStr,
29+
JNIEnv * env, jobject obj, jlong ctxPtr, jlong objPtr, jstring typeStr,
3030
jfloatArray xArr, jfloatArray yArr, jfloat scale);
3131
JNIEXPORT void JNICALL Java_ag_boersego_bgjs_ClientAndroid_close(JNIEnv * env,
32-
jobject obj, jlong ctxPtr, jint jsPtr);
32+
jobject obj, jlong ctxPtr, jlong jsPtr);
3333
JNIEXPORT void JNICALL Java_ag_boersego_bgjs_ClientAndroid_redraw(JNIEnv * env,
34-
jobject obj, jlong ctxPtr, jint jsPtr);
34+
jobject obj, jlong ctxPtr, jlong jsPtr);
3535
};
3636

3737
#endif

bgjslibrary/jni/bgjs/modules/BGJSGLModule.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ static void checkGlError(const char* op) {
10871087
}
10881088
}
10891089

1090-
JNIEXPORT jint JNICALL Java_ag_boersego_bgjs_ClientAndroid_createGL(JNIEnv * env,
1090+
JNIEXPORT jlong JNICALL Java_ag_boersego_bgjs_ClientAndroid_createGL(JNIEnv * env,
10911091
jobject obj, jlong ctxPtr, jobject javaGlView, jfloat pixelRatio, jboolean noClearOnFlip) {
10921092

10931093
v8::Locker l;
@@ -1103,11 +1103,11 @@ JNIEXPORT jint JNICALL Java_ag_boersego_bgjs_ClientAndroid_createGL(JNIEnv * env
11031103
// Register GLView with context so that cancelAnimationRequest works.
11041104
ct->registerGLView(view);
11051105

1106-
return (jint) view;
1106+
return (jlong) view;
11071107
}
11081108

11091109
JNIEXPORT int JNICALL Java_ag_boersego_bgjs_ClientAndroid_init(JNIEnv * env,
1110-
jobject obj, jlong ctxPtr, jint objPtr, jint width, jint height, jstring callbackName) {
1110+
jobject obj, jlong ctxPtr, jlong objPtr, jint width, jint height, jstring callbackName) {
11111111
v8::Locker l;
11121112
HandleScope scope;
11131113

@@ -1150,7 +1150,7 @@ JNIEXPORT int JNICALL Java_ag_boersego_bgjs_ClientAndroid_init(JNIEnv * env,
11501150
}
11511151

11521152
JNIEXPORT void JNICALL Java_ag_boersego_bgjs_ClientAndroid_close(JNIEnv * env,
1153-
jobject obj, jlong ctxPtr, jint objPtr) {
1153+
jobject obj, jlong ctxPtr, jlong objPtr) {
11541154
v8::Locker l;
11551155
HandleScope scope;
11561156

@@ -1168,22 +1168,22 @@ JNIEXPORT void JNICALL Java_ag_boersego_bgjs_ClientAndroid_close(JNIEnv * env,
11681168
const GLfloat gTriangleVertices[] = { 0.0f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f };
11691169

11701170
JNIEXPORT bool JNICALL Java_ag_boersego_bgjs_ClientAndroid_step(JNIEnv * env,
1171-
jobject obj, jlong ctxPtr, jint jsPtr) {
1171+
jobject obj, jlong ctxPtr, jlong jsPtr) {
11721172
BGJSContext* ct = (BGJSContext*) ctxPtr;
11731173
BGJSGLView *view = (BGJSGLView*) jsPtr;
11741174
return BGJSGLModule::_bgjscontext->runAnimationRequests(view);
11751175
}
11761176

11771177
JNIEXPORT void JNICALL Java_ag_boersego_bgjs_ClientAndroid_redraw(JNIEnv * env,
1178-
jobject obj, jlong ctxPtr, jint jsPtr) {
1178+
jobject obj, jlong ctxPtr, jlong jsPtr) {
11791179
BGJSContext* ct = (BGJSContext*) ctxPtr;
11801180
BGJSGLView *view = (BGJSGLView*) jsPtr;
11811181
return view->call(view->_cbRedraw);
11821182
}
11831183

11841184

11851185
JNIEXPORT void JNICALL Java_ag_boersego_bgjs_ClientAndroid_sendTouchEvent(
1186-
JNIEnv * env, jobject obj, jlong ctxPtr, jint objPtr, jstring typeStr,
1186+
JNIEnv * env, jobject obj, jlong ctxPtr, jlong objPtr, jstring typeStr,
11871187
jfloatArray xArr, jfloatArray yArr, jfloat scale) {
11881188
v8::Locker l;
11891189
HandleScope scope;

bgjslibrary/src/main/java/ag/boersego/bgjs/ClientAndroid.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ public class ClientAndroid {
1414
public static native boolean ajaxDone(long ctxPtr, String data, int responseCode, long jsCbPtr, long thisObj, long errorCb, boolean success, boolean processData);
1515

1616
// BGJSGLModule
17-
public static native int createGL(long ctxPtr, V8TextureView gl2jniView, float pixelRatio, boolean noClearOnFlip);
18-
public static native int init(long ctxPtr, int objPtr, int width, int height, String callbackName);
19-
public static native boolean step(long ctxPtr, int jsPtr);
20-
public static native void setTouchPosition(long ctxPtr, int jsPtr, int x, int y);
21-
public static native void sendTouchEvent(long ctxPtr, int objPtr, String typeStr,
17+
public static native long createGL(long ctxPtr, V8TextureView gl2jniView, float pixelRatio, boolean noClearOnFlip);
18+
public static native int init(long ctxPtr, long objPtr, int width, int height, String callbackName);
19+
public static native boolean step(long ctxPtr, long jsPtr);
20+
public static native void setTouchPosition(long ctxPtr, long jsPtr, int x, int y);
21+
public static native void sendTouchEvent(long ctxPtr, long objPtr, String typeStr,
2222
float[] xArr, float[] yArr, float scale);
23-
public static native void redraw (long ctxPtr, int jsPtr);
24-
public static native void close(long ctxPtr, int jsPtr);
23+
public static native void redraw (long ctxPtr, long jsPtr);
24+
public static native void close(long ctxPtr, long jsPtr);
2525

2626
// BGJSModule
2727
public static native void cleanupNativeFnPtr (long nativePtr);

bgjslibrary/src/main/java/ag/boersego/bgjs/V8TextureView.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ public void doDebug(boolean debug) {
7373
DEBUG = debug;
7474
}
7575

76-
abstract public void onGLCreated (int jsId);
76+
abstract public void onGLCreated (long jsId);
7777

78-
abstract public void onGLRecreated (int jsId);
78+
abstract public void onGLRecreated (long jsId);
7979

8080
abstract public void onGLCreateError (Exception ex);
8181

82-
abstract public void onRenderAttentionNeeded (int jsId);
82+
abstract public void onRenderAttentionNeeded (long jsId);
8383

8484
public void doNeedAttention(boolean b) {
8585
mRenderThread.setNeedAttention(b);
@@ -507,7 +507,7 @@ public void unpause() {
507507
* Create the JNI side of OpenGL init. Can be overriden by subclasses to instantiate other BGJSGLView subclasses
508508
* @return pointer to JNI object
509509
*/
510-
protected int createGL () {
510+
protected long createGL () {
511511
return ClientAndroid.createGL(V8Engine.getInstance().getNativePtr(), this, mScaling, false);
512512
}
513513

@@ -531,7 +531,7 @@ private class RenderThread extends Thread {
531531
private EGLSurface mEglSurface;
532532

533533

534-
private int mJSId;
534+
private long mJSId;
535535

536536
private long mLastRenderSec; // Used to calculate FPS
537537
private int mRenderCnt;
@@ -589,7 +589,7 @@ public void requestRender() {
589589
mRenderPending = true;
590590
this.notifyAll();
591591
if (DEBUG) {
592-
Log.d(TAG, "Requested render");
592+
Log.d(TAG, "Requested render mJSID " + String.format("0x%8s", Long.toHexString(mJSId)).replace(' ', '0'));
593593
}
594594
}
595595
}
@@ -685,6 +685,10 @@ public void run() {
685685

686686
final boolean didDraw = ClientAndroid.step(V8Engine.getInstance().getNativePtr(), mJSId);
687687

688+
if (DEBUG) {
689+
Log.d(TAG, "Draw for JSID " + String.format("0x%8s", Long.toHexString(mJSId)).replace(' ', '0') + ", TV " + V8TextureView.this);
690+
}
691+
688692
mRenderCnt++;
689693

690694
// We don't swap buffers here. Because we don't want to clear buffers on buffer swap, we need to do it in native code.

0 commit comments

Comments
 (0)