/**
 * Copy the Surface from the SurfaceControl or the blast adapter.
 *
 * @param surfaceControlCreated true if we created the SurfaceControl and need to update our
 *                              Surface if needed.
 * @param bufferSizeChanged true if the BufferSize has changed and we need to recreate the
 *                          Surface for compatibility reasons.
 */
private void copySurface(boolean surfaceControlCreated, boolean bufferSizeChanged) {
    if (surfaceControlCreated) {
        if (mUseBlastAdapter) {
            mSurface.copyFrom(mBlastBufferQueue);
        } else {
            mSurface.copyFrom(mSurfaceControl);
        }
    }

    if (bufferSizeChanged && getContext().getApplicationInfo().targetSdkVersion
            < Build.VERSION_CODES.O) {
        // Some legacy applications use the underlying native {@link Surface} object
        // as a key to whether anything has changed. In these cases, updates to the
        // existing {@link Surface} will be ignored when the size changes.
        // Therefore, we must explicitly recreate the {@link Surface} in these
        // cases.
        if (mUseBlastAdapter) {
            if (mBlastBufferQueue != null) {
                mSurface.transferFrom(mBlastBufferQueue.createSurfaceWithHandle());
            }
        } else {
            mSurface.createFrom(mSurfaceControl);
        }
    }
}