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

Commit 021623b5 authored by Pablo Ceballos's avatar Pablo Ceballos
Browse files

SF: Fix camera orientation on virtual displays

Camera uses NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY to make the camera
preview always look upright on the device display. This commit changes
the behavior of this flag slightly. Instead of applying the inverse
transform of the current display when compositing, apply the inverse
transform of the primary display to all displays. This assumes that
the camera orientation is tied to the primary display.

Bug 2628180

Change-Id: I0da22423490a93fe943fd59e6c122aa6aaf30b11
parent 9ffa1a4d
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -68,6 +68,8 @@ inline void eglSetSwapRectangleANDROID (EGLDisplay, EGLSurface, EGLint, EGLint,
 *
 */

uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0;

DisplayDevice::DisplayDevice(
        const sp<SurfaceFlinger>& flinger,
        DisplayType type,
@@ -550,10 +552,32 @@ void DisplayDevice::setProjection(int orientation,
    }

    mOrientation = orientation;
    if (mType == DisplayType::DISPLAY_PRIMARY) {
        uint32_t transform = 0;
        switch (mOrientation) {
            case DisplayState::eOrientationDefault:
                transform = Transform::ROT_0;
                break;
            case DisplayState::eOrientation90:
                transform = Transform::ROT_90;
                break;
            case DisplayState::eOrientation180:
                transform = Transform::ROT_180;
                break;
            case DisplayState::eOrientation270:
                transform = Transform::ROT_270;
                break;
        }
        sPrimaryDisplayOrientation = transform;
    }
    mViewport = viewport;
    mFrame = frame;
}

uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() {
    return sPrimaryDisplayOrientation;
}

void DisplayDevice::dump(String8& result) const {
    const Transform& tr(mGlobalTransform);
    result.appendFormat(
+2 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ public:

    int                     getOrientation() const { return mOrientation; }
    uint32_t                getOrientationTransform() const;
    static uint32_t         getPrimaryDisplayOrientationTransform();
    const Transform&        getTransform() const { return mGlobalTransform; }
    const Rect              getViewport() const { return mViewport; }
    const Rect              getFrame() const { return mFrame; }
@@ -238,6 +239,7 @@ private:

    uint32_t mLayerStack;
    int mOrientation;
    static uint32_t sPrimaryDisplayOrientation;
    // user-provided visible area of the layer stack
    Rect mViewport;
    // user-provided rectangle where mViewport gets mapped to
+13 −10
Original line number Diff line number Diff line
@@ -435,9 +435,11 @@ FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {
    uint32_t invTransform = mCurrentTransform;
    if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) {
        /*
         * the code below applies the display's inverse transform to the buffer
         * the code below applies the primary display's inverse transform to the
         * buffer
         */
        uint32_t invTransformOrient = hw->getOrientationTransform();
        uint32_t invTransformOrient =
                DisplayDevice::getPrimaryDisplayOrientationTransform();
        // calculate the inverse transform
        if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) {
            invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V |
@@ -634,13 +636,12 @@ void Layer::setGeometry(

    if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) {
        /*
         * the code below applies the display's inverse transform to the buffer
         * the code below applies the primary display's inverse transform to the
         * buffer
         */
#ifdef USE_HWC2
        uint32_t invTransform = displayDevice->getOrientationTransform();
#else
        uint32_t invTransform = hw->getOrientationTransform();
#endif
        uint32_t invTransform =
                DisplayDevice::getPrimaryDisplayOrientationTransform();

        uint32_t t_orientation = transform.getOrientation();
        // calculate the inverse transform
        if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
@@ -941,7 +942,8 @@ void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip,
        if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) {

            /*
             * the code below applies the display's inverse transform to the texture transform
             * the code below applies the primary display's inverse transform to
             * the texture transform
             */

            // create a 4x4 transform matrix from the display transform flags
@@ -950,7 +952,8 @@ void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip,
            const mat4 rot90( 0,1,0,0, -1,0,0,0, 0,0,1,0, 1,0,0,1);

            mat4 tr;
            uint32_t transform = hw->getOrientationTransform();
            uint32_t transform =
                    DisplayDevice::getPrimaryDisplayOrientationTransform();
            if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90)
                tr = tr * rot90;
            if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_H)