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

Commit f2e37092 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

CameraService: Implement SCALER_ROTATE_AND_CROP_AUTO, part 1

When an app sets SCALER_ROTATE_AND_CROP to AUTO, the camera service
needs to select the right ROTATE_AND_CROP mode given the application
UI state at the moment, received from the window manager.

In addition, some of the metadata in the active array coordinate
system needs to be converted to/from the cropped+rotated coordinate
system to ensure roundtripping UI information works as before.

Also ensure that the available rotate and crop metadata field is
always available, with a value of NONE if nothing else.

This commit adds support for doing the coordinate transforms and
overriding AUTO to a concrete value; it does not wire up a connection
to another system service to receive the correct override value, but
does add a command to set the override value for all current camera
clients.

Test: New CTS tests pass, unit tests for RotateAndCropMapper pass
Bug: 134631897
Change-Id: Icc45530e2cfbaf838a1e4d04e4fd2aef8122e8e1
parent e2a8892e
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -62,6 +62,7 @@ cc_library_shared {
        "device3/CoordinateMapper.cpp",
        "device3/CoordinateMapper.cpp",
        "device3/DistortionMapper.cpp",
        "device3/DistortionMapper.cpp",
        "device3/ZoomRatioMapper.cpp",
        "device3/ZoomRatioMapper.cpp",
        "device3/RotateAndCropMapper.cpp",
        "device3/Camera3OutputStreamInterface.cpp",
        "device3/Camera3OutputStreamInterface.cpp",
        "device3/Camera3OutputUtils.cpp",
        "device3/Camera3OutputUtils.cpp",
        "gui/RingBufferConsumer.cpp",
        "gui/RingBufferConsumer.cpp",
+41 −0
Original line number Original line Diff line number Diff line
@@ -1731,6 +1731,11 @@ 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);
        }

        if (shimUpdateOnly) {
        if (shimUpdateOnly) {
            // If only updating legacy shim parameters, immediately disconnect client
            // If only updating legacy shim parameters, immediately disconnect client
            mServiceLock.unlock();
            mServiceLock.unlock();
@@ -3810,6 +3815,10 @@ status_t CameraService::shellCommand(int in, int out, int err, const Vector<Stri
        return handleResetUidState(args, err);
        return handleResetUidState(args, err);
    } else if (args.size() >= 2 && args[0] == String16("get-uid-state")) {
    } else if (args.size() >= 2 && args[0] == String16("get-uid-state")) {
        return handleGetUidState(args, out, err);
        return handleGetUidState(args, out, err);
    } else if (args.size() >= 2 && args[0] == String16("set-rotate-and-crop")) {
        return handleSetRotateAndCrop(args);
    } else if (args.size() >= 1 && args[0] == String16("get-rotate-and-crop")) {
        return handleGetRotateAndCrop(out);
    } else if (args.size() == 1 && args[0] == String16("help")) {
    } else if (args.size() == 1 && args[0] == String16("help")) {
        printHelp(out);
        printHelp(out);
        return NO_ERROR;
        return NO_ERROR;
@@ -3880,11 +3889,43 @@ status_t CameraService::handleGetUidState(const Vector<String16>& args, int out,
    }
    }
}
}


status_t CameraService::handleSetRotateAndCrop(const Vector<String16>& args) {
    int rotateValue = atoi(String8(args[1]));
    if (rotateValue < ANDROID_SCALER_ROTATE_AND_CROP_NONE ||
            rotateValue > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;
    Mutex::Autolock lock(mServiceLock);

    mOverrideRotateAndCropMode = rotateValue;

    if (rotateValue == ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return OK;

    const auto clients = mActiveClientManager.getAll();
    for (auto& current : clients) {
        if (current != nullptr) {
            const auto basicClient = current->getValue();
            if (basicClient.get() != nullptr) {
                basicClient->setRotateAndCropOverride(rotateValue);
            }
        }
    }

    return OK;
}

status_t CameraService::handleGetRotateAndCrop(int out) {
    Mutex::Autolock lock(mServiceLock);

    return dprintf(out, "rotateAndCrop override: %d\n", mOverrideRotateAndCropMode);
}

status_t CameraService::printHelp(int out) {
status_t CameraService::printHelp(int out) {
    return dprintf(out, "Camera service commands:\n"
    return dprintf(out, "Camera service commands:\n"
        "  get-uid-state <PACKAGE> [--user USER_ID] gets the uid state\n"
        "  get-uid-state <PACKAGE> [--user USER_ID] gets the uid state\n"
        "  set-uid-state <PACKAGE> <active|idle> [--user USER_ID] overrides the uid state\n"
        "  set-uid-state <PACKAGE> <active|idle> [--user USER_ID] overrides the uid state\n"
        "  reset-uid-state <PACKAGE> [--user USER_ID] clears the uid state override\n"
        "  reset-uid-state <PACKAGE> [--user USER_ID] clears the uid state override\n"
        "  set-rotate-and-crop <ROTATION> overrides the rotate-and-crop value for AUTO backcompat\n"
        "      Valid values 0=0 deg, 1=90 deg, 2=180 deg, 3=270 deg, 4=No override\n"
        "  get-rotate-and-crop returns the current override rotate-and-crop value\n"
        "  help print this message\n");
        "  help print this message\n");
}
}


+13 −0
Original line number Original line Diff line number Diff line
@@ -280,6 +280,10 @@ public:
        virtual int32_t getAudioRestriction() const;
        virtual int32_t getAudioRestriction() const;


        static bool isValidAudioRestriction(int32_t mode);
        static bool isValidAudioRestriction(int32_t mode);

        // Override rotate-and-crop AUTO behavior
        virtual status_t setRotateAndCropOverride(uint8_t rotateAndCrop) = 0;

    protected:
    protected:
        BasicClient(const sp<CameraService>& cameraService,
        BasicClient(const sp<CameraService>& cameraService,
                const sp<IBinder>& remoteCallback,
                const sp<IBinder>& remoteCallback,
@@ -1014,6 +1018,12 @@ private:
    // Gets the UID state
    // Gets the UID state
    status_t handleGetUidState(const Vector<String16>& args, int out, int err);
    status_t handleGetUidState(const Vector<String16>& args, int out, int err);


    // Set the rotate-and-crop AUTO override behavior
    status_t handleSetRotateAndCrop(const Vector<String16>& args);

    // Get the rotate-and-crop AUTO override behavior
    status_t handleGetRotateAndCrop(int out);

    // Prints the shell command help
    // Prints the shell command help
    status_t printHelp(int out);
    status_t printHelp(int out);


@@ -1059,6 +1069,9 @@ private:


    // Aggreated audio restriction mode for all camera clients
    // Aggreated audio restriction mode for all camera clients
    int32_t mAudioRestriction;
    int32_t mAudioRestriction;

    // Current override rotate-and-crop mode
    uint8_t mOverrideRotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_AUTO;
};
};


} // namespace android
} // namespace android
+7 −0
Original line number Original line Diff line number Diff line
@@ -2271,6 +2271,13 @@ int32_t Camera2Client::getGlobalAudioRestriction() {
    return INVALID_OPERATION;
    return INVALID_OPERATION;
}
}


status_t Camera2Client::setRotateAndCropOverride(uint8_t rotateAndCrop) {
    if (rotateAndCrop > ANDROID_SCALER_ROTATE_AND_CROP_AUTO) return BAD_VALUE;

    return mDevice->setRotateAndCropAutoBehavior(
        static_cast<camera_metadata_enum_android_scaler_rotate_and_crop_t>(rotateAndCrop));
}

status_t Camera2Client::waitUntilCurrentRequestIdLocked() {
status_t Camera2Client::waitUntilCurrentRequestIdLocked() {
    int32_t activeRequestId = mStreamingProcessor->getActiveRequestId();
    int32_t activeRequestId = mStreamingProcessor->getActiveRequestId();
    if (activeRequestId != 0) {
    if (activeRequestId != 0) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -85,6 +85,7 @@ public:
    virtual status_t        setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer);
    virtual status_t        setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer);
    virtual status_t        setAudioRestriction(int mode);
    virtual status_t        setAudioRestriction(int mode);
    virtual int32_t         getGlobalAudioRestriction();
    virtual int32_t         getGlobalAudioRestriction();
    virtual status_t        setRotateAndCropOverride(uint8_t rotateAndCrop);


    /**
    /**
     * Interface used by CameraService
     * Interface used by CameraService
Loading