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

Commit dde0123e authored by Craig Mautner's avatar Craig Mautner Committed by Android Git Automerger
Browse files

am 60ce6d45: Merge "Call Surface.destroy when Display is removed." into jb-mr1-dev

* commit '60ce6d45':
  Call Surface.destroy when Display is removed.
parents 27fa88dd 60ce6d45
Loading
Loading
Loading
Loading
+23 −12
Original line number Diff line number Diff line
@@ -19,14 +19,11 @@ package com.android.server.display;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.IndentingPrintWriter;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.graphics.SurfaceTexture;
import android.os.Handler;
import android.os.IBinder;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Slog;
@@ -192,28 +189,42 @@ final class OverlayDisplayAdapter extends DisplayAdapter {
        private final int mDensityDpi;

        private Surface mSurface;
        private SurfaceTexture mSurfaceTexture;
        private DisplayDeviceInfo mInfo;

        public OverlayDisplayDevice(IBinder displayToken, String name,
                int width, int height, float refreshRate, int densityDpi,
                Surface surface) {
                SurfaceTexture surfaceTexture) {
            super(OverlayDisplayAdapter.this, displayToken);
            mName = name;
            mWidth = width;
            mHeight = height;
            mRefreshRate = refreshRate;
            mDensityDpi = densityDpi;
            mSurface = surface;
            mSurfaceTexture = surfaceTexture;
        }

        public void clearSurfaceLocked() {
            mSurface = null;
        public void clearSurfaceTextureLocked() {
            if (mSurfaceTexture != null) {
                mSurfaceTexture = null;
            }
            sendTraversalRequestLocked();
        }

        @Override
        public void performTraversalInTransactionLocked() {
            if (mSurfaceTexture != null) {
                if (mSurface == null) {
                    mSurface = new Surface(mSurfaceTexture);
                }
                setSurfaceInTransactionLocked(mSurface);
            } else {
                setSurfaceInTransactionLocked(null);
                if (mSurface != null) {
                    mSurface.destroy();
                    mSurface = null;
                }
            }
        }

        @Override
@@ -268,11 +279,11 @@ final class OverlayDisplayAdapter extends DisplayAdapter {

        // Called on the UI thread.
        @Override
        public void onWindowCreated(Surface surface, float refreshRate) {
        public void onWindowCreated(SurfaceTexture surfaceTexture, float refreshRate) {
            synchronized (getSyncRoot()) {
                IBinder displayToken = Surface.createDisplay(mName);
                mDevice = new OverlayDisplayDevice(displayToken, mName,
                        mWidth, mHeight, refreshRate, mDensityDpi, surface);
                        mWidth, mHeight, refreshRate, mDensityDpi, surfaceTexture);

                sendDisplayDeviceEventLocked(mDevice, DISPLAY_DEVICE_EVENT_ADDED);
            }
@@ -283,7 +294,7 @@ final class OverlayDisplayAdapter extends DisplayAdapter {
        public void onWindowDestroyed() {
            synchronized (getSyncRoot()) {
                if (mDevice != null) {
                    mDevice.clearSurfaceLocked();
                    mDevice.clearSurfaceTextureLocked();
                    sendDisplayDeviceEventLocked(mDevice, DISPLAY_DEVICE_EVENT_REMOVED);
                }
            }
+3 −4
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.WindowManager;
@@ -146,6 +145,7 @@ final class OverlayDisplayWindow implements DumpUtils.Dump {
        }
    }

    @Override
    public void dump(PrintWriter pw) {
        pw.println("mWindowVisible=" + mWindowVisible);
        pw.println("mWindowX=" + mWindowX);
@@ -291,8 +291,7 @@ final class OverlayDisplayWindow implements DumpUtils.Dump {
        @Override
        public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture,
                int width, int height) {
            mListener.onWindowCreated(new Surface(surfaceTexture),
                    mDefaultDisplayInfo.refreshRate);
            mListener.onWindowCreated(surfaceTexture, mDefaultDisplayInfo.refreshRate);
        }

        @Override
@@ -361,7 +360,7 @@ final class OverlayDisplayWindow implements DumpUtils.Dump {
     * Watches for significant changes in the overlay display window lifecycle.
     */
    public interface Listener {
        public void onWindowCreated(Surface surface, float refreshRate);
        public void onWindowCreated(SurfaceTexture surfaceTexture, float refreshRate);
        public void onWindowDestroyed();
    }
}
 No newline at end of file
+38 −21
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import java.io.PrintWriter;
 * all state used for dim animation.
 */
class DimAnimator {
    static final String TAG = "DimAnimator";

    Surface mDimSurface;
    boolean mDimShown = false;
    float mDimCurrentAlpha;
@@ -40,7 +42,6 @@ class DimAnimator {
    int mLastDimWidth, mLastDimHeight;

    DimAnimator (SurfaceSession session, final int layerStack) {
        if (mDimSurface == null) {
        try {
            if (WindowManagerService.DEBUG_SURFACE_TRACE) {
                mDimSurface = new WindowStateAnimator.SurfaceTrace(session,
@@ -62,13 +63,17 @@ class DimAnimator {
            Slog.e(WindowManagerService.TAG, "Exception creating Dim surface", e);
        }
    }
    }

    /**
     * Set's the dim surface's layer and update dim parameters that will be used in
     * {@link #updateSurface} after all windows are examined.
     */
    void updateParameters(final Resources res, final Parameters params, final long currentTime) {
        if (mDimSurface == null) {
            Slog.e(TAG, "updateParameters: no Surface");
            return;
        }

        // Multiply by 1.5 so that rotating a frozen surface that includes this does not expose a
        // corner.
        final int dw = (int) (params.mDimWidth * 1.5);
@@ -133,6 +138,11 @@ class DimAnimator {
     * false when the animation is finished and the dim surface is hidden.
     */
    boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) {
        if (mDimSurface == null) {
            Slog.e(TAG, "updateSurface: no Surface");
            return false;
        }

        if (!dimming) {
            if (mDimTargetAlpha != 0) {
                mLastDimAnimTime = currentTime;
@@ -187,6 +197,13 @@ class DimAnimator {
        return animating;
    }

    public void kill() {
        if (mDimSurface != null) {
            mDimSurface.destroy();
            mDimSurface = null;
        }
    }

    public void printTo(String prefix, PrintWriter pw) {
        pw.print(prefix);
        pw.print("mDimSurface="); pw.print(mDimSurface);
+37 −20
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.view.SurfaceSession;
import java.io.PrintWriter;

class DimSurface {
    static final String TAG = "DimSurface";

    Surface mDimSurface;
    boolean mDimShown = false;
    int mDimColor = 0;
@@ -31,7 +33,6 @@ class DimSurface {
    int mLastDimWidth, mLastDimHeight;

    DimSurface(SurfaceSession session, final int layerStack) {
        if (mDimSurface == null) {
        try {
            if (WindowManagerService.DEBUG_SURFACE_TRACE) {
                mDimSurface = new WindowStateAnimator.SurfaceTrace(session,
@@ -53,12 +54,16 @@ class DimSurface {
            Slog.e(WindowManagerService.TAG, "Exception creating Dim surface", e);
        }
    }
    }

    /**
     * Show the dim surface.
     */
    void show(int dw, int dh, int layer, int color) {
        if (mDimSurface == null) {
            Slog.e(TAG, "show: no Surface");
            return;
        }

        if (!mDimShown) {
            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "  DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
                    dw + "x" + dh + " layer=" + layer + ")");
@@ -88,6 +93,11 @@ class DimSurface {
    }

    void hide() {
        if (mDimSurface == null) {
            Slog.e(TAG, "hide: no Surface");
            return;
        }

        if (mDimShown) {
            mDimShown = false;
            try {
@@ -99,6 +109,13 @@ class DimSurface {
        }
    }

    void kill() {
        if (mDimSurface != null) {
            mDimSurface.destroy();
            mDimSurface = null;
        }
    }

    public void printTo(String prefix, PrintWriter pw) {
        pw.print(prefix); pw.print("mDimSurface="); pw.println(mDimSurface);
        pw.print(prefix); pw.print("mDimShown="); pw.print(mDimShown);
+28 −9
Original line number Diff line number Diff line
@@ -147,6 +147,22 @@ public class WindowAnimator {
    }

    void removeDisplayLocked(final int displayId) {
        final DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId);
        if (displayAnimator != null) {
            if (displayAnimator.mWindowAnimationBackgroundSurface != null) {
                displayAnimator.mWindowAnimationBackgroundSurface.kill();
                displayAnimator.mWindowAnimationBackgroundSurface = null;
            }
            if (displayAnimator.mScreenRotationAnimation != null) {
                displayAnimator.mScreenRotationAnimation.kill();
                displayAnimator.mScreenRotationAnimation = null;
            }
            if (displayAnimator.mDimAnimator != null) {
                displayAnimator.mDimAnimator.kill();
                displayAnimator.mDimAnimator = null;
            }
        }

        mDisplayContentsAnimators.delete(displayId);
    }

@@ -527,13 +543,17 @@ public class WindowAnimator {
                }
            }

            if (windowAnimationBackgroundSurface != null) {
                windowAnimationBackgroundSurface.show(mDw, mDh,
                        animLayer - WindowManagerService.LAYER_OFFSET_DIM,
                        windowAnimationBackgroundColor);
            }
        } else {
            if (windowAnimationBackgroundSurface != null) {
                windowAnimationBackgroundSurface.hide();
            }
        }
    }

    private void testTokenMayBeDrawnLocked() {
        // See if any windows have been drawn, so they (and others
@@ -643,9 +663,8 @@ public class WindowAnimator {

                final DimAnimator.Parameters dimParams = displayAnimator.mDimParams;
                final DimAnimator dimAnimator = displayAnimator.mDimAnimator;
                if (dimParams != null) {
                    dimAnimator.updateParameters(
                            mContext.getResources(), dimParams, mCurrentTime);
                if (dimAnimator != null && dimParams != null) {
                    dimAnimator.updateParameters(mContext.getResources(), dimParams, mCurrentTime);
                }
                if (dimAnimator != null && dimAnimator.mDimShown) {
                    mAnimating |= dimAnimator.updateSurface(isDimmingLocked(displayId),
@@ -801,9 +820,9 @@ public class WindowAnimator {

    private class DisplayContentsAnimator {
        WinAnimatorList mWinAnimators = new WinAnimatorList();
        final DimAnimator mDimAnimator;
        DimAnimator mDimAnimator = null;
        DimAnimator.Parameters mDimParams = null;
        final DimSurface mWindowAnimationBackgroundSurface;
        DimSurface mWindowAnimationBackgroundSurface = null;
        ScreenRotationAnimation mScreenRotationAnimation = null;

        public DisplayContentsAnimator(int displayId) {