Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: ui/android/java/src/org/chromium/ui/VSyncMonitor.java

Issue 611313003: Use estimated vsync period on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.content.Context; 8 import android.content.Context;
9 import android.os.Build; 9 import android.os.Build;
10 import android.os.Handler; 10 import android.os.Handler;
(...skipping 23 matching lines...) Expand all
34 * Called very soon after the start of the display's vertical sync perio d. 34 * Called very soon after the start of the display's vertical sync perio d.
35 * @param monitor The VSyncMonitor that triggered the signal. 35 * @param monitor The VSyncMonitor that triggered the signal.
36 * @param vsyncTimeMicros Absolute frame time in microseconds. 36 * @param vsyncTimeMicros Absolute frame time in microseconds.
37 */ 37 */
38 public void onVSync(VSyncMonitor monitor, long vsyncTimeMicros); 38 public void onVSync(VSyncMonitor monitor, long vsyncTimeMicros);
39 } 39 }
40 40
41 private Listener mListener; 41 private Listener mListener;
42 42
43 // Display refresh rate as reported by the system. 43 // Display refresh rate as reported by the system.
44 private final long mRefreshPeriodNano; 44 private long mRefreshPeriodNano;
45 45
46 private boolean mHaveRequestInFlight; 46 private boolean mHaveRequestInFlight;
47 47
48 // Choreographer is used to detect vsync on >= JB. 48 // Choreographer is used to detect vsync on >= JB.
49 private final Choreographer mChoreographer; 49 private final Choreographer mChoreographer;
50 private final Choreographer.FrameCallback mVSyncFrameCallback; 50 private final Choreographer.FrameCallback mVSyncFrameCallback;
51 51
52 // On ICS we just post a task through the handler (http://crbug.com/156397) 52 // On ICS we just post a task through the handler (http://crbug.com/156397)
53 private final Runnable mVSyncRunnableCallback; 53 private final Runnable mVSyncRunnableCallback;
54 private long mGoodStartingPointNano; 54 private long mGoodStartingPointNano;
(...skipping 27 matching lines...) Expand all
82 if (refreshRate <= 0) refreshRate = 60; 82 if (refreshRate <= 0) refreshRate = 60;
83 mRefreshPeriodNano = (long) (NANOSECONDS_PER_SECOND / refreshRate); 83 mRefreshPeriodNano = (long) (NANOSECONDS_PER_SECOND / refreshRate);
84 84
85 if (enableJBVSync && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_ BEAN) { 85 if (enableJBVSync && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_ BEAN) {
86 // Use Choreographer on JB+ to get notified of vsync. 86 // Use Choreographer on JB+ to get notified of vsync.
87 mChoreographer = Choreographer.getInstance(); 87 mChoreographer = Choreographer.getInstance();
88 mVSyncFrameCallback = new Choreographer.FrameCallback() { 88 mVSyncFrameCallback = new Choreographer.FrameCallback() {
89 @Override 89 @Override
90 public void doFrame(long frameTimeNanos) { 90 public void doFrame(long frameTimeNanos) {
91 TraceEvent.begin("VSync"); 91 TraceEvent.begin("VSync");
92 // Display.getRefreshRate() is unreliable on some platforms.
Sami 2014/09/30 16:04:14 Can we make this logic conditional on whether getR
jmanko 2014/10/01 09:36:51 Acknowledged.
93 // Adjust refresh period- initial value is based on Display. getRefreshRate(),
94 // after that it asymptotically approaches the real value.
95 // Last refresh duration is capped at 30 fps
96 long lastRefreshDurationNano =
97 Math.min(frameTimeNanos - mGoodStartingPointNano,
98 34 * NANOSECONDS_PER_MILLISECOND);
99 mRefreshPeriodNano = (mRefreshPeriodNano + lastRefreshDurati onNano) / 2;
Sami 2014/09/30 16:04:14 Instead of capping arbitrarily, can we just update
jmanko 2014/10/01 09:36:51 You mean something like this? long lastRefreshDura
Sami 2014/10/01 09:39:34 That would work. Please also make the |34 * NANOSE
no sievers 2014/10/01 17:48:09 Can't this be done easier and in a more robust way
92 mGoodStartingPointNano = frameTimeNanos; 100 mGoodStartingPointNano = frameTimeNanos;
93 onVSyncCallback(frameTimeNanos, getCurrentNanoTime()); 101 onVSyncCallback(frameTimeNanos, getCurrentNanoTime());
94 TraceEvent.end("VSync"); 102 TraceEvent.end("VSync");
95 } 103 }
96 }; 104 };
97 mVSyncRunnableCallback = null; 105 mVSyncRunnableCallback = null;
98 } else { 106 } else {
99 // On ICS we just hope that running tasks is relatively predictable. 107 // On ICS we just hope that running tasks is relatively predictable.
100 mChoreographer = null; 108 mChoreographer = null;
101 mVSyncFrameCallback = null; 109 mVSyncFrameCallback = null;
(...skipping 23 matching lines...) Expand all
125 /** 133 /**
126 * Returns the time interval between two consecutive vsync pulses in microse conds. 134 * Returns the time interval between two consecutive vsync pulses in microse conds.
127 */ 135 */
128 public long getVSyncPeriodInMicroseconds() { 136 public long getVSyncPeriodInMicroseconds() {
129 return mRefreshPeriodNano / NANOSECONDS_PER_MICROSECOND; 137 return mRefreshPeriodNano / NANOSECONDS_PER_MICROSECOND;
130 } 138 }
131 139
132 /** 140 /**
133 * Determine whether a true vsync signal is available on this platform. 141 * Determine whether a true vsync signal is available on this platform.
134 */ 142 */
135 private boolean isVSyncSignalAvailable() { 143 public boolean isVSyncSignalAvailable() {
136 return mChoreographer != null; 144 return mChoreographer != null;
137 } 145 }
138 146
139 /** 147 /**
140 * Request to be notified of the closest display vsync events. 148 * Request to be notified of the closest display vsync events.
141 * Listener.onVSync() will be called soon after the upcoming vsync pulses. 149 * Listener.onVSync() will be called soon after the upcoming vsync pulses.
142 */ 150 */
143 public void requestUpdate() { 151 public void requestUpdate() {
144 postCallback(); 152 postCallback();
145 } 153 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 225
218 if (currentTime + delay <= mLastPostedNano + mRefreshPeriodNano / 2) { 226 if (currentTime + delay <= mLastPostedNano + mRefreshPeriodNano / 2) {
219 delay += mRefreshPeriodNano; 227 delay += mRefreshPeriodNano;
220 } 228 }
221 229
222 mLastPostedNano = currentTime + delay; 230 mLastPostedNano = currentTime + delay;
223 if (delay == 0) mHandler.post(mVSyncRunnableCallback); 231 if (delay == 0) mHandler.post(mVSyncRunnableCallback);
224 else mHandler.postDelayed(mVSyncRunnableCallback, delay / NANOSECONDS_PE R_MILLISECOND); 232 else mHandler.postDelayed(mVSyncRunnableCallback, delay / NANOSECONDS_PE R_MILLISECOND);
225 } 233 }
226 } 234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698