Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d90ac713 authored by Ady Abraham's avatar Ady Abraham Committed by Android (Google) Code Review
Browse files

Merge "Handle DISPLAY_EVENT_FRAME_RATE_OVERRIDE"

parents c092761a 15d23d83
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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);
                    }
@@ -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);
            }
        }
+2 −2
Original line number Diff line number Diff line
@@ -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();
    }

    /**
@@ -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
+14 −1
Original line number Diff line number Diff line
@@ -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.
@@ -886,7 +889,7 @@ public final class Display {
    public float getRefreshRate() {
        synchronized (this) {
            updateDisplayInfoLocked();
            return mDisplayInfo.getMode().getRefreshRate();
            return mDisplayInfo.getRefreshRate();
        }
    }

@@ -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) {
+54 −10
Original line number Diff line number Diff line
@@ -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;

@@ -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";

@@ -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);
@@ -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);
    }

    /**
@@ -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");
    }
@@ -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.
@@ -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);
    }

}
+24 −1
Original line number Diff line number Diff line
@@ -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
@@ -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
@@ -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) {
@@ -421,6 +428,7 @@ public final class DisplayInfo implements Parcelable {
        ownerPackageName = source.readString8();
        uniqueId = source.readString8();
        removeMode = source.readInt();
        refreshRateOverride = source.readFloat();
    }

    @Override
@@ -465,6 +473,7 @@ public final class DisplayInfo implements Parcelable {
        dest.writeString8(ownerPackageName);
        dest.writeString8(uniqueId);
        dest.writeInt(removeMode);
        dest.writeFloat(refreshRateOverride);
    }

    @Override
@@ -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);
    }
@@ -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