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

Commit 463ad8ee authored by Marin Shalamanov's avatar Marin Shalamanov
Browse files

Introduce DynamicDisplayInfo

In this CL we introduce SurfaceContorl.getDynamicDisplayInfo
which replaces the current seprate calls for supported and
active display mode, supproted and active color modes and
HDR capabilities.

This way display capabilities can be queried atomically.

Additionally this CL pipes an DisplayMode IDs from
SurfaceFlinger and updates LocalDislayAdapter to use
IDs instead of array indices.

Test: presubmit
Bug: 159590486
Bug: 175678215
Change-Id: I169e3055d07905e2330e11f158b61ffd366f97e6
parent efbe5db9
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@
#include <gui/SurfaceComposerClient.h>
#include <gui/SyncScreenCaptureListener.h>

#include <ui/DisplayInfo.h>
#include <ui/GraphicTypes.h>
#include <ui/PixelFormat.h>

+78 −56
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -161,25 +162,21 @@ public final class SurfaceControl implements Parcelable {
            int L, int T, int R, int B);
    private static native void nativeSetDisplaySize(long transactionObj, IBinder displayToken,
            int width, int height);
    private static native DisplayInfo nativeGetDisplayInfo(IBinder displayToken);
    private static native DisplayMode[] nativeGetDisplayModes(
            IBinder displayToken);
    private static native StaticDisplayInfo nativeGetStaticDisplayInfo(IBinder displayToken);
    private static native DynamicDisplayInfo nativeGetDynamicDisplayInfo(IBinder displayToken);
    private static native DisplayedContentSamplingAttributes
            nativeGetDisplayedContentSamplingAttributes(IBinder displayToken);
    private static native boolean nativeSetDisplayedContentSamplingEnabled(IBinder displayToken,
            boolean enable, int componentMask, int maxFrames);
    private static native DisplayedContentSample nativeGetDisplayedContentSample(
            IBinder displayToken, long numFrames, long timestamp);
    private static native int nativeGetActiveDisplayMode(IBinder displayToken);
    private static native boolean nativeSetDesiredDisplayModeSpecs(IBinder displayToken,
            DesiredDisplayModeSpecs desiredDisplayModeSpecs);
    private static native DesiredDisplayModeSpecs
            nativeGetDesiredDisplayModeSpecs(IBinder displayToken);
    private static native int[] nativeGetDisplayColorModes(IBinder displayToken);
    private static native DisplayPrimaries nativeGetDisplayNativePrimaries(
            IBinder displayToken);
    private static native int[] nativeGetCompositionDataspaces();
    private static native int nativeGetActiveColorMode(IBinder displayToken);
    private static native boolean nativeSetActiveColorMode(IBinder displayToken,
            int colorMode);
    private static native void nativeSetAutoLowLatencyMode(IBinder displayToken, boolean on);
@@ -191,8 +188,6 @@ public final class SurfaceControl implements Parcelable {
    private static native void nativeReparent(long transactionObj, long nativeObject,
            long newParentNativeObject);

    private static native Display.HdrCapabilities nativeGetHdrCapabilities(IBinder displayToken);

    private static native boolean nativeGetAutoLowLatencyModeSupport(IBinder displayToken);
    private static native boolean nativeGetGameContentTypeSupport(IBinder displayToken);

@@ -1707,7 +1702,7 @@ public final class SurfaceControl implements Parcelable {
     *
     * @hide
     */
    public static final class DisplayInfo {
    public static final class StaticDisplayInfo {
        public boolean isInternal;
        public float density;
        public boolean secure;
@@ -1715,7 +1710,7 @@ public final class SurfaceControl implements Parcelable {

        @Override
        public String toString() {
            return "DisplayInfo{isInternal=" + isInternal
            return "StaticDisplayInfo{isInternal=" + isInternal
                    + ", density=" + density
                    + ", secure=" + secure
                    + ", deviceProductInfo=" + deviceProductInfo + "}";
@@ -1725,7 +1720,7 @@ public final class SurfaceControl implements Parcelable {
        public boolean equals(@Nullable Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            DisplayInfo that = (DisplayInfo) o;
            StaticDisplayInfo that = (StaticDisplayInfo) o;
            return isInternal == that.isInternal
                    && density == that.density
                    && secure == that.secure
@@ -1738,6 +1733,49 @@ public final class SurfaceControl implements Parcelable {
        }
    }

    /**
     * Dynamic information about physical display.
     *
     * @hide
     */
    public static final class DynamicDisplayInfo {
        public DisplayMode[] supportedDisplayModes;
        public int activeDisplayModeId;

        public int[] supportedColorModes;
        public int activeColorMode;

        public Display.HdrCapabilities hdrCapabilities;

        @Override
        public String toString() {
            return "DynamicDisplayInfo{"
                    + "supportedDisplayModes=" + Arrays.toString(supportedDisplayModes)
                    + ", activeDisplayModeId=" + activeDisplayModeId
                    + ", supportedColorModes=" + Arrays.toString(supportedColorModes)
                    + ", activeColorMode=" + activeColorMode
                    + ", hdrCapabilities=" + hdrCapabilities + "}";
        }

        @Override
        public boolean equals(@Nullable Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            DynamicDisplayInfo that = (DynamicDisplayInfo) o;
            return Arrays.equals(supportedDisplayModes, that.supportedDisplayModes)
                && activeDisplayModeId == that.activeDisplayModeId
                && Arrays.equals(supportedColorModes, that.supportedColorModes)
                && activeColorMode == that.activeColorMode
                && Objects.equals(hdrCapabilities, that.hdrCapabilities);
        }

        @Override
        public int hashCode() {
            return Objects.hash(supportedDisplayModes, activeDisplayModeId, activeDisplayModeId,
                    activeColorMode, hdrCapabilities);
        }
    }

    /**
     * Configuration supported by physical display.
     *
@@ -1749,6 +1787,7 @@ public final class SurfaceControl implements Parcelable {
         */
        public static final int INVALID_DISPLAY_MODE_ID = -1;

        public int id;
        public int width;
        public int height;
        public float xDpi;
@@ -1768,7 +1807,8 @@ public final class SurfaceControl implements Parcelable {

        @Override
        public String toString() {
            return "DisplayConfig{width=" + width
            return "DisplayMode{id=" + id
                    + ", width=" + width
                    + ", height=" + height
                    + ", xDpi=" + xDpi
                    + ", yDpi=" + yDpi
@@ -1777,46 +1817,58 @@ public final class SurfaceControl implements Parcelable {
                    + ", presentationDeadlineNanos=" + presentationDeadlineNanos
                    + ", group=" + group + "}";
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            DisplayMode that = (DisplayMode) o;
            return id == that.id
                    && width == that.width
                    && height == that.height
                    && Float.compare(that.xDpi, xDpi) == 0
                    && Float.compare(that.yDpi, yDpi) == 0
                    && Float.compare(that.refreshRate, refreshRate) == 0
                    && appVsyncOffsetNanos == that.appVsyncOffsetNanos
                    && presentationDeadlineNanos == that.presentationDeadlineNanos
                    && group == that.group;
        }

    /**
     * @hide
     */
    public static void setDisplayPowerMode(IBinder displayToken, int mode) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        @Override
        public int hashCode() {
            return Objects.hash(id, width, height, xDpi, yDpi, refreshRate, appVsyncOffsetNanos,
                    presentationDeadlineNanos, group);
        }
        nativeSetDisplayPowerMode(displayToken, mode);
    }

    /**
     * @hide
     */
    public static SurfaceControl.DisplayInfo getDisplayInfo(IBinder displayToken) {
    public static void setDisplayPowerMode(IBinder displayToken, int mode) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        return nativeGetDisplayInfo(displayToken);
        nativeSetDisplayPowerMode(displayToken, mode);
    }

    /**
     * @hide
     */
    public static DisplayMode[] getDisplayModes(IBinder displayToken) {
    public static StaticDisplayInfo getStaticDisplayInfo(IBinder displayToken) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        return nativeGetDisplayModes(displayToken);
        return nativeGetStaticDisplayInfo(displayToken);
    }

    /**
     * @hide
     */
    public static int getActiveDisplayMode(IBinder displayToken) {
    public static DynamicDisplayInfo getDynamicDisplayInfo(IBinder displayToken) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        return nativeGetActiveDisplayMode(displayToken);
        return nativeGetDynamicDisplayInfo(displayToken);
    }

    /**
@@ -1977,16 +2029,6 @@ public final class SurfaceControl implements Parcelable {
        return nativeGetDesiredDisplayModeSpecs(displayToken);
    }

    /**
     * @hide
     */
    public static int[] getDisplayColorModes(IBinder displayToken) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        return nativeGetDisplayColorModes(displayToken);
    }

    /**
     * Color coordinates in CIE1931 XYZ color space
     *
@@ -2054,16 +2096,6 @@ public final class SurfaceControl implements Parcelable {
        return nativeGetDisplayNativePrimaries(displayToken);
    }

    /**
     * @hide
     */
    public static int getActiveColorMode(IBinder displayToken) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        return nativeGetActiveColorMode(displayToken);
    }

    /**
     * @hide
     */
@@ -2166,16 +2198,6 @@ public final class SurfaceControl implements Parcelable {
        }
    }

    /**
     * @hide
     */
    public static Display.HdrCapabilities getHdrCapabilities(IBinder displayToken) {
        if (displayToken == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }
        return nativeGetHdrCapabilities(displayToken);
    }

    /**
     * @hide
     */
+128 −110

File changed.

Preview size limit exceeded, changes collapsed.

+4 −4
Original line number Diff line number Diff line
@@ -22,16 +22,16 @@ namespace android {
namespace uirenderer {
namespace test {

const DisplayInfo& getDisplayInfo() {
    static DisplayInfo info = [] {
        DisplayInfo info;
const ui::StaticDisplayInfo& getDisplayInfo() {
    static ui::StaticDisplayInfo info = [] {
        ui::StaticDisplayInfo info;
#if HWUI_NULL_GPU
        info.density = 2.f;
#else
        const sp<IBinder> token = SurfaceComposerClient::getInternalDisplayToken();
        LOG_ALWAYS_FATAL_IF(!token, "%s: No internal display", __FUNCTION__);

        const status_t status = SurfaceComposerClient::getDisplayInfo(token, &info);
        const status_t status = SurfaceComposerClient::getStaticDisplayInfo(token, &info);
        LOG_ALWAYS_FATAL_IF(status, "%s: Failed to get display info", __FUNCTION__);
#endif
        return info;
+2 −2
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/SurfaceControl.h>
#include <ui/DisplayInfo.h>
#include <ui/DisplayMode.h>
#include <ui/StaticDisplayInfo.h>
#include <utils/Looper.h>

#include <atomic>
@@ -36,7 +36,7 @@ namespace android {
namespace uirenderer {
namespace test {

const DisplayInfo& getDisplayInfo();
const ui::StaticDisplayInfo& getDisplayInfo();
const ui::DisplayMode& getActiveDisplayMode();

inline const ui::Size& getActiveDisplayResolution() {
Loading