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 Original line 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
    // now figure out what version of GL did we actually get
    // NOTE: a dummy surface is not needed if KHR_create_context is supported
    // 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;
    EGLConfig dummyConfig = config;
    if (dummyConfig == EGL_NO_CONFIG) {
    if (dummyConfig == EGL_NO_CONFIG) {
@@ -303,10 +301,10 @@ std::unique_ptr<GLES20RenderEngine> GLES20RenderEngine::create(int hwcFormat,
            break;
            break;
        case GLES_VERSION_2_0:
        case GLES_VERSION_2_0:
        case GLES_VERSION_3_0:
        case GLES_VERSION_3_0:
            engine = std::make_unique<GLES20RenderEngine>(featureFlags, display, config, ctxt,
            engine = std::make_unique<GLES20RenderEngine>(featureFlags);
                                                          dummy);
            break;
            break;
    }
    }
    engine->setEGLHandles(display, config, ctxt);


    ALOGI("OpenGL ES informations:");
    ALOGI("OpenGL ES informations:");
    ALOGI("vendor    : %s", extensions.getVendor());
    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_TEXTURE_SIZE = %zu", engine->getMaxTextureSize());
    ALOGI("GL_MAX_VIEWPORT_DIMS = %zu", engine->getMaxViewportDims());
    ALOGI("GL_MAX_VIEWPORT_DIMS = %zu", engine->getMaxViewportDims());


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

    return engine;
    return engine;
}
}


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


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


    // back to main framebuffer
    // back to main framebuffer
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    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 {
void GLES20RenderEngine::checkErrors() const {
@@ -969,6 +974,12 @@ bool GLES20RenderEngine::needsXYZTransformMatrix() const {
    return (isInputHdrDataSpace || isOutputHdrDataSpace) && inputTransfer != outputTransfer;
    return (isInputHdrDataSpace || isOutputHdrDataSpace) && inputTransfer != outputTransfer;
}
}


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

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


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


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


    ANativeWindow* const window = mNativeWindow.get();
    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);
    mDisplayWidth = ANativeWindow_getWidth(window);
    mDisplayHeight = ANativeWindow_getHeight(window);
    mDisplayHeight = ANativeWindow_getHeight(window);


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


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


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


sp<GraphicBuffer> DisplayDevice::dequeueBuffer() {
void DisplayDevice::swapBuffers(HWComposer& hwc) const {
    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)) {
    if (hwc.hasClientComposition(mId) || hwc.hasFlipClientTargetRequest(mId)) {
        // hasFlipClientTargetRequest could return true even if we haven't
        mSurface->swapBuffers();
        // 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();
    status_t result = mDisplaySurface->advanceFrame();
@@ -435,7 +367,7 @@ void DisplayDevice::queueBuffer(HWComposer& hwc) {
    }
    }
}
}


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


@@ -452,13 +384,6 @@ void DisplayDevice::setViewportAndProjection() const {
    mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, ui::Transform::ROT_0);
    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 {
const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const {
    return mDisplaySurface->getClientTargetAcquireFence();
    return mDisplaySurface->getClientTargetAcquireFence();
}
}
+3 −17
Original line number Original line Diff line number Diff line
@@ -28,14 +28,13 @@
#include <gui/LayerState.h>
#include <gui/LayerState.h>
#include <hardware/hwcomposer_defs.h>
#include <hardware/hwcomposer_defs.h>
#include <math/mat4.h>
#include <math/mat4.h>
#include <renderengine/RenderEngine.h>
#include <renderengine/Surface.h>
#include <renderengine/Surface.h>
#include <ui/GraphicTypes.h>
#include <ui/GraphicTypes.h>
#include <ui/HdrCapabilities.h>
#include <ui/HdrCapabilities.h>
#include <ui/Region.h>
#include <ui/Region.h>
#include <ui/Transform.h>
#include <ui/Transform.h>
#include <utils/Mutex.h>
#include <utils/RefBase.h>
#include <utils/RefBase.h>
#include <utils/Mutex.h>
#include <utils/String8.h>
#include <utils/String8.h>
#include <utils/Timers.h>
#include <utils/Timers.h>


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


    // Queues the drawn buffer for consumption by HWC.
    void swapBuffers(HWComposer& hwc) const;
    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
    // called after h/w composer has completed its set() call
    void onPresentDisplayCompleted();
    void onSwapBuffersCompleted() const;


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


    bool makeCurrent() const;
    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;
    void setViewportAndProjection() const;


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


    // ANativeWindow this display is rendering into
    // ANativeWindow this display is rendering into
    sp<ANativeWindow> mNativeWindow;
    sp<ANativeWindow> mNativeWindow;
    // Current buffer that this display can render to.
    sp<GraphicBuffer> mGraphicBuffer;
    sp<DisplaySurface> mDisplaySurface;
    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;
    std::unique_ptr<renderengine::Surface> mSurface;
    int             mDisplayWidth;
    int             mDisplayWidth;
Loading