Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7432f183 authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

App transitions/thumbnails: Switch to HardwareBuffer

Bug: 148155907
Bug: 150395371
Test: go/wm-smoke

These previously used a GraphicBuffer created from a HARDWARE Bitmap to
parcel the Bitmap. As part of moving UI Rendering into a mainline
module, which will not include/expose GraphicBuffer,
Bitmap#createGraphicBufferHandle is being replaced by
Bitmap#getHardwareBuffer. Switch over to the now public API.

Change-Id: Id714a48a10fd03a03faa371e206e0c478ae1a4b7
parent a72a7ffe
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -31,8 +31,8 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.GraphicBuffer;
import android.graphics.Rect;
import android.hardware.HardwareBuffer;
import android.os.Bundle;
import android.os.Handler;
import android.os.IRemoteCallback;
@@ -942,8 +942,8 @@ public class ActivityOptions {
            case ANIM_THUMBNAIL_SCALE_DOWN:
            case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
            case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
                // Unpackage the GraphicBuffer from the parceled thumbnail
                final GraphicBuffer buffer = opts.getParcelable(KEY_ANIM_THUMBNAIL);
                // Unpackage the HardwareBuffer from the parceled thumbnail
                final HardwareBuffer buffer = opts.getParcelable(KEY_ANIM_THUMBNAIL);
                if (buffer != null) {
                    mThumbnail = Bitmap.wrapHardwareBuffer(buffer, null);
                }
@@ -1052,12 +1052,12 @@ public class ActivityOptions {

    /**
     * The thumbnail is copied into a hardware bitmap when it is bundled and sent to the system, so
     * it should always be backed by a GraphicBuffer on the other end.
     * it should always be backed by a HardwareBuffer on the other end.
     *
     * @hide
     */
    public GraphicBuffer getThumbnail() {
        return mThumbnail != null ? mThumbnail.createGraphicBufferHandle() : null;
    public HardwareBuffer getThumbnail() {
        return mThumbnail != null ? mThumbnail.getHardwareBuffer() : null;
    }

    /** @hide */
@@ -1508,11 +1508,11 @@ public class ActivityOptions {
            case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
            case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
                // Once we parcel the thumbnail for transfering over to the system, create a copy of
                // the bitmap to a hardware bitmap and pass through the GraphicBuffer
                // the bitmap to a hardware bitmap and pass through the HardwareBuffer
                if (mThumbnail != null) {
                    final Bitmap hwBitmap = mThumbnail.copy(Config.HARDWARE, false /* isMutable */);
                    if (hwBitmap != null) {
                        b.putParcelable(KEY_ANIM_THUMBNAIL, hwBitmap.createGraphicBufferHandle());
                        b.putParcelable(KEY_ANIM_THUMBNAIL, hwBitmap.getHardwareBuffer());
                    } else {
                        Slog.w(TAG, "Failed to copy thumbnail");
                    }
+3 −3
Original line number Diff line number Diff line
package android.view;

import android.compat.annotation.UnsupportedAppUsage;
import android.graphics.GraphicBuffer;
import android.graphics.Rect;
import android.hardware.HardwareBuffer;
import android.os.Parcel;
import android.os.Parcelable;

@@ -16,11 +16,11 @@ import android.os.Parcelable;
 */
public class AppTransitionAnimationSpec implements Parcelable {
    public final int taskId;
    public final GraphicBuffer buffer;
    public final HardwareBuffer buffer;
    public final Rect rect;

    @UnsupportedAppUsage
    public AppTransitionAnimationSpec(int taskId, GraphicBuffer buffer, Rect rect) {
    public AppTransitionAnimationSpec(int taskId, HardwareBuffer buffer, Rect rect) {
        this.taskId = taskId;
        this.rect = rect;
        this.buffer = buffer;
+9 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.graphics.RecordingCanvas;
import android.graphics.Rect;
import android.graphics.RenderNode;
import android.graphics.SurfaceTexture;
import android.hardware.HardwareBuffer;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
@@ -751,6 +752,14 @@ public class Surface implements Parcelable {
        }
    }

    /**
     * @hide
     */
    public void attachAndQueueBufferWithColorSpace(HardwareBuffer buffer, ColorSpace colorSpace) {
        attachAndQueueBufferWithColorSpace(GraphicBuffer.createFromHardwareBuffer(buffer),
                colorSpace);
    }

    /**
     * Deprecated, use attachAndQueueBufferWithColorSpace instead.
     * Transfer ownership of buffer and present it on the Surface.
+1 −1
Original line number Diff line number Diff line
@@ -36,6 +36,6 @@ public class AppTransitionAnimationSpecCompat {

    public AppTransitionAnimationSpec toAppTransitionAnimationSpec() {
        return new AppTransitionAnimationSpec(mTaskId,
                mBuffer != null ? mBuffer.createGraphicBufferHandle() : null, mRect);
                mBuffer != null ? mBuffer.getHardwareBuffer() : null, mRect);
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -251,10 +251,10 @@ import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.GraphicBuffer;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.HardwareBuffer;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
@@ -3722,7 +3722,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            case ANIM_THUMBNAIL_SCALE_UP:
            case ANIM_THUMBNAIL_SCALE_DOWN:
                final boolean scaleUp = (animationType == ANIM_THUMBNAIL_SCALE_UP);
                final GraphicBuffer buffer = pendingOptions.getThumbnail();
                final HardwareBuffer buffer = pendingOptions.getThumbnail();
                displayContent.mAppTransition.overridePendingAppTransitionThumb(buffer,
                        pendingOptions.getStartX(), pendingOptions.getStartY(),
                        pendingOptions.getOnAnimationStartListener(),
@@ -5898,7 +5898,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (!isAnimating(PARENTS)) {
            return;
        }
        final GraphicBuffer thumbnailHeader =
        final HardwareBuffer thumbnailHeader =
                getDisplayContent().mAppTransition.getAppTransitionThumbnailHeader(task);
        if (thumbnailHeader == null) {
            ProtoLog.d(WM_DEBUG_APP_TRANSITIONS, "No thumbnail header bitmap for: %s", task);
@@ -5929,7 +5929,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        final int thumbnailDrawableRes = task.mUserId == mWmService.mCurrentUserId
                ? R.drawable.ic_account_circle
                : R.drawable.ic_corp_badge;
        final GraphicBuffer thumbnail =
        final HardwareBuffer thumbnail =
                getDisplayContent().mAppTransition
                        .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
        if (thumbnail == null) {
@@ -5944,7 +5944,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        mThumbnail.startAnimation(transaction, animation, new Point(frame.left, frame.top));
    }

    private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
    private Animation loadThumbnailAnimation(HardwareBuffer thumbnailHeader) {
        final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();

        // If this is a multi-window scenario, we use the windows frame as
Loading