privatevoidscheduleFrameLocked(long now){ if (!mFrameScheduled) { mFrameScheduled = true; if (USE_VSYNC) { // If running on the Looper thread, then schedule the vsync immediately, // otherwise post a message to schedule the vsync from the UI thread // as soon as possible. //翻译:如果在主线程(Looper)就立即计划(schedule)一个vsync,否则快马加鞭传信给主线程, //让主线程 马上(as soon as possible) 计划(schedule)一个vsync。 if (isRunningOnLooperThreadLocked()) { scheduleVsyncLocked(); } else { Message msg = mHandler.obtainMessage(MSG_DO_SCHEDULE_VSYNC);//1 msg.setAsynchronous(true); mHandler.sendMessageAtFrontOfQueue(msg); } } else { finallong nextFrameTime = Math.max( mLastFrameTimeNanos / TimeUtils.NANOS_PER_MS + sFrameDelay, now); Message msg = mHandler.obtainMessage(MSG_DO_FRAME);//0 msg.setAsynchronous(true); mHandler.sendMessageAtTime(msg, nextFrameTime); } } }
/** * Schedules a single vertical sync pulse to be delivered when the next * display frame begins. * 计划一个VSync脉冲,用于下一帧到来时的交付。 * 说人话:注册一个监听器,用于监听下一帧的VSync信号 */ @UnsupportedAppUsage publicvoidscheduleVsync(){ if (mReceiverPtr == 0) { Log.w(TAG, "Attempted to schedule a vertical sync pulse but the display event " + "receiver has already been disposed."); } else { nativeScheduleVsync(mReceiverPtr); } }