android.view.SurfaceControl#closeTransaction ( )源码实例Demo

下面列出了android.view.SurfaceControl#closeTransaction ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: ColorFade.java
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;
    }
}
 
源代码2 项目: android_9.0.0_r45   文件: ColorFade.java
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.Builder(mSurfaceSession)
                        .setName("ColorFade")
                        .setSize(mDisplayWidth, mDisplayHeight)
                        .setFlags(flags)
                        .build();
            } 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;
}
 
源代码3 项目: android_9.0.0_r45   文件: ColorFade.java
private boolean showSurface(float alpha) {
    if (!mSurfaceVisible || mSurfaceAlpha != alpha) {
        SurfaceControl.openTransaction();
        try {
            mSurfaceControl.setLayer(COLOR_FADE_LAYER);
            mSurfaceControl.setAlpha(alpha);
            mSurfaceControl.show();
        } finally {
            SurfaceControl.closeTransaction();
        }
        mSurfaceVisible = true;
        mSurfaceAlpha = alpha;
    }
    return true;
}
 
源代码4 项目: android_9.0.0_r45   文件: TaskSnapshotSurface.java
private void drawSizeMismatchSnapshot(GraphicBuffer buffer) {
    final SurfaceSession session = new SurfaceSession(mSurface);

    // Keep a reference to it such that it doesn't get destroyed when finalized.
    mChildSurfaceControl = new SurfaceControl.Builder(session)
            .setName(mTitle + " - task-snapshot-surface")
            .setSize(buffer.getWidth(), buffer.getHeight())
            .setFormat(buffer.getFormat())
            .build();
    Surface surface = new Surface();
    surface.copyFrom(mChildSurfaceControl);

    // Clip off ugly navigation bar.
    final Rect crop = calculateSnapshotCrop();
    final Rect frame = calculateSnapshotFrame(crop);
    SurfaceControl.openTransaction();
    try {
        // We can just show the surface here as it will still be hidden as the parent is
        // still hidden.
        mChildSurfaceControl.show();
        mChildSurfaceControl.setWindowCrop(crop);
        mChildSurfaceControl.setPosition(frame.left, frame.top);

        // Scale the mismatch dimensions to fill the task bounds
        final float scale = 1 / mSnapshot.getScale();
        mChildSurfaceControl.setMatrix(scale, 0, 0, scale);
    } finally {
        SurfaceControl.closeTransaction();
    }
    surface.attachAndQueueBuffer(buffer);
    surface.release();

    final Canvas c = mSurface.lockCanvas(null);
    drawBackgroundAndBars(c, frame);
    mSurface.unlockCanvasAndPost(c);
    mSurface.release();
}
 
源代码5 项目: android_9.0.0_r45   文件: AppWindowToken.java
void detachChildren() {
    SurfaceControl.openTransaction();
    for (int i = mChildren.size() - 1; i >= 0; i--) {
        final WindowState w = mChildren.get(i);
        w.mWinAnimator.detachChildren();
    }
    SurfaceControl.closeTransaction();
}
 
源代码6 项目: android_9.0.0_r45   文件: Magnifier.java
private void doDraw() {
    final ThreadedRenderer.FrameDrawingCallback callback;

    // Draw the current bitmap to the surface, and prepare the callback which updates the
    // surface position. These have to be in the same synchronized block, in order to
    // guarantee the consistency between the bitmap content and the surface position.
    synchronized (mLock) {
        if (!mSurface.isValid()) {
            // Probably #destroy() was called for the current instance, so we skip the draw.
            return;
        }

        final DisplayListCanvas canvas =
                mBitmapRenderNode.start(mContentWidth, mContentHeight);
        try {
            canvas.drawColor(Color.WHITE);

            final Rect srcRect = new Rect(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
            final Rect dstRect = new Rect(0, 0, mContentWidth, mContentHeight);
            final Paint paint = new Paint();
            paint.setFilterBitmap(true);
            paint.setAlpha(CONTENT_BITMAP_ALPHA);
            canvas.drawBitmap(mBitmap, srcRect, dstRect, paint);
        } finally {
            mBitmapRenderNode.end(canvas);
        }

        if (mPendingWindowPositionUpdate || mFirstDraw) {
            // If the window has to be shown or moved, defer this until the next draw.
            final boolean firstDraw = mFirstDraw;
            mFirstDraw = false;
            final boolean updateWindowPosition = mPendingWindowPositionUpdate;
            mPendingWindowPositionUpdate = false;
            final int pendingX = mWindowPositionX;
            final int pendingY = mWindowPositionY;

            callback = frame -> {
                synchronized (mDestroyLock) {
                    if (!mSurface.isValid()) {
                        return;
                    }
                    synchronized (mLock) {
                        mRenderer.setLightCenter(mDisplay, pendingX, pendingY);
                        // Show or move the window at the content draw frame.
                        SurfaceControl.openTransaction();
                        mSurfaceControl.deferTransactionUntil(mSurface, frame);
                        if (updateWindowPosition) {
                            mSurfaceControl.setPosition(pendingX, pendingY);
                        }
                        if (firstDraw) {
                            mSurfaceControl.setLayer(SURFACE_Z);
                            mSurfaceControl.show();
                        }
                        SurfaceControl.closeTransaction();
                    }
                }
            };
        } else {
            callback = null;
        }

        mLastDrawContentPositionX = mWindowPositionX + mOffsetX;
        mLastDrawContentPositionY = mWindowPositionY + mOffsetY;
        mFrameDrawScheduled = false;
    }

    mRenderer.draw(callback);
    if (mCallback != null) {
        mCallback.onOperationComplete();
    }
}