Merge "Camera: Add bandaid for preview orientation on reverse-landscape cameras" into nyc-dev

This commit is contained in:
Eino-Ville Talvala
2016-03-28 17:47:19 +00:00
committed by Android (Google) Code Review
2 changed files with 48 additions and 3 deletions

View File

@@ -76,7 +76,7 @@ import static android.system.OsConstants.*;
* <li>If necessary, modify the returned {@link Camera.Parameters} object and call
* {@link #setParameters(Camera.Parameters)}.
*
* <li>If desired, call {@link #setDisplayOrientation(int)}.
* <li>Call {@link #setDisplayOrientation(int)} to ensure correct orientation of preview.
*
* <li><b>Important</b>: Pass a fully initialized {@link SurfaceHolder} to
* {@link #setPreviewDisplay(SurfaceHolder)}. Without a surface, the camera
@@ -1511,9 +1511,15 @@ public class Camera {
* <p>Starting from API level 14, this method can be called when preview is
* active.
*
* <p><b>Note: </b>Before API level 24, the default value for orientation is 0. Starting in
* API level 24, the default orientation will be such that applications in forced-landscape mode
* will have correct preview orientation, which may be either a default of 0 or
* 180. Applications that operate in portrait mode or allow for changing orientation must still
* call this method after each orientation change to ensure correct preview display in all
* cases.</p>
*
* @param degrees the angle that the picture will be rotated clockwise.
* Valid values are 0, 90, 180, and 270. The starting
* position is 0 (landscape).
* Valid values are 0, 90, 180, and 270.
* @see #setPreviewDisplay(SurfaceHolder)
*/
public native final void setDisplayOrientation(int degrees);

View File

@@ -567,6 +567,45 @@ static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz,
// save context in opaque field
env->SetLongField(thiz, fields.context, (jlong)context.get());
// Update default display orientation in case the sensor is reverse-landscape
CameraInfo cameraInfo;
status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo);
if (rc != NO_ERROR) {
return rc;
}
int defaultOrientation = 0;
switch (cameraInfo.orientation) {
case 0:
break;
case 90:
if (cameraInfo.facing == CAMERA_FACING_FRONT) {
defaultOrientation = 180;
}
break;
case 180:
defaultOrientation = 180;
break;
case 270:
if (cameraInfo.facing != CAMERA_FACING_FRONT) {
defaultOrientation = 180;
}
break;
default:
ALOGE("Unexpected camera orientation %d!", cameraInfo.orientation);
break;
}
if (defaultOrientation != 0) {
ALOGV("Setting default display orientation to %d", defaultOrientation);
rc = camera->sendCommand(CAMERA_CMD_SET_DISPLAY_ORIENTATION,
defaultOrientation, 0);
if (rc != NO_ERROR) {
ALOGE("Unable to update default orientation: %s (%d)",
strerror(-rc), rc);
return rc;
}
}
return NO_ERROR;
}