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

Commit 2262c268 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8456972 from 006a15b8 to tm-release

Change-Id: Id9ef1c8b6c84943e9588b9b0ae4c702c95365cdc
parents f4be6ce3 006a15b8
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -375,6 +375,12 @@ status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) {
        return err;
    }

    String16 userTag;
    if ((err = parcel->readString16(&userTag)) != OK) {
        ALOGE("%s: Failed to read user tag!", __FUNCTION__);
        return BAD_VALUE;
    }

    mCameraId = id;
    mFacing = facing;
    mNewCameraState = newCameraState;
@@ -389,6 +395,7 @@ status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) {
    mResultErrorCount = resultErrorCount;
    mDeviceError = deviceError;
    mStreamStats = std::move(streamStats);
    mUserTag = userTag;

    return OK;
}
@@ -471,6 +478,10 @@ status_t CameraSessionStats::writeToParcel(android::Parcel* parcel) const {
        return err;
    }

    if ((err = parcel->writeString16(mUserTag)) != OK) {
        ALOGE("%s: Failed to write user tag!", __FUNCTION__);
        return err;
    }
    return OK;
}

+22 −0
Original line number Diff line number Diff line
@@ -146,6 +146,20 @@ status_t CaptureRequest::readFromParcel(const android::Parcel* parcel) {
        mSurfaceIdxList.push_back(surfaceIdx);
    }

    int32_t hasUserTag;
    if ((err = parcel->readInt32(&hasUserTag)) != OK) {
        ALOGE("%s: Failed to read user tag availability flag", __FUNCTION__);
        return BAD_VALUE;
    }
    if (hasUserTag) {
        String16 userTag;
        if ((err = parcel->readString16(&userTag)) != OK) {
            ALOGE("%s: Failed to read user tag!", __FUNCTION__);
            return BAD_VALUE;
        }
        mUserTag = String8(userTag).c_str();
    }

    return OK;
}

@@ -213,6 +227,14 @@ status_t CaptureRequest::writeToParcel(android::Parcel* parcel) const {
            return err;
        }
    }

    if (mUserTag.empty()) {
        parcel->writeInt32(0);
    } else {
        parcel->writeInt32(1);
        parcel->writeString16(String16(mUserTag.c_str()));
    }

    return OK;
}

+1 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ public:
    // Whether the device runs into an error state
    bool mDeviceError;
    std::vector<CameraStreamStats> mStreamStats;
    String16 mUserTag;

    // Constructors
    CameraSessionStats();
+2 −0
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ struct CaptureRequest : public Parcelable {

    void*                   mContext; // arbitrary user context from NDK apps, null for java apps

    std::string             mUserTag; // The string representation of object passed into setTag.

    /**
     * Keep impl up-to-date with CaptureRequest.java in frameworks/base
     */
+64 −37
Original line number Diff line number Diff line
@@ -984,16 +984,47 @@ sp<IMapper4> GetMapper4() {
    return sMapper;
}

class NativeHandleDeleter {
class Gralloc4Buffer {
public:
    explicit NativeHandleDeleter(native_handle_t *handle) : mHandle(handle) {}
    ~NativeHandleDeleter() {
        if (mHandle) {
            native_handle_delete(mHandle);
    Gralloc4Buffer(const C2Handle *const handle) : mBuffer(nullptr) {
        sp<IMapper4> mapper = GetMapper4();
        if (!mapper) {
            return;
        }
        // Unwrap raw buffer handle from the C2Handle
        native_handle_t *nh = UnwrapNativeCodec2GrallocHandle(handle);
        if (!nh) {
            return;
        }
        // Import the raw handle so IMapper can use the buffer. The imported
        // handle must be freed when the client is done with the buffer.
        mapper->importBuffer(
                hardware::hidl_handle(nh),
                [&](const Error4 &error, void *buffer) {
                    if (error == Error4::NONE) {
                        mBuffer = buffer;
                    }
                });

        // TRICKY: UnwrapNativeCodec2GrallocHandle creates a new handle but
        //         does not clone the fds. Thus we need to delete the handle
        //         without closing it.
        native_handle_delete(nh);
    }

    ~Gralloc4Buffer() {
        sp<IMapper4> mapper = GetMapper4();
        if (mapper && mBuffer) {
            // Free the imported buffer handle. This does not release the
            // underlying buffer itself.
            mapper->freeBuffer(mBuffer);
        }
    }

    void *get() const { return mBuffer; }
    operator bool() const { return (mBuffer != nullptr); }
private:
    native_handle_t *mHandle;
    void *mBuffer;
};

}  // namspace
@@ -1003,24 +1034,15 @@ c2_status_t GetHdrMetadataFromGralloc4Handle(
        std::shared_ptr<C2StreamHdrStaticMetadataInfo::input> *staticInfo,
        std::shared_ptr<C2StreamHdrDynamicMetadataInfo::input> *dynamicInfo) {
    c2_status_t err = C2_OK;
    native_handle_t *nativeHandle = UnwrapNativeCodec2GrallocHandle(handle);
    if (nativeHandle == nullptr) {
        // Nothing to do
        return err;
    }
    // TRICKY: UnwrapNativeCodec2GrallocHandle creates a new handle but
    //         does not clone the fds. Thus we need to delete the handle
    //         without closing it when going out of scope.
    //         NativeHandle cannot solve this problem, as it would close and
    //         delete the handle, while we need delete only.
    NativeHandleDeleter nhd(nativeHandle);
    sp<IMapper4> mapper = GetMapper4();
    if (!mapper) {
    Gralloc4Buffer buffer(handle);
    if (!mapper || !buffer) {
        // Gralloc4 not supported; nothing to do
        return err;
    }
    Error4 mapperErr = Error4::NONE;
    if (staticInfo) {
        ALOGV("Grabbing static HDR info from gralloc4 metadata");
        staticInfo->reset(new C2StreamHdrStaticMetadataInfo::input(0u));
        memset(&(*staticInfo)->mastering, 0, sizeof((*staticInfo)->mastering));
        (*staticInfo)->maxCll = 0;
@@ -1049,7 +1071,7 @@ c2_status_t GetHdrMetadataFromGralloc4Handle(
                mapperErr = Error4::BAD_VALUE;
            }
        };
        Return<void> ret = mapper->get(nativeHandle, MetadataType_Smpte2086, cb);
        Return<void> ret = mapper->get(buffer.get(), MetadataType_Smpte2086, cb);
        if (!ret.isOk()) {
            err = C2_REFUSED;
        } else if (mapperErr != Error4::NONE) {
@@ -1070,7 +1092,7 @@ c2_status_t GetHdrMetadataFromGralloc4Handle(
                mapperErr = Error4::BAD_VALUE;
            }
        };
        ret = mapper->get(nativeHandle, MetadataType_Cta861_3, cb);
        ret = mapper->get(buffer.get(), MetadataType_Cta861_3, cb);
        if (!ret.isOk()) {
            err = C2_REFUSED;
        } else if (mapperErr != Error4::NONE) {
@@ -1078,6 +1100,7 @@ c2_status_t GetHdrMetadataFromGralloc4Handle(
        }
    }
    if (dynamicInfo) {
        ALOGV("Grabbing dynamic HDR info from gralloc4 metadata");
        dynamicInfo->reset();
        IMapper4::get_cb cb = [&mapperErr, dynamicInfo](Error4 err, const hidl_vec<uint8_t> &vec) {
            mapperErr = err;
@@ -1091,7 +1114,7 @@ c2_status_t GetHdrMetadataFromGralloc4Handle(
                    vec.size(), 0u, C2Config::HDR_DYNAMIC_METADATA_TYPE_SMPTE_2094_40);
            memcpy((*dynamicInfo)->m.data, vec.data(), vec.size());
        };
        Return<void> ret = mapper->get(nativeHandle, MetadataType_Smpte2094_40, cb);
        Return<void> ret = mapper->get(buffer.get(), MetadataType_Smpte2094_40, cb);
        if (!ret.isOk() || mapperErr != Error4::NONE) {
            dynamicInfo->reset();
        }
@@ -1105,21 +1128,14 @@ c2_status_t SetHdrMetadataToGralloc4Handle(
        const std::shared_ptr<const C2StreamHdrDynamicMetadataInfo::output> &dynamicInfo,
        const C2Handle *const handle) {
    c2_status_t err = C2_OK;
    native_handle_t *nativeHandle = UnwrapNativeCodec2GrallocHandle(handle);
    if (nativeHandle == nullptr) {
        // Nothing to do
        return err;
    }
    // TRICKY: UnwrapNativeCodec2GrallocHandle creates a new handle but
    //         does not clone the fds. Thus we need to delete the handle
    //         without closing it when going out of scope.
    NativeHandleDeleter nhd(nativeHandle);
    sp<IMapper4> mapper = GetMapper4();
    if (!mapper) {
    Gralloc4Buffer buffer(handle);
    if (!mapper || !buffer) {
        // Gralloc4 not supported; nothing to do
        return err;
    }
    if (staticInfo && *staticInfo) {
        ALOGV("Setting static HDR info as gralloc4 metadata");
        std::optional<Smpte2086> smpte2086 = Smpte2086{
            {staticInfo->mastering.red.x, staticInfo->mastering.red.y},
            {staticInfo->mastering.green.x, staticInfo->mastering.green.y},
@@ -1129,8 +1145,17 @@ c2_status_t SetHdrMetadataToGralloc4Handle(
            staticInfo->mastering.minLuminance,
        };
        hidl_vec<uint8_t> vec;
        if (gralloc4::encodeSmpte2086(smpte2086, &vec) == OK) {
            Return<Error4> ret = mapper->set(nativeHandle, MetadataType_Smpte2086, vec);
        if (0.0 <= smpte2086->primaryRed.x && smpte2086->primaryRed.x <= 1.0
                && 0.0 <= smpte2086->primaryRed.y && smpte2086->primaryRed.y <= 1.0
                && 0.0 <= smpte2086->primaryGreen.x && smpte2086->primaryGreen.x <= 1.0
                && 0.0 <= smpte2086->primaryGreen.y && smpte2086->primaryGreen.y <= 1.0
                && 0.0 <= smpte2086->primaryBlue.x && smpte2086->primaryBlue.x <= 1.0
                && 0.0 <= smpte2086->primaryBlue.y && smpte2086->primaryBlue.y <= 1.0
                && 0.0 <= smpte2086->whitePoint.x && smpte2086->whitePoint.x <= 1.0
                && 0.0 <= smpte2086->whitePoint.y && smpte2086->whitePoint.y <= 1.0
                && 0.0 <= smpte2086->maxLuminance && 0.0 <= smpte2086->minLuminance
                && gralloc4::encodeSmpte2086(smpte2086, &vec) == OK) {
            Return<Error4> ret = mapper->set(buffer.get(), MetadataType_Smpte2086, vec);
            if (!ret.isOk()) {
                err = C2_REFUSED;
            } else if (ret != Error4::NONE) {
@@ -1141,8 +1166,9 @@ c2_status_t SetHdrMetadataToGralloc4Handle(
            staticInfo->maxCll,
            staticInfo->maxFall,
        };
        if (gralloc4::encodeCta861_3(cta861_3, &vec) == OK) {
            Return<Error4> ret = mapper->set(nativeHandle, MetadataType_Cta861_3, vec);
        if (0.0 <= cta861_3->maxContentLightLevel && 0.0 <= cta861_3->maxFrameAverageLightLevel
                && gralloc4::encodeCta861_3(cta861_3, &vec) == OK) {
            Return<Error4> ret = mapper->set(buffer.get(), MetadataType_Cta861_3, vec);
            if (!ret.isOk()) {
                err = C2_REFUSED;
            } else if (ret != Error4::NONE) {
@@ -1150,7 +1176,8 @@ c2_status_t SetHdrMetadataToGralloc4Handle(
            }
        }
    }
    if (dynamicInfo && *dynamicInfo) {
    if (dynamicInfo && *dynamicInfo && dynamicInfo->flexCount() > 0) {
        ALOGV("Setting dynamic HDR info as gralloc4 metadata");
        hidl_vec<uint8_t> vec;
        vec.resize(dynamicInfo->flexCount());
        memcpy(vec.data(), dynamicInfo->m.data, dynamicInfo->flexCount());
@@ -1164,7 +1191,7 @@ c2_status_t SetHdrMetadataToGralloc4Handle(
            break;
        }
        if (metadataType) {
            Return<Error4> ret = mapper->set(nativeHandle, *metadataType, vec);
            Return<Error4> ret = mapper->set(buffer.get(), *metadataType, vec);
            if (!ret.isOk()) {
                err = C2_REFUSED;
            } else if (ret != Error4::NONE) {
Loading