Added support for BitmapShader anisotropic filtering
Relnote: "Created new BitmapShader constructor that
enables support for anisotropic filtering."
Bug: 267687306
Test: Added tests to BitmapShaderTest
Change-Id: Ie6e5551f3ae6140dc3afb2d65967b5a6bc08523c
diff --git a/libs/hwui/jni/Shader.cpp b/libs/hwui/jni/Shader.cpp
index fa8e2e7..8a0db1c 100644
--- a/libs/hwui/jni/Shader.cpp
+++ b/libs/hwui/jni/Shader.cpp
@@ -71,11 +71,9 @@
return static_cast<jlong>(reinterpret_cast<uintptr_t>(&Shader_safeUnref));
}
-///////////////////////////////////////////////////////////////////////////////////////////////
-
-static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jlong matrixPtr, jlong bitmapHandle,
- jint tileModeX, jint tileModeY, bool filter,
- bool isDirectSampled) {
+static jlong createBitmapShaderHelper(JNIEnv* env, jobject o, jlong matrixPtr, jlong bitmapHandle,
+ jint tileModeX, jint tileModeY, bool isDirectSampled,
+ const SkSamplingOptions& sampling) {
const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
sk_sp<SkImage> image;
if (bitmapHandle) {
@@ -88,8 +86,7 @@
SkBitmap bitmap;
image = SkMakeImageFromRasterBitmap(bitmap, kNever_SkCopyPixelsMode);
}
- SkSamplingOptions sampling(filter ? SkFilterMode::kLinear : SkFilterMode::kNearest,
- SkMipmapMode::kNone);
+
sk_sp<SkShader> shader;
if (isDirectSampled) {
shader = image->makeRawShader((SkTileMode)tileModeX, (SkTileMode)tileModeY, sampling);
@@ -107,6 +104,26 @@
///////////////////////////////////////////////////////////////////////////////////////////////
+static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jlong matrixPtr, jlong bitmapHandle,
+ jint tileModeX, jint tileModeY, bool filter,
+ bool isDirectSampled) {
+ SkSamplingOptions sampling(filter ? SkFilterMode::kLinear : SkFilterMode::kNearest,
+ SkMipmapMode::kNone);
+ return createBitmapShaderHelper(env, o, matrixPtr, bitmapHandle, tileModeX, tileModeY,
+ isDirectSampled, sampling);
+}
+
+static jlong BitmapShader_constructorWithMaxAniso(JNIEnv* env, jobject o, jlong matrixPtr,
+ jlong bitmapHandle, jint tileModeX,
+ jint tileModeY, jint maxAniso,
+ bool isDirectSampled) {
+ auto sampling = SkSamplingOptions::Aniso(static_cast<int>(maxAniso));
+ return createBitmapShaderHelper(env, o, matrixPtr, bitmapHandle, tileModeX, tileModeY,
+ isDirectSampled, sampling);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////
+
static std::vector<SkColor4f> convertColorLongs(JNIEnv* env, jlongArray colorArray) {
const size_t count = env->GetArrayLength(colorArray);
const jlong* colorValues = env->GetLongArrayElements(colorArray, nullptr);
@@ -408,6 +425,8 @@
static const JNINativeMethod gBitmapShaderMethods[] = {
{"nativeCreate", "(JJIIZZ)J", (void*)BitmapShader_constructor},
+ {"nativeCreateWithMaxAniso", "(JJIIIZ)J", (void*)BitmapShader_constructorWithMaxAniso},
+
};
static const JNINativeMethod gLinearGradientMethods[] = {