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

Commit bcbd52a5 authored by petsjonkin's avatar petsjonkin
Browse files

ColorFade : destroy egl context with DisplayPowerState

Verified that no switch display regression itroduced (details in the bug)
Details in bug comment 19

Bug: b/294800371
Test: atest DisplayPowerStateTest

Change-Id: Icca0fcee46e180a08de115ba83ca2d2270878afb
parent fc49c4e6
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -410,6 +410,33 @@ final class ColorFade {
        }
    }

    /**
     * Destroys ColorFade animation and its resources
     *
     * This method should be called when the ColorFade is no longer in use; i.e. when
     * the {@link #mDisplayId display} has been removed.
     */
    public void destroy() {
        if (DEBUG) {
            Slog.d(TAG, "destroy");
        }
        if (mPrepared) {
            if (mCreatedResources) {
                attachEglContext();
                try {
                    destroyScreenshotTexture();
                    destroyGLShaders();
                    destroyGLBuffers();
                    destroyEglSurface();
                } finally {
                    detachEglContext();
                }
            }
            destroyEglContext();
            destroySurface();
        }
    }

    /**
     * Draws an animation frame showing the color fade activated at the
     * specified level.
@@ -793,6 +820,12 @@ final class ColorFade {
        }
    }

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

    private static FloatBuffer createNativeFloatBuffer(int size) {
        ByteBuffer bb = ByteBuffer.allocateDirect(size * 4);
        bb.order(ByteOrder.nativeOrder());
+3 −1
Original line number Diff line number Diff line
@@ -320,7 +320,9 @@ final class DisplayPowerState {
    public void stop() {
        mStopped = true;
        mPhotonicModulator.interrupt();
        dismissColorFade();
        if (mColorFade != null) {
            mColorFade.destroy();
        }
        mCleanListener = null;
        mHandler.removeCallbacksAndMessages(null);
    }
+3 −8
Original line number Diff line number Diff line
@@ -7,19 +7,12 @@ package {
    default_applicable_licenses: ["frameworks_base_license"],
}

// Include all test java files.
filegroup {
    name: "displayservicetests-sources",
    srcs: [
        "src/**/*.java",
    ],
}

android_test {
    name: "DisplayServiceTests",

    srcs: [
        "src/**/*.java",
        "src/**/*.kt",
    ],

    libs: [
@@ -33,6 +26,8 @@ android_test {
        "frameworks-base-testutils",
        "junit",
        "junit-params",
        "kotlin-test",
        "mockito-kotlin2",
        "mockingservicestests-utils-mockito",
        "platform-compat-test-rules",
        "platform-test-annotations",
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.display

import android.view.Display
import androidx.test.filters.SmallTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.junit.MockitoJUnit

import org.mockito.kotlin.mock
import org.mockito.kotlin.verify

@SmallTest
class DisplayPowerStateTest {

    private lateinit var displayPowerState: DisplayPowerState

    @get:Rule
    val mockitoRule = MockitoJUnit.rule()

    private val mockBlanker = mock<DisplayBlanker>()
    private val mockColorFade = mock<ColorFade>()

    @Before
    fun setUp() {
        displayPowerState = DisplayPowerState(mockBlanker, mockColorFade, 123, Display.STATE_ON)
    }

    @Test
    fun `destroys ColorFade on stop`() {
        displayPowerState.stop()

        verify(mockColorFade).destroy()
    }
}
 No newline at end of file