From 992c5f8c46972aadd4713c7df54049098ea92ba7 Mon Sep 17 00:00:00 2001 From: John Reck Date: Thu, 21 Sep 2023 09:12:17 -0400 Subject: Add API to allow overriding a gainmap in BitmapShader Fixes: 296482289 Test: atest android.uirendering.cts.testclasses.GainmapTests -- --template:map preparers=template/preparers/feature-flags --flag-value core_graphics/com.android.graphics.hwui.flags.gainmap_animations=true Change-Id: I1984a625ff3740e8fffd4d1ffc6f16132dfc6788 --- graphics/java/android/graphics/BitmapShader.java | 40 +++++++++++++++++------- 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'graphics/java/android') diff --git a/graphics/java/android/graphics/BitmapShader.java b/graphics/java/android/graphics/BitmapShader.java index 5c065775eea2..dcfff62459ab 100644 --- a/graphics/java/android/graphics/BitmapShader.java +++ b/graphics/java/android/graphics/BitmapShader.java @@ -16,9 +16,13 @@ package android.graphics; +import android.annotation.FlaggedApi; import android.annotation.IntDef; import android.annotation.IntRange; import android.annotation.NonNull; +import android.annotation.Nullable; + +import com.android.graphics.hwui.flags.Flags; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -32,6 +36,7 @@ public class BitmapShader extends Shader { * Prevent garbage collection. */ /*package*/ Bitmap mBitmap; + private Gainmap mOverrideGainmap; private int mTileX; private int mTileY; @@ -172,6 +177,24 @@ public class BitmapShader extends Shader { } } + /** + * Draws the BitmapShader with a copy of the given gainmap instead of the gainmap on the Bitmap + * the shader was constructed from + * + * @param overrideGainmap The gainmap to draw instead, null to use any gainmap on the Bitmap + */ + @FlaggedApi(Flags.FLAG_GAINMAP_ANIMATIONS) + public void setOverrideGainmap(@Nullable Gainmap overrideGainmap) { + if (!Flags.gainmapAnimations()) throw new IllegalStateException("API not available"); + + if (overrideGainmap == null) { + mOverrideGainmap = null; + } else { + mOverrideGainmap = new Gainmap(overrideGainmap, overrideGainmap.getGainmapContents()); + } + discardNativeInstance(); + } + /** * Returns the current max anisotropic filtering value configured by * {@link #setFilterMode(int)}. If {@link #setFilterMode(int)} is invoked this returns zero. @@ -199,14 +222,9 @@ public class BitmapShader extends Shader { mIsDirectSampled = mRequestDirectSampling; mRequestDirectSampling = false; - - if (mMaxAniso > 0) { - return nativeCreateWithMaxAniso(nativeMatrix, mBitmap.getNativeInstance(), mTileX, - mTileY, mMaxAniso, mIsDirectSampled); - } else { - return nativeCreate(nativeMatrix, mBitmap.getNativeInstance(), mTileX, mTileY, - enableLinearFilter, mIsDirectSampled); - } + return nativeCreate(nativeMatrix, mBitmap.getNativeInstance(), mTileX, + mTileY, mMaxAniso, enableLinearFilter, mIsDirectSampled, + mOverrideGainmap != null ? mOverrideGainmap.mNativePtr : 0); } /** @hide */ @@ -217,9 +235,7 @@ public class BitmapShader extends Shader { } private static native long nativeCreate(long nativeMatrix, long bitmapHandle, - int shaderTileModeX, int shaderTileModeY, boolean filter, boolean isDirectSampled); - - private static native long nativeCreateWithMaxAniso(long nativeMatrix, long bitmapHandle, - int shaderTileModeX, int shaderTileModeY, int maxAniso, boolean isDirectSampled); + int shaderTileModeX, int shaderTileModeY, int maxAniso, boolean filter, + boolean isDirectSampled, long overrideGainmapHandle); } -- cgit v1.2.3-59-g8ed1b