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

Commit 6d891a0c authored by Emilian Peev's avatar Emilian Peev Committed by Automerger Merge Worker
Browse files

DO NOT MERGE Camera: Enable session parameter handling for Rotate&Crop am: b9f8381c

parents d781906b b9f8381c
Loading
Loading
Loading
Loading
+59 −23
Original line number Diff line number Diff line
@@ -97,6 +97,8 @@ Camera3Device::Camera3Device(const String8 &id, bool overrideForPerfClass, bool
        mNeedFixupMonochromeTags(false),
        mOverrideForPerfClass(overrideForPerfClass),
        mOverrideToPortrait(overrideToPortrait),
        mRotateAndCropOverride(ANDROID_SCALER_ROTATE_AND_CROP_NONE),
        mComposerOutput(false),
        mActivePhysicalId("")
{
    ATRACE_CALL();
@@ -1360,12 +1362,34 @@ status_t Camera3Device::filterParamsAndConfigureLocked(const CameraMetadata& ses
    set_camera_metadata_vendor_id(meta, mVendorTagId);
    filteredParams.unlock(meta);
    if (availableSessionKeys.count > 0) {
        bool rotateAndCropSessionKey = false;
        for (size_t i = 0; i < availableSessionKeys.count; i++) {
            camera_metadata_ro_entry entry = params.find(
                    availableSessionKeys.data.i32[i]);
            if (entry.count > 0) {
                filteredParams.update(entry);
            }
            if (ANDROID_SCALER_ROTATE_AND_CROP == availableSessionKeys.data.i32[i]) {
                rotateAndCropSessionKey = true;
            }
        }

        if (rotateAndCropSessionKey) {
            sp<CaptureRequest> request = new CaptureRequest();
            PhysicalCameraSettings settingsList;
            settingsList.metadata = filteredParams;
            request->mSettingsList.push_back(settingsList);

            auto rotateAndCropEntry = filteredParams.find(ANDROID_SCALER_ROTATE_AND_CROP);
            if (rotateAndCropEntry.count > 0 &&
                    rotateAndCropEntry.data.u8[0] == ANDROID_SCALER_ROTATE_AND_CROP_AUTO) {
                request->mRotateAndCropAuto = true;
            } else {
                request->mRotateAndCropAuto = false;
            }

            overrideAutoRotateAndCrop(request, mOverrideToPortrait, mRotateAndCropOverride);
            filteredParams = request->mSettingsList.begin()->metadata;
        }
    }

@@ -2377,7 +2401,7 @@ status_t Camera3Device::configureStreamsLocked(int operatingMode,
    }

    mGroupIdPhysicalCameraMap.clear();
    bool composerSurfacePresent = false;
    mComposerOutput = false;
    for (size_t i = 0; i < mOutputStreams.size(); i++) {

        // Don't configure bidi streams twice, nor add them twice to the list
@@ -2420,7 +2444,7 @@ status_t Camera3Device::configureStreamsLocked(int operatingMode,
        }

        if (outputStream->usage & GraphicBuffer::USAGE_HW_COMPOSER) {
            composerSurfacePresent = true;
            mComposerOutput = true;
        }
    }

@@ -2489,7 +2513,7 @@ status_t Camera3Device::configureStreamsLocked(int operatingMode,
        }
    }

    mRequestThread->setComposerSurface(composerSurfacePresent);
    mRequestThread->setComposerSurface(mComposerOutput);

    // Request thread needs to know to avoid using repeat-last-settings protocol
    // across configure_streams() calls
@@ -3442,6 +3466,16 @@ bool Camera3Device::RequestThread::threadLoop() {
        latestRequestId = NAME_NOT_FOUND;
    }

    for (size_t i = 0; i < mNextRequests.size(); i++) {
        auto& nextRequest = mNextRequests.editItemAt(i);
        sp<CaptureRequest> captureRequest = nextRequest.captureRequest;
        // Do not override rotate&crop for stream configurations that include
        // SurfaceViews(HW_COMPOSER) output, unless mOverrideToPortrait is set.
        // The display rotation there will be compensated by NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY
        captureRequest->mRotateAndCropChanged = (mComposerOutput && !mOverrideToPortrait) ? false :
            overrideAutoRotateAndCrop(captureRequest);
    }

    // 'mNextRequests' will at this point contain either a set of HFR batched requests
    //  or a single request from streaming or burst. In either case the first element
    //  should contain the latest camera settings that we need to check for any session
@@ -3587,18 +3621,13 @@ status_t Camera3Device::RequestThread::prepareHalRequests() {
        bool triggersMixedIn = (triggerCount > 0 || mPrevTriggers > 0);
        mPrevTriggers = triggerCount;

        // Do not override rotate&crop for stream configurations that include
        // SurfaceViews(HW_COMPOSER) output, unless mOverrideToPortrait is set.
        // The display rotation there will be compensated by NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY
        bool rotateAndCropChanged = (mComposerOutput && !mOverrideToPortrait) ? false :
            overrideAutoRotateAndCrop(captureRequest);
        bool testPatternChanged = overrideTestPattern(captureRequest);

        // If the request is the same as last, or we had triggers now or last time or
        // changing overrides this time
        bool newRequest =
                (mPrevRequest != captureRequest || triggersMixedIn ||
                        rotateAndCropChanged || testPatternChanged) &&
                        captureRequest->mRotateAndCropChanged || testPatternChanged) &&
                // Request settings are all the same within one batch, so only treat the first
                // request in a batch as new
                !(batchedRequest && i > 0);
@@ -4061,9 +4090,6 @@ status_t Camera3Device::RequestThread::setRotateAndCropAutoBehavior(
        camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropValue) {
    ATRACE_CALL();
    Mutex::Autolock l(mTriggerMutex);
    if (rotateAndCropValue == ANDROID_SCALER_ROTATE_AND_CROP_AUTO) {
        return BAD_VALUE;
    }
    mRotateAndCropOverride = rotateAndCropValue;
    return OK;
}
@@ -4645,13 +4671,20 @@ status_t Camera3Device::RequestThread::addFakeTriggerIds(
    return OK;
}

bool Camera3Device::RequestThread::overrideAutoRotateAndCrop(
        const sp<CaptureRequest> &request) {
bool Camera3Device::RequestThread::overrideAutoRotateAndCrop(const sp<CaptureRequest> &request) {
    ATRACE_CALL();

    if (mOverrideToPortrait) {
    Mutex::Autolock l(mTriggerMutex);
        uint8_t rotateAndCrop_u8 = mRotateAndCropOverride;
    return Camera3Device::overrideAutoRotateAndCrop(request, this->mOverrideToPortrait,
            this->mRotateAndCropOverride);
}

bool Camera3Device::overrideAutoRotateAndCrop(const sp<CaptureRequest> &request,
        bool overrideToPortrait,
        camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropOverride) {
    ATRACE_CALL();

    if (overrideToPortrait) {
        uint8_t rotateAndCrop_u8 = rotateAndCropOverride;
        CameraMetadata &metadata = request->mSettingsList.begin()->metadata;
        metadata.update(ANDROID_SCALER_ROTATE_AND_CROP,
                &rotateAndCrop_u8, 1);
@@ -4659,24 +4692,23 @@ bool Camera3Device::RequestThread::overrideAutoRotateAndCrop(
    }

    if (request->mRotateAndCropAuto) {
        Mutex::Autolock l(mTriggerMutex);
        CameraMetadata &metadata = request->mSettingsList.begin()->metadata;

        auto rotateAndCropEntry = metadata.find(ANDROID_SCALER_ROTATE_AND_CROP);
        if (rotateAndCropEntry.count > 0) {
            if (rotateAndCropEntry.data.u8[0] == mRotateAndCropOverride) {
            if (rotateAndCropEntry.data.u8[0] == rotateAndCropOverride) {
                return false;
            } else {
                rotateAndCropEntry.data.u8[0] = mRotateAndCropOverride;
                rotateAndCropEntry.data.u8[0] = rotateAndCropOverride;
                return true;
            }
        } else {
            uint8_t rotateAndCrop_u8 = mRotateAndCropOverride;
            metadata.update(ANDROID_SCALER_ROTATE_AND_CROP,
                    &rotateAndCrop_u8, 1);
            uint8_t rotateAndCrop_u8 = rotateAndCropOverride;
            metadata.update(ANDROID_SCALER_ROTATE_AND_CROP, &rotateAndCrop_u8, 1);
            return true;
        }
    }

    return false;
}

@@ -5162,6 +5194,10 @@ status_t Camera3Device::setRotateAndCropAutoBehavior(
    if (mRequestThread == nullptr) {
        return INVALID_OPERATION;
    }
    if (rotateAndCropValue == ANDROID_SCALER_ROTATE_AND_CROP_AUTO) {
        return BAD_VALUE;
    }
    mRotateAndCropOverride = rotateAndCropValue;
    return mRequestThread->setRotateAndCropAutoBehavior(rotateAndCropValue);
}

+11 −1
Original line number Diff line number Diff line
@@ -603,6 +603,9 @@ class Camera3Device :
        // overriding of ROTATE_AND_CROP value and adjustment of coordinates
        // in several other controls in both the request and the result
        bool                                mRotateAndCropAuto;
        // Indicates that the ROTATE_AND_CROP value within 'mSettingsList' was modified
        // irrespective of the original value.
        bool                                mRotateAndCropChanged = false;

        // Whether this capture request has its zoom ratio set to 1.0x before
        // the framework overrides it for camera HAL consumption.
@@ -789,6 +792,11 @@ class Camera3Device :
     */
    static nsecs_t getMonoToBoottimeOffset();

    // Override rotate_and_crop control if needed
    static bool    overrideAutoRotateAndCrop(const sp<CaptureRequest> &request /*out*/,
            bool overrideToPortrait,
            camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropOverride);

    struct RequestTrigger {
        // Metadata tag number, e.g. android.control.aePrecaptureTrigger
        uint32_t metadataTag;
@@ -942,7 +950,7 @@ class Camera3Device :
        status_t           addFakeTriggerIds(const sp<CaptureRequest> &request);

        // Override rotate_and_crop control if needed; returns true if the current value was changed
        bool               overrideAutoRotateAndCrop(const sp<CaptureRequest> &request);
        bool               overrideAutoRotateAndCrop(const sp<CaptureRequest> &request /*out*/);

        // Override test_pattern control if needed for camera mute; returns true
        // if the current value was changed
@@ -1381,6 +1389,8 @@ class Camera3Device :
    // Whether the camera framework overrides the device characteristics for
    // app compatibility reasons.
    bool mOverrideToPortrait;
    camera_metadata_enum_android_scaler_rotate_and_crop_t mRotateAndCropOverride;
    bool mComposerOutput;

    // Current active physical id of the logical multi-camera, if any
    std::string mActivePhysicalId;