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

Commit 304134cb authored by Shuzhen Wang's avatar Shuzhen Wang Committed by Android (Google) Code Review
Browse files

Merge "ImageWriter: Check Surface is valid before use" into main

parents b7bb6931 7f974147
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -735,10 +735,15 @@ static void ImageWriter_queueImage(JNIEnv* env, jobject thiz, jlong nativeCtx, j
}

static status_t attachAndQeueuGraphicBuffer(JNIEnv* env, JNIImageWriterContext *ctx,
        sp<Surface> surface, sp<GraphicBuffer> gb, jlong timestampNs, jint dataSpace,
        sp<GraphicBuffer> gb, jlong timestampNs, jint dataSpace,
        jint left, jint top, jint right, jint bottom, jint transform, jint scalingMode) {
    status_t res = OK;
    // Step 1. Attach Image
    sp<Surface> surface = ctx->getProducer();
    if (surface == nullptr) {
        jniThrowException(env, "java/lang/IllegalStateException",
                "Producer surface is null, ImageWriter seems already closed");
    }
    res = surface->attachBuffer(gb.get());
    if (res != OK) {
        ALOGE("Attach image failed: %s (%d)", strerror(-res), res);
@@ -835,7 +840,6 @@ static jint ImageWriter_attachAndQueueImage(JNIEnv* env, jobject thiz, jlong nat
        return -1;
    }

    sp<Surface> surface = ctx->getProducer();
    if (isFormatOpaque(ctx->getBufferFormat()) != isFormatOpaque(nativeHalFormat)) {
        jniThrowException(env, "java/lang/IllegalStateException",
                "Trying to attach an opaque image into a non-opaque ImageWriter, or vice versa");
@@ -851,7 +855,7 @@ static jint ImageWriter_attachAndQueueImage(JNIEnv* env, jobject thiz, jlong nat
        return -1;
    }

    return attachAndQeueuGraphicBuffer(env, ctx, surface, buffer->mGraphicBuffer, timestampNs,
    return attachAndQeueuGraphicBuffer(env, ctx, buffer->mGraphicBuffer, timestampNs,
            dataSpace, left, top, right, bottom, transform, scalingMode);
}

@@ -866,7 +870,6 @@ static jint ImageWriter_attachAndQueueGraphicBuffer(JNIEnv* env, jobject thiz, j
        return -1;
    }

    sp<Surface> surface = ctx->getProducer();
    if (isFormatOpaque(ctx->getBufferFormat()) != isFormatOpaque(nativeHalFormat)) {
        jniThrowException(env, "java/lang/IllegalStateException",
                "Trying to attach an opaque image into a non-opaque ImageWriter, or vice versa");
@@ -880,7 +883,8 @@ static jint ImageWriter_attachAndQueueGraphicBuffer(JNIEnv* env, jobject thiz, j
                "Trying to attach an invalid graphic buffer");
        return -1;
    }
    return attachAndQeueuGraphicBuffer(env, ctx, surface, graphicBuffer, timestampNs,

    return attachAndQeueuGraphicBuffer(env, ctx, graphicBuffer, timestampNs,
            dataSpace, left, top, right, bottom, transform, scalingMode);
}