Extended double buffering fix to Android

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11360 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher 2016-03-13 23:03:42 +00:00
parent b496d18b85
commit 5c3c42f464
7 changed files with 51 additions and 179 deletions

View File

@ -24,7 +24,7 @@ LOCAL_MODULE := native-activity
LOCAL_C_INCLUDES := $(TOP_PATH)
LOCAL_SRC_FILES := \
test/button.cxx \
test/unittests.cxx \
src/flstring.c \
src/scandir.c \
src/numericsort.c \

View File

@ -22,6 +22,7 @@
#include <FL/x.H>
#include <FL/Fl_Window.H>
#include <FL/fl_draw.h>

View File

@ -44,83 +44,6 @@ Fl_Graphics_Driver *Fl_Graphics_Driver::newMainGraphicsDriver()
}
static GLint vertices[][3] = {
{ -0x10000, -0x10000, -0x10000 },
{ 0x10000, -0x10000, -0x10000 },
{ 0x10000, 0x10000, -0x10000 },
{ -0x10000, 0x10000, -0x10000 },
{ -0x10000, -0x10000, 0x10000 },
{ 0x10000, -0x10000, 0x10000 },
{ 0x10000, 0x10000, 0x10000 },
{ -0x10000, 0x10000, 0x10000 }
};
static GLint colors[][4] = {
{ 0x00000, 0x00000, 0x00000, 0x10000 },
{ 0x10000, 0x00000, 0x00000, 0x10000 },
{ 0x10000, 0x10000, 0x00000, 0x10000 },
{ 0x00000, 0x10000, 0x00000, 0x10000 },
{ 0x00000, 0x00000, 0x10000, 0x10000 },
{ 0x10000, 0x00000, 0x10000, 0x10000 },
{ 0x10000, 0x10000, 0x10000, 0x10000 },
{ 0x00000, 0x10000, 0x10000, 0x10000 }
};
GLubyte indices[] = {
0, 4, 5, 0, 5, 1,
1, 5, 6, 1, 6, 2,
2, 6, 7, 2, 7, 3,
3, 7, 4, 3, 4, 0,
4, 7, 6, 4, 6, 5,
3, 0, 1, 3, 1, 2
};
static void drawSomething()
{
/*
static float _angle = 0.0f;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -3.0f);
glRotatef(_angle, 0, 1, 0);
glRotatef(_angle*0.25f, 1, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glFrontFace(GL_CW);
glVertexPointer(3, GL_FIXED, 0, vertices);
glColorPointer(4, GL_FIXED, 0, colors);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices);
_angle += 1.2f;
*/
GLfloat q3[] = {
-10,-10,
10,-10,
10,10,
-10,10
};
uchar r, g, b;
Fl::get_color(FL_RED, r, g, b);
// Fl::get_color(Fl_Graphics_Driver::color(), r, g, b);
glColor4ub(r, g, b, 255);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, q3);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glDisableClientState(GL_VERTEX_ARRAY);
}
void Fl_PicoAndroid_Graphics_Driver::rectf(int x, int y, int w, int h)
{
GLfloat q3[] = {
@ -136,10 +59,8 @@ void Fl_PicoAndroid_Graphics_Driver::rectf(int x, int y, int w, int h)
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, q3);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
LOGI("Rect: %d %d %d %d", x, y, w, h);
}
@ -156,7 +77,7 @@ void Fl_PicoAndroid_Graphics_Driver::line(int x, int y, int x1, int y1)
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, q3);
glDrawArrays(GL_LINES,0,2);
glDrawArrays(GL_LINES, 0, 2);
glDisableClientState(GL_VERTEX_ARRAY);
}
@ -172,8 +93,8 @@ void Fl_PicoAndroid_Graphics_Driver::point(int x, int y)
glColor4ub(r, g, b, 255);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_POINTS, 0, q3);
glDrawArrays(GL_LINES,0,1);
glVertexPointer(2, GL_FLOAT, 0, q3);
glDrawArrays(GL_POINTS, 0, 1);
glDisableClientState(GL_VERTEX_ARRAY);
}

View File

@ -58,6 +58,8 @@ class FL_EXPORT Fl_PicoAndroid_Screen_Driver : public Fl_Pico_Screen_Driver
int32_t handleInputEvent(struct android_app* app, AInputEvent* event);
void initDisplay();
void termDisplay();
public:
void drawFrame();
public:

View File

@ -137,7 +137,7 @@ void Fl_PicoAndroid_Screen_Driver::drawFrame()
return;
}
eglSwapBuffers(pDisplay, pSurface);
LOGI("Swapping buffers");
// LOGI("Swapping buffers");
}
@ -253,7 +253,7 @@ int32_t Fl_PicoAndroid_Screen_Driver::handleInputEvent(struct android_app* app,
// break;
}
// AMOTION_EVENT_ACTION_MASK
LOGI("Motion at %d, %d", x, y);
// LOGI("Motion at %d, %d", x, y);
// fl_unlock_function();
Fl_X::first->w->redraw();
return 1;
@ -261,98 +261,12 @@ int32_t Fl_PicoAndroid_Screen_Driver::handleInputEvent(struct android_app* app,
return 0;
}
#if 0
static int keysym[] = { 0, FL_Button+1, FL_Button+3, FL_Button+2 };
static int px, py;
static char suppressed = 0;
fl_lock_function();
Fl_Window *window = (Fl_Window*)[(FLWindow*)[theEvent window] getFl_Window];
if ( !window->shown() ) {
fl_unlock_function();
return;
}
Fl_Window *first = Fl::first_window();
if (first != window && !(first->modal() || first->non_modal())) Fl::first_window(window);
NSPoint pos = [theEvent locationInWindow];
pos.y = window->h() - pos.y;
NSInteger btn = [theEvent buttonNumber] + 1;
NSUInteger mods = [theEvent modifierFlags];
int sendEvent = 0;
NSEventType etype = [theEvent type];
if (etype == NSLeftMouseDown || etype == NSRightMouseDown || etype == NSOtherMouseDown) {
if (btn == 1) Fl::e_state |= FL_BUTTON1;
else if (btn == 3) Fl::e_state |= FL_BUTTON2;
else if (btn == 2) Fl::e_state |= FL_BUTTON3;
}
else if (etype == NSLeftMouseUp || etype == NSRightMouseUp || etype == NSOtherMouseUp) {
if (btn == 1) Fl::e_state &= ~FL_BUTTON1;
else if (btn == 3) Fl::e_state &= ~FL_BUTTON2;
else if (btn == 2) Fl::e_state &= ~FL_BUTTON3;
}
switch ( etype ) {
case NSLeftMouseDown:
case NSRightMouseDown:
case NSOtherMouseDown:
suppressed = 0;
sendEvent = FL_PUSH;
Fl::e_is_click = 1;
px = (int)pos.x; py = (int)pos.y;
if ([theEvent clickCount] > 1)
Fl::e_clicks++;
else
Fl::e_clicks = 0;
// fall through
case NSLeftMouseUp:
case NSRightMouseUp:
case NSOtherMouseUp:
if (suppressed) {
suppressed = 0;
break;
}
if ( !window ) break;
if ( !sendEvent ) {
sendEvent = FL_RELEASE;
}
Fl::e_keysym = keysym[ btn ];
// fall through
case NSMouseMoved:
suppressed = 0;
if ( !sendEvent ) {
sendEvent = FL_MOVE;
}
// fall through
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged: {
if (suppressed) break;
if ( !sendEvent ) {
sendEvent = FL_MOVE; // Fl::handle will convert into FL_DRAG
if (fabs(pos.x-px)>5 || fabs(pos.y-py)>5)
Fl::e_is_click = 0;
}
mods_to_e_state( mods );
update_e_xy_and_e_xy_root([theEvent window]);
Fl::handle( sendEvent, window );
}
break;
default:
break;
}
fl_unlock_function();
return;
#endif
extern int main(int argc, const char **argv);
void android_main(struct android_app* state)
{
LOGI("Android Main call");
// LOGI("Android Main call");
Fl_PicoAndroid_Screen_Driver *This = (Fl_PicoAndroid_Screen_Driver*)Fl::screen_driver();
This->android_main(state);
static const char *argv[1] = { "native-activity" };

View File

@ -39,7 +39,18 @@ public:
virtual ~Fl_PicoAndroid_Window_Driver();
virtual Fl_X *makeWindow();
virtual void flush();
// --- window data
// virtual int decorated_w() = 0;
// virtual int decorated_h() = 0;
// --- window management
// virtual void take_focus();
virtual void flush_single();
virtual void flush_double();
virtual void flush_overlay();
// virtual void draw_begin();
// virtual void draw_end();
};

View File

@ -33,6 +33,7 @@
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Window_Driver.H>
#include <FL/fl_draw.h>
Fl_Window_Driver *Fl_Window_Driver::newWindowDriver(Fl_Window *win)
@ -85,7 +86,7 @@ Fl_X *Fl_PicoAndroid_Window_Driver::makeWindow()
pWindow->set_visible();
pWindow->redraw();
flush();
pWindow->flush();
int old_event = Fl::e_number;
pWindow->handle(Fl::e_number = FL_SHOW);
Fl::e_number = old_event;
@ -93,19 +94,41 @@ Fl_X *Fl_PicoAndroid_Window_Driver::makeWindow()
return x;
}
#include <FL/fl_draw.h>
void Fl_Window_Driver::draw_begin()
void Fl_PicoAndroid_Window_Driver::flush_single()
{
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
Fl_X *i = Fl_X::i(pWindow);
if (!i) return;
fl_clip_region(i->region);
i->region = 0;
pWindow->draw();
Fl_PicoAndroid_Screen_Driver *scr = (Fl_PicoAndroid_Screen_Driver*)Fl::screen_driver();
scr->drawFrame();
}
void Fl_Window_Driver::draw_end()
void Fl_PicoAndroid_Window_Driver::flush_double()
{
flush_single();
}
void Fl_PicoAndroid_Window_Driver::flush_overlay()
{
flush_single();
}
void Fl_X::flush()
{
w->flush();
}
#if 0
void Fl_PicoAndroid_Window_Driver::flush()
{
Fl_PicoAndroid_Screen_Driver *scr = (Fl_PicoAndroid_Screen_Driver*)Fl::screen_driver();
@ -117,7 +140,7 @@ void Fl_PicoAndroid_Window_Driver::flush()
// fl_rectf(10, 10, 300, 400);
scr->drawFrame();
}
#endif
//
// End of "$Id: Fl_PicoSDL_Window_Driver.cxx 11253 2016-03-01 00:54:21Z matt $".