Merge "Added support for edge treatment parameters for BlurShader"
This commit is contained in:
committed by
Android (Google) Code Review
commit
f03c5aa5f6
@@ -14292,6 +14292,7 @@ package android.graphics {
|
||||
|
||||
public final class BlurShader extends android.graphics.Shader {
|
||||
ctor public BlurShader(float, float, @Nullable android.graphics.Shader);
|
||||
ctor public BlurShader(float, float, @Nullable android.graphics.Shader, @NonNull android.graphics.Shader.TileMode);
|
||||
}
|
||||
|
||||
public class Camera {
|
||||
@@ -15644,6 +15645,7 @@ package android.graphics {
|
||||
|
||||
public enum Shader.TileMode {
|
||||
enum_constant public static final android.graphics.Shader.TileMode CLAMP;
|
||||
enum_constant public static final android.graphics.Shader.TileMode DECAL;
|
||||
enum_constant public static final android.graphics.Shader.TileMode MIRROR;
|
||||
enum_constant public static final android.graphics.Shader.TileMode REPEAT;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.graphics;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
|
||||
/**
|
||||
@@ -28,9 +29,26 @@ public final class BlurShader extends Shader {
|
||||
private final float mRadiusX;
|
||||
private final float mRadiusY;
|
||||
private final Shader mInputShader;
|
||||
private final TileMode mEdgeTreatment;
|
||||
|
||||
private long mNativeInputShader = 0;
|
||||
|
||||
/**
|
||||
* Create a {@link BlurShader} that blurs the contents of the optional input shader
|
||||
* with the specified radius along the x and y axis. If no input shader is provided
|
||||
* then all drawing commands issued with a {@link android.graphics.Paint} that this
|
||||
* shader is installed in will be blurred.
|
||||
*
|
||||
* This uses a default {@link TileMode#DECAL} for edge treatment
|
||||
*
|
||||
* @param radiusX Radius of blur along the X axis
|
||||
* @param radiusY Radius of blur along the Y axis
|
||||
* @param inputShader Input shader that provides the content to be blurred
|
||||
*/
|
||||
public BlurShader(float radiusX, float radiusY, @Nullable Shader inputShader) {
|
||||
this(radiusX, radiusY, inputShader, TileMode.DECAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link BlurShader} that blurs the contents of the optional input shader
|
||||
* with the specified radius along the x and y axis. If no input shader is provided
|
||||
@@ -39,18 +57,22 @@ public final class BlurShader extends Shader {
|
||||
* @param radiusX Radius of blur along the X axis
|
||||
* @param radiusY Radius of blur along the Y axis
|
||||
* @param inputShader Input shader that provides the content to be blurred
|
||||
* @param edgeTreatment Policy for how to blur content near edges of the blur shader
|
||||
*/
|
||||
public BlurShader(float radiusX, float radiusY, @Nullable Shader inputShader) {
|
||||
public BlurShader(float radiusX, float radiusY, @Nullable Shader inputShader,
|
||||
@NonNull TileMode edgeTreatment) {
|
||||
mRadiusX = radiusX;
|
||||
mRadiusY = radiusY;
|
||||
mInputShader = inputShader;
|
||||
mEdgeTreatment = edgeTreatment;
|
||||
}
|
||||
|
||||
/** @hide **/
|
||||
@Override
|
||||
protected long createNativeInstance(long nativeMatrix) {
|
||||
mNativeInputShader = mInputShader != null ? mInputShader.getNativeInstance() : 0;
|
||||
return nativeCreate(nativeMatrix, mRadiusX, mRadiusY, mNativeInputShader);
|
||||
return nativeCreate(nativeMatrix, mRadiusX, mRadiusY, mNativeInputShader,
|
||||
mEdgeTreatment.nativeInt);
|
||||
}
|
||||
|
||||
/** @hide **/
|
||||
@@ -61,5 +83,5 @@ public final class BlurShader extends Shader {
|
||||
}
|
||||
|
||||
private static native long nativeCreate(long nativeMatrix, float radiusX, float radiusY,
|
||||
long inputShader);
|
||||
long inputShader, int edgeTreatment);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,11 @@ public class Shader {
|
||||
* repeat the shader's image horizontally and vertically, alternating
|
||||
* mirror images so that adjacent images always seam
|
||||
*/
|
||||
MIRROR (2);
|
||||
MIRROR(2),
|
||||
/**
|
||||
* Only draw within the original domain, return transparent-black everywhere else
|
||||
*/
|
||||
DECAL(3);
|
||||
|
||||
TileMode(int nativeInt) {
|
||||
this.nativeInt = nativeInt;
|
||||
|
||||
@@ -224,7 +224,7 @@ static jlong ComposeShader_create(JNIEnv* env, jobject o, jlong matrixPtr,
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static jlong BlurShader_create(JNIEnv* env , jobject o, jlong matrixPtr, jfloat sigmaX,
|
||||
jfloat sigmaY, jlong shaderHandle) {
|
||||
jfloat sigmaY, jlong shaderHandle, jint edgeTreatment) {
|
||||
auto* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
|
||||
auto* inputShader = reinterpret_cast<Shader*>(shaderHandle);
|
||||
|
||||
@@ -232,6 +232,7 @@ static jlong BlurShader_create(JNIEnv* env , jobject o, jlong matrixPtr, jfloat
|
||||
sigmaX,
|
||||
sigmaY,
|
||||
inputShader,
|
||||
static_cast<SkTileMode>(edgeTreatment),
|
||||
matrix
|
||||
);
|
||||
return reinterpret_cast<jlong>(blurShader);
|
||||
@@ -291,7 +292,7 @@ static const JNINativeMethod gBitmapShaderMethods[] = {
|
||||
};
|
||||
|
||||
static const JNINativeMethod gBlurShaderMethods[] = {
|
||||
{ "nativeCreate", "(JFFJ)J", (void*)BlurShader_create }
|
||||
{ "nativeCreate", "(JFFJI)J", (void*)BlurShader_create }
|
||||
};
|
||||
|
||||
static const JNINativeMethod gLinearGradientMethods[] = {
|
||||
|
||||
@@ -20,13 +20,14 @@
|
||||
#include "utils/Blur.h"
|
||||
|
||||
namespace android::uirenderer {
|
||||
BlurShader::BlurShader(float radiusX, float radiusY, Shader* inputShader, const SkMatrix* matrix)
|
||||
BlurShader::BlurShader(float radiusX, float radiusY, Shader* inputShader, SkTileMode edgeTreatment,
|
||||
const SkMatrix* matrix)
|
||||
: Shader(matrix)
|
||||
, skImageFilter(
|
||||
SkImageFilters::Blur(
|
||||
Blur::convertRadiusToSigma(radiusX),
|
||||
Blur::convertRadiusToSigma(radiusY),
|
||||
SkTileMode::kClamp,
|
||||
edgeTreatment,
|
||||
inputShader ? inputShader->asSkImageFilter() : nullptr,
|
||||
nullptr)
|
||||
) { }
|
||||
|
||||
@@ -30,8 +30,12 @@ public:
|
||||
*
|
||||
* This will blur the contents of the provided input shader if it is non-null, otherwise
|
||||
* the source bitmap will be blurred instead.
|
||||
*
|
||||
* The edge treatment parameter determines how content near the edges of the source is to
|
||||
* participate in the blur
|
||||
*/
|
||||
BlurShader(float radiusX, float radiusY, Shader* inputShader, const SkMatrix* matrix);
|
||||
BlurShader(float radiusX, float radiusY, Shader* inputShader, SkTileMode edgeTreatment,
|
||||
const SkMatrix* matrix);
|
||||
~BlurShader() override;
|
||||
protected:
|
||||
sk_sp<SkImageFilter> makeSkImageFilter() override;
|
||||
|
||||
@@ -14292,6 +14292,7 @@ package android.graphics {
|
||||
|
||||
public final class BlurShader extends android.graphics.Shader {
|
||||
ctor public BlurShader(float, float, @Nullable android.graphics.Shader);
|
||||
ctor public BlurShader(float, float, @Nullable android.graphics.Shader, @NonNull android.graphics.Shader.TileMode);
|
||||
}
|
||||
|
||||
public class Camera {
|
||||
@@ -15626,6 +15627,7 @@ package android.graphics {
|
||||
|
||||
public enum Shader.TileMode {
|
||||
enum_constant public static final android.graphics.Shader.TileMode CLAMP;
|
||||
enum_constant public static final android.graphics.Shader.TileMode DECAL;
|
||||
enum_constant public static final android.graphics.Shader.TileMode MIRROR;
|
||||
enum_constant public static final android.graphics.Shader.TileMode REPEAT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user