Search in sources :

Example 21 with OutOfResourcesException

use of android.view.Surface.OutOfResourcesException in project platform_frameworks_base by android.

the class WindowManagerService method prepareDragSurface.

// -------------------------------------------------------------
// Drag and drop
// -------------------------------------------------------------
IBinder prepareDragSurface(IWindow window, SurfaceSession session, int flags, int width, int height, Surface outSurface) {
    if (DEBUG_DRAG) {
        Slog.d(TAG_WM, "prepare drag surface: w=" + width + " h=" + height + " flags=" + Integer.toHexString(flags) + " win=" + window + " asbinder=" + window.asBinder());
    }
    final int callerPid = Binder.getCallingPid();
    final int callerUid = Binder.getCallingUid();
    final long origId = Binder.clearCallingIdentity();
    IBinder token = null;
    try {
        synchronized (mWindowMap) {
            try {
                if (mDragState == null) {
                    // TODO(multi-display): support other displays
                    final DisplayContent displayContent = getDefaultDisplayContentLocked();
                    final Display display = displayContent.getDisplay();
                    SurfaceControl surface = new SurfaceControl(session, "drag surface", width, height, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
                    surface.setLayerStack(display.getLayerStack());
                    float alpha = 1;
                    if ((flags & View.DRAG_FLAG_OPAQUE) == 0) {
                        alpha = DRAG_SHADOW_ALPHA_TRANSPARENT;
                    }
                    surface.setAlpha(alpha);
                    if (SHOW_TRANSACTIONS)
                        Slog.i(TAG_WM, "  DRAG " + surface + ": CREATE");
                    outSurface.copyFrom(surface);
                    final IBinder winBinder = window.asBinder();
                    token = new Binder();
                    mDragState = new DragState(this, token, surface, flags, winBinder);
                    mDragState.mPid = callerPid;
                    mDragState.mUid = callerUid;
                    mDragState.mOriginalAlpha = alpha;
                    token = mDragState.mToken = new Binder();
                    // 5 second timeout for this window to actually begin the drag
                    mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
                    Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
                    mH.sendMessageDelayed(msg, 5000);
                } else {
                    Slog.w(TAG_WM, "Drag already in progress");
                }
            } catch (OutOfResourcesException e) {
                Slog.e(TAG_WM, "Can't allocate drag surface w=" + width + " h=" + height, e);
                if (mDragState != null) {
                    mDragState.reset();
                    mDragState = null;
                }
            }
        }
    } finally {
        Binder.restoreCallingIdentity(origId);
    }
    return token;
}
Also used : Binder(android.os.Binder) IBinder(android.os.IBinder) IBinder(android.os.IBinder) Message(android.os.Message) OutOfResourcesException(android.view.Surface.OutOfResourcesException) SurfaceControl(android.view.SurfaceControl) Point(android.graphics.Point) Display(android.view.Display)

Example 22 with OutOfResourcesException

use of android.view.Surface.OutOfResourcesException 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)

Example 23 with OutOfResourcesException

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

the class EmulatorDisplayOverlay method drawIfNeeded.

private void drawIfNeeded() {
    if (!mDrawNeeded || !mVisible) {
        return;
    }
    mDrawNeeded = false;
    Rect dirty = new Rect(0, 0, mScreenSize.x, mScreenSize.y);
    Canvas c = null;
    try {
        c = mSurface.lockCanvas(dirty);
    } catch (IllegalArgumentException e) {
    } catch (OutOfResourcesException e) {
    }
    if (c == null) {
        return;
    }
    c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.SRC);
    mSurfaceControl.setPosition(0, 0);
    // Always draw the overlay with square dimensions
    int size = Math.max(mScreenSize.x, mScreenSize.y);
    mOverlay.setBounds(0, 0, size, size);
    mOverlay.draw(c);
    mSurface.unlockCanvasAndPost(c);
}
Also used : Rect(android.graphics.Rect) OutOfResourcesException(android.view.Surface.OutOfResourcesException) Canvas(android.graphics.Canvas) Point(android.graphics.Point)

Example 24 with OutOfResourcesException

use of android.view.Surface.OutOfResourcesException 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 25 with OutOfResourcesException

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

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) {
        if (mIsPreFlingBoostEnabled && mHaveMoveEvent && !mIsPerfLockAcquired) {
            mIsPerfLockAcquired = true;
            if (mPerf == null) {
                mPerf = new BoostFramework();
            }
            if (mPerf != null) {
                mPerf.perfLockAcquire(mPreFlingBoostTimeOut, mPreFlingBoostParamVal);
            }
        }
        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) BoostFramework(android.util.BoostFramework) 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)

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