diff options
author | Leon Scroggins III <scroggo@google.com> | 2019-04-15 13:52:19 -0400 |
---|---|---|
committer | Leon Scroggins <scroggo@google.com> | 2019-04-25 16:48:08 +0000 |
commit | 3e2d7b7fe053d61c46525bb12c1789897946e688 (patch) | |
tree | be60e7660619db159c119ffbdff35e1acddf2c6a | |
parent | 18184f9c86565f27efa74b317ab464dee1c6b94c (diff) |
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
6 files changed, 35 insertions, 7 deletions
diff --git a/core/java/android/app/SharedElementCallback.java b/core/java/android/app/SharedElementCallback.java index 9fabfde5d06f..0287564bcc56 100644 --- a/core/java/android/app/SharedElementCallback.java +++ b/core/java/android/app/SharedElementCallback.java @@ -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; diff --git a/core/java/android/service/contentsuggestions/ContentSuggestionsService.java b/core/java/android/service/contentsuggestions/ContentSuggestionsService.java index 55e61410b9e2..516d33673012 100644 --- a/core/java/android/service/contentsuggestions/ContentSuggestionsService.java +++ b/core/java/android/service/contentsuggestions/ContentSuggestionsService.java @@ -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( diff --git a/core/java/android/service/contentsuggestions/IContentSuggestionsService.aidl b/core/java/android/service/contentsuggestions/IContentSuggestionsService.aidl index 1926478322c8..6240e00794bd 100644 --- a/core/java/android/service/contentsuggestions/IContentSuggestionsService.aidl +++ b/core/java/android/service/contentsuggestions/IContentSuggestionsService.aidl @@ -32,6 +32,7 @@ oneway interface IContentSuggestionsService { void provideContextImage( int taskId, in GraphicBuffer contextImage, + int colorSpaceId, in Bundle imageContextRequestExtras); void suggestContentSelections( in SelectionsRequest request, diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 07f81c18e1ca..44710178da5e 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -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 diff --git a/services/contentsuggestions/java/com/android/server/contentsuggestions/ContentSuggestionsPerUserService.java b/services/contentsuggestions/java/com/android/server/contentsuggestions/ContentSuggestionsPerUserService.java index 9b70272ed952..770931179c5e 100644 --- a/services/contentsuggestions/java/com/android/server/contentsuggestions/ContentSuggestionsPerUserService.java +++ b/services/contentsuggestions/java/com/android/server/contentsuggestions/ContentSuggestionsPerUserService.java @@ -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); } } diff --git a/services/contentsuggestions/java/com/android/server/contentsuggestions/RemoteContentSuggestionsService.java b/services/contentsuggestions/java/com/android/server/contentsuggestions/RemoteContentSuggestionsService.java index 4b36352bac51..a8b7b814a9ba 100644 --- a/services/contentsuggestions/java/com/android/server/contentsuggestions/RemoteContentSuggestionsService.java +++ b/services/contentsuggestions/java/com/android/server/contentsuggestions/RemoteContentSuggestionsService.java @@ -68,9 +68,9 @@ public class RemoteContentSuggestionsService extends } void provideContextImage(int taskId, @Nullable GraphicBuffer contextImage, - @NonNull Bundle imageContextRequestExtras) { + int colorSpaceId, @NonNull Bundle imageContextRequestExtras) { scheduleAsyncRequest((s) -> s.provideContextImage(taskId, contextImage, - imageContextRequestExtras)); + colorSpaceId, imageContextRequestExtras)); } void suggestContentSelections( |