Exemple #1
0
void CSurfaceTexture::NativeFinalize()
{
    android::sp<GLConsumer> surfaceTexture(SurfaceTexture_getSurfaceTexture(this));
    surfaceTexture->setFrameAvailableListener(0);
    SurfaceTexture_setFrameAvailableListener(this, 0);
    SurfaceTexture_setSurfaceTexture(this, 0);
    SurfaceTexture_setProducer(this, 0);
}
static void SurfaceTexture_finalize(JNIEnv* env, jobject thiz)
{
    sp<GLConsumer> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz));
    surfaceTexture->setFrameAvailableListener(0);
    SurfaceTexture_setFrameAvailableListener(env, thiz, 0);
    SurfaceTexture_setSurfaceTexture(env, thiz, 0);
    SurfaceTexture_setProducer(env, thiz, 0);
}
static void SurfaceTexture_init(JNIEnv* env, jobject thiz, jboolean isDetached,
        jint texName, jboolean singleBufferMode, jobject weakThiz)
{
    sp<IGraphicBufferProducer> producer;
    sp<IGraphicBufferConsumer> consumer;
    BufferQueue::createBufferQueue(&producer, &consumer);

    if (singleBufferMode) {
        consumer->disableAsyncBuffer();
        consumer->setDefaultMaxBufferCount(1);
    }

    sp<GLConsumer> surfaceTexture;
    if (isDetached) {
        surfaceTexture = new GLConsumer(consumer, GL_TEXTURE_EXTERNAL_OES,
                true, true);
    } else {
        surfaceTexture = new GLConsumer(consumer, texName,
                GL_TEXTURE_EXTERNAL_OES, true, true);
    }

    if (surfaceTexture == 0) {
        jniThrowException(env, OutOfResourcesException,
                "Unable to create native SurfaceTexture");
        return;
    }
    surfaceTexture->setName(String8::format("SurfaceTexture-%d-%d-%d",
            (isDetached ? 0 : texName),
            getpid(),
            createProcessUniqueId()));

    SurfaceTexture_setSurfaceTexture(env, thiz, surfaceTexture);
    SurfaceTexture_setProducer(env, thiz, producer);

    jclass clazz = env->GetObjectClass(thiz);
    if (clazz == NULL) {
        jniThrowRuntimeException(env,
                "Can't find android/graphics/SurfaceTexture");
        return;
    }

    sp<JNISurfaceTextureContext> ctx(new JNISurfaceTextureContext(env, weakThiz,
            clazz));
    surfaceTexture->setFrameAvailableListener(ctx);
    SurfaceTexture_setFrameAvailableListener(env, thiz, ctx);
}
ECode CSurfaceTexture::NativeInit(
    /* [in] */ Int32 texName,
    /* [in] */ Boolean allowSynchronousMode)
{
    android::sp<android::SurfaceTexture> surfaceTexture(new android::SurfaceTexture(texName, allowSynchronousMode));
    if (surfaceTexture == 0) {
        // jniThrowException(env, OutOfResourcesException,
        //         "Unable to create native SurfaceTexture");
        return E_OUT_OF_RESOURCES_EXCEPTION;
    }
    SurfaceTexture_setSurfaceTexture(this, surfaceTexture);

    android::sp<DroidSurfaceTextureContext> ctx(new DroidSurfaceTextureContext(this));
    surfaceTexture->setFrameAvailableListener(ctx);

    return NOERROR;
}
Exemple #5
0
ECode CSurfaceTexture::NativeInit(
    /* [in] */ Boolean isDetached,
    /* [in] */ Int32 texName,
    /* [in] */ Boolean singleBufferMode,
    /* [in] */ IWeakReference/*<SurfaceTexture>*/* weakSelf) /*throws Surface.OutOfResourcesException*/
{
    android::sp<IGraphicBufferProducer> producer;
    android::sp<IGraphicBufferConsumer> consumer;
    BufferQueue::createBufferQueue(&producer, &consumer);

    if (singleBufferMode) {
        consumer->disableAsyncBuffer();
        consumer->setDefaultMaxBufferCount(1);
    }

    android::sp<GLConsumer> surfaceTexture;
    if (isDetached) {
        surfaceTexture = new GLConsumer(consumer, GL_TEXTURE_EXTERNAL_OES,
                true, true);
    } else {
        surfaceTexture = new GLConsumer(consumer, texName,
                GL_TEXTURE_EXTERNAL_OES, true, true);
    }

    if (surfaceTexture == 0) {
        // jniThrowException(env, OutOfResourcesException,
        //         "Unable to create native SurfaceTexture");
        return E_OUT_OF_RESOURCES_EXCEPTION;
    }
    SurfaceTexture_setSurfaceTexture(this, surfaceTexture);
    SurfaceTexture_setProducer(this, producer);

    // jclass clazz = env->GetObjectClass(thiz);
    // if (clazz == NULL) {
    //     // jniThrowRuntimeException(env,
    //     //         "Can't find android/graphics/SurfaceTexture");
    //     return E_RUNTIME_EXCEPTION;
    // }

    android::sp<DroidSurfaceTextureContext> ctx(new DroidSurfaceTextureContext(weakSelf));
    surfaceTexture->setFrameAvailableListener(ctx);
    SurfaceTexture_setFrameAvailableListener(this, ctx);
    return NOERROR;
}
static void SurfaceTexture_init(JNIEnv* env, jobject thiz, jint texName,
        jobject weakThiz, jboolean allowSynchronous)
{
    sp<SurfaceTexture> surfaceTexture(new SurfaceTexture(texName, allowSynchronous));
    if (surfaceTexture == 0) {
        jniThrowException(env, OutOfResourcesException,
                "Unable to create native SurfaceTexture");
        return;
    }
    SurfaceTexture_setSurfaceTexture(env, thiz, surfaceTexture);

    jclass clazz = env->GetObjectClass(thiz);
    if (clazz == NULL) {
        jniThrowRuntimeException(env,
                "Can't find android/graphics/SurfaceTexture");
        return;
    }

    sp<JNISurfaceTextureContext> ctx(new JNISurfaceTextureContext(env, weakThiz,
            clazz));
    surfaceTexture->setFrameAvailableListener(ctx);
}
void CSurfaceTexture::NativeFinalize()
{
    android::sp<android::SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(this));
    surfaceTexture->setFrameAvailableListener(0);
    SurfaceTexture_setSurfaceTexture(this, 0);
}