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

Commit 46c927ed authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Convert ScreenshotGraphicBuffer to ScreenshotHardwareBuffer

Bug: 150395371
Test: make && flashall

Bitmap is replacing methods that use a hidden GraphicBuffer with ones
that use the public HardwareBuffer. ScreenshotGraphicBuffer is just a
holder for GraphicBuffer and some metadata; switch it to hold a
HardwareBuffer (and rename to match).

Remove GraphicBuffer#createFromExisting, which was only called by
ScreenshotGraphicBuffer#createFromNative. Also remove JNI references to
that method, which were no longer in use.

Switch uses of GraphicBuffer that retrieve it from a
ScreenshotGraphicBuffer to HardwareBuffer.

Changes are almost entirely mechanical:
- (Screenshot)GraphicBuffer -> (Screenshot)HardwareBuffer
- GraphicBuffer#destroy -> HardwareBuffer#close
- getGraphicBuffer -> getHardwareBuffer

When creating a Snapshot in SurfaceFreezer, use the ColorSpace of the
ScreenshotHardwareBuffer.

Remove GraphicBuffer#createFromExisting. This is no longer necessary,
and although it was marked UnsupportedAppUsage, go/nonsdk-dash shows no
usage.

Change-Id: I41cb03fb65432d208820a428783de82a9f152035
parent ede50490
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Icon;
import android.hardware.HardwareBuffer;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.Build;
@@ -2006,7 +2007,7 @@ public class ActivityManager {
        private final long mId;
        // Top activity in task when snapshot was taken
        private final ComponentName mTopActivityComponent;
        private final GraphicBuffer mSnapshot;
        private final HardwareBuffer mSnapshot;
        /** Indicates whether task was in landscape or portrait */
        @Configuration.Orientation
        private final int mOrientation;
@@ -2029,7 +2030,7 @@ public class ActivityManager {
        private final ColorSpace mColorSpace;

        public TaskSnapshot(long id,
                @NonNull ComponentName topActivityComponent, GraphicBuffer snapshot,
                @NonNull ComponentName topActivityComponent, HardwareBuffer snapshot,
                @NonNull ColorSpace colorSpace, int orientation, int rotation, Point taskSize,
                Rect contentInsets, boolean isLowResolution, boolean isRealSnapshot,
                int windowingMode, int systemUiVisibility, boolean isTranslucent) {
@@ -2084,14 +2085,24 @@ public class ActivityManager {

        /**
         * @return The graphic buffer representing the screenshot.
         *
         * Note: Prefer {@link #getHardwareBuffer}, which returns the internal object. This version
         * creates a new object.
         */
        @UnsupportedAppUsage
        public GraphicBuffer getSnapshot() {
            return GraphicBuffer.createFromHardwareBuffer(mSnapshot);
        }

        /**
         * @return The hardware buffer representing the screenshot.
         */
        public HardwareBuffer getHardwareBuffer() {
            return mSnapshot;
        }

        /**
         * @return The color space of graphic buffer representing the screenshot.
         * @return The color space of hardware buffer representing the screenshot.
         */
        public ColorSpace getColorSpace() {
            return mColorSpace;
@@ -2224,7 +2235,7 @@ public class ActivityManager {
        public static final class Builder {
            private long mId;
            private ComponentName mTopActivity;
            private GraphicBuffer mSnapshot;
            private HardwareBuffer mSnapshot;
            private ColorSpace mColorSpace;
            private int mOrientation;
            private int mRotation;
@@ -2246,7 +2257,7 @@ public class ActivityManager {
                return this;
            }

            public Builder setSnapshot(GraphicBuffer buffer) {
            public Builder setSnapshot(HardwareBuffer buffer) {
                mSnapshot = buffer;
                return this;
            }
+2 −2
Original line number Diff line number Diff line
@@ -155,9 +155,9 @@ public abstract class TaskStackListener extends ITaskStackListener.Stub {
    @UnsupportedAppUsage
    public void onTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) throws RemoteException {
        if (Binder.getCallingPid() != android.os.Process.myPid()
                && snapshot != null && snapshot.getSnapshot() != null) {
                && snapshot != null && snapshot.getHardwareBuffer() != null) {
            // Preemptively clear any reference to the buffer
            snapshot.getSnapshot().destroy();
            snapshot.getHardwareBuffer().close();
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public abstract class DisplayManagerInternal {
     * @param displayId The display id to take the screenshot of.
     * @return The buffer or null if we have failed.
     */
    public abstract SurfaceControl.ScreenshotGraphicBuffer screenshot(int displayId);
    public abstract SurfaceControl.ScreenshotHardwareBuffer screenshot(int displayId);

    /**
     * Returns information about the specified logical display.
+2 −2
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import android.app.contentsuggestions.SelectionsRequest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.ColorSpace;
import android.graphics.GraphicBuffer;
import android.hardware.HardwareBuffer;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -62,7 +62,7 @@ public abstract class ContentSuggestionsService extends Service {

    private final IContentSuggestionsService mInterface = new IContentSuggestionsService.Stub() {
        @Override
        public void provideContextImage(int taskId, GraphicBuffer contextImage,
        public void provideContextImage(int taskId, HardwareBuffer contextImage,
                int colorSpaceId, Bundle imageContextRequestExtras) {
            if (imageContextRequestExtras.containsKey(ContentSuggestionsManager.EXTRA_BITMAP)
                    && contextImage != null) {
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import android.app.contentsuggestions.IClassificationsCallback;
import android.app.contentsuggestions.ISelectionsCallback;
import android.app.contentsuggestions.ClassificationsRequest;
import android.app.contentsuggestions.SelectionsRequest;
import android.graphics.GraphicBuffer;
import android.hardware.HardwareBuffer;
import android.os.Bundle;

/**
@@ -31,7 +31,7 @@ import android.os.Bundle;
oneway interface IContentSuggestionsService {
    void provideContextImage(
            int taskId,
            in GraphicBuffer contextImage,
            in HardwareBuffer contextImage,
            int colorSpaceId,
            in Bundle imageContextRequestExtras);
    void suggestContentSelections(
Loading