summaryrefslogtreecommitdiff
path: root/graphics/java/android
diff options
context:
space:
mode:
author John Reck <jreck@google.com> 2023-10-04 01:26:58 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-10-04 01:26:58 +0000
commit7d17acd3fa5625fcc5393ee9945562ef1360f832 (patch)
tree9befc7f99a233944bcc6a04c7599585639fb504c /graphics/java/android
parenta618dc45191aa7a5ea83a4bd9208aec13e647a8c (diff)
parent992c5f8c46972aadd4713c7df54049098ea92ba7 (diff)
Merge "Add API to allow overriding a gainmap in BitmapShader" into main
Diffstat (limited to 'graphics/java/android')
-rw-r--r--graphics/java/android/graphics/BitmapShader.java40
1 files changed, 28 insertions, 12 deletions
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;
@@ -173,6 +178,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);
}