Kaydet (Commit) 8dd75128 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

ByteBufferWrapper tweaks

operator() gets called in a Java GC thread. A JNIEnv* saved in the
constructor (which is called from the UI thread) is not valid in other
threads (although for now, Dalvik notices, warns, and works around
it). So don't bother keeping the JNIEnv*. Instead fetch one when
needed. Move the method implementations from inline in the header to
libotouch's android.cxx.

Change-Id: I7de6fc54bb8d9a59146576d6e8c325fe917393ee
üst 36244dcf
...@@ -21,25 +21,14 @@ namespace org { namespace libreoffice { namespace touch { ...@@ -21,25 +21,14 @@ namespace org { namespace libreoffice { namespace touch {
class ByteBufferWrapper class ByteBufferWrapper
{ {
private: private:
JNIEnv *env; jobject object;
jobject object;
public: public:
ByteBufferWrapper(JNIEnv *e, jobject o) : ByteBufferWrapper(JNIEnv *env, jobject o);
env(e)
{ sal_uInt8* pointer();
object = env->NewGlobalRef(o);
} void operator()(sal_uInt8 *p);
sal_uInt8* pointer()
{
return (sal_uInt8 *) env->GetDirectBufferAddress(object);
}
void operator()(sal_uInt8 * /* p */)
{
env->DeleteGlobalRef(object);
}
}; };
}; }; }; }; }; };
......
...@@ -33,6 +33,10 @@ $(eval $(call gb_Library_add_exception_objects,libotouch,\ ...@@ -33,6 +33,10 @@ $(eval $(call gb_Library_add_exception_objects,libotouch,\
ifeq ($(OS),ANDROID) ifeq ($(OS),ANDROID)
$(eval $(call gb_Library_use_libraries,libotouch,\
lo-bootstrap \
))
$(eval $(call gb_Library_add_exception_objects,libotouch,\ $(eval $(call gb_Library_add_exception_objects,libotouch,\
touch/source/android/android \ touch/source/android/android \
)) ))
......
...@@ -10,9 +10,43 @@ ...@@ -10,9 +10,43 @@
#include <jni.h> #include <jni.h>
#include <sal/ByteBufferWrapper.hxx> #include <sal/ByteBufferWrapper.hxx>
#include <osl/detail/android-bootstrap.h>
using org::libreoffice::touch::ByteBufferWrapper; using org::libreoffice::touch::ByteBufferWrapper;
static JNIEnv *get_env()
{
JavaVMAttachArgs args = {
JNI_VERSION_1_2,
NULL,
NULL
};
JavaVM *jvm = lo_get_javavm();
JNIEnv *env = NULL;
jvm->AttachCurrentThread(&env, &args);
return env;
}
__attribute__ ((visibility("default")))
ByteBufferWrapper::ByteBufferWrapper(JNIEnv *env, jobject o)
{
object = env->NewGlobalRef(o);
}
__attribute__ ((visibility("default")))
sal_uInt8* ByteBufferWrapper::pointer()
{
return (sal_uInt8 *) get_env()->GetDirectBufferAddress(object);
}
__attribute__ ((visibility("default")))
void ByteBufferWrapper::operator()(sal_uInt8 * /* p */)
{
get_env()->DeleteGlobalRef(object);
}
extern "C" extern "C"
__attribute__ ((visibility("default"))) __attribute__ ((visibility("default")))
jlong jlong
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment