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

Commit c7247a01 authored by Alan Ding's avatar Alan Ding Committed by Android (Google) Code Review
Browse files

Merge "DM: Cleanup SF APIs for creating / destroying virtual display" into main

parents 10ce3491 5cc13f57
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -28,9 +28,9 @@ import java.util.Objects;
 * Calls into SurfaceFlinger for Display creation and deletion.
 */
public class DisplayControl {
    private static native IBinder nativeCreateDisplay(String name, boolean secure,
    private static native IBinder nativeCreateVirtualDisplay(String name, boolean secure,
            String uniqueId, float requestedRefreshRate);
    private static native void nativeDestroyDisplay(IBinder displayToken);
    private static native void nativeDestroyVirtualDisplay(IBinder displayToken);
    private static native void nativeOverrideHdrTypes(IBinder displayToken, int[] modes);
    private static native long[] nativeGetPhysicalDisplayIds();
    private static native IBinder nativeGetPhysicalDisplayToken(long physicalDisplayId);
@@ -41,21 +41,21 @@ public class DisplayControl {
    private static native boolean nativeGetHdrOutputConversionSupport();

    /**
     * Create a display in SurfaceFlinger.
     * Create a virtual display in SurfaceFlinger.
     *
     * @param name The name of the display.
     * @param name The name of the virtual display.
     * @param secure Whether this display is secure.
     * @return The token reference for the display in SurfaceFlinger.
     */
    public static IBinder createDisplay(String name, boolean secure) {
    public static IBinder createVirtualDisplay(String name, boolean secure) {
        Objects.requireNonNull(name, "name must not be null");
        return nativeCreateDisplay(name, secure, "", 0.0f);
        return nativeCreateVirtualDisplay(name, secure, "", 0.0f);
    }

    /**
     * Create a display in SurfaceFlinger.
     * Create a virtual display in SurfaceFlinger.
     *
     * @param name The name of the display.
     * @param name The name of the virtual display.
     * @param secure Whether this display is secure.
     * @param uniqueId The unique ID for the display.
     * @param requestedRefreshRate The requested refresh rate in frames per second.
@@ -65,23 +65,23 @@ public class DisplayControl {
     * display is refreshed at the physical display refresh rate.
     * @return The token reference for the display in SurfaceFlinger.
     */
    public static IBinder createDisplay(String name, boolean secure,
    public static IBinder createVirtualDisplay(String name, boolean secure,
            String uniqueId, float requestedRefreshRate) {
        Objects.requireNonNull(name, "name must not be null");
        Objects.requireNonNull(uniqueId, "uniqueId must not be null");
        return nativeCreateDisplay(name, secure, uniqueId, requestedRefreshRate);
        return nativeCreateVirtualDisplay(name, secure, uniqueId, requestedRefreshRate);
    }

    /**
     * Destroy a display in SurfaceFlinger.
     * Destroy a virtual display in SurfaceFlinger.
     *
     * @param displayToken The display token for the display to be destroyed.
     * @param displayToken The display token for the virtual display to be destroyed.
     */
    public static void destroyDisplay(IBinder displayToken) {
    public static void destroyVirtualDisplay(IBinder displayToken) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        nativeDestroyDisplay(displayToken);
        nativeDestroyVirtualDisplay(displayToken);
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -309,7 +309,7 @@ final class OverlayDisplayAdapter extends DisplayAdapter {
                mSurface.release();
                mSurface = null;
            }
            DisplayControl.destroyDisplay(getDisplayTokenLocked());
            DisplayControl.destroyVirtualDisplay(getDisplayTokenLocked());
        }

        @Override
@@ -467,7 +467,7 @@ final class OverlayDisplayAdapter extends DisplayAdapter {
        public void onWindowCreated(SurfaceTexture surfaceTexture, float refreshRate,
                long presentationDeadlineNanos, int state) {
            synchronized (getSyncRoot()) {
                IBinder displayToken = DisplayControl.createDisplay(mName, mFlags.mSecure);
                IBinder displayToken = DisplayControl.createVirtualDisplay(mName, mFlags.mSecure);
                mDevice = new OverlayDisplayDevice(displayToken, mName, mModes, mActiveMode,
                        DEFAULT_MODE_INDEX, refreshRate, presentationDeadlineNanos,
                        mFlags, state, surfaceTexture, mNumber) {
+3 −2
Original line number Diff line number Diff line
@@ -94,12 +94,13 @@ public class VirtualDisplayAdapter extends DisplayAdapter {
            @Override
            public IBinder createDisplay(String name, boolean secure, String uniqueId,
                                         float requestedRefreshRate) {
                return DisplayControl.createDisplay(name, secure, uniqueId, requestedRefreshRate);
                return DisplayControl.createVirtualDisplay(name, secure, uniqueId,
                                                           requestedRefreshRate);
            }

            @Override
            public void destroyDisplay(IBinder displayToken) {
                DisplayControl.destroyDisplay(displayToken);
                DisplayControl.destroyVirtualDisplay(displayToken);
            }
        }, featureFlags);
    }
+4 −4
Original line number Diff line number Diff line
@@ -392,9 +392,9 @@ final class WifiDisplayAdapter extends DisplayAdapter {

        float refreshRate = 60.0f; // TODO: get this for real

        String name = display.getFriendlyDisplayName();
        String address = display.getDeviceAddress();
        IBinder displayToken = DisplayControl.createDisplay(name, secure);
        final String name = display.getFriendlyDisplayName();
        final String address = display.getDeviceAddress();
        IBinder displayToken = DisplayControl.createVirtualDisplay(name, secure);
        mDisplayDevice = new WifiDisplayDevice(displayToken, name, width, height,
                refreshRate, deviceFlags, address, surface);
        sendDisplayDeviceEventLocked(mDisplayDevice, DISPLAY_DEVICE_EVENT_ADDED);
@@ -631,7 +631,7 @@ final class WifiDisplayAdapter extends DisplayAdapter {
                mSurface.release();
                mSurface = null;
            }
            DisplayControl.destroyDisplay(getDisplayTokenLocked());
            DisplayControl.destroyVirtualDisplay(getDisplayTokenLocked());
        }

        public void setNameLocked(String name) {
+13 −11
Original line number Diff line number Diff line
@@ -23,20 +23,22 @@

namespace android {

static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj, jboolean secure,
                                   jstring uniqueIdStr, jfloat requestedRefreshRate) {
static jobject nativeCreateVirtualDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
                                          jboolean secure, jstring uniqueIdStr,
                                          jfloat requestedRefreshRate) {
    const ScopedUtfChars name(env, nameObj);
    const ScopedUtfChars uniqueId(env, uniqueIdStr);
    sp<IBinder> token(SurfaceComposerClient::createDisplay(String8(name.c_str()), bool(secure),
    sp<IBinder> token(SurfaceComposerClient::createVirtualDisplay(std::string(name.c_str()),
                                                                  bool(secure),
                                                                  std::string(uniqueId.c_str()),
                                                                  requestedRefreshRate));
    return javaObjectForIBinder(env, token);
}

static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
static void nativeDestroyVirtualDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
    sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
    if (token == NULL) return;
    SurfaceComposerClient::destroyDisplay(token);
    SurfaceComposerClient::destroyVirtualDisplay(token);
}

static void nativeOverrideHdrTypes(JNIEnv* env, jclass clazz, jobject tokenObject,
@@ -180,10 +182,10 @@ static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong ph

static const JNINativeMethod sDisplayMethods[] = {
        // clang-format off
    {"nativeCreateDisplay", "(Ljava/lang/String;ZLjava/lang/String;F)Landroid/os/IBinder;",
            (void*)nativeCreateDisplay },
    {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
            (void*)nativeDestroyDisplay },
    {"nativeCreateVirtualDisplay", "(Ljava/lang/String;ZLjava/lang/String;F)Landroid/os/IBinder;",
            (void*)nativeCreateVirtualDisplay },
    {"nativeDestroyVirtualDisplay", "(Landroid/os/IBinder;)V",
            (void*)nativeDestroyVirtualDisplay },
    {"nativeOverrideHdrTypes", "(Landroid/os/IBinder;[I)V",
                (void*)nativeOverrideHdrTypes },
    {"nativeGetPhysicalDisplayIds", "()[J",