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

Commit 5a2c6135 authored by Jim Shargo's avatar Jim Shargo Committed by Android (Google) Code Review
Browse files

Merge "BufferQueues: clean up constructors for GLConsumer and CpuConsumer" into main

parents a22ed275 df578c31
Loading
Loading
Loading
Loading
+4 −17
Original line number Diff line number Diff line
@@ -203,25 +203,12 @@ bool GLHelper::getShaderProgram(const char* name, GLuint* outPgm) {

bool GLHelper::createNamedSurfaceTexture(GLuint name, uint32_t w, uint32_t h,
                                         sp<GLConsumer>* glConsumer, EGLSurface* surface) {
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
    sp<GLConsumer> glc = new GLConsumer(name, GL_TEXTURE_EXTERNAL_OES, false, true);
    auto [glc, surf] = GLConsumer::create(name, GL_TEXTURE_EXTERNAL_OES, false, true);
    glc->setDefaultBufferSize(w, h);
    glc->getSurface()->setMaxDequeuedBufferCount(2);
    glc->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER);
    surf->setMaxDequeuedBufferCount(2);
    sp<ANativeWindow> anw = surf;

    sp<ANativeWindow> anw = glc->getSurface();
#else
    sp<IGraphicBufferProducer> producer;
    sp<IGraphicBufferConsumer> consumer;
    BufferQueue::createBufferQueue(&producer, &consumer);
    sp<GLConsumer> glc = new GLConsumer(consumer, name,
            GL_TEXTURE_EXTERNAL_OES, false, true);
    glc->setDefaultBufferSize(w, h);
    producer->setMaxDequeuedBufferCount(2);
    glc->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER);

    sp<ANativeWindow> anw = new Surface(producer);
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
    EGLSurface s = eglCreateWindowSurface(mDisplay, mConfig, anw.get(), nullptr);
    if (s == EGL_NO_SURFACE) {
        fprintf(stderr, "eglCreateWindowSurface error: %#x\n", eglGetError());
+26 −0
Original line number Diff line number Diff line
@@ -20,7 +20,11 @@

#include <com_android_graphics_libgui_flags.h>
#include <gui/BufferItem.h>
#include <gui/BufferQueue.h>
#include <gui/CpuConsumer.h>
#include <gui/IGraphicBufferConsumer.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/Surface.h>
#include <utils/Log.h>

#define CC_LOGV(x, ...) ALOGV("[%s] " x, mName.c_str(), ##__VA_ARGS__)
@@ -31,6 +35,28 @@

namespace android {

std::tuple<sp<CpuConsumer>, sp<Surface>> CpuConsumer::create(size_t maxLockedBuffers,
                                                             bool controlledByApp,
                                                             bool isConsumerSurfaceFlinger) {
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
    sp<CpuConsumer> consumer =
            sp<CpuConsumer>::make(maxLockedBuffers, controlledByApp, isConsumerSurfaceFlinger);
    return {consumer, consumer->getSurface()};
#else
    sp<IGraphicBufferProducer> igbp;
    sp<IGraphicBufferConsumer> igbc;
    BufferQueue::createBufferQueue(&igbp, &igbc, isConsumerSurfaceFlinger);

    return {sp<CpuConsumer>::make(igbc, maxLockedBuffers, controlledByApp),
            sp<Surface>::make(igbp, controlledByApp)};
#endif
}

sp<CpuConsumer> CpuConsumer::create(const sp<IGraphicBufferConsumer>& bq, size_t maxLockedBuffers,
                                    bool controlledByApp) {
    return sp<CpuConsumer>::make(bq, maxLockedBuffers, controlledByApp);
}

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
CpuConsumer::CpuConsumer(size_t maxLockedBuffers, bool controlledByApp,
                         bool isConsumerSurfaceFlinger)
+45 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include <gui/DebugEGLImageTracker.h>
#include <gui/GLConsumer.h>
#include <gui/ISurfaceComposer.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>

#include <private/gui/ComposerService.h>
@@ -101,6 +102,50 @@ static bool hasEglProtectedContent() {
    return hasIt;
}

std::tuple<sp<GLConsumer>, sp<Surface>> GLConsumer::create(uint32_t tex, uint32_t textureTarget,
                                                           bool useFenceSync,
                                                           bool isControlledByApp) {
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
    sp<GLConsumer> consumer =
            sp<GLConsumer>::make(tex, textureTarget, useFenceSync, isControlledByApp);
    return {consumer, consumer->getSurface()};
#else
    sp<IGraphicBufferProducer> igbp;
    sp<IGraphicBufferConsumer> igbc;
    BufferQueue::createBufferQueue(&igbp, &igbc);

    return {sp<GLConsumer>::make(igbc, tex, textureTarget, useFenceSync, isControlledByApp),
            sp<Surface>::make(igbp, isControlledByApp)};
#endif
}

std::tuple<sp<GLConsumer>, sp<Surface>> GLConsumer::create(uint32_t textureTarget,
                                                           bool useFenceSync,
                                                           bool isControlledByApp) {
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
    sp<GLConsumer> consumer = sp<GLConsumer>::make(textureTarget, useFenceSync, isControlledByApp);
    return {consumer, consumer->getSurface()};
#else
    sp<IGraphicBufferProducer> igbp;
    sp<IGraphicBufferConsumer> igbc;
    BufferQueue::createBufferQueue(&igbp, &igbc);

    return {sp<GLConsumer>::make(igbc, textureTarget, useFenceSync, isControlledByApp),
            sp<Surface>::make(igbp, isControlledByApp)};
#endif
}

sp<GLConsumer> GLConsumer::create(const sp<IGraphicBufferConsumer>& bq, uint32_t tex,
                                  uint32_t textureTarget, bool useFenceSync,
                                  bool isControlledByApp) {
    return sp<GLConsumer>::make(bq, tex, textureTarget, useFenceSync, isControlledByApp);
}

sp<GLConsumer> GLConsumer::create(const sp<IGraphicBufferConsumer>& bq, uint32_t textureTarget,
                                  bool useFenceSync, bool isControlledByApp) {
    return sp<GLConsumer>::make(bq, textureTarget, useFenceSync, isControlledByApp);
}

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
GLConsumer::GLConsumer(uint32_t tex, uint32_t texTarget, bool useFenceSync, bool isControlledByApp)
      : ConsumerBase(isControlledByApp, /* isConsumerSurfaceFlinger */ false),
+10 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ namespace android {
class BufferQueue;
class GraphicBuffer;
class String8;
class Surface;

/**
 * CpuConsumer is a BufferQueue consumer endpoint that allows direct CPU
@@ -92,6 +93,13 @@ class CpuConsumer : public ConsumerBase

    // Create a new CPU consumer. The maxLockedBuffers parameter specifies
    // how many buffers can be locked for user access at the same time.
    static std::tuple<sp<CpuConsumer>, sp<Surface>> create(size_t maxLockedBuffers,
                                                           bool controlledByApp = false,
                                                           bool isConsumerSurfaceFlinger = false);
    static sp<CpuConsumer> create(const sp<IGraphicBufferConsumer>& bq, size_t maxLockedBuffers,
                                  bool controlledByApp = false)
            __attribute((deprecated("Prefer ctors that create their own surface and consumer.")));

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
    CpuConsumer(size_t maxLockedBuffers, bool controlledByApp = false,
                bool isConsumerSurfaceFlinger = false);
@@ -100,8 +108,8 @@ class CpuConsumer : public ConsumerBase
                bool controlledByApp = false)
            __attribute((deprecated("Prefer ctors that create their own surface and consumer.")));
#else
    CpuConsumer(const sp<IGraphicBufferConsumer>& bq,
            size_t maxLockedBuffers, bool controlledByApp = false);
    CpuConsumer(const sp<IGraphicBufferConsumer>& bq, size_t maxLockedBuffers,
                bool controlledByApp = false);
#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)

    // Gets the next graphics buffer from the producer and locks it for CPU use,
+14 −0
Original line number Diff line number Diff line
@@ -83,6 +83,20 @@ public:
    // If the constructor without the tex parameter is used, the GLConsumer is
    // created in a detached state, and attachToContext must be called before
    // calls to updateTexImage.
    static std::tuple<sp<GLConsumer>, sp<Surface>> create(uint32_t tex, uint32_t textureTarget,
                                                          bool useFenceSync,
                                                          bool isControlledByApp);
    static std::tuple<sp<GLConsumer>, sp<Surface>> create(uint32_t textureTarget, bool useFenceSync,
                                                          bool isControlledByApp);
    static sp<GLConsumer> create(const sp<IGraphicBufferConsumer>& bq, uint32_t tex,
                                 uint32_t textureTarget, bool useFenceSync, bool isControlledByApp)
            __attribute((deprecated(
                    "Prefer create functions that create their own surface and consumer.")));
    static sp<GLConsumer> create(const sp<IGraphicBufferConsumer>& bq, uint32_t textureTarget,
                                 bool useFenceSync, bool isControlledByApp)
            __attribute((deprecated(
                    "Prefer create functions that create their own surface and consumer.")));

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
    GLConsumer(uint32_t tex, uint32_t textureTarget, bool useFenceSync, bool isControlledByApp);

Loading