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

Commit 8d4f90aa authored by Alec Mouri's avatar Alec Mouri
Browse files

Revert "Bind to FBO when using GPU composition"

This reverts commit 8147b0ea.

Reason for revert: Breaks screenrecord (b/119534075).

Change-Id: Iea02806d896ac53c805c27ed745f325456d9a3a4
parent 0587464f
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -275,8 +275,6 @@ 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) {
@@ -303,10 +301,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, display, config, ctxt,
                                                          dummy);
            engine = std::make_unique<GLES20RenderEngine>(featureFlags);
            break;
    }
    engine->setEGLHandles(display, config, ctxt);

    ALOGI("OpenGL ES informations:");
    ALOGI("vendor    : %s", extensions.getVendor());
@@ -316,6 +314,9 @@ 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;
}

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

GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags, EGLDisplay display, EGLConfig config,
                                       EGLContext ctxt, EGLSurface dummy)
GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags)
      : renderengine::impl::RenderEngine(featureFlags),
        mEGLDisplay(display),
        mEGLConfig(config),
        mEGLContext(ctxt),
        mDummySurface(dummy),
        mEGLDisplay(EGL_NO_DISPLAY),
        mEGLConfig(nullptr),
        mEGLContext(EGL_NO_CONTEXT),
        mVpWidth(0),
        mVpHeight(0),
        mUseColorManagement(featureFlags & USE_COLOR_MANAGEMENT) {
@@ -637,6 +636,12 @@ 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 {
@@ -969,6 +974,12 @@ 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
+2 −4
Original line number Diff line number Diff line
@@ -47,8 +47,7 @@ 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
                       EGLDisplay display, EGLConfig config, EGLContext ctxt, EGLSurface dummy);
    GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag
    ~GLES20RenderEngine() override;

    std::unique_ptr<Framebuffer> createFramebuffer() override;
@@ -121,12 +120,11 @@ 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, EGLSurface dummy);
    void setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt);

    EGLDisplay mEGLDisplay;
    EGLConfig mEGLConfig;
    EGLContext mEGLContext;
    EGLSurface mDummySurface;
    GLuint mProtectedTexName;
    GLint mMaxViewportDims[2];
    GLint mMaxTextureSize;
+0 −1
Original line number Diff line number Diff line
@@ -183,7 +183,6 @@ cc_defaults {
        "libhidltransport",
        "liblayers_proto",
        "liblog",
        "libsync",
        "libtimestats_proto",
        "libutils",
    ],
+4 −79
Original line number Diff line number Diff line
@@ -35,8 +35,6 @@
#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>
@@ -223,7 +221,6 @@ 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),
@@ -287,10 +284,6 @@ 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);

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

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

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

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) {
void DisplayDevice::swapBuffers(HWComposer& hwc) const {
    if (hwc.hasClientComposition(mId) || hwc.hasFlipClientTargetRequest(mId)) {
        // 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;
        }
        mSurface->swapBuffers();
    }

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

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

@@ -452,13 +384,6 @@ 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();
}
+3 −17
Original line number Diff line number Diff line
@@ -28,14 +28,13 @@
#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/Mutex.h>
#include <utils/RefBase.h>
#include <utils/Mutex.h>
#include <utils/String8.h>
#include <utils/Timers.h>

@@ -147,13 +146,10 @@ public:
                          ui::Dataspace* outDataspace, ui::ColorMode* outMode,
                          ui::RenderIntent* outIntent) 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();
    void swapBuffers(HWComposer& hwc) const;

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

    Rect getBounds() const {
        return Rect(mDisplayWidth, mDisplayHeight);
@@ -164,11 +160,6 @@ 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;
@@ -213,12 +204,7 @@ 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