From ee104a028537daaddd8f0cc4c36ad1e0a3be2fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=AF=E6=AD=8C?= Date: Thu, 5 Aug 2021 12:00:22 +0800 Subject: [PATCH] remaking looper impl,remove MessageListener --- apps/samples/animation.cc | 6 +- apps/samples/emptywin.cc | 4 +- apps/samples/loopersample.cc | 26 - apps/samples/multiwindow.cc | 10 +- apps/samples/tetris.cc | 8 +- apps/samples/textview_exam.cc | 8 +- apps/uidemo/lyrics.cc | 6 +- apps/uidemo/lyrics.h | 2 +- apps/uidemo/lyricsview.cc | 1 - apps/uidemo/multimedia.cc | 1 - src/3rdparty/libjpeg-turbo/CMakeLists.txt | 4 +- src/gui/CMakeLists.txt | 3 +- src/gui/animation/animation.h | 2 +- src/gui/animation/animator.cc | 2 + src/gui/animation/animator.h | 2 +- src/gui/{core => animation}/interpolators.cc | 2 +- src/gui/{core => animation}/interpolators.h | 0 src/gui/animation/layouttransition.h | 1 - src/gui/animation/scaleanimation.h | 2 +- src/gui/animation/transformation.h | 6 +- src/gui/core/alooper.cc | 57 -- src/gui/core/app.cc | 22 +- src/gui/core/app.h | 10 +- src/gui/core/assets.h | 1 - src/gui/core/asynsource.cc | 73 --- src/gui/core/asynsource.h | 53 -- src/gui/core/canvas.h | 2 +- src/gui/core/choreographer.cc | 2 +- src/gui/core/choreographer.h | 2 +- src/gui/core/context.h | 30 +- src/gui/core/eventcodes.h | 2 +- src/gui/core/graph_device.h | 2 +- src/gui/core/gravity.h | 2 +- src/gui/core/inputeventlabels.h | 2 +- src/gui/core/inputeventsource.cc | 37 +- src/gui/core/inputeventsource.h | 13 +- src/gui/core/layout.h | 2 +- src/gui/core/looper.cc | 582 +++++++++++++++++++ src/gui/core/{alooper.h => looper.h} | 68 ++- src/gui/core/scheduler.cc | 14 +- src/gui/core/scheduler.h | 14 +- src/gui/core/scroller.h | 4 +- src/gui/core/uievents.h | 6 +- src/gui/core/uieventsource.cc | 152 ++--- src/gui/core/uieventsource.h | 42 +- src/gui/core/velocitytracker.h | 2 +- src/gui/core/windowmanager.cc | 20 +- src/gui/drawables/colorfilters.h | 2 +- src/gui/drawables/colorstatelist.h | 4 +- src/gui/drawables/drawable.h | 10 +- src/gui/drawables/shape.h | 3 +- src/gui/drawables/stateset.h | 2 +- src/gui/looper/EventLoop.cpp | 227 -------- src/gui/looper/EventLoop.h | 61 -- src/gui/looper/EventSource.h | 55 -- src/gui/looper/FileEvents.h | 43 -- src/gui/looper/FileSource.h | 58 -- src/gui/looper/GenericSignalSource.cpp | 81 --- src/gui/looper/GenericSignalSource.h | 23 - src/gui/looper/IdleSource.h | 39 -- src/gui/looper/Platform.h | 9 - src/gui/looper/SignalFD.cpp | 53 -- src/gui/looper/SignalFD.h | 35 -- src/gui/looper/SignalSource.cpp | 66 --- src/gui/looper/SignalSource.h | 43 -- src/gui/looper/TimeoutSource.cpp | 46 -- src/gui/looper/TimeoutSource.h | 40 -- src/gui/looper/TimerFD.cpp | 78 --- src/gui/looper/TimerFD.h | 62 -- src/gui/looper/Utility.h | 26 - src/gui/looper/looper.h | 20 - src/gui/views/toastwindow.cc | 6 +- src/gui/views/toastwindow.h | 1 - src/gui/widget/abslistview.cc | 3 +- src/gui/widget/abslistview.h | 3 +- src/gui/widget/absspinner.h | 2 +- src/gui/widget/adapter.cc | 6 +- src/gui/widget/analogclock.cc | 8 +- src/gui/widget/analogclock.h | 2 +- src/gui/widget/edgeeffect.h | 6 +- src/gui/widget/horizontalscrollview.h | 1 - src/gui/widget/imageview.cc | 6 +- src/gui/widget/keyboardview.h | 2 +- src/gui/widget/layoutparams.h | 4 +- src/gui/widget/numberpicker.cc | 1 - src/gui/widget/numberpicker.h | 5 +- src/gui/widget/overscroller.cc | 6 +- src/gui/widget/overscroller.h | 6 +- src/gui/widget/progressbar.cc | 7 +- src/gui/widget/recyclebin.h | 2 +- src/gui/widget/scrollview.h | 1 - src/gui/widget/simplemonthview.h | 2 +- src/gui/widget/tablerow.h | 2 +- src/gui/widget/textview.h | 4 +- src/gui/widget/view.cc | 54 +- src/gui/widget/view.h | 32 +- src/gui/widget/viewgroup.cc | 36 -- src/gui/widget/viewgroup.h | 9 +- src/gui/widget/viewpager.cc | 4 +- src/gui/widget/viewpager.h | 3 +- src/gui/widget/window.cc | 17 +- src/gui/widget/window.h | 8 +- src/gui/windows.h | 4 +- src/porting/ali3528/ngl_mediaplayer.c | 66 ++- src/porting/x86/CMakeLists.txt | 1 + tests/gui/app_tests.cc | 13 - tests/gui/benchmark_tests.cc | 2 +- tests/gui/calendar_tests.cc | 3 +- tests/gui/drawable_tests.cc | 4 +- tests/gui/drawablemutate_tests.cc | 6 +- tests/gui/image_unittests.cc | 6 +- tests/gui/looper_tests.cc | 100 ++++ tests/gui/motion_tests.cc | 2 +- tests/gui/preference_tests.cc | 2 +- tests/gui/rect_tests.cc | 1 - tests/gui/scheduler_tests.cc | 18 +- tests/gui/surface_unittests.cc | 6 +- tests/gui/textlayout_tests.cc | 1 - tests/gui/widget_tests.cc | 21 +- tests/gui/window_tests.cc | 25 +- tests/porting/input_unittests.cc | 2 +- 121 files changed, 1114 insertions(+), 1816 deletions(-) mode change 100644 => 100755 apps/samples/animation.cc delete mode 100644 apps/samples/loopersample.cc mode change 100644 => 100755 apps/samples/multiwindow.cc mode change 100644 => 100755 apps/uidemo/lyrics.cc mode change 100644 => 100755 apps/uidemo/lyrics.h mode change 100644 => 100755 apps/uidemo/lyricsview.cc mode change 100644 => 100755 apps/uidemo/multimedia.cc mode change 100644 => 100755 src/3rdparty/libjpeg-turbo/CMakeLists.txt rename src/gui/{core => animation}/interpolators.cc (97%) mode change 100644 => 100755 rename src/gui/{core => animation}/interpolators.h (100%) mode change 100644 => 100755 delete mode 100755 src/gui/core/alooper.cc mode change 100644 => 100755 src/gui/core/app.h mode change 100644 => 100755 src/gui/core/assets.h delete mode 100644 src/gui/core/asynsource.cc delete mode 100755 src/gui/core/asynsource.h mode change 100644 => 100755 src/gui/core/eventcodes.h mode change 100644 => 100755 src/gui/core/graph_device.h mode change 100644 => 100755 src/gui/core/gravity.h mode change 100644 => 100755 src/gui/core/inputeventlabels.h mode change 100644 => 100755 src/gui/core/layout.h create mode 100755 src/gui/core/looper.cc rename src/gui/core/{alooper.h => looper.h} (63%) mode change 100644 => 100755 src/gui/core/scheduler.cc mode change 100644 => 100755 src/gui/core/scheduler.h mode change 100644 => 100755 src/gui/core/scroller.h mode change 100644 => 100755 src/gui/core/uieventsource.cc mode change 100644 => 100755 src/gui/core/uieventsource.h mode change 100644 => 100755 src/gui/core/velocitytracker.h mode change 100644 => 100755 src/gui/drawables/colorfilters.h mode change 100644 => 100755 src/gui/drawables/colorstatelist.h mode change 100644 => 100755 src/gui/drawables/shape.h mode change 100644 => 100755 src/gui/drawables/stateset.h delete mode 100755 src/gui/looper/EventLoop.cpp delete mode 100644 src/gui/looper/EventLoop.h delete mode 100644 src/gui/looper/EventSource.h delete mode 100644 src/gui/looper/FileEvents.h delete mode 100644 src/gui/looper/FileSource.h delete mode 100644 src/gui/looper/GenericSignalSource.cpp delete mode 100644 src/gui/looper/GenericSignalSource.h delete mode 100644 src/gui/looper/IdleSource.h delete mode 100644 src/gui/looper/Platform.h delete mode 100644 src/gui/looper/SignalFD.cpp delete mode 100644 src/gui/looper/SignalFD.h delete mode 100644 src/gui/looper/SignalSource.cpp delete mode 100644 src/gui/looper/SignalSource.h delete mode 100644 src/gui/looper/TimeoutSource.cpp delete mode 100644 src/gui/looper/TimeoutSource.h delete mode 100644 src/gui/looper/TimerFD.cpp delete mode 100644 src/gui/looper/TimerFD.h delete mode 100644 src/gui/looper/Utility.h delete mode 100644 src/gui/looper/looper.h mode change 100644 => 100755 src/gui/views/toastwindow.cc mode change 100644 => 100755 src/gui/views/toastwindow.h mode change 100644 => 100755 src/gui/widget/absspinner.h mode change 100644 => 100755 src/gui/widget/adapter.cc mode change 100644 => 100755 src/gui/widget/analogclock.cc mode change 100644 => 100755 src/gui/widget/analogclock.h mode change 100644 => 100755 src/gui/widget/edgeeffect.h mode change 100644 => 100755 src/gui/widget/horizontalscrollview.h mode change 100644 => 100755 src/gui/widget/imageview.cc mode change 100644 => 100755 src/gui/widget/layoutparams.h mode change 100644 => 100755 src/gui/widget/numberpicker.cc mode change 100644 => 100755 src/gui/widget/numberpicker.h mode change 100644 => 100755 src/gui/widget/scrollview.h mode change 100644 => 100755 src/gui/widget/simplemonthview.h mode change 100644 => 100755 src/gui/widget/tablerow.h mode change 100644 => 100755 src/porting/ali3528/ngl_mediaplayer.c mode change 100644 => 100755 tests/gui/app_tests.cc mode change 100644 => 100755 tests/gui/calendar_tests.cc mode change 100644 => 100755 tests/gui/drawablemutate_tests.cc create mode 100755 tests/gui/looper_tests.cc mode change 100644 => 100755 tests/gui/motion_tests.cc mode change 100644 => 100755 tests/gui/preference_tests.cc mode change 100644 => 100755 tests/gui/rect_tests.cc mode change 100644 => 100755 tests/gui/scheduler_tests.cc diff --git a/apps/samples/animation.cc b/apps/samples/animation.cc old mode 100644 new mode 100755 index 867520a0..90a71e79 --- a/apps/samples/animation.cc +++ b/apps/samples/animation.cc @@ -21,7 +21,7 @@ public : canvas.stroke(); } - virtual bool onMessage(DWORD msg,DWORD wp,ULONG lp)override{ + /*virtual bool onMessage(DWORD msg,DWORD wp,ULONG lp)override{ if(msg==1000){ matrix.scale(cx,cx);cx+=0.01f; matrix.rotate(cx); @@ -30,7 +30,7 @@ public : return true; } return Window::onMessage(msg,wp,lp);; - } + }*/ }; int main(int argc,const char*argv[]){ @@ -40,7 +40,7 @@ int main(int argc,const char*argv[]){ w->addView(new TextView("HelloWorld",400,80)); - w->sendMessage(1000,0,0,500); + //w->sendMessage(1000,0,0,500); return app.exec(); } diff --git a/apps/samples/emptywin.cc b/apps/samples/emptywin.cc index 513750c1..1f735359 100755 --- a/apps/samples/emptywin.cc +++ b/apps/samples/emptywin.cc @@ -75,12 +75,12 @@ public: canvas->fill(); mDegrees=0; } - bool onMessage(DWORD msg,DWORD wp,ULONG lp)override{ + /*bool onMessage(DWORD msg,DWORD wp,ULONG lp)override{ if(msg==1000){ invalidate(nullptr); } return Window::onMessage(msg,wp,lp); - } + }*/ }; int main(int argc,const char*argv[]){ App app(argc,argv); diff --git a/apps/samples/loopersample.cc b/apps/samples/loopersample.cc deleted file mode 100644 index 3a00b9c3..00000000 --- a/apps/samples/loopersample.cc +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc,const char*argv[]){ - App app(argc,argv); - AsyncEventSource*as=new AsyncEventSource(); - Looper::getDefault()->add_event_source(as,[](EventSource&){return true;}); - for(int i=0;i<10;i++){ - std::future res=as->enqueue([i](int a)->int{ - usleep((a+500)*1000); - std::cout<1280)dx*=-1; @@ -22,7 +22,7 @@ public: setPos(x+dx,y+dy); return true; } - return Window::onMessage(msgid,wp,lp); + return true;//Window::onMessage(msgid,wp,lp); } void onDraw(Canvas&c)override{ srand(time(nullptr)*(long)this); @@ -52,9 +52,9 @@ int main(int argc,const char*argv[]){ w2->addView(lv2).setId(0); if(argc>5){ - w1->sendMessage(1000,0,2000,100);w1->setDir(50,40); - w2->sendMessage(1000,0,1000,80);w2->setDir(66,53); - w3->sendMessage(1000,0,200,85);w3->setDir(23,13); + //w1->sendMessage(1000,0,2000,100);w1->setDir(50,40); + //w2->sendMessage(1000,0,1000,80);w2->setDir(66,53); + //w3->sendMessage(1000,0,200,85);w3->setDir(23,13); } return app.exec(); } diff --git a/apps/samples/tetris.cc b/apps/samples/tetris.cc index 0c17b3c9..93cb4ee1 100755 --- a/apps/samples/tetris.cc +++ b/apps/samples/tetris.cc @@ -108,7 +108,7 @@ private: Spinner*mLevelSelector; Button*mStartButton; protected: - bool onMessage(DWORD msgid,DWORD wp,ULONG lp)override; + bool onMessage(DWORD msgid,DWORD wp,ULONG lp); void onDraw(Canvas&canvas)override; bool onKeyUp(int keyCode,KeyEvent&event)override; public: @@ -241,7 +241,7 @@ void TetrisWindow::ResetBlock(){ } void TetrisWindow::StartGame(){ - sendMessage(WM_REFRESH,0,0,speed_ms); + //sendMessage(WM_REFRESH,0,0,speed_ms); //产生初始下一个方块 int block_id=rand()%7; CreateBlock(next_block,block_id); @@ -279,9 +279,9 @@ bool TetrisWindow::onMessage(DWORD msgid,DWORD wp,ULONG lp){ if((msgid==WM_REFRESH)&&(!mGameIsOver)){ BlockMove(DOWN); invalidate(nullptr); - sendMessage(msgid,wp,lp,speed_ms); + //sendMessage(msgid,wp,lp,speed_ms); }else - return Window::onMessage(msgid,wp,lp); + return true;//Window::onMessage(msgid,wp,lp); } void TetrisWindow::GameOver(){ diff --git a/apps/samples/textview_exam.cc b/apps/samples/textview_exam.cc index e3b06e1b..5e655b5e 100755 --- a/apps/samples/textview_exam.cc +++ b/apps/samples/textview_exam.cc @@ -10,7 +10,7 @@ protected: TextView*tv3; public: TestWindow(int w,int h); - bool onMessage(DWORD msg,DWORD wp,ULONG lp)override; + bool onMessage(DWORD msg,DWORD wp,ULONG lp); }; TestWindow::TestWindow(int w,int h):Window(0,0,w,h){ @@ -78,16 +78,16 @@ bool TestWindow::onMessage(DWORD msg,DWORD wp,ULONG lp){ if(flag>0){lvl+=200;if(lvl>=10000)flag=-1;} if(flag<0){lvl-=200;if(lvl<=0)flag=1;} tv3->getForeground()->setLevel(lvl); - sendMessage(msg,wp,lp,200); + //sendMessage(msg,wp,lp,200); }break; - default:return Window::onMessage(msg,wp,lp); + default:return true;//Window::onMessage(msg,wp,lp); } } int main(int argc,const char*argv[]){ App app(argc,argv); Window*w=new TestWindow(1080,720); - w->sendMessage(View::WM_TIMER,0,0,500); + //w->sendMessage(View::WM_TIMER,0,0,500); app.exec(); return 0; } diff --git a/apps/uidemo/lyrics.cc b/apps/uidemo/lyrics.cc old mode 100644 new mode 100755 index 06e01422..842a1818 --- a/apps/uidemo/lyrics.cc +++ b/apps/uidemo/lyrics.cc @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -14,8 +14,8 @@ using namespace tag; #include #include -#include -#include +#include +#include namespace priv{ diff --git a/apps/uidemo/lyrics.h b/apps/uidemo/lyrics.h old mode 100644 new mode 100755 index 8365ace1..fcf26dfe --- a/apps/uidemo/lyrics.h +++ b/apps/uidemo/lyrics.h @@ -1,6 +1,6 @@ #ifndef __ID3_LYRICS__H__ #define __ID3_LYRICS__H__ -#include +#include #include #include #include diff --git a/apps/uidemo/lyricsview.cc b/apps/uidemo/lyricsview.cc old mode 100644 new mode 100755 index 8d89d9d4..f3949033 --- a/apps/uidemo/lyricsview.cc +++ b/apps/uidemo/lyricsview.cc @@ -1,5 +1,4 @@ #include -#include #include #include #include diff --git a/apps/uidemo/multimedia.cc b/apps/uidemo/multimedia.cc old mode 100644 new mode 100755 index 7e4cc396..cf956596 --- a/apps/uidemo/multimedia.cc +++ b/apps/uidemo/multimedia.cc @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include diff --git a/src/3rdparty/libjpeg-turbo/CMakeLists.txt b/src/3rdparty/libjpeg-turbo/CMakeLists.txt old mode 100644 new mode 100755 index 060bb653..b0316f80 --- a/src/3rdparty/libjpeg-turbo/CMakeLists.txt +++ b/src/3rdparty/libjpeg-turbo/CMakeLists.txt @@ -40,7 +40,7 @@ message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}") # Detect CPU type and whether we're building 64-bit or 32-bit code math(EXPR BITS "${CMAKE_SIZEOF_VOID_P} * 8") -#string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} CMAKE_SYSTEM_PROCESSOR_LC) +string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} CMAKE_SYSTEM_PROCESSOR_LC) if(CMAKE_SYSTEM_PROCESSOR_LC MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR_LC MATCHES "amd64" OR CMAKE_SYSTEM_PROCESSOR_LC MATCHES "i[0-9]86" OR @@ -62,6 +62,8 @@ elseif(CMAKE_SYSTEM_PROCESSOR_LC MATCHES "arm*") elseif(CMAKE_SYSTEM_PROCESSOR_LC MATCHES "ppc*" OR CMAKE_SYSTEM_PROCESSOR_LC MATCHES "powerpc*") set(CPU_TYPE powerpc) +elseif(CMAKE_SYSTEM_PROCESSOR_LC MATCHES "mips*") + set(CPU_TYPE mipsel) else() set(CPU_TYPE ${CMAKE_SYSTEM_PROCESSOR_LC}) endif() diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 5244a100..4c066556 100755 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -9,7 +9,6 @@ aux_source_directory(widget SRCS_WIDGET) aux_source_directory(drawables SRCS_DRAWABLES) aux_source_directory(cairomm SRCS_CAIROMM) aux_source_directory(dialogs SRCS_DIALOG) -aux_source_directory(looper SRCS_LOOP) aux_source_directory(animation SRCS_ANIMATION) message("UI Lua script bindings is ${LUA_BINDINGS} guistatic=${GUI_STATIC}") @@ -40,7 +39,7 @@ add_definitions(-DRAPIDJSON_HAS_STDSTRING) set(SOURCES_GUI ${SRCS_GUICORE} ${SRCS_VIEWS} ${SRCS_WIDGET} ${SRCS_DRAWABLES} ${SRCS_CAIROMM} ${SRCS_DIALOG} - ${SRCS_LOOP} ${SRCS_ANIMATION}) + ${SRCS_ANIMATION}) add_library(gui_objs OBJECT ${SOURCES_GUI}) add_library(gui_static STATIC $) diff --git a/src/gui/animation/animation.h b/src/gui/animation/animation.h index a5f92970..f77ca9da 100755 --- a/src/gui/animation/animation.h +++ b/src/gui/animation/animation.h @@ -1,6 +1,6 @@ #ifndef __ANIMATION_H__ #define __ANIMATION_H__ -#include +#include #include diff --git a/src/gui/animation/animator.cc b/src/gui/animation/animator.cc index b52b3dec..78880d16 100755 --- a/src/gui/animation/animator.cc +++ b/src/gui/animation/animator.cc @@ -96,6 +96,7 @@ void Animator::appendChangingConfigurations(int configs) { void Animator::setupStartValues() { } + void Animator::setupEndValues() { } @@ -137,4 +138,5 @@ AnimatorListenerAdapter::AnimatorListenerAdapter(){ onAnimationCancel=onAnimationRepeat=onAnimationPause=onAnimationResume=[](Animator&anim){}; onAnimationEnd=onAnimationStart=[](Animator&aim,bool reverse){}; } + }//endof namespace diff --git a/src/gui/animation/animator.h b/src/gui/animation/animator.h index 8a9d334a..fe2a5728 100755 --- a/src/gui/animation/animator.h +++ b/src/gui/animation/animator.h @@ -2,7 +2,7 @@ #include #include #include -#include +#include namespace cdroid{ diff --git a/src/gui/core/interpolators.cc b/src/gui/animation/interpolators.cc old mode 100644 new mode 100755 similarity index 97% rename from src/gui/core/interpolators.cc rename to src/gui/animation/interpolators.cc index e6ce236f..beae3486 --- a/src/gui/core/interpolators.cc +++ b/src/gui/animation/interpolators.cc @@ -1,4 +1,4 @@ -#include +#include namespace cdroid{ #if 0 diff --git a/src/gui/core/interpolators.h b/src/gui/animation/interpolators.h old mode 100644 new mode 100755 similarity index 100% rename from src/gui/core/interpolators.h rename to src/gui/animation/interpolators.h diff --git a/src/gui/animation/layouttransition.h b/src/gui/animation/layouttransition.h index 58cc6f12..a99fce9c 100755 --- a/src/gui/animation/layouttransition.h +++ b/src/gui/animation/layouttransition.h @@ -3,7 +3,6 @@ #include #include #include -#include #include namespace cdroid{ diff --git a/src/gui/animation/scaleanimation.h b/src/gui/animation/scaleanimation.h index 5bca371f..82c67101 100755 --- a/src/gui/animation/scaleanimation.h +++ b/src/gui/animation/scaleanimation.h @@ -1,7 +1,7 @@ #ifndef __SCALEANIMATION_H__ #define __SCALEANIMATION_H__ #include -#include +#include namespace cdroid{ class ScaleAnimation:public Animation{ diff --git a/src/gui/animation/transformation.h b/src/gui/animation/transformation.h index f3864fbe..7a1fa4cb 100755 --- a/src/gui/animation/transformation.h +++ b/src/gui/animation/transformation.h @@ -1,9 +1,9 @@ #ifndef __TRANSFORMATION_H__ #define __TRANSFORMATION_H__ -#include +#include #include -#include -#include +#include +#include typedef Cairo::Matrix Matrix; namespace cdroid{ diff --git a/src/gui/core/alooper.cc b/src/gui/core/alooper.cc deleted file mode 100755 index 9fbb73ff..00000000 --- a/src/gui/core/alooper.cc +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -namespace alooper{ - -static constexpr int EPOLL_SIZE_HINT = 8; -// Maximum number of file descriptors for which to retrieve poll events each iteration. -static constexpr int EPOLL_MAX_EVENTS = 16; - -void Looper::Looper::Request::initEventItem(struct epoll_event* eventItem) const{ -} - -Looper::Looper(bool allowNonCallbacks) : - mAllowNonCallbacks(allowNonCallbacks), mSendingMessage(false), - mPolling(false), mEpollFd(-1), mEpollRebuildRequired(false), - mNextRequestSeq(0), mResponseIndex(0), mNextMessageUptime(LONG_MAX) { - //mWakeEventFd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); - //LOGE_IF(mWakeEventFd < 0, "Could not make wake event fd: %s",strerror(errno)); - //AutoMutex _l(mLock); - rebuildEpollLocked(); -} - -void Looper::rebuildEpollLocked() { - // Close old epoll instance if we have one. - if (mEpollFd >= 0) { - LOGV("%p ~ rebuildEpollLocked - rebuilding epoll set", this); - close(mEpollFd); - } - - // Allocate the new epoll instance and register the wake pipe. - mEpollFd = epoll_create(EPOLL_SIZE_HINT); - LOGE_IF(mEpollFd < 0, "Could not create epoll instance: %s", strerror(errno)); - - struct epoll_event eventItem; - memset(& eventItem, 0, sizeof(epoll_event)); // zero out unused members of data field union - eventItem.events = EPOLLIN; - eventItem.data.fd = mWakeEventFd; - int result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeEventFd, & eventItem); - LOGE_IF(result != 0, "Could not add wake event fd to epoll instance: %s",strerror(errno)); - - for (auto it=mRequests.begin();it!=mRequests.end(); it++) { - const Request& request = it->second; - struct epoll_event eventItem; - request.initEventItem(&eventItem); - - int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, request.fd, & eventItem); - if (epollResult < 0) { - LOGE("Error adding epoll events for fd %d while rebuilding epoll set: %s",request.fd, strerror(errno)); - } - } -} -} diff --git a/src/gui/core/app.cc b/src/gui/core/app.cc index fbbff01c..a8455641 100755 --- a/src/gui/core/app.cc +++ b/src/gui/core/app.cc @@ -16,7 +16,6 @@ #include #include #include -#include #include @@ -76,13 +75,10 @@ App::App(int argc,const char*argv[],const struct option*extoptions){ setOpacity(getArgAsInt("alpha",255)); InputEventSource*inputsource=new InputEventSource(getArg("record","")); - addEventSource(inputsource,[](EventSource&s){ - ((InputEventSource&)s).processKey(); - return true; - }); + addEventHandler(inputsource); inputsource->playback(getArg("monkey","")); - SignalSource*sigsource=new GenericSignalSource(false); + /*SignalSource*sigsource=new GenericSignalSource(false); addEventSource(sigsource,[this](EventSource&s){ LOGI("Sig interrupt %d",((SignalSource&)s).signo); this->exit(((SignalSource&)s).signo); @@ -91,7 +87,7 @@ App::App(int argc,const char*argv[],const struct option*extoptions){ sigsource->add(SIGABRT); sigsource->add(SIGINT); sigsource->add(SIGTERM); - sigsource->add(SIGKILL); + sigsource->add(SIGKILL);*/ } App::~App(){ @@ -157,20 +153,20 @@ const std::string App::getAssetsPath(){ return path; } -int App::addEventSource(EventSource *source, EventHandler handler){ - return Looper::getDefault()->add_event_source(source,handler); +void App::addEventHandler(const EventHandler*handler){ + Looper::getDefault()->addEventHandler(handler); } -int App::removeEventSource(EventSource*source){ - return Looper::getDefault()->remove_event_source(source); +void App::removeEventHandler(const EventHandler*handler){ + //Looper::getDefault()->remove_event_source(source); } int App::exec(){ - return Looper::getDefault()->run(); + while(1)Looper::getDefault()->pollAll(5); } void App::exit(int code){ - Looper::getDefault()->quit(code); + //Looper::getDefault()->quit(code); } void App::setName(const std::string&appname){ diff --git a/src/gui/core/app.h b/src/gui/core/app.h old mode 100644 new mode 100755 index 7e9a35ca..ca4a96fa --- a/src/gui/core/app.h +++ b/src/gui/core/app.h @@ -4,9 +4,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include struct option; using namespace Cairo; @@ -32,8 +32,8 @@ public: virtual const std::string&getArg(const std::string&key,const std::string&def="")const; virtual int getArgAsInt(const std::string&key,int def)const; - virtual int addEventSource(EventSource *source, EventHandler handler); - virtual int removeEventSource(EventSource*source); + virtual void addEventHandler(const EventHandler* handler); + virtual void removeEventHandler(const EventHandler*handler); virtual int exec(); virtual void exit(int code=0); }; diff --git a/src/gui/core/assets.h b/src/gui/core/assets.h old mode 100644 new mode 100755 index c71588d9..10a18d73 --- a/src/gui/core/assets.h +++ b/src/gui/core/assets.h @@ -1,6 +1,5 @@ #ifndef __ASSETS_H__ #define __ASSETS_H__ -#include #include #include #include diff --git a/src/gui/core/asynsource.cc b/src/gui/core/asynsource.cc deleted file mode 100644 index 00b931f9..00000000 --- a/src/gui/core/asynsource.cc +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include -#include -#include - -namespace cdroid { - -AsyncEventSource::AsyncEventSource(){ - int threads=std::thread::hardware_concurrency(); - for(size_t i = 0; i task; - { - std::unique_lock lock(this->queue_mutex); - this->condition.wait(lock, - [this] { return this->stop || !this->tasks.empty(); }); - if(this->stop && this->tasks.empty()) - return; - task = std::move(this->tasks.front()); - this->tasks.pop(); - } - task(); - } - } - ); - -} - -AsyncEventSource::~AsyncEventSource() { - { - std::unique_lock lock(queue_mutex); - stop = true; - } - condition.notify_all(); - for(std::thread &worker: workers) - worker.join(); -} - -bool AsyncEventSource::prepare(int& max_timeout) { - return tasks.size(); -} - -bool AsyncEventSource::check(){ - return tasks.size()>0; -} -#if 0 -template -auto AsyncEventSource::enqueue(F&& f, Args&&... args)-> std::future::type>{ - using return_type = typename std::result_of::type; - auto task = std::make_shared< std::packaged_task >( - std::bind(std::forward(f), std::forward(args)...) - ); - std::future res = task->get_future(); - { - std::unique_lock lock(queue_mutex); - if(stop)// don't allow enqueueing after stopping the pool - throw std::runtime_error("enqueue on stopped ThreadPool"); - tasks.emplace([task]() { - (*task)(); - }); - } - condition.notify_one(); - return res; -} -#endif -bool AsyncEventSource::dispatch(EventHandler &func) { return func(*this); } - - -} diff --git a/src/gui/core/asynsource.h b/src/gui/core/asynsource.h deleted file mode 100755 index b6951d01..00000000 --- a/src/gui/core/asynsource.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __ASYNC_SOURCE_H__ -#define __ASYNC_SOURCE_H__ -#include -#include -#include -#include -#include -#include -#include -#include -namespace cdroid{ - -DECLARE_UIEVENT(void,AsyncEvent,void); - -//template -class AsyncEventSource:public EventSource{ -protected: - std::vector< std::thread > workers; - // the task queue - std::queue< std::function > tasks; - // synchronization - std::mutex queue_mutex; - std::condition_variable condition; - bool stop; -public: - AsyncEventSource(); - ~AsyncEventSource(); - bool prepare(int& max_timeout); - bool check(); - bool dispatch(EventHandler &func); - bool is_file_source() const override final { return false; } - template - auto enqueue(F&& f, Args&&... args)-> std::future::type>{ - using return_type = typename std::result_of::type; - auto task = std::make_shared< std::packaged_task >( - std::bind(std::forward(f), std::forward(args)...) - ); - std::future res = task->get_future(); - { - std::unique_lock lock(queue_mutex); - if(stop)// don't allow enqueueing after stopping the pool - throw std::runtime_error("enqueue on stopped ThreadPool"); - tasks.emplace([task]() { - (*task)(); - }); - } - condition.notify_one(); - return res; - } -}; - -} -#endif diff --git a/src/gui/core/canvas.h b/src/gui/core/canvas.h index f2559d48..aa818bd9 100755 --- a/src/gui/core/canvas.h +++ b/src/gui/core/canvas.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include using namespace Cairo; diff --git a/src/gui/core/choreographer.cc b/src/gui/core/choreographer.cc index 3b6e5eda..6a3db151 100755 --- a/src/gui/core/choreographer.cc +++ b/src/gui/core/choreographer.cc @@ -85,7 +85,7 @@ namespace cdroid{ CallbackRecord* predecessor = nullptr; for (CallbackRecord* callback = mHead; callback != nullptr;) { CallbackRecord* next = callback->next; - if ((action == nullptr || addr_of(callback->action) == addr_of(action)) + if ((/*action == nullptr ||*/ callback->action.ID == action.ID) && (token == 0 || callback->token == token)) { if (predecessor != nullptr) { predecessor->next = next; diff --git a/src/gui/core/choreographer.h b/src/gui/core/choreographer.h index 826c7994..606a00d8 100755 --- a/src/gui/core/choreographer.h +++ b/src/gui/core/choreographer.h @@ -1,6 +1,6 @@ #ifndef __CHOREO_GRAPHER_H__ #define __CHOREO_GRAPHER_H__ -#include +#include #include namespace cdroid{ class Choreographer{ diff --git a/src/gui/core/context.h b/src/gui/core/context.h index e1c207a3..3c806655 100755 --- a/src/gui/core/context.h +++ b/src/gui/core/context.h @@ -9,7 +9,35 @@ using namespace Cairo; namespace cdroid{ -typedef std::functionRunnable; +class Runnable{ +public: + int ID; + std::functionrun; + Runnable(){ + run=nullptr; + } + Runnable(const std::function&f){ + run=f; + } + void operator=(const std::function&f){ + run=f; + } + void operator=(nullptr_t){ + run=nullptr; + } + bool operator==(nullptr_t)const{ + return run==nullptr; + } + bool operator!=(nullptr_t)const{ + return run!=nullptr; + } + explicit operator bool()const{ + return run!=nullptr; + } + void operator()(){ + run(); + } +}; class Drawable; class ColorStateList; class Context{ diff --git a/src/gui/core/eventcodes.h b/src/gui/core/eventcodes.h old mode 100644 new mode 100755 index 05d84352..00348ddd --- a/src/gui/core/eventcodes.h +++ b/src/gui/core/eventcodes.h @@ -14,7 +14,7 @@ */ #ifndef _INPUT_EVENT_CODES_H #define _INPUT_EVENT_CODES_H -#include +#include /* * Device properties and quirks */ diff --git a/src/gui/core/graph_device.h b/src/gui/core/graph_device.h old mode 100644 new mode 100755 index c7323d8f..841d6cbf --- a/src/gui/core/graph_device.h +++ b/src/gui/core/graph_device.h @@ -1,6 +1,6 @@ #ifndef __GRAPH_DEVICE_H__ #define __GRAPH_DEVICE_H__ -#include +#include #include #include diff --git a/src/gui/core/gravity.h b/src/gui/core/gravity.h old mode 100644 new mode 100755 index e3996819..04f5ef66 --- a/src/gui/core/gravity.h +++ b/src/gui/core/gravity.h @@ -1,6 +1,6 @@ #ifndef __GRAVITY_H__ #define __GRAVITY_H__ -#include +#include #include namespace cdroid{ diff --git a/src/gui/core/inputeventlabels.h b/src/gui/core/inputeventlabels.h old mode 100644 new mode 100755 index 57a12e73..dd894aa1 --- a/src/gui/core/inputeventlabels.h +++ b/src/gui/core/inputeventlabels.h @@ -1,7 +1,7 @@ #ifndef __INPUT_EVENT_LABE_H__ #define __INPUT_EVENT_LABE_H__ //#include -#include +#include #include #include #define DEFINE_KEYCODE(key) { #key, KEY_##key } diff --git a/src/gui/core/inputeventsource.cc b/src/gui/core/inputeventsource.cc index a117fb5e..8a4ac8c9 100755 --- a/src/gui/core/inputeventsource.cc +++ b/src/gui/core/inputeventsource.cc @@ -69,29 +69,15 @@ std::shared_ptrInputEventSource::getdevice(int fd){ return itr->second; } -bool InputEventSource::prepare(int& max_timeout){ +int InputEventSource::checkEvents(){ INPUTEVENT es[32]; if(events.size()>0)return TRUE; int count=InputGetEvents(es,32,1); process(es,count); - return count>0; + return count; } -int InputEventSource::process(const INPUTEVENT*inevents,int count){ - LOGV_IF(count,"%p recv %d events ",this,count); - for(int i=0;idev=getdevice(e->device); - if(dev==nullptr){ - LOGD("%d,%d,%d device=%d ",e->type,e->code,e->value,e->device); - continue; - } - dev->putrawdata(e); - } - return 0; -} - -bool InputEventSource::processKey(){ +int InputEventSource::handleEvents(){ std::lock_guard lock(mtxEvents); if(events.size()==0)return false; while(events.size()){ @@ -109,8 +95,23 @@ bool InputEventSource::processKey(){ e->recycle(); events.pop(); } - return true; + return 0; } + +int InputEventSource::process(const INPUTEVENT*inevents,int count){ + LOGV_IF(count,"%p recv %d events ",this,count); + for(int i=0;idev=getdevice(e->device); + if(dev==nullptr){ + LOGD("%d,%d,%d device=%d ",e->type,e->code,e->value,e->device); + continue; + } + dev->putrawdata(e); + } + return 0; +} + int InputEventSource::pushEvent(InputEvent*evt){ std::lock_guard lock(mtxEvents); events.push(evt); diff --git a/src/gui/core/inputeventsource.h b/src/gui/core/inputeventsource.h index 424828f9..c53522f9 100755 --- a/src/gui/core/inputeventsource.h +++ b/src/gui/core/inputeventsource.h @@ -1,7 +1,7 @@ #ifndef __INPUT_EVENT_SOURCE_H__ #define __INPUT_EVENT_SOURCE_H__ #include -#include +#include #include #include #include @@ -18,10 +18,10 @@ namespace GRT{ namespace cdroid{ -class InputEventSource:public EventSource{ +class InputEventSource:public EventHandler{ protected: std::mutex mtxEvents; - bool isplayback; + bool isplayback; nsecs_t lasteventTime; std::ofstream frecord; std::queueevents; @@ -36,12 +36,9 @@ public: ~InputEventSource(); bool initGesture(const std::string&fname); void playback(const std::string&fname); - bool prepare(int& max_timeout); - bool check(){return events.size()>0;} - bool dispatch(EventHandler &func) { return func(*this); } - bool is_file_source() const override final { return false; } + int checkEvents()override; + int handleEvents()override; int process(const INPUTEVENT*es,int count); - bool processKey(); }; } #endif diff --git a/src/gui/core/layout.h b/src/gui/core/layout.h old mode 100644 new mode 100755 index 83c2dfa7..4b29d442 --- a/src/gui/core/layout.h +++ b/src/gui/core/layout.h @@ -1,6 +1,6 @@ #ifndef __LAYOUT_H__ #define __LAYOUT_H__ -#include +#include namespace cdroid{ class Layout{ private: diff --git a/src/gui/core/looper.cc b/src/gui/core/looper.cc new file mode 100755 index 00000000..6b621a58 --- /dev/null +++ b/src/gui/core/looper.cc @@ -0,0 +1,582 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEBUG_POLL_AND_WAKE 0 +#define DEBUG_CALLBACKS 0 + +namespace cdroid{ + +static constexpr int EPOLL_SIZE_HINT = 8; +// Maximum number of file descriptors for which to retrieve poll events each iteration. +static constexpr int EPOLL_MAX_EVENTS = 16; +#define toMillisecondTimeoutDelay(n,p) ((n)-(p)) + +template +static const void * addr_of(T &&obj) noexcept{ + struct A {}; + return &reinterpret_cast(obj); +} + +void Looper::Looper::Request::initEventItem(struct epoll_event* eventItem) const{ + int epollEvents = 0; + if (events & EVENT_INPUT) epollEvents |= EPOLLIN; + if (events & EVENT_OUTPUT) epollEvents |= EPOLLOUT; + + memset(eventItem, 0, sizeof(epoll_event)); // zero out unused members of data field union + eventItem->events = epollEvents; + eventItem->data.fd = fd; +} + +Looper::Looper(bool allowNonCallbacks) : + mAllowNonCallbacks(allowNonCallbacks), mSendingMessage(false), + mPolling(false), mEpollFd(-1), mEpollRebuildRequired(false), + mNextRequestSeq(0), mResponseIndex(0), mNextMessageUptime(LONG_MAX) { + mWakeEventFd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); + LOGE_IF(mWakeEventFd < 0, "Could not make wake event fd: %s",strerror(errno)); + std::lock_guard_l(mLock); + rebuildEpollLocked(); +} + +Looper::~Looper() { + close(mWakeEventFd); + mWakeEventFd = -1; + if (mEpollFd >= 0) { + close(mEpollFd); + } +} +Looper*Looper::mInst=nullptr; +Looper*Looper::getDefault(){ + if(mInst==nullptr)mInst=new Looper(false); + return mInst; +} + +bool Looper::getAllowNonCallbacks() const { + return mAllowNonCallbacks; +} + +void Looper::rebuildEpollLocked() { + // Close old epoll instance if we have one. + if (mEpollFd >= 0) { + LOGV("%p ~ rebuildEpollLocked - rebuilding epoll set", this); + close(mEpollFd); + } + + // Allocate the new epoll instance and register the wake pipe. + mEpollFd = epoll_create(EPOLL_SIZE_HINT); + LOGE_IF(mEpollFd < 0, "Could not create epoll instance: %s", strerror(errno)); + + struct epoll_event eventItem; + memset(& eventItem, 0, sizeof(epoll_event)); // zero out unused members of data field union + eventItem.events = EPOLLIN; + eventItem.data.fd = mWakeEventFd; + int result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeEventFd, & eventItem); + LOGE_IF(result != 0, "Could not add wake event fd to epoll instance: %s",strerror(errno)); + + for (auto it=mRequests.begin();it!=mRequests.end(); it++) { + const Request& request = it->second; + struct epoll_event eventItem; + request.initEventItem(&eventItem); + + int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, request.fd, & eventItem); + if (epollResult < 0) { + LOGE("Error adding epoll events for fd %d while rebuilding epoll set: %s",request.fd, strerror(errno)); + } + } +} + +void Looper::scheduleEpollRebuildLocked() { + if (!mEpollRebuildRequired) { + LOGD_IF(DEBUG_CALLBACKS,"%p scheduleEpollRebuildLocked - scheduling epoll set rebuild", this); + mEpollRebuildRequired = true; + wake(); + } +} + +int Looper::pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outData) { + int result = 0; + for (;;) { + while (mResponseIndex < mResponses.size()) { + const Response& response = mResponses.at(mResponseIndex++); + int ident = response.request.ident; + if (ident >= 0) { + int fd = response.request.fd; + int events = response.events; + void* data = response.request.data; + LOGD_IF(DEBUG_POLL_AND_WAKE,"%p pollOnce - returning signalled identifier %d: fd=%d, events=0x%x, data=%p", this, ident, fd, events, data); + if (outFd != NULL) *outFd = fd; + if (outEvents != NULL) *outEvents = events; + if (outData != NULL) *outData = data; + return ident; + } + } + + if (result != 0) { + LOGD_IF(DEBUG_POLL_AND_WAKE,"%p pollOnce - returning result %d", this, result); + if (outFd != NULL) *outFd = 0; + if (outEvents != NULL) *outEvents = 0; + if (outData != NULL) *outData = NULL; + return result; + } + + result = pollInner(timeoutMillis); + } +} + +int Looper::pollInner(int timeoutMillis) { + LOGD_IF(DEBUG_POLL_AND_WAKE,"%p pollOnce - waiting: timeoutMillis=%d mNextMessageUptime=%lld", this, timeoutMillis,mNextMessageUptime); + + // Adjust the timeout based on when the next message is due. + if (timeoutMillis != 0 && mNextMessageUptime != LLONG_MAX) { + nsecs_t now = SystemClock::uptimeMillis();//systemTime(SYSTEM_TIME_MONOTONIC); + int messageTimeoutMillis = toMillisecondTimeoutDelay(now, mNextMessageUptime); + if (messageTimeoutMillis >= 0 + && (timeoutMillis < 0 || messageTimeoutMillis < timeoutMillis)) { + timeoutMillis = messageTimeoutMillis; + } + LOGD_IF(DEBUG_POLL_AND_WAKE,"%p pollOnce - next message in %lld ns, adjusted timeout: timeoutMillis=%d",this, mNextMessageUptime - now, timeoutMillis); + } + + // Poll. + int result = POLL_WAKE; + mResponses.clear(); + mResponseIndex = 0; + + for(auto it=mEventHandlers.begin();it!=mEventHandlers.end();it++){ + EventHandler*es=(*it); + if(es&&(es->mRemoved==0)&&(es->checkEvents()>0)){ + es->handleEvents(); + } + } + removeEventHandlers(); + // We are about to idle. + mPolling = true; + + struct epoll_event eventItems[EPOLL_MAX_EVENTS]; + int eventCount = epoll_wait(mEpollFd, eventItems, EPOLL_MAX_EVENTS, timeoutMillis); + + // No longer idling. + mPolling = false; + + // Acquire lock. + mLock.lock(); + + // Rebuild epoll set if needed. + if (mEpollRebuildRequired) { + mEpollRebuildRequired = false; + rebuildEpollLocked(); + goto Done; + } + + // Check for poll error. + if (eventCount < 0) { + if (errno == EINTR) { + goto Done; + } + LOGW("Poll failed with an unexpected error: %s", strerror(errno)); + result = POLL_ERROR; + goto Done; + } + + // Check for poll timeout. + if (eventCount == 0) { + LOGD_IF(DEBUG_POLL_AND_WAKE,"%p pollOnce - timeout", this); + result = POLL_TIMEOUT; + goto Done; + } + + // Handle all events. + LOGD_IF(DEBUG_POLL_AND_WAKE,"%p pollOnce - handling events from %d fds", this, eventCount); + + for (int i = 0; i < eventCount; i++) { + int fd = eventItems[i].data.fd; + uint32_t epollEvents = eventItems[i].events; + if (fd == mWakeEventFd) { + if (epollEvents & EPOLLIN) { + awoken(); + } else { + LOGW("Ignoring unexpected epoll events 0x%x on wake event fd.", epollEvents); + } + } else { + auto it= mRequests.find(fd);//indexOfKey(fd); + if (it!=mRequests.end()){//requestIndex >= 0) { + int events = 0; + if (epollEvents & EPOLLIN) events |= EVENT_INPUT; + if (epollEvents & EPOLLOUT) events |= EVENT_OUTPUT; + if (epollEvents & EPOLLERR) events |= EVENT_ERROR; + if (epollEvents & EPOLLHUP) events |= EVENT_HANGUP; + pushResponse(events, it->second);//mRequests.at(requestIndex)); + } else { + LOGW("Ignoring unexpected epoll events 0x%x on fd %d that is " + "no longer registered.", epollEvents, fd); + } + } + } +Done: ; + + // Invoke pending message callbacks. + mNextMessageUptime = LLONG_MAX; + LOGD_IF(DEBUG_CALLBACKS,"mMessageEnvelopes.size=%d",mMessageEnvelopes.size()); + while (mMessageEnvelopes.size() != 0) { + nsecs_t now = SystemClock::uptimeMillis();//systemTime(SYSTEM_TIME_MONOTONIC); + const MessageEnvelope& messageEnvelope = mMessageEnvelopes.front(); + if (messageEnvelope.uptime <= now) { + // Remove the envelope from the list. + // We keep a strong reference to the handler until the call to handleMessage + // finishes. Then we drop it so that the handler can be deleted *before* + // we reacquire our lock. + { // obtain handler + MessageHandler* handler = messageEnvelope.handler; + Message message = messageEnvelope.message; + mMessageEnvelopes.erase(mMessageEnvelopes.begin());//removeAt(0); + mSendingMessage = true; + mLock.unlock(); + + LOGD_IF(DEBUG_POLL_AND_WAKE || DEBUG_CALLBACKS,"%p pollOnce - sending message: handler=%p, what=%d", this, handler, message.what); + handler->handleMessage(message); + } // release handler + + mLock.lock(); + mSendingMessage = false; + result = POLL_CALLBACK; + } else { + // The last message left at the head of the queue determines the next wakeup time. + mNextMessageUptime = messageEnvelope.uptime; + break; + } + } + + // Release lock. + mLock.unlock(); + + // Invoke all response callbacks. + for (size_t i = 0; i < mResponses.size(); i++) { + Response& response = mResponses.at(i); + if (response.request.ident == POLL_CALLBACK) { + int fd = response.request.fd; + int events = response.events; + void* data = response.request.data; + LOGD_IF(DEBUG_POLL_AND_WAKE || DEBUG_CALLBACKS,"%p pollOnce - invoking fd event callback %p: fd=%d, events=0x%x, data=%p", + this, response.request.callback, fd, events, data); + + // Invoke the callback. Note that the file descriptor may be closed by + // the callback (and potentially even reused) before the function returns so + // we need to be a little careful when removing the file descriptor afterwards. + int callbackResult = response.request.callback->handleEvent(fd, events, data); + if (callbackResult == 0) { + removeFd(fd, response.request.seq); + } + + // Clear the callback reference in the response structure promptly because we + // will not clear the response vector itself until the next poll. + //response.request.callback.clear(); + result = POLL_CALLBACK; + } + } + return result; +} + +int Looper::pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData) { + if (timeoutMillis <= 0) { + int result; + do { + result = pollOnce(timeoutMillis, outFd, outEvents, outData); + } while (result == POLL_CALLBACK); + return result; + } else { + nsecs_t endTime =SystemClock::uptimeMillis()+timeoutMillis;// systemTime(SYSTEM_TIME_MONOTONIC) + milliseconds_to_nanoseconds(timeoutMillis); + + for (;;) { + int result = pollOnce(timeoutMillis, outFd, outEvents, outData); + if (result != POLL_CALLBACK) { + return result; + } + + nsecs_t now = SystemClock::uptimeMillis();//systemTime(SYSTEM_TIME_MONOTONIC); + timeoutMillis = toMillisecondTimeoutDelay(now, endTime); + if (timeoutMillis == 0) { + return POLL_TIMEOUT; + } + } + } +} +//TEMP_FAILURE_RETRY defined in +void Looper::wake() { + LOGD_IF(DEBUG_POLL_AND_WAKE,"%p wake", this); + + uint64_t inc = 1; + ssize_t nWrite = TEMP_FAILURE_RETRY(write(mWakeEventFd, &inc, sizeof(uint64_t))); + if (nWrite != sizeof(uint64_t)) { + LOGE_IF(errno!=EAGAIN,"Could not write wake signal to fd %d: %s",mWakeEventFd, strerror(errno)); + } +} + +void Looper::awoken() { + LOGD_IF(DEBUG_POLL_AND_WAKE,"%p awoken", this); + + uint64_t counter; + TEMP_FAILURE_RETRY(read(mWakeEventFd, &counter, sizeof(uint64_t))); +} + +void Looper::pushResponse(int events, const Request& request) { + Response response; + response.events = events; + response.request = request; + mResponses.push_back(response); +} + +int Looper::addFd(int fd, int ident, int events, Looper_callbackFunc callback, void* data) { + return addFd(fd, ident, events, callback ? new SimpleLooperCallback(callback) : NULL, data); +} + +int Looper::addFd(int fd, int ident, int events,const LooperCallback* callback, void* data) { + LOGD_IF(DEBUG_CALLBACKS,"%p addFd - fd=%d, ident=%d, events=0x%x, callback=%p, data=%p", this, fd, ident, events, callback, data); + + if (callback==nullptr) { + if (! mAllowNonCallbacks) { + LOGE("Invalid attempt to set NULL callback but not allowed for this looper."); + return -1; + } + + if (ident < 0) { + LOGE("Invalid attempt to set NULL callback with ident < 0."); + return -1; + } + } else { + ident = POLL_CALLBACK; + } + + { // acquire lock + std::lock_guard _l(mLock); + + Request request; + request.fd = fd; + request.ident = ident; + request.events = events; + request.seq = mNextRequestSeq++; + request.callback = (LooperCallback*)callback; + request.data = data; + if (mNextRequestSeq == -1) mNextRequestSeq = 0; // reserve sequence number -1 + + struct epoll_event eventItem; + request.initEventItem(&eventItem); + + auto itfd = mRequests.find(fd);//indexOfKey(fd); + if (itfd==mRequests.end()) { + int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, & eventItem); + if (epollResult < 0) { + LOGE("Error adding epoll events for fd %d: %s", fd, strerror(errno)); + return -1; + } + mRequests[fd]=request;//.add(fd, request); + } else { + int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_MOD, fd, & eventItem); + if (epollResult < 0) { + if (errno == ENOENT) { + // Tolerate ENOENT because it means that an older file descriptor was + // closed before its callback was unregistered and meanwhile a new + // file descriptor with the same number has been created and is now + // being registered for the first time. This error may occur naturally + // when a callback has the side-effect of closing the file descriptor + // before returning and unregistering itself. Callback sequence number + // checks further ensure that the race is benign. + // + // Unfortunately due to kernel limitations we need to rebuild the epoll + // set from scratch because it may contain an old file handle that we are + // now unable to remove since its file descriptor is no longer valid. + // No such problem would have occurred if we were using the poll system + // call instead, but that approach carries others disadvantages. + LOGD_IF(DEBUG_CALLBACKS,"%p addFd - EPOLL_CTL_MOD failed due to file descriptor " + "being recycled, falling back on EPOLL_CTL_ADD: %s", this, strerror(errno)); + epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, & eventItem); + if (epollResult < 0) { + LOGE("Error modifying or adding epoll events for fd %d: %s", fd, strerror(errno)); + return -1; + } + scheduleEpollRebuildLocked(); + } else { + LOGE("Error modifying epoll events for fd %d: %s", fd, strerror(errno)); + return -1; + } + } + itfd->second=request;//mRequests.replaceValueAt(requestIndex, request); + } + } // release lock + return 1; +} + +int Looper::removeFd(int fd) { + return removeFd(fd, -1); +} + +int Looper::removeFd(int fd, int seq) { + LOGD_IF(DEBUG_CALLBACKS,"%p removeFd - fd=%d, seq=%d", this, fd, seq); + + { // acquire lock + std::lock_guard _l(mLock); + auto itr= mRequests.find(fd);//indexOfKey(fd); + if (itr==mRequests.end()) { + return 0; + } + + // Check the sequence number if one was given. + if (seq != -1 && itr->second.seq != seq) { + LOGD_IF(DEBUG_CALLBACKS,"%p removeFd - sequence number mismatch, oldSeq=%d", this, itr->second.seq); + return 0; + } + + // Always remove the FD from the request map even if an error occurs while + // updating the epoll set so that we avoid accidentally leaking callbacks. + mRequests.erase(itr);//removeItemsAt(requestIndex); + + int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_DEL, fd, NULL); + if (epollResult < 0) { + if (seq != -1 && (errno == EBADF || errno == ENOENT)) { + // Tolerate EBADF or ENOENT when the sequence number is known because it + // means that the file descriptor was closed before its callback was + // unregistered. This error may occur naturally when a callback has the + // side-effect of closing the file descriptor before returning and + // unregistering itself. + // + // Unfortunately due to kernel limitations we need to rebuild the epoll + // set from scratch because it may contain an old file handle that we are + // now unable to remove since its file descriptor is no longer valid. + // No such problem would have occurred if we were using the poll system + // call instead, but that approach carries others disadvantages. + LOGD_IF(DEBUG_CALLBACKS,"%p removeFd - EPOLL_CTL_DEL failed due to file descriptor " + "being closed: %s", this, strerror(errno)); + scheduleEpollRebuildLocked(); + } else { + // Some other error occurred. This is really weird because it means + // our list of callbacks got out of sync with the epoll set somehow. + // We defensively rebuild the epoll set to avoid getting spurious + // notifications with nowhere to go. + LOGE("Error removing epoll events for fd %d: %s", fd, strerror(errno)); + scheduleEpollRebuildLocked(); + return -1; + } + } + } // release lock + return 1; +} + +void Looper::sendMessage(const MessageHandler* handler, const Message& message) { + nsecs_t now = SystemClock::uptimeMillis();//systemTime(SYSTEM_TIME_MONOTONIC); + sendMessageAtTime(now, handler, message); +} + +void Looper::sendMessageDelayed(nsecs_t uptimeDelay, const MessageHandler* handler, + const Message& message) { + nsecs_t now = SystemClock::uptimeMillis();//systemTime(SYSTEM_TIME_MONOTONIC); + sendMessageAtTime(now + uptimeDelay, handler, message); +} + +void Looper::sendMessageAtTime(nsecs_t uptime, const MessageHandler* handler, + const Message& message) { + LOGD_IF(DEBUG_CALLBACKS,"%p sendMessageAtTime - uptime=%lld, handler=%p, what=%d", this, uptime, handler, message.what); + + size_t i = 0; + { // acquire lock + std::lock_guard _l(mLock); + + std::list::iterator it; + for(it=mMessageEnvelopes.begin();it!=mMessageEnvelopes.end();it++){ + if(uptime>=it->uptime)break; + i+=1; + } + + MessageEnvelope messageEnvelope(uptime,(MessageHandler*)handler, message); + mMessageEnvelopes.insert(it,messageEnvelope); + + // Optimization: If the Looper is currently sending a message, then we can skip + // the call to wake() because the next thing the Looper will do after processing + // messages is to decide when the next wakeup time should be. In fact, it does + // not even matter whether this code is running on the Looper thread. + if (mSendingMessage) return; + } // release lock + + // Wake the poll loop only when we enqueue a new message at the head. + if (i == 0) wake(); +} + +void Looper::addEventHandler(const EventHandler*handler){ + mEventHandlers.insert(mEventHandlers.begin(),(EventHandler*)handler); +} + +void Looper::removeEventHandler(const EventHandler*handler){ + for(auto it=mEventHandlers.begin();it!=mEventHandlers.end();it++){ + if((*it)==handler){ + (*it)->mRemoved=1; + break; + } + } +} + +void Looper::removeEventHandlers(){ + for(auto it=mEventHandlers.begin();it!=mEventHandlers.end();it++){ + if((*it)->mRemoved){ + EventHandler*handler=(*it); + it=mEventHandlers.erase(it); + LOGD(" %p",(*it)); + delete handler; + } + } +} + +void Looper::removeMessages(const MessageHandler* handler) { + LOGD_IF(DEBUG_CALLBACKS,"%p removeMessages - handler=%p", this, handler); + + { // acquire lock + std::lock_guard_l(mLock); + + for( auto it=mMessageEnvelopes.begin();it!=mMessageEnvelopes.end();it++){ + if(it->handler==handler) + it=mMessageEnvelopes.erase(it); + } + } // release lock +} + +void Looper::removeMessages(const MessageHandler* handler, int what) { + LOGD_IF(DEBUG_CALLBACKS,"%p removeMessages - handler=%p, what=%d size=%d", this, handler, what,mMessageEnvelopes.size()); + + { // acquire lock + std::lock_guard_l(mLock); + for( auto it=mMessageEnvelopes.begin();it!=mMessageEnvelopes.end();it++){ + LOGD("addr=%p,%p what=%d,%d",addr_of(it->handler),addr_of(handler),it->message.what,what); + if((it->handler==handler) && (it->message.what==what)){ + it=mMessageEnvelopes.erase(it); + } + } + } // release lock +} + +bool Looper::isPolling() const { + return mPolling; +} + +LooperCallback::~LooperCallback(){ +} + +SimpleLooperCallback::SimpleLooperCallback(Looper_callbackFunc callback) : + mCallback(callback) { +} + +SimpleLooperCallback::~SimpleLooperCallback() { +} + +int SimpleLooperCallback::handleEvent(int fd, int events, void* data) { + return mCallback(fd, events, data); +} + +MessageHandler::~MessageHandler(){ +} + +EventHandler::~EventHandler(){ +} + +} diff --git a/src/gui/core/alooper.h b/src/gui/core/looper.h similarity index 63% rename from src/gui/core/alooper.h rename to src/gui/core/looper.h index 8099a38b..83d80940 100755 --- a/src/gui/core/alooper.h +++ b/src/gui/core/looper.h @@ -4,10 +4,13 @@ #include #include #include -namespace alooper{ +#include +#include + +namespace cdroid{ typedef int64_t nsecs_t; -typedef std::functionLooperCallback; + struct Message { Message() : what(0) { } Message(int w) : what(w) { } @@ -16,15 +19,42 @@ struct Message { int what; }; +typedef int (*Looper_callbackFunc)(int fd, int events, void* data); + +class LooperCallback{ +protected: + virtual ~LooperCallback(); +public: + virtual int handleEvent(int fd, int events, void* data) = 0; +}; + +class SimpleLooperCallback : public LooperCallback { +protected: + virtual ~SimpleLooperCallback(); +public: + SimpleLooperCallback(Looper_callbackFunc callback); + virtual int handleEvent(int fd, int events, void* data); +private: + Looper_callbackFunc mCallback; +}; + class MessageHandler{ protected: virtual ~MessageHandler(); - public: - /* Handles a message. */ - virtual void handleMessage(const Message& message) = 0; + virtual void handleMessage(const Message& message)=0; }; +class EventHandler{ +private: + int mRemoved=0; + friend class Looper; +protected: + virtual ~EventHandler(); +public: + virtual int checkEvents()=0; + virtual int handleEvents()=0; +}; class Looper{ private: struct Request { @@ -32,7 +62,7 @@ private: int ident; int events; int seq; - LooperCallback callback; + LooperCallback* callback; void* data; void initEventItem(struct epoll_event* eventItem) const; }; @@ -54,10 +84,11 @@ private: bool mAllowNonCallbacks; // immutable int mWakeEventFd; // immutable - //Mutex mLock; + std::mutex mLock; - std::vector mMessageEnvelopes; // guarded by mLock + std::list mMessageEnvelopes; // guarded by mLock bool mSendingMessage; // guarded by mLock + std::list mEventHandlers; // Whether we are currently waiting for work. Not protected by a lock, // any use of it is racy anyway. @@ -75,14 +106,16 @@ private: std::vector mResponses; size_t mResponseIndex; nsecs_t mNextMessageUptime; + static Looper*mInst; private: int pollInner(int timeoutMillis); int removeFd(int fd, int seq); void awoken(); void pushResponse(int events, const Request& request); void rebuildEpollLocked(); + void scheduleEpollRebuildLocked(); + void removeEventHandlers(); protected: - virtual ~Looper(){}; public: enum { POLL_WAKE = -1, @@ -103,6 +136,8 @@ public: }; public: Looper(bool allowNonCallbacks=false); + virtual ~Looper(); + static Looper*getDefault(); bool getAllowNonCallbacks() const; int pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outData); inline int pollOnce(int timeoutMillis) { @@ -113,13 +148,16 @@ public: return pollAll(timeoutMillis, NULL, NULL, NULL); } void wake(); - int addFd(int fd, int ident, int events, LooperCallback callback, void* data); + int addFd(int fd, int ident, int events, Looper_callbackFunc callback, void* data); + int addFd(int fd, int ident, int events,const LooperCallback* callback, void* data); int removeFd(int fd); - void sendMessage(MessageHandler& handler, const Message& message); - void sendMessageDelayed(nsecs_t uptimeDelay, const MessageHandler& handler,const Message& message); - void sendMessageAtTime(nsecs_t uptime, const MessageHandler& handler,const Message& message); - void removeMessages(const MessageHandler& handler); - void removeMessages(const MessageHandler& handler, int what); + void sendMessage(const MessageHandler* handler, const Message& message); + void sendMessageDelayed(nsecs_t uptimeDelay, const MessageHandler* handler,const Message& message); + void sendMessageAtTime(nsecs_t uptime, const MessageHandler* handler,const Message& message); + void removeMessages(const MessageHandler* handler); + void removeMessages(const MessageHandler* handler, int what); + void addEventHandler(const EventHandler*handler); + void removeEventHandler(const EventHandler*handler); bool isPolling() const; }; diff --git a/src/gui/core/scheduler.cc b/src/gui/core/scheduler.cc old mode 100644 new mode 100755 index 29a6647d..5a99554a --- a/src/gui/core/scheduler.cc +++ b/src/gui/core/scheduler.cc @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include namespace cdroid{ @@ -15,10 +15,6 @@ static void Repeat2(Scheduler* s, Scheduler::Function f,system_clock::time_point s->schedule(std::bind(&Repeat2,s,f,t,deltaSeconds),t); } -bool Scheduler::dispatch(EventHandler &func){ - /*check(),check will be called by looper*/; - return func(*this); -} void Scheduler::schedule(Function f,system_clock::time_point t){ if(t>system_clock::now()) @@ -63,6 +59,9 @@ void Scheduler::remove(system_clock::time_point t){ taskQueue.erase(it); } +void Scheduler::handleMessage(const Message&){ +} +#if 0 bool Scheduler::check(){ auto task=taskQueue.begin(); if(taskQueue.size()==0)return 0; @@ -76,5 +75,6 @@ bool Scheduler::check(){ } return 0; } +#endif }/*namespace cdroid*/ diff --git a/src/gui/core/scheduler.h b/src/gui/core/scheduler.h old mode 100644 new mode 100755 index d058f8d9..cc9efd04 --- a/src/gui/core/scheduler.h +++ b/src/gui/core/scheduler.h @@ -1,14 +1,14 @@ #ifndef __SHCEDULE_H__ #define __SHCEDULE_H__ -#include -#include -#include -#include +#include +#include +#include +#include using namespace std::chrono; namespace cdroid{ -class Scheduler:public EventSource{ +class Scheduler:public MessageHandler{ public: typedef std::function Function; private: @@ -22,10 +22,8 @@ public: void scheduleDaily(Function f,system_clock::time_point t); void scheduleWeekly(Function f,system_clock::time_point t); void scheduleMonthly(Function f,system_clock::time_point t);/*TODO*/ - virtual void remove(system_clock::time_point t); - bool dispatch(EventHandler &func)override; - bool check()override;/*check schedulered item*/ + void handleMessage(const Message&)override; }; } diff --git a/src/gui/core/scroller.h b/src/gui/core/scroller.h old mode 100644 new mode 100755 index 8654e14d..726b0d9e --- a/src/gui/core/scroller.h +++ b/src/gui/core/scroller.h @@ -1,7 +1,7 @@ #ifndef __SCROLLER_H__ #define __SCROLLER_H__ -#include -#include +#include +#include namespace cdroid{ class Scroller { diff --git a/src/gui/core/uievents.h b/src/gui/core/uievents.h index 716a28f3..5b256a69 100755 --- a/src/gui/core/uievents.h +++ b/src/gui/core/uievents.h @@ -1,9 +1,9 @@ #ifndef __NGL_UIEVENTS_H__ #define __NGL_UIEVENTS_H__ #include -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/src/gui/core/uieventsource.cc b/src/gui/core/uieventsource.cc old mode 100644 new mode 100755 index 8c2dc622..c987a573 --- a/src/gui/core/uieventsource.cc +++ b/src/gui/core/uieventsource.cc @@ -8,136 +8,60 @@ namespace cdroid{ -bool operator>(const UIMSG&m1,const UIMSG m2){ - return m1.time>m2.time; -} - -bool operator==(const UIMSG&m1,const UIMSG m2){ - return m1.msgid==m2.msgid; -} - -template -static const void * addr_of(T &&obj) noexcept{ - struct A {}; - return &reinterpret_cast(obj); -} - UIEventSource::UIEventSource(View*v){ mAttachedView=v; + mID=0; } UIEventSource::~UIEventSource(){ } -int UIEventSource::getEvents(){ - return normal_msgs.size()||hasDelayedMessage()||(mAttachedView&&mAttachedView->isDirty())||GraphDevice::getInstance().needCompose(); -} - -bool UIEventSource::processEvents(){ - bool rc=popMessage();//called by Dispatch,return false the source will be killed - if(GraphDevice::getInstance().needCompose()) - GraphDevice::getInstance().ComposeSurfaces(); +int UIEventSource::checkEvents(){ + int rc= hasDelayedRunners()+(mAttachedView&&mAttachedView->isDirty())+GraphDevice::getInstance().needCompose(); return rc; } -bool UIEventSource::dispatch(EventHandler &func){ - if(func)return func(*this); - return processEvents(); -} - -void UIEventSource::reset(){ - while(!delayed_msgs.empty())delayed_msgs.pop_front(); - while(!normal_msgs.empty())normal_msgs.pop_front(); -} - -void UIEventSource::sendMessage(View*v,DWORD msgid,DWORD wp,ULONG lp,DWORD delayedtime){ - postMessage(v,msgid,wp,lp,nullptr,delayedtime); -} - -void UIEventSource::postMessage(View*v,DWORD msgid,DWORD wp,ULONG lp,const Runnable action,DWORD delayedtime){ - UIMSG msg; - msg.view=v; - msg.msgid=msgid; - msg.wParam=wp; - msg.lParam=lp; - msg.runnable=action; - if(delayedtime!=0||action!=nullptr){ - msg.time=SystemClock::uptimeMillis()+delayedtime; - for(auto itr=delayed_msgs.begin();itr!=delayed_msgs.end();itr++){ - if(msg.timetime){ - delayed_msgs.insert(itr,msg); - return ; - } - } - delayed_msgs.push_back(msg); - return; - } - normal_msgs.push_back(msg); -} - -void UIEventSource::post(View*v,const Runnable run,DWORD delayedtime){ - postMessage(v,0,0,0,run,delayedtime); -} - -void UIEventSource::removeCallbacks(const Runnable what){ - normal_msgs.remove_if([&](const UIMSG & m)->bool{ - return (m.msgid==0) && (addr_of(m.runnable)==addr_of(what)); - }); - delayed_msgs.remove_if([&](const UIMSG& m)->bool{ - return (m.msgid==0) && (addr_of(m.runnable)==addr_of(what)); - }); -} - -bool UIEventSource::hasDelayedMessage(){ - UIMSG msg; - if(delayed_msgs.empty())return false; - ULONGLONG nowms=SystemClock::uptimeMillis(); - msg=delayed_msgs.front(); - return msg.timeisDirty()){ - mAttachedView->draw(); - GraphDevice::getInstance().flip(); + mAttachedView->draw(); + GraphDevice::getInstance().flip(); } - if(msg.view){ - msg.view->onMessage(msg.msgid,msg.wParam,msg.lParam); - } - switch(msg.msgid){ - case View::WM_DESTROY: - WindowManager::getInstance().removeWindow(static_cast(msg.view)); - return false;//return false to tell Eventsource::Dispath,and EventLooper will remove the source. - case View::WM_ACTIVE: - if(msg.wParam)dynamic_cast(msg.view)->onActive(); - else dynamic_cast(msg.view)->onDeactive(); - break; - case 0: - if(msg.runnable)msg.runnable(); - } - return true; + if(GraphDevice::getInstance().needCompose()) + GraphDevice::getInstance().ComposeSurfaces(); + if(hasDelayedRunners()){ + size_t old=mRunnables.size(); + RUNNER runner=mRunnables.front(); + runner.run(); + mRunnables.erase(mRunnables.begin()); + } + return 0; } -bool UIEventSource::hasMessage(const View*v,DWORD msgid){ - const UIMSG msg={(View*)v,msgid}; - return delayed_msgs.end()==std::find(delayed_msgs.begin(),delayed_msgs.end(),msg); +void UIEventSource::post(Runnable& run,DWORD delayedtime){ + RUNNER runner; + runner.time=SystemClock::uptimeMillis()+delayedtime; + runner.run.ID=mID++; + runner.run=run; + for(auto itr=mRunnables.begin();itr!=mRunnables.end();itr++){ + if(runner.timetime){ + mRunnables.insert(itr,runner); + return; + } + } + mRunnables.push_back(runner); } -void UIEventSource::removeMessage(const View*v,DWORD msgid){ - normal_msgs.remove_if([&](const UIMSG& m)->bool{ - return (m.msgid==msgid)&&(m.view==v); - }); - delayed_msgs.remove_if([&](const UIMSG& m)->bool{ - return m.msgid==msgid&&m.view==v; - }); +bool UIEventSource::hasDelayedRunners()const{ + if(mRunnables.empty())return false; + nsecs_t nowms=SystemClock::uptimeMillis(); + RUNNER runner=mRunnables.front(); + return runner.timebool{ + return (m.run.ID==what.ID); + }); } }//end namespace diff --git a/src/gui/core/uieventsource.h b/src/gui/core/uieventsource.h old mode 100644 new mode 100755 index 5b6ebe1e..cb01f896 --- a/src/gui/core/uieventsource.h +++ b/src/gui/core/uieventsource.h @@ -1,43 +1,29 @@ #ifndef __UIEVENT_SOURCE_H__ #define __UIEVENT_SOURCE_H__ -#include +#include #include #include #include namespace cdroid{ -class View; -typedef struct{ - View*view; - DWORD msgid; - DWORD wParam; - ULONG lParam; - Runnable runnable; - ULONG time; -}UIMSG; -class UIEventSource:public EventSource{ + +class UIEventSource:public EventHandler{ private: - std::list normal_msgs; - std::list delayed_msgs; - bool hasDelayedMessage(); + int mID; + typedef struct{ + nsecs_t time; + Runnable run; + }RUNNER; + std::listmRunnables; View*mAttachedView; - bool popMessage(); - void postMessage(View*,DWORD msgid,DWORD wp,ULONG lp,const Runnable action,DWORD delayedtime=0); + bool hasDelayedRunners()const; public: UIEventSource(View*); ~UIEventSource(); - void reset(); - int getEvents(); - bool prepare(int&) override { return getEvents();} - bool check(){ - return getEvents(); - } - bool dispatch(EventHandler &func)override; bool processEvents(); - bool hasMessage(const View*,DWORD msgid); - void removeMessage(const View*,DWORD msgid); - void sendMessage(View*,DWORD msgid,DWORD wp,ULONG lp,DWORD delayedtime=0); - void post(View*v,const Runnable run,DWORD delay=0); - void removeCallbacks(const Runnable what); + int checkEvents()override; + int handleEvents()override; + void post(Runnable& run,DWORD delay=0); + void removeCallbacks(const Runnable& what); }; }//end namespace diff --git a/src/gui/core/velocitytracker.h b/src/gui/core/velocitytracker.h old mode 100644 new mode 100755 index ff2f78d3..81c215fa --- a/src/gui/core/velocitytracker.h +++ b/src/gui/core/velocitytracker.h @@ -1,8 +1,8 @@ #ifndef __VELOCITY_TRACKER_H__ #define __VELOCITY_TRACKER_H__ -#include #include +#include namespace cdroid{ typedef int64_t nsecs_t; class VelocityTrackerStrategy; diff --git a/src/gui/core/windowmanager.cc b/src/gui/core/windowmanager.cc index 19ee5824..c337158b 100755 --- a/src/gui/core/windowmanager.cc +++ b/src/gui/core/windowmanager.cc @@ -48,7 +48,7 @@ WindowManager::~WindowManager() { void WindowManager::addWindow(Window*win){ windows.push_back(win); std::sort(windows.begin(),windows.end(),[](Window*w1,Window*w2){ - return (w2->window_type-w1->window_type)>0; + return (w2->window_type-w1->window_type)>0; }); for(int idx=0,type_idx=0;idxmLayer=w->window_type*10000+(idx-type_idx)*5; LOGV("%p window %p[%s] type=%d layer=%d",win,w,w->getText().c_str(),w->window_type,w->mLayer); } - if(activeWindow)activeWindow->source->sendMessage(activeWindow,View::WM_ACTIVE,0,0); - win->source->sendMessage(win,View::WM_ACTIVE,1,0); + Runnable onact; + if(activeWindow){ + onact=std::bind(&Window::onDeactive,activeWindow); + activeWindow->post(onact); + } + onact=std::bind(&Window::onActive,win); + win->post(onact); activeWindow=win; - Looper::getDefault()->add_event_source(win->source,[](EventSource&e)->bool{ - return ((UIEventSource&)e).processEvents(); - }); + Looper::getDefault()->addEventHandler(win->source); resetVisibleRegion(); LOGV("win=%p source=%p windows.size=%d",win,win->source,windows.size()); } @@ -76,13 +79,14 @@ void WindowManager::removeWindow(Window*w){ const RECT wrect=w->getBound(); windows.erase(itw); resetVisibleRegion(); - for(auto itr=windows.begin();itr!=windows.end();itr++){//!=windows.end()){ + for(auto itr=windows.begin();itr!=windows.end();itr++){ Window*w1=(*itr); RECT rc=w1->getBound(); rc.intersect(wrect); rc.offset(-w1->getX(),-w1->getY()); w1->invalidate(&rc); } + Looper::getDefault()->removeEventHandler(w->source); delete w; for(auto it=windows.rbegin();it!=windows.rend();it++){ if((*it)->hasFlag(View::FOCUSABLE)&&(*it)->getVisibility()==View::VISIBLE){ @@ -116,7 +120,7 @@ void WindowManager::moveWindow(Window*w,int x,int y){ void WindowManager::broadcast(DWORD msgid,DWORD wParam,ULONG lParam){ for(auto win:windows) - win->sendMessage(msgid,wParam,lParam); + ;//win->sendMessage(msgid,wParam,lParam); } int WindowManager::enumWindows(WNDENUMPROC cbk){ diff --git a/src/gui/drawables/colorfilters.h b/src/gui/drawables/colorfilters.h old mode 100644 new mode 100755 index 1d12c963..99d1143c --- a/src/gui/drawables/colorfilters.h +++ b/src/gui/drawables/colorfilters.h @@ -1,7 +1,7 @@ #ifndef __COLOR_FILTERS_H__ #define __COLOR_FILTERS_H__ #include -#include +#include namespace cdroid{ enum TintMode{ CLEAR =0, diff --git a/src/gui/drawables/colorstatelist.h b/src/gui/drawables/colorstatelist.h old mode 100644 new mode 100755 index 92b8a9f7..2d0acd1c --- a/src/gui/drawables/colorstatelist.h +++ b/src/gui/drawables/colorstatelist.h @@ -2,8 +2,8 @@ #define __COLOR_STATE_LIST_H__ #include #include -#include -#include +#include +#include namespace cdroid{ class ComplexColor{ diff --git a/src/gui/drawables/drawable.h b/src/gui/drawables/drawable.h index f29d66f5..3e5d926e 100755 --- a/src/gui/drawables/drawable.h +++ b/src/gui/drawables/drawable.h @@ -1,13 +1,13 @@ #ifndef __DRAWABLE_H__ #define __DRAWABLE_H__ -#include +#include #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace cdroid{ diff --git a/src/gui/drawables/shape.h b/src/gui/drawables/shape.h old mode 100644 new mode 100755 index f8c94f39..d0578182 --- a/src/gui/drawables/shape.h +++ b/src/gui/drawables/shape.h @@ -1,7 +1,6 @@ #ifndef __SHAPE_H__ #define __SHAPE_H__ -#include -#include +#include namespace cdroid{ class Shape{ diff --git a/src/gui/drawables/stateset.h b/src/gui/drawables/stateset.h old mode 100644 new mode 100755 index 7ddbc963..7d6db9ea --- a/src/gui/drawables/stateset.h +++ b/src/gui/drawables/stateset.h @@ -2,7 +2,7 @@ #define __STATESET_H__ #include #include -#include +#include namespace cdroid{ class StateSet{ private: diff --git a/src/gui/looper/EventLoop.cpp b/src/gui/looper/EventLoop.cpp deleted file mode 100755 index a6fccda3..00000000 --- a/src/gui/looper/EventLoop.cpp +++ /dev/null @@ -1,227 +0,0 @@ -// -// Looper.cpp - This file is part of the Looper library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -namespace cdroid { - -struct Looper::Private { - bool quit; - int exit_code; - int epoolfd; - uint64_t time_last; - vector sources; - vector remove_sources; - vector pollable_sources; - vector poll_fds; - unordered_set source_set; - vector idle_sources; - vector timeout_sources; - - Private() : quit(false), exit_code(0) { - epoolfd=epoll_create(128); - } - void add_event_source(EventSource*source) { - sources.emplace_back(source); - source_set.emplace(source); - if (source->is_idle_source()) - idle_sources.emplace_back(dynamic_cast(source)); - else if (source->is_timeout_source()) - timeout_sources.emplace_back(dynamic_cast(source)); - else if (source->is_file_source()) - pollable_sources.emplace_back(dynamic_cast(source)); - } - void remove_event_source(EventSource*source) { - if (source->is_idle_source()) { - idle_sources.erase(remove(begin(idle_sources),end(idle_sources), source), end(idle_sources)); - } else if (source->is_timeout_source()) { - timeout_sources.erase(remove(begin(timeout_sources),end(timeout_sources), source),end(timeout_sources)); - } else if (source->is_file_source()) { - pollable_sources.erase(remove(begin(pollable_sources),end(pollable_sources), source),end(pollable_sources)); - } - sources.erase(remove(begin(sources),end(sources), source), end(sources)); - source_set.erase(source); - } - ~Private() { - for (auto source : sources) - delete source; - close(epoolfd); - } -}; - -Looper*Looper::mInst=nullptr; -Looper*Looper::getDefault(){ - if(mInst==nullptr) - mInst=new Looper(); - return mInst; -} - -Looper::Looper() - : impl(make_shared()) { -} - -void Looper::iteration() { - int max_timeout =10;//-1; - int n_ready = 0; - // prepare and check for already ready event sources - for (auto source : impl->sources) { - if (source->is_idle_source()) - continue; - - int source_timeout = -1; - - if (source->prepare(source_timeout)) { - source->loop_data.ready = true; - n_ready++; - } else if (source_timeout > 0 && (max_timeout == -1 || source_timeout < max_timeout)) { - max_timeout = source_timeout; - } - } - - // poll all of the pollable event sources - impl->poll_fds.resize(impl->pollable_sources.size()); - for (size_t i = 0; i < impl->pollable_sources.size(); i++) { - if (! impl->pollable_sources[i]->loop_data.ready && impl->pollable_sources[i]->fd >= 0) { - impl->poll_fds[i].fd = impl->pollable_sources[i]->fd; - impl->poll_fds[i].events = static_cast(impl->pollable_sources[i]->events); - impl->poll_fds[i].revents = impl->pollable_sources[i]->revents = 0; - } - } - - // if there's nothing else ready and there are idle event sources, make - // poll() return immediately. - if (n_ready < 1 && impl->idle_sources.size() > 0) - max_timeout = 0; - - if (::poll(impl->poll_fds.data(), impl->poll_fds.size(), max_timeout) >0) { - for (size_t i = 0; i < impl->pollable_sources.size(); i++) - impl->pollable_sources[i]->revents = impl->poll_fds[i].revents; - } - - // now check if any more sources are ready after polling - for (auto source : impl->sources) { - if (source->is_idle_source()) - continue; - if (! source->loop_data.ready) { - if (source->check()) { - source->loop_data.ready = true; - n_ready++; - } - } - } - - impl->remove_sources.clear(); - if (n_ready > 0) { - // dispatch all ready event sources - for (int i=0; isources.size(); i++) { - EventSource *source=impl->sources[i]; - if (! source->is_idle_source() && source->loop_data.ready && - source->loop_data.handler) { - if (! source->dispatch(source->loop_data.handler)) - impl->remove_sources.emplace_back(source); - source->loop_data.ready = false; - } - } - } else { - // nothing else ready, dispatch idle event sources - for (auto source : impl->idle_sources) { - if (source->loop_data.handler && - ! source->dispatch(source->loop_data.handler)) { - impl->remove_sources.emplace_back(source); - } - } - } - - // prune event sources which requested to be removed - for (auto source : impl->remove_sources) - remove_event_source(source); -} - -bool Looper::contains_source(EventSource *source) const { - return (impl->source_set.count(source) > 0); -} - -int Looper::run() { - impl->quit = false; - impl->exit_code = 0; - while (! impl->quit) - iteration(); - return impl->exit_code; -} - -void Looper::quit(int exit_code) { - impl->exit_code = exit_code; - impl->quit = true; -} - -bool Looper::add_event_source(EventSource *source, EventHandler handler) { - if (contains_source(source)) - return false; - - source->loop_data.ready = false; - source->loop_data.handler = handler ? move(handler) : nullptr; - - impl->add_event_source(source); - - return true; -} - -bool Looper::set_source_handler(EventSource *source, EventHandler handler) { - if (contains_source(source)) - source->loop_data.handler = handler; - return false; -} - -bool Looper::remove_event_source(EventSource *source) { - if (! contains_source(source)) - return false; - impl->remove_event_source(source); - delete source; - return true; -} - -EventSource *Looper::add_file(int fd, FileEvents events, EventHandler handler) { - auto source = new FileSource(fd, events); - if (! add_event_source(source, handler)) { - delete source; - return nullptr; - } - return source; -} - -EventSource *Looper::add_idle(EventHandler handler) { - auto source = new IdleSource; - if (! add_event_source(source, handler)) { - delete source; - return nullptr; - } - return source; -} - -EventSource *Looper::add_timeout(int timeout_ms, EventHandler handler) { - auto source = new TimeoutSource(timeout_ms); - if (! add_event_source(source, handler)) { - delete source; - return nullptr; - } - return source; -} - -} // namespace Looper diff --git a/src/gui/looper/EventLoop.h b/src/gui/looper/EventLoop.h deleted file mode 100644 index 0b209243..00000000 --- a/src/gui/looper/EventLoop.h +++ /dev/null @@ -1,61 +0,0 @@ -// -// Looper.h - This file is part of the Grinder library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#ifndef LOOPER_EVENTLOOP_H -#define LOOPER_EVENTLOOP_H - -#include -#include -#include -#include - -#include -#include - -namespace cdroid -{ - -class Looper -{ -public: - Looper(); - int run(); - void quit(int exit_code=0); - - template< class T, class... Args > - T *emplace_event_source(Args&&... args){ - auto source = new T(std::forward(args)...); - if (! add_event_source(source)) { - delete source; - return nullptr; - } - return source; - } - - static Looper*getDefault(); - - bool add_event_source(EventSource *source, EventHandler handler=nullptr); - bool set_source_handler(EventSource *source, EventHandler handler); - bool remove_event_source(EventSource *source); - bool clear_source_handler(EventSource *source){ - return set_source_handler(source, nullptr); - } - - EventSource *add_file(int fd, FileEvents events, EventHandler handler=nullptr); - EventSource *add_idle(EventHandler handler=nullptr); - EventSource *add_timeout(int timeout_ms, EventHandler handler=nullptr); -private: - static Looper*mInst; - struct Private; - std::shared_ptr impl; - void iteration(); - bool contains_source(EventSource *source) const; -}; - -} // namespace cdroid - -#endif // LOOP_EVENTLOOP_H diff --git a/src/gui/looper/EventSource.h b/src/gui/looper/EventSource.h deleted file mode 100644 index 7e91dbb0..00000000 --- a/src/gui/looper/EventSource.h +++ /dev/null @@ -1,55 +0,0 @@ -// -// EventSource.h - This file is part of the Grinder library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#ifndef LOOPER_EVENTSOURCE_H -#define LOOPER_EVENTSOURCE_H - -#include - -namespace cdroid -{ - -class Looper; -class EventSource; - -typedef std::function EventHandler; - -class EventSource -{ -public: - virtual ~EventSource() {} - virtual bool prepare(int& max_timeout) - { - max_timeout = -1; - return false; - } - virtual bool check() = 0; - virtual bool dispatch(EventHandler& func) = 0; - virtual bool is_file_source() const - { - return false; - } - virtual bool is_timeout_source() const - { - return false; - } - virtual bool is_idle_source() const - { - return false; - } - -private: - friend class Looper; - struct { - bool ready; - EventHandler handler; - } loop_data; -}; - -} // namespace cdroid - -#endif // LOOPER_EVENTSOURCE_H diff --git a/src/gui/looper/FileEvents.h b/src/gui/looper/FileEvents.h deleted file mode 100644 index 50ea28da..00000000 --- a/src/gui/looper/FileEvents.h +++ /dev/null @@ -1,43 +0,0 @@ -// -// FileEvents.h - This file is part of the UI library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#ifndef LOOP_FILEEVENTS_H -#define LOOP_FILEEVENTS_H - -#include - -namespace cdroid -{ - -enum class FileEvents { - NONE = 0, - INPUT = POLLIN, - OUTPUT = POLLOUT, - PRIORITY = POLLPRI, - ERROR = POLLERR, - HANGUP = POLLHUP, -}; - -} // namespace cdroid - -static inline int operator&(cdroid::FileEvents ev1, cdroid::FileEvents ev2) -{ - return static_cast(ev1) & static_cast(ev2); -} - -static inline int operator&(int ev1, cdroid::FileEvents ev2) -{ - return ev1 & static_cast(ev2); -} - -static inline cdroid::FileEvents operator|(cdroid::FileEvents ev1, cdroid::FileEvents ev2) -{ - return static_cast(static_cast(ev1) | static_cast(ev2)); -} - -#endif // LOOP_FILEEVENTS_H - diff --git a/src/gui/looper/FileSource.h b/src/gui/looper/FileSource.h deleted file mode 100644 index 49149157..00000000 --- a/src/gui/looper/FileSource.h +++ /dev/null @@ -1,58 +0,0 @@ -// -// FileSource.h - This file is part of the Grinder library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#ifndef LOOP_FILESOURCE_H -#define LOOP_FILESOURCE_H - -#include -#include -#include - -namespace cdroid -{ - -class FileSource : public EventSource -{ -public: - int fd, revents; - FileEvents events; - FileSource(int fd, FileEvents events=FileEvents::NONE) - : fd(fd), revents(0), events(events) {} - - bool prepare(int&) override - { - return false; - } - - bool check() override - { - if (events == FileEvents::NONE || revents == 0) - return false; - if (((revents & FileEvents::INPUT) && (events & FileEvents::INPUT)) || - ((revents & FileEvents::OUTPUT) && (events & FileEvents::OUTPUT)) || - ((revents & FileEvents::PRIORITY) && (events & FileEvents::PRIORITY)) || - ((revents & FileEvents::ERROR) && (events & FileEvents::ERROR)) || - ((revents & FileEvents::HANGUP) && (events & FileEvents::HANGUP))) { - return true; - } - return false; - } - - bool dispatch(EventHandler &func) - { - return func(*this); - } - - bool is_file_source() const override final - { - return true; - } -}; - -} // namespace cdroid - -#endif // LOOPER_FILESOURCE_H diff --git a/src/gui/looper/GenericSignalSource.cpp b/src/gui/looper/GenericSignalSource.cpp deleted file mode 100644 index d091b652..00000000 --- a/src/gui/looper/GenericSignalSource.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -namespace cdroid -{ - -static const int SIG_MAX = 128; -static const int PIPE_READ = 0; -static const int PIPE_WRITE = 1; -static int pipe_fds[2] = { -1, -1 }; - -static void signal_handler(int signo) -{ - uint32_t usigno = signo; - ::write(pipe_fds[PIPE_WRITE], &usigno, sizeof(uint32_t)); -} - -GenericSignalSource::GenericSignalSource(bool manage_proc_mask) - : GenericSignalSource(nullptr, manage_proc_mask) -{ -} - -GenericSignalSource::GenericSignalSource(const sigset_t *sigs, bool manage_proc_mask) - : SignalSource(sigs, manage_proc_mask) -{ - if (pipe_fds[0] == -1 && pipe_fds[1] == -1) { - pipe(pipe_fds); - fd = pipe_fds[PIPE_READ]; - } - - if (manage_proc_mask) - sigprocmask(SIG_UNBLOCK, sigs, nullptr); -} - -GenericSignalSource::~GenericSignalSource() -{ - ::close(pipe_fds[0]); - ::close(pipe_fds[1]); - pipe_fds[0] = pipe_fds[1] = -1; - - sigset_t fullset; - sigfillset(&fullset); - for (int i = 0; i < SIG_MAX; i++) { - int res = sigismember(&fullset, i); - if (res > 0) - signal(i, SIG_DFL); - } -} - -bool GenericSignalSource::dispatch(EventHandler &func) -{ - uint32_t sig = 0; - if (::read(fd, &sig, sizeof(uint32_t)) == sizeof(uint32_t)) { - signo = sig; - return FileSource::dispatch(func); - } - return true; -} - -void GenericSignalSource::update_signals(const sigset_t *sigs, bool manage_proc_mask) -{ - for (int i = 0; i < SIG_MAX; i++) { - int res = sigismember(sigs, i); - if (res > 0) - signal(i, signal_handler); - else if (res == 0) - signal(i, SIG_DFL); - } - - if (manage_proc_mask) - sigprocmask(SIG_UNBLOCK, sigs, nullptr); -} - -} // namespace cdroid diff --git a/src/gui/looper/GenericSignalSource.h b/src/gui/looper/GenericSignalSource.h deleted file mode 100644 index 32c3e747..00000000 --- a/src/gui/looper/GenericSignalSource.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef LOOP_GENERICSIGNALSOURCE_H -#define LOOP_GENERICSIGNALSOURCE_H - -#include - -namespace cdroid -{ - -class GenericSignalSource : public SignalSource -{ -public: - GenericSignalSource(bool manage_proc_mask=false); - GenericSignalSource(const sigset_t *sigs=nullptr, bool manage_proc_mask=false); - ~GenericSignalSource(); - bool dispatch(EventHandler &func) override; - -protected: - void update_signals(const sigset_t *sigs, bool manage_proc_mask); -}; - -} // namespace cdroid - -#endif // LOOPER_GENERICSIGNALSOURCE_H diff --git a/src/gui/looper/IdleSource.h b/src/gui/looper/IdleSource.h deleted file mode 100644 index a1774932..00000000 --- a/src/gui/looper/IdleSource.h +++ /dev/null @@ -1,39 +0,0 @@ -// -// IdleSource.h - This file is part of the UI library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#ifndef LOOPIDLESOURCE_H -#define LOOPIDLESOURCE_H - -#include - -namespace cdroid -{ - -class IdleSource : public EventSource -{ -public: - bool prepare(int&) override final - { - return true; - } - bool check() override final - { - return true; - } - bool dispatch(EventHandler &func) override - { - return func(*this); - } - bool is_idle_source() const override final - { - return true; - } -}; - -} // namespace cdroid - -#endif // LOOPER_IDLESOURCE_H diff --git a/src/gui/looper/Platform.h b/src/gui/looper/Platform.h deleted file mode 100644 index 68956006..00000000 --- a/src/gui/looper/Platform.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef LOOPER_PLATFORM_H -#define LOOPER_PLATFORM_H - -#if defined(__linux) || defined(__linux__) -# define LOOPER_LINUX 1 -#endif - -#endif // LOOPER_PLATFORM_H - diff --git a/src/gui/looper/SignalFD.cpp b/src/gui/looper/SignalFD.cpp deleted file mode 100644 index a6a376e9..00000000 --- a/src/gui/looper/SignalFD.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// -// SignalFD.cpp - This file is part of the Grinder library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#include - -#ifdef LOOPER_LINUX - -#include -#include - -namespace cdroid -{ - -SignalFD::SignalFD(bool manage_proc_mask) - : SignalFD(nullptr, manage_proc_mask) -{ -} - -SignalFD::SignalFD(const sigset_t *sigs, bool manage_proc_mask) - : SignalSource(sigs, manage_proc_mask) -{ - if (sigs && manage_proc_mask) - sigprocmask(SIG_BLOCK, sigs, nullptr); -} - -bool SignalFD::dispatch(EventHandler &func) -{ - signalfd_siginfo info; - if (read(fd, &info, sizeof(signalfd_siginfo)) == sizeof(signalfd_siginfo)) { - signo = info.ssi_signo; - return FileSource::dispatch(func); - } - return true; -} - -void SignalFD::update_signals(const sigset_t *sigs, bool manage_proc_mask) -{ - fd = signalfd(fd, sigs, SFD_NONBLOCK | SFD_CLOEXEC); - if (manage_proc_mask) { - sigset_t allset; - ::sigfillset(&allset); - ::sigprocmask(SIG_UNBLOCK, &allset, nullptr); - ::sigprocmask(SIG_BLOCK, sigs, nullptr); - } -} - -} // namespace cdroid - -#endif // LOOPER_LINUX diff --git a/src/gui/looper/SignalFD.h b/src/gui/looper/SignalFD.h deleted file mode 100644 index 16213075..00000000 --- a/src/gui/looper/SignalFD.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// SignalFD.h - This file is part of the Grinder library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#ifndef LOOPER_LINUX_SIGNALFD_H -#define LOOPER_LINUX_SIGNALFD_H - -#include -#ifdef LOOPER_LINUX - -#include - -namespace cdroid -{ - -class SignalFD : public SignalSource -{ -public: - SignalFD(bool manage_proc_mask=false); - SignalFD(const sigset_t *sigs, bool manage_proc_mask=false); - - bool dispatch(EventHandler &func) override; - -protected: - void update_signals(const sigset_t *sigs, bool manage_proc_mask); -}; - -} // namespace cdroid - -#endif // LOOPER_LINUX - -#endif // LOOPER_LINUX_SIGNALFD_H diff --git a/src/gui/looper/SignalSource.cpp b/src/gui/looper/SignalSource.cpp deleted file mode 100644 index 8109d9e8..00000000 --- a/src/gui/looper/SignalSource.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#ifdef LOOPER_LINUX -# include -#else -# include -#endif -#include - -namespace cdroid -{ - -SignalSource::SignalSource(bool manage_proc_mask) - : FileSource(-1, FileEvents::INPUT), - m_manage_proc_mask(manage_proc_mask) -{ - sigemptyset(&m_sigs); - if (m_manage_proc_mask) - sigprocmask(SIG_BLOCK, nullptr, &m_old_sigs); -} - -SignalSource::SignalSource(const sigset_t *sigs, bool manage_proc_mask) - : FileSource(-1, FileEvents::INPUT), - m_manage_proc_mask(manage_proc_mask) -{ - if (sigs) - m_sigs = *sigs; - else - sigemptyset(&m_sigs); - if (m_manage_proc_mask) - sigprocmask(SIG_BLOCK, nullptr, &m_old_sigs); -} - -SignalSource::~SignalSource() -{ - try { - if (m_manage_proc_mask) { - sigset_t ss; - sigfillset(&ss); - sigprocmask(SIG_UNBLOCK, &ss, nullptr); - sigprocmask(SIG_BLOCK, &m_old_sigs, nullptr); - } - close(fd); - } catch (...) { - /* pass */ - } -} - -void SignalSource::add(int signo) -{ - sigaddset(&m_sigs, signo); - update(); -} - -void SignalSource::remove(int signo) -{ - sigdelset(&m_sigs, signo); - update(); -} - -void SignalSource::update() -{ - update_signals(&m_sigs, m_manage_proc_mask); -} - -} // namespace cdroid diff --git a/src/gui/looper/SignalSource.h b/src/gui/looper/SignalSource.h deleted file mode 100644 index 5517cb6b..00000000 --- a/src/gui/looper/SignalSource.h +++ /dev/null @@ -1,43 +0,0 @@ -// -// SignalSource.h - This file is part of the UI library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#ifndef LOOP_SIGNALSOURCE_H -#define LOOP_SIGNALSOURCE_H - -#include -#include - -namespace cdroid -{ - -class SignalSource : public FileSource -{ -public: - int signo; // when event is dispatched, contains the signal number - virtual ~SignalSource(); - void add(int signo); - void remove(int signo); - bool check() override - { - return (revents & FileEvents::INPUT); - } - void update(); - -protected: - SignalSource(bool manage_proc_mask=false); - SignalSource(const sigset_t *sigs, bool manage_proc_mask=false); - virtual void update_signals(const sigset_t *sigs, bool manage_proc_mask) = 0; - -private: - sigset_t m_sigs; - sigset_t m_old_sigs; - bool m_manage_proc_mask; -}; - -} // namespace cdroid - -#endif // LOOP_SIGNALSOURCE_H diff --git a/src/gui/looper/TimeoutSource.cpp b/src/gui/looper/TimeoutSource.cpp deleted file mode 100644 index b703611a..00000000 --- a/src/gui/looper/TimeoutSource.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// -// TimeoutSource.cpp - This file is part of the UI library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#include -#include -#include - -using namespace std; - -namespace cdroid -{ - -TimeoutSource::TimeoutSource(int timeout) - : m_timeout(timeout), - m_next_expiry(time_now() + timeout) -{ -} - -bool TimeoutSource::is_ready(int &max_timeout) -{ - uint64_t now = time_now(); - if (now >= m_next_expiry) { - m_next_expiry = (now + m_timeout) - (now - m_next_expiry); - return true; - } else { - max_timeout = m_next_expiry - now; - return false; - } -} - -bool TimeoutSource::prepare(int &max_timeout) -{ - return is_ready(max_timeout); -} - -bool TimeoutSource::check() -{ - int unused = 0; - return is_ready(unused); -} - -} // namespace cdroid diff --git a/src/gui/looper/TimeoutSource.h b/src/gui/looper/TimeoutSource.h deleted file mode 100644 index 2d7016fd..00000000 --- a/src/gui/looper/TimeoutSource.h +++ /dev/null @@ -1,40 +0,0 @@ -// -// TimeoutSource.h - This file is part of the UI library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#ifndef LOOP_TIMEOUTSOURCE_H -#define LOOP_TIMEOUTSOURCE_H - -#include -#include - -namespace cdroid -{ - -class TimeoutSource : public EventSource -{ -public: - TimeoutSource(int timeout=-1); - bool prepare(int &max_timeout) override; - bool check() override; - bool dispatch(EventHandler &func) override - { - return func(*this); - } - bool is_timeout_source() const override final - { - return true; - } - -private: - int m_timeout; - std::uint64_t m_next_expiry; - bool is_ready(int& max_timeout); -}; - -} // namespace cdroid - -#endif // LOOP_TIMEOUTSOURCE_H diff --git a/src/gui/looper/TimerFD.cpp b/src/gui/looper/TimerFD.cpp deleted file mode 100644 index 1b2192cc..00000000 --- a/src/gui/looper/TimerFD.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// -// TimerFD.cpp - This file is part of the Grinder library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#include - -#ifdef LOOPER_LINUX - -#include -#include -#include -#include - -using namespace std; - -namespace cdroid -{ - -TimerFD::TimerFD(int timeout_ms, bool one_shot) - : FileSource(::timerfd_create(CLOCK_MONOTONIC, - TFD_NONBLOCK | TFD_CLOEXEC), - FileEvents::INPUT), - m_timeout(timeout_ms), - m_one_shot(one_shot) -{ - arm(); -} - -TimerFD::~TimerFD() -{ - if (fd >= 0) - ::close(fd); -} - -static inline void ms_to_timespec(int ms, struct timespec *ts) -{ - ts->tv_sec = ms / 1000; - ts->tv_nsec = (ms % 1000) * 1000000; -} - -void TimerFD::arm(int timeout) -{ - if (timeout >= 0) - m_timeout = timeout; - itimerspec its {{0,0},{0,0}}; - ms_to_timespec(m_timeout, &its.it_value); - if (! m_one_shot) { - its.it_interval.tv_sec = its.it_value.tv_sec; - its.it_interval.tv_nsec = its.it_value.tv_nsec; - } - ::timerfd_settime(fd, 0, &its, nullptr); -} - -void TimerFD::disarm() -{ - itimerspec its {{0,0},{0,0}}; - ::timerfd_settime(fd, 0, &its, nullptr); -} - -bool TimerFD::check() -{ - return (revents & FileEvents::INPUT); -} - -bool TimerFD::dispatch(EventHandler &func) -{ - uint64_t count = 0; - if (::read(fd, &count, sizeof(uint64_t)) == sizeof(uint64_t)) - return FileSource::dispatch(func); - return true; -} - -} // namespace cdroid - -#endif // LOOPER_LINUX diff --git a/src/gui/looper/TimerFD.h b/src/gui/looper/TimerFD.h deleted file mode 100644 index bc692cf5..00000000 --- a/src/gui/looper/TimerFD.h +++ /dev/null @@ -1,62 +0,0 @@ -// -// TimerFD.h - This file is part of the Grinder library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#ifndef LOOPER_LINUX_TIMERFD_H -#define LOOPER_LINUX_TIMERFD_H - -#include -#ifdef LOOPER_LINUX - -#include - -namespace cdroid -{ - -class TimerFD : public FileSource -{ -public: - TimerFD(int timeout_ms, bool one_shot=false); - ~TimerFD(); - - void arm(int timeout=-1); - void disarm(); - - bool one_shot() const - { - return m_one_shot; - } - void set_one_shot(bool one_shot) - { - disarm(); - m_one_shot = one_shot; - arm(); - } - - int timeout() const - { - return m_timeout; - } - void set_timeout(int timeout_ms) - { - disarm(); - m_timeout = timeout_ms; - arm(); - } - - bool check() override; - bool dispatch(EventHandler &func) override; - -private: - int m_timeout; - bool m_one_shot; -}; - -} // namespace cdroid - -#endif // LOOPER_LINUX - -#endif // LOOPER_LINUX_TIMERFD_H diff --git a/src/gui/looper/Utility.h b/src/gui/looper/Utility.h deleted file mode 100644 index a2a66082..00000000 --- a/src/gui/looper/Utility.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// Utility.h - This file is part of the Grinder library -// -// Copyright (c) 2015 Matthew Brush -// All rights reserved. -// - -#ifndef LOOPER_UTILITY_H -#define LOOPER_UTILITY_H - -#include -#include - -namespace cdroid -{ - -static inline std::uint64_t time_now() -{ - return std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); -} - -} // namespace cdroid - -#endif // LOOPER_UTILITY_H - diff --git a/src/gui/looper/looper.h b/src/gui/looper/looper.h deleted file mode 100644 index 9296897d..00000000 --- a/src/gui/looper/looper.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __LOOPER_HEADER__ -#define __LOOPER_HEADER__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef LOOPER_LINUX -# include -# include -#endif - -#endif // LOOPER_HEADER__ diff --git a/src/gui/views/toastwindow.cc b/src/gui/views/toastwindow.cc old mode 100644 new mode 100755 index 3034f52e..b2d069f4 --- a/src/gui/views/toastwindow.cc +++ b/src/gui/views/toastwindow.cc @@ -11,7 +11,7 @@ ToastWindow::ToastWindow(int w,int h):Window(0,0,w,h,TYPE_TOAST){ timeout_=-1; time_elapsed=0; setFocusable(false); - sendMessage((DWORD)WM_TIMER,(DWORD)TIMER_ID,0,500); + //sendMessage((DWORD)WM_TIMER,(DWORD)TIMER_ID,0,500); toasts_.push_back(this); } @@ -19,7 +19,7 @@ ToastWindow::~ToastWindow(){ toasts_.erase(std::find(toasts_.begin(),toasts_.end(),this)); } -bool ToastWindow::onMessage(DWORD msg,DWORD wp,ULONG lp){ +/*bool ToastWindow::onMessage(DWORD msg,DWORD wp,ULONG lp){ if(msg==WM_TIMER && wp==TIMER_ID){ time_elapsed+=500; if(time_elapsed>=timeout_){ @@ -30,7 +30,7 @@ bool ToastWindow::onMessage(DWORD msg,DWORD wp,ULONG lp){ return true; } return Window::onMessage(msg,wp,lp); -} +}*/ bool ToastWindow::onKeyUp(int keyCode,KeyEvent&evt){ time_elapsed=0; diff --git a/src/gui/views/toastwindow.h b/src/gui/views/toastwindow.h old mode 100644 new mode 100755 index 625a1326..6b37b14e --- a/src/gui/views/toastwindow.h +++ b/src/gui/views/toastwindow.h @@ -13,7 +13,6 @@ DECLARE_UIEVENT(ToastWindow*,OnCreateContentListener); public: ToastWindow(int w,int h); ~ToastWindow(); - virtual bool onMessage(DWORD msg,DWORD wp,ULONG lp)override; virtual bool onKeyUp(int,KeyEvent&event)override; static ToastWindow*makeWindow(OnCreateContentListener oncreate,UINT timeout=LENGTH_SHORT); static ToastWindow*makeText(const std::string&txt,UINT timeout=LENGTH_SHORT); diff --git a/src/gui/widget/abslistview.cc b/src/gui/widget/abslistview.cc index 84f9f90b..c86c4abd 100755 --- a/src/gui/widget/abslistview.cc +++ b/src/gui/widget/abslistview.cc @@ -1246,7 +1246,8 @@ void AbsListView::keyPressed() { } } if (longClickable && !mDataChanged) { - postDelayed(std::bind(&AbsListView::CheckForKeyLongPress,this),ViewConfiguration::getLongPressTimeout()); + Runnable mr(std::bind(&AbsListView::CheckForKeyLongPress,this)); + postDelayed(mr,ViewConfiguration::getLongPressTimeout()); } } } diff --git a/src/gui/widget/abslistview.h b/src/gui/widget/abslistview.h index 673a4736..fac438d1 100755 --- a/src/gui/widget/abslistview.h +++ b/src/gui/widget/abslistview.h @@ -1,11 +1,10 @@ #ifndef __ABS_LISTVIEW_H__ #define __ABS_LISTVIEW_H__ -#include +#include #include #include #include #include -#include namespace cdroid{ #define OVERSCROLL_LIMIT_DIVISOR 3 diff --git a/src/gui/widget/absspinner.h b/src/gui/widget/absspinner.h old mode 100644 new mode 100755 index 90413ed2..db701c49 --- a/src/gui/widget/absspinner.h +++ b/src/gui/widget/absspinner.h @@ -1,7 +1,7 @@ #ifndef __ABS_SPINNER_H__ #define __ABS_SPINNER_H__ #include -#include +#include namespace cdroid{ class AbsSpinner:public AdapterView{ protected: diff --git a/src/gui/widget/adapter.cc b/src/gui/widget/adapter.cc old mode 100644 new mode 100755 index 3c4da8c6..c1bbe94a --- a/src/gui/widget/adapter.cc +++ b/src/gui/widget/adapter.cc @@ -58,8 +58,8 @@ bool Adapter::isEmpty()const{ return getCount() == 0; } - /////////////////////////////////////////////////////////////////////////////////////////////// + void PagerAdapter::startUpdate(ViewGroup* container){ startUpdate((View*)container); } @@ -68,10 +68,12 @@ void PagerAdapter::startUpdate(View*container){ } void*PagerAdapter::instantiateItem(ViewGroup* container, int position){ - instantiateItem((View*)container,position); + return instantiateItem((View*)container,position); } void* PagerAdapter::instantiateItem(View* container, int position){ + throw "Required method instantiateItem was not overridden"; + return nullptr; } void PagerAdapter::destroyItem(ViewGroup* container, int position, void* object){ diff --git a/src/gui/widget/analogclock.cc b/src/gui/widget/analogclock.cc old mode 100644 new mode 100755 index c1e6b710..9b6868cf --- a/src/gui/widget/analogclock.cc +++ b/src/gui/widget/analogclock.cc @@ -54,9 +54,9 @@ Drawable*AnalogClock::getClockDrawable(int id){ } void AnalogClock::onAttached(){ - sendMessage(WM_TIMER,0,0,1000); + //sendMessage(WM_TIMER,0,0,1000); } -bool AnalogClock::onMessage(DWORD msg,DWORD wp,ULONG lp){ +/*bool AnalogClock::onMessage(DWORD msg,DWORD wp,ULONG lp){ if(msg==WM_TIMER){ std::time_t t = std::time(NULL); struct std::tm when= *std::localtime(&t); @@ -64,12 +64,12 @@ bool AnalogClock::onMessage(DWORD msg,DWORD wp,ULONG lp){ mHour=when.tm_hour; mMinutes=when.tm_min; mSeconds=when.tm_sec; - sendMessage(msg,wp,lp,1000); + //sendMessage(msg,wp,lp,1000); invalidate(nullptr); return true; } return View::onMessage(msg,wp,lp); -} +}*/ void AnalogClock::onDraw(Canvas&canvas){ View::onDraw(canvas); diff --git a/src/gui/widget/analogclock.h b/src/gui/widget/analogclock.h old mode 100644 new mode 100755 index 8c554c58..463421d6 --- a/src/gui/widget/analogclock.h +++ b/src/gui/widget/analogclock.h @@ -27,7 +27,7 @@ public: AnalogClock(int w,int h); void setClockDrawable(Drawable*d,int id); Drawable*getClockDrawable(int id); - bool onMessage(DWORD msg,DWORD wp,ULONG lp); + //bool onMessage(DWORD msg,DWORD wp,ULONG lp); }; }//namespace diff --git a/src/gui/widget/edgeeffect.h b/src/gui/widget/edgeeffect.h old mode 100644 new mode 100755 index 954cf359..b73e3aea --- a/src/gui/widget/edgeeffect.h +++ b/src/gui/widget/edgeeffect.h @@ -1,8 +1,8 @@ #ifndef __EDGE_EFFECT_H__ #define __EDGE_EFFECT_H__ -#include -#include -#include +#include +#include +#include namespace cdroid{ diff --git a/src/gui/widget/horizontalscrollview.h b/src/gui/widget/horizontalscrollview.h old mode 100644 new mode 100755 index 6cabcb5a..12cf55a5 --- a/src/gui/widget/horizontalscrollview.h +++ b/src/gui/widget/horizontalscrollview.h @@ -3,7 +3,6 @@ #include #include #include -#include namespace cdroid{ diff --git a/src/gui/widget/imageview.cc b/src/gui/widget/imageview.cc old mode 100644 new mode 100755 index 063b0119..1db868db --- a/src/gui/widget/imageview.cc +++ b/src/gui/widget/imageview.cc @@ -317,7 +317,7 @@ void ImageView::configureBounds(){ const bool fits = (dwidth < 0 || vwidth == dwidth) && (dheight < 0 || vheight == dheight); - LOGD("drawables.setBounds(%d,%d) fits=%d mScaleType=%d",vwidth,vheight,fits,mScaleType); + LOGV("drawables.setBounds(%d,%d) fits=%d mScaleType=%d",vwidth,vheight,fits,mScaleType); mDrawable->setBounds(0, 0, vwidth, vheight); @@ -387,8 +387,8 @@ void ImageView::configureBounds(){ //mDrawMatrix.setRectToRect(mTempSrc, mTempDst, scaleTypeToScaleToFit(mScaleType)); } } - LOGD("ScaleType=%d DrawMatrix=%.2f,%.2f, %.2f,%.2f, %.2f,%.2f",mScaleType, - mDrawMatrix.xx,mDrawMatrix.yx,mDrawMatrix.xy,mDrawMatrix.yy,mDrawMatrix.x0,mDrawMatrix.y0); + LOGV("ScaleType=%d DrawMatrix=%.2f,%.2f, %.2f,%.2f, %.2f,%.2f",mScaleType, + mDrawMatrix.xx,mDrawMatrix.yx,mDrawMatrix.xy,mDrawMatrix.yy,mDrawMatrix.x0,mDrawMatrix.y0); } void ImageView::invalidateDrawable(Drawable& dr){ diff --git a/src/gui/widget/keyboardview.h b/src/gui/widget/keyboardview.h index 660a2d1a..3dc3ade3 100755 --- a/src/gui/widget/keyboardview.h +++ b/src/gui/widget/keyboardview.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include namespace cdroid{ diff --git a/src/gui/widget/layoutparams.h b/src/gui/widget/layoutparams.h old mode 100644 new mode 100755 index 32a3c626..8a40dbb4 --- a/src/gui/widget/layoutparams.h +++ b/src/gui/widget/layoutparams.h @@ -1,9 +1,9 @@ #ifndef __LAYOUT_PARAMS_H__ #define __LAYOUT_PARAMS_H__ #include -#include -#include #include +#include +#include namespace cdroid{ class View; diff --git a/src/gui/widget/numberpicker.cc b/src/gui/widget/numberpicker.cc old mode 100644 new mode 100755 index 6dc1bc33..cc33c94a --- a/src/gui/widget/numberpicker.cc +++ b/src/gui/widget/numberpicker.cc @@ -2,7 +2,6 @@ #include #include #include -#include //https://gitee.com/awang/WheelView/blob/master/src/com/wangjie/wheelview/WheelView.java diff --git a/src/gui/widget/numberpicker.h b/src/gui/widget/numberpicker.h old mode 100644 new mode 100755 index d948607c..81d0bb24 --- a/src/gui/widget/numberpicker.h +++ b/src/gui/widget/numberpicker.h @@ -3,9 +3,8 @@ #include #include #include -#include -#include -#include +#include +#include namespace cdroid{ diff --git a/src/gui/widget/overscroller.cc b/src/gui/widget/overscroller.cc index 3db6e54e..f211a6c2 100755 --- a/src/gui/widget/overscroller.cc +++ b/src/gui/widget/overscroller.cc @@ -1,6 +1,7 @@ #include -#include -#include +#include +#include +#include #include @@ -53,6 +54,7 @@ OverScroller::SplineOverScroller::SplineOverScroller(Context* context) { * 39.37f // inch/meter * ppi * 0.84f; // look and feel tuning + mFlingFriction = ViewConfiguration::getScrollFriction(); } void OverScroller::SplineOverScroller::startScroll(int start, int distance, int duration) { diff --git a/src/gui/widget/overscroller.h b/src/gui/widget/overscroller.h index 83b67d21..daaad9dc 100755 --- a/src/gui/widget/overscroller.h +++ b/src/gui/widget/overscroller.h @@ -1,7 +1,7 @@ #ifndef __OVER_SCROLLER_H__ #define __OVER_SCROLLER_H__ -#include -#include +#include +#include namespace cdroid{ @@ -47,7 +47,7 @@ public: // The allowed overshot distance before boundary is reached. int mOver; // Fling friction - float mFlingFriction = ViewConfiguration::getScrollFriction(); + float mFlingFriction; // Current state of the animation. int mState = SPLINE; // A context-specific coefficient adjusted to physical values. diff --git a/src/gui/widget/progressbar.cc b/src/gui/widget/progressbar.cc index 8c87a63c..d6856966 100755 --- a/src/gui/widget/progressbar.cc +++ b/src/gui/widget/progressbar.cc @@ -216,13 +216,15 @@ void ProgressBar::refreshProgress(int id, int progress, bool fromUser,bool anima if(!mRefreshIsPosted){ LOGD("setprogress %d=%d bools=%d,%d",id,progress,mAttached,mRefreshIsPosted); if(mAttached&&!mRefreshIsPosted){ - postDelayed([this](){ + Runnable run; + run=[this](){ for(int i=ID_PRIMARY;i<=ID_SECONDARY;i++){ RefreshData&rd=mData[i]; doRefreshProgress(i, rd.progress, rd.fromUser, true, rd.animate); } mRefreshIsPosted=false; - },10); + }; + postDelayed(run,10); mRefreshIsPosted=true; } } @@ -241,6 +243,7 @@ bool ProgressBar::setProgressInternal(int value, bool fromUser,bool animate){ void ProgressBar::setProgress(int value){ setProgressInternal(value,FALSE); } + void ProgressBar::setSecondaryProgress(int secondaryProgress) { if (mIndeterminate) return; diff --git a/src/gui/widget/recyclebin.h b/src/gui/widget/recyclebin.h index 71dbd381..06f80bf2 100755 --- a/src/gui/widget/recyclebin.h +++ b/src/gui/widget/recyclebin.h @@ -8,7 +8,7 @@ #ifndef __RECYCLEBIN_H__ #define __RECYCLEBIN_H__ #include -#include +#include namespace cdroid{ class RecycleBin{ diff --git a/src/gui/widget/scrollview.h b/src/gui/widget/scrollview.h old mode 100644 new mode 100755 index d9dc2f61..24d83cec --- a/src/gui/widget/scrollview.h +++ b/src/gui/widget/scrollview.h @@ -3,7 +3,6 @@ #include #include #include -#include namespace cdroid{ diff --git a/src/gui/widget/simplemonthview.h b/src/gui/widget/simplemonthview.h old mode 100644 new mode 100755 index bc800189..db7a4bcd --- a/src/gui/widget/simplemonthview.h +++ b/src/gui/widget/simplemonthview.h @@ -1,7 +1,7 @@ #ifndef __SIMPLE_MONTHVIEW_H__ #define __SIMPLE_MONTHVIEW_H__ #include -#include +#include namespace cdroid{ class SimpleMonthView:public View{ diff --git a/src/gui/widget/tablerow.h b/src/gui/widget/tablerow.h old mode 100644 new mode 100755 index 2754e973..d5ba0c65 --- a/src/gui/widget/tablerow.h +++ b/src/gui/widget/tablerow.h @@ -1,7 +1,7 @@ #ifndef __TABLE_ROW_H__ #define __TABLE_ROW_H__ #include -#include +#include namespace cdroid{ diff --git a/src/gui/widget/textview.h b/src/gui/widget/textview.h index fe155cfd..85d6399c 100755 --- a/src/gui/widget/textview.h +++ b/src/gui/widget/textview.h @@ -18,8 +18,8 @@ #define __TEXTVIEW_H__ #include -#include -#include +#include +#include namespace cdroid { diff --git a/src/gui/widget/view.cc b/src/gui/widget/view.cc index ee3a531d..76214b6d 100755 --- a/src/gui/widget/view.cc +++ b/src/gui/widget/view.cc @@ -165,7 +165,6 @@ void View::initView(){ mOnFocusChangeListener=nullptr; mOnScrollChangeListener=nullptr; mOverScrollMode=OVER_SCROLL_NEVER; - mOnMessage=nullptr; mVerticalScrollbarPosition=0; mUserPaddingLeft=mUserPaddingRight=0; mUserPaddingTop=mUserPaddingBottom=0; @@ -532,7 +531,7 @@ void View::setFadingEdgeLength(int length){ } void View::transformFromViewToWindowSpace(int*inOutLocation){ View* view = this; - double position[2]={inOutLocation[0],inOutLocation[1]}; + double position[2]={(double)inOutLocation[0],(double)inOutLocation[1]}; if(!hasIdentityMatrix()){ mMatrix.transform_point(position[0],position[1]); } @@ -1225,10 +1224,6 @@ void View::setOnScrollChangeListener(OnScrollChangeListener l){ mOnScrollChangeListener=l; } -void View::setMessageListener(MessageListener ls){ - mOnMessage=ls; -} - void View::clip(RefPtrrgn){ if(mParent){//clip sliblings BOOL afterthis=FALSE; @@ -2595,7 +2590,9 @@ void View::invalidate(int l,int t,int w,int h){ } void View::postInvalidate(){ - postDelayed([this](){ invalidate(nullptr);},30); + Runnable r; + r=[this](){ invalidate(nullptr);}; + postDelayed(r,30); } void View::postInvalidateOnAnimation(){ @@ -3311,7 +3308,7 @@ void View::checkForLongClick(int delayOffset,int x,int y){ mHasPerformedLongPress = false; mOriginalPressedState=isPressed(); mPendingCheckForLongPress=std::bind(&View::checkLongPressCallback,this,x,y); - post(this,mPendingCheckForLongPress,ViewConfiguration::getLongPressTimeout()-delayOffset); + postDelayed(mPendingCheckForLongPress,ViewConfiguration::getLongPressTimeout()-delayOffset); } } @@ -3427,52 +3424,27 @@ bool View::onTouchEvent(MotionEvent& mt){ return false; } -void View::sendMessage(View*v,DWORD msgid,DWORD wParam,ULONG lParam,DWORD delayedtime){ - View*root=getRootView(); - if(root!=this) - root->sendMessage(v,msgid,wParam,lParam,delayedtime); - -} - -void View::sendMessage(DWORD msgid,DWORD wParam,ULONG lParam,DWORD delayedtime){ - sendMessage(this,msgid,wParam,lParam,delayedtime); -} - void View::postOnAnimation(Runnable action){ - post(this,action,10); + postDelayed(action,10); } void View::postOnAnimationDelayed(Runnable action, long delayMillis){ - post(this,action,delayMillis); + postDelayed(action,delayMillis); } -void View::post(View*v,const Runnable what,DWORD delay){ - View*root=getRootView(); - if(root!=this)root->post(v,what,delay); -} - -void View::post(const Runnable what){ +void View::post(Runnable& what){ postDelayed(what,0); } -void View::postDelayed(const Runnable what,DWORD delay){ +void View::postDelayed(Runnable& what,uint32_t delay){ View*root=getRootView(); - if(root&&(root!=this))root->post(this,what,delay); + if(root&&(root!=this))root->postDelayed(what,delay); } -void View::removeCallbacks(const Runnable what){ +void View::removeCallbacks(const Runnable& what){ View*root=getRootView(); if(root&&(root!=this))root->removeCallbacks(what); } -bool View::onMessage(DWORD msgid,DWORD wParam,ULONG lParam){ - RECT r; - switch(msgid){ - default: - if(mOnMessage)return mOnMessage(*this,msgid,wParam,lParam); - return false; - } -} - /////////////////////////////////////////////////////////////////////////////////////// // For Layout support @@ -3667,7 +3639,7 @@ Matrix View::getInverseMatrix() { } float View::getRotation(){ - + return .0f; } void View::setRotation(float rotation){ @@ -3675,7 +3647,7 @@ void View::setRotation(float rotation){ } float View::getRotationX(){ - + return .0f; } void View::setRotationX(float){ diff --git a/src/gui/widget/view.h b/src/gui/widget/view.h index b29c3ee4..5ece4088 100755 --- a/src/gui/widget/view.h +++ b/src/gui/widget/view.h @@ -1,10 +1,10 @@ #ifndef __NGL_VIEW_H__ #define __NGL_VIEW_H__ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include @@ -12,10 +12,12 @@ #include #include #include -#include +#include #include -#include -#include +#include +#include +#include +#include #ifndef _GLIBCXX_FUNCTIONAL #define DECLARE_UIEVENT(type,name,...) typedef type(*name)(__VA_ARGS__) @@ -238,7 +240,6 @@ public: }; DECLARE_UIEVENT(void,OnClickListener,View&); DECLARE_UIEVENT(bool,OnLongClickListener,View&); - DECLARE_UIEVENT(bool,MessageListener,View&,DWORD,DWORD,ULONG); DECLARE_UIEVENT(void,OnFocusChangeListener,View&,bool); DECLARE_UIEVENT(void,OnScrollChangeListener,View& v, int, int, int, int); DECLARE_UIEVENT(void,OnLayoutChangeListener,View* v, int left, int top, int width, int height, @@ -323,7 +324,6 @@ protected: OnFocusChangeListener mOnFocusChangeListener; std::vector mOnLayoutChangeListeners; OnScrollChangeListener mOnScrollChangeListener; - MessageListener mOnMessage; bool hasIdentityMatrix(); void computeOpaqueFlags(); @@ -356,7 +356,6 @@ protected: void postOnAnimation(Runnable action); void postOnAnimationDelayed(Runnable action, long delayMillis); - virtual void post(View*v,const Runnable what,DWORD delay=0); virtual void onSizeChanged(int w,int h,int oldw,int oldh); virtual void onScrollChanged(int l, int t, int oldl, int oldt); virtual void onLayout(bool ,int,int,int,int); @@ -520,7 +519,6 @@ public: virtual void setOnLongClickListener(OnLongClickListener l); virtual void setOnFocusChangeListener(OnFocusChangeListener listtener); virtual void setOnScrollChangeListener(OnScrollChangeListener l); - virtual void setMessageListener(MessageListener ls); void addOnLayoutChangeListener(OnLayoutChangeListener listener); void removeOnLayoutChangeListener(OnLayoutChangeListener listener); virtual bool performClick(); @@ -680,12 +678,10 @@ public: virtual bool onHoverEvent(MotionEvent& evt); virtual bool onGenericMotionEvent(MotionEvent& event); virtual void onHoverChanged(bool hovered); - virtual void sendMessage(DWORD msgid,DWORD wParam,ULONG lParam,DWORD delayedtime=0); - virtual void sendMessage(View*view,DWORD msgid,DWORD wParam,ULONG lParam,DWORD delayedtime=0); - virtual bool onMessage(DWORD msgid,DWORD wParam,ULONG lParam); - virtual void removeCallbacks(const Runnable what); - virtual void post(const Runnable what); - virtual void postDelayed(const Runnable what,DWORD delay=0); + + virtual void postDelayed(Runnable& what,uint32_t delay=0); + void post(Runnable& what); + virtual void removeCallbacks(const Runnable& what); virtual int getBaseline(); static bool isLayoutModeOptical(View*); diff --git a/src/gui/widget/viewgroup.cc b/src/gui/widget/viewgroup.cc index 605b8d54..5bff2303 100755 --- a/src/gui/widget/viewgroup.cc +++ b/src/gui/widget/viewgroup.cc @@ -85,9 +85,6 @@ ViewGroup::ViewGroup(int x,int y,int w,int h) } void ViewGroup::initGroup(){ - focusRectSrc.set(0,0,0,0); - focusRectDest.set(0,0,0,0); - focusRect.set(0,0,0,0); mFocused=nullptr; mDefaultFocus=nullptr; mFocusedInCluster=nullptr; @@ -1470,20 +1467,6 @@ bool ViewGroup::isTransformedTouchPointInView(int x,int y, View& child,POINT*out return isInView; } -void ViewGroup::onDraw(Canvas& canvas) { - // Draw the background color, if enabled - View::onDraw(canvas); - canvas.save(); - onDrawFocusRect(canvas,focusRect); - canvas.restore(); -} - -void ViewGroup::onDrawFocusRect(Canvas&canvas,const RECT&r){ - canvas.set_source_rgba(1,0,0,.5); - canvas.rectangle(r.x,r.y,r.width,r.height); - canvas.fill(); -} - void ViewGroup::onSizeChanged(int w,int h,int ow,int oh){ } @@ -1770,25 +1753,6 @@ static int isExcludedKeys(int key){ return key==KEY_MENU||key==KEY_ESCAPE;//||key==KEY_EXIT; } -void ViewGroup::moveFocusTo(const RECT&r){ - focusRectSrc=focusRectDest; - focusRectDest=r; - time_lastframe=SystemClock::uptimeMillis(); - - if(hasFlag(ATTR_ANIMATE_FOCUS)) - sendMessage(WM_TIMER,0,0,10); -} - -void ViewGroup::invalidateChildrenInFocusRect(){ - for(int i=0;igetBound(),focusRect))continue; - r.offset(-v->getX(),-v->getY()); - v->invalidate(&r); - } -} - void ViewGroup::drawableStateChanged(){ View::drawableStateChanged(); diff --git a/src/gui/widget/viewgroup.h b/src/gui/widget/viewgroup.h index 3eecc497..64bdc699 100755 --- a/src/gui/widget/viewgroup.h +++ b/src/gui/widget/viewgroup.h @@ -18,7 +18,7 @@ #define __NGLUI_GROUPVIEW_H__ #include -#include +#include namespace cdroid { @@ -80,9 +80,6 @@ private: std::vectormVisibilityChangingChildren; int mChildCountWithTransientState; class TouchTarget* mFirstTouchTarget; - RECT focusRectSrc; - RECT focusRectDest; - RECT focusRect; POINT animateTo;//save window boundray while animating POINT animateFrom;//window animate from boundary Transformation* mChildTransformation; @@ -104,8 +101,6 @@ private: bool dispatchTransformedGenericPointerEvent(MotionEvent& event, View* child); void setTouchscreenBlocksFocusNoRefocus(bool touchscreenBlocksFocus); - void moveFocusTo(const RECT&r); - void invalidateChildrenInFocusRect(); void addInArray(View* child, int index); bool removeViewInternal(View* view); void removeViewInternal(int index, View* view); @@ -161,7 +156,6 @@ protected: void drawableStateChanged()override; std::vector onCreateDrawableState()const override; - virtual void onDraw(Canvas& canvas) override; void dispatchSetPressed(bool pressed)override; virtual int getChildDrawingOrder(int childCount, int i); @@ -257,7 +251,6 @@ public: bool dispatchUnhandledMove(View* focused, int direction)override; bool dispatchTouchEvent(MotionEvent& event)override; bool onInterceptTouchEvent(MotionEvent& evt); - virtual void onDrawFocusRect(Canvas&,const RECT&); void jumpDrawablesToCurrentState()override; void setAddStatesFromChildren(bool addsStates); diff --git a/src/gui/widget/viewpager.cc b/src/gui/widget/viewpager.cc index 94885bdb..bef2c94d 100755 --- a/src/gui/widget/viewpager.cc +++ b/src/gui/widget/viewpager.cc @@ -1144,7 +1144,9 @@ void ViewPager::completeScroll(bool postEvents){ } } if (needPopulate) { - if (postEvents) postOnAnimation([this](){setScrollState(SCROLL_STATE_IDLE);populate();});//mEndScrollRunnable); + Runnable r; + r=[this](){setScrollState(SCROLL_STATE_IDLE);populate();}; + if (postEvents) postOnAnimation(r);//mEndScrollRunnable); else { setScrollState(SCROLL_STATE_IDLE); populate(); diff --git a/src/gui/widget/viewpager.h b/src/gui/widget/viewpager.h index 7bcbc056..2f92ded0 100755 --- a/src/gui/widget/viewpager.h +++ b/src/gui/widget/viewpager.h @@ -10,7 +10,6 @@ #include #include #include -#include #include #include namespace cdroid{ @@ -121,7 +120,7 @@ private: /** * Determines speed during touch scrolling */ - VelocityTracker* mVelocityTracker; + class VelocityTracker* mVelocityTracker; int mMinimumVelocity; int mMaximumVelocity; int mFlingDistance; diff --git a/src/gui/widget/window.cc b/src/gui/widget/window.cc index 0d7152a6..bd2fc4c3 100755 --- a/src/gui/widget/window.cc +++ b/src/gui/widget/window.cc @@ -269,10 +269,12 @@ bool Window::performFocusNavigation(KeyEvent& event){ } bool Window::onKeyDown(int keyCode,KeyEvent& evt){ + Runnable run; switch(keyCode){ case KEY_ESCAPE: LOGD("recv %d %s",keyCode,evt.getLabel()); - sendMessage((DWORD)WM_DESTROY,0,0,0); + run=[this](){WindowManager::getInstance().removeWindow(this);}; + post(run); return true; default: //return performFocusNavigation(evt); @@ -282,15 +284,12 @@ bool Window::onKeyDown(int keyCode,KeyEvent& evt){ return false; } -void Window::sendMessage(View*v,DWORD msgid,DWORD wParam,ULONG lParam,DWORD delayedtime){ - if(source)source->sendMessage(v,msgid,wParam,lParam,delayedtime); + +void Window::postDelayed(Runnable& what,uint32_t delay){ + if(source)source->post(what,delay); } -void Window::post(View*v,const Runnable what,DWORD delay){ - if(source)source->post(v,what,delay); -} - -void Window::removeCallbacks(const Runnable what){ +void Window::removeCallbacks(const Runnable& what){ if(source)source->removeCallbacks(what); } @@ -329,7 +328,7 @@ void Window::broadcast(DWORD msgid,DWORD wParam,ULONG lParam){ } void Window::close(){ - sendMessage(View::WM_DESTROY,0,0); + //sendMessage(View::WM_DESTROY,0,0); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/gui/widget/window.h b/src/gui/widget/window.h index 36d75f80..b0d9c4f7 100755 --- a/src/gui/widget/window.h +++ b/src/gui/widget/window.h @@ -35,7 +35,6 @@ protected: std::string mText; class UIEventSource*source; void onFinishInflate()override; - virtual void post(View*v,const Runnable what,DWORD delay=0)override; int processInputEvent(InputEvent&event); int processKeyEvent(KeyEvent&event); int processPointerEvent(MotionEvent&event); @@ -68,11 +67,12 @@ public: void invalidate(const RECT*r)override; bool dispatchKeyEvent(KeyEvent&event)override; - virtual void sendMessage(DWORD msgid,DWORD wParam,ULONG lParam,DWORD delayedtime=0){ + /*virtual void sendMessage(DWORD msgid,DWORD wParam,ULONG lParam,DWORD delayedtime=0){ sendMessage(this,msgid,wParam,lParam,delayedtime); } - virtual void sendMessage(View*v,DWORD msgid,DWORD wParam,ULONG lParam,DWORD delayedtime=0)override; - virtual void removeCallbacks(const Runnable what)override; + virtual void sendMessage(View*v,DWORD msgid,DWORD wParam,ULONG lParam,DWORD delayedtime=0)override;*/ + void postDelayed(Runnable& what,uint32_t delay)override; + void removeCallbacks(const Runnable& what)override; void requestLayout()override; static void broadcast(DWORD msgid,DWORD wParam,ULONG lParam); void close(); diff --git a/src/gui/windows.h b/src/gui/windows.h index 386e3475..ad1db439 100755 --- a/src/gui/windows.h +++ b/src/gui/windows.h @@ -32,7 +32,7 @@ #include #include #include -#include -#include +#include +#include #include using namespace cdroid; diff --git a/src/porting/ali3528/ngl_mediaplayer.c b/src/porting/ali3528/ngl_mediaplayer.c old mode 100644 new mode 100755 index e5a03816..841d5424 --- a/src/porting/ali3528/ngl_mediaplayer.c +++ b/src/porting/ali3528/ngl_mediaplayer.c @@ -15,7 +15,7 @@ typedef struct{ void *userdata; }NGL_PLAYER; static void MPCallbackFunc( enum aui_mp_message msg, void *data, void *user_data ); - +#if 0 HANDLE nglMPOpen(const char*fname){ aui_hdl hdl; NGL_PLAYER *mp=(NGL_PLAYER*)malloc(sizeof(NGL_PLAYER)); @@ -36,46 +36,46 @@ HANDLE nglMPOpen(const char*fname){ mp->attr.start_time = 0; int rc=aui_mp_open(&mp->attr,&mp->hplayer); - NGLOGD("mp_open=%d hdl=%p uri=%s",rc,hdl,mp->attr.uc_file_name); + LOGD("mp_open=%d hdl=%p uri=%s",rc,hdl,mp->attr.uc_file_name); return mp; } DWORD nglMPPlay(HANDLE handle){ NGL_PLAYER*mp=(NGL_PLAYER*)handle; - NGLOGD("hdl=%p",mp); + LOGD("hdl=%p",mp); int rc=aui_mp_set_buffering_time(mp->hplayer,10,5,30); - NGLOGD("_mp_set_buffering_time=%d hdl=%p",rc,mp); + LOGD("_mp_set_buffering_time=%d hdl=%p",rc,mp); rc=aui_mp_set_start2play_percent(mp->hplayer,3); - NGLOGD("mp_set_start2play_percent=%d hdl=%p",rc,mp); + LOGD("mp_set_start2play_percent=%d hdl=%p",rc,mp); rc=aui_mp_start(mp->hplayer); - NGLOGD("mp_start=%d hdl=%p",rc,mp); + LOGD("mp_start=%d hdl=%p",rc,mp); return E_OK; } DWORD nglMPStop(HANDLE handle){ NGL_PLAYER*mp=(NGL_PLAYER*)handle; int rc=aui_mp_stop(mp->hplayer); - NGLOGD("rc=%d hdl=%p",rc,mp); + LOGD("rc=%d hdl=%p",rc,mp); return E_OK; } DWORD nglMPResume(HANDLE handle){ NGL_PLAYER*mp=(NGL_PLAYER*)handle; int rc=aui_mp_resume(mp->hplayer); - NGLOGD("rc=%d hdl=%p",rc,mp); + LOGD("rc=%d hdl=%p",rc,mp); return E_OK; } DWORD nglMPPause(HANDLE handle){ NGL_PLAYER*mp=(NGL_PLAYER*)handle; int rc=aui_mp_pause(mp->hplayer); - NGLOGD("rc=%d hdl=%p",rc,mp); + LOGD("rc=%d hdl=%p",rc,mp); return E_OK; } DWORD nglMPClose(HANDLE handle){ NGL_PLAYER*mp=(NGL_PLAYER*)handle; int rc=aui_mp_close(&mp->attr,&mp->hplayer); - NGLOGD("rc=%d hdl=%p",rc,mp); + LOGD("rc=%d hdl=%p",rc,mp); free(mp); return E_OK; } @@ -88,7 +88,7 @@ DWORD nglMPGetTime(HANDLE handle,UINT*curtime,UINT*timems){ rc=aui_mp_total_time_get(hdl,&t2); if(curtime)*curtime=t1; if(timems)*timems=t2; - NGLOGD("rc=%d hdl=%p times=%d/%d",rc,hdl,t1,t2); + LOGD("rc=%d hdl=%p times=%d/%d",rc,hdl,t1,t2); return E_OK; } DWORD nglMPSeek(HANDLE handle,UINT timems){ @@ -101,75 +101,87 @@ DWORD nglMPSetCallback(HANDLE handle,MP_CALLBACK cbk,void*userdata){ mp->cbk=cbk; mp->userdata=userdata; } +#else +HANDLE nglMPOpen(const char*fname){} +DWORD nglMPPlay(HANDLE handle){} +DWORD nglMPStop(HANDLE handle){} +DWORD nglMPResume(HANDLE handle){} +DWORD nglMPPause(HANDLE handle){} +DWORD nglMPClose(HANDLE handle){} +DWORD nglMPSeek(HANDLE handle,UINT timems){} +DWORD nglMPGetTime(HANDLE handle,UINT*curtime,UINT*timems){} +DWORD nglMPSetCallback(HANDLE handle,MP_CALLBACK cbk,void*userdata){} + +#endif static void MPCallbackFunc( enum aui_mp_message msg, void *data, void *user_data ) { NGL_PLAYER*mp=(NGL_PLAYER*)user_data; #define MPCBK(msg,param) if(mp->cbk)mp->cbk(mp,msg,param,mp->userdata) - NGLOGD("callback msg:"); + LOGD("callback msg:"); switch ( msg ) { case AUI_MP_PLAY_BEGIN: { - NGLOGD("AUI_MP_PLAY_BEGIN"); + LOGD("AUI_MP_PLAY_BEGIN"); break; } case AUI_MP_PLAY_END: { MPCBK(MP_END,0); - NGLOGD( "AUI_MP_PLAY_END userdata=%p",user_data); + LOGD( "AUI_MP_PLAY_END userdata=%p",user_data); break; } case AUI_MP_VIDEO_CODEC_NOT_SUPPORT: { MPCBK(MP_ERROR,0); - NGLOGD("AUI_MP_VIDEO_CODEC_NOT_SUPPORT"); + LOGD("AUI_MP_VIDEO_CODEC_NOT_SUPPORT"); break; } case AUI_MP_AUDIO_CODEC_NOT_SUPPORT: { MPCBK(MP_ERROR,0); - NGLOGD("AUI_MP_AUDIO_CODEC_NOT_SUPPORT"); + LOGD("AUI_MP_AUDIO_CODEC_NOT_SUPPORT"); break; } case AUI_MP_RESOLUTION_NOT_SUPPORT: { MPCBK(MP_ERROR,0); - NGLOGD("AUI_MP_RESOLUTION_NOT_SUPPORT"); + LOGD("AUI_MP_RESOLUTION_NOT_SUPPORT"); break; } case AUI_MP_FRAMERATE_NOT_SUPPORT: { MPCBK(MP_ERROR,0); - NGLOGD("AUI_MP_FRAMERATE_NOT_SUPPORT"); + LOGD("AUI_MP_FRAMERATE_NOT_SUPPORT"); break; } case AUI_MP_NO_MEMORY: { MPCBK(MP_ERROR,0); - NGLOGD("AUI_MP_NO_MEMORY"); + LOGD("AUI_MP_NO_MEMORY"); break; } case AUI_MP_DECODE_ERROR: { MPCBK(MP_ERROR,0); - NGLOGD("AUI_MP_DECODE_ERROR"); + LOGD("AUI_MP_DECODE_ERROR"); break; } case AUI_MP_ERROR_UNKNOWN: { MPCBK(MP_ERROR,0); - NGLOGD("AUI_MP_ERROR_UNKNOWN%s", ( char * )data ); + LOGD("AUI_MP_ERROR_UNKNOWN%s", ( char * )data ); break; } case AUI_MP_BUFFERING: { - NGLOGD("AUI_MP_BUFFERING"); + LOGD("AUI_MP_BUFFERING"); break; } case AUI_MP_ERROR_SOUPHTTP: { - NGLOGD("AUI_MP_ERROR_SOUPHTTP"); + LOGD("AUI_MP_ERROR_SOUPHTTP"); break; } case AUI_MP_FRAME_CAPTURE: { char path[128], frameInfo[128]; unsigned int h, w; sscanf( ( char * )data, "%[^;];h=%u,w=%u", path, &h, &w ); - NGLOGD("frame captured path %s", path ); - NGLOGD("frame width=%u, height=%u", w, h ); - NGLOGD("AUI_MP_FRAME_CAPTURE" ); + LOGD("frame captured path %s", path ); + LOGD("frame width=%u, height=%u", w, h ); + LOGD("AUI_MP_FRAME_CAPTURE" ); break; } default: - NGLOGD("unkown callback message:%d", msg ); + LOGD("unkown callback message:%d", msg ); break; } } diff --git a/src/porting/x86/CMakeLists.txt b/src/porting/x86/CMakeLists.txt index a4c46a5a..5ce0a6e9 100755 --- a/src/porting/x86/CMakeLists.txt +++ b/src/porting/x86/CMakeLists.txt @@ -42,6 +42,7 @@ list(APPEND X86LIBS pthread) include_directories(./ ../include + ${CMAKE_SOURCE_DIR}/src/gui/ ${CMAKE_SOURCE_DIR}/src/gui/core ${X11_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} diff --git a/tests/gui/app_tests.cc b/tests/gui/app_tests.cc old mode 100644 new mode 100755 index 74d99a0d..ad55175f --- a/tests/gui/app_tests.cc +++ b/tests/gui/app_tests.cc @@ -1,6 +1,5 @@ #include #include -#include #include using namespace cdroid; @@ -17,20 +16,12 @@ class APP:public testing::Test{ TEST_F(APP,EmptyArgs){ App app(0,NULL); - app.addEventSource(new TimerFD(800,true),[&](EventSource&s)->bool{ - app.exit(); - return false; - }); app.exec(); } TEST_F(APP,TwoArgs){ const char*args[]={"arg1","--alpha=255"}; App app(2,args); - app.addEventSource(new TimerFD(800,true),[&](EventSource&s)->bool{ - app.exit(); - return false; - }); app.exec(); } TEST_F(APP,exec){ @@ -44,9 +35,5 @@ TEST_F(APP,add){ w->addView(new TextView("",100,20)); w->addView(new TextView("",100,20)); ASSERT_EQ(2,w->getChildCount()); - app.addEventSource(new TimerFD(5000,true),[&](EventSource&s)->bool{ - app.exit(); - return false; - }); app.exec(); } diff --git a/tests/gui/benchmark_tests.cc b/tests/gui/benchmark_tests.cc index 592a9696..c5c14333 100755 --- a/tests/gui/benchmark_tests.cc +++ b/tests/gui/benchmark_tests.cc @@ -1,6 +1,6 @@ #include #include -#include +#include #include using namespace cdroid; diff --git a/tests/gui/calendar_tests.cc b/tests/gui/calendar_tests.cc old mode 100644 new mode 100755 index e1a24434..8c4d1866 --- a/tests/gui/calendar_tests.cc +++ b/tests/gui/calendar_tests.cc @@ -2,8 +2,7 @@ #include #include #include -#include -#include +#include class CALENDAR:public testing::Test{ diff --git a/tests/gui/drawable_tests.cc b/tests/gui/drawable_tests.cc index d9aa78a2..55cf0cd2 100755 --- a/tests/gui/drawable_tests.cc +++ b/tests/gui/drawable_tests.cc @@ -1,12 +1,10 @@ #include #include -#include -#include #include #include #include #include -#include +#include #define SLEEP(x) usleep((x)*1000) class DRAWABLE:public testing::Test{ public: diff --git a/tests/gui/drawablemutate_tests.cc b/tests/gui/drawablemutate_tests.cc old mode 100644 new mode 100755 index 64f2f4de..06bfcb42 --- a/tests/gui/drawablemutate_tests.cc +++ b/tests/gui/drawablemutate_tests.cc @@ -1,14 +1,14 @@ #include #include -#include -#include +#include +#include #include #include #include #include #include #include -#include +#include class MUTATE:public testing::Test{ public: diff --git a/tests/gui/image_unittests.cc b/tests/gui/image_unittests.cc index 2b52328a..937d1924 100755 --- a/tests/gui/image_unittests.cc +++ b/tests/gui/image_unittests.cc @@ -1,10 +1,10 @@ #include #include #include -#include -#include +#include +#include #include -#include +#include #include #include #include diff --git a/tests/gui/looper_tests.cc b/tests/gui/looper_tests.cc new file mode 100755 index 00000000..ee954521 --- /dev/null +++ b/tests/gui/looper_tests.cc @@ -0,0 +1,100 @@ +#include +#include +#include +#include +#include +#include +#include +class LOOPER:public testing::Test{ + + public : + virtual void SetUp(){ + } + virtual void TearDown(){ + printf("\r\n\r\n"); + } +}; + +class MyRunner{ +public: + int key; + std::functionrun; + //MyRunner(){} + //MyRunner(const std::function&a){} + void operator=(const std::function&a){ + run=a; + } + void test(int i){ + printf("i=%d\r\n",i); + } +}; +TEST_F(LOOPER,function){ + MyRunner r;//=std::bind(&MyRunner::test,&r,100); + r=std::bind(&MyRunner::test,&r,100); + r.run(); +} + +class TestHandler:public MessageHandler{ + int count; +public: + TestHandler(){count=0;} + void handleMessage(const Message&msg)override{ + count++; + } + int getCount()const{return count;} +}; + +TEST_F(LOOPER,pollonce){ + Looper loop(false); + int64_t t1=SystemClock::uptimeMillis(); + loop.pollOnce(1000); + int64_t t2=SystemClock::uptimeMillis(); + ASSERT_TRUE((t2-t1)>=1000&&(t2-t2)<1005); +} + +TEST_F(LOOPER,sendMessage){ + Looper loop(false); + Message msg(100); + int processed=0; + TestHandler ft; + loop.sendMessage(&ft,msg); + loop.pollOnce(10); + ASSERT_EQ(ft.getCount(),1); +} + +TEST_F(LOOPER,sendMessageDelay){ + Looper loop(false); + Message msg(100); + TestHandler ft; + int64_t t1=SystemClock::uptimeMillis(); + loop.sendMessageDelayed(1000,&ft,msg); + while(!ft.getCount()) loop.pollOnce(10); + int64_t t2=SystemClock::uptimeMillis(); + ASSERT_TRUE((t2-t1)>=1000&&(t2-t2)<1005); +} + +TEST_F(LOOPER,removeMessage){ + Looper loop(false); + Message msg(100),msg2(200); + TestHandler ft; + int64_t t2,t1=SystemClock::uptimeMillis(); + loop.sendMessageDelayed(1000,&ft,msg); + loop.sendMessageDelayed(1000,&ft,msg2); + t2=t1; + loop.removeMessages(&ft,100); + while(t2-t1<1100){ + loop.pollOnce(10); + t2=SystemClock::uptimeMillis(); + } + ASSERT_EQ(ft.getCount(),1); +} + +TEST_F(LOOPER,eventhandler){ + +} +TEST_F(LOOPER,loop){ + Looper loop(false); + loop.pollAll(1000); + loop.pollAll(1000); + loop.pollAll(1000); +} diff --git a/tests/gui/motion_tests.cc b/tests/gui/motion_tests.cc old mode 100644 new mode 100755 index 1656d061..c535288c --- a/tests/gui/motion_tests.cc +++ b/tests/gui/motion_tests.cc @@ -2,7 +2,7 @@ #include #include #include -#include +#include class EVENT:public testing::Test{ diff --git a/tests/gui/preference_tests.cc b/tests/gui/preference_tests.cc old mode 100644 new mode 100755 index 62d7d836..ba299664 --- a/tests/gui/preference_tests.cc +++ b/tests/gui/preference_tests.cc @@ -4,7 +4,7 @@ #include #include #include -#include +#include using namespace cdroid; diff --git a/tests/gui/rect_tests.cc b/tests/gui/rect_tests.cc old mode 100644 new mode 100755 index ce53dbec..2a9b836f --- a/tests/gui/rect_tests.cc +++ b/tests/gui/rect_tests.cc @@ -1,6 +1,5 @@ #include #include -#include #include using namespace cdroid; diff --git a/tests/gui/scheduler_tests.cc b/tests/gui/scheduler_tests.cc old mode 100644 new mode 100755 index 29e235e6..f0144a65 --- a/tests/gui/scheduler_tests.cc +++ b/tests/gui/scheduler_tests.cc @@ -1,7 +1,7 @@ #include #include #include -#include +#include class SCHEDULER:public testing::Test{ @@ -32,8 +32,8 @@ TEST_F(SCHEDULER,Once){ sch.schedule([&count](){count++;},system_clock::now()+std::chrono::seconds(10)); sch.schedule(std::bind(&SubscribeItem::onTriggered,&itm),system_clock::now()+std::chrono::seconds(10)); sleep(10); - sch.check(); - sch.check(); + //sch.check(); + //sch.check(); ASSERT_EQ(count,1); } @@ -42,7 +42,7 @@ TEST_F(SCHEDULER,FromNow){ int count=0; sch.scheduleFromNow([&count](){count++;},10); sleep(10); - sch.check(); + //sch.check(); ASSERT_EQ(count,1); } @@ -56,7 +56,7 @@ TEST_F(SCHEDULER,Every){ sch.scheduleEvery(std::bind(&SubscribeItem::onTriggered,&itm),5); for(int i=0;i<20;i++){ sleep(1); - sch.check(); + //sch.check(); } ASSERT_EQ(count,4); } @@ -66,7 +66,7 @@ TEST_F(SCHEDULER,Hourly){ int count=0; sch.scheduleHourly([&count](){count++;},system_clock::now()); sleep(10); - sch.check(); + //sch.check(); ASSERT_EQ(count,0); } @@ -75,7 +75,7 @@ TEST_F(SCHEDULER,Hourly1){ int count=0; sch.scheduleHourly([&count](){count++;},system_clock::now()); sleep(3600); - sch.check(); + //sch.check(); ASSERT_EQ(count,1); } @@ -84,7 +84,7 @@ TEST_F(SCHEDULER,Daily){ int count=0; sch.scheduleDaily([&count](){count++;},system_clock::now()); sleep(10); - sch.check(); + //sch.check(); ASSERT_EQ(count,0); } @@ -93,7 +93,7 @@ TEST_F(SCHEDULER,Weekly){ int count=0; sch.scheduleWeekly([&count](){count++;},system_clock::now()); sleep(10); - sch.check(); + //sch.check(); ASSERT_EQ(count,0); } diff --git a/tests/gui/surface_unittests.cc b/tests/gui/surface_unittests.cc index dda4fdf2..335dc426 100755 --- a/tests/gui/surface_unittests.cc +++ b/tests/gui/surface_unittests.cc @@ -1,12 +1,12 @@ #include #include #include -#include +#include #include -#include +#include #include #include -#include +#include #include #include #include diff --git a/tests/gui/textlayout_tests.cc b/tests/gui/textlayout_tests.cc index d1b775cb..c0f92a1d 100755 --- a/tests/gui/textlayout_tests.cc +++ b/tests/gui/textlayout_tests.cc @@ -1,6 +1,5 @@ #include #include -#include #include using namespace cdroid; diff --git a/tests/gui/widget_tests.cc b/tests/gui/widget_tests.cc index 91a8b451..8b9ee10a 100755 --- a/tests/gui/widget_tests.cc +++ b/tests/gui/widget_tests.cc @@ -131,17 +131,16 @@ TEST_F(WIDGET,ProgressBar){ pb->setIndeterminate(true); w->addView(ll); - w->sendMessage(View::WM_TIMER,0,0,500); - w->setMessageListener([&](View&v,DWORD msg,DWORD wp,ULONG lp)->bool{ - if(msg==View::WM_TIMER){ - ((ProgressBar*)v.findViewById(100))->setProgress(pos); - ((ProgressBar*)v.findViewById(101))->setProgress(pos); - ((ProgressBar*)v.findViewById(102))->setProgress(pos); - pos=(pos+1)%100; - v.sendMessage(View::WM_TIMER,0,0,100);printf("=========ProgressBar::timer\r\n"); - return true; - } - }); + //w->sendMessage(View::WM_TIMER,0,0,500); + Runnable run; + run=[&](){ + ((ProgressBar*)w->findViewById(100))->setProgress(pos); + ((ProgressBar*)w->findViewById(101))->setProgress(pos); + ((ProgressBar*)w->findViewById(102))->setProgress(pos); + pos=(pos+1)%100; + w->postDelayed(run,500); + }; + w->postDelayed(run,500); app.exec(); } diff --git a/tests/gui/window_tests.cc b/tests/gui/window_tests.cc index 5feb44eb..78b2d23b 100755 --- a/tests/gui/window_tests.cc +++ b/tests/gui/window_tests.cc @@ -1,7 +1,6 @@ #include #include #include -#include #include static const char*texts[]={"Creates 中国智造"," the specified format and dimensions.", "Initially the surface contents"," are set to 0.","(Specifically, within each pixel,", @@ -21,7 +20,7 @@ public: TestWindow(int x,int y,int w,int h):Window(x,y,w,h){} virtual bool onKeyRelease(KeyEvent& evt){ App::getInstance().exit(0); - sendMessage(View::WM_DESTROY,0,0); + //sendMessage(View::WM_DESTROY,0,0); return true; } }; @@ -110,13 +109,13 @@ TEST_F(WINDOW,showhide){ w[i]=new Window(80*i,50*i,480,320); w[i]->setBackgroundColor(cls[i]); } - TimerFD *tfd=new TimerFD(50,false); + /*TimerFD *tfd=new TimerFD(50,false); app.addEventSource(tfd,[&](EventSource&s)->bool{ w[index]->show(); index=(index+1)%wc; w[index]->hide(); return true; - }); + });*/ app.exec(); } TEST_F(WINDOW,multilayer){ @@ -175,7 +174,7 @@ private: int dx,dy; public: MWindow(int x,int y,int w,int h):TestWindow(x,y,w,h){dx=dy=50;} - virtual bool onMessage(DWORD msgid,DWORD wp,ULONG lp){ + /*virtual bool onMessage(DWORD msgid,DWORD wp,ULONG lp){ if(View::WM_TIMER==msgid){ sendMessage(msgid,wp,lp,lp); int x=getX(); @@ -188,7 +187,7 @@ public: return true; } return false; - } + }*/ void setDir(int x,int y){dx=x;dy=y;} }; @@ -199,9 +198,9 @@ TEST_F(WINDOW,multiwindow){ MWindow*w2=new MWindow(300,200,420,300); w1->setBackgroundColor(0xFFFF0000); w2->setBackgroundColor(0xFF00FF00); - w1->sendMessage(View::WM_TIMER,0,100,100);w1->setDir(50,40); - w2->sendMessage(View::WM_TIMER,0,100,80);w2->setDir(66,53); - w3->sendMessage(View::WM_TIMER,0,100,85);w3->setDir(69,57); + //w1->sendMessage(View::WM_TIMER,0,100,100);w1->setDir(50,40); + //w2->sendMessage(View::WM_TIMER,0,100,80);w2->setDir(66,53); + //w3->sendMessage(View::WM_TIMER,0,100,85);w3->setDir(69,57); app.exec(); } @@ -240,12 +239,12 @@ TEST_F(WINDOW,TOAST_MAKEWINDOW){ for(int i=0;isetPos(i*50,i*50); } - TimerFD *tfd=new TimerFD(800,false); + /*TimerFD *tfd=new TimerFD(800,false); app.addEventSource(tfd,[&](EventSource&s)->bool{ createCustomToast(texts[index],300,80,1000-index*100)->setPos(index*50,index*50); index=(index+1)%cnt; return true; - }); + });*/ app.exec(); } @@ -283,12 +282,12 @@ public: TEST_F(WINDOW,TOAST_SINGLE){ App app; int index=0; - TimerFD *tfd=new TimerFD(800,false); + /*TimerFD *tfd=new TimerFD(800,false); app.addEventSource(tfd,[&](EventSource&s)->bool{ if(index%2)PopWindow::getInstance()->hide(); else PopWindow::getInstance()->pop(); index++; return true; - }); + });*/ app.exec(); } diff --git a/tests/porting/input_unittests.cc b/tests/porting/input_unittests.cc index 93ea3355..d36c6e61 100755 --- a/tests/porting/input_unittests.cc +++ b/tests/porting/input_unittests.cc @@ -2,7 +2,7 @@ #include #include #include -#include +#include class INPUT:public testing::Test{ public : virtual void SetUp(){