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

Commit 29baa8ae authored by Jerome Gaillard's avatar Jerome Gaillard Committed by Android (Google) Code Review
Browse files

Merge "Add ImageReader to host build of libandroid_runtime" into main

parents fa964f7b 79e0a16c
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -76,6 +76,9 @@ cc_library_shared_for_libandroid_runtime {
    srcs: [
    srcs: [
        "android_animation_PropertyValuesHolder.cpp",
        "android_animation_PropertyValuesHolder.cpp",
        "android_content_res_ApkAssets.cpp",
        "android_content_res_ApkAssets.cpp",
        "android_media_ImageReader.cpp",
        "android_media_PublicFormatUtils.cpp",
        "android_media_Utils.cpp",
        "android_os_SystemClock.cpp",
        "android_os_SystemClock.cpp",
        "android_os_SystemProperties.cpp",
        "android_os_SystemProperties.cpp",
        "android_text_AndroidCharacter.cpp",
        "android_text_AndroidCharacter.cpp",
@@ -134,10 +137,7 @@ cc_library_shared_for_libandroid_runtime {
                "android_app_ActivityThread.cpp",
                "android_app_ActivityThread.cpp",
                "android_app_NativeActivity.cpp",
                "android_app_NativeActivity.cpp",
                "android_app_admin_SecurityLog.cpp",
                "android_app_admin_SecurityLog.cpp",
                "android_media_ImageReader.cpp",
                "android_media_ImageWriter.cpp",
                "android_media_ImageWriter.cpp",
                "android_media_PublicFormatUtils.cpp",
                "android_media_Utils.cpp",
                "android_opengl_EGL14.cpp",
                "android_opengl_EGL14.cpp",
                "android_opengl_EGL15.cpp",
                "android_opengl_EGL15.cpp",
                "android_opengl_EGLExt.cpp",
                "android_opengl_EGLExt.cpp",
+47 −28
Original line number Original line Diff line number Diff line
@@ -25,13 +25,22 @@
#include <android_runtime/android_view_Surface.h>
#include <android_runtime/android_view_Surface.h>
#include <com_android_graphics_libgui_flags.h>
#include <com_android_graphics_libgui_flags.h>
#include <cutils/atomic.h>
#include <cutils/atomic.h>
#ifdef __ANDROID__
#include <grallocusage/GrallocUsageConversion.h>
#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/BufferItemConsumer.h>
#include <gui/Surface.h>
#include <gui/Surface.h>
#include <inttypes.h>
#include <inttypes.h>
#include <jni.h>
#include <jni.h>
#include <jni_wrappers.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JNIHelp.h>
#ifdef __ANDROID__
#include <private/android/AHardwareBufferHelpers.h>
#include <private/android/AHardwareBufferHelpers.h>
#endif
#include <stdint.h>
#include <stdint.h>
#include <ui/Rect.h>
#include <ui/Rect.h>
#include <utils/List.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",
    String8 consumerName = String8::format("ImageReader-%dx%df%xm%d-%d-%d",
            width, height, nativeHalFormat, maxImages, getpid(),
            width, height, nativeHalFormat, maxImages, getpid(),
            createProcessUniqueId());
            createProcessUniqueId());
#ifdef __ANDROID__
    uint64_t consumerUsage =
    uint64_t consumerUsage =
            android_hardware_HardwareBuffer_convertToGrallocUsageBits(ndkUsage);
            android_hardware_HardwareBuffer_convertToGrallocUsageBits(ndkUsage);
#else
    uint64_t consumerUsage = 0;
#endif


#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
    sp<BufferItemConsumer> bufferConsumer = new BufferItemConsumer(consumerUsage, maxImages,
    sp<BufferItemConsumer> bufferConsumer = new BufferItemConsumer(consumerUsage, maxImages,
@@ -773,6 +786,7 @@ static bool Image_getLockedImageInfo(JNIEnv* env, LockedImage* buffer, int idx,
    return true;
    return true;
}
}


#ifdef __ANDROID__
static void ImageReader_unlockGraphicBuffer(JNIEnv* env, jobject /*thiz*/,
static void ImageReader_unlockGraphicBuffer(JNIEnv* env, jobject /*thiz*/,
        jobject buffer) {
        jobject buffer) {
    sp<GraphicBuffer> graphicBuffer =
    sp<GraphicBuffer> graphicBuffer =
@@ -856,6 +870,7 @@ static jobjectArray ImageReader_createImagePlanes(JNIEnv* env, jobject /*thiz*/,


    return imagePlanes;
    return imagePlanes;
}
}
#endif


static jobjectArray Image_createSurfacePlanes(JNIEnv* env, jobject thiz,
static jobjectArray Image_createSurfacePlanes(JNIEnv* env, jobject thiz,
        int numPlanes, int halReaderFormat, uint64_t ndkReaderUsage)
        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) {
static jobject Image_getHardwareBuffer(JNIEnv* env, jobject thiz) {
    BufferItem* buffer = Image_getBufferItem(env, thiz);
    BufferItem* buffer = Image_getBufferItem(env, thiz);
    if (buffer == nullptr) {
    if (buffer == nullptr) {
@@ -976,26 +992,28 @@ static jobject Image_getHardwareBuffer(JNIEnv* env, jobject thiz) {
    // to link against libandroid.so
    // to link against libandroid.so
    return android_hardware_HardwareBuffer_createFromAHardwareBuffer(env, b);
    return android_hardware_HardwareBuffer_createFromAHardwareBuffer(env, b);
}
}
#endif


} // extern "C"
} // extern "C"


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


static const JNINativeMethod gImageReaderMethods[] = {
static const JNINativeMethod gImageReaderMethods[] =
    {"nativeClassInit",        "()V",                        (void*)ImageReader_classInit },
        {{"nativeClassInit", "()V", (void*)ImageReader_classInit},
         {"nativeInit", "(Ljava/lang/Object;IIIJII)V", (void*)ImageReader_init},
         {"nativeInit", "(Ljava/lang/Object;IIIJII)V", (void*)ImageReader_init},
         {"nativeClose", "()V", (void*)ImageReader_close},
         {"nativeClose", "()V", (void*)ImageReader_close},
         {"nativeReleaseImage", "(Landroid/media/Image;)V", (void*)ImageReader_imageRelease},
         {"nativeReleaseImage", "(Landroid/media/Image;)V", (void*)ImageReader_imageRelease},
         {"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;Z)I", (void*)ImageReader_detachImage},
         {"nativeDetachImage", "(Landroid/media/Image;Z)I", (void*)ImageReader_detachImage},
#ifdef __ANDROID__
         {"nativeCreateImagePlanes",
         {"nativeCreateImagePlanes",
          "(ILandroid/graphics/GraphicBuffer;IIIIII)[Landroid/media/ImageReader$ImagePlane;",
          "(ILandroid/graphics/GraphicBuffer;IIIIII)[Landroid/media/ImageReader$ImagePlane;",
          (void*)ImageReader_createImagePlanes},
          (void*)ImageReader_createImagePlanes},
    {"nativeUnlockGraphicBuffer",
         {"nativeUnlockGraphicBuffer", "(Landroid/graphics/GraphicBuffer;)V",
        "(Landroid/graphics/GraphicBuffer;)V",             (void*)ImageReader_unlockGraphicBuffer },
          (void*)ImageReader_unlockGraphicBuffer},
    {"nativeDiscardFreeBuffers", "()V",                      (void*)ImageReader_discardFreeBuffers }
#endif
};
         {"nativeDiscardFreeBuffers", "()V", (void*)ImageReader_discardFreeBuffers}};


static const JNINativeMethod gImageMethods[] = {
static const JNINativeMethod gImageMethods[] = {
        {"nativeCreatePlanes", "(IIJ)[Landroid/media/ImageReader$SurfaceImage$SurfacePlane;",
        {"nativeCreatePlanes", "(IIJ)[Landroid/media/ImageReader$SurfaceImage$SurfacePlane;",
@@ -1004,17 +1022,18 @@ static const JNINativeMethod gImageMethods[] = {
        {"nativeGetHeight", "()I", (void*)Image_getHeight},
        {"nativeGetHeight", "()I", (void*)Image_getHeight},
        {"nativeGetFormat", "(I)I", (void*)Image_getFormat},
        {"nativeGetFormat", "(I)I", (void*)Image_getFormat},
        {"nativeGetFenceFd", "()I", (void*)Image_getFenceFd},
        {"nativeGetFenceFd", "()I", (void*)Image_getFenceFd},
#ifdef __ANDROID__
        {"nativeGetHardwareBuffer", "()Landroid/hardware/HardwareBuffer;",
        {"nativeGetHardwareBuffer", "()Landroid/hardware/HardwareBuffer;",
         (void*)Image_getHardwareBuffer},
         (void*)Image_getHardwareBuffer},
#endif
};
};


int register_android_media_ImageReader(JNIEnv *env) {
int register_android_media_ImageReader(JNIEnv *env) {
    int ret1 = RegisterMethodsOrDie(env, "android/media/ImageReader", gImageReaderMethods,
                                    NELEM(gImageReaderMethods));


    int ret1 = AndroidRuntime::registerNativeMethods(env,
    int ret2 = RegisterMethodsOrDie(env, "android/media/ImageReader$SurfaceImage", gImageMethods,
                   "android/media/ImageReader", gImageReaderMethods, NELEM(gImageReaderMethods));
                                    NELEM(gImageMethods));

    int ret2 = AndroidRuntime::registerNativeMethods(env,
                   "android/media/ImageReader$SurfaceImage", gImageMethods, NELEM(gImageMethods));


    return (ret1 || ret2);
    return (ret1 || ret2);
}
}
+4 −5
Original line number Original line Diff line number Diff line
@@ -16,10 +16,10 @@


#define LOG_TAG "PublicFormatUtils_JNI"
#define LOG_TAG "PublicFormatUtils_JNI"


#include <utils/misc.h>
#include <ui/PublicFormat.h>
#include <android_runtime/AndroidRuntime.h>
#include <jni.h>
#include <jni.h>
#include <jni_wrappers.h>
#include <ui/PublicFormat.h>
#include <utils/misc.h>


using namespace android;
using namespace android;


@@ -53,7 +53,6 @@ static const JNINativeMethod gMethods[] = {
};
};


int register_android_media_PublicFormatUtils(JNIEnv *env) {
int register_android_media_PublicFormatUtils(JNIEnv *env) {
    return AndroidRuntime::registerNativeMethods(env,
    return RegisterMethodsOrDie(env, "android/media/PublicFormatUtils", gMethods, NELEM(gMethods));
             "android/media/PublicFormatUtils", gMethods, NELEM(gMethods));
}
}
+12 −0
Original line number Original line Diff line number Diff line
@@ -19,10 +19,12 @@


#include "android_media_Utils.h"
#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/PixelFormat.h>
#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
#include <ui/GraphicBufferMapper.h>
#include <ui/GraphicBufferMapper.h>
#include <ui/GraphicTypes.h>
#include <ui/GraphicTypes.h>
#endif
#include <utils/Log.h>
#include <utils/Log.h>


#define ALIGN(x, mask) ( ((x) + (mask) - 1) & ~((mask) - 1) )
#define ALIGN(x, mask) ( ((x) + (mask) - 1) & ~((mask) - 1) )
@@ -34,7 +36,13 @@ namespace android {


// -----------Utility functions used by ImageReader/Writer JNI-----------------
// -----------Utility functions used by ImageReader/Writer JNI-----------------


#ifdef __ANDROID__
using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
#else
namespace AidlPixelFormat {
const int32_t YCBCR_P210 = 60;
}
#endif


enum {
enum {
    IMAGE_MAX_NUM_PLANES = 3,
    IMAGE_MAX_NUM_PLANES = 3,
@@ -517,6 +525,7 @@ status_t getLockedImageInfo(LockedImage* buffer, int idx,
    return OK;
    return OK;
}
}


#ifdef __ANDROID__
static status_t extractP010Gralloc4PlaneLayout(
static status_t extractP010Gralloc4PlaneLayout(
        sp<GraphicBuffer> buffer, void *pData, int format, LockedImage *outputImage) {
        sp<GraphicBuffer> buffer, void *pData, int format, LockedImage *outputImage) {
    using aidl::android::hardware::graphics::common::PlaneLayoutComponent;
    using aidl::android::hardware::graphics::common::PlaneLayoutComponent;
@@ -663,6 +672,7 @@ static status_t extractP210Gralloc4PlaneLayout(sp<GraphicBuffer> buffer, void *p
    outputImage->chromaStep = 4;
    outputImage->chromaStep = 4;
    return OK;
    return OK;
}
}
#endif


status_t lockImageFromBuffer(sp<GraphicBuffer> buffer, uint32_t inUsage,
status_t lockImageFromBuffer(sp<GraphicBuffer> buffer, uint32_t inUsage,
        const Rect& rect, int fenceFd, LockedImage* outputImage) {
        const Rect& rect, int fenceFd, LockedImage* outputImage) {
@@ -701,6 +711,7 @@ status_t lockImageFromBuffer(sp<GraphicBuffer> buffer, uint32_t inUsage,
            ALOGE("Lock buffer failed!");
            ALOGE("Lock buffer failed!");
            return res;
            return res;
        }
        }
#ifdef __ANDROID__
        if (isPossibly10BitYUV(format)) {
        if (isPossibly10BitYUV(format)) {
            if (format == HAL_PIXEL_FORMAT_YCBCR_P010 &&
            if (format == HAL_PIXEL_FORMAT_YCBCR_P010 &&
                OK == extractP010Gralloc4PlaneLayout(buffer, pData, format, outputImage)) {
                OK == extractP010Gralloc4PlaneLayout(buffer, pData, format, outputImage)) {
@@ -713,6 +724,7 @@ status_t lockImageFromBuffer(sp<GraphicBuffer> buffer, uint32_t inUsage,
                return OK;
                return OK;
            }
            }
        }
        }
#endif
    }
    }


    outputImage->data = reinterpret_cast<uint8_t*>(pData);
    outputImage->data = reinterpret_cast<uint8_t*>(pData);
+2 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,8 @@
#include <log/log.h>
#include <log/log.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JNIHelp.h>


#include <string>

namespace android {
namespace android {


static inline jclass FindClassOrDie(JNIEnv* env, const char* class_name) {
static inline jclass FindClassOrDie(JNIEnv* env, const char* class_name) {
Loading