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

Commit 77a43465 authored by ramindani's avatar ramindani
Browse files

[DM] Update onModeChanged to send vsyncOffsetNanos

[DM] Update onModeChanged to send presentationDeadlineNanos

BUG: 398872242
Test: atest LocalDisplayAdapterTest
Flag: com.android.server.display.feature.flags.enable_on_mode_changed_vsync_phase_offset
Change-Id: I1722b8dd44e71a98d2128e0b34366f1f743cd99e
parent 192dc873
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -288,9 +288,13 @@ public abstract class DisplayEventReceiver {
     * @param physicalDisplayId Stable display ID that uniquely describes a (display, port) pair.
     * @param modeId The new mode ID
     * @param renderPeriod The render frame period, which is a multiple of the mode's vsync period
     * @param appVsyncOffsetNanos The offset from the vsync of the display refresh rate.
     * @param presentationDeadlineNanos The time in nanoseconds by which the frame should be ready
     *                             from the target vsync, if target vsync is N then the frame
     *                             should be ready by N - presentationDeadlineNanos.
     */
    public void onModeChanged(long timestampNanos, long physicalDisplayId, int modeId,
            long renderPeriod) {
            long renderPeriod, long appVsyncOffsetNanos, long presentationDeadlineNanos) {
    }

    /**
@@ -389,8 +393,9 @@ public abstract class DisplayEventReceiver {
    // Called from native code.
    @SuppressWarnings("unused")
    private void dispatchModeChanged(long timestampNanos, long physicalDisplayId, int modeId,
            long renderPeriod) {
        onModeChanged(timestampNanos, physicalDisplayId, modeId, renderPeriod);
            long renderPeriod, long appVsyncOffsetNanos, long presentationDeadlineNanos) {
        onModeChanged(timestampNanos, physicalDisplayId, modeId, renderPeriod,
                appVsyncOffsetNanos, presentationDeadlineNanos);
    }

    // Called from native code.
+8 −4
Original line number Diff line number Diff line
@@ -96,7 +96,8 @@ private:
    void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId, bool connected) override;
    void dispatchHotplugConnectionError(nsecs_t timestamp, int errorCode) override;
    void dispatchModeChanged(nsecs_t timestamp, PhysicalDisplayId displayId, int32_t modeId,
                             nsecs_t renderPeriod) override;
                             nsecs_t renderPeriod, nsecs_t appVsyncOffset,
                             nsecs_t presentationDeadline) override;
    void dispatchModeRejected(PhysicalDisplayId displayId, int32_t modeId) override;
    void dispatchFrameRateOverrides(nsecs_t timestamp, PhysicalDisplayId displayId,
                                    std::vector<FrameRateOverride> overrides) override;
@@ -260,14 +261,17 @@ void NativeDisplayEventReceiver::dispatchHotplugConnectionError(nsecs_t timestam
}

void NativeDisplayEventReceiver::dispatchModeChanged(nsecs_t timestamp, PhysicalDisplayId displayId,
                                                     int32_t modeId, nsecs_t renderPeriod) {
                                                     int32_t modeId, nsecs_t renderPeriod,
                                                     nsecs_t appVsyncOffset,
                                                     nsecs_t presentationDeadline) {
    JNIEnv* env = AndroidRuntime::getJNIEnv();

    ScopedLocalRef<jobject> receiverObj(env, GetReferent(env, mReceiverWeakGlobal));
    if (receiverObj.get()) {
        ALOGV("receiver %p ~ Invoking mode changed handler.", this);
        env->CallVoidMethod(receiverObj.get(), gDisplayEventReceiverClassInfo.dispatchModeChanged,
                            timestamp, displayId.value, modeId, renderPeriod);
                            timestamp, displayId.value, modeId, renderPeriod, appVsyncOffset,
                            presentationDeadline);
        ALOGV("receiver %p ~ Returned from mode changed handler.", this);
    }

@@ -421,7 +425,7 @@ int register_android_view_DisplayEventReceiver(JNIEnv* env) {
                             "dispatchHotplugConnectionError", "(JI)V");
    gDisplayEventReceiverClassInfo.dispatchModeChanged =
            GetMethodIDOrDie(env, gDisplayEventReceiverClassInfo.clazz, "dispatchModeChanged",
                             "(JJIJ)V");
                             "(JJIJJJ)V");
    gDisplayEventReceiverClassInfo.dispatchModeRejected =
            GetMethodIDOrDie(env, gDisplayEventReceiverClassInfo.clazz, "dispatchModeRejected",
                             "(JI)V");
+46 −12
Original line number Diff line number Diff line
@@ -236,6 +236,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        private int mActiveSfDisplayModeAtStartId = INVALID_MODE_ID;
        private Display.Mode mUserPreferredMode;
        private int mActiveModeId = INVALID_MODE_ID;
        private long mAppVsyncOffsetNanos;
        private long mPresentationDeadlineNanos;
        private boolean mDisplayModeSpecsInvalid;
        private int mActiveColorMode;
        private boolean mHasArrSupport;
@@ -322,6 +324,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
                SurfaceControl.DesiredDisplayModeSpecs modeSpecs) {
            mSfDisplayModes = Arrays.copyOf(displayModes, displayModes.length);
            mActiveSfDisplayMode = getModeById(displayModes, activeSfDisplayModeId);
            mAppVsyncOffsetNanos = mActiveSfDisplayMode.appVsyncOffsetNanos;
            mPresentationDeadlineNanos = mActiveSfDisplayMode.presentationDeadlineNanos;
            SurfaceControl.DisplayMode preferredSfDisplayMode =
                        getModeById(displayModes, preferredSfDisplayModeId);

@@ -514,6 +518,20 @@ final class LocalDisplayAdapter extends DisplayAdapter {
                    : mDefaultModeId;
        }

        private long getAppVsyncOffsetNanos(long defaultValue) {
            if (getFeatureFlags().isDispatchDisplayModeWithVsyncOffsetsEnabled()) {
                return mAppVsyncOffsetNanos;
            }
            return defaultValue;
        }

        private long getPresentationDeadlineNanos(long defaultValue) {
            if (getFeatureFlags().isDispatchDisplayModeWithVsyncOffsetsEnabled()) {
                return mPresentationDeadlineNanos;
            }
            return defaultValue;
        }

        private int getLogicalDensity() {
            DensityMapping densityMapping = getDisplayDeviceConfig().getDensityMapping();
            if (densityMapping == null) {
@@ -734,8 +752,11 @@ final class LocalDisplayAdapter extends DisplayAdapter {
                mInfo.hasArrSupport = mHasArrSupport;
                mInfo.frameRateCategoryRate = mFrameRateCategoryRate;
                mInfo.supportedRefreshRates = mSupportedRefreshRates;
                mInfo.appVsyncOffsetNanos = mActiveSfDisplayMode.appVsyncOffsetNanos;
                mInfo.presentationDeadlineNanos = mActiveSfDisplayMode.presentationDeadlineNanos;
                mInfo.appVsyncOffsetNanos =
                        getAppVsyncOffsetNanos(mActiveSfDisplayMode.appVsyncOffsetNanos);
                mInfo.presentationDeadlineNanos =
                        getPresentationDeadlineNanos(
                                mActiveSfDisplayMode.presentationDeadlineNanos);
                mInfo.state = mState;
                mInfo.committedState = mCommittedState;
                mInfo.uniqueId = getUniqueId();
@@ -1213,8 +1234,10 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            updateDeviceInfoLocked();
        }

        public void onActiveDisplayModeChangedLocked(int sfModeId, float renderFrameRate) {
            if (updateActiveModeLocked(sfModeId, renderFrameRate)) {
        public void onActiveDisplayModeChangedLocked(int sfModeId, float renderFrameRate,
                long appVsyncOffsetNanos, long presentationDeadlineNanos) {
            if (updateActiveModeLocked(sfModeId, renderFrameRate, appVsyncOffsetNanos,
                    presentationDeadlineNanos)) {
                updateDeviceInfoLocked();
            }
        }
@@ -1232,9 +1255,12 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            }
        }

        public boolean updateActiveModeLocked(int activeSfModeId, float renderFrameRate) {
        public boolean updateActiveModeLocked(int activeSfModeId, float renderFrameRate,
                long appVsyncOffsetNanos, long presentationDeadlineNanos) {
            if (mActiveSfDisplayMode.id == activeSfModeId
                    && mActiveRenderFrameRate == renderFrameRate) {
                    && mActiveRenderFrameRate == renderFrameRate
                    && mAppVsyncOffsetNanos == appVsyncOffsetNanos
                    && mPresentationDeadlineNanos == presentationDeadlineNanos) {
                return false;
            }
            mActiveSfDisplayMode = getModeById(mSfDisplayModes, activeSfModeId);
@@ -1244,6 +1270,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
                        + ", activeModeId=" + activeSfModeId);
            }
            mActiveRenderFrameRate = renderFrameRate;
            mAppVsyncOffsetNanos = appVsyncOffsetNanos;
            mPresentationDeadlineNanos = presentationDeadlineNanos;
            return true;
        }

@@ -1359,6 +1387,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
            }
            pw.println("mActiveSfDisplayMode=" + mActiveSfDisplayMode);
            pw.println("mActiveRenderFrameRate=" + mActiveRenderFrameRate);
            pw.println("mAppVsyncOffsetNanos=" + mAppVsyncOffsetNanos);
            pw.println("mPresentationDeadlineNanos=" + mPresentationDeadlineNanos);
            pw.println("mSupportedModes=");
            for (int i = 0; i < mSupportedModes.size(); i++) {
                pw.println("  " + mSupportedModes.valueAt(i));
@@ -1574,7 +1604,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
        void onHotplug(long timestampNanos, long physicalDisplayId, boolean connected);
        void onHotplugConnectionError(long timestampNanos, int connectionError);
        void onModeChanged(long timestampNanos, long physicalDisplayId, int modeId,
                long renderPeriod);
                long renderPeriod, long appVsyncOffsetNanos, long presentationDeadlineNanos);
        void onFrameRateOverridesChanged(long timestampNanos, long physicalDisplayId,
                DisplayEventReceiver.FrameRateOverride[] overrides);
        void onHdcpLevelsChanged(long physicalDisplayId, int connectedLevel, int maxLevel);
@@ -1602,8 +1632,9 @@ final class LocalDisplayAdapter extends DisplayAdapter {

        @Override
        public void onModeChanged(long timestampNanos, long physicalDisplayId, int modeId,
                long renderPeriod) {
            mListener.onModeChanged(timestampNanos, physicalDisplayId, modeId, renderPeriod);
                long renderPeriod, long appVsyncOffsetNanos, long presentationDeadlineNanos) {
            mListener.onModeChanged(timestampNanos, physicalDisplayId, modeId,
                    renderPeriod, appVsyncOffsetNanos, presentationDeadlineNanos);
        }

        @Override
@@ -1643,13 +1674,15 @@ final class LocalDisplayAdapter extends DisplayAdapter {

        @Override
        public void onModeChanged(long timestampNanos, long physicalDisplayId, int modeId,
                long renderPeriod) {
                long renderPeriod, long appVsyncOffsetNanos, long presentationDealineNanos) {
            if (DEBUG) {
                Slog.d(TAG, "onModeChanged("
                        + "timestampNanos=" + timestampNanos
                        + ", physicalDisplayId=" + physicalDisplayId
                        + ", modeId=" + modeId
                        + ", renderPeriod=" + renderPeriod + ")");
                        + ", renderPeriod=" + renderPeriod
                        + ", appVsyncOffsetNanos=" + appVsyncOffsetNanos
                        + ", presentationDealineNanos=" + presentationDealineNanos + ")");
            }
            synchronized (getSyncRoot()) {
                LocalDisplayDevice device = mDevices.get(physicalDisplayId);
@@ -1661,7 +1694,8 @@ final class LocalDisplayAdapter extends DisplayAdapter {
                    return;
                }
                float renderFrameRate = 1e9f / renderPeriod;
                device.onActiveDisplayModeChangedLocked(modeId, renderFrameRate);
                device.onActiveDisplayModeChangedLocked(modeId, renderFrameRate,
                        appVsyncOffsetNanos, presentationDealineNanos);
            }
        }

+8 −2
Original line number Diff line number Diff line
@@ -879,7 +879,10 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                            | LOGICAL_DISPLAY_EVENT_STATE_CHANGED;
                }
            } else if (hasBasicInfoChanged
                    || mTempDisplayInfo.getRefreshRate() != newDisplayInfo.getRefreshRate()) {
                    || mTempDisplayInfo.getRefreshRate() != newDisplayInfo.getRefreshRate()
                    || mTempDisplayInfo.appVsyncOffsetNanos != newDisplayInfo.appVsyncOffsetNanos
                    || mTempDisplayInfo.presentationDeadlineNanos
                    != newDisplayInfo.presentationDeadlineNanos) {
                // If only the hdr/sdr ratio changed, then send just the event for that case
                if ((diff == DisplayDeviceInfo.DIFF_HDR_SDR_RATIO)) {
                    logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_HDR_SDR_RATIO_CHANGED;
@@ -973,7 +976,10 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
    @VisibleForTesting
    int updateAndGetMaskForDisplayPropertyChanges(DisplayInfo newDisplayInfo) {
        int mask = LOGICAL_DISPLAY_EVENT_BASE;
        if (mTempDisplayInfo.getRefreshRate() != newDisplayInfo.getRefreshRate()) {
        if (mTempDisplayInfo.getRefreshRate() != newDisplayInfo.getRefreshRate()
                || mTempDisplayInfo.appVsyncOffsetNanos != newDisplayInfo.appVsyncOffsetNanos
                || mTempDisplayInfo.presentationDeadlineNanos
                != newDisplayInfo.presentationDeadlineNanos) {
            mask |= LOGICAL_DISPLAY_EVENT_REFRESH_RATE_CHANGED;
        }

+10 −0
Original line number Diff line number Diff line
@@ -290,6 +290,11 @@ public class DisplayManagerFlags {
            Flags::delayImplicitRrRegistrationUntilRrAccessed
    );

    private final FlagState mDispatchDisplayModeWithVsyncOffsets = new FlagState(
            Flags.FLAG_ENABLE_ON_MODE_CHANGED_VSYNC_PHASE_OFFSET,
            Flags::enableOnModeChangedVsyncPhaseOffset
    );

    /**
     * @return {@code true} if 'port' is allowed in display layout configuration file.
     */
@@ -627,6 +632,10 @@ public class DisplayManagerFlags {
        return mDelayImplicitRrRegistrationUntilRrAccessed.isEnabled();
    }

    public boolean isDispatchDisplayModeWithVsyncOffsetsEnabled() {
        return mDispatchDisplayModeWithVsyncOffsets.isEnabled();
    }

    /**
     * dumps all flagstates
     * @param pw printWriter
@@ -686,6 +695,7 @@ public class DisplayManagerFlags {
        pw.println(" " + mCommittedStateSeparateEvent);
        pw.println(" " + mSeparateTimeouts);
        pw.println(" " + mDelayImplicitRrRegistrationUntilRrAccessed);
        pw.println(" " + mDispatchDisplayModeWithVsyncOffsets);
    }

    private static class FlagState {
Loading