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

Commit cdd7df92 authored by Robert Carr's avatar Robert Carr
Browse files

SurfaceFlinger::getNewTexture: Don't deadlock on main thread

This codepath may be invoked on the main thread via the
RefreshRateOverlay surface creation codepath. In such case it will
trigger a deadlock as we wait on the main thread to complete while
blocking the main thread. This can be observed by running
RefreshRateOverlayTests with ~5 iterations. It seems safest to just
avoid this deadlock.

Bug: 184991996
Test: Existing tests pass
Change-Id: I3c5c495b8e93761813157840c9878c73bcdee579
parent b7f378a1
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -693,12 +693,16 @@ uint32_t SurfaceFlinger::getNewTexture() {

    // The pool was empty, so we need to get a new texture name directly using a
    // blocking call to the main thread
    return schedule([this] {
    auto genTextures = [this] {
               uint32_t name = 0;
               getRenderEngine().genTextures(1, &name);
               return name;
           })
            .get();
    };
    if (std::this_thread::get_id() == mMainThreadId) {
        return genTextures();
    } else {
        return schedule(genTextures).get();
    }
}

void SurfaceFlinger::deleteTextureAsync(uint32_t texture) {