Guest User

Untitled

a guest
Jun 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. void doFrame(long frameTimeNanos, int frame) {
  2. final long startNanos;
  3. synchronized (mLock) {
  4. if (!mFrameScheduled) {
  5. return; // no work to do
  6. }
  7. if (DEBUG_JANK && mDebugPrintNextFrameTimeDelta) {
  8. mDebugPrintNextFrameTimeDelta = false;
  9. Log.d(TAG, "Frame time delta: "
  10. + ((frameTimeNanos - mLastFrameTimeNanos) * 0.000001f) + " ms");
  11. }
  12. long intendedFrameTimeNanos = frameTimeNanos;
  13. startNanos = System.nanoTime();
  14. final long jitterNanos = startNanos - frameTimeNanos;
  15. if (jitterNanos >= mFrameIntervalNanos) {
  16. final long skippedFrames = jitterNanos / mFrameIntervalNanos;
  17. if (skippedFrames >= SKIPPED_FRAME_WARNING_LIMIT) {
  18. Log.i(TAG, "Skipped " + skippedFrames + " frames! "
  19. + "The application may be doing too much work on its main thread.");
  20. }
  21. final long lastFrameOffset = jitterNanos % mFrameIntervalNanos;
  22. if (DEBUG_JANK) {
  23. Log.d(TAG, "Missed vsync by " + (jitterNanos * 0.000001f) + " ms "
  24. + "which is more than the frame interval of "
  25. + (mFrameIntervalNanos * 0.000001f) + " ms! "
  26. + "Skipping " + skippedFrames + " frames and setting frame "
  27. + "time to " + (lastFrameOffset * 0.000001f) + " ms in the past.");
  28. }
  29. frameTimeNanos = startNanos - lastFrameOffset;
  30. }
  31. if (frameTimeNanos < mLastFrameTimeNanos) {
  32. if (DEBUG_JANK) {
  33. Log.d(TAG, "Frame time appears to be going backwards. May be due to a "
  34. + "previously skipped frame. Waiting for next vsync.");
  35. }
  36. scheduleVsyncLocked();
  37. return;
  38. }
  39. mFrameInfo.setVsync(intendedFrameTimeNanos, frameTimeNanos);
  40. mFrameScheduled = false;
  41. mLastFrameTimeNanos = frameTimeNanos;
  42. }
  43. try {
  44. Trace.traceBegin(Trace.TRACE_TAG_VIEW, "Choreographer#doFrame");
  45. AnimationUtils.lockAnimationClock(frameTimeNanos / TimeUtils.NANOS_PER_MS);
  46. mFrameInfo.markInputHandlingStart();
  47. doCallbacks(Choreographer.CALLBACK_INPUT, frameTimeNanos);
  48. mFrameInfo.markAnimationsStart();
  49. doCallbacks(Choreographer.CALLBACK_ANIMATION, frameTimeNanos);
  50. mFrameInfo.markPerformTraversalsStart();
  51. doCallbacks(Choreographer.CALLBACK_TRAVERSAL, frameTimeNanos);
  52. doCallbacks(Choreographer.CALLBACK_COMMIT, frameTimeNanos);
  53. } finally {
  54. AnimationUtils.unlockAnimationClock();
  55. Trace.traceEnd(Trace.TRACE_TAG_VIEW);
  56. }
  57. if (DEBUG_FRAMES) {
  58. final long endNanos = System.nanoTime();
  59. Log.d(TAG, "Frame " + frame + ": Finished, took "
  60. + (endNanos - startNanos) * 0.000001f + " ms, latency "
  61. + (startNanos - frameTimeNanos) * 0.000001f + " ms.");
  62. }
  63. }
Add Comment
Please, Sign In to add comment