Android Graphics Shading Language (AGSL) 为Android 13 引入的新特性,本文对其使用做一个
简单的介绍。
AGSL的一种用法是结合Paint使用:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
}
private static class MyView extends View {
private static final String SHADER_SRC =
"half4 main(float2 fragCoord) {\n" +
"return half4(1,0,0,1);\n" +
"}";
RuntimeShader mShader = new RuntimeShader(SHADER_SRC);
private Paint mPaint = new Paint();
public MyView(Context context){
super(context);
mPaint.setShader(mShader);
}
@Override
protected void onDraw