Java Code Examples for android.view.Surface#copyFrom()

The following examples show how to use android.view.Surface#copyFrom() . 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 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 2
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 3
Source File: AppWindowThumbnail.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
AppWindowThumbnail(Transaction t, AppWindowToken appToken, GraphicBuffer thumbnailHeader) {
    mAppToken = appToken;
    mSurfaceAnimator = new SurfaceAnimator(this, this::onAnimationFinished, appToken.mService);
    mWidth = thumbnailHeader.getWidth();
    mHeight = thumbnailHeader.getHeight();

    // Create a new surface for the thumbnail
    WindowState window = appToken.findMainWindow();

    // TODO: This should be attached as a child to the app token, once the thumbnail animations
    // use relative coordinates. Once we start animating task we can also consider attaching
    // this to the task.
    mSurfaceControl = appToken.makeSurface()
            .setName("thumbnail anim: " + appToken.toString())
            .setSize(mWidth, mHeight)
            .setFormat(PixelFormat.TRANSLUCENT)
            .setMetadata(appToken.windowType,
                    window != null ? window.mOwnerUid : Binder.getCallingUid())
            .build();

    if (SHOW_TRANSACTIONS) {
        Slog.i(TAG, "  THUMBNAIL " + mSurfaceControl + ": CREATE");
    }

    // Transfer the thumbnail to the surface
    Surface drawSurface = new Surface();
    drawSurface.copyFrom(mSurfaceControl);
    drawSurface.attachAndQueueBuffer(thumbnailHeader);
    drawSurface.release();
    t.show(mSurfaceControl);

    // We parent the thumbnail to the task, and just place it on top of anything else in the
    // task.
    t.setLayer(mSurfaceControl, Integer.MAX_VALUE);
}
 
Example 4
Source File: WindowSurfaceController.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
void getSurface(Surface outSurface) {
    outSurface.copyFrom(mSurfaceControl);
}
 
Example 5
Source File: Magnifier.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
InternalPopupWindow(final Context context, final Display display,
        final Surface parentSurface,
        final int width, final int height, final float elevation, final float cornerRadius,
        final Handler handler, final Object lock, final Callback callback) {
    mDisplay = display;
    mLock = lock;
    mCallback = callback;

    mContentWidth = width;
    mContentHeight = height;
    mOffsetX = (int) (0.1f * width);
    mOffsetY = (int) (0.1f * height);
    // Setup the surface we will use for drawing the content and shadow.
    mSurfaceWidth = mContentWidth + 2 * mOffsetX;
    mSurfaceHeight = mContentHeight + 2 * mOffsetY;
    mSurfaceSession = new SurfaceSession(parentSurface);
    mSurfaceControl = new SurfaceControl.Builder(mSurfaceSession)
            .setFormat(PixelFormat.TRANSLUCENT)
            .setSize(mSurfaceWidth, mSurfaceHeight)
            .setName("magnifier surface")
            .setFlags(SurfaceControl.HIDDEN)
            .build();
    mSurface = new Surface();
    mSurface.copyFrom(mSurfaceControl);

    // Setup the RenderNode tree. The root has only one child, which contains the bitmap.
    mRenderer = new ThreadedRenderer.SimpleRenderer(
            context,
            "magnifier renderer",
            mSurface
    );
    mBitmapRenderNode = createRenderNodeForBitmap(
            "magnifier content",
            elevation,
            cornerRadius
    );

    final DisplayListCanvas canvas = mRenderer.getRootNode().start(width, height);
    try {
        canvas.insertReorderBarrier();
        canvas.drawRenderNode(mBitmapRenderNode);
        canvas.insertInorderBarrier();
    } finally {
        mRenderer.getRootNode().end(canvas);
    }

    // Initialize the update job and the handler where this will be post'd.
    mHandler = handler;
    mMagnifierUpdater = this::doDraw;
    mFrameDrawScheduled = false;
}