diff --git a/java/org/gnu/emacs/EmacsActivity.java b/java/org/gnu/emacs/EmacsActivity.java index 28bb6e4c065..90be9a385cf 100644 --- a/java/org/gnu/emacs/EmacsActivity.java +++ b/java/org/gnu/emacs/EmacsActivity.java @@ -440,8 +440,7 @@ public class EmacsActivity extends Activity if (!EmacsContextMenu.itemAlreadySelected) { serial = EmacsContextMenu.lastMenuEventSerial; - EmacsNative.sendContextMenu ((short) 0, 0, - serial); + EmacsNative.sendContextMenu (0, 0, serial); } super.onContextMenuClosed (menu); diff --git a/java/org/gnu/emacs/EmacsContextMenu.java b/java/org/gnu/emacs/EmacsContextMenu.java index 0f52d45455f..365a7ec40af 100644 --- a/java/org/gnu/emacs/EmacsContextMenu.java +++ b/java/org/gnu/emacs/EmacsContextMenu.java @@ -121,8 +121,7 @@ public final class EmacsContextMenu } /* Send a context menu event. */ - EmacsNative.sendContextMenu ((short) 0, itemID, - lastMenuEventSerial); + EmacsNative.sendContextMenu (0, itemID, lastMenuEventSerial); /* Say that an item has already been selected. */ itemAlreadySelected = true; diff --git a/java/org/gnu/emacs/EmacsCursor.java b/java/org/gnu/emacs/EmacsCursor.java index 1049c03d7da..e5f22c23cfc 100644 --- a/java/org/gnu/emacs/EmacsCursor.java +++ b/java/org/gnu/emacs/EmacsCursor.java @@ -31,9 +31,9 @@ public final class EmacsCursor extends EmacsHandleObject public final PointerIcon icon; public - EmacsCursor (short handle, int glyph) + EmacsCursor (int glyph) { - super (handle); + super (); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { diff --git a/java/org/gnu/emacs/EmacsDialog.java b/java/org/gnu/emacs/EmacsDialog.java index 0d5b650f7d0..31b2969197e 100644 --- a/java/org/gnu/emacs/EmacsDialog.java +++ b/java/org/gnu/emacs/EmacsDialog.java @@ -93,7 +93,7 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener onClick (View view) { wasButtonClicked = true; - EmacsNative.sendContextMenu ((short) 0, id, menuEventSerial); + EmacsNative.sendContextMenu (0, id, menuEventSerial); dismissDialog.dismiss (); } @@ -102,7 +102,7 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener onClick (DialogInterface dialog, int which) { wasButtonClicked = true; - EmacsNative.sendContextMenu ((short) 0, id, menuEventSerial); + EmacsNative.sendContextMenu (0, id, menuEventSerial); } }; @@ -414,6 +414,6 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener if (wasButtonClicked) return; - EmacsNative.sendContextMenu ((short) 0, 0, menuEventSerial); + EmacsNative.sendContextMenu (0, 0, menuEventSerial); } }; diff --git a/java/org/gnu/emacs/EmacsGC.java b/java/org/gnu/emacs/EmacsGC.java index bb11f76c800..f956b230f8c 100644 --- a/java/org/gnu/emacs/EmacsGC.java +++ b/java/org/gnu/emacs/EmacsGC.java @@ -71,13 +71,13 @@ public final class EmacsGC extends EmacsHandleObject /* The following fields are only set on immutable GCs. */ public - EmacsGC (short handle) + EmacsGC () { /* For historical reasons the C code has an extra layer of indirection above this GC handle. struct android_gc is the GC used by Emacs code, while android_gcontext is the type of the handle. */ - super (handle); + super (); fill_style = GC_FILL_SOLID; function = GC_COPY; diff --git a/java/org/gnu/emacs/EmacsHandleObject.java b/java/org/gnu/emacs/EmacsHandleObject.java index 8534f08519c..cbd579bac5b 100644 --- a/java/org/gnu/emacs/EmacsHandleObject.java +++ b/java/org/gnu/emacs/EmacsHandleObject.java @@ -33,14 +33,9 @@ public abstract class EmacsHandleObject /* Whether or not this handle has been destroyed. */ volatile boolean destroyed; - /* The handle associated with this object. */ - public short handle; - - public - EmacsHandleObject (short handle) - { - this.handle = handle; - } + /* The handle associated with this object, set in + android_globalize_reference. */ + public long handle; public void destroyHandle () throws IllegalStateException diff --git a/java/org/gnu/emacs/EmacsInputConnection.java b/java/org/gnu/emacs/EmacsInputConnection.java index 054eca66cf3..5b409fa1f57 100644 --- a/java/org/gnu/emacs/EmacsInputConnection.java +++ b/java/org/gnu/emacs/EmacsInputConnection.java @@ -48,7 +48,7 @@ public final class EmacsInputConnection implements InputConnection private EmacsView view; /* The handle ID associated with that view's window. */ - private short windowHandle; + private long windowHandle; /* Number of batch edits currently underway. Used to avoid synchronizing with the Emacs thread after each diff --git a/java/org/gnu/emacs/EmacsNative.java b/java/org/gnu/emacs/EmacsNative.java index acf9e4b204b..b2764edad10 100644 --- a/java/org/gnu/emacs/EmacsNative.java +++ b/java/org/gnu/emacs/EmacsNative.java @@ -108,92 +108,92 @@ public final class EmacsNative /* Send an ANDROID_CONFIGURE_NOTIFY event. The values of all the functions below are the serials of the events sent. */ - public static native long sendConfigureNotify (short window, long time, + public static native long sendConfigureNotify (long window, long time, int x, int y, int width, int height); /* Send an ANDROID_KEY_PRESS event. */ - public static native long sendKeyPress (short window, long time, int state, + public static native long sendKeyPress (long window, long time, int state, int keyCode, int unicodeChar); /* Send an ANDROID_KEY_RELEASE event. */ - public static native long sendKeyRelease (short window, long time, int state, + public static native long sendKeyRelease (long window, long time, int state, int keyCode, int unicodeChar); /* Send an ANDROID_FOCUS_IN event. */ - public static native long sendFocusIn (short window, long time); + public static native long sendFocusIn (long window, long time); /* Send an ANDROID_FOCUS_OUT event. */ - public static native long sendFocusOut (short window, long time); + public static native long sendFocusOut (long window, long time); /* Send an ANDROID_WINDOW_ACTION event. */ - public static native long sendWindowAction (short window, int action); + public static native long sendWindowAction (long window, int action); /* Send an ANDROID_ENTER_NOTIFY event. */ - public static native long sendEnterNotify (short window, int x, int y, + public static native long sendEnterNotify (long window, int x, int y, long time); /* Send an ANDROID_LEAVE_NOTIFY event. */ - public static native long sendLeaveNotify (short window, int x, int y, + public static native long sendLeaveNotify (long window, int x, int y, long time); /* Send an ANDROID_MOTION_NOTIFY event. */ - public static native long sendMotionNotify (short window, int x, int y, + public static native long sendMotionNotify (long window, int x, int y, long time); /* Send an ANDROID_BUTTON_PRESS event. */ - public static native long sendButtonPress (short window, int x, int y, + public static native long sendButtonPress (long window, int x, int y, long time, int state, int button); /* Send an ANDROID_BUTTON_RELEASE event. */ - public static native long sendButtonRelease (short window, int x, int y, + public static native long sendButtonRelease (long window, int x, int y, long time, int state, int button); /* Send an ANDROID_TOUCH_DOWN event. */ - public static native long sendTouchDown (short window, int x, int y, + public static native long sendTouchDown (long window, int x, int y, long time, int pointerID, int flags); /* Send an ANDROID_TOUCH_UP event. */ - public static native long sendTouchUp (short window, int x, int y, + public static native long sendTouchUp (long window, int x, int y, long time, int pointerID, int flags); /* Send an ANDROID_TOUCH_MOVE event. */ - public static native long sendTouchMove (short window, int x, int y, + public static native long sendTouchMove (long window, int x, int y, long time, int pointerID, int flags); /* Send an ANDROID_WHEEL event. */ - public static native long sendWheel (short window, int x, int y, + public static native long sendWheel (long window, int x, int y, long time, int state, float xDelta, float yDelta); /* Send an ANDROID_ICONIFIED event. */ - public static native long sendIconified (short window); + public static native long sendIconified (long window); /* Send an ANDROID_DEICONIFIED event. */ - public static native long sendDeiconified (short window); + public static native long sendDeiconified (long window); /* Send an ANDROID_CONTEXT_MENU event. */ - public static native long sendContextMenu (short window, int menuEventID, + public static native long sendContextMenu (long window, int menuEventID, int menuEventSerial); /* Send an ANDROID_EXPOSE event. */ - public static native long sendExpose (short window, int x, int y, + public static native long sendExpose (long window, int x, int y, int width, int height); /* Send an ANDROID_DND_DRAG event. */ - public static native long sendDndDrag (short window, int x, int y); + public static native long sendDndDrag (long window, int x, int y); /* Send an ANDROID_DND_URI event. */ - public static native long sendDndUri (short window, int x, int y, + public static native long sendDndUri (long window, int x, int y, String text); /* Send an ANDROID_DND_TEXT event. */ - public static native long sendDndText (short window, int x, int y, + public static native long sendDndText (long window, int x, int y, String text); /* Send an ANDROID_NOTIFICATION_CANCELED event. */ @@ -241,48 +241,48 @@ public final class EmacsNative /* Input connection functions. These mostly correspond to their counterparts in Android's InputConnection. */ - public static native void beginBatchEdit (short window); - public static native void endBatchEdit (short window); - public static native void commitCompletion (short window, String text, + public static native void beginBatchEdit (long window); + public static native void endBatchEdit (long window); + public static native void commitCompletion (long window, String text, int position); - public static native void commitText (short window, String text, + public static native void commitText (long window, String text, int position); - public static native void deleteSurroundingText (short window, + public static native void deleteSurroundingText (long window, int leftLength, int rightLength); - public static native void finishComposingText (short window); - public static native void replaceText (short window, int start, int end, + public static native void finishComposingText (long window); + public static native void replaceText (long window, int start, int end, String text, int newCursorPosition, TextAttribute attributes); - public static native String getSelectedText (short window, int flags); - public static native String getTextAfterCursor (short window, int length, + public static native String getSelectedText (long window, int flags); + public static native String getTextAfterCursor (long window, int length, int flags); - public static native String getTextBeforeCursor (short window, int length, + public static native String getTextBeforeCursor (long window, int length, int flags); - public static native void setComposingText (short window, String text, + public static native void setComposingText (long window, String text, int newCursorPosition); - public static native void setComposingRegion (short window, int start, + public static native void setComposingRegion (long window, int start, int end); - public static native void setSelection (short window, int start, int end); - public static native void performEditorAction (short window, + public static native void setSelection (long window, int start, int end); + public static native void performEditorAction (long window, int editorAction); - public static native void performContextMenuAction (short window, + public static native void performContextMenuAction (long window, int contextMenuAction); - public static native ExtractedText getExtractedText (short window, + public static native ExtractedText getExtractedText (long window, ExtractedTextRequest req, int flags); - public static native void requestSelectionUpdate (short window); - public static native void requestCursorUpdates (short window, int mode); - public static native void clearInputFlags (short window); - public static native SurroundingText getSurroundingText (short window, + public static native void requestSelectionUpdate (long window); + public static native void requestCursorUpdates (long window, int mode); + public static native void clearInputFlags (long window); + public static native SurroundingText getSurroundingText (long window, int left, int right, int flags); - public static native TextSnapshot takeSnapshot (short window); + public static native TextSnapshot takeSnapshot (long window); /* Return the current value of the selection, or -1 upon failure. */ - public static native int[] getSelection (short window); + public static native int[] getSelection (long window); /* Graphics functions used as replacements for potentially buggy diff --git a/java/org/gnu/emacs/EmacsPixmap.java b/java/org/gnu/emacs/EmacsPixmap.java index c621e2de3c5..bd4e085994e 100644 --- a/java/org/gnu/emacs/EmacsPixmap.java +++ b/java/org/gnu/emacs/EmacsPixmap.java @@ -51,9 +51,9 @@ public final class EmacsPixmap extends EmacsHandleObject private long gcClipRectID; public - EmacsPixmap (short handle, int width, int height, int depth) + EmacsPixmap (int width, int height, int depth) { - super (handle); + super (); if (depth != 1 && depth != 24) throw new IllegalArgumentException ("Invalid depth specified" diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index 8e459ce4cdc..ced9f599960 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java @@ -514,10 +514,10 @@ public final class EmacsService extends Service vibrator.vibrate (duration); } - public short[] + public long[] queryTree (EmacsWindow window) { - short[] array; + long[] array; List windowList; int i; @@ -529,7 +529,7 @@ public final class EmacsService extends Service synchronized (windowList) { - array = new short[windowList.size () + 1]; + array = new long[windowList.size () + 1]; i = 1; array[0] = (window == null @@ -846,7 +846,7 @@ public final class EmacsService extends Service } public static int[] - viewGetSelection (short window) + viewGetSelection (long window) { int[] selection; diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java index 961292af527..16ff00070c4 100644 --- a/java/org/gnu/emacs/EmacsWindow.java +++ b/java/org/gnu/emacs/EmacsWindow.java @@ -170,11 +170,9 @@ public final class EmacsWindow extends EmacsHandleObject public boolean preserve, previouslyAttached; public - EmacsWindow (short handle, final EmacsWindow parent, int x, int y, + EmacsWindow (final EmacsWindow parent, int x, int y, int width, int height, boolean overrideRedirect) { - super (handle); - rect = new Rect (x, y, x + width, y + height); pointerMap = new SparseArray (); @@ -205,7 +203,7 @@ public final class EmacsWindow extends EmacsHandleObject }); } - scratchGC = new EmacsGC ((short) 0); + scratchGC = new EmacsGC (); /* Create the map of input method-committed strings. Keep at most ten strings in the map. */ diff --git a/java/org/gnu/emacs/EmacsWindowManager.java b/java/org/gnu/emacs/EmacsWindowManager.java index 49f0ebd5841..23dc71dbd29 100644 --- a/java/org/gnu/emacs/EmacsWindowManager.java +++ b/java/org/gnu/emacs/EmacsWindowManager.java @@ -145,7 +145,7 @@ public final class EmacsWindowManager } } - EmacsNative.sendWindowAction ((short) 0, 0); + EmacsNative.sendWindowAction (0, 0); } public synchronized void diff --git a/src/android.c b/src/android.c index c76afdb9bf2..0dd7702b301 100644 --- a/src/android.c +++ b/src/android.c @@ -129,6 +129,13 @@ struct android_key_character_map jmethodID get_dead_char; }; +struct android_emacs_handle +{ + jclass class; + jmethodID destroy_handle; + jfieldID handle; +}; + /* The API level of the current device. */ static int android_api_level; @@ -214,6 +221,10 @@ static struct android_emacs_cursor cursor_class; /* Various methods associated with the KeyCharacterMap class. */ static struct android_key_character_map key_character_map_class; +/* Various methods and fields associated with the EmacsHandleObject + class. */ +static struct android_emacs_handle handle_class; + /* The time at which Emacs was installed, which also supplies the mtime of asset files. */ struct timespec emacs_installation_time; @@ -1620,7 +1631,7 @@ android_init_emacs_service (void) "Lorg/gnu/emacs/EmacsGC;II)V"); FIND_METHOD (ring_bell, "ringBell", "(I)V"); FIND_METHOD (query_tree, "queryTree", - "(Lorg/gnu/emacs/EmacsWindow;)[S"); + "(Lorg/gnu/emacs/EmacsWindow;)[J"); FIND_METHOD (get_screen_width, "getScreenWidth", "(Z)I"); FIND_METHOD (get_screen_height, "getScreenHeight", "(Z)I"); FIND_METHOD (detect_mouse, "detectMouse", "()Z"); @@ -1723,7 +1734,7 @@ android_init_emacs_pixmap (void) name, signature); \ eassert (pixmap_class.c_name); - FIND_METHOD (constructor_mutable, "", "(SIII)V"); + FIND_METHOD (constructor_mutable, "", "(III)V"); #undef FIND_METHOD } @@ -1876,7 +1887,7 @@ android_init_emacs_cursor (void) name, signature); \ eassert (cursor_class.c_name); - FIND_METHOD (constructor, "", "(SI)V"); + FIND_METHOD (constructor, "", "(I)V"); #undef FIND_METHOD } @@ -1906,6 +1917,42 @@ android_init_key_character_map (void) eassert (key_character_map_class.get_dead_char); } +static void +android_init_emacs_handle (void) +{ + jclass old; + + handle_class.class + = (*android_java_env)->FindClass (android_java_env, + "org/gnu/emacs/EmacsHandleObject"); + eassert (handle_class.class); + + old = handle_class.class; + handle_class.class + = (jclass) (*android_java_env)->NewGlobalRef (android_java_env, + (jobject) old); + ANDROID_DELETE_LOCAL_REF (old); + + if (!handle_class.class) + emacs_abort (); + +#define FIND_METHOD(c_name, name, signature) \ + handle_class.c_name \ + = (*android_java_env)->GetMethodID (android_java_env, \ + handle_class.class, \ + name, signature); \ + eassert (handle_class.c_name); + + FIND_METHOD (destroy_handle, "destroyHandle", "()V"); +#undef FIND_METHOD + + handle_class.handle + = (*android_java_env)->GetFieldID (android_java_env, + handle_class.class, + "handle", "J"); + eassert (handle_class.handle); +} + JNIEXPORT void JNICALL NATIVE_NAME (initEmacs) (JNIEnv *env, jobject object, jarray argv, jobject dump_file_object) @@ -1955,6 +2002,7 @@ NATIVE_NAME (initEmacs) (JNIEnv *env, jobject object, jarray argv, android_init_emacs_window (); android_init_emacs_cursor (); android_init_key_character_map (); + android_init_emacs_handle (); /* Set HOME to the app data directory. */ setenv ("HOME", android_files_dir, 1); @@ -2074,7 +2122,7 @@ NATIVE_NAME (onLowMemory) (JNIEnv *env, jobject object) JNIEXPORT jlong JNICALL NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object, - jshort window, jlong time, + jlong window, jlong time, jint x, jint y, jint width, jint height) { @@ -2097,7 +2145,7 @@ NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendKeyPress) (JNIEnv *env, jobject object, - jshort window, jlong time, + jlong window, jlong time, jint state, jint keycode, jint unicode_char) { @@ -2120,7 +2168,7 @@ NATIVE_NAME (sendKeyPress) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendKeyRelease) (JNIEnv *env, jobject object, - jshort window, jlong time, + jlong window, jlong time, jint state, jint keycode, jint unicode_char) { @@ -2143,7 +2191,7 @@ NATIVE_NAME (sendKeyRelease) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendFocusIn) (JNIEnv *env, jobject object, - jshort window, jlong time) + jlong window, jlong time) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2160,7 +2208,7 @@ NATIVE_NAME (sendFocusIn) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendFocusOut) (JNIEnv *env, jobject object, - jshort window, jlong time) + jlong window, jlong time) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2177,7 +2225,7 @@ NATIVE_NAME (sendFocusOut) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendWindowAction) (JNIEnv *env, jobject object, - jshort window, jint action) + jlong window, jint action) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2194,7 +2242,7 @@ NATIVE_NAME (sendWindowAction) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendEnterNotify) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jlong time) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2214,7 +2262,7 @@ NATIVE_NAME (sendEnterNotify) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendLeaveNotify) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jlong time) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2234,7 +2282,7 @@ NATIVE_NAME (sendLeaveNotify) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendMotionNotify) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jlong time) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2254,7 +2302,7 @@ NATIVE_NAME (sendMotionNotify) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendButtonPress) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jlong time, jint state, jint button) { @@ -2277,7 +2325,7 @@ NATIVE_NAME (sendButtonPress) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendButtonRelease) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jlong time, jint state, jint button) { @@ -2300,7 +2348,7 @@ NATIVE_NAME (sendButtonRelease) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendTouchDown) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jlong time, jint pointer_id, jint flags) { @@ -2323,7 +2371,7 @@ NATIVE_NAME (sendTouchDown) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendTouchUp) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jlong time, jint pointer_id, jint flags) { @@ -2346,7 +2394,7 @@ NATIVE_NAME (sendTouchUp) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendTouchMove) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jlong time, jint pointer_id, jint flags) { @@ -2369,7 +2417,7 @@ NATIVE_NAME (sendTouchMove) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendWheel) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jlong time, jint state, jfloat x_delta, jfloat y_delta) { @@ -2393,7 +2441,7 @@ NATIVE_NAME (sendWheel) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendIconified) (JNIEnv *env, jobject object, - jshort window) + jlong window) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2409,7 +2457,7 @@ NATIVE_NAME (sendIconified) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendDeiconified) (JNIEnv *env, jobject object, - jshort window) + jlong window) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2425,7 +2473,7 @@ NATIVE_NAME (sendDeiconified) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendContextMenu) (JNIEnv *env, jobject object, - jshort window, jint menu_event_id, + jlong window, jint menu_event_id, jint menu_event_serial) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2444,7 +2492,7 @@ NATIVE_NAME (sendContextMenu) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendExpose) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jint width, jint height) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2465,7 +2513,7 @@ NATIVE_NAME (sendExpose) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendDndDrag) (JNIEnv *env, jobject object, - jshort window, jint x, jint y) + jlong window, jint x, jint y) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2485,7 +2533,7 @@ NATIVE_NAME (sendDndDrag) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendDndUri) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jstring string) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2522,7 +2570,7 @@ NATIVE_NAME (sendDndUri) (JNIEnv *env, jobject object, JNIEXPORT jlong JNICALL NATIVE_NAME (sendDndText) (JNIEnv *env, jobject object, - jshort window, jint x, jint y, + jlong window, jint x, jint y, jstring string) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -2711,7 +2759,6 @@ NATIVE_NAME (blitRect) (JNIEnv *env, jobject object, x2 = MAX (x2, 0); y2 = MAX (y2, 0); - if (x1 >= src_info.width || x1 >= dest_info.width) x1 = MIN (dest_info.width - 1, src_info.width - 1); @@ -2854,62 +2901,6 @@ NATIVE_NAME (setupSystemThread) (void) This means that every local reference must be explicitly destroyed with DeleteLocalRef. A helper macro is provided to do this. */ -struct android_handle_entry -{ - /* The type. */ - enum android_handle_type type; - - /* The handle. */ - jobject handle; -}; - -/* Table of handles MAX_HANDLE long. */ -struct android_handle_entry android_handles[USHRT_MAX]; - -/* The largest handle ID currently known, but subject to - wraparound. */ -static android_handle max_handle; - -/* Allocate a new, unused, handle identifier. If Emacs is out of - identifiers, return 0. */ - -static android_handle -android_alloc_id (void) -{ - android_handle handle; - - /* 0 is never a valid handle ID. */ - - if (!max_handle) - max_handle++; - - /* See if the handle is already occupied. */ - - if (android_handles[max_handle].handle) - { - /* Look for a fresh unoccupied handle. */ - - handle = max_handle; - max_handle++; - - while (handle != max_handle) - { - ++max_handle; - - /* Make sure the handle is valid. */ - if (!max_handle) - ++max_handle; - - if (!android_handles[max_handle].handle) - return max_handle++; - } - - return ANDROID_NONE; - } - - return max_handle++; -} - /* Destroy the specified handle and mark it as free on the Java side as well. */ @@ -2919,13 +2910,6 @@ android_destroy_handle (android_handle handle) static jclass old, class; static jmethodID method; - if (!android_handles[handle].handle) - { - __android_log_print (ANDROID_LOG_ERROR, __func__, - "Trying to destroy free handle!"); - emacs_abort (); - } - if (!class) { class @@ -2946,8 +2930,7 @@ android_destroy_handle (android_handle handle) ANDROID_DELETE_LOCAL_REF (old); } - (*android_java_env)->CallVoidMethod (android_java_env, - android_handles[handle].handle, + (*android_java_env)->CallVoidMethod (android_java_env, (jobject) handle, method); /* Just clear any exception thrown. If destroying the handle @@ -2956,76 +2939,7 @@ android_destroy_handle (android_handle handle) (*android_java_env)->ExceptionClear (android_java_env); /* Delete the global reference regardless of any error. */ - (*android_java_env)->DeleteGlobalRef (android_java_env, - android_handles[handle].handle); - android_handles[handle].handle = NULL; -} - -jobject -android_resolve_handle (android_handle handle, - enum android_handle_type type) -{ - if (!handle) - /* ANDROID_NONE. */ - return NULL; - - /* CheckJNI will normally ensure that the handle exists and is - the right type, but with a less informative error message. - Don't waste cycles doing our own checking here. */ - -#ifdef ENABLE_CHECKING - - if (!android_handles[handle].handle) - { - __android_log_print (ANDROID_LOG_ERROR, __func__, - "Trying to resolve free handle!"); - emacs_abort (); - } - - if (android_handles[handle].type != type) - { - __android_log_print (ANDROID_LOG_ERROR, __func__, - "Handle has wrong type!"); - emacs_abort (); - } - -#endif /* ENABLE_CHECKING */ - - return android_handles[handle].handle; -} - -static jobject -android_resolve_handle2 (android_handle handle, - enum android_handle_type type, - enum android_handle_type type2) -{ - if (!handle) - return NULL; - - /* CheckJNI will normally ensure that the handle exists and is - the right type, but with a less informative error message. - Don't waste cycles doing our own checking here. */ - -#ifdef ENABLE_CHECKING - - if (!android_handles[handle].handle) - { - __android_log_print (ANDROID_LOG_ERROR, __func__, - "Trying to resolve free handle!"); - emacs_abort (); - } - - if (android_handles[handle].type != type - && android_handles[handle].type != type2) - { - __android_log_print (ANDROID_LOG_ERROR, __func__, - "Handle has wrong type!"); - emacs_abort (); - } - -#endif /* ENABLE_CHECKING */ - - return android_handles[handle].handle; + (*android_java_env)->DeleteGlobalRef (android_java_env, (jobject) handle); } void @@ -3037,7 +2951,7 @@ android_change_window_attributes (android_window handle, jobject window; jint pixel; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); if (value_mask & ANDROID_CW_BACK_PIXEL) { @@ -3051,6 +2965,35 @@ android_change_window_attributes (android_window handle, } } +/* Return a reference to the local reference HANDLE suitable for + indefinite retention and save its value into HANDLE, deleting HANDLE, + or signal an error if such a reference cannot be allocated. */ + +static android_handle +android_globalize_reference (jobject handle) +{ + jobject global; + + /* Though Android 8.0 and later can support an unlimited number of + active local references, they remain inappropriate in threading + configurations for being local to the current thread. */ + + global = (*android_java_env)->NewGlobalRef (android_java_env, + handle); + (*android_java_env)->ExceptionClear (android_java_env); + ANDROID_DELETE_LOCAL_REF (handle); + + if (__builtin_expect (global == NULL, 0)) + error ("JNI global reference reserves exhausted"); + + /* Save the value of this handle into HANDLE. */ + (*android_java_env)->SetLongField (android_java_env, global, + handle_class.handle, + (jlong) global); + verify (sizeof (jlong) >= sizeof (intptr_t)); + return (intptr_t) global; +} + /* Create a new window with the given width, height and attributes. */ @@ -3064,16 +3007,10 @@ android_create_window (android_window parent, int x, int y, static jmethodID constructor; jobject object, parent_object, old; android_window window; - android_handle prev_max_handle; bool override_redirect; - parent_object = android_resolve_handle (parent, ANDROID_HANDLE_WINDOW); + parent_object = android_resolve_handle (parent); - prev_max_handle = max_handle; - window = android_alloc_id (); - - if (!window) - error ("Out of window handles!"); if (!class) { @@ -3083,7 +3020,7 @@ android_create_window (android_window parent, int x, int y, constructor = (*android_java_env)->GetMethodID (android_java_env, class, "", - "(SLorg/gnu/emacs/EmacsWindow;" + "(Lorg/gnu/emacs/EmacsWindow;" "IIIIZ)V"); eassert (constructor != NULL); @@ -3100,28 +3037,12 @@ android_create_window (android_window parent, int x, int y, && attrs->override_redirect); object = (*android_java_env)->NewObject (android_java_env, class, - constructor, (jshort) window, - parent_object, (jint) x, (jint) y, + constructor, parent_object, + (jint) x, (jint) y, (jint) width, (jint) height, (jboolean) override_redirect); - if (!object) - { - (*android_java_env)->ExceptionClear (android_java_env); - - max_handle = prev_max_handle; - memory_full (0); - } - - android_handles[window].type = ANDROID_HANDLE_WINDOW; - android_handles[window].handle - = (*android_java_env)->NewGlobalRef (android_java_env, - object); - (*android_java_env)->ExceptionClear (android_java_env); - ANDROID_DELETE_LOCAL_REF (object); - - if (!android_handles[window].handle) - memory_full (0); - + android_exception_check (); + window = android_globalize_reference (object); android_change_window_attributes (window, value_mask, attrs); return window; } @@ -3139,13 +3060,6 @@ android_set_window_background (android_window window, unsigned long pixel) void android_destroy_window (android_window window) { - if (android_handles[window].type != ANDROID_HANDLE_WINDOW) - { - __android_log_print (ANDROID_LOG_ERROR, __func__, - "Trying to destroy something not a window!"); - emacs_abort (); - } - android_destroy_handle (window); } @@ -3193,7 +3107,7 @@ android_init_emacs_gc_class (void) emacs_gc_constructor = (*android_java_env)->GetMethodID (android_java_env, emacs_gc_class, - "", "(S)V"); + "", "()V"); eassert (emacs_gc_constructor); emacs_gc_mark_dirty @@ -3279,14 +3193,12 @@ android_create_gc (enum android_gc_value_mask mask, struct android_gc_values *values) { struct android_gc *gc; - android_handle prev_max_handle; jobject object; android_init_emacs_gc_class (); gc = xmalloc (sizeof *gc); - prev_max_handle = max_handle; - gc->gcontext = android_alloc_id (); + gc->gcontext = 0; gc->foreground = 0; gc->background = 0xffffff; gc->clip_rects = NULL; @@ -3309,34 +3221,12 @@ android_create_gc (enum android_gc_value_mask mask, gc->dashes = NULL; gc->n_segments = 0; - if (!gc->gcontext) - { - xfree (gc); - error ("Out of GContext handles!"); - } - object = (*android_java_env)->NewObject (android_java_env, emacs_gc_class, - emacs_gc_constructor, - (jshort) gc->gcontext); - - if (!object) - { - (*android_java_env)->ExceptionClear (android_java_env); - - max_handle = prev_max_handle; - memory_full (0); - } - - android_handles[gc->gcontext].type = ANDROID_HANDLE_GCONTEXT; - android_handles[gc->gcontext].handle - = (*android_java_env)->NewGlobalRef (android_java_env, object); - (*android_java_env)->ExceptionClear (android_java_env); - ANDROID_DELETE_LOCAL_REF (object); - - if (!android_handles[gc->gcontext].handle) - memory_full (0); + emacs_gc_constructor); + android_exception_check (); + gc->gcontext = android_globalize_reference (object); android_change_gc (gc, mask, values); return gc; } @@ -3362,8 +3252,7 @@ android_change_gc (struct android_gc *gc, clip_changed = false; android_init_emacs_gc_class (); - gcontext = android_resolve_handle (gc->gcontext, - ANDROID_HANDLE_GCONTEXT); + gcontext = android_resolve_handle (gc->gcontext); if (mask & ANDROID_GC_FOREGROUND) { @@ -3414,8 +3303,7 @@ android_change_gc (struct android_gc *gc, if (mask & ANDROID_GC_CLIP_MASK) { - what = android_resolve_handle (values->clip_mask, - ANDROID_HANDLE_PIXMAP); + what = android_resolve_handle (values->clip_mask); (*android_java_env)->SetObjectField (android_java_env, gcontext, emacs_gc_clip_mask, @@ -3436,8 +3324,7 @@ android_change_gc (struct android_gc *gc, if (mask & ANDROID_GC_STIPPLE) { - what = android_resolve_handle (values->stipple, - ANDROID_HANDLE_PIXMAP); + what = android_resolve_handle (values->stipple); (*android_java_env)->SetObjectField (android_java_env, gcontext, emacs_gc_stipple, @@ -3549,8 +3436,7 @@ android_set_clip_rectangles (struct android_gc *gc, int clip_x_origin, android_init_android_rect_class (); android_init_emacs_gc_class (); - gcontext = android_resolve_handle (gc->gcontext, - ANDROID_HANDLE_GCONTEXT); + gcontext = android_resolve_handle (gc->gcontext); array = (*android_java_env)->NewObjectArray (android_java_env, n_clip_rects, @@ -3623,8 +3509,7 @@ android_set_dashes (struct android_gc *gc, int dash_offset, int i; jobject array, gcontext; - gcontext = android_resolve_handle (gc->gcontext, - ANDROID_HANDLE_GCONTEXT); + gcontext = android_resolve_handle (gc->gcontext); if (n == gc->n_segments && (!gc->dashes || !memcmp (gc->dashes, dash_list, @@ -3692,9 +3577,8 @@ android_reparent_window (android_window w, android_window parent_handle, jobject window, parent; jmethodID method; - window = android_resolve_handle (w, ANDROID_HANDLE_WINDOW); - parent = android_resolve_handle (parent_handle, - ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (w); + parent = android_resolve_handle (parent_handle); method = window_class.reparent_to; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, window, @@ -3708,7 +3592,7 @@ android_clear_window (android_window handle) { jobject window; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, window, @@ -3723,7 +3607,7 @@ android_map_window (android_window handle) jobject window; jmethodID map_window; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); map_window = window_class.map_window; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, @@ -3739,7 +3623,7 @@ android_unmap_window (android_window handle) jobject window; jmethodID unmap_window; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); unmap_window = window_class.unmap_window; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, @@ -3756,7 +3640,7 @@ android_resize_window (android_window handle, unsigned int width, jobject window; jmethodID resize_window; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); resize_window = window_class.resize_window; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, @@ -3774,7 +3658,7 @@ android_move_window (android_window handle, int x, int y) jobject window; jmethodID move_window; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); move_window = window_class.move_window; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, @@ -3794,8 +3678,7 @@ android_swap_buffers (struct android_swap_info *swap_info, for (i = 0; i < num_windows; ++i) { - window = android_resolve_handle (swap_info[i].swap_window, - ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (swap_info[i].swap_window); (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, window, window_class.class, @@ -3856,11 +3739,8 @@ android_fill_rectangle (android_drawable handle, struct android_gc *gc, { jobject drawable, gcontext; - drawable = android_resolve_handle2 (handle, - ANDROID_HANDLE_WINDOW, - ANDROID_HANDLE_PIXMAP); - gcontext = android_resolve_handle (gc->gcontext, - ANDROID_HANDLE_GCONTEXT); + drawable = android_resolve_handle (handle); + gcontext = android_resolve_handle (gc->gcontext); (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, emacs_service, @@ -4527,7 +4407,9 @@ android_copy_area (android_drawable src, android_drawable dest, /* Now damage the destination drawable accordingly, should it be a window. */ - if (android_handles[dest].type == ANDROID_HANDLE_WINDOW) + if ((*android_java_env)->IsInstanceOf (android_java_env, + (jobject) dest, + window_class.class)) android_damage_window (dest, &bounds); fail2: @@ -4573,11 +4455,8 @@ android_fill_polygon (android_drawable drawable, struct android_gc *gc, jobject point, drawable_object, gcontext; int i; - drawable_object = android_resolve_handle2 (drawable, - ANDROID_HANDLE_WINDOW, - ANDROID_HANDLE_PIXMAP); - gcontext = android_resolve_handle (gc->gcontext, - ANDROID_HANDLE_GCONTEXT); + drawable_object = android_resolve_handle (drawable); + gcontext = android_resolve_handle (gc->gcontext); array = (*android_java_env)->NewObjectArray (android_java_env, npoints, @@ -4615,11 +4494,8 @@ android_draw_rectangle (android_drawable handle, struct android_gc *gc, { jobject drawable, gcontext; - drawable = android_resolve_handle2 (handle, - ANDROID_HANDLE_WINDOW, - ANDROID_HANDLE_PIXMAP); - gcontext = android_resolve_handle (gc->gcontext, - ANDROID_HANDLE_GCONTEXT); + drawable = android_resolve_handle (handle); + gcontext = android_resolve_handle (gc->gcontext); (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, emacs_service, @@ -4640,11 +4516,8 @@ android_draw_point (android_drawable handle, struct android_gc *gc, { jobject drawable, gcontext; - drawable = android_resolve_handle2 (handle, - ANDROID_HANDLE_WINDOW, - ANDROID_HANDLE_PIXMAP); - gcontext = android_resolve_handle (gc->gcontext, - ANDROID_HANDLE_GCONTEXT); + drawable = android_resolve_handle (handle); + gcontext = android_resolve_handle (gc->gcontext); (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, emacs_service, @@ -4664,11 +4537,8 @@ android_draw_line (android_drawable handle, struct android_gc *gc, { jobject drawable, gcontext; - drawable = android_resolve_handle2 (handle, - ANDROID_HANDLE_WINDOW, - ANDROID_HANDLE_PIXMAP); - gcontext = android_resolve_handle (gc->gcontext, - ANDROID_HANDLE_GCONTEXT); + drawable = android_resolve_handle (handle); + gcontext = android_resolve_handle (gc->gcontext); (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, emacs_service, @@ -4687,41 +4557,15 @@ android_pixmap android_create_pixmap (unsigned int width, unsigned int height, int depth) { - android_handle prev_max_handle; jobject object; - android_pixmap pixmap; - - /* First, allocate the pixmap handle. */ - prev_max_handle = max_handle; - pixmap = android_alloc_id (); - - if (!pixmap) - error ("Out of pixmap handles!"); object = (*android_java_env)->NewObject (android_java_env, pixmap_class.class, pixmap_class.constructor_mutable, - (jshort) pixmap, (jint) width, (jint) height, (jint) depth); - - if (!object) - { - (*android_java_env)->ExceptionClear (android_java_env); - max_handle = prev_max_handle; - memory_full (0); - } - - android_handles[pixmap].type = ANDROID_HANDLE_PIXMAP; - android_handles[pixmap].handle - = (*android_java_env)->NewGlobalRef (android_java_env, object); - (*android_java_env)->ExceptionClear (android_java_env); - ANDROID_DELETE_LOCAL_REF (object); - - if (!android_handles[pixmap].handle) - memory_full (0); - - return pixmap; + android_exception_check (); + return android_globalize_reference (object); } void @@ -4742,7 +4586,7 @@ android_clear_area (android_window handle, int x, int y, { jobject window; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, window, @@ -4894,8 +4738,7 @@ android_get_image (android_drawable handle, unsigned char *data1, *data2; int i, x; - drawable = android_resolve_handle2 (handle, ANDROID_HANDLE_WINDOW, - ANDROID_HANDLE_PIXMAP); + drawable = android_resolve_handle (handle); /* Look up the drawable and get the bitmap corresponding to it. Then, lock the bitmap's bits. */ @@ -5029,7 +4872,7 @@ android_put_image (android_pixmap handle, struct android_image *image) unsigned char *data_1, *data_2; int i, x; - drawable = android_resolve_handle (handle, ANDROID_HANDLE_PIXMAP); + drawable = android_resolve_handle (handle); /* Look up the drawable and get the bitmap corresponding to it. Then, lock the bitmap's bits. */ @@ -5131,7 +4974,7 @@ android_set_input_focus (android_window handle, unsigned long time) jobject window; jmethodID make_input_focus; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); make_input_focus = window_class.make_input_focus; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, @@ -5148,7 +4991,7 @@ android_raise_window (android_window handle) jobject window; jmethodID raise; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); raise = window_class.raise; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, @@ -5164,7 +5007,7 @@ android_lower_window (android_window handle) jobject window; jmethodID lower; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); lower = window_class.lower; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, @@ -5181,7 +5024,7 @@ android_reconfigure_wm_window (android_window handle, { jobject sibling, window; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); if (!(value_mask & ANDROID_CW_STACK_MODE)) return; @@ -5193,8 +5036,7 @@ android_reconfigure_wm_window (android_window handle, sibling = NULL; if (value_mask & ANDROID_CW_SIBLING) - sibling = android_resolve_handle (values->sibling, - ANDROID_HANDLE_WINDOW); + sibling = android_resolve_handle (values->sibling); (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, window, @@ -5214,10 +5056,10 @@ android_query_tree (android_window handle, android_window *root_return, jobject window, array; jsize nelements, i; android_window *children; - jshort *shorts; + jlong *longs; jmethodID method; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); /* window can be NULL, so this is a service method. */ method = service_class.query_tree; @@ -5237,25 +5079,25 @@ android_query_tree (android_window handle, android_window *root_return, /* Now fill in the children. */ children = xnmalloc (nelements - 1, sizeof *children); - shorts - = (*android_java_env)->GetShortArrayElements (android_java_env, array, - NULL); - android_exception_check_nonnull (shorts, array); + longs + = (*android_java_env)->GetLongArrayElements (android_java_env, array, + NULL); + android_exception_check_nonnull (longs, array); for (i = 1; i < nelements; ++i) /* Subtract one from the index into children, since the parent is not included. */ - children[i - 1] = shorts[i]; + children[i - 1] = longs[i]; /* Finally, return the parent and other values. */ *root_return = 0; - *parent_return = shorts[0]; + *parent_return = longs[0]; *children_return = children; *nchildren_return = nelements - 1; /* Release the array contents. */ - (*android_java_env)->ReleaseShortArrayElements (android_java_env, array, - shorts, JNI_ABORT); + (*android_java_env)->ReleaseLongArrayElements (android_java_env, array, + longs, JNI_ABORT); ANDROID_DELETE_LOCAL_REF (array); return 1; @@ -5274,7 +5116,7 @@ android_get_geometry (android_window handle, jmethodID get_geometry; jint *ints; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); get_geometry = window_class.get_window_geometry; window_geometry @@ -5336,7 +5178,7 @@ android_translate_coordinates (android_window src, int x, jmethodID method; jint *ints; - window = android_resolve_handle (src, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (src); method = window_class.translate_coordinates; coordinates = (*android_java_env)->CallNonvirtualObjectMethod (android_java_env, @@ -5504,51 +5346,44 @@ android_wc_lookup_string (android_key_pressed_event *event, /* Now look up the window. */ rc = 0; - if (!android_handles[event->window].handle - || (android_handles[event->window].type - != ANDROID_HANDLE_WINDOW)) + window = android_resolve_handle (event->window); + string + = (*env)->CallNonvirtualObjectMethod (env, window, + window_class.class, + window_class.lookup_string, + (jint) event->serial); + android_exception_check (); + + if (!string) status = ANDROID_LOOKUP_NONE; else { - window = android_handles[event->window].handle; - string - = (*env)->CallNonvirtualObjectMethod (env, window, - window_class.class, - window_class.lookup_string, - (jint) event->serial); - android_exception_check (); + /* Now return this input method string. */ + characters = (*env)->GetStringChars (env, string, NULL); + android_exception_check_nonnull ((void *) characters, string); - if (!string) - status = ANDROID_LOOKUP_NONE; + /* Establish the size of the the string. */ + size = (*env)->GetStringLength (env, string); + + /* Copy over the string data. */ + for (i = 0; i < MIN ((unsigned int) wchars_buffer, size); ++i) + buffer_return[i] = characters[i]; + + if (i < size) + status = ANDROID_BUFFER_OVERFLOW; else - { - /* Now return this input method string. */ - characters = (*env)->GetStringChars (env, string, NULL); - android_exception_check_nonnull ((void *) characters, string); + status = ANDROID_LOOKUP_CHARS; - /* Establish the size of the the string. */ - size = (*env)->GetStringLength (env, string); + /* Return the number of characters that should have been + written. */ - /* Copy over the string data. */ - for (i = 0; i < MIN ((unsigned int) wchars_buffer, size); ++i) - buffer_return[i] = characters[i]; + if (size > INT_MAX) + rc = INT_MAX; + else + rc = size; - if (i < size) - status = ANDROID_BUFFER_OVERFLOW; - else - status = ANDROID_LOOKUP_CHARS; - - /* Return the number of characters that should have been - written. */ - - if (size > INT_MAX) - rc = INT_MAX; - else - rc = size; - - (*env)->ReleaseStringChars (env, string, characters); - ANDROID_DELETE_LOCAL_REF (string); - } + (*env)->ReleaseStringChars (env, string, characters); + ANDROID_DELETE_LOCAL_REF (string); } *status_return = status; @@ -5582,8 +5417,7 @@ android_lock_bitmap (android_drawable drawable, jobject object, bitmap; void *data; - object = android_resolve_handle2 (drawable, ANDROID_HANDLE_WINDOW, - ANDROID_HANDLE_PIXMAP); + object = android_resolve_handle (drawable); /* Look up the drawable and get the bitmap corresponding to it. Then, lock the bitmap's bits. */ @@ -5637,7 +5471,7 @@ android_damage_window (android_drawable handle, { jobject drawable; - drawable = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + drawable = android_resolve_handle (handle); /* Post the damage to the drawable. */ (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, @@ -5758,7 +5592,7 @@ android_set_dont_focus_on_map (android_window handle, jmethodID method; jobject window; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); method = window_class.set_dont_focus_on_map; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, window, @@ -5775,7 +5609,7 @@ android_set_dont_accept_focus (android_window handle, jmethodID method; jobject window; - window = android_resolve_handle (handle, ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (handle); method = window_class.set_dont_accept_focus; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, window, @@ -5854,7 +5688,7 @@ android_toggle_on_screen_keyboard (android_window window, bool show) jobject object; jmethodID method; - object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW); + object = android_resolve_handle (window); method = window_class.toggle_on_screen_keyboard; /* Now display the on screen keyboard. */ @@ -6115,11 +5949,7 @@ android_build_jstring (const char *text) if global_foo cannot be allocated, and after the global reference is created. */ -#if __GNUC__ >= 3 #define likely(cond) __builtin_expect (cond, 1) -#else /* __GNUC__ < 3 */ -#define likely(cond) (cond) -#endif /* __GNUC__ >= 3 */ /* Check for JNI exceptions and call memory_full in that situation. */ @@ -6831,7 +6661,7 @@ android_recreate_activity (android_window window) jobject object; jmethodID method; - object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW); + object = android_resolve_handle (window); method = window_class.recreate_activity; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, object, @@ -7196,7 +7026,7 @@ android_update_ic (android_window window, ptrdiff_t selection_start, { jobject object; - object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW); + object = android_resolve_handle (window); (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, emacs_service, @@ -7233,7 +7063,7 @@ android_reset_ic (android_window window, enum android_ic_mode mode) { jobject object; - object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW); + object = android_resolve_handle (window); (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, emacs_service, @@ -7255,7 +7085,7 @@ android_update_extracted_text (android_window window, void *text, jobject object; jmethodID method; - object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW); + object = android_resolve_handle (window); method = service_class.update_extracted_text; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, @@ -7289,7 +7119,7 @@ android_update_cursor_anchor_info (android_window window, float x, jobject object; jmethodID method; - object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW); + object = android_resolve_handle (window); method = service_class.update_cursor_anchor_info; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, @@ -7324,7 +7154,7 @@ android_set_fullscreen (android_window window, bool fullscreen) if (android_api_level < 16) return 1; - object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW); + object = android_resolve_handle (window); (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, object, @@ -7342,40 +7172,15 @@ android_set_fullscreen (android_window window, bool fullscreen) android_cursor android_create_font_cursor (enum android_cursor_shape shape) { - android_cursor id; - short prev_max_handle; jobject object; - /* First, allocate the cursor handle. */ - prev_max_handle = max_handle; - id = android_alloc_id (); - - if (!id) - error ("Out of cursor handles!"); - /* Next, create the cursor. */ object = (*android_java_env)->NewObject (android_java_env, cursor_class.class, cursor_class.constructor, - (jshort) id, (jint) shape); - if (!object) - { - (*android_java_env)->ExceptionClear (android_java_env); - max_handle = prev_max_handle; - memory_full (0); - } - - android_handles[id].type = ANDROID_HANDLE_CURSOR; - android_handles[id].handle - = (*android_java_env)->NewGlobalRef (android_java_env, object); - (*android_java_env)->ExceptionClear (android_java_env); - ANDROID_DELETE_LOCAL_REF (object); - - if (!android_handles[id].handle) - memory_full (0); - - return id; + android_exception_check (); + return android_globalize_reference (object); } void @@ -7384,8 +7189,8 @@ android_define_cursor (android_window window, android_cursor cursor) jobject window1, cursor1; jmethodID method; - window1 = android_resolve_handle (window, ANDROID_HANDLE_WINDOW); - cursor1 = android_resolve_handle (cursor, ANDROID_HANDLE_CURSOR); + window1 = android_resolve_handle (window); + cursor1 = android_resolve_handle (cursor); method = window_class.define_cursor; (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, @@ -7398,13 +7203,6 @@ android_define_cursor (android_window window, android_cursor cursor) void android_free_cursor (android_cursor cursor) { - if (android_handles[cursor].type != ANDROID_HANDLE_CURSOR) - { - __android_log_print (ANDROID_LOG_ERROR, __func__, - "Trying to destroy something not a CURSOR!"); - emacs_abort (); - } - android_destroy_handle (cursor); } diff --git a/src/android.h b/src/android.h index 7074ca2630c..a582a9b7dff 100644 --- a/src/android.h +++ b/src/android.h @@ -101,16 +101,9 @@ extern ssize_t android_readlinkat (int, const char *restrict, char *restrict, extern double android_pixel_density_x, android_pixel_density_y; extern double android_scaled_pixel_density; -enum android_handle_type - { - ANDROID_HANDLE_WINDOW, - ANDROID_HANDLE_GCONTEXT, - ANDROID_HANDLE_PIXMAP, - ANDROID_HANDLE_CURSOR, - }; +verify (sizeof (android_handle) == sizeof (jobject)); +#define android_resolve_handle(handle) ((jobject) (handle)) -extern jobject android_resolve_handle (android_handle, - enum android_handle_type); extern unsigned char *android_lock_bitmap (android_drawable, AndroidBitmapInfo *, jobject *); diff --git a/src/androidfont.c b/src/androidfont.c index 5fd3018b6d4..20a18327ff8 100644 --- a/src/androidfont.c +++ b/src/androidfont.c @@ -657,10 +657,8 @@ androidfont_draw (struct glyph_string *s, int from, int to, verify (sizeof (unsigned int) == sizeof (jint)); info = (struct androidfont_info *) s->font; - gcontext = android_resolve_handle (s->gc->gcontext, - ANDROID_HANDLE_GCONTEXT); - drawable = android_resolve_handle (FRAME_ANDROID_DRAWABLE (s->f), - ANDROID_HANDLE_WINDOW); + gcontext = android_resolve_handle (s->gc->gcontext); + drawable = android_resolve_handle (FRAME_ANDROID_DRAWABLE (s->f)); chars = (*android_java_env)->NewIntArray (android_java_env, to - from); android_exception_check (); diff --git a/src/androidgui.h b/src/androidgui.h index 3b3e08ca024..79e42c7947c 100644 --- a/src/androidgui.h +++ b/src/androidgui.h @@ -19,6 +19,8 @@ along with GNU Emacs. If not, see . */ #ifndef _ANDROID_GUI_H_ #define _ANDROID_GUI_H_ +#include + struct android_char_struct { int rbearing; @@ -30,7 +32,8 @@ struct android_char_struct typedef struct android_char_struct XCharStruct; -typedef unsigned short android_handle; +/* Handles are but JNI handles cast to intptr_t. */ +typedef intptr_t android_handle; typedef android_handle android_pixmap, Emacs_Pixmap; typedef android_handle android_window, Emacs_Window; diff --git a/src/androidmenu.c b/src/androidmenu.c index 362d500ac1a..7d24087fa87 100644 --- a/src/androidmenu.c +++ b/src/androidmenu.c @@ -488,8 +488,7 @@ android_menu_show (struct frame *f, int x, int y, int menuflags, unbind_to (count1, Qnil); /* Now, display the context menu. */ - window = android_resolve_handle (FRAME_ANDROID_WINDOW (f), - ANDROID_HANDLE_WINDOW); + window = android_resolve_handle (FRAME_ANDROID_WINDOW (f)); rc = (*env)->CallNonvirtualBooleanMethod (env, context_menu, menu_class.class, menu_class.display, diff --git a/src/androidterm.c b/src/androidterm.c index 2979e5c1401..f4c071f4519 100644 --- a/src/androidterm.c +++ b/src/androidterm.c @@ -4925,7 +4925,7 @@ android_copy_java_string (JNIEnv *env, jstring string, size_t *length) } JNIEXPORT void JNICALL -NATIVE_NAME (beginBatchEdit) (JNIEnv *env, jobject object, jshort window) +NATIVE_NAME (beginBatchEdit) (JNIEnv *env, jobject object, jlong window) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -4946,7 +4946,7 @@ NATIVE_NAME (beginBatchEdit) (JNIEnv *env, jobject object, jshort window) } JNIEXPORT void JNICALL -NATIVE_NAME (endBatchEdit) (JNIEnv *env, jobject object, jshort window) +NATIVE_NAME (endBatchEdit) (JNIEnv *env, jobject object, jlong window) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -4967,7 +4967,7 @@ NATIVE_NAME (endBatchEdit) (JNIEnv *env, jobject object, jshort window) } JNIEXPORT void JNICALL -NATIVE_NAME (commitCompletion) (JNIEnv *env, jobject object, jshort window, +NATIVE_NAME (commitCompletion) (JNIEnv *env, jobject object, jlong window, jstring completion_text, jint position) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5001,7 +5001,7 @@ NATIVE_NAME (commitCompletion) (JNIEnv *env, jobject object, jshort window, } JNIEXPORT void JNICALL -NATIVE_NAME (commitText) (JNIEnv *env, jobject object, jshort window, +NATIVE_NAME (commitText) (JNIEnv *env, jobject object, jlong window, jstring commit_text, jint position) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5036,7 +5036,7 @@ NATIVE_NAME (commitText) (JNIEnv *env, jobject object, jshort window, JNIEXPORT void JNICALL NATIVE_NAME (deleteSurroundingText) (JNIEnv *env, jobject object, - jshort window, jint left_length, + jlong window, jint left_length, jint right_length) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5059,7 +5059,7 @@ NATIVE_NAME (deleteSurroundingText) (JNIEnv *env, jobject object, JNIEXPORT void JNICALL NATIVE_NAME (finishComposingText) (JNIEnv *env, jobject object, - jshort window) + jlong window) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5080,7 +5080,7 @@ NATIVE_NAME (finishComposingText) (JNIEnv *env, jobject object, } JNIEXPORT void JNICALL -NATIVE_NAME (replaceText) (JNIEnv *env, jobject object, jshort window, +NATIVE_NAME (replaceText) (JNIEnv *env, jobject object, jlong window, jint start, jint end, jobject text, int new_cursor_position, jobject attribute) { @@ -5246,7 +5246,7 @@ android_text_to_string (JNIEnv *env, char *buffer, ptrdiff_t n, } JNIEXPORT jstring JNICALL -NATIVE_NAME (getTextAfterCursor) (JNIEnv *env, jobject object, jshort window, +NATIVE_NAME (getTextAfterCursor) (JNIEnv *env, jobject object, jlong window, jint length, jint flags) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5290,7 +5290,7 @@ NATIVE_NAME (getTextAfterCursor) (JNIEnv *env, jobject object, jshort window, } JNIEXPORT jstring JNICALL -NATIVE_NAME (getTextBeforeCursor) (JNIEnv *env, jobject object, jshort window, +NATIVE_NAME (getTextBeforeCursor) (JNIEnv *env, jobject object, jlong window, jint length, jint flags) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5334,7 +5334,7 @@ NATIVE_NAME (getTextBeforeCursor) (JNIEnv *env, jobject object, jshort window, } JNIEXPORT void JNICALL -NATIVE_NAME (setComposingText) (JNIEnv *env, jobject object, jshort window, +NATIVE_NAME (setComposingText) (JNIEnv *env, jobject object, jlong window, jstring composing_text, jint new_cursor_position) { @@ -5369,7 +5369,7 @@ NATIVE_NAME (setComposingText) (JNIEnv *env, jobject object, jshort window, } JNIEXPORT void JNICALL -NATIVE_NAME (setComposingRegion) (JNIEnv *env, jobject object, jshort window, +NATIVE_NAME (setComposingRegion) (JNIEnv *env, jobject object, jlong window, jint start, jint end) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5391,7 +5391,7 @@ NATIVE_NAME (setComposingRegion) (JNIEnv *env, jobject object, jshort window, } JNIEXPORT void JNICALL -NATIVE_NAME (setSelection) (JNIEnv *env, jobject object, jshort window, +NATIVE_NAME (setSelection) (JNIEnv *env, jobject object, jlong window, jint start, jint end) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5469,7 +5469,7 @@ android_get_selection (void *data) } JNIEXPORT jintArray JNICALL -NATIVE_NAME (getSelection) (JNIEnv *env, jobject object, jshort window) +NATIVE_NAME (getSelection) (JNIEnv *env, jobject object, jlong window) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5508,7 +5508,7 @@ NATIVE_NAME (getSelection) (JNIEnv *env, jobject object, jshort window) JNIEXPORT void JNICALL NATIVE_NAME (performEditorAction) (JNIEnv *env, jobject object, - jshort window, int action) + jlong window, int action) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5560,7 +5560,7 @@ NATIVE_NAME (performEditorAction) (JNIEnv *env, jobject object, JNIEXPORT void JNICALL NATIVE_NAME (performContextMenuAction) (JNIEnv *env, jobject object, - jshort window, int action) + jlong window, int action) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5765,7 +5765,7 @@ android_build_extracted_text (jstring text, ptrdiff_t start, JNIEXPORT jobject JNICALL NATIVE_NAME (getExtractedText) (JNIEnv *env, jobject ignored_object, - jshort window, jobject request, + jlong window, jobject request, jint flags) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5877,7 +5877,7 @@ NATIVE_NAME (getExtractedText) (JNIEnv *env, jobject ignored_object, JNIEXPORT jstring JNICALL NATIVE_NAME (getSelectedText) (JNIEnv *env, jobject object, - jshort window) + jlong window) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5907,7 +5907,7 @@ NATIVE_NAME (getSelectedText) (JNIEnv *env, jobject object, JNIEXPORT void JNICALL NATIVE_NAME (requestSelectionUpdate) (JNIEnv *env, jobject object, - jshort window) + jlong window) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5929,7 +5929,7 @@ NATIVE_NAME (requestSelectionUpdate) (JNIEnv *env, jobject object, JNIEXPORT void JNICALL NATIVE_NAME (requestCursorUpdates) (JNIEnv *env, jobject object, - jshort window, jint mode) + jlong window, jint mode) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -5958,7 +5958,7 @@ NATIVE_NAME (requestCursorUpdates) (JNIEnv *env, jobject object, JNIEXPORT void JNICALL NATIVE_NAME (clearInputFlags) (JNIEnv *env, jobject object, - jshort window) + jlong window) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -6073,7 +6073,7 @@ android_get_surrounding_text (void *data) Value is the object upon success, else NULL. */ static jobject -android_get_surrounding_text_internal (JNIEnv *env, jshort window, +android_get_surrounding_text_internal (JNIEnv *env, jlong window, jint before_length, jint after_length, ptrdiff_t *conversion_start, @@ -6166,7 +6166,7 @@ android_get_surrounding_text_internal (JNIEnv *env, jshort window, JNIEXPORT jobject JNICALL NATIVE_NAME (getSurroundingText) (JNIEnv *env, jobject object, - jshort window, jint before_length, + jlong window, jint before_length, jint after_length, jint flags) { JNI_STACK_ALIGNMENT_PROLOGUE; @@ -6176,7 +6176,7 @@ NATIVE_NAME (getSurroundingText) (JNIEnv *env, jobject object, } JNIEXPORT jobject JNICALL -NATIVE_NAME (takeSnapshot) (JNIEnv *env, jobject object, jshort window) +NATIVE_NAME (takeSnapshot) (JNIEnv *env, jobject object, jlong window) { JNI_STACK_ALIGNMENT_PROLOGUE;