Search in sources :

Example 16 with SurfaceControl

use of android.view.SurfaceControl in project android_frameworks_base by ParanoidAndroid.

the class ElectronBeam method createSurface.

/* not used because it is too expensive to create / destroy contexts all of the time
    private void destroyEglContext() {
        if (mEglContext != null) {
            if (!EGL14.eglDestroyContext(mEglDisplay, mEglContext)) {
                logEglError("eglDestroyContext");
            }
            mEglContext = null;
        }
    }*/
private boolean createSurface() {
    if (mSurfaceSession == null) {
        mSurfaceSession = new SurfaceSession();
    }
    SurfaceControl.openTransaction();
    try {
        if (mSurfaceControl == null) {
            try {
                int flags;
                if (mMode == MODE_FADE) {
                    flags = SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN;
                } else {
                    flags = SurfaceControl.OPAQUE | SurfaceControl.HIDDEN;
                }
                mSurfaceControl = new SurfaceControl(mSurfaceSession, "ElectronBeam", mDisplayWidth, mDisplayHeight, PixelFormat.OPAQUE, flags);
            } catch (SurfaceControl.OutOfResourcesException ex) {
                Slog.e(TAG, "Unable to create surface.", ex);
                return false;
            }
        }
        mSurfaceControl.setLayerStack(mDisplayLayerStack);
        mSurfaceControl.setSize(mDisplayWidth, mDisplayHeight);
        mSurface = new Surface();
        mSurface.copyFrom(mSurfaceControl);
        mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManager, mSurfaceControl);
        mSurfaceLayout.onDisplayTransaction();
    } finally {
        SurfaceControl.closeTransaction();
    }
    return true;
}
Also used : SurfaceSession(android.view.SurfaceSession) SurfaceControl(android.view.SurfaceControl) Surface(android.view.Surface) EGLSurface(android.opengl.EGLSurface)

Example 17 with SurfaceControl

use of android.view.SurfaceControl in project android_frameworks_base by ParanoidAndroid.

the class WindowManagerService method reclaimSomeSurfaceMemoryLocked.

boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator, String operation, boolean secure) {
    final SurfaceControl surface = winAnimator.mSurfaceControl;
    boolean leakedSurface = false;
    boolean killedApps = false;
    EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(), winAnimator.mSession.mPid, operation);
    if (mForceRemoves == null) {
        mForceRemoves = new ArrayList<WindowState>();
    }
    long callingIdentity = Binder.clearCallingIdentity();
    try {
        // There was some problem...   first, do a sanity check of the
        // window list to make sure we haven't left any dangling surfaces
        // around.
        final int numDisplays = mDisplayContents.size();
        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
            final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
            final int numWindows = windows.size();
            for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
                final WindowState ws = windows.get(winNdx);
                WindowStateAnimator wsa = ws.mWinAnimator;
                if (wsa.mSurfaceControl != null) {
                    if (!mSessions.contains(wsa.mSession)) {
                        Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " + ws + " surface=" + wsa.mSurfaceControl + " token=" + ws.mToken + " pid=" + ws.mSession.mPid + " uid=" + ws.mSession.mUid);
                        if (SHOW_TRANSACTIONS)
                            logSurface(ws, "LEAK DESTROY", null);
                        wsa.mSurfaceControl.destroy();
                        wsa.mSurfaceShown = false;
                        wsa.mSurfaceControl = null;
                        ws.mHasSurface = false;
                        mForceRemoves.add(ws);
                        leakedSurface = true;
                    } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
                        Slog.w(TAG, "LEAKED SURFACE (app token hidden): " + ws + " surface=" + wsa.mSurfaceControl + " token=" + ws.mAppToken);
                        if (SHOW_TRANSACTIONS)
                            logSurface(ws, "LEAK DESTROY", null);
                        wsa.mSurfaceControl.destroy();
                        wsa.mSurfaceShown = false;
                        wsa.mSurfaceControl = null;
                        ws.mHasSurface = false;
                        leakedSurface = true;
                    }
                }
            }
        }
        if (!leakedSurface) {
            Slog.w(TAG, "No leaked surfaces; killing applicatons!");
            SparseIntArray pidCandidates = new SparseIntArray();
            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
                final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
                final int numWindows = windows.size();
                for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
                    final WindowState ws = windows.get(winNdx);
                    if (mForceRemoves.contains(ws)) {
                        continue;
                    }
                    WindowStateAnimator wsa = ws.mWinAnimator;
                    if (wsa.mSurfaceControl != null) {
                        pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
                    }
                }
                if (pidCandidates.size() > 0) {
                    int[] pids = new int[pidCandidates.size()];
                    for (int i = 0; i < pids.length; i++) {
                        pids[i] = pidCandidates.keyAt(i);
                    }
                    try {
                        if (mActivityManager.killPids(pids, "Free memory", secure)) {
                            killedApps = true;
                        }
                    } catch (RemoteException e) {
                    }
                }
            }
        }
        if (leakedSurface || killedApps) {
            // We managed to reclaim some memory, so get rid of the trouble
            // surface and ask the app to request another one.
            Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
            if (surface != null) {
                if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC)
                    logSurface(winAnimator.mWin, "RECOVER DESTROY", null);
                surface.destroy();
                winAnimator.mSurfaceShown = false;
                winAnimator.mSurfaceControl = null;
                winAnimator.mWin.mHasSurface = false;
            }
            try {
                winAnimator.mWin.mClient.dispatchGetNewSurface();
            } catch (RemoteException e) {
            }
        }
    } finally {
        Binder.restoreCallingIdentity(callingIdentity);
    }
    return leakedSurface || killedApps;
}
Also used : SparseIntArray(android.util.SparseIntArray) SurfaceControl(android.view.SurfaceControl) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Example 18 with SurfaceControl

use of android.view.SurfaceControl in project android_frameworks_base by ParanoidAndroid.

the class WindowManagerService method handleAppTransitionReadyLocked.

/**
     * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method.
     * @param windows List of windows on default display.
     * @return bitmap indicating if another pass through layout must be made.
     */
public int handleAppTransitionReadyLocked(WindowList windows) {
    int changes = 0;
    int i;
    int NN = mOpeningApps.size();
    boolean goodToGo = true;
    if (DEBUG_APP_TRANSITIONS)
        Slog.v(TAG, "Checking " + NN + " opening apps (frozen=" + mDisplayFrozen + " timeout=" + mAppTransition.isTimeout() + ")...");
    if (!mDisplayFrozen && !mAppTransition.isTimeout()) {
        // we'll unfreeze the display when everyone is ready.
        for (i = 0; i < NN && goodToGo; i++) {
            AppWindowToken wtoken = mOpeningApps.get(i);
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "Check opening app=" + wtoken + ": allDrawn=" + wtoken.allDrawn + " startingDisplayed=" + wtoken.startingDisplayed + " startingMoved=" + wtoken.startingMoved);
            if (!wtoken.allDrawn && !wtoken.startingDisplayed && !wtoken.startingMoved) {
                goodToGo = false;
            }
        }
    }
    if (goodToGo) {
        if (DEBUG_APP_TRANSITIONS)
            Slog.v(TAG, "**** GOOD TO GO");
        int transit = mAppTransition.getAppTransition();
        if (mSkipAppTransitionAnimation) {
            transit = AppTransition.TRANSIT_UNSET;
        }
        mAppTransition.goodToGo();
        mStartingIconInTransition = false;
        mSkipAppTransitionAnimation = false;
        mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
        rebuildAppWindowListLocked();
        // if wallpaper is animating in or out set oldWallpaper to null else to wallpaper
        WindowState oldWallpaper = mWallpaperTarget != null && mWallpaperTarget.mWinAnimator.isAnimating() && !mWallpaperTarget.mWinAnimator.isDummyAnimation() ? null : mWallpaperTarget;
        mInnerFields.mWallpaperMayChange = false;
        // The top-most window will supply the layout params,
        // and we will determine it below.
        LayoutParams animLp = null;
        int bestAnimLayer = -1;
        boolean fullscreenAnim = false;
        if (DEBUG_APP_TRANSITIONS)
            Slog.v(TAG, "New wallpaper target=" + mWallpaperTarget + ", oldWallpaper=" + oldWallpaper + ", lower target=" + mLowerWallpaperTarget + ", upper target=" + mUpperWallpaperTarget);
        boolean openingAppHasWallpaper = false;
        boolean closingAppHasWallpaper = false;
        final AppWindowToken lowerWallpaperAppToken;
        final AppWindowToken upperWallpaperAppToken;
        if (mLowerWallpaperTarget == null) {
            lowerWallpaperAppToken = upperWallpaperAppToken = null;
        } else {
            lowerWallpaperAppToken = mLowerWallpaperTarget.mAppToken;
            upperWallpaperAppToken = mUpperWallpaperTarget.mAppToken;
        }
        // Do a first pass through the tokens for two
        // things:
        // (1) Determine if both the closing and opening
        // app token sets are wallpaper targets, in which
        // case special animations are needed
        // (since the wallpaper needs to stay static
        // behind them).
        // (2) Find the layout params of the top-most
        // application window in the tokens, which is
        // what will control the animation theme.
        final int NC = mClosingApps.size();
        NN = NC + mOpeningApps.size();
        for (i = 0; i < NN; i++) {
            final AppWindowToken wtoken;
            if (i < NC) {
                wtoken = mClosingApps.get(i);
                if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
                    closingAppHasWallpaper = true;
                }
            } else {
                wtoken = mOpeningApps.get(i - NC);
                if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
                    openingAppHasWallpaper = true;
                }
            }
            if (wtoken.appFullscreen) {
                WindowState ws = wtoken.findMainWindow();
                if (ws != null) {
                    animLp = ws.mAttrs;
                    bestAnimLayer = ws.mLayer;
                    fullscreenAnim = true;
                }
            } else if (!fullscreenAnim) {
                WindowState ws = wtoken.findMainWindow();
                if (ws != null) {
                    if (ws.mLayer > bestAnimLayer) {
                        animLp = ws.mAttrs;
                        bestAnimLayer = ws.mLayer;
                    }
                }
            }
        }
        if (closingAppHasWallpaper && openingAppHasWallpaper) {
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "Wallpaper animation!");
            switch(transit) {
                case AppTransition.TRANSIT_ACTIVITY_OPEN:
                case AppTransition.TRANSIT_TASK_OPEN:
                case AppTransition.TRANSIT_TASK_TO_FRONT:
                    transit = AppTransition.TRANSIT_WALLPAPER_INTRA_OPEN;
                    break;
                case AppTransition.TRANSIT_ACTIVITY_CLOSE:
                case AppTransition.TRANSIT_TASK_CLOSE:
                case AppTransition.TRANSIT_TASK_TO_BACK:
                    transit = AppTransition.TRANSIT_WALLPAPER_INTRA_CLOSE;
                    break;
            }
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "New transit: " + transit);
        } else if ((oldWallpaper != null) && !mOpeningApps.contains(oldWallpaper.mAppToken)) {
            // We are transitioning from an activity with
            // a wallpaper to one without.
            transit = AppTransition.TRANSIT_WALLPAPER_CLOSE;
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "New transit away from wallpaper: " + transit);
        } else if (mWallpaperTarget != null && mWallpaperTarget.isVisibleLw()) {
            // We are transitioning from an activity without
            // a wallpaper to now showing the wallpaper
            transit = AppTransition.TRANSIT_WALLPAPER_OPEN;
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "New transit into wallpaper: " + transit);
        }
        // the lock screen.
        if (!mPolicy.allowAppAnimationsLw()) {
            animLp = null;
        }
        AppWindowToken topOpeningApp = null;
        int topOpeningLayer = 0;
        NN = mOpeningApps.size();
        for (i = 0; i < NN; i++) {
            AppWindowToken wtoken = mOpeningApps.get(i);
            final AppWindowAnimator appAnimator = wtoken.mAppAnimator;
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "Now opening app" + wtoken);
            appAnimator.clearThumbnail();
            wtoken.inPendingTransaction = false;
            appAnimator.animation = null;
            setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
            wtoken.updateReportedVisibilityLocked();
            wtoken.waitingToShow = false;
            appAnimator.mAllAppWinAnimators.clear();
            final int N = wtoken.allAppWindows.size();
            for (int j = 0; j < N; j++) {
                appAnimator.mAllAppWinAnimators.add(wtoken.allAppWindows.get(j).mWinAnimator);
            }
            mAnimator.mAnimating |= appAnimator.showAllWindowsLocked();
            if (animLp != null) {
                int layer = -1;
                for (int j = 0; j < wtoken.windows.size(); j++) {
                    WindowState win = wtoken.windows.get(j);
                    if (win.mWinAnimator.mAnimLayer > layer) {
                        layer = win.mWinAnimator.mAnimLayer;
                    }
                }
                if (topOpeningApp == null || layer > topOpeningLayer) {
                    topOpeningApp = wtoken;
                    topOpeningLayer = layer;
                }
            }
        }
        NN = mClosingApps.size();
        for (i = 0; i < NN; i++) {
            AppWindowToken wtoken = mClosingApps.get(i);
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "Now closing app " + wtoken);
            wtoken.mAppAnimator.clearThumbnail();
            wtoken.inPendingTransaction = false;
            wtoken.mAppAnimator.animation = null;
            setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
            wtoken.updateReportedVisibilityLocked();
            wtoken.waitingToHide = false;
            // Force the allDrawn flag, because we want to start
            // this guy's animations regardless of whether it's
            // gotten drawn.
            wtoken.allDrawn = true;
            wtoken.deferClearAllDrawn = false;
        }
        AppWindowAnimator appAnimator = topOpeningApp == null ? null : topOpeningApp.mAppAnimator;
        Bitmap nextAppTransitionThumbnail = mAppTransition.getNextAppTransitionThumbnail();
        if (nextAppTransitionThumbnail != null && appAnimator != null && appAnimator.animation != null) {
            // This thumbnail animation is very special, we need to have
            // an extra surface with the thumbnail included with the animation.
            Rect dirty = new Rect(0, 0, nextAppTransitionThumbnail.getWidth(), nextAppTransitionThumbnail.getHeight());
            try {
                // TODO(multi-display): support other displays
                final DisplayContent displayContent = getDefaultDisplayContentLocked();
                final Display display = displayContent.getDisplay();
                SurfaceControl surfaceControl = new SurfaceControl(mFxSession, "thumbnail anim", dirty.width(), dirty.height(), PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
                surfaceControl.setLayerStack(display.getLayerStack());
                appAnimator.thumbnail = surfaceControl;
                if (SHOW_TRANSACTIONS)
                    Slog.i(TAG, "  THUMBNAIL " + surfaceControl + ": CREATE");
                Surface drawSurface = new Surface();
                drawSurface.copyFrom(surfaceControl);
                Canvas c = drawSurface.lockCanvas(dirty);
                c.drawBitmap(nextAppTransitionThumbnail, 0, 0, null);
                drawSurface.unlockCanvasAndPost(c);
                drawSurface.release();
                appAnimator.thumbnailLayer = topOpeningLayer;
                DisplayInfo displayInfo = getDefaultDisplayInfoLocked();
                Animation anim = mAppTransition.createThumbnailAnimationLocked(transit, true, true, displayInfo.appWidth, displayInfo.appHeight);
                appAnimator.thumbnailAnimation = anim;
                anim.restrictDuration(MAX_ANIMATION_DURATION);
                anim.scaleCurrentDuration(mTransitionAnimationScale);
                Point p = new Point();
                mAppTransition.getStartingPoint(p);
                appAnimator.thumbnailX = p.x;
                appAnimator.thumbnailY = p.y;
            } catch (SurfaceControl.OutOfResourcesException e) {
                Slog.e(TAG, "Can't allocate thumbnail surface w=" + dirty.width() + " h=" + dirty.height(), e);
                appAnimator.clearThumbnail();
            } catch (Surface.OutOfResourcesException e) {
                Slog.e(TAG, "Can't allocate Canvas surface w=" + dirty.width() + " h=" + dirty.height(), e);
                appAnimator.clearThumbnail();
            }
        }
        mAppTransition.postAnimationCallback();
        mAppTransition.clear();
        mOpeningApps.clear();
        mClosingApps.clear();
        // This has changed the visibility of windows, so perform
        // a new layout to get them all up-to-date.
        changes |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
        getDefaultDisplayContentLocked().layoutNeeded = true;
        // TODO(multidisplay): IMEs are only supported on the default display.
        if (windows == getDefaultWindowListLocked() && !moveInputMethodWindowsIfNeededLocked(true)) {
            assignLayersLocked(windows);
        }
        updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, false);
        mFocusMayChange = false;
    }
    return changes;
}
Also used : Rect(android.graphics.Rect) LayoutParams(android.view.WindowManager.LayoutParams) DisplayInfo(android.view.DisplayInfo) SurfaceControl(android.view.SurfaceControl) Canvas(android.graphics.Canvas) Point(android.graphics.Point) Point(android.graphics.Point) Surface(android.view.Surface) Bitmap(android.graphics.Bitmap) Animation(android.view.animation.Animation) Display(android.view.Display)

Example 19 with SurfaceControl

use of android.view.SurfaceControl in project android_frameworks_base by AOSPA.

the class ColorFade method createSurface.

private boolean createSurface() {
    if (mSurfaceSession == null) {
        mSurfaceSession = new SurfaceSession();
    }
    SurfaceControl.openTransaction();
    try {
        if (mSurfaceControl == null) {
            try {
                int flags;
                if (mMode == MODE_FADE) {
                    flags = SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN;
                } else {
                    flags = SurfaceControl.OPAQUE | SurfaceControl.HIDDEN;
                }
                mSurfaceControl = new SurfaceControl(mSurfaceSession, "ColorFade", mDisplayWidth, mDisplayHeight, PixelFormat.OPAQUE, flags);
            } catch (OutOfResourcesException ex) {
                Slog.e(TAG, "Unable to create surface.", ex);
                return false;
            }
            mSurfaceControl.setLayerStack(mDisplayLayerStack);
            mSurfaceControl.setSize(mDisplayWidth, mDisplayHeight);
            mSurface = new Surface();
            mSurface.copyFrom(mSurfaceControl);
            mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManagerInternal, mDisplayId, mSurfaceControl);
            mSurfaceLayout.onDisplayTransaction();
        }
    } finally {
        SurfaceControl.closeTransaction();
    }
    return true;
}
Also used : OutOfResourcesException(android.view.Surface.OutOfResourcesException) SurfaceSession(android.view.SurfaceSession) SurfaceControl(android.view.SurfaceControl) EGLSurface(android.opengl.EGLSurface) Surface(android.view.Surface)

Example 20 with SurfaceControl

use of android.view.SurfaceControl in project android_frameworks_base by DirtyUnicorns.

the class ColorFade method createSurface.

private boolean createSurface() {
    if (mSurfaceSession == null) {
        mSurfaceSession = new SurfaceSession();
    }
    SurfaceControl.openTransaction();
    try {
        if (mSurfaceControl == null) {
            try {
                int flags;
                if (mMode == MODE_FADE) {
                    flags = SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN;
                } else {
                    flags = SurfaceControl.OPAQUE | SurfaceControl.HIDDEN;
                }
                mSurfaceControl = new SurfaceControl(mSurfaceSession, "ColorFade", mDisplayWidth, mDisplayHeight, PixelFormat.OPAQUE, flags);
            } catch (OutOfResourcesException ex) {
                Slog.e(TAG, "Unable to create surface.", ex);
                return false;
            }
            mSurfaceControl.setLayerStack(mDisplayLayerStack);
            mSurfaceControl.setSize(mDisplayWidth, mDisplayHeight);
            mSurface = new Surface();
            mSurface.copyFrom(mSurfaceControl);
            mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManagerInternal, mDisplayId, mSurfaceControl);
            mSurfaceLayout.onDisplayTransaction();
        }
    } finally {
        SurfaceControl.closeTransaction();
    }
    return true;
}
Also used : OutOfResourcesException(android.view.Surface.OutOfResourcesException) SurfaceSession(android.view.SurfaceSession) SurfaceControl(android.view.SurfaceControl) EGLSurface(android.opengl.EGLSurface) Surface(android.view.Surface)

Aggregations

SurfaceControl (android.view.SurfaceControl)27 Display (android.view.Display)14 Surface (android.view.Surface)11 Point (android.graphics.Point)8 OutOfResourcesException (android.view.Surface.OutOfResourcesException)8 EGLSurface (android.opengl.EGLSurface)6 DisplayInfo (android.view.DisplayInfo)6 SurfaceSession (android.view.SurfaceSession)6 Bitmap (android.graphics.Bitmap)5 Canvas (android.graphics.Canvas)5 Rect (android.graphics.Rect)5 Animation (android.view.animation.Animation)5 Binder (android.os.Binder)4 IBinder (android.os.IBinder)4 Message (android.os.Message)4 LayoutParams (android.view.WindowManager.LayoutParams)3 RemoteException (android.os.RemoteException)2 WindowManager (android.view.WindowManager)2 SparseIntArray (android.util.SparseIntArray)1 IWindowManager (android.view.IWindowManager)1