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

Commit 46170518 authored by Alec Mouri's avatar Alec Mouri
Browse files

[ADisplay] Expose preferred WCG format per-display

This mirrors the api exposed by the SDK.

Similarly to the other ADisplay apis, the intention is that these apis
will be #apex stable, but the map file doesn't need to be updated until
HWUI is shipping in an updatable module.

Bug: 144505134
Test: builds
Change-Id: I2a06e4c304edb28d4580ef0aef4431ec8df2d94e
parent 738f785d
Loading
Loading
Loading
Loading
+39 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <gui/SurfaceComposerClient.h>
#include <ui/DisplayInfo.h>
#include <ui/GraphicTypes.h>
#include <ui/PixelFormat.h>

#include <algorithm>
#include <optional>
@@ -81,6 +82,16 @@ struct DisplayImpl {
     */
    ADisplayType type;

    /**
     * The preferred WCG dataspace
     */
    ADataSpace wcgDataspace;

    /**
     * The preferred WCG pixel format
     */
    AHardwareBuffer_Format wcgPixelFormat;

    /**
     * Number of supported configs
     */
@@ -151,6 +162,17 @@ int ADisplay_acquirePhysicalDisplays(ADisplay*** outDisplays) {

    const std::optional<PhysicalDisplayId> internalId =
            SurfaceComposerClient::getInternalDisplayId();
    ui::Dataspace defaultDataspace;
    ui::PixelFormat defaultPixelFormat;
    ui::Dataspace wcgDataspace;
    ui::PixelFormat wcgPixelFormat;

    const status_t status =
            SurfaceComposerClient::getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
                                                            &wcgDataspace, &wcgPixelFormat);
    if (status != NO_ERROR) {
        return status;
    }

    // Here we allocate all our required memory in one block. The layout is as
    // follows:
@@ -176,7 +198,12 @@ int ADisplay_acquirePhysicalDisplays(ADisplay*** outDisplays) {
        const std::vector<DisplayConfigImpl>& configs = configsPerDisplay[i];
        memcpy(configData, configs.data(), sizeof(DisplayConfigImpl) * configs.size());

        displayData[i] = DisplayImpl{id, type, configs.size(), configData};
        displayData[i] = DisplayImpl{id,
                                     type,
                                     static_cast<ADataSpace>(wcgDataspace),
                                     static_cast<AHardwareBuffer_Format>(wcgPixelFormat),
                                     configs.size(),
                                     configData};
        impls[i] = displayData + i;
        // Advance the configData pointer so that future configs are written to
        // the correct display.
@@ -210,6 +237,17 @@ ADisplayType ADisplay_getDisplayType(ADisplay* display) {
    return reinterpret_cast<DisplayImpl*>(display)->type;
}

void ADisplay_getPreferredWideColorFormat(ADisplay* display, ADataSpace* outDataspace,
                                          AHardwareBuffer_Format* outPixelFormat) {
    CHECK_NOT_NULL(display);
    CHECK_NOT_NULL(outDataspace);
    CHECK_NOT_NULL(outPixelFormat);

    DisplayImpl* impl = reinterpret_cast<DisplayImpl*>(display);
    *outDataspace = impl->wcgDataspace;
    *outPixelFormat = impl->wcgPixelFormat;
}

int ADisplay_getCurrentConfig(ADisplay* display, ADisplayConfig** outConfig) {
    CHECK_NOT_NULL(display);

+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ cc_library {
        "libandroidfw",
        "libgui",
        "liblog",
        "libnativewindow",
        "libui",
        "libutils",
    ],
+8 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#pragma once

#include <android/data_space.h>
#include <android/hardware_buffer.h>
#include <inttypes.h>

__BEGIN_DECLS
@@ -71,6 +73,12 @@ float ADisplay_getMaxSupportedFps(ADisplay* display);
 */
ADisplayType ADisplay_getDisplayType(ADisplay* display);

/**
 * Queries the display's preferred WCG format
 */
void ADisplay_getPreferredWideColorFormat(ADisplay* display, ADataSpace* outDataspace,
                                          AHardwareBuffer_Format* outPixelFormat);

/**
 * Gets the current display configuration for the given display.
 *