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

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

Merge "ImageReader: Migrate from IGBP to Surface" into main

parents 4b2e603c ace2e33d
Loading
Loading
Loading
Loading
+51 −2
Original line number Diff line number Diff line
@@ -120,8 +120,18 @@ public:
    void setBufferConsumer(const sp<BufferItemConsumer>& consumer) { mConsumer = consumer; }
    BufferItemConsumer* getBufferConsumer() { return mConsumer.get(); }

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    void setSurface(const sp<Surface>& surface) {
        mSurface = surface;
    }

    Surface* getSurface() {
        return mSurface.get();
    }
#else
    void setProducer(const sp<IGraphicBufferProducer>& producer) { mProducer = producer; }
    IGraphicBufferProducer* getProducer() { return mProducer.get(); }
#endif

    void setBufferFormat(int format) { mFormat = format; }
    int getBufferFormat() { return mFormat; }
@@ -141,7 +151,11 @@ private:

    List<BufferItem*> mBuffers;
    sp<BufferItemConsumer> mConsumer;
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    sp<Surface> mSurface;
#else
    sp<IGraphicBufferProducer> mProducer;
#endif
    jobject mWeakThiz;
    jclass mClazz;
    int mFormat;
@@ -257,8 +271,19 @@ static JNIImageReaderContext* ImageReader_getContext(JNIEnv* env, jobject thiz)
    return ctx;
}

static IGraphicBufferProducer* ImageReader_getProducer(JNIEnv* env, jobject thiz)
{
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
static Surface* ImageReader_getSurfaceFromContext(JNIEnv* env, jobject thiz) {
    ALOGV("%s:", __FUNCTION__);
    JNIImageReaderContext* const ctx = ImageReader_getContext(env, thiz);
    if (ctx == NULL) {
        jniThrowRuntimeException(env, "ImageReaderContext is not initialized");
        return NULL;
    }

    return ctx->getSurface();
}
#else
static IGraphicBufferProducer* ImageReader_getProducer(JNIEnv* env, jobject thiz) {
    ALOGV("%s:", __FUNCTION__);
    JNIImageReaderContext* const ctx = ImageReader_getContext(env, thiz);
    if (ctx == NULL) {
@@ -268,6 +293,7 @@ static IGraphicBufferProducer* ImageReader_getProducer(JNIEnv* env, jobject thiz

    return ctx->getProducer();
}
#endif

static void ImageReader_setNativeContext(JNIEnv* env,
        jobject thiz, sp<JNIImageReaderContext> ctx)
@@ -440,7 +466,11 @@ static void ImageReader_init(JNIEnv* env, jobject thiz, jobject weakThiz, jint w
    ctx->setBufferConsumer(bufferConsumer);
    bufferConsumer->setName(consumerName);

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    ctx->setSurface(sp<Surface>::make(gbProducer));
#else
    ctx->setProducer(gbProducer);
#endif
    bufferConsumer->setFrameAvailableListener(ctx);
    ImageReader_setNativeContext(env, thiz, ctx);
    ctx->setBufferFormat(nativeHalFormat);
@@ -687,7 +717,11 @@ static jint ImageReader_detachImage(JNIEnv* env, jobject thiz, jobject image,

    status_t res = OK;
    Image_unlockIfLocked(env, image);
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    res = bufferConsumer->detachBuffer(buffer->mGraphicBuffer);
#else
    res = bufferConsumer->detachBuffer(buffer->mSlot);
#endif
    if (res != OK) {
        ALOGE("Image detach failed: %s (%d)!!!", strerror(-res), res);
        if ((bool) throwISEOnly) {
@@ -718,6 +752,20 @@ static void ImageReader_discardFreeBuffers(JNIEnv* env, jobject thiz) {
    }
}

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
static jobject ImageReader_getSurface(JNIEnv* env, jobject thiz) {
    ALOGV("%s: ", __FUNCTION__);

    Surface* surface = ImageReader_getSurfaceFromContext(env, thiz);
    if (surface == NULL) {
        jniThrowRuntimeException(env, "Buffer consumer is uninitialized");
        return NULL;
    }

    // Wrap the IGBP in a Java-language Surface.
    return android_view_Surface_createFromSurface(env, surface);
}
#else
static jobject ImageReader_getSurface(JNIEnv* env, jobject thiz)
{
    ALOGV("%s: ", __FUNCTION__);
@@ -731,6 +779,7 @@ static jobject ImageReader_getSurface(JNIEnv* env, jobject thiz)
    // Wrap the IGBP in a Java-language Surface.
    return android_view_Surface_createFromIGraphicBufferProducer(env, gbp);
}
#endif

static void Image_getLockedImage(JNIEnv* env, jobject thiz, LockedImage *image,
        uint64_t ndkReaderUsage) {