* java/org/gnu/emacs/EmacsView.java (swapBuffers): Synchronize
such that code cannot execute between the bitmap's being loaded
and being transferred to surfaceView.
(onDetachedFromWindow): Recycle bitmap after the surface view is
reset.
* java/org/gnu/emacs/EmacsWindow.java (recreateActivity):
* src/android.c (android_init_emacs_window)
(android_recreate_activity):
* src/androidfns.c (Fandroid_recreate_activity)
(syms_of_androidfns): New functions for debugging window
attachment.
* src/androidgui.h: Update prototypes.
(cherry picked from commit
16831e290ed29f5f70dfe144ec63c583527485e8)
{
Canvas canvas;
Rect damageRect;
- Bitmap bitmap;
/* Make sure this function is called only from the Emacs
thread. */
damageRect = damageRegion.getBounds ();
damageRegion.setEmpty ();
- bitmap = getBitmap ();
-
- /* Transfer the bitmap to the surface view, then invalidate
- it. */
- surfaceView.setBitmap (bitmap, damageRect);
+ synchronized (this)
+ {
+ /* Transfer the bitmap to the surface view, then invalidate
+ it. */
+ surfaceView.setBitmap (bitmap, damageRect);
+ }
}
@Override
public synchronized void
onDetachedFromWindow ()
{
- isAttachedToWindow = false;
-
- /* Recycle the bitmap and call GC. */
-
- if (bitmap != null)
- bitmap.recycle ();
+ Bitmap savedBitmap;
+ savedBitmap = bitmap;
+ isAttachedToWindow = false;
bitmap = null;
canvas = null;
+
surfaceView.setBitmap (null, null);
+ /* Recycle the bitmap and call GC. */
+
+ if (savedBitmap != null)
+ savedBitmap.recycle ();
+
/* Collect the bitmap storage; it could be large. */
Runtime.getRuntime ().gc ();
return true;
}
+
+\f
+
+ /* Miscellaneous functions for debugging graphics code. */
+
+ /* Recreate the activity to which this window is attached, if any.
+ This is nonfunctional on Android 2.3.7 and earlier. */
+
+ public void
+ recreateActivity ()
+ {
+ final EmacsWindowAttachmentManager.WindowConsumer attached;
+
+ attached = this.attached;
+
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
+ return;
+
+ view.post (new Runnable () {
+ @Override
+ public void
+ run ()
+ {
+ if (attached instanceof EmacsActivity)
+ ((EmacsActivity) attached).recreate ();
+ }
+ });
+ }
};
jmethodID set_dont_focus_on_map;
jmethodID define_cursor;
jmethodID damage_rect;
+ jmethodID recreate_activity;
};
struct android_emacs_cursor
FIND_METHOD (set_dont_accept_focus, "setDontAcceptFocus", "(Z)V");
FIND_METHOD (define_cursor, "defineCursor",
"(Lorg/gnu/emacs/EmacsCursor;)V");
-
/* In spite of the declaration of this function being located within
EmacsDrawable, the ID of the `damage_rect' method is retrieved
from EmacsWindow, which avoids virtual function dispatch within
android_damage_window. */
FIND_METHOD (damage_rect, "damageRect", "(IIII)V");
+ FIND_METHOD (recreate_activity, "recreateActivity", "()V");
#undef FIND_METHOD
}
android_exception_check ();
}
+/* Recreate the activity to which WINDOW is attached to debug graphics
+ code executed in response to window attachment. */
+
+void
+android_recreate_activity (android_window window)
+{
+ jobject object;
+ jmethodID method;
+
+ object = android_resolve_handle (window, ANDROID_HANDLE_WINDOW);
+ method = window_class.recreate_activity;
+
+ (*android_java_env)->CallNonvirtualVoidMethod (android_java_env, object,
+ window_class.class,
+ method);
+ android_exception_check ();
+}
+
\f
/* The thread from which a query against a thread is currently being
y + w->phys_cursor_height);
}
+\f
+
+/* Debugging. */
+
+DEFUN ("android-recreate-activity", Fandroid_recreate_activity,
+ Sandroid_recreate_activity, 0, 0, "",
+ doc: /* Recreate the activity attached to the current frame.
+This function exists for debugging purposes and is of no interest to
+users. */)
+ (void)
+{
+ struct frame *f;
+
+ f = decode_window_system_frame (Qnil);
+ android_recreate_activity (FRAME_ANDROID_WINDOW (f));
+ return Qnil;
+}
+
#endif /* !ANDROID_STUBIFY */
\f
defsubr (&Sandroid_request_directory_access);
defsubr (&Sandroid_external_storage_available_p);
defsubr (&Sandroid_request_storage_access);
+ defsubr (&Sandroid_recreate_activity);
tip_timer = Qnil;
staticpro (&tip_timer);
extern int android_wc_lookup_string (android_key_pressed_event *,
wchar_t *, int, int *,
enum android_lookup_status *);
+extern void android_recreate_activity (android_window);
extern void android_update_ic (android_window, ptrdiff_t, ptrdiff_t,
ptrdiff_t, ptrdiff_t);
extern void android_reset_ic (android_window, enum android_ic_mode);