Search in sources :

Example 26 with OutOfResourcesException

use of android.view.Surface.OutOfResourcesException in project android_frameworks_base by ResurrectionRemix.

the class WindowStateAnimator method createSurfaceLocked.

WindowSurfaceController createSurfaceLocked() {
    final WindowState w = mWin;
    if (w.hasSavedSurface()) {
        if (DEBUG_ANIM)
            Slog.i(TAG, "createSurface: " + this + ": called when we had a saved surface");
        w.restoreSavedSurface();
        return mSurfaceController;
    }
    if (mSurfaceController != null) {
        return mSurfaceController;
    }
    w.setHasSurface(false);
    if (DEBUG_ANIM || DEBUG_ORIENTATION)
        Slog.i(TAG, "createSurface " + this + ": mDrawState=DRAW_PENDING");
    mDrawState = DRAW_PENDING;
    if (w.mAppToken != null) {
        if (w.mAppToken.mAppAnimator.animation == null) {
            w.mAppToken.clearAllDrawn();
        } else {
            // Currently animating, persist current state of allDrawn until animation
            // is complete.
            w.mAppToken.deferClearAllDrawn = true;
        }
    }
    mService.makeWindowFreezingScreenIfNeededLocked(w);
    int flags = SurfaceControl.HIDDEN;
    final WindowManager.LayoutParams attrs = w.mAttrs;
    if (mService.isSecureLocked(w)) {
        flags |= SurfaceControl.SECURE;
    }
    mTmpSize.set(w.mFrame.left + w.mXOffset, w.mFrame.top + w.mYOffset, 0, 0);
    calculateSurfaceBounds(w, attrs);
    final int width = mTmpSize.width();
    final int height = mTmpSize.height();
    if (DEBUG_VISIBILITY) {
        Slog.v(TAG, "Creating surface in session " + mSession.mSurfaceSession + " window " + this + " w=" + width + " h=" + height + " x=" + mTmpSize.left + " y=" + mTmpSize.top + " format=" + attrs.format + " flags=" + flags);
    }
    // We may abort, so initialize to defaults.
    mLastSystemDecorRect.set(0, 0, 0, 0);
    mHasClipRect = false;
    mClipRect.set(0, 0, 0, 0);
    mLastClipRect.set(0, 0, 0, 0);
    // Set up surface control with initial size.
    try {
        final boolean isHwAccelerated = (attrs.flags & FLAG_HARDWARE_ACCELERATED) != 0;
        final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
        if (!PixelFormat.formatHasAlpha(attrs.format) && // translucent shadow.
        attrs.surfaceInsets.left == 0 && attrs.surfaceInsets.top == 0 && attrs.surfaceInsets.right == 0 && attrs.surfaceInsets.bottom == 0 && // artifacts shown in areas the app isn't drawing content to.
        !w.isDragResizing()) {
            flags |= SurfaceControl.OPAQUE;
        }
        mSurfaceController = new WindowSurfaceController(mSession.mSurfaceSession, attrs.getTitle().toString(), width, height, format, flags, this);
        w.setHasSurface(true);
        if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
            Slog.i(TAG, "  CREATE SURFACE " + mSurfaceController + " IN SESSION " + mSession.mSurfaceSession + ": pid=" + mSession.mPid + " format=" + attrs.format + " flags=0x" + Integer.toHexString(flags) + " / " + this);
        }
    } catch (OutOfResourcesException e) {
        Slog.w(TAG, "OutOfResourcesException creating surface");
        mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
        mDrawState = NO_SURFACE;
        return null;
    } catch (Exception e) {
        Slog.e(TAG, "Exception creating surface", e);
        mDrawState = NO_SURFACE;
        return null;
    }
    if (WindowManagerService.localLOGV)
        Slog.v(TAG, "Got surface: " + mSurfaceController + ", set left=" + w.mFrame.left + " top=" + w.mFrame.top + ", animLayer=" + mAnimLayer);
    if (SHOW_LIGHT_TRANSACTIONS) {
        Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
        WindowManagerService.logSurface(w, "CREATE pos=(" + w.mFrame.left + "," + w.mFrame.top + ") (" + width + "x" + height + "), layer=" + mAnimLayer + " HIDE", false);
    }
    // Start a new transaction and apply position & offset.
    final int layerStack = w.getDisplayContent().getDisplay().getLayerStack();
    mSurfaceController.setPositionAndLayer(mTmpSize.left, mTmpSize.top, layerStack, mAnimLayer);
    mLastHidden = true;
    if (WindowManagerService.localLOGV)
        Slog.v(TAG, "Created surface " + this);
    return mSurfaceController;
}
Also used : OutOfResourcesException(android.view.Surface.OutOfResourcesException) LayoutParams(android.view.WindowManager.LayoutParams) Point(android.graphics.Point) OutOfResourcesException(android.view.Surface.OutOfResourcesException) RemoteException(android.os.RemoteException) WindowManager(android.view.WindowManager)

Example 27 with OutOfResourcesException

use of android.view.Surface.OutOfResourcesException in project android_frameworks_base by ResurrectionRemix.

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 28 with OutOfResourcesException

use of android.view.Surface.OutOfResourcesException in project android_frameworks_base by ResurrectionRemix.

the class ViewRootImpl method draw.

private void draw(boolean fullRedrawNeeded) {
    Surface surface = mSurface;
    if (!surface.isValid()) {
        return;
    }
    if (DEBUG_FPS) {
        trackFPS();
    }
    if (!sFirstDrawComplete) {
        synchronized (sFirstDrawHandlers) {
            sFirstDrawComplete = true;
            final int count = sFirstDrawHandlers.size();
            for (int i = 0; i < count; i++) {
                mHandler.post(sFirstDrawHandlers.get(i));
            }
        }
    }
    scrollToRectOrFocus(null, false);
    if (mAttachInfo.mViewScrollChanged) {
        mAttachInfo.mViewScrollChanged = false;
        mAttachInfo.mTreeObserver.dispatchOnScrollChanged();
    }
    boolean animating = mScroller != null && mScroller.computeScrollOffset();
    final int curScrollY;
    if (animating) {
        curScrollY = mScroller.getCurrY();
    } else {
        curScrollY = mScrollY;
    }
    if (mCurScrollY != curScrollY) {
        mCurScrollY = curScrollY;
        fullRedrawNeeded = true;
        if (mView instanceof RootViewSurfaceTaker) {
            ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY);
        }
    }
    final float appScale = mAttachInfo.mApplicationScale;
    final boolean scalingRequired = mAttachInfo.mScalingRequired;
    int resizeAlpha = 0;
    final Rect dirty = mDirty;
    if (mSurfaceHolder != null) {
        // The app owns the surface, we won't draw.
        dirty.setEmpty();
        if (animating && mScroller != null) {
            mScroller.abortAnimation();
        }
        return;
    }
    if (fullRedrawNeeded) {
        mAttachInfo.mIgnoreDirtyState = true;
        dirty.set(0, 0, (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f));
    }
    if (DEBUG_ORIENTATION || DEBUG_DRAW) {
        Log.v(mTag, "Draw " + mView + "/" + mWindowAttributes.getTitle() + ": dirty={" + dirty.left + "," + dirty.top + "," + dirty.right + "," + dirty.bottom + "} surface=" + surface + " surface.isValid()=" + surface.isValid() + ", appScale:" + appScale + ", width=" + mWidth + ", height=" + mHeight);
    }
    mAttachInfo.mTreeObserver.dispatchOnDraw();
    int xOffset = -mCanvasOffsetX;
    int yOffset = -mCanvasOffsetY + curScrollY;
    final WindowManager.LayoutParams params = mWindowAttributes;
    final Rect surfaceInsets = params != null ? params.surfaceInsets : null;
    if (surfaceInsets != null) {
        xOffset -= surfaceInsets.left;
        yOffset -= surfaceInsets.top;
        // Offset dirty rect for surface insets.
        dirty.offset(surfaceInsets.left, surfaceInsets.right);
    }
    boolean accessibilityFocusDirty = false;
    final Drawable drawable = mAttachInfo.mAccessibilityFocusDrawable;
    if (drawable != null) {
        final Rect bounds = mAttachInfo.mTmpInvalRect;
        final boolean hasFocus = getAccessibilityFocusedRect(bounds);
        if (!hasFocus) {
            bounds.setEmpty();
        }
        if (!bounds.equals(drawable.getBounds())) {
            accessibilityFocusDirty = true;
        }
    }
    mAttachInfo.mDrawingTime = mChoreographer.getFrameTimeNanos() / TimeUtils.NANOS_PER_MS;
    if (!dirty.isEmpty() || mIsAnimating || accessibilityFocusDirty) {
        if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) {
            // If accessibility focus moved, always invalidate the root.
            boolean invalidateRoot = accessibilityFocusDirty || mInvalidateRootRequested;
            mInvalidateRootRequested = false;
            // Draw with hardware renderer.
            mIsAnimating = false;
            if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) {
                mHardwareYOffset = yOffset;
                mHardwareXOffset = xOffset;
                invalidateRoot = true;
            }
            if (invalidateRoot) {
                mAttachInfo.mHardwareRenderer.invalidateRoot();
            }
            dirty.setEmpty();
            // Stage the content drawn size now. It will be transferred to the renderer
            // shortly before the draw commands get send to the renderer.
            final boolean updated = updateContentDrawBounds();
            if (mReportNextDraw) {
                // report next draw overrides setStopped()
                // This value is re-sync'd to the value of mStopped
                // in the handling of mReportNextDraw post-draw.
                mAttachInfo.mHardwareRenderer.setStopped(false);
            }
            if (updated) {
                requestDrawWindow();
            }
            mAttachInfo.mHardwareRenderer.draw(mView, mAttachInfo, this);
        } else {
            // eglTerminate() for instance.
            if (mAttachInfo.mHardwareRenderer != null && !mAttachInfo.mHardwareRenderer.isEnabled() && mAttachInfo.mHardwareRenderer.isRequested()) {
                try {
                    mAttachInfo.mHardwareRenderer.initializeIfNeeded(mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets);
                } catch (OutOfResourcesException e) {
                    handleOutOfResourcesException(e);
                    return;
                }
                mFullRedrawNeeded = true;
                scheduleTraversals();
                return;
            }
            if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset, scalingRequired, dirty)) {
                return;
            }
        }
    }
    if (animating) {
        mFullRedrawNeeded = true;
        scheduleTraversals();
    }
}
Also used : Rect(android.graphics.Rect) RootViewSurfaceTaker(com.android.internal.view.RootViewSurfaceTaker) OutOfResourcesException(android.view.Surface.OutOfResourcesException) Drawable(android.graphics.drawable.Drawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Point(android.graphics.Point)

Example 29 with OutOfResourcesException

use of android.view.Surface.OutOfResourcesException in project android_frameworks_base by crdroidandroid.

the class ViewRootImpl method draw.

private void draw(boolean fullRedrawNeeded) {
    Surface surface = mSurface;
    if (!surface.isValid()) {
        return;
    }
    if (DEBUG_FPS) {
        trackFPS();
    }
    if (!sFirstDrawComplete) {
        synchronized (sFirstDrawHandlers) {
            sFirstDrawComplete = true;
            final int count = sFirstDrawHandlers.size();
            for (int i = 0; i < count; i++) {
                mHandler.post(sFirstDrawHandlers.get(i));
            }
        }
    }
    scrollToRectOrFocus(null, false);
    if (mAttachInfo.mViewScrollChanged) {
        mAttachInfo.mViewScrollChanged = false;
        mAttachInfo.mTreeObserver.dispatchOnScrollChanged();
    }
    boolean animating = mScroller != null && mScroller.computeScrollOffset();
    final int curScrollY;
    if (animating) {
        curScrollY = mScroller.getCurrY();
    } else {
        curScrollY = mScrollY;
    }
    if (mCurScrollY != curScrollY) {
        mCurScrollY = curScrollY;
        fullRedrawNeeded = true;
        if (mView instanceof RootViewSurfaceTaker) {
            ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY);
        }
    }
    final float appScale = mAttachInfo.mApplicationScale;
    final boolean scalingRequired = mAttachInfo.mScalingRequired;
    int resizeAlpha = 0;
    final Rect dirty = mDirty;
    if (mSurfaceHolder != null) {
        // The app owns the surface, we won't draw.
        dirty.setEmpty();
        if (animating && mScroller != null) {
            mScroller.abortAnimation();
        }
        return;
    }
    if (fullRedrawNeeded) {
        mAttachInfo.mIgnoreDirtyState = true;
        dirty.set(0, 0, (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f));
    }
    if (DEBUG_ORIENTATION || DEBUG_DRAW) {
        Log.v(mTag, "Draw " + mView + "/" + mWindowAttributes.getTitle() + ": dirty={" + dirty.left + "," + dirty.top + "," + dirty.right + "," + dirty.bottom + "} surface=" + surface + " surface.isValid()=" + surface.isValid() + ", appScale:" + appScale + ", width=" + mWidth + ", height=" + mHeight);
    }
    mAttachInfo.mTreeObserver.dispatchOnDraw();
    int xOffset = -mCanvasOffsetX;
    int yOffset = -mCanvasOffsetY + curScrollY;
    final WindowManager.LayoutParams params = mWindowAttributes;
    final Rect surfaceInsets = params != null ? params.surfaceInsets : null;
    if (surfaceInsets != null) {
        xOffset -= surfaceInsets.left;
        yOffset -= surfaceInsets.top;
        // Offset dirty rect for surface insets.
        dirty.offset(surfaceInsets.left, surfaceInsets.right);
    }
    boolean accessibilityFocusDirty = false;
    final Drawable drawable = mAttachInfo.mAccessibilityFocusDrawable;
    if (drawable != null) {
        final Rect bounds = mAttachInfo.mTmpInvalRect;
        final boolean hasFocus = getAccessibilityFocusedRect(bounds);
        if (!hasFocus) {
            bounds.setEmpty();
        }
        if (!bounds.equals(drawable.getBounds())) {
            accessibilityFocusDirty = true;
        }
    }
    mAttachInfo.mDrawingTime = mChoreographer.getFrameTimeNanos() / TimeUtils.NANOS_PER_MS;
    if (!dirty.isEmpty() || mIsAnimating || accessibilityFocusDirty) {
        if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) {
            // If accessibility focus moved, always invalidate the root.
            boolean invalidateRoot = accessibilityFocusDirty || mInvalidateRootRequested;
            mInvalidateRootRequested = false;
            // Draw with hardware renderer.
            mIsAnimating = false;
            if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) {
                mHardwareYOffset = yOffset;
                mHardwareXOffset = xOffset;
                invalidateRoot = true;
            }
            if (invalidateRoot) {
                mAttachInfo.mHardwareRenderer.invalidateRoot();
            }
            dirty.setEmpty();
            // Stage the content drawn size now. It will be transferred to the renderer
            // shortly before the draw commands get send to the renderer.
            final boolean updated = updateContentDrawBounds();
            if (mReportNextDraw) {
                // report next draw overrides setStopped()
                // This value is re-sync'd to the value of mStopped
                // in the handling of mReportNextDraw post-draw.
                mAttachInfo.mHardwareRenderer.setStopped(false);
            }
            if (updated) {
                requestDrawWindow();
            }
            mAttachInfo.mHardwareRenderer.draw(mView, mAttachInfo, this);
        } else {
            // eglTerminate() for instance.
            if (mAttachInfo.mHardwareRenderer != null && !mAttachInfo.mHardwareRenderer.isEnabled() && mAttachInfo.mHardwareRenderer.isRequested()) {
                try {
                    mAttachInfo.mHardwareRenderer.initializeIfNeeded(mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets);
                } catch (OutOfResourcesException e) {
                    handleOutOfResourcesException(e);
                    return;
                }
                mFullRedrawNeeded = true;
                scheduleTraversals();
                return;
            }
            if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset, scalingRequired, dirty)) {
                return;
            }
        }
    }
    if (animating) {
        mFullRedrawNeeded = true;
        scheduleTraversals();
    }
}
Also used : Rect(android.graphics.Rect) RootViewSurfaceTaker(com.android.internal.view.RootViewSurfaceTaker) OutOfResourcesException(android.view.Surface.OutOfResourcesException) Drawable(android.graphics.drawable.Drawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Point(android.graphics.Point)

Example 30 with OutOfResourcesException

use of android.view.Surface.OutOfResourcesException in project android_frameworks_base by crdroidandroid.

the class ScreenRotationAnimation method startAnimation.

/**
     * Returns true if animating.
     */
private boolean startAnimation(SurfaceSession session, long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight, boolean dismissing, int exitAnim, int enterAnim) {
    if (mSurfaceControl == null) {
        // Can't do animation.
        return false;
    }
    if (mStarted) {
        return true;
    }
    mStarted = true;
    boolean firstStart = false;
    // Figure out how the screen has moved from the original rotation.
    int delta = DisplayContent.deltaRotation(mCurRotation, mOriginalRotation);
    if (TWO_PHASE_ANIMATION && mFinishExitAnimation == null && (!dismissing || delta != Surface.ROTATION_0)) {
        if (DEBUG_STATE)
            Slog.v(TAG, "Creating start and finish animations");
        firstStart = true;
        mStartExitAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_start_exit);
        mStartEnterAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_start_enter);
        if (USE_CUSTOM_BLACK_FRAME) {
            mStartFrameAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_start_frame);
        }
        mFinishExitAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_finish_exit);
        mFinishEnterAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_finish_enter);
        if (USE_CUSTOM_BLACK_FRAME) {
            mFinishFrameAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_finish_frame);
        }
    }
    if (DEBUG_STATE)
        Slog.v(TAG, "Rotation delta: " + delta + " finalWidth=" + finalWidth + " finalHeight=" + finalHeight + " origWidth=" + mOriginalWidth + " origHeight=" + mOriginalHeight);
    final boolean customAnim;
    if (exitAnim != 0 && enterAnim != 0) {
        customAnim = true;
        mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, exitAnim);
        mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, enterAnim);
    } else {
        customAnim = false;
        switch(delta) {
            case Surface.ROTATION_0:
                mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_0_exit);
                mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_0_enter);
                if (USE_CUSTOM_BLACK_FRAME) {
                    mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_0_frame);
                }
                break;
            case Surface.ROTATION_90:
                mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_plus_90_exit);
                mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_plus_90_enter);
                if (USE_CUSTOM_BLACK_FRAME) {
                    mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_plus_90_frame);
                }
                break;
            case Surface.ROTATION_180:
                mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_180_exit);
                mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_180_enter);
                if (USE_CUSTOM_BLACK_FRAME) {
                    mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_180_frame);
                }
                break;
            case Surface.ROTATION_270:
                mRotateExitAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_minus_90_exit);
                mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_minus_90_enter);
                if (USE_CUSTOM_BLACK_FRAME) {
                    mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.screen_rotate_minus_90_frame);
                }
                break;
        }
    }
    // screen's current/new size.
    if (TWO_PHASE_ANIMATION && firstStart) {
        // Compute partial steps between original and final sizes.  These
        // are used for the dimensions of the exiting and entering elements,
        // so they are never stretched too significantly.
        final int halfWidth = (finalWidth + mOriginalWidth) / 2;
        final int halfHeight = (finalHeight + mOriginalHeight) / 2;
        if (DEBUG_STATE)
            Slog.v(TAG, "Initializing start and finish animations");
        mStartEnterAnimation.initialize(finalWidth, finalHeight, halfWidth, halfHeight);
        mStartExitAnimation.initialize(halfWidth, halfHeight, mOriginalWidth, mOriginalHeight);
        mFinishEnterAnimation.initialize(finalWidth, finalHeight, halfWidth, halfHeight);
        mFinishExitAnimation.initialize(halfWidth, halfHeight, mOriginalWidth, mOriginalHeight);
        if (USE_CUSTOM_BLACK_FRAME) {
            mStartFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
            mFinishFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
        }
    }
    mRotateEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
    mRotateExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
    if (USE_CUSTOM_BLACK_FRAME) {
        mRotateFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
    }
    mAnimRunning = false;
    mFinishAnimReady = false;
    mFinishAnimStartTime = -1;
    if (TWO_PHASE_ANIMATION && firstStart) {
        mStartExitAnimation.restrictDuration(maxAnimationDuration);
        mStartExitAnimation.scaleCurrentDuration(animationScale);
        mStartEnterAnimation.restrictDuration(maxAnimationDuration);
        mStartEnterAnimation.scaleCurrentDuration(animationScale);
        mFinishExitAnimation.restrictDuration(maxAnimationDuration);
        mFinishExitAnimation.scaleCurrentDuration(animationScale);
        mFinishEnterAnimation.restrictDuration(maxAnimationDuration);
        mFinishEnterAnimation.scaleCurrentDuration(animationScale);
        if (USE_CUSTOM_BLACK_FRAME) {
            mStartFrameAnimation.restrictDuration(maxAnimationDuration);
            mStartFrameAnimation.scaleCurrentDuration(animationScale);
            mFinishFrameAnimation.restrictDuration(maxAnimationDuration);
            mFinishFrameAnimation.scaleCurrentDuration(animationScale);
        }
    }
    mRotateExitAnimation.restrictDuration(maxAnimationDuration);
    mRotateExitAnimation.scaleCurrentDuration(animationScale);
    mRotateEnterAnimation.restrictDuration(maxAnimationDuration);
    mRotateEnterAnimation.scaleCurrentDuration(animationScale);
    if (USE_CUSTOM_BLACK_FRAME) {
        mRotateFrameAnimation.restrictDuration(maxAnimationDuration);
        mRotateFrameAnimation.scaleCurrentDuration(animationScale);
    }
    final int layerStack = mDisplayContent.getDisplay().getLayerStack();
    if (USE_CUSTOM_BLACK_FRAME && mCustomBlackFrame == null) {
        if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE)
            Slog.i(TAG_WM, ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
        SurfaceControl.openTransaction();
        // Compute the transformation matrix that must be applied
        // the the black frame to make it stay in the initial position
        // before the new screen rotation.  This is different than the
        // snapshot transformation because the snapshot is always based
        // of the native orientation of the screen, not the orientation
        // we were last in.
        createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix);
        try {
            Rect outer = new Rect(-mOriginalWidth * 1, -mOriginalHeight * 1, mOriginalWidth * 2, mOriginalHeight * 2);
            Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
            mCustomBlackFrame = new BlackFrame(session, outer, inner, SCREEN_FREEZE_LAYER_CUSTOM, layerStack, false);
            mCustomBlackFrame.setMatrix(mFrameInitialMatrix);
        } catch (OutOfResourcesException e) {
            Slog.w(TAG, "Unable to allocate black surface", e);
        } finally {
            SurfaceControl.closeTransaction();
            if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE)
                Slog.i(TAG_WM, "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
        }
    }
    if (!customAnim && mExitingBlackFrame == null) {
        if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE)
            Slog.i(TAG_WM, ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
        SurfaceControl.openTransaction();
        try {
            // Compute the transformation matrix that must be applied
            // the the black frame to make it stay in the initial position
            // before the new screen rotation.  This is different than the
            // snapshot transformation because the snapshot is always based
            // of the native orientation of the screen, not the orientation
            // we were last in.
            createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix);
            final Rect outer;
            final Rect inner;
            if (mForceDefaultOrientation) {
                // Going from a smaller Display to a larger Display, add curtains to sides
                // or top and bottom. Going from a larger to smaller display will result in
                // no BlackSurfaces being constructed.
                outer = mCurrentDisplayRect;
                inner = mOriginalDisplayRect;
            } else {
                outer = new Rect(-mOriginalWidth * 1, -mOriginalHeight * 1, mOriginalWidth * 2, mOriginalHeight * 2);
                inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
            }
            mExitingBlackFrame = new BlackFrame(session, outer, inner, SCREEN_FREEZE_LAYER_EXIT, layerStack, mForceDefaultOrientation);
            mExitingBlackFrame.setMatrix(mFrameInitialMatrix);
        } catch (OutOfResourcesException e) {
            Slog.w(TAG, "Unable to allocate black surface", e);
        } finally {
            SurfaceControl.closeTransaction();
            if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE)
                Slog.i(TAG_WM, "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
        }
    }
    if (customAnim && mEnteringBlackFrame == null) {
        if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE)
            Slog.i(TAG_WM, ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
        SurfaceControl.openTransaction();
        try {
            Rect outer = new Rect(-finalWidth * 1, -finalHeight * 1, finalWidth * 2, finalHeight * 2);
            Rect inner = new Rect(0, 0, finalWidth, finalHeight);
            mEnteringBlackFrame = new BlackFrame(session, outer, inner, SCREEN_FREEZE_LAYER_ENTER, layerStack, false);
        } catch (OutOfResourcesException e) {
            Slog.w(TAG, "Unable to allocate black surface", e);
        } finally {
            SurfaceControl.closeTransaction();
            if (SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE)
                Slog.i(TAG_WM, "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
        }
    }
    return true;
}
Also used : Rect(android.graphics.Rect) OutOfResourcesException(android.view.Surface.OutOfResourcesException)

Aggregations

OutOfResourcesException (android.view.Surface.OutOfResourcesException)31 Point (android.graphics.Point)21 Rect (android.graphics.Rect)19 RootViewSurfaceTaker (com.android.internal.view.RootViewSurfaceTaker)10 RemoteException (android.os.RemoteException)9 SurfaceControl (android.view.SurfaceControl)8 CompatibilityInfo (android.content.res.CompatibilityInfo)5 Configuration (android.content.res.Configuration)5 Resources (android.content.res.Resources)5 Canvas (android.graphics.Canvas)5 Region (android.graphics.Region)5 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)5 Drawable (android.graphics.drawable.Drawable)5 EGLSurface (android.opengl.EGLSurface)5 Surface (android.view.Surface)5 SurfaceSession (android.view.SurfaceSession)5 IAccessibilityInteractionConnectionCallback (android.view.accessibility.IAccessibilityInteractionConnectionCallback)5 InputMethodManager (android.view.inputmethod.InputMethodManager)5 BaseSurfaceHolder (com.android.internal.view.BaseSurfaceHolder)5 WindowManager (android.view.WindowManager)4