Loading core/java/android/view/Surface.java +10 −1 Original line number Diff line number Diff line Loading @@ -197,7 +197,9 @@ public class Surface implements Parcelable { /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"FRAME_RATE_COMPATIBILITY_"}, value = {FRAME_RATE_COMPATIBILITY_DEFAULT, FRAME_RATE_COMPATIBILITY_FIXED_SOURCE}) value = {FRAME_RATE_COMPATIBILITY_DEFAULT, FRAME_RATE_COMPATIBILITY_FIXED_SOURCE, FRAME_RATE_COMPATIBILITY_EXACT, FRAME_RATE_COMPATIBILITY_NO_VOTE, FRAME_RATE_COMPATIBILITY_MIN, FRAME_RATE_COMPATIBILITY_GTE}) public @interface FrameRateCompatibility {} // From native_window.h. Keep these in sync. Loading Loading @@ -242,6 +244,13 @@ public class Surface implements Parcelable { */ public static final int FRAME_RATE_COMPATIBILITY_MIN = 102; // From window.h. Keep these in sync. /** * The surface requests a frame rate that is greater than or equal to {@code frameRate}. * @hide */ public static final int FRAME_RATE_COMPATIBILITY_GTE = 103; /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"CHANGE_FRAME_RATE_"}, Loading tests/CtsSurfaceControlTestsStaging/src/main/java/android/view/surfacecontroltests/GraphicsActivity.java +51 −7 Original line number Diff line number Diff line Loading @@ -235,13 +235,17 @@ public class GraphicsActivity extends Activity { } public int setFrameRate(float frameRate) { return setFrameRate(frameRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT); } public int setFrameRate( float frameRate, @Surface.FrameRateCompatibility int compatibility) { Log.i(TAG, String.format("Setting frame rate for %s: frameRate=%.2f", mName, frameRate)); int rc = 0; try (SurfaceControl.Transaction transaction = new SurfaceControl.Transaction()) { transaction.setFrameRate( mSurfaceControl, frameRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT); transaction.setFrameRate(mSurfaceControl, frameRate, compatibility); transaction.apply(); } return rc; Loading Loading @@ -668,12 +672,34 @@ public class GraphicsActivity extends Activity { } } private void testSurfaceControlFrameRateCategoryInternal(int category) throws InterruptedException { private void testSurfaceControlFrameRateCompatibilityInternal( @Surface.FrameRateCompatibility int compatibility) throws InterruptedException { runOneSurfaceTest((TestSurface surface) -> { Log.i(TAG, "**** Running testSurfaceControlFrameRateCompatibility with compatibility " + compatibility); float expectedFrameRate = getExpectedFrameRateForCompatibility(compatibility); int initialNumEvents = mModeChangedEvents.size(); surface.setFrameRate(30.f, compatibility); verifyExactAndStableFrameRate(expectedFrameRate, surface); verifyModeSwitchesDontChangeResolution(initialNumEvents, mModeChangedEvents.size()); }); } public void testSurfaceControlFrameRateCompatibility( @Surface.FrameRateCompatibility int compatibility) throws InterruptedException { runTestsWithPreconditions( () -> testSurfaceControlFrameRateCompatibilityInternal(compatibility), "frame rate compatibility=" + compatibility); } private void testSurfaceControlFrameRateCategoryInternal( @Surface.FrameRateCategory int category) throws InterruptedException { runOneSurfaceTest((TestSurface surface) -> { Log.i(TAG, "**** Running testSurfaceControlFrameRateCategory for category " + category); float expectedFrameRate = getExpectedFrameRate(category); float expectedFrameRate = getExpectedFrameRateForCategory(category); int initialNumEvents = mModeChangedEvents.size(); surface.setFrameRateCategory(category); verifyCompatibleAndStableFrameRate(expectedFrameRate, surface); Loading @@ -681,7 +707,8 @@ public class GraphicsActivity extends Activity { }); } public void testSurfaceControlFrameRateCategory(int category) throws InterruptedException { public void testSurfaceControlFrameRateCategory(@Surface.FrameRateCategory int category) throws InterruptedException { runTestsWithPreconditions(() -> testSurfaceControlFrameRateCategoryInternal(category), "frame rate category=" + category); Loading Loading @@ -744,7 +771,24 @@ public class GraphicsActivity extends Activity { "frame rate strategy=" + parentStrategy); } private float getExpectedFrameRate(int category) { private float getExpectedFrameRateForCompatibility(int compatibility) { assumeTrue("**** testSurfaceControlFrameRateCompatibility SKIPPED for compatibility " + compatibility, compatibility == Surface.FRAME_RATE_COMPATIBILITY_GTE); Display display = getDisplay(); Optional<Float> expectedFrameRate = getRefreshRates(display.getMode(), display) .stream() .filter(rate -> rate >= 30.f) .min(Comparator.naturalOrder()); assumeTrue("**** testSurfaceControlFrameRateCompatibility SKIPPED because no refresh rate " + "is >= 30", expectedFrameRate.isPresent()); return expectedFrameRate.get(); } private float getExpectedFrameRateForCategory(int category) { Display display = getDisplay(); List<Float> frameRates = getRefreshRates(display.getMode(), display); Loading tests/CtsSurfaceControlTestsStaging/src/main/java/android/view/surfacecontroltests/SurfaceControlTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,12 @@ public class SurfaceControlTest { .dropShellPermissionIdentity(); } @Test public void testSurfaceControlFrameRateCompatibilityGte() throws InterruptedException { GraphicsActivity activity = mActivityRule.getActivity(); activity.testSurfaceControlFrameRateCompatibility(Surface.FRAME_RATE_COMPATIBILITY_GTE); } @Test public void testSurfaceControlFrameRateCategoryHigh() throws InterruptedException { GraphicsActivity activity = mActivityRule.getActivity(); Loading Loading
core/java/android/view/Surface.java +10 −1 Original line number Diff line number Diff line Loading @@ -197,7 +197,9 @@ public class Surface implements Parcelable { /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"FRAME_RATE_COMPATIBILITY_"}, value = {FRAME_RATE_COMPATIBILITY_DEFAULT, FRAME_RATE_COMPATIBILITY_FIXED_SOURCE}) value = {FRAME_RATE_COMPATIBILITY_DEFAULT, FRAME_RATE_COMPATIBILITY_FIXED_SOURCE, FRAME_RATE_COMPATIBILITY_EXACT, FRAME_RATE_COMPATIBILITY_NO_VOTE, FRAME_RATE_COMPATIBILITY_MIN, FRAME_RATE_COMPATIBILITY_GTE}) public @interface FrameRateCompatibility {} // From native_window.h. Keep these in sync. Loading Loading @@ -242,6 +244,13 @@ public class Surface implements Parcelable { */ public static final int FRAME_RATE_COMPATIBILITY_MIN = 102; // From window.h. Keep these in sync. /** * The surface requests a frame rate that is greater than or equal to {@code frameRate}. * @hide */ public static final int FRAME_RATE_COMPATIBILITY_GTE = 103; /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"CHANGE_FRAME_RATE_"}, Loading
tests/CtsSurfaceControlTestsStaging/src/main/java/android/view/surfacecontroltests/GraphicsActivity.java +51 −7 Original line number Diff line number Diff line Loading @@ -235,13 +235,17 @@ public class GraphicsActivity extends Activity { } public int setFrameRate(float frameRate) { return setFrameRate(frameRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT); } public int setFrameRate( float frameRate, @Surface.FrameRateCompatibility int compatibility) { Log.i(TAG, String.format("Setting frame rate for %s: frameRate=%.2f", mName, frameRate)); int rc = 0; try (SurfaceControl.Transaction transaction = new SurfaceControl.Transaction()) { transaction.setFrameRate( mSurfaceControl, frameRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT); transaction.setFrameRate(mSurfaceControl, frameRate, compatibility); transaction.apply(); } return rc; Loading Loading @@ -668,12 +672,34 @@ public class GraphicsActivity extends Activity { } } private void testSurfaceControlFrameRateCategoryInternal(int category) throws InterruptedException { private void testSurfaceControlFrameRateCompatibilityInternal( @Surface.FrameRateCompatibility int compatibility) throws InterruptedException { runOneSurfaceTest((TestSurface surface) -> { Log.i(TAG, "**** Running testSurfaceControlFrameRateCompatibility with compatibility " + compatibility); float expectedFrameRate = getExpectedFrameRateForCompatibility(compatibility); int initialNumEvents = mModeChangedEvents.size(); surface.setFrameRate(30.f, compatibility); verifyExactAndStableFrameRate(expectedFrameRate, surface); verifyModeSwitchesDontChangeResolution(initialNumEvents, mModeChangedEvents.size()); }); } public void testSurfaceControlFrameRateCompatibility( @Surface.FrameRateCompatibility int compatibility) throws InterruptedException { runTestsWithPreconditions( () -> testSurfaceControlFrameRateCompatibilityInternal(compatibility), "frame rate compatibility=" + compatibility); } private void testSurfaceControlFrameRateCategoryInternal( @Surface.FrameRateCategory int category) throws InterruptedException { runOneSurfaceTest((TestSurface surface) -> { Log.i(TAG, "**** Running testSurfaceControlFrameRateCategory for category " + category); float expectedFrameRate = getExpectedFrameRate(category); float expectedFrameRate = getExpectedFrameRateForCategory(category); int initialNumEvents = mModeChangedEvents.size(); surface.setFrameRateCategory(category); verifyCompatibleAndStableFrameRate(expectedFrameRate, surface); Loading @@ -681,7 +707,8 @@ public class GraphicsActivity extends Activity { }); } public void testSurfaceControlFrameRateCategory(int category) throws InterruptedException { public void testSurfaceControlFrameRateCategory(@Surface.FrameRateCategory int category) throws InterruptedException { runTestsWithPreconditions(() -> testSurfaceControlFrameRateCategoryInternal(category), "frame rate category=" + category); Loading Loading @@ -744,7 +771,24 @@ public class GraphicsActivity extends Activity { "frame rate strategy=" + parentStrategy); } private float getExpectedFrameRate(int category) { private float getExpectedFrameRateForCompatibility(int compatibility) { assumeTrue("**** testSurfaceControlFrameRateCompatibility SKIPPED for compatibility " + compatibility, compatibility == Surface.FRAME_RATE_COMPATIBILITY_GTE); Display display = getDisplay(); Optional<Float> expectedFrameRate = getRefreshRates(display.getMode(), display) .stream() .filter(rate -> rate >= 30.f) .min(Comparator.naturalOrder()); assumeTrue("**** testSurfaceControlFrameRateCompatibility SKIPPED because no refresh rate " + "is >= 30", expectedFrameRate.isPresent()); return expectedFrameRate.get(); } private float getExpectedFrameRateForCategory(int category) { Display display = getDisplay(); List<Float> frameRates = getRefreshRates(display.getMode(), display); Loading
tests/CtsSurfaceControlTestsStaging/src/main/java/android/view/surfacecontroltests/SurfaceControlTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,12 @@ public class SurfaceControlTest { .dropShellPermissionIdentity(); } @Test public void testSurfaceControlFrameRateCompatibilityGte() throws InterruptedException { GraphicsActivity activity = mActivityRule.getActivity(); activity.testSurfaceControlFrameRateCompatibility(Surface.FRAME_RATE_COMPATIBILITY_GTE); } @Test public void testSurfaceControlFrameRateCategoryHigh() throws InterruptedException { GraphicsActivity activity = mActivityRule.getActivity(); Loading