Loading core/java/android/hardware/display/DisplayManagerGlobal.java +2 −2 Original line number Diff line number Diff line Loading @@ -358,7 +358,7 @@ public final class DisplayManagerGlobal { // listener. DisplayInfo display = getDisplayInfoLocked(displayId); if (display != null) { float refreshRate = display.getMode().getRefreshRate(); float refreshRate = display.getRefreshRate(); // Signal native callbacks if we ever set a refresh rate. nSignalNativeCallbacks(refreshRate); } Loading Loading @@ -862,7 +862,7 @@ public final class DisplayManagerGlobal { if (display != null) { // We need to tell AChoreographer instances the current refresh rate so that apps // can get it for free once a callback first registers. float refreshRate = display.getMode().getRefreshRate(); float refreshRate = display.getRefreshRate(); nSignalNativeCallbacks(refreshRate); } } Loading core/java/android/view/Choreographer.java +2 −2 Original line number Diff line number Diff line Loading @@ -276,7 +276,7 @@ public final class Choreographer { private static float getRefreshRate() { DisplayInfo di = DisplayManagerGlobal.getInstance().getDisplayInfo( Display.DEFAULT_DISPLAY); return di.getMode().getRefreshRate(); return di.getRefreshRate(); } /** Loading Loading @@ -944,7 +944,7 @@ public final class Choreographer { private VsyncEventData mLastVsyncEventData = new VsyncEventData(); public FrameDisplayEventReceiver(Looper looper, int vsyncSource) { super(looper, vsyncSource, CONFIG_CHANGED_EVENT_SUPPRESS); super(looper, vsyncSource, 0); } // TODO(b/116025192): physicalDisplayId is ignored because SF only emits VSYNC events for Loading core/java/android/view/Display.java +14 −1 Original line number Diff line number Diff line Loading @@ -456,6 +456,9 @@ public final class Display { // TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_DESTROY public static final int REMOVE_MODE_DESTROY_CONTENT = 1; /** @hide */ public static final int DISPLAY_MODE_ID_FOR_FRAME_RATE_OVERRIDE = 0xFF; /** * Internal method to create a display. * The display created with this method will have a static {@link DisplayAdjustments} applied. Loading Loading @@ -886,7 +889,7 @@ public final class Display { public float getRefreshRate() { synchronized (this) { updateDisplayInfoLocked(); return mDisplayInfo.getMode().getRefreshRate(); return mDisplayInfo.getRefreshRate(); } } Loading Loading @@ -1526,6 +1529,16 @@ public final class Display { Float.floatToIntBits(mRefreshRate) == Float.floatToIntBits(refreshRate); } /** * Returns {@code true} if this mode equals to the other mode in all parameters except * the refresh rate. * * @hide */ public boolean equalsExceptRefreshRate(@Nullable Display.Mode other) { return mWidth == other.mWidth && mHeight == other.mHeight; } @Override public boolean equals(@Nullable Object other) { if (this == other) { Loading core/java/android/view/DisplayEventReceiver.java +54 −10 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import android.os.Looper; import android.os.MessageQueue; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import dalvik.annotation.optimization.FastNative; import dalvik.system.CloseGuard; Loading Loading @@ -56,18 +58,18 @@ public abstract class DisplayEventReceiver { public static final int VSYNC_SOURCE_SURFACE_FLINGER = 1; /** * Specifies to suppress config changed events from being generated from Surface Flinger. * Specifies to generate config changed events from Surface Flinger. * <p> * Needs to be kept in sync with frameworks/native/include/gui/ISurfaceComposer.h */ public static final int CONFIG_CHANGED_EVENT_SUPPRESS = 0; public static final int EVENT_REGISTRATION_CONFIG_CHANGED_FLAG = 0x1; /** * Specifies to generate config changed events from Surface Flinger. * Specifies to generate frame rate override events from Surface Flinger. * <p> * Needs to be kept in sync with frameworks/native/include/gui/ISurfaceComposer.h */ public static final int CONFIG_CHANGED_EVENT_DISPATCH = 1; public static final int EVENT_REGISTRATION_FRAME_RATE_OVERRIDE_FLAG = 0x2; private static final String TAG = "DisplayEventReceiver"; Loading @@ -81,7 +83,7 @@ public abstract class DisplayEventReceiver { private MessageQueue mMessageQueue; private static native long nativeInit(WeakReference<DisplayEventReceiver> receiver, MessageQueue messageQueue, int vsyncSource, int configChanged); MessageQueue messageQueue, int vsyncSource, int eventRegistration); private static native void nativeDispose(long receiverPtr); @FastNative private static native void nativeScheduleVsync(long receiverPtr); Loading @@ -93,7 +95,7 @@ public abstract class DisplayEventReceiver { */ @UnsupportedAppUsage public DisplayEventReceiver(Looper looper) { this(looper, VSYNC_SOURCE_APP, CONFIG_CHANGED_EVENT_SUPPRESS); this(looper, VSYNC_SOURCE_APP, 0); } /** Loading @@ -101,17 +103,17 @@ public abstract class DisplayEventReceiver { * * @param looper The looper to use when invoking callbacks. * @param vsyncSource The source of the vsync tick. Must be on of the VSYNC_SOURCE_* values. * @param configChanged Whether to dispatch config changed events. Must be one of the * CONFIG_CHANGED_EVENT_* values. * @param eventRegistration Which events to dispatch. Must be a bitfield consist of the * EVENT_REGISTRATION_*_FLAG values. */ public DisplayEventReceiver(Looper looper, int vsyncSource, int configChanged) { public DisplayEventReceiver(Looper looper, int vsyncSource, int eventRegistration) { if (looper == null) { throw new IllegalArgumentException("looper must not be null"); } mMessageQueue = looper.getQueue(); mReceiverPtr = nativeInit(new WeakReference<DisplayEventReceiver>(this), mMessageQueue, vsyncSource, configChanged); vsyncSource, eventRegistration); mCloseGuard.open("dispose"); } Loading Loading @@ -205,6 +207,41 @@ public abstract class DisplayEventReceiver { public void onConfigChanged(long timestampNanos, long physicalDisplayId, int configId) { } /** * Represents a mapping between a UID and an override frame rate */ public static class FrameRateOverride { // The application uid public final int uid; // The frame rate that this application runs at public final float frameRateHz; @VisibleForTesting public FrameRateOverride(int uid, float frameRateHz) { this.uid = uid; this.frameRateHz = frameRateHz; } @Override public String toString() { return "{uid=" + uid + " frameRateHz=" + frameRateHz + "}"; } } /** * Called when frame rate override event is received. * * @param timestampNanos The timestamp of the event, in the {@link System#nanoTime()} * timebase. * @param physicalDisplayId Stable display ID that uniquely describes a (display, port) pair. * @param overrides The mappings from uid to frame rates */ public void onFrameRateOverridesChanged(long timestampNanos, long physicalDisplayId, FrameRateOverride[] overrides) { } /** * Schedules a single vertical sync pulse to be delivered when the next * display frame begins. Loading Loading @@ -240,4 +277,11 @@ public abstract class DisplayEventReceiver { onConfigChanged(timestampNanos, physicalDisplayId, configId); } // Called from native code. @SuppressWarnings("unused") private void dispatchFrameRateOverrides(long timestampNanos, long physicalDisplayId, FrameRateOverride[] overrides) { onFrameRateOverridesChanged(timestampNanos, physicalDisplayId, overrides); } } core/java/android/view/DisplayInfo.java +24 −1 Original line number Diff line number Diff line Loading @@ -260,6 +260,11 @@ public final class DisplayInfo implements Parcelable { */ public String ownerPackageName; /** * The refresh rate override for this app. 0 means no override. */ public float refreshRateOverride; /** * @hide * Get current remove mode of the display - what actions should be performed with the display's Loading Loading @@ -332,7 +337,8 @@ public final class DisplayInfo implements Parcelable { && state == other.state && ownerUid == other.ownerUid && Objects.equals(ownerPackageName, other.ownerPackageName) && removeMode == other.removeMode; && removeMode == other.removeMode && refreshRateOverride == other.refreshRateOverride; } @Override Loading Loading @@ -376,6 +382,7 @@ public final class DisplayInfo implements Parcelable { ownerUid = other.ownerUid; ownerPackageName = other.ownerPackageName; removeMode = other.removeMode; refreshRateOverride = other.refreshRateOverride; } public void readFromParcel(Parcel source) { Loading Loading @@ -421,6 +428,7 @@ public final class DisplayInfo implements Parcelable { ownerPackageName = source.readString8(); uniqueId = source.readString8(); removeMode = source.readInt(); refreshRateOverride = source.readFloat(); } @Override Loading Loading @@ -465,6 +473,7 @@ public final class DisplayInfo implements Parcelable { dest.writeString8(ownerPackageName); dest.writeString8(uniqueId); dest.writeInt(removeMode); dest.writeFloat(refreshRateOverride); } @Override Loading @@ -472,6 +481,17 @@ public final class DisplayInfo implements Parcelable { return 0; } /** * Returns the refresh rate the application would experience. */ public float getRefreshRate() { if (refreshRateOverride > 0) { return refreshRateOverride; } return getMode().getRefreshRate(); } public Display.Mode getMode() { return findMode(modeId); } Loading Loading @@ -675,6 +695,9 @@ public final class DisplayInfo implements Parcelable { } sb.append(", removeMode "); sb.append(removeMode); sb.append(", refreshRateOverride "); sb.append(refreshRateOverride); sb.append("}"); return sb.toString(); } Loading Loading
core/java/android/hardware/display/DisplayManagerGlobal.java +2 −2 Original line number Diff line number Diff line Loading @@ -358,7 +358,7 @@ public final class DisplayManagerGlobal { // listener. DisplayInfo display = getDisplayInfoLocked(displayId); if (display != null) { float refreshRate = display.getMode().getRefreshRate(); float refreshRate = display.getRefreshRate(); // Signal native callbacks if we ever set a refresh rate. nSignalNativeCallbacks(refreshRate); } Loading Loading @@ -862,7 +862,7 @@ public final class DisplayManagerGlobal { if (display != null) { // We need to tell AChoreographer instances the current refresh rate so that apps // can get it for free once a callback first registers. float refreshRate = display.getMode().getRefreshRate(); float refreshRate = display.getRefreshRate(); nSignalNativeCallbacks(refreshRate); } } Loading
core/java/android/view/Choreographer.java +2 −2 Original line number Diff line number Diff line Loading @@ -276,7 +276,7 @@ public final class Choreographer { private static float getRefreshRate() { DisplayInfo di = DisplayManagerGlobal.getInstance().getDisplayInfo( Display.DEFAULT_DISPLAY); return di.getMode().getRefreshRate(); return di.getRefreshRate(); } /** Loading Loading @@ -944,7 +944,7 @@ public final class Choreographer { private VsyncEventData mLastVsyncEventData = new VsyncEventData(); public FrameDisplayEventReceiver(Looper looper, int vsyncSource) { super(looper, vsyncSource, CONFIG_CHANGED_EVENT_SUPPRESS); super(looper, vsyncSource, 0); } // TODO(b/116025192): physicalDisplayId is ignored because SF only emits VSYNC events for Loading
core/java/android/view/Display.java +14 −1 Original line number Diff line number Diff line Loading @@ -456,6 +456,9 @@ public final class Display { // TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_DESTROY public static final int REMOVE_MODE_DESTROY_CONTENT = 1; /** @hide */ public static final int DISPLAY_MODE_ID_FOR_FRAME_RATE_OVERRIDE = 0xFF; /** * Internal method to create a display. * The display created with this method will have a static {@link DisplayAdjustments} applied. Loading Loading @@ -886,7 +889,7 @@ public final class Display { public float getRefreshRate() { synchronized (this) { updateDisplayInfoLocked(); return mDisplayInfo.getMode().getRefreshRate(); return mDisplayInfo.getRefreshRate(); } } Loading Loading @@ -1526,6 +1529,16 @@ public final class Display { Float.floatToIntBits(mRefreshRate) == Float.floatToIntBits(refreshRate); } /** * Returns {@code true} if this mode equals to the other mode in all parameters except * the refresh rate. * * @hide */ public boolean equalsExceptRefreshRate(@Nullable Display.Mode other) { return mWidth == other.mWidth && mHeight == other.mHeight; } @Override public boolean equals(@Nullable Object other) { if (this == other) { Loading
core/java/android/view/DisplayEventReceiver.java +54 −10 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ import android.os.Looper; import android.os.MessageQueue; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import dalvik.annotation.optimization.FastNative; import dalvik.system.CloseGuard; Loading Loading @@ -56,18 +58,18 @@ public abstract class DisplayEventReceiver { public static final int VSYNC_SOURCE_SURFACE_FLINGER = 1; /** * Specifies to suppress config changed events from being generated from Surface Flinger. * Specifies to generate config changed events from Surface Flinger. * <p> * Needs to be kept in sync with frameworks/native/include/gui/ISurfaceComposer.h */ public static final int CONFIG_CHANGED_EVENT_SUPPRESS = 0; public static final int EVENT_REGISTRATION_CONFIG_CHANGED_FLAG = 0x1; /** * Specifies to generate config changed events from Surface Flinger. * Specifies to generate frame rate override events from Surface Flinger. * <p> * Needs to be kept in sync with frameworks/native/include/gui/ISurfaceComposer.h */ public static final int CONFIG_CHANGED_EVENT_DISPATCH = 1; public static final int EVENT_REGISTRATION_FRAME_RATE_OVERRIDE_FLAG = 0x2; private static final String TAG = "DisplayEventReceiver"; Loading @@ -81,7 +83,7 @@ public abstract class DisplayEventReceiver { private MessageQueue mMessageQueue; private static native long nativeInit(WeakReference<DisplayEventReceiver> receiver, MessageQueue messageQueue, int vsyncSource, int configChanged); MessageQueue messageQueue, int vsyncSource, int eventRegistration); private static native void nativeDispose(long receiverPtr); @FastNative private static native void nativeScheduleVsync(long receiverPtr); Loading @@ -93,7 +95,7 @@ public abstract class DisplayEventReceiver { */ @UnsupportedAppUsage public DisplayEventReceiver(Looper looper) { this(looper, VSYNC_SOURCE_APP, CONFIG_CHANGED_EVENT_SUPPRESS); this(looper, VSYNC_SOURCE_APP, 0); } /** Loading @@ -101,17 +103,17 @@ public abstract class DisplayEventReceiver { * * @param looper The looper to use when invoking callbacks. * @param vsyncSource The source of the vsync tick. Must be on of the VSYNC_SOURCE_* values. * @param configChanged Whether to dispatch config changed events. Must be one of the * CONFIG_CHANGED_EVENT_* values. * @param eventRegistration Which events to dispatch. Must be a bitfield consist of the * EVENT_REGISTRATION_*_FLAG values. */ public DisplayEventReceiver(Looper looper, int vsyncSource, int configChanged) { public DisplayEventReceiver(Looper looper, int vsyncSource, int eventRegistration) { if (looper == null) { throw new IllegalArgumentException("looper must not be null"); } mMessageQueue = looper.getQueue(); mReceiverPtr = nativeInit(new WeakReference<DisplayEventReceiver>(this), mMessageQueue, vsyncSource, configChanged); vsyncSource, eventRegistration); mCloseGuard.open("dispose"); } Loading Loading @@ -205,6 +207,41 @@ public abstract class DisplayEventReceiver { public void onConfigChanged(long timestampNanos, long physicalDisplayId, int configId) { } /** * Represents a mapping between a UID and an override frame rate */ public static class FrameRateOverride { // The application uid public final int uid; // The frame rate that this application runs at public final float frameRateHz; @VisibleForTesting public FrameRateOverride(int uid, float frameRateHz) { this.uid = uid; this.frameRateHz = frameRateHz; } @Override public String toString() { return "{uid=" + uid + " frameRateHz=" + frameRateHz + "}"; } } /** * Called when frame rate override event is received. * * @param timestampNanos The timestamp of the event, in the {@link System#nanoTime()} * timebase. * @param physicalDisplayId Stable display ID that uniquely describes a (display, port) pair. * @param overrides The mappings from uid to frame rates */ public void onFrameRateOverridesChanged(long timestampNanos, long physicalDisplayId, FrameRateOverride[] overrides) { } /** * Schedules a single vertical sync pulse to be delivered when the next * display frame begins. Loading Loading @@ -240,4 +277,11 @@ public abstract class DisplayEventReceiver { onConfigChanged(timestampNanos, physicalDisplayId, configId); } // Called from native code. @SuppressWarnings("unused") private void dispatchFrameRateOverrides(long timestampNanos, long physicalDisplayId, FrameRateOverride[] overrides) { onFrameRateOverridesChanged(timestampNanos, physicalDisplayId, overrides); } }
core/java/android/view/DisplayInfo.java +24 −1 Original line number Diff line number Diff line Loading @@ -260,6 +260,11 @@ public final class DisplayInfo implements Parcelable { */ public String ownerPackageName; /** * The refresh rate override for this app. 0 means no override. */ public float refreshRateOverride; /** * @hide * Get current remove mode of the display - what actions should be performed with the display's Loading Loading @@ -332,7 +337,8 @@ public final class DisplayInfo implements Parcelable { && state == other.state && ownerUid == other.ownerUid && Objects.equals(ownerPackageName, other.ownerPackageName) && removeMode == other.removeMode; && removeMode == other.removeMode && refreshRateOverride == other.refreshRateOverride; } @Override Loading Loading @@ -376,6 +382,7 @@ public final class DisplayInfo implements Parcelable { ownerUid = other.ownerUid; ownerPackageName = other.ownerPackageName; removeMode = other.removeMode; refreshRateOverride = other.refreshRateOverride; } public void readFromParcel(Parcel source) { Loading Loading @@ -421,6 +428,7 @@ public final class DisplayInfo implements Parcelable { ownerPackageName = source.readString8(); uniqueId = source.readString8(); removeMode = source.readInt(); refreshRateOverride = source.readFloat(); } @Override Loading Loading @@ -465,6 +473,7 @@ public final class DisplayInfo implements Parcelable { dest.writeString8(ownerPackageName); dest.writeString8(uniqueId); dest.writeInt(removeMode); dest.writeFloat(refreshRateOverride); } @Override Loading @@ -472,6 +481,17 @@ public final class DisplayInfo implements Parcelable { return 0; } /** * Returns the refresh rate the application would experience. */ public float getRefreshRate() { if (refreshRateOverride > 0) { return refreshRateOverride; } return getMode().getRefreshRate(); } public Display.Mode getMode() { return findMode(modeId); } Loading Loading @@ -675,6 +695,9 @@ public final class DisplayInfo implements Parcelable { } sb.append(", removeMode "); sb.append(removeMode); sb.append(", refreshRateOverride "); sb.append(refreshRateOverride); sb.append("}"); return sb.toString(); } Loading