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

Commit ab57491d authored by Dan Stoza's avatar Dan Stoza
Browse files

GLConsumer: Allow creation in detached mode

Adds a constructor that doesn't require a GLES texture name and sets
up the GLConsumer in detached mode.

Bug: 15616428
Change-Id: Idc9ea2e59baa24bbd959da9fffe0fb71c0aa9818
parent e49ba8e2
Loading
Loading
Loading
Loading
+22 −17
Original line number Diff line number Diff line
@@ -56,23 +56,13 @@ public:
    enum { TEXTURE_EXTERNAL = 0x8D65 }; // GL_TEXTURE_EXTERNAL_OES
    typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;

    // GLConsumer constructs a new GLConsumer object. tex indicates the
    // name of the OpenGL ES texture to which images are to be streamed.
    // allowSynchronousMode specifies whether or not synchronous mode can be
    // enabled. texTarget specifies the OpenGL ES texture target to which the
    // texture will be bound in updateTexImage. useFenceSync specifies whether
    // fences should be used to synchronize access to buffers if that behavior
    // is enabled at compile-time. A custom bufferQueue can be specified
    // if behavior for queue/dequeue/connect etc needs to be customized.
    // Otherwise a default BufferQueue will be created and used.
    //
    // For legacy reasons, the GLConsumer is created in a state where it is
    // considered attached to an OpenGL ES context for the purposes of the
    // attachToContext and detachFromContext methods. However, despite being
    // considered "attached" to a context, the specific OpenGL ES context
    // doesn't get latched until the first call to updateTexImage. After that
    // point, all calls to updateTexImage must be made with the same OpenGL ES
    // context current.
    // GLConsumer constructs a new GLConsumer object. If the constructor with
    // the tex parameter is used, tex indicates the name of the OpenGL ES
    // texture to which images are to be streamed. texTarget specifies the
    // OpenGL ES texture target to which the texture will be bound in
    // updateTexImage. useFenceSync specifies whether fences should be used to
    // synchronize access to buffers if that behavior is enabled at
    // compile-time.
    //
    // A GLConsumer may be detached from one OpenGL ES context and then
    // attached to a different context using the detachFromContext and
@@ -80,10 +70,25 @@ public:
    // purely to allow a GLConsumer to be transferred from one consumer
    // context to another. If such a transfer is not needed there is no
    // requirement that either of these methods be called.
    //
    // If the constructor with the tex parameter is used, the GLConsumer is
    // created in a state where it is considered attached to an OpenGL ES
    // context for the purposes of the attachToContext and detachFromContext
    // methods. However, despite being considered "attached" to a context, the
    // specific OpenGL ES context doesn't get latched until the first call to
    // updateTexImage. After that point, all calls to updateTexImage must be
    // made with the same OpenGL ES context current.
    //
    // 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.
    GLConsumer(const sp<IGraphicBufferConsumer>& bq,
            uint32_t tex, uint32_t texureTarget, bool useFenceSync,
            bool isControlledByApp);

    GLConsumer(const sp<IGraphicBufferConsumer>& bq, uint32_t texureTarget,
            bool useFenceSync, bool isControlledByApp);

    // updateTexImage acquires the most recently queued buffer, and sets the
    // image contents of the target texture to it.
    //
+27 −0
Original line number Diff line number Diff line
@@ -143,6 +143,33 @@ GLConsumer::GLConsumer(const sp<IGraphicBufferConsumer>& bq, uint32_t tex,
    mConsumer->setConsumerUsageBits(DEFAULT_USAGE_FLAGS);
}

GLConsumer::GLConsumer(const sp<IGraphicBufferConsumer>& bq, uint32_t texTarget,
        bool useFenceSync, bool isControlledByApp) :
    ConsumerBase(bq, isControlledByApp),
    mCurrentTransform(0),
    mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
    mCurrentFence(Fence::NO_FENCE),
    mCurrentTimestamp(0),
    mCurrentFrameNumber(0),
    mDefaultWidth(1),
    mDefaultHeight(1),
    mFilteringEnabled(true),
    mTexName(-1),
    mUseFenceSync(useFenceSync),
    mTexTarget(texTarget),
    mEglDisplay(EGL_NO_DISPLAY),
    mEglContext(EGL_NO_CONTEXT),
    mCurrentTexture(BufferQueue::INVALID_BUFFER_SLOT),
    mAttached(false)
{
    ST_LOGV("GLConsumer");

    memcpy(mCurrentTransformMatrix, mtxIdentity,
            sizeof(mCurrentTransformMatrix));

    mConsumer->setConsumerUsageBits(DEFAULT_USAGE_FLAGS);
}

status_t GLConsumer::setDefaultMaxBufferCount(int bufferCount) {
    Mutex::Autolock lock(mMutex);
    return mConsumer->setDefaultMaxBufferCount(bufferCount);