android/experimental/desktop/native-code.cxx | 9 - android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java | 51 ++++++++-- desktop/source/app/sofficemain.cxx | 26 +---- sal/osl/unx/thread.c | 15 +- vcl/android/androidinst.cxx | 30 ++++- vcl/inc/android/androidinst.hxx | 18 ++- vcl/inc/salwtype.hxx | 1 vcl/inc/vcl/window.hxx | 1 vcl/source/window/window.cxx | 6 + 9 files changed, 102 insertions(+), 55 deletions(-)
New commits: commit 334e3dfd84b589b29a742a0c28814fa97b29313a Author: Tor Lillqvist <t...@iki.fi> Date: Thu Mar 7 02:32:50 2013 +0200 Revert "Window::PostPaint() was unused and empty" Nah, seems that it was used after all on Windows, somehow. This reverts commit 5754264f93001978a3c5f5f1cdabd7113de010b8. diff --git a/vcl/inc/vcl/window.hxx b/vcl/inc/vcl/window.hxx index fd638bc..fda621f 100644 --- a/vcl/inc/vcl/window.hxx +++ b/vcl/inc/vcl/window.hxx @@ -590,6 +590,7 @@ public: virtual void PrePaint(); virtual void Paint( const Rectangle& rRect ); + virtual void PostPaint(); virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ); virtual void Move(); virtual void Resize(); diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index ff69d88..38960af 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -4788,6 +4788,12 @@ void Window::Paint( const Rectangle& rRect ) // ----------------------------------------------------------------------- +void Window::PostPaint() +{ +} + +// ----------------------------------------------------------------------- + void Window::Draw( OutputDevice*, const Point&, const Size&, sal_uLong ) { DBG_CHKTHIS( Window, ImplDbgCheckWindow ); commit 0ce2d740a2ed93a029a290fe88748ac92baff9a0 Author: Tor Lillqvist <t...@iki.fi> Date: Thu Mar 7 02:17:49 2013 +0200 Handle damage tracking and redrawing properly in the "desktop" Android app In the damaged() method do a callback up to Java code in Desktop that invalidates the view. For now store the view in a static field, but need to do that in a cleaner way eventually. There might in some circumstancest be several instances of the Desktop activity present. Obviously should also run just one LO thread. Get rid of the temporary self-invalidattion in onDraw() silliness. Start the LO thread that runs soffice_main() from Java, not from native code. Apparently only threads created from Java have proper class loaders in Android. No need for an own DoReleaseYield() in AndroidSalInstance, the one in the SvpSalInstance base class does what needs to be done. Change-Id: I4cb85b352fca1f1375f726620ec8c93d2047f113 diff --git a/android/experimental/desktop/native-code.cxx b/android/experimental/desktop/native-code.cxx index f93c8ad..117a2ba 100644 --- a/android/experimental/desktop/native-code.cxx +++ b/android/experimental/desktop/native-code.cxx @@ -112,10 +112,11 @@ lo_get_libmap(void) { NULL, NULL } }; - // We need to pull these in, too, as they aren't in any of the libs we - // link with -Wl,--whole-archive. - extern void Java_org_libreoffice_experimental_desktop_Desktop_spawnMain(); - volatile void *p = (void *) Java_org_libreoffice_experimental_desktop_Desktop_spawnMain; + // Guard against possible function-level link-time pruning of + // "unused" code. We need to pull these in, too, as they aren't in + // any of the libs we link with -Wl,--whole-archive. Is this necessary? + extern void Java_org_libreoffice_experimental_desktop_Desktop_runMain(); + volatile void *p = (void *) Java_org_libreoffice_experimental_desktop_Desktop_runMain; extern void Java_org_libreoffice_experimental_desktop_Desktop_renderVCL(); p = (void *) Java_org_libreoffice_experimental_desktop_Desktop_renderVCL; diff --git a/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java b/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java index 6d66926..c10df22 100644 --- a/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java +++ b/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java @@ -41,10 +41,10 @@ public class Desktop { private static final String TAG = "LODesktop"; - /* implementend by desktop */ - private static native void spawnMain(); + /* In desktop */ + private static native void runMain(); - /* implementend by vcl */ + /* In vcl */ public static native void renderVCL(Bitmap bitmap); public static native void setViewSize(int width, int height); public static native void key(char c); @@ -70,6 +70,28 @@ public class Desktop Bootstrap.putenv("SAL_LOG=+WARN+INFO"); } + // This sucks, we need to experiment and think, can an app process + // have several instances of this Activity active? + static BitmapView theView; + + // This is called back from LO in the LO thread + static public void callbackDamaged() + { + synchronized (theView) { + if (!invalidatePosted) + theView.post(new Runnable() { + @Override public void run() { + synchronized (theView) { + theView.invalidate(); + invalidatePosted = false; + } + } + }); + invalidatePosted = true; + } + } + static boolean invalidatePosted; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -111,9 +133,22 @@ public class Desktop initBootstrapContext(); Log.i(TAG, "onCreate - set content view"); - setContentView(new BitmapView()); - - spawnMain(); + theView = new BitmapView(); + setContentView(theView); + + // Start a Java thread to run soffice_main(). We don't + // want to start the thread from native code becauce + // native threads apparently have no Java class loaders in + // Android, or someghin. So for instance FindClass fails. + + // See https://groups.google.com/group/android-ndk/msg/a0793f009e6e71f7?dmode=source + // . + + new Thread(new Runnable() { + @Override public void run() { + runMain(); + } + }).start(); } catch (Exception e) { e.printStackTrace(System.err); @@ -199,9 +234,6 @@ public class Desktop canvas.drawBitmap(mBitmap, 0, 0, null); canvas.restore(); renderedOnce = true; - - // re-call ourselves a bit later ... - invalidate(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) @@ -302,6 +334,7 @@ public class Desktop return true; } } + } // vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/desktop/source/app/sofficemain.cxx b/desktop/source/app/sofficemain.cxx index 7ae12fb..8a0f698 100644 --- a/desktop/source/app/sofficemain.cxx +++ b/desktop/source/app/sofficemain.cxx @@ -91,27 +91,19 @@ extern "C" int DESKTOP_DLLPUBLIC soffice_main() } #ifdef ANDROID -class MainThread : public salhelper::Thread -{ -public: - MainThread() : salhelper::Thread("vcl-mainloop") { launch(); } - virtual void execute() - { - int nRet; - do { - nRet = soffice_main(); - LOGI("soffice_main returned %d", nRet ); - } while (nRet == 81 || nRet == 79); // pretend to re-start. - exit (nRet); - } -}; extern "C" SAL_JNI_EXPORT void JNICALL -Java_org_libreoffice_experimental_desktop_Desktop_spawnMain(JNIEnv* /* env */, - jobject /* dummy */) +Java_org_libreoffice_experimental_desktop_Desktop_runMain(JNIEnv* /* env */, + jobject /* clazz */) { - new MainThread(); + int nRet; + do { + nRet = soffice_main(); + LOGI("soffice_main returned %d", nRet ); + } while (nRet == 81 || nRet == 79); // pretend to re-start. + } + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/android/androidinst.cxx b/vcl/android/androidinst.cxx index f742c1b..c353215 100644 --- a/vcl/android/androidinst.cxx +++ b/vcl/android/androidinst.cxx @@ -42,8 +42,6 @@ #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, LOGTAG, __VA_ARGS__)) #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOGTAG, __VA_ARGS__)) -static bool bHitIdle = false; - // Horrible hack static int viewWidth = 1, viewHeight = 1; @@ -305,13 +303,15 @@ void AndroidSalInstance::RedrawWindows(ANativeWindow *pWindow, ANativeWindow_Buf if (pBuffer && pWindow) ANativeWindow_unlockAndPost(pWindow); - - mbQueueReDraw = false; } void AndroidSalInstance::damaged(AndroidSalFrame */* frame */) { - mbQueueReDraw = true; + // Call the Java layer to post an invalidate if necessary + // static public void org.libreoffice.experimental.desktop.Desktop.callbackDamaged(); + + if (m_nDesktopClass != 0 && m_nCallbackDamaged != 0) + m_pJNIEnv->CallStaticVoidMethod(m_nDesktopClass, m_nCallbackDamaged); } #if 0 @@ -583,8 +583,19 @@ extern "C" { AndroidSalInstance::AndroidSalInstance( SalYieldMutex *pMutex ) : SvpSalInstance( pMutex ) - , mbQueueReDraw( false ) { + int res = (lo_get_javavm())->AttachCurrentThread(&m_pJNIEnv, NULL); + LOGI("AttachCurrentThread res=%d env=%p", res, m_pJNIEnv); + + m_nDesktopClass = m_pJNIEnv->FindClass("org/libreoffice/experimental/desktop/Desktop"); + if (m_nDesktopClass == 0) + LOGE("Could not find Desktop class"); + else { + m_nCallbackDamaged = m_pJNIEnv->GetStaticMethodID(m_nDesktopClass, "callbackDamaged", "()V"); + if (m_nCallbackDamaged == 0) + LOGE("Could not find the callbackDamaged method"); + } + LOGI("created Android Sal Instance thread: %d", (int)pthread_self()); } @@ -600,6 +611,8 @@ void AndroidSalInstance::Wakeup() LOGI("busted - no global looper"); } +#if 0 + void AndroidSalInstance::DoReleaseYield (int nTimeoutMS) { if (!bHitIdle) @@ -655,6 +668,8 @@ void AndroidSalInstance::DoReleaseYield (int nTimeoutMS) #endif } +#endif + bool AndroidSalInstance::AnyInput( sal_uInt16 nType ) { if( (nType & VCL_INPUT_TIMER) != 0 ) @@ -847,9 +862,6 @@ Java_org_libreoffice_experimental_desktop_Desktop_renderVCL(JNIEnv *env, jobject /* clazz */, jobject bitmap) { - if (!bHitIdle) - return; - AndroidBitmapInfo info; void* pixels; int ret; diff --git a/vcl/inc/android/androidinst.hxx b/vcl/inc/android/androidinst.hxx index 34c0d6e..77b6fd3 100644 --- a/vcl/inc/android/androidinst.hxx +++ b/vcl/inc/android/androidinst.hxx @@ -30,9 +30,7 @@ #ifndef ANDROID_SALINST_H #define ANDROID_SALINST_H -#include <EGL/egl.h> -#include <GLES/gl.h> - +#include <jni.h> #include <android/input.h> #include <android/native_window.h> #include <headless/svpinst.hxx> @@ -43,6 +41,17 @@ class AndroidSalInstance : public SvpSalInstance { void BlitFrameToWindow(ANativeWindow_Buffer *pOutBuffer, const basebmp::BitmapDeviceSharedPtr& aDev); + + // This JNIEnv is valid only in the thread where this + // AndroidSalInstance object is created, which is the "LO" thread + // in which soffice_main() runs + JNIEnv *m_pJNIEnv; + + // The Desktop class + jclass m_nDesktopClass; + + jmethodID m_nCallbackDamaged; + public: AndroidSalInstance( SalYieldMutex *pMutex ); virtual ~AndroidSalInstance(); @@ -66,9 +75,6 @@ public: SalFrame *getFocusFrame() const; void damaged(AndroidSalFrame *frame); -protected: - virtual void DoReleaseYield( int nTimeoutMS ); - bool mbQueueReDraw; }; #endif // ANDROID_SALINST_H commit 8ba203c726df97039125ad8b3223802fc80a9110 Author: Tor Lillqvist <t...@iki.fi> Date: Thu Mar 7 02:15:59 2013 +0200 Use __android_log_print directly Change-Id: I67d90eb58faa0427c4de894eac107cc2d05a3477 diff --git a/sal/osl/unx/thread.c b/sal/osl/unx/thread.c index 034ca81..0e1ebba 100644 --- a/sal/osl/unx/thread.c +++ b/sal/osl/unx/thread.c @@ -30,6 +30,7 @@ #include <sal/macros.h> #ifdef ANDROID #include <jni.h> +#include <android/log.h> #include <osl/detail/android-bootstrap.h> #endif @@ -242,20 +243,16 @@ static void* osl_thread_start_Impl (void* pData) if (!terminate) { #ifdef ANDROID - { - JNIEnv* env = 0; - int res = (*lo_get_javavm())->AttachCurrentThread(lo_get_javavm(), &env, NULL); // res == 0 - fprintf (stderr, "new sal thread started and attached %d!\n", res); - } + JNIEnv* env = 0; + int res = (*lo_get_javavm())->AttachCurrentThread(lo_get_javavm(), &env, NULL); + __android_log_print(ANDROID_LOG_INFO, "LibreOffice", "New sal thread started and attached res=%d", res); #endif /* call worker function */ pImpl->m_WorkerFunction(pImpl->m_pData); #ifdef ANDROID - { - int res = (*lo_get_javavm())->DetachCurrentThread(lo_get_javavm()); - fprintf (stderr, "detached finished sal thread %d!\n", res); - } + res = (*lo_get_javavm())->DetachCurrentThread(lo_get_javavm()); + __android_log_print(ANDROID_LOG_INFO, "LibreOffice", "Detached finished sal thread res=%d", res); #endif } commit 1ea2124ec68d0cf797ec212e3874dbfee2d9aa90 Author: Tor Lillqvist <t...@iki.fi> Date: Wed Mar 6 22:06:10 2013 +0200 SALEVENT_COUNT is unused Change-Id: Ia4970bd63ae5a9af40a82c894ecd077b7ca199df diff --git a/vcl/inc/salwtype.hxx b/vcl/inc/salwtype.hxx index 589baa6..5902a98 100644 --- a/vcl/inc/salwtype.hxx +++ b/vcl/inc/salwtype.hxx @@ -100,7 +100,6 @@ class FontSelectPattern; #define SALEVENT_STARTRECONVERSION ((sal_uInt16)45) #define SALEVENT_EXTERNALZOOM ((sal_uInt16)46) #define SALEVENT_EXTERNALSCROLL ((sal_uInt16)47) -#define SALEVENT_COUNT ((sal_uInt16)47) // MOUSELEAVE must send, when the pointer leave the client area and // the mouse is not captured _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits