下面列出了android.view.SurfaceControl#Transaction ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
try (final SurfaceControl.Transaction transaction = new SurfaceControl.Transaction()) {
transaction.setPosition(
mSurfaceControl,
(float) animation.getAnimatedValue(ANIMATED_PROPERTY_X),
(float) animation.getAnimatedValue(ANIMATED_PROPERTY_Y));
transaction.setAlpha(
mSurfaceControl,
(float) animation.getAnimatedValue(ANIMATED_PROPERTY_ALPHA));
transaction.setMatrix(
mSurfaceControl,
(float) animation.getAnimatedValue(ANIMATED_PROPERTY_SCALE), 0,
0, (float) animation.getAnimatedValue(ANIMATED_PROPERTY_SCALE));
transaction.apply();
}
}
@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();
}
}
private void performTraversalLocked(SurfaceControl.Transaction t) {
// Clear all viewports before configuring displays so that we can keep
// track of which ones we have configured.
clearViewportsLocked();
// Configure each display device.
final int count = mDisplayDevices.size();
for (int i = 0; i < count; i++) {
DisplayDevice device = mDisplayDevices.get(i);
configureDisplayLocked(t, device);
device.performTraversalLocked(t);
}
// Tell the input system about these new viewports.
if (mInputManagerInternal != null) {
mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT);
}
}
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);
}
}
}
@Override
public void performTraversalLocked(SurfaceControl.Transaction t) {
if ((mPendingChanges & PENDING_RESIZE) != 0) {
t.setDisplaySize(getDisplayTokenLocked(), mWidth, mHeight);
}
if ((mPendingChanges & PENDING_SURFACE_CHANGE) != 0) {
setSurfaceLocked(t, mSurface);
}
mPendingChanges = 0;
}
private void hideSurface(SurfaceControl.Transaction transaction) {
if (mSurfaceControl == null) {
return;
}
setShown(false);
try {
transaction.hide(mSurfaceControl);
} catch (RuntimeException e) {
Slog.w(TAG, "Exception hiding surface in " + this);
}
}
public void clearMatrix(SurfaceControl.Transaction t) {
for (int i=0; i<mBlackSurfaces.length; i++) {
if (mBlackSurfaces[i] != null) {
mBlackSurfaces[i].clearMatrix(t);
}
}
}
/**
* Finish a dim started by dimAbove in the case there was no call to dimAbove.
*
* @param t A Transaction in which to finish the dim.
*/
void stopDim(SurfaceControl.Transaction t) {
if (mDimState != null) {
t.hide(mDimState.mDimLayer);
mDimState.isVisible = false;
mDimState.mDontReset = false;
}
}
private void startDimEnter(WindowContainer container, SurfaceAnimator animator,
SurfaceControl.Transaction t) {
startAnim(container, animator, t, 0 /* startAlpha */, 1 /* endAlpha */);
}
void updateSurfaces(SurfaceControl.Transaction t) {
if (!mStarted) {
return;
}
if (mSurfaceControl != null) {
if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
t.hide(mSurfaceControl);
}
}
if (mCustomBlackFrame != null) {
if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
mCustomBlackFrame.hide(t);
} else {
mCustomBlackFrame.setMatrix(t, mFrameTransformation.getMatrix());
}
}
if (mExitingBlackFrame != null) {
if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding exiting frame");
mExitingBlackFrame.hide(t);
} else {
mExitFrameFinalMatrix.setConcat(mExitTransformation.getMatrix(), mFrameInitialMatrix);
mExitingBlackFrame.setMatrix(t, mExitFrameFinalMatrix);
if (mForceDefaultOrientation) {
mExitingBlackFrame.setAlpha(t, mExitTransformation.getAlpha());
}
}
}
if (mEnteringBlackFrame != null) {
if (!mMoreStartEnter && !mMoreFinishEnter && !mMoreRotateEnter) {
if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding entering frame");
mEnteringBlackFrame.hide(t);
} else {
mEnteringBlackFrame.setMatrix(t, mEnterTransformation.getMatrix());
}
}
setSnapshotTransform(t, mSnapshotFinalMatrix, mExitTransformation.getAlpha());
}
@Override
public void onAnimationLeashCreated(SurfaceControl.Transaction t, SurfaceControl leash) {
}
@Override
public SurfaceControl.Transaction getPendingTransaction() {
return mHost.getPendingTransaction();
}
public void applySurfaceChanges(SurfaceControl.Transaction t) {
mTop.applySurfaceChanges(t);
mLeft.applySurfaceChanges(t);
mBottom.applySurfaceChanges(t);
mRight.applySurfaceChanges(t);
}
void setAlpha(SurfaceControl.Transaction t, float alpha) {
t.setAlpha(surface, alpha);
}
void startAnimation(SurfaceAnimator surfaceAnimator, SurfaceControl.Transaction t,
AnimationAdapter anim, boolean hidden);
private void startAnim(WindowContainer container, SurfaceAnimator animator,
SurfaceControl.Transaction t, float startAlpha, float endAlpha) {
mSurfaceAnimatorStarter.startAnimation(animator, t, new LocalAnimationAdapter(
new AlphaAnimationSpec(startAlpha, endAlpha, getDimDuration(container)),
mHost.mService.mSurfaceAnimationRunner), false /* hidden */);
}
/**
* Gives the display device a chance to update its properties while in a transaction.
*/
public void performTraversalLocked(SurfaceControl.Transaction t) {
}
/**
* Called by the window manager to perform traversals while holding a
* surface flinger transaction.
*/
public abstract void performTraversal(SurfaceControl.Transaction t);
/**
* Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
* that the IME target is one of the docked applications. We'd like the docked divider to be
* above both of the applications, and we'd like the IME to be above the docked divider.
* However we need child windows of the applications to be above the IME (Text drag handles).
* This is a non-strictly hierarcical layering and we need to break out of the Z ordering
* somehow. We do this by relatively ordering children of the target to the IME in cooperation
* with {@link #WindowState#assignLayer}
*/
void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1);
}