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

Commit 3e2d7b7f authored by Leon Scroggins III's avatar Leon Scroggins III Committed by Leon Scroggins
Browse files

Pass ColorSpace along with HardwareBuffers

Bug: 130148101
Bug: 120904891
Test: I3bdb6a7edbab4b9b8f13d4597e5987e6db6fe928

Bitmap#wrapHardwareBuffer defaults to using the SRGB ColorSpace (i.e. if
null is supplied), but it's possible that where the HardwareBuffer was
originally used, it was associated with a different ColorSpace. Update
clients of this API to pass that ColorSpace.

Pass the ColorSpace's ID. This results in only supporting Named
ColorSpaces, which matches some of our other ColorSpace support, and
should be enough for most use cases.

Change-Id: I02460f079ed467199f368b4a4fd7708d6fa5433a
parent 18184f9c
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.app;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.ColorSpace;
import android.graphics.GraphicBuffer;
import android.graphics.Matrix;
import android.graphics.RectF;
@@ -49,6 +50,7 @@ public abstract class SharedElementCallback {
    private static final String BUNDLE_SNAPSHOT_BITMAP = "sharedElement:snapshot:bitmap";
    private static final String BUNDLE_SNAPSHOT_GRAPHIC_BUFFER =
            "sharedElement:snapshot:graphicBuffer";
    private static final String BUNDLE_SNAPSHOT_COLOR_SPACE = "sharedElement:snapshot:colorSpace";
    private static final String BUNDLE_SNAPSHOT_IMAGE_SCALETYPE = "sharedElement:snapshot:imageScaleType";
    private static final String BUNDLE_SNAPSHOT_IMAGE_MATRIX = "sharedElement:snapshot:imageMatrix";

@@ -186,6 +188,10 @@ public abstract class SharedElementCallback {
                    } else {
                        GraphicBuffer graphicBuffer = bitmap.createGraphicBufferHandle();
                        bundle.putParcelable(BUNDLE_SNAPSHOT_GRAPHIC_BUFFER, graphicBuffer);
                        ColorSpace cs = bitmap.getColorSpace();
                        if (cs != null) {
                            bundle.putInt(BUNDLE_SNAPSHOT_COLOR_SPACE, cs.getId());
                        }
                    }
                    bundle.putString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE,
                            imageView.getScaleType().toString());
@@ -235,8 +241,13 @@ public abstract class SharedElementCallback {
                return null;
            }
            if (bitmap == null) {
                ColorSpace colorSpace = null;
                int colorSpaceId = bundle.getInt(BUNDLE_SNAPSHOT_COLOR_SPACE, 0);
                if (colorSpaceId >= 0 && colorSpaceId < ColorSpace.Named.values().length) {
                    colorSpace = ColorSpace.get(ColorSpace.Named.values()[colorSpaceId]);
                }
                bitmap = Bitmap.wrapHardwareBuffer(HardwareBuffer.createFromGraphicBuffer(buffer),
                                                   null);
                                                   colorSpace);
            }
            ImageView imageView = new ImageView(context);
            view = imageView;
+7 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.app.contentsuggestions.ISelectionsCallback;
import android.app.contentsuggestions.SelectionsRequest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.ColorSpace;
import android.graphics.GraphicBuffer;
import android.os.Bundle;
import android.os.Handler;
@@ -62,11 +63,15 @@ public abstract class ContentSuggestionsService extends Service {
    private final IContentSuggestionsService mInterface = new IContentSuggestionsService.Stub() {
        @Override
        public void provideContextImage(int taskId, GraphicBuffer contextImage,
                Bundle imageContextRequestExtras) {
                int colorSpaceId, Bundle imageContextRequestExtras) {

            Bitmap wrappedBuffer = null;
            if (contextImage != null) {
                wrappedBuffer = Bitmap.wrapHardwareBuffer(contextImage, null);
                ColorSpace colorSpace = null;
                if (colorSpaceId >= 0 && colorSpaceId < ColorSpace.Named.values().length) {
                    colorSpace = ColorSpace.get(ColorSpace.Named.values()[colorSpaceId]);
                }
                wrappedBuffer = Bitmap.wrapHardwareBuffer(contextImage, colorSpace);
            }

            mHandler.sendMessage(
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ oneway interface IContentSuggestionsService {
    void provideContextImage(
            int taskId,
            in GraphicBuffer contextImage,
            int colorSpaceId,
            in Bundle imageContextRequestExtras);
    void suggestContentSelections(
            in SelectionsRequest request,
+5 −1
Original line number Diff line number Diff line
@@ -2197,8 +2197,12 @@ public final class Bitmap implements Parcelable {
    }

    /**
     *
     * @return {@link GraphicBuffer} which is internally used by hardware bitmap
     *
     * Note: the GraphicBuffer does *not* have an associated {@link ColorSpace}.
     * To render this object the same as its rendered with this Bitmap, you
     * should also call {@link getColorSpace}.
     *
     * @hide
     */
    @UnsupportedAppUsage
+8 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.app.contentsuggestions.SelectionsRequest;
import android.content.ComponentName;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.graphics.ColorSpace;
import android.graphics.GraphicBuffer;
import android.os.Bundle;
import android.os.RemoteException;
@@ -99,11 +100,17 @@ public final class ContentSuggestionsPerUserService extends
            ActivityManager.TaskSnapshot snapshot =
                    mActivityTaskManagerInternal.getTaskSnapshot(taskId, false);
            GraphicBuffer snapshotBuffer = null;
            int colorSpaceId = 0;
            if (snapshot != null) {
                snapshotBuffer = snapshot.getSnapshot();
                ColorSpace colorSpace = snapshot.getColorSpace();
                if (colorSpace != null) {
                    colorSpaceId = colorSpace.getId();
                }
            }

            service.provideContextImage(taskId, snapshotBuffer, imageContextRequestExtras);
            service.provideContextImage(taskId, snapshotBuffer, colorSpaceId,
                    imageContextRequestExtras);
        }
    }

Loading