diff options
author | Mathias Agopian <mathias@google.com> | 2013-08-02 01:38:38 -0700 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2013-08-06 13:07:42 -0700 |
commit | 52a9a10b6b8c7b7a9f97777541841b94d4fd9754 (patch) | |
tree | aaf72e50f157c69abc8be70991c16e93bef47fc4 | |
parent | 0dff7064897afd4e07993bac28ae877aaeb1b5e3 (diff) | |
download | frameworks_base-52a9a10b6b8c7b7a9f97777541841b94d4fd9754.zip frameworks_base-52a9a10b6b8c7b7a9f97777541841b94d4fd9754.tar.gz frameworks_base-52a9a10b6b8c7b7a9f97777541841b94d4fd9754.tar.bz2 |
Clearly separate consumer and producer interfaces
Bug: 9265647
Change-Id: Ic68e91788d0a05251e1d2fb9f9d4de403c7099bf
-rw-r--r-- | core/java/android/view/TextureView.java | 9 | ||||
-rw-r--r-- | core/jni/android/graphics/SurfaceTexture.cpp | 51 | ||||
-rw-r--r-- | core/jni/android_hardware_Camera.cpp | 12 | ||||
-rw-r--r-- | core/jni/android_opengl_EGL14.cpp | 8 | ||||
-rw-r--r-- | core/jni/android_view_Surface.cpp | 7 | ||||
-rw-r--r-- | core/jni/android_view_TextureView.cpp | 14 | ||||
-rw-r--r-- | core/jni/com_google_android_gles_jni_EGLImpl.cpp | 5 | ||||
-rw-r--r-- | graphics/java/android/graphics/SurfaceTexture.java | 1 | ||||
-rw-r--r-- | include/android_runtime/android_graphics_SurfaceTexture.h | 7 | ||||
-rw-r--r-- | media/jni/android_media_ImageReader.cpp | 24 | ||||
-rw-r--r-- | media/mca/filterfw/native/core/gl_env.cpp | 3 |
11 files changed, 83 insertions, 58 deletions
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java index 52ad76d..b2c9f8c 100644 --- a/core/java/android/view/TextureView.java +++ b/core/java/android/view/TextureView.java @@ -322,7 +322,7 @@ public class TextureView extends View { protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (mSurface != null) { - nSetDefaultBufferSize(mSurface, getWidth(), getHeight()); + mSurface.setDefaultBufferSize(getWidth(), getHeight()); updateLayer(); if (mListener != null) { mListener.onSurfaceTextureSizeChanged(mSurface, getWidth(), getHeight()); @@ -362,7 +362,7 @@ public class TextureView extends View { // Create a new SurfaceTexture for the layer. mSurface = mAttachInfo.mHardwareRenderer.createSurfaceTexture(mLayer); } - nSetDefaultBufferSize(mSurface, getWidth(), getHeight()); + mSurface.setDefaultBufferSize(getWidth(), getHeight()); nCreateNativeWindow(mSurface); mUpdateListener = new SurfaceTexture.OnFrameAvailableListener() { @@ -399,7 +399,7 @@ public class TextureView extends View { mMatrixChanged = true; mAttachInfo.mHardwareRenderer.setSurfaceTexture(mLayer, mSurface); - nSetDefaultBufferSize(mSurface, getWidth(), getHeight()); + mSurface.setDefaultBufferSize(getWidth(), getHeight()); } applyUpdate(); @@ -816,9 +816,6 @@ public class TextureView extends View { private native void nCreateNativeWindow(SurfaceTexture surface); private native void nDestroyNativeWindow(); - private static native void nSetDefaultBufferSize(SurfaceTexture surfaceTexture, - int width, int height); - private static native boolean nLockCanvas(int nativeWindow, Canvas canvas, Rect dirty); private static native void nUnlockCanvasAndPost(int nativeWindow, Canvas canvas); } diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp index 31b2cad..2c482ea 100644 --- a/core/jni/android/graphics/SurfaceTexture.cpp +++ b/core/jni/android/graphics/SurfaceTexture.cpp @@ -40,6 +40,7 @@ const char* const kSurfaceTextureClassPathName = "android/graphics/SurfaceTextur struct fields_t { jfieldID surfaceTexture; + jfieldID bufferQueue; jfieldID frameAvailableListener; jmethodID postEvent; }; @@ -61,6 +62,20 @@ static void SurfaceTexture_setSurfaceTexture(JNIEnv* env, jobject thiz, env->SetIntField(thiz, fields.surfaceTexture, (int)surfaceTexture.get()); } +static void SurfaceTexture_setBufferQueue(JNIEnv* env, jobject thiz, + const sp<BufferQueue>& bq) +{ + BufferQueue* const p = + (BufferQueue*)env->GetIntField(thiz, fields.bufferQueue); + if (bq.get()) { + bq->incStrong((void*)SurfaceTexture_setBufferQueue); + } + if (p) { + p->decStrong((void*)SurfaceTexture_setBufferQueue); + } + env->SetIntField(thiz, fields.bufferQueue, (int)bq.get()); +} + static void SurfaceTexture_setFrameAvailableListener(JNIEnv* env, jobject thiz, sp<GLConsumer::FrameAvailableListener> listener) { @@ -76,23 +91,22 @@ static void SurfaceTexture_setFrameAvailableListener(JNIEnv* env, env->SetIntField(thiz, fields.frameAvailableListener, (int)listener.get()); } -sp<GLConsumer> SurfaceTexture_getSurfaceTexture(JNIEnv* env, - jobject thiz) -{ +sp<GLConsumer> SurfaceTexture_getSurfaceTexture(JNIEnv* env, jobject thiz) { return (GLConsumer*)env->GetIntField(thiz, fields.surfaceTexture); } -sp<ANativeWindow> android_SurfaceTexture_getNativeWindow( - JNIEnv* env, jobject thiz) -{ +sp<IGraphicBufferProducer> SurfaceTexture_getProducer(JNIEnv* env, jobject thiz) { + return (BufferQueue*)env->GetIntField(thiz, fields.bufferQueue); +} + +sp<ANativeWindow> android_SurfaceTexture_getNativeWindow(JNIEnv* env, jobject thiz) { sp<GLConsumer> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz)); - sp<Surface> surfaceTextureClient(surfaceTexture != NULL ? - new Surface(surfaceTexture->getBufferQueue()) : NULL); + sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(env, thiz)); + sp<Surface> surfaceTextureClient(surfaceTexture != NULL ? new Surface(producer) : NULL); return surfaceTextureClient; } -bool android_SurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz) -{ +bool android_SurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz) { jclass surfaceTextureClass = env->FindClass(kSurfaceTextureClassPathName); return env->IsInstanceOf(thiz, surfaceTextureClass); } @@ -175,6 +189,12 @@ void JNISurfaceTextureContext::onFrameAvailable() // ---------------------------------------------------------------------------- + +#define ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID "mSurfaceTexture" +#define ANDROID_GRAPHICS_BUFFERQUEUE_JNI_ID "mBufferQueue" +#define ANDROID_GRAPHICS_FRAMEAVAILABLELISTENER_JNI_ID \ + "mFrameAvailableListener" + static void SurfaceTexture_classInit(JNIEnv* env, jclass clazz) { fields.surfaceTexture = env->GetFieldID(clazz, @@ -183,6 +203,12 @@ static void SurfaceTexture_classInit(JNIEnv* env, jclass clazz) ALOGE("can't find android/graphics/SurfaceTexture.%s", ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID); } + fields.bufferQueue = env->GetFieldID(clazz, + ANDROID_GRAPHICS_BUFFERQUEUE_JNI_ID, "I"); + if (fields.bufferQueue == NULL) { + ALOGE("can't find android/graphics/SurfaceTexture.%s", + ANDROID_GRAPHICS_BUFFERQUEUE_JNI_ID); + } fields.frameAvailableListener = env->GetFieldID(clazz, ANDROID_GRAPHICS_FRAMEAVAILABLELISTENER_JNI_ID, "I"); if (fields.frameAvailableListener == NULL) { @@ -214,6 +240,7 @@ static void SurfaceTexture_init(JNIEnv* env, jobject thiz, return; } SurfaceTexture_setSurfaceTexture(env, thiz, surfaceTexture); + SurfaceTexture_setBufferQueue(env, thiz, bq); jclass clazz = env->GetObjectClass(thiz); if (clazz == NULL) { @@ -234,11 +261,11 @@ static void SurfaceTexture_finalize(JNIEnv* env, jobject thiz) surfaceTexture->setFrameAvailableListener(0); SurfaceTexture_setFrameAvailableListener(env, thiz, 0); SurfaceTexture_setSurfaceTexture(env, thiz, 0); + SurfaceTexture_setBufferQueue(env, thiz, 0); } static void SurfaceTexture_setDefaultBufferSize( - JNIEnv* env, jobject thiz, jint width, jint height) -{ + JNIEnv* env, jobject thiz, jint width, jint height) { sp<GLConsumer> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz)); surfaceTexture->setDefaultBufferSize(width, height); } diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp index dec4cd4..0018dd2 100644 --- a/core/jni/android_hardware_Camera.cpp +++ b/core/jni/android_hardware_Camera.cpp @@ -565,14 +565,10 @@ static void android_hardware_Camera_setPreviewTexture(JNIEnv *env, sp<Camera> camera = get_native_camera(env, thiz, NULL); if (camera == 0) return; - sp<BufferQueue> bufferQueue = NULL; + sp<IGraphicBufferProducer> producer = NULL; if (jSurfaceTexture != NULL) { - sp<GLConsumer> surfaceTexture = - SurfaceTexture_getSurfaceTexture(env, jSurfaceTexture); - if (surfaceTexture != NULL) { - bufferQueue = surfaceTexture->getBufferQueue(); - } - else { + producer = SurfaceTexture_getProducer(env, jSurfaceTexture); + if (producer == NULL) { jniThrowException(env, "java/lang/IllegalArgumentException", "SurfaceTexture already released in setPreviewTexture"); return; @@ -580,7 +576,7 @@ static void android_hardware_Camera_setPreviewTexture(JNIEnv *env, } - if (camera->setPreviewTexture(bufferQueue) != NO_ERROR) { + if (camera->setPreviewTexture(producer) != NO_ERROR) { jniThrowException(env, "java/io/IOException", "setPreviewTexture failed"); } diff --git a/core/jni/android_opengl_EGL14.cpp b/core/jni/android_opengl_EGL14.cpp index 48babb3..1fe4b08 100644 --- a/core/jni/android_opengl_EGL14.cpp +++ b/core/jni/android_opengl_EGL14.cpp @@ -604,7 +604,7 @@ android_eglCreateWindowSurfaceTexture jint _remaining; EGLint *attrib_list = (EGLint *) 0; android::sp<ANativeWindow> window; - android::sp<android::GLConsumer> glConsumer; + android::sp<android::IGraphicBufferProducer> producer; if (!attrib_list_ref) { _exception = 1; @@ -625,12 +625,12 @@ not_valid_surface: _exceptionMessage = "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"; goto exit; } - glConsumer = android::SurfaceTexture_getSurfaceTexture(_env, win); + producer = android::SurfaceTexture_getProducer(_env, win); - if (glConsumer == NULL) + if (producer == NULL) goto not_valid_surface; - window = new android::Surface(glConsumer->getBufferQueue()); + window = new android::Surface(producer); if (window == NULL) goto not_valid_surface; diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index 1007e7d..304514b 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -135,15 +135,14 @@ static inline bool isSurfaceValid(const sp<Surface>& sur) { static jint nativeCreateFromSurfaceTexture(JNIEnv* env, jclass clazz, jobject surfaceTextureObj) { - sp<GLConsumer> st(SurfaceTexture_getSurfaceTexture(env, surfaceTextureObj)); - if (st == NULL) { + sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(env, surfaceTextureObj)); + if (producer == NULL) { jniThrowException(env, "java/lang/IllegalArgumentException", "SurfaceTexture has already been released"); return 0; } - sp<IGraphicBufferProducer> bq = st->getBufferQueue(); - sp<Surface> surface(new Surface(bq, true)); + sp<Surface> surface(new Surface(producer, true)); if (surface == NULL) { jniThrowException(env, OutOfResourcesException, NULL); return 0; diff --git a/core/jni/android_view_TextureView.cpp b/core/jni/android_view_TextureView.cpp index d515696..8dc2fc6 100644 --- a/core/jni/android_view_TextureView.cpp +++ b/core/jni/android_view_TextureView.cpp @@ -69,13 +69,6 @@ static struct { // Native layer // ---------------------------------------------------------------------------- -static void android_view_TextureView_setDefaultBufferSize(JNIEnv* env, jobject, - jobject surface, jint width, jint height) { - - sp<GLConsumer> glConsumer(SurfaceTexture_getSurfaceTexture(env, surface)); - glConsumer->setDefaultBufferSize(width, height); -} - static inline SkBitmap::Config convertPixelFormat(int32_t format) { switch (format) { case WINDOW_FORMAT_RGBA_8888: @@ -106,8 +99,8 @@ static int32_t native_window_unlockAndPost(ANativeWindow* window) { static void android_view_TextureView_createNativeWindow(JNIEnv* env, jobject textureView, jobject surface) { - sp<GLConsumer> glConsumer(SurfaceTexture_getSurfaceTexture(env, surface)); - sp<ANativeWindow> window = new Surface(glConsumer->getBufferQueue()); + sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(env, surface)); + sp<ANativeWindow> window = new Surface(producer); window->incStrong((void*)android_view_TextureView_createNativeWindow); SET_INT(textureView, gTextureViewClassInfo.nativeWindow, jint(window.get())); @@ -208,9 +201,6 @@ static void android_view_TextureView_unlockCanvasAndPost(JNIEnv* env, jobject, const char* const kClassPathName = "android/view/TextureView"; static JNINativeMethod gMethods[] = { - { "nSetDefaultBufferSize", "(Landroid/graphics/SurfaceTexture;II)V", - (void*) android_view_TextureView_setDefaultBufferSize }, - { "nCreateNativeWindow", "(Landroid/graphics/SurfaceTexture;)V", (void*) android_view_TextureView_createNativeWindow }, { "nDestroyNativeWindow", "()V", diff --git a/core/jni/com_google_android_gles_jni_EGLImpl.cpp b/core/jni/com_google_android_gles_jni_EGLImpl.cpp index b0c73a2..a3ce2a5 100644 --- a/core/jni/com_google_android_gles_jni_EGLImpl.cpp +++ b/core/jni/com_google_android_gles_jni_EGLImpl.cpp @@ -352,9 +352,8 @@ not_valid_surface: return 0; } - sp<GLConsumer> glConsumer(SurfaceTexture_getSurfaceTexture(_env, native_window)); - - window = new Surface(glConsumer->getBufferQueue()); + sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(_env, native_window)); + window = new Surface(producer); if (window == NULL) goto not_valid_surface; diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java index 91deb87..e8d6f16 100644 --- a/graphics/java/android/graphics/SurfaceTexture.java +++ b/graphics/java/android/graphics/SurfaceTexture.java @@ -69,6 +69,7 @@ public class SurfaceTexture { * These fields are used by native code, do not access or modify. */ private int mSurfaceTexture; + private int mBufferQueue; private int mFrameAvailableListener; /** diff --git a/include/android_runtime/android_graphics_SurfaceTexture.h b/include/android_runtime/android_graphics_SurfaceTexture.h index 77ccd2a..c534d4b 100644 --- a/include/android_runtime/android_graphics_SurfaceTexture.h +++ b/include/android_runtime/android_graphics_SurfaceTexture.h @@ -24,14 +24,17 @@ namespace android { class GLConsumer; +class IGraphicBufferProducer; -extern sp<ANativeWindow> android_SurfaceTexture_getNativeWindow( - JNIEnv* env, jobject thiz); +extern sp<ANativeWindow> android_SurfaceTexture_getNativeWindow(JNIEnv* env, jobject thiz); extern bool android_SurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz); /* Gets the underlying GLConsumer from a SurfaceTexture Java object. */ extern sp<GLConsumer> SurfaceTexture_getSurfaceTexture(JNIEnv* env, jobject thiz); +/* gets the producer end of the SurfaceTexture */ +extern sp<IGraphicBufferProducer> SurfaceTexture_getProducer(JNIEnv* env, jobject thiz); + } // namespace android #endif // _ANDROID_GRAPHICS_SURFACETEXTURE_H diff --git a/media/jni/android_media_ImageReader.cpp b/media/jni/android_media_ImageReader.cpp index ecc180c..0b429f6 100644 --- a/media/jni/android_media_ImageReader.cpp +++ b/media/jni/android_media_ImageReader.cpp @@ -78,9 +78,11 @@ public: void returnLockedBuffer(CpuConsumer::LockedBuffer* buffer); + void setCpuConsumer(const sp<CpuConsumer>& consumer) { mConsumer = consumer; } CpuConsumer* getCpuConsumer() { return mConsumer.get(); } - void setCpuConsumer(sp<CpuConsumer> consumer) { mConsumer = consumer; } + void setBufferQueue(const sp<BufferQueue>& bq) { mBufferQueue = bq; } + BufferQueue* getBufferQueue() { return mBufferQueue.get(); } void setBufferFormat(int format) { mFormat = format; } int getBufferFormat() { return mFormat; } @@ -97,6 +99,7 @@ private: List<CpuConsumer::LockedBuffer*> mBuffers; sp<CpuConsumer> mConsumer; + sp<BufferQueue> mBufferQueue; jobject mWeakThiz; jclass mClazz; int mFormat; @@ -214,6 +217,17 @@ static CpuConsumer* ImageReader_getCpuConsumer(JNIEnv* env, jobject thiz) return ctx->getCpuConsumer(); } +static BufferQueue* ImageReader_getBufferQueue(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->getBufferQueue(); +} + static void ImageReader_setNativeContext(JNIEnv* env, jobject thiz, sp<JNIImageReaderContext> ctx) { @@ -609,6 +623,7 @@ static void ImageReader_init(JNIEnv* env, jobject thiz, jobject weakThiz, } sp<JNIImageReaderContext> ctx(new JNIImageReaderContext(env, weakThiz, clazz, maxImages)); ctx->setCpuConsumer(consumer); + ctx->setBufferQueue(bq); consumer->setFrameAvailableListener(ctx); ImageReader_setNativeContext(env, thiz, ctx); ctx->setBufferFormat(nativeFormat); @@ -751,15 +766,14 @@ static jobject ImageReader_getSurface(JNIEnv* env, jobject thiz) { ALOGV("%s: ", __FUNCTION__); - CpuConsumer* consumer = ImageReader_getCpuConsumer(env, thiz); - if (consumer == NULL) { + BufferQueue* bq = ImageReader_getBufferQueue(env, thiz); + if (bq == NULL) { jniThrowRuntimeException(env, "CpuConsumer is uninitialized"); return NULL; } // Wrap the IGBP in a Java-language Surface. - return android_view_Surface_createFromIGraphicBufferProducer( - env, consumer->getProducerInterface()); + return android_view_Surface_createFromIGraphicBufferProducer(env, bq); } static jobject Image_createSurfacePlane(JNIEnv* env, jobject thiz, int idx) diff --git a/media/mca/filterfw/native/core/gl_env.cpp b/media/mca/filterfw/native/core/gl_env.cpp index 63fd16e..fdecda3 100644 --- a/media/mca/filterfw/native/core/gl_env.cpp +++ b/media/mca/filterfw/native/core/gl_env.cpp @@ -162,8 +162,7 @@ bool GLEnv::InitWithNewContext() { // Create dummy surface using a GLConsumer sp<BufferQueue> bq = new BufferQueue(); surfaceTexture_ = new GLConsumer(bq, 0); - window_ = new Surface(static_cast<sp<IGraphicBufferProducer> >( - surfaceTexture_->getBufferQueue())); + window_ = new Surface(static_cast<sp<IGraphicBufferProducer> >(bq)); surfaces_[0] = SurfaceWindowPair(eglCreateWindowSurface(display(), config, window_.get(), NULL), NULL); if (CheckEGLError("eglCreateWindowSurface")) return false; |