android.view.SurfaceControl Java Examples
The following examples show how to use
android.view.SurfaceControl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UiAutomationConnection.java From android_9.0.0_r45 with Apache License 2.0 | 8 votes |
@Override public Bitmap takeScreenshot(Rect crop, int rotation) { synchronized (mLock) { throwIfCalledByNotTrustedUidLocked(); throwIfShutdownLocked(); throwIfNotConnectedLocked(); } final long identity = Binder.clearCallingIdentity(); try { int width = crop.width(); int height = crop.height(); return SurfaceControl.screenshot(crop, width, height, rotation); } finally { Binder.restoreCallingIdentity(identity); } }
Example #2
Source File: OverlayDisplayAdapter.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void onWindowCreated(SurfaceTexture surfaceTexture, float refreshRate, long presentationDeadlineNanos, int state) { synchronized (getSyncRoot()) { IBinder displayToken = SurfaceControl.createDisplay(mName, mSecure); mDevice = new OverlayDisplayDevice(displayToken, mName, mModes, mActiveMode, DEFAULT_MODE_INDEX, refreshRate, presentationDeadlineNanos, mSecure, state, surfaceTexture, mNumber) { @Override public void onModeChangedLocked(int index) { onActiveModeChangedLocked(index); } }; sendDisplayDeviceEventLocked(mDevice, DISPLAY_DEVICE_EVENT_ADDED); } }
Example #3
Source File: ColorFade.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void destroySurface() { if (mSurfaceControl != null) { mSurfaceLayout.dispose(); mSurfaceLayout = null; SurfaceControl.openTransaction(); try { mSurfaceControl.destroy(); mSurface.release(); } finally { SurfaceControl.closeTransaction(); } mSurfaceControl = null; mSurfaceVisible = false; mSurfaceAlpha = 0f; } }
Example #4
Source File: ScreenRotationAnimation.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Returns true if animating. */ public boolean dismiss(SurfaceControl.Transaction t, long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight, int exitAnim, int enterAnim) { if (DEBUG_STATE) Slog.v(TAG, "Dismiss!"); if (mSurfaceControl == null) { // Can't do animation. return false; } if (!mStarted) { startAnimation(t, maxAnimationDuration, animationScale, finalWidth, finalHeight, true, exitAnim, enterAnim); } if (!mStarted) { return false; } if (DEBUG_STATE) Slog.v(TAG, "Setting mFinishAnimReady = true"); mFinishAnimReady = true; return true; }
Example #5
Source File: SurfaceAnimator.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Starts an animation. * * @param anim The object that bridges the controller, {@link SurfaceAnimator}, with the * component responsible for running the animation. It runs the animation with * {@link AnimationAdapter#startAnimation} once the hierarchy with * the Leash has been set up. * @param hidden Whether the container holding the child surfaces is currently visible or not. * This is important as it will start with the leash hidden or visible before * handing it to the component that is responsible to run the animation. */ void startAnimation(Transaction t, AnimationAdapter anim, boolean hidden) { cancelAnimation(t, true /* restarting */, true /* forwardCancel */); mAnimation = anim; final SurfaceControl surface = mAnimatable.getSurfaceControl(); if (surface == null) { Slog.w(TAG, "Unable to start animation, surface is null or no children."); cancelAnimation(); return; } mLeash = createAnimationLeash(surface, t, mAnimatable.getSurfaceWidth(), mAnimatable.getSurfaceHeight(), hidden); mAnimatable.onAnimationLeashCreated(t, mLeash); if (mAnimationStartDelayed) { if (DEBUG_ANIM) Slog.i(TAG, "Animation start delayed"); return; } mAnimation.startAnimation(mLeash, t, mInnerAnimationFinishedCallback); }
Example #6
Source File: DisplayManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@VisibleForTesting void performTraversalInternal(SurfaceControl.Transaction t) { synchronized (mSyncRoot) { if (!mPendingTraversal) { return; } mPendingTraversal = false; performTraversalLocked(t); } // List is self-synchronized copy-on-write. for (DisplayTransactionListener listener : mDisplayTransactionListeners) { listener.onDisplayTransaction(); } }
Example #7
Source File: UiAutomationConnection.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public WindowAnimationFrameStats getWindowAnimationFrameStats() { synchronized (mLock) { throwIfCalledByNotTrustedUidLocked(); throwIfShutdownLocked(); throwIfNotConnectedLocked(); } final long identity = Binder.clearCallingIdentity(); try { WindowAnimationFrameStats stats = new WindowAnimationFrameStats(); SurfaceControl.getAnimationFrameStats(stats); return stats; } finally { Binder.restoreCallingIdentity(identity); } }
Example #8
Source File: SurfaceAnimator.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
void transferAnimation(SurfaceAnimator from) { if (from.mLeash == null) { return; } final SurfaceControl surface = mAnimatable.getSurfaceControl(); final SurfaceControl parent = mAnimatable.getAnimationLeashParent(); if (surface == null || parent == null) { Slog.w(TAG, "Unable to transfer animation, surface or parent is null"); cancelAnimation(); return; } endDelayingAnimationStart(); final Transaction t = mAnimatable.getPendingTransaction(); cancelAnimation(t, true /* restarting */, true /* forwardCancel */); mLeash = from.mLeash; mAnimation = from.mAnimation; // Cancel source animation, but don't let animation runner cancel the animation. from.cancelAnimation(t, false /* restarting */, false /* forwardCancel */); t.reparent(surface, mLeash.getHandle()); t.reparent(mLeash, parent.getHandle()); mAnimatable.onAnimationLeashCreated(t, mLeash); mService.mAnimationTransferMap.put(mAnimation, this); }
Example #9
Source File: SurfaceAnimationRunner.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
void onAnimationCancelled(SurfaceControl leash) { synchronized (mLock) { if (mPendingAnimations.containsKey(leash)) { mPendingAnimations.remove(leash); return; } final RunningAnimation anim = mRunningAnimations.get(leash); if (anim != null) { mRunningAnimations.remove(leash); synchronized (mCancelLock) { anim.mCancelled = true; } SurfaceAnimationThread.getHandler().post(() -> { anim.mAnim.cancel(); applyTransaction(); }); } } }
Example #10
Source File: ScreenRotationAnimation.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void setSnapshotTransform(SurfaceControl.Transaction t, Matrix matrix, float alpha) { if (mSurfaceControl != null) { matrix.getValues(mTmpFloats); float x = mTmpFloats[Matrix.MTRANS_X]; float y = mTmpFloats[Matrix.MTRANS_Y]; if (mForceDefaultOrientation) { mDisplayContent.getBounds(mCurrentDisplayRect); x -= mCurrentDisplayRect.left; y -= mCurrentDisplayRect.top; } t.setPosition(mSurfaceControl, x, y); t.setMatrix(mSurfaceControl, mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y], mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]); t.setAlpha(mSurfaceControl, alpha); if (DEBUG_TRANSFORMS) { float[] srcPnts = new float[] { 0, 0, mWidth, mHeight }; float[] dstPnts = new float[4]; matrix.mapPoints(dstPnts, srcPnts); Slog.i(TAG, "Original : (" + srcPnts[0] + "," + srcPnts[1] + ")-(" + srcPnts[2] + "," + srcPnts[3] + ")"); Slog.i(TAG, "Transformed: (" + dstPnts[0] + "," + dstPnts[1] + ")-(" + dstPnts[2] + "," + dstPnts[3] + ")"); } } }
Example #11
Source File: Dimmer.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Call after invoking {@link WindowContainer#prepareSurfaces} on children as * described in {@link #resetDimStates}. * * @param t A transaction in which to update the dims. * @param bounds The bounds at which to dim. * @return true if any Dims were updated. */ boolean updateDims(SurfaceControl.Transaction t, Rect bounds) { if (mDimState == null) { return false; } if (!mDimState.mDimming) { if (!mDimState.mAnimateExit) { t.destroy(mDimState.mDimLayer); } else { startDimExit(mLastRequestedDimContainer, mDimState.mSurfaceAnimator, t); } mDimState = null; return false; } else { // TODO: Once we use geometry from hierarchy this falls away. t.setSize(mDimState.mDimLayer, bounds.width(), bounds.height()); t.setPosition(mDimState.mDimLayer, bounds.left, bounds.top); if (!mDimState.isVisible) { mDimState.isVisible = true; t.show(mDimState.mDimLayer); startDimEnter(mLastRequestedDimContainer, mDimState.mSurfaceAnimator, t); } return true; } }
Example #12
Source File: Letterbox.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void applySurfaceChanges(SurfaceControl.Transaction t) { if (mSurfaceFrame.equals(mLayoutFrame)) { // Nothing changed. return; } mSurfaceFrame.set(mLayoutFrame); if (!mSurfaceFrame.isEmpty()) { if (mSurface == null) { createSurface(); } t.setPosition(mSurface, mSurfaceFrame.left, mSurfaceFrame.top); t.setSize(mSurface, mSurfaceFrame.width(), mSurfaceFrame.height()); t.show(mSurface); } else if (mSurface != null) { t.hide(mSurface); } }
Example #13
Source File: WindowAnimationSpec.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) { final TmpValues tmp = mThreadLocalTmps.get(); tmp.transformation.clear(); mAnimation.getTransformation(currentPlayTime, tmp.transformation); tmp.transformation.getMatrix().postTranslate(mPosition.x, mPosition.y); t.setMatrix(leash, tmp.transformation.getMatrix(), tmp.floats); t.setAlpha(leash, tmp.transformation.getAlpha()); if (mStackClipMode == STACK_CLIP_NONE) { t.setWindowCrop(leash, tmp.transformation.getClipRect()); } else if (mStackClipMode == STACK_CLIP_AFTER_ANIM) { mTmpRect.set(mStackBounds); // Offset stack bounds to stack position so the final crop is in screen space. mTmpRect.offsetTo(mPosition.x, mPosition.y); t.setFinalCrop(leash, mTmpRect); t.setWindowCrop(leash, tmp.transformation.getClipRect()); } else { mTmpRect.set(mStackBounds); mTmpRect.intersect(tmp.transformation.getClipRect()); t.setWindowCrop(leash, mTmpRect); } }
Example #14
Source File: BlackFrame.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
BlackSurface(SurfaceControl.Transaction transaction, int layer, int l, int t, int r, int b, DisplayContent dc) throws OutOfResourcesException { left = l; top = t; this.layer = layer; int w = r-l; int h = b-t; surface = dc.makeOverlay() .setName("BlackSurface") .setSize(w, h) .setColorLayer(true) .setParent(null) // TODO: Work-around for b/69259549 .build(); transaction.setAlpha(surface, 1); transaction.setLayer(surface, layer); transaction.show(surface); if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM, " BLACK " + surface + ": CREATE layer=" + layer); }
Example #15
Source File: AppWindowToken.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) { // The leash is parented to the animation layer. We need to preserve the z-order by using // the prefix order index, but we boost if necessary. int layer = 0; if (!inPinnedWindowingMode()) { layer = getPrefixOrderIndex(); } else { // Pinned stacks have animations take place within themselves rather than an animation // layer so we need to preserve the order relative to the stack (e.g. the order of our // task/parent). layer = getParent().getPrefixOrderIndex(); } if (mNeedsZBoost) { layer += Z_BOOST_BASE; } leash.setLayer(layer); final DisplayContent dc = getDisplayContent(); dc.assignStackOrdering(); if (mAnimatingAppWindowTokenRegistry != null) { mAnimatingAppWindowTokenRegistry.notifyStarting(this); } }
Example #16
Source File: Dimmer.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void dim(SurfaceControl.Transaction t, WindowContainer container, int relativeLayer, float alpha) { final DimState d = getDimState(container); if (d == null) { return; } if (container != null) { // The dim method is called from WindowState.prepareSurfaces(), which is always called // in the correct Z from lowest Z to highest. This ensures that the dim layer is always // relative to the highest Z layer with a dim. t.setRelativeLayer(d.mDimLayer, container.getSurfaceControl(), relativeLayer); } else { t.setLayer(d.mDimLayer, Integer.MAX_VALUE); } t.setAlpha(d.mDimLayer, alpha); d.mDimming = true; }
Example #17
Source File: WindowSurfaceController.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
void setPosition(SurfaceControl.Transaction t, float left, float top, boolean recoveringMemory) { final boolean surfaceMoved = mSurfaceX != left || mSurfaceY != top; if (surfaceMoved) { mSurfaceX = left; mSurfaceY = top; try { if (SHOW_TRANSACTIONS) logSurface( "POS (setPositionInTransaction) @ (" + left + "," + top + ")", null); if (t == null) { mSurfaceControl.setPosition(left, top); } else { t.setPosition(mSurfaceControl, left, top); } } catch (RuntimeException e) { Slog.w(TAG, "Error positioning surface of " + this + " pos=(" + left + "," + top + ")", e); if (!recoveringMemory) { mAnimator.reclaimSomeSurfaceMemory("position", true); } } } }
Example #18
Source File: EmulatorDisplayOverlay.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public EmulatorDisplayOverlay(Context context, DisplayContent dc, int zOrder) { final Display display = dc.getDisplay(); mScreenSize = new Point(); display.getSize(mScreenSize); SurfaceControl ctrl = null; try { ctrl = dc.makeOverlay() .setName("EmulatorDisplayOverlay") .setSize(mScreenSize.x, mScreenSize.y) .setFormat(PixelFormat.TRANSLUCENT) .build(); ctrl.setLayer(zOrder); ctrl.setPosition(0, 0); ctrl.show(); mSurface.copyFrom(ctrl); } catch (OutOfResourcesException e) { } mSurfaceControl = ctrl; mDrawNeeded = true; mOverlay = context.getDrawable( com.android.internal.R.drawable.emulator_circular_window_overlay); }
Example #19
Source File: ScreenRotationAnimation.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void setRotation(SurfaceControl.Transaction t, int rotation) { mCurRotation = rotation; // Compute the transformation matrix that must be applied // to the snapshot to make it stay in the same original position // with the current screen rotation. int delta = DisplayContent.deltaRotation(rotation, Surface.ROTATION_0); createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix); if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta); setSnapshotTransform(t, mSnapshotInitialMatrix, 1.0f); }
Example #20
Source File: WindowSurfaceController.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private boolean updateVisibility() { if (mHiddenForCrop || mHiddenForOtherReasons) { if (mSurfaceShown) { hideSurface(mTmpTransaction); SurfaceControl.mergeToGlobalTransaction(mTmpTransaction); } return false; } else { if (!mSurfaceShown) { return showSurface(); } else { return true; } } }
Example #21
Source File: CircularDisplayMask.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public CircularDisplayMask(DisplayContent dc, int zOrder, int screenOffset, int maskThickness) { final Display display = dc.getDisplay(); mScreenSize = new Point(); display.getSize(mScreenSize); if (mScreenSize.x != mScreenSize.y + screenOffset) { Slog.w(TAG, "Screen dimensions of displayId = " + display.getDisplayId() + "are not equal, circularMask will not be drawn."); mDimensionsUnequal = true; } SurfaceControl ctrl = null; try { ctrl = dc.makeOverlay() .setName("CircularDisplayMask") .setSize(mScreenSize.x, mScreenSize.y) // not a typo .setFormat(PixelFormat.TRANSLUCENT) .build(); ctrl.setLayerStack(display.getLayerStack()); ctrl.setLayer(zOrder); ctrl.setPosition(0, 0); ctrl.show(); mSurface.copyFrom(ctrl); } catch (OutOfResourcesException e) { } mSurfaceControl = ctrl; mDrawNeeded = true; mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); mScreenOffset = screenOffset; mMaskThickness = maskThickness; }
Example #22
Source File: BlackFrame.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public void clearMatrix(SurfaceControl.Transaction t) { for (int i=0; i<mBlackSurfaces.length; i++) { if (mBlackSurfaces[i] != null) { mBlackSurfaces[i].clearMatrix(t); } } }
Example #23
Source File: BlackFrame.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public BlackFrame(SurfaceControl.Transaction t, Rect outer, Rect inner, int layer, DisplayContent dc, boolean forceDefaultOrientation) throws OutOfResourcesException { boolean success = false; mForceDefaultOrientation = forceDefaultOrientation; // TODO: Why do we use 4 surfaces instead of just one big one behind the screenshot? // b/68253229 mOuterRect = new Rect(outer); mInnerRect = new Rect(inner); try { if (outer.top < inner.top) { mBlackSurfaces[0] = new BlackSurface(t, layer, outer.left, outer.top, inner.right, inner.top, dc); } if (outer.left < inner.left) { mBlackSurfaces[1] = new BlackSurface(t, layer, outer.left, inner.top, inner.left, outer.bottom, dc); } if (outer.bottom > inner.bottom) { mBlackSurfaces[2] = new BlackSurface(t, layer, inner.left, inner.bottom, outer.right, outer.bottom, dc); } if (outer.right > inner.right) { mBlackSurfaces[3] = new BlackSurface(t, layer, inner.right, outer.top, outer.right, inner.bottom, dc); } success = true; } finally { if (!success) { kill(); } } }
Example #24
Source File: BlackFrame.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public void hide(SurfaceControl.Transaction t) { if (mBlackSurfaces != null) { for (int i=0; i<mBlackSurfaces.length; i++) { if (mBlackSurfaces[i] != null) { t.hide(mBlackSurfaces[i].surface); } } } }
Example #25
Source File: ScreenRotationAnimation.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public boolean setRotation(SurfaceControl.Transaction t, int rotation, long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight) { setRotation(t, rotation); if (TWO_PHASE_ANIMATION) { return startAnimation(t, maxAnimationDuration, animationScale, finalWidth, finalHeight, false, 0, 0); } // Don't start animation yet. return false; }
Example #26
Source File: SurfaceAnimator.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private SurfaceControl createAnimationLeash(SurfaceControl surface, Transaction t, int width, int height, boolean hidden) { if (DEBUG_ANIM) Slog.i(TAG, "Reparenting to leash"); final SurfaceControl.Builder builder = mAnimatable.makeAnimationLeash() .setParent(mAnimatable.getAnimationLeashParent()) .setName(surface + " - animation-leash") .setSize(width, height); final SurfaceControl leash = builder.build(); if (!hidden) { t.show(leash); } t.reparent(surface, leash.getHandle()); return leash; }
Example #27
Source File: Dimmer.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private SurfaceControl makeDimLayer() { return mHost.makeChildSurface(null) .setParent(mHost.getSurfaceControl()) .setColorLayer(true) .setName("Dim Layer for - " + mHost.getName()) .build(); }
Example #28
Source File: BlackFrame.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public void setAlpha(SurfaceControl.Transaction t, float alpha) { for (int i=0; i<mBlackSurfaces.length; i++) { if (mBlackSurfaces[i] != null) { mBlackSurfaces[i].setAlpha(t, alpha); } } }
Example #29
Source File: RecentsAnimationController.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public void startAnimation(SurfaceControl animationLeash, Transaction t, OnAnimationFinishedCallback finishCallback) { // Restore z-layering, position and stack crop until client has a chance to modify it. t.setLayer(animationLeash, mTask.getPrefixOrderIndex()); t.setPosition(animationLeash, mPosition.x, mPosition.y); mTmpRect.set(mBounds); mTmpRect.offsetTo(0, 0); t.setWindowCrop(animationLeash, mTmpRect); mCapturedLeash = animationLeash; mCapturedFinishCallback = finishCallback; }
Example #30
Source File: SurfaceAnimationRunner.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
void startAnimation(AnimationSpec a, SurfaceControl animationLeash, Transaction t, Runnable finishCallback) { synchronized (mLock) { final RunningAnimation runningAnim = new RunningAnimation(a, animationLeash, finishCallback); mPendingAnimations.put(animationLeash, runningAnim); if (!mAnimationStartDeferred) { mChoreographer.postFrameCallback(this::startAnimations); } // Some animations (e.g. move animations) require the initial transform to be applied // immediately. applyTransformation(runningAnim, t, 0 /* currentPlayTime */); } }