summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tlillqvist@suse.com>2012-01-25 16:41:45 +0200
committerTor Lillqvist <tlillqvist@suse.com>2012-01-25 19:39:06 +0200
commit25f78344e8dea95cedb0b981f08865d676154e5b (patch)
treec47a47c65587669ee0cfa5c4efbe0c79cb94e762
parentc4e35496393c73e73a297e8c5398cb6f96a35e46 (diff)
Bin global_android_app and instead use lo-bootstrap API
Instead of introducing a global variable, use the already existing saved android_app pointer in lo-bootstrap.c, and just add a function to retrieve it from there. Store it in the AndroidSalInstance. Reanme osl/detail/android.h back to android_native_app_glue.h, which is the name of that file in NDK/sources. "android.h" sounded to me too grand, as if it was some universal Android header. But if we do start to modify the android_native_app_glue stuff heavily, then it indeed makes sense to call it something else. Until then, revert also some whitespace changes to android_native_app_glue.c for it to be as close as possible to the "upstream" one in the NDK, for clarity.
-rw-r--r--sal/Package_inc.mk2
-rw-r--r--sal/android/android_native_app_glue.c15
-rw-r--r--sal/android/lo-bootstrap.c7
-rw-r--r--sal/inc/osl/detail/android_native_app_glue.h (renamed from sal/inc/osl/detail/android.h)7
-rw-r--r--solenv/inc/unxandr/lo-bootstrap.h2
-rw-r--r--vcl/android/androidinst.cxx37
-rw-r--r--vcl/inc/android/androidinst.hxx1
7 files changed, 35 insertions, 36 deletions
diff --git a/sal/Package_inc.mk b/sal/Package_inc.mk
index d0520efcd757..e43de3e46388 100644
--- a/sal/Package_inc.mk
+++ b/sal/Package_inc.mk
@@ -64,7 +64,7 @@ $(eval $(call gb_Package_add_file,sal_inc,inc/osl/thread.hxx,osl/thread.hxx))
$(eval $(call gb_Package_add_file,sal_inc,inc/osl/time.h,osl/time.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/osl/util.h,osl/util.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/osl/detail/file.h,osl/detail/file.h))
-$(eval $(call gb_Package_add_file,sal_inc,inc/osl/detail/android.h,osl/detail/android.h))
+$(eval $(call gb_Package_add_file,sal_inc,inc/osl/detail/android_native_app_glue.h,osl/detail/android_native_app_glue.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/rtl/allocator.hxx,rtl/allocator.hxx))
$(eval $(call gb_Package_add_file,sal_inc,inc/rtl/alloc.h,rtl/alloc.h))
$(eval $(call gb_Package_add_file,sal_inc,inc/rtl/bootstrap.h,rtl/bootstrap.h))
diff --git a/sal/android/android_native_app_glue.c b/sal/android/android_native_app_glue.c
index efd7a4b8c38e..cf5d8e8575fd 100644
--- a/sal/android/android_native_app_glue.c
+++ b/sal/android/android_native_app_glue.c
@@ -22,7 +22,7 @@
#include <unistd.h>
#include <sys/resource.h>
-#include "osl/detail/android.h"
+#include "osl/detail/android_native_app_glue.h"
#include <android/log.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "threaded_app", __VA_ARGS__))
@@ -236,14 +236,9 @@ static void* android_app_entry(void* param) {
// --------------------------------------------------------------------
static struct android_app* android_app_create(ANativeActivity* activity,
- void* savedState, size_t savedStateSize)
-{
+ void* savedState, size_t savedStateSize) {
struct android_app* android_app = (struct android_app*)malloc(sizeof(struct android_app));
memset(android_app, 0, sizeof(struct android_app));
-
- // get this across to VCL.
- global_android_app = android_app;
-
android_app->activity = activity;
pthread_mutex_init(&android_app->mutex, NULL);
@@ -419,13 +414,9 @@ static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue)
android_app_set_input((struct android_app*)activity->instance, NULL);
}
-__attribute__ ((visibility("default"))) struct android_app *global_android_app = NULL;
-
__attribute__ ((visibility("default"))) void ANativeActivity_onCreate(ANativeActivity* activity,
- void* savedState, size_t savedStateSize)
-{
+ void* savedState, size_t savedStateSize) {
LOGI("Creating: %p\n", activity);
-
activity->callbacks->onDestroy = onDestroy;
activity->callbacks->onStart = onStart;
activity->callbacks->onResume = onResume;
diff --git a/sal/android/lo-bootstrap.c b/sal/android/lo-bootstrap.c
index bd9049432081..3cb8d3a25300 100644
--- a/sal/android/lo-bootstrap.c
+++ b/sal/android/lo-bootstrap.c
@@ -1470,6 +1470,13 @@ lo_get_javavm(void)
}
__attribute__ ((visibility("default")))
+struct android_app *
+lo_get_app(void)
+{
+ return app;
+}
+
+__attribute__ ((visibility("default")))
void
android_main(struct android_app* state)
{
diff --git a/sal/inc/osl/detail/android.h b/sal/inc/osl/detail/android_native_app_glue.h
index beb5b1d348a3..1b8c1f10725d 100644
--- a/sal/inc/osl/detail/android.h
+++ b/sal/inc/osl/detail/android_native_app_glue.h
@@ -30,11 +30,6 @@
extern "C" {
#endif
-/*
- * Global activity to be hooked by upper layers.
- */
-extern struct android_app *global_android_app;
-
/**
* The native activity interface provided by <android/native_activity.h>
* is based on a set of application-provided callbacks that will be called
@@ -86,6 +81,8 @@ extern struct android_app *global_android_app;
* full usage example. Also look at the JavaDoc of NativeActivity.
*/
+struct android_app;
+
/**
* Data associated with an ALooper fd that will be returned as the "outData"
* when that source has data ready.
diff --git a/solenv/inc/unxandr/lo-bootstrap.h b/solenv/inc/unxandr/lo-bootstrap.h
index 48b1a5c57e72..d78d88beaaab 100644
--- a/solenv/inc/unxandr/lo-bootstrap.h
+++ b/solenv/inc/unxandr/lo-bootstrap.h
@@ -66,6 +66,8 @@ int lo_dlcall_argc_argv(void *function,
JavaVM *lo_get_javavm(void);
+struct android_app *lo_get_app(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/vcl/android/androidinst.cxx b/vcl/android/androidinst.cxx
index aba4b0b3ca65..e6df7fb2a8e0 100644
--- a/vcl/android/androidinst.cxx
+++ b/vcl/android/androidinst.cxx
@@ -33,7 +33,8 @@
#include <android/input.h>
#include <android/looper.h>
#include <android/native_window.h>
-#include <osl/detail/android.h>
+#include <lo-bootstrap.h>
+#include <osl/detail/android_native_app_glue.h>
#include <rtl/strbuf.hxx>
static rtl::OString MotionEdgeFlagsToString(int32_t nFlags)
@@ -72,7 +73,7 @@ extern "C" {
void onAppCmd_cb (struct android_app* app, int32_t cmd)
{
fprintf (stderr, "app cmd for app %p, cmd %d\n", app, cmd);
- ANativeWindow *pWindow = global_android_app->window;
+ ANativeWindow *pWindow = app->window;
switch (cmd) {
case APP_CMD_INIT_WINDOW:
{
@@ -117,7 +118,7 @@ extern "C" {
case APP_CMD_CONTENT_RECT_CHANGED:
{
- ARect aRect = global_android_app->contentRect;
+ ARect aRect = app->contentRect;
fprintf (stderr, "content rect changed [ k/b popped up etc. ] %d,%d->%d,%d\n",
aRect.left, aRect.top, aRect.right, aRect.bottom);
break;
@@ -168,17 +169,18 @@ extern "C" {
AndroidSalInstance::AndroidSalInstance( SalYieldMutex *pMutex )
: SvpSalInstance( pMutex )
{
+ app = lo_get_app();
fprintf (stderr, "created Android Sal Instance for app %p window %p\n",
- global_android_app,
- global_android_app ? global_android_app->window : NULL);
- if (global_android_app)
+ app,
+ app ? app->window : NULL);
+ if (app)
{
- pthread_mutex_lock (&global_android_app->mutex);
- global_android_app->onAppCmd = onAppCmd_cb;
- global_android_app->onInputEvent = onInputEvent_cb;
- if (global_android_app->window != NULL)
- onAppCmd_cb (global_android_app, APP_CMD_INIT_WINDOW);
- pthread_mutex_unlock (&global_android_app->mutex);
+ pthread_mutex_lock (&app->mutex);
+ app->onAppCmd = onAppCmd_cb;
+ app->onInputEvent = onInputEvent_cb;
+ if (app->window != NULL)
+ onAppCmd_cb (app, APP_CMD_INIT_WINDOW);
+ pthread_mutex_unlock (&app->mutex);
}
}
@@ -190,8 +192,8 @@ AndroidSalInstance::~AndroidSalInstance()
void AndroidSalInstance::Wakeup()
{
fprintf (stderr, "Wakeup alooper\n");
- if (global_android_app && global_android_app->looper)
- ALooper_wake (global_android_app->looper);
+ if (app && app->looper)
+ ALooper_wake (app->looper);
else
fprintf (stderr, "busted - no global looper\n");
}
@@ -200,7 +202,6 @@ void AndroidSalInstance::DoReleaseYield (int nTimeoutMS)
{
// release yield mutex
sal_uLong nAcquireCount = ReleaseYieldMutex();
- struct android_app *pApp = global_android_app;
fprintf (stderr, "DoReleaseYield #2 %d ms\n", nTimeoutMS);
void *outData = NULL;
@@ -214,9 +215,9 @@ void AndroidSalInstance::DoReleaseYield (int nTimeoutMS)
// FIXME: this is more or less deranged: why can we not
// set a callback in the native app glue's ALooper_addFd ?
if (nRet == LOOPER_ID_MAIN)
- pApp->cmdPollSource.process(pApp, &pApp->cmdPollSource);
+ app->cmdPollSource.process(app, &app->cmdPollSource);
if (nRet == LOOPER_ID_INPUT)
- pApp->inputPollSource.process(pApp, &pApp->inputPollSource);
+ app->inputPollSource.process(app, &app->inputPollSource);
}
bool AndroidSalInstance::AnyInput( sal_uInt16 nType )
@@ -224,7 +225,7 @@ bool AndroidSalInstance::AnyInput( sal_uInt16 nType )
(void) nType;
// FIXME: ideally we should check the input queue to avoid being busy ...
fprintf (stderr, "FIXME: AnyInput returns true\n");
- // global_android_app->inputQueue ? ...
+ // app->inputQueue ? ...
return true;
}
diff --git a/vcl/inc/android/androidinst.hxx b/vcl/inc/android/androidinst.hxx
index a5c69b0f419a..3b026b0d9357 100644
--- a/vcl/inc/android/androidinst.hxx
+++ b/vcl/inc/android/androidinst.hxx
@@ -45,6 +45,7 @@ public:
virtual bool AnyInput( sal_uInt16 nType );
protected:
virtual void DoReleaseYield( int nTimeoutMS );
+ struct android_app *app;
};
#endif // ANDROID_SALINST_H