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

Commit 13f35add authored by Emilian Peev's avatar Emilian Peev
Browse files

Camera: Enable the rotate&crop heuristics in the legacy shim layer

Enable the rotate&crop heuristics within the legacy shim layer.
To avoid regressions, calls to "setDisplayOrientation" must be handled
differently. The client value passed there takes in to account both
the sensor orientation as well as the necessary extra display
compensation. The heuristics on the other hand will only include the
necessary display adjustment. In order to have consistent behavior
with the Camera2 path, the client display orientation value will
be ignored and we will only use the sensor orientation calculated
transformation instead.

Bug: 228947590
Test: Manual using legacy camera application
Change-Id: I774dbc63c3bcdc8757b3e6b667712452b42426ef
parent 006a15b8
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -1886,8 +1886,7 @@ Status CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8&
        // Set rotate-and-crop override behavior
        if (mOverrideRotateAndCropMode != ANDROID_SCALER_ROTATE_AND_CROP_AUTO) {
            client->setRotateAndCropOverride(mOverrideRotateAndCropMode);
        } else if (effectiveApiLevel == API_2) {

        } else {
          client->setRotateAndCropOverride(
              CameraServiceProxyWrapper::getRotateAndCropOverride(
                  clientPackageName, facing, multiuser_get_user_id(clientUid)));
@@ -2425,7 +2424,7 @@ Status CameraService::notifyDisplayConfigurationChange() {
    for (auto& current : clients) {
        if (current != nullptr) {
            const auto basicClient = current->getValue();
            if (basicClient.get() != nullptr && basicClient->canCastToApiClient(API_2)) {
            if (basicClient.get() != nullptr) {
              basicClient->setRotateAndCropOverride(
                  CameraServiceProxyWrapper::getRotateAndCropOverride(
                      basicClient->getPackageName(),
+29 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <utils/Log.h>
#include <utils/Trace.h>

#include <camera/CameraUtils.h>
#include <cutils/properties.h>
#include <gui/Surface.h>
#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
@@ -33,6 +34,7 @@
#include "api1/client2/CaptureSequencer.h"
#include "api1/client2/CallbackProcessor.h"
#include "api1/client2/ZslProcessor.h"
#include "device3/RotateAndCropMapper.h"
#include "utils/CameraThreadState.h"
#include "utils/CameraServiceProxyWrapper.h"

@@ -68,6 +70,10 @@ Camera2Client::Camera2Client(const sp<CameraService>& cameraService,
{
    ATRACE_CALL();

    mRotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_NONE;
    mRotateAndCropIsSupported = false;
    mRotateAndCropPreviewTransform = 0;

    SharedParameters::Lock l(mParameters);
    l.mParameters.state = Parameters::DISCONNECTED;
}
@@ -116,6 +122,14 @@ status_t Camera2Client::initializeImpl(TProviderPtr providerPtr, const String8&
        l.mParameters.isDeviceZslSupported = isZslEnabledInStillTemplate();
    }

    const CameraMetadata& staticInfo = mDevice->info();
    mRotateAndCropIsSupported = camera3::RotateAndCropMapper::isNeeded(&staticInfo);
    // The 'mRotateAndCropMode' value only accounts for the necessary adjustment
    // when the display rotates. The sensor orientation still needs to be calculated
    // and applied similar to the Camera2 path.
    CameraUtils::getRotationTransform(staticInfo, OutputConfiguration::MIRROR_MODE_AUTO,
            &mRotateAndCropPreviewTransform);

    String8 threadName;

    mStreamingProcessor = new StreamingProcessor(this);
@@ -1676,6 +1690,11 @@ status_t Camera2Client::commandSetDisplayOrientationL(int degrees) {
        return BAD_VALUE;
    }
    SharedParameters::Lock l(mParameters);
    if (mRotateAndCropMode != ANDROID_SCALER_ROTATE_AND_CROP_NONE) {
        ALOGI("%s: Rotate and crop set to: %d, skipping display orientation!", __FUNCTION__,
                mRotateAndCropMode);
        transform = mRotateAndCropPreviewTransform;
    }
    if (transform != l.mParameters.previewTransform &&
            getPreviewStreamId() != NO_STREAM) {
        mDevice->setStreamTransform(getPreviewStreamId(), transform);
@@ -2297,6 +2316,16 @@ int32_t Camera2Client::getGlobalAudioRestriction() {
status_t Camera2Client::setRotateAndCropOverride(uint8_t rotateAndCrop) {
    if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;

    {
        Mutex::Autolock icl(mBinderSerializationLock);
        if (mRotateAndCropIsSupported) {
            mRotateAndCropMode = rotateAndCrop;
        } else {
            mRotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_NONE;
            return OK;
        }
    }

    return mDevice->setRotateAndCropAutoBehavior(
        static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop));
}
+7 −0
Original line number Diff line number Diff line
@@ -238,6 +238,13 @@ private:
    status_t initializeImpl(TProviderPtr providerPtr, const String8& monitorTags);

    bool isZslEnabledInStillTemplate();
    // The current rotate & crop mode passed by camera service
    uint8_t mRotateAndCropMode;
    // Contains the preview stream transformation that would normally be applied
    // when the display rotation is 0
    int mRotateAndCropPreviewTransform;
    // Flag indicating camera device support for the rotate & crop interface
    bool mRotateAndCropIsSupported;

    mutable Mutex mLatestRequestMutex;
    Condition mLatestRequestSignal;