Merge "ImageReader: Add discardFreeBuffers method" into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b417eb176f
@@ -520,6 +520,31 @@ public class ImageReader implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discard any free buffers owned by this ImageReader.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Generally, the ImageReader caches buffers for reuse once they have been
|
||||||
|
* allocated, for best performance. However, sometimes it may be important to
|
||||||
|
* release all the cached, unused buffers to save on memory.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Calling this method will discard all free cached buffers. This does not include any buffers
|
||||||
|
* associated with Images acquired from the ImageReader, any filled buffers waiting to be
|
||||||
|
* acquired, and any buffers currently in use by the source rendering buffers into the
|
||||||
|
* ImageReader's Surface.
|
||||||
|
* <p>
|
||||||
|
* The ImageReader continues to be usable after this call, but may need to reallocate buffers
|
||||||
|
* when more buffers are needed for rendering.
|
||||||
|
* </p>
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void discardFreeBuffers() {
|
||||||
|
synchronized (mCloseLock) {
|
||||||
|
nativeDiscardFreeBuffers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
try {
|
try {
|
||||||
@@ -872,6 +897,7 @@ public class ImageReader implements AutoCloseable {
|
|||||||
private synchronized native void nativeReleaseImage(Image i);
|
private synchronized native void nativeReleaseImage(Image i);
|
||||||
private synchronized native Surface nativeGetSurface();
|
private synchronized native Surface nativeGetSurface();
|
||||||
private synchronized native int nativeDetachImage(Image i);
|
private synchronized native int nativeDetachImage(Image i);
|
||||||
|
private synchronized native void nativeDiscardFreeBuffers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A return code {@code ACQUIRE_*}
|
* @return A return code {@code ACQUIRE_*}
|
||||||
|
|||||||
@@ -611,6 +611,23 @@ static jint ImageReader_detachImage(JNIEnv* env, jobject thiz, jobject image) {
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ImageReader_discardFreeBuffers(JNIEnv* env, jobject thiz) {
|
||||||
|
ALOGV("%s:", __FUNCTION__);
|
||||||
|
JNIImageReaderContext* ctx = ImageReader_getContext(env, thiz);
|
||||||
|
if (ctx == NULL) {
|
||||||
|
jniThrowException(env, "java/lang/IllegalStateException", "ImageReader was already closed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferItemConsumer* bufferConsumer = ctx->getBufferConsumer();
|
||||||
|
status_t res = bufferConsumer->discardFreeBuffers();
|
||||||
|
if (res != OK) {
|
||||||
|
ALOGE("Buffer discard failed: %s (%d)", strerror(-res), res);
|
||||||
|
jniThrowRuntimeException(env,
|
||||||
|
"nativeDicardFreebuffers failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static jobject ImageReader_getSurface(JNIEnv* env, jobject thiz)
|
static jobject ImageReader_getSurface(JNIEnv* env, jobject thiz)
|
||||||
{
|
{
|
||||||
ALOGV("%s: ", __FUNCTION__);
|
ALOGV("%s: ", __FUNCTION__);
|
||||||
@@ -773,6 +790,7 @@ static const JNINativeMethod gImageReaderMethods[] = {
|
|||||||
{"nativeImageSetup", "(Landroid/media/Image;)I", (void*)ImageReader_imageSetup },
|
{"nativeImageSetup", "(Landroid/media/Image;)I", (void*)ImageReader_imageSetup },
|
||||||
{"nativeGetSurface", "()Landroid/view/Surface;", (void*)ImageReader_getSurface },
|
{"nativeGetSurface", "()Landroid/view/Surface;", (void*)ImageReader_getSurface },
|
||||||
{"nativeDetachImage", "(Landroid/media/Image;)I", (void*)ImageReader_detachImage },
|
{"nativeDetachImage", "(Landroid/media/Image;)I", (void*)ImageReader_detachImage },
|
||||||
|
{"nativeDiscardFreeBuffers", "()V", (void*)ImageReader_discardFreeBuffers }
|
||||||
};
|
};
|
||||||
|
|
||||||
static const JNINativeMethod gImageMethods[] = {
|
static const JNINativeMethod gImageMethods[] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user