| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.ui; | 5 package org.chromium.ui; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.os.Handler; | 8 import android.os.Handler; |
| 9 import android.os.Looper; | 9 import android.os.Looper; |
| 10 import android.view.Choreographer; | 10 import android.view.Choreographer; |
| 11 import android.view.WindowManager; | 11 import android.view.WindowManager; |
| 12 | 12 |
| 13 import org.chromium.base.TraceEvent; | 13 import org.chromium.base.TraceEvent; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Notifies clients of the default displays's vertical sync pulses. | 16 * Notifies clients of the default displays's vertical sync pulses. |
| 17 */ | 17 */ |
| 18 public class VSyncMonitor { | 18 public class VSyncMonitor { |
| 19 private static final long NANOSECONDS_PER_SECOND = 1000000000; | 19 private static final long NANOSECONDS_PER_SECOND = 1000000000; |
| 20 private static final long NANOSECONDS_PER_MICROSECOND = 1000; | 20 private static final long NANOSECONDS_PER_MICROSECOND = 1000; |
| 21 | 21 |
| 22 private boolean mInsideVSync = false; | 22 private boolean mInsideVSync; |
| 23 | 23 |
| 24 // Conservative guess about vsync's consecutivity. | 24 // Conservative guess about vsync's consecutivity. |
| 25 // If true, next tick is guaranteed to be consecutive. | 25 // If true, next tick is guaranteed to be consecutive. |
| 26 private boolean mConsecutiveVSync = false; | 26 private boolean mConsecutiveVSync; |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * VSync listener class | 29 * VSync listener class |
| 30 */ | 30 */ |
| 31 public interface Listener { | 31 public interface Listener { |
| 32 /** | 32 /** |
| 33 * Called very soon after the start of the display's vertical sync perio
d. | 33 * Called very soon after the start of the display's vertical sync perio
d. |
| 34 * @param monitor The VSyncMonitor that triggered the signal. | 34 * @param monitor The VSyncMonitor that triggered the signal. |
| 35 * @param vsyncTimeMicros Absolute frame time in microseconds. | 35 * @param vsyncTimeMicros Absolute frame time in microseconds. |
| 36 */ | 36 */ |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 private void postCallback() { | 136 private void postCallback() { |
| 137 if (mHaveRequestInFlight) return; | 137 if (mHaveRequestInFlight) return; |
| 138 mHaveRequestInFlight = true; | 138 mHaveRequestInFlight = true; |
| 139 mConsecutiveVSync = mInsideVSync; | 139 mConsecutiveVSync = mInsideVSync; |
| 140 mChoreographer.postFrameCallback(mVSyncFrameCallback); | 140 mChoreographer.postFrameCallback(mVSyncFrameCallback); |
| 141 } | 141 } |
| 142 } | 142 } |
| OLD | NEW |