diff options
| -rw-r--r-- | core/jni/Android.bp | 6 | ||||
| -rw-r--r-- | core/jni/android_media_ImageReader.cpp | 75 | ||||
| -rw-r--r-- | core/jni/android_media_PublicFormatUtils.cpp | 9 | ||||
| -rw-r--r-- | core/jni/android_media_Utils.cpp | 12 | ||||
| -rw-r--r-- | core/jni/jni_wrappers.h | 2 | ||||
| -rw-r--r-- | core/jni/platform/host/HostRuntime.cpp | 6 | ||||
| -rw-r--r-- | libs/hostgraphics/include/gui/BufferItemConsumer.h | 29 | ||||
| -rw-r--r-- | libs/hostgraphics/include/gui/Surface.h | 4 | ||||
| -rw-r--r-- | libs/hostgraphics/include/ui/Fence.h | 4 |
9 files changed, 110 insertions, 37 deletions
diff --git a/core/jni/Android.bp b/core/jni/Android.bp index 06702e2fa4bf..f1c73dca8574 100644 --- a/core/jni/Android.bp +++ b/core/jni/Android.bp @@ -76,6 +76,9 @@ cc_library_shared_for_libandroid_runtime { srcs: [ "android_animation_PropertyValuesHolder.cpp", "android_content_res_ApkAssets.cpp", + "android_media_ImageReader.cpp", + "android_media_PublicFormatUtils.cpp", + "android_media_Utils.cpp", "android_os_SystemClock.cpp", "android_os_SystemProperties.cpp", "android_text_AndroidCharacter.cpp", @@ -134,10 +137,7 @@ cc_library_shared_for_libandroid_runtime { "android_app_ActivityThread.cpp", "android_app_NativeActivity.cpp", "android_app_admin_SecurityLog.cpp", - "android_media_ImageReader.cpp", "android_media_ImageWriter.cpp", - "android_media_PublicFormatUtils.cpp", - "android_media_Utils.cpp", "android_opengl_EGL14.cpp", "android_opengl_EGL15.cpp", "android_opengl_EGLExt.cpp", diff --git a/core/jni/android_media_ImageReader.cpp b/core/jni/android_media_ImageReader.cpp index 20b9c571317e..a34cb391c2fd 100644 --- a/core/jni/android_media_ImageReader.cpp +++ b/core/jni/android_media_ImageReader.cpp @@ -25,13 +25,22 @@ #include <android_runtime/android_view_Surface.h> #include <com_android_graphics_libgui_flags.h> #include <cutils/atomic.h> +#ifdef __ANDROID__ #include <grallocusage/GrallocUsageConversion.h> +#else +#define GRALLOC_USAGE_PROTECTED 0 +#define GRALLOC_USAGE_SW_READ_OFTEN 0 +#define GRALLOC_USAGE_SW_WRITE_OFTEN 0 +#endif #include <gui/BufferItemConsumer.h> #include <gui/Surface.h> #include <inttypes.h> #include <jni.h> +#include <jni_wrappers.h> #include <nativehelper/JNIHelp.h> +#ifdef __ANDROID__ #include <private/android/AHardwareBufferHelpers.h> +#endif #include <stdint.h> #include <ui/Rect.h> #include <utils/List.h> @@ -393,8 +402,12 @@ static void ImageReader_init(JNIEnv* env, jobject thiz, jobject weakThiz, jint w String8 consumerName = String8::format("ImageReader-%dx%df%xm%d-%d-%d", width, height, nativeHalFormat, maxImages, getpid(), createProcessUniqueId()); +#ifdef __ANDROID__ uint64_t consumerUsage = android_hardware_HardwareBuffer_convertToGrallocUsageBits(ndkUsage); +#else + uint64_t consumerUsage = 0; +#endif #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ) sp<BufferItemConsumer> bufferConsumer = new BufferItemConsumer(consumerUsage, maxImages, @@ -773,6 +786,7 @@ static bool Image_getLockedImageInfo(JNIEnv* env, LockedImage* buffer, int idx, return true; } +#ifdef __ANDROID__ static void ImageReader_unlockGraphicBuffer(JNIEnv* env, jobject /*thiz*/, jobject buffer) { sp<GraphicBuffer> graphicBuffer = @@ -856,6 +870,7 @@ static jobjectArray ImageReader_createImagePlanes(JNIEnv* env, jobject /*thiz*/, return imagePlanes; } +#endif static jobjectArray Image_createSurfacePlanes(JNIEnv* env, jobject thiz, int numPlanes, int halReaderFormat, uint64_t ndkReaderUsage) @@ -964,6 +979,7 @@ static jint Image_getFormat(JNIEnv* env, jobject thiz, jint readerFormat) } } +#ifdef __ANDROID__ static jobject Image_getHardwareBuffer(JNIEnv* env, jobject thiz) { BufferItem* buffer = Image_getBufferItem(env, thiz); if (buffer == nullptr) { @@ -976,45 +992,48 @@ static jobject Image_getHardwareBuffer(JNIEnv* env, jobject thiz) { // to link against libandroid.so return android_hardware_HardwareBuffer_createFromAHardwareBuffer(env, b); } +#endif } // extern "C" // ---------------------------------------------------------------------------- -static const JNINativeMethod gImageReaderMethods[] = { - {"nativeClassInit", "()V", (void*)ImageReader_classInit }, - {"nativeInit", "(Ljava/lang/Object;IIIJII)V", (void*)ImageReader_init }, - {"nativeClose", "()V", (void*)ImageReader_close }, - {"nativeReleaseImage", "(Landroid/media/Image;)V", (void*)ImageReader_imageRelease }, - {"nativeImageSetup", "(Landroid/media/Image;)I", (void*)ImageReader_imageSetup }, - {"nativeGetSurface", "()Landroid/view/Surface;", (void*)ImageReader_getSurface }, - {"nativeDetachImage", "(Landroid/media/Image;Z)I", (void*)ImageReader_detachImage }, - {"nativeCreateImagePlanes", - "(ILandroid/graphics/GraphicBuffer;IIIIII)[Landroid/media/ImageReader$ImagePlane;", - (void*)ImageReader_createImagePlanes }, - {"nativeUnlockGraphicBuffer", - "(Landroid/graphics/GraphicBuffer;)V", (void*)ImageReader_unlockGraphicBuffer }, - {"nativeDiscardFreeBuffers", "()V", (void*)ImageReader_discardFreeBuffers } -}; +static const JNINativeMethod gImageReaderMethods[] = + {{"nativeClassInit", "()V", (void*)ImageReader_classInit}, + {"nativeInit", "(Ljava/lang/Object;IIIJII)V", (void*)ImageReader_init}, + {"nativeClose", "()V", (void*)ImageReader_close}, + {"nativeReleaseImage", "(Landroid/media/Image;)V", (void*)ImageReader_imageRelease}, + {"nativeImageSetup", "(Landroid/media/Image;)I", (void*)ImageReader_imageSetup}, + {"nativeGetSurface", "()Landroid/view/Surface;", (void*)ImageReader_getSurface}, + {"nativeDetachImage", "(Landroid/media/Image;Z)I", (void*)ImageReader_detachImage}, +#ifdef __ANDROID__ + {"nativeCreateImagePlanes", + "(ILandroid/graphics/GraphicBuffer;IIIIII)[Landroid/media/ImageReader$ImagePlane;", + (void*)ImageReader_createImagePlanes}, + {"nativeUnlockGraphicBuffer", "(Landroid/graphics/GraphicBuffer;)V", + (void*)ImageReader_unlockGraphicBuffer}, +#endif + {"nativeDiscardFreeBuffers", "()V", (void*)ImageReader_discardFreeBuffers}}; static const JNINativeMethod gImageMethods[] = { - {"nativeCreatePlanes", "(IIJ)[Landroid/media/ImageReader$SurfaceImage$SurfacePlane;", - (void*)Image_createSurfacePlanes }, - {"nativeGetWidth", "()I", (void*)Image_getWidth }, - {"nativeGetHeight", "()I", (void*)Image_getHeight }, - {"nativeGetFormat", "(I)I", (void*)Image_getFormat }, - {"nativeGetFenceFd", "()I", (void*)Image_getFenceFd }, - {"nativeGetHardwareBuffer", "()Landroid/hardware/HardwareBuffer;", - (void*)Image_getHardwareBuffer }, + {"nativeCreatePlanes", "(IIJ)[Landroid/media/ImageReader$SurfaceImage$SurfacePlane;", + (void*)Image_createSurfacePlanes}, + {"nativeGetWidth", "()I", (void*)Image_getWidth}, + {"nativeGetHeight", "()I", (void*)Image_getHeight}, + {"nativeGetFormat", "(I)I", (void*)Image_getFormat}, + {"nativeGetFenceFd", "()I", (void*)Image_getFenceFd}, +#ifdef __ANDROID__ + {"nativeGetHardwareBuffer", "()Landroid/hardware/HardwareBuffer;", + (void*)Image_getHardwareBuffer}, +#endif }; int register_android_media_ImageReader(JNIEnv *env) { + int ret1 = RegisterMethodsOrDie(env, "android/media/ImageReader", gImageReaderMethods, + NELEM(gImageReaderMethods)); - int ret1 = AndroidRuntime::registerNativeMethods(env, - "android/media/ImageReader", gImageReaderMethods, NELEM(gImageReaderMethods)); - - int ret2 = AndroidRuntime::registerNativeMethods(env, - "android/media/ImageReader$SurfaceImage", gImageMethods, NELEM(gImageMethods)); + int ret2 = RegisterMethodsOrDie(env, "android/media/ImageReader$SurfaceImage", gImageMethods, + NELEM(gImageMethods)); return (ret1 || ret2); } diff --git a/core/jni/android_media_PublicFormatUtils.cpp b/core/jni/android_media_PublicFormatUtils.cpp index 04494ad00a65..bcdf654d5a8c 100644 --- a/core/jni/android_media_PublicFormatUtils.cpp +++ b/core/jni/android_media_PublicFormatUtils.cpp @@ -16,10 +16,10 @@ #define LOG_TAG "PublicFormatUtils_JNI" -#include <utils/misc.h> -#include <ui/PublicFormat.h> -#include <android_runtime/AndroidRuntime.h> #include <jni.h> +#include <jni_wrappers.h> +#include <ui/PublicFormat.h> +#include <utils/misc.h> using namespace android; @@ -53,7 +53,6 @@ static const JNINativeMethod gMethods[] = { }; int register_android_media_PublicFormatUtils(JNIEnv *env) { - return AndroidRuntime::registerNativeMethods(env, - "android/media/PublicFormatUtils", gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, "android/media/PublicFormatUtils", gMethods, NELEM(gMethods)); } diff --git a/core/jni/android_media_Utils.cpp b/core/jni/android_media_Utils.cpp index e8f8644a4503..e48414113cf0 100644 --- a/core/jni/android_media_Utils.cpp +++ b/core/jni/android_media_Utils.cpp @@ -19,10 +19,12 @@ #include "android_media_Utils.h" +#ifdef __ANDROID__ // Layoutlib does not support hardware #include <aidl/android/hardware/graphics/common/PixelFormat.h> #include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h> #include <ui/GraphicBufferMapper.h> #include <ui/GraphicTypes.h> +#endif #include <utils/Log.h> #define ALIGN(x, mask) ( ((x) + (mask) - 1) & ~((mask) - 1) ) @@ -34,7 +36,13 @@ namespace android { // -----------Utility functions used by ImageReader/Writer JNI----------------- +#ifdef __ANDROID__ using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat; +#else +namespace AidlPixelFormat { +const int32_t YCBCR_P210 = 60; +} +#endif enum { IMAGE_MAX_NUM_PLANES = 3, @@ -517,6 +525,7 @@ status_t getLockedImageInfo(LockedImage* buffer, int idx, return OK; } +#ifdef __ANDROID__ static status_t extractP010Gralloc4PlaneLayout( sp<GraphicBuffer> buffer, void *pData, int format, LockedImage *outputImage) { using aidl::android::hardware::graphics::common::PlaneLayoutComponent; @@ -663,6 +672,7 @@ static status_t extractP210Gralloc4PlaneLayout(sp<GraphicBuffer> buffer, void *p outputImage->chromaStep = 4; return OK; } +#endif status_t lockImageFromBuffer(sp<GraphicBuffer> buffer, uint32_t inUsage, const Rect& rect, int fenceFd, LockedImage* outputImage) { @@ -701,6 +711,7 @@ status_t lockImageFromBuffer(sp<GraphicBuffer> buffer, uint32_t inUsage, ALOGE("Lock buffer failed!"); return res; } +#ifdef __ANDROID__ if (isPossibly10BitYUV(format)) { if (format == HAL_PIXEL_FORMAT_YCBCR_P010 && OK == extractP010Gralloc4PlaneLayout(buffer, pData, format, outputImage)) { @@ -713,6 +724,7 @@ status_t lockImageFromBuffer(sp<GraphicBuffer> buffer, uint32_t inUsage, return OK; } } +#endif } outputImage->data = reinterpret_cast<uint8_t*>(pData); diff --git a/core/jni/jni_wrappers.h b/core/jni/jni_wrappers.h index e3e17eed54d5..1f44994b54f2 100644 --- a/core/jni/jni_wrappers.h +++ b/core/jni/jni_wrappers.h @@ -22,6 +22,8 @@ #include <log/log.h> #include <nativehelper/JNIHelp.h> +#include <string> + namespace android { static inline jclass FindClassOrDie(JNIEnv* env, const char* class_name) { diff --git a/core/jni/platform/host/HostRuntime.cpp b/core/jni/platform/host/HostRuntime.cpp index 1a0328338980..746740b0248b 100644 --- a/core/jni/platform/host/HostRuntime.cpp +++ b/core/jni/platform/host/HostRuntime.cpp @@ -48,6 +48,8 @@ using namespace std; * (see AndroidRuntime.cpp). */ +extern int register_android_media_ImageReader(JNIEnv* env); +extern int register_android_media_PublicFormatUtils(JNIEnv* env); extern int register_android_os_Binder(JNIEnv* env); extern int register_libcore_util_NativeAllocationRegistry(JNIEnv* env); @@ -126,6 +128,10 @@ static const std::unordered_map<std::string, RegJNIRec> gRegJNIMap = { {"android.database.sqlite.SQLiteDebug", REG_JNI(register_android_database_SQLiteDebug)}, {"android.database.sqlite.SQLiteRawStatement", REG_JNI(register_android_database_SQLiteRawStatement)}, +#endif + {"android.media.ImageReader", REG_JNI(register_android_media_ImageReader)}, + {"android.media.PublicFormatUtils", REG_JNI(register_android_media_PublicFormatUtils)}, +#ifdef __linux__ {"android.os.Binder", REG_JNI(register_android_os_Binder)}, {"android.os.FileObserver", REG_JNI(register_android_os_FileObserver)}, {"android.os.MessageQueue", REG_JNI(register_android_os_MessageQueue)}, diff --git a/libs/hostgraphics/include/gui/BufferItemConsumer.h b/libs/hostgraphics/include/gui/BufferItemConsumer.h index c25941151800..5c96c82e061c 100644 --- a/libs/hostgraphics/include/gui/BufferItemConsumer.h +++ b/libs/hostgraphics/include/gui/BufferItemConsumer.h @@ -17,6 +17,8 @@ #ifndef ANDROID_GUI_BUFFERITEMCONSUMER_H #define ANDROID_GUI_BUFFERITEMCONSUMER_H +#include <com_android_graphics_libgui_flags.h> +#include <gui/BufferQueue.h> #include <gui/ConsumerBase.h> #include <gui/IGraphicBufferConsumer.h> #include <utils/RefBase.h> @@ -26,9 +28,22 @@ namespace android { class BufferItemConsumer : public ConsumerBase { public: BufferItemConsumer(const sp<IGraphicBufferConsumer>& consumer, uint64_t consumerUsage, - int bufferCount, bool controlledByApp) + int bufferCount = -1, bool controlledByApp = false) : mConsumer(consumer) {} +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ) + BufferItemConsumer(uint64_t consumerUsage, int bufferCount = -1, + bool controlledByApp = false, bool isConsumerSurfaceFlinger = false) { + sp<IGraphicBufferProducer> producer; + BufferQueue::createBufferQueue(&producer, &mConsumer); + mSurface = sp<Surface>::make(producer, controlledByApp); + } + + status_t setConsumerIsProtected(bool isProtected) { + return OK; + } +#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ) + status_t acquireBuffer(BufferItem* item, nsecs_t presentWhen, bool waitForFence = true) { return mConsumer->acquireBuffer(item, presentWhen, 0); } @@ -71,8 +86,20 @@ public: return OK; } +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ) +// Returns a Surface that can be used as the producer for this consumer. + sp<Surface> getSurface() const { + return mSurface; + } +#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ) + private: sp<IGraphicBufferConsumer> mConsumer; +#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ) + // This Surface wraps the IGraphicBufferConsumer created for this + // ConsumerBase. + sp<Surface> mSurface; +#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ) }; } // namespace android diff --git a/libs/hostgraphics/include/gui/Surface.h b/libs/hostgraphics/include/gui/Surface.h index 2774f89cb54c..e268ce6ca769 100644 --- a/libs/hostgraphics/include/gui/Surface.h +++ b/libs/hostgraphics/include/gui/Surface.h @@ -34,6 +34,10 @@ public: ANativeWindow::query = hook_query; } + sp<IGraphicBufferProducer> getIGraphicBufferProducer() const { + return mBufferProducer; + } + static bool isValid(const sp<Surface>& surface) { return surface != nullptr; } diff --git a/libs/hostgraphics/include/ui/Fence.h b/libs/hostgraphics/include/ui/Fence.h index 187c3116f61c..3364b8aed605 100644 --- a/libs/hostgraphics/include/ui/Fence.h +++ b/libs/hostgraphics/include/ui/Fence.h @@ -60,6 +60,10 @@ public: return 0; } + int get() const { + return 0; + } + inline Status getStatus() { // The sync_wait call underlying wait() has been measured to be // significantly faster than the sync_fence_info call underlying |