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

Commit d288f0cf authored by Fiona Campbell's avatar Fiona Campbell
Browse files

Destroy EGL context on colorfade.stop

- Create colorfade.stop
- Call when we destroy a dpc / display power state

Bug: 294800371
Test: atest DisplayServiceTests
Change-Id: I60226f55a8d819c6f74e1dcc782b9c4201dcba4b
Merged-In: I60226f55a8d819c6f74e1dcc782b9c4201dcba4b
parent 071a9f92
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -401,6 +401,12 @@ final class ColorFade {
        }
    }

    void stop() {
        if (mEglContext != null && mEglDisplay != null) {
            EGL14.eglDestroyContext(mEglDisplay, mEglContext);
        }
    }

    /**
     * Draws an animation frame showing the color fade activated at the
     * specified level.
+2 −1
Original line number Diff line number Diff line
@@ -3519,7 +3519,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

        DisplayPowerState getDisplayPowerState(DisplayBlanker blanker, ColorFade colorFade,
                int displayId, int displayState) {
            return new DisplayPowerState(blanker, colorFade, displayId, displayState);
            return new DisplayPowerState(blanker, colorFade, displayId, displayState,
                    new Handler(/*async=*/ true));
        }

        DualRampAnimator<DisplayPowerState> getDualRampAnimator(DisplayPowerState dps,
+2 −3
Original line number Diff line number Diff line
@@ -324,8 +324,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
    // Must only be accessed on the handler thread.
    private DisplayPowerState mPowerState;



    // The currently active screen on unblocker.  This field is non-null whenever
    // we are waiting for a callback to release it and unblock the screen.
    private ScreenOnUnblocker mPendingScreenOnUnblocker;
@@ -2884,7 +2882,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal

        DisplayPowerState getDisplayPowerState(DisplayBlanker blanker, ColorFade colorFade,
                int displayId, int displayState) {
            return new DisplayPowerState(blanker, colorFade, displayId, displayState);
            return new DisplayPowerState(blanker, colorFade, displayId, displayState,
                    new Handler(/*async=*/ true));
        }

        DualRampAnimator<DisplayPowerState> getDualRampAnimator(DisplayPowerState dps,
+9 −2
Original line number Diff line number Diff line
@@ -74,8 +74,9 @@ final class DisplayPowerState {
    private volatile boolean mStopped;

    DisplayPowerState(
            DisplayBlanker blanker, ColorFade colorFade, int displayId, int displayState) {
        mHandler = new Handler(true /*async*/);
            DisplayBlanker blanker, ColorFade colorFade, int displayId, int displayState,
            Handler handler) {
        mHandler = handler;
        mChoreographer = Choreographer.getInstance();
        mBlanker = blanker;
        mColorFade = colorFade;
@@ -317,6 +318,7 @@ final class DisplayPowerState {
        mStopped = true;
        mPhotonicModulator.interrupt();
        dismissColorFade();
        stopColorFade();
        mCleanListener = null;
        mHandler.removeCallbacksAndMessages(null);
    }
@@ -376,6 +378,11 @@ final class DisplayPowerState {
        }
    }

    // Clears up color fade resources.
    private void stopColorFade() {
        if (mColorFade != null) mColorFade.stop();
    }

    private final Runnable mScreenUpdateRunnable = new Runnable() {
        @Override
        public void run() {
+15 −0
Original line number Diff line number Diff line
@@ -1104,6 +1104,21 @@ public final class DisplayPowerController2Test {
        verify(mDisplayWhiteBalanceControllerMock, times(1)).setStrongModeEnabled(true);
    }

    @Test
    public void testPowerStateStopsOnDpcStop() {
        // Set up
        DisplayPowerRequest dpr = new DisplayPowerRequest();
        mHolder.dpc.requestPowerState(dpr, /* waitForNegativeProximity= */ false);
        advanceTime(1);

        // Stop dpc
        mHolder.dpc.stop();
        advanceTime(1);

        // Ensure dps has stopped
        verify(mHolder.displayPowerState, times(1)).stop();
    }

    /**
     * Creates a mock and registers it to {@link LocalServices}.
     */
Loading