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

Commit 2c6f80fe authored by Sally Qi's avatar Sally Qi Committed by Android (Google) Code Review
Browse files

Merge "[Lut] Function changes due to setLuts signature changes, and use...

Merge "[Lut] Function changes due to setLuts signature changes, and use ScopedArrayRO instead because it's cheaper." into main
parents 0fd067c6 2ba62bee
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -765,28 +765,28 @@ static void nativeSetLuts(JNIEnv* env, jclass clazz, jlong transactionObj, jlong
    std::vector<int32_t> dimensions;
    std::vector<int32_t> sizes;
    std::vector<int32_t> samplingKeys;
    int32_t fd = -1;
    base::unique_fd fd;

    if (jdimensionArray) {
        jsize numLuts = env->GetArrayLength(jdimensionArray);
        ScopedIntArrayRW joffsets(env, joffsetArray);
        ScopedIntArrayRO joffsets(env, joffsetArray);
        if (joffsets.get() == nullptr) {
            jniThrowRuntimeException(env, "Failed to get ScopedIntArrayRW from joffsetArray");
            jniThrowRuntimeException(env, "Failed to get ScopedIntArrayRO from joffsetArray");
            return;
        }
        ScopedIntArrayRW jdimensions(env, jdimensionArray);
        ScopedIntArrayRO jdimensions(env, jdimensionArray);
        if (jdimensions.get() == nullptr) {
            jniThrowRuntimeException(env, "Failed to get ScopedIntArrayRW from jdimensionArray");
            jniThrowRuntimeException(env, "Failed to get ScopedIntArrayRO from jdimensionArray");
            return;
        }
        ScopedIntArrayRW jsizes(env, jsizeArray);
        ScopedIntArrayRO jsizes(env, jsizeArray);
        if (jsizes.get() == nullptr) {
            jniThrowRuntimeException(env, "Failed to get ScopedIntArrayRW from jsizeArray");
            jniThrowRuntimeException(env, "Failed to get ScopedIntArrayRO from jsizeArray");
            return;
        }
        ScopedIntArrayRW jsamplingKeys(env, jsamplingKeyArray);
        ScopedIntArrayRO jsamplingKeys(env, jsamplingKeyArray);
        if (jsamplingKeys.get() == nullptr) {
            jniThrowRuntimeException(env, "Failed to get ScopedIntArrayRW from jsamplingKeyArray");
            jniThrowRuntimeException(env, "Failed to get ScopedIntArrayRO from jsamplingKeyArray");
            return;
        }

@@ -796,15 +796,15 @@ static void nativeSetLuts(JNIEnv* env, jclass clazz, jlong transactionObj, jlong
            sizes = std::vector<int32_t>(jsizes.get(), jsizes.get() + numLuts);
            samplingKeys = std::vector<int32_t>(jsamplingKeys.get(), jsamplingKeys.get() + numLuts);

            ScopedFloatArrayRW jbuffers(env, jbufferArray);
            ScopedFloatArrayRO jbuffers(env, jbufferArray);
            if (jbuffers.get() == nullptr) {
                jniThrowRuntimeException(env, "Failed to get ScopedFloatArrayRW from jbufferArray");
                jniThrowRuntimeException(env, "Failed to get ScopedFloatArrayRO from jbufferArray");
                return;
            }

            // create the shared memory and copy jbuffers
            size_t bufferSize = jbuffers.size() * sizeof(float);
            fd = ashmem_create_region("lut_shared_mem", bufferSize);
            fd.reset(ashmem_create_region("lut_shared_mem", bufferSize));
            if (fd < 0) {
                jniThrowRuntimeException(env, "ashmem_create_region() failed");
                return;
@@ -820,7 +820,7 @@ static void nativeSetLuts(JNIEnv* env, jclass clazz, jlong transactionObj, jlong
        }
    }

    transaction->setLuts(ctrl, base::unique_fd(fd), offsets, dimensions, sizes, samplingKeys);
    transaction->setLuts(ctrl, std::move(fd), offsets, dimensions, sizes, samplingKeys);
}

static void nativeSetPictureProfileId(JNIEnv* env, jclass clazz, jlong transactionObj,
+13 −15
Original line number Diff line number Diff line
@@ -715,47 +715,45 @@ void ASurfaceTransaction_setLuts(ASurfaceTransaction* aSurfaceTransaction,
    sp<SurfaceControl> surfaceControl = ASurfaceControl_to_SurfaceControl(aSurfaceControl);
    Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);

    int fd = -1;
    base::unique_fd fd;
    std::vector<int32_t> offsets;
    std::vector<int32_t> dimensions;
    std::vector<int32_t> sizes;
    std::vector<int32_t> samplingKeys;

    if (luts) {
        std::vector<float> buffer(luts->totalBufferSize);
        int32_t count = luts->offsets.size();
        offsets = luts->offsets;

        dimensions.reserve(count);
        sizes.reserve(count);
        samplingKeys.reserve(count);
        for (int32_t i = 0; i < count; i++) {
            dimensions.emplace_back(luts->entries[i]->properties.dimension);
            sizes.emplace_back(luts->entries[i]->properties.size);
            samplingKeys.emplace_back(luts->entries[i]->properties.samplingKey);
            std::copy(luts->entries[i]->buffer.data.begin(), luts->entries[i]->buffer.data.end(),
                      buffer.begin() + offsets[i]);
        }

        // mmap
        fd = ashmem_create_region("lut_shared_mem", luts->totalBufferSize * sizeof(float));
        fd.reset(ashmem_create_region("lut_shared_mem", luts->totalBufferSize * sizeof(float)));
        if (fd < 0) {
            LOG_ALWAYS_FATAL("setLuts, ashmem_create_region() failed");
            return;
        }
        void* ptr = mmap(nullptr, luts->totalBufferSize * sizeof(float), PROT_READ | PROT_WRITE,
                         MAP_SHARED, fd, 0);
        float* ptr = (float*)mmap(nullptr, luts->totalBufferSize * sizeof(float),
                                  PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
        if (ptr == MAP_FAILED) {
            LOG_ALWAYS_FATAL("setLuts, Failed to map the shared memory");
            return;
        }

        memcpy(ptr, buffer.data(), luts->totalBufferSize * sizeof(float));
        for (int32_t i = 0; i < count; i++) {
            dimensions.emplace_back(luts->entries[i]->properties.dimension);
            sizes.emplace_back(luts->entries[i]->properties.size);
            samplingKeys.emplace_back(luts->entries[i]->properties.samplingKey);
            std::copy(luts->entries[i]->buffer.data.begin(), luts->entries[i]->buffer.data.end(),
                      ptr + offsets[i]);
        }

        munmap(ptr, luts->totalBufferSize * sizeof(float));
    }

    transaction->setLuts(surfaceControl, base::unique_fd(fd), offsets, dimensions, sizes,
                         samplingKeys);
    transaction->setLuts(surfaceControl, std::move(fd), offsets, dimensions, sizes, samplingKeys);
}

void ASurfaceTransaction_setColor(ASurfaceTransaction* aSurfaceTransaction,