Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Choreographer work

I was just studying about code of Android framework (v4.1).

I know that the UI message triggered by invalidate() now is posted to Choreographer instead of UI messageQueue directly, and these messages will not be executed until next VSYNC signal comes.

Before this post operation is performed, ViewRootImpl calls Looper's postSyncBarrier() once in order to block the UI MessageQueue which means messages that post into messagesQueue later won't be executed until this block is removed, which happens before function performTraversals().

Based on the above understanding,

If another invalidate() is called even once somewhere within performTraversals() (such as onDraw() of any view instances) the UI messageQueue forever be blocked?

From practical observations, I know that this never happens.
So, where am i wrong?

like image 287
Simon Lee Avatar asked Nov 12 '22 22:11

Simon Lee


1 Answers

I think you can get the answer to this question by looking at the code for scheduleTraversals:

void scheduleTraversals() {
    if (!mTraversalScheduled) {
        mTraversalScheduled = true;
        mTraversalBarrier = mHandler.getLooper().postSyncBarrier();
        mChoreographer.postCallback(
                Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null);
        if (!mUnbufferedInputDispatch) {
            scheduleConsumeBatchedInput();
        }
        notifyRendererOfFramePending();
    }
}

After the first call to scheduleTraversals mTraversalScheduled is set true. Subsequent calls have no affect, postSyncBarrier is not be called and no second barrier is put on the queue, until unscheduleTraversals is called.

like image 198
G. Blake Meike Avatar answered Nov 15 '22 02:11

G. Blake Meike