Search in sources :

Example 41 with Surface

use of android.view.Surface in project cornerstone by Onskreen.

the class WindowManagerService method reclaimSomeSurfaceMemoryLocked.

boolean reclaimSomeSurfaceMemoryLocked(WindowState win, String operation, boolean secure) {
    final Surface surface = win.mSurface;
    boolean leakedSurface = false;
    boolean killedApps = false;
    EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), win.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.
        int N = mWindows.size();
        Slog.i(TAG, "Out of memory for surface!  Looking for leaks...");
        for (int i = 0; i < N; i++) {
            WindowState ws = mWindows.get(i);
            if (ws.mSurface != null) {
                if (!mSessions.contains(ws.mSession)) {
                    Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " + ws + " surface=" + ws.mSurface + " token=" + win.mToken + " pid=" + ws.mSession.mPid + " uid=" + ws.mSession.mUid);
                    if (SHOW_TRANSACTIONS)
                        logSurface(ws, "LEAK DESTROY", null);
                    ws.mSurface.destroy();
                    ws.mSurfaceShown = false;
                    ws.mSurface = null;
                    mForceRemoves.add(ws);
                    i--;
                    N--;
                    leakedSurface = true;
                } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
                    Slog.w(TAG, "LEAKED SURFACE (app token hidden): " + ws + " surface=" + ws.mSurface + " token=" + win.mAppToken);
                    if (SHOW_TRANSACTIONS)
                        logSurface(ws, "LEAK DESTROY", null);
                    ws.mSurface.destroy();
                    ws.mSurfaceShown = false;
                    ws.mSurface = null;
                    leakedSurface = true;
                }
            }
        }
        if (!leakedSurface) {
            Slog.w(TAG, "No leaked surfaces; killing applicatons!");
            SparseIntArray pidCandidates = new SparseIntArray();
            for (int i = 0; i < N; i++) {
                WindowState ws = mWindows.get(i);
                if (ws.mSurface != null) {
                    pidCandidates.append(ws.mSession.mPid, ws.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(win, "RECOVER DESTROY", null);
                surface.destroy();
                win.mSurfaceShown = false;
                win.mSurface = null;
            }
            try {
                win.mClient.dispatchGetNewSurface();
            } catch (RemoteException e) {
            }
        }
    } finally {
        Binder.restoreCallingIdentity(callingIdentity);
    }
    return leakedSurface || killedApps;
}
Also used : SparseIntArray(android.util.SparseIntArray) RemoteException(android.os.RemoteException) Point(android.graphics.Point) Surface(android.view.Surface)

Example 42 with Surface

use of android.view.Surface in project cornerstone by Onskreen.

the class WindowManagerService method handleAppTransitionReadyLocked.

/**
     * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method.
     *
     * @return bitmap indicating if another pass through layout must be made.
     */
public int handleAppTransitionReadyLocked() {
    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=" + mAppTransitionTimeout + ")...");
    if (!mDisplayFrozen && !mAppTransitionTimeout) {
        // 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 = mNextAppTransition;
        if (mSkipAppTransitionAnimation) {
            transit = WindowManagerPolicy.TRANSIT_UNSET;
        }
        mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET;
        mAppTransitionReady = false;
        mAppTransitionRunning = true;
        mAppTransitionTimeout = false;
        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;
        adjustWallpaperWindowsLocked();
        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);
        int foundWallpapers = 0;
        // 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++) {
            AppWindowToken wtoken;
            int mode;
            if (i < NC) {
                wtoken = mClosingApps.get(i);
                mode = 1;
            } else {
                wtoken = mOpeningApps.get(i - NC);
                mode = 2;
            }
            if (mLowerWallpaperTarget != null) {
                if (mLowerWallpaperTarget.mAppToken == wtoken || mUpperWallpaperTarget.mAppToken == wtoken) {
                    foundWallpapers |= mode;
                }
            }
            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 (foundWallpapers == 3) {
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "Wallpaper animation!");
            switch(transit) {
                case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN:
                case WindowManagerPolicy.TRANSIT_TASK_OPEN:
                case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT:
                    transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN;
                    break;
                case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE:
                case WindowManagerPolicy.TRANSIT_TASK_CLOSE:
                case WindowManagerPolicy.TRANSIT_TASK_TO_BACK:
                    transit = WindowManagerPolicy.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 = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE;
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "New transit away from wallpaper: " + transit);
        } else if (mWallpaperTarget != null) {
            // We are transitioning from an activity without
            // a wallpaper to now showing the wallpaper
            transit = WindowManagerPolicy.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);
            if (DEBUG_APP_TRANSITIONS)
                Slog.v(TAG, "Now opening app" + wtoken);
            wtoken.mAppAnimator.clearThumbnail();
            wtoken.reportedVisible = false;
            wtoken.inPendingTransaction = false;
            wtoken.mAppAnimator.animation = null;
            setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
            wtoken.updateReportedVisibilityLocked();
            wtoken.waitingToShow = false;
            mAnimator.mAnimating |= wtoken.mAppAnimator.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;
        }
        if (mNextAppTransitionThumbnail != null && topOpeningApp != null && topOpeningApp.mAppAnimator.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, mNextAppTransitionThumbnail.getWidth(), mNextAppTransitionThumbnail.getHeight());
            try {
                Surface surface = new Surface(mFxSession, Process.myPid(), "thumbnail anim", 0, dirty.width(), dirty.height(), PixelFormat.TRANSLUCENT, Surface.HIDDEN);
                topOpeningApp.mAppAnimator.thumbnail = surface;
                if (SHOW_TRANSACTIONS)
                    Slog.i(TAG, "  THUMBNAIL " + surface + ": CREATE");
                Surface drawSurface = new Surface();
                drawSurface.copyFrom(surface);
                Canvas c = drawSurface.lockCanvas(dirty);
                c.drawBitmap(mNextAppTransitionThumbnail, 0, 0, null);
                drawSurface.unlockCanvasAndPost(c);
                drawSurface.release();
                topOpeningApp.mAppAnimator.thumbnailLayer = topOpeningLayer;
                Animation anim = createThumbnailAnimationLocked(transit, true, true, mNextAppTransitionDelayed);
                topOpeningApp.mAppAnimator.thumbnailAnimation = anim;
                anim.restrictDuration(MAX_ANIMATION_DURATION);
                anim.scaleCurrentDuration(mTransitionAnimationScale);
                topOpeningApp.mAppAnimator.thumbnailX = mNextAppTransitionStartX;
                topOpeningApp.mAppAnimator.thumbnailY = mNextAppTransitionStartY;
            } catch (Surface.OutOfResourcesException e) {
                Slog.e(TAG, "Can't allocate thumbnail surface w=" + dirty.width() + " h=" + dirty.height(), e);
                topOpeningApp.mAppAnimator.clearThumbnail();
            }
        }
        mNextAppTransitionType = ActivityOptions.ANIM_NONE;
        mNextAppTransitionPackage = null;
        mNextAppTransitionThumbnail = null;
        scheduleAnimationCallback(mNextAppTransitionCallback);
        mNextAppTransitionCallback = null;
        mOpeningApps.clear();
        mClosingApps.clear();
        // This has changed the visibility of windows, so perform
        // a new layout to get them all up-to-date.
        changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
        mLayoutNeeded = true;
        if (!moveInputMethodWindowsIfNeededLocked(true)) {
            assignLayersLocked();
        }
        updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, false);
        mFocusMayChange = false;
    }
    return changes;
}
Also used : Rect(android.graphics.Rect) LayoutParams(android.view.WindowManager.LayoutParams) Canvas(android.graphics.Canvas) TranslateAnimation(android.view.animation.TranslateAnimation) AlphaAnimation(android.view.animation.AlphaAnimation) ScaleAnimation(android.view.animation.ScaleAnimation) Animation(android.view.animation.Animation) Point(android.graphics.Point) Surface(android.view.Surface)

Example 43 with Surface

use of android.view.Surface in project cornerstone by Onskreen.

the class WindowManagerService method reclaimSomeSurfaceMemoryLocked.

boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator, String operation, boolean secure) {
    final Surface surface = winAnimator.mSurface;
    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.
        int N = mWindows.size();
        Slog.i(TAG, "Out of memory for surface!  Looking for leaks...");
        for (int i = 0; i < N; i++) {
            WindowState ws = mWindows.get(i);
            WindowStateAnimator wsa = ws.mWinAnimator;
            if (wsa.mSurface != null) {
                if (!mSessions.contains(wsa.mSession)) {
                    Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " + ws + " surface=" + wsa.mSurface + " token=" + ws.mToken + " pid=" + ws.mSession.mPid + " uid=" + ws.mSession.mUid);
                    if (SHOW_TRANSACTIONS)
                        logSurface(ws, "LEAK DESTROY", null);
                    wsa.mSurface.destroy();
                    wsa.mSurfaceShown = false;
                    wsa.mSurface = null;
                    ws.mHasSurface = false;
                    mForceRemoves.add(ws);
                    i--;
                    N--;
                    leakedSurface = true;
                } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
                    Slog.w(TAG, "LEAKED SURFACE (app token hidden): " + ws + " surface=" + wsa.mSurface + " token=" + ws.mAppToken);
                    if (SHOW_TRANSACTIONS)
                        logSurface(ws, "LEAK DESTROY", null);
                    wsa.mSurface.destroy();
                    wsa.mSurfaceShown = false;
                    wsa.mSurface = null;
                    ws.mHasSurface = false;
                    leakedSurface = true;
                }
            }
        }
        if (!leakedSurface) {
            Slog.w(TAG, "No leaked surfaces; killing applicatons!");
            SparseIntArray pidCandidates = new SparseIntArray();
            for (int i = 0; i < N; i++) {
                WindowStateAnimator wsa = mWindows.get(i).mWinAnimator;
                if (wsa.mSurface != 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.mSurface = 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) RemoteException(android.os.RemoteException) Point(android.graphics.Point) Surface(android.view.Surface)

Example 44 with Surface

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

the class ElectronBeam method captureScreenshotTextureAndSetViewport.

private boolean captureScreenshotTextureAndSetViewport() {
    if (!attachEglContext()) {
        return false;
    }
    try {
        if (!mTexNamesGenerated) {
            GLES10.glGenTextures(1, mTexNames, 0);
            if (checkGlErrors("glGenTextures")) {
                return false;
            }
            mTexNamesGenerated = true;
        }
        final SurfaceTexture st = new SurfaceTexture(mTexNames[0]);
        final Surface s = new Surface(st);
        try {
            SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay(SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), s);
        } finally {
            s.release();
        }
        st.updateTexImage();
        st.getTransformMatrix(mTexMatrix);
        // Set up texture coordinates for a quad.
        // We might need to change this if the texture ends up being
        // a different size from the display for some reason.
        mTexCoordBuffer.put(0, 0f);
        mTexCoordBuffer.put(1, 0f);
        mTexCoordBuffer.put(2, 0f);
        mTexCoordBuffer.put(3, 1f);
        mTexCoordBuffer.put(4, 1f);
        mTexCoordBuffer.put(5, 1f);
        mTexCoordBuffer.put(6, 1f);
        mTexCoordBuffer.put(7, 0f);
        // Set up our viewport.
        GLES10.glViewport(0, 0, mDisplayWidth, mDisplayHeight);
        GLES10.glMatrixMode(GLES10.GL_PROJECTION);
        GLES10.glLoadIdentity();
        GLES10.glOrthof(0, mDisplayWidth, 0, mDisplayHeight, 0, 1);
        GLES10.glMatrixMode(GLES10.GL_MODELVIEW);
        GLES10.glLoadIdentity();
        GLES10.glMatrixMode(GLES10.GL_TEXTURE);
        GLES10.glLoadIdentity();
        GLES10.glLoadMatrixf(mTexMatrix, 0);
    } finally {
        detachEglContext();
    }
    return true;
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) Surface(android.view.Surface) EGLSurface(android.opengl.EGLSurface)

Example 45 with Surface

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

the class MediaPlayer method setDisplay.

/**
     * Sets the {@link SurfaceHolder} to use for displaying the video
     * portion of the media.
     *
     * Either a surface holder or surface must be set if a display or video sink
     * is needed.  Not calling this method or {@link #setSurface(Surface)}
     * when playing back a video will result in only the audio track being played.
     * A null surface holder or surface will result in only the audio track being
     * played.
     *
     * @param sh the SurfaceHolder to use for video display
     */
public void setDisplay(SurfaceHolder sh) {
    mSurfaceHolder = sh;
    Surface surface;
    if (sh != null) {
        surface = sh.getSurface();
    } else {
        surface = null;
    }
    _setVideoSurface(surface);
    updateSurfaceScreenOn();
}
Also used : Surface(android.view.Surface)

Aggregations

Surface (android.view.Surface)300 ArrayList (java.util.ArrayList)100 SurfaceTexture (android.graphics.SurfaceTexture)49 BlockingSessionCallback (com.android.ex.camera2.blocking.BlockingSessionCallback)44 Size (android.util.Size)35 CaptureRequest (android.hardware.camera2.CaptureRequest)34 OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)30 IOException (java.io.IOException)27 EGLSurface (android.opengl.EGLSurface)19 Paint (android.graphics.Paint)16 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)15 SurfaceHolder (android.view.SurfaceHolder)15 Rect (android.graphics.Rect)13 SurfaceView (android.view.SurfaceView)13 Canvas (android.graphics.Canvas)12 CameraAccessException (android.hardware.camera2.CameraAccessException)12 WifiDisplay (android.hardware.display.WifiDisplay)12 MediaRecorder (android.media.MediaRecorder)11 SurfaceControl (android.view.SurfaceControl)11 Image (android.media.Image)10