Java Code Examples for android.view.SurfaceControl#closeTransaction()

The following examples show how to use android.view.SurfaceControl#closeTransaction() . 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: ColorFade.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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 2
Source File: ColorFade.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: ColorFade.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: TaskSnapshotSurface.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 5
Source File: AppWindowToken.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void detachChildren() {
    SurfaceControl.openTransaction();
    for (int i = mChildren.size() - 1; i >= 0; i--) {
        final WindowState w = mChildren.get(i);
        w.mWinAnimator.detachChildren();
    }
    SurfaceControl.closeTransaction();
}
 
Example 6
Source File: Magnifier.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
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();
    }
}