Skip to content

Commit

Permalink
Merge "framework: fix screenshot and rotation animation for devices w…
Browse files Browse the repository at this point in the history
…ith abnormal hw rotation" into mr1-staging
  • Loading branch information
DvTonder authored and Gerrit Code Review committed Dec 12, 2012
2 parents 3e65d1e + ac555b9 commit 93fa319
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Expand Up @@ -381,7 +381,10 @@ void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarV
// only in the natural orientation of the device :!)
mDisplay.getRealMetrics(mDisplayMetrics);
float[] dims = {mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels};
float degrees = getDegreesForRotation(mDisplay.getRotation());
int rot = mDisplay.getRotation();
// Allow for abnormal hardware orientation
rot = (rot + (android.os.SystemProperties.getInt("ro.sf.hwrotation",0) / 90 )) % 4;
float degrees = getDegreesForRotation(rot);
boolean requiresRotation = (degrees > 0);
if (requiresRotation) {
// Get the dimensions of the device in its native orientation
Expand Down
28 changes: 20 additions & 8 deletions services/java/com/android/server/wm/ScreenRotationAnimation.java
Expand Up @@ -49,6 +49,7 @@ class ScreenRotationAnimation {
BlackFrame mEnteringBlackFrame;
int mWidth, mHeight;
int mExitAnimId, mEnterAnimId;
int mSnapshotRotation;

int mOriginalRotation;
int mOriginalWidth, mOriginalHeight;
Expand Down Expand Up @@ -196,16 +197,27 @@ public ScreenRotationAnimation(Context context, Display display, SurfaceSession
mExitAnimId = exitAnim;
mEnterAnimId = enterAnim;

// Screenshot does NOT include rotation!
if (originalRotation == Surface.ROTATION_90
// Allow for abnormal hardware orientation
mSnapshotRotation = (4 - android.os.SystemProperties.getInt("ro.sf.hwrotation",0) / 90) % 4;
if (mSnapshotRotation == Surface.ROTATION_0 || mSnapshotRotation == Surface.ROTATION_180) {
if (originalRotation == Surface.ROTATION_90
|| originalRotation == Surface.ROTATION_270) {
mWidth = originalHeight;
mHeight = originalWidth;
mWidth = originalHeight;
mHeight = originalWidth;
} else {
mWidth = originalWidth;
mHeight = originalHeight;
}
} else {
mWidth = originalWidth;
mHeight = originalHeight;
if (originalRotation == Surface.ROTATION_90
|| originalRotation == Surface.ROTATION_270) {
mWidth = originalWidth;
mHeight = originalHeight;
} else {
mWidth = originalHeight;
mHeight = originalWidth;
}
}

mOriginalRotation = originalRotation;
mOriginalWidth = originalWidth;
mOriginalHeight = originalHeight;
Expand Down Expand Up @@ -313,7 +325,7 @@ private void setRotationInTransaction(int rotation) {
// Compute the transformation matrix that must be applied
// to the snapshot to make it stay in the same original position
// with the current screen rotation.
int delta = deltaRotation(rotation, Surface.ROTATION_0);
int delta = deltaRotation(rotation, mSnapshotRotation);
createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);

if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);
Expand Down
3 changes: 3 additions & 0 deletions services/java/com/android/server/wm/WindowManagerService.java
Expand Up @@ -5861,6 +5861,9 @@ public Bitmap screenshotApplications(IBinder appToken, int displayId, int width,

// The screenshot API does not apply the current screen rotation.
rot = getDefaultDisplayContentLocked().getDisplay().getRotation();
// Allow for abnormal hardware orientation
rot = (rot + (android.os.SystemProperties.getInt("ro.sf.hwrotation",0) / 90 )) % 4;

int fw = frame.width();
int fh = frame.height();

Expand Down

0 comments on commit 93fa319

Please sign in to comment.