diff options
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/Android/Fl_Android_Application.H | 18 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Application.cxx | 75 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Graphics_Driver.cxx | 24 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Screen_Driver.H | 2 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Screen_Driver.cxx | 26 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Window_Driver.H | 4 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Window_Driver.cxx | 8 |
7 files changed, 124 insertions, 33 deletions
diff --git a/src/drivers/Android/Fl_Android_Application.H b/src/drivers/Android/Fl_Android_Application.H index 73ff1ccdc..48573e7c1 100644 --- a/src/drivers/Android/Fl_Android_Application.H +++ b/src/drivers/Android/Fl_Android_Application.H @@ -120,11 +120,16 @@ public: static void pre_exec_cmd(int8_t cmd); static void post_exec_cmd(int8_t cmd); - static ANativeWindow *get_native_window() { return pNativeWindow; } + static inline ANativeWindow *native_window() { return pNativeWindow; } + static inline ANativeWindow_Buffer &graphics_buffer() { return pNativeWindowBuffer; } static int destroy_requested() { return pDestroyRequested; } 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 bool lock_screen(); + static void unlock_and_post_screen(); + static bool screen_is_locked(); + protected: static void free_saved_state(); static void print_cur_config(); @@ -134,12 +139,13 @@ protected: static void* thread_entry(void* param); static ANativeActivity *pActivity; - static AConfiguration* pConfig; - static void* pSavedState; + static AConfiguration *pConfig; + static void *pSavedState; static size_t pSavedStateSize; - static ALooper* pLooper; - static AInputQueue* pInputQueue; - static ANativeWindow* pNativeWindow; + static ALooper *pLooper; + static AInputQueue *pInputQueue; + static ANativeWindow *pNativeWindow; + static ANativeWindow_Buffer pNativeWindowBuffer; static int pActivityState; static int pDestroyRequested; static void (*pOnAppCmd)(int32_t cmd); diff --git a/src/drivers/Android/Fl_Android_Application.cxx b/src/drivers/Android/Fl_Android_Application.cxx index 18694bbab..81988b4cd 100644 --- a/src/drivers/Android/Fl_Android_Application.cxx +++ b/src/drivers/Android/Fl_Android_Application.cxx @@ -68,6 +68,9 @@ AInputQueue* Fl_Android_Application::pInputQueue = 0; // When non-NULL, this is the window surface that the app can draw in. ANativeWindow* Fl_Android_Application::pNativeWindow = 0; +// Use this buffer for direct drawing access +ANativeWindow_Buffer Fl_Android_Application::pNativeWindowBuffer = { 0 }; + // Current state of the app's activity. May be either APP_CMD_START, // APP_CMD_RESUME, APP_CMD_PAUSE, or APP_CMD_STOP; see below. int Fl_Android_Application::pActivityState = 0; @@ -314,7 +317,7 @@ void Fl_Android_Application::process_input(struct android_poll_source* source) { AInputEvent* event = NULL; while (AInputQueue_getEvent(pInputQueue, &event) >= 0) { - LOGV("New input event: type=%d\n", AInputEvent_getType(event)); + //LOGV("New input event: type=%d\n", AInputEvent_getType(event)); if (AInputQueue_preDispatchEvent(pInputQueue, event)) { continue; } @@ -363,6 +366,76 @@ void *Fl_Android_Application::thread_entry(void* param) return NULL; } +/** + * Take ownership of screen memory for gaining write access. + * + * If the screen is already locked, it will not be locked again + * and a value of true will be returned. + * + * @return true if we gaines access, false if no access was granted and screen memory must not be writte to + */ +bool Fl_Android_Application::lock_screen() +{ + if (screen_is_locked()) + return true; + + // TODO: or should we wait until the window is mapped? + // TODO: see also Fl_Window_Driver::wait_for_expose_value + if (!pNativeWindow) { + log_w("Unable to lock window buffer: no native window found."); + return false; + } + + // 190, 200, 280, 35 + ARect dirty = { .left=190, .top = 200, .right = 290, .bottom = 235 }; + if (ANativeWindow_lock(pNativeWindow, &pNativeWindowBuffer, &dirty) < 0) { + log_w("Unable to lock window buffer: Android won't lock."); + return false; + } + log_w("Dirty rect is %d %d %d %d", dirty.left, dirty.top, dirty.right, dirty.bottom); + + ANativeWindow_Buffer buf; + if (ANativeWindow_lock(pNativeWindow, &buf, &dirty) < 0) { + log_w("Unable to lock 2nd window buffer: Android won't lock."); + return false; + } + + return true; +} + +#include <FL/fl_draw.H> + +/** + * Release screen memory ownership and give it back to the system. + * + * The memory content will be copied to the physical screen next. + * If the screen is not locked, this call will have no effect. + */ +void Fl_Android_Application::unlock_and_post_screen() +{ + if (!screen_is_locked()) + return; + + static int i = 0; + fl_color( (i&1) ? FL_RED : FL_GREEN); + fl_rectf(i*10, 700, 50, 50); + i++; + if (i>10) i = 0; + + ANativeWindow_unlockAndPost(pNativeWindow); + pNativeWindowBuffer.bits = 0L; // avoid any misunderstandings... +} + +/** + * Is the screen currently locked? + * @return true if it is locked and the app has write access. + */ +bool Fl_Android_Application::screen_is_locked() +{ + return (pNativeWindowBuffer.bits!=0L); +} + + // -------------------------------------------------------------------- // Native activity interaction (called from main thread) // -------------------------------------------------------------------- diff --git a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx index ca74ef539..c9780c8d8 100644 --- a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx @@ -27,8 +27,6 @@ #include "Fl_Android_Screen_Driver.H" #include <android/log.h> -extern ANativeWindow_Buffer* gAGraphicsBuffer; - #define LOG_TAG "FLTK" #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) #define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__) @@ -71,14 +69,14 @@ void Fl_Android_Graphics_Driver::rectf_unscaled(float x, float y, float w, float // TODo: clip the rectangle to all parts of the current clipping region uint16_t cc = make565(color()); - uint32_t ss = gAGraphicsBuffer->stride; - uint16_t *bits = (uint16_t*)gAGraphicsBuffer->bits; + uint32_t ss = Fl_Android_Application::graphics_buffer().stride; + uint16_t *bits = (uint16_t*)Fl_Android_Application::graphics_buffer().bits; uint32_t xx = (uint32_t)x; uint32_t yy = (uint32_t)y; uint32_t ww = (uint32_t)w; uint32_t hh = (uint32_t)h; - for (uint32_t iy = yy; iy<hh; ++iy) { - uint16_t *d = bits + iy*ss + xx; + for (uint32_t iy = 0; iy<hh; ++iy) { + uint16_t *d = bits + (iy+yy)*ss + xx; for (uint32_t ix = ww; ix>0; --ix) { *d++ = cc; } @@ -95,8 +93,8 @@ void Fl_Android_Graphics_Driver::xyline_unscaled(float x, float y, float x1) w = x-x1; x = x1; } - uint32_t ss = gAGraphicsBuffer->stride; - uint16_t *bits = (uint16_t*)gAGraphicsBuffer->bits; + uint32_t ss = Fl_Android_Application::graphics_buffer().stride; + uint16_t *bits = (uint16_t*)Fl_Android_Application::graphics_buffer().bits; uint32_t xx = (uint32_t)x; uint32_t yy = (uint32_t)y; uint32_t ww = (uint32_t)w; @@ -116,8 +114,8 @@ void Fl_Android_Graphics_Driver::yxline_unscaled(float x, float y, float y1) h = y-y1; y = y1; } - uint32_t ss = gAGraphicsBuffer->stride; - uint16_t *bits = (uint16_t*)gAGraphicsBuffer->bits; + uint32_t ss = Fl_Android_Application::graphics_buffer().stride; + uint16_t *bits = (uint16_t*)Fl_Android_Application::graphics_buffer().bits; uint32_t xx = (uint32_t)x; uint32_t yy = (uint32_t)y; uint32_t hh = (uint32_t)h; @@ -144,7 +142,7 @@ static int render_letter(int xx, int yy, uint32_t c) int w,h,i,j, size = 30; int dx, dy; -LOGE("Render letter %c", c); +//LOGE("Render letter %c", c); if (once==0) { once = 1; FILE *f = fopen("/system/fonts/DroidSans.ttf", "rb"); @@ -186,8 +184,8 @@ if (once==0) { // rrrr.rggg.gggb.bbbb xx += dx; yy += dy; uint16_t cc = make565(fl_color()), cc12 = (cc&0xf7de)>>1, cc14 = (cc12&0xf7de)>>1, cc34 = cc12+cc14; - uint32_t ss = gAGraphicsBuffer->stride; - uint16_t *bits = (uint16_t*)gAGraphicsBuffer->bits; + uint32_t ss = Fl_Android_Application::graphics_buffer().stride; + uint16_t *bits = (uint16_t*)Fl_Android_Application::graphics_buffer().bits; uint32_t ww = w; uint32_t hh = h; unsigned char *s = bitmap; diff --git a/src/drivers/Android/Fl_Android_Screen_Driver.H b/src/drivers/Android/Fl_Android_Screen_Driver.H index c829ae183..0aff97c04 100644 --- a/src/drivers/Android/Fl_Android_Screen_Driver.H +++ b/src/drivers/Android/Fl_Android_Screen_Driver.H @@ -79,8 +79,8 @@ public: // --- audible output virtual void beep(int type); // --- global events - virtual void flush(); #endif + virtual void flush(); virtual double wait(double time_to_wait); #if 0 virtual int ready(); diff --git a/src/drivers/Android/Fl_Android_Screen_Driver.cxx b/src/drivers/Android/Fl_Android_Screen_Driver.cxx index e05b1b883..1ffdc382a 100644 --- a/src/drivers/Android/Fl_Android_Screen_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Screen_Driver.cxx @@ -19,6 +19,7 @@ #include "../../config_lib.h" #include "Fl_Android_Screen_Driver.H" +#include "Fl_Android_Application.H" #include "./Fl_Font.H" #include <FL/Fl.H> #include <FL/platform.H> @@ -27,13 +28,6 @@ #include <FL/fl_ask.H> #include <stdio.h> -#include <android/log.h> - -#define LOG_TAG "FLTK" -#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) -#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__) -#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) -#define LOGV(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) static void nothing() {} void (*fl_unlock_function)() = nothing; @@ -375,14 +369,24 @@ void Fl_WinAPI_Screen_Driver::beep(int type) break; } } +#endif - -void Fl_WinAPI_Screen_Driver::flush() +/** + * On Android, get access to screen memory, then flush(), then + * release screen memory and post it to the physicla screen. + * + * Don't do anything if the screen wasn't previously locked by + * any Fl_Window_Driver. We would just needlessly repost the same screen. + */ +void Fl_Android_Screen_Driver::flush() { - GdiFlush(); + if (Fl_Android_Application::screen_is_locked()) { + Fl_Screen_Driver::flush(); + Fl_Android_Application::unlock_and_post_screen(); + } } - +#if 0 extern void fl_fix_focus(); // in Fl.cxx // We have to keep track of whether we have captured the mouse, since diff --git a/src/drivers/Android/Fl_Android_Window_Driver.H b/src/drivers/Android/Fl_Android_Window_Driver.H index 454c86de1..2fa1619d8 100644 --- a/src/drivers/Android/Fl_Android_Window_Driver.H +++ b/src/drivers/Android/Fl_Android_Window_Driver.H @@ -103,8 +103,8 @@ public: virtual void flush_double(); virtual void flush_overlay(); virtual void draw_begin(); - virtual void make_current() { sCurrent = this; } #endif + virtual void make_current(); virtual void show(); #if 0 virtual void label(const char *name,const char *iname); @@ -134,6 +134,8 @@ public: #endif +// Leuwer: 0171 473 1850 + }; diff --git a/src/drivers/Android/Fl_Android_Window_Driver.cxx b/src/drivers/Android/Fl_Android_Window_Driver.cxx index 0df617faf..fab8190db 100644 --- a/src/drivers/Android/Fl_Android_Window_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Window_Driver.cxx @@ -29,6 +29,7 @@ #include "Fl_Android_Window_Driver.H" #include "Fl_Android_Screen_Driver.H" #include "Fl_Android_Graphics_Driver.H" +#include "Fl_Android_Application.H" #if 0 @@ -73,6 +74,13 @@ void Fl_Android_Window_Driver::show() } } + +void Fl_Android_Window_Driver::make_current() +{ + Fl_Android_Application::lock_screen(); +} + + #if 0 Fl_WinAPI_Window_Driver::Fl_WinAPI_Window_Driver(Fl_Window *win) |
