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

Commit 05212134 authored by Ruben Brunk's avatar Ruben Brunk Committed by Android Git Automerger
Browse files

am 5698d446: camera2: Set orientation flags for hardware composer.

* commit '5698d446':
  camera2: Set orientation flags for hardware composer.
parents cf85bbba 5698d446
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ LOCAL_SRC_FILES:= \
	camera2/CaptureRequest.cpp \
	camera2/CaptureRequest.cpp \
	ProCamera.cpp \
	ProCamera.cpp \
	CameraBase.cpp \
	CameraBase.cpp \
	CameraUtils.cpp \
	VendorTagDescriptor.cpp
	VendorTagDescriptor.cpp


LOCAL_SHARED_LIBRARIES := \
LOCAL_SHARED_LIBRARIES := \

camera/CameraUtils.cpp

0 → 100644
+118 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "CameraUtils"
//#define LOG_NDEBUG 0

#include <camera/CameraUtils.h>

#include <system/window.h>
#include <system/graphics.h>

#include <utils/Log.h>

namespace android {

status_t CameraUtils::getRotationTransform(const CameraMetadata& staticInfo,
                /*out*/int32_t* transform) {
    ALOGV("%s", __FUNCTION__);

    if (transform == NULL) {
        ALOGW("%s: null transform", __FUNCTION__);
        return BAD_VALUE;
    }

    *transform = 0;

    camera_metadata_ro_entry_t entry = staticInfo.find(ANDROID_SENSOR_ORIENTATION);
    if (entry.count == 0) {
        ALOGE("%s: Can't find android.sensor.orientation in static metadata!", __FUNCTION__);
        return INVALID_OPERATION;
    }

    camera_metadata_ro_entry_t entryFacing = staticInfo.find(ANDROID_LENS_FACING);
    if (entry.count == 0) {
        ALOGE("%s: Can't find android.lens.facing in static metadata!", __FUNCTION__);
        return INVALID_OPERATION;
    }

    int32_t& flags = *transform;

    bool mirror = (entryFacing.data.u8[0] == ANDROID_LENS_FACING_FRONT);
    int orientation = entry.data.i32[0];
    if (!mirror) {
        switch (orientation) {
            case 0:
                flags = 0;
                break;
            case 90:
                flags = NATIVE_WINDOW_TRANSFORM_ROT_90;
                break;
            case 180:
                flags = NATIVE_WINDOW_TRANSFORM_ROT_180;
                break;
            case 270:
                flags = NATIVE_WINDOW_TRANSFORM_ROT_270;
                break;
            default:
                ALOGE("%s: Invalid HAL android.sensor.orientation value: %d",
                      __FUNCTION__, orientation);
                return INVALID_OPERATION;
        }
    } else {
        switch (orientation) {
            case 0:
                flags = HAL_TRANSFORM_FLIP_H;
                break;
            case 90:
                flags = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_ROT_90;
                break;
            case 180:
                flags = HAL_TRANSFORM_FLIP_V;
                break;
            case 270:
                flags = HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
                break;
            default:
                ALOGE("%s: Invalid HAL android.sensor.orientation value: %d",
                      __FUNCTION__, orientation);
                return INVALID_OPERATION;
        }

    }

    /**
     * This magic flag makes surfaceflinger un-rotate the buffers
     * to counter the extra global device UI rotation whenever the user
     * physically rotates the device.
     *
     * By doing this, the camera buffer always ends up aligned
     * with the physical camera for a "see through" effect.
     *
     * In essence, the buffer only gets rotated during preview use-cases.
     * The user is still responsible to re-create streams of the proper
     * aspect ratio, or the preview will end up looking non-uniformly
     * stretched.
     */
    flags |= NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;

    ALOGV("%s: final transform = 0x%x", __FUNCTION__, flags);

    return OK;
}


} /* namespace android */
+49 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_CAMERA_CLIENT_CAMERAUTILS_H
#define ANDROID_CAMERA_CLIENT_CAMERAUTILS_H

#include <camera/CameraMetadata.h>
#include <utils/Errors.h>

#include <stdint.h>

namespace android {

/**
 * CameraUtils contains utility methods that are shared between the native
 * camera client, and the camera service.
 */
class CameraUtils {
    public:
        /**
         * Calculate the ANativeWindow transform from the static camera
         * metadata.  This is based on the sensor orientation and lens facing
         * attributes of the camera device.
         *
         * Returns OK on success, or a negative error code.
         */
        static status_t getRotationTransform(const CameraMetadata& staticInfo,
                /*out*/int32_t* transform);
    private:
        CameraUtils();
};

} /* namespace android */

#endif /* ANDROID_CAMERA_CLIENT_CAMERAUTILS_H */
+2 −84
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@
#include <utils/Trace.h>
#include <utils/Trace.h>
#include <gui/Surface.h>
#include <gui/Surface.h>
#include <camera/camera2/CaptureRequest.h>
#include <camera/camera2/CaptureRequest.h>
#include <camera/CameraUtils.h>


#include "common/CameraDeviceBase.h"
#include "common/CameraDeviceBase.h"
#include "api2/CameraDeviceClient.h"
#include "api2/CameraDeviceClient.h"
@@ -656,91 +657,8 @@ bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
status_t CameraDeviceClient::getRotationTransformLocked(int32_t* transform) {
status_t CameraDeviceClient::getRotationTransformLocked(int32_t* transform) {
    ALOGV("%s: begin", __FUNCTION__);
    ALOGV("%s: begin", __FUNCTION__);


    if (transform == NULL) {
        ALOGW("%s: null transform", __FUNCTION__);
        return BAD_VALUE;
    }

    *transform = 0;

    const CameraMetadata& staticInfo = mDevice->info();
    const CameraMetadata& staticInfo = mDevice->info();
    camera_metadata_ro_entry_t entry = staticInfo.find(ANDROID_SENSOR_ORIENTATION);
    return CameraUtils::getRotationTransform(staticInfo, transform);
    if (entry.count == 0) {
        ALOGE("%s: Camera %d: Can't find android.sensor.orientation in "
                "static metadata!", __FUNCTION__, mCameraId);
        return INVALID_OPERATION;
    }

    camera_metadata_ro_entry_t entryFacing = staticInfo.find(ANDROID_LENS_FACING);
    if (entry.count == 0) {
        ALOGE("%s: Camera %d: Can't find android.lens.facing in "
                "static metadata!", __FUNCTION__, mCameraId);
        return INVALID_OPERATION;
    }

    int32_t& flags = *transform;

    bool mirror = (entryFacing.data.u8[0] == ANDROID_LENS_FACING_FRONT);
    int orientation = entry.data.i32[0];
    if (!mirror) {
        switch (orientation) {
            case 0:
                flags = 0;
                break;
            case 90:
                flags = NATIVE_WINDOW_TRANSFORM_ROT_90;
                break;
            case 180:
                flags = NATIVE_WINDOW_TRANSFORM_ROT_180;
                break;
            case 270:
                flags = NATIVE_WINDOW_TRANSFORM_ROT_270;
                break;
            default:
                ALOGE("%s: Invalid HAL android.sensor.orientation value: %d",
                      __FUNCTION__, orientation);
                return INVALID_OPERATION;
        }
    } else {
        switch (orientation) {
            case 0:
                flags = HAL_TRANSFORM_FLIP_H;
                break;
            case 90:
                flags = HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_ROT_90;
                break;
            case 180:
                flags = HAL_TRANSFORM_FLIP_V;
                break;
            case 270:
                flags = HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90;
                break;
            default:
                ALOGE("%s: Invalid HAL android.sensor.orientation value: %d",
                      __FUNCTION__, orientation);
                return INVALID_OPERATION;
        }

    }

    /**
     * This magic flag makes surfaceflinger un-rotate the buffers
     * to counter the extra global device UI rotation whenever the user
     * physically rotates the device.
     *
     * By doing this, the camera buffer always ends up aligned
     * with the physical camera for a "see through" effect.
     *
     * In essence, the buffer only gets rotated during preview use-cases.
     * The user is still responsible to re-create streams of the proper
     * aspect ratio, or the preview will end up looking non-uniformly
     * stretched.
     */
    flags |= NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;

    ALOGV("%s: final transform = 0x%x", __FUNCTION__, flags);

    return OK;
}
}


} // namespace android
} // namespace android