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

Commit 31b5ac21 authored by Huihong Luo's avatar Huihong Luo
Browse files

Remove internal display related methods

SurfaceFlinger and SurfaceComposerClient simply return the first
connected display as internal display, which is not really correct.
In particular,in the case of dual display for foldable devices, both
displays are marked as Internal determined by calling into HWC2
IComposerClient::getDisplayConnectionType().

Therefore, the concept of internal/external/primary displays is removed
from SurfaceFlinger, and the display manager is the better place to
handle the logics.

flatland is modified to take an extra argument to specify display id,
and error occurs if no display is specified in case of multi-display.

Bug: 241285477
Bug: 242763577
Bug: 74619554
Test: atest libgui_test libsurfaceflinger_unittest SurfaceFlinger_test
Change-Id: Ib6c7e502ef3269c2c60a4e5388e5ac75275f87ed
parent 5a0d7d49
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -35,9 +35,12 @@ GLHelper::GLHelper() :
GLHelper::~GLHelper() {
}

bool GLHelper::setUp(const ShaderDesc* shaderDescs, size_t numShaders) {
bool GLHelper::setUp(const sp<IBinder>& displayToken, const ShaderDesc* shaderDescs,
                     size_t numShaders) {
    bool result;

    mDisplayToken = displayToken;

    mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (mDisplay == EGL_NO_DISPLAY) {
        fprintf(stderr, "eglGetDisplay error: %#x\n", eglGetError());
@@ -221,14 +224,8 @@ bool GLHelper::createNamedSurfaceTexture(GLuint name, uint32_t w, uint32_t h,
}

bool GLHelper::computeWindowScale(uint32_t w, uint32_t h, float* scale) {
    const sp<IBinder> dpy = mSurfaceComposerClient->getInternalDisplayToken();
    if (dpy == nullptr) {
        fprintf(stderr, "SurfaceComposer::getInternalDisplayToken failed.\n");
        return false;
    }

    ui::DisplayMode mode;
    status_t err = mSurfaceComposerClient->getActiveDisplayMode(dpy, &mode);
    status_t err = mSurfaceComposerClient->getActiveDisplayMode(mDisplayToken, &mode);
    if (err != NO_ERROR) {
        fprintf(stderr, "SurfaceComposer::getActiveDisplayMode failed: %#x\n", err);
        return false;
+3 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public:

    ~GLHelper();

    bool setUp(const ShaderDesc* shaderDescs, size_t numShaders);
    bool setUp(const sp<IBinder>& displayToken, const ShaderDesc* shaderDescs, size_t numShaders);

    void tearDown();

@@ -87,6 +87,8 @@ private:
    size_t mNumShaders;

    GLuint mDitherTexture;

    sp<IBinder> mDisplayToken;
};

} // namespace android
+52 −12
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <gui/SurfaceControl.h>
#include <gui/GLConsumer.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <ui/Fence.h>
#include <utils/Trace.h>

@@ -37,6 +38,7 @@ using namespace ::android;
static uint32_t    g_SleepBetweenSamplesMs = 0;
static bool        g_PresentToWindow       = false;
static size_t      g_BenchmarkNameLen      = 0;
static sp<IBinder> g_DisplayToken          = nullptr;

struct BenchmarkDesc {
    // The name of the test.
@@ -393,7 +395,7 @@ public:
        uint32_t h = mDesc.runHeights[mInstance];

        mGLHelper = new GLHelper();
        result = mGLHelper->setUp(shaders, NELEMS(shaders));
        result = mGLHelper->setUp(g_DisplayToken, shaders, NELEMS(shaders));
        if (!result) {
            return false;
        }
@@ -720,11 +722,15 @@ static size_t maxBenchmarkNameLen() {
// Print the command usage help to stderr.
static void showHelp(const char* cmd) {
  fprintf(stderr, "usage: %s [options]\n", cmd);
    fprintf(stderr, "options include:\n"
  fprintf(
      stderr,
      "options include:\n"
      "  -s N            sleep for N ms between samples\n"
      "  -d              display the test frame to a window\n"
                    "  --help          print this helpful message and exit\n"
            );
      "  -i display-id   specify a display ID to use for multi-display device\n"
      "                  see \"dumpsys SurfaceFlinger --display-id\" for valid "
      "display IDs\n"
      "  --help          print this helpful message and exit\n");
}

int main(int argc, char** argv) {
@@ -733,6 +739,14 @@ int main(int argc, char** argv) {
        exit(0);
    }

    const auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
    if (ids.empty()) {
        fprintf(stderr, "Failed to get ID for any displays.\n");
        exit(3);
    }

    std::optional<PhysicalDisplayId> displayId;

    for (;;) {
        int ret;
        int option_index = 0;
@@ -741,7 +755,7 @@ int main(int argc, char** argv) {
            {     0,               0, 0,  0 }
        };

        ret = getopt_long(argc, argv, "ds:",
        ret = getopt_long(argc, argv, "ds:i:",
                          long_options, &option_index);

        if (ret < 0) {
@@ -757,6 +771,14 @@ int main(int argc, char** argv) {
                g_SleepBetweenSamplesMs = atoi(optarg);
            break;

            case 'i':
                displayId = DisplayId::fromValue<PhysicalDisplayId>(atoll(optarg));
                if (!displayId) {
                    fprintf(stderr, "Invalid display ID: %s.\n", optarg);
                    exit(4);
                }
            break;

            case 0:
                if (strcmp(long_options[option_index].name, "help")) {
                    showHelp(argv[0]);
@@ -770,6 +792,22 @@ int main(int argc, char** argv) {
        }
    }

    if (!displayId) { // no display id is specified
        if (ids.size() == 1) {
            displayId = ids.front();
        } else {
            fprintf(stderr, "Please specify a display ID for multi-display device.\n");
            showHelp(argv[0]);
            exit(5);
        }
    }

    g_DisplayToken = SurfaceComposerClient::getPhysicalDisplayToken(*displayId);
    if (g_DisplayToken == nullptr) {
        fprintf(stderr, "SurfaceComposer::getPhysicalDisplayToken failed.\n");
        exit(6);
    }

    g_BenchmarkNameLen = maxBenchmarkNameLen();

    printf(" cmdline:");
@@ -782,4 +820,6 @@ int main(int argc, char** argv) {
        fprintf(stderr, "exiting due to error.\n");
        return 1;
    }

    return 0;
}
+17 −20
Original line number Diff line number Diff line
@@ -56,6 +56,12 @@ using ui::Dataspace;

namespace {

enum {
    // moved from nativewindow/include/system/window.h, to be removed
    NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT = 28,
    NATIVE_WINDOW_GET_HDR_SUPPORT = 29,
};

bool isInterceptorRegistrationOp(int op) {
    return op == NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR ||
            op == NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR ||
@@ -348,34 +354,25 @@ status_t Surface::getFrameTimestamps(uint64_t frameNumber,
    return NO_ERROR;
}

// Deprecated(b/242763577): to be removed, this method should not be used
// The reason this method still exists here is to support compiled vndk
// Surface support should not be tied to the display
// Return true since most displays should have this support
status_t Surface::getWideColorSupport(bool* supported) {
    ATRACE_CALL();

    const sp<IBinder> display = ComposerServiceAIDL::getInstance().getInternalDisplayToken();
    if (display == nullptr) {
        return NAME_NOT_FOUND;
    }

    *supported = false;
    binder::Status status = composerServiceAIDL()->isWideColorDisplay(display, supported);
    return statusTFromBinderStatus(status);
    *supported = true;
    return NO_ERROR;
}

// Deprecated(b/242763577): to be removed, this method should not be used
// The reason this method still exists here is to support compiled vndk
// Surface support should not be tied to the display
// Return true since most displays should have this support
status_t Surface::getHdrSupport(bool* supported) {
    ATRACE_CALL();

    const sp<IBinder> display = ComposerServiceAIDL::getInstance().getInternalDisplayToken();
    if (display == nullptr) {
        return NAME_NOT_FOUND;
    }

    gui::DynamicDisplayInfo info;
    if (binder::Status status = composerServiceAIDL()->getDynamicDisplayInfo(display, &info);
        !status.isOk()) {
        return statusTFromBinderStatus(status);
    }

    *supported = !info.hdrCapabilities.supportedHdrTypes.empty();
    *supported = true;
    return NO_ERROR;
}

+0 −10
Original line number Diff line number Diff line
@@ -1091,11 +1091,6 @@ std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
    return physicalDisplayIds;
}

std::optional<PhysicalDisplayId> SurfaceComposerClient::getInternalDisplayId() {
    ComposerServiceAIDL& instance = ComposerServiceAIDL::getInstance();
    return instance.getInternalDisplayId();
}

sp<IBinder> SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId displayId) {
    sp<IBinder> display = nullptr;
    binder::Status status =
@@ -1104,11 +1099,6 @@ sp<IBinder> SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId dis
    return status.isOk() ? display : nullptr;
}

sp<IBinder> SurfaceComposerClient::getInternalDisplayToken() {
    ComposerServiceAIDL& instance = ComposerServiceAIDL::getInstance();
    return instance.getInternalDisplayToken();
}

void SurfaceComposerClient::Transaction::setAnimationTransaction() {
    mAnimation = true;
}
Loading