Remove isOpaque from RuntimeShader
Skia can now detect this performance optimization automatically so there is no need to increase the exposure of the public API. Test: atest CtsUiRenderingTestCases Bug: 201546136 Change-Id: I5f80259530a08506f54cef59b4b1940e940bfe91
This commit is contained in:
parent
e3fbc9417f
commit
7843e51a80
@ -15449,8 +15449,6 @@ package android.graphics {
|
||||
|
||||
public class RuntimeShader extends android.graphics.Shader {
|
||||
ctor public RuntimeShader(@NonNull String);
|
||||
ctor public RuntimeShader(@NonNull String, boolean);
|
||||
method public boolean isForceOpaque();
|
||||
method public void setColorUniform(@NonNull String, @ColorInt int);
|
||||
method public void setColorUniform(@NonNull String, @ColorLong long);
|
||||
method public void setColorUniform(@NonNull String, @NonNull android.graphics.Color);
|
||||
|
@ -34,8 +34,6 @@ public class RuntimeShader extends Shader {
|
||||
RuntimeShader.class.getClassLoader(), nativeGetFinalizer());
|
||||
}
|
||||
|
||||
private boolean mForceOpaque;
|
||||
|
||||
/**
|
||||
* Current native shader builder instance.
|
||||
*/
|
||||
@ -47,33 +45,17 @@ public class RuntimeShader extends Shader {
|
||||
* @param shader The text of AGSL shader program to run.
|
||||
*/
|
||||
public RuntimeShader(@NonNull String shader) {
|
||||
this(shader, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new RuntimeShader.
|
||||
*
|
||||
* @param shader The text of AGSL shader program to run.
|
||||
* @param forceOpaque If true then all pixels produced by the AGSL shader program will have an
|
||||
* alpha of 1.0f.
|
||||
*/
|
||||
public RuntimeShader(@NonNull String shader, boolean forceOpaque) {
|
||||
// colorspace is required, but the RuntimeShader always produces colors in the destination
|
||||
// buffer's colorspace regardless of the value specified here.
|
||||
super(ColorSpace.get(ColorSpace.Named.SRGB));
|
||||
if (shader == null) {
|
||||
throw new NullPointerException("RuntimeShader requires a non-null AGSL string");
|
||||
}
|
||||
mForceOpaque = forceOpaque;
|
||||
mNativeInstanceRuntimeShaderBuilder = nativeCreateBuilder(shader);
|
||||
NoImagePreloadHolder.sRegistry.registerNativeAllocation(
|
||||
this, mNativeInstanceRuntimeShaderBuilder);
|
||||
}
|
||||
|
||||
public boolean isForceOpaque() {
|
||||
return mForceOpaque;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the uniform color value corresponding to this shader. If the shader does not have a
|
||||
* uniform with that name or if the uniform is declared with a type other than vec3 or vec4 and
|
||||
@ -322,7 +304,7 @@ public class RuntimeShader extends Shader {
|
||||
/** @hide */
|
||||
@Override
|
||||
protected long createNativeInstance(long nativeMatrix, boolean filterFromPaint) {
|
||||
return nativeCreateShader(mNativeInstanceRuntimeShaderBuilder, nativeMatrix, mForceOpaque);
|
||||
return nativeCreateShader(mNativeInstanceRuntimeShaderBuilder, nativeMatrix);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@ -332,8 +314,7 @@ public class RuntimeShader extends Shader {
|
||||
|
||||
private static native long nativeGetFinalizer();
|
||||
private static native long nativeCreateBuilder(String agsl);
|
||||
private static native long nativeCreateShader(
|
||||
long shaderBuilder, long matrix, boolean isOpaque);
|
||||
private static native long nativeCreateShader(long shaderBuilder, long matrix);
|
||||
private static native void nativeUpdateUniforms(
|
||||
long shaderBuilder, String uniformName, float[] uniforms, boolean isColor);
|
||||
private static native void nativeUpdateUniforms(
|
||||
|
@ -126,7 +126,7 @@ final class RippleShader extends RuntimeShader {
|
||||
private static final double PI_ROTATE_LEFT = Math.PI * -0.0078125;
|
||||
|
||||
RippleShader() {
|
||||
super(SHADER, false);
|
||||
super(SHADER);
|
||||
}
|
||||
|
||||
public void setShader(Shader shader) {
|
||||
|
@ -261,11 +261,10 @@ static jlong RuntimeShader_getNativeFinalizer(JNIEnv*, jobject) {
|
||||
return static_cast<jlong>(reinterpret_cast<uintptr_t>(&SkRuntimeShaderBuilder_delete));
|
||||
}
|
||||
|
||||
static jlong RuntimeShader_create(JNIEnv* env, jobject, jlong shaderBuilder, jlong matrixPtr,
|
||||
jboolean isOpaque) {
|
||||
static jlong RuntimeShader_create(JNIEnv* env, jobject, jlong shaderBuilder, jlong matrixPtr) {
|
||||
SkRuntimeShaderBuilder* builder = reinterpret_cast<SkRuntimeShaderBuilder*>(shaderBuilder);
|
||||
const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
|
||||
sk_sp<SkShader> shader = builder->makeShader(matrix, isOpaque == JNI_TRUE);
|
||||
sk_sp<SkShader> shader = builder->makeShader(matrix, false);
|
||||
ThrowIAE_IfNull(env, shader);
|
||||
return reinterpret_cast<jlong>(shader.release());
|
||||
}
|
||||
@ -419,7 +418,7 @@ static const JNINativeMethod gComposeShaderMethods[] = {
|
||||
|
||||
static const JNINativeMethod gRuntimeShaderMethods[] = {
|
||||
{"nativeGetFinalizer", "()J", (void*)RuntimeShader_getNativeFinalizer},
|
||||
{"nativeCreateShader", "(JJZ)J", (void*)RuntimeShader_create},
|
||||
{"nativeCreateShader", "(JJ)J", (void*)RuntimeShader_create},
|
||||
{"nativeCreateBuilder", "(Ljava/lang/String;)J", (void*)RuntimeShader_createShaderBuilder},
|
||||
{"nativeUpdateUniforms", "(JLjava/lang/String;[FZ)V",
|
||||
(void*)RuntimeShader_updateFloatArrayUniforms},
|
||||
|
@ -33,7 +33,7 @@ import android.util.MathUtils
|
||||
*
|
||||
* Modeled after frameworks/base/graphics/java/android/graphics/drawable/RippleShader.java.
|
||||
*/
|
||||
class DwellRippleShader internal constructor() : RuntimeShader(SHADER, false) {
|
||||
class DwellRippleShader internal constructor() : RuntimeShader(SHADER) {
|
||||
companion object {
|
||||
private const val SHADER_UNIFORMS = """uniform vec2 in_origin;
|
||||
uniform float in_time;
|
||||
|
@ -28,7 +28,7 @@ import android.util.MathUtils
|
||||
*
|
||||
* Modeled after frameworks/base/graphics/java/android/graphics/drawable/RippleShader.java.
|
||||
*/
|
||||
class RippleShader internal constructor() : RuntimeShader(SHADER, false) {
|
||||
class RippleShader internal constructor() : RuntimeShader(SHADER) {
|
||||
companion object {
|
||||
private const val SHADER_UNIFORMS = """uniform vec2 in_origin;
|
||||
uniform float in_progress;
|
||||
|
@ -41,7 +41,7 @@ class BitmapTransitionView @JvmOverloads constructor(
|
||||
ImageDecoder.createSource(context.resources, R.drawable.very_large_photo))
|
||||
private val mShaderA = BitmapShader(mImageA, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
|
||||
private val mShaderB = BitmapShader(mImageB, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
|
||||
private val mShader = RuntimeShader(AGSL, false)
|
||||
private val mShader = RuntimeShader(AGSL)
|
||||
private var mCurrentProgress = -1f
|
||||
private var mForwardProgress = true
|
||||
private var mCurrentAnimator = ValueAnimator.ofFloat(-1f, 1f)
|
||||
|
@ -83,7 +83,7 @@ public class ColorFiltersMutateActivity extends Activity {
|
||||
mBlendPaint = new Paint();
|
||||
mBlendPaint.setColorFilter(new PorterDuffColorFilter(0, PorterDuff.Mode.SRC_OVER));
|
||||
|
||||
mRuntimeShader = new RuntimeShader(sSkSL, false);
|
||||
mRuntimeShader = new RuntimeShader(sSkSL);
|
||||
mRuntimeShader.setFloatUniform("param1", mShaderParam1);
|
||||
mRuntimeShader.setInputShader("bitmapShader", new BitmapShader(mBitmap1,
|
||||
Shader.TileMode.CLAMP,
|
||||
|
@ -30,7 +30,7 @@ import android.view.View
|
||||
|
||||
class RenderEffectViewActivity : Activity() {
|
||||
|
||||
private val mDropsShader = RuntimeShader(dropsAGSL, false)
|
||||
private val mDropsShader = RuntimeShader(dropsAGSL)
|
||||
private var mDropsAnimator = ValueAnimator.ofFloat(0f, 1f)
|
||||
private var mStartTime = System.currentTimeMillis()
|
||||
private lateinit var mScratchesImage: Bitmap
|
||||
|
@ -109,7 +109,7 @@ public class RippleActivity extends Activity {
|
||||
p.setColor(mColor);
|
||||
mPaint = CanvasProperty.createPaint(p);
|
||||
|
||||
mRuntimeShader = new RuntimeShader(sSkSL, false);
|
||||
mRuntimeShader = new RuntimeShader(sSkSL);
|
||||
mRuntimeShader.setFloatUniform("in_maxRadius", MAX_RADIUS);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class StretchShaderActivity extends Activity {
|
||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
mBitmap = ((BitmapDrawable) getDrawable(R.drawable.sunset1)).getBitmap();
|
||||
mRuntimeShader = new RuntimeShader(SKSL, false);
|
||||
mRuntimeShader = new RuntimeShader(SKSL);
|
||||
|
||||
BitmapShader bitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP,
|
||||
Shader.TileMode.CLAMP);
|
||||
|
Loading…
x
Reference in New Issue
Block a user