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

Commit 0a9c7b81 authored by Alec Mouri's avatar Alec Mouri
Browse files

Revert "Revert "Bind to FBO when using GPU composition""

Hold for now while I propose a fix on top of this change.

This reverts commit 8d4f90aa.

Reason for revert: Forward fixing

Bug: 117680609
Change-Id: I68a26ced146fa057de3aeb144cbfe2fa3c9842fe
Test: See If639ce2c6cd600eabb957d278815f80b413d92b3
parent 85c48d12
Loading
Loading
Loading
Loading
+10 −21
Original line number Diff line number Diff line
@@ -275,6 +275,8 @@ std::unique_ptr<GLES20RenderEngine> GLES20RenderEngine::create(int hwcFormat,

    // now figure out what version of GL did we actually get
    // NOTE: a dummy surface is not needed if KHR_create_context is supported
    // TODO(alecmouri): don't create this surface if EGL_KHR_surfaceless_context
    // is supported.

    EGLConfig dummyConfig = config;
    if (dummyConfig == EGL_NO_CONFIG) {
@@ -301,10 +303,10 @@ std::unique_ptr<GLES20RenderEngine> GLES20RenderEngine::create(int hwcFormat,
            break;
        case GLES_VERSION_2_0:
        case GLES_VERSION_3_0:
            engine = std::make_unique<GLES20RenderEngine>(featureFlags);
            engine = std::make_unique<GLES20RenderEngine>(featureFlags, display, config, ctxt,
                                                          dummy);
            break;
    }
    engine->setEGLHandles(display, config, ctxt);

    ALOGI("OpenGL ES informations:");
    ALOGI("vendor    : %s", extensions.getVendor());
@@ -314,9 +316,6 @@ std::unique_ptr<GLES20RenderEngine> GLES20RenderEngine::create(int hwcFormat,
    ALOGI("GL_MAX_TEXTURE_SIZE = %zu", engine->getMaxTextureSize());
    ALOGI("GL_MAX_VIEWPORT_DIMS = %zu", engine->getMaxViewportDims());

    eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    eglDestroySurface(display, dummy);

    return engine;
}

@@ -359,11 +358,13 @@ EGLConfig GLES20RenderEngine::chooseEglConfig(EGLDisplay display, int format, bo
    return config;
}

GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags)
GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags, EGLDisplay display, EGLConfig config,
                                       EGLContext ctxt, EGLSurface dummy)
      : renderengine::impl::RenderEngine(featureFlags),
        mEGLDisplay(EGL_NO_DISPLAY),
        mEGLConfig(nullptr),
        mEGLContext(EGL_NO_CONTEXT),
        mEGLDisplay(display),
        mEGLConfig(config),
        mEGLContext(ctxt),
        mDummySurface(dummy),
        mVpWidth(0),
        mVpHeight(0),
        mUseColorManagement(featureFlags & USE_COLOR_MANAGEMENT) {
@@ -636,12 +637,6 @@ void GLES20RenderEngine::unbindFrameBuffer(Framebuffer* /* framebuffer */) {

    // back to main framebuffer
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    // Workaround for b/77935566 to force the EGL driver to release the
    // screenshot buffer
    setScissor(Rect::EMPTY_RECT);
    clearWithColor(0.0, 0.0, 0.0, 0.0);
    disableScissor();
}

void GLES20RenderEngine::checkErrors() const {
@@ -974,12 +969,6 @@ bool GLES20RenderEngine::needsXYZTransformMatrix() const {
    return (isInputHdrDataSpace || isOutputHdrDataSpace) && inputTransfer != outputTransfer;
}

void GLES20RenderEngine::setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt) {
    mEGLDisplay = display;
    mEGLConfig = config;
    mEGLContext = ctxt;
}

} // namespace gl
} // namespace renderengine
} // namespace android
+4 −2
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@ public:
    static std::unique_ptr<GLES20RenderEngine> create(int hwcFormat, uint32_t featureFlags);
    static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);

    GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag
    GLES20RenderEngine(uint32_t featureFlags, // See RenderEngine::FeatureFlag
                       EGLDisplay display, EGLConfig config, EGLContext ctxt, EGLSurface dummy);
    ~GLES20RenderEngine() override;

    std::unique_ptr<Framebuffer> createFramebuffer() override;
@@ -120,11 +121,12 @@ private:
    // with PQ or HLG transfer function.
    bool isHdrDataSpace(const ui::Dataspace dataSpace) const;
    bool needsXYZTransformMatrix() const;
    void setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt);
    void setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt, EGLSurface dummy);

    EGLDisplay mEGLDisplay;
    EGLConfig mEGLConfig;
    EGLContext mEGLContext;
    EGLSurface mDummySurface;
    GLuint mProtectedTexName;
    GLint mMaxViewportDims[2];
    GLint mMaxTextureSize;
+1 −0
Original line number Diff line number Diff line
@@ -184,6 +184,7 @@ cc_defaults {
        "libhidltransport",
        "liblayers_proto",
        "liblog",
        "libsync",
        "libtimestats_proto",
        "libutils",
    ],
+79 −4
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@
#include <gui/Surface.h>
#include <hardware/gralloc.h>
#include <renderengine/RenderEngine.h>
#include <sync/sync.h>
#include <system/window.h>
#include <ui/DebugUtils.h>
#include <ui/DisplayInfo.h>
#include <ui/PixelFormat.h>
@@ -221,6 +223,7 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args)
        mDisplayToken(args.displayToken),
        mId(args.displayId),
        mNativeWindow(args.nativeWindow),
        mGraphicBuffer(nullptr),
        mDisplaySurface(args.displaySurface),
        mSurface{std::move(args.renderSurface)},
        mDisplayInstallOrientation(args.displayInstallOrientation),
@@ -284,6 +287,10 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args)
    mHdrCapabilities = HdrCapabilities(types, maxLuminance, maxAverageLuminance, minLuminance);

    ANativeWindow* const window = mNativeWindow.get();

    int status = native_window_api_connect(mNativeWindow.get(), NATIVE_WINDOW_API_EGL);
    ALOGE_IF(status != NO_ERROR, "Unable to connect BQ producer: %d", status);

    mDisplayWidth = ANativeWindow_getWidth(window);
    mDisplayHeight = ANativeWindow_getHeight(window);

@@ -321,7 +328,6 @@ uint32_t DisplayDevice::getPageFlipCount() const {

void DisplayDevice::flip() const
{
    mFlinger->getRenderEngine().checkErrors();
    mPageFlipCount++;
}

@@ -356,9 +362,71 @@ status_t DisplayDevice::prepareFrame(HWComposer& hwc,
    return mDisplaySurface->prepareFrame(compositionType);
}

void DisplayDevice::swapBuffers(HWComposer& hwc) const {
sp<GraphicBuffer> DisplayDevice::dequeueBuffer() {
    int fd;
    ANativeWindowBuffer* buffer;

    status_t res = mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buffer, &fd);

    if (res != NO_ERROR) {
        ALOGE("ANativeWindow::dequeueBuffer failed for display [%s] with error: %d",
              getDisplayName().c_str(), res);
        // Return fast here as we can't do much more - any rendering we do
        // now will just be wrong.
        return mGraphicBuffer;
    }

    ALOGW_IF(mGraphicBuffer != nullptr, "Clobbering a non-null pointer to a buffer [%p].",
             mGraphicBuffer->getNativeBuffer()->handle);
    mGraphicBuffer = GraphicBuffer::from(buffer);

    // Block until the buffer is ready
    // TODO(alecmouri): it's perhaps more appropriate to block renderengine so
    // that the gl driver can block instead.
    if (fd >= 0) {
        sync_wait(fd, -1);
        close(fd);
    }

    return mGraphicBuffer;
}

void DisplayDevice::queueBuffer(HWComposer& hwc) {
    if (hwc.hasClientComposition(mId) || hwc.hasFlipClientTargetRequest(mId)) {
        mSurface->swapBuffers();
        // hasFlipClientTargetRequest could return true even if we haven't
        // dequeued a buffer before. Try dequeueing one if we don't have a
        // buffer ready.
        if (mGraphicBuffer == nullptr) {
            ALOGI("Attempting to queue a client composited buffer without one "
                  "previously dequeued for display [%s]. Attempting to dequeue "
                  "a scratch buffer now",
                  mDisplayName.c_str());
            // We shouldn't deadlock here, since mGraphicBuffer == nullptr only
            // after a successful call to queueBuffer, or if dequeueBuffer has
            // never been called.
            dequeueBuffer();
        }

        if (mGraphicBuffer == nullptr) {
            ALOGE("No buffer is ready for display [%s]", mDisplayName.c_str());
        } else {
            int fd = mBufferReady.release();

            status_t res = mNativeWindow->queueBuffer(mNativeWindow.get(),
                                                      mGraphicBuffer->getNativeBuffer(), fd);
            if (res != NO_ERROR) {
                ALOGE("Error when queueing buffer for display [%s]: %d", mDisplayName.c_str(), res);
                // We risk blocking on dequeueBuffer if the primary display failed
                // to queue up its buffer, so crash here.
                if (isPrimary()) {
                    LOG_ALWAYS_FATAL("ANativeWindow::queueBuffer failed with error: %d", res);
                } else {
                    mNativeWindow->cancelBuffer(mNativeWindow.get(),
                                                mGraphicBuffer->getNativeBuffer(), fd);
                }
            }
            mGraphicBuffer = nullptr;
        }
    }

    status_t result = mDisplaySurface->advanceFrame();
@@ -367,7 +435,7 @@ void DisplayDevice::swapBuffers(HWComposer& hwc) const {
    }
}

void DisplayDevice::onSwapBuffersCompleted() const {
void DisplayDevice::onPresentDisplayCompleted() {
    mDisplaySurface->onFrameCommitted();
}

@@ -384,6 +452,13 @@ void DisplayDevice::setViewportAndProjection() const {
    mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, ui::Transform::ROT_0);
}

void DisplayDevice::finishBuffer() {
    mBufferReady = mFlinger->getRenderEngine().flush();
    if (mBufferReady.get() < 0) {
        mFlinger->getRenderEngine().finish();
    }
}

const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const {
    return mDisplaySurface->getClientTargetAcquireFence();
}
+17 −3
Original line number Diff line number Diff line
@@ -28,13 +28,14 @@
#include <gui/LayerState.h>
#include <hardware/hwcomposer_defs.h>
#include <math/mat4.h>
#include <renderengine/RenderEngine.h>
#include <renderengine/Surface.h>
#include <ui/GraphicTypes.h>
#include <ui/HdrCapabilities.h>
#include <ui/Region.h>
#include <ui/Transform.h>
#include <utils/RefBase.h>
#include <utils/Mutex.h>
#include <utils/RefBase.h>
#include <utils/String8.h>
#include <utils/Timers.h>

@@ -146,10 +147,13 @@ public:
                          ui::Dataspace* outDataspace, ui::ColorMode* outMode,
                          ui::RenderIntent* outIntent) const;

    void swapBuffers(HWComposer& hwc) const;
    // Queues the drawn buffer for consumption by HWC.
    void queueBuffer(HWComposer& hwc);
    // Allocates a buffer as scratch space for GPU composition
    sp<GraphicBuffer> dequeueBuffer();

    // called after h/w composer has completed its set() call
    void onSwapBuffersCompleted() const;
    void onPresentDisplayCompleted();

    Rect getBounds() const {
        return Rect(mDisplayWidth, mDisplayHeight);
@@ -160,6 +164,11 @@ public:
    const std::string& getDisplayName() const { return mDisplayName; }

    bool makeCurrent() const;
    // Acquires a new buffer for GPU composition.
    void readyNewBuffer();
    // Marks the current buffer has finished, so that it can be presented and
    // swapped out.
    void finishBuffer();
    void setViewportAndProjection() const;

    const sp<Fence>& getClientTargetAcquireFence() const;
@@ -204,7 +213,12 @@ private:

    // ANativeWindow this display is rendering into
    sp<ANativeWindow> mNativeWindow;
    // Current buffer that this display can render to.
    sp<GraphicBuffer> mGraphicBuffer;
    sp<DisplaySurface> mDisplaySurface;
    // File descriptor indicating that mGraphicBuffer is ready for display, i.e.
    // that drawing to the buffer is now complete.
    base::unique_fd mBufferReady;

    std::unique_ptr<renderengine::Surface> mSurface;
    int             mDisplayWidth;
Loading