diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2018-03-07 16:29:31 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2018-03-07 16:29:31 +0000 |
| commit | dcc10a6a0a4cf0ec6e2a2a95f8b110230d65f1aa (patch) | |
| tree | cf3eb30b0a11f54c0ed89013d07ac23619201a85 /src/drivers/Android | |
| parent | 2df5cb850a8aa3388cd5bc1ef0c8d3bc6f214d4f (diff) | |
Android: improvements to Fl:flush() implementation. Initial draw, no wasted draw cycles.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12717 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/Android')
| -rw-r--r-- | src/drivers/Android/Fl_Android_Application.H | 10 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Application.cxx | 36 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Screen_Driver.cxx | 6 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Window_Driver.cxx | 1 |
4 files changed, 31 insertions, 22 deletions
diff --git a/src/drivers/Android/Fl_Android_Application.H b/src/drivers/Android/Fl_Android_Application.H index f88d29c3c..b141a7e7f 100644 --- a/src/drivers/Android/Fl_Android_Application.H +++ b/src/drivers/Android/Fl_Android_Application.H @@ -126,7 +126,7 @@ public: static void set_on_app_cmd(void (*cmd)(int32_t cmd)) { pOnAppCmd = cmd; } static void set_on_input_event(int32_t (*cmd)(AInputEvent* event)) { pOnInputEvent = cmd; } - static void copy_screen(); + static bool copy_screen(); protected: static void free_saved_state(); @@ -145,7 +145,8 @@ protected: static AConfiguration *pConfig; static void *pSavedState; static size_t pSavedStateSize; - static ALooper *pLooper; + static ALooper *pMsgPipeLooper; + static ALooper *pRedrawLooper; static AInputQueue *pInputQueue; static ANativeWindow *pNativeWindow; static ANativeWindow_Buffer pNativeWindowBuffer; @@ -155,12 +156,11 @@ protected: static void (*pOnAppCmd)(int32_t cmd); static int32_t (*pOnInputEvent)(AInputEvent* event); - // ---- no need to make these visible to the outside ---- static pthread_mutex_t pMutex; static pthread_cond_t pCond; - static int pMsgRead; - static int pMsgWrite; + static int pMsgReadPipe; + static int pMsgWritePipe; static pthread_t pThread; static struct android_poll_source pCmdPollSource; static struct android_poll_source pInputPollSource; diff --git a/src/drivers/Android/Fl_Android_Application.cxx b/src/drivers/Android/Fl_Android_Application.cxx index 0219d66fe..dbaa97d04 100644 --- a/src/drivers/Android/Fl_Android_Application.cxx +++ b/src/drivers/Android/Fl_Android_Application.cxx @@ -59,7 +59,10 @@ void* Fl_Android_Application::pSavedState = 0; size_t Fl_Android_Application::pSavedStateSize = 0; // The ALooper associated with the app's thread. -ALooper* Fl_Android_Application::pLooper = 0; +ALooper* Fl_Android_Application::pMsgPipeLooper = 0; + +// The ALooper tht interrupts the main loop when FLTK requests a redraw. +ALooper* Fl_Android_Application::pRedrawLooper = 0; // When non-NULL, this is the input queue from which the app will // receive user input events. @@ -91,8 +94,8 @@ int32_t (*Fl_Android_Application::pOnInputEvent)(AInputEvent* event) = 0; pthread_mutex_t Fl_Android_Application::pMutex = { 0 }; pthread_cond_t Fl_Android_Application::pCond = { 0 }; -int Fl_Android_Application::pMsgRead = 0; -int Fl_Android_Application::pMsgWrite = 0; +int Fl_Android_Application::pMsgReadPipe = 0; +int Fl_Android_Application::pMsgWritePipe = 0; pthread_t Fl_Android_Application::pThread = 0; struct android_poll_source Fl_Android_Application::pCmdPollSource = { 0 }; struct android_poll_source Fl_Android_Application::pInputPollSource = { 0 }; @@ -164,7 +167,7 @@ void Fl_Android_Application::free_saved_state() int8_t Fl_Android_Application::read_cmd() { int8_t cmd; - if (read(pMsgRead, &cmd, sizeof(cmd)) == sizeof(cmd)) { + if (read(pMsgReadPipe, &cmd, sizeof(cmd)) == sizeof(cmd)) { switch (cmd) { case APP_CMD_SAVE_STATE: free_saved_state(); @@ -222,7 +225,7 @@ void Fl_Android_Application::pre_exec_cmd(int8_t cmd) if (pInputQueue != NULL) { LOGV("Attaching input queue to looper"); AInputQueue_attachLooper(pInputQueue, - pLooper, LOOPER_ID_INPUT, NULL, + pMsgPipeLooper, LOOPER_ID_INPUT, NULL, &pInputPollSource); } pthread_cond_broadcast(&pCond); @@ -350,10 +353,10 @@ void *Fl_Android_Application::thread_entry(void* param) pInputPollSource.id = LOOPER_ID_INPUT; pInputPollSource.process = process_input; - ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); - ALooper_addFd(looper, pMsgRead, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL, + ALooper *looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); + ALooper_addFd(looper, pMsgReadPipe, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL, &pCmdPollSource); - pLooper = looper; + pMsgPipeLooper = looper; pthread_mutex_lock(&pMutex); pRunning = 1; @@ -384,8 +387,9 @@ void Fl_Android_Application::allocate_screen() { #include <FL/fl_draw.H> -void Fl_Android_Application::copy_screen() +bool Fl_Android_Application::copy_screen() { + bool ret = false; if (lock_screen()) { static int i = 0; @@ -413,7 +417,11 @@ void Fl_Android_Application::copy_screen() dst += dstStride; } unlock_and_post_screen(); + ret = true; + } else { + Fl::damage(FL_DAMAGE_EXPOSE); } + return ret; } /** @@ -475,7 +483,7 @@ bool Fl_Android_Application::screen_is_locked() void Fl_Android_Activity::write_cmd(int8_t cmd) { - if (write(pMsgWrite, &cmd, sizeof(cmd)) != sizeof(cmd)) { + if (write(pMsgWritePipe, &cmd, sizeof(cmd)) != sizeof(cmd)) { LOGE("Failure writing android_app cmd: %s\n", strerror(errno)); } } @@ -530,8 +538,8 @@ void Fl_Android_Activity::free() } pthread_mutex_unlock(&pMutex); - close(pMsgRead); - close(pMsgWrite); + close(pMsgReadPipe); + close(pMsgWritePipe); pthread_cond_destroy(&pCond); pthread_mutex_destroy(&pMutex); } @@ -733,8 +741,8 @@ void Fl_Android_Activity::create(ANativeActivity* activity, void* savedState, LOGE("could not create pipe: %s", strerror(errno)); return; } - pMsgRead = msgpipe[0]; - pMsgWrite = msgpipe[1]; + pMsgReadPipe = msgpipe[0]; + pMsgWritePipe = msgpipe[1]; pthread_attr_t attr; pthread_attr_init(&attr); diff --git a/src/drivers/Android/Fl_Android_Screen_Driver.cxx b/src/drivers/Android/Fl_Android_Screen_Driver.cxx index 3b6fdf677..0a187ca9c 100644 --- a/src/drivers/Android/Fl_Android_Screen_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Screen_Driver.cxx @@ -378,10 +378,10 @@ void Fl_WinAPI_Screen_Driver::beep(int type) void Fl_Android_Screen_Driver::flush() { Fl_Screen_Driver::flush(); - // FIXME: do this only if anything actually changed on screen! + // FIXME: do this only if anything actually changed on screen (need to optimize)! if (pScreenContentChanged) { - Fl_Android_Application::copy_screen(); - pScreenContentChanged = false; + if (Fl_Android_Application::copy_screen()) + pScreenContentChanged = false; } } diff --git a/src/drivers/Android/Fl_Android_Window_Driver.cxx b/src/drivers/Android/Fl_Android_Window_Driver.cxx index dddd18c5d..42ffe2917 100644 --- a/src/drivers/Android/Fl_Android_Window_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Window_Driver.cxx @@ -69,6 +69,7 @@ void Fl_Android_Window_Driver::show() i(x); x->next = Fl_X::first; Fl_X::first = x; + pWindow->redraw(); } else { // bring window to front } |
