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

Commit fdb427ef authored by Donald Munn's avatar Donald Munn Committed by Bumble-Bee
Browse files

Fix first frame on rotation animation for Tegra

Modify rotation animation to use a screenshot instead of a black screen.

Change-Id: I71563680f5d7cb355dd50b8873fa1b420a131512
parent e0a8c35c
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ class ScreenRotationAnimation {

    public ScreenRotationAnimation(Context context, SurfaceSession session,
            boolean inTransaction, int originalWidth, int originalHeight, int originalRotation) {
        boolean isTegra = android.os.SystemProperties.get("ro.board.platform","").equals("tegra");
        mContext = context;

        // Screenshot does NOT include rotation!
@@ -99,7 +100,7 @@ class ScreenRotationAnimation {
        try {
            try {
                mSurface = new Surface(session, 0, "FreezeSurface",
                        -1, mWidth, mHeight, PixelFormat.OPAQUE, Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN);
                        -1, mWidth, mHeight, PixelFormat.OPAQUE, isTegra ? 0 : (Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN));
                if (mSurface == null || !mSurface.isValid()) {
                    // Screenshot failed, punt.
                    mSurface = null;
@@ -116,6 +117,35 @@ class ScreenRotationAnimation {
                            "  FREEZE " + mSurface + ": CREATE");

            setRotation(originalRotation);

            if (isTegra) {
                Rect rect = new Rect(0, 0, mWidth, mHeight);
                Canvas canvas = null;

                try {
                    canvas = mSurface.lockCanvas(rect);
                } catch (IllegalArgumentException e) {
                    Slog.w(TAG, "Unable to lock surface", e);
                } catch (Surface.OutOfResourcesException e) {
                    Slog.w(TAG, "Unable to lock surface", e);
                }

                Bitmap screenshot = Surface.screenshot(0, 0);
                if (canvas == null || screenshot == null) {
                    Slog.w(TAG, "Null surface canvas");
                    mSurface.destroy();
                    mSurface = null;
                    return;
                }

                Paint paint = new Paint(0);
                paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));

                canvas.drawBitmap(screenshot, 0, 0, paint);
                mSurface.unlockCanvasAndPost(canvas);

            }

        } finally {
            if (!inTransaction) {
                Surface.closeTransaction();