mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-11-30 03:08:12 +08:00
modify View::postOnAnimationDelayed
This commit is contained in:
parent
b9485829d9
commit
de7a494c9b
@ -51,7 +51,7 @@ void Looper::Looper::Request::initEventItem(struct epoll_event* eventItem) const
|
||||
|
||||
memset(eventItem, 0, sizeof(epoll_event)); // zero out unused members of data field union
|
||||
eventItem->events = epollEvents;
|
||||
eventItem->data.fd = fd;
|
||||
eventItem->data.fd= fd;
|
||||
}
|
||||
|
||||
Looper::Looper(bool allowNonCallbacks) :
|
||||
@ -76,7 +76,7 @@ Looper::~Looper() {
|
||||
}
|
||||
|
||||
void Looper::initTLSKey() {
|
||||
int error = pthread_key_create(&gTLSKey, threadDestructor);
|
||||
const int error = pthread_key_create(&gTLSKey, threadDestructor);
|
||||
LOGE_IF(error != 0, "Could not allocate TLS key: %s", strerror(error));
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ private:
|
||||
|
||||
bool mAllowNonCallbacks; // immutable
|
||||
|
||||
int mWakeEventFd; // immutable
|
||||
int mWakeEventFd; // immutable
|
||||
std::recursive_mutex mLock;
|
||||
|
||||
std::list<MessageEnvelope> mMessageEnvelopes; // guarded by mLock
|
||||
@ -115,7 +115,7 @@ private:
|
||||
// any use of it is racy anyway.
|
||||
bool mPolling;
|
||||
|
||||
int mEpollFd; // guarded by mLock but only modified on the looper thread
|
||||
int mEpollFd; // guarded by mLock but only modified on the looper thread
|
||||
bool mEpollRebuildRequired; // guarded by mLock
|
||||
|
||||
// Locked list of file descriptor monitoring requests.
|
||||
@ -168,18 +168,18 @@ public:
|
||||
static void setForThread(Looper* looper);
|
||||
static Looper* getForThread();
|
||||
bool getAllowNonCallbacks() const;
|
||||
int pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outData);
|
||||
int pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outData);
|
||||
inline int pollOnce(int timeoutMillis) {
|
||||
return pollOnce(timeoutMillis, NULL, NULL, NULL);
|
||||
}
|
||||
int pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData);
|
||||
int pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData);
|
||||
inline int pollAll(int timeoutMillis) {
|
||||
return pollAll(timeoutMillis, NULL, NULL, NULL);
|
||||
}
|
||||
void wake();
|
||||
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);
|
||||
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(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);
|
||||
|
@ -7,7 +7,7 @@ namespace cdroid{
|
||||
#define FRAME_CALLBACK_TOKEN 1
|
||||
|
||||
long Choreographer::sFrameDelay = DEFAULT_FRAME_DELAY;
|
||||
|
||||
#define USE_FRAME_TIME 1
|
||||
Choreographer::Choreographer(){
|
||||
mLooper = nullptr;
|
||||
mFrameScheduled = false;
|
||||
@ -49,7 +49,7 @@ void Choreographer::setFrameDelay(long frameDelay){
|
||||
}
|
||||
|
||||
long Choreographer::getFrameTime()const{
|
||||
return SystemClock::uptimeMillis();
|
||||
return getFrameTimeNanos()/SystemClock::NANOS_PER_MS;
|
||||
}
|
||||
|
||||
long Choreographer::subtractFrameDelay(long delayMillis) {
|
||||
@ -58,11 +58,11 @@ long Choreographer::subtractFrameDelay(long delayMillis) {
|
||||
}
|
||||
|
||||
long Choreographer::getFrameTimeNanos()const{
|
||||
return SystemClock::uptimeMillis();
|
||||
return USE_FRAME_TIME ? mLastFrameTimeNanos:SystemClock::uptimeNanos();
|
||||
}
|
||||
|
||||
long Choreographer::getLastFrameTimeNanos()const{
|
||||
return mLastFrameTimeNanos;
|
||||
return USE_FRAME_TIME ? mLastFrameTimeNanos:SystemClock::uptimeNanos();
|
||||
}
|
||||
|
||||
long Choreographer::getFrameIntervalNanos()const{
|
||||
@ -108,7 +108,7 @@ void Choreographer::postCallbackDelayedInternal(int callbackType,void* action, v
|
||||
msg.arg1 = callbackType;
|
||||
msg.setAsynchronous(true);
|
||||
mHandler.sendMessageAtTime(msg, dueTime);
|
||||
}*/
|
||||
}*/
|
||||
}
|
||||
|
||||
void Choreographer::removeCallbacks(int callbackType,const Runnable* action, void* token){
|
||||
@ -144,7 +144,7 @@ void Choreographer::postFrameCallbackDelayed(const FrameCallback& callback, long
|
||||
void Choreographer::scheduleFrameLocked(long now){
|
||||
if (!mFrameScheduled) {
|
||||
mFrameScheduled = true;
|
||||
long nextFrameTime = std::max(mLastFrameTimeNanos /*/ TimeUtils.NANOS_PER_MS*/ + DEFAULT_FRAME_DELAY, now);
|
||||
nsecs_t nextFrameTime = std::max(mLastFrameTimeNanos /SystemClock::NANOS_PER_MS + sFrameDelay, nsecs_t(now));
|
||||
LOG(DEBUG)<<"Scheduling next frame in " << (nextFrameTime - now) << " ms.";
|
||||
//Message msg = mHandler.obtainMessage(MSG_DO_FRAME);
|
||||
//msg.setAsynchronous(true);
|
||||
@ -186,7 +186,7 @@ void Choreographer::doCallbacks(int callbackType, long frameTimeNanos){
|
||||
// for earlier processing phases in a frame to post callbacks that should run
|
||||
// in a following phase, such as an input event that causes an animation to start.
|
||||
const nsecs_t now = SystemClock::uptimeNanos();
|
||||
callbacks = mCallbackQueues[callbackType]->extractDueCallbacksLocked(now/1000000);
|
||||
callbacks = mCallbackQueues[callbackType]->extractDueCallbacksLocked(now/SystemClock::NANOS_PER_MS);
|
||||
if (callbacks == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
@ -6513,11 +6513,27 @@ bool View::onTouchEvent(MotionEvent& event){
|
||||
}
|
||||
|
||||
void View::postOnAnimation(Runnable& action){
|
||||
#if !NEW_POST_DELAYED
|
||||
postDelayed(action,0);
|
||||
#else
|
||||
if(mAttachInfo){
|
||||
Choreographer::getInstance().postCallback(Choreographer::CALLBACK_ANIMATION,action,nullptr);
|
||||
}else{
|
||||
getRunQueue()->post(action);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void View::postOnAnimationDelayed(Runnable& action, long delayMillis){
|
||||
#if !NEW_POST_DELAYED
|
||||
postDelayed(action,delayMillis);
|
||||
#else
|
||||
if(mAttachInfo){
|
||||
Choreographer::getInstance().postCallbackDelayed(Choreographer::CALLBACK_ANIMATION,action,nullptr,delayMillis);
|
||||
}else{
|
||||
getRunQueue()->postDelayed(action,delayMillis);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
HandlerActionQueue* View::getRunQueue() {
|
||||
@ -6532,10 +6548,14 @@ bool View::post(Runnable& what){
|
||||
}
|
||||
|
||||
bool View::postDelayed(Runnable& what,long delay){
|
||||
//View*root = getRootView();
|
||||
//if(root&&(root!=this)) return root->postDelayed(what,delay);
|
||||
LOGD("%p root=%p post %p delay=%lld",this,getRootView(),&what,delay);
|
||||
#if !NEW_POST_DELAYED
|
||||
View*root = getRootView();
|
||||
if(root&&(root!=this)) return root->postDelayed(what,delay);
|
||||
#else
|
||||
if(mAttachInfo)mAttachInfo->mEventSource->postDelayed(what,delay);
|
||||
else getRunQueue()->postDelayed(what,delay);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -6550,10 +6570,14 @@ bool View::postDelayed(const std::function<void()>&what,long delay){
|
||||
}
|
||||
|
||||
bool View::removeCallbacks(const Runnable& what){
|
||||
//View*root = getRootView();
|
||||
//if( root && (root!=this) ) return root->removeCallbacks(what);
|
||||
LOGD("%p root=%p remove %p",this,getRootView(),&what);
|
||||
#if !NEW_POST_DELAYED
|
||||
View*root = getRootView();
|
||||
if( root && (root!=this) ) return root->removeCallbacks(what);
|
||||
#else
|
||||
if(mAttachInfo)mAttachInfo->mEventSource->removeCallbacks(what);
|
||||
else getRunQueue()->removeCallbacks(what);
|
||||
getRunQueue()->removeCallbacks(what);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@
|
||||
#else
|
||||
#define DECLARE_UIEVENT(type,name,...) typedef std::function< type(__VA_ARGS__) >name
|
||||
#endif
|
||||
|
||||
#define NEW_POST_DELAYED 0
|
||||
namespace cdroid{
|
||||
|
||||
class ViewGroup;
|
||||
|
@ -465,8 +465,9 @@ void Window::onBackPressed(){
|
||||
LOGD("recv BackPressed");
|
||||
post([this](){WindowManager::getInstance().removeWindow(this);} );
|
||||
}
|
||||
|
||||
/*bool Window::postDelayed(Runnable& what,long delay){
|
||||
#if !NEW_POST_DELAYED
|
||||
bool Window::postDelayed(Runnable& what,long delay){
|
||||
LOGD("%p handler=%p post %p delay=%lld",this,mUIEventHandler,&what,delay);
|
||||
return mUIEventHandler && mUIEventHandler->postDelayed(what,delay);
|
||||
}
|
||||
|
||||
@ -474,7 +475,8 @@ bool Window::removeCallbacks(const Runnable& what){
|
||||
if(mUIEventHandler)
|
||||
return mUIEventHandler->removeCallbacks((Runnable&)what);
|
||||
return !(mUIEventHandler==nullptr);
|
||||
}*/
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Window::isInLayout()const{
|
||||
return mInLayout;
|
||||
|
@ -109,8 +109,10 @@ public:
|
||||
virtual void onDeactive();
|
||||
bool dispatchKeyEvent(KeyEvent&event)override;
|
||||
bool isInLayout()const override;
|
||||
//bool postDelayed(Runnable& what,long delay)override;
|
||||
//bool removeCallbacks(const Runnable& what)override;
|
||||
#if !NEW_POST_DELAYED
|
||||
bool postDelayed(Runnable& what,long delay)override;
|
||||
bool removeCallbacks(const Runnable& what)override;
|
||||
#endif
|
||||
void dispatchInvalidateOnAnimation(View* view)override;
|
||||
void dispatchInvalidateRectOnAnimation(View*,const Rect&)override;
|
||||
void dispatchInvalidateDelayed(View*, long delayMilliseconds)override;
|
||||
|
Loading…
Reference in New Issue
Block a user