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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/VSyncMonitorTest.java

Issue 11362177: Replace VSyncMonitor with compositor's VSyncPulseMonitor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: findbugs Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/VSyncMonitor.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/javatests/src/org/chromium/content/browser/VSyncMonitorTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/VSyncMonitorTest.java b/content/public/android/javatests/src/org/chromium/content/browser/VSyncMonitorTest.java
index 730a874046071cccfc7248ae1109af439dc2c3e4..935d1eb607b17c768339224fe6db29d82b1e7ff1 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/VSyncMonitorTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/VSyncMonitorTest.java
@@ -7,86 +7,93 @@ package org.chromium.content.browser;
import android.content.Context;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.MediumTest;
-import android.view.View;
-
import java.util.Arrays;
import java.util.concurrent.Callable;
import org.chromium.base.ThreadUtils;
-import org.chromium.content.browser.VSyncMonitor;
public class VSyncMonitorTest extends InstrumentationTestCase {
- private class VSyncDataCollector implements VSyncMonitor.Listener {
- public long framePeriods[];
- public int frameCount;
+ private static class VSyncDataCollector implements VSyncMonitor.Listener {
+ public long mFramePeriods[];
+ public int mFrameCount;
- private long previousVSyncTimeMicros;
+ private boolean mDone;
+ private long mPreviousVSyncTimeMicros;
+ private Object mSyncRoot = new Object();
VSyncDataCollector(int frames) {
- framePeriods = new long[frames];
+ mFramePeriods = new long[frames];
+ }
+
+ public boolean isDone() {
+ synchronized (mSyncRoot) {
+ return mDone;
+ }
}
@Override
public void onVSync(VSyncMonitor monitor, long vsyncTimeMicros) {
- if (previousVSyncTimeMicros == 0) {
- previousVSyncTimeMicros = vsyncTimeMicros;
+ if (mPreviousVSyncTimeMicros == 0) {
+ mPreviousVSyncTimeMicros = vsyncTimeMicros;
return;
}
- if (frameCount >= framePeriods.length) {
- synchronized (this) {
- notify();
+ if (mFrameCount >= mFramePeriods.length) {
+ synchronized (mSyncRoot) {
+ mDone = true;
+ mSyncRoot.notify();
}
return;
}
- framePeriods[frameCount++] = vsyncTimeMicros - previousVSyncTimeMicros;
- previousVSyncTimeMicros = vsyncTimeMicros;
+ mFramePeriods[mFrameCount++] = vsyncTimeMicros - mPreviousVSyncTimeMicros;
+ mPreviousVSyncTimeMicros = vsyncTimeMicros;
monitor.requestUpdate();
}
- };
+
+ public void waitTillDone() throws InterruptedException {
+ synchronized (mSyncRoot) {
+ while (!isDone()) {
+ mSyncRoot.wait();
+ }
+ }
+ }
+ }
// The vsync monitor must be created on the UI thread to avoid associating the underlying
// Choreographer with the Looper from the test runner thread.
- private VSyncMonitor createVSyncMonitor(final VSyncMonitor.Listener listener) {
+ private VSyncMonitor createVSyncMonitor(
+ final VSyncMonitor.Listener listener, final boolean enableJBVSync) {
return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<VSyncMonitor>() {
@Override
public VSyncMonitor call() {
Context context = getInstrumentation().getContext();
- View dummyView = new View(context);
- return new VSyncMonitor(context, dummyView, listener);
+ return new VSyncMonitor(context, listener, enableJBVSync);
}
});
}
// Check that the vsync period roughly matches the timestamps that the monitor generates.
- @MediumTest
- public void testVSyncPeriod() throws InterruptedException {
- // Collect roughly two seconds of data on a 60 fps display.
- VSyncDataCollector collector = new VSyncDataCollector(60 * 2);
- VSyncMonitor monitor = createVSyncMonitor(collector);
+ private void performVSyncPeriodTest(boolean enableJBVSync) throws InterruptedException {
+ // Collect roughly one second of data on a 60 fps display.
+ final int framesPerSecond = 60;
+ final int secondsToRun = 1;
+ final int totalFrames = secondsToRun * framesPerSecond;
+ VSyncDataCollector collector = new VSyncDataCollector(totalFrames);
+ VSyncMonitor monitor = createVSyncMonitor(collector, enableJBVSync);
long reportedFramePeriod = monitor.getVSyncPeriodInMicroseconds();
assertTrue(reportedFramePeriod > 0);
- if (!monitor.isVSyncSignalAvailable()) {
- // Cannot do timing test without real vsync signal. We can still verify that the monitor
- // throws if we try to use it.
- try {
- monitor.requestUpdate();
- fail("IllegalStateException not thrown.");
- } catch (IllegalStateException e) {
- }
- return;
- }
+ assertFalse(collector.isDone());
monitor.requestUpdate();
- synchronized (collector) {
- collector.wait();
- }
+ collector.waitTillDone();
+ assertTrue(collector.isDone());
monitor.stop();
// Check that the median frame rate is within 10% of the reported frame period.
- Arrays.sort(collector.framePeriods, 0, collector.framePeriods.length);
- long medianFramePeriod = collector.framePeriods[collector.framePeriods.length / 2];
+ assertTrue(collector.mFrameCount == totalFrames);
+ Arrays.sort(collector.mFramePeriods, 0, collector.mFramePeriods.length);
+ long medianFramePeriod = collector.mFramePeriods[collector.mFramePeriods.length / 2];
if (Math.abs(medianFramePeriod - reportedFramePeriod) > reportedFramePeriod * .1) {
fail("Measured median frame period " + medianFramePeriod +
" differs by more than 10% from the reported frame period " +
@@ -94,75 +101,15 @@ public class VSyncMonitorTest extends InstrumentationTestCase {
}
}
- private class TestView extends View {
- private Runnable mPendingAction;
-
- public TestView(Context context) {
- super(context);
- }
-
- @Override
- public boolean postDelayed(Runnable action, long delayMillis) {
- mPendingAction = action;
- return true;
- }
-
- public void runPendingAction() {
- assertNotNull(mPendingAction);
- mPendingAction.run();
- }
- };
-
- private class TestTimeSource implements VSyncMonitor.TestTimeSource {
- long mCurrentTimeMillis;
-
- @Override
- public long currentTimeMillis() {
- return mCurrentTimeMillis;
- }
-
- void setCurrentTimeMillis(long currentTimeMillis) {
- mCurrentTimeMillis = currentTimeMillis;
- }
- };
-
- // Check the the vsync monitor terminates after we have stopped requesting updates for some
- // time.
+ // Check that the vsync period roughly matches the timestamps that the monitor generates.
@MediumTest
- public void testVSyncTimeout() throws InterruptedException {
- VSyncMonitor.Listener listener = new VSyncMonitor.Listener() {
- @Override
- public void onVSync(VSyncMonitor monitor, long vsyncTimeMicros) {
- // No-op vsync listener.
- }
- };
- VSyncMonitor monitor = createVSyncMonitor(listener);
- if (!monitor.isVSyncSignalAvailable()) {
- // Cannot do timeout test without real vsync signal.
- return;
- }
-
- TestTimeSource testTimeSource = new TestTimeSource();
- TestView testView = new TestView(getInstrumentation().getContext());
- monitor.setTestDependencies(testView, testTimeSource);
-
- // Requesting an update should make the monitor active.
- testTimeSource.setCurrentTimeMillis(0);
- monitor.requestUpdate();
- assertTrue(monitor.isActive());
-
- // Running the timeout callback should have no effect when no time has passed.
- testView.runPendingAction();
- assertTrue(monitor.isActive());
-
- // Ditto after half the timeout interval.
- testTimeSource.setCurrentTimeMillis(VSyncMonitor.VSYNC_TIMEOUT_MILLISECONDS / 2);
- testView.runPendingAction();
- assertTrue(monitor.isActive());
+ public void testVSyncPeriodAllowJBVSync() throws InterruptedException {
+ performVSyncPeriodTest(true);
+ }
- // The monitor should be stopped after the timeout interval has passed.
- testTimeSource.setCurrentTimeMillis(VSyncMonitor.VSYNC_TIMEOUT_MILLISECONDS + 1);
- testView.runPendingAction();
- assertFalse(monitor.isActive());
+ // Check that the vsync period roughly matches the timestamps that the monitor generates.
+ @MediumTest
+ public void testVSyncPeriodDisallowJBVSync() throws InterruptedException {
+ performVSyncPeriodTest(false);
}
}
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/VSyncMonitor.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698